mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Move TPMS packet handling to TPMSAppView.
Also rename TPMSModel to TPMSLogger, considering that's what it was *really* doing.
This commit is contained in:
parent
32818ee9ab
commit
feec99ac6a
@ -28,9 +28,8 @@ using namespace portapack;
|
|||||||
|
|
||||||
#include "string_format.hpp"
|
#include "string_format.hpp"
|
||||||
|
|
||||||
tpms::Packet TPMSModel::on_packet(const TPMSPacketMessage& message) {
|
void TPMSLogger::on_packet(const Timestamp& timestamp, const tpms::Packet& packet) {
|
||||||
const ManchesterDecoder decoder(message.packet, 1);
|
const auto hex_formatted = format_manchester(packet);
|
||||||
const auto hex_formatted = format_manchester(decoder);
|
|
||||||
|
|
||||||
if( log_file.is_ready() ) {
|
if( log_file.is_ready() ) {
|
||||||
const auto tuning_frequency = receiver_model.tuning_frequency();
|
const auto tuning_frequency = receiver_model.tuning_frequency();
|
||||||
@ -38,10 +37,8 @@ tpms::Packet TPMSModel::on_packet(const TPMSPacketMessage& message) {
|
|||||||
const auto tuning_frequency_str = to_string_dec_uint(tuning_frequency, 10);
|
const auto tuning_frequency_str = to_string_dec_uint(tuning_frequency, 10);
|
||||||
|
|
||||||
std::string entry = tuning_frequency_str + " FSK 38.4 19.2 " + hex_formatted.data + "/" + hex_formatted.errors;
|
std::string entry = tuning_frequency_str + " FSK 38.4 19.2 " + hex_formatted.data + "/" + hex_formatted.errors;
|
||||||
log_file.write_entry(message.packet.timestamp(), entry);
|
log_file.write_entry(timestamp, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
return hex_formatted;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
@ -54,7 +51,7 @@ TPMSAppView::TPMSAppView() {
|
|||||||
EventDispatcher::message_map().register_handler(Message::ID::TPMSPacket,
|
EventDispatcher::message_map().register_handler(Message::ID::TPMSPacket,
|
||||||
[this](Message* const p) {
|
[this](Message* const p) {
|
||||||
const auto message = static_cast<const TPMSPacketMessage*>(p);
|
const auto message = static_cast<const TPMSPacketMessage*>(p);
|
||||||
this->log(this->model.on_packet(*message));
|
this->on_packet(message->packet);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -75,8 +72,15 @@ void TPMSAppView::set_parent_rect(const Rect new_parent_rect) {
|
|||||||
console.set_parent_rect({ 0, 0, new_parent_rect.width(), new_parent_rect.height() });
|
console.set_parent_rect({ 0, 0, new_parent_rect.width(), new_parent_rect.height() });
|
||||||
}
|
}
|
||||||
|
|
||||||
void TPMSAppView::log(const tpms::Packet& formatted) {
|
void TPMSAppView::on_packet(const baseband::Packet& baseband_packet) {
|
||||||
console.writeln(formatted.data.substr(0, 240 / 8));
|
const tpms::Packet tpms_packet { baseband_packet, 1 };
|
||||||
|
this->logger.on_packet(baseband_packet.timestamp(), tpms_packet);
|
||||||
|
this->draw(tpms_packet);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TPMSAppView::draw(const tpms::Packet& packet) {
|
||||||
|
const auto hex_formatted = format_manchester(packet);
|
||||||
|
console.writeln(hex_formatted.data.substr(0, 240 / 8));
|
||||||
}
|
}
|
||||||
|
|
||||||
} /* namespace ui */
|
} /* namespace ui */
|
||||||
|
@ -30,13 +30,13 @@
|
|||||||
|
|
||||||
namespace tpms {
|
namespace tpms {
|
||||||
|
|
||||||
using Packet = ManchesterFormatted;
|
using Packet = ManchesterDecoder;
|
||||||
|
|
||||||
} /* namespace tpms */
|
} /* namespace tpms */
|
||||||
|
|
||||||
class TPMSModel {
|
class TPMSLogger {
|
||||||
public:
|
public:
|
||||||
tpms::Packet on_packet(const TPMSPacketMessage& message);
|
void on_packet(const Timestamp& timestamp, const tpms::Packet& packet);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LogFile log_file { "tpms.txt" };
|
LogFile log_file { "tpms.txt" };
|
||||||
@ -52,11 +52,12 @@ public:
|
|||||||
void set_parent_rect(const Rect new_parent_rect) override;
|
void set_parent_rect(const Rect new_parent_rect) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TPMSModel model;
|
TPMSLogger logger;
|
||||||
|
|
||||||
Console console;
|
Console console;
|
||||||
|
|
||||||
void log(const tpms::Packet& formatted);
|
void on_packet(const baseband::Packet& packet);
|
||||||
|
void draw(const tpms::Packet& packet);
|
||||||
};
|
};
|
||||||
|
|
||||||
} /* namespace ui */
|
} /* namespace ui */
|
||||||
|
Loading…
Reference in New Issue
Block a user