[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] [gnuradio] 01/03: digital: fixed byte-in, byte-out ver
From: |
git |
Subject: |
[Commit-gnuradio] [gnuradio] 01/03: digital: fixed byte-in, byte-out version of the TSB correlate access code. Matches behavior of the float-in, float-out for bit streams. |
Date: |
Mon, 29 Dec 2014 18:30:06 +0000 (UTC) |
This is an automated email from the git hooks/post-receive script.
trondeau pushed a commit to branch maint
in repository gnuradio.
commit 9a689e6f6acf4db777cbd2a9c2dda757510d0f93
Author: Tom Rondeau <address@hidden>
Date: Mon Dec 29 12:23:38 2014 -0500
digital: fixed byte-in, byte-out version of the TSB correlate access code.
Matches behavior of the float-in, float-out for bit streams.
---
.../gnuradio/digital/correlate_access_code_bb_ts.h | 18 ++-
.../gnuradio/digital/correlate_access_code_ff_ts.h | 8 +-
gr-digital/lib/correlate_access_code_bb_ts_impl.cc | 151 ++++++++++++++-------
gr-digital/lib/correlate_access_code_bb_ts_impl.h | 19 ++-
4 files changed, 140 insertions(+), 56 deletions(-)
diff --git a/gr-digital/include/gnuradio/digital/correlate_access_code_bb_ts.h
b/gr-digital/include/gnuradio/digital/correlate_access_code_bb_ts.h
index d311dda..a933aec 100644
--- a/gr-digital/include/gnuradio/digital/correlate_access_code_bb_ts.h
+++ b/gr-digital/include/gnuradio/digital/correlate_access_code_bb_ts.h
@@ -35,12 +35,19 @@ namespace gr {
* \ingroup packet_operators_blk
*
* \details
- * input: stream of bits, 1 bit per input byte (data in LSB)
- * output: unaltered stream of bits (plus tags)
+ * input: stream of bits (unpacked bytes)
+ * output: a tagged stream set of bits from the payload following
+ * the access code and header.
*
- * This block annotates the input stream with tags. The tags have
- * key name [tag_name], specified in the constructor. Used for
- * searching an input data stream for preambles, etc.
+ * This block searches for the given access code by reading in the
+ * input bits. Once found, it expects the following 32 samples to
+ * contain a header that includes the frame length (16 bits for
+ * the length, repeated). It decodes the header to get the frame
+ * length in order to set up the the tagged stream key
+ * information.
+ *
+ * The output of this block is appropriate for use with tagged
+ * stream blocks.
*/
class DIGITAL_API correlate_access_code_bb_ts : virtual public block
{
@@ -63,6 +70,7 @@ namespace gr {
* e.g., "010101010111000100"
*/
virtual bool set_access_code(const std::string &access_code) = 0;
+ virtual unsigned long long access_code() const = 0;
};
} /* namespace digital */
diff --git a/gr-digital/include/gnuradio/digital/correlate_access_code_ff_ts.h
b/gr-digital/include/gnuradio/digital/correlate_access_code_ff_ts.h
index b0485b1..dfad78c 100644
--- a/gr-digital/include/gnuradio/digital/correlate_access_code_ff_ts.h
+++ b/gr-digital/include/gnuradio/digital/correlate_access_code_ff_ts.h
@@ -36,13 +36,15 @@ namespace gr {
*
* \details
* input: stream of floats (generally, soft decisions)
- * output: unaltered stream of floats in a tagged stream
+ * output: a tagged stream set of samples from the payload following
+ * the access code and header.
*
* This block searches for the given access code by slicing the
* soft decision symbol inputs. Once found, it expects the
* following 32 samples to contain a header that includes the
- * frame length. It decodes the header to get the frame length in
- * order to set up the the tagged stream key information.
+ * frame length (16 bits for the length, repeated). It decodes the
+ * header to get the frame length in order to set up the the
+ * tagged stream key information.
*
* The output of this block is appropriate for use with tagged
* stream blocks.
diff --git a/gr-digital/lib/correlate_access_code_bb_ts_impl.cc
b/gr-digital/lib/correlate_access_code_bb_ts_impl.cc
index e2fe02b..c04bf4e 100644
--- a/gr-digital/lib/correlate_access_code_bb_ts_impl.cc
+++ b/gr-digital/lib/correlate_access_code_bb_ts_impl.cc
@@ -38,8 +38,8 @@ namespace gr {
correlate_access_code_bb_ts::sptr
correlate_access_code_bb_ts::make(const std::string &access_code,
- int threshold,
- const std::string &tag_name)
+ int threshold,
+ const std::string &tag_name)
{
return gnuradio::get_initial_sptr
(new correlate_access_code_bb_ts_impl(access_code,
@@ -66,10 +66,11 @@ namespace gr {
d_me = pmt::string_to_symbol(str.str());
d_key = pmt::string_to_symbol(tag_name);
- // READ IN AS ARGS; MAKE SETTERS/GETTERS
- d_pkt_key = pmt::string_to_symbol("pkt_len");
- d_pkt_len = 120*8;
+ d_state = STATE_SYNC_SEARCH;
+ d_pkt_len = 0;
d_pkt_count = 0;
+ d_hdr_reg = 0;
+ d_hdr_count = 0;
}
correlate_access_code_bb_ts_impl::~correlate_access_code_bb_ts_impl()
@@ -77,8 +78,7 @@ namespace gr {
}
bool
- correlate_access_code_bb_ts_impl::set_access_code(
- const std::string &access_code)
+ correlate_access_code_bb_ts_impl::set_access_code(const std::string
&access_code)
{
d_len = access_code.length(); // # of bytes in string
if(d_len > 64)
@@ -99,6 +99,47 @@ namespace gr {
return true;
}
+ unsigned long long
+ correlate_access_code_bb_ts_impl::access_code() const
+ {
+ return d_access_code;
+ }
+
+ inline void
+ correlate_access_code_bb_ts_impl::enter_search()
+ {
+ d_state = STATE_SYNC_SEARCH;
+ }
+
+ inline void
+ correlate_access_code_bb_ts_impl::enter_have_sync()
+ {
+ d_state = STATE_HAVE_SYNC;
+ d_hdr_reg = 0;
+ d_hdr_count = 0;
+ }
+
+ inline void
+ correlate_access_code_bb_ts_impl::enter_have_header(int payload_len)
+ {
+ d_state = STATE_HAVE_HEADER;
+ d_pkt_len = 8*payload_len;
+ d_pkt_count = 0;
+ }
+
+ bool
+ correlate_access_code_bb_ts_impl::header_ok()
+ {
+ // confirm that two copies of header info are identical
+ return ((d_hdr_reg >> 16) ^ (d_hdr_reg & 0xffff)) == 0;
+ }
+
+ int
+ correlate_access_code_bb_ts_impl::header_payload()
+ {
+ return (d_hdr_reg >> 16) & 0x0fff;
+ }
+
int
correlate_access_code_bb_ts_impl::general_work(int noutput_items,
gr_vector_int &ninput_items,
@@ -112,57 +153,75 @@ namespace gr {
int nprod = 0;
- for(int i = 0; i < noutput_items; i++) {
- if(d_pkt_count > 0) {
- out[nprod] = in[i];
- d_pkt_count--;
- nprod++;
+ int count = 0;
+ while(count < noutput_items) {
+ switch(d_state) {
+ case STATE_SYNC_SEARCH: // Look for the access code correlation
- if(d_pkt_count == 0) {
- add_item_tag(0,
- abs_out_sample_cnt + i,
- pmt::intern("STOP"),
- pmt::from_long(abs_out_sample_cnt + nprod),
- d_me);
+ while(count < noutput_items) {
+ // shift in new data
+ d_data_reg = (d_data_reg << 1) | ((in[count++]) & 0x1);
+
+ // compute hamming distance between desired access code and
current data
+ uint64_t wrong_bits = 0;
+ uint64_t nwrong = d_threshold+1;
+
+ wrong_bits = (d_data_reg ^ d_access_code) & d_mask;
+ volk_64u_popcnt(&nwrong, wrong_bits);
+
+ if(nwrong <= d_threshold) {
+ enter_have_sync();
+ break;
+ }
}
- }
- else {
-
- // compute hamming distance between desired access code and current
data
- uint64_t wrong_bits = 0;
- uint64_t nwrong = d_threshold+1;
-
- wrong_bits = (d_data_reg ^ d_access_code) & d_mask;
- volk_64u_popcnt(&nwrong, wrong_bits);
-
- // shift in new data
- d_data_reg = (d_data_reg << 1) | (in[i] & 0x1);
- if(nwrong <= d_threshold) {
- if(VERBOSE)
- std::cerr << "writing tag at sample " << abs_out_sample_cnt + i
<< std::endl;
- add_item_tag(0, // stream ID
- abs_out_sample_cnt + nprod, // sample
- d_key, // frame info
- pmt::from_long(nwrong), // data (number wrong)
- d_me); // block src id
+ break;
+
+ case STATE_HAVE_SYNC:
+ while(count < noutput_items) { // Shift bits one at a time into
header
+ d_hdr_reg = (d_hdr_reg << 1) | (in[count++] & 0x1);
+ d_hdr_count++;
+
+ if(d_hdr_count == 32) {
+ // we have a full header, check to see if it has been received
properly
+ if(header_ok()) {
+ int payload_len = header_payload();
+ enter_have_header(payload_len);
+ }
+ else {
+ enter_search(); // bad header
+ }
+ break;
+ }
+ }
+ break;
+ case STATE_HAVE_HEADER:
+ if(d_pkt_count == 0) {
// MAKE A TAG OUT OF THIS AND UPDATE OFFSET
- add_item_tag(0, // stream ID
+ add_item_tag(0, // stream ID
abs_out_sample_cnt + nprod, // sample
- d_pkt_key, // length key
- pmt::from_long(d_pkt_len), // length data
- d_me); // block src id
- d_pkt_count = d_pkt_len;
- d_data_reg = 0;
+ d_key, // length key
+ pmt::from_long(d_pkt_len), // length data
+ d_me); // block src id
}
+
+ while(count < noutput_items) {
+ if(d_pkt_count < d_pkt_len) {
+ out[nprod++] = in[count++];
+ d_pkt_count++;
+ }
+ else {
+ enter_search();
+ break;
+ }
+ }
+ break;
}
}
- //std::cerr << "Producing data: " << nprod << std::endl;
consume_each(noutput_items);
return nprod;
}
} /* namespace digital */
} /* namespace gr */
-
diff --git a/gr-digital/lib/correlate_access_code_bb_ts_impl.h
b/gr-digital/lib/correlate_access_code_bb_ts_impl.h
index e829fc9..745ee1f 100644
--- a/gr-digital/lib/correlate_access_code_bb_ts_impl.h
+++ b/gr-digital/lib/correlate_access_code_bb_ts_impl.h
@@ -32,6 +32,10 @@ namespace gr {
public correlate_access_code_bb_ts
{
private:
+ enum state_t {STATE_SYNC_SEARCH, STATE_HAVE_SYNC, STATE_HAVE_HEADER};
+
+ state_t d_state;
+
unsigned long long d_access_code; // access code to locate start
of packet
// access code is left justified in
the word
unsigned long long d_data_reg; // used to look for access_code
@@ -40,10 +44,20 @@ namespace gr {
unsigned int d_threshold; // how many bits may be wrong in sync
vector
unsigned int d_len; // the length of the access code
- pmt::pmt_t d_key, d_me; //d_key is the tag name, d_me is the block name
+ unique ID
- pmt::pmt_t d_pkt_key;
+ unsigned long long d_hdr_reg; // used to look for header
+ int d_hdr_count;
+
+ pmt::pmt_t d_key, d_me; // d_key is the tag name, d_me is the block name
+ unique ID
int d_pkt_len, d_pkt_count;
+
+ void enter_search();
+ void enter_have_sync();
+ void enter_have_header(int payload_len);
+
+ bool header_ok();
+ int header_payload();
+
public:
correlate_access_code_bb_ts_impl(const std::string &access_code,
int threshold,
@@ -56,6 +70,7 @@ namespace gr {
gr_vector_void_star &output_items);
bool set_access_code(const std::string &access_code);
+ unsigned long long access_code() const;
};
} /* namespace digital */