diff --git a/APRSISClient.cpp b/APRSISClient.cpp index 37810cd..226fc65 100644 --- a/APRSISClient.cpp +++ b/APRSISClient.cpp @@ -240,19 +240,56 @@ void APRSISClient::processQueue(bool disconnect){ } } + auto re = QRegExp("full|unavailable|busy"); + auto line = QString(readLine()); + if(line.toLower().indexOf(re) >= 0){ + qDebug() << "APRSISClient Connection Busy:" << line; + return; + } + if(write(loginFrame(m_localCall).toLocal8Bit()) == -1){ qDebug() << "APRSISClient Write Login Error:" << errorString(); return; } + if(!waitForReadyRead(5000)){ + qDebug() << "APRSISClient Login Error: Server Not Responding"; + return; + } + + line = QString(readAll()); + if(line.toLower().indexOf(re) >= 0){ + qDebug() << "APRSISClient Server Busy:" << line; + return; + } + while(!m_frameQueue.isEmpty()){ - if(write(m_frameQueue.head().toLocal8Bit()) == -1){ + QByteArray data = m_frameQueue.head().toLocal8Bit(); + + if(write(data) == -1){ qDebug() << "APRSISClient Write Error:" << errorString(); return; } - auto frame = m_frameQueue.dequeue(); - qDebug() << "APRISISClient Write:" << frame; + if(!waitForBytesWritten(5000)){ + qDebug() << "APRSISClient Cannot Write Error: Write Timeout"; + return; + } + + qDebug() << "APRSISClient Write:" << data; + + if(waitForReadyRead(5000)){ + line = QString(readLine()); + + qDebug() << "APRSISClient Read:" << line; + + if(line.toLower().indexOf(re) >= 0){ + qDebug() << "APRSISClient Cannot Write Error:" << line; + return; + } + } + + m_frameQueue.dequeue(); } if(disconnect){ diff --git a/APRSISClient.h b/APRSISClient.h index 0f067d2..ca1ebf4 100644 --- a/APRSISClient.h +++ b/APRSISClient.h @@ -26,7 +26,7 @@ public: void enqueueThirdParty(QString theircall, QString payload); void enqueueRaw(QString aprsFrame); - void processQueue(bool disconnect=false); + void processQueue(bool disconnect=true); public slots: void sendReports(){ processQueue(true); }