@Override
 public boolean invoke(PacketTuple o, long timestamp) {
   int crcInPacket = o.getIntAttribute(crcAttributeName);
   DecodedPacket packet = o.getPacket();
   int crcPos = phyConfig.CRCpos;
   if (!phyConfig.fixedSize) {
     crcPos += packet.getByte(phyConfig.lengthPos) + phyConfig.lengthOffset;
   }
   // check valid packet size
   if (crcPos > packet.getLength()) {
     return false;
   }
   int crc = 0xffff;
   for (int pos = 0; pos < crcPos; pos++) {
     int data = packet.getByte(pos);
     data ^= crc & 0xff;
     data ^= (data << 4) & 0xff;
     crc = (((data << 8) | (crc >> 8)) ^ (data >> 4) ^ (data << 3)) & 0xffff;
   }
   return (crcInPacket == crc);
 }
Example #2
0
 public void process(Tuple o, int srcID, long timestamp) {
   PacketTuple packet = (PacketTuple) o;
   int nrElements = packet.getIntAttribute(sizeField);
   for (int itemNr = 0; itemNr < nrElements; itemNr++) {
     Tuple newTuple = Tuple.createTuple(newType);
     for (int i = 0; i < prototype.fieldAttributes.length; i++) {
       TupleAttribute aField = prototype.fieldAttributes[i];
       if (!aField.equals(sizeField)
           && !aField.equals(arrayField)
           && !aField.equals(tupleTypeID)) {
         String path = arrayField.getName() + "[" + itemNr + "]." + aField.getName();
         if (((PacketTuple) o).exists(path)) {
           newTuple.setAttribute(aField, packet.getAttribute(path));
         } else {
           newTuple.setAttribute(aField, packet.getAttribute(aField));
         }
       }
     }
     transfer(newTuple, timestamp);
   }
 }