diff options
author | UnavailableDev <69792062+UnavailableDev@users.noreply.github.com> | 2022-10-30 17:42:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-30 17:42:03 +0100 |
commit | b82a9c44d0112f5433c4482e2e5802969515ce7d (patch) | |
tree | 907451385d246dc61b513f3a27043f32b058268a /client/Client.cpp | |
parent | 84341bc53bca3da581ba59f66bf4174420c83d3a (diff) | |
parent | fc95a016d13c1510a024888c1b87bbfe1a7f7601 (diff) |
Merge branch 'dev' into qt-settings
Diffstat (limited to 'client/Client.cpp')
-rw-r--r-- | client/Client.cpp | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/client/Client.cpp b/client/Client.cpp index 87afe99..2075fc2 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -18,46 +18,49 @@ Client::~Client() delete timer; } -void Client::ClientEcho() -{ - - connect(timer, SIGNAL(timeout()),this,SLOT(timeFunction())); // connect timer to time every minute - - // connect to readyread to receive data; - connect(socket,&QTcpSocket::readyRead, [&]() { - QTextStream T(socket); - QString text = T.readAll(); // reads all data - Handlemsg.ParseToSQL(Handlemsg.ParseMessage(text, (totalRecords-'0'))); - - - }); - - timer->start(1000); +void Client::ClientEcho() { + static unsigned int lineCounter = 0; + connect(timer, SIGNAL(timeout()),this,SLOT(timeFunction())); // connect timer to time every minute + + // connect to readyread to receive data; + connect(socket,&QTcpSocket::readyRead, [&]() { + QTextStream T(socket); + QString text = T.readAll(); // reads all data + lineCounter++; + if (lineCounter <= 2) return; + Handlemsg.ParseToSQL(text); + }); + + connect(socket, &QTcpSocket::disconnected, [&]() { + socket->disconnectFromHost(); + lineCounter = 0; + }); + + 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_MIN(WS_MAX(1, _missingRecords), 50); - 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 `tblMain` limit 1"); - - _missingRecords = queryTimeData.value(0).toInt(); + queryTimeData.exec("SELECT (unix_timestamp(now()) - unix_timestamp(`time`))/60 as delta FROM `tblMain` limit 1"); + queryTimeData.first(); + unsigned int secondsSinceLastRecord = queryTimeData.value(0).toInt(); + _missingRecords = secondsSinceLastRecord / WS_CLIENT_STATION_POLL_INTERVAL; } + |