From cb99011de8e22404c792724bbe3ab336bc4eb175 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Thu, 10 Oct 2019 08:12:25 +0200 Subject: [PATCH] Fix building --- .../signal_source/adapters/CMakeLists.txt | 7 +- .../adapters/fmcomms2_signal_source.cc | 196 +++++++++++++++++- .../adapters/fmcomms2_signal_source.h | 10 + 3 files changed, 204 insertions(+), 9 deletions(-) diff --git a/src/algorithms/signal_source/adapters/CMakeLists.txt b/src/algorithms/signal_source/adapters/CMakeLists.txt index bd0fa201a..63f74d68d 100644 --- a/src/algorithms/signal_source/adapters/CMakeLists.txt +++ b/src/algorithms/signal_source/adapters/CMakeLists.txt @@ -57,7 +57,7 @@ if(ENABLE_GN3S) # GN3S (USB dongle) ############################################## if(NOT GRGN3S_FOUND) - message(" gr-gn3s not found, install it from https://github.com/gnss-sdr/gr-gn3s ") + message(" gr-gn3s not found, install it from https://github.com/gnss-sdr/gr-gn3s") message(FATAL_ERROR "gr-gn3s required for building gnss-sdr with this option enabled") endif() set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} gn3s_signal_source.cc) @@ -76,7 +76,7 @@ if(ENABLE_ARRAY) # DBFCTTC GNSS EXPERIMENTAL ARRAY PROTOTYPE ############################################## if(NOT GRDBFCTTC_FOUND) - message(" gr-dbfcttc not found, install it from https://github.com/gnss-sdr/gr-dbfcttc ") + message(" gr-dbfcttc not found, install it from https://github.com/gnss-sdr/gr-dbfcttc") message(FATAL_ERROR "gr-dbfcttc required for building gnss-sdr with this option enabled") endif() set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} raw_array_signal_source.cc) @@ -220,7 +220,6 @@ if(ENABLE_ARRAY AND GRDBFCTTC_FOUND) ) endif() - if(ENABLE_PLUTOSDR OR ENABLE_FMCOMMS2) if(GR_IIO_INCLUDE_HAS_GNURADIO) target_compile_definitions(signal_source_adapters @@ -236,6 +235,8 @@ if(ENABLE_PLUTOSDR OR ENABLE_FMCOMMS2) PUBLIC Gnuradio::iio Boost::chrono + PRIVATE + Iio::iio ) endif() diff --git a/src/algorithms/signal_source/adapters/fmcomms2_signal_source.cc b/src/algorithms/signal_source/adapters/fmcomms2_signal_source.cc index e251d5a26..f5d00c917 100644 --- a/src/algorithms/signal_source/adapters/fmcomms2_signal_source.cc +++ b/src/algorithms/signal_source/adapters/fmcomms2_signal_source.cc @@ -32,18 +32,18 @@ #include "fmcomms2_signal_source.h" #include "GPS_L1_CA.h" #include "GPS_L2C.h" -#include "ad9361_manager.h" #include "configuration_interface.h" #include "gnss_sdr_valve.h" #include +#include #include // for max #include #include #include -Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration, - const std::string& role, unsigned int in_stream, unsigned int out_stream, +Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface *configuration, + 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_item_type = "gr_complex"; @@ -241,7 +241,7 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration scale_dds_dbfs_, phase_dds_deg_); } - catch (const std::runtime_error& e) + catch (const std::runtime_error &e) { std::cout << "Exception cached when configuring the TX carrier: " << e.what() << std::endl; } @@ -308,7 +308,7 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration scale_dds_dbfs_, phase_dds_deg_); } - catch (const std::runtime_error& e) + catch (const std::runtime_error &e) { std::cout << "Exception cached when configuring the TX carrier: " << e.what() << std::endl; } @@ -341,6 +341,190 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration } +bool Fmcomms2SignalSource::config_ad9361_lo_remote(const std::string &remote_host, + uint64_t bandwidth_, + uint64_t sample_rate_, + uint64_t freq_rf_tx_hz_, + double tx_attenuation_db_, + int64_t freq_dds_tx_hz_, + double scale_dds_dbfs_, + double phase_dds_deg_) +{ + // TX stream config + std::cout << "Start of AD9361 TX Local Oscillator DDS configuration\n"; + struct stream_cfg txcfg; + txcfg.bw_hz = bandwidth_; + txcfg.fs_hz = sample_rate_; + txcfg.lo_hz = freq_rf_tx_hz_; + txcfg.rfport = "A"; + + std::cout << "AD9361 Acquiring IIO REMOTE context in host " << remote_host << std::endl; + struct iio_context *ctx; + ctx = iio_create_network_context(remote_host.c_str()); + if (!ctx) + { + std::cout << "No context\n"; + throw std::runtime_error("AD9361 IIO No context"); + } + + // find tx device + struct iio_device *tx; + + std::cout << "* Acquiring AD9361 TX streaming devices\n"; + + if (!get_ad9361_stream_dev(ctx, TX, &tx)) + { + std::cout << "No tx dev found\n"; + throw std::runtime_error("AD9361 IIO No tx dev found"); + }; + + std::cout << "* Configuring AD9361 for streaming TX\n"; + if (!cfg_ad9361_streaming_ch(ctx, &txcfg, TX, 0)) + { + std::cout << "TX port 0 not found\n"; + throw std::runtime_error("AD9361 IIO TX port 0 not found"); + } + + // ENABLE DDS on TX1 + struct iio_device *ad9361_phy; + 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", -std::abs(tx_attenuation_db_)); + if (ret < 0) + { + 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; + dds_channel0_I = iio_device_find_channel(dds, "TX1_I_F1", true); + + struct iio_channel *dds_channel0_Q; + dds_channel0_Q = iio_device_find_channel(dds, "TX1_Q_F1", true); + + ret = iio_channel_attr_write_bool(dds_channel0_I, "raw", true); + if (ret < 0) + { + std::cout << "Failed to toggle DDS: " << ret << std::endl; + } + + // set frequency, scale and phase + ret = iio_channel_attr_write_longlong(dds_channel0_I, "frequency", static_cast(freq_dds_tx_hz_)); + if (ret < 0) + { + std::cout << "Failed to set TX DDS frequency I: " << ret << std::endl; + } + + ret = iio_channel_attr_write_longlong(dds_channel0_Q, "frequency", static_cast(freq_dds_tx_hz_)); + if (ret < 0) + { + std::cout << "Failed to set TX DDS frequency Q: " << ret << std::endl; + } + + ret = iio_channel_attr_write_double(dds_channel0_I, "phase", phase_dds_deg_ * 1000.0); + if (ret < 0) + { + std::cout << "Failed to set TX DDS phase I: " << ret << std::endl; + } + + ret = iio_channel_attr_write_double(dds_channel0_Q, "phase", phase_dds_deg_ * 1000.0 + 270000.0); + if (ret < 0) + { + std::cout << "Failed to set TX DDS phase Q: " << ret << std::endl; + } + + ret = iio_channel_attr_write_double(dds_channel0_I, "scale", pow(10, scale_dds_dbfs_ / 20.0)); + if (ret < 0) + { + std::cout << "Failed to set TX DDS scale I: " << ret << std::endl; + } + + ret = iio_channel_attr_write_double(dds_channel0_Q, "scale", pow(10, scale_dds_dbfs_ / 20.0)); + if (ret < 0) + { + std::cout << "Failed to set TX DDS scale Q: " << ret << std::endl; + } + + // disable TX2 + ret = iio_device_attr_write_double(ad9361_phy, "out_voltage1_hardwaregain", -89.0); + if (ret < 0) + { + std::cout << "Failed to set out_voltage1_hardwaregain value " << -89.0 << " error " << ret << std::endl; + } + + struct iio_channel *dds_channel1_I; + dds_channel1_I = iio_device_find_channel(dds, "TX2_I_F1", true); + + struct iio_channel *dds_channel1_Q; + dds_channel1_Q = iio_device_find_channel(dds, "TX2_Q_F1", true); + + ret = iio_channel_attr_write_double(dds_channel1_I, "scale", 0); + if (ret < 0) + { + std::cout << "Failed to set TX2 DDS scale I: " << ret << std::endl; + } + + ret = iio_channel_attr_write_double(dds_channel1_Q, "scale", 0); + if (ret < 0) + { + std::cout << "Failed to set TX2 DDS scale Q: " << ret << std::endl; + } + + iio_context_destroy(ctx); + return true; +} + + +bool Fmcomms2SignalSource::ad9361_disable_lo_remote(const std::string &remote_host) +{ + std::cout << "AD9361 Acquiring IIO REMOTE context in host " << remote_host << std::endl; + struct iio_context *ctx; + ctx = iio_create_network_context(remote_host.c_str()); + if (!ctx) + { + std::cout << "No context\n"; + throw std::runtime_error("AD9361 IIO No context"); + } + struct iio_device *dds; + dds = iio_context_find_device(ctx, "cf-ad9361-dds-core-lpc"); + struct iio_channel *dds_channel0_I; + dds_channel0_I = iio_device_find_channel(dds, "TX1_I_F1", true); + + struct iio_channel *dds_channel0_Q; + dds_channel0_Q = iio_device_find_channel(dds, "TX1_Q_F1", true); + int ret; + ret = iio_channel_attr_write_bool(dds_channel0_I, "raw", false); + if (ret < 0) + { + std::cout << "Failed to toggle DDS: " << ret << std::endl; + } + + ret = iio_channel_attr_write_double(dds_channel0_I, "scale", 0.0); + if (ret < 0) + { + std::cout << "Failed to set TX DDS scale I: " << ret << std::endl; + } + + ret = iio_channel_attr_write_double(dds_channel0_Q, "scale", 0.0); + if (ret < 0) + { + std::cout << "Failed to set TX DDS scale Q: " << ret << std::endl; + } + + iio_context_destroy(ctx); + + return true; +} + + Fmcomms2SignalSource::~Fmcomms2SignalSource() { if (enable_dds_lo_ == true) @@ -349,7 +533,7 @@ Fmcomms2SignalSource::~Fmcomms2SignalSource() { ad9361_disable_lo_remote(uri_); } - catch (const std::exception& e) + catch (const std::exception &e) { LOG(WARNING) << "Exception thrown in Fmcomms2SignalSource destructor: " << e.what(); } diff --git a/src/algorithms/signal_source/adapters/fmcomms2_signal_source.h b/src/algorithms/signal_source/adapters/fmcomms2_signal_source.h index cc08bfc47..32423dadc 100644 --- a/src/algorithms/signal_source/adapters/fmcomms2_signal_source.h +++ b/src/algorithms/signal_source/adapters/fmcomms2_signal_source.h @@ -82,6 +82,16 @@ public: gr::basic_block_sptr get_right_block() override; private: + bool config_ad9361_lo_remote(const std::string &remote_host, + uint64_t bandwidth, + uint64_t sample_rate, + uint64_t freq_rf_tx_hz, + double tx_attenuation_db, + int64_t freq_dds_tx_hz, + double scale_dds_dbfs, + double phase_dds_deg); + + bool ad9361_disable_lo_remote(const std::string &remote_host); std::string role_; // Front-end settings