Search code examples
serial-portchecksumcrc

what is this 2-byte LRC/VRC checksum?


I am trying to interpret an old (20years) electronic device that sends serial data. The messages are HEX format 22 bytes each. 20 bytes are data (I checked that they change according to specific functions) and the last 2 bytes are somekind of checksum.

The following are sample messages.

MESSAGE 1 : 16 16 16 16 02 FE 4E 8F 04 00 00 00 B0 83 7E 7C 7D 7F 7F 7F 7F SUM 75 FC MESSAGE 2 : 16 16 16 16 02 FE 4E 8F 04 00 00 00 B0 12 7E 7C 7D 7F 7F 7F 7F SUM E4 FA MESSAGE 3 : 16 16 16 16 02 FE 4E 8F 04 00 00 00 B0 94 7E 7C 7D 7F 7F 7F 7F SUM 62 FA MESSAGE 4 : 16 16 16 16 02 FE 4E 8F 04 00 00 00 B0 93 7E 7C 7D 7F 7F 7F 7F SUM 65 FC MESSAGE 5 : 16 16 16 16 02 FE 4E 8F 04 00 00 00 B0 92 7E 7C 7D 7F 7F 7F 7F SUM 64 FA MESSAGE 6 : 16 16 16 16 02 FE 4E 8F 04 00 00 00 B0 8C 7E 7C 7D 7F 7F 7F 7F SUM 7A 0A MESSAGE 7 (Special) : 16 16 16 16 02 FE 4E 50 SUM E2 80

I changed only one byte to make it easier to detect the change in the "checksum" , I confirmed that the first byte in the SUM is LRC by XORing the data bytes, but i cannot interpret the second byte and how it is calculated (i have tried CheckSum8 Modulo 256 / CheckSum8 2s Complement and CRC-8).

Note : The serial communication is 8 bit with even parity.


Solution

  • I think you should take first byte of the "sum" into account when calculating second byte of the "sum". Notice how sum of the changed byte and first byte of the "sum" is same for all lines with the same last byte of the sum. E.g. for lines ending with FC: 83+75=93+65 (in hex). So, it should be something pretty simple, like sum or similar. In fact, from sample lines you provided it looks like last byte in each line is just a sum of all preceding bytes (including first byte of the sum) plus A8 (all modulo 256 of course). Not sure where A8 comes from. Assume it's a sort of non zero seed which is a pretty common thing to do.