diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/Client.cpp | 37 | ||||
-rw-r--r-- | client/Client.h | 2 |
2 files changed, 18 insertions, 21 deletions
diff --git a/client/Client.cpp b/client/Client.cpp index 4d948fa..e50be5e 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -35,29 +35,26 @@ void Client::ClientEcho() timer->start(1000); } -void Client::timeFunction() -{ - totalRecords = WS_MAX(1, _missingRecords); +void Client::timeFunction() { + if((QTime::currentTime().second() % WS_CLIENT_STATION_POLL_INTERVAL) != 0) return; - char* msg = NULL; - asprintf(&msg, "last-records %x %x\n", totalRecords, offsetRecords); - QByteArray msgToSend = msg; - free(msg); + this->missingRecords(); + totalRecords = WS_MAX(1, _missingRecords); - QTime time = QTime::currentTime(); - qint16 currentSeconds = time.second(); - if((currentSeconds % WS_CLIENT_STATION_POLL_INTERVAL) == 1){ + char* msg = NULL; + asprintf(&msg, "last-records %x %x\n", totalRecords, offsetRecords); + QByteArray msgToSend = msg; + free(msg); - socket->connectToHost(networkAddress, tcpPortAddress); - socket->write(msgToSend); - } + socket->connectToHost(networkAddress, tcpPortAddress); + socket->write(msgToSend); } -void Client::missingRecords() -{ - QSqlQuery queryTimeData; - queryTimeData.exec("SELECT (unix_timestamp(now()) - unix_timestamp(`time`))/60 as delta FROM `WSdb`.`tblMain` limit 1"); - - _missingRecords = queryTimeData.value(0).toInt(); - +void Client::missingRecords() { + QSqlQuery queryTimeData; + queryTimeData.exec("select unix_timestamp(now()) - unix_timestamp(time) as delta from WSdb.tblMain order by time desc limit 1"); + queryTimeData.first(); + unsigned int secondsSinceLastRecord = queryTimeData.value(0).toInt(); + _missingRecords = secondsSinceLastRecord / WS_CLIENT_STATION_POLL_INTERVAL; } + diff --git a/client/Client.h b/client/Client.h index b90e5e9..433aecf 100644 --- a/client/Client.h +++ b/client/Client.h @@ -25,7 +25,7 @@ public slots: private: void missingRecords(); - int _missingRecords; + int _missingRecords = 0; QTcpSocket *socket; // tcpsocket for communicating QTimer *timer; // timer to read every second what time it curruntly is. |