From 1b98abe7e801369dff141c36fd853cc16af62090 Mon Sep 17 00:00:00 2001 From: Visualapproach Date: Sat, 8 Jun 2024 19:01:55 +0200 Subject: [PATCH] Add signal quality for 4-wire comms When logging using /debug-on/ --- Code/lib/BWC_unified/FW_VERSION.h | 2 +- Code/lib/BWC_unified/bwc.cpp | 26 ++++++++++++++++++++++---- Code/lib/cio/CIO_4W.cpp | 2 +- Code/lib/cio/CIO_BASE.h | 1 + Code/lib/dsp/DSP_4W.cpp | 1 + Code/lib/dsp/DSP_BASE.h | 1 + Code/platformio.ini | 6 +++--- 7 files changed, 30 insertions(+), 9 deletions(-) diff --git a/Code/lib/BWC_unified/FW_VERSION.h b/Code/lib/BWC_unified/FW_VERSION.h index 6a8375e7..705611ed 100644 --- a/Code/lib/BWC_unified/FW_VERSION.h +++ b/Code/lib/BWC_unified/FW_VERSION.h @@ -1 +1 @@ -#define FW_VERSION "2024-06-06-0950" +#define FW_VERSION "2024-06-08-1820" diff --git a/Code/lib/BWC_unified/bwc.cpp b/Code/lib/BWC_unified/bwc.cpp index 1eb318e3..ef3c788c 100644 --- a/Code/lib/BWC_unified/bwc.cpp +++ b/Code/lib/BWC_unified/bwc.cpp @@ -252,9 +252,17 @@ void BWC::_log() // Serial.println(F("Failed to save states.txt")); return; } - if(++writes > 1000) return; - file.print(_timestamp_secs); - file.printf_P(PSTR("SW:%s \nCIO-ESP:"), FW_VERSION); + if(++writes > 1000) + { + file.printf_P(PSTR("\n**** MAX LENGTH OF FILE REACHED. DELETE FILE TO LOG AGAIN")); + return; + } + + tm * p_time_tm = gmtime((time_t*) &_timestamp_secs); + char tm_string[64]; + strftime(tm_string, 64, "%F %T", p_time_tm); + file.print(tm_string); + file.printf_P(PSTR("UTC. SW:%s \nCIO-ESP:"), FW_VERSION); for(unsigned int i = 0; i< fromcio.size(); i++) { if(i>0)file.print(','); @@ -278,7 +286,17 @@ void BWC::_log() if(i>0)file.print(','); file.print(todsp[i], HEX); } - file.printf_P(PSTR("\nCIO msg count: %d DSP msg count: %d\n"), cio->good_packets_count, dsp->good_packets_count); + file.printf_P(PSTR("\nCIO msg count: %d DSP msg count: %d"), cio->good_packets_count, dsp->good_packets_count); + float CIO_quality, DSP_quality; + if(cio->good_packets_count == 0 && cio->bad_packets_count == 0) + CIO_quality = 0; + else + CIO_quality = 100 * cio->good_packets_count / (cio->good_packets_count + cio->bad_packets_count); + if(dsp->good_packets_count == 0 && dsp->bad_packets_count == 0) + DSP_quality = 0; + else + DSP_quality = 100 * dsp->good_packets_count / (dsp->good_packets_count + dsp->bad_packets_count); + file.printf_P(PSTR("\nCIO msg quality: %f%% DSP msg quality: %f%% (Only useful in 4 wire pumps)\n\n"), CIO_quality, DSP_quality); file.close(); } diff --git a/Code/lib/cio/CIO_4W.cpp b/Code/lib/cio/CIO_4W.cpp index c2114af8..8c0257f5 100644 --- a/Code/lib/cio/CIO_4W.cpp +++ b/Code/lib/cio/CIO_4W.cpp @@ -194,7 +194,7 @@ void CIO_4W::updateStates() calculatedChecksum = tempbuffer[1]+tempbuffer[2]+tempbuffer[3]+tempbuffer[4]; if(tempbuffer[CIO_CHECKSUMINDEX] != calculatedChecksum) { - //badCIO_checksum++; + bad_packets_count++; return; } /*message is good if we get here. Continue*/ diff --git a/Code/lib/cio/CIO_BASE.h b/Code/lib/cio/CIO_BASE.h index 06678e83..e69d3d9f 100644 --- a/Code/lib/cio/CIO_BASE.h +++ b/Code/lib/cio/CIO_BASE.h @@ -36,6 +36,7 @@ class CIO sToggles cio_toggles; int _button_que_len = 0; //length of buttonQ uint32_t good_packets_count = 0; + uint32_t bad_packets_count = 0; std::vector _raw_payload_to_cio = {0,0,0,0,0,0,0,0,0,0,0}; int write_msg_count = 0; diff --git a/Code/lib/dsp/DSP_4W.cpp b/Code/lib/dsp/DSP_4W.cpp index 601b4bb0..f0ba6fa2 100644 --- a/Code/lib/dsp/DSP_4W.cpp +++ b/Code/lib/dsp/DSP_4W.cpp @@ -56,6 +56,7 @@ void DSP_4W::updateToggles() calculatedChecksum = tempbuffer[1]+tempbuffer[2]+tempbuffer[3]+tempbuffer[4]; if(tempbuffer[DSP_CHECKSUMINDEX] != calculatedChecksum) { + bad_packets_count++; return; } /*message is good if we get here. Continue*/ diff --git a/Code/lib/dsp/DSP_BASE.h b/Code/lib/dsp/DSP_BASE.h index 1e443998..5164eb49 100644 --- a/Code/lib/dsp/DSP_BASE.h +++ b/Code/lib/dsp/DSP_BASE.h @@ -25,6 +25,7 @@ class DSP std::vector _raw_payload_to_dsp = {0,0,0,0,0,0,0,0,0,0,0}; int audiofrequency = 0; uint32_t good_packets_count = 0; + uint32_t bad_packets_count = 0; int write_msg_count = 0; /* diff --git a/Code/platformio.ini b/Code/platformio.ini index 085b350c..e32338b8 100644 --- a/Code/platformio.ini +++ b/Code/platformio.ini @@ -18,14 +18,14 @@ platform = espressif8266@^4 board = nodemcuv2 framework = arduino lib_deps = - bblanchon/ArduinoJson@6.21.2 + bblanchon/ArduinoJson@6.21.2 ; v7 is using more memory ; mcxiaoke/ESPDateTime links2004/WebSockets knolleary/PubSubClient me-no-dev/ESPAsyncTCP ; khoih-prog/ESP_WifiManager@^1.12.1 - tzapu/WifiManager - https://github.com/dok-net/ghostl ; << Fix missing circular_queue.h in plerup/EspSoftwareSerial@8.2.0 + tzapu/WifiManager + https://github.com/dok-net/ghostl ; << Fix missing circular_queue.h in plerup/EspSoftwareSerial@8.2.0 plerup/EspSoftwareSerial milesburton/DallasTemperature board_build.filesystem = littlefs