mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2024-12-12 11:10:33 +00:00
Refactored out rtl_tcp stuff to libs
This commit is contained in:
parent
6d16921845
commit
5f3ae0c66b
@ -72,12 +72,15 @@ SignalSource.dump_filename=../data/signal_source.dat
|
||||
; it helps to not overload the CPU, but the processing time will be longer.
|
||||
SignalSource.enable_throttle_control=false
|
||||
|
||||
;#Address of the rtl_tcp server
|
||||
;#Address of the rtl_tcp server (IPv6 allowed)
|
||||
SignalSource.address=127.0.0.1
|
||||
|
||||
;#Port of the rtl_tcp server
|
||||
SignalSource.port=1234
|
||||
|
||||
;# Set to true if I/Q samples come swapped
|
||||
SignalSource.swap_iq=false
|
||||
|
||||
;######### SIGNAL_CONDITIONER CONFIG ############
|
||||
;## It holds blocks to change data type, filter and resample input data.
|
||||
|
||||
|
@ -16,5 +16,6 @@
|
||||
# along with GNSS-SDR. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
add_subdirectory(libs)
|
||||
add_subdirectory(adapters)
|
||||
add_subdirectory(gnuradio_blocks)
|
||||
|
@ -68,6 +68,7 @@ RtlTcpSignalSource::RtlTcpSignalSource(ConfigurationInterface* configuration,
|
||||
item_type_ = configuration->property(role + ".item_type", default_item_type);
|
||||
address_ = configuration->property(role + ".address", default_address);
|
||||
port_ = configuration->property(role + ".port", default_port);
|
||||
flip_iq_ = configuration->property(role + ".flip_iq", false);
|
||||
|
||||
if (item_type_.compare("short") == 0)
|
||||
{
|
||||
@ -81,7 +82,7 @@ RtlTcpSignalSource::RtlTcpSignalSource(ConfigurationInterface* configuration,
|
||||
{
|
||||
std::cout << "Connecting to " << address_ << ":" << port_ << std::endl;
|
||||
LOG (INFO) << "Connecting to " << address_ << ":" << port_;
|
||||
signal_source_ = rtl_tcp_make_signal_source_c (address_, port_);
|
||||
signal_source_ = rtl_tcp_make_signal_source_c (address_, port_, flip_iq_);
|
||||
}
|
||||
catch( boost::exception & e )
|
||||
{
|
||||
@ -94,21 +95,29 @@ RtlTcpSignalSource::RtlTcpSignalSource(ConfigurationInterface* configuration,
|
||||
// 3. set rx frequency
|
||||
signal_source_->set_frequency(freq_);
|
||||
|
||||
// TODO set rx gain
|
||||
// 4. set rx gain
|
||||
signal_source_->set_agc_mode(true);
|
||||
|
||||
/*if (this->AGC_enabled_ == true)
|
||||
{
|
||||
signal_source_->set_agc_mode(true);
|
||||
std::cout << "AGC enabled" << std::endl;
|
||||
LOG(INFO) << "AGC enabled";
|
||||
}
|
||||
|
||||
if (this->AGC_enabled_ == true)
|
||||
{
|
||||
std::cout << "AGC enabled" << std::endl;
|
||||
LOG(INFO) << "AGC enabled";
|
||||
signal_source_->set_agc_mode(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
signal_source_->set_agc_mode(false);
|
||||
signal_source_->set_gain(gain_, 0);
|
||||
signal_source_->set_if_gain(if_gain_, 0);
|
||||
}*/
|
||||
{
|
||||
std::cout << "AGC disabled" << std::endl;
|
||||
LOG(INFO) << "AGC disabled";
|
||||
signal_source_->set_agc_mode(false);
|
||||
|
||||
std::cout << "Setting gain to " << gain_ << std::endl;
|
||||
LOG(INFO) << "Setting gain to " << gain_;
|
||||
signal_source_->set_gain(gain_);
|
||||
|
||||
std::cout << "Setting IF gain to " << if_gain_ << std::endl;
|
||||
LOG(INFO) << "Setting IF gain to " << if_gain_;
|
||||
signal_source_->set_if_gain(if_gain_);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -87,6 +87,7 @@ private:
|
||||
short port_;
|
||||
bool AGC_enabled_;
|
||||
double sample_rate_;
|
||||
bool flip_iq_;
|
||||
|
||||
unsigned int in_stream_;
|
||||
unsigned int out_stream_;
|
||||
|
@ -25,6 +25,7 @@ set(SIGNAL_SOURCE_GR_BLOCKS_SOURCES
|
||||
|
||||
include_directories(
|
||||
$(CMAKE_CURRENT_SOURCE_DIR)
|
||||
${CMAKE_SOURCE_DIR}/src/algorithms/signal_source/libs
|
||||
${GLOG_INCLUDE_DIRS}
|
||||
${GFlags_INCLUDE_DIRS}
|
||||
${GNURADIO_RUNTIME_INCLUDE_DIRS}
|
||||
@ -34,4 +35,4 @@ include_directories(
|
||||
file(GLOB SIGNAL_SOURCE_GR_BLOCKS_HEADERS "*.h")
|
||||
add_library(signal_source_gr_blocks ${SIGNAL_SOURCE_GR_BLOCKS_SOURCES} ${SIGNAL_SOURCE_GR_BLOCKS_HEADERS})
|
||||
source_group(Headers FILES ${SIGNAL_SOURCE_GR_BLOCKS_HEADERS})
|
||||
target_link_libraries(signal_source_gr_blocks ${GNURADIO_RUNTIME_LIBRARIES} ${Boost_LIBRARIES})
|
||||
target_link_libraries(signal_source_gr_blocks signal_source_lib ${GNURADIO_RUNTIME_LIBRARIES} ${Boost_LIBRARIES})
|
||||
|
@ -3,6 +3,8 @@
|
||||
* \brief An rtl_tcp signal source reader.
|
||||
* \author Anthony Arnold, 2015. anthony.arnold(at)uqconnect.edu.au
|
||||
*
|
||||
* This module contains logic taken from gr-omsosdr
|
||||
* <http://git.osmocom.org/gr-osmosdr>
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)
|
||||
@ -29,8 +31,11 @@
|
||||
*/
|
||||
|
||||
#include "rtl_tcp_signal_source_c.h"
|
||||
#include "rtl_tcp_commands.h"
|
||||
#include "rtl_tcp_dongle_info.h"
|
||||
#include <glog/logging.h>
|
||||
#include <boost/thread/thread.hpp>
|
||||
#include <map>
|
||||
|
||||
using google::LogMessage;
|
||||
|
||||
@ -38,119 +43,93 @@ namespace ip = boost::asio::ip;
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
// Buffer constants
|
||||
// TODO: Make these configurable
|
||||
enum {
|
||||
RTL_TCP_BUFFER_SIZE = 1024 * 16, // 16 KB
|
||||
RTL_TCP_PAYLOAD_SIZE = 1024 * 4 // 4 KB
|
||||
};
|
||||
|
||||
// command ids
|
||||
enum {
|
||||
CMD_ID_SET_FREQUENCY = 1,
|
||||
CMD_ID_SET_SAMPLE_RATE = 2,
|
||||
CMD_ID_SET_GAIN_MODE = 3,
|
||||
CMD_ID_SET_GAIN = 4,
|
||||
CMD_ID_SET_IF_GAIN = 6,
|
||||
CMD_ID_SET_AGC_MODE = 8
|
||||
};
|
||||
|
||||
// rtl_tcp command
|
||||
struct command {
|
||||
enum {
|
||||
data_size = 1 + sizeof (unsigned int)
|
||||
};
|
||||
boost::array<unsigned char, data_size> data_;
|
||||
|
||||
command (unsigned char cmd, unsigned int param)
|
||||
{
|
||||
data_[0] = cmd;
|
||||
unsigned int nparam =
|
||||
boost::asio::detail::socket_ops::host_to_network_long (param);
|
||||
memcpy (&data_[1], &nparam, sizeof (nparam));
|
||||
}
|
||||
|
||||
boost::system::error_code send (tcp::socket &socket_) {
|
||||
boost::system::error_code ec;
|
||||
socket_.send (boost::asio::buffer (data_), 0, ec);
|
||||
return ec;
|
||||
}
|
||||
};
|
||||
|
||||
// set frequency command
|
||||
struct set_frequency_command : command {
|
||||
set_frequency_command (unsigned int freq)
|
||||
: command (CMD_ID_SET_FREQUENCY, freq)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
// set sample rate command
|
||||
struct set_sample_rate_command : command {
|
||||
set_sample_rate_command (unsigned int sample_rate)
|
||||
: command (CMD_ID_SET_SAMPLE_RATE, sample_rate)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
// set gain mode command
|
||||
struct set_gain_mode_command : command {
|
||||
set_gain_mode_command (bool manual)
|
||||
: command (CMD_ID_SET_GAIN_MODE, static_cast<unsigned int>( manual ))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// set agc mode command
|
||||
struct set_agc_mode_command : command {
|
||||
set_agc_mode_command (bool manual)
|
||||
: command (CMD_ID_SET_AGC_MODE, static_cast<unsigned int>( manual ))
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
rtl_tcp_signal_source_c_sptr
|
||||
rtl_tcp_make_signal_source_c(const std::string &address,
|
||||
short port)
|
||||
short port,
|
||||
bool flip_iq)
|
||||
{
|
||||
return gnuradio::get_initial_sptr (new rtl_tcp_signal_source_c (address, port));
|
||||
return gnuradio::get_initial_sptr (new rtl_tcp_signal_source_c (address,
|
||||
port,
|
||||
flip_iq));
|
||||
}
|
||||
|
||||
|
||||
rtl_tcp_signal_source_c::rtl_tcp_signal_source_c(const std::string &address,
|
||||
short port)
|
||||
short port,
|
||||
bool flip_iq)
|
||||
: gr::sync_block ("rtl_tcp_signal_source_c",
|
||||
gr::io_signature::make(0, 0, 0),
|
||||
gr::io_signature::make(1, 1, sizeof(gr_complex))),
|
||||
socket_ (io_service_),
|
||||
data_ (RTL_TCP_PAYLOAD_SIZE),
|
||||
flip_iq_(flip_iq),
|
||||
buffer_ (RTL_TCP_BUFFER_SIZE),
|
||||
unread_ (0)
|
||||
{
|
||||
boost::system::error_code ec;
|
||||
|
||||
for (int i = 0; i < 256; i++) {
|
||||
lookup_[i] = (((float)(i & 0xff)) - 127.4f) * (1.0f / 128.0f);
|
||||
// 1. Setup lookup table
|
||||
for (unsigned i = 0; i < 0xff; i++) {
|
||||
lookup_[i] = ((float)(i & 0xff) - 127.4f) * (1.0f / 128.0f);
|
||||
}
|
||||
|
||||
// 2. Set socket options
|
||||
socket_.set_option (boost::asio::socket_base::reuse_address (true), ec);
|
||||
if (ec) {
|
||||
std::cout << "Failed to set reuse address option." << std::endl;
|
||||
LOG (WARNING) << "Failed to set reuse address option";
|
||||
}
|
||||
socket_.set_option (boost::asio::socket_base::linger (true, 0), ec);
|
||||
if (ec) {
|
||||
std::cout << "Failed to set linger option." << std::endl;
|
||||
LOG (WARNING) << "Failed to set linger option";
|
||||
}
|
||||
|
||||
// 3. Connect socket
|
||||
ip::address addr = ip::address::from_string (address, ec);
|
||||
if (ec) {
|
||||
std::cout << address << " is not an IP address" << std::endl;
|
||||
LOG (WARNING) << address << " is not an IP address";
|
||||
LOG (ERROR) << address << " is not an IP address";
|
||||
return;
|
||||
}
|
||||
|
||||
socket_.connect(tcp::endpoint (addr, port), ec);
|
||||
if (ec) {
|
||||
std::cout << "Failed to connect to " << addr << ":" << port
|
||||
<< "(" << ec << ")" << std::endl;
|
||||
LOG (WARNING) << "Failed to connect to " << addr << ":" << port
|
||||
<< "(" << ec << ")";
|
||||
return;
|
||||
std::cout << "Failed to connect to " << addr << ":" << port
|
||||
<< "(" << ec << ")" << std::endl;
|
||||
LOG (ERROR) << "Failed to connect to " << addr << ":" << port
|
||||
<< "(" << ec << ")";
|
||||
return;
|
||||
}
|
||||
std::cout << "Connected to " << addr << ":" << port << std::endl;
|
||||
LOG (WARNING) << "Connected to " << addr << ":" << port;
|
||||
|
||||
// 4. Set nodelay
|
||||
socket_.set_option (tcp::no_delay (true), ec);
|
||||
if (ec) {
|
||||
std::cout << "Failed to set no delay option." << std::endl;
|
||||
LOG (WARNING) << "Failed to set no delay option";
|
||||
}
|
||||
|
||||
// 5. Receive dongle info
|
||||
rtl_tcp_dongle_info info;
|
||||
ec = info.read (socket_);
|
||||
if (ec) {
|
||||
std::cout << "Failed to read dongle info." << std::endl;
|
||||
LOG (WARNING) << "Failed to read dongle info";
|
||||
}
|
||||
else if (info.is_valid ()) {
|
||||
std::cout << "Found " << info.get_type_name() << " tuner." << std::endl;
|
||||
LOG (INFO) << "Found " << info.get_type_name() << " tuner.";
|
||||
}
|
||||
|
||||
// 6. Start reading
|
||||
boost::asio::async_read (socket_, boost::asio::buffer (data_),
|
||||
boost::bind (&rtl_tcp_signal_source_c::handle_read,
|
||||
this, _1, _2));
|
||||
@ -175,9 +154,14 @@ int rtl_tcp_signal_source_c::work (int noutput_items,
|
||||
this));
|
||||
|
||||
for ( ; i < noutput_items && unread_ > 1; i++ ) {
|
||||
float re = buffer_[--unread_];
|
||||
float im = buffer_[--unread_];
|
||||
out[i] = gr_complex (re, im);
|
||||
float re = buffer_[--unread_];
|
||||
if (flip_iq_) {
|
||||
out[i] = gr_complex (im, re);
|
||||
}
|
||||
else {
|
||||
out[i] = gr_complex (re, im);
|
||||
}
|
||||
}
|
||||
}
|
||||
not_full_.notify_one ();
|
||||
@ -187,7 +171,7 @@ int rtl_tcp_signal_source_c::work (int noutput_items,
|
||||
|
||||
void rtl_tcp_signal_source_c::set_frequency (int frequency) {
|
||||
boost::system::error_code ec =
|
||||
set_frequency_command (frequency).send(socket_);
|
||||
rtl_tcp_command (RTL_TCP_SET_FREQUENCY, frequency, socket_);
|
||||
if (ec) {
|
||||
std::cout << "Failed to set frequency" << std::endl;
|
||||
LOG (WARNING) << "Failed to set frequency";
|
||||
@ -196,7 +180,7 @@ void rtl_tcp_signal_source_c::set_frequency (int frequency) {
|
||||
|
||||
void rtl_tcp_signal_source_c::set_sample_rate (int sample_rate) {
|
||||
boost::system::error_code ec =
|
||||
set_sample_rate_command (sample_rate).send(socket_);
|
||||
rtl_tcp_command (RTL_TCP_SET_SAMPLE_RATE, sample_rate, socket_);
|
||||
if (ec) {
|
||||
std::cout << "Failed to set sample rate" << std::endl;
|
||||
LOG (WARNING) << "Failed to set sample rate";
|
||||
@ -205,18 +189,79 @@ void rtl_tcp_signal_source_c::set_sample_rate (int sample_rate) {
|
||||
|
||||
|
||||
void rtl_tcp_signal_source_c::set_agc_mode (bool agc) {
|
||||
boost::system::error_code ec =
|
||||
set_gain_mode_command (!agc).send (socket_);
|
||||
if (ec) {
|
||||
std::cout << "Failed to set gain mode" << std::endl;
|
||||
LOG (WARNING) << "Failed to set gain mode";
|
||||
}
|
||||
ec =
|
||||
set_agc_mode_command (agc).send (socket_);
|
||||
if (ec) {
|
||||
std::cout << "Failed to set gain mode" << std::endl;
|
||||
LOG (WARNING) << "Failed to set gain mode";
|
||||
}
|
||||
boost::system::error_code ec =
|
||||
rtl_tcp_command (RTL_TCP_SET_GAIN_MODE, !agc, socket_);
|
||||
if (ec) {
|
||||
std::cout << "Failed to set gain mode" << std::endl;
|
||||
LOG (WARNING) << "Failed to set gain mode";
|
||||
}
|
||||
ec =
|
||||
rtl_tcp_command (RTL_TCP_SET_AGC_MODE, agc, socket_);
|
||||
if (ec) {
|
||||
std::cout << "Failed to set gain mode" << std::endl;
|
||||
LOG (WARNING) << "Failed to set gain mode";
|
||||
}
|
||||
}
|
||||
|
||||
void rtl_tcp_signal_source_c::set_gain (int gain) {
|
||||
boost::system::error_code ec =
|
||||
rtl_tcp_command (RTL_TCP_SET_GAIN, gain, socket_);
|
||||
if (ec) {
|
||||
std::cout << "Failed to set gain" << std::endl;
|
||||
LOG (WARNING) << "Failed to set gain";
|
||||
}
|
||||
}
|
||||
|
||||
void rtl_tcp_signal_source_c::set_if_gain (int gain) {
|
||||
// from gr-osmosdr
|
||||
struct range {
|
||||
double start, stop, step;
|
||||
};
|
||||
std::vector<range> ranges = {
|
||||
{ -3, 6, 9 },
|
||||
{ 0, 9, 3 },
|
||||
{ 0, 9, 3 },
|
||||
{ 0, 2, 1 },
|
||||
{ 3, 15, 3},
|
||||
{ 3, 15, 3}
|
||||
};
|
||||
|
||||
std::map <int, double> gains;
|
||||
for (int i = 0; i < static_cast<int>(ranges.size ()); i++) {
|
||||
gains[i+1] = ranges[i].start;
|
||||
}
|
||||
|
||||
for (int i = ranges.size() - 1; i >= 0; i--) {
|
||||
const range &r = ranges[i];
|
||||
double error = gain;
|
||||
|
||||
for (double g = r.start; g < r.stop; g += r.step) {
|
||||
double sum = 0;
|
||||
for (int j = 0; j < static_cast<int> ( gains.size() ); j++) {
|
||||
if (i == j) {
|
||||
sum += g;
|
||||
}
|
||||
else {
|
||||
sum += gains[j + 1];
|
||||
}
|
||||
}
|
||||
double err = std::abs (gain - sum);
|
||||
if (err < error) {
|
||||
error = err;
|
||||
gains[i+1] = g;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (unsigned stage = 1; stage <= gains.size(); stage++) {
|
||||
int stage_gain = static_cast<int>( gains[stage] * 10 );
|
||||
unsigned param = (stage << 16) | (stage_gain & 0xffff);
|
||||
boost::system::error_code ec =
|
||||
rtl_tcp_command (RTL_TCP_SET_IF_GAIN, param, socket_);
|
||||
if (ec) {
|
||||
std::cout << "Failed to set if gain" << std::endl;
|
||||
LOG (WARNING) << "Failed to set if gain";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -252,7 +297,7 @@ rtl_tcp_signal_source_c::handle_read (const boost::system::error_code &ec,
|
||||
unread_++;
|
||||
}
|
||||
}
|
||||
// let woker know that more data is available
|
||||
// let woker know that more data is available
|
||||
not_empty_.notify_one ();
|
||||
// Read some more
|
||||
boost::asio::async_read (socket_,
|
||||
|
@ -53,7 +53,8 @@ typedef boost::shared_ptr<rtl_tcp_signal_source_c>
|
||||
|
||||
rtl_tcp_signal_source_c_sptr
|
||||
rtl_tcp_make_signal_source_c(const std::string &address,
|
||||
short port);
|
||||
short port,
|
||||
bool flip_iq = false);
|
||||
|
||||
/*!
|
||||
* \brief This class reads interleaved I/Q samples
|
||||
@ -71,22 +72,27 @@ public:
|
||||
void set_frequency (int frequency);
|
||||
void set_sample_rate (int sample_rate);
|
||||
void set_agc_mode (bool agc);
|
||||
|
||||
void set_gain (int gain);
|
||||
void set_if_gain (int gain);
|
||||
|
||||
private:
|
||||
typedef boost::circular_buffer_space_optimized<float> buffer_type;
|
||||
|
||||
|
||||
friend rtl_tcp_signal_source_c_sptr
|
||||
rtl_tcp_make_signal_source_c(const std::string &address,
|
||||
short port);
|
||||
short port,
|
||||
bool flip_iq);
|
||||
|
||||
rtl_tcp_signal_source_c(const std::string &address,
|
||||
short port);
|
||||
short port,
|
||||
bool flip_iq);
|
||||
|
||||
// IO members
|
||||
boost::asio::io_service io_service_;
|
||||
boost::asio::ip::tcp::socket socket_;
|
||||
std::vector<unsigned char> data_;
|
||||
|
||||
bool flip_iq_;
|
||||
|
||||
// producer-consumer helpers
|
||||
boost::mutex mutex_;
|
||||
boost::condition not_full_;
|
||||
@ -94,13 +100,13 @@ private:
|
||||
buffer_type buffer_;
|
||||
size_t unread_;
|
||||
|
||||
// lookup for scaling bytes
|
||||
boost::array<float, 256> lookup_;
|
||||
// lookup for scaling data
|
||||
boost::array<float, 0xff> lookup_;
|
||||
|
||||
// async read callback
|
||||
void handle_read (const boost::system::error_code &ec,
|
||||
size_t bytes_transferred);
|
||||
|
||||
|
||||
inline bool not_full ( ) const {
|
||||
return unread_ < buffer_.capacity( );
|
||||
}
|
||||
|
25
src/algorithms/signal_source/libs/CMakeLists.txt
Normal file
25
src/algorithms/signal_source/libs/CMakeLists.txt
Normal file
@ -0,0 +1,25 @@
|
||||
# Copyright (C) 2012-2015 (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 <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
|
||||
set (SIGNAL_SOURCE_LIB_SOURCES
|
||||
rtl_tcp_commands.cc
|
||||
rtl_tcp_dongle_info.cc)
|
||||
|
||||
file(GLOB SIGNAL_SOURCE_LIB_HEADERS "*.h")
|
||||
add_library(signal_source_lib ${SIGNAL_SOURCE_LIB_SOURCES} ${SIGNAL_SOURCE_LIB_HEADERS})
|
||||
source_group(Headers FILES ${SIGNAL_SOURCE_LIB_HEADERS})
|
53
src/algorithms/signal_source/libs/rtl_tcp_commands.cc
Normal file
53
src/algorithms/signal_source/libs/rtl_tcp_commands.cc
Normal file
@ -0,0 +1,53 @@
|
||||
/*!
|
||||
* \file rtl_tcp_commands.cc
|
||||
* \brief Defines methods for communicating with rtl_tcp
|
||||
* \author Anthony Arnold, 2015. anthony.arnold(at)uqconnect.edu.au
|
||||
*
|
||||
* This file contains information taken from librtlsdr:
|
||||
* http://git.osmocom.org/rtl-sdr/
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (C) 2010-2015 (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 "rtl_tcp_commands.h"
|
||||
#include <string.h>
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
|
||||
boost::system::error_code
|
||||
rtl_tcp_command (RTL_TCP_COMMAND id, unsigned param, tcp::socket &socket) {
|
||||
// Data payload
|
||||
unsigned char data[sizeof (unsigned char) + sizeof (unsigned)];
|
||||
|
||||
data[0] = static_cast<unsigned char> (id);
|
||||
|
||||
|
||||
unsigned nparam =
|
||||
boost::asio::detail::socket_ops::host_to_network_long (param);
|
||||
::memcpy (&data[1], &nparam, sizeof (nparam));
|
||||
|
||||
boost::system::error_code ec;
|
||||
socket.send (boost::asio::buffer (data), 0, ec);
|
||||
return ec;
|
||||
}
|
55
src/algorithms/signal_source/libs/rtl_tcp_commands.h
Normal file
55
src/algorithms/signal_source/libs/rtl_tcp_commands.h
Normal file
@ -0,0 +1,55 @@
|
||||
/*!
|
||||
* \file rtl_tcp_commands.h
|
||||
* \brief Defines structures and constants for communicating with rtl_tcp
|
||||
* \author Anthony Arnold, 2015. anthony.arnold(at)uqconnect.edu.au
|
||||
*
|
||||
* This file contains information taken from librtlsdr:
|
||||
* http://git.osmocom.org/rtl-sdr/
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (C) 2010-2015 (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 GNSS_SDR_RTL_TCP_COMMANDS_H
|
||||
#define GNSS_SDR_RTL_TCP_COMMANDS_H
|
||||
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
|
||||
/// Command IDs for configuration rtl_tcp
|
||||
enum RTL_TCP_COMMAND {
|
||||
RTL_TCP_SET_FREQUENCY = 1,
|
||||
RTL_TCP_SET_SAMPLE_RATE = 2,
|
||||
RTL_TCP_SET_GAIN_MODE = 3,
|
||||
RTL_TCP_SET_GAIN = 4,
|
||||
RTL_TCP_SET_IF_GAIN = 6,
|
||||
RTL_TCP_SET_AGC_MODE = 8
|
||||
};
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Send a command to rtl_tcp over the given socket.
|
||||
*/
|
||||
boost::system::error_code
|
||||
rtl_tcp_command (RTL_TCP_COMMAND id, unsigned param,
|
||||
boost::asio::ip::tcp::socket &socket);
|
||||
|
||||
#endif // GNSS_SDR_RTL_TCP_COMMANDS_H
|
90
src/algorithms/signal_source/libs/rtl_tcp_dongle_info.cc
Normal file
90
src/algorithms/signal_source/libs/rtl_tcp_dongle_info.cc
Normal file
@ -0,0 +1,90 @@
|
||||
/*!
|
||||
* \file rtl_tcp_dongle_info.cc
|
||||
* \brief Defines methods for retrieving and validating rtl_tcp donle
|
||||
* info.
|
||||
* \author Anthony Arnold, 2015. anthony.arnold(at)uqconnect.edu.au
|
||||
*
|
||||
* This file contains information taken from librtlsdr:
|
||||
* http://git.osmocom.org/rtl-sdr/
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (C) 2010-2015 (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 "rtl_tcp_dongle_info.h"
|
||||
#include <string.h>
|
||||
|
||||
using boost::asio::ip::tcp;
|
||||
|
||||
rtl_tcp_dongle_info::rtl_tcp_dongle_info ()
|
||||
: tuner_type_ (0), tuner_gain_count_ (0)
|
||||
{
|
||||
::memset (magic_, 0, sizeof (magic_));
|
||||
}
|
||||
|
||||
boost::system::error_code rtl_tcp_dongle_info::read (tcp::socket &socket) {
|
||||
boost::system::error_code ec;
|
||||
|
||||
unsigned char data[sizeof (char) * 4 + sizeof (uint32_t) * 2];
|
||||
socket.receive (boost::asio::buffer (data), 0, ec);
|
||||
if (!ec) {
|
||||
::memcpy (magic_, data, 4);
|
||||
|
||||
uint32_t type;
|
||||
::memcpy (&type, &data[4], 4);
|
||||
|
||||
tuner_type_ =
|
||||
boost::asio::detail::socket_ops::network_to_host_long (type);
|
||||
|
||||
|
||||
uint32_t count;
|
||||
::memcpy (&count, &data[8], 4);
|
||||
|
||||
tuner_gain_count_ =
|
||||
boost::asio::detail::socket_ops::network_to_host_long (count);
|
||||
}
|
||||
return ec;
|
||||
}
|
||||
|
||||
|
||||
const char *rtl_tcp_dongle_info::get_type_name () const {
|
||||
switch (get_tuner_type()) {
|
||||
default:
|
||||
return "UNKNOWN";
|
||||
case TUNER_E4000:
|
||||
return "E4000";
|
||||
case TUNER_FC0012:
|
||||
return "FC0012";
|
||||
case TUNER_FC0013:
|
||||
return "FC0013";
|
||||
case TUNER_FC2580:
|
||||
return "FC2580";
|
||||
case TUNER_R820T:
|
||||
return "R820T";
|
||||
case TUNER_R828D:
|
||||
return "R828D";
|
||||
}
|
||||
}
|
||||
|
||||
bool rtl_tcp_dongle_info::is_valid () const {
|
||||
return ::memcmp (magic_, "RTL0", 4) == 0;
|
||||
}
|
78
src/algorithms/signal_source/libs/rtl_tcp_dongle_info.h
Normal file
78
src/algorithms/signal_source/libs/rtl_tcp_dongle_info.h
Normal file
@ -0,0 +1,78 @@
|
||||
/*!
|
||||
* \file rtl_tcp_dongle_info.h
|
||||
* \brief Interface for a structure sent by rtl_tcp defining the hardware.
|
||||
* \author Anthony Arnold, 2015. anthony.arnold(at)uqconnect.edu.au
|
||||
*
|
||||
* This file contains information taken from librtlsdr:
|
||||
* http://git.osmocom.org/rtl-sdr/
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* Copyright (C) 2010-2015 (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 GNSS_SDR_RTL_TCP_DONGLE_INFO_H
|
||||
#define GNSS_SDR_RTL_TCP_DONGLE_INFO_H
|
||||
|
||||
#include <boost/asio/ip/tcp.hpp>
|
||||
|
||||
/*!
|
||||
* \brief This class represents the dongle information
|
||||
* which is sent by rtl_tcp.
|
||||
*/
|
||||
class rtl_tcp_dongle_info {
|
||||
public:
|
||||
enum {
|
||||
TUNER_UNKNOWN = 0,
|
||||
TUNER_E4000,
|
||||
TUNER_FC0012,
|
||||
TUNER_FC0013,
|
||||
TUNER_FC2580,
|
||||
TUNER_R820T,
|
||||
TUNER_R828D
|
||||
};
|
||||
|
||||
private:
|
||||
char magic_[4];
|
||||
uint32_t tuner_type_;
|
||||
uint32_t tuner_gain_count_;
|
||||
|
||||
public:
|
||||
rtl_tcp_dongle_info ();
|
||||
|
||||
boost::system::error_code read (
|
||||
boost::asio::ip::tcp::socket &socket);
|
||||
|
||||
bool is_valid () const;
|
||||
|
||||
const char *get_type_name () const;
|
||||
|
||||
inline uint32_t get_tuner_type () const {
|
||||
return tuner_type_;
|
||||
}
|
||||
|
||||
inline uint32_t get_tuner_gain_count () const {
|
||||
return tuner_gain_count_;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // GNSS_SDR_RTL_TCP_DONGLE_INFO_H
|
Loading…
Reference in New Issue
Block a user