예제 #1
0
  public void messageReceived(int to, Message message) {
    Date date = Calendar.getInstance().getTime();

    if (message instanceof RadioSignalResultsMsg) {
      RadioSignalResultsMsg resultMsg = (RadioSignalResultsMsg) message;
      log(
          date
              + "\t"
              + date.getTime()
              + "\t"
              + "RADIO15.4_RESULT_MSG"
              + "\t"
              + resultMsg.get_idReceiver()
              + "\t"
              + resultMsg.get_idSender()
              + "\t"
              + resultMsg.get_seqno()
              + "\t"
              + resultMsg.get_rssi()
              + "\t"
              + resultMsg.get_lqi()
              + "\t"
              + resultMsg.get_timestamp());
    } else {
      log(date + "\t" + date.getTime() + "\t UNKNOWN_MSG" + "\t" + message.toString());
    }
  }
예제 #2
0
 void setupDrip(Message msg, int msgSize) {
   trickle = new Timer();
   trickleTask = new DripSender();
   dripMsg = new DripMsg(DripMsg.DEFAULT_MESSAGE_SIZE + msgSize);
   dripMsg.dataSet(msg.dataGet(), 0, dripMsg.offset_data(0), msgSize);
   sendCount = 0;
 }
예제 #3
0
  public static void main(String[] args) throws Exception {
    String source = null;
    Vector v = new Vector();
    if (args.length > 0) {
      for (int i = 0; i < args.length; i++) {
        if (args[i].equals("-comm")) {
          source = args[++i];
        } else {
          String className = args[i];
          try {
            Class c = Class.forName(className);
            Object packet = c.newInstance();
            Message msg = (Message) packet;
            if (msg.amType() < 0) {
              System.err.println(className + " does not have an AM type - ignored");
            } else {
              v.addElement(msg);
            }
          } catch (Exception e) {
            System.err.println(e);
          }
        }
      }
    } else if (args.length != 0) {
      usage();
      System.exit(1);
    }

    MsgReader mr = new MsgReader(source);
    Enumeration msgs = v.elements();
    while (msgs.hasMoreElements()) {
      Message m = (Message) msgs.nextElement();
      mr.addMsgType(m);
    }
    mr.start();
  }
예제 #4
0
  Message buildAddrMsg(int dest, Message msg, int msgSize) {
    AddressMsg addrMsg = new AddressMsg(AddressMsg.DEFAULT_MESSAGE_SIZE + msgSize);
    String moteid = Env.getenv("MOTEID");
    int source = 0xFFFF;

    if (moteid != null) {
      source = Integer.parseInt(moteid);
    }

    addrMsg.dataSet(msg.dataGet(), 0, addrMsg.offset_data(0), msgSize);

    addrMsg.set_dest(dest);
    addrMsg.set_source(source);

    return addrMsg;
  }
예제 #5
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;
    }
  }