From 6623c2ced035cf6ed4f574f27e51a98de8ad06c9 Mon Sep 17 00:00:00 2001 From: Phil Taylor Date: Tue, 20 Apr 2021 12:29:10 +0100 Subject: [PATCH] rigctl working (sort of) with WSJT-X --- rigcommander.cpp | 11 +++-- rigcommander.h | 6 +++ rigctld.cpp | 123 ++++++++++++++++++++++++++++++++++++++++------- rigctld.h | 14 ++++-- wfmain.cpp | 22 ++++++--- wfmain.h | 1 + 6 files changed, 145 insertions(+), 32 deletions(-) diff --git a/rigcommander.cpp b/rigcommander.cpp index e3dca75..6c7f9f1 100644 --- a/rigcommander.cpp +++ b/rigcommander.cpp @@ -22,7 +22,9 @@ rigCommander::rigCommander() { - + rigState.filter = 0; + rigState.mode = 0; + rigState.ptt = 0; } rigCommander::~rigCommander() @@ -136,6 +138,7 @@ void rigCommander::commSetup(unsigned char rigCivAddr, udpPreferences prefs) // data from the comm port to the program: emit commReady(); + emit stateInfo(&rigState); pttAllowed = true; // This is for developing, set to false for "safe" debugging. Set to true for deployment. @@ -1890,6 +1893,7 @@ void rigCommander::parsePTT() // PTT on emit havePTTStatus(true); } + rigState.ptt = (unsigned char)payloadIn[2]; } @@ -2805,6 +2809,7 @@ void rigCommander::parseFrequency() freq.MHzDouble = frequencyMhz; + rigState.vfoAFreq = freq; emit haveFrequency(freq); } @@ -2862,7 +2867,6 @@ freqt rigCommander::parseFrequency(QByteArray data, unsigned char lastPosition) freqs.Hz += ((data[lastPosition-3] & 0xf0) >> 4) * 100000; freqs.MHzDouble = (double)freq; - return freqs; } @@ -2876,7 +2880,8 @@ void rigCommander::parseMode() } else { filter = 0; } - + rigState.mode = (unsigned char)payloadIn[01]; + rigState.filter = filter; emit haveMode((unsigned char)payloadIn[01], filter); } diff --git a/rigcommander.h b/rigcommander.h index 80e0879..48a1ad1 100644 --- a/rigcommander.h +++ b/rigcommander.h @@ -43,6 +43,9 @@ struct freqt { struct rigStateStruct { freqt vfoAFreq; freqt vfoBFreq; + unsigned char ptt; + unsigned char mode; + unsigned char filter; }; class rigCommander : public QObject @@ -283,6 +286,9 @@ signals: void havePreamp(unsigned char pre); void haveAntenna(unsigned char ant); + // Rig State + void stateInfo(rigStateStruct* state); + // Housekeeping: void getMoreDebug(); void finished(); diff --git a/rigctld.cpp b/rigctld.cpp index d14c248..6cda1c5 100644 --- a/rigctld.cpp +++ b/rigctld.cpp @@ -12,6 +12,16 @@ rigCtlD::~rigCtlD() { } +void rigCtlD::receiveFrequency(freqt freq) +{ + emit setFrequency(freq); +} +void rigCtlD::receiveStateInfo(rigStateStruct* state) +{ + qDebug("Setting rig state"); + rigState = state; +} + int rigCtlD::startServer(qint16 port) { if (!this->listen(QHostAddress::Any, port)) { @@ -26,7 +36,7 @@ int rigCtlD::startServer(qint16 port) } void rigCtlD::incomingConnection(qintptr socket) { - rigCtlClient* client = new rigCtlClient(socket, rigCaps, this); + rigCtlClient* client = new rigCtlClient(socket, rigCaps, rigState, this); connect(this, SIGNAL(onStopped()), client, SLOT(closeSocket())); } @@ -43,12 +53,14 @@ void rigCtlD::receiveRigCaps(rigCapabilities caps) this->rigCaps = caps; } -rigCtlClient::rigCtlClient(int socketId, rigCapabilities caps, rigCtlD *parent) : QObject(parent) +rigCtlClient::rigCtlClient(int socketId, rigCapabilities caps,rigStateStruct *state, rigCtlD *parent) : QObject(parent) { commandBuffer.clear(); sessionId = socketId; rigCaps = caps; + rigState = state; socket = new QTcpSocket(this); + this->parent = parent; if (!socket->setSocketDescriptor(sessionId)) { qDebug(logRigCtlD()) << " error binding socket: " << sessionId; @@ -64,20 +76,92 @@ void rigCtlClient::socketReadyRead() { QByteArray data = socket->readAll(); commandBuffer.append(data); + static QString sep = " "; + static int num = 0; if (commandBuffer.endsWith('\n')) { // Process command - qDebug(logRigCtlD()) << sessionId << "command received" << commandBuffer; + if (rigState == Q_NULLPTR) + { + qDebug(logRigCtlD()) << "no rigState!"; + return; + } - if (commandBuffer[0].toLower() == "q") + qDebug(logRigCtlD()) << sessionId << "command received" << commandBuffer; + if (commandBuffer[num] == ";" || commandBuffer[num] == "|" || commandBuffer[num] == ",") + { + sep = commandBuffer[num].toLatin1(); + num++; + } + else if (commandBuffer[num] == "+") + { + sep = "\n"; + } + + if (commandBuffer[num] == "q") { closeSocket(); } - else if (commandBuffer[0] == "1") + if (commandBuffer.contains("\\chk_vfo")) { - dumpCaps(); + sendData(QString("0\n")); + } + if (commandBuffer.contains("\\dump_state")) + { + // Currently send "fake" state information until I can work out what is required! + sendData(QString("1\n1\n0\n150000.000000 1500000000.000000 0x1ff -1 -1 0x16000003 0xf\n0 0 0 0 0 0 0\n0 0 0 0 0 0 0\n0x1ff 1\n0x1ff 0\n0 0\n0x1e 2400\n0x2 500\n0x1 8000\n0x1 2400\n0x20 15000\n0x20 8000\n0x40 230000\n0 0\n9990\n9990\n10000\n0\n10\n10 20 30\n0x3effffff\n0x3effffff\n0x7fffffff\n0x7fffffff\n0x7fffffff\n0x7fffffff\ndone\n")); + } + if (commandBuffer[num] == "f" || commandBuffer.contains("\\get_freq")) + { + sendData(QString("%1\n").arg(rigState->vfoAFreq.Hz)); + } + else if (commandBuffer[num] == "F" || commandBuffer.contains("\\set_freq")) + { + const QRegExp rx(QLatin1Literal("[^0-9]+")); + auto&& parts = commandBuffer.split(rx); + freqt freq; + freq.Hz = parts[1].toInt(); + emit parent->setFrequency(freq); + sendData(QString("RPRT 0\n")); + } + else if (commandBuffer[num] == "1" || commandBuffer.contains("\\dump_caps")) + { + dumpCaps(sep); + } + else if (commandBuffer[num] == "t") + { + sendData(QString("%1\n").arg(rigState->ptt)); + } + else if (commandBuffer[num] == "T") + { + if (commandBuffer[num + 2] == "0") { + emit parent->setPTT(false); + } + else { + emit parent->setPTT(true); + } + sendData(QString("RPRT 0\n")); + } + else if (commandBuffer[num] == "v") + { + sendData(QString("VFOA\n")); + } + else if (commandBuffer[num] == "m") + { + sendData(QString("FM\n15000\n")); + } + else if (commandBuffer[num] == "M") + { + // Set mode + sendData(QString("RPRT 0\n")); + } + else if (commandBuffer[num] == "s") + { + sendData(QString("0\nVFOA\n")); } commandBuffer.clear(); + sep = " "; + num = 0; } } @@ -95,23 +179,28 @@ void rigCtlClient::closeSocket() void rigCtlClient::sendData(QString data) { + qDebug(logRigCtlD()) << "Sending:" << data; if (socket != Q_NULLPTR && socket->isValid() && socket->isOpen()) { socket->write(data.toLatin1()); } + else + { + qDebug(logRigCtlD()) << "socket not open!"; + } } -void rigCtlClient::dumpCaps() +void rigCtlClient::dumpCaps(QString sep) { - sendData(QString("Caps dump for model: %1\n").arg(rigCaps.modelID)); - sendData(QString("Model Name:\t%1\n").arg(rigCaps.modelName)); - sendData(QString("Mfg Name:\tIcom\n")); - sendData(QString("Backend version:\t0.1\n")); - sendData(QString("Backend copyright:\t2021\n")); - sendData(QString("Rig type:\tTransceiver\n")); - sendData(QString("PTT type:\tRig capable\n")); - sendData(QString("DCD type:\tRig capable\n")); - sendData(QString("Port type:\tNetwork link\n")); - + sendData(QString("Caps dump for model: %1%2").arg(rigCaps.modelID).arg(sep)); + sendData(QString("Model Name:\t%1%2").arg(rigCaps.modelName).arg(sep)); + sendData(QString("Mfg Name:\tIcom%1").arg(sep)); + sendData(QString("Backend version:\t0.1%1").arg(sep)); + sendData(QString("Backend copyright:\t2021%1").arg(sep)); + sendData(QString("Rig type:\tTransceiver%1").arg(sep)); + sendData(QString("PTT type:\tRig capable%1").arg(sep)); + sendData(QString("DCD type:\tRig capable%1").arg(sep)); + sendData(QString("Port type:\tNetwork link%1").arg(sep)); + sendData(QString("\n")); } \ No newline at end of file diff --git a/rigctld.h b/rigctld.h index b0b3366..f18af29 100644 --- a/rigctld.h +++ b/rigctld.h @@ -27,12 +27,17 @@ signals: void onStarted(); void onStopped(); void sendData(QString data); + void setFrequency(freqt freq); + void setPTT(bool state); public slots: virtual void incomingConnection(qintptr socketDescriptor); void receiveRigCaps(rigCapabilities caps); + void receiveStateInfo(rigStateStruct* state); + void receiveFrequency(freqt freq); - +private: + rigStateStruct* rigState = Q_NULLPTR; }; @@ -42,7 +47,7 @@ class rigCtlClient : public QObject public: - explicit rigCtlClient(int socket, rigCapabilities caps, rigCtlD* parent = Q_NULLPTR); + explicit rigCtlClient(int socket, rigCapabilities caps, rigStateStruct *state, rigCtlD* parent = Q_NULLPTR); int getSocketId(); @@ -58,9 +63,10 @@ protected: QString commandBuffer; private: - void dumpCaps(); + void dumpCaps(QString sep); rigCapabilities rigCaps; - + rigStateStruct* rigState = Q_NULLPTR; + rigCtlD* parent; }; #endif diff --git a/wfmain.cpp b/wfmain.cpp index be83b05..5194965 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -203,13 +203,6 @@ wfmain::wfmain(const QString serialPortCL, const QString hostCL, QWidget *parent } - // Start rigctld - if (prefs.enableRigCtlD) { - rigCtl = new rigCtlD(this); - - rigCtl->startServer(prefs.rigCtlPort); - connect(this, SIGNAL(sendRigCaps(rigCapabilities)), rigCtl, SLOT(receiveRigCaps(rigCapabilities))); - } plot = ui->plot; // rename it waterfall. wf = ui->waterfall; @@ -462,7 +455,7 @@ wfmain::wfmain(const QString serialPortCL, const QString hostCL, QWidget *parent connect(rig, SIGNAL(havePreamp(unsigned char)), this, SLOT(receivePreamp(unsigned char))); connect(this, SIGNAL(getAttenuator()), rig, SLOT(getAttenuator())); connect(rig, SIGNAL(haveAttenuator(unsigned char)), this, SLOT(receiveAttenuator(unsigned char))); - connect(this, SIGNAL(getAntenna()), rig, SLOT(getAntenna)); + connect(this, SIGNAL(getAntenna()), rig, SLOT(getAntenna())); //connect(rig, SIGNAL(haveAntenna(unsigned char)), this, SLOT(receiveAntennaSel(unsigned char))); @@ -612,6 +605,14 @@ void wfmain::openRig() } #endif + // Start rigctld + if (prefs.enableRigCtlD) { + rigCtl = new rigCtlD(this); + + rigCtl->startServer(prefs.rigCtlPort); + connect(this, SIGNAL(sendRigCaps(rigCapabilities)), rigCtl, SLOT(receiveRigCaps(rigCapabilities))); + } + if (rigThread == Q_NULLPTR) { rig = new rigCommander(); @@ -633,6 +634,11 @@ void wfmain::openRig() connect(this, SIGNAL(getRigCIV()), rig, SLOT(findRigs())); connect(rig, SIGNAL(discoveredRigID(rigCapabilities)), this, SLOT(receiveFoundRigID(rigCapabilities))); connect(rig, SIGNAL(commReady()), this, SLOT(receiveCommReady())); + if (rigCtl != Q_NULLPTR) { + connect(rig, SIGNAL(stateInfo(rigStateStruct*)), rigCtl, SLOT(receiveStateInfo(rigStateStruct*))); + connect(rigCtl, SIGNAL(setFrequency(freqt)), rig, SLOT(setFrequency(freqt))); + connect(rigCtl, SIGNAL(setPTT(bool)), rig, SLOT(setPTT(bool))); + } } if (prefs.enableLAN) diff --git a/wfmain.h b/wfmain.h index c33d4e8..ed8c505 100644 --- a/wfmain.h +++ b/wfmain.h @@ -649,6 +649,7 @@ private: Q_DECLARE_METATYPE(struct rigCapabilities) Q_DECLARE_METATYPE(struct freqt) Q_DECLARE_METATYPE(struct udpPreferences) +Q_DECLARE_METATYPE(struct rigStateStruct) Q_DECLARE_METATYPE(enum rigInput) Q_DECLARE_METATYPE(enum meterKind) Q_DECLARE_METATYPE(enum spectrumMode)