From eb10a1a6dc03d83284788128d3f77ff57852c3c6 Mon Sep 17 00:00:00 2001 From: NielsCoding Date: Sun, 30 Oct 2022 10:15:05 +0100 Subject: intervals added and consts.h --- client/Client.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'client/Client.cpp') diff --git a/client/Client.cpp b/client/Client.cpp index 46952b6..01c3867 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -1,5 +1,5 @@ #include "Client.h" - +#include "consts.h" Client::Client(QObject *parent) : QObject(parent) @@ -17,8 +17,6 @@ Client::~Client() void Client::ClientEcho() { - QTime time1 = QTime::currentTime(); - NextMinute = time1.minute()+1; connect(timer, SIGNAL(timeout()),this,SLOT(timeFunction())); // connect timer to time every minute @@ -45,13 +43,12 @@ void Client::timeFunction() QByteArray msgToSend= (msg.toUtf8() + totalRecords + offsetRecords +'\n'); QTime time = QTime::currentTime(); - qint16 currentMinute = time.minute(); + qint16 currentSeconds = time.second(); + auto _intervals = intervals; + if(currentSeconds % _intervals==0){ - if(currentMinute==NextMinute){ socket->connectToHost(networkAddress, tcpPortAddress); - socket->write(msgToSend); - NextMinute++; } } -- cgit v1.2.3 From e8b58762643f0a20454068e352738ecffc372c7e Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 30 Oct 2022 11:40:14 +0100 Subject: fix request send routine --- client/Client.cpp | 16 +++++++++------- client/Client.h | 5 ++--- 2 files changed, 11 insertions(+), 10 deletions(-) (limited to 'client/Client.cpp') diff --git a/client/Client.cpp b/client/Client.cpp index 10d288e..4d948fa 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -1,5 +1,8 @@ +#include + #include "Client.h" #include "consts.h" +#include "../shared/util.h" Client::Client(QObject *parent) : QObject(parent) @@ -34,13 +37,12 @@ void Client::ClientEcho() void Client::timeFunction() { - if(_missingRecords>1){ - totalRecords = _missingRecords; - } - else{ - totalRecords=1; - } - QByteArray msgToSend= (msg.toUtf8() + totalRecords + offsetRecords +'\n'); + totalRecords = WS_MAX(1, _missingRecords); + + char* msg = NULL; + asprintf(&msg, "last-records %x %x\n", totalRecords, offsetRecords); + QByteArray msgToSend = msg; + free(msg); QTime time = QTime::currentTime(); qint16 currentSeconds = time.second(); diff --git a/client/Client.h b/client/Client.h index f675a89..b90e5e9 100644 --- a/client/Client.h +++ b/client/Client.h @@ -35,9 +35,8 @@ private: int tcpPortAddress = WS_SERVER_PORT; // port of communication via tcp QString networkAddress = WS_ESP8266_WLAN_IP; // network address for commincation via tcp - QString msg = "last-records "; // part of mesage to send to wheather staion - char totalRecords = '1'; // total records to ask wheather station - char offsetRecords = '0'; // offset from reqeusting records + uint8_t totalRecords = 1; // total records to ask wheather station + uint8_t offsetRecords = 0; // offset from reqeusting records }; #endif // CLIENT_H -- cgit v1.2.3