Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -r62e9c09c41d40bae4326dce1c19a62020168d057 -r670fd0c4637436f4bf934677b878f557e776022d --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 62e9c09c41d40bae4326dce1c19a62020168d057) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 670fd0c4637436f4bf934677b878f557e776022d) @@ -54,7 +54,6 @@ #define BLOOD_LEAK_ZERO_CMD_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Blood leak zero command timeout in milliseconds. #define BLOOD_LEAK_SELF_TEST_CMD_TIMEOUT_MS ( 2 * MS_PER_SECOND ) ///< Blood leak self test command timeout in milliseconds. #define BLOOD_LEAK_BETWEEN_ZERO_ST_WAIT_MS 250 ///< Blood leak wait time in between zero and self test commands in milliseconds. -#define BLOOD_LEAK_MIN_WAIT_TIME_2_GET_CAL_MS ( 2 * MS_PER_SECOND ) ///< Blood leak minimum wait time to get calibration in milliseconds. #define DATA_PUBLISH_COUNTER_START_COUNT 60 ///< Data publish counter start count. // Embedded mode defines @@ -128,7 +127,7 @@ U32 timeoutMS; ///< Blood leak sensor receive timeout in milliseconds. U32 commandResp; ///< Blood leak sensor command response back. U08 commandRetryCount; ///< Blood leak sensor command retry count. - BOOL isCmdRespRdy; ///< Blood leak sensor is command response ready flag. + BOOL isCmdRespRdy; ///< Blood leak sensor is command response ready flag. } EMB_MODE_CMD_T; // ********** private data ********** @@ -145,7 +144,6 @@ static U32 bloodLeakSetPointSeqLength; ///< Blood leak set point sequence actual length. static U08 bloodLeakSetPointSequence[ BLOOD_LEAK_SET_POINT_SEQ_MAX_LENGTH ][ 2 ]; ///< Blood leak set point sequence array. static HD_BLOOD_LEAK_SENSOR_CAL_RECORD_T bloodLeakCalRecord; ///< Blood leak calibration record structure. -static U32 bloodLeakGetCalStartTime; ///< Blood leak get calibration start time. static BOOL bloodLeakExitNormalRequested; ///< Blood leak exit normal state requested. // Embedded mode variables @@ -194,7 +192,7 @@ * @details Outputs: bloodLeakState, bloodLeakStatus, bloodLeakSelfTestStatus, * bloodLeakUARTCmdIndex, bloodLeakSetPointSequence * bloodLeakDataPublicationTimerCounter, bloodLeakEmbModeHasZeroBeenRqustd - * bloodLeakGetCalStartTime, bloodLeakEmbModeSubstate + * bloodLeakEmbModeSubstate * bloodLeakPersistenceCtr, bloodLeakSignalEmbModeReq, * bloodLeakEmbModeRqstedCmd, bloodLeakEmbModeOpsStartTime, bloodLeakEmbModeRespBuffer, * bloodLeakEmbModeRespIndex, bloodLeakExitNormalRequested, @@ -215,7 +213,6 @@ bloodLeakSelfTestStatus = SELF_TEST_STATUS_IN_PROGRESS; bloodLeakUARTCmdIndex = 0; bloodLeakSetPointSeqLength = 0; - bloodLeakGetCalStartTime = getMSTimerCount(); bloodLeakPersistenceCtr = 0; bloodLeakSignalEmbModeReq = FALSE; bloodLeakEmbModeRqstedCmd = NU_EMB_MODE_CMD; @@ -256,19 +253,11 @@ *************************************************************************/ void execBloodLeak( void ) { - // Check if there is a new calibration data available and whether there has been sufficient time elapsed from the last data calibration get - // The elapsed time is used to make sure the prepare buffer is not called several time when the new calibration signal is TRUE for one second - // otherwise, the prepareSetPointSeq is called multiple time and zeros the start index. In the mean time, the state might have changed to set - // the set point and with the start index being reset to 0, it keeps sending the first character of the set point ('S'). - if ( ( TRUE == isNewCalibrationRecordAvailable() ) && ( calcTimeSince( bloodLeakGetCalStartTime ) > BLOOD_LEAK_MIN_WAIT_TIME_2_GET_CAL_MS ) ) + if ( TRUE == isNewCalibrationRecordAvailable() ) { U32 length = sizeof( HD_BLOOD_LEAK_SENSOR_CAL_RECORD_T ); getNVRecord2Driver( GET_CAL_BLOOD_LEAK_SENSOR, (U08*)&bloodLeakCalRecord, length, 0, ALARM_ID_HD_BLOOD_LEAK_INVALID_CAL_RECORD ); - prepareSetPointSeq( bloodLeakCalRecord.setPoint ); - - // Set the calibration start time to make sure the prepare buffer is not set multiple times in a row - bloodLeakGetCalStartTime = getMSTimerCount(); } switch( bloodLeakState ) @@ -535,6 +524,7 @@ { // Enqueue the zero and self test sequence (Z->G->Z->Q->T) BOOL hasCmdSqncFailed = FALSE; + BOOL hasCurrCmdFailed = FALSE; U08 failedCmd; for ( i = 0; i < NUM_OF_EMB_CMDS; i++ ) @@ -545,14 +535,16 @@ case Q_EMB_MODE_CMD: case T_EMB_MODE_CMD: // Check to see if any of the command responses failed - hasCmdSqncFailed |= ( BLOOD_LEAK_EMB_MODE_FAIL_ASCII == bloodLeakEmbModeCmd[ i ].commandResp ? TRUE : FALSE ); - failedCmd = ( TRUE == hasCmdSqncFailed ? i : NU_EMB_MODE_CMD ); + hasCurrCmdFailed = ( BLOOD_LEAK_EMB_MODE_FAIL_ASCII == bloodLeakEmbModeCmd[ i ].commandResp ? TRUE : FALSE ); + hasCmdSqncFailed |= hasCurrCmdFailed; + failedCmd = ( TRUE == hasCurrCmdFailed ? i : NU_EMB_MODE_CMD ); break; case G_EMB_MODE_CMD: // G command will return a value that has to be greater than 0 - hasCmdSqncFailed |= ( bloodLeakEmbModeCmd[ i ].commandResp > 0 ? FALSE : TRUE ); - failedCmd = ( TRUE == hasCmdSqncFailed ? i : NU_EMB_MODE_CMD ); + hasCurrCmdFailed = ( bloodLeakEmbModeCmd[ i ].commandResp > 0 ? FALSE : TRUE ); + hasCmdSqncFailed |= hasCurrCmdFailed; + failedCmd = ( TRUE == hasCurrCmdFailed ? i : NU_EMB_MODE_CMD ); break; } }