From 22bb94dc020a0bd51197b2c016904d72efd7b6ff Mon Sep 17 00:00:00 2001 From: Joe Taylor Date: Tue, 21 May 2013 19:49:41 +0000 Subject: [PATCH] First attempt at interface to Ham Radio Deluxe (HRD). git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3288 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- devsetup.cpp | 83 +++++++++++++++++++++++++++++++++---------- devsetup.h | 10 ++++++ devsetup.ui | 7 ++++ libHRDInterface001.a | Bin 0 -> 8546 bytes mainwindow.cpp | 8 +++-- rigclass.cpp | 56 +++++++++++++++++++++++++---- rigclass.h | 13 +++++-- wsjtx.pro | 1 + 8 files changed, 148 insertions(+), 30 deletions(-) create mode 100644 libHRDInterface001.a 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 0000000000000000000000000000000000000000..f3cbd2f01b20427a81219f6f7aa439318bf50710 GIT binary patch literal 8546 zcmeI1OK%fN5P-|$goG@wT~GweLxaTLR^BnOCkYA>0+yG8gaEA~v|49kj~|J#kv$;9 z0de54M}EVe_E)U<4V?HjuvOjjsGez$+lYrO+*0?9yQ-$UtG}u4X`kQl2KDyl(r>n! z$}8@Ax$0Ehb=!7?h?lnQu2e#Uoh1M`0bue<;^#-Olc<``2&x0)No->b~QYYhJC>^B((9tF?Wvq1AvIH+nem z>YZK-4LXmX)bt{*|G@7x?)t-_*P=!;Hj0?rZS`BtPS?*dO>1!L+rw-9UeB)wenZ!) zBIb5C{b0)*2EPvm{ejLavv@J`2ziHC zr1yjp&Ce(nPlh@|QPoq}KBLi#{2ke*f8#O%3vdX_AI04AAg~nH*bY4JppzzDL*wfAMS@Z#=gy9WYAxaCj@v1P) zhd%D(Bj*DsX4y4lnKs5LmjA~29mnzxW8iDDyvN$jV>!_4WmtZx*Na&`hx260@&SeA z)HfeKhoalG#$+4&PATE}s;m&D1%KgH;W;&Y4bmBn(Vz7()m1~PXAxS=i-bGgvBXqQ z5~1f6s`+umbQ3*sgyuun;H-)bSgx3|yq1a3v)#spnB_A_x@m--Q&?6`$fi0v(<((N ziO!p{LX;Lf!mARUm7!~3PRR{uUNNOPyWg16oX|W;WG?Dx7RR>VS!7mDth3*Ms@Q<# zi>54R&oO2!e;Uh{!ZQ0W0VCHm@0)3LqLf7DOR_?g7W{!%B{H+2YvQsZH6Xb>BbgkX z+6QO80zc=8MnNH&{lA6%_^wE1L)Vb3NDWAK3`w4yEfer*;^W=&GRjPM%b<`P|Lr=} R6iinit(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