aboutsummaryrefslogtreecommitdiffstats
path: root/lib/edi/common.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2020-03-24 10:23:39 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2020-03-24 10:23:39 +0100
commitd0b77935d6aabf5d50e366ae2cec577b56163a3e (patch)
tree3cb6c7ddb677dbcb93bdb96c7ca22a24538fd6ee /lib/edi/common.cpp
parent32dab81b201b54bee4d58bfbab4d2884de245193 (diff)
downloaddabmod-d0b77935d6aabf5d50e366ae2cec577b56163a3e.tar.gz
dabmod-d0b77935d6aabf5d50e366ae2cec577b56163a3e.tar.bz2
dabmod-d0b77935d6aabf5d50e366ae2cec577b56163a3e.zip
Pull common code efe0a08
Diffstat (limited to 'lib/edi/common.cpp')
-rw-r--r--lib/edi/common.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/edi/common.cpp b/lib/edi/common.cpp
index d6ca89c..8d99619 100644
--- a/lib/edi/common.cpp
+++ b/lib/edi/common.cpp
@@ -73,6 +73,19 @@ double frame_timestamp_t::diff_ms(const frame_timestamp_t& other) const
return lhs - rhs;
}
+frame_timestamp_t& frame_timestamp_t::operator+=(const std::chrono::milliseconds& ms)
+{
+ tsta += (ms.count() % 1000) << 14; // Shift ms by 14 to Timestamp level 2
+ if (tsta > 0xf9FFff) {
+ tsta -= 0xfa0000; // Substract 16384000, corresponding to one second
+ seconds += 1;
+ }
+
+ seconds += (ms.count() / 1000);
+
+ return *this;
+}
+
frame_timestamp_t frame_timestamp_t::from_unix_epoch(std::time_t time, uint32_t tai_utc_offset, uint32_t tsta)
{
frame_timestamp_t ts;
@@ -90,7 +103,10 @@ 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));
+ // We cannot use nanosecond resolution because not all platforms use a
+ // system_clock that has nanosecond precision. It's not really important,
+ // as this function is only used for debugging.
+ ts += chrono::microseconds(std::lrint(tsta / 16.384));
return ts;
}