Products
Technology
SMS solutions
Databases
Modbus
M-Bus
PBX systems
Robotics
Building robot hardware
Building electronics
Building robot software
Introduction/Protocols
Architecture
How to develop a devhandler
Line protocol
Fletcher 16 Checksum generator
CRC 16 Checksum generator
ACK and Checksum examples
DeviceHandlers
Bootloader
Robot training
Upload Arduino code
Company


Ozeki 10
Line protocol Line protocol | CRC 16 Checksum generator CRC 16 Checksum generator

Fletcher 16 Checksum generator

Value:

The task of the Fletcher 16 algorithm is to transform any long input string to 16 bit namely 4 hexadecimal number.

We use this algorithm for generating checksum in order to get proof of whether the message was delivered precisely. If the message on the serial port is X&s=abe4\n, then the Fletcher 16 algorithm is applied to the X. X is one string.

Here you can see examples for its application. The following C++ code demonstrates the operating of the algorithm:

//Fletcher 16 algorithm gives 4 hexadecimal number as follows :
void CommandParser::fletcher16(char* data)
{
  uint16_t sum1 = 0xff, sum2 = 0xff;
  size_t tlen;
  
  // s-ig levagas
  auto x = strstr_P(data, PSTR("&s="));
  // pointer aritmetika: megkaptjuk a levagott string hosszat
  auto bytes = x - data;

  while (bytes) {
    tlen = bytes >= 20 ? 20 : bytes;
    bytes -= tlen;
    do {
      sum2 += sum1 += *data++;
    } while (--tlen);
    sum1 = (sum1 & 0xff) + (sum1 >> 8);
    sum2 = (sum2 & 0xff) + (sum2 >> 8);
  }

  sum1 = (sum1 & 0xff) + (sum1 >> 8);
  sum2 = (sum2 & 0xff) + (sum2 >> 8);
  _checksum = sum2 << 8 | sum1;
}

The activation/deactivation of checksum can be reached using the ID manager 'linksetup' order. For details please review the protocol of 'linksetup'!


Copyright © 2000- - Ozeki Ltd | info@ozeki.hu
Home > Technology > Robotics > Building robot software > Introduction/Protocols > Line protocol > Fletcher 16 Checksum generator
Legal | Privacy policy | Terms of use
Page: 1613 | Login | 3.95.131.97