1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-07-07 12:32:57 +00:00

Merge branch 'xguerreropau-decimation_factor_count' into next

This commit is contained in:
Carles Fernandez 2024-08-08 14:05:41 +02:00
commit 8fea8e1729
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
4 changed files with 35 additions and 17 deletions

7
.gitignore vendored
View File

@ -20,3 +20,10 @@ cmake-build-debug/
.vscode/ .vscode/
.vs/ .vs/
Testing/ Testing/
GSDR*
PVT_*
HAS_*
gnss_sdr_pvt.nmea
build-debug/
build-release/

View File

@ -13,6 +13,7 @@
* ----------------------------------------------------------------------------- * -----------------------------------------------------------------------------
*/ */
#include "ad936x_iio_custom.h" #include "ad936x_iio_custom.h"
#include "display.h"
#include <boost/filesystem.hpp> #include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp> #include <boost/lexical_cast.hpp>
#include <chrono> #include <chrono>
@ -44,6 +45,7 @@ ad936x_iio_custom::ad936x_iio_custom(int debug_level_, int log_level_)
n_channels = 0; n_channels = 0;
} }
ad936x_iio_custom::~ad936x_iio_custom() ad936x_iio_custom::~ad936x_iio_custom()
{ {
// disable TX // disable TX
@ -59,11 +61,13 @@ void ad936x_iio_custom::set_gnsstime_queue(std::shared_ptr<Concurrent_Queue<Gnss
GnssTime_queue = std::move(queue); GnssTime_queue = std::move(queue);
} }
void ad936x_iio_custom::set_pps_samplestamp_queue(std::shared_ptr<Concurrent_Queue<PpsSamplestamp>> queue) void ad936x_iio_custom::set_pps_samplestamp_queue(std::shared_ptr<Concurrent_Queue<PpsSamplestamp>> queue)
{ {
Pps_queue = std::move(queue); Pps_queue = std::move(queue);
} }
bool ad936x_iio_custom::initialize_device(std::string pluto_device_uri, std::string board_type) bool ad936x_iio_custom::initialize_device(std::string pluto_device_uri, std::string board_type)
{ {
// Find devices // Find devices
@ -125,7 +129,6 @@ bool ad936x_iio_custom::initialize_device(std::string pluto_device_uri, std::str
return false; return false;
} }
phy = iio_context_find_device(ctx, "ad9361-phy"); phy = iio_context_find_device(ctx, "ad9361-phy");
if (phy == NULL) if (phy == NULL)
@ -328,7 +331,6 @@ bool ad936x_iio_custom::config_ad9361_dds(uint64_t freq_rf_tx_hz_,
configure_params(dds_dev, params_dds); configure_params(dds_dev, params_dds);
} }
return true; return true;
} }
@ -345,6 +347,7 @@ bool ad936x_iio_custom::check_device()
} }
} }
bool ad936x_iio_custom::get_iio_param(iio_device *dev, const std::string &param, std::string &value) bool ad936x_iio_custom::get_iio_param(iio_device *dev, const std::string &param, std::string &value)
{ {
struct iio_channel *chn = 0; struct iio_channel *chn = 0;
@ -386,6 +389,7 @@ bool ad936x_iio_custom::get_iio_param(iio_device *dev, const std::string &param,
} }
} }
bool ad936x_iio_custom::read_die_temp(double &temp_c) bool ad936x_iio_custom::read_die_temp(double &temp_c)
{ {
std::string temp_mC_str; std::string temp_mC_str;
@ -410,6 +414,8 @@ bool ad936x_iio_custom::read_die_temp(double &temp_c)
return false; return false;
} }
} }
bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_, bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_,
long long sample_rate_, long long sample_rate_,
long long freq_, long long freq_,
@ -425,7 +431,6 @@ bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_,
double lo_attenuation_db_, double lo_attenuation_db_,
bool high_side_lo_, bool high_side_lo_,
int tx_lo_channel_) int tx_lo_channel_)
{ {
if (check_device() == false) return false; if (check_device() == false) return false;
@ -610,14 +615,12 @@ bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_,
std::cerr << "Warning: rf_port_select write returned: " << ret << "\n"; std::cerr << "Warning: rf_port_select write returned: " << ret << "\n";
no_errors = false; no_errors = false;
} }
// ret = iio_channel_attr_write_longlong(phy_ch, "rf_bandwidth", bandwidth_); // ret = iio_channel_attr_write_longlong(phy_ch, "rf_bandwidth", bandwidth_);
// if (ret < 0) // if (ret < 0)
// { // {
// std::cerr << "Warning: rf_bandwidth write returned: " << ret << "\n"; // std::cerr << "Warning: rf_bandwidth write returned: " << ret << "\n";
// no_errors = false; // no_errors = false;
// } // }
long long set_rf_bw; long long set_rf_bw;
ret = iio_channel_attr_read_longlong(phy_ch, "rf_bandwidth", &set_rf_bw); ret = iio_channel_attr_read_longlong(phy_ch, "rf_bandwidth", &set_rf_bw);
if (ret < 0) if (ret < 0)
@ -630,7 +633,6 @@ bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_,
std::cerr << "Info: rf_bandwidth read returned: " << set_rf_bw << " Hz \n"; std::cerr << "Info: rf_bandwidth read returned: " << set_rf_bw << " Hz \n";
} }
if (setRXGain(0, gain_mode_rx0_, rf_gain_rx0_) == false) if (setRXGain(0, gain_mode_rx0_, rf_gain_rx0_) == false)
{ {
std::cerr << "Info: setRXGain read returned false \n"; std::cerr << "Info: setRXGain read returned false \n";
@ -662,14 +664,12 @@ bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_,
std::cerr << "Warning: rf_port_select write returned: " << ret << "\n"; std::cerr << "Warning: rf_port_select write returned: " << ret << "\n";
no_errors = false; no_errors = false;
} }
// ret = iio_channel_attr_write_longlong(phy_ch, "rf_bandwidth", bandwidth_); // ret = iio_channel_attr_write_longlong(phy_ch, "rf_bandwidth", bandwidth_);
// if (ret < 0) // if (ret < 0)
// { // {
// std::cerr << "Warning: rf_bandwidth write returned: " << ret << "\n"; // std::cerr << "Warning: rf_bandwidth write returned: " << ret << "\n";
// no_errors = false; // no_errors = false;
// } // }
long long set_rf_bw; long long set_rf_bw;
ret = iio_channel_attr_read_longlong(phy_ch, "rf_bandwidth", &set_rf_bw); ret = iio_channel_attr_read_longlong(phy_ch, "rf_bandwidth", &set_rf_bw);
if (ret < 0) if (ret < 0)
@ -702,6 +702,7 @@ bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_,
return no_errors; return no_errors;
} }
bool ad936x_iio_custom::set_rx_frequency(long long freq_hz) bool ad936x_iio_custom::set_rx_frequency(long long freq_hz)
{ {
if (check_device() == false) return false; if (check_device() == false) return false;
@ -747,6 +748,7 @@ bool ad936x_iio_custom::get_rx_frequency(long long &freq_hz)
return true; return true;
} }
bool ad936x_iio_custom::setRXGain(int ch_num, std::string gain_mode, double gain_dB) bool ad936x_iio_custom::setRXGain(int ch_num, std::string gain_mode, double gain_dB)
{ {
if (check_device() == false) return false; if (check_device() == false) return false;
@ -779,6 +781,7 @@ bool ad936x_iio_custom::setRXGain(int ch_num, std::string gain_mode, double gain
} }
} }
double ad936x_iio_custom::get_rx_gain(int ch_num) double ad936x_iio_custom::get_rx_gain(int ch_num)
{ {
if (check_device() == false) return -1; if (check_device() == false) return -1;
@ -817,6 +820,7 @@ bool ad936x_iio_custom::calibrate([[maybe_unused]] int ch, [[maybe_unused]] doub
return true; return true;
} }
void ad936x_iio_custom::monitor_thread_fn() void ad936x_iio_custom::monitor_thread_fn()
{ {
uint32_t val; uint32_t val;
@ -849,11 +853,12 @@ void ad936x_iio_custom::monitor_thread_fn()
// } else { // } else {
if (val & 4) if (val & 4)
{ {
std::cout << "WARNING: IIO status register reported overflow!\n"; std::cout
LOG(INFO) << "WARNING: IIO status register reported overflow!"; << TEXT_BOLD_RED
<< "WARNING: IIO status register reported overflow!\n";
LOG(WARNING) << "WARNING: IIO status register reported overflow!";
} }
/* Clear bits */ /* Clear bits */
if (val) if (val)
{ {
@ -867,6 +872,7 @@ void ad936x_iio_custom::monitor_thread_fn()
return; return;
} }
void ad936x_iio_custom::stop_record() void ad936x_iio_custom::stop_record()
{ {
receive_samples = false; receive_samples = false;
@ -915,6 +921,7 @@ void ad936x_iio_custom::PlutoTxEnable(bool txon)
} }
} }
void ad936x_iio_custom::setPlutoGpo(int p) void ad936x_iio_custom::setPlutoGpo(int p)
{ {
char pins[11]; char pins[11];
@ -953,7 +960,6 @@ bool ad936x_iio_custom::select_rf_filter(std::string rf_filter)
// 1 Enable // 1 Enable
// X Enable Mask if Identifier=0xF // X Enable Mask if Identifier=0xF
if (check_device() == false) return false; if (check_device() == false) return false;
// int plutoGpo = 0; // int plutoGpo = 0;
int ret; int ret;
@ -1006,6 +1012,8 @@ bool ad936x_iio_custom::select_rf_filter(std::string rf_filter)
return true; return true;
} }
void ad936x_iio_custom::get_PPS_timestamp() void ad936x_iio_custom::get_PPS_timestamp()
{ {
GnssTime tow; GnssTime tow;
@ -1042,7 +1050,6 @@ void ad936x_iio_custom::get_PPS_timestamp()
// record pps rise samplestamp associated to the absolute sample counter // record pps rise samplestamp associated to the absolute sample counter
// PPS rising edge must be associated with the corresponding uBlox time message (tx once a second) // PPS rising edge must be associated with the corresponding uBlox time message (tx once a second)
if (GnssTime_queue->timed_wait_and_pop(tow, 2000) == false) if (GnssTime_queue->timed_wait_and_pop(tow, 2000) == false)
{ {
if (receive_samples == true) if (receive_samples == true)
@ -1073,6 +1080,8 @@ void ad936x_iio_custom::get_PPS_timestamp()
} }
} }
} }
bool ad936x_iio_custom::start_sample_rx(bool ppsmode) bool ad936x_iio_custom::start_sample_rx(bool ppsmode)
{ {
// using queues of smart pointers to preallocated buffers // using queues of smart pointers to preallocated buffers
@ -1118,9 +1127,7 @@ bool ad936x_iio_custom::start_sample_rx(bool ppsmode)
// start sample overflow detector // start sample overflow detector
overflow_monitor_thread = std::thread(&ad936x_iio_custom::monitor_thread_fn, this); overflow_monitor_thread = std::thread(&ad936x_iio_custom::monitor_thread_fn, this);
// start PPS and GNSS Time capture thread // start PPS and GNSS Time capture thread
if (ppsmode == true) if (ppsmode == true)
{ {
capture_time_thread = std::thread(&ad936x_iio_custom::get_PPS_timestamp, this); capture_time_thread = std::thread(&ad936x_iio_custom::get_PPS_timestamp, this);
@ -1128,16 +1135,19 @@ bool ad936x_iio_custom::start_sample_rx(bool ppsmode)
return true; return true;
} }
void ad936x_iio_custom::pop_sample_buffer(std::shared_ptr<ad936x_iio_samples> &current_buffer) void ad936x_iio_custom::pop_sample_buffer(std::shared_ptr<ad936x_iio_samples> &current_buffer)
{ {
used_buffers.wait_and_pop(current_buffer); used_buffers.wait_and_pop(current_buffer);
} }
void ad936x_iio_custom::push_sample_buffer(std::shared_ptr<ad936x_iio_samples> &current_buffer) void ad936x_iio_custom::push_sample_buffer(std::shared_ptr<ad936x_iio_samples> &current_buffer)
{ {
free_buffers.push(current_buffer); free_buffers.push(current_buffer);
} }
void ad936x_iio_custom::capture(const std::vector<std::string> &channels) void ad936x_iio_custom::capture(const std::vector<std::string> &channels)
{ {
if (check_device() == false) return; if (check_device() == false) return;

View File

@ -50,6 +50,7 @@ gnss_synchro_monitor::gnss_synchro_monitor(int n_channels,
d_decimation_factor(decimation_factor) d_decimation_factor(decimation_factor)
{ {
udp_sink_ptr = std::make_unique<Gnss_Synchro_Udp_Sink>(udp_addresses, udp_port, enable_protobuf); udp_sink_ptr = std::make_unique<Gnss_Synchro_Udp_Sink>(udp_addresses, udp_port, enable_protobuf);
count = 0;
} }
@ -73,7 +74,6 @@ int gnss_synchro_monitor::general_work(int noutput_items __attribute__((unused))
for (int channel_index = 0; channel_index < d_nchannels; channel_index++) for (int channel_index = 0; channel_index < d_nchannels; channel_index++)
{ {
// Loop through each item in each input stream channel // Loop through each item in each input stream channel
int count = 0;
for (int item_index = 0; item_index < ninput_items[channel_index]; item_index++) for (int item_index = 0; item_index < ninput_items[channel_index]; item_index++)
{ {
// Use the count variable to limit how many items are sent per channel // Use the count variable to limit how many items are sent per channel

View File

@ -71,9 +71,10 @@ private:
const std::vector<std::string>& udp_addresses, const std::vector<std::string>& udp_addresses,
bool enable_protobuf); bool enable_protobuf);
std::unique_ptr<Gnss_Synchro_Udp_Sink> udp_sink_ptr;
int count;
int d_nchannels; int d_nchannels;
int d_decimation_factor; int d_decimation_factor;
std::unique_ptr<Gnss_Synchro_Udp_Sink> udp_sink_ptr;
}; };