[fpc-pascal] Calculating CRC16?

Bo Berglund bo.berglund at gmail.com
Tue Oct 25 08:30:19 CEST 2022


I am working on a handler for IoT data from an electricity meter which
communicates via TTL serial at 115200 baud. It only sends data in packets of
less than 1 kbytes every 5-10 seconds.

In order to validate the data I need to check the CRC16 checksum at the end and
here is where I don't find a good way to do it...
The application will run on Linux so I checked for operating support but found
only sksum, which apparently does not do CRC16.

Is there some package or code available somewhere which can calculate the CRC16
value over a byte array of some 1000 bytes?

In a description of the protocol after showing the data structure it adds this:

crc16 = libscrc.ibm(example_data).to_bytes(2, 'big').hex() >> '7945'

Googling libscrc brings me to Python code on GitHub, which I am not really able
to use, never programmed Python...
https://github.com/hex-in/libscrc

Anyone able to help with FPC implementation?

-- 
Bo Berglund
Developer in Sweden



More information about the fpc-pascal mailing list