From 88a9e1f9332d54c1743d062adfaf48aa6d3040ff Mon Sep 17 00:00:00 2001
From: Tom Rondeau <trondeau@vt.edu>
Date: Tue, 27 Nov 2012 11:59:26 -0800
Subject: core: adding ability to handle extra data in headers.

---
 .../src/python/gnuradio/parse_file_metadata.py     | 24 ++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

(limited to 'gnuradio-core/src/python')

diff --git a/gnuradio-core/src/python/gnuradio/parse_file_metadata.py b/gnuradio-core/src/python/gnuradio/parse_file_metadata.py
index cff7566e41..c8a9fbde10 100644
--- a/gnuradio-core/src/python/gnuradio/parse_file_metadata.py
+++ b/gnuradio-core/src/python/gnuradio/parse_file_metadata.py
@@ -112,10 +112,12 @@ def parse_header(p, hdr_start, VERBOSE=False):
         r = gr.pmt_dict_ref(p, gr.pmt_string_to_symbol("strt"), dump)
         seg_start = gr.pmt_to_uint64(r)
         info["strt"] = seg_start
+        info["extra_len"] = seg_start - hdr_start - HEADER_LENGTH
+        info["has_extra"] = info["extra_len"] > 0
         if(VERBOSE):
             print "Segment Start: {0} bytes".format(seg_start)
-            print "Header Length: {0}".format((seg_start-hdr_start))
-            print "Extra Header? {0}".format((seg_start-hdr_start) > HEADER_LENGTH)
+            print "Extra Length: {0}".format((info["extra_len"]))
+            print "Extra Header? {0}".format(info["has_extra"])
     else:
         sys.stderr.write("Could not find key 'strt': invalid or corrupt data file.\n")
         sys.exit(1)
@@ -141,3 +143,21 @@ def parse_header(p, hdr_start, VERBOSE=False):
         sys.exit(1)
 
     return info
+
+# IF THERE IS EXTRA DATA, PULL OUT THE DICTIONARY AND PARSE IT
+def parse_extra_dict(p, info, VERBOSE=False):
+    if(gr.pmt_is_dict(p) is False):
+        sys.stderr.write("Extra header is not a PMT dictionary: invalid or corrupt data file.\n")
+        sys.exit(1)
+
+    items = gr.pmt_dict_items(p)
+    nitems = gr.pmt_length(items)
+    for i in xrange(nitems):
+        item = gr.pmt_nth(i, items)
+        key = gr.pmt_symbol_to_string(gr.pmt_car(item))
+        val = gr.pmt_to_double(gr.pmt_cdr(item))
+        info[key] = val
+        if(VERBOSE):
+            print "{0}: {1}".format(key, val)
+
+    return info
-- 
cgit v1.2.3