From 0cee949dcf9050e8c12c2f4df9998432c17b6042 Mon Sep 17 00:00:00 2001 From: Elliott Liggett Date: Thu, 29 Nov 2018 13:41:42 -0800 Subject: [PATCH] Added automatic IC-7300 serial port search --- commhandler.cpp | 2 +- rigcommander.cpp | 8 +++++--- rigcommander.h | 2 +- wfmain.cpp | 33 +++++++++++++++++++++++++++++---- wfmain.h | 1 + 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/commhandler.cpp b/commhandler.cpp index c681a41..8f89e79 100644 --- a/commhandler.cpp +++ b/commhandler.cpp @@ -46,7 +46,7 @@ commHandler::commHandler(QString portName) setupComm(); // basic parameters openPort(); - qDebug() << "Serial buffer size: " << port->readBufferSize(); + // qDebug() << "Serial buffer size: " << port->readBufferSize(); //port->setReadBufferSize(1024); // manually. 256 never saw any return from the radio. why... //qDebug() << "Serial buffer size: " << port->readBufferSize(); diff --git a/rigcommander.cpp b/rigcommander.cpp index f983f75..04f1197 100644 --- a/rigcommander.cpp +++ b/rigcommander.cpp @@ -27,13 +27,14 @@ // Note: When sending \x00, must use QByteArray.setRawData() -rigCommander::rigCommander() +rigCommander::rigCommander(unsigned char rigCivAddr, QString rigSerialPort) { // 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 = 0x94; // address of the radio. Decimal is 148. + civAddr = rigCivAddr; // address of the radio. Decimal is 148. setCIVAddr(civAddr); //compCivAddr = 0xE1; @@ -50,7 +51,8 @@ rigCommander::rigCommander() // 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("/dev/ttyUSB0"); + comm = new commHandler(rigSerialPort); // data from the comm port to the program: connect(comm, SIGNAL(haveDataFromPort(QByteArray)), this, SLOT(handleNewData(QByteArray))); diff --git a/rigcommander.h b/rigcommander.h index c4332e7..431b321 100644 --- a/rigcommander.h +++ b/rigcommander.h @@ -19,7 +19,7 @@ class rigCommander : public QObject Q_OBJECT public: - rigCommander(); + rigCommander(unsigned char rigCivAddr, QString rigSerialPort); ~rigCommander(); public slots: diff --git a/wfmain.cpp b/wfmain.cpp index 6b722d2..cc19967 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -36,9 +36,34 @@ wfmain::wfmain(QWidget *parent) : connect(keyStar, SIGNAL(activated()), this, SLOT(shortcutStar())); - setDefaultColors(); // set of UI colors with defaults populated - loadSettings(); // Look for default settings + setDefaultColors(); // other default options + loadSettings(); // Look for saved preferences + + prefs.serialPortRadio = QString("auto"); + // if setting for serial port is "auto" then... + if(prefs.serialPortRadio == QString("auto")) + { + // Find the ICOM IC-7300. + qDebug() << "Searching for serial port..."; + QDirIterator it("/dev/serial", QStringList() << "*IC-7300*", QDir::Files, QDirIterator::Subdirectories); + + while (it.hasNext()) + qDebug() << it.next(); + // if (it.isEmpty()) // fail or default to ttyUSB0 if present + // iterator might not make sense + serialPortRig = it.filePath(); // first? last? + if(serialPortRig.isEmpty()) + { + qDebug() << "Cannot find valid serial port. Trying /dev/ttyUSB0"; + serialPortRig = QString("/dev/ttyUSB0"); + } + // end finding the 7300 code + } else { + serialPortRig = prefs.serialPortRadio; + } + + plot = ui->plot; // rename it waterfall. wf = ui->waterfall; tracer = new QCPItemTracer(plot); @@ -80,7 +105,7 @@ wfmain::wfmain(QWidget *parent) : ui->statusBar->showMessage("Ready", 2000); // comm = new commHandler(); - rig = new rigCommander(); + rig = new rigCommander(prefs.radioCIVAddr, serialPortRig ); rigThread = new QThread(this); rig->moveToThread(rigThread); @@ -201,7 +226,7 @@ void wfmain::setDefPrefs() defPrefs.useDarkMode = true; defPrefs.drawPeaks = true; defPrefs.radioCIVAddr = 0x94; - defPrefs.serialPortRadio = QString("/dev/ttyUSB0"); + defPrefs.serialPortRadio = QString("auto"); defPrefs.enablePTT = false; defPrefs.niceTS = true; diff --git a/wfmain.h b/wfmain.h index 8bc8702..8e9a193 100644 --- a/wfmain.h +++ b/wfmain.h @@ -201,6 +201,7 @@ private: void getInitialRigState(); QWidget * theParent; QStringList portList; + QString serialPortRig; QShortcut *keyF11; QShortcut *keyF1;