commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] [gnuradio] 10/17: Add QA code to HDLC framer/deframer.


From: git
Subject: [Commit-gnuradio] [gnuradio] 10/17: Add QA code to HDLC framer/deframer.
Date: Mon, 31 Mar 2014 20:15:53 +0000 (UTC)

This is an automated email from the git hooks/post-receive script.

jcorgan pushed a commit to branch master
in repository gnuradio.

commit 6b9afd3f8eeb1ddcc571d24b2d82d951c6b504d0
Author: Nick Foster <address@hidden>
Date:   Thu Mar 27 17:50:41 2014 -0700

    Add QA code to HDLC framer/deframer.
---
 .../include/gnuradio/digital/hdlc_framer_pb.h      |  9 ++-
 gr-digital/lib/hdlc_deframer_bp_impl.cc            | 62 +++++++++++----------
 gr-digital/lib/hdlc_framer_pb_impl.cc              |  4 +-
 gr-digital/python/digital/qa_hdlc_framer.py        | 64 ++++++++++++++++++++++
 4 files changed, 106 insertions(+), 33 deletions(-)

diff --git a/gr-digital/include/gnuradio/digital/hdlc_framer_pb.h 
b/gr-digital/include/gnuradio/digital/hdlc_framer_pb.h
index f516628..d2931a9 100644
--- a/gr-digital/include/gnuradio/digital/hdlc_framer_pb.h
+++ b/gr-digital/include/gnuradio/digital/hdlc_framer_pb.h
@@ -30,11 +30,18 @@ namespace gr {
   namespace digital {
 
     /*!
-     * \brief HDLC framer which takes in PDU blobs (char data) and outputs HDLC
+     * \brief HDLC framer which takes in PMT binary blobs and outputs HDLC
      * frames as unpacked bits, with CRC and bit stuffing added. The first 
sample
      * of the frame is tagged with the tag frame_tag_name and includes a
      * length field for tagged_stream use.
      *
+     * This block outputs one whole frame at a time; if there is not enough
+     * output buffer space to fit a frame, it is pushed onto a queue. As a 
result
+     * flowgraphs which only run for a finite number of samples may not receive
+     * all frames in the queue, due to the scheduler's granularity. For
+     * flowgraphs that stream continuously (anything using a USRP) this should
+     * not be an issue.
+     *
      * \ingroup digital
      *
      */
diff --git a/gr-digital/lib/hdlc_deframer_bp_impl.cc 
b/gr-digital/lib/hdlc_deframer_bp_impl.cc
index c0e52cb..69f0f8c 100644
--- a/gr-digital/lib/hdlc_deframer_bp_impl.cc
+++ b/gr-digital/lib/hdlc_deframer_bp_impl.cc
@@ -118,37 +118,39 @@ namespace gr {
         uint64_t abs_sample_cnt = nitems_read(0);
         get_tags_in_range(frame_tags, 0, abs_sample_cnt, abs_sample_cnt + 
noutput_items, pmt::string_to_symbol(d_frame_tag_name));
 
-        if(frame_tags.size() == 0) return noutput_items;
-        int start_pos = frame_tags[0].offset - abs_sample_cnt;
-        if(frame_tags.size() == 1) return start_pos; //start here next time
-        int end_pos   = frame_tags[1].offset - abs_sample_cnt;
-        int pkt_len   = frame_tags[1].offset - frame_tags[0].offset - 8; 
//omit EOF delim
-        if(pkt_len > d_length_max) return end_pos; //arbitrary, too long for a 
real pkt
-        if(pkt_len <= d_length_min)  return end_pos;
-
-        //get bit array
-        std::vector<unsigned char> pkt_bits(pkt_len);
-        memcpy(&pkt_bits[0], &in[start_pos], pkt_bits.size());
-
-        unstuff(pkt_bits);
-
-        //pack into bytes (and correct bit order)
-        std::vector<unsigned char> pkt_bytes = pack(pkt_bits);
-
-        //strip off the CRC
-        unsigned int crc = (int(pkt_bytes[pkt_bytes.size()-1]) << 8)
-                         + pkt_bytes[pkt_bytes.size()-2];
-        pkt_bytes.erase(pkt_bytes.end()-2, pkt_bytes.end());
-        unsigned int calc_crc = crc_ccitt(pkt_bytes);
-
-        if(crc == calc_crc) {
-            //publish
-            //TODO manage padding
-            pmt::pmt_t pdu(pmt::cons(pmt::PMT_NIL,
-                                     pmt::make_blob(&pkt_bytes[0], 
pkt_bytes.size())));
-            message_port_pub(pmt::mp("out"), pdu);
+        int end_pos = 0;
+        while(frame_tags.size() > 0) {
+            int start_pos = frame_tags[0].offset - abs_sample_cnt;
+            if(frame_tags.size() == 1) return start_pos; //start here next time
+            end_pos   = frame_tags[1].offset - abs_sample_cnt;
+            int pkt_len   = frame_tags[1].offset - frame_tags[0].offset - 8; 
//omit EOF delim
+            if(pkt_len > d_length_max) return end_pos; //arbitrary, too long 
for a real pkt
+            if(pkt_len <= d_length_min)  return end_pos;
+
+            //get bit array
+            std::vector<unsigned char> pkt_bits(pkt_len);
+            memcpy(&pkt_bits[0], &in[start_pos], pkt_bits.size());
+
+            unstuff(pkt_bits);
+
+            //pack into bytes (and correct bit order)
+            std::vector<unsigned char> pkt_bytes = pack(pkt_bits);
+
+            //strip off the CRC
+            unsigned int crc = (int(pkt_bytes[pkt_bytes.size()-1]) << 8)
+                                    + pkt_bytes[pkt_bytes.size()-2];
+            pkt_bytes.erase(pkt_bytes.end()-2, pkt_bytes.end());
+            unsigned int calc_crc = crc_ccitt(pkt_bytes);
+
+            if(crc == calc_crc) {
+                //publish
+                //TODO manage padding
+                pmt::pmt_t pdu(pmt::cons(pmt::PMT_NIL,
+                                        pmt::make_blob(&pkt_bytes[0], 
pkt_bytes.size())));
+                message_port_pub(pmt::mp("out"), pdu);
+            }
+            frame_tags.erase(frame_tags.begin());
         }
-
         // Tell runtime system how many output items we produced.
         return end_pos;
     }
diff --git a/gr-digital/lib/hdlc_framer_pb_impl.cc 
b/gr-digital/lib/hdlc_framer_pb_impl.cc
index 0111f60..27dec52 100644
--- a/gr-digital/lib/hdlc_framer_pb_impl.cc
+++ b/gr-digital/lib/hdlc_framer_pb_impl.cc
@@ -128,8 +128,8 @@ namespace gr {
         }
 
         //get PDU
-        pmt::pmt_t msg(delete_head_nowait(pmt::string_to_symbol("in")));
-        if(msg.get() == NULL) return 0;
+        pmt::pmt_t msg(delete_head_nowait(pmt::mp("in")));
+        if(msg.get() == NULL) return oidx;
 
         pmt::pmt_t len(pmt::car(msg)); //TODO for non-mult-8 nbits
         pmt::pmt_t blob(pmt::cdr(msg));
diff --git a/gr-digital/python/digital/qa_hdlc_framer.py 
b/gr-digital/python/digital/qa_hdlc_framer.py
new file mode 100755
index 0000000..f8d1923
--- /dev/null
+++ b/gr-digital/python/digital/qa_hdlc_framer.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python
+#
+# Copyright 2006,2007,2010,2011,2013 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 GNU Radio; see the file COPYING.  If not, write to
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
+# 
+
+from gnuradio import gr, gr_unittest, digital, blocks
+import pmt
+import numpy
+from time import sleep
+
+class test_hdlc_framer(gr_unittest.TestCase):
+    def setUp(self):
+        self.tb = gr.top_block()
+
+    def tearDown(self):
+        self.tb = None
+
+    def test_001(self):
+        #test complementary operation of framer & deframer
+        #want to frame some random data that has enough consecutive bits to
+        #stuff at least a few bits
+        npkts = 20
+        src_data = [0xFE, 0xDA, 0xAC, 0x29, 0x7F, 0xA2, 0x90, 0x0F, 0xF8]
+        frame   = digital.hdlc_framer_pb("wat")
+        corr    = digital.correlate_access_code_tag_bb("01111110", 0, "frame")
+        deframe = digital.hdlc_deframer_bp("frame", 32, 500)
+        debug   = blocks.message_debug()
+        self.tb.connect(frame, corr, deframe)
+        self.tb.msg_connect(deframe, "out", debug, "store")
+        self.tb.start()
+        msg = pmt.cons(pmt.PMT_NIL, pmt.init_u8vector(len(src_data),src_data))
+        for i in xrange(npkts):
+            frame.to_basic_block()._post(pmt.intern("in"), msg)
+        sleep(0.2)
+        self.tb.stop()
+        self.tb.wait()
+        rxmsg = debug.get_message(0)
+        result_len = pmt.blob_length(pmt.cdr(rxmsg))
+        msg_data = []
+        for j in xrange(result_len):
+            msg_data.append(pmt.u8vector_ref(pmt.cdr(rxmsg), j))
+        self.assertEqual(src_data, msg_data)
+
+
+if __name__ == '__main__':
+    gr_unittest.run(test_hdlc_framer, "test_hdlc_framer.xml")
+



reply via email to

[Prev in Thread] Current Thread [Next in Thread]