diff --git a/AppInventor/BluetoothHeater.aia b/AppInventor/BluetoothHeater.aia index e66d51a..a097ecd 100644 Binary files a/AppInventor/BluetoothHeater.aia and b/AppInventor/BluetoothHeater.aia differ diff --git a/Arduino/SenderTrial2/Protocol.cpp b/Arduino/SenderTrial2/Protocol.cpp index 5715f15..1c3f4c3 100644 --- a/Arduino/SenderTrial2/Protocol.cpp +++ b/Arduino/SenderTrial2/Protocol.cpp @@ -248,7 +248,7 @@ CProtocol::Init(int FrameMode) setGlowPlug_Voltage(0); setGlowPlug_Current(0); Heater.ActualPumpFreq = 0; // fuel pump freq.: 0.1Hz / digit - Heater.ErrorCode = 0; // + Heater.StoredErrorCode = 0; // Heater.Unknown1 = 0; // always 0x00 Heater.FixedPumpFreq = 23; // fixed mode frequency set point: 0.1Hz / digit Heater.Unknown2 = 100; // always 0x64 "100 ?" diff --git a/Arduino/SenderTrial2/Protocol.h b/Arduino/SenderTrial2/Protocol.h index ccb8c3c..92232a3 100644 --- a/Arduino/SenderTrial2/Protocol.h +++ b/Arduino/SenderTrial2/Protocol.h @@ -49,7 +49,7 @@ public: unsigned char GlowPlugCurrent_MSB; // 16 bit - big endian MSB unsigned char GlowPlugCurrent_LSB; // 16 bit - big endian LSB : 10mA / digit unsigned char ActualPumpFreq; // fuel pump freq.: 0.1Hz / digit - unsigned char ErrorCode; // + unsigned char StoredErrorCode; // unsigned char Unknown1; // always 0x00 unsigned char FixedPumpFreq; // fixed mode frequency set point: 0.1Hz / digit unsigned char Unknown2; // always 0x64 "100 ?" @@ -121,6 +121,8 @@ public: void setRunState(unsigned char state) { Heater.RunState = state; }; unsigned char getErrState() { return Heater.ErrState; }; void setErrState(unsigned char state) { Heater.ErrState = state; }; + unsigned char getStoredErrCode() { return Heater.StoredErrorCode; }; + void setStoredErrCode(unsigned char state) { Heater.StoredErrorCode = state; }; // short getVoltage_Supply(); void setVoltage_Supply(short voltsx10); diff --git a/Arduino/SenderTrial2/SenderTrial2.ino b/Arduino/SenderTrial2/SenderTrial2.ino index 397c491..44a78da 100644 --- a/Arduino/SenderTrial2/SenderTrial2.ino +++ b/Arduino/SenderTrial2/SenderTrial2.ino @@ -67,6 +67,7 @@ #include "pins.h" #include "NVStorage.h" #include "debugport.h" +#include "SmartError.h" #define DEBUG_BTRX @@ -136,6 +137,7 @@ CProtocol OEMCtrlFrame; // data packet received from heater in response t CProtocol HeaterFrame1; // data packet received from heater in response to OEM controller packet CProtocol HeaterFrame2; // data packet received from heater in response to our packet CProtocol DefaultBTCParams(CProtocol::CtrlMode); // defines the default parameters, used in case of no OEM controller +CSmartError SmartError; long lastRxTime; // used to observe inter character delays bool hasOEMController = false; @@ -152,10 +154,6 @@ void PrepareTxFrame(const CProtocol& basisFrame, CProtocol& TxFrame, bool isBTCm void setup() { - // initialize serial port to interact with the "blue wire" - // 25000 baud, Tx and Rx channels of Chinese heater comms interface: - // Tx/Rx data to/from heater, - // Note special baud rate for Chinese heater controllers pinMode(Tx2Pin, OUTPUT); digitalWrite(Tx2Pin, HIGH); pinMode(Rx2Pin, INPUT_PULLUP); @@ -163,6 +161,10 @@ void setup() pinMode(KeyPin, OUTPUT); digitalWrite(KeyPin, LOW); + // initialize serial port to interact with the "blue wire" + // 25000 baud, Tx and Rx channels of Chinese heater comms interface: + // Tx/Rx data to/from heater, + // Note special baud rate for Chinese heater controllers #if defined(__arm__) || defined(__AVR__) BlueWireSerial.begin(25000); pinMode(Rx1Pin, INPUT_PULLUP); // required for MUX to work properly @@ -181,7 +183,7 @@ void setup() TxManage.begin(); // ensure Tx enable pin is setup - // define defaults should heater controller be missing + // define defaults should OEM controller be missing DefaultBTCParams.setTemperature_Desired(23); DefaultBTCParams.setTemperature_Actual(22); DefaultBTCParams.Controller.OperatingVoltage = 120; @@ -310,6 +312,11 @@ void loop() else if(CommState.is(CommStates::HeaterReport1) ) { // received heater frame (after controller message), report + + // do some monitoring of the heater state variable + // if suspicious transitions, introduce a smart error! + SmartError.monitor(HeaterFrame1); + // echo heater reponse data to Bluetooth client Bluetooth_SendFrame("[HTR]", HeaterFrame1); @@ -343,6 +350,11 @@ void loop() else if( CommState.is(CommStates::HeaterReport2) ) { // received heater frame (after our control message), report + + // do some monitoring of the heater state variable + // if suspicious transitions, introduce a smart error! + SmartError.monitor(HeaterFrame2); + delay(5); if(!hasOEMController) { // only convey these frames to Bluetooth when NOT using an OEM controller! @@ -391,10 +403,12 @@ void Command_Interpret(const char* pLine) if(strncmp(pLine, "ON", 2) == 0) { TxManage.queueOnRequest(); DebugPort.println("Heater ON"); + SmartError.reset(); } else if(strncmp(pLine, "OFF", 3) == 0) { TxManage.queueOffRequest(); DebugPort.println("Heater OFF"); + SmartError.inhibit(); } else if(strncmp(pLine, "Pmin", 4) == 0) { pLine += 4;