From ea9463c3ba9335bc3d04dd04502ab9e67e8a718c Mon Sep 17 00:00:00 2001 From: lonkaars Date: Sun, 30 Oct 2022 20:33:41 +0100 Subject: finish merge --- .gitignore | 2 +- client/HandleMessage.cpp | 47 ++++++++++++++++++++++------------------------- client/makefile | 14 ++++++++++++++ makefile | 9 +++------ shared/shared.mk | 1 - shared/util.c | 9 +++++++++ shared/util.h | 9 +++++++++ stm32f091/makefile | 2 +- 8 files changed, 59 insertions(+), 34 deletions(-) create mode 100644 client/makefile delete mode 100644 shared/shared.mk diff --git a/.gitignore b/.gitignore index 312a36e..ebb34c7 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ stm32f091/main.elf stm32f091/main.bin # client-specific files -client/makefile +client/client.mk client/client client/moc_* client/ui_* diff --git a/client/HandleMessage.cpp b/client/HandleMessage.cpp index 02d7257..84f561b 100644 --- a/client/HandleMessage.cpp +++ b/client/HandleMessage.cpp @@ -1,4 +1,5 @@ #include "HandleMessage.h" +#include "../shared/util.h" HandleMessage::HandleMessage(QObject *parent) : QObject(parent) { } @@ -20,31 +21,27 @@ HandleMessage::HandleMessage(QObject *parent) : QObject(parent) { } // } void HandleMessage::ParseToSQL(QString input) { - QSqlQuery queryInsertData; - QString output = "INSERT INTO `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(","); - } - } - queryInsertData.exec(output); + QSqlQuery queryInsertData; + QString output = "INSERT INTO `tblMain` (`temperature`, `humidity`, `pressure`) VALUES "; + QStringList data; + QStringList list = input.split("\n"); + for (int i = 0; i < list.size(); ++i) { + if (list[i].size() == 0) continue; + data=list[i].split(","); + bool valid; + + output.append("("); + output.append(QString::number(ws_sensor_tmp_to_f(data[1].toInt(&valid, 16)))); + output.append(","); + output.append(QString::number(ws_sensor_hum_to_f(data[2].toInt(&valid, 16)))); + output.append(","); + output.append(QString::number(ws_sensor_atm_to_f(data[3].toInt(&valid, 16)))); + output.append(")"); + + if (i+1 < list.size()) output.append(","); + } + printf("%s\n", output.toStdString().c_str()); + queryInsertData.exec(output); } diff --git a/client/makefile b/client/makefile new file mode 100644 index 0000000..a87857a --- /dev/null +++ b/client/makefile @@ -0,0 +1,14 @@ +all: client + +ifeq ($(wildcard client.mk),) +client.mk: + qmake client.pro -o client.mk +endif + +include client.mk + +OBJECTS += $(patsubst %.c,%.o, $(wildcard ../shared/*.c)) +client: $(OBJECTS) + +../shared/%.o: ../shared/%.c + $(CC) -c $(CFLAGS) -w $< -o $@ diff --git a/makefile b/makefile index 31ff4bf..eb70910 100644 --- a/makefile +++ b/makefile @@ -4,14 +4,11 @@ clean: make -C client clean make -C stm32f091 clean -client_makefile: - qmake client/client.pro -o client/makefile +client_compile_commands: + compiledb -o client/compile_commands.json make -BnC client -client: client_makefile +client: make -j -C client -client_compile_commands: client_makefile - compiledb -o client/compile_commands.json make -BnC client - stm32: make -j -C stm32f091 diff --git a/shared/shared.mk b/shared/shared.mk deleted file mode 100644 index f9586ff..0000000 --- a/shared/shared.mk +++ /dev/null @@ -1 +0,0 @@ -OBJS += $(patsubst %.c,%-stm.o, $(wildcard ../shared/*.c)) diff --git a/shared/util.c b/shared/util.c index 648631a..94f2273 100644 --- a/shared/util.c +++ b/shared/util.c @@ -6,6 +6,10 @@ unsigned int ws_log16(unsigned int x) { return l; } +#ifdef __cplusplus +extern "C" { +#endif + uint8_t ws_sensor_tmp_to_8(uint16_t temperature) { return temperature / 256; } @@ -29,3 +33,8 @@ float ws_sensor_hum_to_f(uint8_t humidity) { float ws_sensor_atm_to_f(uint8_t atmospheric_pressure) { return ((20.0 * atmospheric_pressure) / 256.0) + 990.0; // datasheet no? } + +#ifdef __cplusplus +} +#endif + diff --git a/shared/util.h b/shared/util.h index 1bee487..8cb54c1 100644 --- a/shared/util.h +++ b/shared/util.h @@ -8,6 +8,10 @@ /** @brief take the log base 16 of `x` */ unsigned int ws_log16(unsigned int x); +#ifdef __cplusplus +extern "C" { +#endif + /** @brief convert 16-bit temperature value to uint8_t */ uint8_t ws_sensor_tmp_to_8(uint16_t temperature); /** @brief convert 16-bit humidity value to uint8_t */ @@ -21,3 +25,8 @@ float ws_sensor_tmp_to_f(uint8_t temperature); float ws_sensor_hum_to_f(uint8_t humidity); /** @brief convert 8-bit atmospheric pressure value back to float */ float ws_sensor_atm_to_f(uint8_t atmospheric_pressure); + +#ifdef __cplusplus +} +#endif + diff --git a/stm32f091/makefile b/stm32f091/makefile index dd03761..7ac73a0 100644 --- a/stm32f091/makefile +++ b/stm32f091/makefile @@ -6,7 +6,7 @@ RM = rm -f TARGET = main HOST=$(strip $(shell uname -o)) -include ../shared/shared.mk +OBJS += $(patsubst %.c,%-stm.o, $(wildcard ../shared/*.c)) SHARED_FLAGS += -g SHARED_FLAGS += -DSTM32F091xC -- cgit v1.2.3