diff --git a/commhandler.cpp b/commhandler.cpp index 2366431..75a8c43 100644 --- a/commhandler.cpp +++ b/commhandler.cpp @@ -320,7 +320,7 @@ void commHandler::openPort() qInfo(logSerial()) << "Could not open serial port " << portName << " , please restart."; isConnected = false; serialError = true; - emit haveSerialPortError(portName, "Could not open port. Please restart."); + emit havePortError(errorType(portName, "Could not open port. Please restart.")); return; } } diff --git a/commhandler.h b/commhandler.h index acfc8be..f0e6a40 100644 --- a/commhandler.h +++ b/commhandler.h @@ -9,6 +9,8 @@ #include #include +#include "wfviewtypes.h" + // This class abstracts the comm port in a useful way and connects to // the command creator and command parser. @@ -39,7 +41,7 @@ signals: void haveTextMessage(QString message); // status, debug only void sendDataOutToPort(const QByteArray &writeData); // not used void haveDataFromPort(QByteArray data); // emit this when we have data, connect to rigcommander - void haveSerialPortError(const QString port, const QString error); + void havePortError(errorType err); void haveStatusUpdate(const QString text); private: diff --git a/pttyhandler.cpp b/pttyhandler.cpp index 60ea0ae..909a0b9 100644 --- a/pttyhandler.cpp +++ b/pttyhandler.cpp @@ -90,7 +90,7 @@ void pttyHandler::openPort() qInfo(logSerial()) << "Could not open pseudo terminal port, please restart."; isConnected = false; serialError = true; - emit haveSerialPortError(portName, "Could not open pseudo terminal port. Please restart."); + emit havePortError(errorType(portName, "Could not open pseudo terminal port. Please restart.")); return; } diff --git a/pttyhandler.h b/pttyhandler.h index d056e77..dda18ac 100644 --- a/pttyhandler.h +++ b/pttyhandler.h @@ -10,6 +10,7 @@ #include #include "rigidentities.h" +#include "wfviewtypes.h" // This class abstracts the comm port in a useful way and connects to // the command creator and command parser. @@ -34,7 +35,7 @@ private slots: signals: void haveTextMessage(QString message); // status, debug only void haveDataFromPort(QByteArray data); // emit this when we have data, connect to rigcommander - void haveSerialPortError(const QString port, const QString error); + void havePortError(errorType err); void haveStatusUpdate(const QString text); private: diff --git a/rigcommander.cpp b/rigcommander.cpp index dac1c04..663f8c9 100644 --- a/rigcommander.cpp +++ b/rigcommander.cpp @@ -86,8 +86,8 @@ void rigCommander::commSetup(unsigned char rigCivAddr, QString rigSerialPort, qu // data from the rig to the ptty: connect(comm, SIGNAL(haveDataFromPort(QByteArray)), ptty, SLOT(receiveDataFromRigToPtty(QByteArray))); - connect(comm, SIGNAL(haveSerialPortError(QString, QString)), this, SLOT(handleSerialPortError(QString, QString))); - connect(ptty, SIGNAL(haveSerialPortError(QString, QString)), this, SLOT(handleSerialPortError(QString, QString))); + connect(comm, SIGNAL(havePortError(errorType)), this, SLOT(handlePortError(errorType))); + connect(ptty, SIGNAL(havePortError(errotType)), this, SLOT(handlePortError(errorType))); connect(this, SIGNAL(getMoreDebug()), comm, SLOT(debugThis())); connect(this, SIGNAL(getMoreDebug()), ptty, SLOT(debugThis())); @@ -164,12 +164,12 @@ void rigCommander::commSetup(unsigned char rigCivAddr, udpPreferences prefs, aud connect(udp, SIGNAL(haveBaudRate(quint32)), this, SLOT(receiveBaudRate(quint32))); // Connect for errors/alerts - connect(udp, SIGNAL(haveNetworkError(QString, QString)), this, SLOT(handleSerialPortError(QString, QString))); + connect(udp, SIGNAL(haveNetworkError(errorType)), this, SLOT(handlePortError(errorType))); connect(udp, SIGNAL(haveNetworkStatus(networkStatus)), this, SLOT(handleStatusUpdate(networkStatus))); connect(udp, SIGNAL(haveNetworkAudioLevels(networkAudioLevels)), this, SLOT(handleNetworkAudioLevels(networkAudioLevels))); - connect(ptty, SIGNAL(haveSerialPortError(QString, QString)), this, SLOT(handleSerialPortError(QString, QString))); + connect(ptty, SIGNAL(havePortError(errorType)), this, SLOT(handlePortError(errorType))); connect(this, SIGNAL(getMoreDebug()), ptty, SLOT(debugThis())); connect(this, SIGNAL(discoveredRigID(rigCapabilities)), ptty, SLOT(receiveFoundRigID(rigCapabilities))); @@ -232,14 +232,14 @@ void rigCommander::process() // new thread enters here. Do nothing but do check for errors. if(comm!=Q_NULLPTR && comm->serialError) { - emit haveSerialPortError(rigSerialPort, QString("Error from commhandler. Check serial port.")); + emit havePortError(errorType(rigSerialPort, QString("Error from commhandler. Check serial port."))); } } -void rigCommander::handleSerialPortError(const QString port, const QString errorText) +void rigCommander::handlePortError(errorType err) { - qInfo(logRig()) << "Error using port " << port << " message: " << errorText; - emit haveSerialPortError(port, errorText); + qInfo(logRig()) << "Error using port " << err.device << " message: " << err.message; + emit havePortError(err); } void rigCommander::handleStatusUpdate(const networkStatus status) diff --git a/rigcommander.h b/rigcommander.h index 9f49832..4aa11ac 100644 --- a/rigcommander.h +++ b/rigcommander.h @@ -227,7 +227,7 @@ public slots: // UDP: void handleNewData(const QByteArray& data); void receiveAudioData(const audioPacket& data); - void handleSerialPortError(const QString port, const QString errorText); + void handlePortError(errorType err); void changeLatency(const quint16 value); void dataFromServer(QByteArray data); void receiveBaudRate(quint32 baudrate); @@ -249,7 +249,7 @@ public slots: signals: // Communication: void commReady(); - void haveSerialPortError(const QString port, const QString errorText); + void havePortError(errorType err); void haveStatusUpdate(const networkStatus status); void haveNetworkAudioLevels(const networkAudioLevels l); void dataForComm(const QByteArray &outData); diff --git a/servermain.cpp b/servermain.cpp index 6312523..17d455c 100644 --- a/servermain.cpp +++ b/servermain.cpp @@ -29,6 +29,7 @@ servermain::servermain(const QString settingsFile) qRegisterMetaType>(); qRegisterMetaType(); qRegisterMetaType(); + qRegisterMetaType(); setDefPrefs(); @@ -119,7 +120,7 @@ void servermain::makeRig() connect(radio->rigThread, SIGNAL(finished()), radio->rig, SLOT(deleteLater())); radio->rigThread->start(); // Rig status and Errors: - connect(radio->rig, SIGNAL(haveSerialPortError(QString, QString)), this, SLOT(receiveSerialPortError(QString, QString))); + connect(radio->rig, SIGNAL(havePortError(errorType)), this, SLOT(receivePortError(errorType))); connect(radio->rig, SIGNAL(haveStatusUpdate(networkStatus)), this, SLOT(receiveStatusUpdate(networkStatus))); // Rig comm setup: @@ -328,7 +329,7 @@ void servermain::receiveFoundRigID(rigCapabilities rigCaps) return; } -void servermain::receiveSerialPortError(QString port, QString errorText) +void servermain::receivePortError(errorType err) { qInfo(logSystem()) << "servermain: received serial port error for port: " << port << " with message: " << errorText; diff --git a/servermain.h b/servermain.h index 18cbf10..4c53e51 100644 --- a/servermain.h +++ b/servermain.h @@ -175,7 +175,7 @@ private slots: void receivePTTstatus(bool pttOn); void receiveFoundRigID(rigCapabilities rigCaps); - void receiveSerialPortError(QString port, QString errorText); + void receivePortError(errorType err); void receiveBaudRate(quint32 baudrate); void handlePttLimit(); @@ -305,6 +305,7 @@ Q_DECLARE_METATYPE(enum meterKind) Q_DECLARE_METATYPE(enum spectrumMode) Q_DECLARE_METATYPE(rigstate*) Q_DECLARE_METATYPE(codecType) +Q_DECLARE_METATYPE(errorType) #endif // WFMAIN_H diff --git a/udphandler.cpp b/udphandler.cpp index a666b90..9aa3ef9 100644 --- a/udphandler.cpp +++ b/udphandler.cpp @@ -325,12 +325,12 @@ void udpHandler::dataReceived() if (in->type != 0x01) { if (in->error == 0xffffffff && !streamOpened) { - emit haveNetworkError(radioIP.toString(), "Connection failed, wait a few minutes or reboot the radio."); + emit haveNetworkError(errorType(true, radioIP.toString(), "Connection failed\ntry rebooting the radio.")); qInfo(logUdp()) << this->metaObject()->className() << ": Connection failed, wait a few minutes or reboot the radio."; } else if (in->error == 0x00000000 && in->disc == 0x01) { - emit haveNetworkError(radioIP.toString(), "Got radio disconnected."); + emit haveNetworkError(errorType(radioIP.toString(), "Got radio disconnected.")); qInfo(logUdp()) << this->metaObject()->className() << ": Got radio disconnected."; if (streamOpened) { // Close stream connections but keep connection open to the radio. @@ -395,7 +395,7 @@ void udpHandler::dataReceived() { if (rxSetup.codec >= 0x40 || txSetup.codec >= 0x40) { - emit haveNetworkError(QString("UDP"), QString("Opus codec not supported, forcing LPCM16")); + emit haveNetworkError(errorType(QString("UDP"), QString("Opus codec not supported, forcing LPCM16"))); if (rxSetup.codec >= 0x40) rxSetup.codec = 0x04; if (txSetup.codec >= 0x40) @@ -406,7 +406,7 @@ void udpHandler::dataReceived() if (in->error == 0xfeffffff) { - status.message = "Invalid Username/Password"; + emit haveNetworkError(errorType(true, radioIP.toString(), "Invalid Username/Password")); qInfo(logUdp()) << this->metaObject()->className() << ": Invalid Username/Password"; } else if (!isAuthenticated) diff --git a/udphandler.h b/udphandler.h index 157006e..169284b 100644 --- a/udphandler.h +++ b/udphandler.h @@ -62,7 +62,7 @@ public slots: signals: void haveDataFromPort(QByteArray data); // emit this when we have data, connect to rigcommander void haveAudioData(audioPacket data); // emit this when we have data, connect to rigcommander - void haveNetworkError(QString, QString); + void haveNetworkError(errorType); void haveChangeLatency(quint16 value); void haveSetVolume(unsigned char value); void haveNetworkStatus(networkStatus); diff --git a/wfmain.cpp b/wfmain.cpp index 423c5e1..e0710a4 100644 --- a/wfmain.cpp +++ b/wfmain.cpp @@ -74,6 +74,7 @@ wfmain::wfmain(const QString settingsFile, const QString logFile, bool debugMode qRegisterMetaType(); qRegisterMetaType(); qRegisterMetaType(); + qRegisterMetaType(); haveRigCaps = false; @@ -493,7 +494,7 @@ void wfmain::makeRig() rigThread->start(); // Rig status and Errors: - connect(rig, SIGNAL(haveSerialPortError(QString, QString)), this, SLOT(receiveSerialPortError(QString, QString))); + connect(rig, SIGNAL(havePortError(errorType)), this, SLOT(receivePortError(errorType))); connect(rig, SIGNAL(haveStatusUpdate(networkStatus)), this, SLOT(receiveStatusUpdate(networkStatus))); connect(rig, SIGNAL(haveNetworkAudioLevels(networkAudioLevels)), this, SLOT(receiveNetworkAudioLevels(networkAudioLevels))); connect(rig, SIGNAL(requestRadioSelection(QList)), this, SLOT(radioSelection(QList))); @@ -673,11 +674,16 @@ void wfmain::receiveFoundRigID(rigCapabilities rigCaps) return; } -void wfmain::receiveSerialPortError(QString port, QString errorText) +void wfmain::receivePortError(errorType err) { - qInfo(logSystem()) << "wfmain: received serial port error for port: " << port << " with message: " << errorText; - ui->statusBar->showMessage(QString("ERROR: using port ").append(port).append(": ").append(errorText), 10000); - + if (err.alert) { + QMessageBox::critical(this, err.device, err.message, QMessageBox::Ok); + } + else + { + qInfo(logSystem()) << "wfmain: received error for device: " << err.device << " with message: " << err.message; + ui->statusBar->showMessage(QString("ERROR: using device ").append(err.device).append(": ").append(err.message), 10000); + } // TODO: Dialog box, exit, etc } diff --git a/wfmain.h b/wfmain.h index 638e900..a1397bf 100644 --- a/wfmain.h +++ b/wfmain.h @@ -296,7 +296,7 @@ private slots: void receiveAntennaSel(unsigned char ant, bool rx); void receiveRigID(rigCapabilities rigCaps); void receiveFoundRigID(rigCapabilities rigCaps); - void receiveSerialPortError(QString port, QString errorText); + void receivePortError(errorType err); void receiveStatusUpdate(networkStatus status); void receiveNetworkAudioLevels(networkAudioLevels l); void handlePlotClick(QMouseEvent *); @@ -1076,6 +1076,7 @@ Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(rigstate*) Q_DECLARE_METATYPE(codecType) +Q_DECLARE_METATYPE(errorType) //void (*wfmain::logthistext)(QString text) = NULL; diff --git a/wfview.sln b/wfview.sln index 3f1c01e..dc35573 100644 --- a/wfview.sln +++ b/wfview.sln @@ -20,13 +20,13 @@ Global {326108AD-FA9D-3AAF-8D3E-062C4DDC34E2}.Debug|x64.Build.0 = Debug|x64 {326108AD-FA9D-3AAF-8D3E-062C4DDC34E2}.Release|Win32.ActiveCfg = Release|Win32 {326108AD-FA9D-3AAF-8D3E-062C4DDC34E2}.Release|x64.ActiveCfg = Release|x64 + {326108AD-FA9D-3AAF-8D3E-062C4DDC34E2}.Release|x64.Build.0 = Release|x64 {00E054F8-A1D4-3ECA-A8D6-DFC8A68AFD56}.Debug|Win32.ActiveCfg = Debug|Win32 {00E054F8-A1D4-3ECA-A8D6-DFC8A68AFD56}.Debug|Win32.Build.0 = Debug|Win32 {00E054F8-A1D4-3ECA-A8D6-DFC8A68AFD56}.Debug|x64.ActiveCfg = Debug|x64 {00E054F8-A1D4-3ECA-A8D6-DFC8A68AFD56}.Release|Win32.ActiveCfg = Release|Win32 {00E054F8-A1D4-3ECA-A8D6-DFC8A68AFD56}.Release|Win32.Build.0 = Release|Win32 {00E054F8-A1D4-3ECA-A8D6-DFC8A68AFD56}.Release|x64.ActiveCfg = Release|x64 - {00E054F8-A1D4-3ECA-A8D6-DFC8A68AFD56}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/wfviewtypes.h b/wfviewtypes.h index ae95829..2e3c9ff 100644 --- a/wfviewtypes.h +++ b/wfviewtypes.h @@ -45,6 +45,17 @@ struct timekind { bool isMinus; }; +struct errorType { + errorType(bool alert, QString message) : alert(alert), message(message) {}; + errorType(bool alert, QString device, QString message) : alert(alert), device(device), message(message) {}; + errorType(QString device, QString message) : alert(false), device(device), message(message) {}; + errorType(QString message) : alert(false), message(message) {}; + + bool alert; + QString device; + QString message; +}; + enum audioType {qtAudio,portAudio,rtAudio}; enum codecType { LPCM, PCMU, OPUS };