Пример #1
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]";
 }
Пример #2
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);
    }
  }
Пример #3
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;
  }
  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);
    }
  }
Пример #5
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;
    }
  }