From 47033e0ba1377cee310490587b87490249d9b510 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Sat, 1 Aug 2015 11:03:38 +0200 Subject: Add option to pad TAGPacket in different ways --- src/dabOutput/edi/TagItems.cpp | 20 ++++++++++++++++++++ src/dabOutput/edi/TagItems.h | 13 +++++++++++++ src/dabOutput/edi/TagPacket.cpp | 21 +++++++++++++++++---- src/dabOutput/edi/TagPacket.h | 4 ++++ 4 files changed, 54 insertions(+), 4 deletions(-) (limited to 'src/dabOutput/edi') diff --git a/src/dabOutput/edi/TagItems.cpp b/src/dabOutput/edi/TagItems.cpp index 2cae7d1..b97721a 100644 --- a/src/dabOutput/edi/TagItems.cpp +++ b/src/dabOutput/edi/TagItems.cpp @@ -171,5 +171,25 @@ std::vector TagESTn::Assemble() */ return packet; } + +std::vector TagStarDMY::Assemble() +{ + std::string pack_data("*dmy"); + std::vector packet(pack_data.begin(), pack_data.end()); + + packet.resize(4 + 4 + length_); + + const uint32_t length_bits = length_ * 8; + + packet[4] = (length_bits >> 24) & 0xFF; + packet[5] = (length_bits >> 16) & 0xFF; + packet[6] = (length_bits >> 8) & 0xFF; + packet[7] = length_bits & 0xFF; + + // The remaining bytes in the packet are "undefined data" + + return packet; +} + #endif diff --git a/src/dabOutput/edi/TagItems.h b/src/dabOutput/edi/TagItems.h index fccea2d..e75d241 100644 --- a/src/dabOutput/edi/TagItems.h +++ b/src/dabOutput/edi/TagItems.h @@ -111,5 +111,18 @@ class TagESTn : public TagItem private: uint8_t id_; }; + +// ETSI TS 102 821, 5.2.2.2 Dummy padding +class TagStarDMY : public TagItem +{ + public: + /* length is the TAG value length in bytes */ + TagStarDMY(uint32_t length) : length_(length) {} + std::vector Assemble(); + + private: + uint32_t length_; +}; + #endif diff --git a/src/dabOutput/edi/TagPacket.cpp b/src/dabOutput/edi/TagPacket.cpp index aa4f23b..435c071 100644 --- a/src/dabOutput/edi/TagPacket.cpp +++ b/src/dabOutput/edi/TagPacket.cpp @@ -33,6 +33,8 @@ #include #include +TagPacket::TagPacket(unsigned int alignment) : m_alignment(alignment) +{ } std::vector TagPacket::Assemble() { @@ -49,10 +51,21 @@ std::vector TagPacket::Assemble() //std::cerr << " Add TAGItem of length " << tag_data.size() << std::endl; } - // Add padding - while (packet.size() % 8 > 0) - { - packet.push_back(0); // TS 102 821, 5.1, "padding shall be undefined" + if (m_alignment == 0) { /* no padding */ } + else if (m_alignment == 8) { + // Add padding inside TAG packet + while (packet.size() % 8 > 0) { + packet.push_back(0); // TS 102 821, 5.1, "padding shall be undefined" + } + } + else if (m_alignment > 8) { + TagStarDMY dmy(m_alignment - 8); + auto dmy_data = dmy.Assemble(); + packet.insert(packet.end(), dmy_data.begin(), dmy_data.end()); + } + else { + std::cerr << "Invalid alignment requirement " << m_alignment << + " defined in TagPacket" << std::endl; } return packet; diff --git a/src/dabOutput/edi/TagPacket.h b/src/dabOutput/edi/TagPacket.h index 9d69226..5ad1904 100644 --- a/src/dabOutput/edi/TagPacket.h +++ b/src/dabOutput/edi/TagPacket.h @@ -42,9 +42,13 @@ class TagPacket { public: + TagPacket(unsigned int alignment); std::vector Assemble(); std::list tag_items; + + private: + unsigned int m_alignment; }; #endif -- cgit v1.2.3