From baf1def165b26a5ed49ea981e19df05a9a295713 Mon Sep 17 00:00:00 2001 From: rljonesau Date: Mon, 29 Oct 2018 06:01:26 +1100 Subject: [PATCH] Left out SmartError.cpp & SmartError.h :-( --- Arduino/SenderTrial2/SmartError.cpp | 93 +++++++++++++++++++++++++++++ Arduino/SenderTrial2/SmartError.h | 14 +++++ 2 files changed, 107 insertions(+) create mode 100644 Arduino/SenderTrial2/SmartError.cpp create mode 100644 Arduino/SenderTrial2/SmartError.h diff --git a/Arduino/SenderTrial2/SmartError.cpp b/Arduino/SenderTrial2/SmartError.cpp new file mode 100644 index 0000000..3bad5f8 --- /dev/null +++ b/Arduino/SenderTrial2/SmartError.cpp @@ -0,0 +1,93 @@ +#include "SmartError.h" + +CSmartError::CSmartError() +{ + reset(); +} + +void +CSmartError::reset() +{ + m_prevRunState = 0; + m_Error = 0; + m_bInhibit = false; +} + +// we use inhibit when we manually command the heater off during preheat +// otherwise we'll register an ignition fail event +void +CSmartError::inhibit() +{ + m_bInhibit = true; + m_Error = 0; +} + +// accept a fresh heater frame +// inpsect the advertised run state, tracking when and how it transitions out +// of preheat especially. +// abnormal transitions are registered and becoem our smart m_Error +// In addition, the hetaer frame has the ErrState updated to track the +// smart error, providing no heater error exists! +void +CSmartError::monitor(CProtocol& heaterFrame) +{ + if(heaterFrame.verifyCRC()) { + // only accept valid heater frames! + monitor(heaterFrame.getRunState()); + unsigned char HtrErr = heaterFrame.getErrState(); + if((HtrErr & 0xfe) == 0) { + // heater is Idle or Normal running state (E-0X + 1 in protocol!!) + unsigned char smartErr = getError(); + if(smartErr) { + heaterFrame.setErrState(smartErr); // 10 = ign fail, 11 = retry + heaterFrame.setCRC(); // changed the message, fix the CRC! + } + } + } +} + +// test the new run state value, comparing to previous +// detect abnormal transitions +void +CSmartError::monitor(unsigned char newRunState) +{ + // check if moving away from heater Idle state (S0) + // especially useful if an OEM controller exists + if((m_prevRunState == 0) && newRunState) { + // reset the smart error + m_Error = 0; + m_bInhibit = false; + } + + if(!m_bInhibit) { + if(m_prevRunState == 2) { // preheat state (S2) + if(newRunState == 4) { + // transitioned from preheat to ignited + // - all good! + m_Error = 0; + } + else if(newRunState > 5) { + // transitioned from preheat to post glow + // - second ignition attempt failed, heater is shutting down + m_Error = 11; + } + else if(newRunState == 3) { + // transitioned from preheat to retry + // - first ignition attempt failed, heater will retry + m_Error = 12; + } + } + } + + m_prevRunState = newRunState; +} + +// return our smart error, if it exists, as the registered code +unsigned char +CSmartError::getError() +{ + if(m_Error) { + return m_Error; + } + return 0; +} \ No newline at end of file diff --git a/Arduino/SenderTrial2/SmartError.h b/Arduino/SenderTrial2/SmartError.h new file mode 100644 index 0000000..94a19a0 --- /dev/null +++ b/Arduino/SenderTrial2/SmartError.h @@ -0,0 +1,14 @@ +#include "Protocol.h" + +class CSmartError { + unsigned char m_prevRunState; + unsigned char m_Error; + bool m_bInhibit; +public: + CSmartError(); + void reset(); + void inhibit(); + void monitor(CProtocol& heaterFrame); + void monitor(unsigned char runstate); + unsigned char getError(); +}; \ No newline at end of file