3 * Copyright 2009 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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)
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.
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.
21 #ifndef INCLUDED_VRT_EXPANDED_HEADER_H
22 #define INCLUDED_VRT_EXPANDED_HEADER_H
30 static const size_t HEADER_MAX_N32_BIT_WORDS = 7;
31 static const size_t TRAILER_MAX_N32_BIT_WORDS = 1;
34 * \brief All headers and trailer for VRT IF-Data, Extension-Data,
35 * IF-Context and Extension-Context packets.
37 * There are fields allocated for each possible header. Their content may
38 * or may not be valid. Check the header field to confirm their validity.
39 * All values are in host-endian format.
41 struct expanded_header {
42 uint32_t header; // first word of all packets
43 uint32_t stream_id; // optional stream identifier
44 uint64_t class_id; // optional class identifier
45 uint32_t integer_secs; // optional integer seconds timestamp
46 uint64_t fractional_secs; // optional fractional seconds timestamp
47 uint32_t trailer; // optional trailer (only possible in data pkts)
50 : header(0) /*, stream_id(0), class_id(0),
51 integer_secs(0), fractional_secs(0), trailer(0)*/ {}
54 int pkt_type() const {
55 return (header & VRTH_PT_MASK) >> 28;
58 int pkt_cnt() const { return vrth_pkt_cnt(header); }
59 size_t pkt_size() const { return vrth_pkt_size(header); }
62 // packet type predicates
63 bool if_data_p() const { return s_if_data[pkt_type()]; }
64 bool ext_data_p() const { return s_ext_data[pkt_type()]; }
65 bool if_context_p() const { return (header & VRTH_PT_MASK) == VRTH_PT_IF_CONTEXT; }
66 bool ext_context_p() const { return (header & VRTH_PT_MASK) == VRTH_PT_EXT_CONTEXT; }
68 bool data_p() const { return s_data[pkt_type()]; } // if_data_p() || ext_data_p()
69 bool context_p() const { return s_context[pkt_type()]; } // if_context_p() || ext_context_p()
71 // optional info predicates
72 bool stream_id_p() const { return s_stream_id[pkt_type()]; }
73 bool class_id_p() const { return (header & VRTH_HAS_CLASSID) != 0; }
74 bool integer_secs_p() const { return (header & VRTH_TSI_MASK) != 0; }
75 bool fractional_secs_p() const { return (header & VRTH_TSF_MASK) != 0; }
76 bool trailer_p() const { return (header & VRTH_HAS_TRAILER) != 0 && data_p(); }
80 * \brief unparse expanded header, fill-in the words of a vrt packet header and trailer
81 * This method is only intended to fill the buffers with header and trailer information.
82 * The actual handling of the separate header, payload, trailer buffers is up to the caller.
84 static void unparse(const expanded_header *hdr, // in
85 size_t n32_bit_words_payload, // in
86 uint32_t *header, // out
87 size_t *n32_bit_words_header, // out
88 uint32_t *trailer, // out
89 size_t *n32_bit_words_trailer);// out
92 * \brief parse packet, fill-in expanded header, start of payload and len of payload
94 static bool parse(const uint32_t *packet, // in
95 size_t n32_bit_words_packet, // in
96 expanded_header *hdr, // out
97 const uint32_t **payload, // out
98 size_t *n32_bit_words_payload); // out
101 static unsigned char s_if_data[16];
102 static unsigned char s_ext_data[16];
103 static unsigned char s_data[16];
104 static unsigned char s_context[16];
105 static unsigned char s_stream_id[16];
112 #endif /* INCLUDED_VRT_EXPANDED_HEADER_H */