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
This commit is contained in:
Dr. Rubisco 2021-07-26 20:30:03 -04:00 committed by GitHub
parent 4092874f5c
commit 22e9d25bed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -361,8 +361,47 @@ private:
// Execute commands // Execute commands
if (parts.size() == 0) { return; } if (parts.size() == 0) { return; }
else if (parts[0].at(0) == '\\') { else if (parts[0].at(0) == '\\') { // Check to see if command is longform
parts[0].replace(0,1,""); 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") { 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
@ -416,22 +455,23 @@ private:
} }
} }
else { 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') { if (parts[0].at(i) == 'F') {
std::lock_guard lck(vfoMtx); std::lock_guard lck(vfoMtx);
// if number of arguments isn't correct, return error // if number of arguments isn't correct, return error
if (parts.size() != 2) { if (parts.size() != 2) {
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());
return; continue;
} }
// If not controlling the VFO, return // If not controlling the VFO, return
if (!tuningEnabled) { if (!tuningEnabled) {
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());
return; continue;
} }
// Parse frequency and assign it to the VFO // Parse frequency and assign it to the VFO
@ -463,10 +503,12 @@ private:
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());
return; break;
} }
} }
} }
return;
} }
std::string name; std::string name;