public Tuple getTuple() throws IllegalArgumentException {
   int r = 0;
   int t = 0;
   Tuple content = new Tuple();
   Tuple envelope = new Tuple();
   System.out.println("ACCELERATION TASK DEFINITION");
   System.out.println("Insert the reporting period in SECONDS (= " + Constants.SECOND + " ms)");
   try {
     r = Integer.parseInt(reader.readLine());
   } catch (Exception e) {
     throw new IllegalArgumentException(e);
   }
   System.out.println("Insert the total number of reporting periods (-1 for an infinite task)");
   try {
     t = Integer.parseInt(reader.readLine());
     if (t == -1) {
       t = Constants.INFINITE_OP_TIME;
     }
   } catch (Exception e) {
     throw new IllegalArgumentException(e);
   }
   content.add(new Field().actualField(new Uint8(Constants.TASK_TYPE)));
   content.add(new Field().actualField(new Uint8(Constants.ACCELERATION)));
   content.add(new Field().actualField(new Uint16(r)));
   content.add(new Field().actualField(new Uint16(t)));
   envelope.add(new Field().actualField(new Uint8(Constants.DISSEMINATION_TYPE)));
   envelope.add(new Field().actualField(new Uint16(Constants.DISSEMINATE_A_NEW_TUPLE)));
   envelope.add(new Field().actualField(new Uint16(Constants.ACCELERATION)));
   envelope.add(
       new Field()
           .actualField(
               new Uint8Array(Properties.TUPLE_DISS_PAYLOAD_SIZE)
                   .setValue(Serializer.toSerial(content))));
   return envelope;
 }
Beispiel #2
0
  public Hashtable<_CollectionFeature, Sample> read(Tuple tuple) {
    short[] data = ((Uint8Array) tuple.get(3).getValue()).serializeValue();
    int target_gw = (data[2] << 8) + data[3];
    int node_identifier = (data[4] << 8) + data[5];
    int period = (data[6] << 8) + data[7];
    int info_id = (data[8] << 8) + data[9];
    int value = (data[10] << 8) + data[11];

    if (log) {
      try {
        Timestamp ts = new Timestamp(new Date().getTime());
        writer = new FileWriter(fileName, true);
        writer.write(
            "GW\t"
                + target_gw
                + "\tID\t"
                + node_identifier
                + "\tSEQ_NO\t"
                + period
                + "\tINFO_ID\t"
                + info_id
                + "\tVALUE\t"
                + value
                + "\t"
                + ts);
        writer.write("\n");
        writer.flush();
        writer.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }

    Hashtable<_CollectionFeature, Sample> ret = new Hashtable<_CollectionFeature, Sample>();
    Vector<Integer> v = new Vector<Integer>();
    switch (info_id) {
      case Constants.ROUTING_PARENT:
        v.add(value);
        ret.put(Parent.getFeature(), new Sample(v, new Date(System.currentTimeMillis())));
        break;
      case Constants.ROUTING_PARENT_LQI:
        v.add(value);
        ret.put(ParentQuality.getFeature(), new Sample(v, new Date(System.currentTimeMillis())));
        break;
      case Constants.BATTERY:
        ret.put(
            Battery.getFeature(),
            new Sample(Battery.convert((int) value), new Date(System.currentTimeMillis())));
        break;
      case Constants.TEMPERATURE:
        ret.put(
            Temperature.getFeature(),
            new Sample(Temperature.convert((int) value), new Date(System.currentTimeMillis())));
        break;
    }
    return ret;
  }
Beispiel #3
0
 public SourceId getSource(Tuple tuple) {
   short[] data = ((Uint8Array) tuple.get(3).getValue()).serializeValue();
   int node_identifier = (data[4] << 8) + data[5];
   return new SourceId(node_identifier);
 }