diff --git a/firmware/application/ais_app.cpp b/firmware/application/ais_app.cpp index 1d511309..95c7bd7d 100644 --- a/firmware/application/ais_app.cpp +++ b/firmware/application/ais_app.cpp @@ -159,6 +159,12 @@ static std::string true_heading(const TrueHeading value) { } /* namespace format */ } /* namespace ais */ +AISLogger::AISLogger( + const std::string& file_path +) : log_file { file_path } +{ +} + void AISLogger::on_packet(const ais::Packet& packet) { // TODO: Unstuff here, not in baseband! if( log_file.is_ready() ) { @@ -368,6 +374,8 @@ AISAppView::AISAppView(NavigationView&) { recent_entry_detail_view.on_close = [this]() { this->on_show_list(); }; + + logger = std::make_unique("ais.txt"); } AISAppView::~AISAppView() { @@ -389,7 +397,10 @@ void AISAppView::set_parent_rect(const Rect new_parent_rect) { } void AISAppView::on_packet(const ais::Packet& packet) { - logger.on_packet(packet); + if( logger ) { + logger->on_packet(packet); + } + const auto updated_entry = recent.on_packet(packet.source_id(), packet); recent_entries_view.set_dirty(); diff --git a/firmware/application/ais_app.hpp b/firmware/application/ais_app.hpp index 9e2c81b2..f0f81c91 100644 --- a/firmware/application/ais_app.hpp +++ b/firmware/application/ais_app.hpp @@ -90,10 +90,12 @@ using AISRecentEntries = RecentEntries; class AISLogger { public: + AISLogger(const std::string& file_path); + void on_packet(const ais::Packet& packet); private: - LogFile log_file { "ais.txt" }; + LogFile log_file; }; namespace ui { @@ -150,7 +152,7 @@ private: static constexpr uint32_t baseband_bandwidth = 1750000; AISRecentEntries recent; - AISLogger logger; + std::unique_ptr logger; AISRecentEntriesView recent_entries_view { recent }; AISRecentEntryDetailView recent_entry_detail_view; diff --git a/firmware/application/ert_app.cpp b/firmware/application/ert_app.cpp index 6ad67d96..74080b5f 100644 --- a/firmware/application/ert_app.cpp +++ b/firmware/application/ert_app.cpp @@ -55,6 +55,12 @@ std::string consumption(Consumption value) { } /* namespace ert */ +ERTLogger::ERTLogger( + const std::string& file_path +) : log_file { file_path } +{ +} + void ERTLogger::on_packet(const ert::Packet& packet) { if( log_file.is_ready() ) { const auto formatted = packet.symbols_formatted(); @@ -144,6 +150,8 @@ ERTAppView::ERTAppView(NavigationView&) { .sampling_rate = sampling_rate, .decimation_factor = 1, }); + + logger = std::make_unique("ert.txt"); } ERTAppView::~ERTAppView() { @@ -163,7 +171,9 @@ void ERTAppView::set_parent_rect(const Rect new_parent_rect) { } void ERTAppView::on_packet(const ert::Packet& packet) { - logger.on_packet(packet); + if( logger ) { + logger->on_packet(packet); + } if( packet.crc_ok() ) { recent.on_packet(packet.id(), packet); diff --git a/firmware/application/ert_app.hpp b/firmware/application/ert_app.hpp index 4b8c21d5..560e0228 100644 --- a/firmware/application/ert_app.hpp +++ b/firmware/application/ert_app.hpp @@ -60,10 +60,12 @@ struct ERTRecentEntry { class ERTLogger { public: + ERTLogger(const std::string& file_path); + void on_packet(const ert::Packet& packet); private: - LogFile log_file { "ert.txt" }; + LogFile log_file; }; using ERTRecentEntries = RecentEntries; @@ -93,7 +95,7 @@ public: private: ERTRecentEntries recent; - ERTLogger logger; + std::unique_ptr logger; ERTRecentEntriesView recent_entries_view { recent }; diff --git a/firmware/application/log_file.cpp b/firmware/application/log_file.cpp index 3b5f4f01..e87cce36 100644 --- a/firmware/application/log_file.cpp +++ b/firmware/application/log_file.cpp @@ -27,7 +27,7 @@ using namespace lpc43xx; LogFile::LogFile( - const std::string file_path + const std::string& file_path ) : file_path { file_path } { file.open_for_append(file_path); diff --git a/firmware/application/log_file.hpp b/firmware/application/log_file.hpp index 0ddf781c..30883b0f 100644 --- a/firmware/application/log_file.hpp +++ b/firmware/application/log_file.hpp @@ -32,7 +32,7 @@ using namespace lpc43xx; class LogFile { public: - LogFile(const std::string file_path); + LogFile(const std::string& file_path); ~LogFile(); bool is_ready(); diff --git a/firmware/application/tpms_app.cpp b/firmware/application/tpms_app.cpp index 55ef0811..2c436506 100644 --- a/firmware/application/tpms_app.cpp +++ b/firmware/application/tpms_app.cpp @@ -136,6 +136,12 @@ size_t Packet::crc_valid_length() const { } /* namespace tpms */ +TPMSLogger::TPMSLogger( + const std::string& file_path +) : log_file { file_path } +{ +} + void TPMSLogger::on_packet(const tpms::Packet& packet, const uint32_t target_frequency) { const auto hex_formatted = packet.symbols_formatted(); @@ -251,6 +257,8 @@ TPMSAppView::TPMSAppView(NavigationView&) { .sampling_rate = sampling_rate, .decimation_factor = 1, }); + + logger = std::make_unique("tpms.txt"); } TPMSAppView::~TPMSAppView() { @@ -270,7 +278,9 @@ void TPMSAppView::set_parent_rect(const Rect new_parent_rect) { } void TPMSAppView::on_packet(const tpms::Packet& packet) { - logger.on_packet(packet, target_frequency()); + if( logger ) { + logger->on_packet(packet, target_frequency()); + } const auto reading_opt = packet.reading(); if( reading_opt.is_valid() ) { diff --git a/firmware/application/tpms_app.hpp b/firmware/application/tpms_app.hpp index 6a06cbb3..0c2f6462 100644 --- a/firmware/application/tpms_app.hpp +++ b/firmware/application/tpms_app.hpp @@ -186,10 +186,12 @@ using TPMSRecentEntries = RecentEntries; class TPMSLogger { public: + TPMSLogger(const std::string& file_path); + void on_packet(const tpms::Packet& packet, const uint32_t target_frequency); private: - LogFile log_file { "tpms.txt" }; + LogFile log_file; }; namespace ui { @@ -217,7 +219,7 @@ private: static constexpr uint32_t baseband_bandwidth = 1750000; TPMSRecentEntries recent; - TPMSLogger logger; + std::unique_ptr logger; TPMSRecentEntriesView recent_entries_view { recent };