mirror of https://github.com/gnss-sdr/gnss-sdr
Code cleaning
This commit is contained in:
parent
2f2ed7938e
commit
1cf508ad20
|
@ -94,8 +94,8 @@ void ad936x_iio_source::ad9361_channel_demux_and_record(ad936x_iio_samples *samp
|
||||||
{
|
{
|
||||||
for (ch = 0; ch < nchannels; ch++)
|
for (ch = 0; ch < nchannels; ch++)
|
||||||
{
|
{
|
||||||
//std::cout << current_byte << " of " << samples_in->n_bytes << " test: " << (int)samples_in->buffer[current_byte] << "\n";
|
// std::cout << current_byte << " of " << samples_in->n_bytes << " test: " << (int)samples_in->buffer[current_byte] << "\n";
|
||||||
(*files_out).at(ch).write(&samples_in->buffer[current_byte], 4); //two bytes I + two bytes Q per channel
|
(*files_out).at(ch).write(&samples_in->buffer[current_byte], 4); // two bytes I + two bytes Q per channel
|
||||||
current_byte += 4;
|
current_byte += 4;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ ad936x_iio_source::ad936x_iio_source(
|
||||||
{
|
{
|
||||||
if (ad936x_custom->initialize_device(pluto_uri_, board_type_) == true)
|
if (ad936x_custom->initialize_device(pluto_uri_, board_type_) == true)
|
||||||
{
|
{
|
||||||
//configure channels
|
// configure channels
|
||||||
if (ad936x_custom->init_config_ad9361_rx(bandwidth_,
|
if (ad936x_custom->init_config_ad9361_rx(bandwidth_,
|
||||||
sample_rate_,
|
sample_rate_,
|
||||||
freq_,
|
freq_,
|
||||||
|
@ -153,19 +153,19 @@ ad936x_iio_source::ad936x_iio_source(
|
||||||
{
|
{
|
||||||
std::cout << "ad936x_iio_source HW configured OK!\n";
|
std::cout << "ad936x_iio_source HW configured OK!\n";
|
||||||
|
|
||||||
//PPS FPGA Samplestamp information from TCP server
|
// PPS FPGA Samplestamp information from TCP server
|
||||||
pps_rx = std::make_shared<pps_tcp_rx>();
|
pps_rx = std::make_shared<pps_tcp_rx>();
|
||||||
ppsqueue = std::shared_ptr<Concurrent_Queue<PpsSamplestamp>>(new Concurrent_Queue<PpsSamplestamp>());
|
ppsqueue = std::shared_ptr<Concurrent_Queue<PpsSamplestamp>>(new Concurrent_Queue<PpsSamplestamp>());
|
||||||
|
|
||||||
pps_rx->set_pps_samplestamp_queue(ppsqueue);
|
pps_rx->set_pps_samplestamp_queue(ppsqueue);
|
||||||
ad936x_custom->set_pps_samplestamp_queue(ppsqueue);
|
ad936x_custom->set_pps_samplestamp_queue(ppsqueue);
|
||||||
|
|
||||||
//start PPS RX thread
|
// start PPS RX thread
|
||||||
if (ppsmode_ == true or customsamplesize_ == true)
|
if (ppsmode_ == true or customsamplesize_ == true)
|
||||||
{
|
{
|
||||||
pps_rx_thread = std::thread(&pps_tcp_rx::receive_pps, pps_rx, fe_ip_, fe_ctlport_);
|
pps_rx_thread = std::thread(&pps_tcp_rx::receive_pps, pps_rx, fe_ip_, fe_ctlport_);
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
//configure custom FPGA options
|
// configure custom FPGA options
|
||||||
switch (ssize_)
|
switch (ssize_)
|
||||||
{
|
{
|
||||||
case 16:
|
case 16:
|
||||||
|
@ -251,13 +251,13 @@ ad936x_iio_source::ad936x_iio_source(
|
||||||
|
|
||||||
set_min_noutput_items(IIO_DEFAULTAD936XAPIFIFOSIZE_SAMPLES * 2); // multiplexed I,Q, so, two samples per complex sample
|
set_min_noutput_items(IIO_DEFAULTAD936XAPIFIFOSIZE_SAMPLES * 2); // multiplexed I,Q, so, two samples per complex sample
|
||||||
set_min_output_buffer(IIO_DEFAULTAD936XAPIFIFOSIZE_SAMPLES * sizeof(int16_t) * 2);
|
set_min_output_buffer(IIO_DEFAULTAD936XAPIFIFOSIZE_SAMPLES * sizeof(int16_t) * 2);
|
||||||
//std::cout << "max_output_buffer " << min_output_buffer(0) << " min_noutput_items: " << min_noutput_items() << "\n";
|
// std::cout << "max_output_buffer " << min_output_buffer(0) << " min_noutput_items: " << min_noutput_items() << "\n";
|
||||||
|
|
||||||
// for (int n = 0; n < ad936x_custom->n_channels; n++)
|
// for (int n = 0; n < ad936x_custom->n_channels; n++)
|
||||||
// {
|
// {
|
||||||
// std::string cap_file_root_name = "./debug_cap_ch";
|
// std::string cap_file_root_name = "./debug_cap_ch";
|
||||||
// samplesfile.push_back(std::fstream(cap_file_root_name + std::to_string(n) + ".dat", std::ios::out | std::ios::binary));
|
// samplesfile.push_back(std::fstream(cap_file_root_name + std::to_string(n) + ".dat", std::ios::out | std::ios::binary));
|
||||||
// //samplesfile.back().exceptions(std::ios_base::badbit | std::ios_base::failbit); //this will enable exceptions for debug
|
// // samplesfile.back().exceptions(std::ios_base::badbit | std::ios_base::failbit); //this will enable exceptions for debug
|
||||||
//
|
//
|
||||||
// if (samplesfile.back().is_open() == false)
|
// if (samplesfile.back().is_open() == false)
|
||||||
// {
|
// {
|
||||||
|
@ -301,7 +301,7 @@ int ad936x_iio_source::general_work(int noutput_items,
|
||||||
ad936x_custom->pop_sample_buffer(current_buffer);
|
ad936x_custom->pop_sample_buffer(current_buffer);
|
||||||
current_samples = current_buffer.get();
|
current_samples = current_buffer.get();
|
||||||
|
|
||||||
//I and Q samples are interleaved in buffer: IQIQIQ...
|
// I and Q samples are interleaved in buffer: IQIQIQ...
|
||||||
int32_t n_interleaved_iq_samples_per_channel = current_samples->n_bytes / (ad936x_custom->n_channels * 2);
|
int32_t n_interleaved_iq_samples_per_channel = current_samples->n_bytes / (ad936x_custom->n_channels * 2);
|
||||||
if (noutput_items < n_interleaved_iq_samples_per_channel)
|
if (noutput_items < n_interleaved_iq_samples_per_channel)
|
||||||
{
|
{
|
||||||
|
@ -310,12 +310,12 @@ int ad936x_iio_source::general_work(int noutput_items,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
//ad9361_channel_demux_and_record(current_samples, ad936x_custom->n_channels, &samplesfile);
|
// ad9361_channel_demux_and_record(current_samples, ad936x_custom->n_channels, &samplesfile);
|
||||||
|
|
||||||
uint32_t current_byte = 0;
|
uint32_t current_byte = 0;
|
||||||
uint32_t current_byte_in_gr = 0;
|
uint32_t current_byte_in_gr = 0;
|
||||||
int16_t ch = 0;
|
int16_t ch = 0;
|
||||||
//std::cout << "nbytes: " << samples_in->n_bytes << " nsamples: " << samples_in->n_samples << " nch: " << nchannels << "\n";
|
// std::cout << "nbytes: " << samples_in->n_bytes << " nsamples: " << samples_in->n_samples << " nch: " << nchannels << "\n";
|
||||||
if (ad936x_custom->n_channels == 1)
|
if (ad936x_custom->n_channels == 1)
|
||||||
{
|
{
|
||||||
memcpy(&((char *)output_items[0])[0], ¤t_samples->buffer[current_byte], current_samples->n_bytes);
|
memcpy(&((char *)output_items[0])[0], ¤t_samples->buffer[current_byte], current_samples->n_bytes);
|
||||||
|
|
|
@ -193,7 +193,7 @@ bool Gr_Complex_Ip_Packet_Source::stop()
|
||||||
bool Gr_Complex_Ip_Packet_Source::open()
|
bool Gr_Complex_Ip_Packet_Source::open()
|
||||||
{
|
{
|
||||||
std::array<char, PCAP_ERRBUF_SIZE> errbuf{};
|
std::array<char, PCAP_ERRBUF_SIZE> errbuf{};
|
||||||
//boost::mutex::scoped_lock lock(d_mutex); // hold mutex for duration of this function
|
// boost::mutex::scoped_lock lock(d_mutex); // hold mutex for duration of this function
|
||||||
gr::thread::scoped_lock guard(d_setlock);
|
gr::thread::scoped_lock guard(d_setlock);
|
||||||
// open device for reading
|
// open device for reading
|
||||||
descr = pcap_open_live(d_src_device.c_str(), 1500, 1, 1000, errbuf.data());
|
descr = pcap_open_live(d_src_device.c_str(), 1500, 1, 1000, errbuf.data());
|
||||||
|
@ -250,7 +250,7 @@ void Gr_Complex_Ip_Packet_Source::static_pcap_callback(u_char *args, const struc
|
||||||
void Gr_Complex_Ip_Packet_Source::pcap_callback(__attribute__((unused)) u_char *args, __attribute__((unused)) const struct pcap_pkthdr *pkthdr,
|
void Gr_Complex_Ip_Packet_Source::pcap_callback(__attribute__((unused)) u_char *args, __attribute__((unused)) const struct pcap_pkthdr *pkthdr,
|
||||||
const u_char *packet)
|
const u_char *packet)
|
||||||
{
|
{
|
||||||
//boost::mutex::scoped_lock lock(d_mutex); // hold mutex for duration of this function
|
// boost::mutex::scoped_lock lock(d_mutex); // hold mutex for duration of this function
|
||||||
|
|
||||||
const gr_ip_header *ih;
|
const gr_ip_header *ih;
|
||||||
const gr_udp_header *uh;
|
const gr_udp_header *uh;
|
||||||
|
@ -500,7 +500,7 @@ int Gr_Complex_Ip_Packet_Source::work(int noutput_items,
|
||||||
gr_vector_void_star &output_items)
|
gr_vector_void_star &output_items)
|
||||||
{
|
{
|
||||||
// send samples to next GNU Radio block
|
// send samples to next GNU Radio block
|
||||||
//boost::mutex::scoped_lock lock(d_mutex); // hold mutex for duration of this function
|
// boost::mutex::scoped_lock lock(d_mutex); // hold mutex for duration of this function
|
||||||
if (fifo_items == 0)
|
if (fifo_items == 0)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -83,7 +83,7 @@ private:
|
||||||
bool open();
|
bool open();
|
||||||
|
|
||||||
boost::thread *d_pcap_thread;
|
boost::thread *d_pcap_thread;
|
||||||
//boost::mutex d_mutex;
|
// boost::mutex d_mutex;
|
||||||
struct sockaddr_in si_me
|
struct sockaddr_in si_me
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
|
@ -40,10 +40,10 @@ ad936x_iio_custom::ad936x_iio_custom(int debug_level_, int log_level_)
|
||||||
|
|
||||||
ad936x_iio_custom::~ad936x_iio_custom()
|
ad936x_iio_custom::~ad936x_iio_custom()
|
||||||
{
|
{
|
||||||
//disable TX
|
// disable TX
|
||||||
if (phy != NULL) PlutoTxEnable(false);
|
if (phy != NULL) PlutoTxEnable(false);
|
||||||
|
|
||||||
//Close device
|
// Close device
|
||||||
if (ctx != NULL) iio_context_destroy(ctx);
|
if (ctx != NULL) iio_context_destroy(ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +60,7 @@ void ad936x_iio_custom::set_pps_samplestamp_queue(std::shared_ptr<Concurrent_Que
|
||||||
|
|
||||||
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
|
||||||
if (pluto_device_uri == "local")
|
if (pluto_device_uri == "local")
|
||||||
{
|
{
|
||||||
struct iio_scan_context *tmp_ctx = iio_create_scan_context("usb", 0);
|
struct iio_scan_context *tmp_ctx = iio_create_scan_context("usb", 0);
|
||||||
|
@ -130,7 +130,7 @@ bool ad936x_iio_custom::initialize_device(std::string pluto_device_uri, std::str
|
||||||
|
|
||||||
if (board_type.compare("fmcomms5") == 0)
|
if (board_type.compare("fmcomms5") == 0)
|
||||||
{
|
{
|
||||||
stream_dev = iio_context_find_device(ctx, "cf-ad9361-A"); //first ad9361 in FMCOMMS5
|
stream_dev = iio_context_find_device(ctx, "cf-ad9361-A"); // first ad9361 in FMCOMMS5
|
||||||
if (stream_dev == NULL)
|
if (stream_dev == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Unable to find cf-ad9361-A device from uri: " << pluto_device_uri << std::endl;
|
std::cout << "Unable to find cf-ad9361-A device from uri: " << pluto_device_uri << std::endl;
|
||||||
|
@ -139,13 +139,13 @@ bool ad936x_iio_custom::initialize_device(std::string pluto_device_uri, std::str
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stream_dev = iio_context_find_device(ctx, "cf-ad9361-lpc"); //regular AD9361 stream device in single AD9361 boards
|
stream_dev = iio_context_find_device(ctx, "cf-ad9361-lpc"); // regular AD9361 stream device in single AD9361 boards
|
||||||
if (stream_dev == NULL)
|
if (stream_dev == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Unable to find cf-ad9361-lpc device from uri: " << pluto_device_uri << std::endl;
|
std::cout << "Unable to find cf-ad9361-lpc device from uri: " << pluto_device_uri << std::endl;
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
dds_dev = iio_context_find_device(ctx, "cf-ad9361-dds-core-lpc"); //DDS core for LO oscillator (external transverter operation)
|
dds_dev = iio_context_find_device(ctx, "cf-ad9361-dds-core-lpc"); // DDS core for LO oscillator (external transverter operation)
|
||||||
if (stream_dev == NULL)
|
if (stream_dev == NULL)
|
||||||
{
|
{
|
||||||
std::cout << "Warning: Unable to find cf-ad9361-dds-core-lpc device from uri: " << pluto_device_uri << std::endl;
|
std::cout << "Warning: Unable to find cf-ad9361-dds-core-lpc device from uri: " << pluto_device_uri << std::endl;
|
||||||
|
@ -267,13 +267,13 @@ bool ad936x_iio_custom::config_ad9361_dds(uint64_t freq_rf_tx_hz_,
|
||||||
{
|
{
|
||||||
params_phy.push_back("out_voltage0_hardwaregain=" +
|
params_phy.push_back("out_voltage0_hardwaregain=" +
|
||||||
std::to_string(-tx_attenuation_db_));
|
std::to_string(-tx_attenuation_db_));
|
||||||
//disable the other TX
|
// disable the other TX
|
||||||
params_phy.push_back("out_voltage1_hardwaregain=" +
|
params_phy.push_back("out_voltage1_hardwaregain=" +
|
||||||
std::to_string(-disabled_tx_attenuation));
|
std::to_string(-disabled_tx_attenuation));
|
||||||
|
|
||||||
configure_params(phy, params_phy);
|
configure_params(phy, params_phy);
|
||||||
|
|
||||||
//DDS TX CH1 I (tone #1)
|
// DDS TX CH1 I (tone #1)
|
||||||
params_dds.push_back("out_altvoltage0_TX1_I_F1_frequency=" +
|
params_dds.push_back("out_altvoltage0_TX1_I_F1_frequency=" +
|
||||||
std::to_string(freq_dds_tx_hz_));
|
std::to_string(freq_dds_tx_hz_));
|
||||||
params_dds.push_back("out_altvoltage0_TX1_I_F1_phase=" +
|
params_dds.push_back("out_altvoltage0_TX1_I_F1_phase=" +
|
||||||
|
@ -281,7 +281,7 @@ bool ad936x_iio_custom::config_ad9361_dds(uint64_t freq_rf_tx_hz_,
|
||||||
params_dds.push_back("out_altvoltage0_TX1_I_F1_scale=" +
|
params_dds.push_back("out_altvoltage0_TX1_I_F1_scale=" +
|
||||||
std::to_string(scale_dds_));
|
std::to_string(scale_dds_));
|
||||||
params_dds.push_back("out_altvoltage0_TX1_I_F1_raw=1");
|
params_dds.push_back("out_altvoltage0_TX1_I_F1_raw=1");
|
||||||
//DDS TX CH1 Q (tone #1)
|
// DDS TX CH1 Q (tone #1)
|
||||||
params_dds.push_back("out_altvoltage2_TX1_Q_F1_frequency=" +
|
params_dds.push_back("out_altvoltage2_TX1_Q_F1_frequency=" +
|
||||||
std::to_string(freq_dds_tx_hz_));
|
std::to_string(freq_dds_tx_hz_));
|
||||||
params_dds.push_back("out_altvoltage2_TX1_Q_F1_phase=" +
|
params_dds.push_back("out_altvoltage2_TX1_Q_F1_phase=" +
|
||||||
|
@ -296,13 +296,13 @@ bool ad936x_iio_custom::config_ad9361_dds(uint64_t freq_rf_tx_hz_,
|
||||||
{
|
{
|
||||||
params_phy.push_back("out_voltage1_hardwaregain=" +
|
params_phy.push_back("out_voltage1_hardwaregain=" +
|
||||||
std::to_string(-tx_attenuation_db_));
|
std::to_string(-tx_attenuation_db_));
|
||||||
//disable the other TX
|
// disable the other TX
|
||||||
params_phy.push_back("out_voltage0_hardwaregain=" +
|
params_phy.push_back("out_voltage0_hardwaregain=" +
|
||||||
std::to_string(-disabled_tx_attenuation));
|
std::to_string(-disabled_tx_attenuation));
|
||||||
|
|
||||||
configure_params(phy, params_phy);
|
configure_params(phy, params_phy);
|
||||||
|
|
||||||
//DDS TX CH2 I (tone #1)
|
// DDS TX CH2 I (tone #1)
|
||||||
params_dds.push_back("out_altvoltage4_TX2_I_F1_frequency=" +
|
params_dds.push_back("out_altvoltage4_TX2_I_F1_frequency=" +
|
||||||
std::to_string(freq_dds_tx_hz_));
|
std::to_string(freq_dds_tx_hz_));
|
||||||
params_dds.push_back("out_altvoltage4_TX2_I_F1_phase=" +
|
params_dds.push_back("out_altvoltage4_TX2_I_F1_phase=" +
|
||||||
|
@ -310,7 +310,7 @@ bool ad936x_iio_custom::config_ad9361_dds(uint64_t freq_rf_tx_hz_,
|
||||||
params_dds.push_back("out_altvoltage4_TX2_I_F1_scale=" +
|
params_dds.push_back("out_altvoltage4_TX2_I_F1_scale=" +
|
||||||
std::to_string(scale_dds_));
|
std::to_string(scale_dds_));
|
||||||
params_dds.push_back("out_altvoltage4_TX2_I_F1_raw=1");
|
params_dds.push_back("out_altvoltage4_TX2_I_F1_raw=1");
|
||||||
//DDS TX CH2 Q (tone #1)
|
// DDS TX CH2 Q (tone #1)
|
||||||
params_dds.push_back("out_altvoltage6_TX2_Q_F1_frequency=" +
|
params_dds.push_back("out_altvoltage6_TX2_Q_F1_frequency=" +
|
||||||
std::to_string(freq_dds_tx_hz_));
|
std::to_string(freq_dds_tx_hz_));
|
||||||
params_dds.push_back("out_altvoltage6_TX2_Q_F1_phase=" +
|
params_dds.push_back("out_altvoltage6_TX2_Q_F1_phase=" +
|
||||||
|
@ -549,7 +549,7 @@ bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PlutoTxEnable(false); //power down the TX LO to reduce interferences
|
PlutoTxEnable(false); // power down the TX LO to reduce interferences
|
||||||
}
|
}
|
||||||
|
|
||||||
int set_filter_ret = ad9361_set_bb_rate(phy, sample_rate_sps);
|
int set_filter_ret = ad9361_set_bb_rate(phy, sample_rate_sps);
|
||||||
|
@ -564,7 +564,7 @@ bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_,
|
||||||
// std::cout << "Warning: Unable to set AD936x RX filter parameters!\n";
|
// std::cout << "Warning: Unable to set AD936x RX filter parameters!\n";
|
||||||
// }
|
// }
|
||||||
|
|
||||||
//testing: set manual RX filter chain
|
// testing: set manual RX filter chain
|
||||||
// unsigned long RX_analog_bb_lpf_stop_hz = 1000000;
|
// unsigned long RX_analog_bb_lpf_stop_hz = 1000000;
|
||||||
// unsigned long TX_analog_bb_lpf_stop_hz = 1000000;
|
// unsigned long TX_analog_bb_lpf_stop_hz = 1000000;
|
||||||
//
|
//
|
||||||
|
@ -588,7 +588,7 @@ bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_,
|
||||||
name << "voltage";
|
name << "voltage";
|
||||||
name << 0;
|
name << 0;
|
||||||
struct iio_channel *phy_ch;
|
struct iio_channel *phy_ch;
|
||||||
phy_ch = iio_device_find_channel(phy, name.str().c_str(), false); //false means RX
|
phy_ch = iio_device_find_channel(phy, name.str().c_str(), false); // false means RX
|
||||||
if (!phy_ch)
|
if (!phy_ch)
|
||||||
{
|
{
|
||||||
std::cerr << "Could not find AD9361 phy channel: " << name.str() << "\n";
|
std::cerr << "Could not find AD9361 phy channel: " << name.str() << "\n";
|
||||||
|
@ -639,7 +639,7 @@ bool ad936x_iio_custom::init_config_ad9361_rx(long long bandwidth_,
|
||||||
name << "voltage";
|
name << "voltage";
|
||||||
name << 1;
|
name << 1;
|
||||||
struct iio_channel *phy_ch;
|
struct iio_channel *phy_ch;
|
||||||
phy_ch = iio_device_find_channel(phy, name.str().c_str(), false); //false means RX
|
phy_ch = iio_device_find_channel(phy, name.str().c_str(), false); // false means RX
|
||||||
if (!phy_ch)
|
if (!phy_ch)
|
||||||
{
|
{
|
||||||
std::cerr << "Could not find AD9361 phy channel: " << name.str() << "\n";
|
std::cerr << "Could not find AD9361 phy channel: " << name.str() << "\n";
|
||||||
|
@ -773,7 +773,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;
|
||||||
double gain_dB; //gain in dB
|
double gain_dB; // gain in dB
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
if (ch_num == 0)
|
if (ch_num == 0)
|
||||||
{
|
{
|
||||||
|
@ -804,7 +804,7 @@ double ad936x_iio_custom::get_rx_gain(int ch_num)
|
||||||
bool ad936x_iio_custom::calibrate(int ch, double bw_hz)
|
bool ad936x_iio_custom::calibrate(int ch, double bw_hz)
|
||||||
{
|
{
|
||||||
if (check_device() == false) return false;
|
if (check_device() == false) return false;
|
||||||
//todo
|
// todo
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -889,7 +889,7 @@ void ad936x_iio_custom::PlutoTxEnable(bool txon)
|
||||||
int ret;
|
int ret;
|
||||||
if (txon == false)
|
if (txon == false)
|
||||||
{
|
{
|
||||||
ret = iio_channel_attr_write_bool(iio_device_find_channel(phy, "altvoltage1", true), "powerdown", true); //turn off TX LO
|
ret = iio_channel_attr_write_bool(iio_device_find_channel(phy, "altvoltage1", true), "powerdown", true); // turn off TX LO
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to write altvoltage1 powerdown: " << ret << std::endl;
|
std::cerr << "Failed to write altvoltage1 powerdown: " << ret << std::endl;
|
||||||
|
@ -897,7 +897,7 @@ void ad936x_iio_custom::PlutoTxEnable(bool txon)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = iio_channel_attr_write_bool(iio_device_find_channel(phy, "altvoltage1", true), "powerdown", false); //turn on TX LO
|
ret = iio_channel_attr_write_bool(iio_device_find_channel(phy, "altvoltage1", true), "powerdown", false); // turn on TX LO
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to write altvoltage1 powerdown: " << ret << std::endl;
|
std::cerr << "Failed to write altvoltage1 powerdown: " << ret << std::endl;
|
||||||
|
@ -909,10 +909,10 @@ 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];
|
||||||
sprintf(pins, "0x27 0x%x0", p); //direct access to AD9361 registers... WARNING!
|
sprintf(pins, "0x27 0x%x0", p); // direct access to AD9361 registers... WARNING!
|
||||||
pins[9] = 0;
|
pins[9] = 0;
|
||||||
int ret;
|
int ret;
|
||||||
//std::cout << "send: " << pins << " \n";
|
// std::cout << "send: " << pins << " \n";
|
||||||
if (check_device())
|
if (check_device())
|
||||||
{
|
{
|
||||||
ret = iio_device_debug_attr_write(phy, "direct_reg_access", pins);
|
ret = iio_device_debug_attr_write(phy, "direct_reg_access", pins);
|
||||||
|
@ -932,7 +932,7 @@ bool ad936x_iio_custom::select_rf_filter(std::string rf_filter)
|
||||||
// adi,gpo-manual-mode-enable-mask does not work...
|
// adi,gpo-manual-mode-enable-mask does not work...
|
||||||
// some software use the direct_reg_access (see https://github.com/g4eml/Langstone/blob/master/LangstoneGUI.c)
|
// some software use the direct_reg_access (see https://github.com/g4eml/Langstone/blob/master/LangstoneGUI.c)
|
||||||
|
|
||||||
//since plutosdr fw 31:
|
// since plutosdr fw 31:
|
||||||
// GPOs can be addressed individual 0..3 or altogether using 0xF as Identifier.
|
// GPOs can be addressed individual 0..3 or altogether using 0xF as Identifier.
|
||||||
//
|
//
|
||||||
// SYNTAX:
|
// SYNTAX:
|
||||||
|
@ -958,7 +958,7 @@ bool ad936x_iio_custom::select_rf_filter(std::string rf_filter)
|
||||||
|
|
||||||
if (rf_filter.compare("E1") == 0)
|
if (rf_filter.compare("E1") == 0)
|
||||||
{
|
{
|
||||||
//set gpio0 to switch L1 filter
|
// set gpio0 to switch L1 filter
|
||||||
// setPlutoGpo(plutoGpo);
|
// setPlutoGpo(plutoGpo);
|
||||||
ret = iio_device_debug_attr_write(phy, "gpo_set", "0 0");
|
ret = iio_device_debug_attr_write(phy, "gpo_set", "0 0");
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
@ -969,7 +969,7 @@ bool ad936x_iio_custom::select_rf_filter(std::string rf_filter)
|
||||||
}
|
}
|
||||||
else if (rf_filter.compare("E5E6") == 0)
|
else if (rf_filter.compare("E5E6") == 0)
|
||||||
{
|
{
|
||||||
//set gpio0 to switch L5/L6 filter (GPO0)
|
// set gpio0 to switch L5/L6 filter (GPO0)
|
||||||
// plutoGpo = plutoGpo | 0x10;
|
// plutoGpo = plutoGpo | 0x10;
|
||||||
// setPlutoGpo(plutoGpo); //set the Pluto GPO Pin
|
// setPlutoGpo(plutoGpo); //set the Pluto GPO Pin
|
||||||
ret = iio_device_debug_attr_write(phy, "gpo_set", "0 1");
|
ret = iio_device_debug_attr_write(phy, "gpo_set", "0 1");
|
||||||
|
@ -1018,20 +1018,20 @@ void ad936x_iio_custom::get_PPS_timestamp()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Get new PPS samplestamp and associate it to the corresponding uBlox TP message
|
// Get new PPS samplestamp and associate it to the corresponding uBlox TP message
|
||||||
while (receive_samples == true)
|
while (receive_samples == true)
|
||||||
{
|
{
|
||||||
std::cout << "[" << pps.samplestamp << "][o:" << pps.overflow_reg << "] uBlox time message received with TOW=" << tow.tow_ms << "\n";
|
std::cout << "[" << pps.samplestamp << "][o:" << pps.overflow_reg << "] uBlox time message received with TOW=" << tow.tow_ms << "\n";
|
||||||
LOG(INFO) << "[" << pps.samplestamp << "][o:" << pps.overflow_reg << "] uBlox time message received with TOW=" << tow.tow_ms << "\n";
|
LOG(INFO) << "[" << pps.samplestamp << "][o:" << pps.overflow_reg << "] uBlox time message received with TOW=" << tow.tow_ms << "\n";
|
||||||
//write timestamp information to timestamp metadata file:
|
// write timestamp information to timestamp metadata file:
|
||||||
//uint64_t: absolute sample counter from the beginning of sample capture associated to the rising edge of the PPS signal
|
// uint64_t: absolute sample counter from the beginning of sample capture associated to the rising edge of the PPS signal
|
||||||
// ppstimefile.write(reinterpret_cast<char *>(&pps.samplestamp), sizeof(uint64_t));
|
// ppstimefile.write(reinterpret_cast<char *>(&pps.samplestamp), sizeof(uint64_t));
|
||||||
//int32_t: Galileo/GPS Week Number associated to the rising edge of PPS signal
|
// int32_t: Galileo/GPS Week Number associated to the rising edge of PPS signal
|
||||||
// ppstimefile.write(reinterpret_cast<char *>(&tow.week), sizeof(int32_t));
|
// ppstimefile.write(reinterpret_cast<char *>(&tow.week), sizeof(int32_t));
|
||||||
//int32_t: Galileo/GPS TOW associated to the rising edge of PPS signal
|
// int32_t: Galileo/GPS TOW associated to the rising edge of PPS signal
|
||||||
// ppstimefile.write(reinterpret_cast<char *>(&tow.tow_ms), sizeof(int32_t));
|
// ppstimefile.write(reinterpret_cast<char *>(&tow.tow_ms), sizeof(int32_t));
|
||||||
//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)
|
||||||
|
@ -1066,10 +1066,10 @@ 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
|
||||||
free_buffers.clear();
|
free_buffers.clear();
|
||||||
used_buffers.clear();
|
used_buffers.clear();
|
||||||
//preallocate buffers and use queues
|
// preallocate buffers and use queues
|
||||||
std::cerr << "Allocating memory..\n";
|
std::cerr << "Allocating memory..\n";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -1084,33 +1084,33 @@ bool ad936x_iio_custom::start_sample_rx(bool ppsmode)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//prepare capture channels
|
// prepare capture channels
|
||||||
std::vector<std::string> channels;
|
std::vector<std::string> channels;
|
||||||
switch (n_channels)
|
switch (n_channels)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
channels.push_back("voltage0"); //Channel 0 I
|
channels.push_back("voltage0"); // Channel 0 I
|
||||||
channels.push_back("voltage1"); //Channel 0 Q
|
channels.push_back("voltage1"); // Channel 0 Q
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
channels.push_back("voltage0"); //Channel 0 I
|
channels.push_back("voltage0"); // Channel 0 I
|
||||||
channels.push_back("voltage1"); //Channel 0 Q
|
channels.push_back("voltage1"); // Channel 0 Q
|
||||||
channels.push_back("voltage2"); //Channel 1 I
|
channels.push_back("voltage2"); // Channel 1 I
|
||||||
channels.push_back("voltage3"); //Channel 1 Q
|
channels.push_back("voltage3"); // Channel 1 Q
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
channels.push_back("voltage0"); //Channel 0 I
|
channels.push_back("voltage0"); // Channel 0 I
|
||||||
channels.push_back("voltage1"); //Channel 0 Q
|
channels.push_back("voltage1"); // Channel 0 Q
|
||||||
}
|
}
|
||||||
|
|
||||||
receive_samples = true;
|
receive_samples = true;
|
||||||
//start sample capture thread
|
// start sample capture thread
|
||||||
capture_samples_thread = std::thread(&ad936x_iio_custom::capture, this, channels);
|
capture_samples_thread = std::thread(&ad936x_iio_custom::capture, this, channels);
|
||||||
//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)
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "ad936x_iio_samples.h"
|
#include "ad936x_iio_samples.h"
|
||||||
#include <ad9361.h> //multichip sync and high level functions
|
#include <ad9361.h> // multichip sync and high level functions
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -114,13 +114,13 @@ private:
|
||||||
void PlutoTxEnable(bool txon);
|
void PlutoTxEnable(bool txon);
|
||||||
void setPlutoGpo(int p);
|
void setPlutoGpo(int p);
|
||||||
|
|
||||||
//Device structure
|
// Device structure
|
||||||
struct iio_context *ctx;
|
struct iio_context *ctx;
|
||||||
struct iio_device *phy;
|
struct iio_device *phy;
|
||||||
struct iio_device *stream_dev;
|
struct iio_device *stream_dev;
|
||||||
struct iio_device *dds_dev;
|
struct iio_device *dds_dev;
|
||||||
|
|
||||||
//stream
|
// stream
|
||||||
|
|
||||||
uint64_t sample_rate_sps;
|
uint64_t sample_rate_sps;
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ private:
|
||||||
boost::atomic<bool> receive_samples;
|
boost::atomic<bool> receive_samples;
|
||||||
|
|
||||||
boost::atomic<bool> fpga_overflow;
|
boost::atomic<bool> fpga_overflow;
|
||||||
//using queues of smart pointers to preallocated buffers
|
// using queues of smart pointers to preallocated buffers
|
||||||
Concurrent_Queue<std::shared_ptr<ad936x_iio_samples>> free_buffers;
|
Concurrent_Queue<std::shared_ptr<ad936x_iio_samples>> free_buffers;
|
||||||
Concurrent_Queue<std::shared_ptr<ad936x_iio_samples>> used_buffers;
|
Concurrent_Queue<std::shared_ptr<ad936x_iio_samples>> used_buffers;
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ public:
|
||||||
uint32_t n_interleaved_iq_samples;
|
uint32_t n_interleaved_iq_samples;
|
||||||
uint16_t n_channels;
|
uint16_t n_channels;
|
||||||
uint16_t step_bytes;
|
uint16_t step_bytes;
|
||||||
char buffer[IIO_DEFAULTAD936XAPIFIFOSIZE_SAMPLES * 4 * 4]; //max 16 bits samples per buffer (4 channels, 2-bytes per I + 2-bytes per Q)
|
char buffer[IIO_DEFAULTAD936XAPIFIFOSIZE_SAMPLES * 4 * 4]; // max 16 bits samples per buffer (4 channels, 2-bytes per I + 2-bytes per Q)
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
class PpsSamplestamp
|
class PpsSamplestamp
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uint64_t samplestamp; //PPS rising edge samples counter from the beginning of rx stream opperation. Notice that it is reseted to zero if sample buffer overflow is detected on the FPGA side
|
uint64_t samplestamp; // PPS rising edge samples counter from the beginning of rx stream opperation. Notice that it is reseted to zero if sample buffer overflow is detected on the FPGA side
|
||||||
uint32_t overflow_reg; // >0 indicates overflow situation in the FPGA RX buffer
|
uint32_t overflow_reg; // >0 indicates overflow situation in the FPGA RX buffer
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -52,16 +52,16 @@ bool pps_tcp_rx::send_cmd(std::string cmd)
|
||||||
}
|
}
|
||||||
void pps_tcp_rx::receive_pps(std::string ip_address, int port)
|
void pps_tcp_rx::receive_pps(std::string ip_address, int port)
|
||||||
{
|
{
|
||||||
//create a message buffer
|
// create a message buffer
|
||||||
char buf[1500];
|
char buf[1500];
|
||||||
//setup a socket and connection tools
|
// setup a socket and connection tools
|
||||||
sockaddr_in sendSockAddr;
|
sockaddr_in sendSockAddr;
|
||||||
sendSockAddr.sin_family = AF_INET;
|
sendSockAddr.sin_family = AF_INET;
|
||||||
sendSockAddr.sin_addr.s_addr =
|
sendSockAddr.sin_addr.s_addr =
|
||||||
inet_addr(ip_address.c_str());
|
inet_addr(ip_address.c_str());
|
||||||
sendSockAddr.sin_port = htons(port);
|
sendSockAddr.sin_port = htons(port);
|
||||||
clientSd = socket(AF_INET, SOCK_STREAM, 0);
|
clientSd = socket(AF_INET, SOCK_STREAM, 0);
|
||||||
//try to connect...
|
// try to connect...
|
||||||
int status = connect(clientSd,
|
int status = connect(clientSd,
|
||||||
(sockaddr *)&sendSockAddr, sizeof(sendSockAddr));
|
(sockaddr *)&sendSockAddr, sizeof(sendSockAddr));
|
||||||
if (status < 0)
|
if (status < 0)
|
||||||
|
@ -84,8 +84,8 @@ void pps_tcp_rx::receive_pps(std::string ip_address, int port)
|
||||||
{
|
{
|
||||||
if (new_pps_line.length() > 0)
|
if (new_pps_line.length() > 0)
|
||||||
{
|
{
|
||||||
//std::cout << "pps_tcp_rx debug: " << new_pps_line << "\n";
|
// std::cout << "pps_tcp_rx debug: " << new_pps_line << "\n";
|
||||||
//parse string and push PPS data to the PPS queue
|
// parse string and push PPS data to the PPS queue
|
||||||
std::stringstream ss(new_pps_line);
|
std::stringstream ss(new_pps_line);
|
||||||
std::vector<std::string> data;
|
std::vector<std::string> data;
|
||||||
while (ss.good())
|
while (ss.good())
|
||||||
|
@ -97,7 +97,7 @@ void pps_tcp_rx::receive_pps(std::string ip_address, int port)
|
||||||
if (data.size() >= 2)
|
if (data.size() >= 2)
|
||||||
{
|
{
|
||||||
PpsSamplestamp new_pps;
|
PpsSamplestamp new_pps;
|
||||||
//sample counter
|
// sample counter
|
||||||
std::size_t found = data.at(0).find("sc=");
|
std::size_t found = data.at(0).find("sc=");
|
||||||
if (found != std::string::npos)
|
if (found != std::string::npos)
|
||||||
{
|
{
|
||||||
|
@ -131,7 +131,7 @@ void pps_tcp_rx::receive_pps(std::string ip_address, int port)
|
||||||
std::cout << "pps_tcp_rx debug: o parse error str " << data.at(1) << "\n";
|
std::cout << "pps_tcp_rx debug: o parse error str " << data.at(1) << "\n";
|
||||||
}
|
}
|
||||||
Pps_queue->push(new_pps);
|
Pps_queue->push(new_pps);
|
||||||
//std::cout << "pps_tcp_rx debug: pps pushed!\n";
|
// std::cout << "pps_tcp_rx debug: pps pushed!\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue