Move TPMS packet handling to TPMSAppView.

Also rename TPMSModel to TPMSLogger, considering that's what it was *really* doing.
This commit is contained in:
Jared Boone 2016-01-18 14:21:24 -08:00
parent 32818ee9ab
commit feec99ac6a
2 changed files with 19 additions and 14 deletions

View File

@ -28,9 +28,8 @@ using namespace portapack;
#include "string_format.hpp"
tpms::Packet TPMSModel::on_packet(const TPMSPacketMessage& message) {
const ManchesterDecoder decoder(message.packet, 1);
const auto hex_formatted = format_manchester(decoder);
void TPMSLogger::on_packet(const Timestamp& timestamp, const tpms::Packet& packet) {
const auto hex_formatted = format_manchester(packet);
if( log_file.is_ready() ) {
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);
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 {
@ -54,7 +51,7 @@ TPMSAppView::TPMSAppView() {
EventDispatcher::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));
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() });
}
void TPMSAppView::log(const tpms::Packet& formatted) {
console.writeln(formatted.data.substr(0, 240 / 8));
void TPMSAppView::on_packet(const baseband::Packet& baseband_packet) {
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 */

View File

@ -30,13 +30,13 @@
namespace tpms {
using Packet = ManchesterFormatted;
using Packet = ManchesterDecoder;
} /* namespace tpms */
class TPMSModel {
class TPMSLogger {
public:
tpms::Packet on_packet(const TPMSPacketMessage& message);
void on_packet(const Timestamp& timestamp, const tpms::Packet& packet);
private:
LogFile log_file { "tpms.txt" };
@ -52,11 +52,12 @@ public:
void set_parent_rect(const Rect new_parent_rect) override;
private:
TPMSModel model;
TPMSLogger logger;
Console console;
void log(const tpms::Packet& formatted);
void on_packet(const baseband::Packet& packet);
void draw(const tpms::Packet& packet);
};
} /* namespace ui */