Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -rea3922a0b9f1cec5becaa26e2ba5f34ab4579209 -r050984357442e3ee0d6d5b21e274c1306643c598 --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision ea3922a0b9f1cec5becaa26e2ba5f34ab4579209) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 050984357442e3ee0d6d5b21e274c1306643c598) @@ -69,6 +69,10 @@ #define BLOOD_LEAK_EMB_MODE_RX_TIMEOUT_MS ( 5 * MS_PER_SECOND ) ///< Blood leak embedded mode calibration receive timeout in milliseconds. #define BLOOD_LEAK_EMB_MODE_RX_BUFFER_EMPTY 0x80 ///< Blood leak embedded mode buffer empty value. #define BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN 5 ///< Blood leak embedded mode number of commands. +#define BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES 4 ///< Blood leak embedded mode max number of command tries. +#define BLOOD_LEAK_EMB_MODE_0_NUM_ASCII 48 ///< Blood leak embedded mode character 0 in ASCII. +#define BLOOD_LEAK_EMB_MODE_9_NUM_ASCII 57 ///< Blood leak embedded mode character 9 in ASCII. +#define BLOOD_LEAK_EMB_MODE_SET_PNT_RESP_LEN 4 ///< Blood leak embedded mode set point response length. /// Defined states for the blood leak detector state machine. typedef enum BloodLeakStates @@ -91,28 +95,10 @@ { 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_EMB_WAIT_FOR_COMMAND_TO_SETTLE_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_EMB_MODE_STATE_T; -/// Defined embedded commands -/*typedef enum EmbCommands -{ - NU = 0, ///< Null command. - CS = 19, ///< Control S command to switch to embedded mode. - SP = 83, ///< Set point command to set the set point. - T = 84, ///< Self test command. - G = 71, ///< Get self test command. - I = 73, ///< Intensity command. - V = 86, ///< Blood detection level command. - Z = 90, ///< Zero sensor command. - Q = 81, ///< Zero sensor confirm command. - D = 68, ///< Display blood detection command. - C = 67, ///< Calibration sensor command. - NUM_OF_EMB_CMDS, ///< Number of embedded mode commands. -} EMB_MODE_CMD_T;*/ - enum EmbCommands { NU = 0, ///< Null command. @@ -132,10 +118,10 @@ /// Embedded mode commands specifications typedef struct { - U08 commandASCII; - U08 expChar1; - U08 expChar2; - U08 length; + U08 commandASCII; ///< Blood leak sensor command ID number in ASCII. + U08 expChar1; ///< Blood leak sensor expected response in character. + U08 expChar2; ///< Blood leak sensor expected response in character. + U08 length; ///< Blood leak sensor expected response length in bytes. } EMB_MODE_CMD_T; // ********** private data ********** @@ -180,6 +166,7 @@ static EMB_MODE_CMD_T bloodLeakEmbModeCmd [ NUM_OF_EMB_CMDS ]; ///< Blood leak embedded mode commands. static U08 bloodLeakEmbModeRespBuffer[ BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN ]; ///< Blood leak embedded mode response buffer. static U32 bloodLeakEmbModeRespIndex; ///< Blood leak embedded mode response buffer index. +static U32 bloodLeakEmbModeNumOfCmdTries; ///< Blood leak embedded mode number of command trials. // ********** private function prototypes ********** @@ -196,7 +183,6 @@ static BLOOD_LEAK_EMB_MODE_STATE_T handleCalBloodLeakWaitForCommandState( void ); static BLOOD_LEAK_EMB_MODE_STATE_T handleCalBloodLeakSendCommandState( void ); -static BLOOD_LEAK_EMB_MODE_STATE_T handleCalBloodLeakWaitForCommandToSettleState( void ); static BLOOD_LEAK_EMB_MODE_STATE_T handleCalBloodLeakWaitForCommandResponseState( void ); static void prepareSetPointSeq( U16 setPoint ); @@ -214,7 +200,7 @@ * bloodLeakCommandWriteTryCount, bloodLeakGetCalStartTime, bloodLeakEmbModeSubstate * bloodLeakIsPOSTComplete, bloodLeakPersistenceCtr, bloodLeakSignalEmbModeReq, * bloodLeakEmbModeRqstedCmd, bloodLeakEmbModeOpsStartTime, bloodLeakEmbModeRespBuffer, - * bloodLeakEmbModeRespIndex + * bloodLeakEmbModeRespIndex, bloodLeakEmbModeNumOfCmdTries * @return none *************************************************************************/ void initBloodLeak( void ) @@ -242,6 +228,7 @@ bloodLeakEmbModeSubstate = BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE; bloodLeakEmbModeOpsStartTime = 0; bloodLeakEmbModeRespIndex = 0; + bloodLeakEmbModeNumOfCmdTries = 0; // Set the blood leak set pint sequence to 0 to be initialized memset( bloodLeakSetPointSequence, 0x0, BLOOD_LEAK_SET_POINT_SEQ_MAX_LENGTH ); @@ -778,10 +765,6 @@ bloodLeakEmbModeSubstate = handleCalBloodLeakSendCommandState(); break; - case BLOOD_LEAK_EMB_WAIT_FOR_COMMAND_TO_SETTLE_STATE: - bloodLeakEmbModeSubstate = handleCalBloodLeakWaitForCommandToSettleState(); - break; - case BLOOD_LEAK_CAL_WAIT_FOR_COMMAND_RESPONSE_STATE: bloodLeakEmbModeSubstate = handleCalBloodLeakWaitForCommandResponseState(); break; @@ -843,6 +826,8 @@ { BLOOD_LEAK_EMB_MODE_STATE_T state = BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE; + U08 test = getFPGABloodLeakTxFIFOCount(); + switch( bloodLeakEmbModeRqstedCmd ) { case NU: @@ -862,12 +847,15 @@ // The first index of calibration command sequence is the requested command in ASCII. bloodLeakEmbModeCmdSquence[ 0 ] = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].commandASCII; bloodLeakUARTCmdIndex = 0; + bloodLeakEmbModeNumOfCmdTries = 0; state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; break; case SP: prepareSetPointSeq( bloodLeakEmbModeSetPoint ); - state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; + + bloodLeakEmbModeNumOfCmdTries = 0; + state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; break; } @@ -916,8 +904,8 @@ // The active high index is the length - 2 they are the last two elements U32 activeHighIndex = bloodLeakSetPointSeqLength - 2; command = bloodLeakSetPointSequence[ bloodLeakUARTCmdIndex ]; - isUARTTxDone = ( activeHighIndex > bloodLeakUARTCmdIndex ? TRUE : FALSE ); - isUARTCtrlDone = FALSE; + isUARTTxDone = ( bloodLeakUARTCmdIndex >= activeHighIndex ? TRUE : FALSE ); + isUARTCtrlDone = ( bloodLeakUARTCmdIndex > bloodLeakSetPointSeqLength ? TRUE : FALSE ); bloodLeakUARTCmdIndex++; } @@ -928,6 +916,9 @@ // Check if the current index towards the end of the buffer which are FIFO set and FIFO reset if ( FALSE == isUARTCtrlDone ) { + // TODO test this + //FALSE == isUARTTxDone ? setFPGABloodLeakUARTTransmit( (U08)command ) : setFPGABloodLeakUARTControl( (U08)command ); + if( FALSE == isUARTTxDone ) { setFPGABloodLeakUARTTransmit( (U08)command ); @@ -940,24 +931,11 @@ else { // Reset the variables for the next - bloodLeakEmbModeOpsStartTime = getMSTimerCount(); - state = BLOOD_LEAK_EMB_WAIT_FOR_COMMAND_TO_SETTLE_STATE; - } + bloodLeakEmbModeOpsStartTime = getMSTimerCount(); + bloodLeakUARTCmdIndex = 0; + bloodLeakEmbModeRespIndex = 0; + state = BLOOD_LEAK_CAL_WAIT_FOR_COMMAND_RESPONSE_STATE; - return state; -} - -static BLOOD_LEAK_EMB_MODE_STATE_T handleCalBloodLeakWaitForCommandToSettleState( void ) -{ - BLOOD_LEAK_EMB_MODE_STATE_T state = BLOOD_LEAK_EMB_WAIT_FOR_COMMAND_TO_SETTLE_STATE; - - if ( TRUE == didTimeout( bloodLeakEmbModeOpsStartTime, 20 ) ) - { - bloodLeakEmbModeOpsStartTime = getMSTimerCount(); - bloodLeakUARTCmdIndex = 0; - bloodLeakEmbModeRespIndex = 0; - state = BLOOD_LEAK_CAL_WAIT_FOR_COMMAND_RESPONSE_STATE; - memset( bloodLeakEmbModeRespBuffer, 0x0, BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN ); } @@ -976,29 +954,38 @@ { BLOOD_LEAK_EMB_MODE_STATE_T state = BLOOD_LEAK_CAL_WAIT_FOR_COMMAND_RESPONSE_STATE; U08 rxFIFOCount = getFPGABloodLeakRxFIFOCount(); + U08 length = 0; if ( rxFIFOCount > 0 ) { /* + * There are 3 types of data that can be received from the the sensor: * 1. It could be a start character and the length (i.e. VXXXX) * 2. It could be two discrete characters (i.e. P, F) * 3. It could be none of the two characters (i.e. XXXX) */ + length = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].length; U08 data = getFPGABloodLeakRxFIFODataOut(); U08 expChar1 = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].expChar1; U08 expChar2 = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].expChar2; - U08 length = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].length; + U08 command = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].commandASCII; if ( ( expChar1 != NU ) && ( NU == expChar2 ) ) { + // This is the case that there is a start character. If current character buffer index is less than the + // length of the expected response of the command. if ( bloodLeakEmbModeRespIndex < length ) { + // Check if the expected char is received and the response buffer is empty because the index is 0, + // insert the buffer data if ( ( expChar1 == data ) && ( 0 == bloodLeakEmbModeRespIndex ) ) { bloodLeakEmbModeRespBuffer[ bloodLeakEmbModeRespIndex ] = data; bloodLeakEmbModeRespIndex++; } + // Check if the buffer index is > 0 so the first char has been inserted and the rest is data + // For instance, V has been inserted and XXX is inserted that is followed by V. So V123. else if ( bloodLeakEmbModeRespIndex > 0 ) { bloodLeakEmbModeRespBuffer[ bloodLeakEmbModeRespIndex ] = data; @@ -1009,26 +996,95 @@ } else if ( ( expChar1 != NU ) && ( expChar2 != NU ) ) { + // This is the case that both expected chars are not null. Either of the chars are accepted like P or F if ( bloodLeakEmbModeRespIndex < length ) { + // Check if either of the expected chars are received and if they are insert it into the response buffer if ( ( expChar1 == data ) || ( expChar2 == data ) ) { bloodLeakEmbModeRespBuffer[ bloodLeakEmbModeRespIndex ] = data; bloodLeakEmbModeRespIndex++; } } + + if ( BLOOD_LEAK_SET_POINT_START_CHAR_ASCII == command ) + { + // There is an exception in this case which is the set point command. + // The set point command can either receive X for timeout or F if the command failed. + // But if the command was received properly, the response is XXXX. For example if set point is 200, the response is 0200 + // The response buffer length of a successful set point is 4 characters (XXXX) + if ( bloodLeakEmbModeRespIndex < BLOOD_LEAK_EMB_MODE_SET_PNT_RESP_LEN ) + { + U08 spResponse = bloodLeakEmbModeRespBuffer[ 0 ]; + length = BLOOD_LEAK_EMB_MODE_SET_PNT_RESP_LEN; + + if ( ( spResponse != expChar1 ) && ( spResponse != expChar2 ) ) + { + // Check if the failed and timeout characters are not inserted + // Check if the response buffer has not been filled and the current received data is a number in between 0 to 9 + if ( ( data >= BLOOD_LEAK_EMB_MODE_0_NUM_ASCII ) && ( data <= BLOOD_LEAK_EMB_MODE_9_NUM_ASCII ) ) + { + bloodLeakEmbModeRespBuffer[ bloodLeakEmbModeRespIndex ] = data; + + bloodLeakEmbModeRespIndex++; + } + } + } + } } + else if ( ( NU == expChar1 ) && ( NU == expChar2 ) ) + { + // This is the case that there are no expected characters and the received value are numbers + if ( bloodLeakEmbModeRespIndex < length ) + { + // If the received character is in the range of numbers chars (0 to 9), then insert them into the response buffer + if ( ( data >= BLOOD_LEAK_EMB_MODE_0_NUM_ASCII ) && ( data <= BLOOD_LEAK_EMB_MODE_9_NUM_ASCII ) ) + { + bloodLeakEmbModeRespBuffer[ bloodLeakEmbModeRespIndex ] = data; - BOOL test = FALSE; + bloodLeakEmbModeRespIndex++; + } + } + } + + BOOL test = FALSE; // TODO for testing remove } - // If wait for the receive FIFO has timed out or all there is no buffer left in the Rx FIFO transition back to wait for command - // state for the next command + // If wait for the receive FIFO has timed out or all there is no buffer left in the Rx FIFO transition back to wait for command state for the next command if ( ( TRUE == didTimeout( bloodLeakEmbModeOpsStartTime, BLOOD_LEAK_EMB_MODE_RX_TIMEOUT_MS ) ) || ( BLOOD_LEAK_EMB_MODE_RX_BUFFER_EMPTY == rxFIFOCount ) ) { - bloodLeakEmbModeRqstedCmd = NU; - state = BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE; + // Check if the first element of the response buffer is null and the number of tries has not exceeded. When the response buffer is + // null but it is the end of the receive buffer it means no response has been received back + if ( ( NU == bloodLeakEmbModeRespBuffer[ 0 ] ) && ( ++bloodLeakEmbModeNumOfCmdTries < BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) ) + { + state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; + } + else + { + U08 i; + + BOOL isNull = FALSE; + + for ( i = 0; i < length; i++ ) + { + isNull |= ( bloodLeakEmbModeRespBuffer[ i ] != NU ? FALSE : TRUE ); + } + + // Check if the failed command is Control S which is switch to embedded mode and if + // it failed set the embedded mode request to false so the other commands cannot be sent again + bloodLeakSignalEmbModeReq = ( ( CS == bloodLeakEmbModeRqstedCmd ) && ( NU == bloodLeakEmbModeRespBuffer[ 0 ] ) ? FALSE : TRUE ); + + if ( ( TRUE == isNull ) && ( bloodLeakEmbModeNumOfCmdTries < BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) ) + { + state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; + } + else + { + bloodLeakEmbModeRqstedCmd = NU; + state = BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE; + } + } } return state; @@ -1083,10 +1139,10 @@ bufferIndex++; // Set active high and active low into the buffer - bloodLeakSetPointSequence[ bufferIndex ] = BLOOD_LEAK_UART_COMM_ACTIVE_HIGH; + bloodLeakSetPointSequence[ bufferIndex ] = ( TRUE == bloodLeakSignalEmbModeReq ? BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_HIGH : BLOOD_LEAK_UART_COMM_ACTIVE_HIGH ); bufferIndex++; - bloodLeakSetPointSequence[ bufferIndex ] = BLOOD_LEAK_UART_COMM_ACTIVE_LOW; + bloodLeakSetPointSequence[ bufferIndex ] = ( TRUE == bloodLeakSignalEmbModeReq ? BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW : BLOOD_LEAK_UART_COMM_ACTIVE_LOW ); // Update the sequence length for writing to the sensor bloodLeakSetPointSeqLength = bufferIndex + 1; @@ -1119,7 +1175,6 @@ data.bloodLeakStCount = (U32)getFPGABloodLeakStCount(); data.bloodLeakLEDIntesity = (U32)getFPGABloodLeakLEDIntensity(); data.bloodLeakRegisterCounter = (U32)getFPGABloodLeakRegisterCounter(); - data.bloodLeakEmbModeRxChars = 0; broadcastData( MSG_ID_HD_BLOOD_LEAK_DATA, COMM_BUFFER_OUT_CAN_HD_BROADCAST, (U08*)&data, sizeof( BLOOD_LEAK_DATA_T ) ); bloodLeakDataPublicationTimerCounter = 0; @@ -1130,66 +1185,77 @@ * @brief * The initEmbModeSpecs function initializes the embedded mode specifications * structure. - * @details Inputs: bloodLeakEmbModeCmd + * @details Inputs: none * @details Outputs: bloodLeakEmbModeCmd * @return none *************************************************************************/ static void initEmbModeSpecs( void ) { - bloodLeakEmbModeCmd[ NU ].commandASCII = 0; - bloodLeakEmbModeCmd[ NU ].expChar1 = 0; - bloodLeakEmbModeCmd[ NU ].expChar2 = 0; - bloodLeakEmbModeCmd[ NU ].length = 0; + // Null command + bloodLeakEmbModeCmd[ NU ].commandASCII = NU; + bloodLeakEmbModeCmd[ NU ].expChar1 = NU; + bloodLeakEmbModeCmd[ NU ].expChar2 = NU; + bloodLeakEmbModeCmd[ NU ].length = 0; - bloodLeakEmbModeCmd[ CS ].commandASCII = 19; - bloodLeakEmbModeCmd[ CS ].expChar1 = 69; // ASCII for E (Embedded ...) - bloodLeakEmbModeCmd[ CS ].expChar2 = NU; - bloodLeakEmbModeCmd[ CS ].length = 5; + // Control S command + bloodLeakEmbModeCmd[ CS ].commandASCII = 19; // ASCII for Control S + bloodLeakEmbModeCmd[ CS ].expChar1 = 69; // ASCII for E (Embedded ...) + bloodLeakEmbModeCmd[ CS ].expChar2 = NU; + bloodLeakEmbModeCmd[ CS ].length = 5; - bloodLeakEmbModeCmd[ SP ].commandASCII = 83; - bloodLeakEmbModeCmd[ SP ].expChar1 = 88; // ASCII for X (Timeout) - bloodLeakEmbModeCmd[ SP ].expChar2 = 70; // ASCII for F (Fail) - bloodLeakEmbModeCmd[ SP ].length = 0; + // Set point command + bloodLeakEmbModeCmd[ SP ].commandASCII = 83; // ASCII for S + bloodLeakEmbModeCmd[ SP ].expChar1 = 88; // ASCII for X (Timeout) + bloodLeakEmbModeCmd[ SP ].expChar2 = 70; // ASCII for F (Fail) + bloodLeakEmbModeCmd[ SP ].length = 1; - bloodLeakEmbModeCmd[ T ].commandASCII = 84; - bloodLeakEmbModeCmd[ T ].expChar1 = 80; // ASCII for P - bloodLeakEmbModeCmd[ T ].expChar2 = 70; // ASCII for F - bloodLeakEmbModeCmd[ T ].length = 1; + // Self test command + bloodLeakEmbModeCmd[ T ].commandASCII = 84; // ASCII for T + bloodLeakEmbModeCmd[ T ].expChar1 = 80; // ASCII for P + bloodLeakEmbModeCmd[ T ].expChar2 = 70; // ASCII for F + bloodLeakEmbModeCmd[ T ].length = 1; - bloodLeakEmbModeCmd[ G ].commandASCII = 71; - bloodLeakEmbModeCmd[ G ].expChar1 = 0; - bloodLeakEmbModeCmd[ G ].expChar2 = 0; - bloodLeakEmbModeCmd[ G ].length = 3; + // Get self test command + bloodLeakEmbModeCmd[ G ].commandASCII = 71; // ASCII for G + bloodLeakEmbModeCmd[ G ].expChar1 = NU; + bloodLeakEmbModeCmd[ G ].expChar2 = NU; + bloodLeakEmbModeCmd[ G ].length = 4; - bloodLeakEmbModeCmd[ I ].commandASCII = 73; - bloodLeakEmbModeCmd[ I ].expChar1 = 0; - bloodLeakEmbModeCmd[ I ].expChar2 = 0; - bloodLeakEmbModeCmd[ I ].length = 3; + // Intensity command + bloodLeakEmbModeCmd[ I ].commandASCII = 73; // ASCII for I + bloodLeakEmbModeCmd[ I ].expChar1 = NU; + bloodLeakEmbModeCmd[ I ].expChar2 = NU; + bloodLeakEmbModeCmd[ I ].length = 4; - bloodLeakEmbModeCmd[ V ].commandASCII = 86; - bloodLeakEmbModeCmd[ V ].expChar1 = 86; - bloodLeakEmbModeCmd[ V ].expChar2 = 0; - bloodLeakEmbModeCmd[ V ].length = 5; + // Blood detection command + bloodLeakEmbModeCmd[ V ].commandASCII = 86; // ASCII for V + bloodLeakEmbModeCmd[ V ].expChar1 = 86; + bloodLeakEmbModeCmd[ V ].expChar2 = NU; + bloodLeakEmbModeCmd[ V ].length = 5; - bloodLeakEmbModeCmd[ Z ].commandASCII = 90; - bloodLeakEmbModeCmd[ Z ].expChar1 = 89; // ASCII for Y - bloodLeakEmbModeCmd[ Z ].expChar2 = 0; - bloodLeakEmbModeCmd[ Z ].length = 1; + // Zero sensor command + bloodLeakEmbModeCmd[ Z ].commandASCII = 90; // ASCII for Z + bloodLeakEmbModeCmd[ Z ].expChar1 = 89; // ASCII for Y + bloodLeakEmbModeCmd[ Z ].expChar2 = NU; + bloodLeakEmbModeCmd[ Z ].length = 1; - bloodLeakEmbModeCmd[ Q ].commandASCII = 81; - bloodLeakEmbModeCmd[ Q ].expChar1 = 80; // ASCII for P - bloodLeakEmbModeCmd[ Q ].expChar2 = 70; // ASCII for F - bloodLeakEmbModeCmd[ Q ].length = 1; + // Zero confirm command + bloodLeakEmbModeCmd[ Q ].commandASCII = 81; // ASCII for Q + bloodLeakEmbModeCmd[ Q ].expChar1 = 80; // ASCII for P + bloodLeakEmbModeCmd[ Q ].expChar2 = 70; // ASCII for F + bloodLeakEmbModeCmd[ Q ].length = 1; - bloodLeakEmbModeCmd[ D ].commandASCII = 68; - bloodLeakEmbModeCmd[ D ].expChar1 = 68; // ASCII for D - bloodLeakEmbModeCmd[ D ].expChar2 = 0; - bloodLeakEmbModeCmd[ D ].length = 5; + // Display blood detection command + bloodLeakEmbModeCmd[ D ].commandASCII = 68; + bloodLeakEmbModeCmd[ D ].expChar1 = 68; // ASCII for D + bloodLeakEmbModeCmd[ D ].expChar2 = NU; + bloodLeakEmbModeCmd[ D ].length = 5; - bloodLeakEmbModeCmd[ C ].commandASCII = 67; - bloodLeakEmbModeCmd[ C ].expChar1 = 67; // ASCII for C - bloodLeakEmbModeCmd[ C ].expChar2 = 0; - bloodLeakEmbModeCmd[ C ].length = 4; + // Calibrate command + bloodLeakEmbModeCmd[ C ].commandASCII = 67; + bloodLeakEmbModeCmd[ C ].expChar1 = 67; // ASCII for C + bloodLeakEmbModeCmd[ C ].expChar2 = NU; + bloodLeakEmbModeCmd[ C ].length = 4; } @@ -1316,7 +1382,7 @@ if ( ( MODE_FAUL == mode ) || ( MODE_SERV == mode ) || ( MODE_STAN == mode ) ) { bloodLeakSignalEmbModeReq = TRUE; - bloodLeakEmbModeRqstedCmd = CS; + bloodLeakEmbModeRqstedCmd = CS; result = TRUE; } } @@ -1330,49 +1396,28 @@ * calibration command. * @details Inputs: bloodLeakSignalEmbeddedModeReq, bloodLeakCalSubstate * @details Outputs: bloodLeakCalASCIIChar + * @param command the command ID to be sent to blood leak in embedded mode + * @param setpointPayload the set point value that is sent with the set point + * command. This value is 0 with other commands since they do not have a payload * @return TRUE if the command is accepted otherwise, FALSE *************************************************************************/ -BOOL testSetBloodLeakEmbeddedModeCommand( U08 command ) +BOOL testSetBloodLeakEmbeddedModeCommand( U08 command, U16 setPointPayload ) { BOOL result = FALSE; - if ( TRUE == isTestingActivated() ) + if ( ( TRUE == isTestingActivated() ) && ( command < NUM_OF_EMB_CMDS ) ) { // 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 == bloodLeakSignalEmbModeReq ) && ( BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE == bloodLeakEmbModeSubstate ) ) { bloodLeakEmbModeRqstedCmd = command; + bloodLeakEmbModeSetPoint = setPointPayload; + result = TRUE; } } 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 == bloodLeakSignalEmbModeReq ) && - ( BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE == bloodLeakEmbModeSubstate ) ) - { - bloodLeakEmbModeRqstedCmd = SP; - bloodLeakEmbModeSetPoint = setPoint; - } - } - - return result; -} - /**@}*/