aboutsummaryrefslogtreecommitdiffstats
path: root/lib/edi/common.hpp
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2020-05-11 21:04:18 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2020-05-11 21:29:43 +0200
commitb4d788a065fb3338df26c44a94d804c194af4955 (patch)
treed711b52d9f8f24dd91db1152ba362b3dc513232d /lib/edi/common.hpp
parentb07511ef22303f969b6aae2bcb026891b355d0b0 (diff)
downloaddabmod-b4d788a065fb3338df26c44a94d804c194af4955.tar.gz
dabmod-b4d788a065fb3338df26c44a94d804c194af4955.tar.bz2
dabmod-b4d788a065fb3338df26c44a94d804c194af4955.zip
Update common EDI input and adapt to API changes
Diffstat (limited to 'lib/edi/common.hpp')
-rw-r--r--lib/edi/common.hpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/edi/common.hpp b/lib/edi/common.hpp
index 2a9c683..498b28a 100644
--- a/lib/edi/common.hpp
+++ b/lib/edi/common.hpp
@@ -1,5 +1,5 @@
/*
- Copyright (C) 2019
+ Copyright (C) 2020
Matthias P. Braendli, matthias.braendli@mpb.li
http://opendigitalradio.org
@@ -41,7 +41,7 @@ struct frame_timestamp_t {
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;
+ double diff_s(const frame_timestamp_t& other) const;
frame_timestamp_t& operator+=(const std::chrono::milliseconds& ms);
@@ -55,6 +55,10 @@ struct decode_state_t {
size_t num_bytes_consumed;
};
+using tag_name_t = std::array<uint8_t, 4>;
+
+std::string tag_name_to_human_readable(const tag_name_t& name);
+
/* The TagDispatcher takes care of decoding EDI, with or without PFT, and
* will call functions when TAGs are encountered.
*
@@ -63,7 +67,10 @@ struct decode_state_t {
*/
class TagDispatcher {
public:
- TagDispatcher(std::function<void()>&& af_packet_completed, bool verbose);
+ TagDispatcher(std::function<void()>&& af_packet_completed);
+
+ void set_verbose(bool verbose);
+
/* Push bytes into the decoder. The buf can contain more
* than a single packet. This is useful when reading from streams
@@ -81,9 +88,19 @@ class TagDispatcher {
*/
void setMaxDelay(int num_af_packets);
- using tag_handler = std::function<bool(std::vector<uint8_t>, uint16_t)>;
+ /* Handler function for a tag. The first argument contains the tag value,
+ * the second argument contains the tag name */
+ using tag_handler = std::function<bool(const std::vector<uint8_t>&, const tag_name_t&)>;
+
+ /* Register a handler for a tag. If the tag string can be length 0, 1, 2, 3 or 4.
+ * If is shorter than 4, it will perform a longest match on the tag name.
+ */
void register_tag(const std::string& tag, tag_handler&& h);
+ /* The complete tagpacket can also be retrieved */
+ using tagpacket_handler = std::function<void(const std::vector<uint8_t>&)>;
+ void register_tagpacket_handler(tagpacket_handler&& h);
+
private:
decode_state_t decode_afpacket(const std::vector<uint8_t> &input_data);
bool decode_tagpacket(const std::vector<uint8_t> &payload);
@@ -93,6 +110,7 @@ class TagDispatcher {
std::vector<uint8_t> m_input_data;
std::map<std::string, tag_handler> m_handlers;
std::function<void()> m_af_packet_completed;
+ tagpacket_handler m_tagpacket_handler;
};
// Data carried inside the ODRv EDI TAG