From 697876d86a2f1cbf61c88fabcfe907607c54c704 Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Sun, 23 Apr 2023 01:26:37 -0500 Subject: [PATCH 1/7] Support for ERT SCM+ meter protocol --- firmware/application/apps/ert_app.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/firmware/application/apps/ert_app.cpp b/firmware/application/apps/ert_app.cpp index e046736b..894caca8 100644 --- a/firmware/application/apps/ert_app.cpp +++ b/firmware/application/apps/ert_app.cpp @@ -38,9 +38,10 @@ namespace format { std::string type(Packet::Type value) { switch(value) { default: - case Packet::Type::Unknown: return "???"; - case Packet::Type::IDM: return "IDM"; - case Packet::Type::SCM: return "SCM"; + case Packet::Type::Unknown: return "??? "; + case Packet::Type::IDM: return "IDM "; + case Packet::Type::SCM: return "SCM "; + case Packet::Type::SCMPLUS: return "SCM+"; } } From fe1d296b48ff8481e0f0849c6364e86627992a98 Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Sun, 23 Apr 2023 01:29:51 -0500 Subject: [PATCH 2/7] Support for ERT SCM+ meter protocol --- firmware/common/ert_packet.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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 Date: Sun, 23 Apr 2023 01:31:45 -0500 Subject: [PATCH 3/7] Support for ERT SCM+ meter protocol --- firmware/common/ert_packet.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/firmware/common/ert_packet.hpp b/firmware/common/ert_packet.hpp index fcdf8e33..90818421 100644 --- a/firmware/common/ert_packet.hpp +++ b/firmware/common/ert_packet.hpp @@ -45,6 +45,7 @@ public: Unknown = 0, IDM = 1, SCM = 2, + SCMPLUS = 3, }; Packet( @@ -80,7 +81,7 @@ private: const Reader reader_; const Type type_; - bool crc_ok_idm() const; + bool crc_ok_ccitt() const; bool crc_ok_scm() const; }; From 48ed7b1b1aaf2a22180e78f4ec2f61f9808b8dff Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Sun, 23 Apr 2023 01:33:42 -0500 Subject: [PATCH 4/7] Support for ERT SCM+ meter protocol --- firmware/baseband/proc_ert.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) 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 ) { From 44b2e5ea61f53ed5726db2e69709694055f2e455 Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Sun, 23 Apr 2023 01:34:56 -0500 Subject: [PATCH 5/7] Support for ERT SCM+ meter protocol --- firmware/baseband/proc_ert.hpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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]; From 6cdada111845f9de17890392960cc92f257e2bde Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Mon, 24 Apr 2023 09:59:43 -0500 Subject: [PATCH 6/7] Include ERT packet type in ert.txt log file --- firmware/application/apps/ert_app.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/firmware/application/apps/ert_app.cpp b/firmware/application/apps/ert_app.cpp index 894caca8..5c0adc91 100644 --- a/firmware/application/apps/ert_app.cpp +++ b/firmware/application/apps/ert_app.cpp @@ -63,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 { }; From b1f5023fe15a72930e5bd951b62fdc3d8210f4b1 Mon Sep 17 00:00:00 2001 From: Mark Thompson <129641948+NotherNgineer@users.noreply.github.com> Date: Mon, 24 Apr 2023 15:29:51 -0500 Subject: [PATCH 7/7] Removed unneeded space characters --- firmware/application/apps/ert_app.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/firmware/application/apps/ert_app.cpp b/firmware/application/apps/ert_app.cpp index 5c0adc91..447286ef 100644 --- a/firmware/application/apps/ert_app.cpp +++ b/firmware/application/apps/ert_app.cpp @@ -38,9 +38,9 @@ namespace format { std::string type(Packet::Type value) { switch(value) { default: - case Packet::Type::Unknown: return "??? "; - case Packet::Type::IDM: return "IDM "; - case Packet::Type::SCM: return "SCM "; + case Packet::Type::Unknown: return "???"; + case Packet::Type::IDM: return "IDM"; + case Packet::Type::SCM: return "SCM"; case Packet::Type::SCMPLUS: return "SCM+"; } }