Numerious modifications

merge-requests/1/merge
Elliott Liggett 2018-11-07 15:54:03 -08:00
rodzic 3f7edad074
commit 208e2017eb
9 zmienionych plików z 299 dodań i 32 usunięć

Wyświetl plik

@ -93,9 +93,9 @@ void commHandler::receiveDataIn()
rolledBack = true;
}
} else {
port->commitTransaction();
qDebug() << "Warning: received data with invalid start. Dropping data.";
qDebug() << "THIS SHOULD ONLY HAPPEN ONCE!!";
port->commitTransaction(); // do not emit data, do not keep data.
//qDebug() << "Warning: received data with invalid start. Dropping data.";
//qDebug() << "THIS SHOULD ONLY HAPPEN ONCE!!";
// THIS SHOULD ONLY HAPPEN ONCE!
// unrecoverable. We did not receive the start and must
@ -115,11 +115,11 @@ void commHandler::openPort()
if(success)
{
isConnected = true;
qDebug() << "Opened port!";
//qDebug() << "Opened port!";
return;
} else {
// debug?
qDebug() << "Could not open serial port.";
//qDebug() << "Could not open serial port.";
isConnected = false;
return;
}
@ -135,6 +135,7 @@ void commHandler::closePort()
void commHandler::debugThis()
{
// Do not use, function is for debug only and subject to change.
qDebug() << "comm debug called.";
inPortData = port->readAll();

6
freqmemory.cpp 100644
Wyświetl plik

@ -0,0 +1,6 @@
#include "freqmemory.h"
freqMemory::freqMemory()
{
}

48
freqmemory.h 100644
Wyświetl plik

@ -0,0 +1,48 @@
#ifndef FREQMEMORY_H
#define FREQMEMORY_H
#include <QString>
#include <QDebug>
// 0 1 2 3 4
//modes << "LSB" << "USB" << "AM" << "CW" << "RTTY";
// 5 6 7 8 9
// modes << "FM" << "CW-R" << "RTTY-R" << "LSB-D" << "USB-D";
enum mode_kind {
modeLSB=0,
modeUSB,
modeAM,
modeCW,
modeRTTY,
modeFM,
modeCW_R,
modeRTTY_R,
modeLSB_D,
modeUSB_D
};
struct preset_kind {
QString name;
QString comment;
unsigned int index; // channel number
double frequency;
mode_kind mode;
bool isSet;
};
class freqMemory
{
public:
freqMemory();
void setPreset(unsigned int index, double frequency, mode_kind mode);
void setPreset(unsigned int index, double frequency, mode_kind mode, QString name);
void setPreset(unsigned int index, double frequency, mode_kind mode, QString name, QString comment);
preset_kind getPreset(unsigned int index);
private:
void initializePresets();
unsigned int maxIndex;
};
#endif // FREQMEMORY_H

Wyświetl plik

@ -9,7 +9,7 @@
// The IC-7300 "full" manual also contains a command reference.
// How to make spectrum display stop using rigctl:
// echo "w \0xFE\0xFE\0x094\0xE0\0x27\0x11\0x00\0xFD" | rigctl -m 373 -r /dev/ttyUSB0 -s 115200 -vvvvv
// echo "w \0xFE\0xFE\0x94\0xE0\0x27\0x11\0x00\0xFD" | rigctl -m 373 -r /dev/ttyUSB0 -s 115200 -vvvvv
// Note: When sending \x00, must use QByteArray.setRawData()
@ -17,7 +17,9 @@
rigCommander::rigCommander()
{
// construct
// TODO: Bring this parameter and the comm port from the UI.
civAddr = 0x94; // address of the radio. Decimal is 148.
setCIVAddr(civAddr);
//payloadPrefix = QByteArray("\xFE\xFE\x94\xE0");
payloadPrefix = QByteArray("\xFE\xFE");
@ -34,6 +36,7 @@ rigCommander::rigCommander()
connect(this, SIGNAL(dataForComm(QByteArray)), comm, SLOT(receiveDataFromUserToRig(QByteArray)));
connect(this, SIGNAL(getMoreDebug()), comm, SLOT(debugThis()));
pttAllowed = true; // This is for developing, set to false for "safe" debugging. Set to true for deployment.
}
rigCommander::~rigCommander()
@ -205,13 +208,37 @@ void rigCommander::setMode(char mode)
QByteArray payload;
if((mode >=0) && (mode < 10))
{
// annoying hack as mode 6 is undefined.
if(mode > 5)
{
mode++;
}
// valid
payload.setRawData("\x06", 1); // cmd 06 will apply the default filter, no need to specify.
payload.setRawData("\x06", 1); // cmd 06 needs filter specified
//payload.setRawData("\x04", 1); // cmd 04 will apply the default filter, but it seems to always pick FIL 02
payload.append(mode);
payload.append("\x03"); // wide band
prepDataAndSend(payload);
}
}
void rigCommander::setDataMode(bool dataOn)
{
QByteArray payload;
payload.setRawData("\x1A\x06", 2);
if(dataOn)
{
payload.append("\x01\x03", 2); // data mode on, wide bandwidth
} else {
payload.append("\x00\x00", 2); // data mode off, bandwidth not defined per ICD.
}
prepDataAndSend(payload);
}
void rigCommander::getFrequency()
{
// figure out frequency and then respond with haveFrequency();
@ -233,6 +260,25 @@ void rigCommander::getDataMode()
prepDataAndSend(payload);
}
void rigCommander::getPTT()
{
QByteArray payload("\x1C\x00", 2);
prepDataAndSend(payload);
}
void rigCommander::setPTT(bool pttOn)
{
//bool pttAllowed = false;
if(pttAllowed)
{
QByteArray payload("\x1C\x00", 2);
payload.append((char)pttOn);
prepDataAndSend(payload);
}
}
void rigCommander::setCIVAddr(unsigned char civAddr)
{
this->civAddr = civAddr;
@ -402,6 +448,9 @@ void rigCommander::parseCommand()
} else {
parseRegisters1A();
}
case '\x1C':
parseRegisters1C();
break;
case '\xFB':
// Fine Business, ACK from rig.
break;
@ -410,6 +459,7 @@ void rigCommander::parseCommand()
qDebug() << "Error (FA) received from rig.";
printHex(payloadIn, false ,true);
break;
default:
qDebug() << "Have other data with cmd: " << std::hex << payloadIn[00];
printHex(payloadIn, false, true);
@ -419,6 +469,34 @@ void rigCommander::parseCommand()
}
void rigCommander::parseRegisters1C()
{
// PTT lives here
switch(payloadIn[02])
{
case '\x00':
parsePTT();
break;
default:
break;
}
}
void rigCommander::parsePTT()
{
// read after payloadIn[02]
if(payloadIn[03] == (char)0)
{
// PTT off
emit havePTTStatus(false);
} else {
// PTT on
emit havePTTStatus(true);
}
}
void rigCommander::parseRegisters1A()
{
// The simpler of the 1A stuff:

Wyświetl plik

@ -31,6 +31,9 @@ public slots:
void setMode(char mode);
void getFrequency();
void getMode();
void getPTT();
void setPTT(bool pttOn);
void setDataMode(bool dataOn);
void getDataMode();
void setCIVAddr(unsigned char civAddr);
void handleNewData(const QByteArray &data);
@ -45,6 +48,7 @@ signals:
void dataForComm(const QByteArray &outData);
void getMoreDebug();
void finished();
void havePTTStatus(bool pttOn);
private:
@ -59,6 +63,8 @@ private:
void parseSpectrum();
void parseDetailedRegisters1A05();
void parseRegisters1A();
void parseRegisters1C();
void parsePTT();
void sendDataOut();
void prepDataAndSend(QByteArray data);
void debugMe();
@ -81,6 +87,7 @@ private:
double frequencyMhz;
unsigned char civAddr; // 0x94 is default = 148decimal
bool pttAllowed;

Wyświetl plik

@ -14,11 +14,11 @@ wfmain::wfmain(QWidget *parent) :
tracer = new QCPItemTracer(plot);
//tracer->setGraphKey(5.5);
tracer->setInterpolating(true);
tracer->setStyle(QCPItemTracer::tsPlus);
tracer->setStyle(QCPItemTracer::tsCrosshair);
tracer->setPen(QPen(Qt::green));
tracer->setBrush(Qt::green);
tracer->setSize(20);
tracer->setSize(30);
spectWidth = 475; // fixed for now
wfLength = 160; // fixed for now
@ -32,7 +32,6 @@ wfmain::wfmain(QWidget *parent) :
wfimage.append(empty);
}
// TODO: FM is missing, should be where CW is, all other modes get +1?
// 0 1 2 3 4
modes << "LSB" << "USB" << "AM" << "CW" << "RTTY";
// 5 6 7 8 9
@ -47,6 +46,7 @@ wfmain::wfmain(QWidget *parent) :
ui->scopeEdgeCombo->insertItems(0,edges);
ui->splitter->setHandleWidth(5);
ui->statusBar->showMessage("Ready", 2000);
// comm = new commHandler();
rig = new rigCommander();
@ -62,6 +62,9 @@ wfmain::wfmain(QWidget *parent) :
connect(this, SIGNAL(getFrequency()), rig, SLOT(getFrequency()));
connect(this, SIGNAL(getMode()), rig, SLOT(getMode()));
connect(this, SIGNAL(getDataMode()), rig, SLOT(getDataMode()));
connect(this, SIGNAL(setDataMode(bool)), rig, SLOT(setDataMode(bool)));
connect(rig, SIGNAL(havePTTStatus(bool)), this, SLOT(receivePTTstatus(bool)));
connect(this, SIGNAL(getDebug()), rig, SLOT(getDebug()));
connect(this, SIGNAL(spectOutputDisable()), rig, SLOT(disableSpectOutput()));
connect(this, SIGNAL(spectOutputEnable()), rig, SLOT(enableSpectOutput()));
@ -79,7 +82,8 @@ wfmain::wfmain(QWidget *parent) :
// Plot user interaction
connect(plot, SIGNAL(mouseDoubleClick(QMouseEvent*)), this, SLOT(handlePlotDoubleClick(QMouseEvent*)));
connect(wf, SIGNAL(mouseDoubleClick(QMouseEvent*)), this, SLOT(handleWFDoubleClick(QMouseEvent*)));
connect(plot, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(handlePlotClick(QMouseEvent*)));
connect(wf, SIGNAL(mousePress(QMouseEvent*)), this, SLOT(handleWFClick(QMouseEvent*)));
ui->plot->addGraph(); // primary
ui->plot->addGraph(0, 0); // secondary, peaks, same axis as first?
@ -114,7 +118,7 @@ wfmain::wfmain(QWidget *parent) :
ui->freqMhzLineEdit->setValidator( new QDoubleValidator(0, 100, 6, this));
delayedCommand = new QTimer(this);
delayedCommand->setInterval(250);
delayedCommand->setInterval(100); // ms. 250 was fine.
delayedCommand->setSingleShot(true);
connect(delayedCommand, SIGNAL(timeout()), this, SLOT(runDelayedCommand()));
@ -151,6 +155,10 @@ void wfmain::getInitialRigState()
delayedCommand->start();
}
void wfmain::showStatusBarText(QString text)
{
ui->statusBar->showMessage(text, 5000);
}
void wfmain::on_useDarkThemeChk_clicked(bool checked)
{
@ -267,6 +275,12 @@ void wfmain::runDelayedCommand()
case cmdGetDataMode:
emit getDataMode();
break;
case cmdSetDataModeOff:
emit setDataMode(false);
break;
case cmdSetDataModeOn:
emit setDataMode(true);
break;
default:
break;
}
@ -287,6 +301,12 @@ void wfmain::receiveFreq(double freqMhz)
ui->freqLabel->setText(QString("%1").arg(freqMhz, 0, 'f'));
this->freqMhz = freqMhz;
this->knobFreqMhz = freqMhz;
showStatusBarText(QString("Frequency: %1").arg(freqMhz));
}
void wfmain::receivePTTstatus(bool pttOn)
{
qDebug() << "PTT status: " << pttOn;
}
void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double endFreq)
@ -388,15 +408,15 @@ void wfmain::receiveSpectrumData(QByteArray spectrum, double startFreq, double e
void wfmain::handlePlotDoubleClick(QMouseEvent *me)
{
double x;
double y;
//double y;
//double px;
x = plot->xAxis->pixelToCoord(me->pos().x());
y = plot->yAxis->pixelToCoord(me->pos().y());
//y = plot->yAxis->pixelToCoord(me->pos().y());
emit setFrequency(x);
cmdOut = cmdGetFreq;
delayedCommand->start();
showStatusBarText(QString("Going to %1 MHz").arg(x));
qDebug() << "PLOT double click: " << x << ", " << y;
}
void wfmain::handleWFDoubleClick(QMouseEvent *me)
@ -410,19 +430,20 @@ void wfmain::handleWFDoubleClick(QMouseEvent *me)
emit setFrequency(x);
cmdOut = cmdGetFreq;
delayedCommand->start();
//qDebug() << "WF double click: " << x << ", " << y;
showStatusBarText(QString("Going to %1 MHz").arg(x));
}
void wfmain::handlePlotClick(QMouseEvent *me)
{
double x = plot->xAxis->pixelToCoord(me->pos().x());
showStatusBarText(QString("Selected %1 MHz").arg(x));
}
void wfmain::handleWFClick(QMouseEvent *me)
{
double x = plot->xAxis->pixelToCoord(me->pos().x());
showStatusBarText(QString("Selected %1 MHz").arg(x));
}
@ -639,18 +660,32 @@ void wfmain::on_modeSelectCombo_currentIndexChanged(int index)
void wfmain::on_modeSelectCombo_activated(int index)
{
// Reference:
// 0 1 2 3 4
//modes << "LSB" << "USB" << "AM" << "CW" << "RTTY";
// 5 6 7 8 9
//modes << "FM" << "CW-R" << "RTTY-R" << "LSB-D" << "USB-D";
// the user initiated a mode change.
if(index < 10)
{
qDebug() << "Mode selection changed. index: " << index;
emit setMode(index);
// qDebug() << "Mode selection changed. index: " << index;
if(index > 7)
{
// set data mode on
// emit setDataMode(true);
cmdOutQue.append(cmdSetDataModeOn);
delayedCommand->start();
index = index - 8;
} else {
// set data mode off
//emit setDataMode(false);
cmdOutQue.append(cmdSetDataModeOff);
delayedCommand->start();
}
emit setMode(index);
}
}
@ -658,12 +693,13 @@ void wfmain::on_modeSelectCombo_activated(int index)
void wfmain::on_freqDial_actionTriggered(int action)
{
//qDebug() << "Action: " << action; // "7" == changed?
// TODO: remove this
}
void wfmain::on_freqDial_valueChanged(int value)
{
// qDebug() << "Old value: " << oldFreqDialVal << " New value: " << value ;
double stepSize = 0.001000; // 1kHz steps
double stepSize = 0.000100; // 100 Hz steps
double newFreqMhz = 0;
volatile int delta = 0;
int maxVal = ui->freqDial->maximum();

Wyświetl plik

@ -30,7 +30,10 @@ signals:
void setFrequency(double freq);
void getMode();
void setMode(char modeIndex);
void setDataMode(bool dataOn);
void getDataMode();
void getPTT();
void setPTT(bool pttOn);
void getDebug();
void spectOutputEnable();
void spectOutputDisable();
@ -45,11 +48,13 @@ private slots:
void receiveFreq(double);
void receiveMode(QString);
void receiveSpectrumData(QByteArray spectrum, double startFreq, double endFreq);
void receivePTTstatus(bool pttOn);
void handlePlotClick(QMouseEvent *);
void handlePlotDoubleClick(QMouseEvent *);
void handleWFClick(QMouseEvent *);
void handleWFDoubleClick(QMouseEvent *);
void runDelayedCommand();
void showStatusBarText(QString text);
void on_getFreqBtn_clicked();
@ -146,7 +151,7 @@ private:
double oldUpperFreq;
double freqMhz;
double knobFreqMhz;
enum cmds {cmdNone, cmdGetFreq, cmdGetMode, cmdGetDataMode};
enum cmds {cmdNone, cmdGetFreq, cmdGetMode, cmdGetDataMode, cmdSetDataModeOn, cmdSetDataModeOff};
cmds cmdOut;
QVector <cmds> cmdOutQue;
int oldFreqDialVal;

Wyświetl plik

@ -100,6 +100,12 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>175</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>145</width>
@ -247,11 +253,27 @@
</item>
<item>
<widget class="QPushButton" name="debugBtn">
<property name="toolTip">
<string>Don't press this button!</string>
</property>
<property name="text">
<string>Debug</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_6">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
@ -1015,6 +1037,68 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_14">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="tuningFloorZerosChk">
<property name="text">
<string>When tuning, set lower digits to zero</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="pttEnableChk">
<property name="text">
<string>Enable PTT</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="enableXmlRpcChk">
<property name="text">
<string>Enable XML RPC server</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_15">
<property name="topMargin">
<number>9</number>
</property>
<item>
<widget class="QPushButton" name="pttOnBtn">
<property name="text">
<string>PTT On</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pttOffBtn">
<property name="text">
<string>PTT Off</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_5">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">

Wyświetl plik

@ -23,13 +23,13 @@ DEFINES += QCUSTOMPLOT_COMPILE_LIBRARY
RESOURCES += qdarkstyle/style.qrc
#CONFIG(debug, release|debug) {
# win32:QCPLIB = qcustomplotd1
# else: QCPLIB = qcustomplotd
#} else {
# win32:QCPLIB = qcustomplot1
# else: QCPLIB = qcustomplot
#}
CONFIG(debug, release|debug) {
win32:QCPLIB = qcustomplotd1
else: QCPLIB = qcustomplotd
} else {
win32:QCPLIB = qcustomplot1
else: QCPLIB = qcustomplot
}
QCPLIB = qcustomplot
@ -39,11 +39,13 @@ LIBS += -L./ -l$$QCPLIB
SOURCES += main.cpp\
wfmain.cpp \
commhandler.cpp \
rigcommander.cpp
rigcommander.cpp \
freqmemory.cpp
HEADERS += wfmain.h \
../../../../../usr/include/qcustomplot.h \
commhandler.h \
rigcommander.h
rigcommander.h \
freqmemory.h
FORMS += wfmain.ui