From fc4fa0a1894f0f85be1a76e48b922effb3d5dd9b Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 17 Dec 2009 16:48:54 -0800 Subject: [PATCH] Added unparse capability to the vrt expanded header. Unparse can fill in a vrt header and trailer from an expanded header. --- vrt/include/vrt/expanded_header.h | 15 +- vrt/lib/Makefile.am | 6 +- vrt/lib/expanded_header.cc | 18 +- ....h => expanded_header_parse_switch_body.h} | 0 vrt/lib/expanded_header_unparse_switch_body.h | 272 ++++++++++++++++++ ...witch_body.py => gen_parse_switch_body.py} | 0 vrt/lib/gen_unparse_switch_body.py | 79 +++++ 7 files changed, 386 insertions(+), 4 deletions(-) rename vrt/lib/{expanded_header_switch_body.h => expanded_header_parse_switch_body.h} (100%) create mode 100644 vrt/lib/expanded_header_unparse_switch_body.h rename vrt/lib/{gen_switch_body.py => gen_parse_switch_body.py} (100%) create mode 100755 vrt/lib/gen_unparse_switch_body.py diff --git a/vrt/include/vrt/expanded_header.h b/vrt/include/vrt/expanded_header.h index 0cfca04a..b3333a72 100644 --- a/vrt/include/vrt/expanded_header.h +++ b/vrt/include/vrt/expanded_header.h @@ -27,6 +27,9 @@ namespace vrt { + static const size_t HEADER_MAX_N32_BIT_WORDS = 7; + static const size_t TRAILER_MAX_N32_BIT_WORDS = 1; + /*! * \brief All headers and trailer for VRT IF-Data, Extension-Data, * IF-Context and Extension-Context packets. @@ -73,7 +76,17 @@ namespace vrt { bool trailer_p() const { return (header & VRTH_HAS_TRAILER) != 0 && data_p(); } - // parser + /*! + * \brief unparse expanded header, fill-in the words of a vrt packet header and trailer + * This method is only intended to fill the buffers with header and trailer information. + * The actual handling of the separate header, payload, trailer buffers is up to the caller. + */ + static void unparse(const expanded_header *hdr, // in + size_t n32_bit_words_payload, // in + uint32_t *header, // out + size_t *n32_bit_words_header, // out + uint32_t *trailer, // out + size_t *n32_bit_words_trailer);// out /*! * \brief parse packet, fill-in expanded header, start of payload and len of payload diff --git a/vrt/lib/Makefile.am b/vrt/lib/Makefile.am index 3a758eea..f2fcce0c 100644 --- a/vrt/lib/Makefile.am +++ b/vrt/lib/Makefile.am @@ -42,9 +42,11 @@ libvrt_la_LIBADD = noinst_HEADERS = \ data_handler.h \ expanded_header_cw_tables.h \ - expanded_header_switch_body.h \ + expanded_header_parse_switch_body.h \ + expanded_header_unparse_switch_body.h \ socket_rx_buffer.h EXTRA_DIST = \ gen_cw_tables.py \ - gen_switch_body.py + gen_parse_switch_body.py \ + gen_unparse_switch_body.py diff --git a/vrt/lib/expanded_header.cc b/vrt/lib/expanded_header.cc index bd1d92e5..64e97ef9 100644 --- a/vrt/lib/expanded_header.cc +++ b/vrt/lib/expanded_header.cc @@ -71,6 +71,22 @@ namespace vrt { return cw; } + void expanded_header::unparse(const expanded_header *h, // in + size_t n32_bit_words_payload, // in + uint32_t *header, // out + size_t *n32_bit_words_header, // out + uint32_t *trailer, // out + size_t *n32_bit_words_trailer){// out + int cw = compute_codeword(*h); + //fills in the header (except word0), header length, trailer, trailer length + switch (cw & 0x1f){ +#include "expanded_header_unparse_switch_body.h" + } + //fill in the header word 0 with the calculated length + size_t n32_bit_words_packet = *n32_bit_words_header + n32_bit_words_payload + *n32_bit_words_trailer; + header[0] = htonl((h->header & ~VRTH_PKT_SIZE_MASK) | (n32_bit_words_packet & VRTH_PKT_SIZE_MASK)); + } + bool expanded_header::parse(const uint32_t *packet, // in size_t n32_bit_words_packet, // in @@ -109,7 +125,7 @@ namespace vrt { // h->header, cw, cw_header_len(cw), cw_trailer_len(cw)); switch (cw & 0x1f){ -#include "expanded_header_switch_body.h" +#include "expanded_header_parse_switch_body.h" } return true; diff --git a/vrt/lib/expanded_header_switch_body.h b/vrt/lib/expanded_header_parse_switch_body.h similarity index 100% rename from vrt/lib/expanded_header_switch_body.h rename to vrt/lib/expanded_header_parse_switch_body.h diff --git a/vrt/lib/expanded_header_unparse_switch_body.h b/vrt/lib/expanded_header_unparse_switch_body.h new file mode 100644 index 00000000..ca6e1498 --- /dev/null +++ b/vrt/lib/expanded_header_unparse_switch_body.h @@ -0,0 +1,272 @@ + case 0: + *n32_bit_words_header = 1; + *n32_bit_words_trailer = 0; + break; + + case 1: + header[1] = htonl(h->stream_id); + *n32_bit_words_header = 2; + *n32_bit_words_trailer = 0; + break; + + case 2: + header[1] = htonl((uint32_t)((h->class_id >> 32) & 0xffffffff)); + header[2] = htonl((uint32_t)((h->class_id >> 0) & 0xffffffff)); + *n32_bit_words_header = 3; + *n32_bit_words_trailer = 0; + break; + + case 3: + header[1] = htonl(h->stream_id); + header[2] = htonl((uint32_t)((h->class_id >> 32) & 0xffffffff)); + header[3] = htonl((uint32_t)((h->class_id >> 0) & 0xffffffff)); + *n32_bit_words_header = 4; + *n32_bit_words_trailer = 0; + break; + + case 4: + header[1] = htonl(h->integer_secs); + *n32_bit_words_header = 2; + *n32_bit_words_trailer = 0; + break; + + case 5: + header[1] = htonl(h->stream_id); + header[2] = htonl(h->integer_secs); + *n32_bit_words_header = 3; + *n32_bit_words_trailer = 0; + break; + + case 6: + header[1] = htonl((uint32_t)((h->class_id >> 32) & 0xffffffff)); + header[2] = htonl((uint32_t)((h->class_id >> 0) & 0xffffffff)); + header[3] = htonl(h->integer_secs); + *n32_bit_words_header = 4; + *n32_bit_words_trailer = 0; + break; + + case 7: + header[1] = htonl(h->stream_id); + header[2] = htonl((uint32_t)((h->class_id >> 32) & 0xffffffff)); + header[3] = htonl((uint32_t)((h->class_id >> 0) & 0xffffffff)); + header[4] = htonl(h->integer_secs); + *n32_bit_words_header = 5; + *n32_bit_words_trailer = 0; + break; + + case 8: + header[1] = htonl((uint32_t)((h->fractional_secs >> 32) & 0xffffffff)); + header[2] = htonl((uint32_t)((h->fractional_secs >> 0) & 0xffffffff)); + *n32_bit_words_header = 3; + *n32_bit_words_trailer = 0; + break; + + case 9: + header[1] = htonl(h->stream_id); + header[2] = htonl((uint32_t)((h->fractional_secs >> 32) & 0xffffffff)); + header[3] = htonl((uint32_t)((h->fractional_secs >> 0) & 0xffffffff)); + *n32_bit_words_header = 4; + *n32_bit_words_trailer = 0; + break; + + case 10: + header[1] = htonl((uint32_t)((h->class_id >> 32) & 0xffffffff)); + header[2] = htonl((uint32_t)((h->class_id >> 0) & 0xffffffff)); + header[3] = htonl((uint32_t)((h->fractional_secs >> 32) & 0xffffffff)); + header[4] = htonl((uint32_t)((h->fractional_secs >> 0) & 0xffffffff)); + *n32_bit_words_header = 5; + *n32_bit_words_trailer = 0; + break; + + case 11: + header[1] = htonl(h->stream_id); + header[2] = htonl((uint32_t)((h->class_id >> 32) & 0xffffffff)); + header[3] = htonl((uint32_t)((h->class_id >> 0) & 0xffffffff)); + header[4] = htonl((uint32_t)((h->fractional_secs >> 32) & 0xffffffff)); + header[5] = htonl((uint32_t)((h->fractional_secs >> 0) & 0xffffffff)); + *n32_bit_words_header = 6; + *n32_bit_words_trailer = 0; + break; + + case 12: + header[1] = htonl(h->integer_secs); + header[2] = htonl((uint32_t)((h->fractional_secs >> 32) & 0xffffffff)); + header[3] = htonl((uint32_t)((h->fractional_secs >> 0) & 0xffffffff)); + *n32_bit_words_header = 4; + *n32_bit_words_trailer = 0; + break; + + case 13: + header[1] = htonl(h->stream_id); + header[2] = htonl(h->integer_secs); + header[3] = htonl((uint32_t)((h->fractional_secs >> 32) & 0xffffffff)); + header[4] = htonl((uint32_t)((h->fractional_secs >> 0) & 0xffffffff)); + *n32_bit_words_header = 5; + *n32_bit_words_trailer = 0; + break; + + case 14: + header[1] = htonl((uint32_t)((h->class_id >> 32) & 0xffffffff)); + header[2] = htonl((uint32_t)((h->class_id >> 0) & 0xffffffff)); + header[3] = htonl(h->integer_secs); + header[4] = htonl((uint32_t)((h->fractional_secs >> 32) & 0xffffffff)); + header[5] = htonl((uint32_t)((h->fractional_secs >> 0) & 0xffffffff)); + *n32_bit_words_header = 6; + *n32_bit_words_trailer = 0; + break; + + case 15: + header[1] = htonl(h->stream_id); + header[2] = htonl((uint32_t)((h->class_id >> 32) & 0xffffffff)); + header[3] = htonl((uint32_t)((h->class_id >> 0) & 0xffffffff)); + header[4] = htonl(h->integer_secs); + header[5] = htonl((uint32_t)((h->fractional_secs >> 32) & 0xffffffff)); + header[6] = htonl((uint32_t)((h->fractional_secs >> 0) & 0xffffffff)); + *n32_bit_words_header = 7; + *n32_bit_words_trailer = 0; + break; + + case 16: + *n32_bit_words_header = 1; + trailer[0] = htonl(h->trailer); + *n32_bit_words_trailer = 1; + break; + + case 17: + header[1] = htonl(h->stream_id); + *n32_bit_words_header = 2; + trailer[0] = htonl(h->trailer); + *n32_bit_words_trailer = 1; + break; + + case 18: + header[1] = htonl((uint32_t)((h->class_id >> 32) & 0xffffffff)); + header[2] = htonl((uint32_t)((h->class_id >> 0) & 0xffffffff)); + *n32_bit_words_header = 3; + trailer[0] = htonl(h->trailer); + *n32_bit_words_trailer = 1; + break; + + case 19: + header[1] = htonl(h->stream_id); + header[2] = htonl((uint32_t)((h->class_id >> 32) & 0xffffffff)); + header[3] = htonl((uint32_t)((h->class_id >> 0) & 0xffffffff)); + *n32_bit_words_header = 4; + trailer[0] = htonl(h->trailer); + *n32_bit_words_trailer = 1; + break; + + case 20: + header[1] = htonl(h->integer_secs); + *n32_bit_words_header = 2; + trailer[0] = htonl(h->trailer); + *n32_bit_words_trailer = 1; + break; + + case 21: + header[1] = htonl(h->stream_id); + header[2] = htonl(h->integer_secs); + *n32_bit_words_header = 3; + trailer[0] = htonl(h->trailer); + *n32_bit_words_trailer = 1; + break; + + case 22: + header[1] = htonl((uint32_t)((h->class_id >> 32) & 0xffffffff)); + header[2] = htonl((uint32_t)((h->class_id >> 0) & 0xffffffff)); + header[3] = htonl(h->integer_secs); + *n32_bit_words_header = 4; + trailer[0] = htonl(h->trailer); + *n32_bit_words_trailer = 1; + break; + + case 23: + header[1] = htonl(h->stream_id); + header[2] = htonl((uint32_t)((h->class_id >> 32) & 0xffffffff)); + header[3] = htonl((uint32_t)((h->class_id >> 0) & 0xffffffff)); + header[4] = htonl(h->integer_secs); + *n32_bit_words_header = 5; + trailer[0] = htonl(h->trailer); + *n32_bit_words_trailer = 1; + break; + + case 24: + header[1] = htonl((uint32_t)((h->fractional_secs >> 32) & 0xffffffff)); + header[2] = htonl((uint32_t)((h->fractional_secs >> 0) & 0xffffffff)); + *n32_bit_words_header = 3; + trailer[0] = htonl(h->trailer); + *n32_bit_words_trailer = 1; + break; + + case 25: + header[1] = htonl(h->stream_id); + header[2] = htonl((uint32_t)((h->fractional_secs >> 32) & 0xffffffff)); + header[3] = htonl((uint32_t)((h->fractional_secs >> 0) & 0xffffffff)); + *n32_bit_words_header = 4; + trailer[0] = htonl(h->trailer); + *n32_bit_words_trailer = 1; + break; + + case 26: + header[1] = htonl((uint32_t)((h->class_id >> 32) & 0xffffffff)); + header[2] = htonl((uint32_t)((h->class_id >> 0) & 0xffffffff)); + header[3] = htonl((uint32_t)((h->fractional_secs >> 32) & 0xffffffff)); + header[4] = htonl((uint32_t)((h->fractional_secs >> 0) & 0xffffffff)); + *n32_bit_words_header = 5; + trailer[0] = htonl(h->trailer); + *n32_bit_words_trailer = 1; + break; + + case 27: + header[1] = htonl(h->stream_id); + header[2] = htonl((uint32_t)((h->class_id >> 32) & 0xffffffff)); + header[3] = htonl((uint32_t)((h->class_id >> 0) & 0xffffffff)); + header[4] = htonl((uint32_t)((h->fractional_secs >> 32) & 0xffffffff)); + header[5] = htonl((uint32_t)((h->fractional_secs >> 0) & 0xffffffff)); + *n32_bit_words_header = 6; + trailer[0] = htonl(h->trailer); + *n32_bit_words_trailer = 1; + break; + + case 28: + header[1] = htonl(h->integer_secs); + header[2] = htonl((uint32_t)((h->fractional_secs >> 32) & 0xffffffff)); + header[3] = htonl((uint32_t)((h->fractional_secs >> 0) & 0xffffffff)); + *n32_bit_words_header = 4; + trailer[0] = htonl(h->trailer); + *n32_bit_words_trailer = 1; + break; + + case 29: + header[1] = htonl(h->stream_id); + header[2] = htonl(h->integer_secs); + header[3] = htonl((uint32_t)((h->fractional_secs >> 32) & 0xffffffff)); + header[4] = htonl((uint32_t)((h->fractional_secs >> 0) & 0xffffffff)); + *n32_bit_words_header = 5; + trailer[0] = htonl(h->trailer); + *n32_bit_words_trailer = 1; + break; + + case 30: + header[1] = htonl((uint32_t)((h->class_id >> 32) & 0xffffffff)); + header[2] = htonl((uint32_t)((h->class_id >> 0) & 0xffffffff)); + header[3] = htonl(h->integer_secs); + header[4] = htonl((uint32_t)((h->fractional_secs >> 32) & 0xffffffff)); + header[5] = htonl((uint32_t)((h->fractional_secs >> 0) & 0xffffffff)); + *n32_bit_words_header = 6; + trailer[0] = htonl(h->trailer); + *n32_bit_words_trailer = 1; + break; + + case 31: + header[1] = htonl(h->stream_id); + header[2] = htonl((uint32_t)((h->class_id >> 32) & 0xffffffff)); + header[3] = htonl((uint32_t)((h->class_id >> 0) & 0xffffffff)); + header[4] = htonl(h->integer_secs); + header[5] = htonl((uint32_t)((h->fractional_secs >> 32) & 0xffffffff)); + header[6] = htonl((uint32_t)((h->fractional_secs >> 0) & 0xffffffff)); + *n32_bit_words_header = 7; + trailer[0] = htonl(h->trailer); + *n32_bit_words_trailer = 1; + break; + diff --git a/vrt/lib/gen_switch_body.py b/vrt/lib/gen_parse_switch_body.py similarity index 100% rename from vrt/lib/gen_switch_body.py rename to vrt/lib/gen_parse_switch_body.py diff --git a/vrt/lib/gen_unparse_switch_body.py b/vrt/lib/gen_unparse_switch_body.py new file mode 100755 index 00000000..6c7cd01b --- /dev/null +++ b/vrt/lib/gen_unparse_switch_body.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python +# +# Copyright 2009 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio 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, or (at your option) +# any later version. +# +# GNU Radio 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 this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# + +import sys + +# dispatch codeword bits +HAS_STREAM_ID = 1 << 0; +HAS_CLASS_ID = 1 << 1; +HAS_INTEGER_SECS = 1 << 2; +HAS_FRACTIONAL_SECS = 1 << 3; +HAS_TRAILER = 1 << 4; + +def do_case(f, cw): + + def do32(name, mask, index): + if cw & mask: + f.write(" header[%d] = htonl(h->%s);\n" % (index, name)) + return 1 + return 0 + + def do64(name, mask, index): + if cw & mask: + f.write(" header[%d] = htonl((uint32_t)((h->%s >> 32) & 0xffffffff));\n" % (index, name)) + f.write(" header[%d] = htonl((uint32_t)((h->%s >> 0) & 0xffffffff));\n" % (index+1, name)) + return 2 + return 0 + + def dolength(index): + f.write(" *n32_bit_words_header = %d;\n"%index) + + def dotrailer(name, mask): + if cw & mask: + f.write(" trailer[%d] = htonl(h->%s);\n" % (0, name)) + f.write(" *n32_bit_words_trailer = 1;\n") + return 1 + else: + f.write(" *n32_bit_words_trailer = 0;\n") + return 0 + + f.write(" case %d:\n" % (cw,)) + + index = 1 + index += do32("stream_id", HAS_STREAM_ID, index) + index += do64("class_id", HAS_CLASS_ID, index) + index += do32("integer_secs", HAS_INTEGER_SECS, index) + index += do64("fractional_secs", HAS_FRACTIONAL_SECS, index) + dolength(index) + dotrailer("trailer", HAS_TRAILER) + + f.write(" break;\n\n") + + +def main(): + f = sys.stdout + + for cw in range(32): + do_case(f, cw) + + +if __name__ == '__main__': + main() -- 2.39.5