diff --git a/devsetup.cpp b/devsetup.cpp index d3901743f..52ed6a769 100644 --- a/devsetup.cpp +++ b/devsetup.cpp @@ -126,6 +126,7 @@ void DevSetup::initDlg() this, SLOT(p4Error())); p4.start("rigctl -l"); p4.waitForFinished(1000); + ui.rigComboBox->addItem(" 9999 Ham Radio Deluxe"); QPalette pal(ui.myCallEntry->palette()); if(m_myCall=="") { @@ -244,6 +245,7 @@ void DevSetup::accept() // Check to see whether SoundInThread must be restarted, // and save user parameters. + qDebug() << "a"; if(m_nDevIn!=ui.comboBoxSndIn->currentIndex() or m_paInDevice!=m_inDevList[m_nDevIn]) m_restartSoundIn=true; @@ -291,9 +293,12 @@ void DevSetup::accept() m_dFreq.append(ui.f15->text()); m_dFreq.append(ui.f16->text()); + qDebug() << "b"; + if(m_bRigOpen) { rig->close(); - delete rig; + if(m_rig!=9999) delete rig; + qDebug() << "c"; m_bRigOpen=false; } @@ -436,31 +441,34 @@ void DevSetup::on_testCATButton_clicked() if(!m_catEnabled) return; if(m_bRigOpen) { rig->close(); - delete rig; + if(m_rig!=9999) delete rig; m_bRigOpen=false; } + rig = new Rig(); - if (!rig->init(m_rig)) { + if(m_rig != 9999) { + if (!rig->init(m_rig)) { msgBox("Rig init failure"); return; + } + + rig->setConf("rig_pathname", m_catPort.toAscii().data()); + char buf[80]; + sprintf(buf,"%d",m_serialRate); + rig->setConf("serial_speed",buf); + sprintf(buf,"%d",m_dataBits); + rig->setConf("data_bits",buf); + sprintf(buf,"%d",m_stopBits); + rig->setConf("stop_bits",buf); + rig->setConf("serial_handshake",m_handshake.toAscii().data()); + + if(m_bDTRoff) { + rig->setConf("rts_state","OFF"); + rig->setConf("dtr_state","OFF"); + } } - rig->setConf("rig_pathname", m_catPort.toAscii().data()); - char buf[80]; - sprintf(buf,"%d",m_serialRate); - rig->setConf("serial_speed",buf); - sprintf(buf,"%d",m_dataBits); - rig->setConf("data_bits",buf); - sprintf(buf,"%d",m_stopBits); - rig->setConf("stop_bits",buf); - rig->setConf("serial_handshake",m_handshake.toAscii().data()); - - if(m_bDTRoff) { - rig->setConf("rts_state","OFF"); - rig->setConf("dtr_state","OFF"); - } - - ret=rig->open(); + ret=rig->open(m_rig); if(ret==RIG_OK) { m_bRigOpen=true; } else { @@ -530,3 +538,40 @@ void DevSetup::on_pttMethodComboBox_currentIndexChanged(int index) bool b=m_pttMethodIndex==1 or m_pttMethodIndex==2; ui.pttComboBox->setEnabled(b); } + +void DevSetup::on_pbHRD_clicked() +{ + + bool bConnect=false; + bConnect = HRDInterfaceConnect(L"localhost",7809); + if(bConnect) { + QString t2; + + const wchar_t* context=HRDInterfaceSendMessage(L"Get Context"); + QString qc="[" + QString::fromWCharArray (context,-1) + "] "; + + const wchar_t* cmnd = (const wchar_t*) (qc+"Get Frequency").utf16(); + const wchar_t* freqString=HRDInterfaceSendMessage(cmnd); + t2=QString::fromWCharArray (freqString,-1); + qDebug() << "Freq1:" << t2; + + cmnd = (const wchar_t*) (qc+"Set Frequency-Hz 14070000").utf16(); + const wchar_t* result=HRDInterfaceSendMessage(cmnd); + t2=QString::fromWCharArray (result,-1); + qDebug() << "Freq2:" << t2; + + cmnd = (const wchar_t*) (qc+"Get Frequency").utf16(); + freqString=HRDInterfaceSendMessage(cmnd); + t2=QString::fromWCharArray (freqString,-1); + qDebug() << "Freq3:" << t2; + + + HRDInterfaceDisconnect(); + bConnect = HRDInterfaceIsConnected(); + HRDInterfaceFreeString(context); + HRDInterfaceFreeString(freqString); + HRDInterfaceFreeString(cmnd); + } else { + qDebug() << "Connection to HRD failed."; + } +} diff --git a/devsetup.h b/devsetup.h index 6d7009669..6662baa80 100644 --- a/devsetup.h +++ b/devsetup.h @@ -93,6 +93,8 @@ private slots: void on_pttMethodComboBox_currentIndexChanged(int index); + void on_pbHRD_clicked(); + private: Rig* rig; void msgBox(QString t); @@ -101,4 +103,12 @@ private: extern int ptt(int nport, int ntx, int* iptt, int* nopen); +extern "C" { + const bool HRDInterfaceConnect(const wchar_t *host, const ushort); + void HRDInterfaceDisconnect(); + const bool HRDInterfaceIsConnected(); + const wchar_t* HRDInterfaceSendMessage(const wchar_t *msg); + void HRDInterfaceFreeString(const wchar_t *lstring); +} + #endif // DEVSETUP_H diff --git a/devsetup.ui b/devsetup.ui index fca51c9cd..22d56dfa6 100644 --- a/devsetup.ui +++ b/devsetup.ui @@ -104,6 +104,13 @@ + + + + HRD + + + diff --git a/libHRDInterface001.a b/libHRDInterface001.a new file mode 100644 index 000000000..f3cbd2f01 Binary files /dev/null and b/libHRDInterface001.a differ diff --git a/mainwindow.cpp b/mainwindow.cpp index 9fe116b20..153dd6e1c 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -716,6 +716,7 @@ void MainWindow::on_actionDeviceSetup_triggered() //Setup Dialog } } m_catEnabled=dlg.m_catEnabled; + if(m_catEnabled) { rigOpen(); } @@ -2773,11 +2774,12 @@ void MainWindow::rigOpen() { QString t; int ret; - rig = new Rig(); - if (!rig->init(m_rig)) { + if(m_rig != 9999) { + if (!rig->init(m_rig)) { msgBox("Rig init failure"); return; + } } rig->setConf("rig_pathname", m_catPort.toAscii().data()); @@ -2793,7 +2795,7 @@ void MainWindow::rigOpen() rig->setConf("rts_state","OFF"); rig->setConf("dtr_state","OFF"); } - ret=rig->open(); + ret=rig->open(m_rig); if(ret==RIG_OK) { m_bRigOpen=true; if(m_poll==0) ui->readFreq->setEnabled(true); diff --git a/rigclass.cpp b/rigclass.cpp index 424c4f122..5f3caa476 100644 --- a/rigclass.cpp +++ b/rigclass.cpp @@ -35,6 +35,7 @@ #include #include "rigclass.h" +#include static int hamlibpp_freq_event(RIG *rig, vfo_t vfo, freq_t freq, rig_ptr_t arg); @@ -76,12 +77,31 @@ int Rig::init(rig_model_t rig_model) return initOk; } -int Rig::open(void) { - return rig_open(theRig); +int Rig::open(int n) { + m_hrd=(n==9999); + if(m_hrd) { + bool bConnect=false; + bConnect = HRDInterfaceConnect(L"localhost",7809); + if(bConnect) { + const wchar_t* context=HRDInterfaceSendMessage(L"Get Context"); + m_context="[" + QString::fromWCharArray (context,-1) + "] "; + return 0; + } else { + m_hrd=false; + return -1; + } + } else { + return rig_open(theRig); + } } int Rig::close(void) { - return rig_close(theRig); + if(m_hrd) { + HRDInterfaceDisconnect(); + + } else { + return rig_close(theRig); + } } int Rig::setConf(const char *name, const char *val) @@ -90,14 +110,38 @@ int Rig::setConf(const char *name, const char *val) } int Rig::setFreq(freq_t freq, vfo_t vfo) { - return rig_set_freq(theRig, vfo, freq); + if(m_hrd) { + QString t; + int nhz=(int)freq; + t=m_context + "Set Frequency-Hz " + QString::number(nhz); + qDebug() << "a" << freq << nhz << t; + const wchar_t* cmnd = (const wchar_t*) t.utf16(); + const wchar_t* result=HRDInterfaceSendMessage(cmnd); + QString t2=QString::fromWCharArray (result,-1); + if(t2=="OK") { + return 0; + } else { + return -1; + } + } else { + return rig_set_freq(theRig, vfo, freq); + } } freq_t Rig::getFreq(vfo_t vfo) { freq_t freq; - rig_get_freq(theRig, vfo, &freq); - return freq; + if(m_hrd) { + const wchar_t* cmnd = (const wchar_t*) (m_context+"Get Frequency").utf16(); + const wchar_t* freqString=HRDInterfaceSendMessage(cmnd); + QString t2=QString::fromWCharArray (freqString,-1); + HRDInterfaceFreeString(freqString); + freq=t2.toDouble(); + return freq; + } else { + rig_get_freq(theRig, vfo, &freq); + return freq; + } } int Rig::setMode(rmode_t mode, pbwidth_t width, vfo_t vfo) { diff --git a/rigclass.h b/rigclass.h index 3568d2131..e4c5cd6f5 100644 --- a/rigclass.h +++ b/rigclass.h @@ -24,11 +24,13 @@ #include #include - +#include class BACKEND_IMPEXP Rig { private: RIG* theRig; // Global ref. to the rig + bool m_hrd; + QString m_context; protected: public: @@ -41,7 +43,7 @@ public: int init(rig_model_t rig_model); // This method open the communication port to the rig - int open(void); + int open(int n); // This method close the communication port to the rig int close(void); @@ -77,5 +79,12 @@ public: } }; +extern "C" { + const bool HRDInterfaceConnect(const wchar_t *host, const ushort); + void HRDInterfaceDisconnect(); + const bool HRDInterfaceIsConnected(); + const wchar_t* HRDInterfaceSendMessage(const wchar_t *msg); + void HRDInterfaceFreeString(const wchar_t *lstring); +} #endif // _RIGCLASS_H diff --git a/wsjtx.pro b/wsjtx.pro index 486bcd792..ec801aefa 100644 --- a/wsjtx.pro +++ b/wsjtx.pro @@ -66,6 +66,7 @@ LIBS += ../../hamlib-1.2.15.3/src/.libs/libhamlib.dll.a LIBS += ../wsjtx/lib/libjt9.a LIBS += ../wsjtx/libfftw3f_win.a LIBS += ../wsjtx/libpskreporter.a +LIBS += ../wsjtx/libHRDInterface001.a LIBS += ../QtSupport/palir-02.dll LIBS += libwsock32 LIBS += C:/MinGW/lib/libf95.a