Fixed bug, that made the timeout look like an empty response

This commit is contained in:
Dorian Zedler 2018-09-18 17:36:11 +02:00
parent 2849dc0e3b
commit 19acffbe11

View file

@ -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<double> times = gettimes(2000, true);
@ -115,7 +116,6 @@ QList<double> BuzzerConn::gettimes(int timeout, bool bothTimes)
QList<double> 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;