From eff7bbdd5a886d3b5fa5d91ee082777ace123046 Mon Sep 17 00:00:00 2001 From: Ryzerth Date: Sun, 4 Oct 2020 15:23:40 +0200 Subject: [PATCH] added new patrons --- core/src/gui/dialogs/credits.cpp | 1 + core/src/io/soapy.h | 185 ----------------------------- readme.md | 1 + root_dev/soapy_source_config.json | 2 +- rtl_tcp_source/src/main.cpp | 6 + rtl_tcp_source/src/rtltcp_client.h | 11 ++ 6 files changed, 20 insertions(+), 186 deletions(-) delete mode 100644 core/src/io/soapy.h diff --git a/core/src/gui/dialogs/credits.cpp b/core/src/gui/dialogs/credits.cpp index 5abd1e8..060fc92 100644 --- a/core/src/gui/dialogs/credits.cpp +++ b/core/src/gui/dialogs/credits.cpp @@ -50,6 +50,7 @@ namespace credits { ImGui::NextColumn(); ImGui::Text("Patrons"); ImGui::BulletText("SignalsEverywhere"); + ImGui::BulletText("Lee Donaghy"); ImGui::EndPopup(); ImGui::PopStyleVar(1); diff --git a/core/src/io/soapy.h b/core/src/io/soapy.h deleted file mode 100644 index 5415183..0000000 --- a/core/src/io/soapy.h +++ /dev/null @@ -1,185 +0,0 @@ -#pragma once -#include -#include -#include -#include -#include -#include -#include - -namespace io { - class SoapyWrapper { - public: - SoapyWrapper() { - - } - - void init() { - SoapySDR::registerLogHandler(_logHandler); - //SoapySDR::Device::make(""); - - output.init(64000); - currentGains = new float[1]; - refresh(); - if (devList.size() == 0) { - dev = NULL; - return; - } - setDevice(devList[0]); - } - - void start() { - if (devList.size() == 0) { - return; - } - if (running) { - return; - } - dev = SoapySDR::Device::make(args); - _stream = dev->setupStream(SOAPY_SDR_RX, "CF32"); - dev->activateStream(_stream); - running = true; - _workerThread = std::thread(_worker, this); - } - - void stop() { - if (!running) { - return; - } - running = false; - dev->deactivateStream(_stream); - dev->closeStream(_stream); - _workerThread.join(); - SoapySDR::Device::unmake(dev); - } - - void refresh() { - if (running) { - return; - } - devList = SoapySDR::Device::enumerate(); - txtDevList = ""; - devNameList.clear(); - if (devList.size() == 0) { - txtDevList += '\0'; - return; - } - for (int i = 0; i < devList.size(); i++) { - txtDevList += devList[i]["label"]; - txtDevList += '\0'; - devNameList.push_back(devList[i]["label"]); - } - } - - void setDevice(SoapySDR::Kwargs devArgs) { - if (running) { - return; - } - args = devArgs; - dev = SoapySDR::Device::make(devArgs); - txtSampleRateList = ""; - sampleRates = dev->listSampleRates(SOAPY_SDR_RX, 0); - for (int i = 0; i < sampleRates.size(); i++) { - txtSampleRateList += std::to_string((int)sampleRates[i]); - txtSampleRateList += '\0'; - } - _sampleRate = sampleRates[0]; - - gainList = dev->listGains(SOAPY_SDR_RX, 0); - gainRanges.clear(); - if (gainList.size() == 0) { - return; - } - delete[] currentGains; - currentGains = new float[gainList.size()]; - for (int i = 0; i < gainList.size(); i++) { - gainRanges.push_back(dev->getGainRange(SOAPY_SDR_RX, 0, gainList[i])); - SoapySDR::Range rng = dev->getGainRange(SOAPY_SDR_RX, 0, gainList[i]); - - spdlog::info("{0}: {1} -> {2} (Step: {3})", gainList[i], rng.minimum(), rng.maximum(), rng.step()); - - currentGains[i] = rng.minimum(); - } - } - - void setSampleRate(float sampleRate) { - if (running || dev == NULL) { - return; - } - _sampleRate = sampleRate; - dev->setSampleRate(SOAPY_SDR_RX, 0, sampleRate); - } - - void setFrequency(float freq) { - if (dev == NULL) { - return; - } - dev->setFrequency(SOAPY_SDR_RX, 0, freq); - } - - void setGain(int gainId, float gain) { - if (dev == NULL) { - return; - } - currentGains[gainId] = gain; - dev->setGain(SOAPY_SDR_RX, 0, gainList[gainId], gain); - } - - bool isRunning() { - return running; - } - - float getSampleRate() { - return _sampleRate; - } - - SoapySDR::KwargsList devList; - std::vector devNameList; - std::string txtDevList; - - std::vector sampleRates; - std::string txtSampleRateList; - - std::vector gainList; - std::vector gainRanges; - float* currentGains; - - dsp::stream output; - - private: - static void _worker(SoapyWrapper* _this) { - int blockSize = _this->_sampleRate / 200.0f; - dsp::complex_t* buf = new dsp::complex_t[blockSize]; - int flags = 0; - long long timeMs = 0; - - while (_this->running) { - int res = _this->dev->readStream(_this->_stream, (void**)&buf, blockSize, flags, timeMs); - if (res < 1) { - continue; - } - _this->output.write(buf, res); - } - delete[] buf; - } - - static void _logHandler(const SoapySDRLogLevel lvl, const char* message) { - if (lvl == SOAPY_SDR_FATAL || lvl == SOAPY_SDR_CRITICAL || lvl == SOAPY_SDR_ERROR) { - spdlog::error(message); - } - else if (lvl == SOAPY_SDR_WARNING) { - spdlog::warn(message); - } - else if (lvl == SOAPY_SDR_NOTICE | SOAPY_SDR_INFO) { - spdlog::info(message); - } - } - - SoapySDR::Kwargs args; - SoapySDR::Device* dev; - SoapySDR::Stream* _stream; - std::thread _workerThread; - bool running = false; - float _sampleRate = 0; - }; -}; \ No newline at end of file diff --git a/readme.md b/readme.md index 9c0e69b..1db8333 100644 --- a/readme.md +++ b/readme.md @@ -73,6 +73,7 @@ I will soon publish a contributing.md listing the code style to use. ## Patrons * [SignalsEverywhere](https://signalseverywhere.com/) +* [Lee Donaghy](https://github.com/github) ## Contributors * [aosync](https://github.com/aosync) diff --git a/root_dev/soapy_source_config.json b/root_dev/soapy_source_config.json index 1e60665..06f6e45 100644 --- a/root_dev/soapy_source_config.json +++ b/root_dev/soapy_source_config.json @@ -1,5 +1,5 @@ { - "device": "Generic RTL2832U OEM :: 00000001", + "device": "HackRF One #0 901868dc282c8f8b", "devices": { "Generic RTL2832U OEM :: 00000001": { "gains": { diff --git a/rtl_tcp_source/src/main.cpp b/rtl_tcp_source/src/main.cpp index ad35dc7..a072432 100644 --- a/rtl_tcp_source/src/main.cpp +++ b/rtl_tcp_source/src/main.cpp @@ -56,6 +56,9 @@ private: static void start(void* ctx) { RTLTCPSourceModule* _this = (RTLTCPSourceModule*)ctx; + if (_this->running) { + return; + } if (!_this->client.connectToRTL(_this->ip, _this->port)) { spdlog::error("Could not connect to {0}:{1}", _this->ip, _this->port); return; @@ -73,6 +76,9 @@ private: static void stop(void* ctx) { RTLTCPSourceModule* _this = (RTLTCPSourceModule*)ctx; + if (!_this->running) { + return; + } _this->running = false; _this->stream.stopWriter(); _this->workerThread.join(); diff --git a/rtl_tcp_source/src/rtltcp_client.h b/rtl_tcp_source/src/rtltcp_client.h index 2fc4435..bf930e6 100644 --- a/rtl_tcp_source/src/rtltcp_client.h +++ b/rtl_tcp_source/src/rtltcp_client.h @@ -24,6 +24,10 @@ public: } bool connectToRTL(char* host, uint16_t port) { + if (connected) { + return true; + } + struct addrinfo *result = NULL; struct addrinfo *ptr = NULL; struct addrinfo hints; @@ -62,12 +66,18 @@ public: } freeaddrinfo(result); + connected = true; + return true; } void disconnect() { + if (!connected) { + return; + } closesocket(sock); WSACleanup(); + connected = false; } // struct command_t { @@ -116,5 +126,6 @@ public: private: SOCKET sock; + bool connected = false; }; \ No newline at end of file