From 19da8863f020d06ad7d38463944a66d404143495 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Fri, 26 Apr 2024 15:37:12 +0100 Subject: [PATCH] Add get/set command types and make dial change current receiver. --- rigcommander.cpp | 34 +++++++++++++++++++++++++++++----- rigcreator.cpp | 45 +++++++++++++++++++++++++++++++++++++++++++++ rigcreator.ui | 7 ++++++- spectrumscope.cpp | 4 ++-- wfmain.cpp | 29 +++++++++++++++++------------ wfviewtypes.h | 4 +++- 6 files changed, 102 insertions(+), 21 deletions(-) diff --git a/rigcommander.cpp b/rigcommander.cpp index 29801ea..c3f4688 100644 --- a/rigcommander.cpp +++ b/rigcommander.cpp @@ -216,7 +216,7 @@ void rigCommander::commonSetup() // Add the below commands so we can get a response until we have received rigCaps rigCaps.commands.clear(); rigCaps.commandsReverse.clear(); - rigCaps.commands.insert(funcTransceiverId,funcType(funcTransceiverId, QString("Transceiver ID"),QByteArrayLiteral("\x19\x00"),0,0,false)); + rigCaps.commands.insert(funcTransceiverId,funcType(funcTransceiverId, QString("Transceiver ID"),QByteArrayLiteral("\x19\x00"),0,0,false,true,false)); rigCaps.commandsReverse.insert(QByteArrayLiteral("\x19\x00"),funcTransceiverId); this->setObjectName("Rig Commander"); @@ -1338,7 +1338,9 @@ void rigCommander::determineRigCaps() rigCaps.commands.insert(func, funcType(func, funcString[int(func)], QByteArray::fromHex(settings->value("String", "").toString().toUtf8()), settings->value("Min", 0).toInt(NULL), settings->value("Max", 0).toInt(NULL), - settings->value("Command29",false).toBool())); + settings->value("Command29",false).toBool(), + settings->value("GetCommand",true).toBool(), + settings->value("SetCommand",true).toBool())); rigCaps.commandsReverse.insert(QByteArray::fromHex(settings->value("String", "").toString().toUtf8()),func); } else { @@ -2485,10 +2487,27 @@ void rigCommander::receiveCommand(funcs func, QVariant value, uchar receiver) } QByteArray payload; + auto cmd = rigCaps.commands.find(func); + if (cmd == rigCaps.commands.end()) + { + // Command not found, remove from queue + qDebug(logRig()) << "Removing unsupported command from queue" << funcString[func] << "VFO" << receiver; + queue->del(func,receiver); + return; + } + if (getCommand(func,payload,val,receiver)) { if (value.isValid()) { + if (!cmd->setCmd) { + qDebug(logRig()) << "Removing unsupported set command from queue" << funcString[func] << "VFO" << receiver; + queue->del(func,receiver); + return; + } else if (cmd->getCmd && func != funcScopeFixedEdgeFreq && func != funcSpeech && func != funcBandStackReg && func != funcMemoryContents && func != funcSendCW) { + queue->addUnique(priorityImmediate,func,false,receiver); + } + if (!strcmp(value.typeName(),"bool")) { payload.append(value.value()); @@ -2855,10 +2874,15 @@ void rigCommander::receiveCommand(funcs func, QVariant value, uchar receiver) return; } // This was a set command, so queue a get straight after to retrieve the updated value - // will fail on some commands so they would need to be added here: - if (func != funcScopeFixedEdgeFreq && func != funcSpeech && func != funcBandStackReg && func != funcMemoryContents && func != funcSendCW) + // will fail on some commands so they would need to be added here: + } else { + // This is a get command + if (!cmd->getCmd) { - queue->addUnique(priorityImmediate,func,false,receiver); + // Get command not supported + qDebug(logRig()) << "Removing unsupported get command from queue" << funcString[func] << "VFO" << receiver; + queue->del(func,receiver); + return; } } prepDataAndSend(payload); diff --git a/rigcreator.cpp b/rigcreator.cpp index 03d7ce7..4e02a92 100644 --- a/rigcreator.cpp +++ b/rigcreator.cpp @@ -55,6 +55,21 @@ void rigCreator::commandRowAdded(int row) layoutCheckBox->setAlignment(Qt::AlignCenter); // Center the checkbox layoutCheckBox->setContentsMargins(0,0,0,0); // Set the zero padding ui->commands->setCellWidget(row,4, checkBoxWidget); + + QWidget *getSetWidget = new QWidget(); + QCheckBox *get = new QCheckBox(); // We declare and initialize the checkbox + QCheckBox *set = new QCheckBox(); // We declare and initialize the checkbox + get->setChecked(true); + set->setChecked(true); + get->setObjectName("get"); + set->setObjectName("set"); + QHBoxLayout *layoutGetSet = new QHBoxLayout(getSetWidget); // create a layer with reference to the widget + layoutGetSet->addWidget(get); // Set the checkbox in the layer + layoutGetSet->addWidget(set); // Set the checkbox in the layer + layoutGetSet->setAlignment(Qt::AlignCenter); // Center the checkbox + layoutGetSet->setContentsMargins(0,0,0,0); // Set the zero padding + ui->commands->setCellWidget(row,5, getSetWidget); + } @@ -194,6 +209,27 @@ void rigCreator::loadRigFile(QString file) ui->commands->model()->setData(ui->commands->model()->index(c,3),QString::number(settings->value("Max", 0).toInt())); ui->commands->setCellWidget(c,4, checkBoxWidget); + QWidget *getSetWidget = new QWidget(); + QCheckBox *get = new QCheckBox(); // We declare and initialize the checkbox + QCheckBox *set = new QCheckBox(); // We declare and initialize the checkbox + if (settings->value("GetCommand",true).toBool()) { + get->setChecked(true); + } else { + get->setChecked(false); + } + if (settings->value("SetCommand",true).toBool()) { + set->setChecked(true); + } else { + set->setChecked(false); + } + get->setObjectName("get"); + set->setObjectName("set"); + QHBoxLayout *layoutGetSet = new QHBoxLayout(getSetWidget); // create a layer with reference to the widget + layoutGetSet->addWidget(get); // Set the checkbox in the layer + layoutGetSet->addWidget(set); // Set the checkbox in the layer + layoutGetSet->setAlignment(Qt::AlignCenter); // Center the checkbox + layoutGetSet->setContentsMargins(0,0,0,0); // Set the zero padding + ui->commands->setCellWidget(c,5, getSetWidget); } settings->endArray(); } @@ -513,6 +549,15 @@ void rigCreator::saveRigFile(QString file) settings->setValue("Command29", chk->isChecked()); } + QList getSet =ui->commands->cellWidget(n,5)->findChildren(QString(), Qt::FindChildrenRecursively); + qDebug() << "size = "<objectName() == "get") + settings->setValue("GetCommand", c->isChecked()); + else if (c->objectName() == "set") + settings->setValue("SetCommand", c->isChecked()); + } } settings->endArray(); diff --git a/rigcreator.ui b/rigcreator.ui index 34a896c..02ce401 100644 --- a/rigcreator.ui +++ b/rigcreator.ui @@ -199,7 +199,7 @@ 0 - 5 + 6 false @@ -253,6 +253,11 @@ 29 + + + G/S + + diff --git a/spectrumscope.cpp b/spectrumscope.cpp index 9eeb55d..d7ffaa2 100644 --- a/spectrumscope.cpp +++ b/spectrumscope.cpp @@ -1804,11 +1804,11 @@ void spectrumScope::newFrequency(qint64 freq,uchar vfo) { if (vfo > 0) { - queue->add(priorityImmediate,queueItem((funcUnselectedFreq),QVariant::fromValue(f),false,receiver)); + queue->addUnique(priorityImmediate,queueItem((funcUnselectedFreq),QVariant::fromValue(f),false,receiver)); } else { - queue->add(priorityImmediate,queueItem((receiver?funcSubFreq:funcMainFreq),QVariant::fromValue(f),false,receiver)); + queue->addUnique(priorityImmediate,queueItem((receiver?funcSubFreq:funcMainFreq),QVariant::fromValue(f),false,receiver)); } } } diff --git a/wfmain.cpp b/wfmain.cpp index 1a79e64..c827c15 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -3989,19 +3989,24 @@ void wfmain::on_freqDial_valueChanged(int value) // With the number of steps and direction of steps established, // we can now adjust the frequency: - if (receivers.size()) { - f.Hz = roundFrequencyWithStep(receivers[0]->getFrequency().Hz, delta, tsKnobHz); - f.MHzDouble = f.Hz / (double)1E6; - if (f.Hz > 0) + + for (uchar i=0;inumReceiver;i++) + { + if (receivers[i]->isSelected()) { - oldFreqDialVal = value; - receivers[0]->setFrequency(f); - queue->add(priorityImmediate,queueItem(funcMainFreq,QVariant::fromValue(f),false)); - } else { - ui->freqDial->blockSignals(true); - ui->freqDial->setValue(oldFreqDialVal); - ui->freqDial->blockSignals(false); - return; + f.Hz = roundFrequencyWithStep(receivers[i]->getFrequency().Hz, delta, tsKnobHz); + f.MHzDouble = f.Hz / (double)1E6; + if (f.Hz > 0) + { + oldFreqDialVal = value; + receivers[i]->setFrequency(f); + queue->addUnique(priorityImmediate,queueItem((i==0)?funcMainFreq:funcSubFreq,QVariant::fromValue(f),false,i)); + } else { + ui->freqDial->blockSignals(true); + ui->freqDial->setValue(oldFreqDialVal); + ui->freqDial->blockSignals(false); + return; + } } } } diff --git a/wfviewtypes.h b/wfviewtypes.h index 37641c1..dcc24dc 100644 --- a/wfviewtypes.h +++ b/wfviewtypes.h @@ -323,13 +323,15 @@ struct spanType { struct funcType { funcType() {} - funcType(funcs cmd, QString name, QByteArray data, int minVal, int maxVal, bool cmd29) : cmd(cmd), name(name), data(data), minVal(minVal), maxVal(maxVal), cmd29(cmd29) {} + funcType(funcs cmd, QString name, QByteArray data, int minVal, int maxVal, bool cmd29, bool getCmd, bool setCmd) : cmd(cmd), name(name), data(data), minVal(minVal), maxVal(maxVal), cmd29(cmd29), getCmd(getCmd), setCmd(setCmd) {} funcs cmd; QString name; QByteArray data; int minVal; int maxVal; bool cmd29; + bool getCmd; + bool setCmd; }; //struct commandtype {