From 7aa19d9642bcc730087681cc2e982106fedb05ca Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sun, 18 Aug 2024 10:57:40 +0200 Subject: [PATCH 1/8] Use lock_guard instead of unique_lock --- .../adrv9361_z7035_signal_source_fpga.cc | 35 +++++++++---------- .../adrv9361_z7035_signal_source_fpga.h | 10 +++--- .../adapters/fmcomms5_signal_source_fpga.cc | 35 +++++++++---------- .../adapters/fmcomms5_signal_source_fpga.h | 11 +++--- .../max2771_evkit_signal_source_fpga.cc | 21 +++++------ .../max2771_evkit_signal_source_fpga.h | 4 +-- 6 files changed, 52 insertions(+), 64 deletions(-) diff --git a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc index 9d29e2de2..392d91b13 100644 --- a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc +++ b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc @@ -1,6 +1,6 @@ /*! * \file adrv9361_z7035_signal_source_fpga.cc - * \brief signal source for the Analog Devices ADRV9361-Z7035 evaluation board + * \brief Signal source for the Analog Devices ADRV9361-Z7035 evaluation board * directly connected to the FPGA accelerators. * This source implements only the AD9361 control. It is NOT compatible with * conventional SDR acquisition and tracking blocks. @@ -257,7 +257,6 @@ Adrv9361z7035SignalSourceFPGA::Adrv9361z7035SignalSourceFPGA(const Configuration buffer_monitor_fpga = std::make_shared(num_freq_bands, dump_, dump_filename); thread_buffer_monitor = std::thread([&] { run_buffer_monitor_process(); }); - // dynamic bits selection if (enable_dynamic_bit_selection_) { @@ -278,8 +277,7 @@ Adrv9361z7035SignalSourceFPGA::Adrv9361z7035SignalSourceFPGA(const Configuration Adrv9361z7035SignalSourceFPGA::~Adrv9361z7035SignalSourceFPGA() { - /* cleanup and exit */ - + // cleanup and exit if (rf_shutdown_) { std::cout << "* AD9361 Disabling RX streaming channels\n"; @@ -301,24 +299,27 @@ Adrv9361z7035SignalSourceFPGA::~Adrv9361z7035SignalSourceFPGA() } // disable buffer overflow checking and buffer monitoring - std::unique_lock lock_buffer_monitor(buffer_monitor_mutex); - enable_ovf_check_buffer_monitor_active_ = false; - lock_buffer_monitor.unlock(); + { + std::lock_guard lock_buffer_monitor(buffer_monitor_mutex); + enable_ovf_check_buffer_monitor_active_ = false; + } if (thread_buffer_monitor.joinable()) { thread_buffer_monitor.join(); } - - std::unique_lock lock_dyn_bit_sel(dynamic_bit_selection_mutex); - bool bit_selection_enabled = enable_dynamic_bit_selection_; - lock_dyn_bit_sel.unlock(); + bool bit_selection_enabled = false; + { + std::lock_guard lock_dyn_bit_sel(dynamic_bit_selection_mutex); + bit_selection_enabled = enable_dynamic_bit_selection_; + } if (bit_selection_enabled == true) { - std::unique_lock lock(dynamic_bit_selection_mutex); - enable_dynamic_bit_selection_ = false; - lock.unlock(); + { + std::lock_guard lock(dynamic_bit_selection_mutex); + enable_dynamic_bit_selection_ = false; + } if (thread_dynamic_bit_selection.joinable()) { @@ -337,12 +338,11 @@ void Adrv9361z7035SignalSourceFPGA::run_dynamic_bit_selection_process() // setting the bit selection to the top bits dynamic_bit_selection_fpga->bit_selection(); std::this_thread::sleep_for(std::chrono::milliseconds(Gain_control_period_ms)); - std::unique_lock lock(dynamic_bit_selection_mutex); + std::lock_guard lock(dynamic_bit_selection_mutex); if (enable_dynamic_bit_selection_ == false) { dynamic_bit_selection_active = false; } - lock.unlock(); } } @@ -357,12 +357,11 @@ void Adrv9361z7035SignalSourceFPGA::run_buffer_monitor_process() { buffer_monitor_fpga->check_buffer_overflow_and_monitor_buffer_status(); std::this_thread::sleep_for(std::chrono::milliseconds(buffer_monitor_period_ms)); - std::unique_lock lock(buffer_monitor_mutex); + std::lock_guard lock(buffer_monitor_mutex); if (enable_ovf_check_buffer_monitor_active_ == false) { enable_ovf_check_buffer_monitor_active = false; } - lock.unlock(); } } diff --git a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.h b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.h index 5e7e8b7e4..beffb3c70 100644 --- a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.h +++ b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.h @@ -1,6 +1,6 @@ /*! * \file adrv9361_z7035_signal_source_fpga.h - * \brief signal source for the Analog Devices ADRV9361-Z7035 evaluation board + * \brief Signal source for the Analog Devices ADRV9361-Z7035 evaluation board * directly connected to the FPGA accelerators. * This source implements only the AD9361 control. It is NOT compatible with * conventional SDR acquisition and tracking blocks. @@ -78,13 +78,14 @@ private: const uint32_t buffer_monitor_period_ms = 1000; // buffer overflow and buffer monitoring initial delay const uint32_t buffer_monitoring_initial_delay_ms = 2000; - // sample block size when running in post-processing mode - const int sample_block_size = 16384; const int32_t switch_to_real_time_mode = 2; void run_dynamic_bit_selection_process(); void run_buffer_monitor_process(); + mutable std::mutex dynamic_bit_selection_mutex; + mutable std::mutex buffer_monitor_mutex; + std::thread thread_dynamic_bit_selection; std::thread thread_buffer_monitor; @@ -92,9 +93,6 @@ private: std::shared_ptr dynamic_bit_selection_fpga; std::shared_ptr buffer_monitor_fpga; - std::mutex dynamic_bit_selection_mutex; - std::mutex buffer_monitor_mutex; - std::string gain_mode_rx1_; std::string gain_mode_rx2_; std::string rf_port_select_; diff --git a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc index d8c5a65c0..096e422db 100644 --- a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc +++ b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc @@ -1,6 +1,6 @@ /*! * \file fmcomms5_signal_source_fpga.cc - * \brief signal source for the Analog Devices FMCOMMS5 directly connected + * \brief Signal source for the Analog Devices FMCOMMS5 directly connected * to the FPGA accelerators. * This source implements only the AD9361 control. It is NOT compatible with * conventional SDR acquisition and tracking blocks. @@ -217,7 +217,6 @@ Fmcomms5SignalSourceFPGA::Fmcomms5SignalSourceFPGA(const ConfigurationInterface buffer_monitor_fpga = std::make_shared(num_freq_bands, dump_, dump_filename); thread_buffer_monitor = std::thread([&] { run_buffer_monitor_process(); }); - // dynamic bits selection if (enable_dynamic_bit_selection_) { @@ -238,8 +237,7 @@ Fmcomms5SignalSourceFPGA::Fmcomms5SignalSourceFPGA(const ConfigurationInterface Fmcomms5SignalSourceFPGA::~Fmcomms5SignalSourceFPGA() { - /* cleanup and exit */ - + // cleanup and exit if (rf_shutdown_) { std::cout << "* Disabling RX streaming channels\n"; @@ -250,24 +248,27 @@ Fmcomms5SignalSourceFPGA::~Fmcomms5SignalSourceFPGA() } // disable buffer overflow checking and buffer monitoring - std::unique_lock lock_buffer_monitor(buffer_monitor_mutex); - enable_ovf_check_buffer_monitor_active_ = false; - lock_buffer_monitor.unlock(); + { + std::lock_guard lock_buffer_monitor(buffer_monitor_mutex); + enable_ovf_check_buffer_monitor_active_ = false; + } if (thread_buffer_monitor.joinable()) { thread_buffer_monitor.join(); } - - std::unique_lock lock_dyn_bit_sel(dynamic_bit_selection_mutex); - bool bit_selection_enabled = enable_dynamic_bit_selection_; - lock_dyn_bit_sel.unlock(); + bool bit_selection_enabled = false; + { + std::lock_guard lock_dyn_bit_sel(dynamic_bit_selection_mutex); + bit_selection_enabled = enable_dynamic_bit_selection_; + } if (bit_selection_enabled == true) { - std::unique_lock lock(dynamic_bit_selection_mutex); - enable_dynamic_bit_selection_ = false; - lock.unlock(); + { + std::lock_guard lock(dynamic_bit_selection_mutex); + enable_dynamic_bit_selection_ = false; + } if (thread_dynamic_bit_selection.joinable()) { @@ -286,12 +287,11 @@ void Fmcomms5SignalSourceFPGA::run_dynamic_bit_selection_process() // setting the bit selection to the top bits dynamic_bit_selection_fpga->bit_selection(); std::this_thread::sleep_for(std::chrono::milliseconds(Gain_control_period_ms)); - std::unique_lock lock(dynamic_bit_selection_mutex); + std::lock_guard lock(dynamic_bit_selection_mutex); if (enable_dynamic_bit_selection_ == false) { dynamic_bit_selection_active = false; } - lock.unlock(); } } @@ -306,12 +306,11 @@ void Fmcomms5SignalSourceFPGA::run_buffer_monitor_process() { buffer_monitor_fpga->check_buffer_overflow_and_monitor_buffer_status(); std::this_thread::sleep_for(std::chrono::milliseconds(buffer_monitor_period_ms)); - std::unique_lock lock(buffer_monitor_mutex); + std::lock_guard lock(buffer_monitor_mutex); if (enable_ovf_check_buffer_monitor_active_ == false) { enable_ovf_check_buffer_monitor_active = false; } - lock.unlock(); } } diff --git a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.h b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.h index 1bdcf4e6f..1c5c37c73 100644 --- a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.h +++ b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.h @@ -1,6 +1,6 @@ /*! * \file fmcomms5_signal_source_fpga.h - * \brief signal source for the Analog Devices FMCOMMS5 directly connected + * \brief Signal source for the Analog Devices FMCOMMS5 directly connected * to the FPGA accelerators. * This source implements only the AD9361 control. It is NOT compatible with * conventional SDR acquisition and tracking blocks. @@ -67,7 +67,6 @@ private: const std::string default_dump_filename = std::string("FPGA_buffer_monitor_dump.dat"); const std::string default_rf_port_select = std::string("A_BALANCED"); const std::string default_gain_mode = std::string("slow_attack"); - const double default_tx_attenuation_db = -10.0; const double default_manual_gain_rx1 = 64.0; const double default_manual_gain_rx2 = 64.0; const uint64_t default_bandwidth = 12500000; @@ -78,13 +77,14 @@ private: const uint32_t buffer_monitor_period_ms = 1000; // buffer overflow and buffer monitoring initial delay const uint32_t buffer_monitoring_initial_delay_ms = 2000; - // sample block size when running in post-processing mode - const int sample_block_size = 16384; const int32_t switch_to_real_time_mode = 2; void run_dynamic_bit_selection_process(); void run_buffer_monitor_process(); + mutable std::mutex dynamic_bit_selection_mutex; + mutable std::mutex buffer_monitor_mutex; + std::thread thread_dynamic_bit_selection; std::thread thread_buffer_monitor; @@ -92,9 +92,6 @@ private: std::shared_ptr dynamic_bit_selection_fpga; std::shared_ptr buffer_monitor_fpga; - std::mutex dynamic_bit_selection_mutex; - std::mutex buffer_monitor_mutex; - std::string gain_mode_rx1_; std::string gain_mode_rx2_; std::string rf_port_select_; diff --git a/src/algorithms/signal_source/adapters/max2771_evkit_signal_source_fpga.cc b/src/algorithms/signal_source/adapters/max2771_evkit_signal_source_fpga.cc index 788b50e77..80b310034 100644 --- a/src/algorithms/signal_source/adapters/max2771_evkit_signal_source_fpga.cc +++ b/src/algorithms/signal_source/adapters/max2771_evkit_signal_source_fpga.cc @@ -140,13 +140,11 @@ MAX2771EVKITSignalSourceFPGA::MAX2771EVKITSignalSourceFPGA(const ConfigurationIn } } + std::vector MAX2771EVKITSignalSourceFPGA::setup_regs(void) { - std::vector register_values = std::vector(MAX2771_NUM_REGS); - - + auto register_values = std::vector(MAX2771_NUM_REGS); uint32_t LNA_mode = (LNA_active_) ? 0x0 : 0x2; - uint32_t Filter_Bandwidth; switch (bandwidth_) @@ -376,10 +374,10 @@ bool MAX2771EVKITSignalSourceFPGA::configure(std::vector register_valu return 0; } + MAX2771EVKITSignalSourceFPGA::~MAX2771EVKITSignalSourceFPGA() { - /* cleanup and exit */ - + // cleanup and exit if (rf_shutdown_) { chipen_ = false; @@ -392,7 +390,6 @@ MAX2771EVKITSignalSourceFPGA::~MAX2771EVKITSignalSourceFPGA() return; } - if (configure(register_values)) { std::cerr << "Error disabling the MAX2771 device " << '\n'; @@ -405,9 +402,10 @@ MAX2771EVKITSignalSourceFPGA::~MAX2771EVKITSignalSourceFPGA() } // disable buffer overflow checking and buffer monitoring - std::unique_lock lock_buffer_monitor(buffer_monitor_mutex); - enable_ovf_check_buffer_monitor_active_ = false; - lock_buffer_monitor.unlock(); + { + std::lock_guard lock_buffer_monitor(buffer_monitor_mutex); + enable_ovf_check_buffer_monitor_active_ = false; + } if (thread_buffer_monitor.joinable()) { @@ -426,12 +424,11 @@ void MAX2771EVKITSignalSourceFPGA::run_buffer_monitor_process() { buffer_monitor_fpga->check_buffer_overflow_and_monitor_buffer_status(); std::this_thread::sleep_for(std::chrono::milliseconds(buffer_monitor_period_ms)); - std::unique_lock lock(buffer_monitor_mutex); + std::lock_guard lock(buffer_monitor_mutex); if (enable_ovf_check_buffer_monitor_active_ == false) { enable_ovf_check_buffer_monitor_active = false; } - lock.unlock(); } } diff --git a/src/algorithms/signal_source/adapters/max2771_evkit_signal_source_fpga.h b/src/algorithms/signal_source/adapters/max2771_evkit_signal_source_fpga.h index 3008aa384..5ba036ca3 100644 --- a/src/algorithms/signal_source/adapters/max2771_evkit_signal_source_fpga.h +++ b/src/algorithms/signal_source/adapters/max2771_evkit_signal_source_fpga.h @@ -53,7 +53,6 @@ public: std::vector setup_regs(void); - inline size_t item_size() override { return item_size_; @@ -130,14 +129,13 @@ private: bool configure(std::vector register_values); void run_buffer_monitor_process(); + mutable std::mutex buffer_monitor_mutex; std::thread thread_buffer_monitor; std::shared_ptr buffer_monitor_fpga; std::shared_ptr spidev_fpga; - std::mutex buffer_monitor_mutex; - uint64_t freq_; // frequency of local oscillator uint64_t sample_rate_; From df1314945f43afdb531f9b5df848e26e28e87178 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 19 Aug 2024 10:56:11 +0200 Subject: [PATCH 2/8] Fix CMake lists --- src/algorithms/signal_source/libs/CMakeLists.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/algorithms/signal_source/libs/CMakeLists.txt b/src/algorithms/signal_source/libs/CMakeLists.txt index 3506dc4f7..19235ceac 100644 --- a/src/algorithms/signal_source/libs/CMakeLists.txt +++ b/src/algorithms/signal_source/libs/CMakeLists.txt @@ -9,12 +9,12 @@ set(OPT_SIGNAL_SOURCE_LIB_SOURCES "") set(OPT_SIGNAL_SOURCE_LIB_HEADERS "") if(ENABLE_FMCOMMS2 OR ENABLE_AD9361) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad9361_manager.cc) - set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ad9361_manager.h) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ad9361_manager.h) endif() if(ENABLE_MAX2771) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} fpga_spidev.cc) - set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_SOURCES} fpga_spidev.h) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} fpga_spidev.h) endif() if(ENABLE_FPGA) @@ -36,10 +36,10 @@ 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_SOURCES} ad936x_iio_samples.h) + 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_SOURCES} ad936x_iio_custom.h) - set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_SOURCES} pps_samplestamp.h) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} ad936x_iio_custom.h) + set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_HEADERS} pps_samplestamp.h) set(OPT_SIGNAL_SOURCE_LIB_SOURCES ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ppstcprx.cc) set(OPT_SIGNAL_SOURCE_LIB_HEADERS ${OPT_SIGNAL_SOURCE_LIB_SOURCES} ppstcprx.h) endif() From 126421f8476be402d4ab99f7c1aaa2fd0932a50d Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 19 Aug 2024 12:30:25 +0200 Subject: [PATCH 3/8] Catch all exceptions --- .../adapters/adrv9361_z7035_signal_source_fpga.cc | 13 +++++++++++-- .../adapters/fmcomms5_signal_source_fpga.cc | 11 +++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc index 392d91b13..cc8f7fe32 100644 --- a/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc +++ b/src/algorithms/signal_source/adapters/adrv9361_z7035_signal_source_fpga.cc @@ -281,10 +281,19 @@ Adrv9361z7035SignalSourceFPGA::~Adrv9361z7035SignalSourceFPGA() if (rf_shutdown_) { std::cout << "* AD9361 Disabling RX streaming channels\n"; - if (!disable_ad9361_rx_local()) + try { - LOG(WARNING) << "Problem shutting down the AD9361 RX channels"; + if (!disable_ad9361_rx_local()) + { + LOG(WARNING) << "Problem shutting down the AD9361 RX channels"; + } } + catch (const std::exception &e) + { + LOG(WARNING) << "Problem shutting down the AD9361 RX channels: " << e.what(); + std::cerr << "Problem shutting down the AD9361 RX channels: " << e.what() << '\n'; + } + if (enable_dds_lo_) { try diff --git a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc index 096e422db..be2108aa4 100644 --- a/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc +++ b/src/algorithms/signal_source/adapters/fmcomms5_signal_source_fpga.cc @@ -241,9 +241,16 @@ Fmcomms5SignalSourceFPGA::~Fmcomms5SignalSourceFPGA() if (rf_shutdown_) { std::cout << "* Disabling RX streaming channels\n"; - if (!disable_ad9361_rx_local()) + try { - LOG(WARNING) << "Problem shutting down the AD9361 RX channels"; + if (!disable_ad9361_rx_local()) + { + LOG(WARNING) << "Problem shutting down the AD9361 RX channels"; + } + } + catch (const std::exception &e) + { + std::cerr << "Problem shutting down the AD9361 RX channels: " << e.what() << '\n'; } } From 6836ac44fb5cb8d9fc5327aac5bb1b8ab1d9b370 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 19 Aug 2024 14:21:59 +0200 Subject: [PATCH 4/8] Fix building for -DENABLE_PLUTOSDR=ON --- CMakeLists.txt | 2 +- .../signal_source/adapters/CMakeLists.txt | 2 +- .../gnuradio_blocks/ad936x_iio_source.cc | 2 +- .../signal_source/libs/ad936x_iio_custom.cc | 3 +- .../signal_source/libs/ad936x_iio_custom.h | 32 +++++++++---------- .../signal_source/libs/ad936x_iio_samples.h | 12 +++++-- 6 files changed, 30 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3696eede2..8c0e25d25 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3338,7 +3338,7 @@ set_package_properties(LIBIIO PROPERTIES PURPOSE "Used for communication with the AD9361 chipset." TYPE OPTIONAL ) -if(ENABLE_AD9361 OR ENABLE_FMCOMMS2) +if(ENABLE_AD9361 OR ENABLE_FMCOMMS2 OR ENABLE_PLUTOSDR) if(NOT LIBIIO_FOUND) message(STATUS "libiio not found, its installation is required.") message(STATUS "Please build and install the following projects:") diff --git a/src/algorithms/signal_source/adapters/CMakeLists.txt b/src/algorithms/signal_source/adapters/CMakeLists.txt index 0aa745101..6b253d8c7 100644 --- a/src/algorithms/signal_source/adapters/CMakeLists.txt +++ b/src/algorithms/signal_source/adapters/CMakeLists.txt @@ -239,7 +239,7 @@ if(ENABLE_LIMESDR AND GRLIMESDR_FOUND) ) endif() -if(ENABLE_AD9361 AND LIBIIO_FOUND) +if(LIBIIO_FOUND) target_link_libraries(signal_source_adapters PRIVATE Iio::iio 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 0cf885fe2..375edf7da 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/ad936x_iio_source.cc @@ -87,7 +87,7 @@ ad936x_iio_source_sptr ad936x_iio_make_source_sptr( void ad936x_iio_source::ad9361_channel_demux_and_record(ad936x_iio_samples *samples_in, int nchannels, std::vector *files_out) { - int32_t current_byte = 0; + uint32_t current_byte = 0; int16_t ch = 0; // std::cout << "nbytes: " << samples_in->n_bytes << " nsamples: " << samples_in->n_samples << " nch: " << nchannels << "\n"; while (current_byte < samples_in->n_bytes) diff --git a/src/algorithms/signal_source/libs/ad936x_iio_custom.cc b/src/algorithms/signal_source/libs/ad936x_iio_custom.cc index 72461bafd..ad983aa6b 100644 --- a/src/algorithms/signal_source/libs/ad936x_iio_custom.cc +++ b/src/algorithms/signal_source/libs/ad936x_iio_custom.cc @@ -1,6 +1,7 @@ /*! * \file ad936x_iio_custom.cc - * \brief A direct IIO custom front-end driver for the AD936x AD front-end family with special FPGA custom functionalities. + * \brief A direct IIO custom front-end driver for the AD936x AD front-end + * family with special FPGA custom functionalities. * \author Javier Arribas, jarribas(at)cttc.es * ----------------------------------------------------------------------------- * diff --git a/src/algorithms/signal_source/libs/ad936x_iio_custom.h b/src/algorithms/signal_source/libs/ad936x_iio_custom.h index 83a61282a..ab58f36cc 100644 --- a/src/algorithms/signal_source/libs/ad936x_iio_custom.h +++ b/src/algorithms/signal_source/libs/ad936x_iio_custom.h @@ -1,6 +1,7 @@ /*! * \file ad936x_iio_custom.h - * \brief A direct IIO custom front-end driver for the AD936x AD front-end family with special FPGA custom functionalities. + * \brief A direct IIO custom front-end driver for the AD936x AD front-end + * family with special FPGA custom functionalities. * \author Javier Arribas, jarribas(at)cttc.es * ----------------------------------------------------------------------------- * @@ -14,27 +15,27 @@ */ -#ifndef SRC_LIBS_ad936x_iio_custom_H_ -#define SRC_LIBS_ad936x_iio_custom_H_ +#ifndef GNSS_SDR_AD936X_IIO_CUSTOM_H +#define GNSS_SDR_AD936X_IIO_CUSTOM_H +#include "ad936x_iio_samples.h" #include "concurrent_queue.h" #include "gnss_time.h" #include "pps_samplestamp.h" #include +#include +#include // multichip sync and high level functions #include #include - -#ifdef __APPLE__ -#include -#else -#include -#endif - -#include "ad936x_iio_samples.h" -#include // multichip sync and high level functions #include #include +/** \addtogroup Signal_Source + * \{ */ +/** \addtogroup Signal_Source_libs + * \{ */ + + class ad936x_iio_custom { public: @@ -121,10 +122,7 @@ private: struct iio_device *dds_dev; // stream - uint64_t sample_rate_sps; - - int debug_level; int log_level; bool PPS_mode; @@ -144,4 +142,6 @@ private: std::thread capture_time_thread; }; -#endif /* SRC_LIBS_ad936x_iio_custom_H_ */ +/** \} */ +/** \} */ +#endif // GNSS_SDR_AD936X_IIO_CUSTOM_H diff --git a/src/algorithms/signal_source/libs/ad936x_iio_samples.h b/src/algorithms/signal_source/libs/ad936x_iio_samples.h index 63d30545b..53fff2c9e 100644 --- a/src/algorithms/signal_source/libs/ad936x_iio_samples.h +++ b/src/algorithms/signal_source/libs/ad936x_iio_samples.h @@ -15,17 +15,21 @@ */ -#ifndef SRC_LIBS_ad936x_iio_samples_H_ -#define SRC_LIBS_ad936x_iio_samples_H_ +#ifndef GNSS_SDR_AD936X_IIO_SAMPLES_H +#define GNSS_SDR_AD936X_IIO_SAMPLES_H #define IIO_DEFAULTAD936XAPIFIFOSIZE_SAMPLES 32768 * 4 - #define IIO_INPUTRAMFIFOSIZE 256 #include #include #include +/** \addtogroup Signal_Source + * \{ */ +/** \addtogroup Signal_Source_libs + * \{ */ + class ad936x_iio_samples { public: @@ -37,4 +41,6 @@ public: char buffer[IIO_DEFAULTAD936XAPIFIFOSIZE_SAMPLES * 4 * 4]; // max 16 bits samples per buffer (4 channels, 2-bytes per I + 2-bytes per Q) }; +/** \} */ +/** \} */ #endif From 9bf3f457c361c67175e4a12563d8204d9b0a3146 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 20 Aug 2024 14:54:15 +0200 Subject: [PATCH 5/8] Cleaner exit if the data file is not found --- .../signal_source/gnuradio_blocks/ion_gsms.cc | 12 +++++++++--- .../signal_source/gnuradio_blocks/ion_gsms.h | 1 - 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc index 034f43379..60a08ba6c 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc +++ b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.cc @@ -18,6 +18,8 @@ #include "gnuradio/block.h" #include #include +#include +#include #if USE_GLOG_AND_GFLAGS #include @@ -25,8 +27,6 @@ #include #endif -using namespace std::string_literals; - IONGSMSFileSource::IONGSMSFileSource( const fs::path& metadata_filepath, const GnssMetadata::File& file, @@ -46,7 +46,10 @@ IONGSMSFileSource::IONGSMSFileSource( if (!file_stream_.is_open()) { - LOG(ERROR) << "ion_gsms_file_source: Unable to open the samples file: " << (data_filepath).c_str(); + LOG(WARNING) << "ION_GSMS_Signal_Source - Unable to open the samples file: " << (data_filepath).c_str(); + std::cerr << "ION_GSMS_Signal_Source - Unable to open the samples file: " << (data_filepath).c_str() << std::endl; + std::cout << "GNSS-SDR program ended.\n"; + exit(1); } // Skip offset and block header @@ -96,11 +99,13 @@ std::size_t IONGSMSFileSource::output_stream_item_size(std::size_t stream_index) return output_stream_item_sizes_[stream_index]; } + std::size_t IONGSMSFileSource::output_stream_total_sample_count(std::size_t stream_index) const { return output_stream_total_sample_counts_[stream_index]; } + gr::io_signature::sptr IONGSMSFileSource::make_output_signature(const GnssMetadata::Block& block, const std::vector& stream_ids) { int nstreams = 0; @@ -142,6 +147,7 @@ gr::io_signature::sptr IONGSMSFileSource::make_output_signature(const GnssMetada item_sizes); } + int IONGSMSFileSource::work( int noutput_items, gr_vector_const_void_star& input_items __attribute__((unused)), diff --git a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h index a787344bf..c82726b85 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h +++ b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h @@ -23,7 +23,6 @@ #include #include #include -#include #include #include #include From 4929d8775921c59f3f0cddf90481e7a4968e5ecc Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 20 Aug 2024 14:58:01 +0200 Subject: [PATCH 6/8] Fix uninitialized warning --- .../signal_source/libs/ion_gsms_chunk_unpacking_ctx.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h b/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h index 3c5d7b662..6799f1080 100644 --- a/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h +++ b/src/algorithms/signal_source/libs/ion_gsms_chunk_unpacking_ctx.h @@ -34,8 +34,8 @@ struct IONGSMSChunkUnpackingCtx static constexpr uint8_t word_bitsize_ = sizeof(WT) * 8; const GnssMetadata::Chunk::WordShift word_shift_direction_; - WT* iterator_; // Not owned by this class, MUST NOT destroy - WT current_word_; + WT* iterator_ = nullptr; // Not owned by this class, MUST NOT destroy + WT current_word_{}; uint8_t bitshift_ = 0; IONGSMSChunkUnpackingCtx( @@ -51,7 +51,10 @@ struct IONGSMSChunkUnpackingCtx { iterator_ = &data_buffer[data_buffer_word_count]; } - advance_word(); // Initializes current_word_ + if (iterator_) + { + advance_word(); // Initializes current_word_ + } } void advance_word() From ca150572d10ef0dbbf1e354455bdce17ca822703 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 20 Aug 2024 15:12:38 +0200 Subject: [PATCH 7/8] Remove unused configuration parameter. Uniformize guard names --- .../signal_source/adapters/ion_gsms_signal_source.cc | 7 ++++--- .../signal_source/adapters/ion_gsms_signal_source.h | 7 +++---- src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc index b67ec8a3a..2def04c75 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.cc @@ -19,9 +19,8 @@ #include "gnss_sdr_string_literals.h" #include "gnss_sdr_valve.h" #include -#include +#include #include -#include #if USE_GLOG_AND_GFLAGS #include @@ -59,7 +58,6 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura : SignalSourceBase(configuration, role, "ION_GSMS_Signal_Source"s), stream_ids_(parse_comma_list(configuration->property(role + ".streams"s, ""s))), metadata_filepath_(configuration->property(role + ".metadata_filename"s, "../data/example_capture_metadata.sdrx"s)), - timestamp_clock_offset_ms_(configuration->property(role + ".timestamp_clock_offset_ms"s, 0.0)), in_streams_(in_streams), out_streams_(out_streams) { @@ -88,6 +86,7 @@ IONGSMSSignalSource::IONGSMSSignalSource(const ConfigurationInterface* configura } } + void IONGSMSSignalSource::load_metadata() { try @@ -117,6 +116,7 @@ void IONGSMSSignalSource::load_metadata() } } + std::vector IONGSMSSignalSource::make_stream_sources(const std::vector& stream_ids) const { std::vector sources{}; @@ -180,6 +180,7 @@ std::vector IONGSMSSignalSource::make_stream_sources(co return sources; } + void IONGSMSSignalSource::connect(gr::top_block_sptr top_block) { std::size_t cumulative_index = 0; diff --git a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h index 31d0f7815..fd0a5140c 100644 --- a/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h +++ b/src/algorithms/signal_source/adapters/ion_gsms_signal_source.h @@ -15,8 +15,8 @@ */ -#ifndef GNSS_SDR_ION_METADATA_STANDARD_SIGNAL_SOURCE_H -#define GNSS_SDR_ION_METADATA_STANDARD_SIGNAL_SOURCE_H +#ifndef GNSS_SDR_ION_GSMS_SIGNAL_SOURCE_H +#define GNSS_SDR_ION_GSMS_SIGNAL_SOURCE_H #include "configuration_interface.h" #include "file_source_base.h" @@ -73,7 +73,6 @@ private: gnss_shared_ptr timestamp_block_; std::string timestamp_file_; - double timestamp_clock_offset_ms_; uint32_t in_streams_; uint32_t out_streams_; @@ -82,4 +81,4 @@ private: /** \} */ /** \} */ -#endif // GNSS_SDR_ION_METADATA_STANDARD_SIGNAL_SOURCE_H +#endif // GNSS_SDR_ION_GSMS_SIGNAL_SOURCE_H diff --git a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h index c82726b85..4a6baa7e9 100644 --- a/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h +++ b/src/algorithms/signal_source/gnuradio_blocks/ion_gsms.h @@ -14,8 +14,8 @@ * ----------------------------------------------------------------------------- */ -#ifndef GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H -#define GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H +#ifndef GNSS_SDR_ION_GSMS_H +#define GNSS_SDR_ION_GSMS_H #include "gnss_block_interface.h" #include "gnss_sdr_filesystem.h" @@ -30,7 +30,7 @@ /** \addtogroup Signal_Source * \{ */ -/** \addtogroup Signal_Source_libs +/** \addtogroup Signal_Source_gnuradio_blocks * \{ */ class IONGSMSFileSource : public gr::sync_block @@ -71,4 +71,4 @@ private: /** \} */ /** \} */ -#endif // GNSS_SDR_ION_GNSS_SDR_METADATA_STANDARD_H +#endif // GNSS_SDR_ION_GSMS_H From 7f5704917f1ba47bebaa0835ca2b683939fb9654 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Tue, 20 Aug 2024 15:21:39 +0200 Subject: [PATCH 8/8] Fix for CMake < 3.14 --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 18aa2e276..a0606e348 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1424,6 +1424,7 @@ else() endif() + ################################################################################ # Abseil C++ - https://abseil.io/docs/cpp/ ################################################################################ @@ -3360,6 +3361,9 @@ endif() ################################################################################ # ION GNSS-SDR Metadata Standard https://sdr.ion.org/ (OPTIONAL) ################################################################################ +if(CMAKE_VERSION VERSION_LESS 3.14) + set(ENABLE_ION OFF) # FetchContent_MakeAvailable is available from CMake 3.14 +endif() if(ENABLE_ION) include(FetchContent) set(CMAKE_POLICY_DEFAULT_CMP0063 NEW)