First support for LAN connection

Auto detection still not working so need to hard-code C-IV address, hope to fix this very soon!
merge-requests/1/head
Phil Taylor 2021-02-03 19:36:35 +00:00
rodzic 65f9a70ee9
commit 4bf23cea43
6 zmienionych plików z 306 dodań i 25 usunięć

Wyświetl plik

@ -74,15 +74,62 @@ rigCommander::rigCommander(unsigned char rigCivAddr, QString rigSerialPort, quin
}
rigCommander::rigCommander(unsigned char rigCivAddr, QHostAddress ip, int cport, int sport, int aport, QString username, QString password)
{
// construct
// TODO: Bring this parameter and the comm port from the UI.
// Keep in hex in the UI as is done with other CIV apps.
// civAddr = 0x94; // address of the radio. Decimal is 148.
civAddr = rigCivAddr; // address of the radio. Decimal is 148.
setCIVAddr(civAddr);
usingNativeLAN = true;
spectSeqMax = 0; // this is now set after rig ID determined
//compCivAddr = 0xE1;
//payloadPrefix = QByteArray("\xFE\xFE\x94\xE0");
payloadPrefix = QByteArray("\xFE\xFE");
payloadPrefix.append(civAddr);
payloadPrefix.append(compCivAddr);
// payloadPrefix.append("\xE0");
lookingForRig = false;
foundRig = false;
payloadSuffix = QByteArray("\xFD");
// TODO: list full contents of /dev/serial, grep for IC-7300
// /dev/serial/by-path$ ls
// total 0
// lrwxrwxrwx 1 root root 13 Nov 24 21:43 pci-0000:00:12.0-usb-0:2.1:1.0-port0 -> ../../ttyUSB0
// comm = new commHandler("/dev/ttyUSB0");
//comm = new commHandler(rigSerialPort, rigBaudRate);
udp = new udpHandler(ip, cport, sport, aport, username, password);
// data from the comm port to the program:
connect(udp, SIGNAL(haveDataFromPort(QByteArray)), this, SLOT(handleNewData(QByteArray)));
// data from the program to the comm port:
connect(this, SIGNAL(dataForComm(QByteArray)), udp, 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()
{
delete comm;
if (comm!=nullptr)
delete comm;
if (udp != nullptr)
delete udp;
}
void rigCommander::process()
{
// new thread enters here. Do nothing but do check for errors.
if(comm->serialError)
if(comm!=nullptr && comm->serialError)
{
emit haveSerialPortError(rigSerialPort, QString("Error from commhandler. Check serial port."));
}
@ -577,12 +624,12 @@ void rigCommander::parseCommand()
case '\x19':
// qDebug() << "Have rig ID: " << (unsigned int)payloadIn[2];
// printHex(payloadIn, false, true);
model = determineRadioModel(payloadIn[2]); // verify this is the model not the CIV
determineRigCaps();
qDebug() << "Have rig ID: decimal: " << (unsigned int)model;
break;
case '\x26':
if((int)payloadIn[1] == 0)
@ -880,6 +927,11 @@ void rigCommander::parseWFData()
// [1] 0x16
// [2] 0x01, 0x02, 0x03: Edge 1,2,3
break;
case 0x17:
// Hold status (only 9700?)
qDebug() << "Received 0x17 hold status - need to deal with this!";
printHex(payloadIn, false, true);
break;
case 0x19:
// scope reference level
// [1] 0x19
@ -976,7 +1028,6 @@ void rigCommander::determineRigCaps()
qDebug() << "---Rig FOUND from broadcast query:";
#endif
this->civAddr = incomingCIVAddr; // Override and use immediately.
payloadPrefix = QByteArray("\xFE\xFE");
payloadPrefix.append(civAddr);
payloadPrefix.append(compCivAddr);
@ -1056,7 +1107,7 @@ void rigCommander::parseSpectrum()
// It looks like the data length may be variable, so we need to detect it each time.
// start at payloadIn.length()-1 (to override the FD). Never mind, index -1 bad.
// chop off FD.
if(sequence == 1)
if ((sequence == 1) && (sequence < rigCaps.spectSeqMax))
{
// wave information
spectrumLine.clear();
@ -1069,6 +1120,12 @@ void rigCommander::parseSpectrum()
spectrumStartFreq -= spectrumEndFreq;
spectrumEndFreq = spectrumStartFreq + 2*(spectrumEndFreq);
}
if (payloadIn.length() > 400) // Must be a LAN packet.
{
payloadIn.chop(1);
spectrumLine.append(payloadIn.mid(5,475)); // write over the FD, last one doesn't, oh well.
emit haveSpectrumData(spectrumLine, spectrumStartFreq, spectrumEndFreq);
}
} else if ((sequence > 1) && (sequence < rigCaps.spectSeqMax))
{
// spectrum from index 05 to index 54, length is 55 per segment. Length is 56 total. Pixel data is 50 pixels.

Wyświetl plik

@ -5,6 +5,7 @@
#include <QDebug>
#include "commhandler.h"
#include "udphandler.h"
#include "rigidentities.h"
// This file figures out what to send to the comm and also
@ -21,6 +22,7 @@ class rigCommander : public QObject
public:
rigCommander(unsigned char rigCivAddr, QString rigSerialPort, quint32 rigBaudRate);
rigCommander(unsigned char rigCivAddr, QHostAddress ip, int cport, int sport, int aport, QString username, QString password);
~rigCommander();
public slots:
@ -112,8 +114,9 @@ private:
void prepDataAndSend(QByteArray data);
void debugMe();
void printHex(const QByteArray &pdata, bool printVert, bool printHoriz);
commHandler * comm=nullptr;
udpHandler* udp=nullptr;
void determineRigCaps();
commHandler * comm;
QByteArray payloadIn;
QByteArray echoPerfix;
QByteArray replyPrefix;

Wyświetl plik

@ -354,7 +354,9 @@ wfmain::wfmain(const QString serialPortCL, const QString hostCL, QWidget *parent
wfmain::~wfmain()
{
// rigThread->quit();
#ifdef Q_OS_WIN // Prevent crash on exit in Windows.
rigThread->quit();
#endif
delete ui;
}
@ -440,11 +442,15 @@ void wfmain::openRig()
}
}
// Here, the radioCIVAddr is being set from a default preference, whihc is for the 7300.
// Here, the radioCIVAddr is being set from a default preference, which is for the 7300.
// However, we will not use it initially. OTOH, if it is set explicitedly to a value in the prefs,
// then we skip auto detection.
rig = new rigCommander(prefs.radioCIVAddr, serialPortRig, prefs.serialPortBaud);
if (prefs.enableLAN)
rig = new rigCommander(prefs.radioCIVAddr, QHostAddress(prefs.ipAddress), prefs.controlLANPort, prefs.serialLANPort, prefs.audioLANPort, prefs.username, prefs.password);
else
rig = new rigCommander(prefs.radioCIVAddr, serialPortRig, prefs.serialPortBaud);
rigThread = new QThread(this);
rig->moveToThread(rigThread);
@ -541,6 +547,29 @@ void wfmain::loadSettings()
prefs.niceTS = settings.value("NiceTS", defPrefs.niceTS).toBool();
settings.endGroup();
settings.beginGroup("LAN");
prefs.enableLAN = settings.value("EnableLAN", defPrefs.enableLAN).toBool();
ui->lanEnableChk->setChecked(prefs.enableLAN);
prefs.ipAddress = settings.value("IPAddress", defPrefs.ipAddress).toString();
ui->ipAddressTxt->setEnabled(ui->lanEnableChk->isChecked());
ui->ipAddressTxt->setText(prefs.ipAddress);
prefs.controlLANPort = settings.value("ControlLANPort", defPrefs.controlLANPort).toInt();
ui->controlPortTxt->setEnabled(ui->lanEnableChk->isChecked());
ui->controlPortTxt->setText(QString("%1").arg(prefs.controlLANPort));
prefs.serialLANPort = settings.value("SerialLANPort", defPrefs.serialLANPort).toInt();
ui->serialPortTxt->setEnabled(ui->lanEnableChk->isChecked());
ui->serialPortTxt->setText(QString("%1").arg(prefs.serialLANPort));
prefs.audioLANPort = settings.value("AudioLANPort", defPrefs.audioLANPort).toInt();
ui->audioPortTxt->setEnabled(ui->lanEnableChk->isChecked());
ui->audioPortTxt->setText(QString("%1").arg(prefs.audioLANPort));
prefs.username = settings.value("Username", defPrefs.username).toString();
ui->usernameTxt->setEnabled(ui->lanEnableChk->isChecked());
ui->usernameTxt->setText(QString("%1").arg(prefs.username));
prefs.password = settings.value("Password", defPrefs.password).toString();
ui->passwordTxt->setEnabled(ui->lanEnableChk->isChecked());
ui->passwordTxt->setText(QString("%1").arg(prefs.password));
settings.endGroup();
// Memory channels
settings.beginGroup("Memory");
@ -607,6 +636,16 @@ void wfmain::saveSettings()
settings.setValue("NiceTS", prefs.niceTS);
settings.endGroup();
settings.beginGroup("LAN");
settings.setValue("EnableLAN", prefs.enableLAN);
settings.setValue("IPAddress", prefs.ipAddress);
settings.setValue("ControlLANPort", prefs.controlLANPort);
settings.setValue("SerialLANPort", prefs.serialLANPort);
settings.setValue("AudioLANPort", prefs.audioLANPort);
settings.setValue("Username", prefs.username);
settings.setValue("Password", prefs.password);
settings.endGroup();
// Memory channels
settings.beginGroup("Memory");
settings.beginWriteArray("Channel", (int)mem.getNumPresets());
@ -2064,6 +2103,45 @@ void wfmain::on_pttEnableChk_clicked(bool checked)
prefs.enablePTT = checked;
}
void wfmain::on_lanEnableChk_clicked(bool checked)
{
prefs.enableLAN = checked;
ui->ipAddressTxt->setEnabled(ui->lanEnableChk->isChecked());
ui->controlPortTxt->setEnabled(ui->lanEnableChk->isChecked());
ui->serialPortTxt->setEnabled(ui->lanEnableChk->isChecked());
ui->audioPortTxt->setEnabled(ui->lanEnableChk->isChecked());
}
void wfmain::on_ipAddressTxt_textChanged(QString text)
{
prefs.ipAddress = text;
}
void wfmain::on_controlPortTxt_textChanged(QString text)
{
prefs.controlLANPort = text.toInt();
}
void wfmain::on_serialPortTxt_textChanged(QString text)
{
prefs.serialLANPort = text.toInt();
}
void wfmain::on_audioPortTxt_textChanged(QString text)
{
prefs.audioLANPort = text.toInt();
}
void wfmain::on_usernameTxt_textChanged(QString text)
{
prefs.username = text;
}
void wfmain::on_passwordTxt_textChanged(QString text)
{
prefs.password = text;
}
// --- DEBUG FUNCTION ---
void wfmain::on_debugBtn_clicked()
{

Wyświetl plik

@ -237,6 +237,20 @@ private slots:
void on_pttEnableChk_clicked(bool checked);
void on_lanEnableChk_clicked(bool checked);
void on_ipAddressTxt_textChanged(QString text);
void on_controlPortTxt_textChanged(QString text);
void on_serialPortTxt_textChanged(QString text);
void on_audioPortTxt_textChanged(QString text);
void on_usernameTxt_textChanged(QString text);
void on_passwordTxt_textChanged(QString text);
private:
Ui::wfmain *ui;
QSettings settings;
@ -364,6 +378,13 @@ private:
quint32 serialPortBaud;
bool enablePTT;
bool niceTS;
bool enableLAN;
QString ipAddress;
quint32 controlLANPort;
quint32 serialLANPort;
quint32 audioLANPort;
QString username;
QString password;
} prefs;

124
wfmain.ui
Wyświetl plik

@ -140,7 +140,7 @@
</font>
</property>
<property name="text">
<string>00.000000</string>
<string>0000.000000</string>
</property>
</widget>
</item>
@ -1219,6 +1219,124 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QCheckBox" name="lanEnableChk">
<property name="text">
<string>Enable LAN</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<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>
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QLabel" name="label_4">
<property name="text">
<string>Radio IP Address</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="ipAddressTxt"/>
</item>
<item>
<widget class="QLabel" name="label_5">
<property name="text">
<string>Radio Control Port</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="controlPortTxt">
<property name="placeholderText">
<string>50001</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_9">
<property name="text">
<string>Radio Serial Port</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="serialPortTxt">
<property name="placeholderText">
<string>50002</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_12">
<property name="text">
<string>Radio Audio Port</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="audioPortTxt">
<property name="placeholderText">
<string>50003</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item>
<widget class="QLabel" name="label_15">
<property name="text">
<string>Username</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="usernameTxt"/>
</item>
<item>
<widget class="QLabel" name="label_14">
<property name="text">
<string>Password</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="passwordTxt">
<property name="inputMethodHints">
<set>Qt::ImhSensitiveData</set>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_13">
<property name="text">
<string>Audio Output </string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="audioOutputCombo"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="topMargin">
@ -1277,7 +1395,7 @@
<x>0</x>
<y>0</y>
<width>703</width>
<height>22</height>
<height>21</height>
</rect>
</property>
</widget>
@ -1287,8 +1405,6 @@
<customwidgets>
<customwidget>
<class>QCustomPlot</class>
<extends>QWidget</extends>
<!-- <header>qcustomplot.h</header> -->
<container>1</container>
</customwidget>
</customwidgets>

Wyświetl plik

@ -4,7 +4,7 @@
#
#-------------------------------------------------
QT += core gui serialport
QT += core gui serialport network multimedia
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets printsupport
@ -31,9 +31,14 @@ QMAKE_LFLAGS += -O2 -march=native -s
DEFINES += QT_DEPRECATED_WARNINGS
DEFINES += QCUSTOMPLOT_COMPILE_LIBRARY
DEFINES += HOST=\\\"`hostname`\\\" UNAME=\\\"`whoami`\\\"
linux:DEFINES += HOST=\\\"`hostname`\\\" UNAME=\\\"`whoami`\\\"
DEFINES += GITSHORT="\\\"$(shell git -C $$PWD rev-parse --short HEAD)\\\""
linux:DEFINES += GITSHORT="\\\"$(shell git -C $$PWD rev-parse --short HEAD)\\\""
win32:INCLUDEPATH += c:/qcustomplot
win32:DEFINES += HOST=1
win32:DEFINES += UNAME=1
win32:DEFINES += GITSHORT=1
RESOURCES += qdarkstyle/style.qrc \
@ -44,18 +49,17 @@ DISTFILES += resources/wfview.png \
resources/install.sh
DISTFILES += resources/wfview.desktop
QMAKE_POST_LINK += cp ../wfview/resources/wfview.png .;
QMAKE_POST_LINK += cp ../wfview/resources/wfview.desktop .;
QMAKE_POST_LINK += cp ../wfview/resources/install.sh .;
QMAKE_POST_LINK += cp -r ../wfview/qdarkstyle .;
QMAKE_POST_LINK += chmod 755 install.sh;
QMAKE_POST_LINK += echo; echo; echo "Run install.sh as root from the build directory to install."; echo; echo;
linux:QMAKE_POST_LINK += cp ../wfview/resources/wfview.png .;
linux:QMAKE_POST_LINK += cp ../wfview/resources/wfview.desktop .;
linux:QMAKE_POST_LINK += cp ../wfview/resources/install.sh .;
linux:QMAKE_POST_LINK += cp -r ../wfview/qdarkstyle .;
linux:QMAKE_POST_LINK += chmod 755 install.sh;
linux:QMAKE_POST_LINK += echo; echo; echo "Run install.sh as root from the build directory to install."; echo; echo;
# Do not do this, it will hang on start:
# CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
CONFIG(debug, release|debug) {
win32:QCPLIB = qcustomplotd1
else: QCPLIB = qcustomplotd
@ -74,13 +78,15 @@ SOURCES += main.cpp\
commhandler.cpp \
rigcommander.cpp \
freqmemory.cpp \
rigidentities.cpp
rigidentities.cpp \
udphandler.cpp
HEADERS += wfmain.h \
commhandler.h \
rigcommander.h \
freqmemory.h \
rigidentities.h
rigidentities.h \
udphandler.h
FORMS += wfmain.ui