mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Clean up ERT packet type notation.
Still not great, but at least repeated code is reduced.
This commit is contained in:
parent
9e004d4754
commit
b9643dc988
@ -45,27 +45,27 @@ rtc::RTC Packet::received_at() const {
|
||||
return received_at_;
|
||||
}
|
||||
|
||||
Packet::Type Packet::type() const {
|
||||
ERTPacket::Type Packet::type() const {
|
||||
return type_;
|
||||
}
|
||||
|
||||
ID Packet::id() const {
|
||||
if( type() == Packet::Type::SCM ) {
|
||||
if( type() == ERTPacket::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 ) {
|
||||
if( type() == ERTPacket::Type::IDM ) {
|
||||
return reader_.read(5 * 8, 32);
|
||||
}
|
||||
return invalid_id;
|
||||
}
|
||||
|
||||
Consumption Packet::consumption() const {
|
||||
if( type() == Packet::Type::SCM ) {
|
||||
if( type() == ERTPacket::Type::SCM ) {
|
||||
return reader_.read(11, 24);
|
||||
}
|
||||
if( type() == Packet::Type::IDM ) {
|
||||
if( type() == ERTPacket::Type::IDM ) {
|
||||
return reader_.read(25 * 8, 32);
|
||||
}
|
||||
return invalid_consumption;
|
||||
@ -99,14 +99,7 @@ void ERTView::on_show() {
|
||||
const auto message = static_cast<const ERTPacketMessage*>(p);
|
||||
rtc::RTC datetime;
|
||||
rtcGetTime(&RTCD1, &datetime);
|
||||
ert::Packet::Type packet_type = ert::Packet::Type::Unknown;
|
||||
if( message->packet.preamble == 0x1f2a60 ) {
|
||||
packet_type = ert::Packet::Type::SCM;
|
||||
} else if( message->packet.preamble == 0x555516a3 ) {
|
||||
packet_type = ert::Packet::Type::IDM;
|
||||
}
|
||||
|
||||
const ert::Packet packet { datetime, packet_type, message->packet.payload, message->packet.bits_received };
|
||||
const ert::Packet packet { datetime, message->packet.type, message->packet.payload, message->packet.bits_received };
|
||||
if( this->model.on_packet(packet) ) {
|
||||
this->on_packet(packet);
|
||||
}
|
||||
@ -124,14 +117,14 @@ void ERTView::on_hide() {
|
||||
void ERTView::on_packet(const ert::Packet& packet) {
|
||||
std::string msg;
|
||||
switch(packet.type()) {
|
||||
case ert::Packet::Type::SCM:
|
||||
case ERTPacket::Type::SCM:
|
||||
msg += "SCM ";
|
||||
msg += to_string_dec_uint(packet.id(), 10);
|
||||
msg += " ";
|
||||
msg += to_string_dec_uint(packet.consumption(), 10);
|
||||
break;
|
||||
|
||||
case ert::Packet::Type::IDM:
|
||||
case ERTPacket::Type::IDM:
|
||||
msg += "IDM ";
|
||||
msg += to_string_dec_uint(packet.id(), 10);
|
||||
msg += " ";
|
||||
|
@ -48,15 +48,9 @@ using Consumption = uint32_t;
|
||||
|
||||
class Packet {
|
||||
public:
|
||||
enum Type {
|
||||
Unknown = 0,
|
||||
IDM = 1,
|
||||
SCM = 2,
|
||||
};
|
||||
|
||||
Packet(
|
||||
const rtc::RTC& received_at,
|
||||
const Type type,
|
||||
const ERTPacket::Type type,
|
||||
const std::bitset<1024>& payload,
|
||||
const size_t payload_length
|
||||
) : payload_ { payload },
|
||||
@ -74,7 +68,7 @@ public:
|
||||
|
||||
rtc::RTC received_at() const;
|
||||
|
||||
Type type() const;
|
||||
ERTPacket::Type type() const;
|
||||
ID id() const;
|
||||
Consumption consumption() const;
|
||||
|
||||
@ -86,7 +80,7 @@ private:
|
||||
const rtc::RTC received_at_;
|
||||
const ManchesterDecoder decoder_;
|
||||
const Reader reader_;
|
||||
const Type type_;
|
||||
const ERTPacket::Type type_;
|
||||
|
||||
const ID invalid_id = 0;
|
||||
const Consumption invalid_consumption = 0;
|
||||
|
@ -99,7 +99,7 @@ void ERTProcessor::scm_handler(
|
||||
const size_t bits_received
|
||||
) {
|
||||
ERTPacketMessage message;
|
||||
message.packet.preamble = 0x1f2a60;
|
||||
message.packet.type = ERTPacket::Type::SCM;
|
||||
message.packet.payload = payload;
|
||||
message.packet.bits_received = bits_received;
|
||||
shared_memory.application_queue.push(message);
|
||||
@ -110,7 +110,7 @@ void ERTProcessor::idm_handler(
|
||||
const size_t bits_received
|
||||
) {
|
||||
ERTPacketMessage message;
|
||||
message.packet.preamble = 0x555516a3;
|
||||
message.packet.type = ERTPacket::Type::IDM;
|
||||
message.packet.payload = payload;
|
||||
message.packet.bits_received = bits_received;
|
||||
shared_memory.application_queue.push(message);
|
||||
|
@ -242,7 +242,13 @@ public:
|
||||
};
|
||||
|
||||
struct ERTPacket {
|
||||
uint64_t preamble { 0 };
|
||||
enum class Type : uint32_t {
|
||||
Unknown = 0,
|
||||
IDM = 1,
|
||||
SCM = 2,
|
||||
};
|
||||
|
||||
Type type { Type::Unknown };
|
||||
std::bitset<1024> payload;
|
||||
size_t bits_received { 0 };
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user