diff options
Diffstat (limited to 'gr-digital/lib')
-rw-r--r-- | gr-digital/lib/CMakeLists.txt | 5 | ||||
-rw-r--r-- | gr-digital/lib/correlate_access_code_bb_impl.cc | 10 | ||||
-rw-r--r-- | gr-digital/lib/correlate_access_code_bb_ts_impl.cc | 11 | ||||
-rw-r--r-- | gr-digital/lib/correlate_access_code_ff_ts_impl.cc | 11 | ||||
-rw-r--r-- | gr-digital/lib/correlate_access_code_tag_bb_impl.cc | 13 | ||||
-rw-r--r-- | gr-digital/lib/correlate_access_code_tag_ff_impl.cc | 132 | ||||
-rw-r--r-- | gr-digital/lib/correlate_access_code_tag_ff_impl.h | 61 | ||||
-rw-r--r-- | gr-digital/lib/costas_loop_cc_impl.cc | 66 | ||||
-rw-r--r-- | gr-digital/lib/header_format_counter.cc | 3 | ||||
-rw-r--r-- | gr-digital/lib/header_format_default.cc | 10 |
10 files changed, 245 insertions, 77 deletions
diff --git a/gr-digital/lib/CMakeLists.txt b/gr-digital/lib/CMakeLists.txt index 84f53ec4f3..9df6808d1c 100644 --- a/gr-digital/lib/CMakeLists.txt +++ b/gr-digital/lib/CMakeLists.txt @@ -29,12 +29,10 @@ include_directories( ${GR_BLOCKS_INCLUDE_DIRS} ${GNURADIO_RUNTIME_INCLUDE_DIRS} ${VOLK_INCLUDE_DIRS} - ${LOG4CPP_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} ) link_directories(${Boost_LIBRARY_DIRS}) -link_directories(${LOG4CPP_LIBRARY_DIRS}) if(ENABLE_GR_CTRLPORT) ADD_DEFINITIONS(-DGR_CTRLPORT) @@ -64,6 +62,7 @@ list(APPEND digital_sources corr_est_cc_impl.cc correlate_access_code_bb_impl.cc correlate_access_code_tag_bb_impl.cc + correlate_access_code_tag_ff_impl.cc correlate_access_code_bb_ts_impl.cc correlate_access_code_ff_ts_impl.cc correlate_and_sync_cc_impl.cc @@ -151,7 +150,6 @@ list(APPEND digital_libs gnuradio-analog ${VOLK_LIBRARIES} ${Boost_LIBRARIES} - ${LOG4CPP_LIBRARIES} ) add_library(gnuradio-digital SHARED ${digital_sources}) @@ -228,7 +226,6 @@ if(ENABLE_TESTING) gnuradio-digital ${Boost_LIBRARIES} ${CPPUNIT_LIBRARIES} - ${LOG4CPP_LIBRARIES} ) GR_ADD_TEST(test_gr_digital test-gr-digital) diff --git a/gr-digital/lib/correlate_access_code_bb_impl.cc b/gr-digital/lib/correlate_access_code_bb_impl.cc index 532871a407..a01eb6a2b5 100644 --- a/gr-digital/lib/correlate_access_code_bb_impl.cc +++ b/gr-digital/lib/correlate_access_code_bb_impl.cc @@ -27,14 +27,13 @@ #include "correlate_access_code_bb_impl.h" #include <gnuradio/io_signature.h> #include <gnuradio/blocks/count_bits.h> +#include <boost/format.hpp> #include <stdexcept> #include <cstdio> namespace gr { namespace digital { -#define VERBOSE 0 - correlate_access_code_bb::sptr correlate_access_code_bb::make(const std::string &access_code, int threshold) { @@ -51,6 +50,7 @@ namespace gr { d_threshold(threshold) { if(!set_access_code(access_code)) { + GR_LOG_ERROR(d_logger, "access_code is > 64 bits"); throw std::out_of_range ("access_code is > 64 bits"); } } @@ -109,14 +109,12 @@ namespace gr { // test for access code with up to threshold errors new_flag = (nwrong <= d_threshold); -#if VERBOSE if(new_flag) { - fprintf(stderr, "access code found: %llx\n", d_access_code); + GR_LOG_DEBUG(d_logger, boost::format("access code found: %llx") % d_access_code); } else { - fprintf(stderr, "%llx ==> %llx\n", d_access_code, d_data_reg); + GR_LOG_DEBUG(d_logger, boost::format("%llx ==> %llx") % d_access_code % d_data_reg); } -#endif // shift in new data and new flag d_data_reg = (d_data_reg << 1) | (in[i] & 0x1); 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 e2fe37d8bb..91b57feac3 100644 --- a/gr-digital/lib/correlate_access_code_bb_ts_impl.cc +++ b/gr-digital/lib/correlate_access_code_bb_ts_impl.cc @@ -26,6 +26,7 @@ #include "correlate_access_code_bb_ts_impl.h" #include <gnuradio/io_signature.h> +#include <boost/format.hpp> #include <stdexcept> #include <volk/volk.h> #include <cstdio> @@ -34,8 +35,6 @@ namespace gr { namespace digital { -#define VERBOSE 0 - correlate_access_code_bb_ts::sptr correlate_access_code_bb_ts::make(const std::string &access_code, int threshold, @@ -58,6 +57,7 @@ namespace gr { set_tag_propagation_policy(TPP_DONT); if(!set_access_code(access_code)) { + GR_LOG_ERROR(d_logger, "access_code is > 64 bits"); throw std::out_of_range ("access_code is > 64 bits"); } @@ -91,10 +91,9 @@ namespace gr { for(unsigned i=0; i < d_len; i++){ d_access_code = (d_access_code << 1) | (access_code[i] & 1); } - if(VERBOSE) { - std::cerr << "Access code: " << std::hex << d_access_code << std::dec << std::endl; - std::cerr << "Mask: " << std::hex << d_mask << std::dec << std::endl; - } + + GR_LOG_DEBUG(d_logger, boost::format("Access code: %llx") % d_access_code); + GR_LOG_DEBUG(d_logger, boost::format("Mask: %llx") % d_mask); return true; } diff --git a/gr-digital/lib/correlate_access_code_ff_ts_impl.cc b/gr-digital/lib/correlate_access_code_ff_ts_impl.cc index dfbac40505..21ff3fbda0 100644 --- a/gr-digital/lib/correlate_access_code_ff_ts_impl.cc +++ b/gr-digital/lib/correlate_access_code_ff_ts_impl.cc @@ -27,6 +27,7 @@ #include "correlate_access_code_ff_ts_impl.h" #include <gnuradio/io_signature.h> #include <gnuradio/math.h> +#include <boost/format.hpp> #include <stdexcept> #include <volk/volk.h> #include <cstdio> @@ -35,8 +36,6 @@ namespace gr { namespace digital { -#define VERBOSE 0 - correlate_access_code_ff_ts::sptr correlate_access_code_ff_ts::make(const std::string &access_code, int threshold, @@ -58,6 +57,7 @@ namespace gr { set_tag_propagation_policy(TPP_DONT); if(!set_access_code(access_code)) { + GR_LOG_ERROR(d_logger, "access_code is > 64 bits"); throw std::out_of_range ("access_code is > 64 bits"); } @@ -91,10 +91,9 @@ namespace gr { for(unsigned i=0; i < d_len; i++){ d_access_code = (d_access_code << 1) | (access_code[i] & 1); } - if(VERBOSE) { - std::cerr << "Access code: " << std::hex << d_access_code << std::dec << std::endl; - std::cerr << "Mask: " << std::hex << d_mask << std::dec << std::endl; - } + + GR_LOG_DEBUG(d_logger, boost::format("Access code: %llx") % d_access_code); + GR_LOG_DEBUG(d_logger, boost::format("Mask: %llx") % d_mask); return true; } diff --git a/gr-digital/lib/correlate_access_code_tag_bb_impl.cc b/gr-digital/lib/correlate_access_code_tag_bb_impl.cc index de2e1a06c3..753efa7a51 100644 --- a/gr-digital/lib/correlate_access_code_tag_bb_impl.cc +++ b/gr-digital/lib/correlate_access_code_tag_bb_impl.cc @@ -26,6 +26,7 @@ #include "correlate_access_code_tag_bb_impl.h" #include <gnuradio/io_signature.h> +#include <boost/format.hpp> #include <stdexcept> #include <volk/volk.h> #include <cstdio> @@ -34,8 +35,6 @@ namespace gr { namespace digital { -#define VERBOSE 0 - correlate_access_code_tag_bb::sptr correlate_access_code_tag_bb::make(const std::string &access_code, int threshold, @@ -56,6 +55,7 @@ namespace gr { d_threshold(threshold), d_len(0) { if(!set_access_code(access_code)) { + GR_LOG_ERROR(d_logger, "access_code is > 64 bits"); throw std::out_of_range ("access_code is > 64 bits"); } @@ -85,10 +85,8 @@ namespace gr { d_access_code = (d_access_code << 1) | (access_code[i] & 1); } - if(VERBOSE) { - std::cerr << "Access code: " << std::hex << d_access_code << std::dec << std::endl; - std::cerr << "Mask: " << std::hex << d_mask << std::dec << std::endl; - } + GR_LOG_DEBUG(d_logger, boost::format("Access code: %llx") % d_access_code); + GR_LOG_DEBUG(d_logger, boost::format("Mask: %llx") % d_mask); return true; } @@ -116,8 +114,7 @@ namespace gr { // 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; + GR_LOG_DEBUG(d_logger, boost::format("writing tag at sample %llu") % (abs_out_sample_cnt + i)); add_item_tag(0, //stream ID abs_out_sample_cnt + i, //sample d_key, //frame info diff --git a/gr-digital/lib/correlate_access_code_tag_ff_impl.cc b/gr-digital/lib/correlate_access_code_tag_ff_impl.cc new file mode 100644 index 0000000000..6efacbb08b --- /dev/null +++ b/gr-digital/lib/correlate_access_code_tag_ff_impl.cc @@ -0,0 +1,132 @@ +/* -*- c++ -*- */ +/* + * Copyright 2004,2006,2010-2012,2017 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. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "correlate_access_code_tag_ff_impl.h" +#include <gnuradio/io_signature.h> +#include <gnuradio/math.h> +#include <boost/format.hpp> +#include <stdexcept> +#include <volk/volk.h> +#include <cstdio> +#include <iostream> + +namespace gr { + namespace digital { + + correlate_access_code_tag_ff::sptr + correlate_access_code_tag_ff::make(const std::string &access_code, + int threshold, + const std::string &tag_name) + { + return gnuradio::get_initial_sptr + (new correlate_access_code_tag_ff_impl(access_code, + threshold, tag_name)); + } + + + correlate_access_code_tag_ff_impl::correlate_access_code_tag_ff_impl( + const std::string &access_code, int threshold, const std::string &tag_name) + : sync_block("correlate_access_code_tag_ff", + io_signature::make(1, 1, sizeof(float)), + io_signature::make(1, 1, sizeof(float))), + d_data_reg(0), d_mask(0), + d_threshold(threshold), d_len(0) + { + if(!set_access_code(access_code)) { + GR_LOG_ERROR(d_logger, "access_code is > 64 bits"); + throw std::out_of_range ("access_code is > 64 bits"); + } + + std::stringstream str; + str << name() << unique_id(); + d_me = pmt::string_to_symbol(str.str()); + d_key = pmt::string_to_symbol(tag_name); + } + + correlate_access_code_tag_ff_impl::~correlate_access_code_tag_ff_impl() + { + } + + bool + correlate_access_code_tag_ff_impl::set_access_code( + const std::string &access_code) + { + d_len = access_code.length(); // # of bytes in string + if(d_len > 64) + return false; + + // set len bottom bits to 1. + d_mask = ((~0ULL) >> (64 - d_len)); + + d_access_code = 0; + for(unsigned i=0; i < d_len; i++){ + d_access_code = (d_access_code << 1) | (access_code[i] & 1); + } + + GR_LOG_DEBUG(d_logger, boost::format("Access code: %llx") % d_access_code); + GR_LOG_DEBUG(d_logger, boost::format("Mask: %llx") % d_mask); + + return true; + } + + int + correlate_access_code_tag_ff_impl::work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items) + { + const float *in = (const float*)input_items[0]; + float *out = (float*)output_items[0]; + + uint64_t abs_out_sample_cnt = nitems_written(0); + + for(int i = 0; i < noutput_items; i++) { + out[i] = in[i]; + + // 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) | (gr::branchless_binary_slicer(in[i]) & 0x1); + if(nwrong <= d_threshold) { + GR_LOG_DEBUG(d_logger, boost::format("writing tag at sample %llu") % (abs_out_sample_cnt + i)); + add_item_tag(0, //stream ID + abs_out_sample_cnt + i, //sample + d_key, //frame info + pmt::from_long(nwrong), //data (number wrong) + d_me //block src id + ); + } + } + + return noutput_items; + } + + } /* namespace digital */ +} /* namespace gr */ diff --git a/gr-digital/lib/correlate_access_code_tag_ff_impl.h b/gr-digital/lib/correlate_access_code_tag_ff_impl.h new file mode 100644 index 0000000000..67d3ba2d6d --- /dev/null +++ b/gr-digital/lib/correlate_access_code_tag_ff_impl.h @@ -0,0 +1,61 @@ +/* -*- c++ -*- */ +/* + * Copyright 2005,2006,2011,2012,2017 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. + */ + +#ifndef INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_TAG_FF_IMPL_H +#define INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_TAG_FF_IMPL_H + +#include <gnuradio/digital/correlate_access_code_tag_ff.h> + +namespace gr { + namespace digital { + + class correlate_access_code_tag_ff_impl : + public correlate_access_code_tag_ff + { + private: + 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 + 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) + 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 + + public: + correlate_access_code_tag_ff_impl(const std::string &access_code, + int threshold, + const std::string &tag_name); + ~correlate_access_code_tag_ff_impl(); + + int work(int noutput_items, + gr_vector_const_void_star &input_items, + gr_vector_void_star &output_items); + + bool set_access_code(const std::string &access_code); + }; + + } /* namespace digital */ +} /* namespace gr */ + +#endif /* INCLUDED_DIGITAL_CORRELATE_ACCESS_CODE_TAG_FF_IMPL_H */ diff --git a/gr-digital/lib/costas_loop_cc_impl.cc b/gr-digital/lib/costas_loop_cc_impl.cc index d29d95684a..edf0db33ef 100644 --- a/gr-digital/lib/costas_loop_cc_impl.cc +++ b/gr-digital/lib/costas_loop_cc_impl.cc @@ -41,10 +41,13 @@ namespace gr { (new costas_loop_cc_impl(loop_bw, order, use_snr)); } + static int ios[] = { sizeof(gr_complex), sizeof(float), sizeof(float), sizeof(float) }; + static std::vector<int> iosig(ios, ios+sizeof(ios)/sizeof(int)); + costas_loop_cc_impl::costas_loop_cc_impl(float loop_bw, int order, bool use_snr) : sync_block("costas_loop_cc", io_signature::make(1, 1, sizeof(gr_complex)), - io_signature::make2(1, 2, sizeof(gr_complex), sizeof(float))), + io_signature::makev(1, 4, iosig)), blocks::control_loop(loop_bw, 1.0, -1.0), d_order(order), d_error(0), d_noise(1.0), d_phase_detector(NULL) { @@ -180,9 +183,9 @@ namespace gr { { const gr_complex *iptr = (gr_complex *) input_items[0]; gr_complex *optr = (gr_complex *) output_items[0]; - float *foptr = (float *) output_items[1]; - - bool write_foptr = output_items.size() >= 2; + float *freq_optr = output_items.size() >= 2 ? (float *) output_items[1] : NULL; + float *phase_optr = output_items.size() >= 3 ? (float *) output_items[2] : NULL; + float *error_optr = output_items.size() >= 4 ? (float *) output_items[3] : NULL; gr_complex nco_out; @@ -191,47 +194,30 @@ namespace gr { nitems_read(0)+noutput_items, pmt::intern("phase_est")); - if(write_foptr) { - for(int i = 0; i < noutput_items; i++) { - if(tags.size() > 0) { - if(tags[0].offset-nitems_read(0) == (size_t)i) { - d_phase = (float)pmt::to_double(tags[0].value); - tags.erase(tags.begin()); - } + for(int i = 0; i < noutput_items; i++) { + if(tags.size() > 0) { + if(tags[0].offset-nitems_read(0) == (size_t)i) { + d_phase = (float)pmt::to_double(tags[0].value); + tags.erase(tags.begin()); } - - nco_out = gr_expj(-d_phase); - optr[i] = iptr[i] * nco_out; - - d_error = (*this.*d_phase_detector)(optr[i]); - d_error = gr::branchless_clip(d_error, 1.0); - - advance_loop(d_error); - phase_wrap(); - frequency_limit(); - - foptr[i] = d_freq; } - } - else { - for(int i = 0; i < noutput_items; i++) { - if(tags.size() > 0) { - if(tags[0].offset-nitems_read(0) == (size_t)i) { - d_phase = (float)pmt::to_double(tags[0].value); - tags.erase(tags.begin()); - } - } - nco_out = gr_expj(-d_phase); - optr[i] = iptr[i] * nco_out; + nco_out = gr_expj(-d_phase); + optr[i] = iptr[i] * nco_out; - d_error = (*this.*d_phase_detector)(optr[i]); - d_error = gr::branchless_clip(d_error, 1.0); + d_error = (*this.*d_phase_detector)(optr[i]); + d_error = gr::branchless_clip(d_error, 1.0); - advance_loop(d_error); - phase_wrap(); - frequency_limit(); - } + advance_loop(d_error); + phase_wrap(); + frequency_limit(); + + if (freq_optr != NULL) + freq_optr[i] = d_freq; + if (phase_optr != NULL) + phase_optr[i] = d_phase; + if (error_optr != NULL) + error_optr[i] = d_error; } return noutput_items; diff --git a/gr-digital/lib/header_format_counter.cc b/gr-digital/lib/header_format_counter.cc index 6244ec1679..078d7d4be1 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 1b7a60e17f..621a801729 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); } |