diff --git a/firmware/application/app_ais.cpp b/firmware/application/app_ais.cpp index 6f2b3a30..5c387e5b 100644 --- a/firmware/application/app_ais.cpp +++ b/firmware/application/app_ais.cpp @@ -33,13 +33,7 @@ using namespace portapack; namespace baseband { namespace ais { -struct CRCBitRemap { - constexpr size_t operator()(const size_t& bit_index) const { - return bit_index; - } -}; - -using CRCFieldReader = ::FieldReader<::Packet, CRCBitRemap>; +using CRCFieldReader = ::FieldReader<::Packet, BitRemapNone>; struct PacketLengthRange { constexpr PacketLengthRange( diff --git a/firmware/application/app_ais.hpp b/firmware/application/app_ais.hpp index 160aec45..8cba0dac 100644 --- a/firmware/application/app_ais.hpp +++ b/firmware/application/app_ais.hpp @@ -43,14 +43,6 @@ using namespace lpc43xx; namespace baseband { namespace ais { -struct BitRemap { - constexpr size_t operator()(const size_t bit_index) const { - return bit_index ^ 7; - } -}; - -using FieldReader = ::FieldReader<::Packet, BitRemap>; - struct DateTime { uint16_t year; uint8_t month; @@ -98,9 +90,11 @@ public: bool crc_ok() const; private: + using Reader = FieldReader<::Packet, BitRemapByteReverse>; + const ::Packet packet_; const rtc::RTC received_at_; - const FieldReader field_; + const Reader field_; const size_t fcs_length = 16; diff --git a/firmware/application/app_ert.hpp b/firmware/application/app_ert.hpp index 0053dbce..bb78254f 100644 --- a/firmware/application/app_ert.hpp +++ b/firmware/application/app_ert.hpp @@ -38,12 +38,6 @@ using namespace lpc43xx; namespace ert { -struct BitRemap { - constexpr size_t operator()(const size_t bit_index) const { - return bit_index; - } -}; - using ID = uint32_t; using Consumption = uint32_t; @@ -76,7 +70,7 @@ public: bool crc_ok() const; private: - using Reader = FieldReader; + using Reader = FieldReader; const ::Packet packet_; const rtc::RTC received_at_; diff --git a/firmware/common/field_reader.hpp b/firmware/common/field_reader.hpp index 4a1e05d6..03d0a24d 100644 --- a/firmware/common/field_reader.hpp +++ b/firmware/common/field_reader.hpp @@ -25,6 +25,18 @@ #include #include +struct BitRemapNone { + constexpr size_t operator()(const size_t& bit_index) const { + return bit_index; + } +}; + +struct BitRemapByteReverse { + constexpr size_t operator()(const size_t bit_index) const { + return bit_index ^ 7; + } +}; + template class FieldReader { public: @@ -34,6 +46,9 @@ public: { } + /* The "start_bit" winds up being the MSB of the returned field value. */ + /* The BitRemap functor determines which bits are read from the source + * packet. */ uint32_t read(const size_t start_bit, const size_t length) const { uint32_t value = 0; for(size_t i=start_bit; i<(start_bit + length); i++) {