How calculate checksum in hdlc frame

433 Views Asked by At

I try to find how calculate checksum form hdlc frame. I try with example: 7E A0 0A 00 02 00 23 21 93 [18 71] - checksum 7E I tried this calculator: https://www.scadacore.com/tools/programming-calculators/online-checksum-calculator/

I put there this part of frame: A0 0A 00 02 00 23 21 93 but result didn't match...

I need your advice, guys...

2

There are 2 best solutions below

1
On

Without hitting the books, I recall that 7E is not the checksum, just the Tag - first byte in an hdlc message. Do you have the whole message you can share?

0
On

Implement on python: After calculating crc, write higher bit first and then your lower bits, for eg

crc= "3a3b" crc_used in packet=3b3a

you can try this:

import crcmod   #pip3 install crcmod
import sys
def calculate_crc(packet):
    packet=''.join(packet.split(' '))
    crc16 = crcmod.mkCrcFun(0x11021, rev=True, initCrc=0x0000, xorOut=0xFFFF)
    fcs=str(hex(crc16(bytes.fromhex(packet))))
    crc_f=str(fcs[4:6])+str(fcs[2:4])
    if len(crc_f)<4:
        diff=4-len(crc_f)
        crc_f= "0"*diff + crc_f
    return str(crc_f).upper()
print(calculate_crc("A0 0A 00 02 00 23 21 93"))

output: 1871