1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-14 12:10:34 +00:00

Merge branch 'fir' into next

Implement AD9361's FIR configuration options
This commit is contained in:
Carles Fernandez 2019-10-10 11:22:45 +02:00
commit bcd80c87c9
10 changed files with 591 additions and 105 deletions

View File

@ -2286,6 +2286,15 @@ else()
TYPE OPTIONAL TYPE OPTIONAL
) )
endif() endif()
find_package(LIBAD9361)
set_package_properties(LIBAD9361 PROPERTIES
PURPOSE "Used for configuring the AD9361 chipset"
TYPE OPTIONAL
)
if(NOT LIBAD9361_FOUND)
set(ENABLE_AD9361 OFF)
set(ENABLE_FMCOMMS2 OFF)
endif()
if(ENABLE_PLUTOSDR OR ENABLE_FMCOMMS2) if(ENABLE_PLUTOSDR OR ENABLE_FMCOMMS2)
if(NOT GRIIO_FOUND) if(NOT GRIIO_FOUND)
message(STATUS "gnuradio-iio not found, its installation is required.") message(STATUS "gnuradio-iio not found, its installation is required.")
@ -2566,9 +2575,9 @@ add_subdirectory(src)
################################################################################ ################################################################################
add_feature_info(ENABLE_UHD ENABLE_UHD "Enables UHD_Signal_Source for using RF front-ends from the USRP family. Requires gr-uhd.") add_feature_info(ENABLE_UHD ENABLE_UHD "Enables UHD_Signal_Source for using RF front-ends from the USRP family. Requires gr-uhd.")
add_feature_info(ENABLE_OSMOSDR ENABLE_OSMOSDR "Enables Osmosdr_Signal_Source and RtlTcp_Signal_Source for using RF front-ends compatible with the OsmoSDR driver. Requires gr-osmosdr.") add_feature_info(ENABLE_OSMOSDR ENABLE_OSMOSDR "Enables Osmosdr_Signal_Source and RtlTcp_Signal_Source for using RF front-ends compatible with the OsmoSDR driver. Requires gr-osmosdr.")
add_feature_info(ENABLE_FMCOMMS2 ENABLE_FMCOMMS2 "Enables Fmcomms2_Signal_Source for FMCOMMS2/3/4 devices. Requires gr-iio.") add_feature_info(ENABLE_FMCOMMS2 ENABLE_FMCOMMS2 "Enables Fmcomms2_Signal_Source for FMCOMMS2/3/4 devices. Requires gr-iio and libad9361-dev.")
add_feature_info(ENABLE_PLUTOSDR ENABLE_PLUTOSDR "Enables Plutosdr_Signal_Source for using ADALM-PLUTO boards. Requires gr-iio.") add_feature_info(ENABLE_PLUTOSDR ENABLE_PLUTOSDR "Enables Plutosdr_Signal_Source for using ADALM-PLUTO boards. Requires gr-iio.")
add_feature_info(ENABLE_AD9361 ENABLE_AD9361 "Enables Ad9361_Fpga_Signal_Source for devices with the AD9361 chipset. Requires libiio.") add_feature_info(ENABLE_AD9361 ENABLE_AD9361 "Enables Ad9361_Fpga_Signal_Source for devices with the AD9361 chipset. Requires libiio and libad9361-dev.")
add_feature_info(ENABLE_RAW_UDP ENABLE_RAW_UDP "Enables Custom_UDP_Signal_Source for custom UDP packet sample source. Requires libpcap.") add_feature_info(ENABLE_RAW_UDP ENABLE_RAW_UDP "Enables Custom_UDP_Signal_Source for custom UDP packet sample source. Requires libpcap.")
add_feature_info(ENABLE_FLEXIBAND ENABLE_FLEXIBAND "Enables Flexiband_Signal_Source for using Teleorbit's Flexiband RF front-end. Requires gr-teleorbit.") add_feature_info(ENABLE_FLEXIBAND ENABLE_FLEXIBAND "Enables Flexiband_Signal_Source for using Teleorbit's Flexiband RF front-end. Requires gr-teleorbit.")
add_feature_info(ENABLE_GN3S ENABLE_GN3S "Enables Gn3s_Signal_Source for using the GN3S v2 dongle. Requires gr-gn3s.") add_feature_info(ENABLE_GN3S ENABLE_GN3S "Enables Gn3s_Signal_Source for using the GN3S v2 dongle. Requires gr-gn3s.")

View File

@ -0,0 +1,124 @@
# Copyright (C) 2011-2019 (see AUTHORS file for a list of contributors)
#
# This file is part of GNSS-SDR.
#
# GNSS-SDR is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# GNSS-SDR is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
#
# Provides the following imported target:
# Iio::iio
#
if(NOT COMMAND feature_summary)
include(FeatureSummary)
endif()
set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH TRUE)
include(FindPkgConfig)
pkg_check_modules(PC_LIBAD9361 libad9361)
find_path(
LIBAD9361_INCLUDE_DIRS
NAMES ad9361.h
HINTS ${PC_LIBAD9361_INCLUDEDIR}
PATHS /usr/include
/usr/local/include
/opt/local/include
${CMAKE_INSTALL_PREFIX}/include
${LIBAD9361_ROOT}/include
$ENV{LIBAD9361_ROOT}/include
$ENV{LIBAD9361_DIR}/include
)
find_library(
LIBAD9361_LIBRARIES
NAMES ad9361
HINTS ${PC_LIBAD9361_LIBDIR}
PATHS /usr/lib
/usr/lib64
/usr/lib/x86_64-linux-gnu
/usr/lib/i386-linux-gnu
/usr/lib/alpha-linux-gnu
/usr/lib/aarch64-linux-gnu
/usr/lib/arm-linux-gnueabi
/usr/lib/arm-linux-gnueabihf
/usr/lib/hppa-linux-gnu
/usr/lib/i686-gnu
/usr/lib/i686-linux-gnu
/usr/lib/x86_64-kfreebsd-gnu
/usr/lib/i686-kfreebsd-gnu
/usr/lib/m68k-linux-gnu
/usr/lib/mips-linux-gnu
/usr/lib/mips64el-linux-gnuabi64
/usr/lib/mipsel-linux-gnu
/usr/lib/powerpc-linux-gnu
/usr/lib/powerpc-linux-gnuspe
/usr/lib/powerpc64-linux-gnu
/usr/lib/powerpc64le-linux-gnu
/usr/lib/s390x-linux-gnu
/usr/lib/sparc64-linux-gnu
/usr/lib/x86_64-linux-gnux32
/usr/lib/sh4-linux-gnu
/usr/lib/riscv64-linux-gnu
/usr/local/lib
/usr/local/lib64
/opt/local/lib
/Library/Frameworks/ad9361.framework
${CMAKE_INSTALL_PREFIX}/lib
${CMAKE_INSTALL_PREFIX}/lib64
${LIBAD9361_ROOT}/lib
$ENV{LIBAD9361_ROOT}/lib
${LIBAD9361_ROOT}/lib64
$ENV{LIBAD9361_ROOT}/lib64
$ENV{LIBAD9361_DIR}/lib
)
if(LIBAD9361_LIBRARIES AND APPLE)
if(LIBAD9361_LIBRARIES MATCHES "framework")
set(LIBAD9361_LIBRARIES ${LIBAD9361_LIBRARIES}/ad9361)
endif()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LIBAD9361 DEFAULT_MSG LIBAD9361_LIBRARIES LIBAD9361_INCLUDE_DIRS)
if(PC_LIBAD9361_VERSION)
set(LIBAD9361_VERSION ${PC_LIBAD9361_VERSION})
endif()
if(LIBAD9361_FOUND AND LIBAD9361_VERSION)
set_package_properties(LIBAD9361 PROPERTIES
DESCRIPTION "A library for interfacing with AD936X RF transceivers (found: v${LIBAD9361_VERSION})"
)
else()
set_package_properties(LIBAD9361 PROPERTIES
DESCRIPTION "A library for interfacing with AD936X RF transceivers"
)
endif()
set_package_properties(LIBAD9361 PROPERTIES
URL "https://github.com/analogdevicesinc/libad9361-iio"
)
if(LIBAD9361_FOUND AND NOT TARGET Iio::ad9361)
add_library(Iio::ad9361 SHARED IMPORTED)
set_target_properties(Iio::ad9361 PROPERTIES
IMPORTED_LINK_INTERFACE_LANGUAGES "CXX"
IMPORTED_LOCATION "${LIBAD9361_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${LIBAD9361_INCLUDE_DIRS}"
INTERFACE_LINK_LIBRARIES "${LIBAD9361_LIBRARIES}"
)
endif()
mark_as_advanced(LIBAD9361_LIBRARIES LIBAD9361_INCLUDE_DIRS)

View File

@ -57,7 +57,7 @@ if(ENABLE_GN3S)
# GN3S (USB dongle) # GN3S (USB dongle)
############################################## ##############################################
if(NOT GRGN3S_FOUND) 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") message(FATAL_ERROR "gr-gn3s required for building gnss-sdr with this option enabled")
endif() endif()
set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} gn3s_signal_source.cc) set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} gn3s_signal_source.cc)
@ -76,7 +76,7 @@ if(ENABLE_ARRAY)
# DBFCTTC GNSS EXPERIMENTAL ARRAY PROTOTYPE # DBFCTTC GNSS EXPERIMENTAL ARRAY PROTOTYPE
############################################## ##############################################
if(NOT GRDBFCTTC_FOUND) 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") message(FATAL_ERROR "gr-dbfcttc required for building gnss-sdr with this option enabled")
endif() endif()
set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} raw_array_signal_source.cc) set(OPT_DRIVER_SOURCES ${OPT_DRIVER_SOURCES} raw_array_signal_source.cc)
@ -189,6 +189,16 @@ if(ENABLE_AD9361 AND LIBIIO_FOUND)
) )
endif() endif()
if(ENABLE_AD9361 OR ENABLE_FMCOMMS2 OR ENABLE_PLUTOSDR)
if(LIBAD9361_VERSION)
if(LIBAD9361_VERSION VERSION_GREATER 0.1)
target_compile_definitions(signal_source_adapters
PRIVATE -DLIBAD9361_VERSION_GREATER_THAN_01=1
)
endif()
endif()
endif()
if(ENABLE_FLEXIBAND AND TELEORBIT_FOUND) if(ENABLE_FLEXIBAND AND TELEORBIT_FOUND)
target_link_libraries(signal_source_adapters target_link_libraries(signal_source_adapters
PRIVATE PRIVATE
@ -210,7 +220,6 @@ if(ENABLE_ARRAY AND GRDBFCTTC_FOUND)
) )
endif() endif()
if(ENABLE_PLUTOSDR OR ENABLE_FMCOMMS2) if(ENABLE_PLUTOSDR OR ENABLE_FMCOMMS2)
if(GR_IIO_INCLUDE_HAS_GNURADIO) if(GR_IIO_INCLUDE_HAS_GNURADIO)
target_compile_definitions(signal_source_adapters target_compile_definitions(signal_source_adapters
@ -226,6 +235,8 @@ if(ENABLE_PLUTOSDR OR ENABLE_FMCOMMS2)
PUBLIC PUBLIC
Gnuradio::iio Gnuradio::iio
Boost::chrono Boost::chrono
PRIVATE
Iio::iio
) )
endif() endif()

View File

@ -279,14 +279,15 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(ConfigurationInterface *configura
const std::string &role, unsigned int in_stream, unsigned int out_stream, const std::string &role, unsigned int in_stream, unsigned int out_stream,
std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> queue) : role_(role), in_stream_(in_stream), out_stream_(out_stream), queue_(std::move(queue)) std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> queue) : role_(role), in_stream_(in_stream), out_stream_(out_stream), queue_(std::move(queue))
{ {
std::string default_gain_mode("slow attack"); std::string default_gain_mode("slow_attack");
double default_tx_attenuation_db = -10.0; double default_tx_attenuation_db = -10.0;
double default_manual_gain_rx1 = 64.0; double default_manual_gain_rx1 = 64.0;
double default_manual_gain_rx2 = 64.0; double default_manual_gain_rx2 = 64.0;
uint64_t default_bandwidth = 12500000;
std::string default_rf_port_select("A_BALANCED"); std::string default_rf_port_select("A_BALANCED");
freq_ = configuration->property(role + ".freq", GPS_L1_FREQ_HZ); freq_ = configuration->property(role + ".freq", GPS_L1_FREQ_HZ);
sample_rate_ = configuration->property(role + ".sampling_frequency", 12500000); sample_rate_ = configuration->property(role + ".sampling_frequency", 12500000);
bandwidth_ = configuration->property(role + ".bandwidth", 12500000); bandwidth_ = configuration->property(role + ".bandwidth", default_bandwidth);
quadrature_ = configuration->property(role + ".quadrature", true); quadrature_ = configuration->property(role + ".quadrature", true);
rf_dc_ = configuration->property(role + ".rf_dc", true); rf_dc_ = configuration->property(role + ".rf_dc", true);
bb_dc_ = configuration->property(role + ".bb_dc", true); bb_dc_ = configuration->property(role + ".bb_dc", true);
@ -296,7 +297,18 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(ConfigurationInterface *configura
rf_gain_rx2_ = configuration->property(role + ".gain_rx2", default_manual_gain_rx2); 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); rf_port_select_ = configuration->property(role + ".rf_port_select", default_rf_port_select);
filter_file_ = configuration->property(role + ".filter_file", std::string("")); filter_file_ = configuration->property(role + ".filter_file", std::string(""));
filter_filename_ = configuration->property(role + ".filter_filename", filter_file_);
filter_auto_ = configuration->property(role + ".filter_auto", false); filter_auto_ = configuration->property(role + ".filter_auto", false);
if (filter_auto_)
{
filter_source_ = configuration->property(role + ".filter_source", std::string("Auto"));
}
else
{
filter_source_ = configuration->property(role + ".filter_source", std::string("Off"));
}
Fpass_ = configuration->property(role + ".Fpass", 0.0);
Fstop_ = configuration->property(role + ".Fstop", 0.0);
enable_dds_lo_ = configuration->property(role + ".enable_dds_lo", false); enable_dds_lo_ = configuration->property(role + ".enable_dds_lo", false);
freq_dds_tx_hz_ = configuration->property(role + ".freq_dds_tx_hz", 1000); freq_dds_tx_hz_ = configuration->property(role + ".freq_dds_tx_hz", 1000);
freq_rf_tx_hz_ = configuration->property(role + ".freq_rf_tx_hz", GPS_L1_FREQ_HZ - GPS_L2_FREQ_HZ - freq_dds_tx_hz_); freq_rf_tx_hz_ = configuration->property(role + ".freq_rf_tx_hz", GPS_L1_FREQ_HZ - GPS_L2_FREQ_HZ - freq_dds_tx_hz_);
@ -408,6 +420,28 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(ConfigurationInterface *configura
} }
} }
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";
}
if (bandwidth_ < 200000 or bandwidth_ > 56000000)
{
std::cout << "Configuration parameter bandwidth should take values between 200000 and 56000000 Hz" << std::endl;
std::cout << "Error: provided value bandwidth=" << bandwidth_ << " is not among valid values" << std::endl;
std::cout << " This parameter has been set to its default value bandwidth=" << default_bandwidth << std::endl;
bandwidth_ = default_bandwidth;
LOG(WARNING) << "Invalid configuration value for bandwidth parameter. Set to bandwidth=" << default_bandwidth;
}
std::cout << "LO frequency : " << freq_ << " Hz" << std::endl; std::cout << "LO frequency : " << freq_ << " Hz" << std::endl;
try try
{ {
@ -421,7 +455,11 @@ Ad9361FpgaSignalSource::Ad9361FpgaSignalSource(ConfigurationInterface *configura
rf_gain_rx2_, rf_gain_rx2_,
quadrature_, quadrature_,
rf_dc_, rf_dc_,
bb_dc_); bb_dc_,
filter_source_,
filter_filename_,
Fpass_,
Fstop_);
} }
catch (const std::runtime_error &e) catch (const std::runtime_error &e)
{ {

View File

@ -93,6 +93,10 @@ private:
std::string rf_port_select_; std::string rf_port_select_;
std::string filter_file_; std::string filter_file_;
bool filter_auto_; bool filter_auto_;
std::string filter_source_;
std::string filter_filename_;
float Fpass_;
float Fstop_;
// DDS configuration for LO generation for external mixer // DDS configuration for LO generation for external mixer
bool enable_dds_lo_; bool enable_dds_lo_;

View File

@ -42,13 +42,13 @@
#include <utility> #include <utility>
Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration, Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface *configuration,
const std::string& role, unsigned int in_stream, unsigned int out_stream, const std::string &role, unsigned int in_stream, unsigned int out_stream,
std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> queue) : role_(role), in_stream_(in_stream), out_stream_(out_stream), queue_(std::move(queue)) std::shared_ptr<Concurrent_Queue<pmt::pmt_t>> queue) : role_(role), in_stream_(in_stream), out_stream_(out_stream), queue_(std::move(queue))
{ {
std::string default_item_type = "gr_complex"; std::string default_item_type = "gr_complex";
std::string default_dump_file = "./data/signal_source.dat"; std::string default_dump_file = "./data/signal_source.dat";
std::string default_gain_mode("slow attack"); std::string default_gain_mode("slow_attack");
double default_tx_attenuation_db = -10.0; double default_tx_attenuation_db = -10.0;
uri_ = configuration->property(role + ".device_address", std::string("192.168.2.1")); uri_ = configuration->property(role + ".device_address", std::string("192.168.2.1"));
freq_ = configuration->property(role + ".freq", GPS_L1_FREQ_HZ); freq_ = configuration->property(role + ".freq", GPS_L1_FREQ_HZ);
@ -67,11 +67,19 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration
rf_gain_rx2_ = configuration->property(role + ".gain_rx2", 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")); rf_port_select_ = configuration->property(role + ".rf_port_select", std::string("A_BALANCED"));
filter_file_ = configuration->property(role + ".filter_file", std::string("")); filter_file_ = configuration->property(role + ".filter_file", std::string(""));
filter_source_ = configuration->property(role + ".filter_source", std::string("Off")); filter_auto_ = configuration->property(role + ".filter_auto", false);
filter_filename_ = configuration->property(role + ".filter_filename", std::string("")); if (filter_auto_)
{
filter_source_ = configuration->property(role + ".filter_source", std::string("Auto"));
}
else
{
filter_source_ = configuration->property(role + ".filter_source", std::string("Off"));
}
filter_filename_ = configuration->property(role + ".filter_filename", filter_file_);
Fpass_ = configuration->property(role + ".Fpass", 0.0); Fpass_ = configuration->property(role + ".Fpass", 0.0);
Fstop_ = configuration->property(role + ".Fstop", 0.0); Fstop_ = configuration->property(role + ".Fstop", 0.0);
filter_auto_ = configuration->property(role + ".filter_auto", false);
item_type_ = configuration->property(role + ".item_type", default_item_type); item_type_ = configuration->property(role + ".item_type", default_item_type);
samples_ = configuration->property(role + ".samples", 0); samples_ = configuration->property(role + ".samples", 0);
dump_ = configuration->property(role + ".dump", false); dump_ = configuration->property(role + ".dump", false);
@ -119,17 +127,15 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration
LOG(WARNING) << "Invalid configuration value for gain_mode_rx1 parameter. Set to 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")) 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 << "Configuration parameter filter_source should take one of these values:" << std::endl;
std::cout << " Off: Disable filter" << std::endl; std::cout << " Off: Disable filter" << std::endl;
std::cout << " Auto: Use auto-generated filters" << 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 << " File: User-provided filter in filter_filename parameter" << std::endl;
#if LIBAD9361_VERSION_GREATER_THAN_01
std::cout << " Design: Create filter from Fpass, Fstop, sampling_frequency and bandwidth parameters" << std::endl; std::cout << " Design: Create filter from Fpass, Fstop, sampling_frequency and bandwidth parameters" << std::endl;
#endif
std::cout << "Error: provided value filter_source=" << filter_source_ << " is not among valid values" << 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; std::cout << " This parameter has been set to its default value filter_source=Off" << std::endl;
filter_source_ = std::string("Off"); filter_source_ = std::string("Off");
@ -160,6 +166,15 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration
} }
} }
if (bandwidth_ < 200000 or bandwidth_ > 56000000)
{
std::cout << "Configuration parameter bandwidth should take values between 200000 and 56000000 Hz" << std::endl;
std::cout << "Error: provided value bandwidth=" << bandwidth_ << " is not among valid values" << std::endl;
std::cout << " This parameter has been set to its default value bandwidth=2000000" << std::endl;
bandwidth_ = 2000000;
LOG(WARNING) << "Invalid configuration value for bandwidth parameter. Set to bandwidth=2000000";
}
std::cout << "device address: " << uri_ << std::endl; std::cout << "device address: " << uri_ << std::endl;
std::cout << "LO frequency : " << freq_ << " Hz" << std::endl; std::cout << "LO frequency : " << freq_ << " Hz" << std::endl;
std::cout << "sample rate: " << sample_rate_ << " Hz" << std::endl; std::cout << "sample rate: " << sample_rate_ << " Hz" << std::endl;
@ -226,7 +241,7 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration
scale_dds_dbfs_, scale_dds_dbfs_,
phase_dds_deg_); 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; std::cout << "Exception cached when configuring the TX carrier: " << e.what() << std::endl;
} }
@ -293,7 +308,7 @@ Fmcomms2SignalSource::Fmcomms2SignalSource(ConfigurationInterface* configuration
scale_dds_dbfs_, scale_dds_dbfs_,
phase_dds_deg_); 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; std::cout << "Exception cached when configuring the TX carrier: " << e.what() << std::endl;
} }
@ -334,7 +349,7 @@ Fmcomms2SignalSource::~Fmcomms2SignalSource()
{ {
ad9361_disable_lo_remote(uri_); ad9361_disable_lo_remote(uri_);
} }
catch (const std::exception& e) catch (const std::exception &e)
{ {
LOG(WARNING) << "Exception thrown in Fmcomms2SignalSource destructor: " << e.what(); LOG(WARNING) << "Exception thrown in Fmcomms2SignalSource destructor: " << e.what();
} }

View File

@ -43,7 +43,7 @@ PlutosdrSignalSource::PlutosdrSignalSource(ConfigurationInterface* configuration
{ {
std::string default_item_type = "gr_complex"; std::string default_item_type = "gr_complex";
std::string default_dump_file = "./data/signal_source.dat"; std::string default_dump_file = "./data/signal_source.dat";
std::string default_gain_mode("slow attack"); std::string default_gain_mode("slow_attack");
uri_ = configuration->property(role + ".device_address", std::string("192.168.2.1")); uri_ = configuration->property(role + ".device_address", std::string("192.168.2.1"));
freq_ = configuration->property(role + ".freq", GPS_L1_FREQ_HZ); freq_ = configuration->property(role + ".freq", GPS_L1_FREQ_HZ);
sample_rate_ = configuration->property(role + ".sampling_frequency", 3000000); sample_rate_ = configuration->property(role + ".sampling_frequency", 3000000);
@ -56,7 +56,14 @@ PlutosdrSignalSource::PlutosdrSignalSource(ConfigurationInterface* configuration
rf_gain_ = configuration->property(role + ".gain", 50.0); rf_gain_ = configuration->property(role + ".gain", 50.0);
filter_file_ = configuration->property(role + ".filter_file", std::string("")); filter_file_ = configuration->property(role + ".filter_file", std::string(""));
filter_auto_ = configuration->property(role + ".filter_auto", false); filter_auto_ = configuration->property(role + ".filter_auto", false);
filter_source_ = configuration->property(role + ".filter_source", std::string("Off")); if (filter_auto_)
{
filter_source_ = configuration->property(role + ".filter_source", std::string("Auto"));
}
else
{
filter_source_ = configuration->property(role + ".filter_source", std::string("Off"));
}
filter_filename_ = configuration->property(role + ".filter_filename", filter_file_); filter_filename_ = configuration->property(role + ".filter_filename", filter_file_);
Fpass_ = configuration->property(role + ".Fpass", 0.0); Fpass_ = configuration->property(role + ".Fpass", 0.0);
Fstop_ = configuration->property(role + ".Fstop", 0.0); Fstop_ = configuration->property(role + ".Fstop", 0.0);
@ -65,11 +72,6 @@ PlutosdrSignalSource::PlutosdrSignalSource(ConfigurationInterface* configuration
dump_ = configuration->property(role + ".dump", false); dump_ = configuration->property(role + ".dump", false);
dump_filename_ = configuration->property(role + ".dump_filename", default_dump_file); dump_filename_ = configuration->property(role + ".dump_filename", default_dump_file);
if (filter_auto_)
{
filter_source_ = std::string("Auto");
}
if (item_type_ != "gr_complex") if (item_type_ != "gr_complex")
{ {
std::cout << "Configuration error: item_type must be gr_complex" << std::endl; std::cout << "Configuration error: item_type must be gr_complex" << std::endl;
@ -105,13 +107,24 @@ PlutosdrSignalSource::PlutosdrSignalSource(ConfigurationInterface* configuration
std::cout << " Off: Disable filter" << std::endl; std::cout << " Off: Disable filter" << std::endl;
std::cout << " Auto: Use auto-generated filters" << 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 << " File: User-provided filter in filter_filename parameter" << std::endl;
#if LIBAD9361_VERSION_GREATER_THAN_01
std::cout << " Design: Create filter from Fpass, Fstop, sampling_frequency and bandwidth parameters" << std::endl; std::cout << " Design: Create filter from Fpass, Fstop, sampling_frequency and bandwidth parameters" << std::endl;
#endif
std::cout << "Error: provided value filter_source=" << filter_source_ << " is not among valid values" << 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; std::cout << " This parameter has been set to its default value filter_source=Off" << std::endl;
filter_source_ = std::string("Off"); filter_source_ = std::string("Off");
LOG(WARNING) << "Invalid configuration value for filter_source parameter. Set to filter_source=Off"; LOG(WARNING) << "Invalid configuration value for filter_source parameter. Set to filter_source=Off";
} }
if (bandwidth_ < 200000 or bandwidth_ > 56000000)
{
std::cout << "Configuration parameter bandwidth should take values between 200000 and 56000000 Hz" << std::endl;
std::cout << "Error: provided value bandwidth=" << bandwidth_ << " is not among valid values" << std::endl;
std::cout << " This parameter has been set to its default value bandwidth=2000000" << std::endl;
bandwidth_ = 2000000;
LOG(WARNING) << "Invalid configuration value for bandwidth parameter. Set to bandwidth=2000000";
}
item_size_ = sizeof(gr_complex); item_size_ = sizeof(gr_complex);
std::cout << "device address: " << uri_ << std::endl; std::cout << "device address: " << uri_ << std::endl;

View File

@ -67,7 +67,16 @@ if(ENABLE_FMCOMMS2 OR ENABLE_AD9361)
target_link_libraries(signal_source_libs target_link_libraries(signal_source_libs
PUBLIC PUBLIC
Iio::iio Iio::iio
) PRIVATE
Iio::ad9361
)
if(LIBAD9361_VERSION)
if(LIBAD9361_VERSION VERSION_GREATER 0.1)
target_compile_definitions(signal_source_libs
PRIVATE -DLIBAD9361_VERSION_GREATER_THAN_01=1
)
endif()
endif()
endif() endif()
if(ENABLE_CLANG_TIDY) if(ENABLE_CLANG_TIDY)

View File

@ -31,10 +31,12 @@
*/ */
#include "ad9361_manager.h" #include "ad9361_manager.h"
#include <glog/logging.h> #include <glog/logging.h>
#include <ad9361.h>
#include <cmath> #include <cmath>
#include <fstream> // for ifstream
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <vector>
/* check return value of attr_write function */ /* check return value of attr_write function */
void errchk(int v, const char *what) void errchk(int v, const char *what)
@ -186,23 +188,34 @@ bool config_ad9361_rx_local(uint64_t bandwidth_,
double rf_gain_rx2_, double rf_gain_rx2_,
bool quadrature_, bool quadrature_,
bool rfdc_, bool rfdc_,
bool bbdc_) bool bbdc_,
std::string filter_source_,
std::string filter_filename_,
float Fpass_,
float Fstop_)
{ {
// RX stream config // 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.)
std::cout << "AD9361 Acquiring IIO LOCAL context\n"; std::cout << "AD9361 Acquiring IIO LOCAL context\n";
struct iio_context *ctx; struct iio_context *ctx;
// Streaming devices // Streaming devices
struct iio_device *rx; struct iio_device *rx;
struct iio_channel *rx0_i; struct iio_channel *rx_chan1;
struct iio_channel *rx0_q; struct iio_channel *rx_chan2;
int ret;
#ifndef LIBAD9361_VERSION_GREATER_THAN_01
if (filter_source_ == "Design")
{
std::cout << "Option filter_source=Design is not available in this version. Set to filter_source=Off" << std::endl;
filter_source_ = std::string("Off");
}
if (Fpass_ != 0.0 or Fstop_ != 0.0)
{
Fpass_ = 0.0;
Fstop_ = 0.0;
}
#endif
ctx = iio_create_default_context(); ctx = iio_create_default_context();
if (!ctx) if (!ctx)
@ -217,41 +230,131 @@ bool config_ad9361_rx_local(uint64_t bandwidth_,
throw std::runtime_error("AD9361 IIO No devices"); throw std::runtime_error("AD9361 IIO No devices");
} }
std::cout << "* Acquiring AD9361 streaming devices\n"; struct iio_device *ad9361_phy;
ad9361_phy = iio_context_find_device(ctx, "ad9361-phy");
std::cout << "* Acquiring AD9361 streaming devices\n";
if (!get_ad9361_stream_dev(ctx, RX, &rx)) if (!get_ad9361_stream_dev(ctx, RX, &rx))
{ {
std::cout << "No rx dev found\n"; std::cout << "No rx dev found\n";
throw std::runtime_error("AD9361 IIO No rx dev found"); throw std::runtime_error("AD9361 IIO No rx dev found");
}; };
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 << "* 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)) if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx_chan1))
{ {
std::cout << "RX chan i not found\n"; std::cout << "RX channel 1 not found\n";
throw std::runtime_error("RX chan i not found"); throw std::runtime_error("RX channel 1 not found");
} }
if (!get_ad9361_stream_ch(ctx, RX, rx, 1, &rx0_q)) if (!get_ad9361_stream_ch(ctx, RX, rx, 1, &rx_chan2))
{ {
std::cout << "RX chan q not found\n"; std::cout << "RX channel 2 not found\n";
throw std::runtime_error("RX chan q not found"); throw std::runtime_error("RX channel 2 not found");
}
if (filter_source_ == "Off")
{
struct stream_cfg rxcfg;
rxcfg.bw_hz = bandwidth_;
rxcfg.fs_hz = sample_rate_;
rxcfg.lo_hz = freq_;
rxcfg.rfport = rf_port_select_.c_str();
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");
}
}
else if (filter_source_ == "Auto")
{
ret = ad9361_set_bb_rate(ad9361_phy, sample_rate_);
if (ret)
{
throw std::runtime_error("Unable to set BB rate");
// set bw
//params.push_back("in_voltage_rf_bandwidth=" + boost::to_string(bandwidth));
}
//wr_ch_str(rx_chan1, "rf_port_select", rf_port_select_.c_str());
ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str());
if (ret)
{
throw std::runtime_error("Unable to set rf_port_select");
}
wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_);
if (!get_lo_chan(ctx, RX, &rx_chan1))
{
return false;
}
wr_ch_lli(rx_chan1, "frequency", freq_);
}
else if (filter_source_ == "File")
{
try
{
if (!load_fir_filter(filter_filename_, ad9361_phy))
{
throw std::runtime_error("Unable to load filter file");
}
}
catch (const std::runtime_error &e)
{
std::cout << "Exception cached when configuring the RX FIR filter: " << e.what() << std::endl;
}
ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str());
if (ret)
{
throw std::runtime_error("Unable to set rf_port_select");
}
wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_);
if (!get_lo_chan(ctx, RX, &rx_chan1))
{
return false;
}
wr_ch_lli(rx_chan1, "frequency", freq_);
}
#if LIBAD9361_VERSION_GREATER_THAN_01
else if (filter_source_ == "Design")
{
ret = ad9361_set_bb_rate_custom_filter_manual(
ad9361_phy, sample_rate_, static_cast<uint64_t>(Fpass_), static_cast<uint64_t>(Fstop_), bandwidth_, bandwidth_);
if (ret)
{
throw std::runtime_error("Unable to set BB rate");
}
ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str());
if (ret)
{
throw std::runtime_error("Unable to set rf_port_select");
}
wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_);
if (!get_lo_chan(ctx, RX, &rx_chan1))
{
return false;
}
wr_ch_lli(rx_chan1, "frequency", freq_);
}
#endif
else
{
throw std::runtime_error("Unknown filter configuration");
}
// Filters can only be disabled after the sample rate has been set
if (filter_source_ == "Off")
{
ret = ad9361_set_trx_fir_enable(ad9361_phy, false);
if (ret)
{
throw std::runtime_error("Unable to disable filters");
}
} }
std::cout << "* Enabling IIO streaming channels\n"; std::cout << "* Enabling IIO streaming channels\n";
iio_channel_enable(rx0_i); iio_channel_enable(rx_chan1);
iio_channel_enable(rx0_q); iio_channel_enable(rx_chan2);
struct iio_device *ad9361_phy;
ad9361_phy = iio_context_find_device(ctx, "ad9361-phy");
int ret;
ret = iio_device_attr_write(ad9361_phy, "trx_rate_governor", "nominal"); ret = iio_device_attr_write(ad9361_phy, "trx_rate_governor", "nominal");
if (ret < 0) if (ret < 0)
{ {
@ -320,22 +423,32 @@ bool config_ad9361_rx_remote(const std::string &remote_host,
double rf_gain_rx2_, double rf_gain_rx2_,
bool quadrature_, bool quadrature_,
bool rfdc_, bool rfdc_,
bool bbdc_) bool bbdc_,
std::string filter_source_,
std::string filter_filename_,
float Fpass_,
float Fstop_)
{ {
// RX stream config // 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.)
std::cout << "AD9361 Acquiring IIO REMOTE context in host " << remote_host << std::endl; std::cout << "AD9361 Acquiring IIO REMOTE context in host " << remote_host << std::endl;
struct iio_context *ctx; struct iio_context *ctx;
// Streaming devices // Streaming devices
struct iio_device *rx; struct iio_device *rx;
struct iio_channel *rx0_i; struct iio_channel *rx_chan1;
struct iio_channel *rx0_q; struct iio_channel *rx_chan2;
#ifndef LIBAD9361_VERSION_GREATER_THAN_01
if (filter_source_ == "Design")
{
std::cout << "Option filter_source=Design is not available in this version. Set to filter_source=Off" << std::endl;
filter_source_ = std::string("Off");
}
if (Fpass_ != 0.0 or Fstop_ != 0.0)
{
Fpass_ = 0.0;
Fstop_ = 0.0;
}
#endif
ctx = iio_create_network_context(remote_host.c_str()); ctx = iio_create_network_context(remote_host.c_str());
if (!ctx) if (!ctx)
@ -359,32 +472,126 @@ bool config_ad9361_rx_remote(const std::string &remote_host,
}; };
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 << "* 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");
}
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 << "* Enabling IIO streaming channels\n";
iio_channel_enable(rx0_i);
iio_channel_enable(rx0_q);
struct iio_device *ad9361_phy; 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; int ret;
std::cout << "* Initializing AD9361 IIO streaming channels\n";
if (!get_ad9361_stream_ch(ctx, RX, rx, 0, &rx_chan1))
{
std::cout << "RX channel 1 not found\n";
throw std::runtime_error("RX channel 1 not found");
}
if (!get_ad9361_stream_ch(ctx, RX, rx, 1, &rx_chan2))
{
std::cout << "RX channel 2 not found\n";
throw std::runtime_error("RX channel 2 not found");
}
if (filter_source_ == "Off")
{
struct stream_cfg rxcfg;
rxcfg.bw_hz = bandwidth_;
rxcfg.fs_hz = sample_rate_;
rxcfg.lo_hz = freq_;
rxcfg.rfport = rf_port_select_.c_str();
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");
}
}
else if (filter_source_ == "Auto")
{
ret = ad9361_set_bb_rate(ad9361_phy, sample_rate_);
if (ret)
{
throw std::runtime_error("Unable to set BB rate");
// set bw
//params.push_back("in_voltage_rf_bandwidth=" + boost::to_string(bandwidth));
}
//wr_ch_str(rx_chan1, "rf_port_select", rf_port_select_.c_str());
ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str());
if (ret)
{
throw std::runtime_error("Unable to set rf_port_select");
}
wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_);
if (!get_lo_chan(ctx, RX, &rx_chan1))
{
return false;
}
wr_ch_lli(rx_chan1, "frequency", freq_);
}
else if (filter_source_ == "File")
{
try
{
if (!load_fir_filter(filter_filename_, ad9361_phy))
{
throw std::runtime_error("Unable to load filter file");
}
}
catch (const std::runtime_error &e)
{
std::cout << "Exception cached when configuring the RX FIR filter: " << e.what() << std::endl;
}
ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str());
if (ret)
{
throw std::runtime_error("Unable to set rf_port_select");
}
wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_);
if (!get_lo_chan(ctx, RX, &rx_chan1))
{
return false;
}
wr_ch_lli(rx_chan1, "frequency", freq_);
}
#if LIBAD9361_VERSION_GREATER_THAN_01
else if (filter_source_ == "Design")
{
ret = ad9361_set_bb_rate_custom_filter_manual(
ad9361_phy, sample_rate_, static_cast<uint64_t>(Fpass_), static_cast<uint64_t>(Fstop_), bandwidth_, bandwidth_);
if (ret)
{
throw std::runtime_error("Unable to set BB rate");
}
ret = iio_device_attr_write(ad9361_phy, "in_voltage0_rf_port_select", rf_port_select_.c_str());
if (ret)
{
throw std::runtime_error("Unable to set rf_port_select");
}
wr_ch_lli(rx_chan1, "rf_bandwidth", bandwidth_);
if (!get_lo_chan(ctx, RX, &rx_chan1))
{
return false;
}
wr_ch_lli(rx_chan1, "frequency", freq_);
}
#endif
else
{
throw std::runtime_error("Unknown filter configuration");
}
// Filters can only be disabled after the sample rate has been set
if (filter_source_ == "Off")
{
ret = ad9361_set_trx_fir_enable(ad9361_phy, false);
if (ret)
{
throw std::runtime_error("Unable to disable filters");
}
}
std::cout << "* Enabling IIO streaming channels\n";
iio_channel_enable(rx_chan1);
iio_channel_enable(rx_chan2);
ret = iio_device_attr_write(ad9361_phy, "trx_rate_governor", "nominal"); ret = iio_device_attr_write(ad9361_phy, "trx_rate_governor", "nominal");
if (ret < 0) if (ret < 0)
{ {
@ -425,15 +632,21 @@ bool config_ad9361_rx_remote(const std::string &remote_host,
{ {
std::cout << "Failed to set in_voltage1_gain_control_mode: " << ret << std::endl; std::cout << "Failed to set in_voltage1_gain_control_mode: " << ret << std::endl;
} }
ret = iio_device_attr_write_double(ad9361_phy, "in_voltage0_hardwaregain", rf_gain_rx1_); if (gain_mode_rx1_ == "manual")
if (ret < 0)
{ {
std::cout << "Failed to set in_voltage0_hardwaregain: " << ret << std::endl; ret = iio_device_attr_write_double(ad9361_phy, "in_voltage0_hardwaregain", rf_gain_rx1_);
if (ret < 0)
{
std::cout << "Failed to set in_voltage0_hardwaregain: " << ret << std::endl;
}
} }
ret = iio_device_attr_write_double(ad9361_phy, "in_voltage1_hardwaregain", rf_gain_rx2_); if (gain_mode_rx2_ == "manual")
if (ret < 0)
{ {
std::cout << "Failed to set in_voltage1_hardwaregain: " << ret << std::endl; ret = iio_device_attr_write_double(ad9361_phy, "in_voltage1_hardwaregain", rf_gain_rx2_);
if (ret < 0)
{
std::cout << "Failed to set in_voltage1_hardwaregain: " << ret << std::endl;
}
} }
std::cout << "End of AD9361 RX configuration.\n"; std::cout << "End of AD9361 RX configuration.\n";
@ -808,3 +1021,47 @@ bool ad9361_disable_lo_local()
return true; return true;
} }
bool load_fir_filter(
std::string &filter, struct iio_device *phy)
{
if (filter.empty() || !iio_device_find_attr(phy, "filter_fir_config"))
{
return false;
}
std::ifstream ifs(filter.c_str(), std::ifstream::binary);
if (!ifs)
{
return false;
}
// Here, we verify that the filter file contains data for both RX+TX.
{
char buf[256];
do
{
ifs.getline(buf, sizeof(buf));
}
while (!(buf[0] == '-' || (buf[0] >= '0' && buf[0] <= '9')));
std::string line(buf);
if (line.find(',') == std::string::npos)
throw std::runtime_error("Incompatible filter file");
}
ifs.seekg(0, ifs.end);
int length = ifs.tellg();
ifs.seekg(0, ifs.beg);
std::vector<char> buffer(length);
ifs.read(buffer.data(), length);
ifs.close();
int ret = iio_device_attr_write_raw(phy,
"filter_fir_config", buffer.data(), length);
return ret > 0;
}

View File

@ -37,6 +37,7 @@
#include <cstdint> #include <cstdint>
#include <string> #include <string>
#define FIR_BUF_SIZE 8192
/* RX is input, TX is output */ /* RX is input, TX is output */
enum iodev enum iodev
@ -48,13 +49,12 @@ enum iodev
/* common RX and TX streaming params */ /* common RX and TX streaming params */
struct stream_cfg struct stream_cfg
{ {
int64_t bw_hz; // Analog banwidth in Hz int64_t bw_hz; // Analog bandwidth in Hz
int64_t fs_hz; // Baseband sample rate in Hz int64_t fs_hz; // Baseband sample rate in Hz
int64_t lo_hz; // Local oscillator frequency in Hz int64_t lo_hz; // Local oscillator frequency in Hz
const char *rfport; // Port name const char *rfport; // Port name
}; };
/* check return value of attr_write function */ /* check return value of attr_write function */
void errchk(int v, const char *what); void errchk(int v, const char *what);
@ -64,9 +64,6 @@ void wr_ch_lli(struct iio_channel *chn, const char *what, int64_t val);
/* write attribute: string */ /* 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);
/* returns ad9361 phy device */ /* returns ad9361 phy device */
struct iio_device *get_ad9361_phy(struct iio_context *ctx); struct iio_device *get_ad9361_phy(struct iio_context *ctx);
@ -95,7 +92,11 @@ bool config_ad9361_rx_local(uint64_t bandwidth_,
double rf_gain_rx2_, double rf_gain_rx2_,
bool quadrature_, bool quadrature_,
bool rfdc_, bool rfdc_,
bool bbdc_); bool bbdc_,
std::string filter_source_,
std::string filter_filename_,
float Fpass_,
float Fstop_);
bool config_ad9361_rx_remote(const std::string &remote_host, bool config_ad9361_rx_remote(const std::string &remote_host,
uint64_t bandwidth_, uint64_t bandwidth_,
@ -108,7 +109,11 @@ bool config_ad9361_rx_remote(const std::string &remote_host,
double rf_gain_rx2_, double rf_gain_rx2_,
bool quadrature_, bool quadrature_,
bool rfdc_, bool rfdc_,
bool bbdc_); bool bbdc_,
std::string filter_source_,
std::string filter_filename_,
float Fpass_,
float Fstop_);
bool config_ad9361_lo_local(uint64_t bandwidth_, bool config_ad9361_lo_local(uint64_t bandwidth_,
uint64_t sample_rate_, uint64_t sample_rate_,
@ -127,9 +132,10 @@ bool config_ad9361_lo_remote(const std::string &remote_host,
double scale_dds_dbfs_, double scale_dds_dbfs_,
double phase_dds_deg_); double phase_dds_deg_);
bool ad9361_disable_lo_remote(const std::string &remote_host); bool ad9361_disable_lo_remote(const std::string &remote_host);
bool ad9361_disable_lo_local(); bool ad9361_disable_lo_local();
bool load_fir_filter(std::string &filter, struct iio_device *phy);
#endif // GNSS_SDR_AD9361_MANAGER_H_ #endif // GNSS_SDR_AD9361_MANAGER_H_