ERTModel -> ERTLogger, now ERTApp does setup.

This commit is contained in:
Jared Boone 2016-01-23 21:17:04 -08:00
parent e4f5539407
commit cca8c6dc06
2 changed files with 47 additions and 55 deletions

View File

@ -31,7 +31,24 @@ using namespace portapack;
#include "crc.hpp" #include "crc.hpp"
#include "string_format.hpp" #include "string_format.hpp"
ERTModel::ERTModel() { void ERTLogger::on_packet(const ert::Packet& packet) {
if( log_file.is_ready() ) {
const auto formatted = packet.symbols_formatted();
log_file.write_entry(packet.received_at(), formatted.data + "/" + formatted.errors);
}
}
namespace ui {
ERTView::ERTView() {
EventDispatcher::message_map().register_handler(Message::ID::ERTPacket,
[this](Message* const p) {
const auto message = static_cast<const ERTPacketMessage*>(p);
const ert::Packet packet { message->type, message->packet };
this->on_packet(packet);
}
);
receiver_model.set_baseband_configuration({ receiver_model.set_baseband_configuration({
.mode = 6, .mode = 6,
.sampling_rate = 4194304, .sampling_rate = 4194304,
@ -40,38 +57,14 @@ ERTModel::ERTModel() {
receiver_model.set_baseband_bandwidth(2500000); receiver_model.set_baseband_bandwidth(2500000);
} }
bool ERTModel::on_packet(const ert::Packet& packet) { ERTView::~ERTView() {
if( log_file.is_ready() ) {
const auto formatted = packet.symbols_formatted();
log_file.write_entry(packet.received_at(), formatted.data + "/" + formatted.errors);
}
return packet.crc_ok();
}
namespace ui {
void ERTView::on_show() {
Console::on_show();
EventDispatcher::message_map().register_handler(Message::ID::ERTPacket,
[this](Message* const p) {
const auto message = static_cast<const ERTPacketMessage*>(p);
const ert::Packet packet { message->type, message->packet };
if( this->model.on_packet(packet) ) {
this->on_packet(packet);
}
}
);
}
void ERTView::on_hide() {
EventDispatcher::message_map().unregister_handler(Message::ID::ERTPacket); EventDispatcher::message_map().unregister_handler(Message::ID::ERTPacket);
Console::on_hide();
} }
void ERTView::on_packet(const ert::Packet& packet) { void ERTView::on_packet(const ert::Packet& packet) {
logger.on_packet(packet);
if( packet.crc_ok() ) {
std::string msg; std::string msg;
switch(packet.type()) { switch(packet.type()) {
case ert::Packet::Type::SCM: case ert::Packet::Type::SCM:
@ -94,6 +87,7 @@ void ERTView::on_packet(const ert::Packet& packet) {
} }
writeln(msg); writeln(msg);
}
} }
} /* namespace ui */ } /* namespace ui */

View File

@ -31,11 +31,9 @@
#include <string> #include <string>
#include <bitset> #include <bitset>
class ERTModel { class ERTLogger {
public: public:
ERTModel(); void on_packet(const ert::Packet& packet);
bool on_packet(const ert::Packet& packet);
private: private:
LogFile log_file { "ert.txt" }; LogFile log_file { "ert.txt" };
@ -45,11 +43,11 @@ namespace ui {
class ERTView : public Console { class ERTView : public Console {
public: public:
void on_show() override; ERTView();
void on_hide() override; ~ERTView();
private: private:
ERTModel model; ERTLogger logger;
void on_packet(const ert::Packet& packet); void on_packet(const ert::Packet& packet);
}; };