aboutsummaryrefslogtreecommitdiffstats
path: root/lib/edi/common.hpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2022-03-29 16:43:19 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2022-03-29 16:43:19 +0200
commit6d1d9f47edef8352c6f25d7736171ec2bbe5471a (patch)
treeb9194956abb0f672c16b1136b90f59448cb86b75 /lib/edi/common.hpp
parentcf58fa375c003173215baf81b4b64cf4e5c1873c (diff)
downloaddabmux-6d1d9f47edef8352c6f25d7736171ec2bbe5471a.tar.gz
dabmux-6d1d9f47edef8352c6f25d7736171ec2bbe5471a.tar.bz2
dabmux-6d1d9f47edef8352c6f25d7736171ec2bbe5471a.zip
Common: log timestamps, socket changes and frame_timestamp_t
Diffstat (limited to 'lib/edi/common.hpp')
-rw-r--r--lib/edi/common.hpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/lib/edi/common.hpp b/lib/edi/common.hpp
index 5e31984..c3e6c40 100644
--- a/lib/edi/common.hpp
+++ b/lib/edi/common.hpp
@@ -35,7 +35,7 @@ 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
+ uint32_t tsta = 0xFFFFFF; // According to EN 300 797 Annex B
bool valid() const;
std::string to_string() const;
@@ -47,6 +47,33 @@ struct frame_timestamp_t {
frame_timestamp_t& operator+=(const std::chrono::milliseconds& ms);
static frame_timestamp_t from_unix_epoch(std::time_t time, uint32_t tai_utc_offset, uint32_t tsta);
+
+ friend bool operator==(const frame_timestamp_t& l, const frame_timestamp_t& r) {
+ return (l.seconds - l.utco) == (r.seconds - r.utco) and l.tsta == r.tsta;
+ }
+
+ friend bool operator!=(const frame_timestamp_t& l, const frame_timestamp_t& r) {
+ return not (l == r);
+ }
+
+ friend bool operator< (const frame_timestamp_t& l, const frame_timestamp_t& r) {
+ if (l.seconds - l.utco == r.seconds - r.utco) {
+ return l.tsta < r.tsta;
+ }
+ return l.seconds - l.utco < r.seconds - r.utco;
+ }
+
+ friend bool operator<= (const frame_timestamp_t& l, const frame_timestamp_t& r) {
+ return l < r or l == r;
+ }
+
+ friend bool operator> (const frame_timestamp_t& l, const frame_timestamp_t& r) {
+ return r < l;
+ }
+
+ friend bool operator>= (const frame_timestamp_t& l, const frame_timestamp_t& r) {
+ return l > r or l == r;
+ }
};
using tag_name_t = std::array<uint8_t, 4>;