Example #1
0
  public static void main(String[] args) throws Exception {
    String source = null;
    if (args.length == 2) {
      if (!args[0].equals("-comm")) {
        usage();
        System.exit(1);
      }
      source = args[1];
    } else if (args.length != 0) {
      usage();
      System.exit(1);
    }

    PhoenixSource phoenix;

    if (source == null) {
      phoenix = BuildSource.makePhoenix(PrintStreamMessenger.err);
    } else {
      phoenix = BuildSource.makePhoenix(source, PrintStreamMessenger.err);
    }

    MoteIF mif = new MoteIF(phoenix);
    TestSerial serial = new TestSerial(mif);
    serial.sendPackets();
  }
Example #2
0
  public static void duration() {
    connectDb();
    String sql = "select min(time), max(time), count(*) from " + tablename + ";";
    try {
      ResultSet rs = query.executeQuery(sql);
      rs.next();
      int numCols = rs.getMetaData().getColumnCount();
      String minTime = rs.getString(1);
      String maxTime = rs.getString(2);
      String numPackets = rs.getString(3);
      System.out.println(
          "Experiment "
              + tablename
              + "\n\tfrom: "
              + minTime
              + "\n\tto: "
              + maxTime
              + "\n\tpackets: "
              + numPackets);

    } catch (SQLException e) {
      System.out.println("SQL Exception: " + e);
      System.exit(1);
    }
  }
Example #3
0
  public void run() {

    // setup advertisement message
    advMsg.set_sourceAddr(TOS_UART_ADDR);

    if (reboot) {
      advMsg.set_summary_vNum(0x0);
      advMsg.set_runningVNum(0xffff);
    } else {
      advMsg.set_summary_vNum(0xffff);
      advMsg.set_runningVNum(0x0);
    }
    advMsg.set_summary_numPgsComplete((byte) numPgs);

    while (true) {
      try {
        // send an advertisement message every second
        if (printAllMsgs) System.out.print(advMsg);
        send(advMsg);
        Thread.currentThread().sleep(1000);
        if (reboot) {
          System.exit(0);
        }
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
Example #4
0
 static void help() {
   System.out.println("");
   System.out.println("Usage: java RawLogger [options] ");
   System.out.println("  [options] are:");
   System.out.println("  -h, --help                  Display this message.");
   System.out.println("  --logging                   Enable Logging.");
   System.out.println("                              Required options (source). ");
   System.out.println("                              And (url, user, pass, tablename). ");
   System.out.println("  --display                   Display Packets.");
   System.out.println("                              Required options (source). ");
   System.out.println("  --createtable               Create a table.");
   System.out.println(
       "                              Required options (url, user, pass, tablename).");
   System.out.println("  --droptable                 Drop a table.");
   System.out.println(
       "                              Required options (url, user, pass, tablename).");
   System.out.println("  --cleartable                Clear a table.");
   System.out.println(
       "                              Required options (url, user, pass, tablename).");
   System.out.println("  --duration                  Summary of Experiement Duration.");
   System.out.println(
       "                              Required options (url, user, pass, tablename).");
   System.out.println("  --reset                     Reseting EPRB and the attached mote ");
   System.out.println("                              Required options (source). ");
   System.out.println("  --tablename=<name>          Specify sql tablename ");
   System.out.println("  --url=<ip/dbname>           JDBC URL. eg: localhost/rsc.");
   System.out.println("  --user=<user>               User of the database.");
   System.out.println("  --pass=<password>           Password of the database.");
   System.out.println("  --source=<type>             Standard TinyOS Source");
   System.out.println("                              serial@COM1:platform");
   System.out.println("                              network@HOSTNAME:PORTNUMBER");
   System.out.println("                              sf@HOSTNAME:PORTNUMBER");
   System.out.println("");
   System.exit(-1);
 }
Example #5
0
 private static void usage() {
   System.err.println("usage: java net.tinyos.drain.Drip <opts>");
   System.err.println("  -d <data value>");
   System.err.println("  -c <channel id>");
   System.err.println("  -w : send message with wakeup bit set");
   System.err.println("  -h, --help : this information");
   System.exit(1);
 }
Example #6
0
  Download(String[] args) {

    boolean done = false;
    boolean dumpSrec2 = false;
    String infile = "";
    vNum = -1;

    for (int i = 0; i < args.length; i++) {
      if (done) usage();

      if (args[i].equals("--srecfile")) {
        infile = args[++i];
      } else if (args[i].equals("--printmsgs")) {
        printAllMsgs = true;
      } else if (args[i].equals("--dumpsrec")) {
        dumpSrec2 = true;
      } else if (args[i].equals("--reboot")) {
        reboot = true;
      } else if (args[i].equals("-h") || args[i].equals("--help")) usage();
      else usage();
    }
    if (!reboot) {
      if (infile.equals("")) {
        usage();
      } else {
        readSrecCode(infile);
      }
    }

    if (dumpSrec2) {
      dumpSrec();
      System.exit(0);
    }

    try {
      intf = new MoteIF((Messenger) null);
      intf.registerListener(new DelugeAdvMsg(), this);
      intf.registerListener(new DelugeReqUpdMetadataMsg(), this);
      intf.registerListener(new DelugeReqMsg(), this);
    } catch (Exception e) {
      System.out.println("ERROR: Couldn't contact serial forwarder.");
      System.exit(1);
    }

    intf.start();
  }
Example #7
0
  public synchronized void messageReceived(int to, Message m) {

    switch (m.amType()) {
      case DelugeAdvMsg.AM_TYPE:
        DelugeAdvMsg rxAdvMsg = (DelugeAdvMsg) m;

        if (vNum == rxAdvMsg.get_summary_vNum()
            && numPgs == rxAdvMsg.get_summary_numPgsComplete()) {
          // ALL DONE, QUIT!
          System.out.println("DOWNLOAD COMPLETE!");
          System.out.println("--------------------------------------------------");
          System.exit(0);
        }

        break;

      case DelugeReqUpdMetadataMsg.AM_TYPE:
        DelugeReqUpdMetadataMsg reqUpd = (DelugeReqUpdMetadataMsg) m;

        if (printAllMsgs) System.out.print(reqUpd);
        vNum = (short) (reqUpd.get_vNum() + 1);
        advMsg.set_summary_vNum(vNum);

        System.out.print("Upgrading from version [" + reqUpd.get_vNum() + "]");
        System.out.println(" to version [" + vNum + "]");

        transmitMetadataUpd();

        break;

      case DelugeReqMsg.AM_TYPE:
        DelugeReqMsg req = (DelugeReqMsg) m;

        if (printAllMsgs) System.out.print(req);

        if (vNum != req.get_vNum()) {
          System.out.println("ERROR: Node requesting wrong version");
          System.exit(1);
        }

        transmitPage(req.get_pgNum());

        break;
    }
  }
Example #8
0
 public synchronized void send(Message m) {
   try {
     intf.send(MoteIF.TOS_BCAST_ADDR, m);
   } catch (IOException e) {
     e.printStackTrace();
     System.out.println("ERROR: Can't send message");
     System.exit(1);
   }
 }
Example #9
0
 private void usage() {
   System.err.println("usage: java net.tinyos.deluge.Download [options]");
   System.err.println("[options] are:");
   System.err.println("  --srecfile <srec> : srec file to download");
   System.err.println("  --reboot          : send reboot command to network");
   System.err.println("  --dumpsrec        : dumps hex of srec image");
   System.err.println("  --printmsgs       : print all sent/received msgs");
   System.exit(1);
 }
Example #10
0
 private void send(Message m) {
   try {
     moteIF.send(MoteIF.TOS_BCAST_ADDR, m);
   } catch (IOException e) {
     e.printStackTrace();
     System.out.println("ERROR: Can't send message");
     System.exit(1);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Example #11
0
 static void connectDb() {
   // before: localhost/rsc
   sqlURL = "jdbc:postgresql://" + sqlURL;
   // after: "jdbc:postgresql://localhost/rsc";
   // "jdbc:postgresql://webbie.berkeley.intel-research.net/rsc"
   try {
     Class.forName("org.postgresql.Driver");
   } catch (ClassNotFoundException cnfe) {
     System.out.println("Couldn't find the driver!");
     System.out.println("Let's print a stack trace, and exit.");
     System.exit(1);
   }
   Connection connection = null;
   try {
     connection = DriverManager.getConnection(sqlURL, sqlUser, sqlPassword);
     query = connection.createStatement();
   } catch (SQLException se) {
     System.out.println("Couldn't connect: " + se);
     System.exit(1);
   }
 }
 public AntiTheftGui() {
   try {
     guiInit();
     /* Setup communication with the mote and request a messageReceived
     callback when an AlertMsg is received */
     mote = new MoteIF(this);
     mote.registerListener(new AlertMsg(), this);
   } catch (Exception e) {
     e.printStackTrace();
     System.exit(2);
   }
 }
Example #13
0
  public static void clearTable() {
    connectDb();
    String sql = "delete from " + tablename + ";";
    try {
      query.executeUpdate(sql);

    } catch (SQLException e) {
      System.out.println("SQL Exception: " + e);
      System.exit(1);
    }
    System.out.println("Table Cleared Successfully");
  }
Example #14
0
  public Drip(int id) {

    log.info("Started id=" + id);
    try {
      moteIF = new MoteIF();
      moteIF.registerListener(new DripMsg(), this);
    } catch (Exception e) {
      System.out.println("ERROR: Couldn't contact serial forwarder.");
      System.exit(1);
    }

    this.id = id;
  }
Example #15
0
 public NodeInfo(Integer pNodeNumber) {
   packetTimesPointer = 0;
   packetSkipsPointer = 0;
   neighbors = new NeighborInfo[5];
   for (int i = 0; i < 5; i++) neighbors[i] = new NeighborInfo();
   packetTimes = new long[SensorAnalyzer.HISTORY_LENGTH];
   packetSkips = new long[SensorAnalyzer.HISTORY_LENGTH];
   yieldHistory = new double[SensorAnalyzer.YIELD_HISTORY_LENGTH];
   depthHistory = new byte[SensorAnalyzer.YIELD_HISTORY_LENGTH];
   lastTime = System.currentTimeMillis() - 500;
   nodeNumber = pNodeNumber;
   value = -1; // if it doesn't change from this value nothing will be written
   infoString = "[none]";
 }
Example #16
0
  public static void main(String[] args) throws Exception {
    String source = "";
    if (args.length == 2) {
      if (!args[0].equals("-comm")) {
        usage();
        System.exit(1);
      }
      source = args[1];
    } else {
      usage();
      System.exit(1);
    }

    PhoenixSource phoenix;
    if (source == null) {
      phoenix = BuildSource.makePhoenix(PrintStreamMessenger.err);
    } else {
      phoenix = BuildSource.makePhoenix(source, PrintStreamMessenger.err);
    }
    System.out.print(phoenix);
    MoteIF mif = new MoteIF(phoenix);
    PrintfClient client = new PrintfClient(mif);
  }
  public TestTtsp() {
    try {
      mote = new MoteIF(PrintStreamMessenger.err);
      mote.registerListener(new TestTtspMsg(), this);
      System.out.println("Connecting to basestation...OK");
    } catch (Exception e) {
      System.out.println("Connecting to basestation...FAILED");
      e.printStackTrace();
      System.exit(2);
    }

    System.out.println(
        "[Reception Time (ms)] [Node] [Beacon] [GlobalTime (ms)] [LocalTime (ms)] [Offset (ms)] [Root] [Period]");
  }
Example #18
0
  public static void main(String[] args) {

    parseArgs(args);

    Drip drip = new Drip(channel);
    TestDripMsg msg = new TestDripMsg();
    msg.set_data((short) data);

    if (wakeup) {
      drip.sendWakeup(msg, TestDripMsg.DEFAULT_MESSAGE_SIZE);
    } else {
      drip.send(msg, TestDripMsg.DEFAULT_MESSAGE_SIZE);
    }
    System.exit(0);
  }
Example #19
0
  public static void reset() {
    // network@ip:10002
    String address = source.substring(8, source.length() - 6);

    try {
      Socket server = new Socket(address, 9999);
      DataOutputStream out = new DataOutputStream(server.getOutputStream());
      out.writeBytes("\r\n");
      out.flush();
      out.writeBytes("9\r\n");
      out.flush();
    } catch (Exception e) {
      System.out.println("Sorry I can't reset the device fro some reason: " + e);
      System.exit(1);
    }
    System.out.println("Issued reset command to " + address);
  }
  public static void main(String[] args) {
    String motePort = null;
    String outputFile = null;
    for (int i = 0; i < args.length; i++) {
      if (args[i].equals("-comm")) {
        motePort = args[++i];
        System.out.println("Using mote port: " + motePort);
      } else if (args[i].equals("-file")) {
        outputFile = args[++i];
        System.out.println("Saving data to: " + outputFile);
      } else {
        usage();
        System.exit(1);
      }
    }

    RadioSignalMeter meter = new RadioSignalMeter(motePort, outputFile);
  }
Example #21
0
  public void messageReceived(int to, Message message) {
    long t = System.currentTimeMillis();
    // System.out.print("" + t + ": ");
    // System.out.println(message);

    MessageProcessor messageProcessor = new MessageProcessor((SerialMsg) message, t);

    JSONObject json = messageProcessor.getJSON();
    client.sendCollectionJSON(json);

    JSONObject processingJson = messageProcessor.getCouchJSON();
    client.sendProcessingJSON(processingJson);

    fireStatus[messageProcessor.nodeToSensorID()] = messageProcessor.getFire();

    if (fireStatus[0] || fireStatus[1] || fireStatus[2]) {
      client.sendFireRepresentation(fireStatus);
    }
  }
Example #22
0
  public void decay() {

    long curtime = System.currentTimeMillis();
    msgRate = calcMsgRate(curtime - lastTime);
    msgYield = calcMsgYield(curtime - lastTime);
    // also cycle the yield history.
    if (yieldHistoryCounter++ > SensorAnalyzer.YIELD_INTERVAL) {
      yieldHistoryCounter = 0;
      depthHistory[yieldHistoryPointer] = (byte) hopcount;
      yieldHistory[yieldHistoryPointer++] = yield();

      yieldHistoryPointer %= yieldHistory.length;
      if (panel != null) panel.repaint();
      if (link_panel != null) link_panel.get_new_data();
    }
    if (active) {
      active = false;
      return;
    }

    if (curtime - lastTime >= AVERAGE_INTERVAL) {
      if (self_calc != false) infoString = msgCount + " msgs ";
      else infoString = "";
      if (panel != null) panel.YieldLabel.setText(String.valueOf(percent_yield()) + " %");
    }
    int best = 0;
    int best_parent = 0;
    for (int i = 0; i < parent_count.length; i++) {
      if (parent_count[i] > best) {
        best_parent = i;
        best = parent_count[i];
      }
    }
    primary_parent = best_parent;
    best = 0;
    for (int i = 0; i < parent_count.length; i++) {
      if (parent_count[i] > best && i != primary_parent) {
        best_parent = i;
        best = parent_count[i];
      }
    }
    secondary_parent = best_parent;
  }
Example #23
0
  public static void createTable() {
    connectDb();
    String dataField = "";
    for (int i = 0; i < AM_HEADER_LENGTH + TOSH_DATA_LENGTH + CRC_LENGTH; i++) {
      dataField = dataField + ", " + "b" + Integer.toString(i) + " smallint";
    }
    String sql =
        "create table "
            + tablename
            + " (time timestamp without time zone, packetid serial"
            + dataField;
    sql += ", primary key (packetid) );";
    try {
      query.executeUpdate(sql);

    } catch (SQLException e) {
      System.out.println("SQL Exception: " + e);
      System.exit(1);
    }
    System.out.println("Initialise Table Successfully");
  }
Example #24
0
  public static void main(String[] args) throws Exception {
    String source = null;
    Vector v = new Vector();
    if (args.length > 0) {
      for (int i = 0; i < args.length; i++) {
        if (args[i].equals("-comm")) {
          source = args[++i];
        } else {
          String className = args[i];
          try {
            Class c = Class.forName(className);
            Object packet = c.newInstance();
            Message msg = (Message) packet;
            if (msg.amType() < 0) {
              System.err.println(className + " does not have an AM type - ignored");
            } else {
              v.addElement(msg);
            }
          } catch (Exception e) {
            System.err.println(e);
          }
        }
      }
    } else if (args.length != 0) {
      usage();
      System.exit(1);
    }

    MsgReader mr = new MsgReader(source);
    Enumeration msgs = v.elements();
    while (msgs.hasMoreElements()) {
      Message m = (Message) msgs.nextElement();
      mr.addMsgType(m);
    }
    mr.start();
  }
  public void processTtspMsg(TestTtspMsg msg) {
    if (seconds.containsKey(msg.get_beaconId())) {

    } else {
      if (seconds.containsKey(msg.get_beaconId() - 1)) {
        seconds.remove(msg.get_beaconId() - 1);
      }

      seconds.put(msg.get_beaconId(), new Second());

      System.out.printf("\n");
    }

    globalTimes.put(msg.get_srcAddr(), msg.get_globalTime());
    lastReceivedBeacons.put(msg.get_srcAddr(), msg.get_beaconId());

    try {
      System.out.printf(
          "%20d %6d %8d %17d %16d %13d",
          System.currentTimeMillis(),
          msg.get_srcAddr(),
          msg.get_beaconId(),
          msg.get_globalTime(),
          msg.get_localTime(),
          msg.get_offset());
    } catch (Exception e) {
      System.out.printf(
          "%20d %6d %8d %17d %16d %13d",
          System.currentTimeMillis(),
          msg.get_srcAddr(),
          msg.get_beaconId(),
          msg.get_globalTime(),
          msg.get_localTime(),
          msg.get_offset());
    }

    if (msg.get_rootId() == 65535) {
      System.out.printf("      -        -");
    } else {
      System.out.printf(" %6d %8d", msg.get_rootId(), msg.get_syncPeriod());
    }

    // System.out.printf(" %6d", msg.get_precisionError());

    System.out.printf("\n");

    if (!timeSeries.containsKey(msg.get_srcAddr())) {
      timeSeries.put(
          msg.get_srcAddr(),
          new TimeSeries("node " + msg.get_srcAddr(), org.jfree.data.time.Second.class));
      timeSeries.get(msg.get_srcAddr()).setMaximumItemAge(MAX_AGE);
      pec.getTimeSeriesCollection().addSeries(timeSeries.get(msg.get_srcAddr()));
    }

    if (msg.get_rootId() == msg.get_srcAddr()
        && !syncPeriodTimeSeries.containsKey(msg.get_srcAddr())) {
      syncPeriodTimeSeries.put(
          msg.get_srcAddr(),
          new TimeSeries("node " + msg.get_srcAddr(), org.jfree.data.time.Second.class));
      syncPeriodTimeSeries.get(msg.get_srcAddr()).setMaximumItemAge(MAX_AGE);
      spc.getTimeSeriesCollection().addSeries(syncPeriodTimeSeries.get(msg.get_srcAddr()));
    }

    if (msg.get_srcAddr() != msg.get_rootId()
        && globalTimes.containsKey(msg.get_rootId())
        && lastReceivedBeacons.get(msg.get_rootId()) == msg.get_beaconId()) {
      timeSeries
          .get(msg.get_srcAddr())
          .addOrUpdate(
              seconds.get(msg.get_beaconId()),
              globalTimes.get(msg.get_rootId()) - msg.get_globalTime());
    }

    if (msg.get_srcAddr() == msg.get_rootId()) {
      syncPeriodTimeSeries
          .get(msg.get_srcAddr())
          .addOrUpdate(seconds.get(msg.get_beaconId()), (int) msg.get_syncPeriod() / 1.024);
    }
  }
Example #26
0
 public static void usage() {
   System.err.println("java net.tinyos.wakeup.Wakeup {both,bat,cap} <timeout in seconds>");
   System.exit(1);
 }
Example #27
0
  public void update(MultihopMsg msg) {
    String info;
    SurgeMsg SMsg = new SurgeMsg(msg.dataGet(), msg.offset_data(0));
    if (SMsg.get_type() == 0) {

      if (SMsg.get_parentaddr() == MainFrame.BEACON_BASE_ADDRESS) {
        isDirectChild = true;
      } else {
        isDirectChild = false;
      }

      // Update message count and rate
      // Only update if this message is coming to the root from
      // a direct child
      int saddr = msg.get_sourceaddr();
      NodeInfo ni = (NodeInfo) SensorAnalyzer.proprietaryNodeInfo.get(new Integer(saddr));
      if (ni != null) {
        if (ni.isDirectChild) {
          msgCount++;
          int new_seq_no = (int) SMsg.get_seq_no() & 0x7fffff;
          if (stats_start_sequence_number == 0) stats_start_sequence_number = new_seq_no;
          if (seq_no == 0) seq_no = new_seq_no - 1;
          int diff = new_seq_no - seq_no;
          if (diff > 1000) diff = 1;
          active = true;
          long curtime = System.currentTimeMillis();
          packetTimes[packetTimesPointer++] = curtime - lastTime;
          packetTimesPointer %= SensorAnalyzer.HISTORY_LENGTH;
          packetSkips[packetSkipsPointer++] = diff;
          packetSkipsPointer %= SensorAnalyzer.HISTORY_LENGTH;
          msgRate = calcMsgRate(0);
          msgYield = calcMsgYield(0);

          SimpleDateFormat formatter = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");

          String log = "";
          log += nodeNumber + "#";
          log += msgCount + "#";
          log += formatter.format(new Date()) + "#";
          log += curtime + "#";
          log += (curtime - lastTime) + "#";
          log += SMsg.get_parentaddr() + "#";

          parent_count[SMsg.get_parentaddr()]++;
          log += msgRate + "#";
          seq_no = new_seq_no;
          batt = (int) SMsg.get_seq_no() >> 23 & 0x1ff;

          log += seq_no + "#";
          log += hopcount + "#";

          level_sum += hopcount;
          log += SMsg.get_reading() + "#";
          log += batt + "#";
          for (int i = 0; i < 5; i++) {
            log += neighbors[i].id + "#";
            log += neighbors[i].hopcount + "#";
            log += neighbors[i].link_quality / 255.0 + "#";
          }
          log += SMsg.get_temp() + "#";
          log += SMsg.get_light() + "#";
          log += SMsg.get_accelx() + "#";
          log += SMsg.get_accely() + "#";
          log += SMsg.get_magx() + "#";
          log += SMsg.get_magy() + "#";
          System.out.println(log);

          double batt_val = (double) batt;
          batt_val = 1.25 * 1023.0 / batt_val;
          batt_val *= 256.0 / 4.0;
          // System.out.println(batt_val);
          // Store the sensor readings.
          yield_series.insertNewReading(total_yield++, new Integer((int) (yield() * 256.0)));
          time_series.insertNewReading(seq_no, new Long(curtime));
          batt_series.insertNewReading(seq_no, new Integer((int) batt_val));
          temp_series.insertNewReading(seq_no, new Integer(SMsg.get_temp()));
          light_series.insertNewReading(seq_no, new Integer(SMsg.get_light()));
          accelx_series.insertNewReading(seq_no, new Integer(SMsg.get_accelx()));
          accely_series.insertNewReading(seq_no, new Integer(SMsg.get_accely()));
          magx_series.insertNewReading(seq_no, new Integer(SMsg.get_magx()));
          magy_series.insertNewReading(seq_no, new Integer(SMsg.get_magy()));

          link_quality = neighbors[0].link_quality / 255;

          // update the edge quality as well...
          MainClass.locationAnalyzer.setQualityForEdge(
              nodeNumber.intValue(), SMsg.get_parentaddr(), (int) (link_quality * 255.0));

          lastTime = curtime;
        }
      }

      if (self_calc != false) info = msgCount + " msgs ";
      else info = "";

      this.value = SMsg.get_reading();
      if (panel != null) {
        panel.YieldLabel.setText(String.valueOf(percent_yield()) + " %");
        panel.SensorLabel.setText(String.valueOf(value));
        panel.ParentLabel.setText(String.valueOf(SMsg.get_parentaddr()));
        panel.SequenceLabel.setText(String.valueOf(seq_no));
        panel.CountLabel.setText(String.valueOf(msgCount));
        panel.DepthLabel.setText(String.valueOf(hopcount));
        panel.repaint();
      }

      this.infoString = info;
    }
  }