diff --git a/freqmemory.h b/freqmemory.h index b803f4a..96d3c6b 100644 --- a/freqmemory.h +++ b/freqmemory.h @@ -37,6 +37,7 @@ enum mode_kind { struct mode_info { mode_kind mk; unsigned char reg; + unsigned char filter; QString name; }; diff --git a/wfmain.cpp b/wfmain.cpp index 4fac1aa..498edaa 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -2214,6 +2214,33 @@ void wfmain::setPlotTheme(QCustomPlot *plot, bool isDark) } } +void wfmain::doCmd(commandtype cmddata) +{ + cmds cmd = cmddata.cmd; + std::shared_ptr data = cmddata.data; + + switch (cmd) + { + case cmdSetFreq: + { + freqt f = (*std::static_pointer_cast(data)); + emit setFrequency(f); + break; + } + case cmdSetMode: + { + mode_info m = (*std::static_pointer_cast(data)); + emit setMode(m); + break; + } + default: + doCmd(cmd); + break; + } + +} + + void wfmain::doCmd(cmds cmd) { // Use this function to take action upon a command. @@ -2401,9 +2428,9 @@ void wfmain::sendRadioCommandLoop() // if ther's a command waiting, run it. if(!delayedCmdQue.empty()) { - cmds cmd = delayedCmdQue.front(); + commandtype cmddata = delayedCmdQue.front(); delayedCmdQue.pop_front(); - doCmd(cmd); + doCmd(cmddata); } else if(!(loopTickCounter % 10)) { // pick from useful queries to make now and then @@ -2431,14 +2458,20 @@ void wfmain::sendRadioCommandLoop() void wfmain::issueDelayedCommand(cmds cmd) { // Append to end of command queue - delayedCmdQue.push_back(cmd); + commandtype cmddata; + cmddata.cmd = cmd; + cmddata.data = NULL; + delayedCmdQue.push_back(cmddata); } void wfmain::issueDelayedCommandPriority(cmds cmd) { // Places the new command at the top of the queue // Use only when needed. - delayedCmdQue.push_front(cmd); + commandtype cmddata; + cmddata.cmd = cmd; + cmddata.data = NULL; + delayedCmdQue.push_front(cmddata); } void wfmain::issueDelayedCommandUnique(cmds cmd) @@ -2446,13 +2479,46 @@ void wfmain::issueDelayedCommandUnique(cmds cmd) // Use this function to insert commands where // multiple (redundant) commands don't make sense. - if( std::find(delayedCmdQue.begin(), delayedCmdQue.end(), cmd ) == delayedCmdQue.end()) + commandtype cmddata; + cmddata.cmd = cmd; + cmddata.data = NULL; + + // The following is both expensive and not that great, + // since it does not check if the arguments are the same. + bool found = false; + for(unsigned int i=0; i < delayedCmdQue.size(); i++) { - delayedCmdQue.push_front(cmd); + if(delayedCmdQue.at(i).cmd == cmd) + { + found = true; + break; + } } + if(!found) + { + delayedCmdQue.push_front(cmddata); + } + +// if( std::find(delayedCmdQue.begin(), delayedCmdQue.end(), cmddata ) == delayedCmdQue.end()) +// { +// delayedCmdQue.push_front(cmddata); +// } + } +void wfmain::cmdGoToFreq(freqt f) +{ + commandtype cmddata; + cmddata.cmd = cmdSetFreq; + cmddata.data = std::shared_ptr(new freqt()); + *static_cast(cmddata.data.get()) = f; + //static_cast(cmddata.data.get())->Hz = f.Hz; + //static_cast(cmddata.data.get())->MHzDouble = f.MHzDouble; + delayedCmdQue.push_back(cmddata); +} + + void wfmain::receiveRigID(rigCapabilities rigCaps) { // Note: We intentionally request rigID several times @@ -3023,7 +3089,8 @@ void wfmain::on_goFreqBtn_clicked() if(ok) { f.Hz = freq*1E6; - emit setFrequency(f); + //emit setFrequency(f); + cmdGoToFreq(f); issueDelayedCommand(cmdGetFreq); } } else { @@ -3031,7 +3098,8 @@ void wfmain::on_goFreqBtn_clicked() if(ok) { f.Hz = KHz*1E3; - emit setFrequency(f); + cmdGoToFreq(f); + //emit setFrequency(f); issueDelayedCommand(cmdGetFreq); } } @@ -3286,7 +3354,8 @@ void wfmain::on_freqDial_valueChanged(int value) ui->freqLabel->setText(QString("%1").arg(f.MHzDouble, 0, 'f')); - emit setFrequency(f); + //emit setFrequency(f); + cmdGoToFreq(f); } else { ui->freqDial->blockSignals(true); ui->freqDial->setValue(oldFreqDialVal); @@ -4720,6 +4789,8 @@ void wfmain::on_pollingBtn_clicked() void wfmain::on_debugBtn_clicked() { qInfo(logSystem()) << "Debug button pressed."; - emit getFrequency(); + freqt f; + f.Hz = 14290000; + cmdGoToFreq(f); } diff --git a/wfmain.h b/wfmain.h index 3c50f73..dbeb95c 100644 --- a/wfmain.h +++ b/wfmain.h @@ -30,6 +30,7 @@ #include #include +#include namespace Ui { class wfmain; @@ -58,6 +59,7 @@ signals: void setFrequency(freqt freq); void getMode(); void setMode(unsigned char modeIndex, unsigned char modeFilter); + void setMode(mode_info); void setDataMode(bool dataOn, unsigned char filter); void getDataMode(); void getModInput(bool dataOn); @@ -580,7 +582,7 @@ private: unsigned char setModeVal=0; unsigned char setFilterVal=0; - enum cmds {cmdNone, cmdGetRigID, cmdGetRigCIV, cmdGetFreq, cmdGetMode, cmdGetDataMode, cmdSetModeFilter, + enum cmds {cmdNone, cmdGetRigID, cmdGetRigCIV, cmdGetFreq, cmdSetFreq, cmdGetMode, cmdSetMode, cmdGetDataMode, cmdSetModeFilter, cmdSetDataModeOn, cmdSetDataModeOff, cmdGetRitEnabled, cmdGetRitValue, cmdSpecOn, cmdSpecOff, cmdDispEnable, cmdDispDisable, cmdGetRxGain, cmdGetAfGain, cmdGetSql, cmdGetATUStatus, cmdGetSpectrumMode, cmdGetSpectrumSpan, cmdScopeCenterMode, cmdScopeFixedMode, cmdGetPTT, @@ -589,10 +591,18 @@ private: cmdGetVdMeter, cmdGetIdMeter, cmdGetSMeter, cmdGetPowerMeter, cmdGetALCMeter, cmdGetCompMeter, cmdGetTxRxMeter, cmdGetTone, cmdGetTSQL, cmdGetDTCS, cmdGetRptAccessMode, cmdGetPreamp, cmdGetAttenuator, cmdGetAntenna}; - std::deque delayedCmdQue; - std::deque periodicCmdQueue; - std::deque slowPollCmdQueue; + struct commandtype { + cmds cmd; + std::shared_ptr data; + }; + + std::deque delayedCmdQue; // rapid que for commands to the radio + std::deque periodicCmdQueue; // rapid que for metering + std::deque slowPollCmdQueue; // slow, regular checking for UI sync void doCmd(cmds cmd); + void doCmd(commandtype cmddata); + void cmdGoToFreq(freqt f); + int pCmdNum = 0; int delayedCmdIntervalLAN_ms = 100; int delayedCmdIntervalSerial_ms = 100;