Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -r4e4ab946c0bc4b668cf5b197c7f841355814ccf5 -r62e9c09c41d40bae4326dce1c19a62020168d057 --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 4e4ab946c0bc4b668cf5b197c7f841355814ccf5) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 62e9c09c41d40bae4326dce1c19a62020168d057) @@ -418,13 +418,18 @@ // Since set point was requested in the init function as well, both are requested here because we have to be // in the embedded mode first enqueueEmbModeCmd( CS_EMB_MODE_CMD ); - enqueueEmbModeCmd( SP_EMB_MODE_CMD ); + enqueueEmbModeCmd( D_EMB_MODE_CMD ); bloodLeakEmbModeCmd[ CS_EMB_MODE_CMD ].commandRetryCount++; } else { - // TODO fault, we cannot get to the embedded mode +#ifndef _RELEASE_ + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_BLOOD_LEAK_ALARM ) != SW_CONFIG_ENABLE_VALUE ) +#endif + { + activateAlarmNoData( ALARM_ID_HD_BLOOD_LEAK_SENSOR_EMBEDDED_MODE_FAILURE ); + } } } @@ -491,8 +496,7 @@ // Check if the zero command has been requested if ( TRUE == bloodLeakEmbModeHasZeroBeenRqustd ) { - bloodLeakEmbModeHasZeroBeenRqustd = FALSE; - state = BLOOD_LEAK_CHECK_ZERO_AND_SELF_TEST_STATE; + state = BLOOD_LEAK_CHECK_ZERO_AND_SELF_TEST_STATE; } return state; @@ -509,8 +513,9 @@ static BLOOD_LEAK_STATE_T handleBloodLeakCheckZeroAndSelfTestState( void ) { U08 i; - BLOOD_LEAK_STATE_T state = BLOOD_LEAK_CHECK_ZERO_AND_SELF_TEST_STATE; - BOOL areCommandsReady = TRUE; + BLOOD_LEAK_STATE_T state = BLOOD_LEAK_CHECK_ZERO_AND_SELF_TEST_STATE; + BOOL areCommandsReady = TRUE; + bloodLeakEmbModeHasZeroBeenRqustd = FALSE; for ( i = 0; i < NUM_OF_EMB_CMDS; i++ ) { @@ -520,6 +525,7 @@ case G_EMB_MODE_CMD: case Q_EMB_MODE_CMD: case T_EMB_MODE_CMD: + // All the commands shall be processed and have data prior to checking the results areCommandsReady &= bloodLeakEmbModeCmd[ i ].isCmdRespRdy; break; } @@ -529,17 +535,25 @@ { // Enqueue the zero and self test sequence (Z->G->Z->Q->T) BOOL hasCmdSqncFailed = FALSE; + U08 failedCmd; for ( i = 0; i < NUM_OF_EMB_CMDS; i++ ) { switch( i ) { case Z_EMB_MODE_CMD: - case G_EMB_MODE_CMD: 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 ); 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 ); + break; } } @@ -549,14 +563,18 @@ } else if ( bloodLeakEmbModeCmd[ Z_EMB_MODE_CMD ].commandRetryCount < BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) { - // NOTE: assume one of the commands' retries is less than the allowed and try it again - // Enqueue the zero and self test sequence (Z->G->Z->Q->T) - enqueueEmbModeCmd( Z_EMB_MODE_CMD ); - enqueueEmbModeCmd( G_EMB_MODE_CMD ); - enqueueEmbModeCmd( Z_EMB_MODE_CMD ); - enqueueEmbModeCmd( Q_EMB_MODE_CMD ); - enqueueEmbModeCmd( T_EMB_MODE_CMD ); + // Zero sequence failed, try again + zeroBloodLeak(); } + else + { +#ifndef _RELEASE_ + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_BLOOD_LEAK_ALARM ) != SW_CONFIG_ENABLE_VALUE ) +#endif + { + SET_ALARM_WITH_1_U32_DATA( ALARM_ID_HD_BLOOD_LEAK_SENSOR_ZERO_SEQUENCE_FAILED, failedCmd ); + } + } } return state; @@ -918,6 +936,7 @@ // Done with receiving the data bloodLeakEmbModeRqstedCmd = NU_EMB_MODE_CMD; state = BLOOD_LEAK_EMB_MODE_WAIT_FOR_COMAND_STATE; + sendBloodLeakEmbeddedModeCommandResponse( length, bloodLeakEmbModeRespBuffer ); } @@ -1033,15 +1052,20 @@ U08 i; U32 bufferValue; U32 respExpectedLength = bloodLeakEmbModeCmd[ cmd ].length; - + // Reset the command response bloodLeakEmbModeCmd[ cmd ].commandResp = 0; for ( i = 0; i < respExpectedLength; i++ ) { + // The last value is inserted into the response buffer (i.e. S030) + // So the buffer array is used from the last element of the array bufferValue = bloodLeakEmbModeRespBuffer[ respExpectedLength - 1 - i ]; if ( ( bufferValue >= BLOOD_LEAK_EMB_MODE_0_NUM_ASCII ) && ( bufferValue <= BLOOD_LEAK_EMB_MODE_9_NUM_ASCII ) ) { + // If the value in the response buffer is within the ASCII values of 0 (ASCII 48) to 9 (ASCII 57) then it is a number and needs to be converted to integer + // Subtract the buffer value from ASCII 48 to get the offset (i.e. buffer = 50 - 48 = 2) + // Add the offset value to the command response in the right order (i.e. if i = 1, then it is 2 x 10 ^1 = 20) bufferValue -= BLOOD_LEAK_EMB_MODE_0_NUM_ASCII; bloodLeakEmbModeCmd[ cmd ].commandResp += ( bufferValue * pow( 10, i ) ); }