Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -r27a68f930508638f2eb6265ebb381c8918cbc37b -r5b448e81db260e5b041699a83c6f2a3faa260ea9 --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 27a68f930508638f2eb6265ebb381c8918cbc37b) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 5b448e81db260e5b041699a83c6f2a3faa260ea9) @@ -61,6 +61,11 @@ #define DATA_PUBLISH_COUNTER_START_COUNT 60 ///< Data publish counter start count. +// Calibration mode defines +#define BLOOD_LEAK_EMB_MODE_CTRL_S_ASCII 19 ///< Blood leak embedded mode start command, ^S in ascii. +#define BLOOD_LEAK_CAL_COMMAND_SEQ_LENGTH 4 ///< Blood leak calibration state command length. +#define BLOOD_LEAK_EMB_MODE_STOP_INDEX 1 ///< Blood leak embedded mode stop writing to FIFO index. + /// Defined states for the blood leak detector state machine. typedef enum BloodLeakStates { @@ -73,27 +78,36 @@ BLOOD_LEAK_ZERO_STATE, ///< Zero state. BLOOD_LEAK_SELF_TEST_STATE, ///< Self-test state. BLOOD_LEAK_NORMAL_STATE, ///< Normal state. + BLOOD_LEAK_CALIBRATION_STATE, ///< Calibration state. NUM_OF_BLOOD_LEAK_STATES ///< Number of blood leak detector states. -} BLOOD_LEAK_STATES_T; +} BLOOD_LEAK_STATE_T; +typedef enum CalibrationStates +{ + BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE = 0, ///< Blood leak calibration state wait for command state. + BLOOD_LEAK_CAL_SEND_COMMAND_STATE, ///< Blood leak calibration state send command state. + BLOOD_LEAK_CAL_WAIT_FOR_COMMAND_RESPONSE_STATE, ///< Blood leak calibration state wait for command response state. + NUM_CAL_STATES ///< Number of blood leak calibration states. +} BLOOD_LEAK_CAL_STATE_T; + // ********** private data ********** -static BLOOD_LEAK_STATES_T bloodLeakState; ///< Current state of blood leak state machine. +static BLOOD_LEAK_STATE_T bloodLeakState; ///< Current state of blood leak state machine. static OVERRIDE_U32_T bloodLeakStatus; ///< Detected blood leak status for blood leak detector. static SELF_TEST_STATUS_T bloodLeakSelfTestStatus; ///< Current status of blood leak self-test. -static BOOL bloodLeakZeroRequested = FALSE; ///< Blood leak zero requested flag -static U32 bloodLeakZeroStartTime = 0; ///< Blood leak zeroing start time. -static U32 bloodLeakSelfTestStartTime = 0; ///< Blood leak self-test start time. +static BOOL bloodLeakZeroRequested; ///< Blood leak zero requested flag +static U32 bloodLeakZeroStartTime; ///< Blood leak zeroing start time. +static U32 bloodLeakSelfTestStartTime; ///< Blood leak self-test start time. static BOOL bloodLeakIsPOSTComplete; ///< Blood leak is POST complete flag. static U32 bloodLeakPersistenceCtr = 0; ///< Blood leak alarm persistence timer counter. static OVERRIDE_U32_T bloodLeakDataPublishInterval = { BLOOD_LEAK_PUB_INTERVAL, BLOOD_LEAK_PUB_INTERVAL, 0, 0 }; ///< Interval (in ms) at which to publish blood leak data to CAN bus. static U32 bloodLeakDataPublicationTimerCounter; ///< Timer counter used to schedule blood leak data publication to CAN bus. -static U32 bloodLeakUARTCmdIndex = 0; ///< Blood leak UART command index. -static U32 bloodLeakSetPointSeqLength = 0; ///< Blood leak set point sequence actual length. +static U32 bloodLeakUARTCmdIndex; ///< Blood leak UART command index. +static U32 bloodLeakSetPointSeqLength; ///< Blood leak set point sequence actual length. static U08 bloodLeakSetPointSequence[ BLOOD_LEAK_SET_POINT_SEQ_MAX_LENGTH ]; ///< Blood leak set point sequence array. static U32 bloodLeakWait2ReadResponseCounter; ///< Blood leak wait to read response counter. static U32 bloodLeakCommandWriteTryCount; ///< Blood leak current set point write try number. @@ -108,20 +122,31 @@ BLOOD_LEAK_STOP_WRITE_FIFO_COMMAND, BLOOD_LEAK_UART_COMM_ACTIVE_HIGH, BLOOD_LEAK_UART_COMM_ACTIVE_LOW }; +// Embedded mode variables +static BOOL bloodLeakSignalEmbeddedModeReq; ///< Blood leak signal embedded mode has been requested. +static U08 bloodLeakCalASCIIChar; ///< Blood leak signal calibration command. +static U08 bloodLeakCalCommandSquence[ BLOOD_LEAK_CAL_COMMAND_SEQ_LENGTH ]; ///< Blood leak calibration command sequence. +static BLOOD_LEAK_CAL_STATE_T bloodLeakCalSubstate; ///< Blood leak calibration substate. +static U16 bloodLeakCalSetPoint; ///< Blood leak calibration set point command. // ********** private function prototypes ********** -static BLOOD_LEAK_STATES_T handleBloodLeakWaitForPostState( void ); -static BLOOD_LEAK_STATES_T handleBloodLeakStartupState( void ); -static BLOOD_LEAK_STATES_T handleBloodLeakCheckCommState( void ); -static BLOOD_LEAK_STATES_T handleBloodLeakCheckSetPointState( void ); -static BLOOD_LEAK_STATES_T handleBloodLeakSetSetPointState( void ); -static BLOOD_LEAK_STATES_T handleBloodLeakInitState( void ); -static BLOOD_LEAK_STATES_T handleBloodLeakZeroState( void ); -static BLOOD_LEAK_STATES_T handleBloodLeakSelfTestState( void ); -static BLOOD_LEAK_STATES_T handleBloodLeakNormalState( void ); +static BLOOD_LEAK_STATE_T handleBloodLeakWaitForPostState( void ); +static BLOOD_LEAK_STATE_T handleBloodLeakStartupState( void ); +static BLOOD_LEAK_STATE_T handleBloodLeakCheckCommState( void ); +static BLOOD_LEAK_STATE_T handleBloodLeakCheckSetPointState( void ); +static BLOOD_LEAK_STATE_T handleBloodLeakSetSetPointState( void ); +static BLOOD_LEAK_STATE_T handleBloodLeakInitState( void ); +static BLOOD_LEAK_STATE_T handleBloodLeakZeroState( void ); +static BLOOD_LEAK_STATE_T handleBloodLeakSelfTestState( void ); +static BLOOD_LEAK_STATE_T handleBloodLeakNormalState( void ); +static BLOOD_LEAK_STATE_T handleBloodLeakCalibrationState( void ); -static void prepareSetPointSeq( void ); +static BLOOD_LEAK_CAL_STATE_T handleCalBloodLeakWaitForCommandState( void ); +static BLOOD_LEAK_CAL_STATE_T handleCalBloodLeakSendCommandState( void ); +static BLOOD_LEAK_CAL_STATE_T handleCalBloodLeakWaitForCommandResponseState( void ); + +static void prepareSetPointSeq( U16 setPoint ); static void publishBloodLeakData( void ); /*********************************************************************//** @@ -132,8 +157,9 @@ * bloodLeakZeroRequested, bloodLeakZeroRequested, bloodLeakSelfTestStartTime, * bloodLeakUARTCmdIndex, bloodLeakSetPointSequence, bloodLeakPrevFPGARegisterCount * bloodLeakWait2ReadResponseCounter, bloodLeakDataPublicationTimerCounter, - * bloodLeakCommandWriteTryCount, bloodLeakGetCalStartTime, - * bloodLeakIsPOSTComplete + * bloodLeakCommandWriteTryCount, bloodLeakGetCalStartTime, bloodLeakCalSubstate + * bloodLeakIsPOSTComplete, bloodLeakPersistenceCtr, bloodLeakSignalEmbeddedModeReq, + * bloodLeakCalASCIIChar * @return none *************************************************************************/ void initBloodLeak( void ) @@ -155,15 +181,27 @@ bloodLeakGetCalStartTime = getMSTimerCount(); bloodLeakIsPOSTComplete = FALSE; bloodLeakPrevFPGARegisterCount = 0; + bloodLeakPersistenceCtr = 0; + bloodLeakSignalEmbeddedModeReq = FALSE; + bloodLeakCalASCIIChar = 0; + bloodLeakCalSubstate = BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE; // Set the blood leak set pint sequence to 0 to be initialized memset( bloodLeakSetPointSequence, 0x0, BLOOD_LEAK_SET_POINT_SEQ_MAX_LENGTH ); + + // Initialize the blood leak calibration command sequence array. + // The first index is the command character so it can be changed upon request. + // The reset of the commands are never changing. + bloodLeakCalCommandSquence[ 0 ] = 0; + bloodLeakCalCommandSquence[ 1 ] = BLOOD_LEAK_STOP_WRITE_FIFO_COMMAND; + bloodLeakCalCommandSquence[ 2 ] = BLOOD_LEAK_UART_COMM_ACTIVE_HIGH; + bloodLeakCalCommandSquence[ 3 ] = BLOOD_LEAK_UART_COMM_ACTIVE_LOW; } /*********************************************************************//** * @brief * The execBloodLeak function executes the blood leak detector driver. - * @details Inputs: bloodLeakGetCalStartTime + * @details Inputs: bloodLeakGetCalStartTime, bloodLeakSignalEmbeddedModeReq * @details Outputs: bloodLeakStatus, bloodLeakGetCalStartTime * @return none *************************************************************************/ @@ -178,7 +216,7 @@ 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(); + prepareSetPointSeq( bloodLeakCalRecord.setPoint ); // Force the state machine to go back to set the set point that has been received from // the calibration data @@ -188,9 +226,18 @@ bloodLeakGetCalStartTime = getMSTimerCount(); } + // If a request to transition to embedded mode has been made, change the state to calibration state, and request a transition to service mode. + // This type of work can only be done in the service mode and then the user has to restart the device to return to the normal operations of BLD. + if ( TRUE == bloodLeakSignalEmbeddedModeReq ) + { + bloodLeakState = BLOOD_LEAK_CALIBRATION_STATE; + + requestNewOperationMode( MODE_SERV ); + } + + // Check if the mode is not in init and then run the sensor if ( getCurrentOperationMode() != MODE_INIT ) { - // Execute blood leak state machine switch( bloodLeakState ) { case BLOOD_LEAK_WAIT_FOR_POST_STATE: @@ -229,6 +276,10 @@ bloodLeakState = handleBloodLeakNormalState(); break; + case BLOOD_LEAK_CALIBRATION_STATE: + bloodLeakState = handleBloodLeakCalibrationState(); + break; + default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_HD_INVALID_BLOOD_LEAK_STATE, bloodLeakState ) bloodLeakState = BLOOD_LEAK_INIT_STATE; @@ -290,9 +341,9 @@ * @details Outputs: none * @return next state *************************************************************************/ -static BLOOD_LEAK_STATES_T handleBloodLeakWaitForPostState( void ) +static BLOOD_LEAK_STATE_T handleBloodLeakWaitForPostState( void ) { - BLOOD_LEAK_STATES_T state = BLOOD_LEAK_WAIT_FOR_POST_STATE; + BLOOD_LEAK_STATE_T state = BLOOD_LEAK_WAIT_FOR_POST_STATE; if ( TRUE == bloodLeakIsPOSTComplete ) { @@ -313,9 +364,9 @@ * @details Outputs: bloodLeakUARTCmdIndex * @return next state *************************************************************************/ -static BLOOD_LEAK_STATES_T handleBloodLeakStartupState( void ) +static BLOOD_LEAK_STATE_T handleBloodLeakStartupState( void ) { - BLOOD_LEAK_STATES_T state = BLOOD_LEAK_START_UP_STATE; + BLOOD_LEAK_STATE_T state = BLOOD_LEAK_START_UP_STATE; U32 command = BLOOD_LEAK_START_UP_SEQUENCE[ bloodLeakUARTCmdIndex ]; @@ -356,9 +407,9 @@ * @details Outputs: bloodLeakCommandWriteTryCount, bloodLeakPrevFPGARegisterCount * @return next state *************************************************************************/ -static BLOOD_LEAK_STATES_T handleBloodLeakCheckCommState( void ) +static BLOOD_LEAK_STATE_T handleBloodLeakCheckCommState( void ) { - BLOOD_LEAK_STATES_T state = BLOOD_LEAK_CHECK_COMM_STATE; + BLOOD_LEAK_STATE_T state = BLOOD_LEAK_CHECK_COMM_STATE; // Check if the blood leak sensor has started communicating BOOL isBloodLeakCommunicating = ( bloodLeakPrevFPGARegisterCount != getFPGABloodLeakRegisterCounter() ? TRUE : FALSE ); @@ -396,9 +447,9 @@ * @details Outputs: bloodLeakUARTCmdIndex * @return next state *************************************************************************/ -static BLOOD_LEAK_STATES_T handleBloodLeakCheckSetPointState( void ) +static BLOOD_LEAK_STATE_T handleBloodLeakCheckSetPointState( void ) { - BLOOD_LEAK_STATES_T state = BLOOD_LEAK_CHECK_SET_POINT_STATE; + BLOOD_LEAK_STATE_T state = BLOOD_LEAK_CHECK_SET_POINT_STATE; U16 bloodLeakSetPoint = getFPGABloodLeakDetectSetPoint(); @@ -411,7 +462,7 @@ { if ( bloodLeakCommandWriteTryCount < BLOOD_LEAK_MAX_SET_POINT_WRITE_TRIALS ) { - prepareSetPointSeq(); + prepareSetPointSeq( bloodLeakCalRecord.setPoint ); bloodLeakCommandWriteTryCount++; state = BLOOD_LEAK_SET_SET_POINT_STATE; } @@ -441,9 +492,9 @@ * @details Outputs: bloodLeakUARTCmdIndex, bloodLeakSetPointSeqLength * @return next state *************************************************************************/ -static BLOOD_LEAK_STATES_T handleBloodLeakSetSetPointState( void ) +static BLOOD_LEAK_STATE_T handleBloodLeakSetSetPointState( void ) { - BLOOD_LEAK_STATES_T state = BLOOD_LEAK_SET_SET_POINT_STATE; + BLOOD_LEAK_STATE_T state = BLOOD_LEAK_SET_SET_POINT_STATE; // Check if the current buffer index is less than the buffer length if( bloodLeakUARTCmdIndex < bloodLeakSetPointSeqLength ) @@ -487,17 +538,17 @@ * @details Outputs: none * @return next state *************************************************************************/ -static BLOOD_LEAK_STATES_T handleBloodLeakInitState( void ) +static BLOOD_LEAK_STATE_T handleBloodLeakInitState( void ) { - BLOOD_LEAK_STATES_T state = BLOOD_LEAK_INIT_STATE; + BLOOD_LEAK_STATE_T state = BLOOD_LEAK_INIT_STATE; if ( TRUE == bloodLeakZeroRequested ) { - state = BLOOD_LEAK_ZERO_STATE; + state = BLOOD_LEAK_ZERO_STATE; bloodLeakZeroRequested = FALSE; + bloodLeakZeroStartTime = getMSTimerCount(); setFPGABloodLeakZero(); - bloodLeakZeroStartTime = getMSTimerCount(); } return state; @@ -511,17 +562,18 @@ * @details Outputs: Blood Leak module zeroing. * @return next state *************************************************************************/ -static BLOOD_LEAK_STATES_T handleBloodLeakZeroState( void ) +static BLOOD_LEAK_STATE_T handleBloodLeakZeroState( void ) { - BLOOD_LEAK_STATES_T state = BLOOD_LEAK_ZERO_STATE; + BLOOD_LEAK_STATE_T state = BLOOD_LEAK_ZERO_STATE; if ( TRUE == FPGABloodLeakZeroDetected() ) { - state = BLOOD_LEAK_SELF_TEST_STATE; - bloodLeakSelfTestStatus = SELF_TEST_STATUS_IN_PROGRESS; + state = BLOOD_LEAK_SELF_TEST_STATE; + bloodLeakSelfTestStatus = SELF_TEST_STATUS_IN_PROGRESS; + bloodLeakSelfTestStartTime = getMSTimerCount(); + clearFPGABloodLeakZero(); setFPGABloodLeakSelfTest(); - bloodLeakSelfTestStartTime = getMSTimerCount(); } else { @@ -547,9 +599,9 @@ * @details Outputs: Blood Leak module self test. * @return next state *************************************************************************/ -static BLOOD_LEAK_STATES_T handleBloodLeakSelfTestState( void ) +static BLOOD_LEAK_STATE_T handleBloodLeakSelfTestState( void ) { - BLOOD_LEAK_STATES_T state = BLOOD_LEAK_SELF_TEST_STATE; + BLOOD_LEAK_STATE_T state = BLOOD_LEAK_SELF_TEST_STATE; if ( SELF_TEST_STATUS_IN_PROGRESS == bloodLeakSelfTestStatus ) { @@ -585,9 +637,9 @@ * @details Outputs: Blood Leak module normal. * @return next state *************************************************************************/ -static BLOOD_LEAK_STATES_T handleBloodLeakNormalState( void ) +static BLOOD_LEAK_STATE_T handleBloodLeakNormalState( void ) { - BLOOD_LEAK_STATES_T state = BLOOD_LEAK_NORMAL_STATE; + BLOOD_LEAK_STATE_T state = BLOOD_LEAK_NORMAL_STATE; if ( TRUE == noFPGABloodLeakDetected() ) { @@ -631,7 +683,7 @@ if ( TRUE == bloodLeakZeroRequested ) { - state = BLOOD_LEAK_ZERO_STATE; + state = BLOOD_LEAK_ZERO_STATE; bloodLeakZeroRequested = FALSE; setFPGABloodLeakZero(); @@ -643,6 +695,36 @@ /*********************************************************************//** * @brief + * The handleBloodLeakCalibrationState function handles the Blood leak + * calibration state. + * @details Inputs: bloodLeakCalSubstate + * @details Outputs: bloodLeakCalSubstate + * @return next state + *************************************************************************/ +static BLOOD_LEAK_STATE_T handleBloodLeakCalibrationState( void ) +{ + BLOOD_LEAK_STATE_T state = BLOOD_LEAK_CALIBRATION_STATE; + + switch ( bloodLeakCalSubstate ) + { + case BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE: + bloodLeakCalSubstate = handleCalBloodLeakWaitForCommandState(); + break; + + case BLOOD_LEAK_CAL_SEND_COMMAND_STATE: + bloodLeakCalSubstate = handleCalBloodLeakSendCommandState(); + break; + + case BLOOD_LEAK_CAL_WAIT_FOR_COMMAND_RESPONSE_STATE: + bloodLeakCalSubstate = handleCalBloodLeakWaitForCommandResponseState(); + break; + } + + return state; +} + +/*********************************************************************//** + * @brief * The getBloodLeakStatus function gets the current reading for the blood * leak detector. * @details Inputs: bloodLeakStatus @@ -683,24 +765,137 @@ /*********************************************************************//** * @brief + * The handleCalBloodLeakWaitForCommandState function handles the wait for + * command state. The state prepares the message to be sent to the blood leak + * sensor. + * @details Inputs: bloodLeakCalCharacter + * @details Outputs: bloodLeakCalCommandSquence, bloodLeakUARTCmdIndex + * @return next state + *************************************************************************/ +static BLOOD_LEAK_CAL_STATE_T handleCalBloodLeakWaitForCommandState( void ) +{ + BLOOD_LEAK_CAL_STATE_T state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; + + // Check if the requested command is set point, so if the character is S (for set point) + // then prepare the set point buffer to be sent + if ( bloodLeakCalASCIIChar == BLOOD_LEAK_SET_POINT_START_CHAR_ASCII ) + { + prepareSetPointSeq( bloodLeakCalSetPoint ); + } + else + { + // The requested command is not set point and so update the command sequence buffer. + // The first index of calibration command sequence is the requested command in ASCII. + bloodLeakCalCommandSquence[ 0 ] = bloodLeakCalASCIIChar; + bloodLeakUARTCmdIndex = 0; + } + + return state; +} + +/*********************************************************************//** + * @brief + * The handleCalBloodLeakSendCommandState function handles the send command + * state. The state sends the command sequence to the blood leak sensor one by + * one. + * @details Inputs: bloodLeakCalCharacter, bloodLeakUARTCmdIndex + * @details Outputs: bloodLeakCalCommandSquence, bloodLeakUARTCmdIndex + * @return next state + *************************************************************************/ +static BLOOD_LEAK_CAL_STATE_T handleCalBloodLeakSendCommandState( void ) +{ + BLOOD_LEAK_CAL_STATE_T state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; + + if ( bloodLeakCalASCIIChar == BLOOD_LEAK_SET_POINT_START_CHAR_ASCII ) + { + // Check if the current buffer index is less than the buffer length + if( bloodLeakUARTCmdIndex < bloodLeakSetPointSeqLength ) + { + U32 command = bloodLeakSetPointSequence[ bloodLeakUARTCmdIndex ]; + + // The active high index is the length - 2 they are the last two elements + U32 activeHighIndex = bloodLeakSetPointSeqLength - 2; + + // Check if the current index towards the end of the buffer which are FIFO set and FIFO reset + if( activeHighIndex > bloodLeakUARTCmdIndex ) + { + setFPGABloodLeakUARTTransmit( (U08)command ); + } + else + { + setFPGABloodLeakUARTControl( (U08)command ); + } + + bloodLeakUARTCmdIndex++; + } + else + { + bloodLeakCalASCIIChar = 0; + bloodLeakUARTCmdIndex = 0; + state = BLOOD_LEAK_CAL_WAIT_FOR_COMMAND_RESPONSE_STATE; + } + } + else + { + U32 command = bloodLeakCalCommandSquence[ bloodLeakUARTCmdIndex ]; + + // Check if the index is the stop writing to the FIFO bit. Up until the stop writing + // bit they are written to the UART channel and the high, low bits are written to the UART control + if ( bloodLeakUARTCmdIndex <= BLOOD_LEAK_EMB_MODE_STOP_INDEX ) + { + setFPGABloodLeakUARTTransmit( (U08)command ); + } + else + { + setFPGABloodLeakUARTControl( (U08)command ); + } + + // Done with writing all the commands, reset the index and transition + if ( bloodLeakUARTCmdIndex >= ( BLOOD_LEAK_CAL_COMMAND_SEQ_LENGTH - 1 ) ) + { + bloodLeakCalASCIIChar = 0; + bloodLeakUARTCmdIndex = 0; + state = BLOOD_LEAK_CAL_WAIT_FOR_COMMAND_RESPONSE_STATE; + } + else + { + bloodLeakUARTCmdIndex++; + } + } + + return state; +} + +static BLOOD_LEAK_CAL_STATE_T handleCalBloodLeakWaitForCommandResponseState( void ) +{ + BLOOD_LEAK_CAL_STATE_T state = BLOOD_LEAK_CAL_WAIT_FOR_COMMAND_RESPONSE_STATE; + + + return state; +} + +/*********************************************************************//** + * @brief * The prepareSetPointSeq function prepares the set point sequence to be * written to the blood leak sensor. * @details Inputs: none * @details Outputs: bloodLeakSetPointSequence, bloodLeakSetPointSeqLength + * @param setPoint the set point that has to be prepared to be sent to the sensor * @return none *************************************************************************/ -static void prepareSetPointSeq( void ) +static void prepareSetPointSeq( U16 setPoint ) { U08 i; // Set the local variables. U32 digitCount; - U32 setPoint = bloodLeakCalRecord.setPoint; - U32 bufferIndex = BLOOD_LEAK_SET_POINT_START_CHAR_INDEX; char tempCharBuffer[ BLOOD_LEAK_SET_POINT_MAX_CHAR_LENGTH ]; + + U32 bufferIndex = BLOOD_LEAK_SET_POINT_START_CHAR_INDEX; + memset( tempCharBuffer, 0x0, BLOOD_LEAK_SET_POINT_MAX_CHAR_LENGTH ); // Convert the set point number to the equivalent ASCII number with the unsigned integer data type - sprintf( tempCharBuffer, "%u", setPoint ); + sprintf( tempCharBuffer, "%u", (U32)setPoint ); // Calculate the length of the character buffer. strlen does not count the null character. digitCount = strlen( tempCharBuffer ); @@ -794,7 +989,7 @@ { U32 intvl = value / TASK_PRIORITY_INTERVAL; - result = TRUE; + result = TRUE; bloodLeakDataPublishInterval.ovData = intvl; bloodLeakDataPublishInterval.override = OVERRIDE_KEY; } @@ -816,7 +1011,7 @@ if ( TRUE == isTestingActivated() ) { - result = TRUE; + result = TRUE; bloodLeakDataPublishInterval.override = OVERRIDE_RESET; bloodLeakDataPublishInterval.ovData = bloodLeakDataPublishInterval.ovInitData; } @@ -842,7 +1037,7 @@ { if ( TRUE == isTestingActivated() ) { - result = TRUE; + result = TRUE; bloodLeakStatus.ovData = (U32)status; bloodLeakStatus.override = OVERRIDE_KEY; } @@ -866,12 +1061,91 @@ if ( TRUE == isTestingActivated() ) { - result = TRUE; + result = TRUE; bloodLeakStatus.override = OVERRIDE_RESET; bloodLeakStatus.ovData = bloodLeakStatus.ovInitData; } return result; } +/*********************************************************************//** + * @brief + * The testSetBloodLeak2EmbeddedMode function sets the blood leak driver to the + * embedded more for calibration. + * @details Inputs: none + * @details Outputs: bloodLeakSignalEmbeddedModeReq + * @return TRUE if switching to embedded mode was accepted otherwise, FALSE + *************************************************************************/ +BOOL testSetBloodLeak2EmbeddedMode( void ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + HD_OP_MODE_T mode = getCurrentOperationMode(); + + // Check if the mode is fault, service or standby before accepting a transition to + // the embedded mode + if ( ( MODE_FAUL == mode ) || ( MODE_SERV == mode ) || ( MODE_STAN == mode ) ) + { + bloodLeakSignalEmbeddedModeReq = TRUE; + result = TRUE; + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testSetBloodLeakCalibrationCommand function sets the blood leak calibration + * command. + * @details Inputs: bloodLeakSignalEmbeddedModeReq, bloodLeakCalSubstate + * @details Outputs: bloodLeakCalASCIIChar + * @return TRUE if the command is accepted otherwise, FALSE + *************************************************************************/ +BOOL testSetBloodLeakCalibrationCommand( U08 command ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + // If the HD is already in service mode and in the blood leak is in the embedded mode and the sensor is waiting for another command + if ( ( MODE_SERV == getCurrentOperationMode() ) && ( TRUE == bloodLeakSignalEmbeddedModeReq ) && + ( BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE == bloodLeakCalSubstate ) ) + { + bloodLeakCalASCIIChar = command; + } + } + + return result; +} + +/*********************************************************************//** + * @brief + * The testSetBloodLeakSetPoint function sets the blood leak set point in + * the embedded mode. + * @details Inputs: bloodLeakSignalEmbeddedModeReq, bloodLeakCalSubstate + * @details Outputs: bloodLeakCalASCIIChar, bloodLeakCalSetPoint + * @return TRUE if the set point is accepted otherwise, FALSE + *************************************************************************/ +BOOL testSetBloodLeakSetPoint( U16 setPoint ) +{ + BOOL result = FALSE; + + if ( TRUE == isTestingActivated() ) + { + // If the HD is already in service mode and in the blood leak is in the embedded mode and the sensor is waiting for another command + if ( ( MODE_SERV == getCurrentOperationMode() ) && ( TRUE == bloodLeakSignalEmbeddedModeReq ) && + ( BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE == bloodLeakCalSubstate ) ) + { + bloodLeakCalASCIIChar = BLOOD_LEAK_SET_POINT_START_CHAR_ASCII; + bloodLeakCalSetPoint = setPoint; + } + } + + return result; +} + /**@}*/