summaryrefslogtreecommitdiffstats
path: root/lib/edi/common.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-07-29 15:27:32 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-07-29 15:27:32 +0200
commit14f69f9c915cf644147a52b803d79ff8f40a4ea1 (patch)
treeb89eabcdb3c2fb2ae3f911b08867f46061e6cf37 /lib/edi/common.cpp
parent6ff1dd95a6552c0f7e868dda1dffeb9ae572b8b7 (diff)
downloaddabmux-14f69f9c915cf644147a52b803d79ff8f40a4ea1.tar.gz
dabmux-14f69f9c915cf644147a52b803d79ff8f40a4ea1.tar.bz2
dabmux-14f69f9c915cf644147a52b803d79ff8f40a4ea1.zip
First prototype taking EDI TIST into account for contribution
Diffstat (limited to 'lib/edi/common.cpp')
-rw-r--r--lib/edi/common.cpp25
1 files changed, 24 insertions, 1 deletions
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 <iomanip>
#include <sstream>
#include <cassert>
+#include <cmath>
#include <cstdio>
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<void()>&& af_packet_completed, bool verbose) :