From: Josh Blum Date: Fri, 18 Dec 2009 00:48:54 +0000 (-0800) Subject: Added unparse capability to the vrt expanded header. X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=fc4fa0a1894f0f85be1a76e48b922effb3d5dd9b;p=debian%2Fgnuradio Added unparse capability to the vrt expanded header. Unparse can fill in a vrt header and trailer from an expanded header. --- 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_parse_switch_body.h b/vrt/lib/expanded_header_parse_switch_body.h new file mode 100644 index 00000000..40e575c2 --- /dev/null +++ b/vrt/lib/expanded_header_parse_switch_body.h @@ -0,0 +1,256 @@ + case 0: + h->stream_id = 0; + h->class_id = 0; + h->integer_secs = 0; + h->fractional_secs = 0; + h->trailer = 0; + break; + + case 1: + h->stream_id = ntohl(p[1]); + h->class_id = 0; + h->integer_secs = 0; + h->fractional_secs = 0; + h->trailer = 0; + break; + + case 2: + h->stream_id = 0; + h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); + h->integer_secs = 0; + h->fractional_secs = 0; + h->trailer = 0; + break; + + case 3: + h->stream_id = ntohl(p[1]); + h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); + h->integer_secs = 0; + h->fractional_secs = 0; + h->trailer = 0; + break; + + case 4: + h->stream_id = 0; + h->class_id = 0; + h->integer_secs = ntohl(p[1]); + h->fractional_secs = 0; + h->trailer = 0; + break; + + case 5: + h->stream_id = ntohl(p[1]); + h->class_id = 0; + h->integer_secs = ntohl(p[2]); + h->fractional_secs = 0; + h->trailer = 0; + break; + + case 6: + h->stream_id = 0; + h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); + h->integer_secs = ntohl(p[3]); + h->fractional_secs = 0; + h->trailer = 0; + break; + + case 7: + h->stream_id = ntohl(p[1]); + h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); + h->integer_secs = ntohl(p[4]); + h->fractional_secs = 0; + h->trailer = 0; + break; + + case 8: + h->stream_id = 0; + h->class_id = 0; + h->integer_secs = 0; + h->fractional_secs = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); + h->trailer = 0; + break; + + case 9: + h->stream_id = ntohl(p[1]); + h->class_id = 0; + h->integer_secs = 0; + h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); + h->trailer = 0; + break; + + case 10: + h->stream_id = 0; + h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); + h->integer_secs = 0; + h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]); + h->trailer = 0; + break; + + case 11: + h->stream_id = ntohl(p[1]); + h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); + h->integer_secs = 0; + h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]); + h->trailer = 0; + break; + + case 12: + h->stream_id = 0; + h->class_id = 0; + h->integer_secs = ntohl(p[1]); + h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); + h->trailer = 0; + break; + + case 13: + h->stream_id = ntohl(p[1]); + h->class_id = 0; + h->integer_secs = ntohl(p[2]); + h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]); + h->trailer = 0; + break; + + case 14: + h->stream_id = 0; + h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); + h->integer_secs = ntohl(p[3]); + h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]); + h->trailer = 0; + break; + + case 15: + h->stream_id = ntohl(p[1]); + h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); + h->integer_secs = ntohl(p[4]); + h->fractional_secs = ((uint64_t)(ntohl(p[5])) << 32) | ntohl(p[6]); + h->trailer = 0; + break; + + case 16: + h->stream_id = 0; + h->class_id = 0; + h->integer_secs = 0; + h->fractional_secs = 0; + h->trailer = ntohl(p[len-1]); + break; + + case 17: + h->stream_id = ntohl(p[1]); + h->class_id = 0; + h->integer_secs = 0; + h->fractional_secs = 0; + h->trailer = ntohl(p[len-1]); + break; + + case 18: + h->stream_id = 0; + h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); + h->integer_secs = 0; + h->fractional_secs = 0; + h->trailer = ntohl(p[len-1]); + break; + + case 19: + h->stream_id = ntohl(p[1]); + h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); + h->integer_secs = 0; + h->fractional_secs = 0; + h->trailer = ntohl(p[len-1]); + break; + + case 20: + h->stream_id = 0; + h->class_id = 0; + h->integer_secs = ntohl(p[1]); + h->fractional_secs = 0; + h->trailer = ntohl(p[len-1]); + break; + + case 21: + h->stream_id = ntohl(p[1]); + h->class_id = 0; + h->integer_secs = ntohl(p[2]); + h->fractional_secs = 0; + h->trailer = ntohl(p[len-1]); + break; + + case 22: + h->stream_id = 0; + h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); + h->integer_secs = ntohl(p[3]); + h->fractional_secs = 0; + h->trailer = ntohl(p[len-1]); + break; + + case 23: + h->stream_id = ntohl(p[1]); + h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); + h->integer_secs = ntohl(p[4]); + h->fractional_secs = 0; + h->trailer = ntohl(p[len-1]); + break; + + case 24: + h->stream_id = 0; + h->class_id = 0; + h->integer_secs = 0; + h->fractional_secs = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); + h->trailer = ntohl(p[len-1]); + break; + + case 25: + h->stream_id = ntohl(p[1]); + h->class_id = 0; + h->integer_secs = 0; + h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); + h->trailer = ntohl(p[len-1]); + break; + + case 26: + h->stream_id = 0; + h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); + h->integer_secs = 0; + h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]); + h->trailer = ntohl(p[len-1]); + break; + + case 27: + h->stream_id = ntohl(p[1]); + h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); + h->integer_secs = 0; + h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]); + h->trailer = ntohl(p[len-1]); + break; + + case 28: + h->stream_id = 0; + h->class_id = 0; + h->integer_secs = ntohl(p[1]); + h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); + h->trailer = ntohl(p[len-1]); + break; + + case 29: + h->stream_id = ntohl(p[1]); + h->class_id = 0; + h->integer_secs = ntohl(p[2]); + h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]); + h->trailer = ntohl(p[len-1]); + break; + + case 30: + h->stream_id = 0; + h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); + h->integer_secs = ntohl(p[3]); + h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]); + h->trailer = ntohl(p[len-1]); + break; + + case 31: + h->stream_id = ntohl(p[1]); + h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); + h->integer_secs = ntohl(p[4]); + h->fractional_secs = ((uint64_t)(ntohl(p[5])) << 32) | ntohl(p[6]); + h->trailer = ntohl(p[len-1]); + break; + diff --git a/vrt/lib/expanded_header_switch_body.h b/vrt/lib/expanded_header_switch_body.h deleted file mode 100644 index 40e575c2..00000000 --- a/vrt/lib/expanded_header_switch_body.h +++ /dev/null @@ -1,256 +0,0 @@ - case 0: - h->stream_id = 0; - h->class_id = 0; - h->integer_secs = 0; - h->fractional_secs = 0; - h->trailer = 0; - break; - - case 1: - h->stream_id = ntohl(p[1]); - h->class_id = 0; - h->integer_secs = 0; - h->fractional_secs = 0; - h->trailer = 0; - break; - - case 2: - h->stream_id = 0; - h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); - h->integer_secs = 0; - h->fractional_secs = 0; - h->trailer = 0; - break; - - case 3: - h->stream_id = ntohl(p[1]); - h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); - h->integer_secs = 0; - h->fractional_secs = 0; - h->trailer = 0; - break; - - case 4: - h->stream_id = 0; - h->class_id = 0; - h->integer_secs = ntohl(p[1]); - h->fractional_secs = 0; - h->trailer = 0; - break; - - case 5: - h->stream_id = ntohl(p[1]); - h->class_id = 0; - h->integer_secs = ntohl(p[2]); - h->fractional_secs = 0; - h->trailer = 0; - break; - - case 6: - h->stream_id = 0; - h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); - h->integer_secs = ntohl(p[3]); - h->fractional_secs = 0; - h->trailer = 0; - break; - - case 7: - h->stream_id = ntohl(p[1]); - h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); - h->integer_secs = ntohl(p[4]); - h->fractional_secs = 0; - h->trailer = 0; - break; - - case 8: - h->stream_id = 0; - h->class_id = 0; - h->integer_secs = 0; - h->fractional_secs = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); - h->trailer = 0; - break; - - case 9: - h->stream_id = ntohl(p[1]); - h->class_id = 0; - h->integer_secs = 0; - h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); - h->trailer = 0; - break; - - case 10: - h->stream_id = 0; - h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); - h->integer_secs = 0; - h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]); - h->trailer = 0; - break; - - case 11: - h->stream_id = ntohl(p[1]); - h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); - h->integer_secs = 0; - h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]); - h->trailer = 0; - break; - - case 12: - h->stream_id = 0; - h->class_id = 0; - h->integer_secs = ntohl(p[1]); - h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); - h->trailer = 0; - break; - - case 13: - h->stream_id = ntohl(p[1]); - h->class_id = 0; - h->integer_secs = ntohl(p[2]); - h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]); - h->trailer = 0; - break; - - case 14: - h->stream_id = 0; - h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); - h->integer_secs = ntohl(p[3]); - h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]); - h->trailer = 0; - break; - - case 15: - h->stream_id = ntohl(p[1]); - h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); - h->integer_secs = ntohl(p[4]); - h->fractional_secs = ((uint64_t)(ntohl(p[5])) << 32) | ntohl(p[6]); - h->trailer = 0; - break; - - case 16: - h->stream_id = 0; - h->class_id = 0; - h->integer_secs = 0; - h->fractional_secs = 0; - h->trailer = ntohl(p[len-1]); - break; - - case 17: - h->stream_id = ntohl(p[1]); - h->class_id = 0; - h->integer_secs = 0; - h->fractional_secs = 0; - h->trailer = ntohl(p[len-1]); - break; - - case 18: - h->stream_id = 0; - h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); - h->integer_secs = 0; - h->fractional_secs = 0; - h->trailer = ntohl(p[len-1]); - break; - - case 19: - h->stream_id = ntohl(p[1]); - h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); - h->integer_secs = 0; - h->fractional_secs = 0; - h->trailer = ntohl(p[len-1]); - break; - - case 20: - h->stream_id = 0; - h->class_id = 0; - h->integer_secs = ntohl(p[1]); - h->fractional_secs = 0; - h->trailer = ntohl(p[len-1]); - break; - - case 21: - h->stream_id = ntohl(p[1]); - h->class_id = 0; - h->integer_secs = ntohl(p[2]); - h->fractional_secs = 0; - h->trailer = ntohl(p[len-1]); - break; - - case 22: - h->stream_id = 0; - h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); - h->integer_secs = ntohl(p[3]); - h->fractional_secs = 0; - h->trailer = ntohl(p[len-1]); - break; - - case 23: - h->stream_id = ntohl(p[1]); - h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); - h->integer_secs = ntohl(p[4]); - h->fractional_secs = 0; - h->trailer = ntohl(p[len-1]); - break; - - case 24: - h->stream_id = 0; - h->class_id = 0; - h->integer_secs = 0; - h->fractional_secs = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); - h->trailer = ntohl(p[len-1]); - break; - - case 25: - h->stream_id = ntohl(p[1]); - h->class_id = 0; - h->integer_secs = 0; - h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); - h->trailer = ntohl(p[len-1]); - break; - - case 26: - h->stream_id = 0; - h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); - h->integer_secs = 0; - h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]); - h->trailer = ntohl(p[len-1]); - break; - - case 27: - h->stream_id = ntohl(p[1]); - h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); - h->integer_secs = 0; - h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]); - h->trailer = ntohl(p[len-1]); - break; - - case 28: - h->stream_id = 0; - h->class_id = 0; - h->integer_secs = ntohl(p[1]); - h->fractional_secs = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); - h->trailer = ntohl(p[len-1]); - break; - - case 29: - h->stream_id = ntohl(p[1]); - h->class_id = 0; - h->integer_secs = ntohl(p[2]); - h->fractional_secs = ((uint64_t)(ntohl(p[3])) << 32) | ntohl(p[4]); - h->trailer = ntohl(p[len-1]); - break; - - case 30: - h->stream_id = 0; - h->class_id = ((uint64_t)(ntohl(p[1])) << 32) | ntohl(p[2]); - h->integer_secs = ntohl(p[3]); - h->fractional_secs = ((uint64_t)(ntohl(p[4])) << 32) | ntohl(p[5]); - h->trailer = ntohl(p[len-1]); - break; - - case 31: - h->stream_id = ntohl(p[1]); - h->class_id = ((uint64_t)(ntohl(p[2])) << 32) | ntohl(p[3]); - h->integer_secs = ntohl(p[4]); - h->fractional_secs = ((uint64_t)(ntohl(p[5])) << 32) | ntohl(p[6]); - h->trailer = ntohl(p[len-1]); - break; - 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_parse_switch_body.py b/vrt/lib/gen_parse_switch_body.py new file mode 100755 index 00000000..105fa76a --- /dev/null +++ b/vrt/lib/gen_parse_switch_body.py @@ -0,0 +1,80 @@ +#!/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): + f.write(" ") + if cw & mask: + f.write("h->%s = ntohl(p[%d]);\n" % (name, index)) + return 1 + else: + f.write("h->%s = 0;\n" % (name,)) + return 0 + + def do64(name, mask, index): + f.write(" ") + if cw & mask: + f.write("h->%s = ((uint64_t)(ntohl(p[%d])) << 32) | ntohl(p[%d]);\n" % (name, index, index+1)) + return 2 + else: + f.write("h->%s = 0;\n" % (name,)) + return 0 + + def dotrailer(name, mask): + f.write(" ") + if cw & mask: + f.write("h->%s = ntohl(p[len-1]);\n" % (name,)) + return 1 + else: + f.write("h->%s = 0;\n" % (name,)) + 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) + 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() diff --git a/vrt/lib/gen_switch_body.py b/vrt/lib/gen_switch_body.py deleted file mode 100755 index 105fa76a..00000000 --- a/vrt/lib/gen_switch_body.py +++ /dev/null @@ -1,80 +0,0 @@ -#!/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): - f.write(" ") - if cw & mask: - f.write("h->%s = ntohl(p[%d]);\n" % (name, index)) - return 1 - else: - f.write("h->%s = 0;\n" % (name,)) - return 0 - - def do64(name, mask, index): - f.write(" ") - if cw & mask: - f.write("h->%s = ((uint64_t)(ntohl(p[%d])) << 32) | ntohl(p[%d]);\n" % (name, index, index+1)) - return 2 - else: - f.write("h->%s = 0;\n" % (name,)) - return 0 - - def dotrailer(name, mask): - f.write(" ") - if cw & mask: - f.write("h->%s = ntohl(p[len-1]);\n" % (name,)) - return 1 - else: - f.write("h->%s = 0;\n" % (name,)) - 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) - 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() 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()