Use ert::Packet for basic packet decoding.

This commit is contained in:
Jared Boone 2015-12-06 15:32:21 -08:00
parent 51026609ce
commit 2a55030d4e
2 changed files with 35 additions and 30 deletions

View File

@ -29,6 +29,8 @@ using namespace portapack;
#include "lpc43xx_cpp.hpp" #include "lpc43xx_cpp.hpp"
using namespace lpc43xx; using namespace lpc43xx;
#include "string_format.hpp"
namespace ert { namespace ert {
size_t Packet::length() const { size_t Packet::length() const {
@ -82,31 +84,8 @@ ERTModel::ERTModel() {
log_file.open_for_append("ert.txt"); log_file.open_for_append("ert.txt");
} }
std::string ERTModel::on_packet(const ERTPacketMessage& message) { bool ERTModel::on_packet(const ert::Packet&) {
rtc::RTC received_at; return true;
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;
} }
namespace ui { namespace ui {
@ -118,7 +97,12 @@ void ERTView::on_show() {
message_map.register_handler(Message::ID::ERTPacket, message_map.register_handler(Message::ID::ERTPacket,
[this](Message* const p) { [this](Message* const p) {
const auto message = static_cast<const ERTPacketMessage*>(p); const auto message = static_cast<const ERTPacketMessage*>(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(); Console::on_hide();
} }
void ERTView::log(const std::string& s) { void ERTView::on_packet(const ert::Packet& packet) {
writeln(s); 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 */ } /* namespace ui */

View File

@ -103,7 +103,7 @@ class ERTModel {
public: public:
ERTModel(); ERTModel();
std::string on_packet(const ERTPacketMessage& message); bool on_packet(const ert::Packet& packet);
private: private:
LogFile log_file; LogFile log_file;
@ -119,7 +119,7 @@ public:
private: private:
ERTModel model; ERTModel model;
void log(const std::string& s); void on_packet(const ert::Packet& packet);
}; };
} /* namespace ui */ } /* namespace ui */