mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-01-26 14:36:17 -05:00
Clean up FieldReader and BitRemap types.
This commit is contained in:
parent
31fdf026f2
commit
90a7327cd5
@ -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(
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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<ManchesterDecoder, BitRemap>;
|
||||
using Reader = FieldReader<ManchesterDecoder, BitRemapNone>;
|
||||
|
||||
const ::Packet packet_;
|
||||
const rtc::RTC received_at_;
|
||||
|
@ -25,6 +25,18 @@
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
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<typename T, typename BitRemap>
|
||||
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++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user