@@ -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