Touch-ups and commentary

This commit is contained in:
Dr. Rubisco 2021-07-27 12:18:50 -04:00 committed by GitHub
parent cd74313bc8
commit d73a18ddcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -405,11 +405,31 @@ private:
client->write(strlen(buf), (uint8_t*)buf); client->write(strlen(buf), (uint8_t*)buf);
} }
else if (parts[0] == "set_mode") { 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] == "?") { if(parts[1] == "?") {
resp = "FM WFM AM DSB USB CW LSB RAW"; resp = "FM WFM AM DSB USB CW LSB RAW";
client->write(resp.size(), (uint8_t*)resp.c_str()); client->write(resp.size(), (uint8_t*)resp.c_str());
return; return;
} }
// Parse mode and bandwidth
int mode; int mode;
switch(parts[1]) { switch(parts[1]) {
case "FM" : mode = RADIO_IFACE_MODE_NFM; case "FM" : mode = RADIO_IFACE_MODE_NFM;
@ -428,7 +448,7 @@ private:
break; break;
case "RAW" : mode = RADIO_IFACE_MODE_RAW; case "RAW" : mode = RADIO_IFACE_MODE_RAW;
break; break;
default: default: // If mode is not supported, return error
spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); spdlog::error("Rigctl client sent invalid command: '{0}'", cmd);
resp = "RPRT 1\n"; resp = "RPRT 1\n";
client->write(resp.size(), (uint8_t*)resp.c_str()); client->write(resp.size(), (uint8_t*)resp.c_str());
@ -436,14 +456,19 @@ private:
} }
int bandwidth = std::stoi(parts[2]); int bandwidth = std::stoi(parts[2]);
// Set mode and bandwidth and respond
core::modComManager.callInterface(selectedVfo, RADIO_IFACE_CMD_SET_MODE, &mode, 0); core::modComManager.callInterface(selectedVfo, RADIO_IFACE_CMD_SET_MODE, &mode, 0);
sigpath::vfoManager.setBandwidth(selectedVfo, bandwidth, true); sigpath::vfoManager.setBandwidth(selectedVfo, bandwidth, true);
resp = "RPRT 0\n"; resp = "RPRT 0\n";
client->write(resp.size(), (uint8_t*)resp.c_str()); client->write(resp.size(), (uint8_t*)resp.c_str());
} }
else if (parts[0] == "get_mode") { else if (parts[0] == "get_mode") {
std::lock_guard lck(vfoMtx);
// Initialize output stream
std::stringstream buf; std::stringstream buf;
// Get mode enum and parse to the output stream
int mode; int mode;
core::modComManager.callInterface(selectedVfo, RADIO_IFACE_CMD_GET_MODE, 0, &mode); core::modComManager.callInterface(selectedVfo, RADIO_IFACE_CMD_GET_MODE, 0, &mode);
switch(mode) { switch(mode) {
@ -464,20 +489,32 @@ private:
case RADIO_IFACE_MODE_RAW : buf << "RAW\n"; case RADIO_IFACE_MODE_RAW : buf << "RAW\n";
break; break;
} }
// Send bandwidth to output stream and respond
buf << sigpath::vfoManager.getBandwidth(selectedVfo) << "\n"; buf << sigpath::vfoManager.getBandwidth(selectedVfo) << "\n";
resp = buf.str(); resp = buf.str();
client->write(resp.size(), (uint8_t*)resp.c_str()); client->write(resp.size(), (uint8_t*)resp.c_str());
} }
else if (parts[0] == "set_vfo") { 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"; resp = "RPRT 0\n";
client->write(resp.size(), (uint8_t*)resp.c_str()); client->write(resp.size(), (uint8_t*)resp.c_str());
} }
else if (parts[0] == "get_vfo") { else if (parts[0] == "get_vfo") {
// Respond with VFO
resp = "VFO\n"; resp = "VFO\n";
client->write(resp.size(), (uint8_t*)resp.c_str()); client->write(resp.size(), (uint8_t*)resp.c_str());
} }
else if (parts[0] == "recorder_start") { else if (parts[0] == "recorder_start") {
std::lock_guard lck(recorderMtx); std::lock_guard lck(recorderMtx);
// If not controlling the recorder, return // If not controlling the recorder, return
if (!recordingEnabled) { if (!recordingEnabled) {
resp = "RPRT 0\n"; resp = "RPRT 0\n";
@ -499,6 +536,7 @@ private:
} }
else if (parts[0] == "recorder_stop") { else if (parts[0] == "recorder_stop") {
std::lock_guard lck(recorderMtx); std::lock_guard lck(recorderMtx);
// If not controlling the recorder, return // If not controlling the recorder, return
if (!recordingEnabled) { if (!recordingEnabled) {
resp = "RPRT 0\n"; resp = "RPRT 0\n";
@ -522,6 +560,7 @@ private:
// Will close automatically // Will close automatically
} }
else { else {
// If command is not recognized, return error
spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); spdlog::error("Rigctl client sent invalid command: '{0}'", cmd);
resp = "RPRT 1\n"; resp = "RPRT 1\n";
client->write(resp.size(), (uint8_t*)resp.c_str()); client->write(resp.size(), (uint8_t*)resp.c_str());
@ -571,11 +610,31 @@ private:
client->write(strlen(buf), (uint8_t*)buf); client->write(strlen(buf), (uint8_t*)buf);
} }
else if (parts[0].at(i) == 'M') { 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] == "?") { if(parts[1] == "?") {
resp = "FM WFM AM DSB USB CW LSB RAW"; resp = "FM WFM AM DSB USB CW LSB RAW";
client->write(resp.size(), (uint8_t*)resp.c_str()); client->write(resp.size(), (uint8_t*)resp.c_str());
return; return;
} }
// Parse mode and bandwidth
int mode; int mode;
switch(parts[1]) { switch(parts[1]) {
case "FM" : mode = RADIO_IFACE_MODE_NFM; case "FM" : mode = RADIO_IFACE_MODE_NFM;
@ -594,7 +653,7 @@ private:
break; break;
case "RAW" : mode = RADIO_IFACE_MODE_RAW; case "RAW" : mode = RADIO_IFACE_MODE_RAW;
break; break;
default: default: // If mode is not supported, return error
spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); spdlog::error("Rigctl client sent invalid command: '{0}'", cmd);
resp = "RPRT 1\n"; resp = "RPRT 1\n";
client->write(resp.size(), (uint8_t*)resp.c_str()); client->write(resp.size(), (uint8_t*)resp.c_str());
@ -602,14 +661,19 @@ private:
} }
int bandwidth = std::stoi(parts[2]); int bandwidth = std::stoi(parts[2]);
// Set mode and bandwidth and respond
core::modComManager.callInterface(selectedVfo, RADIO_IFACE_CMD_SET_MODE, &mode, 0); core::modComManager.callInterface(selectedVfo, RADIO_IFACE_CMD_SET_MODE, &mode, 0);
sigpath::vfoManager.setBandwidth(selectedVfo, bandwidth, true); sigpath::vfoManager.setBandwidth(selectedVfo, bandwidth, true);
resp = "RPRT 0\n"; resp = "RPRT 0\n";
client->write(resp.size(), (uint8_t*)resp.c_str()); client->write(resp.size(), (uint8_t*)resp.c_str());
} }
else if (parts[0].at(i) == 'm') { else if (parts[0].at(i) == 'm') {
std::lock_guard lck(vfoMtx);
// Initialize output stream
std::stringstream buf; std::stringstream buf;
// Get mode enum and parse to the output stream
int mode; int mode;
core::modComManager.callInterface(selectedVfo, RADIO_IFACE_CMD_GET_MODE, 0, &mode); core::modComManager.callInterface(selectedVfo, RADIO_IFACE_CMD_GET_MODE, 0, &mode);
switch(mode) { switch(mode) {
@ -630,15 +694,26 @@ private:
case RADIO_IFACE_MODE_RAW : buf << "RAW\n"; case RADIO_IFACE_MODE_RAW : buf << "RAW\n";
break; break;
} }
// Send bandwidth to output stream and respond
buf << sigpath::vfoManager.getBandwidth(selectedVfo) << "\n"; buf << sigpath::vfoManager.getBandwidth(selectedVfo) << "\n";
resp = buf.str(); resp = buf.str();
client->write(resp.size(), (uint8_t*)resp.c_str()); client->write(resp.size(), (uint8_t*)resp.c_str());
} }
else if (parts[0].at(i) == 'V') { 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"; resp = "RPRT 0\n";
client->write(resp.size(), (uint8_t*)resp.c_str()); client->write(resp.size(), (uint8_t*)resp.c_str());
} }
else if (parts[0].at(i) == 'v') { else if (parts[0].at(i) == 'v') {
// Respond with VFO
resp = "VFO\n"; resp = "VFO\n";
client->write(resp.size(), (uint8_t*)resp.c_str()); client->write(resp.size(), (uint8_t*)resp.c_str());
} }
@ -646,6 +721,7 @@ private:
// Will close automatically // Will close automatically
} }
else { else {
// If command is not recognized, return error
spdlog::error("Rigctl client sent invalid command: '{0}'", cmd); spdlog::error("Rigctl client sent invalid command: '{0}'", cmd);
resp = "RPRT 1\n"; resp = "RPRT 1\n";
client->write(resp.size(), (uint8_t*)resp.c_str()); client->write(resp.size(), (uint8_t*)resp.c_str());