blob: 4d948fa9df488f96e447d33b2a7f916982d50098 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
#include <stdio.h>
#include "Client.h"
#include "consts.h"
#include "../shared/util.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()
{
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()
{
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();
if((currentSeconds % WS_CLIENT_STATION_POLL_INTERVAL) == 1){
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();
}
|