aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-10-30 15:55:56 +0100
committerlonkaars <loek@pipeframe.xyz>2022-10-30 15:55:56 +0100
commit0c8e3c7e6cdc99a14b38edd747d07d7b03fb294c (patch)
treefda541fb5f170a3df6f51ab6ac8ad9f726dc3d49
parenta2f62610144d1ba496ece3946a1e64fe8d6e0f9c (diff)
client fix
-rw-r--r--client/Client.cpp30
-rw-r--r--client/HandleMessage.cpp47
-rw-r--r--client/HandleMessage.h2
3 files changed, 31 insertions, 48 deletions
diff --git a/client/Client.cpp b/client/Client.cpp
index e50be5e..61e51e4 100644
--- a/client/Client.cpp
+++ b/client/Client.cpp
@@ -18,28 +18,32 @@ 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')));
+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);
+ timer->start(1000);
}
void Client::timeFunction() {
if((QTime::currentTime().second() % WS_CLIENT_STATION_POLL_INTERVAL) != 0) return;
this->missingRecords();
- totalRecords = WS_MAX(1, _missingRecords);
+ totalRecords = WS_MIN(WS_MAX(1, _missingRecords), 50);
char* msg = NULL;
asprintf(&msg, "last-records %x %x\n", totalRecords, offsetRecords);
diff --git a/client/HandleMessage.cpp b/client/HandleMessage.cpp
index dc25b21..a6b9ce4 100644
--- a/client/HandleMessage.cpp
+++ b/client/HandleMessage.cpp
@@ -1,43 +1,24 @@
#include "HandleMessage.h"
+HandleMessage::HandleMessage(QObject *parent) : QObject(parent) { }
-HandleMessage::HandleMessage(QObject *parent) : QObject(parent)
-{
+void HandleMessage::ParseToSQL(QString input) {
+ QSqlQuery queryInsertData;
+ QString output = "insert into WSdb.tblMain (temperature, humidity, pressure) values ";
+ QStringList data;
-}
-
-QString HandleMessage::ParseMessage(const QString Msg , int totalRecords )
-{
- QString message= Msg.section('\n',2,(3+totalRecords));
+ output.append("(");
+ data=input.split(",");
- return message;
+ for (int i = 1; i < data.size(); i++) {
+ bool valid;
+ output.append(QString::number(data[i].toInt(&valid, 16)));
+ if (i + 1 < data.size()) output.append(",");
+ }
-}
+ output.append(")");
-void HandleMessage::ParseToSQL(QString input)
-{
- QSqlQuery queryInsertData;
- QString output = "insert into WSdb.tblMain (temperature, humidity, pressure) values ";
- QStringList data;
- QStringList list = input.split("\n");
- for (int i = 0; i < list.size(); ++i) {
- output += "(";
- data=list[i].split(",");
- for (int j = 1; j < data.size(); ++j) {
- bool valid;
- output.append(QString::number(data[j].toInt(&valid, 16)));
- if (j <= data[j].size()) {
- output.append(",");
- }
-
- }
- output.append(")");
- if (i+1 < list.size()){
- output.append(",");
- }
- }
- printf("%s\n", output.toStdString().c_str());
- queryInsertData.exec(output);
+ queryInsertData.exec(output);
}
diff --git a/client/HandleMessage.h b/client/HandleMessage.h
index f228633..f5995c7 100644
--- a/client/HandleMessage.h
+++ b/client/HandleMessage.h
@@ -12,8 +12,6 @@ class HandleMessage : public QObject
Q_OBJECT
public:
HandleMessage(QObject *parent = 0);
-
- QString ParseMessage(const QString , int);
void ParseToSQL(QString);
private: