diff --git a/cmake/Modules/Findlibiio.cmake b/cmake/Modules/Findlibiio.cmake index a708d7062..4ce6ca9c5 100644 --- a/cmake/Modules/Findlibiio.cmake +++ b/cmake/Modules/Findlibiio.cmake @@ -5,17 +5,18 @@ FIND_PATH( LIBIIO_INCLUDE_DIRS NAMES gnuradio/iio/api.h HINTS $ENV{LIBIIO_DIR}/include - ${PC_LIBIIO_INCLUDEDIR} + ${PC_LIBIIO_INCLUDEDIR} PATHS ${CMAKE_INSTALL_PREFIX}/include /usr/local/include /usr/include + /opt/local/include ) FIND_LIBRARY( LIBIIO_LIBRARIES - NAMES libiio.so + NAMES libiio.so iio HINTS $ENV{LIBIIO_DIR}/lib - ${PC_LIBIIO_LIBDIR} + ${PC_LIBIIO_LIBDIR} PATHS ${CMAKE_INSTALL_PREFIX}/lib ${CMAKE_INSTALL_PREFIX}/lib64 /usr/local/lib @@ -23,10 +24,30 @@ FIND_LIBRARY( /usr/lib /usr/lib64 /usr/lib/x86_64-linux-gnu + /usr/lib/gcc/alpha-linux-gnu + /usr/lib/gcc/aarch64-linux-gnu + /usr/lib/gcc/arm-linux-gnueabi + /usr/lib/gcc/arm-linux-gnueabihf + /usr/lib/gcc/hppa-linux-gnu + /usr/lib/gcc/i686-gnu + /usr/lib/gcc/i686-linux-gnu + /usr/lib/gcc/x86_64-kfreebsd-gnu + /usr/lib/gcc/i686-kfreebsd-gnu + /usr/lib/gcc/m68k-linux-gnu + /usr/lib/gcc/mips-linux-gnu + /usr/lib/gcc/mips64el-linux-gnuabi64 + /usr/lib/gcc/mipsel-linux-gnu + /usr/lib/gcc/powerpc-linux-gnu + /usr/lib/gcc/powerpc-linux-gnuspe + /usr/lib/gcc/powerpc64-linux-gnu + /usr/lib/gcc/powerpc64le-linux-gnu + /usr/lib/gcc/s390x-linux-gnu + /usr/lib/gcc/sparc64-linux-gnu + /usr/lib/gcc/x86_64-linux-gnux32 + /usr/lib/gcc/sh4-linux-gnu + /Library/Frameworks/iio.framework/ ) -message("find libiio:") -message(${LIBIIO_LIBRARIES}) INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(LIBIIO DEFAULT_MSG LIBIIO_LIBRARIES LIBIIO_INCLUDE_DIRS) MARK_AS_ADVANCED(LIBIIO_LIBRARIES LIBIIO_INCLUDE_DIRS) diff --git a/src/algorithms/signal_source/adapters/fmcomms2_signal_source.cc b/src/algorithms/signal_source/adapters/fmcomms2_signal_source.cc index 0b590f722..6caf9ddee 100644 --- a/src/algorithms/signal_source/adapters/fmcomms2_signal_source.cc +++ b/src/algorithms/signal_source/adapters/fmcomms2_signal_source.cc @@ -71,13 +71,12 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration dump_filename_ = configuration->property(role + ".dump_filename", default_dump_file); //AD9361 Local Oscillator generation for dual band operation - 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", 0.0); - phase_dds_deg_=configuration->property(role + ".phase_dds_deg", 0.0); - tx_attenuation_db_=configuration->property(role + ".tx_attenuation_db", 0.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", 0.0); + phase_dds_deg_ = configuration->property(role + ".phase_dds_deg", 0.0); + tx_attenuation_db_ = configuration->property(role + ".tx_attenuation_db", 0.0); item_size_ = sizeof(gr_complex); @@ -87,72 +86,73 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration if (item_type_.compare("gr_complex") == 0) { - if (RF_channels_==1) - { - if (rx1_en_ and rx2_en_) + if (RF_channels_ == 1) { - LOG(FATAL) << "Configuration error: both rx1 and rx2 are enabled but RF_channels=1 !"; - } - else - { - fmcomms2_source_f32c_ = gr::iio::fmcomms2_source_f32c::make( - uri_.c_str(), freq_, sample_rate_, - bandwidth_, - rx1_en_, rx2_en_, - buffer_size_, quadrature_, rf_dc_, - bb_dc_, gain_mode_rx1_.c_str(), rf_gain_rx1_, - gain_mode_rx2_.c_str(), rf_gain_rx2_, - rf_port_select_.c_str(), filter_file_.c_str(), - filter_auto_); + if (rx1_en_ and rx2_en_) + { + LOG(FATAL) << "Configuration error: both rx1 and rx2 are enabled but RF_channels=1 !"; + } + else + { + fmcomms2_source_f32c_ = gr::iio::fmcomms2_source_f32c::make( + uri_.c_str(), freq_, sample_rate_, + bandwidth_, + rx1_en_, rx2_en_, + buffer_size_, quadrature_, rf_dc_, + bb_dc_, gain_mode_rx1_.c_str(), rf_gain_rx1_, + gain_mode_rx2_.c_str(), rf_gain_rx2_, + rf_port_select_.c_str(), filter_file_.c_str(), + filter_auto_); - //configure LO - if (enable_dds_lo_==true) - { - 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_); - } + //configure LO + if (enable_dds_lo_ == true) + { + 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_); + } + } } - } - else if(RF_channels_==2) - { - if (!(rx1_en_ and rx2_en_)) + else if (RF_channels_ == 2) { - LOG(FATAL) << "Configuration error: RF_channels=2 but are not enabled both receivers in FMCOMMS2 !"; + if (!(rx1_en_ and rx2_en_)) + { + LOG(FATAL) << "Configuration error: RF_channels=2 but are not enabled both receivers in FMCOMMS2 !"; + } + else + { + fmcomms2_source_f32c_ = gr::iio::fmcomms2_source_f32c::make( + uri_.c_str(), freq_, sample_rate_, + bandwidth_, + rx1_en_, rx2_en_, + buffer_size_, quadrature_, rf_dc_, + bb_dc_, gain_mode_rx1_.c_str(), rf_gain_rx1_, + gain_mode_rx2_.c_str(), rf_gain_rx2_, + rf_port_select_.c_str(), filter_file_.c_str(), + filter_auto_); + //configure LO + if (enable_dds_lo_ == true) + { + 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_); + } + } } - else + else { - fmcomms2_source_f32c_ = gr::iio::fmcomms2_source_f32c::make( - uri_.c_str(), freq_, sample_rate_, - bandwidth_, - rx1_en_, rx2_en_, - buffer_size_, quadrature_, rf_dc_, - bb_dc_, gain_mode_rx1_.c_str(), rf_gain_rx1_, - gain_mode_rx2_.c_str(), rf_gain_rx2_, - rf_port_select_.c_str(), filter_file_.c_str(), - filter_auto_); - //configure LO - if (enable_dds_lo_==true) - { - 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_); - } + LOG(FATAL) << "Configuration error: Unsupported number of RF_channels !"; } - }else{ - LOG(FATAL) << "Configuration error: Unsupported number of RF_channels !"; - } - } else { @@ -177,10 +177,10 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration Fmcomms2SignalSource::~Fmcomms2SignalSource() { - if (enable_dds_lo_==true) - { - ad9361_disable_lo_remote(uri_); - } + if (enable_dds_lo_ == true) + { + ad9361_disable_lo_remote(uri_); + } } diff --git a/src/algorithms/signal_source/libs/ad9361_manager.cc b/src/algorithms/signal_source/libs/ad9361_manager.cc index 66a95ee14..51a949eed 100644 --- a/src/algorithms/signal_source/libs/ad9361_manager.cc +++ b/src/algorithms/signal_source/libs/ad9361_manager.cc @@ -35,98 +35,116 @@ #include #include + /* check return value of attr_write function */ -void errchk(int v, const char* what) { +void errchk(int v, const char *what) +{ if (v < 0) - { - LOG(WARNING)<<"Error "<rfport); - wr_ch_lli(chn, "rf_bandwidth", cfg->bw_hz); + std::cout << "* Acquiring AD9361 phy channel" << chid << std::endl; + if (!get_phy_chan(ctx, type, chid, &chn)) + { + return false; + } + wr_ch_str(chn, "rf_port_select", cfg->rfport); + wr_ch_lli(chn, "rf_bandwidth", cfg->bw_hz); wr_ch_lli(chn, "sampling_frequency", cfg->fs_hz); // Configure LO channel //LOG(INFO)<<"* Acquiring AD9361 "<lo_hz); return true; } bool config_ad9361_rx_local(unsigned long bandwidth_, - unsigned long sample_rate_, - unsigned long freq_, - std::string rf_port_select_, - std::string gain_mode_rx1_, - std::string gain_mode_rx2_, - double rf_gain_rx1_, - double rf_gain_rx2_) + unsigned long sample_rate_, + unsigned long freq_, + std::string rf_port_select_, + std::string gain_mode_rx1_, + std::string gain_mode_rx2_, + double rf_gain_rx1_, + double rf_gain_rx2_) { // RX stream config // Stream configurations struct stream_cfg rxcfg; - rxcfg.bw_hz = bandwidth_; // 2 MHz rf bandwidth - rxcfg.fs_hz = sample_rate_; // 2.5 MS/s rx sample rate - rxcfg.lo_hz = freq_; // 2.5 GHz rf frequency - rxcfg.rfport = rf_port_select_.c_str(); // port A (select for rf freq.) + rxcfg.bw_hz = bandwidth_; // 2 MHz rf bandwidth + rxcfg.fs_hz = sample_rate_; // 2.5 MS/s rx sample rate + rxcfg.lo_hz = freq_; // 2.5 GHz rf frequency + rxcfg.rfport = rf_port_select_.c_str(); // port A (select for rf freq.) - std::cout<<"AD9361 Acquiring IIO LOCAL context\n"; + std::cout << "AD9361 Acquiring IIO LOCAL context\n"; struct iio_context *ctx; // Streaming devices struct iio_device *rx; @@ -179,106 +203,114 @@ bool config_ad9361_rx_local(unsigned long bandwidth_, ctx = iio_create_default_context(); if (!ctx) - { - std::cout<<"No context\n"; - throw std::runtime_error("AD9361 IIO No context"); - } + { + std::cout << "No context\n"; + throw std::runtime_error("AD9361 IIO No context"); + } if (iio_context_get_devices_count(ctx) <= 0) - { - std::cout<<"No devices\n"; - throw std::runtime_error("AD9361 IIO No devices"); - } + { + std::cout << "No devices\n"; + throw std::runtime_error("AD9361 IIO No devices"); + } - std::cout<<"* Acquiring AD9361 streaming devices\n"; + std::cout << "* Acquiring AD9361 streaming devices\n"; - if(!get_ad9361_stream_dev(ctx, RX, &rx)) - { - std::cout<<"No rx dev found\n"; - throw std::runtime_error("AD9361 IIO No rx dev found"); - }; + if (!get_ad9361_stream_dev(ctx, RX, &rx)) + { + std::cout << "No rx dev found\n"; + throw std::runtime_error("AD9361 IIO No rx dev found"); + }; - std::cout<<"* Configuring AD9361 for streaming\n"; + std::cout << "* Configuring AD9361 for streaming\n"; if (!cfg_ad9361_streaming_ch(ctx, &rxcfg, RX, 0)) - { - std::cout<<"RX port 0 not found\n"; - throw std::runtime_error("AD9361 IIO RX port 0 not found"); - } + { + std::cout << "RX port 0 not found\n"; + throw std::runtime_error("AD9361 IIO RX port 0 not found"); + } - std::cout<<"* Initializing AD9361 IIO streaming channels\n"; + std::cout << "* Initializing AD9361 IIO streaming channels\n"; if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx0_i)) - { - std::cout<<"RX chan i not found\n"; - throw std::runtime_error("RX chan i not found"); - } + { + std::cout << "RX chan i not found\n"; + throw std::runtime_error("RX chan i not found"); + } if (!get_ad9361_stream_ch(ctx, RX, rx, 1, &rx0_q)) - { - std::cout<<"RX chan q not found\n"; - throw std::runtime_error("RX chan q not found"); - } + { + std::cout << "RX chan q not found\n"; + throw std::runtime_error("RX chan q not found"); + } - std::cout<<"* Enabling IIO streaming channels\n"; + std::cout << "* Enabling IIO streaming channels\n"; iio_channel_enable(rx0_i); iio_channel_enable(rx0_q); struct iio_device *ad9361_phy; - ad9361_phy= iio_context_find_device(ctx, "ad9361-phy"); + ad9361_phy = iio_context_find_device(ctx, "ad9361-phy"); int ret; - ret=iio_device_attr_write(ad9361_phy,"trx_rate_governor","nominal"); - if (ret < 0) { - std::cout<<"Failed to set trx_rate_governor: "< @@ -42,31 +42,36 @@ #endif /* RX is input, TX is output */ -enum iodev { RX, TX }; +enum iodev +{ + RX, + TX +}; /* common RX and TX streaming params */ -struct stream_cfg { - long long bw_hz; // Analog banwidth in Hz - long long fs_hz; // Baseband sample rate in Hz - long long lo_hz; // Local oscillator frequency in Hz - const char* rfport; // Port name +struct stream_cfg +{ + long long bw_hz; // Analog banwidth in Hz + long long fs_hz; // Baseband sample rate in Hz + long long lo_hz; // Local oscillator frequency in Hz + const char *rfport; // Port name }; /* check return value of attr_write function */ -void errchk(int v, const char* what); +void errchk(int v, const char *what); /* write attribute: long long int */ -void wr_ch_lli(struct iio_channel *chn, const char* what, long long val); +void wr_ch_lli(struct iio_channel *chn, const char *what, long long val); /* write attribute: string */ -void wr_ch_str(struct iio_channel *chn, const char* what, const char* str); +void wr_ch_str(struct iio_channel *chn, const char *what, const char *str); /* helper function generating channel names */ -char* get_ch_name(const char* type, int id, char* tmpstr); +char *get_ch_name(const char *type, int id, char *tmpstr); /* returns ad9361 phy device */ -struct iio_device* get_ad9361_phy(struct iio_context *ctx); +struct iio_device *get_ad9361_phy(struct iio_context *ctx); /* finds AD9361 streaming IIO devices */ bool get_ad9361_stream_dev(struct iio_context *ctx, enum iodev d, struct iio_device **dev); @@ -83,45 +88,43 @@ bool get_lo_chan(struct iio_context *ctx, enum iodev d, struct iio_channel **chn /* applies streaming configuration through IIO */ bool cfg_ad9361_streaming_ch(struct iio_context *ctx, struct stream_cfg *cfg, enum iodev type, int chid); - bool config_ad9361_rx_local(unsigned long bandwidth_, - unsigned long sample_rate_, - unsigned long freq_, - std::string rf_port_select_, - std::string gain_mode_rx1_, - std::string gain_mode_rx2_, - double rf_gain_rx1_, - double rf_gain_rx2_); + unsigned long sample_rate_, + unsigned long freq_, + std::string rf_port_select_, + std::string gain_mode_rx1_, + std::string gain_mode_rx2_, + double rf_gain_rx1_, + double rf_gain_rx2_); bool config_ad9361_rx_remote(std::string remote_host, - unsigned long bandwidth_, - unsigned long sample_rate_, - unsigned long freq_, - std::string rf_port_select_, - std::string gain_mode_rx1_, - std::string gain_mode_rx2_, - double rf_gain_rx1_, - double rf_gain_rx2_); + unsigned long bandwidth_, + unsigned long sample_rate_, + unsigned long freq_, + std::string rf_port_select_, + std::string gain_mode_rx1_, + std::string gain_mode_rx2_, + double rf_gain_rx1_, + double rf_gain_rx2_); bool config_ad9361_lo_local(unsigned long bandwidth_, - unsigned long sample_rate_, - unsigned long freq_rf_tx_hz_, - double tx_attenuation_db_, - long long freq_dds_tx_hz_, - double scale_dds_dbfs_); + unsigned long sample_rate_, + unsigned long freq_rf_tx_hz_, + double tx_attenuation_db_, + long long freq_dds_tx_hz_, + double scale_dds_dbfs_); bool config_ad9361_lo_remote(std::string remote_host, - unsigned long bandwidth_, - unsigned long sample_rate_, - unsigned long freq_rf_tx_hz_, - double tx_attenuation_db_, - long long freq_dds_tx_hz_, - double scale_dds_dbfs_); + unsigned long bandwidth_, + unsigned long sample_rate_, + unsigned long freq_rf_tx_hz_, + double tx_attenuation_db_, + long long freq_dds_tx_hz_, + double scale_dds_dbfs_); bool ad9361_disable_lo_remote(std::string remote_host); bool ad9361_disable_lo_local(); - #endif