Search code examples
protocolschecksumserial-communication

Which algorithm is used to calculate checksum?


I am trying to decipher the protocol used for RS485 communication between several HVAC controllers. I was able to identify single messages as you can see in the list below.

00020003400012A9
00030103400012A7

00010303400012A7
2001030A400012010104FFFFFFFF7E

00010303400016A3
200103094000160C0C010400441C

000103074100000024A003ED
2001030A4100000024A0030895BA73

0001032A90020030000200310700013000020131070002300002023107060330000203310700043000FF053000FF1F
2001030290004A

00020003400012A9
00030103400012A7

00010302D10227
20010312D140200100002101000022010000230100002F

00020003400012A9
00030103400012A7

00010302D20226
20010302D240C8

00020003400012A9
00030103400012A7

00010302D10227
20010312D140200100002101000022010000230100002F

00020003400012A9
00030103400012A7

00010302D20226
20010302D240C8

00020003400012A9
00030103400012A7

00010302D20226
20010302D240C8

00020003400012A9
00030103400012A7

00010302D20226
20010302D240C8

00020003400012A9
00030103400012A7

00010302D20226
20010302D240C8

Each line contains one complete message in hex format. I think the last byte (last two hex characters) is the checksum of the previous data, but that is only a guess of me.

Which algorithm is used to calculate this checksum?


Solution

  • I now discovered the algorithm. Its only summing up data and building some kind of 2s complement. Here is an example:

    data: 0x20010312D14020010000210100002201000023010000
    
    binary sum: 1 1101 0001 (0x1D1)
    last byte:    1101 1110 (0xD1)
    invert:       0010 1110 (0x2E)
    add 1:        0010 1111 (0x2F)
    use only last byte of calculated CS
    
    CS: 0x2F