diff --git a/firmware/application/app_ais.cpp b/firmware/application/app_ais.cpp index b3960879..ca2545e7 100644 --- a/firmware/application/app_ais.cpp +++ b/firmware/application/app_ais.cpp @@ -33,7 +33,7 @@ using namespace portapack; namespace baseband { namespace ais { -using CRCFieldReader = ::FieldReader<::Packet, BitRemapNone>; +using CRCFieldReader = ::FieldReader; struct PacketLengthRange { constexpr PacketLengthRange( @@ -320,7 +320,7 @@ void AISView::on_show() { const auto message = static_cast(p); rtc::RTC datetime; rtcGetTime(&RTCD1, &datetime); - const baseband::ais::Packet packet { datetime, message->packet.packet }; + const baseband::ais::Packet packet { datetime, message->packet }; if( this->model.on_packet(packet) ) { this->on_packet(packet); } diff --git a/firmware/application/app_ais.hpp b/firmware/application/app_ais.hpp index 8cba0dac..3f2cad3f 100644 --- a/firmware/application/app_ais.hpp +++ b/firmware/application/app_ais.hpp @@ -26,7 +26,7 @@ #include "message.hpp" #include "log_file.hpp" #include "field_reader.hpp" -#include "packet.hpp" +#include "baseband_packet.hpp" #include "lpc43xx_cpp.hpp" using namespace lpc43xx; @@ -61,7 +61,7 @@ class Packet { public: constexpr Packet( const rtc::RTC& received_at, - const ::Packet& packet + const baseband::Packet& packet ) : packet_ { packet }, received_at_ { received_at }, field_ { packet_ } @@ -90,9 +90,9 @@ public: bool crc_ok() const; private: - using Reader = FieldReader<::Packet, BitRemapByteReverse>; + using Reader = FieldReader; - const ::Packet packet_; + const baseband::Packet packet_; const rtc::RTC received_at_; const Reader field_; diff --git a/firmware/application/app_ert.cpp b/firmware/application/app_ert.cpp index 970e8588..28c17b54 100644 --- a/firmware/application/app_ert.cpp +++ b/firmware/application/app_ert.cpp @@ -46,27 +46,27 @@ rtc::RTC Packet::received_at() const { return received_at_; } -ERTPacket::Type Packet::type() const { +ERTPacketMessage::Type Packet::type() const { return type_; } ID Packet::id() const { - if( type() == ERTPacket::Type::SCM ) { + if( type() == ERTPacketMessage::Type::SCM ) { const auto msb = reader_.read(0, 2); const auto lsb = reader_.read(35, 24); return (msb << 24) | lsb; } - if( type() == ERTPacket::Type::IDM ) { + if( type() == ERTPacketMessage::Type::IDM ) { return reader_.read(5 * 8, 32); } return invalid_id; } Consumption Packet::consumption() const { - if( type() == ERTPacket::Type::SCM ) { + if( type() == ERTPacketMessage::Type::SCM ) { return reader_.read(11, 24); } - if( type() == ERTPacket::Type::IDM ) { + if( type() == ERTPacketMessage::Type::IDM ) { return reader_.read(25 * 8, 32); } return invalid_consumption; @@ -78,8 +78,8 @@ ManchesterFormatted Packet::symbols_formatted() const { bool Packet::crc_ok() const { switch(type()) { - case ERTPacket::Type::SCM: return crc_ok_scm(); - case ERTPacket::Type::IDM: return crc_ok_idm(); + case ERTPacketMessage::Type::SCM: return crc_ok_scm(); + case ERTPacketMessage::Type::IDM: return crc_ok_idm(); default: return false; } } @@ -135,7 +135,7 @@ void ERTView::on_show() { const auto message = static_cast(p); rtc::RTC datetime; rtcGetTime(&RTCD1, &datetime); - const ert::Packet packet { datetime, message->packet.type, message->packet.packet }; + const ert::Packet packet { datetime, message->type, message->packet }; if( this->model.on_packet(packet) ) { this->on_packet(packet); } @@ -153,14 +153,14 @@ void ERTView::on_hide() { void ERTView::on_packet(const ert::Packet& packet) { std::string msg; switch(packet.type()) { - case ERTPacket::Type::SCM: + case ERTPacketMessage::Type::SCM: msg += "SCM "; msg += to_string_dec_uint(packet.id(), 10); msg += " "; msg += to_string_dec_uint(packet.consumption(), 10); break; - case ERTPacket::Type::IDM: + case ERTPacketMessage::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 bb78254f..e35c7d3a 100644 --- a/firmware/application/app_ert.hpp +++ b/firmware/application/app_ert.hpp @@ -27,7 +27,7 @@ #include "log_file.hpp" #include "manchester.hpp" #include "field_reader.hpp" -#include "packet.hpp" +#include "baseband_packet.hpp" #include "lpc43xx_cpp.hpp" using namespace lpc43xx; @@ -45,8 +45,8 @@ class Packet { public: Packet( const rtc::RTC& received_at, - const ERTPacket::Type type, - const ::Packet& packet + const ERTPacketMessage::Type type, + const baseband::Packet& packet ) : packet_ { packet }, received_at_ { received_at }, decoder_ { packet_ }, @@ -61,7 +61,7 @@ public: rtc::RTC received_at() const; - ERTPacket::Type type() const; + ERTPacketMessage::Type type() const; ID id() const; Consumption consumption() const; @@ -72,11 +72,11 @@ public: private: using Reader = FieldReader; - const ::Packet packet_; + const baseband::Packet packet_; const rtc::RTC received_at_; const ManchesterDecoder decoder_; const Reader reader_; - const ERTPacket::Type type_; + const ERTPacketMessage::Type type_; const ID invalid_id = 0; const Consumption invalid_consumption = 0; diff --git a/firmware/application/app_tpms.cpp b/firmware/application/app_tpms.cpp index b88b6fa4..25d1cacf 100644 --- a/firmware/application/app_tpms.cpp +++ b/firmware/application/app_tpms.cpp @@ -44,7 +44,7 @@ ManchesterFormatted TPMSModel::on_packet(const TPMSPacketMessage& message) { rtc::RTC received_at; rtcGetTime(&RTCD1, &received_at); - const ManchesterDecoder decoder(message.packet.packet, 1); + const ManchesterDecoder decoder(message.packet, 1); const auto hex_formatted = format_manchester(decoder); if( log_file.is_ready() ) { diff --git a/firmware/application/manchester.hpp b/firmware/application/manchester.hpp index 77262c46..50cae73f 100644 --- a/firmware/application/manchester.hpp +++ b/firmware/application/manchester.hpp @@ -27,7 +27,7 @@ #include #include -#include "packet.hpp" +#include "baseband_packet.hpp" class ManchesterDecoder { public: @@ -37,7 +37,7 @@ public: }; constexpr ManchesterDecoder( - const ::Packet& packet, + const baseband::Packet& packet, const size_t sense = 0 ) : packet { packet }, sense { sense } @@ -49,7 +49,7 @@ public: size_t symbols_count() const; private: - const ::Packet& packet; + const baseband::Packet& packet; const size_t sense; }; diff --git a/firmware/baseband/packet_builder.hpp b/firmware/baseband/packet_builder.hpp index 66892f63..168f242e 100644 --- a/firmware/baseband/packet_builder.hpp +++ b/firmware/baseband/packet_builder.hpp @@ -28,7 +28,7 @@ #include #include "bit_pattern.hpp" -#include "packet.hpp" +#include "baseband_packet.hpp" struct NeverMatch { bool operator()(const BitHistory&, const size_t) const { @@ -47,7 +47,7 @@ struct FixedLength { template class PacketBuilder { public: - using PayloadHandlerFunc = std::function; + using PayloadHandlerFunc = std::function; PacketBuilder( const PreambleMatcher preamble_matcher, @@ -122,7 +122,7 @@ private: EndMatcher end; State state { State::Preamble }; - ::Packet packet; + baseband::Packet packet; void reset_state() { packet.clear(); diff --git a/firmware/baseband/proc_ais.cpp b/firmware/baseband/proc_ais.cpp index c0ba0efb..b411dc3d 100644 --- a/firmware/baseband/proc_ais.cpp +++ b/firmware/baseband/proc_ais.cpp @@ -60,9 +60,9 @@ void AISProcessor::consume_symbol( } void AISProcessor::payload_handler( - const ::Packet& packet + const baseband::Packet& packet ) { AISPacketMessage message; - message.packet.packet = packet; + message.packet = packet; shared_memory.application_queue.push(message); } diff --git a/firmware/baseband/proc_ais.hpp b/firmware/baseband/proc_ais.hpp index c8a407e0..94de70e0 100644 --- a/firmware/baseband/proc_ais.hpp +++ b/firmware/baseband/proc_ais.hpp @@ -30,7 +30,7 @@ #include "clock_recovery.hpp" #include "symbol_coding.hpp" #include "packet_builder.hpp" -#include "packet.hpp" +#include "baseband_packet.hpp" #include "message.hpp" @@ -57,13 +57,13 @@ private: { 0b0101010101111110, 16, 1 }, { 0b111110, 6 }, { 0b01111110, 8 }, - [this](const ::Packet& packet) { + [this](const baseband::Packet& packet) { this->payload_handler(packet); } }; void consume_symbol(const float symbol); - void payload_handler(const ::Packet& packet); + void payload_handler(const baseband::Packet& packet); }; #endif/*__PROC_AIS_H__*/ diff --git a/firmware/baseband/proc_ert.cpp b/firmware/baseband/proc_ert.cpp index f3d68386..36f3d55c 100644 --- a/firmware/baseband/proc_ert.cpp +++ b/firmware/baseband/proc_ert.cpp @@ -95,19 +95,19 @@ void ERTProcessor::consume_symbol( } void ERTProcessor::scm_handler( - const ::Packet& packet + const baseband::Packet& packet ) { ERTPacketMessage message; - message.packet.type = ERTPacket::Type::SCM; - message.packet.packet = packet; + message.type = ERTPacketMessage::Type::SCM; + message.packet = packet; shared_memory.application_queue.push(message); } void ERTProcessor::idm_handler( - const ::Packet& packet + const baseband::Packet& packet ) { ERTPacketMessage message; - message.packet.type = ERTPacket::Type::IDM; - message.packet.packet = packet; + message.type = ERTPacketMessage::Type::IDM; + message.packet = packet; shared_memory.application_queue.push(message); } diff --git a/firmware/baseband/proc_ert.hpp b/firmware/baseband/proc_ert.hpp index e5b2654e..9663a1f3 100644 --- a/firmware/baseband/proc_ert.hpp +++ b/firmware/baseband/proc_ert.hpp @@ -29,7 +29,7 @@ #include "clock_recovery.hpp" #include "symbol_coding.hpp" #include "packet_builder.hpp" -#include "packet.hpp" +#include "baseband_packet.hpp" #include "message.hpp" @@ -72,7 +72,7 @@ private: { scm_preamble_and_sync_manchester, scm_preamble_and_sync_length, 1 }, { }, { scm_payload_length_max }, - [this](const ::Packet& packet) { + [this](const baseband::Packet& packet) { this->scm_handler(packet); } }; @@ -81,14 +81,14 @@ private: { idm_preamble_and_sync_manchester, idm_preamble_and_sync_length, 1 }, { }, { idm_payload_length_max }, - [this](const ::Packet& packet) { + [this](const baseband::Packet& packet) { this->idm_handler(packet); } }; void consume_symbol(const float symbol); - void scm_handler(const ::Packet& packet); - void idm_handler(const ::Packet& packet); + void scm_handler(const baseband::Packet& packet); + void idm_handler(const baseband::Packet& packet); float sum_half_period[2]; float sum_period[3]; diff --git a/firmware/baseband/proc_tpms.cpp b/firmware/baseband/proc_tpms.cpp index a6f18c73..17eebafb 100644 --- a/firmware/baseband/proc_tpms.cpp +++ b/firmware/baseband/proc_tpms.cpp @@ -58,9 +58,9 @@ void TPMSProcessor::consume_symbol( } void TPMSProcessor::payload_handler( - const ::Packet& packet + const baseband::Packet& packet ) { TPMSPacketMessage message; - message.packet.packet = packet; + message.packet = packet; shared_memory.application_queue.push(message); } diff --git a/firmware/baseband/proc_tpms.hpp b/firmware/baseband/proc_tpms.hpp index 1e531186..fd7e1d20 100644 --- a/firmware/baseband/proc_tpms.hpp +++ b/firmware/baseband/proc_tpms.hpp @@ -30,7 +30,7 @@ #include "clock_recovery.hpp" #include "symbol_coding.hpp" #include "packet_builder.hpp" -#include "packet.hpp" +#include "baseband_packet.hpp" #include "message.hpp" @@ -64,13 +64,13 @@ private: { 0b010101010101010101010101010110, 30, 1 }, { }, { 256 }, - [this](const ::Packet& packet) { + [this](const baseband::Packet& packet) { this->payload_handler(packet); } }; void consume_symbol(const float symbol); - void payload_handler(const ::Packet& packet); + void payload_handler(const baseband::Packet& packet); }; #endif/*__PROC_TPMS_H__*/ diff --git a/firmware/common/packet.hpp b/firmware/common/baseband_packet.hpp similarity index 89% rename from firmware/common/packet.hpp rename to firmware/common/baseband_packet.hpp index 816a4727..4285828c 100644 --- a/firmware/common/packet.hpp +++ b/firmware/common/baseband_packet.hpp @@ -19,12 +19,14 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PACKET_H__ -#define __PACKET_H__ +#ifndef __BASEBAND_PACKET_H__ +#define __BASEBAND_PACKET_H__ #include #include +namespace baseband { + class Packet { public: void add(const bool symbol) { @@ -54,4 +56,6 @@ private: size_t count { 0 }; }; -#endif/*__PACKET_H__*/ +} /* namespace baseband */ + +#endif/*__BASEBAND_PACKET_H__*/ diff --git a/firmware/common/message.hpp b/firmware/common/message.hpp index b88f8aca..fd232bef 100644 --- a/firmware/common/message.hpp +++ b/firmware/common/message.hpp @@ -27,7 +27,7 @@ #include #include -#include "packet.hpp" +#include "baseband_packet.hpp" #include "utility.hpp" @@ -203,10 +203,6 @@ public: ChannelSpectrum spectrum; }; -struct AISPacket { - ::Packet packet; -}; - class AISPacketMessage : public Message { public: constexpr AISPacketMessage( @@ -214,11 +210,7 @@ public: { } - AISPacket packet; -}; - -struct TPMSPacket { - ::Packet packet; + baseband::Packet packet; }; class TPMSPacketMessage : public Message { @@ -228,7 +220,7 @@ public: { } - TPMSPacket packet; + baseband::Packet packet; }; class ShutdownMessage : public Message { @@ -239,17 +231,6 @@ public: } }; -struct ERTPacket { - enum class Type : uint32_t { - Unknown = 0, - IDM = 1, - SCM = 2, - }; - - Type type { Type::Unknown }; - ::Packet packet; -}; - class ERTPacketMessage : public Message { public: constexpr ERTPacketMessage( @@ -257,7 +238,15 @@ public: { } - ERTPacket packet; + enum class Type : uint32_t { + Unknown = 0, + IDM = 1, + SCM = 2, + }; + + Type type { Type::Unknown }; + + baseband::Packet packet; }; class MessageHandlerMap {