mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-25 15:29:37 -05:00
Refactor digital mode handlers into Model and View classes.
This commit is contained in:
parent
ec977ccd05
commit
f49cdfdd99
@ -499,26 +499,6 @@ ReceiverView::~ReceiverView() {
|
||||
}
|
||||
|
||||
void ReceiverView::on_show() {
|
||||
auto& message_map = context().message_map();
|
||||
message_map.register_handler(Message::ID::AISPacket,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const AISPacketMessage*>(p);
|
||||
this->on_packet_ais(*message);
|
||||
}
|
||||
);
|
||||
message_map.register_handler(Message::ID::TPMSPacket,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const TPMSPacketMessage*>(p);
|
||||
this->on_packet_tpms(*message);
|
||||
}
|
||||
);
|
||||
message_map.register_handler(Message::ID::ERTPacket,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const ERTPacketMessage*>(p);
|
||||
this->on_packet_ert(*message);
|
||||
}
|
||||
);
|
||||
|
||||
sd_card_status_signal_token = sd_card::status_signal += [this](const sd_card::Status status) {
|
||||
this->on_sd_card_status(status);
|
||||
};
|
||||
@ -526,20 +506,6 @@ void ReceiverView::on_show() {
|
||||
|
||||
void ReceiverView::on_hide() {
|
||||
sd_card::status_signal -= sd_card_status_signal_token;
|
||||
|
||||
auto& message_map = context().message_map();
|
||||
message_map.unregister_handler(Message::ID::ERTPacket);
|
||||
message_map.unregister_handler(Message::ID::TPMSPacket);
|
||||
message_map.unregister_handler(Message::ID::AISPacket);
|
||||
}
|
||||
|
||||
void ReceiverView::on_packet_ais(const AISPacketMessage& message) {
|
||||
const auto result = baseband::ais::packet_decode(message.packet.payload, message.packet.bits_received);
|
||||
|
||||
auto console = reinterpret_cast<Console*>(widget_content.get());
|
||||
if( result.first == "OK" ) {
|
||||
console->writeln(result.second);
|
||||
}
|
||||
}
|
||||
|
||||
static FIL fil_tpms;
|
||||
@ -619,13 +585,52 @@ static ManchesterFormatted format_manchester(
|
||||
return { hex_data, hex_error };
|
||||
}
|
||||
|
||||
void ReceiverView::on_packet_tpms(const TPMSPacketMessage& message) {
|
||||
class AISModel {
|
||||
public:
|
||||
baseband::ais::decoded_packet on_packet(const AISPacketMessage& message) {
|
||||
return baseband::ais::packet_decode(message.packet.payload, message.packet.bits_received);
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class AISView : public Console {
|
||||
public:
|
||||
void on_show() override {
|
||||
Console::on_show();
|
||||
|
||||
auto& message_map = context().message_map();
|
||||
message_map.register_handler(Message::ID::AISPacket,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const AISPacketMessage*>(p);
|
||||
this->log(this->model.on_packet(*message));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void on_hide() override {
|
||||
auto& message_map = context().message_map();
|
||||
message_map.unregister_handler(Message::ID::AISPacket);
|
||||
|
||||
Console::on_hide();
|
||||
}
|
||||
|
||||
private:
|
||||
AISModel model;
|
||||
|
||||
void log(const baseband::ais::decoded_packet decoded) {
|
||||
if( decoded.first == "OK" ) {
|
||||
writeln(decoded.second);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class TPMSModel {
|
||||
public:
|
||||
ManchesterFormatted on_packet(const TPMSPacketMessage& message) {
|
||||
const ManchesterDecoder decoder(message.packet.payload, message.packet.bits_received, 1);
|
||||
const auto hex_formatted = format_manchester(decoder);
|
||||
|
||||
auto console = reinterpret_cast<Console*>(widget_content.get());
|
||||
console->writeln(hex_formatted.data.substr(0, 240 / 8));
|
||||
|
||||
if( !f_error(&fil_tpms) ) {
|
||||
rtc::RTC datetime;
|
||||
rtcGetTime(&RTCD1, &datetime);
|
||||
@ -645,24 +650,96 @@ void ReceiverView::on_packet_tpms(const TPMSPacketMessage& message) {
|
||||
f_puts(log.c_str(), &fil_tpms);
|
||||
f_sync(&fil_tpms);
|
||||
}
|
||||
}
|
||||
|
||||
void ReceiverView::on_packet_ert(const ERTPacketMessage& message) {
|
||||
auto console = reinterpret_cast<Console*>(widget_content.get());
|
||||
return hex_formatted;
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class TPMSView : public Console {
|
||||
public:
|
||||
void on_show() override {
|
||||
Console::on_show();
|
||||
|
||||
auto& message_map = context().message_map();
|
||||
message_map.register_handler(Message::ID::TPMSPacket,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const TPMSPacketMessage*>(p);
|
||||
this->log(this->model.on_packet(*message));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void on_hide() override {
|
||||
auto& message_map = context().message_map();
|
||||
message_map.unregister_handler(Message::ID::TPMSPacket);
|
||||
|
||||
Console::on_hide();
|
||||
}
|
||||
|
||||
private:
|
||||
TPMSModel model;
|
||||
|
||||
void log(const ManchesterFormatted& formatted) {
|
||||
writeln(formatted.data.substr(0, 240 / 8));
|
||||
}
|
||||
};
|
||||
|
||||
class ERTModel {
|
||||
public:
|
||||
std::string on_packet(const ERTPacketMessage& message) {
|
||||
std::string s;
|
||||
|
||||
if( message.packet.preamble == 0x555516a3 ) {
|
||||
console->writeln("IDM");
|
||||
s += "IDM\n";
|
||||
}
|
||||
if( message.packet.preamble == 0x1f2a60 ) {
|
||||
console->writeln("SCM");
|
||||
s += "SCM\n";
|
||||
}
|
||||
|
||||
const ManchesterDecoder decoder(message.packet.payload, message.packet.bits_received);
|
||||
|
||||
const auto hex_formatted = format_manchester(decoder);
|
||||
console->writeln(hex_formatted.data);
|
||||
console->writeln(hex_formatted.errors);
|
||||
}
|
||||
s += hex_formatted.data;
|
||||
s += "\n";
|
||||
s += hex_formatted.errors;
|
||||
s += "\n";
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
class ERTView : public Console {
|
||||
public:
|
||||
void on_show() override {
|
||||
Console::on_show();
|
||||
|
||||
auto& message_map = context().message_map();
|
||||
message_map.register_handler(Message::ID::ERTPacket,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const ERTPacketMessage*>(p);
|
||||
this->log(this->model.on_packet(*message));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void on_hide() override {
|
||||
auto& message_map = context().message_map();
|
||||
message_map.unregister_handler(Message::ID::ERTPacket);
|
||||
|
||||
Console::on_hide();
|
||||
}
|
||||
|
||||
private:
|
||||
ERTModel model;
|
||||
|
||||
void log(const std::string& s) {
|
||||
write(s);
|
||||
}
|
||||
};
|
||||
|
||||
void ReceiverView::on_sd_card_status(const sd_card::Status status) {
|
||||
if( status == sd_card::Status::Mounted ) {
|
||||
@ -754,9 +831,17 @@ void ReceiverView::on_modulation_changed(int32_t modulation) {
|
||||
|
||||
switch(modulation) {
|
||||
case 3:
|
||||
widget_content = std::make_unique<AISView>();
|
||||
add_child(widget_content.get());
|
||||
break;
|
||||
|
||||
case 5:
|
||||
widget_content = std::make_unique<TPMSView>();
|
||||
add_child(widget_content.get());
|
||||
break;
|
||||
|
||||
case 6:
|
||||
widget_content = std::make_unique<Console>();
|
||||
widget_content = std::make_unique<ERTView>();
|
||||
add_child(widget_content.get());
|
||||
break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user