diff --git a/devsetup.cpp b/devsetup.cpp index 80f61c5e5..efdcdfbb0 100644 --- a/devsetup.cpp +++ b/devsetup.cpp @@ -218,9 +218,6 @@ void DevSetup::initDlg() ui.f14->setText(m_dFreq[13]); ui.f15->setText(m_dFreq[14]); ui.f16->setText(m_dFreq[15]); - - qDebug() << "A" << m_poll; - } //------------------------------------------------------- accept() @@ -408,6 +405,8 @@ void DevSetup::on_cbID73_toggled(bool checked) void DevSetup::on_testCATButton_clicked() { + QString t; + int ret; if(!m_catEnabled) return; if(m_bRigOpen) { @@ -416,36 +415,44 @@ void DevSetup::on_testCATButton_clicked() m_bRigOpen=false; } rig = new Rig(m_rig); - try { - 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"); - } - //qDebug() << "B6"; - rig->open(); - //rig->getVFO(); - //qDebug() << "B7" << rig->getVFO(); - m_bRigOpen=true; + 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"); } - catch (const RigException &Ex) { -// qDebug() << "B8"; - m_bRigOpen=false; - msgBox("Failed to open rig (devsetup)"); + + ret=rig->open(); + if(ret==RIG_OK) { + m_bRigOpen=true; + } else { + t="Open rig failed"; + msgBox(t); + m_catEnabled=false; + ui.cbEnableCAT->setChecked(false); return; } -// qDebug() << "B9"; + double fMHz=rig->getFreq(RIG_VFO_CURR)/1000000.0; - QString t; - t.sprintf("Rig control working.\nDial Frequency: %.6f",fMHz); + if(fMHz>0.0) { + t.sprintf("Rig control appears to be working.\nDial Frequency: %.6f MHz", + fMHz); + } else { + t.sprintf("Rig control error %d\nFailed to read frequency.", + int(1000000.0*fMHz)); + if(m_poll>0) { + m_catEnabled=false; + ui.cbEnableCAT->setChecked(false); + } + } msgBox(t); } diff --git a/devsetup.h b/devsetup.h index ccf6e4a52..bc0659d83 100644 --- a/devsetup.h +++ b/devsetup.h @@ -5,7 +5,7 @@ #include #include #include "ui_devsetup.h" -#include +#include "rigclass.h" class DevSetup : public QDialog { diff --git a/devsetup.ui b/devsetup.ui index 4f23b97cf..09197187a 100644 --- a/devsetup.ui +++ b/devsetup.ui @@ -1050,7 +1050,7 @@ - + 0 0 @@ -1062,7 +1062,7 @@ - Polling interval: + Polling interval (s): diff --git a/getfile.cpp b/getfile.cpp index adb4c4e75..59a1729ac 100644 --- a/getfile.cpp +++ b/getfile.cpp @@ -206,3 +206,8 @@ int ptt(int nport, int ntx, int* iptt, int* nopen) return 0; #endif } + +int hamlibError(int retcode) +{ + qDebug() << "Hamlib error" << retcode; +} diff --git a/mainwindow.cpp b/mainwindow.cpp index bacc2cd76..8668a1b84 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -179,6 +179,7 @@ MainWindow::MainWindow(QSharedMemory *shdmem, QWidget *parent) : m_bRigOpen=false; m_secBandChanged=0; m_bMultipleOK=false; + m_dontReadFreq=false; decodeBusy(false); ui->xThermo->setFillBrush(Qt::green); @@ -866,7 +867,7 @@ void MainWindow::dialFreqChanged2(double f) t.sprintf("%.6f",m_dialFreq); int n=t.length(); t=t.mid(0,n-3) + " " + t.mid(n-3,3); - if(qAbs(m_dialFreq-dFreq[m_band])<0.1) { + if(qAbs(m_dialFreq-dFreq[m_band])<0.01) { ui->labDialFreq->setStyleSheet( \ "QLabel { background-color : black; color : yellow; }"); } else { @@ -1466,13 +1467,14 @@ void MainWindow::decodeBusy(bool b) //decodeBusy() void MainWindow::guiUpdate() { static int iptt0=0; -// static int iptt=0; static bool btxok0=false; static int nc0=1; static char message[29]; static char msgsent[29]; static int nsendingsh=0; int khsym=0; + int ret=0; + QString rt; double tx1=0.0; double tx2=1.0 + 85.0*m_nsps/12000.0 + icw[0]*2560.0/48000.0; @@ -1500,8 +1502,13 @@ void MainWindow::guiUpdate() //Raise PTT if(m_catEnabled and m_bRigOpen and m_pttMethodIndex==0) { m_iptt=1; - if(m_pttData) rig->setPTT(RIG_PTT_ON_DATA, RIG_VFO_CURR); - if(!m_pttData) rig->setPTT(RIG_PTT_ON_MIC, RIG_VFO_CURR); + if(m_pttData) ret=rig->setPTT(RIG_PTT_ON_DATA, RIG_VFO_CURR); + if(!m_pttData) ret=rig->setPTT(RIG_PTT_ON_MIC, RIG_VFO_CURR); + if(ret!=RIG_OK) { + rt.sprintf("CAT control PTT failed: %d",ret); + msgBox(rt); + } + } if(m_pttMethodIndex==1 or m_pttMethodIndex==2) { //DTR or RTS ptt(m_pttPort,1,&m_iptt,&m_COMportOpen); @@ -1634,7 +1641,11 @@ void MainWindow::guiUpdate() //Lower PTT if(m_catEnabled and m_bRigOpen and m_pttMethodIndex==0) { m_iptt=0; - rig->setPTT(RIG_PTT_OFF, RIG_VFO_CURR); //CAT control for PTT=0 + ret=rig->setPTT(RIG_PTT_OFF, RIG_VFO_CURR); //CAT control for PTT=0 + if(ret!=RIG_OK) { + rt.sprintf("CAT control PTT failed: %d",ret); + msgBox(rt); + } } if(m_pttMethodIndex==1 or m_pttMethodIndex==2) { //DTR-RTS ptt(m_pttPort,0,&m_iptt,&m_COMportOpen); @@ -1698,14 +1709,26 @@ void MainWindow::guiUpdate() if(!m_monitoring and !m_diskData) { ui->xThermo->setValue(0.0); } + + if(m_catEnabled and m_poll>0 and (nsec%m_poll)==0) { + if(m_dontReadFreq) { + m_dontReadFreq=false; + } else { + double fMHz=rig->getFreq(RIG_VFO_CURR)/1000000.0; + if(fMHz<0.0) { + rt.sprintf("Rig control error %d\nFailed to read frequency.", + int(1000000.0*fMHz)); + msgBox(rt); + m_catEnabled=false; + } + + int ndiff=1000000.0*(fMHz-m_dialFreq); + if(ndiff!=0) dialFreqChanged2(fMHz); + } + } + m_hsym0=khsym; m_sec0=nsec; - - if(m_catEnabled) { - double fMHz=rig->getFreq(RIG_VFO_CURR)/1000000.0; - int ndiff=1000000.0*(fMHz-m_dialFreq); - if(ndiff!=0) dialFreqChanged2(fMHz); - } } iptt0=m_iptt; @@ -1761,9 +1784,16 @@ void MainWindow::stopTx() void MainWindow::stopTx2() { + int ret=0; + QString rt; + //Lower PTT if(m_catEnabled and m_bRigOpen and m_pttMethodIndex==0) { - rig->setPTT(RIG_PTT_OFF, RIG_VFO_CURR); //CAT control for PTT=0 + ret=rig->setPTT(RIG_PTT_OFF, RIG_VFO_CURR); //CAT control for PTT=0 + if(ret!=RIG_OK) { + rt.sprintf("CAT control PTT failed: %d",ret); + msgBox(rt); + } } if(m_pttMethodIndex==1 or m_pttMethodIndex==2) { ptt(m_pttPort,0,&m_iptt,&m_COMportOpen); @@ -2534,6 +2564,9 @@ void MainWindow::on_actionLog_dB_reports_to_Comments_triggered(bool checked) void MainWindow::on_bandComboBox_activated(int index) { + int ret=0; + QString rt; + m_band=index; QString t=m_dFreq[index]; m_dialFreq=t.toDouble(); @@ -2544,7 +2577,14 @@ void MainWindow::on_bandComboBox_activated(int index) if(!m_bRigOpen) { rigOpen(); } - if(m_bRigOpen) rig->setFreq(MHz(m_dialFreq)); + if(m_bRigOpen) { + m_dontReadFreq=true; + ret=rig->setFreq(MHz(m_dialFreq)); + if(ret!=RIG_OK) { + rt.sprintf("Set rig frequency failed: %d",ret); + msgBox(rt); + } + } } QFile f2("ALL.TXT"); f2.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Append); @@ -2719,34 +2759,36 @@ void MainWindow::on_stopTxButton_clicked() //Stop Tx void MainWindow::rigOpen() { + QString t; + int ret; + rig = new Rig(m_rig); - try { - 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->open(); - pbwidth_t bw; - rmode_t rigMode; - rigMode=rig->getMode(bw); - if(rigMode!=RIG_MODE_USB) rig->setMode(RIG_MODE_USB); - m_bRigOpen=true; - ui->labRigOpen->setStyleSheet("QLabel{background-color: red}"); + 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"); } - catch (const RigException &Ex) { - m_catEnabled=false; - m_bRigOpen=false; - ui->labRigOpen->setStyleSheet(""); - delete rig; + + ret=rig->open(); + if(ret==RIG_OK) { + m_bRigOpen=true; + } else { + t="Open rig failed"; + msgBox(t); + } + + if(m_poll>0) { + ui->labRigOpen->setStyleSheet("QLabel{background-color: red}"); + } else { + ui->labRigOpen->setStyleSheet("QLabel{background-color: orange}"); } } diff --git a/mainwindow.h b/mainwindow.h index c4abec9f7..78d9966d1 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -7,7 +7,7 @@ #include "soundout.h" #include "commons.h" #include "psk_reporter.h" -#include +#include "rigclass.h" #ifdef WIN32 #include "PSKReporter.h" @@ -254,6 +254,7 @@ private: bool m_bMultipleOK; bool m_bDTRoff; bool m_pttData; + bool m_dontReadFreq; char m_decoded[80]; diff --git a/rigclass.cpp b/rigclass.cpp index f66b10297..3e8c0a5ed 100644 --- a/rigclass.cpp +++ b/rigclass.cpp @@ -35,10 +35,14 @@ #include #include "rigclass.h" +#include #define CHECK_RIG(cmd) { int _retval = cmd; if (_retval != RIG_OK) \ THROW(new RigException (_retval)); } +#define CHECK_RIG2(cmd) { int _retval = cmd; if (_retval != RIG_OK) \ + return _retval; } + static int hamlibpp_freq_event(RIG *rig, vfo_t vfo, freq_t freq, rig_ptr_t arg); static int hamlibpp_freq_event(RIG *rig, vfo_t vfo, freq_t freq, rig_ptr_t arg) @@ -68,24 +72,41 @@ Rig::~Rig() { caps = NULL; } -void Rig::open(void) { - CHECK_RIG( rig_open(theRig) ); +int Rig::open(void) { + CHECK_RIG2( rig_open(theRig) ); } -void Rig::close(void) { - CHECK_RIG( rig_close(theRig) ); +int Rig::close(void) { + CHECK_RIG2( rig_close(theRig) ); } -void Rig::setConf(token_t token, const char *val) +int Rig::setConf(const char *name, const char *val) +{ + CHECK_RIG2( rig_set_conf(theRig, tokenLookup(name), val) ); +} + +int Rig::setPTT(ptt_t ptt, vfo_t vfo) +{ + CHECK_RIG2( rig_set_ptt(theRig, vfo, ptt) ); +} + +int Rig::setFreq(freq_t freq, vfo_t vfo) { + CHECK_RIG2( rig_set_freq(theRig, vfo, freq) ); +} + +freq_t Rig::getFreq(vfo_t vfo) +{ + freq_t freq; + CHECK_RIG2( rig_get_freq(theRig, vfo, &freq) ); + return freq; +} + +//-------------------------------------------------------------- +int Rig::setConf(token_t token, const char *val) { CHECK_RIG( rig_set_conf(theRig, token, val) ); } -void Rig::setConf(const char *name, const char *val) -{ - CHECK_RIG( rig_set_conf(theRig, tokenLookup(name), val) ); -} - void Rig::getConf(token_t token, char *val) { CHECK_RIG( rig_get_conf(theRig, token, val) ); @@ -101,17 +122,6 @@ token_t Rig::tokenLookup(const char *name) return rig_token_lookup(theRig, name); } -void Rig::setFreq(freq_t freq, vfo_t vfo) { - CHECK_RIG( rig_set_freq(theRig, vfo, freq) ); -} - -freq_t Rig::getFreq(vfo_t vfo) -{ - freq_t freq; - CHECK_RIG( rig_get_freq(theRig, vfo, &freq) ); - return freq; -} - void Rig::setMode(rmode_t mode, pbwidth_t width, vfo_t vfo) { CHECK_RIG(rig_set_mode(theRig, vfo, mode, width)); } @@ -134,10 +144,6 @@ vfo_t Rig::getVFO() return vfo; } -void Rig::setPTT(ptt_t ptt, vfo_t vfo) -{ - CHECK_RIG( rig_set_ptt(theRig, vfo, ptt) ); -} ptt_t Rig::getPTT(vfo_t vfo) { diff --git a/rigclass.h b/rigclass.h index d34811507..fd33c0309 100644 --- a/rigclass.h +++ b/rigclass.h @@ -25,6 +25,7 @@ #include #include +//extern int hamlibError(int retcode); class BACKEND_IMPEXP Rig { private: @@ -39,25 +40,27 @@ public: const struct rig_caps *caps; // This method open the communication port to the rig - void open(void); + int open(void); // This method close the communication port to the rig - void close(void); + int close(void); - void setConf(token_t token, const char *val); - void setConf(const char *name, const char *val); + int setConf(const char *name, const char *val); + int setFreq(freq_t freq, vfo_t vfo = RIG_VFO_CURR); + freq_t getFreq(vfo_t vfo = RIG_VFO_CURR); + int setPTT (ptt_t ptt, vfo_t vfo = RIG_VFO_CURR); + + int setConf(token_t token, const char *val); void getConf(token_t token, char *val); void getConf(const char *name, char *val); token_t tokenLookup(const char *name); - void setFreq(freq_t freq, vfo_t vfo = RIG_VFO_CURR); - freq_t getFreq(vfo_t vfo = RIG_VFO_CURR); + void setMode(rmode_t, pbwidth_t width = RIG_PASSBAND_NORMAL, vfo_t vfo = RIG_VFO_CURR); rmode_t getMode(pbwidth_t&, vfo_t vfo = RIG_VFO_CURR); void setVFO(vfo_t); vfo_t getVFO(); - void setPTT (ptt_t ptt, vfo_t vfo = RIG_VFO_CURR); ptt_t getPTT (vfo_t vfo = RIG_VFO_CURR); dcd_t getDCD (vfo_t vfo = RIG_VFO_CURR); @@ -273,5 +276,4 @@ inline void THROW(const RigException *e) { #define THROWS(s) - #endif // _RIGCLASS_H