예제 #1
0
 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);
   }
 }
  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]");
  }
예제 #3
0
  /* User pressed the "Update" button. Read the GUI fields and
  send a SettingsMsg with the requested values. When the
  requested settings are bad, we silently update them to sane
  values. */
  public void updateSettings() {
    SettingsMsg smsg = new SettingsMsg();
    short alert = 0;
    short detect = 0;
    int checkInterval = Constants.DEFAULT_CHECK_INTERVAL;

    /* Extract current interval value, fixing bad values */
    String intervalS = fieldInterval.getText().trim();
    try {
      int newInterval = Integer.parseInt(intervalS);
      if (newInterval < 10) throw new NumberFormatException();
      checkInterval = newInterval;
    } catch (NumberFormatException e) {
      /* Reset field when value is bad */
      fieldInterval.setText("" + checkInterval);
    }

    /* Extract alert settings */
    if (repLedCb.isSelected()) alert |= Constants.ALERT_LEDS;
    if (repSirenCb.isSelected()) alert |= Constants.ALERT_SOUND;
    if (repNeighboursCb.isSelected()) alert |= Constants.ALERT_RADIO;
    if (repServerCb.isSelected()) alert |= Constants.ALERT_ROOT;
    if (alert == 0) {
      /* If nothing select, force-select LEDs */
      alert = Constants.ALERT_LEDS;
      repLedCb.setSelected(true);
    }

    /* Extract detection settings */
    if (detDarkCb.isSelected()) detect |= Constants.DETECT_DARK;
    if (detAccelCb.isSelected()) detect |= Constants.DETECT_ACCEL;
    if (detect == 0) {
      /* If no detection selected, force-select dark */
      detect = Constants.DETECT_DARK;
      detDarkCb.setSelected(true);
    }

    /* Build and send settings message */
    smsg.set_alert(alert);
    smsg.set_detect(detect);
    smsg.set_checkInterval(checkInterval);
    try {
      mote.send(MoteIF.TOS_BCAST_ADDR, smsg);
    } catch (IOException e) {
      error("Cannot send message to mote");
    }
  }