Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions src/mainwindow.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <QMessageBox>
#include <QScreen>
#include <QApplication>
#include <QtConcurrent/QtConcurrentRun>
#include "filewatcher.h"
#include "ftpfunctions.h"

Expand All @@ -59,6 +60,9 @@
mainWindow::mainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{
inStartup=true;
exitingApp=false;
rigPollInProgress=false;
rigFreqWatcher=nullptr;
QApplication::instance()->thread()->setObjectName("qsstv_main");
wfTextPushButton=new QPushButton("WF Text",this);
bsrPushButton=new QPushButton("BSR",this);
Expand Down Expand Up @@ -103,6 +107,8 @@ mainWindow::mainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainW
ui->statusBar->addPermanentWidget(pttIcon);
statusBarPtr=statusBar(); // must be after setup UI
spectrumFramePtr=ui->spectrumFrame;
rigFreqWatcher=new QFutureWatcher<double>(this);
connect(rigFreqWatcher,SIGNAL(finished()),this,SLOT(slotRigFrequencyPollFinished()));


// setting up pointers
Expand Down Expand Up @@ -355,6 +361,7 @@ void mainWindow::slotExit()

if(exit==QMessageBox::Ok)
{
exitingApp=true;
statusBarPtr->showMessage("Cleaning up...");
dispatcherPtr->idleAll();
rxWidgetPtr->setOnlineStatus(false);
Expand Down Expand Up @@ -515,11 +522,26 @@ void mainWindow::slotSetFrequency(int freqIndex)

void mainWindow::timerEvent(QTimerEvent *)
{
double fr;
if(rigControllerPtr->getFrequency(fr))
if(exitingApp) return;
if(rigPollInProgress) return;

rigPollInProgress=true;
rigFreqWatcher->setFuture(QtConcurrent::run([this]() -> double {
double fr=0;
if(rigControllerPtr->getFrequency(fr)) return fr;
return -1;
}));
}

void mainWindow::slotRigFrequencyPollFinished()
{
rigPollInProgress=false;
if(exitingApp) return;

const double fr=rigFreqWatcher->result();
if(fr>1000000.)
{
fr/=1000000.;
if(fr>1) freqDisplay->setText(QString::number(fr,'f',6));
freqDisplay->setText(QString::number(fr/1000000.,'f',6));
}
else
{
Expand Down
5 changes: 5 additions & 0 deletions src/mainwindow.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <QComboBox>
#include <QPushButton>
#include <QLabel>
#include <QFutureWatcher>

class configDialog;
class spectrumWidget;
Expand Down Expand Up @@ -45,6 +46,7 @@ private slots:
void slotSendBSR();
void slotSendWfText();
void slotSetFrequency(int freqIndex);
void slotRigFrequencyPollFinished();



Expand Down Expand Up @@ -79,6 +81,9 @@ private slots:
void timerEvent(QTimerEvent *);
QStringList modModeList;
QStringList modPassBandList;
bool exitingApp;
bool rigPollInProgress;
QFutureWatcher<double> *rigFreqWatcher;
};

#endif // MAINWINDOW_H
2 changes: 1 addition & 1 deletion src/qsstv.pro
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets network xml
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets network xml concurrent

CONFIG += c++11

Expand Down
33 changes: 23 additions & 10 deletions src/rig/rigcontrol.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QSplashScreen>
#include <QMessageBox>
#include <QApplication>
#include <QMutexLocker>
#include <sys/ioctl.h>
#include <unistd.h>
#include <fcntl.h>
Expand Down Expand Up @@ -61,11 +62,13 @@ rigControl::rigControl(int radioIndex)
getRadioList();
serialP=0;
lastFrequency=0.0;
getFreqErrorCount=0;
xmlModes<<"USB"<<"LSB"<<"FM"<<"AM";
}

rigControl::~rigControl()
{
QMutexLocker locker(&rigAccessMutex);
rig_close(my_rig); /* close port */
rig_cleanup(my_rig); /* if you care about memory */
}
Expand Down Expand Up @@ -145,23 +148,27 @@ bool rigControl::getFrequency(double &frequency)
if(catParams.enableXMLRPC)
{
frequency=xmlIntfPtr->getFrequency();
lastFrequency=frequency;
getFreqErrorCount=0;
return true;
}

if(!rigControlEnabled || !canGetFreq) return false;
QMutexLocker locker(&rigAccessMutex);
retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &frequency);
for(int i=0;i<RIGCMDTRIES;i++)
if (retcode==RIG_OK)
{
qDebug() << "getFreq";
retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &frequency);
qDebug() << "got Freq";
if (retcode==RIG_OK)
{
return true;
}
lastFrequency=frequency;
getFreqErrorCount=0;
return true;
}

getFreqErrorCount++;
if(getFreqErrorCount>=RIGCMDTRIES)
{
// Stop polling after repeated failures to avoid blocking the UI thread.
canGetFreq=false;
}
// errorMessage(retcode,"getFrequency");
canGetFreq=false; // too many errors;
frequency=lastFrequency;
return false;

Expand All @@ -176,6 +183,7 @@ bool rigControl::setFrequency(double frequency)
return true;
}
if(!rigControlEnabled || !canSetFreq) return false;
QMutexLocker locker(&rigAccessMutex);
// retcode = rig_set_vfo(my_rig, RIG_VFO_CURR);
// if (retcode != RIG_OK ) {errorMessage(retcode,"setVFO"); return false; }

Expand All @@ -194,6 +202,7 @@ bool rigControl::setFrequency(double frequency)

void rigControl::disable()
{
QMutexLocker locker(&rigAccessMutex);
if(rigControlEnabled)
{
rig_close(my_rig); /* close port */
Expand All @@ -214,6 +223,7 @@ bool rigControl::getMode(QString &mode)
pbwidth_t width;
int retcode;
if(!rigControlEnabled || !canGetMode) return false;
QMutexLocker locker(&rigAccessMutex);

for(int i=0;i<RIGCMDTRIES;i++)
{
Expand Down Expand Up @@ -268,6 +278,7 @@ bool rigControl::setMode(QString mode,QString passBand)
}
int retcode;
if(!rigControlEnabled || !canSetMode) return false;
QMutexLocker locker(&rigAccessMutex);

for(int i=0;i<RIGCMDTRIES;i++)
{
Expand All @@ -291,6 +302,7 @@ bool rigControl::setPTT(bool on)
/* Hamlib will fall back to RIG_PTT_ON if RIG_PTT_ON_DATA is not available in current hamlib configuration */
if(on) ptt=RIG_PTT_ON_DATA; else ptt=RIG_PTT_OFF;
if(!rigControlEnabled || !canSetPTT) return false;
QMutexLocker locker(&rigAccessMutex);

for(int i=0;i<RIGCMDTRIES;i++)
{
Expand Down Expand Up @@ -458,6 +470,7 @@ int rigControl::rawCommand(QByteArray ba)
QString command="w ";
QByteArray cmdBa;
if(!rigControlEnabled) return 0;
QMutexLocker locker(&rigAccessMutex);
struct rig_state *rs;
rs = &my_rig->state;
// check if backend via rigctld
Expand Down
3 changes: 3 additions & 0 deletions src/rig/rigcontrol.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <QObject>
#include <QComboBox>
#include <QMutex>

extern "C" int write_block(hamlib_port_t *p, const char *txbuffer, size_t count);
extern "C" int read_block(hamlib_port_t *p, char *rxbuffer, size_t count);
Expand Down Expand Up @@ -88,6 +89,8 @@ class rigControl: public QObject
bool canGetMode;
bool canSetPTT;
bool canGetPTT;
int getFreqErrorCount;
QMutex rigAccessMutex;
};


Expand Down