mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Create log files on heap.
...for imminent refactor where user can manually start/stop logging, and maybe even change the filename! *swoon*
This commit is contained in:
parent
58864ebbe7
commit
937dad62ee
@ -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<AISLogger>("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();
|
||||
|
||||
|
@ -90,10 +90,12 @@ using AISRecentEntries = RecentEntries<ais::Packet, AISRecentEntry>;
|
||||
|
||||
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<AISLogger> logger;
|
||||
|
||||
AISRecentEntriesView recent_entries_view { recent };
|
||||
AISRecentEntryDetailView recent_entry_detail_view;
|
||||
|
@ -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<ERTLogger>("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);
|
||||
|
@ -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<ert::Packet, ERTRecentEntry>;
|
||||
@ -93,7 +95,7 @@ public:
|
||||
|
||||
private:
|
||||
ERTRecentEntries recent;
|
||||
ERTLogger logger;
|
||||
std::unique_ptr<ERTLogger> logger;
|
||||
|
||||
ERTRecentEntriesView recent_entries_view { recent };
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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<TPMSLogger>("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() ) {
|
||||
|
@ -186,10 +186,12 @@ using TPMSRecentEntries = RecentEntries<tpms::Reading, TPMSRecentEntry>;
|
||||
|
||||
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<TPMSLogger> logger;
|
||||
|
||||
TPMSRecentEntriesView recent_entries_view { recent };
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user