mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2024-12-14 12:08:40 +00:00
ert::Packet parser.
This commit is contained in:
parent
5cfd44a546
commit
51026609ce
@ -29,6 +29,48 @@ using namespace portapack;
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
using namespace lpc43xx;
|
||||
|
||||
namespace ert {
|
||||
|
||||
size_t Packet::length() const {
|
||||
return payload_length_;
|
||||
}
|
||||
|
||||
bool Packet::is_valid() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
rtc::RTC Packet::received_at() const {
|
||||
return received_at_;
|
||||
}
|
||||
|
||||
Packet::Type Packet::type() const {
|
||||
return type_;
|
||||
}
|
||||
|
||||
ID Packet::id() const {
|
||||
if( type() == Packet::Type::SCM ) {
|
||||
const auto msb = reader_.read(0, 2);
|
||||
const auto lsb = reader_.read(35, 24);
|
||||
return (msb << 24) | lsb;
|
||||
}
|
||||
if( type() == Packet::Type::IDM ) {
|
||||
return reader_.read(5 * 8, 32);
|
||||
}
|
||||
return invalid_id;
|
||||
}
|
||||
|
||||
Consumption Packet::consumption() const {
|
||||
if( type() == Packet::Type::SCM ) {
|
||||
return reader_.read(11, 24);
|
||||
}
|
||||
if( type() == Packet::Type::IDM ) {
|
||||
return reader_.read(25 * 8, 32);
|
||||
}
|
||||
return invalid_consumption;
|
||||
}
|
||||
|
||||
} /* namespace ert */
|
||||
|
||||
ERTModel::ERTModel() {
|
||||
receiver_model.set_baseband_configuration({
|
||||
.mode = 6,
|
||||
|
@ -25,8 +25,79 @@
|
||||
#include "ui_console.hpp"
|
||||
#include "message.hpp"
|
||||
#include "log_file.hpp"
|
||||
#include "manchester.hpp"
|
||||
#include "field_reader.hpp"
|
||||
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
using namespace lpc43xx;
|
||||
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
#include <bitset>
|
||||
|
||||
namespace ert {
|
||||
|
||||
struct BitRemap {
|
||||
size_t operator()(const size_t bit_index) const {
|
||||
return bit_index;
|
||||
}
|
||||
};
|
||||
|
||||
using ID = uint32_t;
|
||||
using Consumption = uint32_t;
|
||||
|
||||
class Packet {
|
||||
public:
|
||||
enum Type {
|
||||
Unknown = 0,
|
||||
IDM = 1,
|
||||
SCM = 2,
|
||||
};
|
||||
|
||||
Packet(
|
||||
const rtc::RTC& received_at,
|
||||
const uint64_t preamble,
|
||||
const std::bitset<1024>& payload,
|
||||
const size_t payload_length
|
||||
) : payload_ { payload },
|
||||
payload_length_ { payload_length },
|
||||
received_at_ { received_at },
|
||||
decoder_ { payload_, payload_length_ },
|
||||
reader_ { decoder_ },
|
||||
type_ { Type::Unknown }
|
||||
{
|
||||
if( preamble == 0x1f2a60 ) {
|
||||
type_ = Type::SCM;
|
||||
} else if( preamble == 0x555516a3 ) {
|
||||
type_ = Type::IDM;
|
||||
}
|
||||
}
|
||||
|
||||
size_t length() const;
|
||||
|
||||
bool is_valid() const;
|
||||
|
||||
rtc::RTC received_at() const;
|
||||
|
||||
Type type() const;
|
||||
ID id() const;
|
||||
Consumption consumption() const;
|
||||
|
||||
private:
|
||||
using Reader = FieldReader<ManchesterDecoder, BitRemap>;
|
||||
|
||||
const std::bitset<1024> payload_;
|
||||
const size_t payload_length_;
|
||||
const rtc::RTC received_at_;
|
||||
const ManchesterDecoder decoder_;
|
||||
const Reader reader_;
|
||||
Type type_;
|
||||
|
||||
const ID invalid_id = 0;
|
||||
const Consumption invalid_consumption = 0;
|
||||
};
|
||||
|
||||
} /* namespace ert */
|
||||
|
||||
class ERTModel {
|
||||
public:
|
||||
|
Loading…
Reference in New Issue
Block a user