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:
Jared Boone 2016-01-13 23:11:19 -08:00
parent 30ca545b52
commit bd07e4e7e5
8 changed files with 34 additions and 15 deletions

View File

@ -80,10 +80,6 @@ static std::string navigational_status(const unsigned int value) {
} /* namespace format */
} /* namespace ais */
AISLogger::AISLogger() {
log_file.open_for_append("ais.txt");
}
void AISLogger::on_packet(const ais::Packet& packet) {
// TODO: Unstuff here, not in baseband!
if( log_file.is_ready() ) {

View File

@ -98,12 +98,10 @@ private:
class AISLogger {
public:
AISLogger();
void on_packet(const ais::Packet& packet);
private:
LogFile log_file;
LogFile log_file { "ais.txt" };
};
namespace ui {

View File

@ -38,8 +38,6 @@ ERTModel::ERTModel() {
.decimation_factor = 1,
});
receiver_model.set_baseband_bandwidth(2500000);
log_file.open_for_append("ert.txt");
}
bool ERTModel::on_packet(const ert::Packet& packet) {

View File

@ -38,7 +38,7 @@ public:
bool on_packet(const ert::Packet& packet);
private:
LogFile log_file;
LogFile log_file { "ert.txt" };
};
namespace ui {

View File

@ -26,11 +26,24 @@
#include "lpc43xx_cpp.hpp"
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() {
sd_card::status_signal -= sd_card_status_signal_token;
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);
if( open_result == FR_OK ) {
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);
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();
}
}

View File

@ -25,24 +25,32 @@
#include <string>
#include "ff.h"
#include "sd_card.hpp"
#include "lpc43xx_cpp.hpp"
using namespace lpc43xx;
class LogFile {
public:
LogFile(const std::string file_path);
~LogFile();
bool open_for_append(const std::string& file_path);
bool open();
bool close();
bool is_ready();
bool write_entry(const rtc::RTC& datetime, const std::string& entry);
private:
const std::string file_path;
FIL f;
SignalToken sd_card_status_signal_token;
bool write(const std::string& message);
void on_sd_card_status(const sd_card::Status status);
};
#endif/*__LOG_FILE_H__*/

View File

@ -35,8 +35,6 @@ TPMSModel::TPMSModel() {
.decimation_factor = 1,
});
receiver_model.set_baseband_bandwidth(1750000);
log_file.open_for_append("tpms.txt");
}
ManchesterFormatted TPMSModel::on_packet(const TPMSPacketMessage& message) {

View File

@ -35,7 +35,7 @@ public:
ManchesterFormatted on_packet(const TPMSPacketMessage& message);
private:
LogFile log_file;
LogFile log_file { "tpms.txt" };
};
namespace ui {