Understand checksum value

Home Forums UM7 Product Support Understand checksum value

This topic contains 1 reply, has 1 voice, and was last updated by  till 1 year, 10 months ago.

  • Author
    Posts
  • #1180

    MatteoRM

    Hi,

    i’ve an UM7 and i’m trying to implement it on my system.I’m using Binary Packet and i’ve a question about checksum.

    “The two checksum bytes consist of the unsigned 16-bit sum of all preceding bytes in the packet, including the packet header. ”

    I don’t understand it.So,i have to sum the value of pt,address and databytes(PT+ADDRESS+DATABYTES) and check if it is equal to checksum1 or checksum 0(or checksum 0 appended to checksum1?)?

    Thanks!

  • #1185

    till

    hi matteo,

    Please see UM7 Datasheet page 37:

    uint16_t computed_checksum = 's' + 'n' + 'p' + packet_data->PT + packet_data->Address;
    for( index = 0; index < data_length; index++ ) {
      packet->data[index] = rx_data[packet_index + 5 + index];
      computed_checksum += packet->data[index];
    }
    uint16_t received_checksum = (rx_data[packet_index + 5 + data_length] << 8);
    received_checksum |= rx_data[packet_index + 6 + data_length];
    

    checksum1 and checksum0 are just the two bytes making up the 16-bit short integer. you take a 16-bit integer initialized to 0 and then add the value of each byte in the packet to calculate the checksum.

    the received checksum consists of two bytes which you have to combine to a 16-bit integer.

    regards,

    -till

You must be logged in to reply to this topic.