LogFile puts timestamp before entry, CRLF after.

This commit is contained in:
Jared Boone 2015-12-02 14:05:25 -08:00
parent 76845c4335
commit bfcd25d857
5 changed files with 34 additions and 29 deletions

View File

@ -299,8 +299,7 @@ bool AISModel::on_packet(const baseband::ais::Packet& packet) {
entry += (nibble >= 10) ? ('W' + nibble) : ('0' + nibble); entry += (nibble >= 10) ? ('W' + nibble) : ('0' + nibble);
} }
entry += "\r\n"; log_file.write_entry(entry);
log_file.write(entry);
} }
return true; return true;

View File

@ -38,29 +38,27 @@ ERTModel::ERTModel() {
} }
std::string ERTModel::on_packet(const ERTPacketMessage& message) { std::string ERTModel::on_packet(const ERTPacketMessage& message) {
std::string s; std::string entry;
if( message.packet.preamble == 0x555516a3 ) { if( message.packet.preamble == 0x555516a3 ) {
s += "IDM\n"; entry += "IDM ";
} }
if( message.packet.preamble == 0x1f2a60 ) { if( message.packet.preamble == 0x1f2a60 ) {
s += "SCM\n"; entry += "SCM ";
} }
const ManchesterDecoder decoder(message.packet.payload, message.packet.bits_received); const ManchesterDecoder decoder(message.packet.payload, message.packet.bits_received);
const auto hex_formatted = format_manchester(decoder); const auto hex_formatted = format_manchester(decoder);
s += hex_formatted.data; entry += hex_formatted.data;
s += "\n"; entry += "/";
s += hex_formatted.errors; entry += hex_formatted.errors;
s += "\n";
if( log_file.is_ready() ) { if( log_file.is_ready() ) {
std::string entry = hex_formatted.data + "/" + hex_formatted.errors + "\r\n"; log_file.write_entry(entry);
log_file.write(entry);
} }
return s; return entry;
} }
namespace ui { namespace ui {

View File

@ -24,10 +24,6 @@
#include "portapack.hpp" #include "portapack.hpp"
using namespace portapack; using namespace portapack;
#include <hal.h>
// #include "lpc43xx_cpp.hpp"
// using namespace lpc43xx;
#include "string_format.hpp" #include "string_format.hpp"
TPMSModel::TPMSModel() { TPMSModel::TPMSModel() {
@ -46,22 +42,12 @@ ManchesterFormatted TPMSModel::on_packet(const TPMSPacketMessage& message) {
const auto hex_formatted = format_manchester(decoder); const auto hex_formatted = format_manchester(decoder);
if( log_file.is_ready() ) { if( log_file.is_ready() ) {
rtc::RTC datetime;
rtcGetTime(&RTCD1, &datetime);
std::string timestamp =
to_string_dec_uint(datetime.year(), 4, '0') +
to_string_dec_uint(datetime.month(), 2, '0') +
to_string_dec_uint(datetime.day(), 2, '0') +
to_string_dec_uint(datetime.hour(), 2, '0') +
to_string_dec_uint(datetime.minute(), 2, '0') +
to_string_dec_uint(datetime.second(), 2, '0');
const auto tuning_frequency = receiver_model.tuning_frequency(); const auto tuning_frequency = receiver_model.tuning_frequency();
// TODO: function doesn't take uint64_t, so when >= 1<<32, weirdness will ensue! // TODO: function doesn't take uint64_t, so when >= 1<<32, weirdness will ensue!
const auto tuning_frequency_str = to_string_dec_uint(tuning_frequency, 10); const auto tuning_frequency_str = to_string_dec_uint(tuning_frequency, 10);
std::string log = timestamp + " " + tuning_frequency_str + " FSK 38.4 19.2 " + hex_formatted.data + "/" + hex_formatted.errors + "\r\n"; std::string entry = tuning_frequency_str + " FSK 38.4 19.2 " + hex_formatted.data + "/" + hex_formatted.errors;
log_file.write(log); log_file.write_entry(entry);
} }
return hex_formatted; return hex_formatted;

View File

@ -21,6 +21,11 @@
#include "log_file.hpp" #include "log_file.hpp"
#include "string_format.hpp"
#include "lpc43xx_cpp.hpp"
using namespace lpc43xx;
LogFile::~LogFile() { LogFile::~LogFile() {
close(); close();
} }
@ -48,6 +53,20 @@ bool LogFile::is_ready() {
return !f_error(&f); return !f_error(&f);
} }
bool LogFile::write_entry(const std::string entry) {
rtc::RTC datetime;
rtcGetTime(&RTCD1, &datetime);
std::string timestamp =
to_string_dec_uint(datetime.year(), 4, '0') +
to_string_dec_uint(datetime.month(), 2, '0') +
to_string_dec_uint(datetime.day(), 2, '0') +
to_string_dec_uint(datetime.hour(), 2, '0') +
to_string_dec_uint(datetime.minute(), 2, '0') +
to_string_dec_uint(datetime.second(), 2, '0');
return write(timestamp + " " + entry + "\r\n");
}
bool LogFile::write(const std::string message) { bool LogFile::write(const std::string message) {
const auto puts_result = f_puts(message.c_str(), &f); const auto puts_result = f_puts(message.c_str(), &f);
const auto sync_result = f_sync(&f); const auto sync_result = f_sync(&f);

View File

@ -33,10 +33,13 @@ public:
bool open_for_append(const std::string file_path); bool open_for_append(const std::string file_path);
bool close(); bool close();
bool is_ready(); bool is_ready();
bool write(const std::string message);
bool write_entry(const std::string entry);
private: private:
FIL f; FIL f;
bool write(const std::string message);
}; };
#endif/*__LOG_FILE_H__*/ #endif/*__LOG_FILE_H__*/