From da7ca482a8030b60615ae59487d74f967cb259f4 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 2 Jul 2019 17:24:54 +0200 Subject: [PATCH 1/2] Hide direct constructor as private member --- .../input_filter/adapters/beamformer_filter.cc | 2 +- .../input_filter/gnuradio_blocks/beamformer.cc | 2 +- .../input_filter/gnuradio_blocks/beamformer.h | 4 ++-- .../input_filter/gnuradio_blocks/notch_cc.h | 12 ++++++++---- .../gnuradio_blocks/notch_lite_cc.h | 12 +++++++++--- .../gnuradio_blocks/pulse_blanking_cc.h | 11 +++++++---- .../signal_source/libs/gnss_sdr_valve.cc | 4 ++-- .../signal_source/libs/gnss_sdr_valve.h | 18 ++++++++++-------- .../tracking/tracking_pull-in_test.cc | 3 +-- 9 files changed, 41 insertions(+), 27 deletions(-) diff --git a/src/algorithms/input_filter/adapters/beamformer_filter.cc b/src/algorithms/input_filter/adapters/beamformer_filter.cc index 2975b8d1d..52f46ca6b 100644 --- a/src/algorithms/input_filter/adapters/beamformer_filter.cc +++ b/src/algorithms/input_filter/adapters/beamformer_filter.cc @@ -49,7 +49,7 @@ BeamformerFilter::BeamformerFilter( if (item_type_ == "gr_complex") { item_size_ = sizeof(gr_complex); - beamformer_ = make_beamformer(); + beamformer_ = make_beamformer_sptr(); DLOG(INFO) << "Item size " << item_size_; DLOG(INFO) << "resampler(" << beamformer_->unique_id() << ")"; } diff --git a/src/algorithms/input_filter/gnuradio_blocks/beamformer.cc b/src/algorithms/input_filter/gnuradio_blocks/beamformer.cc index 6f53c6099..9656f57d0 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/beamformer.cc +++ b/src/algorithms/input_filter/gnuradio_blocks/beamformer.cc @@ -36,7 +36,7 @@ #define GNSS_SDR_BEAMFORMER_CHANNELS 8 -beamformer_sptr make_beamformer() +beamformer_sptr make_beamformer_sptr() { return beamformer_sptr(new beamformer()); } diff --git a/src/algorithms/input_filter/gnuradio_blocks/beamformer.h b/src/algorithms/input_filter/gnuradio_blocks/beamformer.h index 55e9fcc27..b9cdd247a 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/beamformer.h +++ b/src/algorithms/input_filter/gnuradio_blocks/beamformer.h @@ -36,7 +36,7 @@ class beamformer; using beamformer_sptr = boost::shared_ptr; -beamformer_sptr make_beamformer(); +beamformer_sptr make_beamformer_sptr(); /*! * \brief This class implements a real-time software-defined spatial filter using the CTTC GNSS experimental antenna array input and a set of dynamically reloadable weights @@ -44,13 +44,13 @@ beamformer_sptr make_beamformer(); class beamformer : public gr::sync_block { public: - beamformer(); ~beamformer(); int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); private: friend beamformer_sptr make_beamformer_sptr(); + beamformer(); gr_complex *weight_vector; }; diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h index 4f898b154..4640ba4d1 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_cc.h @@ -41,8 +41,12 @@ class Notch; using notch_sptr = boost::shared_ptr; -notch_sptr make_notch_filter(float pfa, float p_c_factor, - int32_t length_, int32_t n_segments_est, int32_t n_segments_reset); +notch_sptr make_notch_filter( + float pfa, + float p_c_factor, + int32_t length_, + int32_t n_segments_est, + int32_t n_segments_reset); /*! * \brief This class implements a real-time software-defined multi state notch filter @@ -50,8 +54,6 @@ notch_sptr make_notch_filter(float pfa, float p_c_factor, class Notch : public gr::block { public: - Notch(float pfa, float p_c_factor, int32_t length_, int32_t n_segments_est, int32_t n_segments_reset); - ~Notch(); void forecast(int noutput_items, gr_vector_int &ninput_items_required); @@ -61,6 +63,8 @@ public: gr_vector_void_star &output_items); private: + friend notch_sptr make_notch_filter(float pfa, float p_c_factor, int32_t length_, int32_t n_segments_est, int32_t n_segments_reset); + Notch(float pfa, float p_c_factor, int32_t length_, int32_t n_segments_est, int32_t n_segments_reset); float pfa; float noise_pow_est; float thres_; diff --git a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h index 0a7114240..7b274a13c 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/notch_lite_cc.h @@ -41,7 +41,13 @@ class NotchLite; using notch_lite_sptr = boost::shared_ptr; -notch_lite_sptr make_notch_filter_lite(float p_c_factor, float pfa, int32_t length_, int32_t n_segments_est, int32_t n_segments_reset, int32_t n_segments_coeff); +notch_lite_sptr make_notch_filter_lite( + float p_c_factor, + float pfa, + int32_t length_, + int32_t n_segments_est, + int32_t n_segments_reset, + int32_t n_segments_coeff); /*! * \brief This class implements a real-time software-defined multi state notch filter light version @@ -49,8 +55,6 @@ notch_lite_sptr make_notch_filter_lite(float p_c_factor, float pfa, int32_t leng class NotchLite : public gr::block { public: - NotchLite(float p_c_factor, float pfa, int32_t length_, int32_t n_segments_est, int32_t n_segments_reset, int32_t n_segments_coeff); - ~NotchLite(); void forecast(int noutput_items, gr_vector_int &ninput_items_required); @@ -60,6 +64,8 @@ public: gr_vector_void_star &output_items); private: + friend notch_lite_sptr make_notch_filter_lite(float p_c_factor, float pfa, int32_t length_, int32_t n_segments_est, int32_t n_segments_reset, int32_t n_segments_coeff); + NotchLite(float p_c_factor, float pfa, int32_t length_, int32_t n_segments_est, int32_t n_segments_reset, int32_t n_segments_coeff); int32_t length_; int32_t n_segments; int32_t n_segments_est; diff --git a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h index 52abef24f..edbd9c5e8 100644 --- a/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h +++ b/src/algorithms/input_filter/gnuradio_blocks/pulse_blanking_cc.h @@ -39,14 +39,15 @@ class pulse_blanking_cc; using pulse_blanking_cc_sptr = boost::shared_ptr; -pulse_blanking_cc_sptr make_pulse_blanking_cc(float pfa, int32_t length_, int32_t n_segments_est, int32_t n_segments_reset); - +pulse_blanking_cc_sptr make_pulse_blanking_cc( + float pfa, + int32_t length_, + int32_t n_segments_est, + int32_t n_segments_reset); class pulse_blanking_cc : public gr::block { public: - pulse_blanking_cc(float pfa, int32_t length_, int32_t n_segments_est, int32_t n_segments_reset); - ~pulse_blanking_cc(); void forecast(int noutput_items, gr_vector_int &ninput_items_required); @@ -55,6 +56,8 @@ public: gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); private: + friend pulse_blanking_cc_sptr make_pulse_blanking_cc(float pfa, int32_t length_, int32_t n_segments_est, int32_t n_segments_reset); + pulse_blanking_cc(float pfa, int32_t length_, int32_t n_segments_est, int32_t n_segments_reset); int32_t length_; int32_t n_segments; int32_t n_segments_est; diff --git a/src/algorithms/signal_source/libs/gnss_sdr_valve.cc b/src/algorithms/signal_source/libs/gnss_sdr_valve.cc index aa2bd1237..615cb65b7 100644 --- a/src/algorithms/signal_source/libs/gnss_sdr_valve.cc +++ b/src/algorithms/signal_source/libs/gnss_sdr_valve.cc @@ -55,14 +55,14 @@ Gnss_Sdr_Valve::Gnss_Sdr_Valve(size_t sizeof_stream_item, } -boost::shared_ptr gnss_sdr_make_valve(size_t sizeof_stream_item, uint64_t nitems, gr::msg_queue::sptr queue, bool stop_flowgraph) +boost::shared_ptr gnss_sdr_make_valve(size_t sizeof_stream_item, uint64_t nitems, gr::msg_queue::sptr queue, bool stop_flowgraph) { boost::shared_ptr valve_(new Gnss_Sdr_Valve(sizeof_stream_item, nitems, std::move(queue), stop_flowgraph)); return valve_; } -boost::shared_ptr gnss_sdr_make_valve(size_t sizeof_stream_item, uint64_t nitems, gr::msg_queue::sptr queue) +boost::shared_ptr gnss_sdr_make_valve(size_t sizeof_stream_item, uint64_t nitems, gr::msg_queue::sptr queue) { boost::shared_ptr valve_(new Gnss_Sdr_Valve(sizeof_stream_item, nitems, std::move(queue), true)); return valve_; diff --git a/src/algorithms/signal_source/libs/gnss_sdr_valve.h b/src/algorithms/signal_source/libs/gnss_sdr_valve.h index 9bd90a188..b56807c2b 100644 --- a/src/algorithms/signal_source/libs/gnss_sdr_valve.h +++ b/src/algorithms/signal_source/libs/gnss_sdr_valve.h @@ -41,12 +41,14 @@ #include // for size_t #include -boost::shared_ptr gnss_sdr_make_valve( +class Gnss_Sdr_Valve; + +boost::shared_ptr gnss_sdr_make_valve( size_t sizeof_stream_item, uint64_t nitems, gr::msg_queue::sptr queue); -boost::shared_ptr gnss_sdr_make_valve( +boost::shared_ptr gnss_sdr_make_valve( size_t sizeof_stream_item, uint64_t nitems, gr::msg_queue::sptr queue, @@ -65,22 +67,22 @@ public: gr_vector_const_void_star &input_items, gr_vector_void_star &output_items); - Gnss_Sdr_Valve(size_t sizeof_stream_item, - uint64_t nitems, - gr::msg_queue::sptr queue, bool stop_flowgraph); - private: - friend boost::shared_ptr gnss_sdr_make_valve( + friend boost::shared_ptr gnss_sdr_make_valve( size_t sizeof_stream_item, uint64_t nitems, gr::msg_queue::sptr queue); - friend boost::shared_ptr gnss_sdr_make_valve( + friend boost::shared_ptr gnss_sdr_make_valve( size_t sizeof_stream_item, uint64_t nitems, gr::msg_queue::sptr queue, bool stop_flowgraph); + Gnss_Sdr_Valve(size_t sizeof_stream_item, + uint64_t nitems, + gr::msg_queue::sptr queue, bool stop_flowgraph); + uint64_t d_nitems; uint64_t d_ncopied_items; gr::msg_queue::sptr d_queue; diff --git a/src/tests/unit-tests/signal-processing-blocks/tracking/tracking_pull-in_test.cc b/src/tests/unit-tests/signal-processing-blocks/tracking/tracking_pull-in_test.cc index e7aa0676f..fb38b8efa 100644 --- a/src/tests/unit-tests/signal-processing-blocks/tracking/tracking_pull-in_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/tracking/tracking_pull-in_test.cc @@ -796,9 +796,8 @@ TEST_F(TrackingPullInTest, ValidationOfResults) // create the msg queue for valve queue = gr::msg_queue::make(0); - boost::shared_ptr reseteable_valve; long long int acq_to_trk_delay_samples = ceil(static_cast(FLAGS_fs_gen_sps) * FLAGS_acq_to_trk_delay_s); - boost::shared_ptr resetable_valve_(new Gnss_Sdr_Valve(sizeof(gr_complex), acq_to_trk_delay_samples, queue, false)); + auto resetable_valve_ = gnss_sdr_make_valve(sizeof(gr_complex), acq_to_trk_delay_samples, queue, false); std::shared_ptr control_message_factory_; std::shared_ptr>> control_messages_; From 081439d6f830f4b05a6cd5796829d44f2af3a229 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 2 Jul 2019 17:48:00 +0200 Subject: [PATCH 2/2] Code cleaning --- .../acquisition/libs/fpga_acquisition.cc | 4 ++-- .../acquisition/libs/fpga_acquisition.h | 20 +++++++++++++++---- src/algorithms/channel/libs/channel_fsm.cc | 5 +++++ .../channel/libs/channel_msg_receiver_cc.h | 4 ++-- 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/algorithms/acquisition/libs/fpga_acquisition.cc b/src/algorithms/acquisition/libs/fpga_acquisition.cc index 00b1b65b3..16d5534de 100644 --- a/src/algorithms/acquisition/libs/fpga_acquisition.cc +++ b/src/algorithms/acquisition/libs/fpga_acquisition.cc @@ -81,7 +81,6 @@ Fpga_Acquisition::Fpga_Acquisition(std::string device_name, int64_t fs_in, uint32_t sampled_ms __attribute__((unused)), uint32_t select_queue, - //lv_16sc_t *all_fft_codes, uint32_t *all_fft_codes, uint32_t excludelimit) { @@ -209,6 +208,7 @@ void Fpga_Acquisition::set_block_exp(uint32_t total_block_exp) d_map_base[11] = total_block_exp; } + void Fpga_Acquisition::set_doppler_sweep(uint32_t num_sweeps, uint32_t doppler_step, int32_t doppler_min) { float phase_step_rad_real; @@ -233,7 +233,6 @@ void Fpga_Acquisition::set_doppler_sweep(uint32_t num_sweeps, uint32_t doppler_s void Fpga_Acquisition::configure_acquisition() { //Fpga_Acquisition::open_device(); - d_map_base[0] = d_select_queue; d_map_base[1] = d_vector_length; d_map_base[2] = d_nsamples; @@ -318,6 +317,7 @@ void Fpga_Acquisition::read_fpga_total_scale_factor(uint32_t *total_scale_factor *fw_scale_factor = 0; } + void Fpga_Acquisition::read_result_valid(uint32_t *result_valid) { uint32_t readval = 0; diff --git a/src/algorithms/acquisition/libs/fpga_acquisition.h b/src/algorithms/acquisition/libs/fpga_acquisition.h index 805297bd3..823400290 100644 --- a/src/algorithms/acquisition/libs/fpga_acquisition.h +++ b/src/algorithms/acquisition/libs/fpga_acquisition.h @@ -36,7 +36,6 @@ #ifndef GNSS_SDR_FPGA_ACQUISITION_H_ #define GNSS_SDR_FPGA_ACQUISITION_H_ -#include // for lv_16sc_t #include #include @@ -46,7 +45,8 @@ class Fpga_Acquisition { public: - Fpga_Acquisition(std::string device_name, + Fpga_Acquisition( + std::string device_name, uint32_t nsamples, uint32_t doppler_max, uint32_t nsamples_total, @@ -57,13 +57,24 @@ public: uint32_t excludelimit); ~Fpga_Acquisition(); + bool set_local_code(uint32_t PRN); + void set_doppler_sweep(uint32_t num_sweeps, uint32_t doppler_step, int32_t doppler_min); + void run_acquisition(void); - void read_acquisition_results(uint32_t *max_index, float *firstpeak, float *secondpeak, uint64_t *initial_sample, float *power_sum, uint32_t *doppler_index, uint32_t *total_blk_exp); + void read_acquisition_results( + uint32_t *max_index, + float *firstpeak, + float *secondpeak, + uint64_t *initial_sample, + float *power_sum, + uint32_t *doppler_index, + uint32_t *total_blk_exp); void block_samples(); + void unblock_samples(); /*! @@ -100,9 +111,10 @@ public: void configure_acquisition(void); - void close_device(); void open_device(); + void close_device(); + private: int64_t d_fs_in; // data related to the hardware module and the driver diff --git a/src/algorithms/channel/libs/channel_fsm.cc b/src/algorithms/channel/libs/channel_fsm.cc index f5e75ed7c..ac533d310 100644 --- a/src/algorithms/channel/libs/channel_fsm.cc +++ b/src/algorithms/channel/libs/channel_fsm.cc @@ -87,6 +87,7 @@ bool ChannelFsm::Event_start_acquisition_fpga() return true; } + bool ChannelFsm::Event_start_acquisition() { std::lock_guard lk(mx); @@ -170,11 +171,14 @@ void ChannelFsm::set_tracking(std::shared_ptr tracking) trk_ = std::move(tracking); } + void ChannelFsm::set_telemetry(std::shared_ptr telemetry) { std::lock_guard lk(mx); nav_ = std::move(telemetry); } + + void ChannelFsm::set_queue(gr::msg_queue::sptr queue) { std::lock_guard lk(mx); @@ -194,6 +198,7 @@ void ChannelFsm::stop_acquisition() acq_->stop_acquisition(); } + void ChannelFsm::stop_tracking() { trk_->stop_tracking(); diff --git a/src/algorithms/channel/libs/channel_msg_receiver_cc.h b/src/algorithms/channel/libs/channel_msg_receiver_cc.h index 7f305f7f7..8b38e10ab 100644 --- a/src/algorithms/channel/libs/channel_msg_receiver_cc.h +++ b/src/algorithms/channel/libs/channel_msg_receiver_cc.h @@ -51,11 +51,11 @@ public: ~channel_msg_receiver_cc(); //!< Default destructor private: + friend channel_msg_receiver_cc_sptr channel_msg_receiver_make_cc(std::shared_ptr channel_fsm, bool repeat); + channel_msg_receiver_cc(std::shared_ptr channel_fsm, bool repeat); std::shared_ptr d_channel_fsm; bool d_repeat; // todo: change FSM to include repeat value - friend channel_msg_receiver_cc_sptr channel_msg_receiver_make_cc(std::shared_ptr channel_fsm, bool repeat); void msg_handler_events(pmt::pmt_t msg); - channel_msg_receiver_cc(std::shared_ptr channel_fsm, bool repeat); }; #endif