mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
Modify LogFile to open/close file on SD card status.
Previously, would only open on construction, which was only when the receiver mode changed, which wasn't all that useful.
This commit is contained in:
parent
30ca545b52
commit
bd07e4e7e5
@ -80,10 +80,6 @@ static std::string navigational_status(const unsigned int value) {
|
|||||||
} /* namespace format */
|
} /* namespace format */
|
||||||
} /* namespace ais */
|
} /* namespace ais */
|
||||||
|
|
||||||
AISLogger::AISLogger() {
|
|
||||||
log_file.open_for_append("ais.txt");
|
|
||||||
}
|
|
||||||
|
|
||||||
void AISLogger::on_packet(const ais::Packet& packet) {
|
void AISLogger::on_packet(const ais::Packet& packet) {
|
||||||
// TODO: Unstuff here, not in baseband!
|
// TODO: Unstuff here, not in baseband!
|
||||||
if( log_file.is_ready() ) {
|
if( log_file.is_ready() ) {
|
||||||
|
@ -98,12 +98,10 @@ private:
|
|||||||
|
|
||||||
class AISLogger {
|
class AISLogger {
|
||||||
public:
|
public:
|
||||||
AISLogger();
|
|
||||||
|
|
||||||
void on_packet(const ais::Packet& packet);
|
void on_packet(const ais::Packet& packet);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LogFile log_file;
|
LogFile log_file { "ais.txt" };
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
@ -38,8 +38,6 @@ ERTModel::ERTModel() {
|
|||||||
.decimation_factor = 1,
|
.decimation_factor = 1,
|
||||||
});
|
});
|
||||||
receiver_model.set_baseband_bandwidth(2500000);
|
receiver_model.set_baseband_bandwidth(2500000);
|
||||||
|
|
||||||
log_file.open_for_append("ert.txt");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ERTModel::on_packet(const ert::Packet& packet) {
|
bool ERTModel::on_packet(const ert::Packet& packet) {
|
||||||
|
@ -38,7 +38,7 @@ public:
|
|||||||
bool on_packet(const ert::Packet& packet);
|
bool on_packet(const ert::Packet& packet);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LogFile log_file;
|
LogFile log_file { "ert.txt" };
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
@ -26,11 +26,24 @@
|
|||||||
#include "lpc43xx_cpp.hpp"
|
#include "lpc43xx_cpp.hpp"
|
||||||
using namespace lpc43xx;
|
using namespace lpc43xx;
|
||||||
|
|
||||||
|
LogFile::LogFile(
|
||||||
|
const std::string file_path
|
||||||
|
) : file_path { file_path }
|
||||||
|
{
|
||||||
|
open();
|
||||||
|
|
||||||
|
sd_card_status_signal_token = sd_card::status_signal += [this](const sd_card::Status status) {
|
||||||
|
this->on_sd_card_status(status);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
LogFile::~LogFile() {
|
LogFile::~LogFile() {
|
||||||
|
sd_card::status_signal -= sd_card_status_signal_token;
|
||||||
|
|
||||||
close();
|
close();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LogFile::open_for_append(const std::string& file_path) {
|
bool LogFile::open() {
|
||||||
const auto open_result = f_open(&f, file_path.c_str(), FA_WRITE | FA_OPEN_ALWAYS);
|
const auto open_result = f_open(&f, file_path.c_str(), FA_WRITE | FA_OPEN_ALWAYS);
|
||||||
if( open_result == FR_OK ) {
|
if( open_result == FR_OK ) {
|
||||||
const auto seek_result = f_lseek(&f, f_size(&f));
|
const auto seek_result = f_lseek(&f, f_size(&f));
|
||||||
@ -70,3 +83,11 @@ bool LogFile::write(const std::string& message) {
|
|||||||
const auto sync_result = f_sync(&f);
|
const auto sync_result = f_sync(&f);
|
||||||
return (puts_result >= 0) && (sync_result == FR_OK);
|
return (puts_result >= 0) && (sync_result == FR_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void LogFile::on_sd_card_status(const sd_card::Status status) {
|
||||||
|
if( status == sd_card::Status::Mounted ) {
|
||||||
|
open();
|
||||||
|
} else {
|
||||||
|
close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -25,24 +25,32 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "ff.h"
|
#include "ff.h"
|
||||||
|
#include "sd_card.hpp"
|
||||||
|
|
||||||
#include "lpc43xx_cpp.hpp"
|
#include "lpc43xx_cpp.hpp"
|
||||||
using namespace lpc43xx;
|
using namespace lpc43xx;
|
||||||
|
|
||||||
class LogFile {
|
class LogFile {
|
||||||
public:
|
public:
|
||||||
|
LogFile(const std::string file_path);
|
||||||
~LogFile();
|
~LogFile();
|
||||||
|
|
||||||
bool open_for_append(const std::string& file_path);
|
bool open();
|
||||||
bool close();
|
bool close();
|
||||||
bool is_ready();
|
bool is_ready();
|
||||||
|
|
||||||
bool write_entry(const rtc::RTC& datetime, const std::string& entry);
|
bool write_entry(const rtc::RTC& datetime, const std::string& entry);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
const std::string file_path;
|
||||||
|
|
||||||
FIL f;
|
FIL f;
|
||||||
|
|
||||||
|
SignalToken sd_card_status_signal_token;
|
||||||
|
|
||||||
bool write(const std::string& message);
|
bool write(const std::string& message);
|
||||||
|
|
||||||
|
void on_sd_card_status(const sd_card::Status status);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif/*__LOG_FILE_H__*/
|
#endif/*__LOG_FILE_H__*/
|
||||||
|
@ -35,8 +35,6 @@ TPMSModel::TPMSModel() {
|
|||||||
.decimation_factor = 1,
|
.decimation_factor = 1,
|
||||||
});
|
});
|
||||||
receiver_model.set_baseband_bandwidth(1750000);
|
receiver_model.set_baseband_bandwidth(1750000);
|
||||||
|
|
||||||
log_file.open_for_append("tpms.txt");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ManchesterFormatted TPMSModel::on_packet(const TPMSPacketMessage& message) {
|
ManchesterFormatted TPMSModel::on_packet(const TPMSPacketMessage& message) {
|
||||||
|
@ -35,7 +35,7 @@ public:
|
|||||||
ManchesterFormatted on_packet(const TPMSPacketMessage& message);
|
ManchesterFormatted on_packet(const TPMSPacketMessage& message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
LogFile log_file;
|
LogFile log_file { "tpms.txt" };
|
||||||
};
|
};
|
||||||
|
|
||||||
namespace ui {
|
namespace ui {
|
||||||
|
Loading…
Reference in New Issue
Block a user