FACT++  1.0
template<typename T >
uint16_t Tools::Fletcher16 ( const T *  t,
size_t  cnt 
)

Definition at line 22 of file tools.h.

References data, and t.

Referenced by ConnectionFSC::CheckChecksum(), and ConnectionPFmini::HandleReceivedData().

23  {
24  const uint8_t *data = reinterpret_cast<const uint8_t*>(t);
25 
26  size_t bytes = cnt*sizeof(T);
27 
28  uint16_t sum1 = 0xff;
29  uint16_t sum2 = 0xff;
30 
31  while (bytes)
32  {
33  size_t tlen = bytes > 20 ? 20 : bytes;
34  bytes -= tlen;
35 
36  do {
37  sum2 += sum1 += *data++;
38  } while (--tlen);
39 
40  sum1 = (sum1 & 0xff) + (sum1 >> 8);
41  sum2 = (sum2 & 0xff) + (sum2 >> 8);
42  }
43 
44  // Second reduction step to reduce sums to 8 bits
45  sum1 = (sum1 & 0xff) + (sum1 >> 8);
46  sum2 = (sum2 & 0xff) + (sum2 >> 8);
47 
48  return sum2 << 8 | sum1;
49  }
float data[4 *1440]
TT t
Definition: test_client.c:26

+ Here is the caller graph for this function: