aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2019-10-01 14:55:31 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2019-10-01 14:55:31 +0200
commit0ce6e65cc3b379c7d7a0628e1af7ad191e023fd1 (patch)
tree183877af6ff811eb11bffdb3bcd345a40735fbd2
parent705cf1bcd4428fc5f0f5630624412e48bf6fc50a (diff)
downloadodr-edilib-0ce6e65cc3b379c7d7a0628e1af7ad191e023fd1.tar.gz
odr-edilib-0ce6e65cc3b379c7d7a0628e1af7ad191e023fd1.tar.bz2
odr-edilib-0ce6e65cc3b379c7d7a0628e1af7ad191e023fd1.zip
Pull code updates from common
-rw-r--r--decoder/STIDecoder.cpp35
-rw-r--r--decoder/STIDecoder.hpp13
-rw-r--r--decoder/STIWriter.cpp10
-rw-r--r--decoder/STIWriter.hpp8
-rw-r--r--decoder/common.cpp32
-rw-r--r--decoder/common.hpp14
6 files changed, 110 insertions, 2 deletions
diff --git a/decoder/STIDecoder.cpp b/decoder/STIDecoder.cpp
index 2f196df..ede70f3 100644
--- a/decoder/STIDecoder.cpp
+++ b/decoder/STIDecoder.cpp
@@ -44,6 +44,10 @@ STIDecoder::STIDecoder(STIDataCollector& data_collector, bool verbose) :
std::bind(&STIDecoder::decode_ssn, this, _1, _2));
m_dispatcher.register_tag("*dmy",
std::bind(&STIDecoder::decode_stardmy, this, _1, _2));
+ m_dispatcher.register_tag("ODRa",
+ std::bind(&STIDecoder::decode_odraudiolevel, this, _1, _2));
+ m_dispatcher.register_tag("ODRv",
+ std::bind(&STIDecoder::decode_odrversion, this, _1, _2));
}
void STIDecoder::push_bytes(const vector<uint8_t> &buf)
@@ -187,6 +191,37 @@ bool STIDecoder::decode_stardmy(const vector<uint8_t>& /*value*/, uint16_t)
return true;
}
+bool STIDecoder::decode_odraudiolevel(const vector<uint8_t>& value, uint16_t)
+{
+ constexpr size_t expected_length = 2 * sizeof(int16_t);
+
+ audio_level_data audio_level;
+
+ if (value.size() == expected_length) {
+ audio_level.left = read_16b(value.begin());
+ audio_level.right = read_16b(value.begin() + 2);
+ }
+ else {
+ audio_level.left = 0;
+ audio_level.right = 0;
+ etiLog.level(warn) << "EDI: ODR AudioLevel TAG has wrong length!";
+ }
+
+ m_data_collector.update_audio_levels(audio_level);
+
+ // Not being able to decode the audio level is a soft-failure, it should
+ // not disrupt decoding the actual audio data.
+ return true;
+}
+
+bool STIDecoder::decode_odrversion(const vector<uint8_t>& value, uint16_t)
+{
+ const auto vd = parse_odr_version_data(value);
+ m_data_collector.update_odr_version(vd);
+
+ return true;
+}
+
void STIDecoder::packet_completed()
{
m_data_collector.assemble();
diff --git a/decoder/STIDecoder.hpp b/decoder/STIDecoder.hpp
index 3f6f729..e2aa850 100644
--- a/decoder/STIDecoder.hpp
+++ b/decoder/STIDecoder.hpp
@@ -53,6 +53,12 @@ struct sti_payload_data {
uint16_t stl(void) const { return istd.size(); }
};
+struct audio_level_data {
+ int16_t left = 0;
+ int16_t right = 0;
+};
+
+
/* A class that receives STI data must implement the interface described
* in the STIDataCollector. This can be e.g. a converter to ETI, or something that
* prepares data structures for a modulator.
@@ -78,6 +84,9 @@ class STIDataCollector {
virtual void add_payload(sti_payload_data&& payload) = 0;
+ virtual void update_audio_levels(const audio_level_data& data) = 0;
+ virtual void update_odr_version(const odr_version_data& data) = 0;
+
virtual void assemble() = 0;
};
@@ -113,11 +122,13 @@ class STIDecoder {
bool decode_ssn(const std::vector<uint8_t> &value, uint16_t n);
bool decode_stardmy(const std::vector<uint8_t> &value, uint16_t);
+ bool decode_odraudiolevel(const std::vector<uint8_t> &value, uint16_t);
+ bool decode_odrversion(const std::vector<uint8_t> &value, uint16_t);
+
void packet_completed();
STIDataCollector& m_data_collector;
TagDispatcher m_dispatcher;
-
};
}
diff --git a/decoder/STIWriter.cpp b/decoder/STIWriter.cpp
index 82cdd06..72be07d 100644
--- a/decoder/STIWriter.cpp
+++ b/decoder/STIWriter.cpp
@@ -80,6 +80,16 @@ void STIWriter::add_payload(sti_payload_data&& payload)
m_payload_valid = true;
}
+void STIWriter::update_audio_levels(const audio_level_data& data)
+{
+ m_audio_levels = data;
+}
+
+void STIWriter::update_odr_version(const odr_version_data& data)
+{
+ m_version_data = data;
+}
+
void STIWriter::update_edi_time(
uint32_t utco,
uint32_t seconds)
diff --git a/decoder/STIWriter.hpp b/decoder/STIWriter.hpp
index 4728131..fc08e97 100644
--- a/decoder/STIWriter.hpp
+++ b/decoder/STIWriter.hpp
@@ -33,6 +33,8 @@ namespace EdiDecoder {
struct sti_frame_t {
std::vector<uint8_t> frame;
frame_timestamp_t timestamp;
+ audio_level_data audio_levels;
+ odr_version_data version_data;
};
class STIWriter : public STIDataCollector {
@@ -57,6 +59,9 @@ class STIWriter : public STIDataCollector {
virtual void update_sti_management(const sti_management_data& data);
virtual void add_payload(sti_payload_data&& payload);
+ virtual void update_audio_levels(const audio_level_data& data);
+ virtual void update_odr_version(const odr_version_data& data);
+
virtual void assemble(void);
private:
std::function<void(sti_frame_t&&)> m_frame_callback;
@@ -76,6 +81,9 @@ class STIWriter : public STIDataCollector {
bool m_payload_valid = false;
sti_payload_data m_payload;
+
+ audio_level_data m_audio_levels;
+ odr_version_data m_version_data;
};
}
diff --git a/decoder/common.cpp b/decoder/common.cpp
index cb1f425..ac8ec0c 100644
--- a/decoder/common.cpp
+++ b/decoder/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());
@@ -320,4 +339,17 @@ bool TagDispatcher::decode_tagpacket(const vector<uint8_t> &payload)
return success;
}
+odr_version_data parse_odr_version_data(const std::vector<uint8_t>& data)
+{
+ if (data.size() < sizeof(uint32_t)) {
+ return {};
+ }
+
+ const size_t versionstr_length = data.size() - sizeof(uint32_t);
+ string version(data.begin(), data.begin() + versionstr_length);
+ uint32_t uptime_s = read_32b(data.begin() + versionstr_length);
+
+ return {version, uptime_s};
+}
+
}
diff --git a/decoder/common.hpp b/decoder/common.hpp
index 887bc3d..8252a7a 100644
--- a/decoder/common.hpp
+++ b/decoder/common.hpp
@@ -38,8 +38,12 @@ 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 {
@@ -89,4 +93,12 @@ class TagDispatcher {
std::function<void()> m_af_packet_completed;
};
+// Data carried inside the ODRv EDI TAG
+struct odr_version_data {
+ std::string version;
+ uint32_t uptime_s;
+};
+
+odr_version_data parse_odr_version_data(const std::vector<uint8_t>& data);
+
}