aboutsummaryrefslogtreecommitdiff
path: root/client/Client.cpp
diff options
context:
space:
mode:
authorUnavailableDev <69792062+UnavailableDev@users.noreply.github.com>2022-10-30 10:57:11 +0100
committerUnavailableDev <69792062+UnavailableDev@users.noreply.github.com>2022-10-30 10:57:50 +0100
commit8952e19f00e0930e53e3731fd30be5e2600d9fd6 (patch)
tree2770bfd4319402c88b6872d1f8699252329c6603 /client/Client.cpp
parent6d9df6fe97502a852b68c8c8e6781d7208170cae (diff)
parent60f954dbaa399f8f0bcaeeb307953fc3b37b9dc7 (diff)
finish merge
Diffstat (limited to 'client/Client.cpp')
-rw-r--r--client/Client.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/client/Client.cpp b/client/Client.cpp
new file mode 100644
index 0000000..46952b6
--- /dev/null
+++ b/client/Client.cpp
@@ -0,0 +1,65 @@
+#include "Client.h"
+
+
+
+Client::Client(QObject *parent) : QObject(parent)
+{
+ // initislise timer and socket
+ socket = new QTcpSocket(this);
+ timer = new QTimer(this);
+}
+Client::~Client()
+{
+ // delete if called again
+ delete socket;
+ delete timer;
+}
+
+void Client::ClientEcho()
+{
+ QTime time1 = QTime::currentTime();
+ NextMinute = time1.minute()+1;
+
+ 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::timeFunction()
+{
+ if(_missingRecords>1){
+ totalRecords = _missingRecords;
+ }
+ else{
+ totalRecords=1;
+ }
+ QByteArray msgToSend= (msg.toUtf8() + totalRecords + offsetRecords +'\n');
+
+ QTime time = QTime::currentTime();
+ qint16 currentMinute = time.minute();
+
+ if(currentMinute==NextMinute){
+ socket->connectToHost(networkAddress, tcpPortAddress);
+
+ socket->write(msgToSend);
+ NextMinute++;
+ }
+}
+
+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();
+
+}