Calculates a packet "checksum". If the calculated "checksum" matches the one mentioned in a packet, then a packet arrived undamaged
check-packet
@/check-packet
Calculates a packet "checksum". If the calculated "checksum" matches the one mentioned in a packet, then a packet arrived undamaged
IN@/packet
CHCKpulse
Triggers a new packet check
CSBbyte
A "checksum" byte value
BADpulse
Fires on a broken packet
OKpulse
Fires if a packet arrived undamaged
OUT@/packet
To use the node in your project you should have the gabbapeople/simple-byte-protocol library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.
C++ implementation
struct State {
};
{{ GENERATED_CODE }}
void evaluate(Context ctx) {
if (!isInputDirty<input_CHCK>(ctx))
return;
uint8_t result = 0;
uint16_t sum = 0;
auto _packet = getValue<input_IN>(ctx);
uint8_t originalResult = _packet.buffer[_packet.bufferSize - 1];
for(uint8_t i = 0; i < (_packet.bufferSize - 1); i++){
sum += _packet.buffer[i];
}
uint8_t checksumByte = getValue<input_CSB>(ctx);
result = sum & checksumByte;
if (originalResult == result){
emitValue<output_OUT>(ctx, _packet);
emitValue<output_OK>(ctx, 1);
} else {
emitValue<output_BAD>(ctx, 1);
}
}