示例#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 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;
    }
  }