diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-09-05 17:12:04 +0200 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2019-09-05 17:12:04 +0200 |
commit | 4336f2bdfc36372f33a51bebbebc1f751a78cf53 (patch) | |
tree | 66f270c988e321b7d354c905375608b1faf61555 | |
parent | b536ace6b4f48f9f9a45b66881c6e2e024ed7d93 (diff) | |
download | dabmod-4336f2bdfc36372f33a51bebbebc1f751a78cf53.tar.gz dabmod-4336f2bdfc36372f33a51bebbebc1f751a78cf53.tar.bz2 dabmod-4336f2bdfc36372f33a51bebbebc1f751a78cf53.zip |
lib: update from common code cdf104a and 2847f4d
-rw-r--r-- | lib/edi/common.cpp | 21 | ||||
-rw-r--r-- | lib/edi/common.hpp | 7 |
2 files changed, 26 insertions, 2 deletions
diff --git a/lib/edi/common.cpp b/lib/edi/common.cpp index b4b0c79..4629b55 100644 --- a/lib/edi/common.cpp +++ b/lib/edi/common.cpp @@ -61,6 +61,25 @@ time_t frame_timestamp_t::to_unix_epoch() const return 946684800 + seconds - utco; } +double frame_timestamp_t::diff_ms(const frame_timestamp_t& other) const +{ + const double lhs = (double)seconds + (tsta / 16384000.0); + const double rhs = (double)other.seconds + (other.tsta / 16384000.0); + return lhs - rhs; +} + +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; + + const std::time_t posix_timestamp_1_jan_2000 = 946684800; + + ts.utco = tai_utc_offset - 32; + ts.seconds = time - posix_timestamp_1_jan_2000 + ts.utco; + ts.tsta = tsta; + return ts; +} + std::chrono::system_clock::time_point frame_timestamp_t::to_system_clock() const { auto ts = chrono::system_clock::from_time_t(to_unix_epoch()); @@ -202,7 +221,7 @@ decode_state_t TagDispatcher::decode_afpacket( return {false, 0}; } - if (m_last_seq + 1 != seq) { + if (m_last_seq + (uint16_t)1 != seq) { etiLog.level(warn) << "EDI AF Packet sequence error, " << seq; } m_last_seq = seq; diff --git a/lib/edi/common.hpp b/lib/edi/common.hpp index 887bc3d..1aa2cb6 100644 --- a/lib/edi/common.hpp +++ b/lib/edi/common.hpp @@ -38,10 +38,15 @@ struct frame_timestamp_t { bool valid() const; std::string to_string() const; - time_t to_unix_epoch() const; + std::time_t to_unix_epoch() const; std::chrono::system_clock::time_point to_system_clock() const; + + double diff_ms(const frame_timestamp_t& other) const; + + static frame_timestamp_t from_unix_epoch(std::time_t time, uint32_t tai_utc_offset, uint32_t tsta); }; + struct decode_state_t { decode_state_t(bool _complete, size_t _num_bytes_consumed) : complete(_complete), num_bytes_consumed(_num_bytes_consumed) {} |