Skip to content

Commit 9c1361a

Browse files
Added radio mode info in the recorder and fixed horrible code in the rigctl_server module
1 parent 4d0d148 commit 9c1361a

File tree

3 files changed

+41
-52
lines changed

3 files changed

+41
-52
lines changed

misc_modules/recorder/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ file(GLOB SRC "src/*.cpp")
55

66
include(${SDRPP_MODULE_CMAKE})
77

8-
target_include_directories(recorder PRIVATE "src/")
8+
target_include_directories(recorder PRIVATE "src/")
9+
target_include_directories(recorder PRIVATE "../../decoder_modules/radio/src")

misc_modules/recorder/src/main.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <core.h>
2222
#include <utils/optionlist.h>
2323
#include <utils/wav.h>
24+
#include <radio_interface.h>
2425

2526
#define CONCAT(a, b) ((std::string(a) + b).c_str())
2627

@@ -437,6 +438,17 @@ class RecorderModule : public ModuleManager::Instance {
437438
if (dbLvl.r > lvl.r) { lvl.r = dbLvl.r; }
438439
}
439440

441+
std::map<int, const char*> radioModeToString = {
442+
{ RADIO_IFACE_MODE_NFM, "NFM" },
443+
{ RADIO_IFACE_MODE_WFM, "WFM" },
444+
{ RADIO_IFACE_MODE_AM, "AM" },
445+
{ RADIO_IFACE_MODE_DSB, "DSB" },
446+
{ RADIO_IFACE_MODE_USB, "USB" },
447+
{ RADIO_IFACE_MODE_CW, "CW" },
448+
{ RADIO_IFACE_MODE_LSB, "LSB" },
449+
{ RADIO_IFACE_MODE_RAW, "RAW" }
450+
};
451+
440452
std::string genFileName(std::string templ, std::string type, std::string name) {
441453
// Get data
442454
time_t now = time(0);
@@ -455,13 +467,19 @@ class RecorderModule : public ModuleManager::Instance {
455467
char dayStr[128];
456468
char monStr[128];
457469
char yearStr[128];
470+
const char* modeStr = "Unknown";
458471
sprintf(freqStr, "%.0lfHz", freq);
459472
sprintf(hourStr, "%02d", ltm->tm_hour);
460473
sprintf(minStr, "%02d", ltm->tm_min);
461474
sprintf(secStr, "%02d", ltm->tm_sec);
462475
sprintf(dayStr, "%02d", ltm->tm_mday);
463476
sprintf(monStr, "%02d", ltm->tm_mon + 1);
464477
sprintf(yearStr, "%02d", ltm->tm_year + 1900);
478+
if (core::modComManager.getModuleName(name) == "radio") {
479+
int mode;
480+
core::modComManager.callInterface(name, RADIO_IFACE_CMD_GET_MODE, NULL, &mode);
481+
modeStr = radioModeToString[mode];
482+
}
465483

466484
// Replace in template
467485
templ = std::regex_replace(templ, std::regex("\\$t"), type);
@@ -472,6 +490,7 @@ class RecorderModule : public ModuleManager::Instance {
472490
templ = std::regex_replace(templ, std::regex("\\$d"), dayStr);
473491
templ = std::regex_replace(templ, std::regex("\\$M"), monStr);
474492
templ = std::regex_replace(templ, std::regex("\\$y"), yearStr);
493+
templ = std::regex_replace(templ, std::regex("\\$r"), modeStr);
475494
return templ;
476495
}
477496

misc_modules/rigctl_server/src/main.cpp

Lines changed: 20 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,17 @@ class SigctlServerModule : public ModuleManager::Instance {
333333
_this->client->readAsync(1024, _this->dataBuf, dataHandler, _this, false);
334334
}
335335

336+
std::map<int, const char*> radioModeToString = {
337+
{ RADIO_IFACE_MODE_NFM, "NFM" },
338+
{ RADIO_IFACE_MODE_WFM, "WFM" },
339+
{ RADIO_IFACE_MODE_AM, "AM" },
340+
{ RADIO_IFACE_MODE_DSB, "DSB" },
341+
{ RADIO_IFACE_MODE_USB, "USB" },
342+
{ RADIO_IFACE_MODE_CW, "CW" },
343+
{ RADIO_IFACE_MODE_LSB, "LSB" },
344+
{ RADIO_IFACE_MODE_RAW, "RAW" }
345+
};
346+
336347
void commandHandler(std::string cmd) {
337348
std::string corr = "";
338349
std::vector<std::string> parts;
@@ -442,38 +453,18 @@ class SigctlServerModule : public ModuleManager::Instance {
442453
pos++;
443454
}
444455

456+
const std::string& newModeStr = parts[1];
445457
float newBandwidth = std::atoi(parts[2].c_str());
446-
447-
int newMode;
448-
if (parts[1] == "FM") {
449-
newMode = RADIO_IFACE_MODE_NFM;
450-
}
451-
else if (parts[1] == "WFM") {
452-
newMode = RADIO_IFACE_MODE_WFM;
453-
}
454-
else if (parts[1] == "AM") {
455-
newMode = RADIO_IFACE_MODE_AM;
456-
}
457-
else if (parts[1] == "DSB") {
458-
newMode = RADIO_IFACE_MODE_DSB;
459-
}
460-
else if (parts[1] == "USB") {
461-
newMode = RADIO_IFACE_MODE_USB;
462-
}
463-
else if (parts[1] == "CW") {
464-
newMode = RADIO_IFACE_MODE_CW;
465-
}
466-
else if (parts[1] == "LSB") {
467-
newMode = RADIO_IFACE_MODE_LSB;
468-
}
469-
else if (parts[1] == "RAW") {
470-
newMode = RADIO_IFACE_MODE_RAW;
471-
}
472-
else {
458+
459+
auto it = std::find_if(radioModeToString.begin(), radioModeToString.end(), [&newModeStr](const auto& e) {
460+
return e.second == newModeStr;
461+
});
462+
if (it == radioModeToString.end()) {
473463
resp = "RPRT 1\n";
474464
client->write(resp.size(), (uint8_t*)resp.c_str());
475465
return;
476466
}
467+
int newMode = it->first;
477468

478469
// If tuning is enabled, set the mode and optionally the bandwidth
479470
if (!selectedVfo.empty() && core::modComManager.getModuleName(selectedVfo) == "radio" && tuningEnabled) {
@@ -492,31 +483,9 @@ class SigctlServerModule : public ModuleManager::Instance {
492483
if (!selectedVfo.empty() && core::modComManager.getModuleName(selectedVfo) == "radio") {
493484
int mode;
494485
core::modComManager.callInterface(selectedVfo, RADIO_IFACE_CMD_GET_MODE, NULL, &mode);
495-
496-
if (mode == RADIO_IFACE_MODE_NFM) {
497-
resp = "FM\n";
498-
}
499-
else if (mode == RADIO_IFACE_MODE_WFM) {
500-
resp = "WFM\n";
501-
}
502-
else if (mode == RADIO_IFACE_MODE_AM) {
503-
resp = "AM\n";
504-
}
505-
else if (mode == RADIO_IFACE_MODE_DSB) {
506-
resp = "DSB\n";
507-
}
508-
else if (mode == RADIO_IFACE_MODE_USB) {
509-
resp = "USB\n";
510-
}
511-
else if (mode == RADIO_IFACE_MODE_CW) {
512-
resp = "CW\n";
513-
}
514-
else if (mode == RADIO_IFACE_MODE_LSB) {
515-
resp = "LSB\n";
516-
}
486+
resp = std::string(radioModeToString[mode]) + "\n";
517487
}
518-
519-
if (!selectedVfo.empty()) {
488+
else if (!selectedVfo.empty()) {
520489
resp += std::to_string((int)sigpath::vfoManager.getBandwidth(selectedVfo)) + "\n";
521490
}
522491
else {

0 commit comments

Comments
 (0)