calculate checksum python iridium

40 Views Asked by At

I keep getting the wrong checksum, unfortunately I don't know a way of finding out which checksum iridium has calculated for my message. I want to calculate the checksum of 123 (which I need in hexadeximal which is 7b for my current function). I think maybe the checksum I'm calculating with my code is not the same iridium calculates. This is all information I have. The checksum is the least significant 2-bytes of the summation of the entire SBD message. The high order byte must be sent first. For example if the DTE were to send the word “hello” encoded in ASCII to the 9602/3 the binary stream would be hex 68 65 6c 6c 6f 02 14.

Any help is much apreciated.

This is my current code...

def calculate_checksum(string):  #function expects a given string to be in hexadecimal formatting
    total_sum = 0
    if len(string) != 0:
        byte_list = [int(string[i:i+2], 16) for i in range(0, len(string), 2)]
        total_sum = sum(byte_list)
    checksum = total_sum & 0xFFFF #sets digits w value >0xFFFF to zero (requirement)
    logging.debug('Calculated Checksum: ' + str(checksum))
    return checksum
1

There are 1 best solutions below

1
X3R0 On

try this checksum calc code got it from here in c

def calc_checksum(data):
    check_sum = 0
    for i in range(len(data)):
        check_sum += data[i] & 0xFF
    return check_sum & 0xFFFF