aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-10-30 14:34:49 +0100
committerlonkaars <loek@pipeframe.xyz>2022-10-30 14:34:49 +0100
commite892ee5639d0f538740e4f1d51284ec27039e270 (patch)
treecd6906c0c4f0f3290875d839ccb308e5d045da4e
parent762a3b76d9b3351a93d8156598a79eaec4c0ef90 (diff)
fix last record time delta fetch
-rw-r--r--client/Client.cpp37
-rw-r--r--client/Client.h2
-rw-r--r--makefile6
3 files changed, 21 insertions, 24 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.
diff --git a/makefile b/makefile
index 60e06ef..a94d2a0 100644
--- a/makefile
+++ b/makefile
@@ -8,10 +8,10 @@ client_makefile:
qmake client/client.pro -o client/makefile
client: client_makefile
- make -C client
+ make -jC client
client_compile_commands: client_makefile
- compiledb -o client/compile_commands.json make -C client
+ compiledb -o client/compile_commands.json make -BnC client
stm32:
- make -C stm32f091
+ make -jC stm32f091