From fbcf784959fa4bb5b01862539752c347634fc7d1 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Mon, 18 Jan 2016 14:34:30 -0800 Subject: [PATCH] Make tpms::Packet into real type. --- firmware/application/tpms_app.cpp | 30 +++++++++++++++++++++--------- firmware/application/tpms_app.hpp | 22 +++++++++++++++++++--- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/firmware/application/tpms_app.cpp b/firmware/application/tpms_app.cpp index a5bdac307..2809fa0df 100644 --- a/firmware/application/tpms_app.cpp +++ b/firmware/application/tpms_app.cpp @@ -28,8 +28,20 @@ using namespace portapack; #include "string_format.hpp" -void TPMSLogger::on_packet(const Timestamp& timestamp, const tpms::Packet& packet) { - const auto hex_formatted = format_manchester(packet); +namespace tpms { + +Timestamp Packet::received_at() const { + return packet_.timestamp(); +} + +ManchesterFormatted Packet::symbols_formatted() const { + return format_manchester(decoder_); +} + +} /* namespace tpms */ + +void TPMSLogger::on_packet(const tpms::Packet& packet) { + const auto hex_formatted = packet.symbols_formatted(); if( log_file.is_ready() ) { const auto tuning_frequency = receiver_model.tuning_frequency(); @@ -37,7 +49,7 @@ void TPMSLogger::on_packet(const Timestamp& timestamp, const tpms::Packet& packe 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(timestamp, entry); + log_file.write_entry(packet.received_at(), entry); } } @@ -51,7 +63,8 @@ TPMSAppView::TPMSAppView() { EventDispatcher::message_map().register_handler(Message::ID::TPMSPacket, [this](Message* const p) { const auto message = static_cast(p); - this->on_packet(message->packet); + const tpms::Packet packet { message->packet }; + this->on_packet(packet); } ); @@ -72,14 +85,13 @@ 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::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::on_packet(const tpms::Packet& packet) { + this->logger.on_packet(packet); + this->draw(packet); } void TPMSAppView::draw(const tpms::Packet& packet) { - const auto hex_formatted = format_manchester(packet); + const auto hex_formatted = packet.symbols_formatted(); console.writeln(hex_formatted.data.substr(0, 240 / 8)); } diff --git a/firmware/application/tpms_app.hpp b/firmware/application/tpms_app.hpp index d4904e666..3a1571f16 100644 --- a/firmware/application/tpms_app.hpp +++ b/firmware/application/tpms_app.hpp @@ -30,13 +30,29 @@ namespace tpms { -using Packet = ManchesterDecoder; +class Packet { +public: + constexpr Packet( + const baseband::Packet& packet + ) : packet_ { packet }, + decoder_ { packet_, 1 } + { + } + + Timestamp received_at() const; + + ManchesterFormatted symbols_formatted() const; + +private: + const baseband::Packet packet_; + const ManchesterDecoder decoder_; +}; } /* namespace tpms */ class TPMSLogger { public: - void on_packet(const Timestamp& timestamp, const tpms::Packet& packet); + void on_packet(const tpms::Packet& packet); private: LogFile log_file { "tpms.txt" }; @@ -56,7 +72,7 @@ private: Console console; - void on_packet(const baseband::Packet& packet); + void on_packet(const tpms::Packet& packet); void draw(const tpms::Packet& packet); };