From e27702c1669e0b55f8f4b6b463285cba69b28a99 Mon Sep 17 00:00:00 2001 From: "Dr. Rubisco" <76263371+thedocruby@users.noreply.github.com> Date: Mon, 26 Jul 2021 20:00:32 -0400 Subject: [PATCH 1/9] Rearrange commands, add slash commands. --- rigctl_server/src/main.cpp | 180 ++++++++++++++++++++----------------- 1 file changed, 97 insertions(+), 83 deletions(-) diff --git a/rigctl_server/src/main.cpp b/rigctl_server/src/main.cpp index b7bb2ab8..48a53c5a 100644 --- a/rigctl_server/src/main.cpp +++ b/rigctl_server/src/main.cpp @@ -361,95 +361,109 @@ private: // Execute commands if (parts.size() == 0) { return; } - else if (parts[0] == "F") { - std::lock_guard lck(vfoMtx); + else if (parts[0].at(0) == '\\') { + parts[0].replace(0,1,""); + else if (parts[0] == "recorder_start") { + std::lock_guard lck(recorderMtx); + // If not controlling the recorder, return + if (!recordingEnabled) { + resp = "RPRT 0\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } - // if number of arguments isn't correct, return error - if (parts.size() != 2) { + // Send the command to the selected recorder + if (recorderType == RECORDER_TYPE_METEOR_DEMODULATOR) { + core::modComManager.callInterface(selectedRecorder, METEOR_DEMODULATOR_IFACE_CMD_START, NULL, NULL); + } + else { + core::modComManager.callInterface(selectedRecorder, RECORDER_IFACE_CMD_START, NULL, NULL); + } + + // Respond with a sucess + resp = "RPRT 0\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + } + else if (parts[0] == "recorder_stop") { + std::lock_guard lck(recorderMtx); + // If not controlling the recorder, return + if (!recordingEnabled) { + resp = "RPRT 0\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } + + // Send the command to the selected recorder + if (recorderType == RECORDER_TYPE_METEOR_DEMODULATOR) { + core::modComManager.callInterface(selectedRecorder, METEOR_DEMODULATOR_IFACE_CMD_STOP, NULL, NULL); + } + else { + core::modComManager.callInterface(selectedRecorder, RECORDER_IFACE_CMD_STOP, NULL, NULL); + } + + // Respond with a sucess + resp = "RPRT 0\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + } + else if (parts[0] == "quit") { + // Will close automatically + } + else { + spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); resp = "RPRT 1\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); return; } - - // If not controlling the VFO, return - if (!tuningEnabled) { - resp = "RPRT 0\n"; - client->write(resp.size(), (uint8_t*)resp.c_str()); - return; - } - - // Parse frequency and assign it to the VFO - long long freq = std::stoll(parts[1]); - tuner::tune(tuner::TUNER_MODE_NORMAL, selectedVfo, freq); - resp = "RPRT 0\n"; - client->write(resp.size(), (uint8_t*)resp.c_str()); - } - else if (parts[0] == "f") { - std::lock_guard lck(vfoMtx); - - // Get center frequency of the SDR - double freq = gui::waterfall.getCenterFrequency(); - - // Add the offset of the VFO if it exists - if (sigpath::vfoManager.vfoExists(selectedVfo)) { - freq += sigpath::vfoManager.getOffset(selectedVfo); - } - - // Respond with the frequency - char buf[128]; - sprintf(buf, "%" PRIu64 "\n", (uint64_t)freq); - client->write(strlen(buf), (uint8_t*)buf); - } - else if (parts[0] == "AOS") { - std::lock_guard lck(recorderMtx); - // If not controlling the recorder, return - if (!recordingEnabled) { - resp = "RPRT 0\n"; - client->write(resp.size(), (uint8_t*)resp.c_str()); - return; - } - - // Send the command to the selected recorder - if (recorderType == RECORDER_TYPE_METEOR_DEMODULATOR) { - core::modComManager.callInterface(selectedRecorder, METEOR_DEMODULATOR_IFACE_CMD_START, NULL, NULL); - } - else { - core::modComManager.callInterface(selectedRecorder, RECORDER_IFACE_CMD_START, NULL, NULL); - } - - // Respond with a sucess - resp = "RPRT 0\n"; - client->write(resp.size(), (uint8_t*)resp.c_str()); - } - else if (parts[0] == "LOS") { - std::lock_guard lck(recorderMtx); - // If not controlling the recorder, return - if (!recordingEnabled) { - resp = "RPRT 0\n"; - client->write(resp.size(), (uint8_t*)resp.c_str()); - return; - } - - // Send the command to the selected recorder - if (recorderType == RECORDER_TYPE_METEOR_DEMODULATOR) { - core::modComManager.callInterface(selectedRecorder, METEOR_DEMODULATOR_IFACE_CMD_STOP, NULL, NULL); - } - else { - core::modComManager.callInterface(selectedRecorder, RECORDER_IFACE_CMD_STOP, NULL, NULL); - } - - // Respond with a sucess - resp = "RPRT 0\n"; - client->write(resp.size(), (uint8_t*)resp.c_str()); - } - else if (parts[0] == "q") { - // Will close automatically } else { - spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); - resp = "RPRT 1\n"; - client->write(resp.size(), (uint8_t*)resp.c_str()); - return; + if (parts[0] == "F") { + std::lock_guard lck(vfoMtx); + + // if number of arguments isn't correct, return error + if (parts.size() != 2) { + resp = "RPRT 1\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } + + // If not controlling the VFO, return + if (!tuningEnabled) { + resp = "RPRT 0\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } + + // Parse frequency and assign it to the VFO + long long freq = std::stoll(parts[1]); + tuner::tune(tuner::TUNER_MODE_NORMAL, selectedVfo, freq); + resp = "RPRT 0\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + } + else if (parts[0] == "f") { + std::lock_guard lck(vfoMtx); + + // Get center frequency of the SDR + double freq = gui::waterfall.getCenterFrequency(); + + // Add the offset of the VFO if it exists + if (sigpath::vfoManager.vfoExists(selectedVfo)) { + freq += sigpath::vfoManager.getOffset(selectedVfo); + } + + // Respond with the frequency + char buf[128]; + sprintf(buf, "%" PRIu64 "\n", (uint64_t)freq); + client->write(strlen(buf), (uint8_t*)buf); + } + else if (parts[0] == "q") { + // Will close automatically + } + else { + spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); + resp = "RPRT 1\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } } } @@ -503,4 +517,4 @@ MOD_EXPORT void _DELETE_INSTANCE_(void* instance) { MOD_EXPORT void _END_() { config.disableAutoSave(); config.save(); -} \ No newline at end of file +} From 4092874f5c89c5d253e4ae6132be6a78cfa1fcbc Mon Sep 17 00:00:00 2001 From: "Dr. Rubisco" <76263371+thedocruby@users.noreply.github.com> Date: Mon, 26 Jul 2021 20:06:33 -0400 Subject: [PATCH 2/9] Add support for compound commands --- rigctl_server/src/main.cpp | 86 +++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/rigctl_server/src/main.cpp b/rigctl_server/src/main.cpp index 48a53c5a..5a43bf6b 100644 --- a/rigctl_server/src/main.cpp +++ b/rigctl_server/src/main.cpp @@ -416,53 +416,55 @@ private: } } else { - if (parts[0] == "F") { - std::lock_guard lck(vfoMtx); + for(int i = 0; i < parts[0].length(); i++){ + if (parts[0].at(i) == 'F') { + std::lock_guard lck(vfoMtx); - // if number of arguments isn't correct, return error - if (parts.size() != 2) { + // if number of arguments isn't correct, return error + if (parts.size() != 2) { + resp = "RPRT 1\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } + + // If not controlling the VFO, return + if (!tuningEnabled) { + resp = "RPRT 0\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } + + // Parse frequency and assign it to the VFO + long long freq = std::stoll(parts[1]); + tuner::tune(tuner::TUNER_MODE_NORMAL, selectedVfo, freq); + resp = "RPRT 0\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + } + else if (parts[0].at(i) == 'f') { + std::lock_guard lck(vfoMtx); + + // Get center frequency of the SDR + double freq = gui::waterfall.getCenterFrequency(); + + // Add the offset of the VFO if it exists + if (sigpath::vfoManager.vfoExists(selectedVfo)) { + freq += sigpath::vfoManager.getOffset(selectedVfo); + } + + // Respond with the frequency + char buf[128]; + sprintf(buf, "%" PRIu64 "\n", (uint64_t)freq); + client->write(strlen(buf), (uint8_t*)buf); + } + else if (parts[0].at(i) == 'q') { + // Will close automatically + } + else { + spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); resp = "RPRT 1\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); return; } - - // If not controlling the VFO, return - if (!tuningEnabled) { - resp = "RPRT 0\n"; - client->write(resp.size(), (uint8_t*)resp.c_str()); - return; - } - - // Parse frequency and assign it to the VFO - long long freq = std::stoll(parts[1]); - tuner::tune(tuner::TUNER_MODE_NORMAL, selectedVfo, freq); - resp = "RPRT 0\n"; - client->write(resp.size(), (uint8_t*)resp.c_str()); - } - else if (parts[0] == "f") { - std::lock_guard lck(vfoMtx); - - // Get center frequency of the SDR - double freq = gui::waterfall.getCenterFrequency(); - - // Add the offset of the VFO if it exists - if (sigpath::vfoManager.vfoExists(selectedVfo)) { - freq += sigpath::vfoManager.getOffset(selectedVfo); - } - - // Respond with the frequency - char buf[128]; - sprintf(buf, "%" PRIu64 "\n", (uint64_t)freq); - client->write(strlen(buf), (uint8_t*)buf); - } - else if (parts[0] == "q") { - // Will close automatically - } - else { - spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); - resp = "RPRT 1\n"; - client->write(resp.size(), (uint8_t*)resp.c_str()); - return; } } } From 22e9d25bed553e7a46e3b98202e3d77a0c9e233c Mon Sep 17 00:00:00 2001 From: "Dr. Rubisco" <76263371+thedocruby@users.noreply.github.com> Date: Mon, 26 Jul 2021 20:30:03 -0400 Subject: [PATCH 3/9] Added longform frequency commands for consistency Also: - fixed control error at line 366 - fixed control errors related to returning in compound command loop - added commentary --- rigctl_server/src/main.cpp | 54 +++++++++++++++++++++++++++++++++----- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/rigctl_server/src/main.cpp b/rigctl_server/src/main.cpp index 5a43bf6b..61cc5d48 100644 --- a/rigctl_server/src/main.cpp +++ b/rigctl_server/src/main.cpp @@ -361,8 +361,47 @@ private: // Execute commands if (parts.size() == 0) { return; } - else if (parts[0].at(0) == '\\') { - parts[0].replace(0,1,""); + else if (parts[0].at(0) == '\\') { // Check to see if command is longform + parts[0].replace(0,1,""); // Remove leading backslash + if (parts[0] == "set_freq") { + std::lock_guard lck(vfoMtx); + + // if number of arguments isn't correct, return error + if (parts.size() != 2) { + resp = "RPRT 1\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } + + // If not controlling the VFO, return + if (!tuningEnabled) { + resp = "RPRT 0\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } + + // Parse frequency and assign it to the VFO + long long freq = std::stoll(parts[1]); + tuner::tune(tuner::TUNER_MODE_NORMAL, selectedVfo, freq); + resp = "RPRT 0\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + } + else if (parts[0] == "get_freq") { + std::lock_guard lck(vfoMtx); + + // Get center frequency of the SDR + double freq = gui::waterfall.getCenterFrequency(); + + // Add the offset of the VFO if it exists + if (sigpath::vfoManager.vfoExists(selectedVfo)) { + freq += sigpath::vfoManager.getOffset(selectedVfo); + } + + // Respond with the frequency + char buf[128]; + sprintf(buf, "%" PRIu64 "\n", (uint64_t)freq); + client->write(strlen(buf), (uint8_t*)buf); + } else if (parts[0] == "recorder_start") { std::lock_guard lck(recorderMtx); // If not controlling the recorder, return @@ -416,22 +455,23 @@ private: } } else { - for(int i = 0; i < parts[0].length(); i++){ + for(int i = 0; i < parts[0].length(); i++){ // Loop adds support for compound commands if (parts[0].at(i) == 'F') { std::lock_guard lck(vfoMtx); // if number of arguments isn't correct, return error if (parts.size() != 2) { + spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); resp = "RPRT 1\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); - return; + continue; } // If not controlling the VFO, return if (!tuningEnabled) { resp = "RPRT 0\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); - return; + continue; } // Parse frequency and assign it to the VFO @@ -463,10 +503,12 @@ private: spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); resp = "RPRT 1\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); - return; + break; } } } + + return; } std::string name; From cd74313bc898a1b7769ac0f56ea38ae6b48f31d5 Mon Sep 17 00:00:00 2001 From: "Dr. Rubisco" <76263371+thedocruby@users.noreply.github.com> Date: Tue, 27 Jul 2021 11:57:51 -0400 Subject: [PATCH 4/9] Added mode and vfo commands vfo command is currently a dummy implementation, but as some rigs officially supported by rigctl do not support vfo besides a dummy response, such an implementation is acceptable for now. --- rigctl_server/src/main.cpp | 154 +++++++++++++++++++++++++++++++++++-- 1 file changed, 149 insertions(+), 5 deletions(-) diff --git a/rigctl_server/src/main.cpp b/rigctl_server/src/main.cpp index 61cc5d48..85306b6f 100644 --- a/rigctl_server/src/main.cpp +++ b/rigctl_server/src/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -368,6 +369,7 @@ private: // if number of arguments isn't correct, return error if (parts.size() != 2) { + spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); resp = "RPRT 1\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); return; @@ -402,6 +404,78 @@ private: sprintf(buf, "%" PRIu64 "\n", (uint64_t)freq); client->write(strlen(buf), (uint8_t*)buf); } + else if (parts[0] == "set_mode") { + if(parts[1] == "?") { + resp = "FM WFM AM DSB USB CW LSB RAW"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } + int mode; + switch(parts[1]) { + case "FM" : mode = RADIO_IFACE_MODE_NFM; + break; + case "WFM" : mode = RADIO_IFACE_MODE_WFM; + break; + case "AM" : mode = RADIO_IFACE_MODE_AM; + break; + case "DSB" : mode = RADIO_IFACE_MODE_DSB; + break; + case "USB" : mode = RADIO_IFACE_MODE_USB; + break; + case "CW" : mode = RADIO_IFACE_MODE_CW; + break; + case "LSB" : mode = RADIO_IFACE_MODE_LSB; + break; + case "RAW" : mode = RADIO_IFACE_MODE_RAW; + break; + default: + spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); + resp = "RPRT 1\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } + int bandwidth = std::stoi(parts[2]); + + core::modComManager.callInterface(selectedVfo, RADIO_IFACE_CMD_SET_MODE, &mode, 0); + sigpath::vfoManager.setBandwidth(selectedVfo, bandwidth, true); + + resp = "RPRT 0\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + } + else if (parts[0] == "get_mode") { + std::stringstream buf; + int mode; + core::modComManager.callInterface(selectedVfo, RADIO_IFACE_CMD_GET_MODE, 0, &mode); + switch(mode) { + case RADIO_IFACE_MODE_NFM : buf << "FM\n"; + break; + case RADIO_IFACE_MODE_WFM : buf << "WFM\n"; + break; + case RADIO_IFACE_MODE_AM : buf << "AM\n"; + break; + case RADIO_IFACE_MODE_DSB : buf << "DSB\n"; + break; + case RADIO_IFACE_MODE_USB : buf << "USB\n"; + break; + case RADIO_IFACE_MODE_CW : buf << "CW\n"; + break; + case RADIO_IFACE_MODE_LSB : buf << "LSB\n"; + break; + case RADIO_IFACE_MODE_RAW : buf << "RAW\n"; + break; + } + buf << sigpath::vfoManager.getBandwidth(selectedVfo) << "\n"; + resp = buf.str(); + client->write(resp.size(), (uint8_t*)resp.c_str()); + } + else if (parts[0] == "set_vfo") { + resp = "RPRT 0\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + } + else if (parts[0] == "get_vfo") { + resp = "VFO\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + } else if (parts[0] == "recorder_start") { std::lock_guard lck(recorderMtx); // If not controlling the recorder, return @@ -464,14 +538,14 @@ private: spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); resp = "RPRT 1\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); - continue; + return; } // If not controlling the VFO, return if (!tuningEnabled) { resp = "RPRT 0\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); - continue; + return; } // Parse frequency and assign it to the VFO @@ -496,6 +570,78 @@ private: sprintf(buf, "%" PRIu64 "\n", (uint64_t)freq); client->write(strlen(buf), (uint8_t*)buf); } + else if (parts[0].at(i) == 'M') { + if(parts[1] == "?") { + resp = "FM WFM AM DSB USB CW LSB RAW"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } + int mode; + switch(parts[1]) { + case "FM" : mode = RADIO_IFACE_MODE_NFM; + break; + case "WFM" : mode = RADIO_IFACE_MODE_WFM; + break; + case "AM" : mode = RADIO_IFACE_MODE_AM; + break; + case "DSB" : mode = RADIO_IFACE_MODE_DSB; + break; + case "USB" : mode = RADIO_IFACE_MODE_USB; + break; + case "CW" : mode = RADIO_IFACE_MODE_CW; + break; + case "LSB" : mode = RADIO_IFACE_MODE_LSB; + break; + case "RAW" : mode = RADIO_IFACE_MODE_RAW; + break; + default: + spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); + resp = "RPRT 1\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } + int bandwidth = std::stoi(parts[2]); + + core::modComManager.callInterface(selectedVfo, RADIO_IFACE_CMD_SET_MODE, &mode, 0); + sigpath::vfoManager.setBandwidth(selectedVfo, bandwidth, true); + + resp = "RPRT 0\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + } + else if (parts[0].at(i) == 'm') { + std::stringstream buf; + int mode; + core::modComManager.callInterface(selectedVfo, RADIO_IFACE_CMD_GET_MODE, 0, &mode); + switch(mode) { + case RADIO_IFACE_MODE_NFM : buf << "FM\n"; + break; + case RADIO_IFACE_MODE_WFM : buf << "WFM\n"; + break; + case RADIO_IFACE_MODE_AM : buf << "AM\n"; + break; + case RADIO_IFACE_MODE_DSB : buf << "DSB\n"; + break; + case RADIO_IFACE_MODE_USB : buf << "USB\n"; + break; + case RADIO_IFACE_MODE_CW : buf << "CW\n"; + break; + case RADIO_IFACE_MODE_LSB : buf << "LSB\n"; + break; + case RADIO_IFACE_MODE_RAW : buf << "RAW\n"; + break; + } + buf << sigpath::vfoManager.getBandwidth(selectedVfo) << "\n"; + resp = buf.str(); + client->write(resp.size(), (uint8_t*)resp.c_str()); + } + else if (parts[0].at(i) == 'V') { + resp = "RPRT 0\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + } + else if (parts[0].at(i) == 'v') { + resp = "VFO\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + } else if (parts[0].at(i) == 'q') { // Will close automatically } @@ -503,12 +649,10 @@ private: spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); resp = "RPRT 1\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); - break; + return; } } } - - return; } std::string name; From d73a18ddcc92d824e0d80c67fa8dcb47c7a21ce7 Mon Sep 17 00:00:00 2001 From: "Dr. Rubisco" <76263371+thedocruby@users.noreply.github.com> Date: Tue, 27 Jul 2021 12:18:50 -0400 Subject: [PATCH 5/9] Touch-ups and commentary --- rigctl_server/src/main.cpp | 84 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 80 insertions(+), 4 deletions(-) diff --git a/rigctl_server/src/main.cpp b/rigctl_server/src/main.cpp index 85306b6f..b3a9635f 100644 --- a/rigctl_server/src/main.cpp +++ b/rigctl_server/src/main.cpp @@ -405,11 +405,31 @@ private: client->write(strlen(buf), (uint8_t*)buf); } else if (parts[0] == "set_mode") { + std::lock_guard lck(vfoMtx); + + // if number of arguments isn't correct, return error + if (parts.size() != 3) { + spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); + resp = "RPRT 1\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } + + // If not controlling the VFO, return + if (!tuningEnabled) { + resp = "RPRT 0\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } + + // If client is querying, respond accordingly if(parts[1] == "?") { resp = "FM WFM AM DSB USB CW LSB RAW"; client->write(resp.size(), (uint8_t*)resp.c_str()); return; } + + // Parse mode and bandwidth int mode; switch(parts[1]) { case "FM" : mode = RADIO_IFACE_MODE_NFM; @@ -428,7 +448,7 @@ private: break; case "RAW" : mode = RADIO_IFACE_MODE_RAW; break; - default: + default: // If mode is not supported, return error spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); resp = "RPRT 1\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); @@ -436,14 +456,19 @@ private: } int bandwidth = std::stoi(parts[2]); + // Set mode and bandwidth and respond core::modComManager.callInterface(selectedVfo, RADIO_IFACE_CMD_SET_MODE, &mode, 0); sigpath::vfoManager.setBandwidth(selectedVfo, bandwidth, true); - resp = "RPRT 0\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); } else if (parts[0] == "get_mode") { + std::lock_guard lck(vfoMtx); + + // Initialize output stream std::stringstream buf; + + // Get mode enum and parse to the output stream int mode; core::modComManager.callInterface(selectedVfo, RADIO_IFACE_CMD_GET_MODE, 0, &mode); switch(mode) { @@ -464,20 +489,32 @@ private: case RADIO_IFACE_MODE_RAW : buf << "RAW\n"; break; } + // Send bandwidth to output stream and respond buf << sigpath::vfoManager.getBandwidth(selectedVfo) << "\n"; resp = buf.str(); client->write(resp.size(), (uint8_t*)resp.c_str()); } else if (parts[0] == "set_vfo") { + // if number of arguments isn't correct, return error + if (parts.size() != 2) { + spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); + resp = "RPRT 1\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } + + // Respond resp = "RPRT 0\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); } else if (parts[0] == "get_vfo") { + // Respond with VFO resp = "VFO\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); } else if (parts[0] == "recorder_start") { std::lock_guard lck(recorderMtx); + // If not controlling the recorder, return if (!recordingEnabled) { resp = "RPRT 0\n"; @@ -499,6 +536,7 @@ private: } else if (parts[0] == "recorder_stop") { std::lock_guard lck(recorderMtx); + // If not controlling the recorder, return if (!recordingEnabled) { resp = "RPRT 0\n"; @@ -522,6 +560,7 @@ private: // Will close automatically } else { + // If command is not recognized, return error spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); resp = "RPRT 1\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); @@ -571,11 +610,31 @@ private: client->write(strlen(buf), (uint8_t*)buf); } else if (parts[0].at(i) == 'M') { + std::lock_guard lck(vfoMtx); + + // if number of arguments isn't correct, return error + if (parts.size() != 3) { + spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); + resp = "RPRT 1\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } + + // If not controlling the VFO, return + if (!tuningEnabled) { + resp = "RPRT 0\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } + + // If client is querying, respond accordingly if(parts[1] == "?") { resp = "FM WFM AM DSB USB CW LSB RAW"; client->write(resp.size(), (uint8_t*)resp.c_str()); return; } + + // Parse mode and bandwidth int mode; switch(parts[1]) { case "FM" : mode = RADIO_IFACE_MODE_NFM; @@ -594,7 +653,7 @@ private: break; case "RAW" : mode = RADIO_IFACE_MODE_RAW; break; - default: + default: // If mode is not supported, return error spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); resp = "RPRT 1\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); @@ -602,14 +661,19 @@ private: } int bandwidth = std::stoi(parts[2]); + // Set mode and bandwidth and respond core::modComManager.callInterface(selectedVfo, RADIO_IFACE_CMD_SET_MODE, &mode, 0); sigpath::vfoManager.setBandwidth(selectedVfo, bandwidth, true); - resp = "RPRT 0\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); } else if (parts[0].at(i) == 'm') { + std::lock_guard lck(vfoMtx); + + // Initialize output stream std::stringstream buf; + + // Get mode enum and parse to the output stream int mode; core::modComManager.callInterface(selectedVfo, RADIO_IFACE_CMD_GET_MODE, 0, &mode); switch(mode) { @@ -630,15 +694,26 @@ private: case RADIO_IFACE_MODE_RAW : buf << "RAW\n"; break; } + // Send bandwidth to output stream and respond buf << sigpath::vfoManager.getBandwidth(selectedVfo) << "\n"; resp = buf.str(); client->write(resp.size(), (uint8_t*)resp.c_str()); } else if (parts[0].at(i) == 'V') { + // if number of arguments isn't correct, return error + if (parts.size() != 3) { + spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); + resp = "RPRT 1\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; + } + + // Respond resp = "RPRT 0\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); } else if (parts[0].at(i) == 'v') { + // Respond with VFO resp = "VFO\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); } @@ -646,6 +721,7 @@ private: // Will close automatically } else { + // If command is not recognized, return error spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); resp = "RPRT 1\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); From 8f43110c7241bea08a1c96c12f6309d58bbd5238 Mon Sep 17 00:00:00 2001 From: "Dr. Rubisco" <76263371+thedocruby@users.noreply.github.com> Date: Tue, 27 Jul 2021 12:46:25 -0400 Subject: [PATCH 6/9] Fix dependency issue --- rigctl_server/CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rigctl_server/CMakeLists.txt b/rigctl_server/CMakeLists.txt index cb7ff5ef..5c81e77a 100644 --- a/rigctl_server/CMakeLists.txt +++ b/rigctl_server/CMakeLists.txt @@ -14,10 +14,11 @@ file(GLOB SRC "src/*.cpp") include_directories("src/") include_directories("../recorder/src") include_directories("../meteor_demodulator/src") +include_directories("../radio/src") add_library(rigctl_server SHARED ${SRC}) target_link_libraries(rigctl_server PRIVATE sdrpp_core) set_target_properties(rigctl_server PROPERTIES PREFIX "") # Install directives -install(TARGETS rigctl_server DESTINATION lib/sdrpp/plugins) \ No newline at end of file +install(TARGETS rigctl_server DESTINATION lib/sdrpp/plugins) From d21a61aefdb7351d3b34e71ff03484175381000a Mon Sep 17 00:00:00 2001 From: "Dr. Rubisco" <76263371+thedocruby@users.noreply.github.com> Date: Tue, 27 Jul 2021 13:01:15 -0400 Subject: [PATCH 7/9] Switches only take ints dumb mistake. I squashed the if-else chain just a bit so that it wasn't any longer than the switch. it's already really, long, I didn't want it to be any longer. Thought it might be more readable this way. --- rigctl_server/src/main.cpp | 44 +++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/rigctl_server/src/main.cpp b/rigctl_server/src/main.cpp index b3a9635f..f544f45d 100644 --- a/rigctl_server/src/main.cpp +++ b/rigctl_server/src/main.cpp @@ -431,28 +431,28 @@ private: // Parse mode and bandwidth int mode; - switch(parts[1]) { - case "FM" : mode = RADIO_IFACE_MODE_NFM; - break; - case "WFM" : mode = RADIO_IFACE_MODE_WFM; - break; - case "AM" : mode = RADIO_IFACE_MODE_AM; - break; - case "DSB" : mode = RADIO_IFACE_MODE_DSB; - break; - case "USB" : mode = RADIO_IFACE_MODE_USB; - break; - case "CW" : mode = RADIO_IFACE_MODE_CW; - break; - case "LSB" : mode = RADIO_IFACE_MODE_LSB; - break; - case "RAW" : mode = RADIO_IFACE_MODE_RAW; - break; - default: // If mode is not supported, return error - spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); - resp = "RPRT 1\n"; - client->write(resp.size(), (uint8_t*)resp.c_str()); - return; + if(parts[1] == "FM"){ + mode = RADIO_IFACE_MODE_NFM; + }else if(parts[1] == "WFM"){ + mode = RADIO_IFACE_MODE_WFM; + }else if(parts[1] == "AM"){ + mode = RADIO_IFACE_MODE_AM; + }else if(parts[1] == "DSB"){ + mode = RADIO_IFACE_MODE_DSB; + }else if(parts[1] == "USB"){ + mode = RADIO_IFACE_MODE_USB; + }else if(parts[1] == "CW"){ + mode = RADIO_IFACE_MODE_CW; + }else if(parts[1] == "LSB"){ + mode = RADIO_IFACE_MODE_LSB; + }else if(parts[1] == "RAW"){ + mode = RADIO_IFACE_MODE_RAW; + }else{ + // If mode is not supported, return error + spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); + resp = "RPRT 1\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; } int bandwidth = std::stoi(parts[2]); From 666b89c4c7063bdfbb76218a5b8b8bcf64aef7f2 Mon Sep 17 00:00:00 2001 From: "Dr. Rubisco" <76263371+thedocruby@users.noreply.github.com> Date: Tue, 27 Jul 2021 13:02:31 -0400 Subject: [PATCH 8/9] Copy down last edit --- rigctl_server/src/main.cpp | 44 +++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/rigctl_server/src/main.cpp b/rigctl_server/src/main.cpp index f544f45d..2c8b17b7 100644 --- a/rigctl_server/src/main.cpp +++ b/rigctl_server/src/main.cpp @@ -636,28 +636,28 @@ private: // Parse mode and bandwidth int mode; - switch(parts[1]) { - case "FM" : mode = RADIO_IFACE_MODE_NFM; - break; - case "WFM" : mode = RADIO_IFACE_MODE_WFM; - break; - case "AM" : mode = RADIO_IFACE_MODE_AM; - break; - case "DSB" : mode = RADIO_IFACE_MODE_DSB; - break; - case "USB" : mode = RADIO_IFACE_MODE_USB; - break; - case "CW" : mode = RADIO_IFACE_MODE_CW; - break; - case "LSB" : mode = RADIO_IFACE_MODE_LSB; - break; - case "RAW" : mode = RADIO_IFACE_MODE_RAW; - break; - default: // If mode is not supported, return error - spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); - resp = "RPRT 1\n"; - client->write(resp.size(), (uint8_t*)resp.c_str()); - return; + if(parts[1] == "FM"){ + mode = RADIO_IFACE_MODE_NFM; + }else if(parts[1] == "WFM"){ + mode = RADIO_IFACE_MODE_WFM; + }else if(parts[1] == "AM"){ + mode = RADIO_IFACE_MODE_AM; + }else if(parts[1] == "DSB"){ + mode = RADIO_IFACE_MODE_DSB; + }else if(parts[1] == "USB"){ + mode = RADIO_IFACE_MODE_USB; + }else if(parts[1] == "CW"){ + mode = RADIO_IFACE_MODE_CW; + }else if(parts[1] == "LSB"){ + mode = RADIO_IFACE_MODE_LSB; + }else if(parts[1] == "RAW"){ + mode = RADIO_IFACE_MODE_RAW; + }else{ + // If mode is not supported, return error + spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); + resp = "RPRT 1\n"; + client->write(resp.size(), (uint8_t*)resp.c_str()); + return; } int bandwidth = std::stoi(parts[2]); From e9cdf162faf721795966bb95a7eb40b877f94f3d Mon Sep 17 00:00:00 2001 From: AlexandreRouma Date: Thu, 29 Jul 2021 21:20:40 +0200 Subject: [PATCH 9/9] More fixes --- rigctl_server/src/main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rigctl_server/src/main.cpp b/rigctl_server/src/main.cpp index 1bc00189..4139c6b0 100644 --- a/rigctl_server/src/main.cpp +++ b/rigctl_server/src/main.cpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -392,6 +391,7 @@ private: if (!tuningEnabled) { resp = "RPRT 0\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); + return; } // Parse frequency and assign it to the VFO @@ -551,7 +551,7 @@ private: resp = "VFO\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); } - else if (parts[0] == "\\recorder_start") { + else if (parts[0] == "AOS" || parts[0] == "\\recorder_start") { std::lock_guard lck(recorderMtx); // If not controlling the recorder, return @@ -573,7 +573,7 @@ private: resp = "RPRT 0\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); } - else if (parts[0] == "\\recorder_stop") { + else if (parts[0] == "LOS" || parts[0] == "\\recorder_stop") { std::lock_guard lck(recorderMtx); // If not controlling the recorder, return @@ -595,7 +595,7 @@ private: resp = "RPRT 0\n"; client->write(resp.size(), (uint8_t*)resp.c_str()); } - else if (parts[0] == "quit") { + else if (parts[0] == "q" || parts[0] == "\\quit") { // Will close automatically } else {