From 2a55030d4ebb0aaa4b0c8eddd004b9b12d2e5de8 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 6 Dec 2015 15:32:21 -0800 Subject: [PATCH] Use ert::Packet for basic packet decoding. --- firmware/application/app_ert.cpp | 61 +++++++++++++++++--------------- firmware/application/app_ert.hpp | 4 +-- 2 files changed, 35 insertions(+), 30 deletions(-) diff --git a/firmware/application/app_ert.cpp b/firmware/application/app_ert.cpp index fe017437..785f133c 100644 --- a/firmware/application/app_ert.cpp +++ b/firmware/application/app_ert.cpp @@ -29,6 +29,8 @@ using namespace portapack; #include "lpc43xx_cpp.hpp" using namespace lpc43xx; +#include "string_format.hpp" + namespace ert { size_t Packet::length() const { @@ -82,31 +84,8 @@ ERTModel::ERTModel() { log_file.open_for_append("ert.txt"); } -std::string ERTModel::on_packet(const ERTPacketMessage& message) { - rtc::RTC received_at; - rtcGetTime(&RTCD1, &received_at); - - std::string entry; - - if( message.packet.preamble == 0x555516a3 ) { - entry += "IDM "; - } - if( message.packet.preamble == 0x1f2a60 ) { - entry += "SCM "; - } - - const ManchesterDecoder decoder(message.packet.payload, message.packet.bits_received); - - const auto hex_formatted = format_manchester(decoder); - entry += hex_formatted.data; - entry += "/"; - entry += hex_formatted.errors; - - if( log_file.is_ready() ) { - log_file.write_entry(received_at, entry); - } - - return entry; +bool ERTModel::on_packet(const ert::Packet&) { + return true; } namespace ui { @@ -118,7 +97,12 @@ void ERTView::on_show() { message_map.register_handler(Message::ID::ERTPacket, [this](Message* const p) { const auto message = static_cast(p); - this->log(this->model.on_packet(*message)); + rtc::RTC datetime; + rtcGetTime(&RTCD1, &datetime); + const ert::Packet packet { datetime, message->packet.preamble, message->packet.payload, message->packet.bits_received }; + if( this->model.on_packet(packet) ) { + this->on_packet(packet); + } } ); } @@ -130,8 +114,29 @@ void ERTView::on_hide() { Console::on_hide(); } -void ERTView::log(const std::string& s) { - writeln(s); +void ERTView::on_packet(const ert::Packet& packet) { + std::string msg; + switch(packet.type()) { + case ert::Packet::Type::SCM: + msg += "SCM "; + msg += to_string_dec_uint(packet.id(), 10); + msg += " "; + msg += to_string_dec_uint(packet.consumption(), 10); + break; + + case ert::Packet::Type::IDM: + msg += "IDM "; + msg += to_string_dec_uint(packet.id(), 10); + msg += " "; + msg += to_string_dec_uint(packet.consumption(), 10); + break; + + default: + msg += "???"; + break; + } + + writeln(msg); } } /* namespace ui */ diff --git a/firmware/application/app_ert.hpp b/firmware/application/app_ert.hpp index ebc26864..8ca08d19 100644 --- a/firmware/application/app_ert.hpp +++ b/firmware/application/app_ert.hpp @@ -103,7 +103,7 @@ class ERTModel { public: ERTModel(); - std::string on_packet(const ERTPacketMessage& message); + bool on_packet(const ert::Packet& packet); private: LogFile log_file; @@ -119,7 +119,7 @@ public: private: ERTModel model; - void log(const std::string& s); + void on_packet(const ert::Packet& packet); }; } /* namespace ui */