From 81c9563f1679dfad95022336288c34e5fef30bf4 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Sat, 4 Dec 2021 19:21:23 +0000 Subject: [PATCH] Various changes and fixes to rigctld/rigstate --- rigcommander.cpp | 24 +++++++++----- rigctld.cpp | 82 +++++++++++++++++++++++++++--------------------- rigstate.h | 15 ++++++++- wfmain.cpp | 53 ++++++------------------------- wfmain.h | 4 +++ 5 files changed, 90 insertions(+), 88 deletions(-) diff --git a/rigcommander.cpp b/rigcommander.cpp index f635688..c2b4e78 100644 --- a/rigcommander.cpp +++ b/rigcommander.cpp @@ -4222,13 +4222,6 @@ void rigCommander::stateUpdated() { // A remote process has updated the rigState // First we need to find which item(s) have been updated and send the command(s) to the rig. - /* - FAGCFUNC, NBFUNC, COMPFUNC, VOXFUNC, TONEFUNC, TSQLFUNC, SBKINFUNC, FBKINFUNC, ANFFUNC, NRFUNC, AIPFUNC, APFFUNC, MONFUNC, MNFUNC,RFFUNC, - AROFUNC, MUTEFUNC, VSCFUNC, REVFUNC, SQLFUNC, ABMFUNC, BCFUNC, MBCFUNC, RITFUNC, AFCFUNC, SATMODEFUNC, SCOPEFUNC, - RESUMEFUNC, TBURSTFUNC, TUNERFUNC}; - */ - - /* VFOAFREQ, VFOBFREQ, CURRENTVFO, PTT, MODE, FILTER, DUPLEX, DATAMODE, ANTENNA, RXANTENNA, CTCSS, TSQL, DTCS, CSQL */ QMap::iterator i = state.map.begin(); while (i != state.map.end()) { @@ -4460,7 +4453,22 @@ void rigCommander::stateUpdated() disableSpectOutput(); } } - + break; + case RIGINPUT: + if (i.value()._valid) { + setModInput(state.getInput(RIGINPUT), state.getBool(DATAMODE)); + } + getModInput(state.getBool(DATAMODE)); + break; + case POWERONOFF: + if (i.value()._valid) { + if (state.getBool(POWERONOFF)) { + powerOn(); + } + else { + powerOff(); + } + } } } ++i; diff --git a/rigctld.cpp b/rigctld.cpp index 1ef76ac..0ab4e09 100644 --- a/rigctld.cpp +++ b/rigctld.cpp @@ -55,11 +55,7 @@ rigCtlD::~rigCtlD() qInfo(logRigCtlD()) << "closing rigctld"; } -//void rigCtlD::receiveFrequency(freqt freq) -//{ -// emit setFrequency(0, freq); -// emit setFrequency(0, freq); -//} + void rigCtlD::receiveStateInfo(rigstate* state) { @@ -127,21 +123,29 @@ void rigCtlClient::socketReadyRead() { QByteArray data = socket->readAll(); commandBuffer.append(data); + QStringList commandList(commandBuffer.split('\n')); QString sep = "\n"; static int num = 0; - bool longReply = false; - char responseCode = 0; - QStringList response; - bool setCommand = false; - if (commandBuffer.endsWith('\n')) + + for (QString &commands : commandList) { - //qDebug(logRigCtlD()) << sessionId << "command received" << commandBuffer; - commandBuffer.chop(1); // Remove \n character - if (commandBuffer.endsWith('\r')) + bool longReply = false; + char responseCode = 0; + QStringList response; + bool setCommand = false; + //commands.chop(1); // Remove \n character + if (commands.endsWith('\r')) { - commandBuffer.chop(1); // Remove \n character + commands.chop(1); // Remove \n character } + if (commands.isEmpty()) + { + continue; + } + + qDebug(logRigCtlD()) << sessionId << "command received" << commands; + // We have a full line so process command. if (rigState == Q_NULLPTR) @@ -150,33 +154,33 @@ void rigCtlClient::socketReadyRead() return; } - if (commandBuffer[num] == ";" || commandBuffer[num] == "|" || commandBuffer[num] == ",") + if (commands[num] == ";" || commands[num] == "|" || commands[num] == ",") { - sep = commandBuffer[num].toLatin1(); + sep = commands[num].toLatin1(); num++; } - else if (commandBuffer[num] == "+") + else if (commands[num] == "+") { longReply = true; sep = "\n"; num++; } - else if (commandBuffer[num] == "#") + else if (commands[num] == "#") { - return; + continue; } - else if (commandBuffer[num].toLower() == "q") + else if (commands[num].toLower() == "q") { closeSocket(); return; } - if (commandBuffer[num] == "\\") + if (commands[num] == "\\") { num++; } - QStringList command = commandBuffer.mid(num).split(" "); + QStringList command = commands.mid(num).split(" "); if (command[0] == 0xf0 || command[0] == "chk_vfo") @@ -403,10 +407,10 @@ void rigCtlClient::socketReadyRead() response.append("MEM"); } else if (command[1] == "VFOB" || command[1] == "Sub") { - //emit parent->setVFO(1); + rigState->set(CURRENTVFO, (quint8)1, true); } else { - //emit parent->setVFO(0); + rigState->set(CURRENTVFO, (quint8)0, true); } } else if (command[0] == "s" || command[0] == "get_split_vfo") @@ -450,8 +454,15 @@ void rigCtlClient::socketReadyRead() else if (command[0] == "\xf3" || command[0] == "get_vfo_info") { if (longReply) { - response.append(QString("set_vfo: %1").arg(command[1])); - + if (command[1] == "?") { + if (rigState->getChar(CURRENTVFO) == 0) { + response.append(QString("set_vfo: VFOA")); + } + else + { + response.append(QString("set_vfo: VFOB")); + } + } if (command[1] == "VFOB") { response.append(QString("Freq: %1").arg(rigState->getInt64(VFOBFREQ))); } @@ -1022,17 +1033,17 @@ void rigCtlClient::socketReadyRead() } else if (command.length() > 1 && (command[0] == 0x87 || command[0] == "set_powerstat")) { - setCommand = true; - if (command[1] == "0") - { - emit parent->sendPowerOff(); + setCommand = true; + if (command[1] == "0") + { + rigState->set(POWERONOFF, false, true); } - else { - emit parent->sendPowerOn(); + else { + rigState->set(POWERONOFF, true, true); } } else { - qInfo(logRigCtlD()) << "Unimplemented command" << commandBuffer; + qInfo(logRigCtlD()) << "Unimplemented command" << commands; } if (longReply) { if (command.length() == 2) @@ -1045,6 +1056,7 @@ void rigCtlClient::socketReadyRead() if (setCommand) { + // This was a set command so state has likely been updated. emit parent->stateUpdated(); } @@ -1067,11 +1079,11 @@ void rigCtlClient::socketReadyRead() sendData(QString("\n")); } - commandBuffer.clear(); sep = " "; num = 0; } + commandBuffer.clear(); } void rigCtlClient::socketDisconnected() @@ -1088,7 +1100,7 @@ void rigCtlClient::closeSocket() void rigCtlClient::sendData(QString data) { - //qDebug(logRigCtlD()) << "Sending:" << data; + qDebug(logRigCtlD()) << "Sending:" << data; if (socket != Q_NULLPTR && socket->isValid() && socket->isOpen()) { socket->write(data.toLatin1()); diff --git a/rigstate.h b/rigstate.h index 54267fd..d0ff1e0 100644 --- a/rigstate.h +++ b/rigstate.h @@ -9,13 +9,14 @@ #include #include "rigcommander.h" +#include "rigidentities.h" // Meters at the end as they are ALWAYS updated from the rig! enum stateTypes { NONE, VFOAFREQ, VFOBFREQ, CURRENTVFO, PTT, MODE, FILTER, DUPLEX, DATAMODE, ANTENNA, RXANTENNA, CTCSS, TSQL, DTCS, CSQL, PREAMP, AGC, ATTENUATOR, MODINPUT, AFGAIN, RFGAIN, SQUELCH, TXPOWER, MICGAIN, COMPLEVEL, MONITORLEVEL, VOXGAIN, ANTIVOXGAIN, FAGCFUNC, NBFUNC, COMPFUNC, VOXFUNC, TONEFUNC, TSQLFUNC, SBKINFUNC, FBKINFUNC, ANFFUNC, NRFUNC, AIPFUNC, APFFUNC, MONFUNC, MNFUNC,RFFUNC, AROFUNC, MUTEFUNC, VSCFUNC, REVFUNC, SQLFUNC, ABMFUNC, BCFUNC, MBCFUNC, RITFUNC, AFCFUNC, SATMODEFUNC, SCOPEFUNC, - NBLEVEL, NBDEPTH, NBWIDTH, NRLEVEL, + NBLEVEL, NBDEPTH, NBWIDTH, NRLEVEL, RIGINPUT, POWERONOFF, RESUMEFUNC, TBURSTFUNC, TUNERFUNC, LOCKFUNC, SMETER, POWERMETER, SWRMETER, ALCMETER, COMPMETER, VOLTAGEMETER, CURRENTMETER }; @@ -97,12 +98,24 @@ public: } } + void set(stateTypes s, rigInput x, bool u) { + if ((quint64)x != map[s]._value) { + _mutex.lock(); + map[s]._value = (quint64)x; + map[s]._valid = true; + map[s]._updated = u; + map[s]._dateUpdated = QDateTime::currentDateTime(); + _mutex.unlock(); + } + } + bool getBool(stateTypes s) { return map[s]._value != 0; } quint8 getChar(stateTypes s) { return map[s]._value & 0xff; } quint16 getInt16(stateTypes s) { return map[s]._value != 0xffff; } quint32 getInt32(stateTypes s) { return map[s]._value != 0xffffffff; } quint64 getInt64(stateTypes s) { return map[s]._value; } duplexMode getDuplex(stateTypes s) { return(duplexMode)map[s]._value; } + rigInput getInput(stateTypes s) { return(rigInput)map[s]._value; } QMap map; diff --git a/wfmain.cpp b/wfmain.cpp index 3c0403b..de6ceed 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -413,32 +413,12 @@ void wfmain::makeRig() connect(rig, SIGNAL(discoveredRigID(rigCapabilities)), this, SLOT(receiveFoundRigID(rigCapabilities))); connect(rig, SIGNAL(commReady()), this, SLOT(receiveCommReady())); + connect(this, SIGNAL(requestRigState()), rig, SLOT(sendState())); + connect(this, SIGNAL(stateUpdated()), rig, SLOT(stateUpdated())); + connect(rig, SIGNAL(stateInfo(rigstate*)), this, SLOT(receiveStateInfo(rigstate*))); if (rigCtl != Q_NULLPTR) { connect(rig, SIGNAL(stateInfo(rigstate*)), rigCtl, SLOT(receiveStateInfo(rigstate*))); - connect(this, SIGNAL(requestRigState()), rig, SLOT(sendState())); - connect(rigCtl, SIGNAL(setFrequency(unsigned char, freqt)), rig, SLOT(setFrequency(unsigned char, freqt))); - connect(rigCtl, SIGNAL(setMode(unsigned char, unsigned char)), rig, SLOT(setMode(unsigned char, unsigned char))); - connect(rigCtl, SIGNAL(setDataMode(bool, unsigned char)), rig, SLOT(setDataMode(bool, unsigned char))); - connect(rigCtl, SIGNAL(setPTT(bool)), rig, SLOT(setPTT(bool))); - connect(rigCtl, SIGNAL(sendPowerOn()), rig, SLOT(powerOn())); - connect(rigCtl, SIGNAL(sendPowerOff()), rig, SLOT(powerOff())); connect(rigCtl, SIGNAL(stateUpdated()), rig, SLOT(stateUpdated())); - - connect(rigCtl, SIGNAL(setAttenuator(unsigned char)), rig, SLOT(setAttenuator(unsigned char))); - connect(rigCtl, SIGNAL(setPreamp(unsigned char)), rig, SLOT(setPreamp(unsigned char))); - connect(rigCtl, SIGNAL(setDuplexMode(duplexMode)), rig, SLOT(setDuplexMode(duplexMode))); - - // Levels: Set: - connect(rigCtl, SIGNAL(setRfGain(unsigned char)), rig, SLOT(setRfGain(unsigned char))); - connect(rigCtl, SIGNAL(setAfGain(unsigned char)), rig, SLOT(setAfGain(unsigned char))); - connect(rigCtl, SIGNAL(setSql(unsigned char)), rig, SLOT(setSquelch(unsigned char))); - connect(rigCtl, SIGNAL(setTxPower(unsigned char)), rig, SLOT(setTxPower(unsigned char))); - connect(rigCtl, SIGNAL(setMicGain(unsigned char)), rig, SLOT(setMicGain(unsigned char))); - connect(rigCtl, SIGNAL(setMonitorLevel(unsigned char)), rig, SLOT(setMonitorLevel(unsigned char))); - connect(rigCtl, SIGNAL(setVoxGain(unsigned char)), rig, SLOT(setVoxGain(unsigned char))); - connect(rigCtl, SIGNAL(setAntiVoxGain(unsigned char)), rig, SLOT(setAntiVoxGain(unsigned char))); - connect(rigCtl, SIGNAL(setSpectrumRefLevel(int)), rig, SLOT(setSpectrumRefLevel(int))); - } } } @@ -5461,29 +5441,8 @@ void wfmain::on_enableRigctldChk_clicked(bool checked) if (rig != Q_NULLPTR) { // We are already connected to a rig. connect(rig, SIGNAL(stateInfo(rigstate*)), rigCtl, SLOT(receiveStateInfo(rigstate*))); - connect(rigCtl, SIGNAL(setFrequency(unsigned char, freqt)), rig, SLOT(setFrequency(unsigned char, freqt))); - connect(rigCtl, SIGNAL(setMode(unsigned char, unsigned char)), rig, SLOT(setMode(unsigned char, unsigned char))); - connect(rigCtl, SIGNAL(setDataMode(bool, unsigned char)), rig, SLOT(setDataMode(bool, unsigned char))); - connect(rigCtl, SIGNAL(setPTT(bool)), rig, SLOT(setPTT(bool))); - connect(rigCtl, SIGNAL(sendPowerOn()), rig, SLOT(powerOn())); - connect(rigCtl, SIGNAL(sendPowerOff()), rig, SLOT(powerOff())); connect(rigCtl, SIGNAL(stateUpdated()), rig, SLOT(stateUpdated())); - connect(rigCtl, SIGNAL(setAttenuator(unsigned char)), rig, SLOT(setAttenuator(unsigned char))); - connect(rigCtl, SIGNAL(setPreamp(unsigned char)), rig, SLOT(setPreamp(unsigned char))); - connect(rigCtl, SIGNAL(setDuplexMode(duplexMode)), rig, SLOT(setDuplexMode(duplexMode))); - - // Levels: Set: - connect(rigCtl, SIGNAL(setRfGain(unsigned char)), rig, SLOT(setRfGain(unsigned char))); - connect(rigCtl, SIGNAL(setAfGain(unsigned char)), rig, SLOT(setAfGain(unsigned char))); - connect(rigCtl, SIGNAL(setSql(unsigned char)), rig, SLOT(setSquelch(unsigned char))); - connect(rigCtl, SIGNAL(setTxPower(unsigned char)), rig, SLOT(setTxPower(unsigned char))); - connect(rigCtl, SIGNAL(setMicGain(unsigned char)), rig, SLOT(setMicGain(unsigned char))); - connect(rigCtl, SIGNAL(setMonitorLevel(unsigned char)), rig, SLOT(setMonitorLevel(unsigned char))); - connect(rigCtl, SIGNAL(setVoxGain(unsigned char)), rig, SLOT(setVoxGain(unsigned char))); - connect(rigCtl, SIGNAL(setAntiVoxGain(unsigned char)), rig, SLOT(setAntiVoxGain(unsigned char))); - connect(rigCtl, SIGNAL(setSpectrumRefLevel(int)), rig, SLOT(setSpectrumRefLevel(int))); - emit sendRigCaps(rigCaps); emit requestRigState(); } @@ -5512,6 +5471,12 @@ void wfmain::on_useCIVasRigIDChk_clicked(bool checked) prefs.CIVisRadioModel = checked; } +void wfmain::receiveStateInfo(rigstate* state) +{ + qInfo("Setting rig state for wfmain"); + rigState = state; +} + // --- DEBUG FUNCTION --- void wfmain::on_debugBtn_clicked() { diff --git a/wfmain.h b/wfmain.h index 1b19d7b..3a889a4 100644 --- a/wfmain.h +++ b/wfmain.h @@ -166,6 +166,7 @@ signals: void sendServerConfig(SERVERCONFIG conf); void sendRigCaps(rigCapabilities caps); void requestRigState(); + void stateUpdated(); private slots: void updateSizes(int tabIndex); @@ -501,6 +502,8 @@ private slots: void on_useCIVasRigIDChk_clicked(bool checked); + void receiveStateInfo(rigstate* state); + private: Ui::wfmain *ui; void closeEvent(QCloseEvent *event); @@ -843,6 +846,7 @@ private: unsigned int tsWfScrollHz; unsigned int tsKnobHz; + rigstate* rigState = Q_NULLPTR; SERVERCONFIG serverConfig; };