Update revision to release 3.3.0-rc1, update autotools
[debian/gnuradio] / vrt / lib / expanded_header.cc
index d7da06af48a082fd45ef7bd1707a17e9fa21c377..8b22fb92549f845ab46d60b9a1cc455492d075ea 100644 (file)
@@ -57,8 +57,6 @@ namespace vrt {
   static const int HAS_FRACTIONAL_SECS = 1 << 3;
   static const int HAS_TRAILER         = 1 << 4;
 
-#include "expanded_header_cw_tables.h"
-
   static int
   compute_codeword(const expanded_header &h)
   {
@@ -71,6 +69,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
@@ -78,6 +92,8 @@ namespace vrt {
                        const uint32_t **payload,       // out
                        size_t *n32_bit_words_payload)  // out
   {
+    size_t n32_bit_words_header = 0;
+    size_t n32_bit_words_trailer = 0;
     size_t len = n32_bit_words_packet;
     const uint32_t *p = packet;
 
@@ -99,24 +115,18 @@ namespace vrt {
     len = h->pkt_size();       // valid length of packet
 
     int cw = compute_codeword(*h);
-    if (cw_header_len(cw) + cw_trailer_len(cw) > len)
-      return false;            // negative payload len
-
-    *payload = p + cw_header_len(cw);
-    *n32_bit_words_payload = len - (cw_header_len(cw) + cw_trailer_len(cw));
-
-    // printf("parse: hdr = 0x%08x, cw = 0x%02x, cw_header_len(cw) = %d, cw_trailer_len(cw) = %d\n",
-    //   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"
     }
 
-    /* is this a if context packet? */
-    if (ntohl(p[0]) & VRTH_PT_IF_CONTEXT){
-        *payload = p;
-        *n32_bit_words_payload = n32_bit_words_packet;
-    }
+    if (n32_bit_words_header + n32_bit_words_trailer > len)
+      return false;            // negative payload len
+
+    *payload = p + n32_bit_words_header;
+    *n32_bit_words_payload = len - (n32_bit_words_header + n32_bit_words_trailer);
+
+    // printf("parse: hdr = 0x%08x, cw = 0x%02x, n32_bit_words_header = %d, n32_bit_words_trailer = %d\n",
+    //   h->header, cw, n32_bit_words_header, n32_bit_words_trailer);
 
     return true;
   }