diff options
author | Tom Rondeau <tom@trondeau.com> | 2014-12-29 13:09:00 -0500 |
---|---|---|
committer | Tom Rondeau <tom@trondeau.com> | 2014-12-29 13:09:00 -0500 |
commit | 8c86d9490d5b33ed5652aa38984be457a472d199 (patch) | |
tree | e0026f3609e105b705b61acefab143b777b54df6 | |
parent | ccebbe0a028158df250aae02c1dd893dd1551dda (diff) | |
parent | b508945c8096a778a171ee70fe769d97924e4978 (diff) |
Merge branch 'maint'
Conflicts:
gr-fec/lib/decoder_impl.cc
gr-fec/lib/encoder_impl.cc
-rw-r--r-- | gr-digital/include/gnuradio/digital/correlate_access_code_bb_ts.h | 18 | ||||
-rw-r--r-- | gr-digital/include/gnuradio/digital/correlate_access_code_ff_ts.h | 8 | ||||
-rw-r--r-- | gr-digital/lib/correlate_access_code_bb_ts_impl.cc | 151 | ||||
-rw-r--r-- | gr-digital/lib/correlate_access_code_bb_ts_impl.h | 19 | ||||
-rw-r--r-- | gr-fec/include/gnuradio/fec/dummy_decoder.h | 1 | ||||
-rw-r--r-- | gr-fec/lib/decoder_impl.cc | 6 | ||||
-rw-r--r-- | gr-fec/lib/dummy_decoder_impl.cc | 10 | ||||
-rw-r--r-- | gr-fec/lib/dummy_decoder_impl.h | 1 | ||||
-rw-r--r-- | gr-fec/lib/encoder_impl.cc | 9 |
9 files changed, 143 insertions, 80 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 d311dda3c3..a933aec116 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 b0485b1d90..dfad78ccc4 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 e2fe02be4b..c04bf4e180 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 e829fc9e99..745ee1fc1c 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 */ diff --git a/gr-fec/include/gnuradio/fec/dummy_decoder.h b/gr-fec/include/gnuradio/fec/dummy_decoder.h index 071b57151e..0561803ea1 100644 --- a/gr-fec/include/gnuradio/fec/dummy_decoder.h +++ b/gr-fec/include/gnuradio/fec/dummy_decoder.h @@ -67,6 +67,7 @@ namespace gr { * Returns the coding rate of this encoder (it will always be 1). */ virtual double rate() = 0; + }; } /* namespace code */ diff --git a/gr-fec/lib/decoder_impl.cc b/gr-fec/lib/decoder_impl.cc index 62c301d501..d570c4077a 100644 --- a/gr-fec/lib/decoder_impl.cc +++ b/gr-fec/lib/decoder_impl.cc @@ -95,9 +95,6 @@ namespace gr { noutput_items/(output_multiple() - d_decoder->get_history()) : innum; - //GR_LOG_DEBUG(d_debug_logger, boost::format("%1%, %2%, %3%") \ - // % outnum % ninput_items[0] % items); - for(int i = 0; i < items; ++i) { d_decoder->generic_work((void*)(in+(i*d_decoder->get_input_size()*d_input_item_size)), (void*)(out+(i*d_decoder->get_output_size()*d_output_item_size))); @@ -109,9 +106,6 @@ namespace gr { int consumed = static_cast<int>(items/relative_rate()*(output_multiple() - d_decoder->get_history()) + 0.5); int returned = items*(output_multiple() - d_decoder->get_history()); - //GR_LOG_DEBUG(d_debug_logger, boost::format("consumed %1%") % consumed); - //GR_LOG_DEBUG(d_debug_logger, boost::format("returned %1%") % returned); - consume_each(consumed); return returned; } diff --git a/gr-fec/lib/dummy_decoder_impl.cc b/gr-fec/lib/dummy_decoder_impl.cc index 105057447f..f1bada4f5a 100644 --- a/gr-fec/lib/dummy_decoder_impl.cc +++ b/gr-fec/lib/dummy_decoder_impl.cc @@ -81,12 +81,6 @@ namespace gr { return "none"; } - float - dummy_decoder_impl::get_shift() - { - return 1; - } - bool dummy_decoder_impl::set_frame_size(unsigned int frame_size) { @@ -116,8 +110,8 @@ namespace gr { int8_t *out = (int8_t*)outbuffer; //memcpy(out, in, d_frame_size*sizeof(char)); - //volk_32f_binary_slicer_8i(out, in, d_frame_size); - volk_32f_s32f_convert_8i(out, in, 1.0/2.0, d_frame_size); + volk_32f_binary_slicer_8i(out, in, d_frame_size); + //volk_32f_s32f_convert_8i(out, in, 1.0/2.0, d_frame_size); } } /* namespace code */ diff --git a/gr-fec/lib/dummy_decoder_impl.h b/gr-fec/lib/dummy_decoder_impl.h index 4685a86f14..bcdd606f18 100644 --- a/gr-fec/lib/dummy_decoder_impl.h +++ b/gr-fec/lib/dummy_decoder_impl.h @@ -39,7 +39,6 @@ namespace gr { int get_output_size(); int get_input_size(); int get_input_item_size(); - float get_shift(); const char* get_input_conversion(); //const char* get_output_conversion(); diff --git a/gr-fec/lib/encoder_impl.cc b/gr-fec/lib/encoder_impl.cc index af72f31133..dfa1f48592 100644 --- a/gr-fec/lib/encoder_impl.cc +++ b/gr-fec/lib/encoder_impl.cc @@ -91,20 +91,11 @@ namespace gr { char *inbuffer = (char*)input_items[0]; char *outbuffer = (char*)output_items[0]; - //GR_LOG_DEBUG(d_debug_logger, boost::format("%1%, %2%, %3%") \ - // % noutput_items % ninput_items[0] % (noutput_items/output_multiple())); - - for(int i = 0; i < noutput_items/output_multiple(); i++) { d_encoder->generic_work((void*)(inbuffer+(i*d_input_size)), (void*)(outbuffer+(i*d_output_size))); } - //GR_LOG_DEBUG(d_debug_logger, boost::format("consuming: %1%") \ - // % (fixed_rate_noutput_to_ninput(noutput_items))); - //GR_LOG_DEBUG(d_debug_logger, boost::format("returning: %1%") \ - // % (noutput_items)); - consume_each(fixed_rate_noutput_to_ninput(noutput_items)); return noutput_items; } |