commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] [gnuradio] 01/02: digital: Add Bits per Symbol paramet


From: git
Subject: [Commit-gnuradio] [gnuradio] 01/02: digital: Add Bits per Symbol parameter to header_format_default
Date: Tue, 21 Mar 2017 04:36:18 +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 aabe4f825a5ffeac5cbe446cd7203f6efd79ade9
Author: Brian Orr <address@hidden>
Date:   Thu Jan 26 18:06:40 2017 -0800

    digital: Add Bits per Symbol parameter to header_format_default
    
    Added payload bits per symbol parameter to the header_format_default
    block. This allows it to be used with payload modulations besides, for
    example, BPSK.
    
    Fixes #1162
---
 gr-digital/grc/variable_header_format_default.xml  | 13 ++++--
 .../gnuradio/digital/header_format_counter.h       |  1 -
 .../gnuradio/digital/header_format_default.h       | 10 ++++-
 gr-digital/lib/header_format_counter.cc            |  3 +-
 gr-digital/lib/header_format_default.cc            | 10 ++---
 gr-digital/python/digital/qa_packet_format.py      | 47 +++++++++++++++++++++-
 6 files changed, 70 insertions(+), 14 deletions(-)

diff --git a/gr-digital/grc/variable_header_format_default.xml 
b/gr-digital/grc/variable_header_format_default.xml
index 55b361f..8872760 100644
--- a/gr-digital/grc/variable_header_format_default.xml
+++ b/gr-digital/grc/variable_header_format_default.xml
@@ -10,12 +10,12 @@
   <import>from gnuradio import digital</import>
   <var_make>
 #if int($access_code())==0 #
-self.$(id) = $(id) = 
digital.header_format_default(digital.packet_utils.default_access_code, 
$threshold)
+self.$(id) = $(id) = 
digital.header_format_default(digital.packet_utils.default_access_code, 
$threshold, $bps)
 #else
-self.$(id) = $(id) = digital.header_format_default($access_code, $threshold)
+self.$(id) = $(id) = digital.header_format_default($access_code, $threshold, 
$bps)
 #end if
   </var_make>
-  <var_value>digital.header_format_default($access_code, 
$threshold)</var_value>
+  <var_value>digital.header_format_default($access_code, $threshold, 
$bps)</var_value>
   <make></make>
 
   <param>
@@ -32,4 +32,11 @@ self.$(id) = $(id) = 
digital.header_format_default($access_code, $threshold)
     <type>int</type>
   </param>
 
+  <param>
+    <name>Payload Bits per Symbol</name>
+    <key>bps</key>
+    <value>1</value>
+    <type>int</type>
+  </param>
+
 </block>
diff --git a/gr-digital/include/gnuradio/digital/header_format_counter.h 
b/gr-digital/include/gnuradio/digital/header_format_counter.h
index 5eb075a..752a9ec 100644
--- a/gr-digital/include/gnuradio/digital/header_format_counter.h
+++ b/gr-digital/include/gnuradio/digital/header_format_counter.h
@@ -112,7 +112,6 @@ namespace gr {
 
     protected:
       uint16_t d_counter;    //!< keeps track of the number of packets 
transmitted
-      uint16_t d_bps;        //!< bits/sec of payload modulation
 
       //! Verify that the header is valid
       bool header_ok();
diff --git a/gr-digital/include/gnuradio/digital/header_format_default.h 
b/gr-digital/include/gnuradio/digital/header_format_default.h
index 4abd7bb..bfea356 100644
--- a/gr-digital/include/gnuradio/digital/header_format_default.h
+++ b/gr-digital/include/gnuradio/digital/header_format_default.h
@@ -82,7 +82,8 @@ namespace gr {
       : public header_format_base
     {
      public:
-      header_format_default(const std::string &access_code, int threshold);
+      header_format_default(const std::string &access_code, int threshold,
+                            int bps);
       virtual ~header_format_default();
 
       /*!
@@ -179,13 +180,18 @@ namespace gr {
        * receiver. Can be up to 64-bits long.
        * \param threshold How many bits can be wrong in the access
        * code and still count as correct.
+       * \param bps The number of bits/second used in the payload's
+       * modulator.
        */
-      static sptr make(const std::string &access_code, int threshold);
+      static sptr make(const std::string &access_code, int threshold,
+                       int bps = 1);
 
     protected:
       uint64_t d_access_code;        //!< register to hold the access code
       size_t d_access_code_len;      //!< length in bits of the access code
 
+      uint16_t d_bps;                //!< bits/sec of payload modulation
+
       unsigned long long d_data_reg; //!< used to look for access_code
       unsigned long long d_mask;     /*!< masks access_code bits (top N bits 
are set where
                                        N is the number of bits in the access 
code) */
diff --git a/gr-digital/lib/header_format_counter.cc 
b/gr-digital/lib/header_format_counter.cc
index 6244ec1..078d7d4 100644
--- a/gr-digital/lib/header_format_counter.cc
+++ b/gr-digital/lib/header_format_counter.cc
@@ -44,9 +44,8 @@ namespace gr {
 
     header_format_counter::header_format_counter(const std::string 
&access_code,
                                                  int threshold, int bps)
-      : header_format_default(access_code, threshold)
+      : header_format_default(access_code, threshold, bps)
     {
-      d_bps = bps;
       d_counter = 0;
     }
 
diff --git a/gr-digital/lib/header_format_default.cc 
b/gr-digital/lib/header_format_default.cc
index 1b7a60e..621a801 100644
--- a/gr-digital/lib/header_format_default.cc
+++ b/gr-digital/lib/header_format_default.cc
@@ -34,16 +34,16 @@ namespace gr {
 
     header_format_default::sptr
     header_format_default::make(const std::string &access_code,
-                                int threshold)
+                                int threshold, int bps)
     {
       return header_format_default::sptr
-        (new header_format_default(access_code, threshold));
+       (new header_format_default(access_code, threshold, bps));
     }
 
     header_format_default::header_format_default(const std::string 
&access_code,
-                                                 int threshold)
+                                                 int threshold, int bps)
       : header_format_base(),
-        d_data_reg(0), d_mask(0), d_threshold(0),
+        d_bps(bps), d_data_reg(0), d_mask(0), d_threshold(0),
         d_pkt_len(0), d_pkt_count(0), d_nbits(0)
     {
       if(!set_access_code(access_code)) {
@@ -214,7 +214,7 @@ namespace gr {
 
       d_info = pmt::make_dict();
       d_info = pmt::dict_add(d_info, pmt::intern("payload symbols"),
-                             pmt::from_long(8*len));
+                             pmt::from_long(8*len / d_bps));
       return static_cast<int>(len);
     }
 
diff --git a/gr-digital/python/digital/qa_packet_format.py 
b/gr-digital/python/digital/qa_packet_format.py
index 6440b80..ae1a79f 100644
--- a/gr-digital/python/digital/qa_packet_format.py
+++ b/gr-digital/python/digital/qa_packet_format.py
@@ -20,7 +20,7 @@
 # Boston, MA 02110-1301, USA.
 #
 
-import random, time, struct
+import time, struct
 import pmt
 from gnuradio import gr, gr_unittest, digital, blocks
 from gnuradio.digital import packet_utils
@@ -80,6 +80,51 @@ class test_packet_format_fb(gr_unittest.TestCase):
         self.assertEqual(send_str, payload[0:length])
 
 
+    def test_packet_parse_default(self):
+        ac = packet_utils.default_access_code
+        length = '0000000000000001'
+
+        hdr_format_1bps = digital.header_format_default(ac, 0)
+        hdr_format_4bps = digital.header_format_default(ac, 0, 4)
+
+        ac_bits = [int(x) & 1 for x in ac]
+        length_bits = [int(x) & 1 for x in length]
+        header_bits = ac_bits + length_bits + length_bits
+
+        src_hdr = blocks.vector_source_b(header_bits)
+
+        parser_1bps = digital.protocol_parser_b(hdr_format_1bps)
+        parser_4bps = digital.protocol_parser_b(hdr_format_4bps)
+
+        snk_hdr_1bps = blocks.message_debug()
+        snk_hdr_4bps = blocks.message_debug()
+
+        self.tb.connect(src_hdr, parser_1bps)
+        self.tb.connect(src_hdr, parser_4bps)
+
+        self.tb.msg_connect(parser_1bps, 'info', snk_hdr_1bps, 'store')
+        self.tb.msg_connect(parser_4bps, 'info', snk_hdr_4bps, 'store')
+
+        self.tb.start()
+        while (snk_hdr_1bps.num_messages() < 1) and 
(snk_hdr_4bps.num_messages() < 1):
+            time.sleep(0.1)
+        self.tb.stop()
+        self.tb.wait()
+
+        result_1bps = snk_hdr_1bps.get_message(0)
+        result_4bps = snk_hdr_4bps.get_message(0)
+
+        self.assertTrue(pmt.dict_has_key(
+            result_1bps, pmt.intern('payload symbols')))
+        self.assertEqual(pmt.to_long(pmt.dict_ref(
+            result_1bps, pmt.intern('payload symbols'), pmt.PMT_F)), 8)
+
+        self.assertTrue(pmt.dict_has_key(
+            result_4bps, pmt.intern('payload symbols')))
+        self.assertEqual(pmt.to_long(pmt.dict_ref(
+            result_4bps, pmt.intern('payload symbols'), pmt.PMT_F)), 2)
+
+
     def test_packet_format_async_counter(self):
         bps = 2
         ac = packet_utils.default_access_code



reply via email to

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