From ace1fe1e5e99cf2d6e7538b34ddcf7ec544afec2 Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Tue, 6 Oct 2020 10:54:00 +0200 Subject: [PATCH] added linux support for rtl_tcp --- CMakeLists.txt | 2 +- root_dev/config.json | 17 +++++++---- root_dev/module_list.json | 12 ++++---- root_dev/soapy_source_config.json | 39 +++++++++++++------------ rtl_tcp_source/src/rtltcp_client.h | 47 +++++++++++++++++++++++++++++- 5 files changed, 86 insertions(+), 31 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d353fe4..49729acd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,4 +20,4 @@ else() add_custom_target(do_always ALL cp \"$/sdrpp_core.so\" \"$\") endif (MSVC) -# cmake .. "-DCMAKE_TOOLCHAIN_FILE=C:/Users/Alex/vcpkg/scripts/buildsystems/vcpkg.cmake" -G "Visual Studio 15 2017 Win64" \ No newline at end of file +# cmake .. "-DCMAKE_TOOLCHAIN_FILE=C:/Users/Alex/vcpkg/scripts/buildsystems/vcpkg.cmake" -G "Visual Studio 15 2017 Win64" diff --git a/root_dev/config.json b/root_dev/config.json index 3e634e81..d77e7e49 100644 --- a/root_dev/config.json +++ b/root_dev/config.json @@ -3,17 +3,24 @@ "bandPlan": "General", "bandPlanEnabled": true, "fftHeight": 300, - "frequency": 96570096, + "frequency": 96571704, "max": 0.0, "maximized": false, + "menuOrder": [ + "Source", + "Radio", + "Recorder", + "Audio", + "Band Plan", + "Display" + ], "menuWidth": 300, "min": -51.47058868408203, "showWaterfall": true, "source": "", "sourceSettings": {}, "windowSize": { - "h": 720, - "w": 1280 - }, - "menuOrder": ["Source", "Radio", "Recorder", "Audio", "Band Plan", "Display"] + "h": 1053, + "w": 1920 + } } \ No newline at end of file diff --git a/root_dev/module_list.json b/root_dev/module_list.json index bb2ebb0c..f026332f 100644 --- a/root_dev/module_list.json +++ b/root_dev/module_list.json @@ -1,7 +1,7 @@ { - "Radio": "./radio/Release/radio.dll", - "Recorder": "./recorder/Release/recorder.dll", - "Soapy": "./soapy/Release/soapy.dll", - "FileSource": "./file_source/Release/file_source.dll", - "RTLTCPSource": "./rtl_tcp_source/Release/rtl_tcp_source.dll" -} \ No newline at end of file + "Radio": "./radio/radio.so", + "Recorder": "./recorder/recorder.so", + "Soapy": "./soapy/soapy.so", + "FileSource": "./file_source/file_source.so", + "RTLTCPSource": "./rtl_tcp_source/rtl_tcp_source.so" +} diff --git a/root_dev/soapy_source_config.json b/root_dev/soapy_source_config.json index 06f6e45b..9f57e6a2 100644 --- a/root_dev/soapy_source_config.json +++ b/root_dev/soapy_source_config.json @@ -1,19 +1,22 @@ -{ - "device": "HackRF One #0 901868dc282c8f8b", - "devices": { - "Generic RTL2832U OEM :: 00000001": { - "gains": { - "TUNER": 12.817999839782715 - }, - "sampleRate": 2560000.0 - }, - "HackRF One #0 901868dc282c8f8b": { - "gains": { - "AMP": 0.0, - "LNA": 24.711999893188477, - "VGA": 15.906000137329102 - }, - "sampleRate": 8000000.0 - } - } +{ + "device": "HackRF One #0 901868dc282c8f8b", + "devices": { + "Generic RTL2832U OEM :: 00000001": { + "gains": { + "TUNER": 12.817999839782715 + }, + "sampleRate": 2560000.0 + }, + "HackRF One #0 901868dc282c8f8b": { + "gains": { + "AMP": 0.0, + "LNA": 24.711999893188477, + "VGA": 15.906000137329102 + }, + "sampleRate": 8000000.0 + }, + "PulseAudio": { + "sampleRate": 96000.0 + } + } } \ No newline at end of file diff --git a/rtl_tcp_source/src/rtltcp_client.h b/rtl_tcp_source/src/rtltcp_client.h index bf930e68..09d68182 100644 --- a/rtl_tcp_source/src/rtltcp_client.h +++ b/rtl_tcp_source/src/rtltcp_client.h @@ -2,8 +2,18 @@ #include #include #include + +#ifdef _WIN32 #include #include +#else +#include +#include +#include +#include +#include +#include +#endif #ifdef _WIN32 #define __attribute__(x) @@ -28,6 +38,7 @@ public: return true; } +#ifdef _WIN32 struct addrinfo *result = NULL; struct addrinfo *ptr = NULL; struct addrinfo hints; @@ -65,6 +76,23 @@ public: return false; } freeaddrinfo(result); +#else + sockfd = socket(AF_INET, SOCK_STREAM, 0); + if (sockfd < 0) { + // TODO: Log error + return false; + } + struct hostent *server = gethostbyname(host); + struct sockaddr_in serv_addr; + bzero(&serv_addr, sizeof(struct sockaddr_in)); + serv_addr.sin_family = AF_INET; + bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length); + serv_addr.sin_port = port; + if (connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr)) < 0) { + // TODO: log error + return false; + } +#endif connected = true; @@ -75,8 +103,12 @@ public: if (!connected) { return; } +#ifdef _WIN32 closesocket(sock); WSACleanup(); +#else + close(sockfd); +#endif connected = false; } @@ -89,11 +121,19 @@ public: command_t cmd; cmd.cmd = command; cmd.param = htonl(param); - send(sock, (char*)&cmd, sizeof(command_t), 0); +#ifdef _WIN32 + send(sock, (char*)&cmd, sizeof(command_t), 0); +#else + write(sockfd, &cmd, sizeof(command_t)); +#endif } void receiveData(uint8_t* buf, size_t count) { +#ifdef _WIN32 recv(sock, (char*)buf, count, 0); +#else + read(sockfd, buf, count); +#endif } void setFrequency(double freq) { @@ -125,7 +165,12 @@ public: } private: +#ifdef _WIN32 SOCKET sock; +#else + int sockfd; +#endif + bool connected = false; }; \ No newline at end of file