mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-12-24 23:09:26 -05:00
Move packet timestamping into baseband.
Now reads the RTC peripheral at the end of each received packet. TODO: Improve resolution to milliseconds or better. TODO: Work back from end of packet to compute timestamp for beginning of packet. TODO: Reuse ChibiOS RTC code, which isn't used now because ChibiOS on M0 core is responsible for RTC configuration, and including ChibiOS RTC API on M4 will also try to initialize/manage the peripheral.
This commit is contained in:
parent
c825a027b2
commit
b058d609eb
@ -120,9 +120,7 @@ void AISView::on_show() {
|
||||
message_map.register_handler(Message::ID::AISPacket,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const AISPacketMessage*>(p);
|
||||
rtc::RTC datetime;
|
||||
rtcGetTime(&RTCD1, &datetime);
|
||||
const ais::Packet packet { datetime, message->packet };
|
||||
const ais::Packet packet { message->packet };
|
||||
if( this->model.on_packet(packet) ) {
|
||||
this->on_packet(packet);
|
||||
}
|
||||
|
@ -26,9 +26,6 @@ using namespace portapack;
|
||||
|
||||
#include "manchester.hpp"
|
||||
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
using namespace lpc43xx;
|
||||
|
||||
#include "crc.hpp"
|
||||
#include "string_format.hpp"
|
||||
|
||||
@ -61,9 +58,7 @@ void ERTView::on_show() {
|
||||
message_map.register_handler(Message::ID::ERTPacket,
|
||||
[this](Message* const p) {
|
||||
const auto message = static_cast<const ERTPacketMessage*>(p);
|
||||
rtc::RTC datetime;
|
||||
rtcGetTime(&RTCD1, &datetime);
|
||||
const ert::Packet packet { datetime, message->type, message->packet };
|
||||
const ert::Packet packet { message->type, message->packet };
|
||||
if( this->model.on_packet(packet) ) {
|
||||
this->on_packet(packet);
|
||||
}
|
||||
|
@ -26,9 +26,6 @@ using namespace portapack;
|
||||
|
||||
#include "string_format.hpp"
|
||||
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
using namespace lpc43xx;
|
||||
|
||||
TPMSModel::TPMSModel() {
|
||||
receiver_model.set_baseband_configuration({
|
||||
.mode = 5,
|
||||
@ -41,9 +38,6 @@ TPMSModel::TPMSModel() {
|
||||
}
|
||||
|
||||
ManchesterFormatted TPMSModel::on_packet(const TPMSPacketMessage& message) {
|
||||
rtc::RTC received_at;
|
||||
rtcGetTime(&RTCD1, &received_at);
|
||||
|
||||
const ManchesterDecoder decoder(message.packet, 1);
|
||||
const auto hex_formatted = format_manchester(decoder);
|
||||
|
||||
@ -53,7 +47,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(received_at, entry);
|
||||
log_file.write_entry(message.packet.timestamp(), entry);
|
||||
}
|
||||
|
||||
return hex_formatted;
|
||||
|
@ -89,6 +89,7 @@ public:
|
||||
}
|
||||
|
||||
if( end(bit_history, packet.size()) ) {
|
||||
packet.set_timestamp(Timestamp::now());
|
||||
payload_handler(packet);
|
||||
reset_state();
|
||||
} else {
|
||||
|
@ -128,8 +128,8 @@ bool Packet::is_valid() const {
|
||||
return length_valid() && crc_ok();
|
||||
}
|
||||
|
||||
rtc::RTC Packet::received_at() const {
|
||||
return received_at_;
|
||||
Timestamp Packet::received_at() const {
|
||||
return packet_.timestamp();
|
||||
}
|
||||
|
||||
uint32_t Packet::message_id() const {
|
||||
|
@ -25,9 +25,6 @@
|
||||
#include "baseband_packet.hpp"
|
||||
#include "field_reader.hpp"
|
||||
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
using namespace lpc43xx;
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <string>
|
||||
@ -51,10 +48,8 @@ using MMSI = uint32_t;
|
||||
class Packet {
|
||||
public:
|
||||
constexpr Packet(
|
||||
const rtc::RTC& received_at,
|
||||
const baseband::Packet& packet
|
||||
) : packet_ { packet },
|
||||
received_at_ { received_at },
|
||||
field_ { packet_ }
|
||||
{
|
||||
}
|
||||
@ -63,7 +58,7 @@ public:
|
||||
|
||||
bool is_valid() const;
|
||||
|
||||
rtc::RTC received_at() const;
|
||||
Timestamp received_at() const;
|
||||
|
||||
uint32_t message_id() const;
|
||||
MMSI user_id() const;
|
||||
@ -85,7 +80,6 @@ private:
|
||||
using CRCReader = FieldReader<baseband::Packet, BitRemapNone>;
|
||||
|
||||
const baseband::Packet packet_;
|
||||
const rtc::RTC received_at_;
|
||||
const Reader field_;
|
||||
|
||||
const size_t fcs_length = 16;
|
||||
|
@ -22,6 +22,8 @@
|
||||
#ifndef __BASEBAND_PACKET_H__
|
||||
#define __BASEBAND_PACKET_H__
|
||||
|
||||
#include "baseband.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <bitset>
|
||||
|
||||
@ -29,6 +31,14 @@ namespace baseband {
|
||||
|
||||
class Packet {
|
||||
public:
|
||||
void set_timestamp(const Timestamp& value) {
|
||||
timestamp_ = value;
|
||||
}
|
||||
|
||||
Timestamp timestamp() const {
|
||||
return timestamp_;
|
||||
}
|
||||
|
||||
void add(const bool symbol) {
|
||||
if( count < capacity() ) {
|
||||
data[count++] = symbol;
|
||||
@ -53,6 +63,7 @@ public:
|
||||
|
||||
private:
|
||||
std::bitset<1408> data;
|
||||
Timestamp timestamp_ { };
|
||||
size_t count { 0 };
|
||||
};
|
||||
|
||||
|
@ -25,16 +25,50 @@
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
/* LPC43xx RTC structure. Avoiding using the ChibiOS-defined structure because
|
||||
* it pulls in all sorts of dependencies and initialization and other stuff that
|
||||
* the M0 needs to remain in control of.
|
||||
*
|
||||
* But yes, this is a hack, and something better is needed. It's too tangled of
|
||||
* a knot to tackle at the moment, though...
|
||||
*/
|
||||
#if defined(LPC43XX_M4)
|
||||
#include "lpc43xx_m4.h"
|
||||
|
||||
struct Timestamp {
|
||||
uint32_t tv_date { 0 };
|
||||
uint32_t tv_time { 0 };
|
||||
|
||||
static Timestamp now() {
|
||||
// Code stolen from LPC43xx rtc_lld.c
|
||||
Timestamp timestamp;
|
||||
do {
|
||||
timestamp.tv_time = LPC_RTC->CTIME0;
|
||||
timestamp.tv_date = LPC_RTC->CTIME1;
|
||||
} while( (timestamp.tv_time != LPC_RTC->CTIME0) || (timestamp.tv_date != LPC_RTC->CTIME1) );
|
||||
return timestamp;
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(LPC43XX_M0)
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
|
||||
using Timestamp = lpc43xx::rtc::RTC;
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
struct buffer_t {
|
||||
T* const p;
|
||||
const size_t count;
|
||||
const uint32_t sampling_rate;
|
||||
const Timestamp timestamp;
|
||||
|
||||
constexpr buffer_t(
|
||||
) : p { nullptr },
|
||||
count { 0 },
|
||||
sampling_rate { 0 }
|
||||
sampling_rate { 0 },
|
||||
timestamp { }
|
||||
{
|
||||
}
|
||||
|
||||
@ -42,17 +76,20 @@ struct buffer_t {
|
||||
const buffer_t<T>& other
|
||||
) : p { other.p },
|
||||
count { other.count },
|
||||
sampling_rate { other.sampling_rate }
|
||||
sampling_rate { other.sampling_rate },
|
||||
timestamp { other.timestamp }
|
||||
{
|
||||
}
|
||||
|
||||
constexpr buffer_t(
|
||||
T* const p,
|
||||
const size_t count,
|
||||
const uint32_t sampling_rate = 0
|
||||
const uint32_t sampling_rate = 0,
|
||||
const Timestamp timestamp = { }
|
||||
) : p { p },
|
||||
count { count },
|
||||
sampling_rate { sampling_rate }
|
||||
sampling_rate { sampling_rate },
|
||||
timestamp { timestamp }
|
||||
{
|
||||
}
|
||||
};
|
||||
|
@ -33,8 +33,8 @@ bool Packet::is_valid() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
rtc::RTC Packet::received_at() const {
|
||||
return received_at_;
|
||||
Timestamp Packet::received_at() const {
|
||||
return packet_.timestamp();
|
||||
}
|
||||
|
||||
Packet::Type Packet::type() const {
|
||||
|
@ -29,9 +29,6 @@
|
||||
#include "baseband_packet.hpp"
|
||||
#include "manchester.hpp"
|
||||
|
||||
#include "lpc43xx_cpp.hpp"
|
||||
using namespace lpc43xx;
|
||||
|
||||
namespace ert {
|
||||
|
||||
using ID = uint32_t;
|
||||
@ -46,11 +43,9 @@ public:
|
||||
};
|
||||
|
||||
Packet(
|
||||
const rtc::RTC& received_at,
|
||||
const Type type,
|
||||
const baseband::Packet& packet
|
||||
) : packet_ { packet },
|
||||
received_at_ { received_at },
|
||||
decoder_ { packet_ },
|
||||
reader_ { decoder_ },
|
||||
type_ { type }
|
||||
@ -61,7 +56,7 @@ public:
|
||||
|
||||
bool is_valid() const;
|
||||
|
||||
rtc::RTC received_at() const;
|
||||
Timestamp received_at() const;
|
||||
|
||||
Type type() const;
|
||||
ID id() const;
|
||||
@ -75,7 +70,6 @@ private:
|
||||
using Reader = FieldReader<ManchesterDecoder, BitRemapNone>;
|
||||
|
||||
const baseband::Packet packet_;
|
||||
const rtc::RTC received_at_;
|
||||
const ManchesterDecoder decoder_;
|
||||
const Reader reader_;
|
||||
const Type type_;
|
||||
|
Loading…
Reference in New Issue
Block a user