aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUnavailableDev <69792062+UnavailableDev@users.noreply.github.com>2022-10-30 12:16:26 +0100
committerGitHub <noreply@github.com>2022-10-30 12:16:26 +0100
commit75064a08587bc960c06d2324a0334ee88441fb35 (patch)
tree601d4870582bae2077b83eb43b099995e1e98e29
parent1390db8f7332768a133ae846b90c98d43c9b9f74 (diff)
parente8b58762643f0a20454068e352738ecffc372c7e (diff)
Merge branch 'dev' into qt-settings
-rw-r--r--.gitignore4
-rw-r--r--client/Client.cpp26
-rw-r--r--client/Client.h15
-rw-r--r--client/HandleMessage.h2
-rw-r--r--client/client.pro1
-rw-r--r--client/consts.h5
-rw-r--r--client/dbconnector.h1
-rw-r--r--client/dbconnector.ui4
-rw-r--r--shared/wifi.def.h (renamed from stm32f091/wifi.def.h)1
-rw-r--r--stm32f091/consts.h5
-rw-r--r--stm32f091/esp8266.c2
-rw-r--r--stm32f091/readme.md3
-rw-r--r--stm32f091/util.h4
13 files changed, 40 insertions, 33 deletions
diff --git a/.gitignore b/.gitignore
index 68c9d32..e4eb018 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,14 +6,16 @@
# stm32-specific files
stm32f091/main.elf
stm32f091/main.bin
-stm32f091/wifi.h
# client-specific files
client/makefile
client/client
client/moc_*
+client/ui_*
+**/.user
# others
+shared/wifi.h
shared/main
.qmake.stash
.vscode/.cortex-debug.registers.state.json
diff --git a/client/Client.cpp b/client/Client.cpp
index 46952b6..4d948fa 100644
--- a/client/Client.cpp
+++ b/client/Client.cpp
@@ -1,5 +1,8 @@
-#include "Client.h"
+#include <stdio.h>
+#include "Client.h"
+#include "consts.h"
+#include "../shared/util.h"
Client::Client(QObject *parent) : QObject(parent)
@@ -17,8 +20,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
@@ -36,22 +37,19 @@ 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 currentMinute = time.minute();
+ qint16 currentSeconds = time.second();
+ if((currentSeconds % WS_CLIENT_STATION_POLL_INTERVAL) == 1){
- if(currentMinute==NextMinute){
socket->connectToHost(networkAddress, tcpPortAddress);
-
socket->write(msgToSend);
- NextMinute++;
}
}
diff --git a/client/Client.h b/client/Client.h
index 10af3e1..b90e5e9 100644
--- a/client/Client.h
+++ b/client/Client.h
@@ -1,5 +1,6 @@
#ifndef CLIENT_H
#define CLIENT_H
+
#include <QTcpSocket>
#include <QTextStream>
#include <QTimer>
@@ -7,6 +8,7 @@
#include <QSqlQuery>
#include "HandleMessage.h"
+#include "../shared/wifi.h"
// class client for wheather station
class Client : public QObject
@@ -27,19 +29,14 @@ private:
QTcpSocket *socket; // tcpsocket for communicating
QTimer *timer; // timer to read every second what time it curruntly is.
- qint16 NextMinute; // timing for next minute
// qint16 currentMinute; // timing for currentMinute
HandleMessage Handlemsg; // add HandleMessage to Client.h
- int tcpPortAddress = 80; // port of communication via tcp
- QString networkAddress = "192.168.137.76"; // 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
-
-
+ int tcpPortAddress = WS_SERVER_PORT; // port of communication via tcp
+ QString networkAddress = WS_ESP8266_WLAN_IP; // network address for commincation via tcp
+ uint8_t totalRecords = 1; // total records to ask wheather station
+ uint8_t offsetRecords = 0; // offset from reqeusting records
};
#endif // CLIENT_H
diff --git a/client/HandleMessage.h b/client/HandleMessage.h
index bfc5063..f228633 100644
--- a/client/HandleMessage.h
+++ b/client/HandleMessage.h
@@ -16,8 +16,6 @@ public:
QString ParseMessage(const QString , int);
void ParseToSQL(QString);
-
-
private:
};
diff --git a/client/client.pro b/client/client.pro
index 76f2b56..8305949 100644
--- a/client/client.pro
+++ b/client/client.pro
@@ -3,6 +3,7 @@ QT += core gui sql charts network
HEADERS += \
Client.h \
HandleMessage.h \
+ consts.h \
dbconnector.h \
main.h \
mainwindow.h
diff --git a/client/consts.h b/client/consts.h
new file mode 100644
index 0000000..7ee81c8
--- /dev/null
+++ b/client/consts.h
@@ -0,0 +1,5 @@
+#pragma once
+
+// delay between new record request in seconds
+#define WS_CLIENT_STATION_POLL_INTERVAL 10
+
diff --git a/client/dbconnector.h b/client/dbconnector.h
index 4737d6f..5b9b1cf 100644
--- a/client/dbconnector.h
+++ b/client/dbconnector.h
@@ -8,7 +8,6 @@
#define WS_ESP8266_WLAN_IP "129.168.0.1"
-
namespace Ui {
class dbConnector;
}
diff --git a/client/dbconnector.ui b/client/dbconnector.ui
index 22e0a64..fe9c05e 100644
--- a/client/dbconnector.ui
+++ b/client/dbconnector.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>362</width>
- <height>273</height>
+ <width>401</width>
+ <height>288</height>
</rect>
</property>
<property name="windowTitle">
diff --git a/stm32f091/wifi.def.h b/shared/wifi.def.h
index 61e1706..aead0b6 100644
--- a/stm32f091/wifi.def.h
+++ b/shared/wifi.def.h
@@ -4,4 +4,5 @@
#define WS_ESP8266_WLAN_PASSWD "12345678"
// #define WS_ESP8266_WLAN_MAC "f2:9b:89:47:c4:f3"
// #define WS_ESP8266_WLAN_IP "192.168.2.69"
+#define WS_SERVER_PORT 80
diff --git a/stm32f091/consts.h b/stm32f091/consts.h
index 3d2ef5a..6d5b8d2 100644
--- a/stm32f091/consts.h
+++ b/stm32f091/consts.h
@@ -1,9 +1,10 @@
#pragma once
-#include "wifi.h"
+#include "../shared/wifi.h"
+#include "util.h"
-#define WS_SERVER_PORT "80"
#define WS_SERVER_MAX_CHANNELS 4
+#define WS_SERVER_PORT_STR WS_MTS(WS_SERVER_PORT)
#define WS_DMA_RX_BUFFER_SIZE 100
#define WS_DMA_TX_BUFFER_SIZE 1024
diff --git a/stm32f091/esp8266.c b/stm32f091/esp8266.c
index 74ec347..8ff9547 100644
--- a/stm32f091/esp8266.c
+++ b/stm32f091/esp8266.c
@@ -77,7 +77,7 @@ void ws_esp8266_ap_client_mode() {
void ws_esp8266_start_tcp_server() {
ws_esp8266_send_seq("AT+CIPSERVER=0\r\n"); // stop tcp server (if running)
ws_esp8266_send_seq("AT+CIPMUX=1\r\n"); // enable multiplexing (allow multiple connections)
- ws_esp8266_send_seq("AT+CIPSERVER=1," WS_SERVER_PORT "\r\n"); // start tcp server
+ ws_esp8266_send_seq("AT+CIPSERVER=1," WS_SERVER_PORT_STR "\r\n"); // start tcp server
}
void ws_esp8266_set_mac() {
diff --git a/stm32f091/readme.md b/stm32f091/readme.md
index d2758b5..e6af60f 100644
--- a/stm32f091/readme.md
+++ b/stm32f091/readme.md
@@ -3,7 +3,8 @@
- uses make
- make sure to initialize the git submodules
- all warnings from source files in the lib/ subfolder are hidden
-- copy wifi.def.h to wifi.h and edit the network credentials
+- copy ../shared/wifi.def.h to ../shared/wifi.h and edit the network
+ credentials
- the initialization code is broken in some way which means that a soft reset
is required for the uart dma to work, either (a) press the reset button on
the development board after plugging in, or (b) run `st-flash reset` after
diff --git a/stm32f091/util.h b/stm32f091/util.h
index 11bee6f..9c15f8b 100644
--- a/stm32f091/util.h
+++ b/stm32f091/util.h
@@ -8,6 +8,10 @@
#include "setup.h"
#include "../shared/util.h"
+// macro to string macro's
+#define WS_MTS_EXPAND(x) #x
+#define WS_MTS(x) WS_MTS_EXPAND(x)
+
#define WS_DBG_TTY_COLOR_BLK 0x0
#define WS_DBG_TTY_COLOR_RED 0x1
#define WS_DBG_TTY_COLOR_GRN 0x2