neato lidar checksum calculator

i'm working on developing some software for the neato lidar. i was wondering if anyone has the checksum generator code in C?

i have found the code in python and C sharp but i don't know either one of those languages.

The algorithm should be clear, regardless of the language.
Post the code you have, using code tags “</>” button.

    def checksum(data):
        # group the data by word, little endian
        data_list = []
        for t in range(10):
            data_list.append( data[2*t] + (data[2*t+1] << 8) )
        # compute the checksum.
        chk32 = 0
        for data in data_list:
            chk32 = (chk32 << 1) + data

        # return a value wrapped around on 15bits, and truncated to still fit into 15 bits
        checksum = (chk32 & 0x7FFF) + ( chk32 >> 15 ) # wrap around to fit into 15 bits
        checksum = checksum & 0x7FFF # truncate to 15 bits
        return int( checksum )

redid python code

    def checksum(data):
        # group the data by word, little endian
        data_list = []
        for t in range(10):
            data_list.append( data[2*t] + (data[2*t+1] << 8) )
        # compute the checksum.
        chk32 = 0
        for data in data_list:
            chk32 = (chk32 << 1) + data

        # return a value wrapped around on 15bits, and truncated to still fit into 15 bits
        checksum = (chk32 & 0x7FFF) + ( chk32 >> 15 ) # wrap around to fit into 15 bits
        checksum = checksum & 0x7FFF # truncate to 15 bits
        return int( checksum )

in C++ it would be something like

int checksum(byte* data)
{
  int dataList[10];
  for (int i=0; i<10; i++)
  {
    dataList[i] = data[2*i] + (data[2*i+1] << 8);
  }
  uint32_t chk32 = 0;
  for (int i=0; i<10; i++)
  {
    chk32 = (chk32 << 1) + data[i];
  }
  uint32_t checksum = (chk32 & 0x7FFF) + (chk32 >> 15);
  return int(checksum & 0x7FFFF);
}

Please give it a try

thanks, i will give it a try and let you know if it works.

int dataList[10];If Rob's suggestion doesn't work properly, try unsigned int here.