mirror of
https://github.com/gnss-sdr/gnss-sdr
synced 2025-11-12 13:23:09 +00:00
Refactored out rtl_tcp stuff to libs
This commit is contained in:
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
|
||||
Reference in New Issue
Block a user