mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-10-27 21:47:39 +00:00
Optimizing custom UDP packet source and applying code style
This commit is contained in:
@@ -1,13 +1,12 @@
|
||||
/*!
|
||||
* \file rtl_tcp_signal_source.cc
|
||||
* \brief Signal source for the Realtek RTL2832U USB dongle DVB-T receiver
|
||||
* over TCP.
|
||||
* (see http://sdr.osmocom.org/trac/wiki/rtl-sdr for more information)
|
||||
* \author Anthony Arnold, 2015. anthony.arnold(at)uqconnect.edu.au
|
||||
* \file udp_signal_source.cc
|
||||
*
|
||||
* \brief Receives ip frames containing samples in UDP frame encapsulation
|
||||
* using a high performance packet capture library (libpcap)
|
||||
* \author Javier Arribas jarribas (at) cttc.es
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)
|
||||
* Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors)
|
||||
*
|
||||
* GNSS-SDR is a software defined Global Navigation
|
||||
* Satellite Systems receiver
|
||||
@@ -30,6 +29,7 @@
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#include "udp_signal_source.h"
|
||||
#include "configuration_interface.h"
|
||||
#include "GPS_L1_CA.h"
|
||||
@@ -64,58 +64,46 @@ UDPSignalSource::UDPSignalSource(ConfigurationInterface* configuration,
|
||||
|
||||
|
||||
RF_channels_ = configuration->property(role + ".RF_channels", 1);
|
||||
select_single_channel_ = configuration->property(role + ".select_single_channel", 0);
|
||||
channels_in_udp_= configuration->property(role + ".channels_in_udp", 1);
|
||||
IQ_swap_= configuration->property(role + ".IQ_swap", false);
|
||||
channels_in_udp_ = configuration->property(role + ".channels_in_udp", 1);
|
||||
IQ_swap_ = configuration->property(role + ".IQ_swap", false);
|
||||
|
||||
std::string default_sample_type = "cbyte";
|
||||
std::string sample_type = configuration->property(role + ".sample_type", default_sample_type);
|
||||
item_type_ = configuration->property(role + ".item_type", default_item_type);
|
||||
|
||||
if (sample_type.compare("cbyte")==0)
|
||||
{
|
||||
udp_gnss_rx_source_ = raw_ip_packet_source::make(capture_device, address, port, payload_bytes);
|
||||
demux_=gr::blocks::deinterleave::make(sizeof(char),1);
|
||||
}else{
|
||||
std::cout<<"WARNING: Requested UDP sample type unsuported, setting sample type to cbyte\n";
|
||||
udp_gnss_rx_source_ = raw_ip_packet_source::make(capture_device, address, port, payload_bytes);
|
||||
demux_=gr::blocks::deinterleave::make(sizeof(char),1);
|
||||
}
|
||||
|
||||
//create I, Q -> gr_complex type conversion blocks
|
||||
for (int n = 0; n < (channels_in_udp_ * 2); n++)
|
||||
{
|
||||
char_to_float_.push_back(gr::blocks::char_to_float::make());
|
||||
}
|
||||
|
||||
for (int n = 0; n < channels_in_udp_; n++)
|
||||
{
|
||||
float_to_complex_.push_back(gr::blocks::float_to_complex::make());
|
||||
}
|
||||
|
||||
if (channels_in_udp_>RF_channels_)
|
||||
{
|
||||
for (int n = 0; n < channels_in_udp_; n++)
|
||||
{
|
||||
null_sinks_.push_back(gr::blocks::null_sink::make(sizeof(gr_complex)));
|
||||
}
|
||||
}else
|
||||
{
|
||||
std::cout<<"Configuration error: RF_channels<channels_in_use"<<std::endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
//output item size is always gr_complex
|
||||
item_size_ = sizeof(gr_complex);
|
||||
|
||||
udp_gnss_rx_source_ = gr_complex_ip_packet_source::make(capture_device,
|
||||
address,
|
||||
port,
|
||||
payload_bytes,
|
||||
channels_in_udp_,
|
||||
sample_type,
|
||||
item_size_,
|
||||
IQ_swap_);
|
||||
|
||||
if (channels_in_udp_ >= RF_channels_)
|
||||
{
|
||||
for (int n = 0; n < channels_in_udp_; n++)
|
||||
{
|
||||
null_sinks_.push_back(gr::blocks::null_sink::make(sizeof(gr_complex)));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Configuration error: RF_channels<channels_in_use" << std::endl;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
||||
if (dump_)
|
||||
{
|
||||
for (int n = 0; n < channels_in_udp_; n++)
|
||||
{
|
||||
DLOG(INFO) << "Dumping output into file " << (dump_filename_+"c_h"+std::to_string(n)+".bin");
|
||||
file_sink_.push_back(gr::blocks::file_sink::make(item_size_, (dump_filename_+"_ch"+std::to_string(n)+".bin").c_str()));
|
||||
}
|
||||
{
|
||||
DLOG(INFO) << "Dumping output into file " << (dump_filename_ + "c_h" + std::to_string(n) + ".bin");
|
||||
file_sink_.push_back(gr::blocks::file_sink::make(item_size_, (dump_filename_ + "_ch" + std::to_string(n) + ".bin").c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -126,92 +114,40 @@ UDPSignalSource::~UDPSignalSource()
|
||||
|
||||
void UDPSignalSource::connect(gr::top_block_sptr top_block)
|
||||
{
|
||||
top_block->connect(udp_gnss_rx_source_,0, demux_,0);
|
||||
DLOG(INFO)<<"connected udp_source to demux"<<std::endl;
|
||||
for (int n = 0; n < (channels_in_udp_ * 2); n++)
|
||||
{
|
||||
|
||||
top_block->connect(demux_, n, char_to_float_.at(n), 0);
|
||||
DLOG(INFO) << "connected demux to char_to_float CH" << n;
|
||||
}
|
||||
//connect null sinks to unused streams
|
||||
for (int n = 0; n < channels_in_udp_; n++)
|
||||
{
|
||||
if (!IQ_swap_)
|
||||
{
|
||||
top_block->connect(char_to_float_.at(n * 2), 0, float_to_complex_.at(n), 0);
|
||||
top_block->connect(char_to_float_.at(n * 2 + 1), 0, float_to_complex_.at(n), 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
top_block->connect(char_to_float_.at(n * 2), 0, float_to_complex_.at(n), 1);
|
||||
top_block->connect(char_to_float_.at(n * 2 + 1), 0, float_to_complex_.at(n), 0);
|
||||
}
|
||||
DLOG(INFO) << "connected char_to_float to float_to_complex_ CH" << n;
|
||||
top_block->connect(udp_gnss_rx_source_, n, null_sinks_.at(n), 0);
|
||||
}
|
||||
|
||||
//connect null sinks to unused streams
|
||||
if (channels_in_udp_>RF_channels_)
|
||||
{
|
||||
for (int n = 0; n < channels_in_udp_; n++)
|
||||
{
|
||||
top_block->connect(float_to_complex_.at(n),0,null_sinks_.at(n),0);
|
||||
}
|
||||
}
|
||||
DLOG(INFO) << "connected udp_source to null_sinks to enable the use of spare channels" << std::endl;
|
||||
|
||||
if (dump_)
|
||||
{
|
||||
for (int n = 0; n < channels_in_udp_; n++)
|
||||
{
|
||||
top_block->connect(float_to_complex_.at(n), 0, file_sink_.at(n), 0);
|
||||
DLOG(INFO) << "connected source to file sink";
|
||||
}
|
||||
{
|
||||
top_block->connect(udp_gnss_rx_source_, n, file_sink_.at(n), 0);
|
||||
DLOG(INFO) << "connected source to file sink";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void UDPSignalSource::disconnect(gr::top_block_sptr top_block)
|
||||
{
|
||||
|
||||
for (int n = 0; n < (channels_in_udp_ * 2); n++)
|
||||
{
|
||||
top_block->disconnect(demux_, n, char_to_float_.at(n), 0);
|
||||
DLOG(INFO) << "disconnect demux to char_to_float CH" << n;
|
||||
}
|
||||
//disconnect null sinks to unused streams
|
||||
for (int n = 0; n < channels_in_udp_; n++)
|
||||
{
|
||||
if (!IQ_swap_)
|
||||
{
|
||||
top_block->disconnect(char_to_float_.at(n * 2), 0, float_to_complex_.at(n), 0);
|
||||
top_block->disconnect(char_to_float_.at(n * 2 + 1), 0, float_to_complex_.at(n), 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
top_block->disconnect(char_to_float_.at(n * 2), 0, float_to_complex_.at(n), 1);
|
||||
top_block->disconnect(char_to_float_.at(n * 2 + 1), 0, float_to_complex_.at(n), 0);
|
||||
}
|
||||
DLOG(INFO) << "disconnect char_to_float to float_to_complex_ CH" << n;
|
||||
top_block->disconnect(udp_gnss_rx_source_, n, null_sinks_.at(n), 0);
|
||||
}
|
||||
|
||||
//disconnect null sinks to unused streams
|
||||
if (channels_in_udp_>RF_channels_)
|
||||
{
|
||||
for (int n = 0; n < channels_in_udp_; n++)
|
||||
{
|
||||
top_block->disconnect(float_to_complex_.at(n),0,null_sinks_.at(n),0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (dump_)
|
||||
{
|
||||
for (int n = 0; n < channels_in_udp_; n++)
|
||||
{
|
||||
top_block->disconnect(float_to_complex_.at(n), 0, file_sink_.at(n), 0);
|
||||
DLOG(INFO) << "disconnected source to file sink";
|
||||
for (int n = 0; n < channels_in_udp_; n++)
|
||||
{
|
||||
top_block->disconnect(udp_gnss_rx_source_, n, file_sink_.at(n), 0);
|
||||
DLOG(INFO) << "disconnected source to file sink";
|
||||
}
|
||||
}
|
||||
}
|
||||
top_block->disconnect(udp_gnss_rx_source_,0, demux_,0);
|
||||
DLOG(INFO)<<"disconnected udp_source to demux"<<std::endl;
|
||||
DLOG(INFO) << "disconnected udp_source" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
@@ -224,11 +160,10 @@ gr::basic_block_sptr UDPSignalSource::get_left_block()
|
||||
|
||||
gr::basic_block_sptr UDPSignalSource::get_right_block()
|
||||
{
|
||||
return get_right_block(select_single_channel_);
|
||||
return udp_gnss_rx_source_;
|
||||
}
|
||||
|
||||
gr::basic_block_sptr UDPSignalSource::get_right_block(int RF_channel)
|
||||
{
|
||||
return float_to_complex_.at(RF_channel);
|
||||
return udp_gnss_rx_source_;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/*!
|
||||
* \file rtl_tcp_signal_source.h
|
||||
* \brief Signal source which reads from rtl_tcp.
|
||||
* (see http://sdr.osmocom.org/trac/wiki/rtl-sdr for more information)
|
||||
* \author Anthony Arnold, 2015. anthony.arnold(at)uqconnect.edu.au
|
||||
* \file udp_signal_source.h
|
||||
*
|
||||
* \brief Receives ip frames containing samples in UDP frame encapsulation
|
||||
* using a high performance packet capture library (libpcap)
|
||||
* \author Javier Arribas jarribas (at) cttc.es
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)
|
||||
* Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors)
|
||||
*
|
||||
* GNSS-SDR is a software defined Global Navigation
|
||||
* Satellite Systems receiver
|
||||
@@ -29,18 +29,16 @@
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GNSS_SDR_UDP_SIGNAL_SOURCE_H
|
||||
#define GNSS_SDR_UDP_SIGNAL_SOURCE_H
|
||||
|
||||
#include "gnss_block_interface.h"
|
||||
#include "raw_ip_packet_source.h"
|
||||
#include "gr_complex_ip_packet_source.h"
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <gnuradio/msg_queue.h>
|
||||
#include <gnuradio/blocks/char_to_float.h>
|
||||
#include <gnuradio/blocks/file_sink.h>
|
||||
#include <gnuradio/blocks/null_sink.h>
|
||||
#include <gnuradio/blocks/deinterleave.h>
|
||||
#include <gnuradio/blocks/float_to_complex.h>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -90,7 +88,6 @@ private:
|
||||
|
||||
bool IQ_swap_;
|
||||
int RF_channels_;
|
||||
int select_single_channel_;
|
||||
int channels_in_udp_;
|
||||
unsigned int in_stream_;
|
||||
unsigned int out_stream_;
|
||||
@@ -99,12 +96,8 @@ private:
|
||||
size_t item_size_;
|
||||
bool dump_;
|
||||
std::string dump_filename_;
|
||||
std::vector<boost::shared_ptr<gr::block>> char_to_float_;
|
||||
std::vector<boost::shared_ptr<gr::block>> float_to_complex_;
|
||||
std::vector<boost::shared_ptr<gr::block>> null_sinks_;
|
||||
|
||||
raw_ip_packet_source::sptr udp_gnss_rx_source_;
|
||||
gr::blocks::deinterleave::sptr demux_;
|
||||
gr_complex_ip_packet_source::sptr udp_gnss_rx_source_;
|
||||
std::vector<boost::shared_ptr<gr::block>> file_sink_;
|
||||
boost::shared_ptr<gr::msg_queue> queue_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user