From b7c0efbb64dce5dc5502a5cb51c1c4bd07a82f77 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Wed, 6 Apr 2016 16:16:10 -0700 Subject: [PATCH] Add ERT commodity type. --- firmware/application/ert_app.cpp | 13 +++++++++--- firmware/application/ert_app.hpp | 35 +++++++++++++++++++++++++++----- firmware/common/ert_packet.cpp | 10 +++++++++ firmware/common/ert_packet.hpp | 9 +++++--- 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/firmware/application/ert_app.cpp b/firmware/application/ert_app.cpp index 74080b5f0..938aef9d4 100644 --- a/firmware/application/ert_app.cpp +++ b/firmware/application/ert_app.cpp @@ -51,6 +51,10 @@ std::string consumption(Consumption value) { return to_string_dec_uint(value, 10); } +std::string commodity_type(CommodityType value) { + return to_string_dec_uint(value, 2); +} + } /* namespace format */ } /* namespace ert */ @@ -68,6 +72,8 @@ void ERTLogger::on_packet(const ert::Packet& packet) { } } +const ERTRecentEntry::Key ERTRecentEntry::invalid_key { }; + void ERTRecentEntry::update(const ert::Packet& packet) { received_count++; @@ -76,8 +82,9 @@ void ERTRecentEntry::update(const ert::Packet& packet) { namespace ui { -static const std::array, 3> ert_columns { { +static const std::array, 4> ert_columns { { { "ID", 10 }, + { "Tp", 2 }, { "Consumpt", 10 }, { "Cnt", 3 }, } }; @@ -111,7 +118,7 @@ void RecentEntriesView::draw( ) { const auto& draw_style = is_selected ? style.invert() : style; - std::string line = ert::format::id(entry.id) + " " + ert::format::consumption(entry.last_consumption); + std::string line = ert::format::id(entry.id) + " " + ert::format::commodity_type(entry.commodity_type) + " " + ert::format::consumption(entry.last_consumption); if( entry.received_count > 999 ) { line += " +++"; @@ -176,7 +183,7 @@ void ERTAppView::on_packet(const ert::Packet& packet) { } if( packet.crc_ok() ) { - recent.on_packet(packet.id(), packet); + recent.on_packet({ packet.id(), packet.commodity_type() }, packet); recent_entries_view.set_dirty(); } } diff --git a/firmware/application/ert_app.hpp b/firmware/application/ert_app.hpp index 560e0228b..e280f3792 100644 --- a/firmware/application/ert_app.hpp +++ b/firmware/application/ert_app.hpp @@ -33,13 +33,37 @@ #include #include +struct ERTKey { + ert::ID id; + ert::CommodityType commodity_type; + + constexpr ERTKey( + ert::ID id = ert::invalid_id, + ert::CommodityType commodity_type = ert::invalid_commodity_type + ) : id { id }, + commodity_type { commodity_type } + { + } + + ERTKey& operator=(const ERTKey& other) { + id = other.id; + commodity_type = other.commodity_type; + return *this; + } + + bool operator==(const ERTKey& other) const { + return (id == other.id) && (commodity_type == other.commodity_type); + } +}; + struct ERTRecentEntry { - using Key = ert::ID; + using Key = ERTKey; // TODO: Is this the right choice of invalid key value? - static constexpr Key invalid_key = 0; + static const Key invalid_key; - ert::ID id { invalid_key }; + ert::ID id { ert::invalid_id }; + ert::CommodityType commodity_type { ert::invalid_commodity_type }; size_t received_count { 0 }; @@ -47,12 +71,13 @@ struct ERTRecentEntry { ERTRecentEntry( const Key& key - ) : id { key } + ) : id { key.id }, + commodity_type { key.commodity_type } { } Key key() const { - return id; + return { id, commodity_type }; } void update(const ert::Packet& packet); diff --git a/firmware/common/ert_packet.cpp b/firmware/common/ert_packet.cpp index 06e010dd5..3fcf0ede1 100644 --- a/firmware/common/ert_packet.cpp +++ b/firmware/common/ert_packet.cpp @@ -63,6 +63,16 @@ Consumption Packet::consumption() const { return invalid_consumption; } +CommodityType Packet::commodity_type() const { + if( type() == Type::SCM ) { + return reader_.read(5, 4); + } + if( type() == Type::IDM ) { + return reader_.read(4 * 8 + 4, 4); + } + return invalid_commodity_type; +} + ManchesterFormatted Packet::symbols_formatted() const { return format_manchester(decoder_); } diff --git a/firmware/common/ert_packet.hpp b/firmware/common/ert_packet.hpp index f0bb3a132..0a0535366 100644 --- a/firmware/common/ert_packet.hpp +++ b/firmware/common/ert_packet.hpp @@ -33,6 +33,11 @@ namespace ert { using ID = uint32_t; using Consumption = uint32_t; +using CommodityType = uint32_t; + +constexpr ID invalid_id = 0; +constexpr CommodityType invalid_commodity_type = -1; +constexpr Consumption invalid_consumption = 0; class Packet { public: @@ -60,6 +65,7 @@ public: Type type() const; ID id() const; + CommodityType commodity_type() const; Consumption consumption() const; ManchesterFormatted symbols_formatted() const; @@ -74,9 +80,6 @@ private: const Reader reader_; const Type type_; - const ID invalid_id = 0; - const Consumption invalid_consumption = 0; - bool crc_ok_idm() const; bool crc_ok_scm() const; };