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]");
  }
Exemplo n.º 2
0
 public SerializationTest1(String s) {
   super(s);
   lastValue = 100D;
   series = new TimeSeries("Random Data");
   TimeSeriesCollection timeseriescollection = new TimeSeriesCollection(series);
   JFreeChart jfreechart = createChart(timeseriescollection);
   JFreeChart jfreechart1 = null;
   try {
     ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream();
     ObjectOutputStream objectoutputstream = new ObjectOutputStream(bytearrayoutputstream);
     objectoutputstream.writeObject(jfreechart);
     objectoutputstream.close();
     jfreechart = null;
     Object obj = null;
     series = null;
     System.gc();
     ObjectInputStream objectinputstream =
         new ObjectInputStream(new ByteArrayInputStream(bytearrayoutputstream.toByteArray()));
     jfreechart1 = (JFreeChart) objectinputstream.readObject();
     objectinputstream.close();
   } catch (Exception exception) {
     exception.printStackTrace();
   }
   XYPlot xyplot = (XYPlot) jfreechart1.getPlot();
   TimeSeriesCollection timeseriescollection1 = (TimeSeriesCollection) xyplot.getDataset();
   series = timeseriescollection1.getSeries(0);
   ChartPanel chartpanel = new ChartPanel(jfreechart1);
   JButton jbutton = new JButton("Add New Data Item");
   jbutton.setActionCommand("ADD_DATA");
   jbutton.addActionListener(this);
   JPanel jpanel = new JPanel(new BorderLayout());
   jpanel.add(chartpanel);
   jpanel.add(jbutton, "South");
   chartpanel.setPreferredSize(new Dimension(500, 270));
   setContentPane(jpanel);
 }
  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);
    }
  }