Skip to content

Commit ec0b6f9

Browse files
committed
Initial commit
0 parents  commit ec0b6f9

21 files changed

+2227
-0
lines changed

.clang-format

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
UseTab: Never
2+
IndentWidth: 4
3+
ContinuationIndentWidth: 8
4+
BreakBeforeBraces: Allman
5+
AlignAfterOpenBracket: DontAlign
6+
AlignEscapedNewlines: DontAlign
7+
AlignConsecutiveAssignments: true
8+
AllowShortIfStatementsOnASingleLine: false
9+
AccessModifierOffset: -4
10+
IndentCaseLabels: false
11+
ColumnLimit: 0
12+
SortIncludes: false

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

CMakeLists.txt

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
########################################################################
2+
# Build Soapy SDR support module for RTL-TCP Devices
3+
########################################################################
4+
cmake_minimum_required(VERSION 2.8.7)
5+
project(SoapyRTLTCP CXX)
6+
7+
find_package(SoapySDR "0.4.0" NO_MODULE REQUIRED)
8+
if (NOT SoapySDR_FOUND)
9+
message(FATAL_ERROR "Soapy SDR development files not found...")
10+
endif ()
11+
12+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR})
13+
14+
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
15+
16+
# Test for Atomics
17+
include(CheckAtomic)
18+
if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB OR NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
19+
set(ATOMIC_LIBS "atomic")
20+
endif()
21+
22+
#enable c++11 features
23+
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" OR "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
24+
#C++11 is a required language feature for this project
25+
include(CheckCXXCompilerFlag)
26+
CHECK_CXX_COMPILER_FLAG("-std=c++11" HAS_STD_CXX11)
27+
if(HAS_STD_CXX11)
28+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
29+
else(HAS_STD_CXX11)
30+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
31+
endif()
32+
33+
#Thread support enabled (not the same as -lpthread)
34+
list(APPEND RTLTCP_LIBRARIES -pthread)
35+
endif()
36+
37+
if (APPLE)
38+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wc++11-extensions")
39+
endif(APPLE)
40+
41+
SOAPY_SDR_MODULE_UTIL(
42+
TARGET rtltcpSupport
43+
SOURCES
44+
SoapyRTLTCP.hpp
45+
Registration.cpp
46+
Settings.cpp
47+
Streaming.cpp
48+
LIBRARIES
49+
${RTLTCP_LIBRARIES}
50+
${ATOMIC_LIBS}
51+
)
52+
53+
#network libraries
54+
if (WIN32)
55+
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
56+
add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
57+
target_link_libraries(rtltcpSupport PRIVATE ws2_32)
58+
endif (WIN32)
59+
60+
########################################################################
61+
# uninstall target
62+
########################################################################
63+
add_custom_target(uninstall
64+
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
65+
configure_file(
66+
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in"
67+
"${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake"
68+
IMMEDIATE @ONLY)
69+

Changelog.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Release 0.1.0 (2021-12-31)
2+
==========================
3+
4+
- Initial release of Soapy RTL-TCP support module

CheckAtomic.cmake

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
# - Try to find if atomics need -latomic linking
2+
# Once done this will define
3+
# HAVE_CXX_ATOMICS_WITHOUT_LIB - Wether atomic types work without -latomic
4+
# HAVE_CXX_ATOMICS64_WITHOUT_LIB - Wether 64 bit atomic types work without -latomic
5+
6+
INCLUDE(CheckCXXSourceCompiles)
7+
INCLUDE(CheckLibraryExists)
8+
9+
# Sometimes linking against libatomic is required for atomic ops, if
10+
# the platform doesn't support lock-free atomics.
11+
12+
function(check_working_cxx_atomics varname)
13+
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
14+
set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -std=c++11")
15+
CHECK_CXX_SOURCE_COMPILES("
16+
#include <atomic>
17+
std::atomic<int> x;
18+
int main() {
19+
return std::atomic_is_lock_free(&x);
20+
}
21+
" ${varname})
22+
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
23+
endfunction(check_working_cxx_atomics)
24+
25+
function(check_working_cxx_atomics64 varname)
26+
set(OLD_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS})
27+
set(CMAKE_REQUIRED_FLAGS "-std=c++11 ${CMAKE_REQUIRED_FLAGS}")
28+
CHECK_CXX_SOURCE_COMPILES("
29+
#include <atomic>
30+
#include <cstdint>
31+
std::atomic<uint64_t> x (0);
32+
int main() {
33+
uint64_t i = x.load(std::memory_order_relaxed);
34+
return std::atomic_is_lock_free(&x);
35+
}
36+
" ${varname})
37+
set(CMAKE_REQUIRED_FLAGS ${OLD_CMAKE_REQUIRED_FLAGS})
38+
endfunction(check_working_cxx_atomics64)
39+
40+
# Check for atomic operations.
41+
if(MSVC)
42+
# This isn't necessary on MSVC.
43+
set(HAVE_CXX_ATOMICS_WITHOUT_LIB True)
44+
else()
45+
# First check if atomics work without the library.
46+
check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITHOUT_LIB)
47+
endif()
48+
49+
# If not, check if the library exists, and atomics work with it.
50+
if(NOT HAVE_CXX_ATOMICS_WITHOUT_LIB)
51+
check_library_exists(atomic __atomic_fetch_add_4 "" HAVE_LIBATOMIC)
52+
if(NOT HAVE_LIBATOMIC)
53+
message(STATUS "Host compiler appears to require libatomic, but cannot locate it.")
54+
endif()
55+
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
56+
check_working_cxx_atomics(HAVE_CXX_ATOMICS_WITH_LIB)
57+
if (NOT HAVE_CXX_ATOMICS_WITH_LIB)
58+
message(FATAL_ERROR "Host compiler must support std::atomic!")
59+
endif()
60+
endif()
61+
62+
# Check for 64 bit atomic operations.
63+
if(MSVC)
64+
set(HAVE_CXX_ATOMICS64_WITHOUT_LIB True)
65+
else()
66+
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITHOUT_LIB)
67+
endif()
68+
69+
# If not, check if the library exists, and atomics work with it.
70+
if(NOT HAVE_CXX_ATOMICS64_WITHOUT_LIB)
71+
check_library_exists(atomic __atomic_load_8 "" HAVE_LIBATOMIC64)
72+
if(NOT HAVE_LIBATOMIC64)
73+
message(STATUS "Host compiler appears to require libatomic, but cannot locate it.")
74+
endif()
75+
list(APPEND CMAKE_REQUIRED_LIBRARIES "atomic")
76+
check_working_cxx_atomics64(HAVE_CXX_ATOMICS64_WITH_LIB)
77+
if (NOT HAVE_CXX_ATOMICS64_WITH_LIB)
78+
message(FATAL_ERROR "Host compiler must support std::atomic!")
79+
endif()
80+
endif()
81+

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2021 Christian Zuckschwerdt <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Soapy SDR module for RTL-TCP
2+
3+
Use an rtl_tcp server transparently as SoapySDR device.
4+
The rtl_tcp protocol lacks many features, like reporting current settings and stream control.
5+
Prefer any other module if possible.
6+
7+
By default, the module will attempt to discover a local rtl_tcp server. Specify the "rtltcp" key to connect at a specific address. The value of the "rtltcp" key should be the rtltcp server's hostname or IP address. If a custom port was selected, the value should be specified as "myServer:portNum":
8+
9+
```
10+
SoapySDRUtil --find="rtltcp=myServer"
11+
```
12+
13+
Note that IPv6 will be used if available and assigned for the interface, if you want IPv4 use e.g.:
14+
15+
```
16+
SoapySDRUtil --find="rtltcp=127.0.0.1"
17+
```
18+
19+
## Dependencies
20+
21+
* SoapySDR - https://github.com/pothosware/SoapySDR/wiki
22+
23+
## Licensing information
24+
25+
The MIT License (MIT)
26+
27+
Copyright (c) 2021 Christian Zuckschwerdt <[email protected]>
28+
29+
Permission is hereby granted, free of charge, to any person obtaining a copy
30+
of this software and associated documentation files (the "Software"), to deal
31+
in the Software without restriction, including without limitation the rights
32+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
33+
copies of the Software, and to permit persons to whom the Software is
34+
furnished to do so, subject to the following conditions:
35+
36+
The above copyright notice and this permission notice shall be included in
37+
all copies or substantial portions of the Software.
38+
39+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
41+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
42+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
43+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
44+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
45+
THE SOFTWARE.

Registration.cpp

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2021 Christian Zuckschwerdt <[email protected]>
5+
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
13+
* The above copyright notice and this permission notice shall be included in
14+
* all copies or substantial portions of the Software.
15+
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
#include "SoapyRTLTCP.hpp"
26+
#include <SoapySDR/Registry.hpp>
27+
28+
static std::vector<SoapySDR::Kwargs> findRTLTCP(const SoapySDR::Kwargs &args)
29+
{
30+
std::vector<SoapySDR::Kwargs> results;
31+
32+
try
33+
{
34+
SoapySDR_logf(SOAPY_SDR_DEBUG, "RTL-TCP trying to find server");
35+
SoapyRTLTCP device(args);
36+
37+
const auto tuner = device.getHardwareKey();
38+
39+
SoapySDR::Kwargs devInfo;
40+
devInfo["label"] = std::string("rtl_tcp :: " + device.address);
41+
devInfo["rtltcp"] = device.address;
42+
devInfo["tuner"] = tuner;
43+
44+
results.push_back(devInfo);
45+
}
46+
catch (const std::exception &)
47+
{
48+
// no rtl_tcp server found
49+
}
50+
51+
return results;
52+
}
53+
54+
static SoapySDR::Device *makeRTLTCP(const SoapySDR::Kwargs &args)
55+
{
56+
return new SoapyRTLTCP(args);
57+
}
58+
59+
static SoapySDR::Registry registerRTLTCP("rtltcp", &findRTLTCP, &makeRTLTCP, SOAPY_SDR_ABI_VERSION);

0 commit comments

Comments
 (0)