55
LRC
The LRC (Longitudinal Redundancy Check) is used to validate a data block, it is performed over every
transmitted character, starting from and including STX till the last character of the packets body, or
the Packet Number Low Nibble in case of no Data Body..
By this assertion is univocally defined that the data bytes, as previously explained, are converted into
ASCII characters, and the LRC is performed over those converted ASCII characters and NOT over the
original data.
In the case of a packet with no Data, the LRC will be performed over the 15 first characters of the
packet.
On the other side, the receiving LRC will be performed over the received data in the order they are
arriving.
The order is important since is a factor used for the calculation.
The formula used is:
LRC = (LRC + Data) XOR Position
The Position (or Index) is the position of the data in the string, first position is 1 and is incremented at
every step.
Data is the byte of present data.
All the values (LRC, DATA, Position) are 8 bits values, wrapping to 00 and discarding the carry at
overflow.
The initial values for calculations are:
LRC = 0
Position = 1
The final result will be an 8 bits value that, after conversion into 2 ASCII characters, shall be
appended to the packet, before the ETX.