From 3019ac0f9b3c05b3b5a877fb026b1025a34172d5 Mon Sep 17 00:00:00 2001 From: jaime <29511627+ea4k@users.noreply.github.com> Date: Sun, 14 Apr 2019 18:44:21 +0000 Subject: [PATCH] Working in hamlib --- Changelog | 3 + KLog.pro | 6 +- TODO | 4 + hamlibclass.cpp | 341 ++++++++++++++++++++++++++++++++++++++++++++ hamlibclass.h | 71 +++++++++ mainwindow.cpp | 84 +++++++---- mainwindow.h | 47 +----- setupdialog.cpp | 17 ++- setuppagehamlib.cpp | 92 ++++++++++-- setuppagehamlib.h | 21 ++- 10 files changed, 590 insertions(+), 96 deletions(-) create mode 100644 hamlibclass.cpp create mode 100644 hamlibclass.h diff --git a/Changelog b/Changelog index 2d9f3fba..df0de0eb 100644 --- a/Changelog +++ b/Changelog @@ -1,3 +1,6 @@ +TBD - 0.9.8 +- Working: Hamlib support! + TBD - 0.9.7.3 - TODO: Remove the band 0 / Light from the DB. - UI: KLog warns the user if the frequency used is out of the hamradio bands. diff --git a/KLog.pro b/KLog.pro index cf527d87..9fc3cadf 100644 --- a/KLog.pro +++ b/KLog.pro @@ -102,7 +102,8 @@ HEADERS += setupdialog.h \ charts/statsqsosperbandbarchartwidget.h \ setuppagesats.h \ setuppagesatsnew.h \ - setuppagehamlib.h + setuppagehamlib.h \ + hamlibclass.h SOURCES += main.cpp \ @@ -168,7 +169,8 @@ SOURCES += main.cpp \ charts/statsqsosperbandbarchartwidget.cpp \ setuppagesats.cpp \ setuppagesatsnew.cpp \ - setuppagehamlib.cpp + setuppagehamlib.cpp \ + hamlibclass.cpp OTHER_FILES += \ diff --git a/TODO b/TODO index 84385abe..3c949eea 100644 --- a/TODO +++ b/TODO @@ -1,7 +1,11 @@ RC-BUGS: + TODO: Check if dxccStatusWidget in logwindow is useful and remove it if not. NONE +TBD - 0.9.8 +Hamlib: COMports in Windows must follow the format: \\.\com14 for ports highet than 9 but it works also for lower so ALL should be managed that way. + For next release: TODO: - Some warnings removed from compilation time. TODO: - The log can be now updated with a LoTW ADIF file import. diff --git a/hamlibclass.cpp b/hamlibclass.cpp new file mode 100644 index 00000000..18116b4a --- /dev/null +++ b/hamlibclass.cpp @@ -0,0 +1,341 @@ +#include "hamlibclass.h" + + +HamLibClass::HamLibClass(QObject *parent) : QObject(parent) +{ + timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), this, SLOT(slotTimer()) ); + //timer->start(1000); + clean(); +} + +void HamLibClass::slotTimer() +{ + //freq_old = freq; + int retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &freq); + if (retcode == RIG_OK) + { + if (freq_old != freq) + { + emit freqChanged(freq/1000000); + freq_old = freq; + qDebug() << "HamLibClass::slotTimer EMITING; " << QString::number(freq) << endl; + } + //qDebug() << "HamLibClass::slotTimer read: " << QString::number(freq) << endl; + + } + else + { + qDebug() << "HamLibClass::slotTimer Unable to read FREQ" << endl; + } + +} + +bool HamLibClass::stop() +{ + qDebug() << "HamLibClass::stop" << endl; + int errorCode = rig_close(my_rig); + qDebug() << "HamLibClass::stop-1" << endl; + timer->stop(); + + if (errorCode == RIG_OK) + { + qDebug() << "HamLibClass::stop: rig_close OK" << endl; + errorCode = rig_cleanup(my_rig); + if (errorCode == RIG_OK) + { + qDebug() << "HamLibClass::stop: rig_cleanUp OK" << endl; + rigLaunched = false; + qDebug() << "HamLibClass::stop - true" << endl; + return true; + } + else + { + qDebug() << "HamLibClass::stop: rig_cleanup NOK: " << QString::number(errorCode) << endl; + } + } + else + { + qDebug() << "HamLibClass::stop: rig_close NOK: " << QString::number(errorCode) << endl; + } + qDebug() << "HamLibClass::stop - false" << endl; + return false; +} + +void HamLibClass::clean() +{ + myrig_model = 1; //Dummy equipment + rigLaunched = false; + parity = QSerialPort::NoParity; + flowControl = QSerialPort::NoFlowControl; + dataBits = QSerialPort::Data8; + stopBits = QSerialPort::OneStop; + bauds = QSerialPort::Baud9600; +} + +HamLibClass::~HamLibClass() +{ + if (rigLaunched) + { + rig_close(my_rig); + rig_cleanup(my_rig); + rigLaunched = false; + } +} +bool HamLibClass::isRunning() +{ + return rigLaunched; +} + +QStringList HamLibClass::getRigList () +{ + qDebug() << "HamLibClass::getRigList" << endl; + // Rutine to fill the rig combo boxes + // Do not display debug codes when load the rig's + rig_set_debug (RIG_DEBUG_NONE); + + // and continue... + + strings.clear(); + rig_load_all_backends (); + rig_list_foreach (addRigToList, this); + + strings.sort (); + return strings; + } + +int HamLibClass::addRigToList (const struct rig_caps *caps, void *data) +{ + qDebug() << "HamLibClass::addRigToList" << endl; + QString name; + HamLibClass *r = (HamLibClass *) data; + name = caps->model_name; + + r->rigName2RigId[name] = caps->rig_model; // We fill the equivalences between name & Id + r->rigId2RigName[caps->rig_model] = name; + r->strings << name; + return -1; // not 0 --> we want all rigs +} + +int HamLibClass::getModelIdFromName (const QString _name) +{ + //HamLibClass *r (HamLibClass *) data; + int i = -1; + i = rigName2RigId[_name]; + return i; +} + +QString HamLibClass::getNameFromModelId(const int _id) +{ + return rigId2RigName[_id]; +} + +void HamLibClass::setModelId(const int _id) +{ + myrig_model = _id; +} + +void HamLibClass::setPort(const QString _port) +{ + serialPort = _port; + qstrncpy(myport.pathname, serialPort.toLocal8Bit().constData(), serialPort.length()); +} + +void HamLibClass::setSpeed(const int _speed) +{ + bauds = _speed; + switch (_speed) + { + case QSerialPort::Baud1200: + myport.parm.serial.rate = 1200; + break; + case QSerialPort::Baud2400: + myport.parm.serial.rate = 2400; + break; + case QSerialPort::Baud4800: + myport.parm.serial.rate = 4800; + break; + case QSerialPort::Baud9600: + myport.parm.serial.rate = 9600; + break; + case QSerialPort::Baud19200: + myport.parm.serial.rate = 19200; + break; + case QSerialPort::Baud38400: + myport.parm.serial.rate = 38400; + break; + case QSerialPort::Baud57600: + myport.parm.serial.rate = 57600; + break; + case QSerialPort::Baud115200: + myport.parm.serial.rate = 115200; + break; + default: + myport.parm.serial.rate = 9600; + break; + } +} + +void HamLibClass::setPatity(const int _parity) +{ + parity = _parity; + switch (_parity) + { + case QSerialPort::NoParity: + myport.parm.serial.parity = RIG_PARITY_NONE; + break; + case QSerialPort::EvenParity: + myport.parm.serial.parity = RIG_PARITY_EVEN; + break; + case QSerialPort::OddParity: + myport.parm.serial.parity = RIG_PARITY_ODD; + break; + case QSerialPort::SpaceParity: + myport.parm.serial.parity = RIG_PARITY_SPACE; + break; + case QSerialPort::MarkParity: + myport.parm.serial.parity = RIG_PARITY_MARK; + break; + default: + myport.parm.serial.parity = RIG_PARITY_NONE; + break; + } +} + +void HamLibClass::setFlow(const int _flow) +{ + flowControl = _flow; + switch (_flow) + { + case QSerialPort::QSerialPort::NoFlowControl: + myport.parm.serial.handshake = RIG_HANDSHAKE_NONE; + break; + case QSerialPort::HardwareControl: + myport.parm.serial.handshake = RIG_HANDSHAKE_HARDWARE; + break; + case QSerialPort::SoftwareControl: + myport.parm.serial.handshake = RIG_HANDSHAKE_XONXOFF; + break; + default: + myport.parm.serial.handshake = RIG_HANDSHAKE_NONE; + break; + } + +} + +void HamLibClass::setStop(const int _stop) +{ + stopBits = _stop; + + if ((_stop >=1) || (_stop<=3)) + { + myport.parm.serial.data_bits = _stop; + } + else + { + myport.parm.serial.data_bits = 1; + } + +} + +void HamLibClass::setData(const int _data) +{ + dataBits = _data; + if ((_data >=5) || (_data<=8)) + { + myport.parm.serial.data_bits = _data; + } + else + { + myport.parm.serial.data_bits = 8; + } + + +} + +bool HamLibClass::init() +{ + qDebug() << "HamLibClass::init: " << endl; + if (myrig_model == -1) + { + return false; + } + if (!rigLaunched) + { + rig_set_debug(RIG_DEBUG_NONE); + qDebug() << "HamLibClass::init: " << endl; + myport.type.rig = RIG_PORT_SERIAL; + qDebug() << "HamLibClass::init: 1" << endl; + //myport.parm.serial.rate = bauds; + //myport.parm.serial.data_bits = dataBits; + //myport.parm.serial.stop_bits = stopBits; + qDebug() << "HamLibClass::init: 2" << endl; + //TODO: CHECK PARITY + //myport.parm.serial.parity = RIG_PARITY_NONE; + //TODO: CHECK HANDSHAKE + //myport.parm.serial.handshake = RIG_HANDSHAKE_NONE; + //qstrncpy(myport.pathname, serialPort.toLocal8Bit().constData(), serialPort.length()); + //serialPort = myport.pathname; + qDebug() << "HamLibClass::init: 3" << endl; + my_rig = rig_init((myrig_model)); + if (!my_rig) + { + rigLaunched = false; + qDebug() << "HamLibClass::init: END FALSE1" << endl; + return false; + } + qDebug() << "HamLibClass::init: 4" << endl; + //qstrncpy(my_rig->state.rigport.pathname, serialPort.toLocal8Bit().constEnd(), serialPort.length()); + //serialPort = my_rig->state.rigport.pathname; + int recode = rig_open(my_rig); + + qDebug() << "HamLibClass::init: 5" << endl; + if (retcode != RIG_OK) + { + rigLaunched = false; + qDebug() << "HamLibClass::init: Error: " << QString::number(retcode) << "-" << rigerror(retcode); + qDebug() << "HamLibClass::init: END FALSE2" << endl; + return false; + } + rigLaunched = true; + timer->start(1000); + } + else + { + qDebug() << "HamLibClass::init: Rig was already launched" << endl; + } + qDebug() << "HamLibClass::init: END TRUE" << endl; + return true; +} + +bool HamLibClass::setFreq(const double _fr) +{ + qDebug() << "HamLibClass::setFreq: " << QString::number(_fr) << endl; + + freq = _fr * 1000000; + int retcode = rig_set_freq(my_rig, RIG_VFO_CURR, freq); + if (retcode != RIG_OK) + { + qDebug() << "HamLibClass::setFreq NOK: " << endl; + + return false; + } + else + { + qDebug() << "HamLibClass::setFreq OK: " << QString::number(freq) << endl; + retcode = rig_get_freq(my_rig, RIG_VFO_CURR, &freq); + if (retcode == RIG_OK) + { + qDebug() << "HamLibClass::setFreq read: " << QString::number(freq) << endl; + } + else + { + qDebug() << "HamLibClass::setFreq Unable to read FREQ" << endl; + } + return true; + } + +} + + + diff --git a/hamlibclass.h b/hamlibclass.h new file mode 100644 index 00000000..631dfb78 --- /dev/null +++ b/hamlibclass.h @@ -0,0 +1,71 @@ +#ifndef HAMLIBCLASS_H +#define HAMLIBCLASS_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + + +class HamLibClass : public QObject +{ + Q_OBJECT +public: + explicit HamLibClass(QObject *parent = nullptr); + ~HamLibClass(); + QStringList getRigList (); + int getModelIdFromName (const QString _name); + QString getNameFromModelId(const int _id); + void setModelId(const int _id); + void setPort(const QString _port); + void setSpeed(const int _speed); + void setPatity(const int _parity); + void setFlow(const int _flow); + void setStop(const int _stop); + void setData(const int _data); + bool setFreq(const double _fr); + + bool init(); + bool stop(); + bool isRunning(); + void clean(); + +signals: + void freqChanged(double newFreq); + +public slots: + void slotTimer(); + +private: + static int addRigToList(const struct rig_caps* caps, void* data); + QStringList strings; + QTimer *timer; + QMap rigName2RigId; + QMap rigId2RigName; + + RIG *my_rig; // handle to rig (instance) + freq_t freq, freq_old; // Radio freq + rmode_t rmode; // Radio mode + + int retcode; // generic return code from functions + + rig_model_t myrig_model; // Integer radio model + hamlib_port_t myport; // Hamlib port + + int bauds; // default 9600 + int dataBits; // default 8 + int stopBits; // default 1 + int flowControl; // default QSerialPort::NoFLowControl + int parity; // default QSerialPort::NoParity + QString serialPort; + + bool rigLaunched; +}; + +#endif // HAMLIBCLASS_H diff --git a/mainwindow.cpp b/mainwindow.cpp index e23fd752..38b8eb54 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -40,7 +40,6 @@ MainWindow::MainWindow(const QString _klogDir, const QString tversion) { - //qDebug() << "MainWindow::MainWindow: "<< _klogDir << " Ver: " << tversion << endl; //qDebug() << "MainWindow::MainWindow: Con func: "<< Q_FUNC_INFO << endl; @@ -49,13 +48,12 @@ MainWindow::MainWindow(const QString _klogDir, const QString tversion) //qDebug() << "MainWindow::MainWindow: "<< (QTime::currentTime()).toString("hhmmsszzz")<< endl; showErrorDialog = new ShowErrorDialog(); - UDPLogServer = new UDPServer(); + UDPLogServer = new UDPServer(); + hamlib = new HamLibClass(); + hamlibActive = false; upAndRunning = false; // To define some actions that can only be run when starting the software - //connect(&manager, SIGNAL(finished(QNetworkReply*)), SLOT(slotDownloadFinished(QNetworkReply*))); // To download cty.csv - //flagIcon = new QPushButton; // To paint a flag of the worked entity - // softwareVersion = tversion; itIsANewversion = false; dataProxy = new DataProxy_SQLite(softwareVersion, Q_FUNC_INFO); @@ -147,20 +145,7 @@ MainWindow::MainWindow(const QString _klogDir, const QString tversion) infoLabel1T = QString(); infoLabel2T = QString(); -/* - db = new DataBase(Q_FUNC_INFO, softwareVersion, util->getKLogDBFile()); - if (!db->createConnection()) - { - //qDebug() << "MainWindow::MainWindow: Conection not created" << endl; - return; - } - else - { - //db->updateIfNeeded(); // Check if we need to update the DB - //qDebug() << "MainWindow::MainWindow: DB updated was checked here" << endl; - } -*/ elogClublog = new eLogClubLog(); clublogAnswer = -1; @@ -269,6 +254,8 @@ MainWindow::MainWindow(const QString _klogDir, const QString tversion) connect(satTabWidget, SIGNAL(satTxFreqChanged(double)), this, SLOT(slotSatChangeTXFreq(double)) ); connect(satTabWidget, SIGNAL(dxLocatorChanged(QString)), this, SLOT(slotUpdateLocator(QString)) ); + connect(hamlib, SIGNAL(freqChanged(double)), this, SLOT(slotHamlibTXFreqChanged(double)) ); + myDataTabWidget = new MainWindowMyDataTab(); commentTabWidget = new MainWindowInputComment(); othersTabWidget = new MainWindowInputOthers(dataProxy); @@ -748,7 +735,7 @@ void MainWindow::slotModeComboBoxChanged() } void MainWindow::slotBandComboBoxChanged(){ - qDebug() << "MainWindow::slotBandComboBoxChanged: " << QString::number(bandComboBox->currentIndex()) << "/" << bandComboBox->currentText()<< endl; + //qDebug() << "MainWindow::slotBandComboBoxChanged: " << QString::number(bandComboBox->currentIndex()) << "/" << bandComboBox->currentText()<< endl; /* int i; i = dataProxy->getIdFromBandName(bandComboBox->currentText()); @@ -760,14 +747,14 @@ void MainWindow::slotBandComboBoxChanged(){ */ if (txFreqBeingChanged) { - qDebug() << "MainWindow::slotBandComboBoxChanged: txFreqBeingChanged" << endl; + //qDebug() << "MainWindow::slotBandComboBoxChanged: txFreqBeingChanged" << endl; return; } bool isFRinBand = dataProxy->isThisFreqInBand(bandComboBox->currentText(), QString::number(txFreqSpinBox->value())); if ((isFRinBand) && (txFreqSpinBox->value() >0 )) { - qDebug() << "MainWindow::slotBandComboBoxChanged: idFRinBand and Freq >0" << endl; + //qDebug() << "MainWindow::slotBandComboBoxChanged: idFRinBand and Freq >0" << endl; return; } @@ -791,15 +778,15 @@ void MainWindow::slotBandComboBoxChanged(){ //qDebug() << "MainWindow::slotBandComboBoxChanged Freq in txFreqSpinBox" << QString::number(txFreqSpinBox->value()) << endl; //qDebug() << "MainWindow::slotBandComboBoxChanged: Band Shown: " << dataProxy->getNameFromBandId(currentBandShown) << endl; // bool isFRinBand = dataProxy->isThisFreqInBand((dataProxy->getNameFromBandId(currentBandShown)), QString::number(txFreqSpinBox->value())); - qDebug() << "MainWindow::MainWindow: Freq: " << QString::number(txFreqSpinBox->value()) << endl; + //qDebug() << "MainWindow::MainWindow: Freq: " << QString::number(txFreqSpinBox->value()) << endl; if ((!isFRinBand) || (txFreqSpinBox->value()<=0)) { double txFr = (dataProxy->getFreqFromBandId(currentBandShown)).toDouble(); //satTabWidget->setUpLinkFreq(txFr); - qDebug() << "MainWindow::slotBandComboBoxChanged updating txFreqSpinBox" << QString::number(txFr) << endl; + //qDebug() << "MainWindow::slotBandComboBoxChanged updating txFreqSpinBox" << QString::number(txFr) << endl; txFreqSpinBox->setValue(txFr); } - qDebug() << "MainWindow::MainWindow: Freq2: " << QString::number(txFreqSpinBox->value()) << endl; + //qDebug() << "MainWindow::MainWindow: Freq2: " << QString::number(txFreqSpinBox->value()) << endl; //currentModeShown = modeComboBox->currentIndex(); checkIfWorkedB4(currentQrz); @@ -810,7 +797,7 @@ void MainWindow::slotBandComboBoxChanged(){ showStatusOfDXCC(_qs); - qDebug() << "MainWindow::slotBandComboBoxChanged: END" << endl; + //qDebug() << "MainWindow::slotBandComboBoxChanged: END" << endl; } @@ -3294,7 +3281,7 @@ void MainWindow::slotClearButtonClicked() void MainWindow::clearUIDX(bool full) { - qDebug() << "MainWindow::clearUIDX" << endl; + //qDebug() << "MainWindow::clearUIDX" << endl; SRXLineEdit->setText("59"); STXLineEdit->setText("59"); nameLineEdit->clear(); @@ -4346,7 +4333,14 @@ void MainWindow::readConfigData() //qDebug() << "MainWindow::readConfigData: UDP Log server already stopped no need to restop!" << endl; } } - + if (hamlibActive) + { + hamlib->init(); + } + else + { + hamlib->stop(); + } //qDebug() << "MainWindow::readConfigData - END" << endl; @@ -4614,6 +4608,22 @@ bool MainWindow::processConfigLine(const QString _line){ //UDPLogServer->setLogging(false); } } + else if (field == "HAMLIBRIGTYPE" ) + { + hamlib->setModelId(value.toInt()); + } + else if(field == "HAMLIBSERIALPORT") + { + hamlib->setPort(value); + } + else if (field == "HAMLIBSERIALBAUDS") + { + hamlib->setSpeed(value.toInt()); + } + else if (field == "HAMLIB") + { + hamlibActive = true; + } else if (field=="REALTIMEFROMWSJTX") { //qDebug() << "MainWindow::processConfigLine: REALTIMEFROMWSJTX: " << value << endl; @@ -7178,13 +7188,17 @@ void MainWindow::updateBandComboBox(const QString _band) void MainWindow::slotFreqTXChanged() { - //qDebug() << "MainWindow::slotFreqTXChanged" << QString::number(txFreqSpinBox->value()) << endl; + qDebug() << "MainWindow::slotFreqTXChanged" << QString::number(txFreqSpinBox->value()) << endl; txFreqBeingChanged = true; int bandId = dataProxy->getBandIdFromFreq(txFreqSpinBox->value()); if (bandId > 1) - { // If the freq belongs to onne ham band + { // If the freq belongs to one ham band txFreqSpinBox->setPalette(palBlack); txFreqSpinBox->setToolTip(tr("TX Frequency in MHz.")); + if (hamlibActive) + { + hamlib->setFreq(txFreqSpinBox->value()); + } bool freqInBand = dataProxy->isThisFreqInBand(bandComboBox->currentText(), QString::number(txFreqSpinBox->value())); if(!freqInBand) @@ -7193,6 +7207,7 @@ void MainWindow::slotFreqTXChanged() QString _newBand = dataProxy->getBandNameFromFreq(txFreqSpinBox->value()); updateBandComboBox(_newBand); bandComboBox->setCurrentIndex(bandComboBox->findText(_newBand, Qt::MatchCaseSensitive)); + } } else @@ -7653,8 +7668,8 @@ void MainWindow::slotQueryErrorManagement(QString functionFailed, QString errorC "
  • " + tr("Error code") +": " + QString::number(errorCodeN) + "
  • " + "
  • " + tr("Error text") + ": " + errorCodeS + "
  • " + "
  • " + tr("Failed query") + ": " + queryFailed + "
  • " + - "
    " - "Recomendation: Export, periodically, your data to ADIF to prevent a potential data loss.
    "; + "
    " + + "" + tr("Recomendation:") + "" + tr("Export, periodically, your data to ADIF to prevent a potential data loss.") + "
    "; showErrorDialog->setText(aux + errorMSG); //showErrorDialog->setModal(true); @@ -7693,6 +7708,13 @@ void MainWindow::slotSatChangeTXFreq(const double _f) txFreqSpinBox->setValue(_f); } + +void MainWindow::slotHamlibTXFreqChanged(const double _f) +{ + txFreqSpinBox->setValue(_f); +} + + void MainWindow::slotUpdateLocator(QString _loc) { locatorLineEdit->setText(_loc.toUpper()); diff --git a/mainwindow.h b/mainwindow.h index 6ba59a43..6c27e18e 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -66,8 +66,7 @@ #include "udpserver.h" #include "statisticswidget.h" #include "updatesatsdata.h" - - +#include "hamlibclass.h" @@ -155,14 +154,6 @@ private slots: void slotToolLoTWMarkAllQueued(); void slotToolLoTWMarkAllYesThisLog(); void slotToolLoTWMarkAllYes(); - //void slotSearchExportButtonClicked(); - //void slotSearchBoxSelectAllButtonClicked(); - //void slotSearchClearButtonClicked(); - //void slotSearchBoxSelectionChanged(); - //void slotSearchBoxReSearchButtonClicked(); - - //void showMenuRightButtonSearchCreateActions(); - //void righButtonSearchMenu(const int trow); void slotModeComboBoxChanged(); void slotBandComboBoxChanged(); @@ -183,20 +174,6 @@ private slots: void slotSetup(const int _page=0); - //void slotQsoDeleteFromSearch(); - //void slotQSLSentViaBureauFromSearch(); - //void slotQSLSentViaDirectFromSearch(); - //void slotQSLSentViaDirectMarkDXReqFromSearch(); - - //void slotQSLSentViaBureuMarkDXReqFromSearch(); - //void slotQSLRecViaDirectFromSearch(); - //void slotQSLRecViaBureauFromSearch(); - //void slotQSLRecViaDirectMarkReqFromSearch(); - //void slotQSLRecViaBureauMarkReqFromSearch(); - //void slotQSLSentMarkAsRequested(); - //void slotQSLRecMarkAsRequested(); - //void slotQSOToEditFromSearch(); - void slotrstTXTextChanged(); void slotrstRXTextChanged(); void slotADIFExport(); @@ -209,15 +186,6 @@ private slots: //void slotQSLViaTextChanged(); void slotTimeOutInfoBars(); // Clears the infoLabels when the timeout emits the signal - -//TODO: REMOVE EQSL - //void slotQSLRecvComboBoxChanged(); - //void slotQSLSentComboBoxChanged(); - //void sloteQSLRecvComboBoxChanged(); - //void sloteQSLSentComboBoxChanged(); - //void slotLotwRecvComboBoxChanged(); - //void slotLotwSentComboBoxChanged(); - void slotSetPropMode(const QString _p); void slotFillEmptyDXCCInTheLog(); void slotUpdateCTYDAT(); @@ -254,12 +222,6 @@ private slots: //SEARCH void slotShowSearchWidget(); // The SearchWidget request being shown - //void slotDoubleClickSearch( QTreeWidgetItem* item, int); // Double click on a QSO in the search box - //void slotRighButtonSearch(const QPoint& pos); - //void slotToolSearchNeededQSLToSend(); - //void slotToolSearchNeededQSLPendingToReceive(); - //void slotToolSearchNeededQSLRequested(); - //void slotToolSearchQSL(const int actionQSL); //SEARCH // CLUSTER @@ -280,7 +242,10 @@ private slots: void slotDefineNewBands(const QStringList _bands); void slotSatChangeRXFreq(const double _f); void slotSatChangeTXFreq(const double _f); - + + //HAMLIB + void slotHamlibTXFreqChanged(const double _f); + //DXCCWIDGET void slotShowQSOFromDXCCWidget(const int _q); void slotShowQSOsFromDXCCWidget(QList _qsos); @@ -302,6 +267,8 @@ private: UpdateSatsData *updateSatsData; //UPDATE CTY.DAT DownLoadCTY *downloadcty; + HamLibClass *hamlib; + bool hamlibActive; // void createStatusBar(); diff --git a/setupdialog.cpp b/setupdialog.cpp index b3ac8bab..f855e20c 100644 --- a/setupdialog.cpp +++ b/setupdialog.cpp @@ -685,7 +685,8 @@ bool SetupDialog::processConfigLine(const QString _line) value = value.left(value.length() - (value.length() - endValue)); } value = checkAndFixASCIIinADIF(value); // Check whether the value is valid. - + qDebug() << "SetupDialog::processConfigLine: TAB: " << tab << endl; + qDebug() << "SetupDialog::processConfigLine: VALUE: " << value << endl; if (tab == "CALLSIGN"){ //qDebug() << "SetupDialog::processConfigLine: CALLSIGN: " << value << endl; userDataPage->setStationQrz(value); @@ -868,6 +869,20 @@ bool SetupDialog::processConfigLine(const QString _line) colorsPage->setConfirmedColor(value); }else if(tab =="DEFAULTCOLOR"){ colorsPage->setDefaultColor(value); + qDebug() << "SetupDialog::processConfigLine: DEFAULTCOLOR: " << value << endl; + }else if(tab =="HAMLIBRIGTYPE"){ + qDebug() << "SetupDialog::processConfigLine: HAMLIBRIGTYPE: " << value << endl; + hamlibPage->setRigType(value); + }else if(tab =="HAMLIBSERIALPORT"){ + qDebug() << "SetupDialog::processConfigLine: HAMLIBSERIALPORT: " << value << endl; + hamlibPage->setSerialPort(value); + }else if(tab =="HAMLIBSERIALBAUDS"){ + qDebug() << "SetupDialog::processConfigLine: HAMLIBSERIALBAUDS: " << value << endl; + hamlibPage->setSerialSpeed(value); + }else if(tab =="HAMLIB"){ + qDebug() << "SetupDialog::processConfigLine: HAMLIB: " << value << endl; + hamlibPage->setActive(value); + }else if(tab =="SELECTEDLOG"){ //qDebug() << "SetupDialog::processConfigLine: SELECTEDLOG: " << value << endl; i = value.toInt(); diff --git a/setuppagehamlib.cpp b/setuppagehamlib.cpp index 8b256e3f..81c6d84b 100755 --- a/setuppagehamlib.cpp +++ b/setuppagehamlib.cpp @@ -3,7 +3,8 @@ SetupPageHamLib::SetupPageHamLib(DataProxy *dp, QWidget *parent) : QWidget(parent) { //qDebug() << "SetupPageHamLib::SetupPageHamLib" << endl; - + hamlib = new HamLibClass(); + activateHamlibCheckBox = new QCheckBox(); rigTypeComboBox = new QComboBox(); serialBaudsComboBox = new QComboBox(); serialPortComboBox = new QComboBox(); @@ -17,6 +18,7 @@ SetupPageHamLib::SetupPageHamLib(DataProxy *dp, QWidget *parent) : QWidget(paren handshakeHCheckBox = new QCheckBox(); flowControlLinesDTRCheckBox = new QCheckBox(); flowControlLinesRTSCheckBox = new QCheckBox(); + scanSerialPortButton = new QPushButton(); //serialBaudsSpinBox = new QSpinBox; @@ -33,12 +35,27 @@ SetupPageHamLib::SetupPageHamLib(DataProxy *dp, QWidget *parent) : QWidget(paren qDebug() << "SetupPageHamLib::SetupPageHamLib END" << endl; } +void SetupPageHamLib::fillSerialPortsComboBox() +{ + qDebug() << "SetupPageHamLib::fillSerialPortsComboBox" << endl; + serialPortComboBox->clear(); + serialPortComboBox->addItems(getAvailableSerialPorts()); + //serialPortComboBox->setCurrentIndex(0); +} + void SetupPageHamLib::createUI() { + + connect(scanSerialPortButton, SIGNAL(clicked(bool)), this, SLOT(slotScanPorts()) ); + + activateHamlibCheckBox->setText(tr("Activate HamLib")); + activateHamlibCheckBox->setToolTip(tr("Activates the hamlib support that will enable the connection to a radio.")); + rigTypeComboBox->clear(); strings.clear(); setRig(); - serialPortComboBox->addItems(getAvailableSerialPorts()); + //serialPortComboBox->addItems(getAvailableSerialPorts()); + fillSerialPortsComboBox(); rigTypeComboBox->setCurrentIndex(0); @@ -55,6 +72,9 @@ void SetupPageHamLib::createUI() serialPortLabel->setAlignment(Qt::AlignVCenter| Qt::AlignCenter); serialPortLabel->setEnabled(true); + scanSerialPortButton->setText(tr("Scan"));; + scanSerialPortButton->setToolTip(tr("Click to identify the serial ports available in your computer.")); + serialBaudsComboBox->addItems(baudSpeeds); QLabel *serialBaudsLabel = new QLabel(tr("Bauds")); serialBaudsLabel->setBuddy(serialBaudsComboBox); @@ -67,6 +87,7 @@ void SetupPageHamLib::createUI() topData->addWidget(rigTypeComboBox, 0, 1); topData->addWidget(serialPortLabel, 1, 0); topData->addWidget(serialPortComboBox, 1, 1); + topData->addWidget(scanSerialPortButton, 1, 2); topData->addWidget(serialBaudsLabel, 2, 0); topData->addWidget(serialBaudsComboBox, 2, 1); /* @@ -125,15 +146,21 @@ void SetupPageHamLib::createUI() flowControlLineButtonsLayout->addWidget(flowControlLinesRTSCheckBox); flowControlLineGroupBox->setLayout(flowControlLineButtonsLayout); */ - QGridLayout *mainLayout = new QGridLayout; + QGridLayout *mainLayout = new QGridLayout; mainLayout->addLayout(topData, 0, 0); //mainLayout->addWidget(dataBitsGroupBox, 1, 0); //mainLayout->addWidget(stopBitsGroupBox, 1, 1); //mainLayout->addWidget(handShakeGroupBox, 2, 0); //mainLayout->addWidget(flowControlLineGroupBox, 2, 1); - setLayout(mainLayout); + QVBoxLayout *mLayout = new QVBoxLayout; + mLayout->addWidget(activateHamlibCheckBox); + mLayout->addLayout(mainLayout); + //mLayout->setAlignment(activateHamlibCheckBox, Qt::AlignHCenter | Qt::AlignTop); + + + setLayout(mLayout); } void SetupPageHamLib::setRig () @@ -141,7 +168,10 @@ void SetupPageHamLib::setRig () qDebug() << "SetupPageHamLib::SetRig" << endl; // Rutine to fill the rig combo boxes // Do not display debug codes when load the rig's - rig_set_debug (RIG_DEBUG_NONE); + + rigTypeComboBox->insertItems(0, hamlib->getRigList()); +/* + rig_set_debug (RIG_DEBUG_NONE); // and continue... rig_load_all_backends (); @@ -149,8 +179,9 @@ void SetupPageHamLib::setRig () strings.sort (); rigTypeComboBox->insertItems (0, strings); strings.clear (); + */ } - +/* int SetupPageHamLib::addRigToList (const struct rig_caps *caps, void *data) { qDebug() << "SetupPageHamLib::addRigToList" << endl; @@ -165,6 +196,7 @@ int SetupPageHamLib::addRigToList (const struct rig_caps *caps, void *data) r->strings << name; return -1; // not 0 --> we want all rigs } +*/ QStringList SetupPageHamLib::getAvailableSerialPorts() { @@ -199,6 +231,7 @@ QString SetupPageHamLib::getData() _output.clear(); QString _rigType, _serialPort, _baudsSpeed;//, dataBits, stopBits, handshake, flowControlLine; + _rigType = rigTypeComboBox->currentText(); _serialPort = serialPortComboBox->currentText(); _baudsSpeed = serialBaudsComboBox->currentText(); @@ -250,22 +283,34 @@ QString SetupPageHamLib::getData() } */ _output.clear(); - _output = _output + "HamLibRigType=" + _rigType + "\n"; - _output = _output + "HamlibSerialPort=" + _serialPort + "\n"; - _output = _output + "HamlibSerialBauds=" + _baudsSpeed + "\n"; + if (activateHamlibCheckBox->isChecked()) + { + _output = _output + "Hamlib=True;\n"; + } + else + { - //_output + "SerialDataBits=" + dataBits + "\n"; - //_output + "SerialStopBits=" + stopBits + "\n"; - //_output + "SerialHandShake=" + handshake + "\n"; - //_output + "SerialFlowControlLine=" + flowControlLine + "\n"; + } + //qDebug() << "SetupPageHamLib::getData: " << QString::number(hamlib->getModelIdFromName(_rigType)) << endl; + _output = _output + "HamLibRigType=" + QString::number(hamlib->getModelIdFromName(_rigType)) + ";\n"; + //_output = _output + "HamLibRigType=" + _rigType + "\n"; + _output = _output + "HamlibSerialPort=" + _serialPort + ";\n"; + _output = _output + "HamlibSerialBauds=" + _baudsSpeed + ";\n"; - qDebug() << "SetupPageHamLib::getData: " << _output << endl; + //_output + "SerialDataBits=" + dataBits + ";\n"; + //_output + "SerialStopBits=" + stopBits + ";\n"; + //_output + "SerialHandShake=" + handshake + ";\n"; + //_output + "SerialFlowControlLine=" + flowControlLine + ";\n"; + + //qDebug() << "SetupPageHamLib::getData: " << _output << endl; return _output; } bool SetupPageHamLib::setRigType(const QString _radio) { - int _index = rigTypeComboBox->findText(_radio, Qt::MatchFlag::MatchExactly); + qDebug() << "SetupPageHamLib::setRig: " << _radio << endl; + + int _index = rigTypeComboBox->findText(hamlib->getNameFromModelId(_radio.toInt()), Qt::MatchFlag::MatchExactly); if (_index >= 0) { rigTypeComboBox->setCurrentIndex(_index); @@ -307,3 +352,20 @@ bool SetupPageHamLib::setSerialSpeed(const QString _speed ) } return false; } + +bool SetupPageHamLib::setActive(const QString _active) +{ + if (_active.toUpper() == "TRUE") + { + activateHamlibCheckBox->setChecked(true); + } + else { + activateHamlibCheckBox->setChecked(false); + } +} + +void SetupPageHamLib::slotScanPorts() +{ + qDebug() << "SetupPageHamLib::slotScanPorts" << endl; + fillSerialPortsComboBox(); +} diff --git a/setuppagehamlib.h b/setuppagehamlib.h index 416ccdc5..c77d7ddb 100755 --- a/setuppagehamlib.h +++ b/setuppagehamlib.h @@ -32,7 +32,7 @@ #include //#include #include - +#include "hamlibclass.h" #include "dataproxy.h" #include @@ -46,31 +46,38 @@ public: bool setRigType(const QString _radio); bool setSerialPort(const QString _port); bool setSerialSpeed(const QString _speed ); + bool setActive(const QString _active); + signals: public slots: + void slotScanPorts(); private: void createUI(); void setRig(); void setDefaults(); - static int addRigToList(const struct rig_caps* caps, void* data); + void fillSerialPortsComboBox(); + //static int addRigToList(const struct rig_caps* caps, void* data); QStringList getAvailableSerialPorts(); QButtonGroup *flowControlLineButtonGroup, *handshakeButtonGroup, *dataBitsGroupButton, *stopBitsButtonGroup; - + QPushButton *scanSerialPortButton; QComboBox *rigTypeComboBox, *serialBaudsComboBox, *serialPortComboBox; //QSpinBox *serialBaudsSpinBox; QLineEdit *serialPort; - RIG *my_rig; // handle to rig (instance) - freq_t freq; - rig_model_t myrig_model; + HamLibClass *hamlib; + + //RIG *my_rig; // handle to rig (instance) + //freq_t freq; + //rig_model_t myrig_model; QStringList strings, baudSpeeds, serialPorts; QCheckBox *dataBits7CheckBox, *dataBits8CheckBox, *stopBits1CheckBox, *stopBits2CheckBox, *handshakeNoneCheckBox, *handshakeXCheckBox, *handshakeHCheckBox, - *flowControlLinesDTRCheckBox, *flowControlLinesRTSCheckBox; + *flowControlLinesDTRCheckBox, *flowControlLinesRTSCheckBox, + *activateHamlibCheckBox; //int defaultPortSpeed;