From bb3cb6f0802fe2beef05edc64c376898e19fa541 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Thu, 3 Dec 2015 14:04:20 -0800 Subject: [PATCH] Push packet timestamping earlier in packet handling. Ideally, it'd get pushed back into baseband, and baseband would correct for the length of the packet (based on preamble/access code match timestamp minus preamble/access code duration) to give the exact time the packet started. --- firmware/application/app_ais.cpp | 10 ++++++++-- firmware/application/app_ais.hpp | 8 ++++++++ firmware/application/app_ert.cpp | 8 +++++++- firmware/application/app_tpms.cpp | 8 +++++++- firmware/application/log_file.cpp | 4 +--- firmware/application/log_file.hpp | 5 ++++- 6 files changed, 35 insertions(+), 8 deletions(-) diff --git a/firmware/application/app_ais.cpp b/firmware/application/app_ais.cpp index df5b36f1..1afbb06f 100644 --- a/firmware/application/app_ais.cpp +++ b/firmware/application/app_ais.cpp @@ -220,6 +220,10 @@ bool Packet::is_valid() const { return true; } +rtc::RTC Packet::received_at() const { + return received_at_; +} + uint32_t Packet::message_id() const { return field_.read(0, 6); } @@ -303,7 +307,7 @@ bool AISModel::on_packet(const baseband::ais::Packet& packet) { entry += (nibble >= 10) ? ('W' + nibble) : ('0' + nibble); } - log_file.write_entry(entry); + log_file.write_entry(packet.received_at(), entry); } return true; @@ -318,7 +322,9 @@ void AISView::on_show() { message_map.register_handler(Message::ID::AISPacket, [this](Message* const p) { const auto message = static_cast(p); - const baseband::ais::Packet packet { message->packet.payload, message->packet.bits_received }; + rtc::RTC datetime; + rtcGetTime(&RTCD1, &datetime); + const baseband::ais::Packet packet { datetime, message->packet.payload, message->packet.bits_received }; if( this->model.on_packet(packet) ) { this->log(packet); } diff --git a/firmware/application/app_ais.hpp b/firmware/application/app_ais.hpp index b5739ce2..1bd7c763 100644 --- a/firmware/application/app_ais.hpp +++ b/firmware/application/app_ais.hpp @@ -27,6 +27,9 @@ #include "log_file.hpp" #include "field_reader.hpp" +#include "lpc43xx_cpp.hpp" +using namespace lpc43xx; + #include #include #include @@ -61,10 +64,12 @@ using MMSI = uint32_t; class Packet { public: constexpr Packet( + const rtc::RTC& received_at, const std::bitset<1024>& payload, const size_t payload_length ) : payload_ { payload }, payload_length_ { payload_length }, + received_at_ { received_at }, field_ { payload_ } { } @@ -73,6 +78,8 @@ public: bool is_valid() const; + rtc::RTC received_at() const; + uint32_t message_id() const; MMSI user_id() const; MMSI source_id() const; @@ -89,6 +96,7 @@ public: private: const std::bitset<1024> payload_; const size_t payload_length_; + const rtc::RTC received_at_; const FieldReader field_; }; diff --git a/firmware/application/app_ert.cpp b/firmware/application/app_ert.cpp index ae21df4b..755bbcfe 100644 --- a/firmware/application/app_ert.cpp +++ b/firmware/application/app_ert.cpp @@ -26,6 +26,9 @@ using namespace portapack; #include "manchester.hpp" +#include "lpc43xx_cpp.hpp" +using namespace lpc43xx; + ERTModel::ERTModel() { receiver_model.set_baseband_configuration({ .mode = 6, @@ -38,6 +41,9 @@ ERTModel::ERTModel() { } std::string ERTModel::on_packet(const ERTPacketMessage& message) { + rtc::RTC received_at; + rtcGetTime(&RTCD1, &received_at); + std::string entry; if( message.packet.preamble == 0x555516a3 ) { @@ -55,7 +61,7 @@ std::string ERTModel::on_packet(const ERTPacketMessage& message) { entry += hex_formatted.errors; if( log_file.is_ready() ) { - log_file.write_entry(entry); + log_file.write_entry(received_at, entry); } return entry; diff --git a/firmware/application/app_tpms.cpp b/firmware/application/app_tpms.cpp index 3df0a0e5..a02aaf3c 100644 --- a/firmware/application/app_tpms.cpp +++ b/firmware/application/app_tpms.cpp @@ -26,6 +26,9 @@ using namespace portapack; #include "string_format.hpp" +#include "lpc43xx_cpp.hpp" +using namespace lpc43xx; + TPMSModel::TPMSModel() { receiver_model.set_baseband_configuration({ .mode = 5, @@ -38,6 +41,9 @@ TPMSModel::TPMSModel() { } ManchesterFormatted TPMSModel::on_packet(const TPMSPacketMessage& message) { + rtc::RTC received_at; + rtcGetTime(&RTCD1, &received_at); + const ManchesterDecoder decoder(message.packet.payload, message.packet.bits_received, 1); const auto hex_formatted = format_manchester(decoder); @@ -47,7 +53,7 @@ ManchesterFormatted TPMSModel::on_packet(const TPMSPacketMessage& message) { const auto tuning_frequency_str = to_string_dec_uint(tuning_frequency, 10); std::string entry = tuning_frequency_str + " FSK 38.4 19.2 " + hex_formatted.data + "/" + hex_formatted.errors; - log_file.write_entry(entry); + log_file.write_entry(received_at, entry); } return hex_formatted; diff --git a/firmware/application/log_file.cpp b/firmware/application/log_file.cpp index 3225ea45..a32149f1 100644 --- a/firmware/application/log_file.cpp +++ b/firmware/application/log_file.cpp @@ -53,9 +53,7 @@ bool LogFile::is_ready() { return !f_error(&f); } -bool LogFile::write_entry(const std::string entry) { - rtc::RTC datetime; - rtcGetTime(&RTCD1, &datetime); +bool LogFile::write_entry(const rtc::RTC& datetime, const std::string entry) { std::string timestamp = to_string_dec_uint(datetime.year(), 4, '0') + to_string_dec_uint(datetime.month(), 2, '0') + diff --git a/firmware/application/log_file.hpp b/firmware/application/log_file.hpp index 2e4708dd..cf7dcf4d 100644 --- a/firmware/application/log_file.hpp +++ b/firmware/application/log_file.hpp @@ -26,6 +26,9 @@ #include "ff.h" +#include "lpc43xx_cpp.hpp" +using namespace lpc43xx; + class LogFile { public: ~LogFile(); @@ -34,7 +37,7 @@ public: bool close(); bool is_ready(); - bool write_entry(const std::string entry); + bool write_entry(const rtc::RTC& datetime, const std::string entry); private: FIL f;