From 19acffbe11a171e7d0a5889d8af4936a2c425cdb Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Tue, 18 Sep 2018 17:36:11 +0200 Subject: [PATCH] Fixed bug, that made the timeout look like an empty response --- sources/buzzerconn.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/sources/buzzerconn.cpp b/sources/buzzerconn.cpp index a8960d2..80b17be 100644 --- a/sources/buzzerconn.cpp +++ b/sources/buzzerconn.cpp @@ -51,13 +51,14 @@ bool BuzzerConn::connect() //wait for the connection to finish loop.exec(); - timer.stop(); - if(timer.remainingTime() == 0){ + //loop finished + if(timer.remainingTime() == -1){ //the time has been triggered -> timeout setState("disconnected"); return(false); } + timer.stop(); QList times = gettimes(2000, true); @@ -115,7 +116,6 @@ QList BuzzerConn::gettimes(int timeout, bool bothTimes) QList times; signed long ret; ret = this->sendCommand("GET_TIMESTAMP", timeout); - qDebug() << timeout << bothTimes; if(ret >= 0){ times.append(double(200)); @@ -262,15 +262,17 @@ signed long BuzzerConn::sendCommand(QString command, int timeout){ loop.exec(); //loop finished - timer.stop(); - if(timer.remainingTime() == 0){ + if(timer.remainingTime() == -1){ //the time has been triggered -> timeout return(-1); } + timer.stop(); + + //if the data is not 4 bytes long it is invalid -> clear and terminate if(this->socket->bytesAvailable() != 4){ - qDebug() << this->socket->readAll(); + this->socket->readAll(); return(-2); } long data = 0;