Changeset 18189


Ignore:
Timestamp:
06/01/15 11:53:37 (9 years ago)
Author:
tbretz
Message:
Moved Fletcher16 checksum claculation to tools.h
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/fscctrl.cc

    r18036 r18189  
    7878    }
    7979
    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 bits
    104         sum1 = (sum1 & 0xff) + (sum1 >> 8);
    105         sum2 = (sum2 & 0xff) + (sum2 >> 8);
    106 
    107         return sum2 << 8 | sum1;
    108     }
    109 
    11080    bool CheckChecksum()
    11181    {
    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);
    11484
    11585        const bool volt_ok = volt_checksum == fMsg.adc_values_checksum;
Note: See TracChangeset for help on using the changeset viewer.