copied over vrt context and type headers, updated bits.h as well
[debian/gnuradio] / vrt / include / vrt / expanded_header.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2009 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21 #ifndef INCLUDED_VRT_EXPANDED_HEADER_H
22 #define INCLUDED_VRT_EXPANDED_HEADER_H
23
24 #include <stdint.h>
25 #include <stddef.h>
26 #include <vrt/bits.h>
27
28 namespace vrt {
29
30   /*!
31    * \brief All headers and trailer for VRT IF-Data, Extension-Data,
32    * IF-Context and Extension-Context packets.
33    *
34    * There are fields allocated for each possible header.  Their content may
35    * or may not be valid.  Check the header field to confirm their validity.
36    * All values are in host-endian format.
37    */
38   struct expanded_header {
39     uint32_t    header;                 // first word of all packets
40     uint32_t    stream_id;              // optional stream identifier
41     uint64_t    class_id;               // optional class identifier
42     uint32_t    integer_secs;           // optional integer seconds timestamp
43     uint64_t    fractional_secs;        // optional fractional seconds timestamp
44     uint32_t    trailer;                // optional trailer (only possible in data pkts)
45
46     expanded_header()
47       : header(0) /*, stream_id(0), class_id(0),
48         integer_secs(0), fractional_secs(0), trailer(0)*/ {}
49
50
51     int pkt_type() const {
52       return (header & VRTH_PT_MASK) >> 28;
53     }
54     
55     int pkt_cnt() const { return vrth_pkt_cnt(header); }
56     size_t pkt_size() const { return vrth_pkt_size(header); }
57
58
59     // packet type predicates
60     bool if_data_p() const { return s_if_data[pkt_type()]; }
61     bool ext_data_p() const { return s_ext_data[pkt_type()]; }
62     bool if_context_p() const { return (header & VRTH_PT_MASK) == VRTH_PT_IF_CONTEXT; }
63     bool ext_context_p() const { return (header & VRTH_PT_MASK) == VRTH_PT_EXT_CONTEXT; }
64
65     bool data_p() const { return s_data[pkt_type()]; }  // if_data_p() || ext_data_p()
66     bool context_p() const { return s_context[pkt_type()]; }    // if_context_p() || ext_context_p()
67
68     // optional info predicates
69     bool stream_id_p() const { return s_stream_id[pkt_type()]; }
70     bool class_id_p() const { return (header & VRTH_HAS_CLASSID) != 0; }
71     bool integer_secs_p() const { return (header & VRTH_TSI_MASK) != 0; }
72     bool fractional_secs_p() const { return (header & VRTH_TSF_MASK) != 0; }
73     bool trailer_p() const { return (header & VRTH_HAS_TRAILER) != 0 && data_p(); }
74
75
76     // parser
77
78     /*!
79      * \brief parse packet, fill-in expanded header, start of payload and len of payload
80      */
81     static bool parse(const uint32_t *packet,           // in
82                       size_t n32_bit_words_packet,      // in
83                       expanded_header *hdr,             // out
84                       const uint32_t **payload,         // out
85                       size_t *n32_bit_words_payload);   // out
86                       
87   private:
88     static unsigned char s_if_data[16];
89     static unsigned char s_ext_data[16];
90     static unsigned char s_data[16];
91     static unsigned char s_context[16];
92     static unsigned char s_stream_id[16];
93
94   };
95
96 }; // vrt
97
98
99 #endif /* INCLUDED_VRT_EXPANDED_HEADER_H */