Repository for import to local machine
Dependencies: DMBasicGUI DMSupport
Diff: GCStateAndFaultCodes.cpp
- Revision:
- 0:47c880c1463d
- Child:
- 1:a5258871b33d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GCStateAndFaultCodes.cpp Wed Jan 13 13:17:05 2016 +0000 @@ -0,0 +1,156 @@ +#include "GCStateAndFaultCodes.h" + +#include <string.h> + +/* + Classes that match state or fault code integer values to the corresponding strings +*/ + +GCStateOrFaultCode::GCStateOrFaultCode(int theCodeNumber, char* theCodeString) +{ + codeNumber = theCodeNumber; + + strcpy(codeString, theCodeString); +} + +int GCStateOrFaultCode::GetCodeNumber(void) +{ + return codeNumber; +} + +void GCStateOrFaultCode::GetCodeString(char *buff) +{ + strcpy(buff, codeString); +} + + +GCStateAndFaultCodes::GCStateAndFaultCodes() +{ + // The state and fault codes below are taken from the Nemesis 2 GC Control Protocol, + // version 1.0, dated 01/10/15. Note that the fault codes include those marked 'not used'. + + + // First - the state codes + + stateCodeArray[0] = new GCStateOrFaultCode(0, "Idle"); + stateCodeArray[1] = new GCStateOrFaultCode(1, "Not Ready"); + stateCodeArray[2] = new GCStateOrFaultCode(2, "Equilibrating"); + stateCodeArray[3] = new GCStateOrFaultCode(4, "Running initial time"); + + stateCodeArray[4] = new GCStateOrFaultCode(5, "Ramping segment 1"); + stateCodeArray[5] = new GCStateOrFaultCode(6, "At upper temp segment 1"); + stateCodeArray[6] = new GCStateOrFaultCode(7, "Ramping segment 2"); + stateCodeArray[7] = new GCStateOrFaultCode(8, "At upper temp segment 2"); + stateCodeArray[8] = new GCStateOrFaultCode(9, "Ramping segment 3"); + stateCodeArray[9] = new GCStateOrFaultCode(10, "At upper temp segment 3"); + stateCodeArray[10] = new GCStateOrFaultCode(11, "Ramping segment 4"); + stateCodeArray[11] = new GCStateOrFaultCode(12, "At upper temp segment 4"); + stateCodeArray[12] = new GCStateOrFaultCode(13, "Ramping segment 5"); + stateCodeArray[13] = new GCStateOrFaultCode(14, "At upper temp segment 5"); + + stateCodeArray[14] = new GCStateOrFaultCode(15, "Holding"); + stateCodeArray[15] = new GCStateOrFaultCode(16, "Aborting"); + stateCodeArray[16] = new GCStateOrFaultCode(17, "Cooling"); + + stateCodeArray[17] = new GCStateOrFaultCode(31, "Ready to pre-run"); + stateCodeArray[18] = new GCStateOrFaultCode(32, "Pre-running"); + stateCodeArray[19] = new GCStateOrFaultCode(33, "Ready to run"); + + stateCodeArray[20] = new GCStateOrFaultCode(99, "Faulted"); + + + // Now the fault codes - these only apply if the state is 99, "Faulted" + + faultCodeArray[0] = new GCStateOrFaultCode(0, "No error"); + faultCodeArray[1] = new GCStateOrFaultCode(1, "EEPROM failure"); + faultCodeArray[2] = new GCStateOrFaultCode(2, "Door open"); + faultCodeArray[3] = new GCStateOrFaultCode(3, "IRsensor open"); + faultCodeArray[4] = new GCStateOrFaultCode(4, "IRsensor short"); + faultCodeArray[5] = new GCStateOrFaultCode(5, "Injector PRT open"); + faultCodeArray[6] = new GCStateOrFaultCode(6, "Injector PRT short"); + faultCodeArray[7] = new GCStateOrFaultCode(7, "Detector PRT open"); + faultCodeArray[8] = new GCStateOrFaultCode(8, "Detector PRT short"); + + faultCodeArray[9] = new GCStateOrFaultCode(9, "(Not used): Injector coupling PRT open"); + faultCodeArray[10] = new GCStateOrFaultCode(10, "(Not used): Injector coupling PRT short"); + faultCodeArray[11] = new GCStateOrFaultCode(11, "(Not used): Detector coupling PRT open"); + faultCodeArray[12] = new GCStateOrFaultCode(12, "(Not used): Detector coupling PRT short"); + + faultCodeArray[13] = new GCStateOrFaultCode(13, "(Fault code 13, not used)"); + faultCodeArray[14] = new GCStateOrFaultCode(14, "(Fault code 14, not used)"); + + faultCodeArray[15] = new GCStateOrFaultCode(15, "Voltage ref error"); + faultCodeArray[16] = new GCStateOrFaultCode(16, "Voltage sensor error"); + + faultCodeArray[17] = new GCStateOrFaultCode(17, "Column over temp error"); + faultCodeArray[18] = new GCStateOrFaultCode(18, "Injector over temp error"); + faultCodeArray[19] = new GCStateOrFaultCode(19, "Detector over temp error"); + + faultCodeArray[20] = new GCStateOrFaultCode(20, "(Not used): Injector coupling over temp error"); + faultCodeArray[21] = new GCStateOrFaultCode(21, "(Not used): Detector coupling over temp error"); + + faultCodeArray[22] = new GCStateOrFaultCode(22, "(Fault code 22, not used)"); + + faultCodeArray[23] = new GCStateOrFaultCode(23, "(Not used): Column not init"); + faultCodeArray[24] = new GCStateOrFaultCode(24, "(Not used): Column insert failed"); + + faultCodeArray[25] = new GCStateOrFaultCode(25, "I2C NAK error"); + + faultCodeArray[26] = new GCStateOrFaultCode(26, "TWI timeout error"); + faultCodeArray[27] = new GCStateOrFaultCode(27, "TWI bus error"); + faultCodeArray[28] = new GCStateOrFaultCode(28, "TWI SLAW NACK"); + faultCodeArray[29] = new GCStateOrFaultCode(29, "TWI SLADATA NACK"); + faultCodeArray[30] = new GCStateOrFaultCode(30, "TWI SLAR NACK"); + faultCodeArray[31] = new GCStateOrFaultCode(31, "TWI arbitration lost"); + faultCodeArray[32] = new GCStateOrFaultCode(32, "TWI unknown error"); + + faultCodeArray[33] = new GCStateOrFaultCode(33, "TWI2 timeout error"); + faultCodeArray[34] = new GCStateOrFaultCode(34, "TWI2 bus error"); + faultCodeArray[35] = new GCStateOrFaultCode(35, "TWI2 unknown error 1"); + faultCodeArray[36] = new GCStateOrFaultCode(36, "TWI2 unknown error 2"); +} + +GCStateAndFaultCodes::~GCStateAndFaultCodes() +{ + int i; + + for (i = 0; i < STATE_CODE_COUNT; ++i) { + delete stateCodeArray[i]; + } + + for (i = 0; i < FAULT_CODE_COUNT; ++i) { + delete faultCodeArray[i]; + } +} + +bool GCStateAndFaultCodes::GetStateCodeString(int stateCode, char *buff) +{ + for (int i = 0; i < STATE_CODE_COUNT; ++i) { + if(stateCodeArray[i]->GetCodeNumber() == stateCode) { + stateCodeArray[i]->GetCodeString(buff); + return true; + } + } + + // 'else' - state code not found + buff[0] = '\0'; + return false; +} + +bool GCStateAndFaultCodes::GetFaultCodeString(int faultCode, char *buff) +{ + for (int i = 0; i < FAULT_CODE_COUNT; ++i) { + if(faultCodeArray[i]->GetCodeNumber() == faultCode) { + faultCodeArray[i]->GetCodeString(buff); + return true; + } + } + + // 'else' - fault code not found + buff[0] = '\0'; + return false; +} + + + +