Extract LogFile, add (dumb) logging to ERT, AIS apps.

This commit is contained in:
Jared Boone 2015-12-01 22:39:27 -08:00
parent 29f2d0e50a
commit 57aed55cc7
9 changed files with 128 additions and 31 deletions

View File

@ -175,6 +175,7 @@ CPPSRC = main.cpp \
app_ert.cpp \ app_ert.cpp \
app_spectrum_analysis.cpp \ app_spectrum_analysis.cpp \
sd_card.cpp \ sd_card.cpp \
log_file.cpp \
manchester.cpp \ manchester.cpp \
../common/utility.cpp \ ../common/utility.cpp \
../common/chibios_cpp.cpp \ ../common/chibios_cpp.cpp \

View File

@ -31,10 +31,19 @@ AISModel::AISModel() {
.decimation_factor = 4, .decimation_factor = 4,
}); });
receiver_model.set_baseband_bandwidth(1750000); receiver_model.set_baseband_bandwidth(1750000);
log_file.open_for_append("ais.txt");
} }
baseband::ais::decoded_packet AISModel::on_packet(const AISPacketMessage& message) { baseband::ais::decoded_packet AISModel::on_packet(const AISPacketMessage& message) {
return baseband::ais::packet_decode(message.packet.payload, message.packet.bits_received); const auto result = baseband::ais::packet_decode(message.packet.payload, message.packet.bits_received);
if( log_file.is_ready() ) {
std::string entry = result.first + "/" + result.second + "\r\n";
log_file.write(entry);
}
return result;
} }
namespace ui { namespace ui {

View File

@ -24,6 +24,7 @@
#include "ui_console.hpp" #include "ui_console.hpp"
#include "message.hpp" #include "message.hpp"
#include "log_file.hpp"
#include "ais_baseband.hpp" #include "ais_baseband.hpp"
@ -32,6 +33,9 @@ public:
AISModel(); AISModel();
baseband::ais::decoded_packet on_packet(const AISPacketMessage& message); baseband::ais::decoded_packet on_packet(const AISPacketMessage& message);
private:
LogFile log_file;
}; };
namespace ui { namespace ui {

View File

@ -33,6 +33,8 @@ ERTModel::ERTModel() {
.decimation_factor = 1, .decimation_factor = 1,
}); });
receiver_model.set_baseband_bandwidth(1750000); receiver_model.set_baseband_bandwidth(1750000);
log_file.open_for_append("ert.txt");
} }
std::string ERTModel::on_packet(const ERTPacketMessage& message) { std::string ERTModel::on_packet(const ERTPacketMessage& message) {
@ -53,6 +55,11 @@ std::string ERTModel::on_packet(const ERTPacketMessage& message) {
s += hex_formatted.errors; s += hex_formatted.errors;
s += "\n"; s += "\n";
if( log_file.is_ready() ) {
std::string entry = hex_formatted.data + "/" + hex_formatted.errors + "\r\n";
log_file.write(entry);
}
return s; return s;
} }

View File

@ -24,6 +24,7 @@
#include "ui_console.hpp" #include "ui_console.hpp"
#include "message.hpp" #include "message.hpp"
#include "log_file.hpp"
#include <string> #include <string>
@ -32,6 +33,9 @@ public:
ERTModel(); ERTModel();
std::string on_packet(const ERTPacketMessage& message); std::string on_packet(const ERTPacketMessage& message);
private:
LogFile log_file;
}; };
namespace ui { namespace ui {

View File

@ -39,18 +39,14 @@ TPMSModel::TPMSModel() {
}); });
receiver_model.set_baseband_bandwidth(1750000); receiver_model.set_baseband_bandwidth(1750000);
open_file(); log_file.open_for_append("tpms.txt");
}
TPMSModel::~TPMSModel() {
f_close(&fil);
} }
ManchesterFormatted TPMSModel::on_packet(const TPMSPacketMessage& message) { ManchesterFormatted TPMSModel::on_packet(const TPMSPacketMessage& message) {
const ManchesterDecoder decoder(message.packet.payload, message.packet.bits_received, 1); const ManchesterDecoder decoder(message.packet.payload, message.packet.bits_received, 1);
const auto hex_formatted = format_manchester(decoder); const auto hex_formatted = format_manchester(decoder);
if( !f_error(&fil) ) { if( log_file.is_ready() ) {
rtc::RTC datetime; rtc::RTC datetime;
rtcGetTime(&RTCD1, &datetime); rtcGetTime(&RTCD1, &datetime);
std::string timestamp = std::string timestamp =
@ -66,29 +62,12 @@ ManchesterFormatted TPMSModel::on_packet(const TPMSPacketMessage& message) {
const auto tuning_frequency_str = ui::to_string_dec_uint(tuning_frequency, 10); const auto tuning_frequency_str = ui::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 log = timestamp + " " + tuning_frequency_str + " FSK 38.4 19.2 " + hex_formatted.data + "/" + hex_formatted.errors + "\r\n";
f_puts(log.c_str(), &fil); log_file.write(log);
f_sync(&fil);
} }
return hex_formatted; return hex_formatted;
} }
void TPMSModel::open_file() {
const auto open_result = f_open(&fil, "tpms.txt", FA_WRITE | FA_OPEN_ALWAYS);
if( open_result == FR_OK ) {
const auto fil_size = f_size(&fil);
const auto seek_result = f_lseek(&fil, fil_size);
if( seek_result != FR_OK ) {
f_close(&fil);
// TODO: Error, indicate somehow.
} else {
// TODO: Indicate success.
}
} else {
// TODO: Error, indicate somehow.
}
}
namespace ui { namespace ui {
void TPMSView::on_show() { void TPMSView::on_show() {

View File

@ -26,20 +26,16 @@
#include "message.hpp" #include "message.hpp"
#include "manchester.hpp" #include "manchester.hpp"
#include "log_file.hpp"
#include "ff.h"
class TPMSModel { class TPMSModel {
public: public:
TPMSModel(); TPMSModel();
~TPMSModel();
ManchesterFormatted on_packet(const TPMSPacketMessage& message); ManchesterFormatted on_packet(const TPMSPacketMessage& message);
private: private:
FIL fil; LogFile log_file;
void open_file();
}; };
namespace ui { namespace ui {

View File

@ -0,0 +1,55 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#include "log_file.hpp"
LogFile::~LogFile() {
close();
}
bool LogFile::open_for_append(const std::string file_path) {
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));
if( seek_result == FR_OK ) {
return true;
} else {
close();
}
}
return false;
}
bool LogFile::close() {
f_close(&f);
return true;
}
bool LogFile::is_ready() {
return !f_error(&f);
}
bool LogFile::write(const std::string message) {
const auto puts_result = f_puts(message.c_str(), &f);
const auto sync_result = f_sync(&f);
return (puts_result >= 0) && (sync_result == FR_OK);
}

View File

@ -0,0 +1,42 @@
/*
* Copyright (C) 2015 Jared Boone, ShareBrained Technology, Inc.
*
* This file is part of PortaPack.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; see the file COPYING. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street,
* Boston, MA 02110-1301, USA.
*/
#ifndef __LOG_FILE_H__
#define __LOG_FILE_H__
#include <string>
#include "ff.h"
class LogFile {
public:
~LogFile();
bool open_for_append(const std::string file_path);
bool close();
bool is_ready();
bool write(const std::string message);
private:
FIL f;
};
#endif/*__LOG_FILE_H__*/