From 67300d5c4fa279eb5144d60874753b10de678f55 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Tue, 24 Dec 2013 16:59:09 +0100 Subject: add TagPacket, add to DabMux.cpp. Must fix the goto EXIT now --- src/dabOutput/edi/AFPacket.cpp | 8 ++++-- src/dabOutput/edi/AFPacket.h | 10 +++++-- src/dabOutput/edi/TagItems.h | 2 +- src/dabOutput/edi/TagPacket.cpp | 58 +++++++++++++++++++++++++++++++++++++++++ src/dabOutput/edi/TagPacket.h | 51 ++++++++++++++++++++++++++++++++++++ 5 files changed, 124 insertions(+), 5 deletions(-) create mode 100644 src/dabOutput/edi/TagPacket.cpp create mode 100644 src/dabOutput/edi/TagPacket.h (limited to 'src/dabOutput/edi') 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 #include #include @@ -37,8 +39,10 @@ // AF Packet Major (3 bits) and Minor (4 bits) version #define AFHEADER_VERSION 0x8 // MAJ=1, MIN=0 -std::vector AFPacket::Assemble(char protocol_type, std::vector payload) +std::vector AFPacket::Assemble(TagPacket tag_packet) { + std::vector payload = tag_packet.Assemble(); + header.ar_maj = 1; header.ar_min = 0; header.pt = protocol_type; @@ -60,7 +64,7 @@ std::vector AFPacket::Assemble(char protocol_type, std::vector 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 #include +#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 Assemble(char protocol_type, std::vector payload); + std::vector 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 . + */ + +#include "config.h" +#include "Eti.h" +#include "TagPacket.h" +#include "TagItems.h" +#include +#include +#include +#include + + +std::vector TagPacket::Assemble() +{ + std::list::iterator tag; + + std::vector packet; + + size_t packet_length = 0; + for (tag = tag_items.begin(); tag != tag_items.end(); ++tag) { + std::vector 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 . + */ + +#ifndef _TAGPACKET_H_ +#define _TAGPACKET_H_ + +#include "config.h" +#include "Eti.h" +#include +#include +#include +#include + + + +// 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 Assemble(); + + std::list tag_items; +}; + +#endif + -- cgit v1.2.3