mirror of
https://github.com/eried/portapack-mayhem.git
synced 2025-03-20 13:46:28 -04:00
Add ERT commodity type.
This commit is contained in:
parent
6571ef0c11
commit
b7c0efbb64
@ -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<std::pair<std::string, size_t>, 3> ert_columns { {
|
||||
static const std::array<std::pair<std::string, size_t>, 4> ert_columns { {
|
||||
{ "ID", 10 },
|
||||
{ "Tp", 2 },
|
||||
{ "Consumpt", 10 },
|
||||
{ "Cnt", 3 },
|
||||
} };
|
||||
@ -111,7 +118,7 @@ void RecentEntriesView<ERTRecentEntries>::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();
|
||||
}
|
||||
}
|
||||
|
@ -33,13 +33,37 @@
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
|
||||
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);
|
||||
|
@ -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_);
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user