diff options
Diffstat (limited to 'src/dabOutput')
-rw-r--r-- | src/dabOutput/edi/AFPacket.cpp | 8 | ||||
-rw-r--r-- | src/dabOutput/edi/AFPacket.h | 10 | ||||
-rw-r--r-- | src/dabOutput/edi/TagItems.h | 2 | ||||
-rw-r--r-- | src/dabOutput/edi/TagPacket.cpp | 58 | ||||
-rw-r--r-- | src/dabOutput/edi/TagPacket.h | 51 |
5 files changed, 124 insertions, 5 deletions
diff --git a/src/dabOutput/edi/AFPacket.cpp b/src/dabOutput/edi/AFPacket.cpp index cd845d7..1516561 100644 --- a/src/dabOutput/edi/AFPacket.cpp +++ b/src/dabOutput/edi/AFPacket.cpp @@ -26,6 +26,8 @@ #include "config.h" #include "crc.h" #include "AFPacket.h" +#include "TagItems.h" +#include "TagPacket.h" #include <vector> #include <string> #include <stdint.h> @@ -37,8 +39,10 @@ // AF Packet Major (3 bits) and Minor (4 bits) version #define AFHEADER_VERSION 0x8 // MAJ=1, MIN=0 -std::vector<uint8_t> AFPacket::Assemble(char protocol_type, std::vector<uint8_t> payload) +std::vector<uint8_t> AFPacket::Assemble(TagPacket tag_packet) { + std::vector<uint8_t> payload = tag_packet.Assemble(); + header.ar_maj = 1; header.ar_min = 0; header.pt = protocol_type; @@ -60,7 +64,7 @@ std::vector<uint8_t> AFPacket::Assemble(char protocol_type, std::vector<uint8_t> packet.push_back((have_crc ? 0x80 : 0) | AFHEADER_VERSION); // ar_cf: CRC=1 packet.push_back(AFHEADER_PT_TAG); - // insert payload + // insert payload, must have a length multiple of 8 bytes packet.insert(packet.end(), payload.begin(), payload.end()); // calculate CRC over AF Header and payload diff --git a/src/dabOutput/edi/AFPacket.h b/src/dabOutput/edi/AFPacket.h index 1fd0d16..0d41878 100644 --- a/src/dabOutput/edi/AFPacket.h +++ b/src/dabOutput/edi/AFPacket.h @@ -30,8 +30,12 @@ #include "config.h" #include <vector> #include <stdint.h> +#include "TagItems.h" +#include "TagPacket.h" #define PACKED __attribute__ ((packed)) +#define EDI_AFPACKET_PROTOCOLTYPE_TAGITEMS ('T') + // ETSI TS 102 821, 6.1 AF packet structure struct AFHeader { @@ -47,15 +51,17 @@ struct AFHeader class AFPacket { public: - AFPacket(); + AFPacket(char protocolType) : protocol_type(protocolType) {}; - std::vector<uint8_t> Assemble(char protocol_type, std::vector<uint8_t> payload); + std::vector<uint8_t> Assemble(TagPacket tag_packet); private: static const bool have_crc = true; AFHeader header; uint16_t seq; //counter that overflows at 0xFFFF + + char protocol_type; }; #endif diff --git a/src/dabOutput/edi/TagItems.h b/src/dabOutput/edi/TagItems.h index 6ae3bc6..2cebaf8 100644 --- a/src/dabOutput/edi/TagItems.h +++ b/src/dabOutput/edi/TagItems.h @@ -82,7 +82,7 @@ class TagDETI : public TagItem // the FIC (optional) bool ficf; - const char* fic_data; + const unsigned char* fic_data; size_t fic_length; // rfu diff --git a/src/dabOutput/edi/TagPacket.cpp b/src/dabOutput/edi/TagPacket.cpp new file mode 100644 index 0000000..b4d0bce --- /dev/null +++ b/src/dabOutput/edi/TagPacket.cpp @@ -0,0 +1,58 @@ +/* + Copyright (C) 2013 Matthias P. Braendli + http://mpb.li + + EDI output. + This defines a TAG Packet. + */ +/* + This file is part of CRC-DabMux. + + CRC-DabMux is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + CRC-DabMux is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with CRC-DabMux. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "config.h" +#include "Eti.h" +#include "TagPacket.h" +#include "TagItems.h" +#include <vector> +#include <string> +#include <list> +#include <stdint.h> + + +std::vector<uint8_t> TagPacket::Assemble() +{ + std::list<TagItem*>::iterator tag; + + std::vector<uint8_t> packet; + + size_t packet_length = 0; + for (tag = tag_items.begin(); tag != tag_items.end(); ++tag) { + std::vector<uint8_t> tag_data = (*tag)->Assemble(); + packet.insert(packet.end(), tag_data.begin(), tag_data.end()); + + packet_length += tag_data.size(); + } + + // Add padding + while (packet_length % 8 > 0) + { + packet.push_back(0); // TS 102 821, 5.1, "padding shall be undefined" + packet_length++; + } + + return packet; +} + diff --git a/src/dabOutput/edi/TagPacket.h b/src/dabOutput/edi/TagPacket.h new file mode 100644 index 0000000..1286d2c --- /dev/null +++ b/src/dabOutput/edi/TagPacket.h @@ -0,0 +1,51 @@ +/* + Copyright (C) 2013 Matthias P. Braendli + http://mpb.li + + EDI output. + This defines a TAG Packet. + */ +/* + This file is part of CRC-DabMux. + + CRC-DabMux is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + CRC-DabMux is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with CRC-DabMux. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef _TAGPACKET_H_ +#define _TAGPACKET_H_ + +#include "config.h" +#include "Eti.h" +#include <vector> +#include <string> +#include <list> +#include <stdint.h> + + + +// A TagPacket is nothing else than a list of tag items, with an +// Assemble function that puts the bytestream together and adds +// padding such that the total length is a multiple of 8 Bytes. +// +// ETSI TS 102 821, 5.1 Tag Packet +class TagPacket +{ + public: + std::vector<uint8_t> Assemble(); + + std::list<TagItem*> tag_items; +}; + +#endif + |