From d0be37d448b86be98aedd4d7b0c0ba8ef8348efd Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Fri, 8 Dec 2023 23:30:42 +0000 Subject: [PATCH 1/2] Rename from .ino to .cpp --- sensor/src/{sensor.ino => sensor.cpp} | 10 +++++++--- sensor/src/{telnet.ino => telnet.h} | 0 sensor/src/{webserver.ino => webstatus.h} | 0 3 files changed, 7 insertions(+), 3 deletions(-) rename sensor/src/{sensor.ino => sensor.cpp} (99%) rename sensor/src/{telnet.ino => telnet.h} (100%) rename sensor/src/{webserver.ino => webstatus.h} (100%) diff --git a/sensor/src/sensor.ino b/sensor/src/sensor.cpp similarity index 99% rename from sensor/src/sensor.ino rename to sensor/src/sensor.cpp index 91d7d8a..4991f2c 100644 --- a/sensor/src/sensor.ino +++ b/sensor/src/sensor.cpp @@ -154,6 +154,13 @@ ArduinoQueue sendBuffer(10); // TODO: might be better bigger for large unsigned long msgStartTime; unsigned long timeSinceMsgStart; +byte nibble(char c); +void hexCharacterStringToBytes(byte* byteArray, const char* hexString); +void handleMessage(size_t len, uint8_t buf[]); +String HexString2TimeString(String hexstring); +String HexString2ASCIIString(String hexstring); +void sendCommand(); + void clearRXbuffer(void) { // clear the rx buffer #if defined(ESP32) || defined(RSC3) @@ -1002,10 +1009,7 @@ void hexCharacterStringToBytes(byte* byteArray, const char* hexString) { byte nibble(char c) { if (c >= '0' && c <= '9') return c - '0'; - if (c >= 'a' && c <= 'f') return c - 'a' + 10; - if (c >= 'A' && c <= 'F') return c - 'A' + 10; - return 0; // Not a valid hexadecimal character } diff --git a/sensor/src/telnet.ino b/sensor/src/telnet.h similarity index 100% rename from sensor/src/telnet.ino rename to sensor/src/telnet.h diff --git a/sensor/src/webserver.ino b/sensor/src/webstatus.h similarity index 100% rename from sensor/src/webserver.ino rename to sensor/src/webstatus.h From d134fb4e2abd0adac0901f5df5a5350f5b1e5cb2 Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Fri, 8 Dec 2023 23:34:53 +0000 Subject: [PATCH 2/2] Fix ordering --- sensor/src/sensor.cpp | 32 ++++++++++++++++++-------------- sensor/src/webstatus.h | 7 ++++--- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/sensor/src/sensor.cpp b/sensor/src/sensor.cpp index 4991f2c..c671b1e 100644 --- a/sensor/src/sensor.cpp +++ b/sensor/src/sensor.cpp @@ -154,6 +154,24 @@ ArduinoQueue sendBuffer(10); // TODO: might be better bigger for large unsigned long msgStartTime; unsigned long timeSinceMsgStart; +String result = ""; +String lastRaw = ""; +String lastRaw2 = ""; +String lastRaw3 = ""; +String lastRaw4 = ""; +String lastRaw5 = ""; +String lastRaw6 = ""; +String lastFB = ""; +String lastJSON = ""; +uint32_t lastUptime = 0; +String timeString = ""; +int msgLength = 0; +boolean panelDetected = false; +const unsigned long readBytesTimeout = 2500; // Timeout in microseconds (2.5 ms) + +#include "telnet.h" +#include "webstatus.h" + byte nibble(char c); void hexCharacterStringToBytes(byte* byteArray, const char* hexString); void handleMessage(size_t len, uint8_t buf[]); @@ -529,20 +547,6 @@ void setup() { digitalWrite(LED_BUILTIN, LOW); } -String result = ""; -String lastRaw = ""; -String lastRaw2 = ""; -String lastRaw3 = ""; -String lastRaw4 = ""; -String lastRaw5 = ""; -String lastRaw6 = ""; -String lastFB = ""; -String lastJSON = ""; -uint32_t lastUptime = 0; -String timeString = ""; -int msgLength = 0; -boolean panelDetected = false; -const unsigned long readBytesTimeout = 2500; // Timeout in microseconds (2.5 ms) /* * waitforGLBytes checks the first byte in the serial buffer diff --git a/sensor/src/webstatus.h b/sensor/src/webstatus.h index 6481686..2caccc2 100644 --- a/sensor/src/webstatus.h +++ b/sensor/src/webstatus.h @@ -15,6 +15,10 @@ void handleSend() { sendBuffer.enqueue(message); } +String getStatusJSON() { + return "{\"type\": \"status\", \"data\" : { \"temp\": \"" + String(tubTemp,1) + "\", \"heater\": " + (heaterState ? "true" : "false") + ", \"light\": " + (lightState ? "true" : "false") + ", \"mode\": \""+tubMode.getCurrentState()+"\", \"uptime\": " + lastUptime + ", \"state\": \"" + state + "\" } }"; +} + void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length) { switch (type) { @@ -44,6 +48,3 @@ void webSocketEvent(uint8_t num, WStype_t type, uint8_t * payload, size_t length } -String getStatusJSON() { - return "{\"type\": \"status\", \"data\" : { \"temp\": \"" + String(tubTemp,1) + "\", \"heater\": " + (heaterState ? "true" : "false") + ", \"light\": " + (lightState ? "true" : "false") + ", \"mode\": \""+tubMode.getCurrentState()+"\", \"uptime\": " + lastUptime + ", \"state\": \"" + state + "\" } }"; -}