diff --git a/rigcommander.cpp b/rigcommander.cpp index a6f9761..c77a146 100644 --- a/rigcommander.cpp +++ b/rigcommander.cpp @@ -25,6 +25,8 @@ rigCommander::rigCommander() rigState.filter = 0; rigState.mode = 0; rigState.ptt = 0; + rigState.currentVfo = 0; + rigState.splitEnabled = 0; } rigCommander::~rigCommander() @@ -140,7 +142,7 @@ void rigCommander::commSetup(unsigned char rigCivAddr, udpPreferences prefs, aud // data from the comm port to the program: emit commReady(); - emit stateInfo(&rigState); + sendState(); // Send current rig state to rigctld pttAllowed = true; // This is for developing, set to false for "safe" debugging. Set to true for deployment. @@ -3785,6 +3787,11 @@ QByteArray rigCommander::stripData(const QByteArray &data, unsigned char cutPosi return rtndata; } +void rigCommander::sendState() +{ + emit stateInfo(&rigState); +} + void rigCommander::getDebug() { // generic debug function for development. diff --git a/rigcommander.h b/rigcommander.h index 676d07f..ebb03f6 100644 --- a/rigcommander.h +++ b/rigcommander.h @@ -62,9 +62,11 @@ struct timekind { struct rigStateStruct { freqt vfoAFreq; freqt vfoBFreq; + unsigned char currentVfo; unsigned char ptt; unsigned char mode; unsigned char filter; + unsigned char splitEnabled; bool datamode; // Tones quint16 ctcss; @@ -270,6 +272,7 @@ public slots: // Housekeeping: void handleStatusUpdate(const QString text); + void sendState(); void getDebug(); signals: diff --git a/rigctld.cpp b/rigctld.cpp index 7eff599..384b3c9 100644 --- a/rigctld.cpp +++ b/rigctld.cpp @@ -9,6 +9,7 @@ rigCtlD::rigCtlD(QObject* parent) : rigCtlD::~rigCtlD() { + qInfo(logRigCtlD()) << "closing rigctld"; } void rigCtlD::receiveFrequency(freqt freq) @@ -82,6 +83,7 @@ void rigCtlClient::socketReadyRead() static QString sep = " "; static int num = 0; bool longReply = false; + unsigned char responseCode = 0; if (commandBuffer.endsWith('\n')) { qDebug(logRigCtlD()) << sessionId << "command received" << commandBuffer; @@ -107,30 +109,27 @@ void rigCtlClient::socketReadyRead() else if (commandBuffer[num] == "+") { sep = "\n"; - } - - else if (commandBuffer[num].toLower() == "q") - { - closeSocket(); + num++; } else if (commandBuffer[num] == "#") { return; } - else if (commandBuffer[num] == "\\") + else if (commandBuffer[num].toLower() == "q") + { + closeSocket(); + } + + if (commandBuffer[num] == "\\") { num++; longReply = true; } QStringList command = commandBuffer.mid(num).split(" "); - if (command[0] == 0xf0 || command[0]=="chk_vfo") { - if (longReply) - sendData(QString("0\n")); - else - sendData(QString("0\n")); + sendData(QString("%1\n").arg(rigState->currentVfo)); } else if (command[0] == "dump_state") { @@ -139,27 +138,37 @@ void rigCtlClient::socketReadyRead() } else if (command[0] == "f" || command[0] == "get_freq") { - sendData(QString("%1\n").arg(rigState->vfoAFreq.Hz)); + if (rigState->currentVfo == 0) { + sendData(QString("%1\n").arg(rigState->vfoAFreq.Hz)); + } + else { + sendData(QString("%1\n").arg(rigState->vfoBFreq.Hz)); + } } else if (command[0] == "F" || command[0] == "set_freq") { if (command.length()>1) { freqt freq; - freq.Hz = command[1].toInt(); + bool ok; + double newFreq = command[1].toDouble(&ok); + if (ok) { + freq.Hz = static_cast(newFreq); + } + qInfo(logRigCtlD()) << QString("Set frequency: %1 (%2)").arg(freq.Hz).arg(command[1]); emit parent->setFrequency(freq); } - sendData(QString("RPRT 0\n")); + sendData(QString("RPRT %1\n").arg(responseCode)); } else if (command[0] == "1" || command[0] == "dump_caps") { dumpCaps(sep); } - else if (command[0] == "t") + else if (command[0] == "t" || command[0] == "get_ptt") { sendData(QString("%1\n").arg(rigState->ptt)); } - else if (command[0] == "T") + else if (command[0] == "T" || command[0] == "set_ptt") { if (command.length()>1 && command[1] == "0") { emit parent->setPTT(false); @@ -167,24 +176,95 @@ void rigCtlClient::socketReadyRead() else { emit parent->setPTT(true); } - sendData(QString("RPRT 0\n")); + sendData(QString("RPRT %1\n").arg(responseCode)); } - else if (command[0] == "v" || command[0] == "get_vfo") + else if (command[0] == "v" || command[0] == "get_vfo") { - sendData(QString("VFOA\n")); + if (rigState->currentVfo == 0) { + sendData(QString("%1\n").arg("VFOA")); + } + else { + sendData(QString("%1\n").arg("VFOB")); + } } - else if (command[0] == "m" || command[0] == "get_mode") + else if (command[0] == "V" || command[0] == "set_vfo") { - sendData(QString("%1\n%2\n").arg(getMode(rigState->mode,rigState->datamode)).arg(getFilter(rigState->mode,rigState->filter))); + qDebug(logRigCtlD()) << QString("Got VFO command: %1").arg(command[1]); + if (command.length() > 1 && command[1] == "VFOB") { + emit parent->setVFO(1); + } + else { + emit parent->setVFO(0); + } + sendData(QString("RPRT %1\n").arg(responseCode)); + } + else if (command[0] == "s" || command[0] == "get_split_vfo") + { + sendData(QString("%1\n").arg(rigState->splitEnabled)); + if (rigState->currentVfo == 0) + { + sendData(QString("%1\n").arg("VFOB")); + } + else { + sendData(QString("%1\n").arg("VFOA")); + } + } + else if (command[0] == "S" || command[0] == "set_split_vfo") + { + if (command.length() > 1 && command[1] == "1") + { + emit parent->setSplit(1); + } + else { + emit parent->setSplit(0); + } + sendData(QString("RPRT %1\n").arg(responseCode)); + } + else if (command[0] == "i" || command[0] == "get_split_freq") + { + if (rigState->currentVfo == 0) { + sendData(QString("%1\n").arg(rigState->vfoBFreq.Hz)); + } + else { + sendData(QString("%1\n").arg(rigState->vfoAFreq.Hz)); + } + } + else if (command[0] == "I" || command[0] == "set_split_freq") + { + sendData(QString("RPRT %1\n").arg(responseCode)); + } + else if (command[0] == "m" || command[0] == "get_mode") + { + if (longReply) { + sendData(QString("Mode: %1\nPassband: %2\n").arg(getMode(rigState->mode, rigState->datamode)).arg(getFilter(rigState->mode, rigState->filter))); + } + else { + sendData(QString("%1\n%2\n").arg(getMode(rigState->mode, rigState->datamode)).arg(getFilter(rigState->mode, rigState->filter))); + } + sendData(QString("RPRT %1\n").arg(responseCode)); } else if (command[0] == "M" || command[0] == "set_mode") { // Set mode - if (command.length() > 1) { - qInfo(logRigCtlD()) << "setting mode: " << getMode(command[1]); - emit parent->setMode(getMode(command[1]), 0x06); + if (command.length() > 2) { + + qInfo(logRigCtlD()) << "setting mode: " << getMode(command[1]) << command[1] << "width" << command[2]; + int width = command[2].toInt(); + + if (width != -1 && width <= 1800) + width = 2; + else + width = 1; + + emit parent->setMode(getMode(command[1]), width); + if (command[1].mid(0, 3) == "PKT") { + emit parent->setDataMode(true, width); + } + else { + emit parent->setDataMode(false, 0x01); + } } - sendData(QString("RPRT 0\n")); + sendData(QString("RPRT %1\n").arg(responseCode)); } else if (command[0] == "s" || command[0] == "get_split_vfo") { @@ -221,7 +301,6 @@ void rigCtlClient::sendData(QString data) } } - void rigCtlClient::dumpCaps(QString sep) { sendData(QString("Caps dump for model: %1%2").arg(rigCaps.modelID).arg(sep)); @@ -295,36 +374,51 @@ QString rigCtlClient::getFilter(unsigned char mode, unsigned char filter) { } QString rigCtlClient::getMode(unsigned char mode, bool datamode) { - (void)datamode; + + QString ret; + if (datamode) { + return ret="PKT"; + } + switch (mode) { case 0: - return QString("LSB"); + ret.append("LSB"); + break; case 1: - return QString("USB"); + ret.append("USB"); + break; case 2: - return QString("AM"); + ret.append("AM"); + break; case 3: - return QString("CW"); + ret.append("CW"); + break; case 4: - return QString("RTTY"); + ret.append("RTTY"); + break; case 5: - return QString("FM"); + ret.append("FM"); + break; case 6: - return QString("WFM"); + ret.append("WFM"); + break; case 7: - return QString("CWR"); + ret.append("CWR"); + break; case 8: - return QString("RTTYR"); + ret.append("RTTYR"); + break; case 12: - return QString("PKTUSB"); + ret.append("USB"); + break; case 17: - return QString("PKTLSB"); + ret.append("LSB"); + break; case 22: - return QString("PKTFM"); - default: - return QString(""); + ret.append("FM"); + break; } - return QString(""); + return ret; } unsigned char rigCtlClient::getMode(QString modeString) { @@ -370,3 +464,4 @@ unsigned char rigCtlClient::getMode(QString modeString) { } return 0; } + diff --git a/rigctld.h b/rigctld.h index 8694f4b..917091f 100644 --- a/rigctld.h +++ b/rigctld.h @@ -33,6 +33,9 @@ signals: void setFrequency(freqt freq); void setPTT(bool state); void setMode(unsigned char mode, unsigned char modeFilter); + void setDataMode(bool dataOn, unsigned char modeFilter); + void setVFO(unsigned char vfo); + void setSplit(unsigned char split); public slots: virtual void incomingConnection(qintptr socketDescriptor); @@ -74,7 +77,6 @@ private: QString getMode(unsigned char mode, bool datamode); unsigned char getMode(QString modeString); QString getFilter(unsigned char mode, unsigned char filter); - }; diff --git a/wfmain.cpp b/wfmain.cpp index b5d1497..6db49bb 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -175,13 +175,6 @@ void wfmain::openRig() qDebug(logSystem()) << "Remote host name specified by user: " << hostCL; } - // Start rigctld - if (prefs.enableRigCtlD && rigCtl == Q_NULLPTR) { - rigCtl = new rigCtlD(this); - - rigCtl->startServer(prefs.rigCtlPort); - connect(this, SIGNAL(sendRigCaps(rigCapabilities)), rigCtl, SLOT(receiveRigCaps(rigCapabilities))); - } makeRig(); @@ -405,8 +398,10 @@ void wfmain::makeRig() if (rigCtl != Q_NULLPTR) { connect(rig, SIGNAL(stateInfo(rigStateStruct*)), rigCtl, SLOT(receiveStateInfo(rigStateStruct*))); + connect(this, SIGNAL(requestRigState()), rig, SLOT(sendState())); connect(rigCtl, SIGNAL(setFrequency(freqt)), rig, SLOT(setFrequency(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))); } } @@ -425,7 +420,7 @@ void wfmain::removeRig() delete rigThread; delete rig; - + rig = Q_NULLPTR; } } @@ -1367,7 +1362,11 @@ void wfmain::loadSettings() ui->connectBtn->setEnabled(true); prefs.enableRigCtlD = settings->value("EnableRigCtlD", defPrefs.enableRigCtlD).toBool(); + ui->enableRigctldChk->setChecked(prefs.enableRigCtlD); prefs.rigCtlPort = settings->value("RigCtlPort", defPrefs.rigCtlPort).toInt(); + ui->rigctldPortTxt->setText(QString("%1").arg(prefs.rigCtlPort)); + // Call the function to start rigctld if enabled. + on_enableRigctldChk_clicked(prefs.enableRigCtlD); udpPrefs.ipAddress = settings->value("IPAddress", udpDefPrefs.ipAddress).toString(); ui->ipAddressTxt->setEnabled(ui->lanEnableBtn->isChecked()); @@ -5244,6 +5243,45 @@ void wfmain::on_meter2selectionCombo_activated(int index) (void)index; } +void wfmain::on_enableRigctldChk_clicked(bool checked) +{ + if (rigCtl != Q_NULLPTR) + { + rigCtl->disconnect(); + delete rigCtl; + rigCtl = Q_NULLPTR; + } + + if (checked) { + // Start rigctld + rigCtl = new rigCtlD(this); + rigCtl->startServer(prefs.rigCtlPort); + connect(this, SIGNAL(sendRigCaps(rigCapabilities)), rigCtl, SLOT(receiveRigCaps(rigCapabilities))); + if (rig != Q_NULLPTR) { + // We are already connected to a rig. + connect(rig, SIGNAL(stateInfo(rigStateStruct*)), rigCtl, SLOT(receiveStateInfo(rigStateStruct*))); + connect(rigCtl, SIGNAL(setFrequency(freqt)), rig, SLOT(setFrequency(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))); + emit sendRigCaps(rigCaps); + emit requestRigState(); + } + } + prefs.enableRigCtlD = checked; +} + +void wfmain::on_rigctldPortTxt_editingFinished() +{ + + bool okconvert = false; + unsigned int port = ui->rigctldPortTxt->text().toUInt(&okconvert); + if (okconvert) + { + prefs.rigCtlPort = port; + } +} + // --- DEBUG FUNCTION --- void wfmain::on_debugBtn_clicked() { diff --git a/wfmain.h b/wfmain.h index a119c77..934870d 100644 --- a/wfmain.h +++ b/wfmain.h @@ -153,6 +153,7 @@ signals: void initServer(); void sendServerConfig(SERVERCONFIG conf); void sendRigCaps(rigCapabilities caps); + void requestRigState(); private slots: void updateSizes(int tabIndex); @@ -472,6 +473,10 @@ private slots: void on_meter2selectionCombo_activated(int index); + void on_enableRigctldChk_clicked(bool checked); + + void on_rigctldPortTxt_editingFinished(); + private: Ui::wfmain *ui; void closeEvent(QCloseEvent *event); diff --git a/wfmain.ui b/wfmain.ui index fe15c95..d55ba9b 100644 --- a/wfmain.ui +++ b/wfmain.ui @@ -2232,7 +2232,7 @@ - + Qt::Horizontal @@ -2244,6 +2244,26 @@ + + + + Qt::RightToLeft + + + Enable RigCtld + + + + + + + Port + + + + + + diff --git a/wfview.vcxproj b/wfview.vcxproj index 2502415..6d319a1 100644 --- a/wfview.vcxproj +++ b/wfview.vcxproj @@ -57,7 +57,7 @@ Sync release\ MaxSpeed - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;USE_SSE;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;__WINDOWS_WASAPI__;GITSHORT="ea09e1f";HOST="wfview.org";UNAME="build";QT_NO_DEBUG;NDEBUG;%(PreprocessorDefinitions) + _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;USE_SSE;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;__WINDOWS_WASAPI__;GITSHORT="eddc5d4";HOST="wfview.org";UNAME="build";NDEBUG;QT_NO_DEBUG;%(PreprocessorDefinitions) false MultiThreadedDLL @@ -67,12 +67,13 @@ true shell32.lib;%(AdditionalDependencies) - C:\opensslx86\lib;C:\Utils\my_sql\mysql-5.6.11-win32\lib;C:\Utils\postgresqlx86\pgsql\lib;%(AdditionalLibraryDirectories) + C:\opensslx86\lib;C:\Utils\my_sql\mysql-5.7.25-win32\lib;C:\Utils\postgresqlx86\pgsql\lib;%(AdditionalLibraryDirectories) "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" %(AdditionalOptions) true false true false + true $(OutDir)\wfview.exe true Windows @@ -84,7 +85,7 @@ 0 - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;USE_SSE;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;__WINDOWS_WASAPI__;GITSHORT=\"ea09e1f\";HOST=\"wfview.org\";UNAME=\"build\";QT_NO_DEBUG;QT_MULTIMEDIA_LIB;QT_PRINTSUPPORT_LIB;QT_WIDGETS_LIB;QT_GUI_LIB;QT_SERIALPORT_LIB;QT_NETWORK_LIB;QT_CORE_LIB;%(PreprocessorDefinitions) + _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;USE_SSE;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;__WINDOWS_WASAPI__;GITSHORT=\"eddc5d4\";HOST=\"wfview.org\";UNAME=\"build\";NDEBUG;QT_NO_DEBUG;QT_MULTIMEDIA_LIB;QT_PRINTSUPPORT_LIB;QT_WIDGETS_LIB;QT_GUI_LIB;QT_SERIALPORT_LIB;QT_NETWORK_LIB;QT_CORE_LIB;%(PreprocessorDefinitions) msvc./$(Configuration)/moc_predefs.hMoc'ing %(Identity)...output$(Configuration)moc_%(Filename).cppdefaultRcc'ing %(Identity)...$(Configuration)qrc_%(Filename).cppUic'ing %(Identity)...$(ProjectDir)ui_%(Filename).h @@ -98,7 +99,7 @@ Sync debug\ Disabled - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;USE_SSE;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;__WINDOWS_WASAPI__;GITSHORT="ea09e1f";HOST="wfview.org";UNAME="build";%(PreprocessorDefinitions) + _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;USE_SSE;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;__WINDOWS_WASAPI__;GITSHORT="eddc5d4";HOST="wfview.org";UNAME="build";%(PreprocessorDefinitions) false MultiThreadedDebugDLL true @@ -107,7 +108,7 @@ true shell32.lib;%(AdditionalDependencies) - C:\opensslx86\lib;C:\Utils\my_sql\mysql-5.6.11-win32\lib;C:\Utils\postgresqlx86\pgsql\lib;%(AdditionalLibraryDirectories) + C:\opensslx86\lib;C:\Utils\my_sql\mysql-5.7.25-win32\lib;C:\Utils\postgresqlx86\pgsql\lib;%(AdditionalLibraryDirectories) "/MANIFESTDEPENDENCY:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' publicKeyToken='6595b64144ccf1df' language='*' processorArchitecture='*'" %(AdditionalOptions) true true @@ -123,10 +124,11 @@ 0 - _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;USE_SSE;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;__WINDOWS_WASAPI__;GITSHORT=\"ea09e1f\";HOST=\"wfview.org\";UNAME=\"build\";QT_MULTIMEDIA_LIB;QT_PRINTSUPPORT_LIB;QT_WIDGETS_LIB;QT_GUI_LIB;QT_SERIALPORT_LIB;QT_NETWORK_LIB;QT_CORE_LIB;_DEBUG;%(PreprocessorDefinitions) + _WINDOWS;UNICODE;_UNICODE;WIN32;_ENABLE_EXTENDED_ALIGNED_STORAGE;QT_DEPRECATED_WARNINGS;QCUSTOMPLOT_COMPILE_LIBRARY;USE_SSE;OUTSIDE_SPEEX;RANDOM_PREFIX=wf;__WINDOWS_WASAPI__;GITSHORT=\"eddc5d4\";HOST=\"wfview.org\";UNAME=\"build\";QT_MULTIMEDIA_LIB;QT_PRINTSUPPORT_LIB;QT_WIDGETS_LIB;QT_GUI_LIB;QT_SERIALPORT_LIB;QT_NETWORK_LIB;QT_CORE_LIB;_DEBUG;%(PreprocessorDefinitions) msvc./$(Configuration)/moc_predefs.hMoc'ing %(Identity)...output$(Configuration)moc_%(Filename).cppdefaultRcc'ing %(Identity)...$(Configuration)qrc_%(Filename).cppUic'ing %(Identity)...$(ProjectDir)ui_%(Filename).h + @@ -144,12 +146,23 @@ + + + + + + + + + + + @@ -161,6 +174,7 @@ + @@ -269,6 +283,16 @@ + + + + + + + + + + @@ -320,6 +344,8 @@ + + Document true @@ -362,6 +388,10 @@ + + + + @@ -369,6 +399,17 @@ + + + + + + + + + + + @@ -401,6 +442,17 @@ + + + + + + + + + + + diff --git a/wfview.vcxproj.filters b/wfview.vcxproj.filters index bc7845e..d78480d 100644 --- a/wfview.vcxproj.filters +++ b/wfview.vcxproj.filters @@ -57,6 +57,9 @@ + + Source Files + Source Files @@ -108,6 +111,9 @@ Source Files + + Source Files + Source Files @@ -122,12 +128,18 @@ + + Header Files + Header Files Header Files + + Header Files + Header Files @@ -182,6 +194,9 @@ Header Files + + Header Files + Header Files @@ -207,6 +222,8 @@ + + Generated Files @@ -239,6 +256,10 @@ + + + + @@ -246,6 +267,9 @@ + + Form Files + Form Files @@ -255,6 +279,9 @@ Form Files + + Form Files + Form Files