From b02d298518ddc0491c5a4d6c8b58ed095e1f7423 Mon Sep 17 00:00:00 2001 From: Joe Taylor Date: Mon, 15 Apr 2013 20:20:06 +0000 Subject: [PATCH] 1. CAT control now working with calls to hamlib functions. Needs testing!!! 2. Added "Test CAT Control" and "Test PTT" buttons on Setup | Configuration screen. (Must fix flaky behavior of calls to ptt().) git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@3172 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- devsetup.cpp | 38 + devsetup.h | 7 + devsetup.ui | 2051 +++++++++++++++++++++++---------------------- lib/rig_control.c | 56 +- mainwindow.cpp | 48 +- mainwindow.h | 11 +- mainwindow.ui | 2 +- 7 files changed, 1181 insertions(+), 1032 deletions(-) diff --git a/devsetup.cpp b/devsetup.cpp index e03f7adfa..fea72030e 100644 --- a/devsetup.cpp +++ b/devsetup.cpp @@ -14,6 +14,9 @@ DevSetup::DevSetup(QWidget *parent) : QDialog(parent) m_restartSoundIn=false; m_restartSoundOut=false; m_firstCall=true; + m_count=0; + m_iptt=0; + m_bRigOpen=false; } DevSetup::~DevSetup() @@ -369,3 +372,38 @@ void DevSetup::on_cbID73_toggled(bool checked) { m_After73=checked; } + +void DevSetup::on_testCATButton_clicked() +{ + if(!m_catEnabled) return; + if(!m_bRigOpen) { + QString conf_parms; + conf_parms.sprintf("data_bits=%d,stop_bits=%d,serial_handshake=", + m_dataBits,m_stopBits); + conf_parms+=m_handshake; + int iret=rigOpen(0,m_rig,m_catPort.toAscii().data(),m_serialRate, + conf_parms.toAscii().data()); + if(iret!=0) { + msgBox("Failed to open connection to radio."); + return; + } + m_bRigOpen=true; + } + m_count=1-m_count; + int freq=10130000; + if(m_count!=1) freq=14078000; + rigSetFreq(freq); +} + +void DevSetup::on_testPTTButton_clicked() +{ + int iret=0; + m_iptt=1-m_iptt; + if(m_pttMethodIndex==1 or m_pttMethodIndex==2) { + int iptt=m_iptt; + ptt(m_pttPort,iptt,&m_iptt,&m_COMportOpen); + } + if(m_pttMethodIndex==0 and m_bRigOpen) { + iret=rigSetPTT(m_iptt); + } +} diff --git a/devsetup.h b/devsetup.h index 137efdcdb..d27ad8a13 100644 --- a/devsetup.h +++ b/devsetup.h @@ -34,6 +34,9 @@ public: qint32 m_stopBits; qint32 m_stopBitsIndex; qint32 m_handshakeIndex; + qint32 m_count; + qint32 m_iptt; + qint32 m_COMportOpen; bool m_restartSoundIn; bool m_restartSoundOut; @@ -41,6 +44,7 @@ public: bool m_firstCall; bool m_catEnabled; bool m_After73; + bool m_bRigOpen; QString m_myCall; QString m_myGrid; @@ -74,6 +78,9 @@ private slots: void on_stopBitsComboBox_activated(int index); void on_rigComboBox_activated(int index); void on_cbID73_toggled(bool checked); + void on_testCATButton_clicked(); + + void on_testPTTButton_clicked(); private: void msgBox(QString t); diff --git a/devsetup.ui b/devsetup.ui index bd400cc0d..33119f228 100644 --- a/devsetup.ui +++ b/devsetup.ui @@ -35,1044 +35,1107 @@ Station - + - + - - - - - - 0 - 0 - - - - - 80 - 20 - - - - - 80 - 16777215 - - - - My Call: - - - - - - - - 0 - 0 - - - - - 90 - 0 - - - - - 90 - 16777215 - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 80 - 20 - - - - - 80 - 16777215 - - - - My Grid: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - - 60 - 0 - - - - - 60 - 16777215 - - - - - - - - + + + + 0 + 0 + + + + + 80 + 20 + + + + + 80 + 16777215 + + + + My Call: + + - - - - - - 0 - 0 - - - - - 80 - 0 - - - - - 80 - 16777215 - - - - PTT method: - - - - - - - - 0 - 0 - - - - - 90 - 0 - - - - - 90 - 16777215 - - - - 1 - - - - CAT - - - - - DTR - - - - - RTS - - - - - VOX - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 80 - 0 - - - - - 80 - 16777215 - - - - PTT Port: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - - - - - 0 - 0 - - - - - 60 - 0 - - - - - 60 - 16777215 - - - - - None - - - - - COM1 - - - - - COM2 - - - - - COM3 - - - - - COM4 - - - - - COM5 - - - - - COM6 - - - - - COM7 - - - - - COM8 - - - - - COM9 - - - - - COM10 - - - - - COM11 - - - - - COM12 - - - - - COM13 - - - - - COM14 - - - - - COM15 - - - - - USB - - - - - + + + + 0 + 0 + + + + + 90 + 0 + + + + + 90 + 16777215 + + + + + + - + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 80 + 20 + + + + + 80 + 16777215 + + + + My Grid: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 60 + 0 + + + + + 60 + 16777215 + + + + + + + + + + + + + + + + 0 + 0 + + + + + 80 + 0 + + + + + 80 + 16777215 + + + + PTT method: + + + + + + + + 0 + 0 + + + + + 90 + 0 + + + + + 90 + 16777215 + + + + 1 + - + + CAT + + + + + DTR + + + + + RTS + + + + + VOX + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 80 + 0 + + + + + 80 + 16777215 + + + + PTT Port: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + 60 + 0 + + + + + 60 + 16777215 + + + + + None + + + + + COM1 + + + + + COM2 + + + + + COM3 + + + + + COM4 + + + + + COM5 + + + + + COM6 + + + + + COM7 + + + + + COM8 + + + + + COM9 + + + + + COM10 + + + + + COM11 + + + + + COM12 + + + + + COM13 + + + + + COM14 + + + + + COM15 + + + + + USB + + + + + + + + + + + + + 0 + 20 + + + + ID Interval (min): + + + + + + + true + + + + 60 + 16777215 + + + + -20 + + + 10 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + ID after 73 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 146 + 0 + + + + + 146 + 16777215 + + + + Enable PSK Reporter + + + + + + + + + Qt::Vertical + + + + 20 + 13 + + + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + Enable CAT + + + + + + + + 0 + 0 + + + + + 20 + 0 + + + + + 20 + 16777215 + + + + Rig: + + + + + + + + 0 + 0 + + + + + 200 + 0 + + + + + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + CAT port: + + + + + + + + 0 + 0 + + + + + 90 + 0 + + + + + 90 + 16777215 + + + + 0 + + + + None + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 60 + 0 + + + + + 60 + 16777215 + + + + Data bits: + + + + + + + + 0 + 0 + + + + + 50 + 0 + + + + + 50 + 16777215 + + + + 1 + + + + 7 + + + + + 8 + + + + + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + Serial rate: + + + + + + + + 0 + 0 + + + + + 90 + 0 + + + + + 90 + 16777215 + + + + 1 + + + + 1200 + + + + + 4800 + + + + + 9600 + + + + + 19200 + + + + + 38400 + + + + + 57600 + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + + 60 + 0 + + + + + 60 + 16777215 + + + + Stop bits: + + + + + + + + 0 + 0 + + + + + 50 + 0 + + + + + 50 + 16777215 + + + + 1 + + + + 1 + + + + + 2 + + + + + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + Handshake: + + + + + + + + 0 + 0 + + + + + 90 + 0 + + + + + 90 + 16777215 + + + + 2 + + + + None + + + + + XonXoff + + + + + Hardware + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + + 0 + 0 + + + + + 100 + 0 + + + + + 100 + 16777215 + + + + Test CAT Control + + + + + + + + 0 + 0 + + + + + 90 + 0 + + + + + 90 + 16777215 + + + + Test PTT + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 13 + + + + + + + + + + + 90 + 0 + + + + + 90 + 16777215 + + + + Dev Channel + + + + + + + API Name + + + Qt::AlignCenter + + + + + + + + + + + - 0 - 20 + 90 + 0 + + + + + 75 + 16777215 - ID Interval (min): + Audio In: - + true + + + + + + + + + + + 0 + 0 + + + + + 90 + 0 + + - 60 + 75 16777215 - - -20 - - - 10 + + Audio Out: - - - Qt::Horizontal + + + + + + + + + + + 0 + 0 + - + - 40 + 90 20 - - - - - ID after 73 + Save Directory: - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 146 - 0 - - - - - 146 - 16777215 - - + - Enable PSK Reporter + C:\Users\joe\wsjt\map65\save - - - - Qt::Vertical - - - - 20 - 15 - - - - - - - - - - - 0 - 0 - - - - - 100 - 0 - - - - - 100 - 16777215 - - - - Enable CAT - - - - - - - - 0 - 0 - - - - - 20 - 0 - - - - - 20 - 16777215 - - - - Rig: - - - - - - - - 0 - 0 - - - - - 200 - 0 - - - - - - - - - - - - - 0 - 0 - - - - - 100 - 0 - - - - - 100 - 16777215 - - - - CAT port: - - - - - - - - 0 - 0 - - - - - 90 - 0 - - - - - 90 - 16777215 - - - - 0 - - - - None - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 60 - 0 - - - - - 60 - 16777215 - - - - Data bits: - - - - - - - - 0 - 0 - - - - - 50 - 0 - - - - - 50 - 16777215 - - - - 1 - - - - 7 - - - - - 8 - - - - - - - - - - - - - 0 - 0 - - - - - 100 - 0 - - - - - 100 - 16777215 - - - - Serial rate: - - - - - - - - 0 - 0 - - - - - 90 - 0 - - - - - 90 - 16777215 - - - - 1 - - - - 1200 - - - - - 4800 - - - - - 9600 - - - - - 19200 - - - - - 38400 - - - - - 57600 - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - 0 - 0 - - - - - 60 - 0 - - - - - 60 - 16777215 - - - - Stop bits: - - - - - - - - 0 - 0 - - - - - 50 - 0 - - - - - 50 - 16777215 - - - - 1 - - - - 1 - - - - - 2 - - - - - - - - - - - - - 0 - 0 - - - - - 100 - 0 - - - - - 100 - 16777215 - - - - Handshake: - - - - - - - - 0 - 0 - - - - - 90 - 0 - - - - - 90 - 16777215 - - - - 2 - - - - None - - - - - XonXoff - - - - - Hardware - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - - - Qt::Vertical - - - - 20 - 15 - - - - - - - - - - - 90 - 0 - - - - - 90 - 16777215 - - - - Dev Channel - - - - - - - API Name - - - Qt::AlignCenter - - - - - - - - - - - - - - 90 - 0 - - - - - 75 - 16777215 - - - - Audio In: - - - - - - - true - - - - - - - - - - - - 0 - 0 - - - - - 90 - 0 - - - - - 75 - 16777215 - - - - Audio Out: - - - - - - - - - - - - - - - 0 - 0 - - - - - 90 - 20 - - - - Save Directory: - - - - - - - C:\Users\joe\wsjt\map65\save - - - - - - - diff --git a/lib/rig_control.c b/lib/rig_control.c index d105718e4..2fb364619 100644 --- a/lib/rig_control.c +++ b/lib/rig_control.c @@ -12,7 +12,7 @@ int set_conf(RIG *my_rig, char *conf_parms); int set_conf(RIG *my_rig, char *conf_parms) { char *p, *q, *n; - int ret; + int iret; p = conf_parms; while (p && *p != '\0') { @@ -26,38 +26,40 @@ int set_conf(RIG *my_rig, char *conf_parms) printf("%s %s\n",p,q); - ret = rig_set_conf(my_rig, rig_token_lookup(my_rig, p), q); - if (ret != RIG_OK) - return ret; + iret = rig_set_conf(my_rig, rig_token_lookup(my_rig, p), q); + if (iret != RIG_OK) + return iret; p = n; } return RIG_OK; } //------------------------------------------------------------------------ -int rigOpen(rig_model_t my_model, int verbose) +int rigOpen(int verbose, rig_model_t my_model, const char* rig_file, + int serial_rate, const char* conf_parms2) { - int retcode; /* generic return code from functions */ + int iret; /* generic return code from functions */ char *civaddr = NULL; /* NULL means no need to set conf */ - const char *rig_file; - const char *conf_parms2; - int serial_rate; + // const char *rig_file; + // const char *conf_parms2; + // int serial_rate; rig_set_debug(verbose); my_rig=rig_init(my_model); if (!my_rig) { - fprintf(stderr, "Unknown rig num %d, or initialization error.\n",my_model); - exit(2); + // fprintf(stderr, "Unknown rig num %d, or initialization error.\n",my_model); + return -1; } - rig_file="COM1"; - serial_rate=4800; - conf_parms2="data_bits=8,stop_bits=2,serial_handshake=Hardware"; - retcode=set_conf(my_rig, conf_parms2); - if (retcode!=RIG_OK) { - fprintf(stderr, "Config parameter error: %s\n", rigerror(retcode)); - exit(2); + // rig_file="COM1"; + // serial_rate=4800; + // conf_parms2="data_bits=8,stop_bits=2,serial_handshake=Hardware"; + + iret=set_conf(my_rig, conf_parms2); + if (iret!=RIG_OK) { + // fprintf(stderr, "Config parameter error: %s\n", rigerror(iret)); + return -2; } if (rig_file) @@ -69,7 +71,8 @@ int rigOpen(rig_model_t my_model, int verbose) if (civaddr) rig_set_conf(my_rig, rig_token_lookup(my_rig, "civaddr"), civaddr); - retcode = rig_open(my_rig); + iret = rig_open(my_rig); + if(iret!=0) return -3; return 0; } @@ -78,17 +81,18 @@ int rigSetFreq(int fHz) return rig_set_freq(my_rig,RIG_VFO_CURR,fHz); } -int rigFreq() +int rigFreq(int *fHz) { int iret=0; freq_t freq; iret=rig_get_freq(my_rig, RIG_VFO_CURR, &freq); - if (iret == RIG_OK ) { - printf("rig_get_freq: freq = %"PRIfreq"\n", freq); - } else { - printf("rig_get_freq: error = %s \n", rigerror(iret)); - } - return freq; + *fHz=freq; + return iret; +} + +int rigSetPTT(int iptt) +{ + return rig_set_ptt(my_rig, RIG_VFO_CURR, iptt); } void rigClose() diff --git a/mainwindow.cpp b/mainwindow.cpp index ffb972844..72aaa4b12 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -177,6 +177,7 @@ MainWindow::MainWindow(QSharedMemory *shdmem, QWidget *parent) : m_watchdogLimit=5; m_tune=false; m_repeatMsg=0; + m_bRigOpen=false; decodeBusy(false); ui->xThermo->setFillBrush(Qt::green); @@ -285,6 +286,23 @@ MainWindow::MainWindow(QSharedMemory *shdmem, QWidget *parent) : } } #endif + +//### + if(m_catEnabled) { + QString conf_parms; + conf_parms.sprintf("data_bits=%d,stop_bits=%d,serial_handshake=", + m_dataBits,m_stopBits); + conf_parms+=m_handshake; + int iret=rigOpen(0,m_rig,m_catPort.toAscii().data(),m_serialRate, + conf_parms.toAscii().data()); + if(iret!=0) { + msgBox("Failed to open connection to radio."); + return; + } + m_bRigOpen=true; + } +//### + } // End of MainWindow constructor //--------------------------------------------------- MainWindow destructor @@ -599,6 +617,7 @@ void MainWindow::on_actionDeviceSetup_triggered() //Setup Dialog dlg.m_stopBitsIndex=m_stopBitsIndex; dlg.m_handshake=m_handshake; dlg.m_handshakeIndex=m_handshakeIndex; + dlg.m_bRigOpen=m_bRigOpen; dlg.initDlg(); if(dlg.exec() == QDialog::Accepted) { @@ -627,6 +646,7 @@ void MainWindow::on_actionDeviceSetup_triggered() //Setup Dialog m_stopBitsIndex=dlg.m_stopBitsIndex; m_handshake=dlg.m_handshake; m_handshakeIndex=dlg.m_handshakeIndex; + m_bRigOpen=dlg.m_bRigOpen; #ifdef WIN32 if(dlg.m_pskReporter!=m_pskReporter) { @@ -1406,8 +1426,8 @@ void MainWindow::guiUpdate() //Raise PTT if(m_pttMethodIndex==0) { //CAT control for PTT m_cmnd=rig_command() + " T 1"; - p3.start(m_cmnd); - p3.waitForFinished(); +// p3.start(m_cmnd); +// p3.waitForFinished(); m_iptt=1; } if(m_pttMethodIndex==1 or m_pttMethodIndex==2) { //DTR or RTS @@ -1539,8 +1559,8 @@ void MainWindow::guiUpdate() //Lower PTT if(m_pttMethodIndex==0) { //CAT m_cmnd=rig_command() + " T 0"; - p3.start(m_cmnd); - p3.waitForFinished(); +// p3.start(m_cmnd); +// p3.waitForFinished(); } if(m_pttMethodIndex==1 or m_pttMethodIndex==2) { //DTR-RTS ptt(m_pttPort,0,&m_iptt,&m_COMportOpen); @@ -1598,12 +1618,20 @@ void MainWindow::guiUpdate() } m_hsym0=khsym; m_sec0=nsec; - +/* if(m_catEnabled) { m_cmnd=rig_command() + " f"; p3.start(m_cmnd); p3.waitForFinished(); } +*/ + if(m_bRigOpen) { + int fHz; + int iret=rigFreq(&fHz); + double fMHz=fHz/1000000.0; + int d=1000000.0*(fMHz-m_dialFreq); + if(abs(d)>0) dialFreqChanged2(fMHz); + } } iptt0=m_iptt; @@ -1675,8 +1703,8 @@ void MainWindow::stopTx2() //Lower PTT if(m_pttMethodIndex==0) { m_cmnd=rig_command() + " T 0"; - p3.start(m_cmnd); - p3.waitForFinished(); +// p3.start(m_cmnd); +// p3.waitForFinished(); } if(m_pttMethodIndex==1 or m_pttMethodIndex==2) { ptt(m_pttPort,0,&m_iptt,&m_COMportOpen); @@ -2407,8 +2435,9 @@ void MainWindow::on_bandComboBox_currentIndexChanged(int index) m_dialFreq=t.toDouble(); dialFreqChanged2(m_dialFreq); m_repeatMsg=0; + int nHz=int(1000000.0*m_dialFreq + 0.5); +/* if(m_catEnabled) { - int nHz=int(1000000.0*m_dialFreq + 0.5); QString cmnd1,cmnd3; cmnd1=rig_command(); cmnd3.sprintf(" F %d",nHz); @@ -2416,6 +2445,9 @@ void MainWindow::on_bandComboBox_currentIndexChanged(int index) p3.start(m_cmnd); p3.waitForFinished(); } +*/ + + if(m_bRigOpen) rigSetFreq(nHz); } void MainWindow::on_actionPrompt_to_log_QSO_triggered(bool checked) diff --git a/mainwindow.h b/mainwindow.h index 89b9b471a..f7bee54a3 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -247,6 +247,7 @@ private: bool m_runaway; bool m_tx2QSO; bool m_tune; + bool m_bRigOpen; char m_decoded[80]; @@ -341,7 +342,7 @@ extern int killbyname(const char* progName); extern void getDev(int* numDevices,char hostAPI_DeviceName[][50], int minChan[], int maxChan[], int minSpeed[], int maxSpeed[]); -extern int ptt(int nport, int itx, int* iptt); +extern int ptt(int nport, int itx, int* iptt, int* nopen); //extern int ReporterInitialize(char* hostname, char* port); @@ -365,9 +366,13 @@ void morse_(char* msg, int* icw, int* ncw, int len); //void rig_control(int nrig, int verbose); -int rigOpen(int nrig, int verbose); +int rigOpen(int vervose, int nrig, const char* rig_file, int serial_rate, + const char* conf_parms); + void rigSetFreq(int fHz); -int rigFreq(); +int rigFreq(int *fHz); +int rigSetPTT(int iptt); +void rigClose(); } diff --git a/mainwindow.ui b/mainwindow.ui index 15c351b70..8a8b0016c 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -2097,7 +2097,7 @@ answer callers - true + false Configuration