From 97f34331588c3d6652b41597dc6e7df3bdced743 Mon Sep 17 00:00:00 2001 From: Ray Jones Date: Wed, 6 May 2020 10:41:26 +1000 Subject: [PATCH] BIG FIXES: External thermostat start denied if internal thermostat too high Pump priming from web page only worked once - was because prime command was never released from heater. --- src/Afterburner.cpp | 4 ++-- src/Protocol/BlueWireTask.cpp | 26 ++++++++++++-------------- src/Protocol/Protocol.cpp | 15 ++++++++------- src/Protocol/SmartError.cpp | 18 ++++++++++++++++-- src/Protocol/SmartError.h | 4 +++- src/Protocol/TxManage.cpp | 8 ++++++++ src/Protocol/TxManage.h | 2 ++ src/Utility/DemandManager.cpp | 26 ++++++++++++++------------ src/WiFi/BTCWebServer.cpp | 8 ++++---- 9 files changed, 69 insertions(+), 42 deletions(-) diff --git a/src/Afterburner.cpp b/src/Afterburner.cpp index ea916b1..9c144f1 100644 --- a/src/Afterburner.cpp +++ b/src/Afterburner.cpp @@ -202,7 +202,7 @@ CSecuritySetup SecurityMenu; TaskHandle_t handleWatchdogTask; TaskHandle_t handleBlueWireTask; -extern TaskHandle_t handleSSLTask; +extern TaskHandle_t handleWebServerTask; // these variables will persist over a soft reboot. __NOINIT_ATTR float persistentRunTime; @@ -647,7 +647,7 @@ bool checkTemperatureSensors() DebugPort.printf(" Arduino: %d\r\n", uxTaskGetStackHighWaterMark(NULL)); DebugPort.printf(" BlueWire: %d\r\n", uxTaskGetStackHighWaterMark(handleBlueWireTask)); DebugPort.printf(" Watchdog: %d\r\n", uxTaskGetStackHighWaterMark(handleWatchdogTask)); - DebugPort.printf(" SSL loop: %d\r\n", uxTaskGetStackHighWaterMark(handleSSLTask)); + DebugPort.printf(" SSL loop: %d\r\n", uxTaskGetStackHighWaterMark(handleWebServerTask)); } TempSensor.readSensors(); diff --git a/src/Protocol/BlueWireTask.cpp b/src/Protocol/BlueWireTask.cpp index bf7ac81..34f40f2 100644 --- a/src/Protocol/BlueWireTask.cpp +++ b/src/Protocol/BlueWireTask.cpp @@ -53,6 +53,7 @@ CProtocol HeaterFrame2; // data packet received from heater in resp // CSmartError SmartError; CProtocolPackage reportHeaterData; CProtocolPackage primaryHeaterData; +char dbgMsg[BLUEWIRE_MSGQUEUESIZE]; static bool bHasOEMController = false; static bool bHasOEMLCDController = false; @@ -142,9 +143,8 @@ void BlueWireTask(void*) { if(RxTimeElapsed >= moderator) { moderator += 10; if(bReportRecyleEvents) { - char msg[32]; - sprintf(msg, "%ldms - ", RxTimeElapsed); - pushDebugMsg(msg); + sprintf(dbgMsg, "%ldms - ", RxTimeElapsed); + pushDebugMsg(dbgMsg); } if(CommState.is(CommStates::OEMCtrlRx)) { bHasOEMController = false; @@ -208,9 +208,8 @@ void BlueWireTask(void*) { if(BlueWireRxData.available() && (RxTimeElapsed > (RX_DATA_TIMOUT+10))) { if(bReportOEMresync) { - char msg[64]; - sprintf(msg, "Re-sync'd with OEM Controller. %ldms Idle time.\r\n", RxTimeElapsed); - pushDebugMsg(msg); + sprintf(dbgMsg, "Re-sync'd with OEM Controller. %ldms Idle time.\r\n", RxTimeElapsed); + pushDebugMsg(dbgMsg); } bHasHtrData = false; @@ -395,12 +394,11 @@ bool validateFrame(const CProtocol& frame, const char* name) { if(!frame.verifyCRC(pushDebugMsg)) { // Bad CRC - restart blue wire Serial port - char msg[128]; - sprintf(msg, "\007Bad CRC detected for %s frame - restarting blue wire's serial port\r\n", name); - pushDebugMsg(msg); - msg[0] = 0; // empty string - DebugReportFrame("BAD CRC:", frame, "\r\n", msg); - pushDebugMsg(msg); + sprintf(dbgMsg, "\007Bad CRC detected for %s frame - restarting blue wire's serial port\r\n", name); + pushDebugMsg(dbgMsg); + dbgMsg[0] = 0; // empty string + DebugReportFrame("BAD CRC:", frame, "\r\n", dbgMsg); + pushDebugMsg(dbgMsg); #ifdef REBOOT_BLUEWIRE initBlueWireSerial(); #endif @@ -415,7 +413,7 @@ void DebugReportFrame(const char* hdr, const CProtocol& Frame, const char* ftr, { strcat(msg, hdr); // header for(int i=0; i<24; i++) { - char str[16]; + char str[8]; sprintf(str, " %02X", Frame.Data[i]); // build 2 dig hex values strcat(msg, str); // and print } @@ -478,7 +476,7 @@ const char* getBlueWireStatStr() void reqPumpPrime(bool on) { - DefaultBTCParams.setPump_Prime(on); + TxManage.reqPrime(on); } diff --git a/src/Protocol/Protocol.cpp b/src/Protocol/Protocol.cpp index 1a2f607..0a5e98b 100644 --- a/src/Protocol/Protocol.cpp +++ b/src/Protocol/Protocol.cpp @@ -431,20 +431,21 @@ CProtocolPackage::setRefTime() _timeStamp.setRefTime(); }*/ +char dbgFrameMsg[192]; + void CProtocolPackage::reportFrames(bool isOEM, std::function pushMsg) { - char msg[192]; - msg[0] = 0; - _timeStamp.report(msg); // absolute time + dbgFrameMsg[0] = 0; + _timeStamp.report(dbgFrameMsg); // absolute time if(isOEM) { - DebugReportFrame("OEM:", Controller, TERMINATE_OEM_LINE ? "\r\n" : " ", msg); + DebugReportFrame("OEM:", Controller, TERMINATE_OEM_LINE ? "\r\n" : " ", dbgFrameMsg); } else { - DebugReportFrame("BTC:", Controller, TERMINATE_BTC_LINE ? "\r\n" : " ", msg); + DebugReportFrame("BTC:", Controller, TERMINATE_BTC_LINE ? "\r\n" : " ", dbgFrameMsg); } - DebugReportFrame("HTR:", Heater, "\r\n", msg); - pushMsg(msg); + DebugReportFrame("HTR:", Heater, "\r\n", dbgFrameMsg); + pushMsg(dbgFrameMsg); } int diff --git a/src/Protocol/SmartError.cpp b/src/Protocol/SmartError.cpp index c9d771a..96956bb 100644 --- a/src/Protocol/SmartError.cpp +++ b/src/Protocol/SmartError.cpp @@ -36,6 +36,7 @@ void CSmartError::reset() { _prevRunState = 0; + _prevPumpHz = 0; _Error = 0; _bInhibit = false; } @@ -61,14 +62,15 @@ CSmartError::monitor(const CProtocol& heaterFrame) { if(heaterFrame.verifyCRC(NULL)) { // check but don't report dodgy frames to debug // only accept valid heater frames! - monitor(heaterFrame.getRunState()); + _monitor(heaterFrame.getRunState()); + _monitorPriming(heaterFrame.getRunState(), heaterFrame.getPump_Actual()); } } // test the new run state value, comparing to previous // detect abnormal transitions void -CSmartError::monitor(uint8_t newRunState) +CSmartError::_monitor(uint8_t newRunState) { // check if moving away from heater Idle state (S0) // especially useful if an OEM controller exists @@ -209,3 +211,15 @@ CSmartError::checkfuelUsage(bool throwfault) } return retval; } + +void +CSmartError::_monitorPriming(uint8_t runState, uint8_t pumpHz) +{ + if(runState == 0 && pumpHz == 0 && _prevPumpHz != 0) { + TxManage.reqPrime(false); // cancel pump priming request upon heater auto stopping priming + } + if(runState != 0) { + TxManage.reqPrime(false); // ALWAYS cancel pump priming request upon heater running + } + _prevPumpHz = pumpHz; +} diff --git a/src/Protocol/SmartError.h b/src/Protocol/SmartError.h index 4ec52a8..913187c 100644 --- a/src/Protocol/SmartError.h +++ b/src/Protocol/SmartError.h @@ -23,14 +23,16 @@ class CSmartError { uint8_t _prevRunState; + uint8_t _prevPumpHz; uint8_t _Error; bool _bInhibit; + void _monitorPriming(uint8_t runState, uint8_t pumpHz); + void _monitor(uint8_t runstate); public: CSmartError(); void reset(); void inhibit(bool reseterror=false); void monitor(const CProtocol& heaterFrame); - void monitor(uint8_t runstate); int checkVolts(float volts, float plugI, bool throwfault=true); // 0 = OK, 1 = within 0.5V of LVC, 2 = under LVC int checkfuelUsage(bool throwfault=true); uint8_t getError(); diff --git a/src/Protocol/TxManage.cpp b/src/Protocol/TxManage.cpp index 3fc4403..eb074c5 100644 --- a/src/Protocol/TxManage.cpp +++ b/src/Protocol/TxManage.cpp @@ -70,6 +70,7 @@ CTxManage::CTxManage(int TxGatePin, HardwareSerial& serial) : _rawCommand = 0; m_HWTimer = NULL; _callback = NULL; + _prime = false; } // static function used for the tx gate termination @@ -178,6 +179,8 @@ CTxManage::PrepareFrame(const CProtocol& basisFrame, bool isBTCmaster) m_TxFrame.setAltitude(3500); // default height - yes it is weird, but that's what the simple controllers send! } + m_TxFrame.setPump_Prime(_prime); + float tActual = getTemperatureSensor(); int8_t s8Temp = (int8_t)(tActual + 0.5); m_TxFrame.setTemperature_Actual(s8Temp); // use current temp, for now @@ -338,3 +341,8 @@ CTxManage::CheckTx(unsigned long timenow) return m_nStartTime == 0; // returns true when done } +void +CTxManage::reqPrime(bool on) +{ + _prime = on; +} diff --git a/src/Protocol/TxManage.h b/src/Protocol/TxManage.h index 820efed..2ae3dd3 100644 --- a/src/Protocol/TxManage.h +++ b/src/Protocol/TxManage.h @@ -28,6 +28,7 @@ class CTxManage const int m_nFrontPorch = 0; int m_sysUpdate; std::function _callback; + bool _prime; public: CTxManage(int TxGatePin, HardwareSerial& serial); @@ -42,6 +43,7 @@ public: static void IRAM_ATTR callbackGateTerminate(); void queueSysUpdate(); // use to implant NV settings into heater void setCallback(std::function fn) { _callback = fn; }; + void reqPrime(bool on); private: HardwareSerial& m_BlueWireSerial; diff --git a/src/Utility/DemandManager.cpp b/src/Utility/DemandManager.cpp index 3668474..d89b8f5 100644 --- a/src/Utility/DemandManager.cpp +++ b/src/Utility/DemandManager.cpp @@ -123,28 +123,30 @@ CDemandManager::checkStart() // create a deny start temperature margin int stopDeltaT = 0; - int cyclicstop = NVstore.getUserSettings().cyclic.Stop; - if(cyclicstop) { // cyclic mode enabled - // if cylic mode, raise the margin by the cyclic stop range - stopDeltaT = cyclicstop + 1; // bump up by 1 degree - no point invoking cyclic at 1 deg over! - } - // determine temperature error vs desired thermostat value float deltaT = getTemperatureSensor() - getDegC(); - if(deltaT > stopDeltaT) { - // temperature exceeded the allowed margin - if(cyclicstop) { - // using cyclic mode - suggest immediate cyclic suspend + int cyclicstop = NVstore.getUserSettings().cyclic.Stop; + if(cyclicstop) { // cyclic mode enabled + // if cyclic mode, raise the margin by the cyclic stop range + stopDeltaT = cyclicstop + 1; // bump up by 1 degree - no point invoking cyclic at 1 deg over! + + // alows honour cyclic stop threshold - immediate suspend transition + if(deltaT > stopDeltaT) { return eStartSuspend; } - else { - // only deny start if actually using thermostat mode + } + + if(!isExtThermostatMode()) { + if(deltaT > stopDeltaT) { + // temperature exceeded the allowed margin + // only deny start if actually using inbuilt thermostat mode if(isThermostat()) { return eStartTooWarm; // too warm - deny start } } } + return eStartOK; // allow start } diff --git a/src/WiFi/BTCWebServer.cpp b/src/WiFi/BTCWebServer.cpp index e639f84..34a4bb5 100644 --- a/src/WiFi/BTCWebServer.cpp +++ b/src/WiFi/BTCWebServer.cpp @@ -77,9 +77,9 @@ void streamFileCoreSSL(const size_t fileSize, const String & fileName, const Str void processWebsocketQueue(); QueueHandle_t webSocketQueue = NULL; +TaskHandle_t handleWebServerTask; #if USE_HTTPS == 1 SSLCert* pCert; -TaskHandle_t handleSSLTask; HTTPSServer * secureServer; #endif HTTPServer * insecureServer; @@ -403,7 +403,7 @@ void initWebServer(void) { 16384, NULL, TASK_PRIORITY_SSL_CERT, // low priority as this blocks BIG time - &handleSSLTask); + &handleWebServerTask); while(!xSemaphoreTake(SSLSemaphore, 250)) { ScreenManager.showBootWait(1); @@ -476,12 +476,12 @@ void initWebServer(void) { // setup task to handle webserver webSocketQueue = xQueueCreate(50, sizeof(char*) ); xTaskCreate(SSLloopTask, - "SSLloopTask", + "Web server task", 8192, // 16384, NULL, TASK_PRIORITY_SSL_LOOP, // low priority as this potentially blocks BIG time - &handleSSLTask); + &handleWebServerTask); DebugPort.println("HTTP task started"); }