mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-24 23:09:26 -05:00
AISModel receive packets from baseband, notifies AISView.
Use Signal class to distribute packets to multiple listeners.
This commit is contained in:
parent
9cab3c9978
commit
f8a063312c
@ -89,6 +89,18 @@ AISModel::AISModel() {
|
||||
receiver_model.set_baseband_bandwidth(1750000);
|
||||
|
||||
log_file.open_for_append("ais.txt");
|
||||
|
||||
EventDispatcher::message_map().register_handler(Message::ID::AISPacket,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const AISPacketMessage*>(p);
|
||||
const ais::Packet packet { message->packet };
|
||||
this->on_packet(packet);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
AISModel::~AISModel() {
|
||||
EventDispatcher::message_map().unregister_handler(Message::ID::AISPacket);
|
||||
}
|
||||
|
||||
bool AISModel::on_packet(const ais::Packet& packet) {
|
||||
@ -110,31 +122,13 @@ bool AISModel::on_packet(const ais::Packet& packet) {
|
||||
log_file.write_entry(packet.received_at(), entry);
|
||||
}
|
||||
|
||||
packet_signal.emit(packet);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace ui {
|
||||
|
||||
void AISView::on_show() {
|
||||
View::on_show();
|
||||
|
||||
EventDispatcher::message_map().register_handler(Message::ID::AISPacket,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const AISPacketMessage*>(p);
|
||||
const ais::Packet packet { message->packet };
|
||||
if( this->model.on_packet(packet) ) {
|
||||
this->on_packet(packet);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void AISView::on_hide() {
|
||||
EventDispatcher::message_map().unregister_handler(Message::ID::AISPacket);
|
||||
|
||||
View::on_hide();
|
||||
}
|
||||
|
||||
void AISView::truncate_entries() {
|
||||
while(recent.size() > 64) {
|
||||
recent.pop_back();
|
||||
|
@ -25,8 +25,12 @@
|
||||
#include "ui_widget.hpp"
|
||||
#include "log_file.hpp"
|
||||
|
||||
#include "message.hpp"
|
||||
|
||||
#include "ais_packet.hpp"
|
||||
|
||||
#include "signal.hpp"
|
||||
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
using namespace lpc43xx;
|
||||
|
||||
@ -66,11 +70,14 @@ struct AISRecentEntry {
|
||||
class AISModel {
|
||||
public:
|
||||
AISModel();
|
||||
~AISModel();
|
||||
|
||||
bool on_packet(const ais::Packet& packet);
|
||||
Signal<const ais::Packet&> packet_signal;
|
||||
|
||||
private:
|
||||
LogFile log_file;
|
||||
|
||||
bool on_packet(const ais::Packet& packet);
|
||||
};
|
||||
|
||||
namespace ui {
|
||||
@ -79,10 +86,15 @@ class AISView : public View {
|
||||
public:
|
||||
AISView() {
|
||||
flags.focusable = true;
|
||||
|
||||
packet_signal_token = model.packet_signal += [this](const ais::Packet& packet) {
|
||||
this->on_packet(packet);
|
||||
};
|
||||
}
|
||||
|
||||
void on_show() override;
|
||||
void on_hide() override;
|
||||
~AISView() {
|
||||
model.packet_signal -= packet_signal_token;
|
||||
}
|
||||
|
||||
void paint(Painter& painter) override;
|
||||
|
||||
@ -93,6 +105,7 @@ public:
|
||||
|
||||
private:
|
||||
AISModel model;
|
||||
SignalToken packet_signal_token;
|
||||
|
||||
using EntryKey = ais::MMSI;
|
||||
EntryKey selected_key;
|
||||
|
Loading…
Reference in New Issue
Block a user