mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
LogFile puts timestamp before entry, CRLF after.
This commit is contained in:
parent
76845c4335
commit
bfcd25d857
@ -299,8 +299,7 @@ bool AISModel::on_packet(const baseband::ais::Packet& packet) {
|
||||
entry += (nibble >= 10) ? ('W' + nibble) : ('0' + nibble);
|
||||
}
|
||||
|
||||
entry += "\r\n";
|
||||
log_file.write(entry);
|
||||
log_file.write_entry(entry);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -38,29 +38,27 @@ ERTModel::ERTModel() {
|
||||
}
|
||||
|
||||
std::string ERTModel::on_packet(const ERTPacketMessage& message) {
|
||||
std::string s;
|
||||
std::string entry;
|
||||
|
||||
if( message.packet.preamble == 0x555516a3 ) {
|
||||
s += "IDM\n";
|
||||
entry += "IDM ";
|
||||
}
|
||||
if( message.packet.preamble == 0x1f2a60 ) {
|
||||
s += "SCM\n";
|
||||
entry += "SCM ";
|
||||
}
|
||||
|
||||
const ManchesterDecoder decoder(message.packet.payload, message.packet.bits_received);
|
||||
|
||||
const auto hex_formatted = format_manchester(decoder);
|
||||
s += hex_formatted.data;
|
||||
s += "\n";
|
||||
s += hex_formatted.errors;
|
||||
s += "\n";
|
||||
entry += hex_formatted.data;
|
||||
entry += "/";
|
||||
entry += hex_formatted.errors;
|
||||
|
||||
if( log_file.is_ready() ) {
|
||||
std::string entry = hex_formatted.data + "/" + hex_formatted.errors + "\r\n";
|
||||
log_file.write(entry);
|
||||
log_file.write_entry(entry);
|
||||
}
|
||||
|
||||
return s;
|
||||
return entry;
|
||||
}
|
||||
|
||||
namespace ui {
|
||||
|
@ -24,10 +24,6 @@
|
||||
#include "portapack.hpp"
|
||||
using namespace portapack;
|
||||
|
||||
#include <hal.h>
|
||||
// #include "lpc43xx_cpp.hpp"
|
||||
// using namespace lpc43xx;
|
||||
|
||||
#include "string_format.hpp"
|
||||
|
||||
TPMSModel::TPMSModel() {
|
||||
@ -46,22 +42,12 @@ ManchesterFormatted TPMSModel::on_packet(const TPMSPacketMessage& message) {
|
||||
const auto hex_formatted = format_manchester(decoder);
|
||||
|
||||
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();
|
||||
// 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);
|
||||
|
||||
std::string log = timestamp + " " + tuning_frequency_str + " FSK 38.4 19.2 " + hex_formatted.data + "/" + hex_formatted.errors + "\r\n";
|
||||
log_file.write(log);
|
||||
std::string entry = tuning_frequency_str + " FSK 38.4 19.2 " + hex_formatted.data + "/" + hex_formatted.errors;
|
||||
log_file.write_entry(entry);
|
||||
}
|
||||
|
||||
return hex_formatted;
|
||||
|
@ -21,6 +21,11 @@
|
||||
|
||||
#include "log_file.hpp"
|
||||
|
||||
#include "string_format.hpp"
|
||||
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
using namespace lpc43xx;
|
||||
|
||||
LogFile::~LogFile() {
|
||||
close();
|
||||
}
|
||||
@ -48,6 +53,20 @@ bool LogFile::is_ready() {
|
||||
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) {
|
||||
const auto puts_result = f_puts(message.c_str(), &f);
|
||||
const auto sync_result = f_sync(&f);
|
||||
|
@ -33,10 +33,13 @@ public:
|
||||
bool open_for_append(const std::string file_path);
|
||||
bool close();
|
||||
bool is_ready();
|
||||
bool write(const std::string message);
|
||||
|
||||
bool write_entry(const std::string entry);
|
||||
|
||||
private:
|
||||
FIL f;
|
||||
|
||||
bool write(const std::string message);
|
||||
};
|
||||
|
||||
#endif/*__LOG_FILE_H__*/
|
||||
|
Loading…
Reference in New Issue
Block a user