From 14f69f9c915cf644147a52b803d79ff8f40a4ea1 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 29 Jul 2019 15:27:32 +0200 Subject: First prototype taking EDI TIST into account for contribution --- lib/edi/STIWriter.cpp | 1 + lib/edi/common.cpp | 25 ++++++++++++++++++++++++- lib/edi/common.hpp | 4 ++++ 3 files changed, 29 insertions(+), 1 deletion(-) (limited to 'lib/edi') diff --git a/lib/edi/STIWriter.cpp b/lib/edi/STIWriter.cpp index 6964eb1..399922a 100644 --- a/lib/edi/STIWriter.cpp +++ b/lib/edi/STIWriter.cpp @@ -120,6 +120,7 @@ void STIWriter::assemble() m_stiFrame.frame = m_payload.istd; m_stiFrame.timestamp.seconds = m_seconds; m_stiFrame.timestamp.utco = m_utco; + m_stiFrame.timestamp.tsta = m_management_data.tsta; } sti_frame_t STIWriter::getFrame() diff --git a/lib/edi/common.cpp b/lib/edi/common.cpp index bc0fa1b..b4b0c79 100644 --- a/lib/edi/common.cpp +++ b/lib/edi/common.cpp @@ -25,18 +25,31 @@ #include #include #include +#include #include namespace EdiDecoder { using namespace std; +bool frame_timestamp_t::valid() const +{ + return tsta != 0xFFFFFF; +} + string frame_timestamp_t::to_string() const { const time_t seconds_in_unix_epoch = to_unix_epoch(); stringstream ss; - ss << "Timestamp: " << std::put_time(std::gmtime(&seconds_in_unix_epoch), "%c %Z"); + if (valid()) { + ss << "Timestamp: "; + } + else { + ss << "Timestamp not valid: "; + } + ss << std::put_time(std::gmtime(&seconds_in_unix_epoch), "%c %Z") << + " + " << ((double)tsta / 16384000.0); return ss.str(); } @@ -48,6 +61,16 @@ time_t frame_timestamp_t::to_unix_epoch() const return 946684800 + seconds - utco; } +std::chrono::system_clock::time_point frame_timestamp_t::to_system_clock() const +{ + auto ts = chrono::system_clock::from_time_t(to_unix_epoch()); + + // PPS offset in seconds = tsta / 16384000 + ts += chrono::nanoseconds(std::lrint(tsta / 0.016384)); + + return ts; +} + TagDispatcher::TagDispatcher( std::function&& af_packet_completed, bool verbose) : diff --git a/lib/edi/common.hpp b/lib/edi/common.hpp index 1433004..887bc3d 100644 --- a/lib/edi/common.hpp +++ b/lib/edi/common.hpp @@ -23,6 +23,7 @@ #include "PFT.hpp" #include #include +#include #include #include #include @@ -33,9 +34,12 @@ namespace EdiDecoder { struct frame_timestamp_t { uint32_t seconds = 0; uint32_t utco = 0; + uint32_t tsta = 0; // According to EN 300 797 Annex B + bool valid() const; std::string to_string() const; time_t to_unix_epoch() const; + std::chrono::system_clock::time_point to_system_clock() const; }; struct decode_state_t { -- cgit v1.2.3