From 48a62594eb2a17b8f8cb3bf6c695dff9a1b49369 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Mon, 7 Oct 2019 22:45:09 +0200 Subject: [PATCH] Add work on RF configuration parameters for AD9361 --- .../adapters/ad9361_fpga_signal_source.cc | 120 ++++++++++++----- .../adapters/ad9361_fpga_signal_source.h | 3 +- .../adapters/fmcomms2_signal_source.cc | 125 +++++++++++++++--- .../adapters/fmcomms2_signal_source.h | 18 +-- .../adapters/plutosdr_signal_source.cc | 44 +++++- .../adapters/plutosdr_signal_source.h | 13 +- .../signal_source/libs/ad9361_manager.cc | 20 ++- 7 files changed, 266 insertions(+), 77 deletions(-) diff --git a/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.cc b/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.cc index c2cc90137..4a5febc21 100644 --- a/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.cc +++ b/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.cc @@ -37,6 +37,7 @@ #include "configuration_interface.h" #include #include +#include // for abs #include #include // for open, O_WRONLY #include // for std::ifstream @@ -277,6 +278,11 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(ConfigurationInterface *configura const std::string &role, unsigned int in_stream, unsigned int out_stream, std::shared_ptr> queue) : role_(role), in_stream_(in_stream), out_stream_(out_stream), queue_(std::move(queue)) { + std::string default_gain_mode("slow attack"); + double default_tx_attenuation_db = -10.0; + double default_manual_gain_rx1 = 64.0; + double default_manual_gain_rx2 = 64.0; + std::string default_rf_port_select("A_BALANCED"); freq_ = configuration->property(role + ".freq", GPS_L1_FREQ_HZ); sample_rate_ = configuration->property(role + ".sampling_frequency", 12500000); bandwidth_ = configuration->property(role + ".bandwidth", 12500000); @@ -286,25 +292,33 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(ConfigurationInterface *configura quadrature_ = configuration->property(role + ".quadrature", true); rf_dc_ = configuration->property(role + ".rf_dc", true); bb_dc_ = configuration->property(role + ".bb_dc", true); - gain_mode_rx1_ = configuration->property(role + ".gain_mode_rx1", std::string("manual")); - gain_mode_rx2_ = configuration->property(role + ".gain_mode_rx2", std::string("manual")); - rf_gain_rx1_ = configuration->property(role + ".gain_rx1", 64.0); - rf_gain_rx2_ = configuration->property(role + ".gain_rx2", 64.0); - rf_port_select_ = configuration->property(role + ".rf_port_select", std::string("A_BALANCED")); + gain_mode_rx1_ = configuration->property(role + ".gain_mode_rx1", default_gain_mode); + gain_mode_rx2_ = configuration->property(role + ".gain_mode_rx2", default_gain_mode); + rf_gain_rx1_ = configuration->property(role + ".gain_rx1", default_manual_gain_rx1); + rf_gain_rx2_ = configuration->property(role + ".gain_rx2", default_manual_gain_rx2); + rf_port_select_ = configuration->property(role + ".rf_port_select", default_rf_port_select); filter_file_ = configuration->property(role + ".filter_file", std::string("")); - filter_auto_ = configuration->property(role + ".filter_auto", true); + filter_auto_ = configuration->property(role + ".filter_auto", false); samples_ = configuration->property(role + ".samples", 0); enable_dds_lo_ = configuration->property(role + ".enable_dds_lo", false); freq_rf_tx_hz_ = configuration->property(role + ".freq_rf_tx_hz", GPS_L1_FREQ_HZ - GPS_L2_FREQ_HZ - 1000); freq_dds_tx_hz_ = configuration->property(role + ".freq_dds_tx_hz", 1000); scale_dds_dbfs_ = configuration->property(role + ".scale_dds_dbfs", -3.0); phase_dds_deg_ = configuration->property(role + ".phase_dds_deg", 0.0); - tx_attenuation_db_ = configuration->property(role + ".tx_attenuation_db", 0.0); + tx_attenuation_db_ = configuration->property(role + ".tx_attenuation_db", default_tx_attenuation_db); + tx_bandwidth_ = configuration->property(role + ".tx_bandwidth", 500000); // turn switch to A/D position std::string default_device_name = "/dev/uio1"; std::string device_name = configuration->property(role + ".devicename", default_device_name); switch_position = configuration->property(role + ".switch_position", 0); + if (switch_position != 0 && switch_position != 2) + { + std::cout << "SignalSource.switch_position configuration parameter must be either 0: read from file(s) via DMA, or 2: read from AD9361" << std::endl; + std::cout << "SignalSource.switch_position configuration parameter set to its default value switch_position=0 - read from file(s)" << std::endl; + switch_position = 0; + } + switch_fpga = std::make_shared(device_name); switch_fpga->set_switch_position(switch_position); @@ -348,8 +362,9 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(ConfigurationInterface *configura std::cout << "Configuration parameter rf_port_select should take one of these values:" << std::endl; std::cout << " A_BALANCED, B_BALANCED, A_N, B_N, B_P, C_N, C_P, TX_MONITOR1, TX_MONITOR2, TX_MONITOR1_2" << std::endl; std::cout << "Error: provided value rf_port_select=" << rf_port_select_ << " is not among valid values" << std::endl; - std::cout << " This parameter has been set to its default value rf_port_select=A_BALANCED" << std::endl; - rf_port_select_ = std::string("A_BALANCED"); + std::cout << " This parameter has been set to its default value rf_port_select=" << default_rf_port_select << std::endl; + rf_port_select_ = default_rf_port_select; + LOG(WARNING) << "Invalid configuration value for rf_port_select parameter. Set to rf_port_select=" << default_rf_port_select; } if ((gain_mode_rx1_ != "manual") and (gain_mode_rx1_ != "slow_attack") and (gain_mode_rx1_ != "fast_attack") and (gain_mode_rx1_ != "hybrid")) @@ -357,8 +372,9 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(ConfigurationInterface *configura std::cout << "Configuration parameter gain_mode_rx1 should take one of these values:" << std::endl; std::cout << " manual, slow_attack, fast_attack, hybrid" << std::endl; std::cout << "Error: provided value gain_mode_rx1=" << gain_mode_rx1_ << " is not among valid values" << std::endl; - std::cout << " This parameter has been set to its default value gain_mode_rx1=manual" << std::endl; - gain_mode_rx1_ = std::string("manual"); + std::cout << " This parameter has been set to its default value gain_mode_rx1=" << default_gain_mode << std::endl; + gain_mode_rx1_ = default_gain_mode; + LOG(WARNING) << "Invalid configuration value for gain_mode_rx1 parameter. Set to gain_mode_rx1=" << default_gain_mode; } if ((gain_mode_rx2_ != "manual") and (gain_mode_rx2_ != "slow_attack") and (gain_mode_rx2_ != "fast_attack") and (gain_mode_rx2_ != "hybrid")) @@ -366,27 +382,74 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(ConfigurationInterface *configura std::cout << "Configuration parameter gain_mode_rx2 should take one of these values:" << std::endl; std::cout << " manual, slow_attack, fast_attack, hybrid" << std::endl; std::cout << "Error: provided value gain_mode_rx2=" << gain_mode_rx2_ << " is not among valid values" << std::endl; - std::cout << " This parameter has been set to its default value gain_mode_rx2=manual" << std::endl; - gain_mode_rx2_ = std::string("manual"); + std::cout << " This parameter has been set to its default value gain_mode_rx2=" << default_gain_mode << std::endl; + gain_mode_rx2_ = default_gain_mode; + LOG(WARNING) << "Invalid configuration value for gain_mode_rx2 parameter. Set to gain_mode_rx2=" << default_gain_mode; + } + + if (gain_mode_rx1_ == "manual") + { + if (rf_gain_rx1_ > 73.0 or rf_gain_rx1_ < -1.0) + { + std::cout << "Configuration parameter rf_gain_rx1 should take values between -1.0 and 73 dB" << std::endl; + std::cout << "Error: provided value rf_gain_rx1=" << rf_gain_rx1_ << " is not among valid values" << std::endl; + std::cout << " This parameter has been set to its default value rf_gain_rx1=" << default_manual_gain_rx1 << std::endl; + rf_gain_rx1_ = default_manual_gain_rx1; + LOG(WARNING) << "Invalid configuration value for rf_gain_rx1 parameter. Set to rf_gain_rx1=" << default_manual_gain_rx1; + } + } + + if (gain_mode_rx2_ == "manual") + { + if (rf_gain_rx2_ > 73.0 or rf_gain_rx2_ < -1.0) + { + std::cout << "Configuration parameter rf_gain_rx2 should take values between -1.0 and 73 dB" << std::endl; + std::cout << "Error: provided value rf_gain_rx2=" << rf_gain_rx2_ << " is not among valid values" << std::endl; + std::cout << " This parameter has been set to its default value rf_gain_rx2=" << default_manual_gain_rx2 << std::endl; + rf_gain_rx2_ = default_manual_gain_rx2; + LOG(WARNING) << "Invalid configuration value for rf_gain_rx2 parameter. Set to rf_gain_rx2=" << default_manual_gain_rx2; + } } std::cout << "LO frequency : " << freq_ << " Hz" << std::endl; - config_ad9361_rx_local(bandwidth_, - sample_rate_, - freq_, - rf_port_select_, - gain_mode_rx1_, - gain_mode_rx2_, - rf_gain_rx1_, - rf_gain_rx2_, - quadrature_, - rf_dc_, - bb_dc_); - + try + { + config_ad9361_rx_local(bandwidth_, + sample_rate_, + freq_, + rf_port_select_, + gain_mode_rx1_, + gain_mode_rx2_, + rf_gain_rx1_, + rf_gain_rx2_, + quadrature_, + rf_dc_, + bb_dc_); + } + catch (const std::runtime_error &e) + { + std::cout << "Exception cached when configuring the RX chain: " << e.what() << std::endl; + } // LOCAL OSCILLATOR DDS GENERATOR FOR DUAL FREQUENCY OPERATION if (enable_dds_lo_ == true) { - config_ad9361_lo_local(bandwidth_, + if (tx_bandwidth_ < static_cast(std::floor(static_cast(freq_rf_tx_hz_) * 1.1))) + { + std::cout << "Configuration parameter tx_bandwidth should be higher than " << static_cast(freq_rf_tx_hz_) * 1.1 << " Hz" << std::endl; + std::cout << "Error: provided value tx_bandwidth=" << tx_bandwidth_ << " is lower than the minimum allowed value" << std::endl; + std::cout << " This parameter has been set to its default value tx_bandwidth=500000" << std::endl; + tx_bandwidth_ = 500000; + LOG(WARNING) << "Invalid configuration value for tx_bandwidth parameter. Set to tx_bandwidth=500000"; + } + if (tx_attenuation_db_ > 0.0 or tx_attenuation_db_ < -89.75) + { + std::cout << "Configuration parameter tx_attenuation_db should take values between 0.0 and -89.95 in 0.25 dB steps" << std::endl; + std::cout << "Error: provided value tx_attenuation_db=" << tx_attenuation_db_ << " is not among valid values" << std::endl; + std::cout << " This parameter has been set to its default value tx_attenuation_db=" << default_tx_attenuation_db << std::endl; + tx_attenuation_db_ = default_tx_attenuation_db; + LOG(WARNING) << "Invalid configuration value for tx_attenuation_db parameter. Set to tx_attenuation_db=" << default_tx_attenuation_db; + } + config_ad9361_lo_local(tx_bandwidth_, sample_rate_, freq_rf_tx_hz_, tx_attenuation_db_, @@ -394,10 +457,7 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(ConfigurationInterface *configura scale_dds_dbfs_); } } - if (switch_position != 0 && switch_position != 2) - { - std::cout << "SignalSource.switch_position configuration parameter must be either 0: read from file(s) via DMA, or 2: read from AD9361" << std::endl; - } + if (in_stream_ > 0) { LOG(ERROR) << "A signal source does not have an input stream"; diff --git a/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.h b/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.h index dd807308d..8e26c4bb3 100644 --- a/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.h +++ b/src/algorithms/signal_source/adapters/ad9361_fpga_signal_source.h @@ -101,6 +101,7 @@ private: bool enable_dds_lo_; uint64_t freq_rf_tx_hz_; uint64_t freq_dds_tx_hz_; + uint64_t tx_bandwidth_; double scale_dds_dbfs_; double phase_dds_deg_; double tx_attenuation_db_; @@ -109,7 +110,7 @@ private: uint32_t out_stream_; size_t item_size_; - long samples_; + int64_t samples_; std::shared_ptr> queue_; diff --git a/src/algorithms/signal_source/adapters/fmcomms2_signal_source.cc b/src/algorithms/signal_source/adapters/fmcomms2_signal_source.cc index 3a83bfe31..c62acb083 100644 --- a/src/algorithms/signal_source/adapters/fmcomms2_signal_source.cc +++ b/src/algorithms/signal_source/adapters/fmcomms2_signal_source.cc @@ -47,6 +47,8 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration { std::string default_item_type = "gr_complex"; std::string default_dump_file = "./data/signal_source.dat"; + std::string default_gain_mode("slow attack"); + double default_tx_attenuation_db = -10.0; uri_ = configuration->property(role + ".device_address", std::string("192.168.2.1")); freq_ = configuration->property(role + ".freq", GPS_L1_FREQ_HZ); sample_rate_ = configuration->property(role + ".sampling_frequency", 2600000); @@ -58,8 +60,8 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration rf_dc_ = configuration->property(role + ".rf_dc", true); bb_dc_ = configuration->property(role + ".bb_dc", true); RF_channels_ = configuration->property(role + ".RF_channels", 1); - gain_mode_rx1_ = configuration->property(role + ".gain_mode_rx1", std::string("manual")); - gain_mode_rx2_ = configuration->property(role + ".gain_mode_rx2", std::string("manual")); + gain_mode_rx1_ = configuration->property(role + ".gain_mode_rx1", default_gain_mode); + gain_mode_rx2_ = configuration->property(role + ".gain_mode_rx2", default_gain_mode); rf_gain_rx1_ = configuration->property(role + ".gain_rx1", 64.0); rf_gain_rx2_ = configuration->property(role + ".gain_rx2", 64.0); rf_port_select_ = configuration->property(role + ".rf_port_select", std::string("A_BALANCED")); @@ -68,7 +70,7 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration filter_filename_ = configuration->property(role + ".filter_filename", std::string("")); Fpass_ = configuration->property(role + ".Fpass", 0.0); Fstop_ = configuration->property(role + ".Fstop", 0.0); - filter_auto_ = configuration->property(role + ".filter_auto", true); + filter_auto_ = configuration->property(role + ".filter_auto", false); item_type_ = configuration->property(role + ".item_type", default_item_type); samples_ = configuration->property(role + ".samples", 0); dump_ = configuration->property(role + ".dump", false); @@ -80,7 +82,8 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration freq_dds_tx_hz_ = configuration->property(role + ".freq_dds_tx_hz", 1000); scale_dds_dbfs_ = configuration->property(role + ".scale_dds_dbfs", 0.0); phase_dds_deg_ = configuration->property(role + ".phase_dds_deg", 0.0); - tx_attenuation_db_ = configuration->property(role + ".tx_attenuation_db", 0.0); + tx_attenuation_db_ = configuration->property(role + ".tx_attenuation_db", default_tx_attenuation_db); + tx_bandwidth_ = configuration->property(role + ".tx_bandwidth", 500000); item_size_ = sizeof(gr_complex); @@ -92,6 +95,7 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration std::cout << "Error: provided value rf_port_select=" << rf_port_select_ << " is not among valid values" << std::endl; std::cout << " This parameter has been set to its default value rf_port_select=A_BALANCED" << std::endl; rf_port_select_ = std::string("A_BALANCED"); + LOG(WARNING) << "Invalid configuration value for rf_port_select parameter. Set to rf_port_select=A_BALANCED"; } if ((gain_mode_rx1_ != "manual") and (gain_mode_rx1_ != "slow_attack") and (gain_mode_rx1_ != "fast_attack") and (gain_mode_rx1_ != "hybrid")) @@ -99,8 +103,9 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration std::cout << "Configuration parameter gain_mode_rx1 should take one of these values:" << std::endl; std::cout << " manual, slow_attack, fast_attack, hybrid" << std::endl; std::cout << "Error: provided value gain_mode_rx1=" << gain_mode_rx1_ << " is not among valid values" << std::endl; - std::cout << " This parameter has been set to its default value gain_mode_rx1=manual" << std::endl; - gain_mode_rx1_ = std::string("manual"); + std::cout << " This parameter has been set to its default value gain_mode_rx1=" << default_gain_mode << std::endl; + gain_mode_rx1_ = default_gain_mode; + LOG(WARNING) << "Invalid configuration value for gain_mode_rx1 parameter. Set to gain_mode_rx1=" << default_gain_mode; } if ((gain_mode_rx2_ != "manual") and (gain_mode_rx2_ != "slow_attack") and (gain_mode_rx2_ != "fast_attack") and (gain_mode_rx2_ != "hybrid")) @@ -108,10 +113,15 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration std::cout << "Configuration parameter gain_mode_rx2 should take one of these values:" << std::endl; std::cout << " manual, slow_attack, fast_attack, hybrid" << std::endl; std::cout << "Error: provided value gain_mode_rx2=" << gain_mode_rx2_ << " is not among valid values" << std::endl; - std::cout << " This parameter has been set to its default value gain_mode_rx2=manual" << std::endl; - gain_mode_rx2_ = std::string("manual"); + std::cout << " This parameter has been set to its default value gain_mode_rx2=" << default_gain_mode << std::endl; + gain_mode_rx2_ = default_gain_mode; + LOG(WARNING) << "Invalid configuration value for gain_mode_rx1 parameter. Set to gain_mode_rx2=" << default_gain_mode; } + if (filter_auto_) + { + filter_source_ = std::string("Auto"); + } if ((filter_source_ != "Off") and (filter_source_ != "Auto") and (filter_source_ != "File") and (filter_source_ != "Design")) { std::cout << "Configuration parameter filter_source should take one of these values:" << std::endl; @@ -122,6 +132,31 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration std::cout << "Error: provided value filter_source=" << filter_source_ << " is not among valid values" << std::endl; std::cout << " This parameter has been set to its default value filter_source=Off" << std::endl; filter_source_ = std::string("Off"); + LOG(WARNING) << "Invalid configuration value for filter_source parameter. Set to filter_source=Off"; + } + + if (gain_mode_rx1_ == "manual") + { + if (rf_gain_rx1_ > 73.0 or rf_gain_rx1_ < -1.0) + { + std::cout << "Configuration parameter rf_gain_rx1 should take values between -1.0 and 73 dB" << std::endl; + std::cout << "Error: provided value rf_gain_rx1=" << rf_gain_rx1_ << " is not among valid values" << std::endl; + std::cout << " This parameter has been set to its default value rf_gain_rx1=64.0" << std::endl; + rf_gain_rx1_ = 64.0; + LOG(WARNING) << "Invalid configuration value for rf_gain_rx1 parameter. Set to rf_gain_rx1=64.0"; + } + } + + if (gain_mode_rx2_ == "manual") + { + if (rf_gain_rx2_ > 73.0 or rf_gain_rx2_ < -1.0) + { + std::cout << "Configuration parameter rf_gain_rx2 should take values between -1.0 and 73 dB" << std::endl; + std::cout << "Error: provided value rf_gain_rx2=" << rf_gain_rx2_ << " is not among valid values" << std::endl; + std::cout << " This parameter has been set to its default value rf_gain_rx2=64.0" << std::endl; + rf_gain_rx2_ = 64.0; + LOG(WARNING) << "Invalid configuration value for rf_gain_rx2 parameter. Set to rf_gain_rx2=64.0"; + } } std::cout << "device address: " << uri_ << std::endl; @@ -162,14 +197,37 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration // configure LO if (enable_dds_lo_ == true) { + if (tx_bandwidth_ < static_cast(freq_rf_tx_hz_) * 1.1) + { + std::cout << "Configuration parameter tx_bandwidth should be higher than " << static_cast(freq_rf_tx_hz_) * 1.1 << " Hz" << std::endl; + std::cout << "Error: provided value tx_bandwidth=" << tx_bandwidth_ << " is lower than the minimum allowed value" << std::endl; + std::cout << " This parameter has been set to its default value tx_bandwidth=500000" << std::endl; + tx_bandwidth_ = 500000; + LOG(WARNING) << "Invalid configuration value for tx_bandwidth parameter. Set to tx_bandwidth=500000"; + } + if (tx_attenuation_db_ > 0.0 or tx_attenuation_db_ < -89.75) + { + std::cout << "Configuration parameter tx_attenuation_db should take values between 0.0 and -89.95 in 0.25 dB steps" << std::endl; + std::cout << "Error: provided value tx_attenuation_db=" << tx_attenuation_db_ << " is not among valid values" << std::endl; + std::cout << " This parameter has been set to its default value tx_attenuation_db=" << default_tx_attenuation_db << std::endl; + tx_attenuation_db_ = default_tx_attenuation_db; + LOG(WARNING) << "Invalid configuration value for tx_attenuation_db parameter. Set to tx_attenuation_db=" << default_tx_attenuation_db; + } std::cout << "Enabling Local Oscillator generator in FMCOMMS2\n"; - config_ad9361_lo_remote(uri_, - bandwidth_, - sample_rate_, - freq_rf_tx_hz_, - tx_attenuation_db_, - freq_dds_tx_hz_, - scale_dds_dbfs_); + try + { + config_ad9361_lo_remote(uri_, + tx_bandwidth_, + sample_rate_, + freq_rf_tx_hz_, + tx_attenuation_db_, + freq_dds_tx_hz_, + scale_dds_dbfs_); + } + catch (const std::runtime_error& e) + { + std::cout << "Exception cached when configuring the TX carrier: " << e.what() << std::endl; + } } } } @@ -205,14 +263,37 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration // configure LO if (enable_dds_lo_ == true) { + if (tx_bandwidth_ < static_cast(std::floor(static_cast(freq_rf_tx_hz_) * 1.1))) + { + std::cout << "Configuration parameter tx_bandwidth should be higher than " << static_cast(freq_rf_tx_hz_) * 1.1 << " Hz" << std::endl; + std::cout << "Error: provided value tx_bandwidth=" << tx_bandwidth_ << " is lower than the minimum allowed value" << std::endl; + std::cout << " This parameter has been set to its default value tx_bandwidth=500000" << std::endl; + tx_bandwidth_ = 500000; + LOG(WARNING) << "Invalid configuration value for tx_bandwidth parameter. Set to tx_bandwidth=500000"; + } + if (tx_attenuation_db_ > 0.0 or tx_attenuation_db_ < -89.75) + { + std::cout << "Configuration parameter tx_attenuation_db should take values between 0.0 and -89.95 in 0.25 dB steps" << std::endl; + std::cout << "Error: provided value tx_attenuation_db=" << tx_attenuation_db_ << " is not among valid values" << std::endl; + std::cout << " This parameter has been set to its default value tx_attenuation_db=" << default_tx_attenuation_db << std::endl; + tx_attenuation_db_ = default_tx_attenuation_db; + LOG(WARNING) << "Invalid configuration value for tx_attenuation_db parameter. Set to tx_attenuation_db=" << default_tx_attenuation_db; + } std::cout << "Enabling Local Oscillator generator in FMCOMMS2\n"; - config_ad9361_lo_remote(uri_, - bandwidth_, - sample_rate_, - freq_rf_tx_hz_, - tx_attenuation_db_, - freq_dds_tx_hz_, - scale_dds_dbfs_); + try + { + config_ad9361_lo_remote(uri_, + tx_bandwidth_, + sample_rate_, + freq_rf_tx_hz_, + tx_attenuation_db_, + freq_dds_tx_hz_, + scale_dds_dbfs_); + } + catch (const std::runtime_error& e) + { + std::cout << "Exception cached when configuring the TX carrier: " << e.what() << std::endl; + } } } } diff --git a/src/algorithms/signal_source/adapters/fmcomms2_signal_source.h b/src/algorithms/signal_source/adapters/fmcomms2_signal_source.h index b4d2c19f7..cc08bfc47 100644 --- a/src/algorithms/signal_source/adapters/fmcomms2_signal_source.h +++ b/src/algorithms/signal_source/adapters/fmcomms2_signal_source.h @@ -43,6 +43,7 @@ #endif #include "concurrent_queue.h" #include +#include #include #include @@ -84,11 +85,11 @@ private: std::string role_; // Front-end settings - std::string uri_; // device direction - unsigned long freq_; // frequency of local oscilator - unsigned long sample_rate_; - unsigned long bandwidth_; - unsigned long buffer_size_; // reception buffer + std::string uri_; // device direction + uint64_t freq_; // frequency of local oscilator + uint64_t sample_rate_; + uint64_t bandwidth_; + uint64_t buffer_size_; // reception buffer bool rx1_en_; bool rx2_en_; bool quadrature_; @@ -109,18 +110,19 @@ private: // DDS configuration for LO generation for external mixer bool enable_dds_lo_; - unsigned long freq_rf_tx_hz_; - unsigned long freq_dds_tx_hz_; + uint64_t freq_rf_tx_hz_; + uint64_t freq_dds_tx_hz_; double scale_dds_dbfs_; double phase_dds_deg_; double tx_attenuation_db_; + uint64_t tx_bandwidth_; unsigned int in_stream_; unsigned int out_stream_; std::string item_type_; size_t item_size_; - long samples_; + int64_t samples_; bool dump_; std::string dump_filename_; diff --git a/src/algorithms/signal_source/adapters/plutosdr_signal_source.cc b/src/algorithms/signal_source/adapters/plutosdr_signal_source.cc index c3bcf4619..b4fcac2ba 100644 --- a/src/algorithms/signal_source/adapters/plutosdr_signal_source.cc +++ b/src/algorithms/signal_source/adapters/plutosdr_signal_source.cc @@ -43,6 +43,7 @@ PlutosdrSignalSource::PlutosdrSignalSource(ConfigurationInterface* configuration { std::string default_item_type = "gr_complex"; std::string default_dump_file = "./data/signal_source.dat"; + std::string default_gain_mode("slow attack"); uri_ = configuration->property(role + ".device_address", std::string("192.168.2.1")); freq_ = configuration->property(role + ".freq", GPS_L1_FREQ_HZ); sample_rate_ = configuration->property(role + ".sampling_frequency", 3000000); @@ -51,12 +52,12 @@ PlutosdrSignalSource::PlutosdrSignalSource(ConfigurationInterface* configuration quadrature_ = configuration->property(role + ".quadrature", true); rf_dc_ = configuration->property(role + ".rf_dc", true); bb_dc_ = configuration->property(role + ".bb_dc", true); - gain_mode_ = configuration->property(role + ".gain_mode", std::string("manual")); + gain_mode_ = configuration->property(role + ".gain_mode", default_gain_mode); rf_gain_ = configuration->property(role + ".gain", 50.0); filter_file_ = configuration->property(role + ".filter_file", std::string("")); - filter_auto_ = configuration->property(role + ".filter_auto", true); + filter_auto_ = configuration->property(role + ".filter_auto", false); filter_source_ = configuration->property(role + ".filter_source", std::string("Off")); - filter_filename_ = configuration->property(role + ".filter_filename", std::string("")); + filter_filename_ = configuration->property(role + ".filter_filename", filter_file_); Fpass_ = configuration->property(role + ".Fpass", 0.0); Fstop_ = configuration->property(role + ".Fstop", 0.0); item_type_ = configuration->property(role + ".item_type", default_item_type); @@ -64,6 +65,11 @@ PlutosdrSignalSource::PlutosdrSignalSource(ConfigurationInterface* configuration dump_ = configuration->property(role + ".dump", false); dump_filename_ = configuration->property(role + ".dump_filename", default_dump_file); + if (filter_auto_) + { + filter_source_ = std::string("Auto"); + } + if (item_type_ != "gr_complex") { std::cout << "Configuration error: item_type must be gr_complex" << std::endl; @@ -73,11 +79,37 @@ PlutosdrSignalSource::PlutosdrSignalSource(ConfigurationInterface* configuration // basic check if ((gain_mode_ != "manual") and (gain_mode_ != "slow_attack") and (gain_mode_ != "fast_attack") and (gain_mode_ != "hybrid")) { - std::cout << "Configuration parameter gain_mode_rx1 should take one of these values:" << std::endl; + std::cout << "Configuration parameter gain_mode should take one of these values:" << std::endl; std::cout << " manual, slow_attack, fast_attack, hybrid" << std::endl; std::cout << "Error: provided value gain_mode=" << gain_mode_ << " is not among valid values" << std::endl; - std::cout << " This parameter has been set to its default value gain_mode=manual" << std::endl; - gain_mode_ = std::string("manual"); + std::cout << " This parameter has been set to its default value gain_mode=" << default_gain_mode << std::endl; + gain_mode_ = default_gain_mode; + LOG(WARNING) << "Invalid configuration value for gain_mode parameter. Set to gain_mode=" << default_gain_mode; + } + + if (gain_mode_ == "manual") + { + if (rf_gain_ > 73.0 or rf_gain_ < -1.0) + { + std::cout << "Configuration parameter rf_gain should take values between -1.0 and 73 dB" << std::endl; + std::cout << "Error: provided value rf_gain=" << rf_gain_ << " is not among valid values" << std::endl; + std::cout << " This parameter has been set to its default value rf_gain=64.0" << std::endl; + rf_gain_ = 64.0; + LOG(WARNING) << "Invalid configuration value for rf_gain parameter. Set to rf_gain=64.0"; + } + } + + if ((filter_source_ != "Off") and (filter_source_ != "Auto") and (filter_source_ != "File") and (filter_source_ != "Design")) + { + std::cout << "Configuration parameter filter_source should take one of these values:" << std::endl; + std::cout << " Off: Disable filter" << std::endl; + std::cout << " Auto: Use auto-generated filters" << std::endl; + std::cout << " File: User-provided filter in filter_filename parameter" << std::endl; + std::cout << " Design: Create filter from Fpass, Fstop, sampling_frequency and bandwidth parameters" << std::endl; + std::cout << "Error: provided value filter_source=" << filter_source_ << " is not among valid values" << std::endl; + std::cout << " This parameter has been set to its default value filter_source=Off" << std::endl; + filter_source_ = std::string("Off"); + LOG(WARNING) << "Invalid configuration value for filter_source parameter. Set to filter_source=Off"; } item_size_ = sizeof(gr_complex); diff --git a/src/algorithms/signal_source/adapters/plutosdr_signal_source.h b/src/algorithms/signal_source/adapters/plutosdr_signal_source.h index 7c0f6a89d..4ee083ca4 100644 --- a/src/algorithms/signal_source/adapters/plutosdr_signal_source.h +++ b/src/algorithms/signal_source/adapters/plutosdr_signal_source.h @@ -42,6 +42,7 @@ #endif #include "concurrent_queue.h" #include +#include #include #include @@ -85,11 +86,11 @@ private: std::string role_; // Front-end settings - std::string uri_; // device direction - unsigned long freq_; // frequency of local oscilator - unsigned long sample_rate_; - unsigned long bandwidth_; - unsigned long buffer_size_; // reception buffer + std::string uri_; // device direction + uint64_t freq_; // frequency of local oscilator + uint64_t sample_rate_; + uint64_t bandwidth_; + uint64_t buffer_size_; // reception buffer bool quadrature_; bool rf_dc_; bool bb_dc_; @@ -107,7 +108,7 @@ private: std::string item_type_; size_t item_size_; - long samples_; + int64_t samples_; bool dump_; std::string dump_filename_; diff --git a/src/algorithms/signal_source/libs/ad9361_manager.cc b/src/algorithms/signal_source/libs/ad9361_manager.cc index 7a81e6617..e778865ea 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.cc +++ b/src/algorithms/signal_source/libs/ad9361_manager.cc @@ -490,10 +490,16 @@ bool config_ad9361_lo_local(uint64_t bandwidth_, ad9361_phy = iio_context_find_device(ctx, "ad9361-phy"); int ret; // set output amplifier attenuation - ret = iio_device_attr_write_double(ad9361_phy, "out_voltage0_hardwaregain", -tx_attenuation_db_); + ret = iio_device_attr_write_double(ad9361_phy, "out_voltage0_hardwaregain", -std::abs(tx_attenuation_db_)); if (ret < 0) { - std::cout << "Failed to set out_voltage0_hardwaregain value " << -tx_attenuation_db_ << " error " << ret << std::endl; + std::cout << "Failed to set out_voltage0_hardwaregain value " << -std::abs(tx_attenuation_db_) << ". Error " << ret << std::endl; + } + // shut down signal in TX2 + ret = iio_device_attr_write_double(ad9361_phy, "out_voltage1_hardwaregain", -89.75); + if (ret < 0) + { + std::cout << "Failed to set out_voltage1_hardwaregain value -89.75 dB. Error " << ret << std::endl; } struct iio_device *dds; @@ -625,12 +631,18 @@ bool config_ad9361_lo_remote(const std::string &remote_host, ad9361_phy = iio_context_find_device(ctx, "ad9361-phy"); int ret; // set output amplifier attenuation - ret = iio_device_attr_write_double(ad9361_phy, "out_voltage0_hardwaregain", -tx_attenuation_db_); + ret = iio_device_attr_write_double(ad9361_phy, "out_voltage0_hardwaregain", -std::abs(tx_attenuation_db_)); if (ret < 0) { - std::cout << "Failed to set out_voltage0_hardwaregain value " << -tx_attenuation_db_ << " error " << ret << std::endl; + std::cout << "Failed to set out_voltage0_hardwaregain value " << -std::abs(tx_attenuation_db_) << ". Error " << ret << std::endl; } + // shut down signal in TX2 + ret = iio_device_attr_write_double(ad9361_phy, "out_voltage1_hardwaregain", -89.75); + if (ret < 0) + { + std::cout << "Failed to set out_voltage1_hardwaregain value -89.75 dB. Error " << ret << std::endl; + } struct iio_device *dds; dds = iio_context_find_device(ctx, "cf-ad9361-dds-core-lpc"); struct iio_channel *dds_channel0_I;