diff --git a/firmware/application/apps/ert_app.cpp b/firmware/application/apps/ert_app.cpp index e046736b..447286ef 100644 --- a/firmware/application/apps/ert_app.cpp +++ b/firmware/application/apps/ert_app.cpp @@ -41,6 +41,7 @@ std::string type(Packet::Type value) { case Packet::Type::Unknown: return "???"; case Packet::Type::IDM: return "IDM"; case Packet::Type::SCM: return "SCM"; + case Packet::Type::SCMPLUS: return "SCM+"; } } @@ -62,7 +63,8 @@ std::string commodity_type(CommodityType value) { void ERTLogger::on_packet(const ert::Packet& packet) { const auto formatted = packet.symbols_formatted(); - log_file.write_entry(packet.received_at(), formatted.data + "/" + formatted.errors); + std::string entry = ert::format::type(packet.type()) + " " + formatted.data + "/" + formatted.errors; + log_file.write_entry(packet.received_at(), entry); } const ERTRecentEntry::Key ERTRecentEntry::invalid_key { }; diff --git a/firmware/baseband/proc_ert.cpp b/firmware/baseband/proc_ert.cpp index 9997704b..2bc8b858 100644 --- a/firmware/baseband/proc_ert.cpp +++ b/firmware/baseband/proc_ert.cpp @@ -87,6 +87,7 @@ void ERTProcessor::consume_symbol( ) { const uint_fast8_t sliced_symbol = (raw_symbol >= 0.0f) ? 1 : 0; scm_builder.execute(sliced_symbol); + scmplus_builder.execute(sliced_symbol); idm_builder.execute(sliced_symbol); } @@ -97,6 +98,13 @@ void ERTProcessor::scm_handler( shared_memory.application_queue.push(message); } +void ERTProcessor::scmplus_handler( + const baseband::Packet& packet +) { + const ERTPacketMessage message { ert::Packet::Type::SCMPLUS, packet }; + shared_memory.application_queue.push(message); +} + void ERTProcessor::idm_handler( const baseband::Packet& packet ) { diff --git a/firmware/baseband/proc_ert.hpp b/firmware/baseband/proc_ert.hpp index 71122606..f830305f 100644 --- a/firmware/baseband/proc_ert.hpp +++ b/firmware/baseband/proc_ert.hpp @@ -44,10 +44,14 @@ constexpr uint64_t scm_preamble_and_sync_manchester { 0b101010101001011001100110 constexpr size_t scm_preamble_and_sync_length { 42 - 10 }; constexpr size_t scm_payload_length_max { 150 }; +// ''.join(['%d%d' % (c, 1-c) for c in map(int, bin(0x16a3)[2:].zfill(16))]) +constexpr uint64_t scmplus_preamble_and_sync_manchester { 0b01010110011010011001100101011010 }; +constexpr size_t scmplus_preamble_and_sync_length { 32 - 0 }; +constexpr size_t scmplus_payload_length_max { 224 }; + // ''.join(['%d%d' % (c, 1-c) for c in map(int, bin(0x555516a3)[2:].zfill(32))]) constexpr uint64_t idm_preamble_and_sync_manchester { 0b0110011001100110011001100110011001010110011010011001100101011010 }; constexpr size_t idm_preamble_and_sync_length { 64 - 16 }; - constexpr size_t idm_payload_length_max { 1408 }; class ERTProcessor : public BasebandProcessor { @@ -80,6 +84,15 @@ private: } }; + PacketBuilder scmplus_builder { + { scmplus_preamble_and_sync_manchester, scmplus_preamble_and_sync_length, 1 }, + { }, + { scmplus_payload_length_max }, + [this](const baseband::Packet& packet) { + this->scmplus_handler(packet); + } + }; + PacketBuilder idm_builder { { idm_preamble_and_sync_manchester, idm_preamble_and_sync_length, 1 }, { }, @@ -91,6 +104,7 @@ private: void consume_symbol(const float symbol); void scm_handler(const baseband::Packet& packet); + void scmplus_handler(const baseband::Packet& packet); void idm_handler(const baseband::Packet& packet); float sum_half_period[2]; diff --git a/firmware/common/ert_packet.cpp b/firmware/common/ert_packet.cpp index ff9e7d10..5286d751 100644 --- a/firmware/common/ert_packet.cpp +++ b/firmware/common/ert_packet.cpp @@ -47,6 +47,9 @@ ID Packet::id() const { const auto lsb = reader_.read(35, 24); return (msb << 24) | lsb; } + if( type() == Type::SCMPLUS ) { + return reader_.read(2 * 8, 32); + } if( type() == Type::IDM ) { return reader_.read(5 * 8, 32); } @@ -57,6 +60,9 @@ Consumption Packet::consumption() const { if( type() == Type::SCM ) { return reader_.read(11, 24); } + if( type() == Type::SCMPLUS ) { + return reader_.read(6 * 8, 32); + } if( type() == Type::IDM ) { return reader_.read(25 * 8, 32); } @@ -67,6 +73,9 @@ CommodityType Packet::commodity_type() const { if( type() == Type::SCM ) { return reader_.read(5, 4); } + if( type() == Type::SCMPLUS ) { + return reader_.read(1 * 8 + 4, 4); + } if( type() == Type::IDM ) { return reader_.read(4 * 8 + 4, 4); } @@ -80,7 +89,8 @@ FormattedSymbols Packet::symbols_formatted() const { bool Packet::crc_ok() const { switch(type()) { case Type::SCM: return crc_ok_scm(); - case Type::IDM: return crc_ok_idm(); + case Type::SCMPLUS: + case Type::IDM: return crc_ok_ccitt(); default: return false; } } @@ -95,7 +105,7 @@ bool Packet::crc_ok_scm() const { return ert_bch.checksum() == 0x0000; } -bool Packet::crc_ok_idm() const { +bool Packet::crc_ok_ccitt() const { CRC<16> ert_crc_ccitt { 0x1021, 0xffff, 0x1d0f }; for(size_t i=0; i