Changeset 18189
- Timestamp:
- 06/01/15 11:53:37 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/FACT++/src/fscctrl.cc
r18036 r18189 78 78 } 79 79 80 template<typename T>81 uint16_t fletcher16(const T *t, size_t cnt)82 {83 const uint8_t *data = reinterpret_cast<const uint8_t*>(t);84 85 size_t bytes = cnt*sizeof(T);86 87 uint16_t sum1 = 0xff;88 uint16_t sum2 = 0xff;89 90 while (bytes)91 {92 size_t tlen = bytes > 20 ? 20 : bytes;93 bytes -= tlen;94 95 do {96 sum2 += sum1 += *data++;97 } while (--tlen);98 99 sum1 = (sum1 & 0xff) + (sum1 >> 8);100 sum2 = (sum2 & 0xff) + (sum2 >> 8);101 }102 103 // Second reduction step to reduce sums to 8 bits104 sum1 = (sum1 & 0xff) + (sum1 >> 8);105 sum2 = (sum2 & 0xff) + (sum2 >> 8);106 107 return sum2 << 8 | sum1;108 }109 110 80 bool CheckChecksum() 111 81 { 112 const uint16_t volt_checksum = fletcher16(fMsg.adc_values, kNumVoltageChannels);113 const uint16_t resi_checksum = fletcher16(fMsg.ad7719_values, kNumResistanceChannels);82 const uint16_t volt_checksum = Tools::Fletcher16(fMsg.adc_values, kNumVoltageChannels); 83 const uint16_t resi_checksum = Tools::Fletcher16(fMsg.ad7719_values, kNumResistanceChannels); 114 84 115 85 const bool volt_ok = volt_checksum == fMsg.adc_values_checksum;
Note:
See TracChangeset
for help on using the changeset viewer.