Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote TCP Input and Remote TCP Sink Plugins #1350

Merged
merged 6 commits into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ option(ENABLE_CHANNELRX_FILESINK "Enable channelrx filesink plugin" ON)
option(ENABLE_CHANNELRX_DEMODFREEDV "Enable channelrx demodfreedv plugin" ON)
option(ENABLE_CHANNELRX_DEMODCHIRPCHAT "Enable channelrx demodchirpchat plugin" ON)
option(ENABLE_CHANNELRX_REMOTESINK "Enable channelrx remotesink plugin" ON)
option(ENABLE_CHANNELRX_REMOTETCPSINK "Enable channelrx remotetcpsink plugin" ON)
option(ENABLE_CHANNELRX_DEMODSSB "Enable channelrx demodssb plugin" ON)
option(ENABLE_CHANNELRX_CHANALYZER "Enable channelrx chanalyzer plugin" ON)
option(ENABLE_CHANNELRX_SIGMFFILESINK "Enable channelrx sigmffilesink plugin" ON)
Expand Down
Binary file added doc/img/RemoteTCPInput_plugin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/img/RemoteTCPSink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions plugins/channelrx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ if (ENABLE_CHANNELRX_REMOTESINK AND CM256CC_FOUND AND (HAS_SSE3 OR HAS_NEON))
add_subdirectory(remotesink)
endif()

if (ENABLE_CHANNELRX_REMOTETCPSINK)
add_subdirectory(remotetcpsink)
endif()

if (ENABLE_CHANNELRX_DEMODFREEDV AND CODEC2_FOUND)
add_subdirectory(demodfreedv)
endif()
Expand Down
64 changes: 64 additions & 0 deletions plugins/channelrx/remotetcpsink/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
project(remotetcpsink)

set(remotetcpsink_SOURCES
remotetcpsink.cpp
remotetcpsinkbaseband.cpp
remotetcpsinksink.cpp
remotetcpsinksettings.cpp
remotetcpsinkwebapiadapter.cpp
remotetcpsinkplugin.cpp
)

set(remotetcpsink_HEADERS
remotetcpsink.h
remotetcpsinkbaseband.h
remotetcpsinksink.h
remotetcpsinksettings.h
remotetcpsinkwebapiadapter.h
remotetcpsinkplugin.h
remotetcpprotocol.h
)

include_directories(
${CMAKE_SOURCE_DIR}/swagger/sdrangel/code/qt5/client
)

if(NOT SERVER_MODE)
set(remotetcpsink_SOURCES
${remotetcpsink_SOURCES}
remotetcpsinkgui.cpp
remotetcpsinkgui.ui
)
set(remotetcpsink_HEADERS
${remotetcpsink_HEADERS}
remotetcpsinkgui.h
)
set(TARGET_NAME remotetcpsink)
set(TARGET_LIB "Qt5::Widgets")
set(TARGET_LIB_GUI "sdrgui")
set(INSTALL_FOLDER ${INSTALL_PLUGINS_DIR})
else()
set(TARGET_NAME remotetcpsinksrv)
set(TARGET_LIB "")
set(TARGET_LIB_GUI "")
set(INSTALL_FOLDER ${INSTALL_PLUGINSSRV_DIR})
endif()

add_library(${TARGET_NAME} SHARED
${remotetcpsink_SOURCES}
)

target_link_libraries(${TARGET_NAME}
Qt5::Core
${TARGET_LIB}
sdrbase
${TARGET_LIB_GUI}
swagger
)

install(TARGETS ${TARGET_NAME} DESTINATION ${INSTALL_FOLDER})

# Install debug symbols
if (WIN32)
install(FILES $<TARGET_PDB_FILE:${TARGET_NAME}> CONFIGURATIONS Debug RelWithDebInfo DESTINATION ${INSTALL_FOLDER} )
endif()
44 changes: 44 additions & 0 deletions plugins/channelrx/remotetcpsink/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<h1>Remote TCP sink channel plugin</h1>

<h2>Introduction</h2>

This plugin sends I/Q samples from the baseband via TCP/IP across a network to a client application.
The client application could be SDRangel using the [Remote TCP Input](../../samplesource/remotetcpinput/readme.md) plugin or a rtl_tcp compatible application.
This means that applications using rtl_tcp protcol can connect to the wide variety of SDRs supported by SDRangel.

<h2>Interface</h2>

![Remote TCP sink channel plugin GUI](../../../doc/img/RemoteTCPSink.png)

<h3>1: Frequency shift from center frequency of reception</h3>

This is the shift of the channel center frequency from the device center frequency.
This is used to select the desired part of the signal when the channel sample rate is lower than the baseband sample rate.

<h3>2: Gain</h3>

Sets a gain figure in dB that is applied to I/Q samples before transmission via TCP/IP.
This option may be useful for amplifying very small signals from SDRs with high-dynamic range (E.g. 24-bits), when the network sample bit-depth is 8-bits.

<h3>3: Sample rate</h3>

Specifies the channel and network sample rate in samples per second. If this is different from the baseband sample rate, the baseband signal will be decimated to the specified rate.

<h3>4: Sample bit depth</h3>

Specifies number of bits per I/Q sample transmitted via TCP/IP.

<h3>5: IP address</h3>

IP address of the local network interface on which the server will listen for TCP/IP connections from network clients.

<h3>6: Port</h3>

TCP port on which the server will listen for connections.

<h3>7: Protocol</h3>

Specifies the protocol used for sending IQ samples and metadata to clients via TCP/IP.

- RTL0: Compatible with rtl_tcp - limited to 8-bit IQ data.
- SDRA: Enhanced version of protocol that allows device settings to be sent to clients and for higher bit depths to be used (8, 16, 24 and 32).
171 changes: 171 additions & 0 deletions plugins/channelrx/remotetcpsink/remotetcpprotocol.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
///////////////////////////////////////////////////////////////////////////////////
// Copyright (C) 2018 Edouard Griffiths, F4EXB //
// Copyright (C) 2022 Jon Beniston, M7RCE //
// //
// This program 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 as version 3 of the License, or //
// (at your option) any later version. //
// //
// This program 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 V3 for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
///////////////////////////////////////////////////////////////////////////////////

#ifndef PLUGINS_CHANNELRX_REMOTETCPSINK_REMOTETCPPROTOCOL_H_
#define PLUGINS_CHANNELRX_REMOTETCPSINK_REMOTETCPPROTOCOL_H_

#include <QString>

// Remote TCP protocol based on rtl_tcp (for compatibility) with a few extensions (as SDRangel supports more SDRs)
class RemoteTCPProtocol
{
public:

enum Device {
// These are compatible with rtl_tcp
UNKNOWN = 0,
RTLSDR_E4000,
RTLSDR_FC0012,
RTLSDR_FC0013,
RTLSDR_FC2580,
RTLSDR_R820T, // Used by rsp_tcp
RTLSDR_R828D,
// SDRangel extensions that correspond to sample source devices
AIRSPY = 0x80,
AIRSPY_HF,
AUDIO_INPUT,
BLADE_RF1,
BLADE_RF2,
FCD_PRO,
FCD_PRO_PLUS,
FILE_INPUT,
HACK_RF,
KIWI_SDR,
LIME_SDR,
LOCAL_INPUT,
PERSEUS,
PLUTO_SDR,
REMOTE_INPUT,
REMOTE_TCP_INPUT,
SDRPLAY_1,
SDRPLAY_V3_RSP1,
SDRPLAY_V3_RSP1A,
SDRPLAY_V3_RSP2,
SDRPLAY_V3_RSPDUO,
SDRPLAY_V3_RSPDX,
SIGMF_FILE_INPUT,
SOAPY_SDR,
TEST_SOURCE,
USRP,
XTRX
};

enum Command {
// These are compatbile with osmocom rtl_tcp: https://github.com/osmocom/rtl-sdr/blob/master/src/rtl_tcp.c
setCenterFrequency = 0x1, // rtlsdr_set_center_freq
setSampleRate = 0x2, // rtlsdr_set_sample_rate
setTunerGainMode = 0x3, // rtlsdr_set_tuner_gain_mode
setTunerGain = 0x4, // rtlsdr_set_tuner_gain
setFrequencyCorrection = 0x5, // rtlsdr_set_freq_correction
setTunerIFGain = 0x6, // rtlsdr_set_tuner_if_gain - Used by SDRangel to set LNA/VGA/IF gain individually
setTestMode = 0x7, // Not supported by SDRangel
setAGCMode = 0x8, // rtlsdr_set_agc_mode
setDirectSampling = 0x9, // rtlsdr_set_direct_sampling
setOffsetTuning = 0xa,
setXtalFrequency = 0xb, // Not supported by SDRangel
setXtalFrequency2 = 0xc, // Not supported by SDRangel
setGainByIndex = 0xd, // Not supported by SDRangel
setBiasTee = 0xe, // rtlsdr_set_bias_tee
// These extensions are from librtlsdr rtl_tcp: https://github.com/librtlsdr/librtlsdr/blob/development/include/rtl_tcp.h
setTunerBandwidth = 0x40,
// These are SDRangel extensions
setDCOffsetRemoval = 0xc0,
setIQCorrection = 0xc1,
setDecimation = 0xc2, // Device to baseband decimation
setChannelSampleRate = 0xc3,
setChannelFreqOffset = 0xc4,
setChannelGain = 0xc5,
setSampleBitDepth = 0xc6, // Bit depth for samples sent over network
//setAntenna?
//setLOOffset?
};

static const int m_rtl0MetaDataSize = 12;
static const int m_sdraMetaDataSize = 64;

static void encodeInt16(quint8 *p, qint16 data)
{
p[0] = (data >> 8) & 0xff;
p[1] = data & 0xff;
}

static void encodeUInt32(quint8 *p, quint32 data)
{
p[0] = (data >> 24) & 0xff;
p[1] = (data >> 16) & 0xff;
p[2] = (data >> 8) & 0xff;
p[3] = data & 0xff;
}

static void encodeInt32(quint8 *p, qint32 data)
{
encodeUInt32(p, (quint32)data);
}

static qint16 extractInt16(quint8 *p)
{
qint16 data;
data = (p[1] & 0xff)
| ((p[0] & 0xff) << 8);
return data;
}

static quint32 extractUInt32(quint8 *p)
{
quint32 data;
data = (p[3] & 0xff)
| ((p[2] & 0xff) << 8)
| ((p[1] & 0xff) << 16)
| ((p[0] & 0xff) << 24);
return data;
}

static qint32 extractInt32(quint8 *p)
{
return (qint32)extractUInt32(p);
}

static void encodeUInt64(quint8 *p, quint64 data)
{
p[0] = (data >> 56) & 0xff;
p[1] = (data >> 48) & 0xff;
p[2] = (data >> 40) & 0xff;
p[3] = (data >> 32) & 0xff;
p[4] = (data >> 24) & 0xff;
p[5] = (data >> 16) & 0xff;
p[6] = (data >> 8) & 0xff;
p[7] = data & 0xff;
}

static quint64 extractUInt64(quint8 *p)
{
quint64 data;
data = (p[7] & 0xff)
| ((p[6] & 0xff) << 8)
| ((p[5] & 0xff) << 16)
| ((p[4] & 0xff) << 24)
| (((quint64)(p[3] & 0xff)) << 32)
| (((quint64)(p[2] & 0xff)) << 40)
| (((quint64)(p[1] & 0xff)) << 48)
| (((quint64)(p[0] & 0xff)) << 56);
return data;
}

};

#endif /* PLUGINS_CHANNELRX_REMOTETCPSINK_REMOTETCPPROTOCOL_H_ */
Loading