From c4e84ffcfcb512d89c5bb04f10edb2d58f46490a Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Fri, 23 Aug 2024 07:02:56 +0200 Subject: [PATCH] Apply clang-tidy fixes --- .../adapters/ad936x_custom_signal_source.cc | 17 +- .../gnuradio_blocks/ad936x_iio_source.cc | 93 +++++--- .../gnuradio_blocks/ad936x_iio_source.h | 42 ++-- .../signal_source/libs/CMakeLists.txt | 1 - .../signal_source/libs/ad9361_manager.cc | 2 +- .../signal_source/libs/ad936x_iio_custom.cc | 211 +++++++++++------- .../signal_source/libs/ad936x_iio_custom.h | 32 +-- .../signal_source/libs/ad936x_iio_samples.cc | 25 --- .../signal_source/libs/ad936x_iio_samples.h | 10 +- src/algorithms/signal_source/libs/ppstcprx.cc | 25 +-- src/algorithms/signal_source/libs/ppstcprx.h | 12 +- 11 files changed, 257 insertions(+), 213 deletions(-) delete mode 100644 src/algorithms/signal_source/libs/ad936x_iio_samples.cc diff --git a/src/algorithms/signal_source/adapters/ad936x_custom_signal_source.cc b/src/algorithms/signal_source/adapters/ad936x_custom_signal_source.cc index b93dc9344..b824a250d 100644 --- a/src/algorithms/signal_source/adapters/ad936x_custom_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ad936x_custom_signal_source.cc @@ -76,8 +76,11 @@ Ad936xCustomSignalSource::Ad936xCustomSignalSource(const ConfigurationInterface* item_size_ = sizeof(gr_complex); // 1. Make the driver instance bool customsamplesize = false; - if (ssize_ != 12 or spattern_ == true) customsamplesize = true; // custom FPGA DMA firmware - if (ssize_ == 12) // default original FPGA DMA firmware + if (ssize_ != 12 || spattern_ == true) + { + customsamplesize = true; // custom FPGA DMA firmware + } + if (ssize_ == 12) // default original FPGA DMA firmware { ssize_ = 16; // set to 16 bits and do not try to change sample size } @@ -153,8 +156,14 @@ Ad936xCustomSignalSource::Ad936xCustomSignalSource(const ConfigurationInterface* for (int n = 0; n < n_channels; n++) { - if (n == 0) inverted_spectrum_vec.push_back(inverted_spectrum_ch0_); - if (n == 1) inverted_spectrum_vec.push_back(inverted_spectrum_ch1_); + if (n == 0) + { + inverted_spectrum_vec.push_back(inverted_spectrum_ch0_); + } + if (n == 1) + { + inverted_spectrum_vec.push_back(inverted_spectrum_ch1_); + } } for (int n = 0; n < n_channels; n++) diff --git a/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc b/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc index 375edf7da..1f0288dc9 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc @@ -33,15 +33,15 @@ ad936x_iio_source_sptr ad936x_iio_make_source_sptr( - std::string pluto_uri_, - std::string board_type_, + const std::string& pluto_uri_, + const std::string& board_type_, long long bandwidth_, long long sample_rate_, long long freq_, - std::string rf_port_select_, - std::string rf_filter, - std::string gain_mode_rx0_, - std::string gain_mode_rx1_, + const std::string& rf_port_select_, + const std::string& rf_filter, + const std::string& gain_mode_rx0_, + const std::string& gain_mode_rx1_, double rf_gain_rx0_, double rf_gain_rx1_, bool enable_ch0, @@ -49,7 +49,7 @@ ad936x_iio_source_sptr ad936x_iio_make_source_sptr( long long freq_2ch, bool ppsmode_, bool customsamplesize_, - std::string fe_ip_, + const std::string& fe_ip_, int fe_ctlport_, int ssize_, int bshift_, @@ -85,7 +85,8 @@ ad936x_iio_source_sptr ad936x_iio_make_source_sptr( tx_lo_channel_)); } -void ad936x_iio_source::ad9361_channel_demux_and_record(ad936x_iio_samples *samples_in, int nchannels, std::vector *files_out) + +void ad936x_iio_source::ad9361_channel_demux_and_record(ad936x_iio_samples* samples_in, int nchannels, std::vector* files_out) { uint32_t current_byte = 0; int16_t ch = 0; @@ -101,16 +102,17 @@ void ad936x_iio_source::ad9361_channel_demux_and_record(ad936x_iio_samples *samp } } + ad936x_iio_source::ad936x_iio_source( - std::string pluto_uri_, - std::string board_type_, + const std::string& pluto_uri_, + const std::string& board_type_, long long bandwidth_, long long sample_rate_, long long freq_, - std::string rf_port_select_, - std::string rf_filter, - std::string gain_mode_rx0_, - std::string gain_mode_rx1_, + const std::string& rf_port_select_, + const std::string& rf_filter, + const std::string& gain_mode_rx0_, + const std::string& gain_mode_rx1_, double rf_gain_rx0_, double rf_gain_rx1_, bool enable_ch0, @@ -118,7 +120,7 @@ ad936x_iio_source::ad936x_iio_source( long long freq_2ch, bool ppsmode_, bool customsamplesize_, - std::string fe_ip_, + const std::string& fe_ip_, int fe_ctlport_, int ssize_, int bshift_, @@ -171,54 +173,81 @@ ad936x_iio_source::ad936x_iio_source( case 16: { std::cout << "FPGA sample size set to 16 bits per sample.\n"; - if (pps_rx->send_cmd("ssize=16\n") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("ssize=16\n") == false) + { + std::cout << "cmd send error!\n"; + } break; } case 8: { std::cout << "FPGA sample size set to 8 bits per sample.\n"; - if (pps_rx->send_cmd("ssize=8\n") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("ssize=8\n") == false) + { + std::cout << "cmd send error!\n"; + } break; } case 4: { std::cout << "FPGA sample size set to 4 bits per sample.\n"; - if (pps_rx->send_cmd("ssize=4\n") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("ssize=4\n") == false) + { + std::cout << "cmd send error!\n"; + } break; } case 2: { std::cout << "FPGA sample size set to 2 bits per sample.\n"; - if (pps_rx->send_cmd("ssize=2\n") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("ssize=2\n") == false) + { + std::cout << "cmd send error!\n"; + } break; } default: { std::cout << "WARNING: Unsupported ssize. FPGA sample size set to 16 bits per sample.\n"; - if (pps_rx->send_cmd("ssize=16") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("ssize=16") == false) + { + std::cout << "cmd send error!\n"; + } } } if (bshift_ >= 0 and bshift_ <= 14) { std::cout << "FPGA sample bits shift left set to " + std::to_string(bshift_) + " positions.\n"; - if (pps_rx->send_cmd("bshift=" + std::to_string(bshift_) + "\n") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("bshift=" + std::to_string(bshift_) + "\n") == false) + { + std::cout << "cmd send error!\n"; + } } else { std::cout << "WARNING: Unsupported bshift. FPGA sample bits shift left set to 0.\n"; - if (pps_rx->send_cmd("bshift=0\n") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("bshift=0\n") == false) + { + std::cout << "cmd send error!\n"; + } } if (spattern_ == true) { std::cout << "FPGA debug sample pattern is active!.\n"; - if (pps_rx->send_cmd("spattern=1\n") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("spattern=1\n") == false) + { + std::cout << "cmd send error!\n"; + } } else { std::cout << "FPGA debug sample pattern disabled.\n"; - if (pps_rx->send_cmd("spattern=0\n") == false) std::cout << "cmd send error!\n"; + if (pps_rx->send_cmd("spattern=0\n") == false) + { + std::cout << "cmd send error!\n"; + } } } else @@ -238,7 +267,7 @@ ad936x_iio_source::ad936x_iio_source( exit(1); } } - catch (std::exception const &ex) + catch (std::exception const& ex) { std::cerr << "STD exception: " << ex.what() << std::endl; exit(1); @@ -267,6 +296,7 @@ ad936x_iio_source::ad936x_iio_source( // } } + ad936x_iio_source::~ad936x_iio_source() { // Terminate PPS thread @@ -284,6 +314,7 @@ bool ad936x_iio_source::start() return ad936x_custom->start_sample_rx(false); } + bool ad936x_iio_source::stop() { std::cout << "stopping ad936x_iio_source...\n"; @@ -291,17 +322,17 @@ bool ad936x_iio_source::stop() return true; } + int ad936x_iio_source::general_work(int noutput_items, - __attribute__((unused)) gr_vector_int &ninput_items, - __attribute__((unused)) gr_vector_const_void_star &input_items, - gr_vector_void_star &output_items) + __attribute__((unused)) gr_vector_int& ninput_items, + __attribute__((unused)) gr_vector_const_void_star& input_items, + gr_vector_void_star& output_items) { std::shared_ptr current_buffer; - ad936x_iio_samples *current_samples; + ad936x_iio_samples* current_samples; ad936x_custom->pop_sample_buffer(current_buffer); current_samples = current_buffer.get(); - // I and Q samples are interleaved in buffer: IQIQIQ... int32_t n_interleaved_iq_samples_per_channel = current_samples->n_bytes / (ad936x_custom->n_channels * 2); if (noutput_items < n_interleaved_iq_samples_per_channel) @@ -312,7 +343,7 @@ int ad936x_iio_source::general_work(int noutput_items, else { // ad9361_channel_demux_and_record(current_samples, ad936x_custom->n_channels, &samplesfile); - auto **out = reinterpret_cast(&output_items[0]); + auto** out = reinterpret_cast(&output_items[0]); uint32_t current_byte = 0; uint32_t current_byte_in_gr = 0; int16_t ch = 0; diff --git a/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.h b/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.h index 411906a3e..a1a29f6ab 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.h +++ b/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.h @@ -44,15 +44,15 @@ class ad936x_iio_source; using ad936x_iio_source_sptr = gnss_shared_ptr; ad936x_iio_source_sptr ad936x_iio_make_source_sptr( - std::string pluto_uri_, - std::string board_type_, + const std::string &pluto_uri_, + const std::string &board_type_, long long bandwidth_, long long sample_rate_, long long freq_, - std::string rf_port_select_, - std::string rf_filter, - std::string gain_mode_rx0_, - std::string gain_mode_rx1_, + const std::string &rf_port_select_, + const std::string &rf_filter, + const std::string &gain_mode_rx0_, + const std::string &gain_mode_rx1_, double rf_gain_rx0_, double rf_gain_rx1_, bool enable_ch0, @@ -60,7 +60,7 @@ ad936x_iio_source_sptr ad936x_iio_make_source_sptr( long long freq_2ch, bool ppsmode_, bool customsamplesize_, - std::string fe_ip_, + const std::string &fe_ip_, int fe_ctlport_, int ssize_, int bshift_, @@ -90,15 +90,15 @@ public: private: friend ad936x_iio_source_sptr ad936x_iio_make_source_sptr( - std::string pluto_uri_, - std::string board_type_, + const std::string &pluto_uri_, + const std::string &board_type_, long long bandwidth_, long long sample_rate_, long long freq_, - std::string rf_port_select_, - std::string rf_filter, - std::string gain_mode_rx0_, - std::string gain_mode_rx1_, + const std::string &rf_port_select_, + const std::string &rf_filter, + const std::string &gain_mode_rx0_, + const std::string &gain_mode_rx1_, double rf_gain_rx0_, double rf_gain_rx1_, bool enable_ch0, @@ -106,7 +106,7 @@ private: long long freq_2ch, bool ppsmode_, bool customsamplesize_, - std::string fe_ip_, + const std::string &fe_ip_, int fe_ctlport_, int ssize_, int bshift_, @@ -116,15 +116,15 @@ private: int tx_lo_channel_); ad936x_iio_source( - std::string pluto_uri_, - std::string board_type_, + const std::string &pluto_uri_, + const std::string &board_type_, long long bandwidth_, long long sample_rate_, long long freq_, - std::string rf_port_select_, - std::string rf_filter, - std::string gain_mode_rx0_, - std::string gain_mode_rx1_, + const std::string &rf_port_select_, + const std::string &rf_filter, + const std::string &gain_mode_rx0_, + const std::string &gain_mode_rx1_, double rf_gain_rx0_, double rf_gain_rx1_, bool enable_ch0, @@ -132,7 +132,7 @@ private: long long freq_2ch, bool ppsmode_, bool customsamplesize_, - std::string fe_ip_, + const std::string &fe_ip_, int fe_ctlport_, int ssize_, int bshift_, diff --git a/src/algorithms/signal_source/libs/CMakeLists.txt b/src/algorithms/signal_source/libs/CMakeLists.txt index bdbd3aace..9d9732d3c 100644 --- a/src/algorithms/signal_source/libs/CMakeLists.txt +++ b/src/algorithms/signal_source/libs/CMakeLists.txt @@ -36,7 +36,6 @@ if((ENABLE_FPGA AND ENABLE_AD9361) OR ENABLE_MAX2771) endif() if(ENABLE_PLUTOSDR) - set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad936x_iio_samples.cc) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ad936x_iio_samples.h) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad936x_iio_custom.cc) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ad936x_iio_custom.h) diff --git a/src/algorithms/signal_source/libs/ad9361_manager.cc b/src/algorithms/signal_source/libs/ad9361_manager.cc index d2f82b367..025f97627 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.cc +++ b/src/algorithms/signal_source/libs/ad9361_manager.cc @@ -636,7 +636,7 @@ bool config_ad9361_rx_remote(const std::string &remote_host, { return false; } - if (setup_filter(std::move(filter_source_), bandwidth_, sample_rate_, freq_, rf_port_select_, ad9361_phy, rx_chan0, chn, 0, std::move(filter_filename_), Fpass_, Fstop_) == -1) + if (setup_filter(filter_source_, bandwidth_, sample_rate_, freq_, rf_port_select_, ad9361_phy, rx_chan0, chn, 0, std::move(filter_filename_), Fpass_, Fstop_) == -1) { return false; } diff --git a/src/algorithms/signal_source/libs/ad936x_iio_custom.cc b/src/algorithms/signal_source/libs/ad936x_iio_custom.cc index ad983aa6b..c41d74b9a 100644 --- a/src/algorithms/signal_source/libs/ad936x_iio_custom.cc +++ b/src/algorithms/signal_source/libs/ad936x_iio_custom.cc @@ -31,29 +31,36 @@ #include #endif -ad936x_iio_custom::ad936x_iio_custom(int debug_level_, int log_level_) +ad936x_iio_custom::ad936x_iio_custom( + int debug_level_, + int log_level_) : n_channels(0), + ctx(nullptr), + phy(nullptr), + stream_dev(nullptr), + dds_dev(nullptr), + receive_samples(false), + fpga_overflow(false), + sample_rate_sps(0), + debug_level(debug_level_), + log_level(log_level_), + PPS_mode(false) { - receive_samples = false; - fpga_overflow = false; - sample_rate_sps = 0; - ctx = NULL; - phy = NULL; - dds_dev = NULL; - stream_dev = NULL; - debug_level = debug_level_; - log_level = log_level_; - PPS_mode = false; - n_channels = 0; } ad936x_iio_custom::~ad936x_iio_custom() { // disable TX - if (phy != NULL) PlutoTxEnable(false); + if (phy != nullptr) + { + PlutoTxEnable(false); + } // Close device - if (ctx != NULL) iio_context_destroy(ctx); + if (ctx != nullptr) + { + iio_context_destroy(ctx); + } } @@ -69,7 +76,7 @@ void ad936x_iio_custom::set_pps_samplestamp_queue(std::shared_ptr ¶ms) { - for (std::vector::const_iterator it = params.begin(); - it != params.end(); ++it) + for (const auto ¶m : params) { - struct iio_channel *chn = NULL; - const char *attr = NULL; + struct iio_channel *chn = nullptr; + const char *attr = nullptr; size_t pos; int ret; - pos = it->find('='); + pos = param.find('='); if (pos == std::string::npos) { - std::cerr << "Malformed line: " << *it << std::endl; + std::cerr << "Malformed line: " << param << std::endl; continue; } - std::string key = it->substr(0, pos); - std::string val = it->substr(pos + 1, std::string::npos); + std::string key = param.substr(0, pos); + std::string val = param.substr(pos + 1, std::string::npos); ret = iio_device_identify_filename(phy, key.c_str(), &chn, &attr); @@ -197,13 +203,19 @@ void ad936x_iio_custom::configure_params(struct iio_device *phy, } if (chn) - ret = iio_channel_attr_write(chn, - attr, val.c_str()); + { + ret = iio_channel_attr_write(chn, + attr, val.c_str()); + } else if (iio_device_find_attr(phy, attr)) - ret = iio_device_attr_write(phy, attr, val.c_str()); + { + ret = iio_device_attr_write(phy, attr, val.c_str()); + } else - ret = iio_device_debug_attr_write(phy, - attr, val.c_str()); + { + ret = iio_device_debug_attr_write(phy, + attr, val.c_str()); + } if (ret < 0) { std::cerr << "Unable to write attribute " << key @@ -217,9 +229,9 @@ void ad936x_iio_custom::set_params_rx(struct iio_device *phy_device, unsigned long long frequency, unsigned long samplerate, unsigned long bandwidth, bool quadrature, bool rfdc, bool bbdc, - std::string gain1, double gain1_value, - std::string gain2, double gain2_value, - std::string port_select) + const std::string &gain1, double gain1_value, + const std::string &gain2, double gain2_value, + const std::string &port_select) { std::vector params; @@ -290,7 +302,7 @@ bool ad936x_iio_custom::config_ad9361_dds(uint64_t freq_rf_tx_hz_, std::to_string(phase_dds_deg_ * 1000.0)); params_dds.push_back("out_altvoltage0_TX1_I_F1_scale=" + std::to_string(scale_dds_)); - params_dds.push_back("out_altvoltage0_TX1_I_F1_raw=1"); + params_dds.emplace_back("out_altvoltage0_TX1_I_F1_raw=1"); // DDS TX CH1 Q (tone #1) params_dds.push_back("out_altvoltage2_TX1_Q_F1_frequency=" + std::to_string(freq_dds_tx_hz_)); @@ -298,7 +310,7 @@ bool ad936x_iio_custom::config_ad9361_dds(uint64_t freq_rf_tx_hz_, std::to_string(phase_dds_deg_ * 1000.0 + 270000.0)); params_dds.push_back("out_altvoltage2_TX1_Q_F1_scale=" + std::to_string(scale_dds_)); - params_dds.push_back("out_altvoltage2_TX1_Q_F1_raw=1"); + params_dds.emplace_back("out_altvoltage2_TX1_Q_F1_raw=1"); configure_params(dds_dev, params_dds); } @@ -319,7 +331,7 @@ bool ad936x_iio_custom::config_ad9361_dds(uint64_t freq_rf_tx_hz_, std::to_string(phase_dds_deg_ * 1000.0)); params_dds.push_back("out_altvoltage4_TX2_I_F1_scale=" + std::to_string(scale_dds_)); - params_dds.push_back("out_altvoltage4_TX2_I_F1_raw=1"); + params_dds.emplace_back("out_altvoltage4_TX2_I_F1_raw=1"); // DDS TX CH2 Q (tone #1) params_dds.push_back("out_altvoltage6_TX2_Q_F1_frequency=" + std::to_string(freq_dds_tx_hz_)); @@ -327,7 +339,7 @@ bool ad936x_iio_custom::config_ad9361_dds(uint64_t freq_rf_tx_hz_, std::to_string(phase_dds_deg_ * 1000.0 + 270000.0)); params_dds.push_back("out_altvoltage6_TX2_Q_F1_scale=" + std::to_string(scale_dds_)); - params_dds.push_back("out_altvoltage6_TX2_Q_F1_raw=1"); + params_dds.emplace_back("out_altvoltage6_TX2_Q_F1_raw=1"); configure_params(dds_dev, params_dds); } @@ -338,7 +350,7 @@ bool ad936x_iio_custom::config_ad9361_dds(uint64_t freq_rf_tx_hz_, bool ad936x_iio_custom::check_device() { - if (stream_dev != NULL) + if (stream_dev != nullptr) { return true; } @@ -351,8 +363,8 @@ bool ad936x_iio_custom::check_device() bool ad936x_iio_custom::get_iio_param(iio_device *dev, const std::string ¶m, std::string &value) { - struct iio_channel *chn = 0; - const char *attr = 0; + struct iio_channel *chn = nullptr; + const char *attr = nullptr; char valuestr[256]; int ret; ssize_t nchars; @@ -399,9 +411,12 @@ bool ad936x_iio_custom::read_die_temp(double &temp_c) { try { - uint32_t temp_mC = boost::lexical_cast(temp_mC_str); + auto temp_mC = boost::lexical_cast(temp_mC_str); temp_c = static_cast(temp_mC) / 1000.0; - if (temp_c > 120) temp_c = -1; + if (temp_c > 120) + { + temp_c = -1; + } return true; } catch (const boost::bad_lexical_cast &e) @@ -420,10 +435,10 @@ bool ad936x_iio_custom::read_die_temp(double &temp_c) bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_, long long sample_rate_, long long freq_, - std::string rf_port_select_, - std::string rf_filter, - std::string gain_mode_rx0_, - std::string gain_mode_rx1_, + const std::string &rf_port_select_, + const std::string &rf_filter, + const std::string &gain_mode_rx0_, + const std::string &gain_mode_rx1_, double rf_gain_rx0_, double rf_gain_rx1_, bool enable_ch0, @@ -433,16 +448,19 @@ bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_, bool high_side_lo_, int tx_lo_channel_) { - if (check_device() == false) return false; + if (check_device() == false) + { + return false; + } bool no_errors = true; std::cout << "Configuring phy device parameters...\n"; int ret; - if (rf_filter.compare("Disabled") == 0) + if (rf_filter == "Disabled") { std::cout << "LNA Filter switch is disabled.\n"; } - else if (rf_filter.compare("Auto") == 0) + else if (rf_filter == "Auto") { std::cout << "Selecting LNA RF filter based on the selected RF frequency... \n"; if (freq_ == 1575420000) @@ -499,9 +517,9 @@ bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_, params.push_back("out_voltage_rf_bandwidth=" + std::to_string(bandwidth_)); - params.push_back("in_voltage_quadrature_tracking_en=1"); - params.push_back("in_voltage_rf_dc_offset_tracking_en=1"); - params.push_back("in_voltage_bb_dc_offset_tracking_en=1"); + params.emplace_back("in_voltage_quadrature_tracking_en=1"); + params.emplace_back("in_voltage_rf_dc_offset_tracking_en=1"); + params.emplace_back("in_voltage_bb_dc_offset_tracking_en=1"); configure_params(phy, params); @@ -706,7 +724,10 @@ bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_, bool ad936x_iio_custom::set_rx_frequency(long long freq_hz) { - if (check_device() == false) return false; + if (check_device() == false) + { + return false; + } // Configure RX LO channel (NOTICE that altvoltage0 is the RX LO oscillator!, altvoltage1 is the TX oscillator) struct iio_channel *lo_ch; @@ -729,7 +750,10 @@ bool ad936x_iio_custom::set_rx_frequency(long long freq_hz) bool ad936x_iio_custom::get_rx_frequency(long long &freq_hz) { - if (check_device() == false) return false; + if (check_device() == false) + { + return false; + } // Configure RX LO channel (NOTICE that altvoltage0 is the RX LO oscillator!, altvoltage1 is the TX oscillator) struct iio_channel *lo_ch; @@ -750,9 +774,12 @@ bool ad936x_iio_custom::get_rx_frequency(long long &freq_hz) } -bool ad936x_iio_custom::setRXGain(int ch_num, std::string gain_mode, double gain_dB) +bool ad936x_iio_custom::setRXGain(int ch_num, const std::string &gain_mode, double gain_dB) { - if (check_device() == false) return false; + if (check_device() == false) + { + return false; + } std::vector params; if (ch_num == 0) { @@ -785,7 +812,10 @@ bool ad936x_iio_custom::setRXGain(int ch_num, std::string gain_mode, double gain double ad936x_iio_custom::get_rx_gain(int ch_num) { - if (check_device() == false) return -1; + if (check_device() == false) + { + return -1; + } double gain_dB; // gain in dB int ret = 0; if (ch_num == 0) @@ -816,7 +846,10 @@ double ad936x_iio_custom::get_rx_gain(int ch_num) bool ad936x_iio_custom::calibrate([[maybe_unused]] int ch, [[maybe_unused]] double bw_hz) { - if (check_device() == false) return false; + if (check_device() == false) + { + return false; + } // todo return true; } @@ -865,12 +898,13 @@ void ad936x_iio_custom::monitor_thread_fn() { ret = iio_device_reg_write(stream_dev, 0x80000088, val); if (ret) - fprintf(stderr, "Failed to clearn DMA status register: %s\n", - strerror(-ret)); + { + fprintf(stderr, "Failed to clearn DMA status register: %s\n", + strerror(-ret)); + } } sleep(1); } - return; } @@ -941,7 +975,7 @@ void ad936x_iio_custom::setPlutoGpo(int p) } -bool ad936x_iio_custom::select_rf_filter(std::string rf_filter) +bool ad936x_iio_custom::select_rf_filter(const std::string &rf_filter) { // adi,gpo-manual-mode-enable Enables GPO manual mode, this will conflict with automatic ENSM slave and eLNA mode // adi,gpo-manual-mode-enable-mask Enable bit mask, setting or clearing bits will change the level of the corresponding output. Bit0 → GPO, Bit1 → GPO1, Bit2 → GPO2, Bit3 → GP03 @@ -961,7 +995,10 @@ bool ad936x_iio_custom::select_rf_filter(std::string rf_filter) // 1 Enable // X Enable Mask if Identifier=0xF - if (check_device() == false) return false; + if (check_device() == false) + { + return false; + } // int plutoGpo = 0; int ret; ret = iio_device_debug_attr_write(phy, "adi,gpo-manual-mode-enable", "1"); @@ -972,7 +1009,7 @@ bool ad936x_iio_custom::select_rf_filter(std::string rf_filter) return false; } - if (rf_filter.compare("E1") == 0) + if (rf_filter == "E1") { // set gpio0 to switch L1 filter // setPlutoGpo(plutoGpo); @@ -983,7 +1020,7 @@ bool ad936x_iio_custom::select_rf_filter(std::string rf_filter) return false; } } - else if (rf_filter.compare("E5E6") == 0) + else if (rf_filter == "E5E6") { // set gpio0 to switch L5/L6 filter (GPO0) // plutoGpo = plutoGpo | 0x10; @@ -995,7 +1032,7 @@ bool ad936x_iio_custom::select_rf_filter(std::string rf_filter) return false; } } - if (rf_filter.compare("none") == 0) + if (rf_filter == "none") { std::cout << "RF external filter not selected\n"; } @@ -1108,18 +1145,18 @@ bool ad936x_iio_custom::start_sample_rx(bool ppsmode) switch (n_channels) { case 1: - channels.push_back("voltage0"); // Channel 0 I - channels.push_back("voltage1"); // Channel 0 Q + channels.emplace_back("voltage0"); // Channel 0 I + channels.emplace_back("voltage1"); // Channel 0 Q break; case 2: - channels.push_back("voltage0"); // Channel 0 I - channels.push_back("voltage1"); // Channel 0 Q - channels.push_back("voltage2"); // Channel 1 I - channels.push_back("voltage3"); // Channel 1 Q + channels.emplace_back("voltage0"); // Channel 0 I + channels.emplace_back("voltage1"); // Channel 0 Q + channels.emplace_back("voltage2"); // Channel 1 I + channels.emplace_back("voltage3"); // Channel 1 Q break; default: - channels.push_back("voltage0"); // Channel 0 I - channels.push_back("voltage1"); // Channel 0 Q + channels.emplace_back("voltage0"); // Channel 0 I + channels.emplace_back("voltage1"); // Channel 0 Q } receive_samples = true; @@ -1151,7 +1188,10 @@ void ad936x_iio_custom::push_sample_buffer(std::shared_ptr & void ad936x_iio_custom::capture(const std::vector &channels) { - if (check_device() == false) return; + if (check_device() == false) + { + return; + } struct iio_buffer *rxbuf; @@ -1179,16 +1219,14 @@ void ad936x_iio_custom::capture(const std::vector &channels) } else { - for (std::vector::const_iterator it = - channels.begin(); - it != channels.end(); ++it) + for (const auto &channel : channels) { struct iio_channel *chn = iio_device_find_channel(stream_dev, - it->c_str(), false); + channel.c_str(), false); if (!chn) { - std::cerr << "Channel " << it->c_str() << " not found\n"; + std::cerr << "Channel " << channel.c_str() << " not found\n"; return; } else @@ -1247,7 +1285,10 @@ void ad936x_iio_custom::capture(const std::vector &channels) items_in_buffer = static_cast(ret) / bytes_to_interleaved_iq_samples; - if (items_in_buffer == 0) return; + if (items_in_buffer == 0) + { + return; + } current_samples->n_channels = n_channels; current_samples->n_interleaved_iq_samples = items_in_buffer; diff --git a/src/algorithms/signal_source/libs/ad936x_iio_custom.h b/src/algorithms/signal_source/libs/ad936x_iio_custom.h index ab58f36cc..0c6199968 100644 --- a/src/algorithms/signal_source/libs/ad936x_iio_custom.h +++ b/src/algorithms/signal_source/libs/ad936x_iio_custom.h @@ -41,15 +41,15 @@ class ad936x_iio_custom public: ad936x_iio_custom(int debug_level_, int log_level_); virtual ~ad936x_iio_custom(); - bool initialize_device(std::string pluto_device_uri, std::string board_type); + bool initialize_device(const std::string &pluto_device_uri, const std::string &board_type); bool init_config_ad9361_rx(long long bandwidth_, long long sample_rate_, long long freq_, - std::string rf_port_select_, - std::string rf_filter, - std::string gain_mode_rx0_, - std::string gain_mode_rx1_, + const std::string &rf_port_select_, + const std::string &rf_filter, + const std::string &gain_mode_rx0_, + const std::string &gain_mode_rx1_, double rf_gain_rx0_, double rf_gain_rx1_, bool enable_ch0, @@ -62,7 +62,7 @@ public: bool calibrate(int ch, double bw_hz); double get_rx_gain(int ch_num); - bool setRXGain(int ch_num, std::string gain_mode, double gain_dB); + bool setRXGain(int ch_num, const std::string &gain_mode, double gain_dB); bool set_antenna_port(int ch, int antenna_idx); double get_frequency(int ch); @@ -94,9 +94,9 @@ private: unsigned long long frequency, unsigned long samplerate, unsigned long bandwidth, bool quadrature, bool rfdc, bool bbdc, - std::string gain1, double gain1_value, - std::string gain2, double gain2_value, - std::string port_select); + const std::string &gain1, double gain1_value, + const std::string &gain2, double gain2_value, + const std::string &port_select); bool config_ad9361_dds(uint64_t freq_rf_tx_hz_, double tx_attenuation_db_, @@ -108,7 +108,7 @@ private: void get_PPS_timestamp(); void capture(const std::vector &channels); - bool select_rf_filter(std::string rf_filter); + bool select_rf_filter(const std::string &rf_filter); void monitor_thread_fn(); @@ -121,12 +121,6 @@ private: struct iio_device *stream_dev; struct iio_device *dds_dev; - // stream - uint64_t sample_rate_sps; - int debug_level; - int log_level; - bool PPS_mode; - std::mutex mtx; std::condition_variable cv; @@ -140,6 +134,12 @@ private: std::thread capture_samples_thread; std::thread overflow_monitor_thread; std::thread capture_time_thread; + + // stream + uint64_t sample_rate_sps; + int debug_level; + int log_level; + bool PPS_mode; }; /** \} */ diff --git a/src/algorithms/signal_source/libs/ad936x_iio_samples.cc b/src/algorithms/signal_source/libs/ad936x_iio_samples.cc deleted file mode 100644 index b9b7b505a..000000000 --- a/src/algorithms/signal_source/libs/ad936x_iio_samples.cc +++ /dev/null @@ -1,25 +0,0 @@ -/*! - * \file ad936x_iio_samples.cc - * \brief A class that holds a custom sample buffer for Analog Devices AD936x family front-ends. - * \author Javier Arribas, jarribas(at)cttc.es - * - * ----------------------------------------------------------------------------- - * - * GNSS-SDR is a Global Navigation Satellite System software-defined receiver. - * This file is part of GNSS-SDR. - * - * Copyright (C) 2010-2022 (see AUTHORS file for a list of contributors) - * SPDX-License-Identifier: GPL-3.0-or-later - * - * ----------------------------------------------------------------------------- - */ - -#include "ad936x_iio_samples.h" - -ad936x_iio_samples::ad936x_iio_samples() -{ - n_bytes = 0; - n_interleaved_iq_samples = 0; - step_bytes = 0; - n_channels = 0; -} diff --git a/src/algorithms/signal_source/libs/ad936x_iio_samples.h b/src/algorithms/signal_source/libs/ad936x_iio_samples.h index 53fff2c9e..9a1d7ce90 100644 --- a/src/algorithms/signal_source/libs/ad936x_iio_samples.h +++ b/src/algorithms/signal_source/libs/ad936x_iio_samples.h @@ -33,11 +33,11 @@ class ad936x_iio_samples { public: - ad936x_iio_samples(); - uint32_t n_bytes; - uint32_t n_interleaved_iq_samples; - uint16_t n_channels; - uint16_t step_bytes; + ad936x_iio_samples() = default; + uint32_t n_bytes{0}; + uint32_t n_interleaved_iq_samples{0}; + uint16_t n_channels{0}; + uint16_t step_bytes{0}; char buffer[IIO_DEFAULTAD936XAPIFIFOSIZE_SAMPLES * 4 * 4]; // max 16 bits samples per buffer (4 channels, 2-bytes per I + 2-bytes per Q) }; diff --git a/src/algorithms/signal_source/libs/ppstcprx.cc b/src/algorithms/signal_source/libs/ppstcprx.cc index c23261aff..94dda2052 100644 --- a/src/algorithms/signal_source/libs/ppstcprx.cc +++ b/src/algorithms/signal_source/libs/ppstcprx.cc @@ -20,19 +20,6 @@ #include #include -pps_tcp_rx::pps_tcp_rx() -{ - // TODO Auto-generated constructor stub - is_connected = false; - clientSd = -1; -} - - -pps_tcp_rx::~pps_tcp_rx() -{ - // TODO Auto-generated destructor stub -} - void pps_tcp_rx::set_pps_samplestamp_queue(std::shared_ptr> queue) { @@ -40,7 +27,7 @@ void pps_tcp_rx::set_pps_samplestamp_queue(std::shared_ptr> Pps_queue; - int clientSd; + int clientSd{-1}; public: - volatile bool is_connected; - pps_tcp_rx(); - virtual ~pps_tcp_rx(); + volatile bool is_connected{false}; + pps_tcp_rx() = default; + virtual ~pps_tcp_rx() = default; - void receive_pps(std::string ip_address, int port); - bool send_cmd(std::string cmd); + void receive_pps(const std::string& ip_address, int port); + bool send_cmd(std::string cmd) const; void set_pps_samplestamp_queue(std::shared_ptr> queue); };