1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2025-10-20 01:57:41 +00:00

New signal source for real-time operation with Universal Hardware Driver (UHD) devices. RF Real-time milestone reached!!

git-svn-id: https://svn.code.sf.net/p/gnss-sdr/code/trunk@180 64b25241-fba3-4117-9849-534c7e92360d
This commit is contained in:
Javier Arribas
2012-03-02 18:50:21 +00:00
parent c428fe21c5
commit 1cb02b5df2
8 changed files with 377 additions and 26 deletions

View File

@@ -1,5 +1,6 @@
project : build-dir ../../../../build ;
obj file_signal_source : file_signal_source.cc ;
obj uhd_signal_source : uhd_signal_source.cc ;
#obj usrp1_signal_source : usrp1_signal_source.cc ;

View File

@@ -0,0 +1,232 @@
/*!
* \file uhd_signal_source.cc
* \brief Universal Hardware Driver signal source
* \author Javier Arribas, 2012. jarribas(at)cttc.es
*
* Detailed description of the file here if needed.
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* 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 <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#include "uhd_signal_source.h"
//#include <uhd/usrp/multi_usrp.hpp>
#include <gnuradio/gr_uhd_usrp_source.h>
#include <uhd/types/device_addr.hpp>
#include <uhd/exception.hpp>
#include <boost/program_options.hpp>
#include <gnuradio/gr_file_sink.h>
#include "configuration_interface.h"
#include "gnss_sdr_valve.h"
#include <glog/log_severity.h>
#include <glog/logging.h>
#include <iostream>
using google::LogMessage;
UhdSignalSource::UhdSignalSource(ConfigurationInterface* configuration,
std::string role, unsigned int in_stream, unsigned int out_stream,
gr_msg_queue_sptr queue) :
role_(role), in_stream_(in_stream), out_stream_(out_stream),
queue_(queue)
{
// DUMP PARAMETERS
std::string empty = "";
std::string default_dump_file = "./data/signal_source.dat";
std::string default_item_type = "short";
samples_ = configuration->property(role + ".samples", 0);
dump_ = configuration->property(role + ".dump", false);
dump_filename_ = configuration->property(role + ".dump_filename",
default_dump_file);
// UHD PARAMETERS
uhd::device_addr_t dev_addr;
device_address_= configuration->property(role + ".device_address",empty);
if (empty.compare(empty)!=0)
{
dev_addr["addr0"]=device_address_;
}
subdevice_=configuration->property(role + ".subdevice",empty);
freq_ = configuration->property(role + ".freq", (double)1.57542e9);
gain_ = configuration->property(role + ".gain", (double)50.0);
sample_rate_ = configuration->property(role + ".sampling_frequency", (double)4.0e6);
IF_bandwidth_hz_ = configuration->property(role + ".IF_bandwidth_hz", sample_rate_/2);
item_type_ = configuration->property(role + ".item_type",
default_item_type);
if (item_type_.compare("short") == 0)
{
item_size_ = sizeof(short);
}
else if (item_type_.compare("gr_complex") == 0)
{
// 1. Make the uhd driver instance
//uhd_source_= uhd::usrp::multi_usrp::make(dev_addr);
// sigle source
// * \param device_addr the address to identify the hardware
// * \param io_type the desired output data type
uhd_source_= uhd_make_usrp_source(dev_addr,uhd::stream_args_t("fc32"));
// 2.1 set sampling clock reference
//Lock mboard clocks internal, external, or mimo
std::string clk_reference="internal";
uhd_source_->set_clock_source(clk_reference);
// 2.2 set sampling rate
uhd_source_->set_samp_rate(sample_rate_);
std::cout << boost::format("Actual RX Rate: %f [SPS]...") % (uhd_source_->get_samp_rate()) << std::endl << std::endl;
DLOG(INFO) << boost::format("Actual RX Rate: %f [SPS]...") % (uhd_source_->get_samp_rate()) << std::endl << std::endl;
// 3. set rx frequency
uhd_source_->set_center_freq(freq_);
std::cout << boost::format("Actual RX Freq: %f [Hz]...") % (uhd_source_->get_center_freq()) << std::endl << std::endl;
DLOG(INFO) << boost::format("Actual RX Freq: %f [Hz]...") % (uhd_source_->get_center_freq()) << std::endl << std::endl;
// 4. set rx gain
uhd_source_->set_gain(gain_);
std::cout << boost::format("Actual RX Gain: %f dB...") % uhd_source_->get_gain() << std::endl << std::endl;
DLOG(INFO) << boost::format("Actual RX Gain: %f dB...") % uhd_source_->get_gain() << std::endl << std::endl;
//5. set the IF filter bandwidth
std::cout << boost::format("Setting RX Bandwidth: %f [Hz]...") % IF_bandwidth_hz_ << std::endl;
uhd_source_->set_bandwidth(IF_bandwidth_hz_);
///std::cout << boost::format("Actual RX Bandwidth: %f MHz...") % uhd_source_->get_rx_bandwidth() << std::endl << std::endl;
//DLOG(INFO) << boost::format("Actual RX Bandwidth: %f MHz...") % uhd_source_->get_rx_bandwidth() << std::endl << std::endl;
//set the antenna (optional)
//uhd_source_->set_antenna(ant);
//LO lock status
//Check Ref and LO Lock detect
//std::vector<std::string> sensor_names;
//sensor_names = uhd_source_->get_rx_sensor_names(0);
//if (std::find(sensor_names.begin(), sensor_names.end(), "lo_locked") != sensor_names.end()) {
// uhd::sensor_value_t lo_locked = uhd_source_->get_rx_sensor("lo_locked",0);
// std::cout << boost::format("Checking RX: %s ...") % lo_locked.to_pp_string() << std::endl;
//UHD_ASSERT_THROW(lo_locked.to_bool());
//}
uhd_source_->set_subdev_spec(subdevice_);
}
else
{
LOG_AT_LEVEL(WARNING) << item_type_
<< " unrecognized item type. Using short.";
item_size_ = sizeof(short);
}
if (samples_ != 0)
{
DLOG(INFO) << "Send STOP signal after " << samples_ << " samples";
valve_ = gnss_sdr_make_valve(item_size_, samples_, queue_);
DLOG(INFO) << "valve(" << valve_->unique_id() << ")";
}
if (dump_)
{
DLOG(INFO) << "Dumping output into file " << dump_filename_;
file_sink_ = gr_make_file_sink(item_size_, dump_filename_.c_str());
DLOG(INFO) << "file_sink(" << file_sink_->unique_id() << ")";
}
}
UhdSignalSource::~UhdSignalSource()
{
}
void UhdSignalSource::connect(gr_top_block_sptr top_block)
{
if (samples_ != 0)
{
top_block->connect(uhd_source_, 0, valve_, 0);
DLOG(INFO) << "connected usrp source to valve";
if (dump_)
{
top_block->connect(valve_, 0, file_sink_, 0);
DLOG(INFO) << "connected valve to file sink";
}
}
else
{
if (dump_)
{
top_block->connect(uhd_source_, 0, file_sink_, 0);
DLOG(INFO) << "connected usrp source to file sink";
}
}
}
void UhdSignalSource::disconnect(gr_top_block_sptr top_block)
{
if (samples_ != 0)
{
top_block->disconnect(uhd_source_, 0, valve_, 0);
if (dump_)
{
top_block->disconnect(valve_, 0, file_sink_, 0);
}
}
else
{
if (dump_)
{
top_block->disconnect(uhd_source_, 0, file_sink_, 0);
}
}
}
gr_basic_block_sptr UhdSignalSource::get_left_block()
{
LOG_AT_LEVEL(WARNING) << "Trying to get signal source left block.";
return gr_basic_block_sptr();
}
gr_basic_block_sptr UhdSignalSource::get_right_block()
{
if (samples_ != 0)
{
return valve_;
}
else
{
return uhd_source_;
}
}

View File

@@ -0,0 +1,107 @@
/*!
* \file uhd_signal_source.h
* \brief Universal Hardware Driver signal source
* \author Javier Arribas, 2012. jarribas(at)cttc.es
*
* Detailed description of the file here if needed.
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2012 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
*
* 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 <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#ifndef UHD_SIGNAL_SOURCE_H_
#define UHD_SIGNAL_SOURCE_H_
#include <boost/shared_ptr.hpp>
//#include <uhd/usrp/multi_usrp.hpp>
#include <gnuradio/gr_uhd_usrp_source.h>
#include <gnuradio/gr_hier_block2.h>
#include <gnuradio/gr_msg_queue.h>
#include "gnss_block_interface.h"
class ConfigurationInterface;
class UhdSignalSource: public GNSSBlockInterface
{
public:
UhdSignalSource(ConfigurationInterface* configuration,
std::string role, unsigned int in_stream,
unsigned int out_stream, gr_msg_queue_sptr queue);
virtual ~UhdSignalSource();
std::string role()
{
return role_;
}
std::string implementation()
{
return "UhdSignalSource";
}
size_t item_size()
{
return item_size_;
}
void connect(gr_top_block_sptr top_block);
void disconnect(gr_top_block_sptr top_block);
gr_basic_block_sptr get_left_block();
gr_basic_block_sptr get_right_block();
private:
std::string role_;
// UHD SETTINGS
std::string device_address_;
std::string subdevice_;
double sample_rate_;
unsigned int in_stream_;
unsigned int out_stream_;
double freq_;
double gain_;
double IF_bandwidth_hz_;
std::string item_type_;
size_t item_size_;
long samples_;
bool dump_;
std::string dump_filename_;
//uhd::usrp::multi_usrp::sptr uhd_source_;
//boost::shared_ptr<uhd_usrp_source>
boost::shared_ptr<uhd_usrp_source> uhd_source_;
gr_block_sptr valve_;
gr_block_sptr file_sink_;
gr_msg_queue_sptr queue_;
};
#endif /*UHD_SIGNAL_SOURCE_H_*/

View File

@@ -47,7 +47,7 @@
#include "null_sink_output_filter.h"
#include "file_output_filter.h"
#include "channel.h"
//#include "usrp1_signal_source.h"
#include "uhd_signal_source.h"
#include "signal_conditioner.h"
#include "direct_resampler_conditioner.h"
#include "fir_filter.h"
@@ -250,13 +250,11 @@ GNSSBlockInterface* GNSSBlockFactory::GetBlock(
out_streams, queue);
}
// else if (implementation.compare("USRP1_Signal_Source") == 0)
// {
// block = new Usrp1SignalSource(configuration, role, in_streams,
// out_streams, queue);
// }
//! \todo Create a UHD block
else if (implementation.compare("UHD_Signal_Source") == 0)
{
block = new UhdSignalSource(configuration, role, in_streams,
out_streams, queue);
}
// DATA TYPE ADAPTER -----------------------------------------------------------

View File

@@ -25,7 +25,7 @@ exe gnss-sdr : main.cc
../algorithms/resampler/gnuradio_blocks//direct_resampler_conditioner_cc
#../algorithms/resampler/gnuradio_blocks//direct_resampler_conditioner_ss
../algorithms/signal_source/adapters//file_signal_source
#../algorithms/signal_source/adapters//usrp1_signal_source
../algorithms/signal_source/adapters//uhd_signal_source
../algorithms/telemetry_decoder/adapters//gps_l1_ca_telemetry_decoder
../algorithms/telemetry_decoder/gnuradio_blocks//gps_l1_ca_telemetry_decoder_cc
../algorithms/telemetry_decoder/libs//gps_l1_ca_subframe_fsm
@@ -57,7 +57,9 @@ exe gnss-sdr : main.cc
../core/system_parameters//gnss_synchro
../..//gflags
../..//glog
../..//gnuradio-core ;
../..//gnuradio-core
../..//uhd
../..//gnuradio-uhd ;
#../..//gnuradio-usrp ;
install ../../install : gnss-sdr ;

View File

@@ -26,7 +26,7 @@ exe run_tests : test_main.cc
../algorithms/resampler/gnuradio_blocks//direct_resampler_conditioner_cc
#../algorithms/resampler/gnuradio_blocks//direct_resampler_conditioner_ss
../algorithms/signal_source/adapters//file_signal_source
#../algorithms/signal_source/adapters//usrp1_signal_source
../algorithms/signal_source/adapters//uhd_signal_source
../algorithms/telemetry_decoder/adapters//gps_l1_ca_telemetry_decoder
../algorithms/telemetry_decoder/gnuradio_blocks//gps_l1_ca_telemetry_decoder_cc
../algorithms/telemetry_decoder/libs//gps_l1_ca_subframe_fsm
@@ -58,7 +58,9 @@ exe run_tests : test_main.cc
../core/system_parameters//gnss_synchro
../..//gflags
../..//glog
../..//gnuradio-core
../..//gnuradio-core
../..//uhd
../..//gnuradio-uhd
../..//gtest : <include>$(GTEST_DIR)/include ;
install ../../install : run_tests ;