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.
This commit is contained in:
Jared Boone 2015-12-03 14:04:20 -08:00
parent 0909cdb31e
commit bb3cb6f080
6 changed files with 35 additions and 8 deletions

View File

@ -220,6 +220,10 @@ bool Packet::is_valid() const {
return true; return true;
} }
rtc::RTC Packet::received_at() const {
return received_at_;
}
uint32_t Packet::message_id() const { uint32_t Packet::message_id() const {
return field_.read(0, 6); 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); entry += (nibble >= 10) ? ('W' + nibble) : ('0' + nibble);
} }
log_file.write_entry(entry); log_file.write_entry(packet.received_at(), entry);
} }
return true; return true;
@ -318,7 +322,9 @@ void AISView::on_show() {
message_map.register_handler(Message::ID::AISPacket, message_map.register_handler(Message::ID::AISPacket,
[this](Message* const p) { [this](Message* const p) {
const auto message = static_cast<const AISPacketMessage*>(p); const auto message = static_cast<const AISPacketMessage*>(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) ) { if( this->model.on_packet(packet) ) {
this->log(packet); this->log(packet);
} }

View File

@ -27,6 +27,9 @@
#include "log_file.hpp" #include "log_file.hpp"
#include "field_reader.hpp" #include "field_reader.hpp"
#include "lpc43xx_cpp.hpp"
using namespace lpc43xx;
#include <cstdint> #include <cstdint>
#include <cstddef> #include <cstddef>
#include <string> #include <string>
@ -61,10 +64,12 @@ using MMSI = uint32_t;
class Packet { class Packet {
public: public:
constexpr Packet( constexpr Packet(
const rtc::RTC& received_at,
const std::bitset<1024>& payload, const std::bitset<1024>& payload,
const size_t payload_length const size_t payload_length
) : payload_ { payload }, ) : payload_ { payload },
payload_length_ { payload_length }, payload_length_ { payload_length },
received_at_ { received_at },
field_ { payload_ } field_ { payload_ }
{ {
} }
@ -73,6 +78,8 @@ public:
bool is_valid() const; bool is_valid() const;
rtc::RTC received_at() const;
uint32_t message_id() const; uint32_t message_id() const;
MMSI user_id() const; MMSI user_id() const;
MMSI source_id() const; MMSI source_id() const;
@ -89,6 +96,7 @@ public:
private: private:
const std::bitset<1024> payload_; const std::bitset<1024> payload_;
const size_t payload_length_; const size_t payload_length_;
const rtc::RTC received_at_;
const FieldReader field_; const FieldReader field_;
}; };

View File

@ -26,6 +26,9 @@ using namespace portapack;
#include "manchester.hpp" #include "manchester.hpp"
#include "lpc43xx_cpp.hpp"
using namespace lpc43xx;
ERTModel::ERTModel() { ERTModel::ERTModel() {
receiver_model.set_baseband_configuration({ receiver_model.set_baseband_configuration({
.mode = 6, .mode = 6,
@ -38,6 +41,9 @@ ERTModel::ERTModel() {
} }
std::string ERTModel::on_packet(const ERTPacketMessage& message) { std::string ERTModel::on_packet(const ERTPacketMessage& message) {
rtc::RTC received_at;
rtcGetTime(&RTCD1, &received_at);
std::string entry; std::string entry;
if( message.packet.preamble == 0x555516a3 ) { if( message.packet.preamble == 0x555516a3 ) {
@ -55,7 +61,7 @@ std::string ERTModel::on_packet(const ERTPacketMessage& message) {
entry += hex_formatted.errors; entry += hex_formatted.errors;
if( log_file.is_ready() ) { if( log_file.is_ready() ) {
log_file.write_entry(entry); log_file.write_entry(received_at, entry);
} }
return entry; return entry;

View File

@ -26,6 +26,9 @@ using namespace portapack;
#include "string_format.hpp" #include "string_format.hpp"
#include "lpc43xx_cpp.hpp"
using namespace lpc43xx;
TPMSModel::TPMSModel() { TPMSModel::TPMSModel() {
receiver_model.set_baseband_configuration({ receiver_model.set_baseband_configuration({
.mode = 5, .mode = 5,
@ -38,6 +41,9 @@ TPMSModel::TPMSModel() {
} }
ManchesterFormatted TPMSModel::on_packet(const TPMSPacketMessage& message) { 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 ManchesterDecoder decoder(message.packet.payload, message.packet.bits_received, 1);
const auto hex_formatted = format_manchester(decoder); 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); 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; 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; return hex_formatted;

View File

@ -53,9 +53,7 @@ bool LogFile::is_ready() {
return !f_error(&f); return !f_error(&f);
} }
bool LogFile::write_entry(const std::string entry) { bool LogFile::write_entry(const rtc::RTC& datetime, const std::string entry) {
rtc::RTC datetime;
rtcGetTime(&RTCD1, &datetime);
std::string timestamp = std::string timestamp =
to_string_dec_uint(datetime.year(), 4, '0') + to_string_dec_uint(datetime.year(), 4, '0') +
to_string_dec_uint(datetime.month(), 2, '0') + to_string_dec_uint(datetime.month(), 2, '0') +

View File

@ -26,6 +26,9 @@
#include "ff.h" #include "ff.h"
#include "lpc43xx_cpp.hpp"
using namespace lpc43xx;
class LogFile { class LogFile {
public: public:
~LogFile(); ~LogFile();
@ -34,7 +37,7 @@ public:
bool close(); bool close();
bool is_ready(); bool is_ready();
bool write_entry(const std::string entry); bool write_entry(const rtc::RTC& datetime, const std::string entry);
private: private:
FIL f; FIL f;