diff --git a/core/src/gui/main_window.cpp b/core/src/gui/main_window.cpp index dec57544..ada9929f 100644 --- a/core/src/gui/main_window.cpp +++ b/core/src/gui/main_window.cpp @@ -610,4 +610,8 @@ void drawWindow() { void setViewBandwidthSlider(float bandwidth) { bw = bandwidth; +} + +bool sdrIsRunning() { + return playing; } \ No newline at end of file diff --git a/core/src/gui/main_window.h b/core/src/gui/main_window.h index aae67c5b..e0e95fce 100644 --- a/core/src/gui/main_window.h +++ b/core/src/gui/main_window.h @@ -5,4 +5,5 @@ void windowInit(); void drawWindow(); -void setViewBandwidthSlider(float bandwidth); \ No newline at end of file +void setViewBandwidthSlider(float bandwidth); +bool sdrIsRunning(); \ No newline at end of file diff --git a/core/src/gui/menus/source.cpp b/core/src/gui/menus/source.cpp index fe640892..e8bdd27e 100644 --- a/core/src/gui/menus/source.cpp +++ b/core/src/gui/menus/source.cpp @@ -2,6 +2,8 @@ #include #include #include +#include +#include #include namespace sourecmenu { @@ -33,6 +35,8 @@ namespace sourecmenu { items += '\0'; } float itemWidth = ImGui::GetContentRegionAvailWidth(); + + if (sdrIsRunning()) { style::beginDisabled(); } ImGui::SetNextItemWidth(itemWidth); if (ImGui::Combo("##source", &sourceId, items.c_str())) { @@ -42,7 +46,10 @@ namespace sourecmenu { core::configManager.release(true); } + if (sdrIsRunning()) { style::endDisabled(); } + sigpath::sourceManager.showSelectedMenu(); + ImGui::SetNextItemWidth(itemWidth - ImGui::CalcTextSize("Offset (Hz)").x - 10); if (ImGui::InputDouble("Offset (Hz)##freq_offset", &freqOffset, 1.0, 100.0)) { sigpath::sourceManager.setTuningOffset(freqOffset); diff --git a/readme.md b/readme.md index a7b1a518..f23b619d 100644 --- a/readme.md +++ b/readme.md @@ -136,6 +136,8 @@ Next install dependencies based on the modules you wish to build: * plutosdr_source: libiio, libad9361 * audio_sink: portaudio +Note: make sure you're using GCC 8 or later as older versions do not have `std::filesystem` built-in. + ## Building replace `` with the number of threads you wish to use to build ```sh diff --git a/rtl_tcp_source/src/main.cpp b/rtl_tcp_source/src/main.cpp index dd09a363..3936ed82 100644 --- a/rtl_tcp_source/src/main.cpp +++ b/rtl_tcp_source/src/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #define CONCAT(a, b) ((std::string(a) + b).c_str()) @@ -17,6 +18,34 @@ SDRPP_MOD_INFO { /* Max instances */ 1 }; +ConfigManager config; + +const double sampleRates[] = { + 250000, + 1024000, + 1536000, + 1792000, + 1920000, + 2048000, + 2160000, + 2560000, + 2880000, + 3200000 +}; + +const char* sampleRatesTxt[] = { + "250KHz", + "1.024MHz", + "1.536MHz", + "1.792MHz", + "1.92MHz", + "2.048MHz", + "2.16MHz", + "2.56MHz", + "2.88MHz", + "3.2MHz" +}; + class RTLTCPSourceModule : public ModuleManager::Instance { public: RTLTCPSourceModule(std::string name) { @@ -24,6 +53,24 @@ public: sampleRate = 2560000.0; + int srCount = sizeof(sampleRatesTxt) / sizeof(char*); + for (int i = 0; i < srCount; i++) { + srTxt += sampleRatesTxt[i]; + srTxt += '\0'; + } + srId = 7; + + config.aquire(); + std::string hostStr = config.conf["host"]; + port = config.conf["port"]; + directSamplingMode = config.conf["directSamplingMode"]; + rtlAGC = config.conf["rtlAGC"]; + tunerAGC = config.conf["tunerAGC"]; + gain = config.conf["gainIndex"]; + hostStr = hostStr.substr(0, 1023); + strcpy(ip, hostStr.c_str()); + config.release(); + handler.ctx = this; handler.selectHandler = menuSelected; handler.deselectHandler = menuDeselected; @@ -72,12 +119,13 @@ private: spdlog::error("Could not connect to {0}:{1}", _this->ip, _this->port); return; } + spdlog::warn("Setting sample rate to {0}", _this->sampleRate); _this->client.setFrequency(_this->freq); _this->client.setSampleRate(_this->sampleRate); - _this->client.setGainIndex(_this->gain); _this->client.setGainMode(!_this->tunerAGC); _this->client.setDirectSampling(_this->directSamplingMode); _this->client.setAGCMode(_this->rtlAGC); + _this->client.setGainIndex(_this->gain); _this->running = true; _this->workerThread = std::thread(worker, _this); spdlog::info("RTLTCPSourceModule '{0}': Start!", _this->name); @@ -110,22 +158,36 @@ private: float menuWidth = ImGui::GetContentRegionAvailWidth(); float portWidth = ImGui::CalcTextSize("00000").x + 20; + if (_this->running) { style::beginDisabled(); } + ImGui::SetNextItemWidth(menuWidth - portWidth); ImGui::InputText(CONCAT("##_ip_select_", _this->name), _this->ip, 1024); ImGui::SameLine(); ImGui::SetNextItemWidth(portWidth); ImGui::InputInt(CONCAT("##_port_select_", _this->name), &_this->port, 0); + ImGui::SetNextItemWidth(menuWidth); + if (ImGui::Combo(CONCAT("##_rtltcp_sr_", _this->name), &_this->srId, _this->srTxt.c_str())) { + _this->sampleRate = sampleRates[_this->srId]; + core::setInputSampleRate(_this->sampleRate); + } + + if (_this->running) { style::endDisabled(); } + ImGui::SetNextItemWidth(ImGui::CalcTextSize("OOOOOOOOOO").x); - if (ImGui::Combo("Direct sampling", &_this->directSamplingMode, "Disabled\0I branch\0Q branch\0")) { + if (ImGui::Combo(CONCAT("Direct Sampling##_rtltcp_ds_", _this->name), &_this->directSamplingMode, "Disabled\0I branch\0Q branch\0")) { if (_this->running) { _this->client.setDirectSampling(_this->directSamplingMode); + _this->client.setGainIndex(_this->gain); } } if (ImGui::Checkbox("RTL AGC", &_this->rtlAGC)) { if (_this->running) { _this->client.setAGCMode(_this->rtlAGC); + if (!_this->rtlAGC) { + _this->client.setGainIndex(_this->gain); + } } } @@ -182,10 +244,22 @@ private: bool rtlAGC = false; bool tunerAGC = false; int directSamplingMode = 0; + int srId = 0; + + std::string srTxt = ""; }; MOD_EXPORT void _INIT_() { - // Do your one time init here + config.setPath(options::opts.root + "/rtl_tcp_config.json"); + json defConf; + defConf["host"] = "localhost"; + defConf["port"] = 1234; + defConf["directSamplingMode"] = 0; + defConf["rtlAGC"] = false; + defConf["tunerAGC"] = false; + defConf["gainIndex"] = 0; + config.load(defConf); + config.enableAutoSave(); } MOD_EXPORT ModuleManager::Instance* _CREATE_INSTANCE_(std::string name) { @@ -197,5 +271,6 @@ MOD_EXPORT void _DELETE_INSTANCE_(ModuleManager::Instance* instance) { } MOD_EXPORT void _END_() { - // Do your one shutdown here + config.disableAutoSave(); + config.save(); } \ 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 c00057e2..f563d89e 100644 --- a/rtl_tcp_source/src/rtltcp_client.h +++ b/rtl_tcp_source/src/rtltcp_client.h @@ -43,6 +43,9 @@ public: struct addrinfo *ptr = NULL; struct addrinfo hints; + WSADATA wsaData; + WSAStartup(MAKEWORD(2,2), &wsaData); + ZeroMemory( &hints, sizeof(hints) ); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; @@ -54,7 +57,7 @@ public: int iResult = getaddrinfo(host, buf, &hints, &result); if (iResult != 0) { // TODO: log error - printf("A"); + printf("\n%s\n", gai_strerror(iResult)); WSACleanup(); return false; }