Calculates a packet "checksum". Adds a "checksum" byte to the end of a packet
add-checksum
@/add-checksum
Calculates a packet "checksum". Adds a "checksum" byte to the end of a packet
IN@/packet
CSBbyte
A "checksum" byte value
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) {
uint16_t sum = 0;
auto _packet = getValue<input_IN>(ctx);
for(uint8_t i = 0; i < (_packet.bufferSize - 1); i++){
sum += _packet.buffer[i];
}
uint8_t checksumByte = getValue<input_CSB>(ctx);
_packet.buffer[_packet.bufferSize - 1] = sum & checksumByte;
emitValue<output_OUT>(ctx, _packet);
}