some more small steps on the painful way to an ULE decoder ;)
[senf.git] / Packets / MPEGDVBBundle / SNDUPacket.hh
1 // $Id:DSMCCSection.hh 327 2007-07-20 10:03:44Z tho $
2 //
3 // Copyright (C) 2007
4 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
5 // Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
6 //     Stefan Bund <stefan.bund@fokus.fraunhofer.de>
7 //
8 // This program is free software; you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation; either version 2 of the License, or
11 // (at your option) any later version.
12 //
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU General Public License
19 // along with this program; if not, write to the
20 // Free Software Foundation, Inc.,
21 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
23 /** \file
24     \brief SNDUPacket public header */
25
26 #ifndef HH_SNDUPacket_
27 #define HH_SNDUPacket_ 1
28
29 // Custom includes
30 #include <algorithm>
31 #include "Packets/PacketType.hh"
32 #include "Packets/ParseInt.hh"
33 #include "Packets/PacketRegistry.hh"
34 #include "Packets/PacketParser.hh"
35 #include "Packets/DefaultBundle/EthernetPacket.hh"
36
37 //#include "SNDUPacket.mpp"
38 ///////////////////////////////hh.p////////////////////////////////////////
39
40 namespace senf {
41
42     /** \brief parse ULE SNDU Packet
43     
44         Parser implementing the header and trailer of a ULE SNDU Packet
45         
46         \see SNDUPacketType
47      */
48     struct Parse_SNDUPacket : public PacketParserBase
49     {
50 #       ifndef DOXYGEN
51         
52         SENF_PACKET_PARSER_NO_INIT(Parse_SNDUPacket);
53
54 #       endif
55         
56         typedef Parse_Flag      <     0 > Parse_daaf;  // Destination Address Absent Field
57         typedef Parse_UIntField < 1, 16 > Parse_length;
58                 
59         Parse_daaf d_bit() const {
60             return parse<Parse_daaf>( 0 );
61         }
62         Parse_length length() const {
63             return parse<Parse_length>( 0 );
64         }
65         Parse_UInt16 type() const {
66             return parse<Parse_UInt16>( 2 );
67         }
68         Parse_MAC destination() const {
69             BOOST_ASSERT( ! d_bit() );
70             return parse<Parse_MAC>( 4 );
71         }
72         Parse_UInt32 crc() const { 
73             return parse<Parse_UInt32>( data().size()-4 ); 
74         }
75         
76         void init() const {
77             defaultInit();
78             d_bit() = false;
79         }
80         
81         PacketParserBase::size_type bytes() const;
82         
83         static const size_type init_bytes = 2+2+4; // D-Bit + 15 bits length + 16 bits type field + 32 bits crc
84     };
85
86     /** \brief ULE SNDU Packet
87         
88         \par Packet type (typedef):
89             \ref SNDUPacket
90
91         \par Fields:
92             \ref Parse_SNDUPacket
93
94         \ingroup protocolbundle_mpegdvb
95      */
96     struct SNDUPacketType
97         : public PacketTypeBase,
98           public PacketTypeMixin<SNDUPacketType>
99     {
100         typedef PacketTypeMixin<SNDUPacketType> mixin;
101         typedef ConcretePacket<SNDUPacketType> packet;
102         typedef Parse_SNDUPacket parser;
103
104         using mixin::nextPacketRange;
105 //          using mixin::nextPacketType;
106         using mixin::init;
107         
108         static void dump(packet p, std::ostream & os);
109         
110         static PacketParserBase::size_type initSize();
111         static PacketParserBase::size_type initHeadSize();
112     };
113         
114     typedef SNDUPacketType::packet SNDUPacket;
115
116     /*!
117      \def ULE_END_INDICATOR 
118          ULE End Indicator; indicates to the receiver that there are no 
119          further SNDUs present within the current TS packet.
120     */
121 #   define ULE_END_INDICATOR 0xffff
122 }
123
124
125 ///////////////////////////////hh.e////////////////////////////////////////
126 //#include "SNDUPacket.cci"
127 //#include "SNDUPacket.ct"
128 //#include "SNDUPacket.cti"
129 #endif
130
131 \f
132 // Local Variables:
133 // mode: c++
134 // fill-column: 100
135 // c-file-style: "senf"
136 // indent-tabs-mode: nil
137 // ispell-local-dictionary: "american"
138 // compile-command: "scons -u test"
139 // comment-column: 40
140 // End: