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] 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;