From b9643dc9884bdc339dcd3056c49d1e3d6d81e186 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 6 Dec 2015 15:47:04 -0800 Subject: [PATCH] Clean up ERT packet type notation. Still not great, but at least repeated code is reduced. --- firmware/application/app_ert.cpp | 23 ++++++++--------------- firmware/application/app_ert.hpp | 12 +++--------- firmware/baseband/proc_ert.cpp | 4 ++-- firmware/common/message.hpp | 8 +++++++- 4 files changed, 20 insertions(+), 27 deletions(-) diff --git a/firmware/application/app_ert.cpp b/firmware/application/app_ert.cpp index 39e2632c..3a0c75a6 100644 --- a/firmware/application/app_ert.cpp +++ b/firmware/application/app_ert.cpp @@ -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(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 += " "; diff --git a/firmware/application/app_ert.hpp b/firmware/application/app_ert.hpp index 4230483e..53b0e533 100644 --- a/firmware/application/app_ert.hpp +++ b/firmware/application/app_ert.hpp @@ -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; diff --git a/firmware/baseband/proc_ert.cpp b/firmware/baseband/proc_ert.cpp index f27396c2..97fd6307 100644 --- a/firmware/baseband/proc_ert.cpp +++ b/firmware/baseband/proc_ert.cpp @@ -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); diff --git a/firmware/common/message.hpp b/firmware/common/message.hpp index d5c0101b..995d0730 100644 --- a/firmware/common/message.hpp +++ b/firmware/common/message.hpp @@ -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 }; };