示例#1
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();
      }
    }
  }
示例#2
0
  public static void main(String[] args) {

    Thread thread = new Thread(new Download(args));
    thread.setDaemon(true);
    thread.start();
    try {
      thread.join();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
示例#3
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();
   }
 }
 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]");
  }
示例#6
0
  public boolean readSrecCode(String fName) {

    FileInputStream fis = null;

    srec = new short[SREC_MAX_LINES][PKT_PAYLOAD_SIZE];
    numLines = 1;
    numPkts = 0;

    try {
      BufferedReader dis =
          new BufferedReader(new InputStreamReader(fis = new FileInputStream(fName)));
      System.out.println("--------------------------------------------------");
      System.out.println("Reading file: " + fName);
      // WARNING
      int curByte = 0; // 16; // account for S0 line which is not parsed

      while (true) {
        char bline[] = dis.readLine().toUpperCase().toCharArray();
        if (bline[1] == '1') {
          numLines++;
          if (bline.length > SREC_MAX_LINE_LEN) {
            System.out.println("ERROR: SREC Read: Too many byes on line: " + numLines);
            return false;
          }
          // srec length
          int length =
              Integer.parseInt(Character.toString(bline[2]) + Character.toString(bline[3]), 16) - 3;

          // data
          for (int i = 0, j = 8; i < length; i++, j += 2) {
            if (curByte >= PKT_PAYLOAD_SIZE) {
              numPkts++;
              curByte = 0;
            }
            srec[numPkts][curByte++] =
                (short)
                    Integer.parseInt(
                        Character.toString(bline[j]) + Character.toString(bline[j + 1]), 16);
            imgSize++;
          }
        } else if (bline[1] == '2') {
          numLines++;
          if (bline.length > SREC_MAX_LINE_LEN) {
            System.out.println("ERROR: SREC Read: Too many byes on line: " + numLines);
            return false;
          }
          // srec length
          int length =
              Integer.parseInt(Character.toString(bline[2]) + Character.toString(bline[3]), 16) - 4;

          // data
          for (int i = 0, j = 10; i < length; i++, j += 2) {
            if (curByte >= PKT_PAYLOAD_SIZE) {
              numPkts++;
              curByte = 0;
            }
            srec[numPkts][curByte++] =
                (short)
                    Integer.parseInt(
                        Character.toString(bline[j]) + Character.toString(bline[j + 1]), 16);
            imgSize++;
          }
        }
      }
    } catch (FileNotFoundException e) {
      System.out.println("ERROR: (SREC Read) " + e);
      return false;
    } catch (Exception e) {
      numPgs = (short) (((imgSize - 1) / BYTES_PER_PAGE) + 1);
      System.out.println(
          "Read END: (Lines="
              + numLines
              + ",Pages="
              + numPgs
              + ",Pkts="
              + numPkts
              + ",Size="
              + imgSize
              + ")");
      System.out.println("--------------------------------------------------");
    }

    try {
      if (fis != null) fis.close();
    } catch (Exception e) {
      e.printStackTrace();
    }

    return true;
  }