mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
ERTModel -> ERTLogger, now ERTApp does setup.
This commit is contained in:
parent
e4f5539407
commit
cca8c6dc06
@ -31,7 +31,24 @@ using namespace portapack;
|
||||
#include "crc.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({
|
||||
.mode = 6,
|
||||
.sampling_rate = 4194304,
|
||||
@ -40,38 +57,14 @@ ERTModel::ERTModel() {
|
||||
receiver_model.set_baseband_bandwidth(2500000);
|
||||
}
|
||||
|
||||
bool ERTModel::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);
|
||||
}
|
||||
|
||||
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() {
|
||||
ERTView::~ERTView() {
|
||||
EventDispatcher::message_map().unregister_handler(Message::ID::ERTPacket);
|
||||
|
||||
Console::on_hide();
|
||||
}
|
||||
|
||||
void ERTView::on_packet(const ert::Packet& packet) {
|
||||
logger.on_packet(packet);
|
||||
|
||||
if( packet.crc_ok() ) {
|
||||
std::string msg;
|
||||
switch(packet.type()) {
|
||||
case ert::Packet::Type::SCM:
|
||||
@ -94,6 +87,7 @@ void ERTView::on_packet(const ert::Packet& packet) {
|
||||
}
|
||||
|
||||
writeln(msg);
|
||||
}
|
||||
}
|
||||
|
||||
} /* namespace ui */
|
||||
|
@ -31,11 +31,9 @@
|
||||
#include <string>
|
||||
#include <bitset>
|
||||
|
||||
class ERTModel {
|
||||
class ERTLogger {
|
||||
public:
|
||||
ERTModel();
|
||||
|
||||
bool on_packet(const ert::Packet& packet);
|
||||
void on_packet(const ert::Packet& packet);
|
||||
|
||||
private:
|
||||
LogFile log_file { "ert.txt" };
|
||||
@ -45,11 +43,11 @@ namespace ui {
|
||||
|
||||
class ERTView : public Console {
|
||||
public:
|
||||
void on_show() override;
|
||||
void on_hide() override;
|
||||
ERTView();
|
||||
~ERTView();
|
||||
|
||||
private:
|
||||
ERTModel model;
|
||||
ERTLogger logger;
|
||||
|
||||
void on_packet(const ert::Packet& packet);
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user