summaryrefslogtreecommitdiffstats
path: root/lib/edi/common.cpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2020-05-11 21:03:36 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2020-05-11 21:03:36 +0200
commit19d907c885081a3218d81705fd45870b10f99d8d (patch)
tree2a56f22a1b4d5ba1d2d2619725899d5f49e260e9 /lib/edi/common.cpp
parent3a8a2aa8b682545a2a18bf24975555c7eb07152c (diff)
downloaddabmux-19d907c885081a3218d81705fd45870b10f99d8d.tar.gz
dabmux-19d907c885081a3218d81705fd45870b10f99d8d.tar.bz2
dabmux-19d907c885081a3218d81705fd45870b10f99d8d.zip
Common: update common code with EDI input changes
Diffstat (limited to 'lib/edi/common.cpp')
-rw-r--r--lib/edi/common.cpp62
1 files changed, 41 insertions, 21 deletions
diff --git a/lib/edi/common.cpp b/lib/edi/common.cpp
index 470b3ba..3005802 100644
--- a/lib/edi/common.cpp
+++ b/lib/edi/common.cpp
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2019
+ Copyright (C) 2020
Matthias P. Braendli, matthias.braendli@mpb.li
http://opendigitalradio.org
@@ -26,6 +26,7 @@
#include <cassert>
#include <cmath>
#include <cstdio>
+#include <cctype>
namespace EdiDecoder {
@@ -66,7 +67,7 @@ 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
+double frame_timestamp_t::diff_s(const frame_timestamp_t& other) const
{
const double lhs = (double)seconds + (tsta / 16384000.0);
const double rhs = (double)other.seconds + (other.tsta / 16384000.0);
@@ -111,10 +112,30 @@ std::chrono::system_clock::time_point frame_timestamp_t::to_system_clock() const
return ts;
}
+std::string tag_name_to_human_readable(const tag_name_t& name)
+{
+ std::string s;
+ for (const uint8_t c : name) {
+ if (isprint(c)) {
+ s += (char)c;
+ }
+ else {
+ char escaped[5];
+ snprintf(escaped, 5, "\\x%02x", c);
+ s += escaped;
+ }
+ }
+ return s;
+}
TagDispatcher::TagDispatcher(
- std::function<void()>&& af_packet_completed, bool verbose) :
- m_af_packet_completed(move(af_packet_completed))
+ std::function<void()>&& af_packet_completed) :
+ m_af_packet_completed(move(af_packet_completed)),
+ m_tagpacket_handler([](const std::vector<uint8_t>& ignore){})
+{
+}
+
+void TagDispatcher::set_verbose(bool verbose)
{
m_pft.setVerbose(verbose);
}
@@ -295,6 +316,11 @@ void TagDispatcher::register_tag(const std::string& tag, tag_handler&& h)
m_handlers[tag] = move(h);
}
+void TagDispatcher::register_tagpacket_handler(tagpacket_handler&& h)
+{
+ m_tagpacket_handler = move(h);
+}
+
bool TagDispatcher::decode_tagpacket(const vector<uint8_t> &payload)
{
@@ -326,31 +352,23 @@ bool TagDispatcher::decode_tagpacket(const vector<uint8_t> &payload)
break;
}
+ const array<uint8_t, 4> tag_name({
+ (uint8_t)tag_sz[0], (uint8_t)tag_sz[1], (uint8_t)tag_sz[2], (uint8_t)tag_sz[3]
+ });
vector<uint8_t> tag_value(taglength);
copy( payload.begin() + i+8,
payload.begin() + i+8+taglength,
tag_value.begin());
- bool tagsuccess = false;
+ bool tagsuccess = true;
bool found = false;
for (auto tag_handler : m_handlers) {
- if (tag_handler.first.size() == 4 and tag_handler.first == tag) {
- found = true;
- tagsuccess = tag_handler.second(tag_value, 0);
- }
- else if (tag_handler.first.size() == 3 and
- tag.substr(0, 3) == tag_handler.first) {
- found = true;
- uint8_t n = tag_sz[3];
- tagsuccess = tag_handler.second(tag_value, n);
- }
- else if (tag_handler.first.size() == 2 and
- tag.substr(0, 2) == tag_handler.first) {
+ if ( (tag_handler.first.size() == 4 and tag == tag_handler.first) or
+ (tag_handler.first.size() == 3 and tag.substr(0, 3) == tag_handler.first) or
+ (tag_handler.first.size() == 2 and tag.substr(0, 2) == tag_handler.first) or
+ (tag_handler.first.size() == 1 and tag.substr(0, 1) == tag_handler.first)) {
found = true;
- uint16_t n = 0;
- n = (uint16_t)(tag_sz[2]) << 8;
- n |= (uint16_t)(tag_sz[3]);
- tagsuccess = tag_handler.second(tag_value, n);
+ tagsuccess &= tag_handler.second(tag_value, tag_name);
}
}
@@ -366,6 +384,8 @@ bool TagDispatcher::decode_tagpacket(const vector<uint8_t> &payload)
}
}
+ m_tagpacket_handler(payload);
+
return success;
}