Beispiel #1
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 #2
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);
 }