[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 06/24: digital: updates to packet_formatter
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 06/24: digital: updates to packet_formatter classes and parsing blocks. |
Date: |
Tue, 14 Jun 2016 00:40:57 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
jcorgan pushed a commit to branch packet2
in repository gnuradio.
commit a20bd92f676cca9bfbc727a8c219710ec352cc0a
Author: Tom Rondeau <address@hidden>
Date: Fri Mar 11 11:58:07 2016 -0500
digital: updates to packet_formatter classes and parsing blocks.
Emits PMT_F message when header parsing fails.
When we exit the loop prematurely, return false and the number of
items we've processed so far. This tells the parser block to emit a
PMT_F message that should be used to reset any other blocks' states
(like the header/payload demux block).
Adding loggers to packet_formatter class for easier debugging.
---
.../gnuradio/digital/packet_formatter_default.h | 24 ++++++++++++++--
gr-digital/lib/packet_formatter_default.cc | 33 +++++++++++++---------
gr-digital/lib/packet_parse_b_impl.cc | 14 ++++++---
gr-digital/lib/packet_parse_f_impl.cc | 14 ++++++---
gr-digital/lib/qa_packet_formatters.cc | 12 +++++---
5 files changed, 68 insertions(+), 29 deletions(-)
diff --git a/gr-digital/include/gnuradio/digital/packet_formatter_default.h
b/gr-digital/include/gnuradio/digital/packet_formatter_default.h
index 71355d7..371a92c 100644
--- a/gr-digital/include/gnuradio/digital/packet_formatter_default.h
+++ b/gr-digital/include/gnuradio/digital/packet_formatter_default.h
@@ -25,6 +25,7 @@
#include <pmt/pmt.h>
#include <gnuradio/digital/api.h>
#include <gnuradio/digital/header_buffer.h>
+#include <gnuradio/logger.h>
#include <boost/enable_shared_from_this.hpp>
namespace gr {
@@ -178,10 +179,15 @@ namespace gr {
* Each packet has a single PMT dictionary of info, so
* the vector length is the number of packets received
* extracted during one call to this parser function.
+ * \param nbits_processed Number of input bits actually
+ * processed; If all goes well, this is nbits_in. A
+ * premature return after a bad header could be less than
+ * this.
*/
virtual bool parse(int nbits_in,
const unsigned char *input,
- std::vector<pmt::pmt_t> &info);
+ std::vector<pmt::pmt_t> &info,
+ int &nbits_processed);
/*!
* Parses a header of the form:
@@ -212,10 +218,15 @@ namespace gr {
* Each packet has a single PMT dictionary of info, so
* the vector length is the number of packets received
* extracted during one call to this parser function.
+ * \param nbits_processed Number of input bits actually
+ * processed; If all goes well, this is nbits_in. A
+ * premature return after a bad header could be less than
+ * this.
*/
virtual bool parse_soft(int nbits_in,
const float *input,
- std::vector<pmt::pmt_t> &info);
+ std::vector<pmt::pmt_t> &info,
+ int &nbits_processed);
/*!
* Returns the length of the formatted header in bits.
@@ -275,6 +286,8 @@ namespace gr {
uint16_t d_bps; //!< bits/sec of payload modulation
+ int d_nbits; //!< num bits processed since reset
+
//! Enter Search state of the state machine to find the access code.
virtual void enter_search();
@@ -291,7 +304,12 @@ namespace gr {
* rest of data in d_info dictionary.
*/
virtual int header_payload();
- };
+
+ /*! Used by blocks to access the logger system.
+ */
+ gr::logger_ptr d_logger;
+ gr::logger_ptr d_debug_logger;
+ };
} // namespace digital
} // namespace gr
diff --git a/gr-digital/lib/packet_formatter_default.cc
b/gr-digital/lib/packet_formatter_default.cc
index 6ac5a83..053918b 100644
--- a/gr-digital/lib/packet_formatter_default.cc
+++ b/gr-digital/lib/packet_formatter_default.cc
@@ -50,6 +50,8 @@ namespace gr {
d_threshold = 0;
d_data_reg = 0;
d_bps = 1; // set in child classes that use this
+
+ configure_default_loggers(d_logger, d_debug_logger, "packet formatter");
}
packet_formatter_default::~packet_formatter_default()
@@ -124,16 +126,17 @@ namespace gr {
bool
packet_formatter_default::parse(int nbits_in,
const unsigned char *input,
- std::vector<pmt::pmt_t> &info)
+ std::vector<pmt::pmt_t> &info,
+ int &nbits_processed)
{
- int count = 0;
+ nbits_processed = 0;
- while(count < nbits_in) {
+ while(nbits_processed < nbits_in) {
switch(d_state) {
case STATE_SYNC_SEARCH: // Look for the access code correlation
- while(count < nbits_in) {
+ while(nbits_processed < nbits_in) {
// shift in new data
- d_data_reg = (d_data_reg << 1) | ((input[count++]) & 0x1);
+ d_data_reg = (d_data_reg << 1) | ((input[nbits_processed++]) &
0x1);
// compute hamming distance between desired access code and
current data
uint64_t wrong_bits = 0;
@@ -150,8 +153,8 @@ namespace gr {
break;
case STATE_HAVE_SYNC:
- while(count <= nbits_in) { // Shift bits one at a time into header
- d_hdr_reg.insert_bit(input[count++]);
+ while(nbits_processed <= nbits_in) { // Shift bits one at a time
into header
+ d_hdr_reg.insert_bit(input[nbits_processed++]);
if(d_hdr_reg.length() == (header_nbits()-d_access_code_len)) {
// we have a full header, check to see if it has been received
properly
if(header_ok()) {
@@ -161,6 +164,7 @@ namespace gr {
}
else {
enter_search(); // bad header
+ return false;
}
break;
}
@@ -175,17 +179,18 @@ namespace gr {
bool
packet_formatter_default::parse_soft(int nbits_in,
const float *input,
- std::vector<pmt::pmt_t> &info)
+ std::vector<pmt::pmt_t> &info,
+ int &nbits_processed)
{
- int count = 0;
+ nbits_processed = 0;
- while(count < nbits_in) {
+ while(nbits_processed < nbits_in) {
switch(d_state) {
case STATE_SYNC_SEARCH: // Look for the access code correlation
- while(count < nbits_in) {
+ while(nbits_processed < nbits_in) {
// shift in new data
- d_data_reg = (d_data_reg << 1) |
(gr::branchless_binary_slicer(input[count++]) & 0x1);
+ d_data_reg = (d_data_reg << 1) |
(gr::branchless_binary_slicer(input[nbits_processed++]) & 0x1);
// compute hamming distance between desired access code and
current data
uint64_t wrong_bits = 0;
@@ -202,8 +207,8 @@ namespace gr {
break;
case STATE_HAVE_SYNC:
- while(count < nbits_in) { // Shift bits one at a time into header
- d_hdr_reg.insert_bit(gr::branchless_binary_slicer(input[count++]));
+ while(nbits_processed < nbits_in) { // Shift bits one at a time
into header
+
d_hdr_reg.insert_bit(gr::branchless_binary_slicer(input[nbits_processed++]));
if(d_hdr_reg.length() == (header_nbits()-d_access_code_len)) {
// we have a full header, check to see if it has been received
properly
diff --git a/gr-digital/lib/packet_parse_b_impl.cc
b/gr-digital/lib/packet_parse_b_impl.cc
index 01f1653..fb1a65c 100644
--- a/gr-digital/lib/packet_parse_b_impl.cc
+++ b/gr-digital/lib/packet_parse_b_impl.cc
@@ -79,14 +79,20 @@ namespace gr {
{
const unsigned char *in = (const unsigned char*)input_items[0];
+ int count = 0;
std::vector<pmt::pmt_t> info;
- d_formatter->parse(noutput_items, in, info);
+ bool ret = d_formatter->parse(noutput_items, in, info, count);
- for(size_t i = 0; i < info.size(); i++) {
- message_port_pub(d_out_port, info[i]);
+ if(ret) {
+ for(size_t i = 0; i < info.size(); i++) {
+ message_port_pub(d_out_port, info[i]);
+ }
+ }
+ else {
+ message_port_pub(d_out_port, pmt::PMT_F);
}
- return noutput_items;
+ return count;
}
} /* namespace digital */
diff --git a/gr-digital/lib/packet_parse_f_impl.cc
b/gr-digital/lib/packet_parse_f_impl.cc
index 8a45e11..3fe65ba 100644
--- a/gr-digital/lib/packet_parse_f_impl.cc
+++ b/gr-digital/lib/packet_parse_f_impl.cc
@@ -78,14 +78,20 @@ namespace gr {
{
const float *in = (const float*)input_items[0];
+ int count = 0;
std::vector<pmt::pmt_t> info;
- d_formatter->parse_soft(noutput_items, in, info);
+ bool ret = d_formatter->parse_soft(noutput_items, in, info, count);
- for(size_t i = 0; i < info.size(); i++) {
- message_port_pub(d_out_port, info[i]);
+ if(ret) {
+ for(size_t i = 0; i < info.size(); i++) {
+ message_port_pub(d_out_port, info[i]);
+ }
+ }
+ else {
+ message_port_pub(d_out_port, pmt::PMT_F);
}
- return noutput_items;
+ return count;
}
} /* namespace digital */
diff --git a/gr-digital/lib/qa_packet_formatters.cc
b/gr-digital/lib/qa_packet_formatters.cc
index a36c55a..97696d7 100644
--- a/gr-digital/lib/qa_packet_formatters.cc
+++ b/gr-digital/lib/qa_packet_formatters.cc
@@ -118,8 +118,9 @@ qa_packet_formatters::test_default_parse()
formatter = gr::digital::packet_formatter_default::make(ac);
formatter->set_threshold(0);
+ int count = 0;
std::vector<pmt::pmt_t> info;
- bool ret = formatter->parse(nbits, bits, info);
+ bool ret = formatter->parse(nbits, bits, info, count);
CPPUNIT_ASSERT(ret);
CPPUNIT_ASSERT_EQUAL((size_t)1, info.size());
@@ -184,8 +185,9 @@ qa_packet_formatters::test_default_parse_soft()
formatter = gr::digital::packet_formatter_default::make(ac);
formatter->set_threshold(0);
+ int count = 0;
std::vector<pmt::pmt_t> info;
- bool ret = formatter->parse_soft(nbits, soft, info);
+ bool ret = formatter->parse_soft(nbits, soft, info, count);
CPPUNIT_ASSERT(ret);
CPPUNIT_ASSERT_EQUAL((size_t)1, info.size());
@@ -311,8 +313,9 @@ qa_packet_formatters::test_counter_parse()
formatter = gr::digital::packet_formatter_counter::make(ac, expected_bps);
formatter->set_threshold(0);
+ int count = 0;
std::vector<pmt::pmt_t> info;
- bool ret = formatter->parse(nbits, bits, info);
+ bool ret = formatter->parse(nbits, bits, info, count);
CPPUNIT_ASSERT(ret);
CPPUNIT_ASSERT_EQUAL((size_t)1, info.size());
@@ -388,8 +391,9 @@ qa_packet_formatters::test_counter_parse_soft()
formatter = gr::digital::packet_formatter_counter::make(ac, expected_bps);
formatter->set_threshold(0);
+ int count = 0;
std::vector<pmt::pmt_t> info;
- bool ret = formatter->parse_soft(nbits, soft, info);
+ bool ret = formatter->parse_soft(nbits, soft, info, count);
CPPUNIT_ASSERT(ret);
CPPUNIT_ASSERT_EQUAL((size_t)1, info.size());
- [Commit-gnuradio] [gnuradio] branch packet2 created (now 93acb5b), git, 2016/06/13
- [Commit-gnuradio] [gnuradio] 11/24: digital: fixed packet parser QA tests, git, 2016/06/13
- [Commit-gnuradio] [gnuradio] 04/24: digital: Cleaning up some of the packet parsing code., git, 2016/06/13
- [Commit-gnuradio] [gnuradio] 12/24: blocks: Adds a multiple (complex only) block that responds to tags., git, 2016/06/13
- [Commit-gnuradio] [gnuradio] 13/24: digital: Dealing with scaling issues with corr_est., git, 2016/06/13
- [Commit-gnuradio] [gnuradio] 09/24: digital: Removed parse_soft and packet_parse_f., git, 2016/06/13
- [Commit-gnuradio] [gnuradio] 15/24: digital: wip: packet formatters specify payload in symbols, not bits., git, 2016/06/13
- [Commit-gnuradio] [gnuradio] 03/24: Adding new test block to adjust the sample rate of a stream and make sure tags are being placed in the correct locations., git, 2016/06/13
- [Commit-gnuradio] [gnuradio] 06/24: digital: updates to packet_formatter classes and parsing blocks.,
git <=
- [Commit-gnuradio] [gnuradio] 08/24: digital: fixing PFB clock sync block handling of tags., git, 2016/06/13
- [Commit-gnuradio] [gnuradio] 23/24: digital: Fixing QA code for testing header formatter/parsers., git, 2016/06/13
- [Commit-gnuradio] [gnuradio] 14/24: digital: wip: pfb_clock_sync_ccf tag offset update., git, 2016/06/13
- [Commit-gnuradio] [gnuradio] 18/24: digital: fixing up some of the packet formatters since the new base class., git, 2016/06/13
- [Commit-gnuradio] [gnuradio] 17/24: docs: Adding documentation for packet comms, git, 2016/06/13
- [Commit-gnuradio] [gnuradio] 07/24: digital: Updates to corr_est block., git, 2016/06/13
- [Commit-gnuradio] [gnuradio] 20/24: digital: fixed packet_parse from using default formatter to base class, git, 2016/06/13
- [Commit-gnuradio] [gnuradio] 24/24: digital: fixed up some header_buffer issues and added QA., git, 2016/06/13
- [Commit-gnuradio] [gnuradio] 19/24: digital: adding more support for packet formatters., git, 2016/06/13
- [Commit-gnuradio] [gnuradio] 10/24: digital: Redid packet formatter class hierarchy., git, 2016/06/13