File indexing completed on 2024-04-06 12:04:09
0001 #ifndef DIGIFTL_BTLSAMPLE_H
0002 #define DIGIFTL_BTLSAMPLE_H
0003
0004 #include <iostream>
0005 #include <ostream>
0006 #include <cstdint>
0007
0008
0009
0010
0011
0012
0013 class BTLSample {
0014 public:
0015 enum BTLSampleDataMasks { kToA2Mask = 0x3ff, kToAMask = 0x3ff, kDataMask = 0x3ff };
0016 enum BTLSampleDataShifts { kToA2Shift = 20, kToAShift = 10, kDataShift = 0 };
0017
0018 enum BTLSampleFlagMasks { kThreshMask = 0x1, kModeMask = 0x1 };
0019 enum BTLSampleFlagShifts { kThreshShift = 1, kModeShift = 0 };
0020
0021
0022
0023
0024 BTLSample() : value_(0), flag_(0), row_(0), col_(0) {}
0025 BTLSample(uint32_t value, uint16_t flag, uint8_t row, uint8_t col)
0026 : value_(value), flag_(flag), row_(row), col_(col) {}
0027 BTLSample(const BTLSample& o) : value_(o.value_), flag_(o.flag_), row_(o.row_), col_(o.col_) {}
0028 BTLSample& operator=(const BTLSample&) = default;
0029
0030
0031
0032
0033 void setThreshold(bool thr) { setFlagWord(thr, kThreshMask, kThreshShift); }
0034 void setMode(bool mode) { setFlagWord(mode, kModeMask, kModeShift); }
0035 void setToA(uint16_t toa) { setDataWord(toa, kToAMask, kToAShift); }
0036 void setToA2(uint16_t toa2) { setDataWord(toa2, kToA2Mask, kToA2Shift); }
0037 void setData(uint16_t data) { setDataWord(data, kDataMask, kDataShift); }
0038 void set(bool thr, bool mode, uint16_t toa2, uint16_t toa, uint16_t data, uint8_t row, uint8_t col) {
0039 flag_ = (((uint16_t)thr & kThreshMask) << kThreshShift | ((uint16_t)mode & kModeMask) << kModeShift);
0040
0041 value_ = (((uint32_t)toa2 & kToA2Mask) << kToA2Shift | ((uint32_t)toa & kToAMask) << kToAShift |
0042 ((uint32_t)data & kDataMask) << kDataShift);
0043 row_ = row;
0044 col_ = col;
0045 }
0046 void print(std::ostream& out = std::cout) {
0047 out << "THR: " << threshold() << " Mode: " << mode() << " ToA2: " << toa2() << " ToA: " << toa()
0048 << " Data: " << data() << " Row: " << (uint32_t)row() << " Column: " << (uint32_t)column() << " Raw Flag=0x"
0049 << std::hex << raw_flag() << std::dec << " Raw Data=0x" << std::hex << raw_data() << std::dec << std::endl;
0050 }
0051
0052
0053
0054
0055 uint32_t raw_data() const { return value_; }
0056 uint16_t raw_flag() const { return flag_; }
0057 bool threshold() const { return ((flag_ >> kThreshShift) & kThreshMask); }
0058 bool mode() const { return ((flag_ >> kModeShift) & kModeMask); }
0059 uint32_t toa() const { return ((value_ >> kToAShift) & kToAMask); }
0060 uint32_t toa2() const { return ((value_ >> kToA2Shift) & kToA2Mask); }
0061 uint32_t data() const { return ((value_ >> kDataShift) & kDataMask); }
0062 uint8_t row() const { return row_; }
0063 uint8_t column() const { return col_; }
0064
0065 private:
0066
0067
0068
0069 void setDataWord(uint32_t word, uint32_t mask, uint32_t pos) {
0070
0071 value_ &= ~(mask << pos);
0072
0073 value_ |= ((word & mask) << pos);
0074 }
0075 void setFlagWord(uint16_t word, uint16_t mask, uint16_t pos) {
0076
0077 flag_ &= ~(mask << pos);
0078
0079 flag_ |= ((word & mask) << pos);
0080 }
0081
0082
0083 uint32_t value_;
0084 uint16_t flag_;
0085 uint8_t row_, col_;
0086 };
0087
0088 #endif