Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -r91913f55375f8e6b3e443c154a3132e9f4ef54af -r8ae411fa0d1b5da4aefdf44d2a7f28c94c78ed8d --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 91913f55375f8e6b3e443c154a3132e9f4ef54af) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 8ae411fa0d1b5da4aefdf44d2a7f28c94c78ed8d) @@ -50,7 +50,7 @@ #define BLOOD_LEAK_STOP_WRITE_FIFO_COMMAND 0 ///< Blood leak set point stop writing to FIFO command. #define BLOOD_LEAK_SET_POINT_START_CHAR_INDEX 0 ///< Blood leak set point sequence start character index number. #define BLOOD_LEAK_CARRIAGE_RETURN_ASCII 13 ///< Blood leak set point sequence carriage return character in ASCII. -#define BLOOD_LEAK_SET_POINT_SEQ_MAX_LENGTH 15 ///< Blood leak set point sequence maximum length. +#define BLOOD_LEAK_SET_POINT_SEQ_MAX_LENGTH 17 ///< Blood leak set point sequence maximum length. #define BLOOD_LEAK_WAIT_2_READ_SET_POINT ( 1 * MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Blood leak wait to read set point in counts. #define BLOOD_LEAK_WAIT_2_READ_CTRL_U ( 1 * MS_PER_SECOND / TASK_PRIORITY_INTERVAL ) ///< Blood leak wait to read control U in counts. @@ -63,12 +63,11 @@ // Embedded mode defines #define BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH 6 ///< Blood leak embedded mode command sequence length. -#define BLOOD_LEAK_EMB_MODE_STOP_INDEX 1 // TODO remove ///< Blood leak embedded mode stop writing to FIFO index. +#define BLOOD_LEAK_EMB_MODE_RQST_RX_LENGTH 2 ///< Blood leak embedded mode request new Rx data length. #define BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_HIGH 5 ///< Blood leak embedded mode communication active high command. #define BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW 4 ///< Blood leak embedded mode communication active low command. #define BLOOD_LEAK_EMB_MODE_COMM_RESET 6 ///< Blood leak embedded mode communication reset. #define BLOOD_LEAK_EMB_MODE_COMM_READ_REQST 12 ///< Blood leak embedded mode communication read Rx byte request. -#define BLOOD_LEAK_EMB_MODE_RX_TIMEOUT_MS ( 5 * MS_PER_SECOND ) // TODO remove ///< 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. @@ -77,7 +76,15 @@ #define BLOOD_LEAK_EMB_MODE_SET_PNT_RESP_LEN 4 ///< Blood leak embedded mode set point response length. #define BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX 0 ///< Blood leak embedded mode command (UART/Transmit) column index number. #define BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX 1 ///< Blood leak embedded mode is command type UART or transmit flag. +#define BLOOD_LEAK_EMB_MODE_PASS_ASCII 80 ///< Blood leak embedded mode P (pass) in ASCII. +#define BLOOD_LEAK_EMB_MODE_FAIL_ASCII 70 ///< Blood leak embedded mode F (fail) in ASCII. +#define BLOOD_LEAK_EMB_MODE_RESET_INDEX 0 ///< Blood leak embedded mode reset FIFO command index. +#define BLOOD_LEAK_EMB_MODE_CMD_INDEX 2 ///< Blood leak embedded mode command index. +#define BLOOD_LEAK_EMB_MODE_STOP_WRITE_INDEX 3 ///< Blood leak embedded mode stop write to FIFO index. +#define BLOOD_LEAK_EMB_MODE_ACTIVE_HIGH_INDEX 4 ///< Blood leak embedded mode active high command index. +#define BLOOD_LEAK_EMB_MODE_REQUEST_RX_INDEX 0 ///< Blood leak embedded mode request Rx to read index. + /// Defined states for the blood leak detector state machine. typedef enum BloodLeakStates { @@ -125,8 +132,8 @@ 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. - U32 timeout; ///< Blood leak sensor receive timeout. + U32 length; ///< Blood leak sensor expected response length in bytes. + U32 timeoutMS; ///< Blood leak sensor receive timeout in milliseconds. } EMB_MODE_CMD_T; // ********** private data ********** @@ -147,7 +154,7 @@ static U32 bloodLeakDataPublicationTimerCounter; ///< Timer counter used to schedule blood leak data publication to CAN bus. 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 U08 bloodLeakSetPointSequence[ BLOOD_LEAK_SET_POINT_SEQ_MAX_LENGTH ][ 2 ]; ///< 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. static HD_BLOOD_LEAK_SENSOR_CAL_RECORD_T bloodLeakCalRecord; ///< Blood leak calibration record structure. @@ -165,18 +172,16 @@ // Embedded mode variables static BOOL bloodLeakSignalEmbModeReq; ///< Blood leak signal embedded mode has been requested. static U08 bloodLeakEmbModeRqstedCmd; ///< Blood leak signal embedded mode requested command. -// TOOD this has changed for the systems team testing static U08 bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH ][ 2 ]; ///< Blood leak embedded mode command sequence. static BLOOD_LEAK_EMB_MODE_STATE_T bloodLeakEmbModeSubstate; ///< Blood leak embedded mode state. static U32 bloodLeakEmbModeOpsStartTime; ///< Blood leak embedded mode operations start time. static U16 bloodLeakEmbModeSetPoint; ///< Blood leak embedded mode set point command. 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 bloodLeakEmbModeCmdSeqLength; ///< Blood leak embedded mode command sequence length. static U32 bloodLeakEmbModeNumOfCmdTries; // TODO remove? ///< Blood leak embedded mode number of command trials. -static BOOL areTempDone; - // ********** private function prototypes ********** static BLOOD_LEAK_STATE_T handleBloodLeakWaitForPostState( void ); @@ -194,6 +199,7 @@ static BLOOD_LEAK_EMB_MODE_STATE_T handleCalBloodLeakSendCommandState( void ); static BLOOD_LEAK_EMB_MODE_STATE_T handleCalBloodLeakWaitForCommandResponseState( void ); +static void processReceivedEmbModeChar( U08 data ); static void prepareSetPointSeq( U16 setPoint ); static void publishBloodLeakData( void ); static void initEmbModeSpecs( void ); @@ -209,7 +215,8 @@ * bloodLeakCommandWriteTryCount, bloodLeakGetCalStartTime, bloodLeakEmbModeSubstate * bloodLeakIsPOSTComplete, bloodLeakPersistenceCtr, bloodLeakSignalEmbModeReq, * bloodLeakEmbModeRqstedCmd, bloodLeakEmbModeOpsStartTime, bloodLeakEmbModeRespBuffer, - * bloodLeakEmbModeRespIndex, bloodLeakEmbModeNumOfCmdTries, bloodLeakExitNormalRequested + * bloodLeakEmbModeRespIndex, bloodLeakEmbModeNumOfCmdTries, bloodLeakExitNormalRequested, + * bloodLeakEmbModeCmdSeqLength * @return none *************************************************************************/ void initBloodLeak( void ) @@ -239,39 +246,19 @@ bloodLeakEmbModeRespIndex = 0; bloodLeakEmbModeNumOfCmdTries = 0; bloodLeakExitNormalRequested = FALSE; + bloodLeakEmbModeCmdSeqLength = 0; // 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 embedded mode response buffer memset( bloodLeakEmbModeRespBuffer, 0x0, BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN ); - // Initialize the blood leak calibration command sequence array. - bloodLeakEmbModeCmdSquence[ 0 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_RESET; - bloodLeakEmbModeCmdSquence[ 0 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + // Initialize the blood leak embedded mode command sequence + memset( bloodLeakEmbModeCmdSquence, 0x0, BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH ); - bloodLeakEmbModeCmdSquence[ 1 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW; - bloodLeakEmbModeCmdSquence[ 1 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; - - bloodLeakEmbModeCmdSquence[ 2 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = NU_EMB_MODE_CMD; - bloodLeakEmbModeCmdSquence[ 2 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = FALSE; - - bloodLeakEmbModeCmdSquence[ 3 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_STOP_WRITE_FIFO_COMMAND; - bloodLeakEmbModeCmdSquence[ 3 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = FALSE; - - bloodLeakEmbModeCmdSquence[ 4 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_HIGH; - bloodLeakEmbModeCmdSquence[ 4 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; - - bloodLeakEmbModeCmdSquence[ 5 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW; - bloodLeakEmbModeCmdSquence[ 5 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; - - //bloodLeakEmbModeCmdSquence[ 5 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_READ_REQST; - //bloodLeakEmbModeCmdSquence[ 5 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; - // Initialize the embedded mode specifications initEmbModeSpecs(); - - areTempDone = TRUE; } /*********************************************************************//** @@ -594,7 +581,7 @@ // Check if the current buffer index is less than the buffer length if( bloodLeakUARTCmdIndex < bloodLeakSetPointSeqLength ) { - U32 command = bloodLeakSetPointSequence[ bloodLeakUARTCmdIndex ]; + U32 command = bloodLeakSetPointSequence[ bloodLeakUARTCmdIndex ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ]; // The active high index is the length - 2 they are the last two elements U32 activeHighIndex = bloodLeakSetPointSeqLength - 2; @@ -877,7 +864,7 @@ static BLOOD_LEAK_EMB_MODE_STATE_T handleCalBloodLeakWaitForCommandState( void ) { BLOOD_LEAK_EMB_MODE_STATE_T state = BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE; - U08 test = getFPGABloodLeakTxFIFOCount(); + U08 command = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].commandASCII; switch( bloodLeakEmbModeRqstedCmd ) { @@ -894,20 +881,39 @@ case Q_EMB_MODE_CMD: case D_EMB_MODE_CMD: case C_EMB_MODE_CMD: - // 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. - bloodLeakEmbModeCmdSquence[ 2 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].commandASCII; + + // First clear the buffer from the older data + memset( bloodLeakEmbModeCmdSquence, 0x0, BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH ); + + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_RESET_INDEX ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_RESET; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_RESET_INDEX ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_RESET_INDEX + 1 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_RESET_INDEX + 1 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_CMD_INDEX ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = command; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_CMD_INDEX ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = FALSE; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_STOP_WRITE_INDEX ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_STOP_WRITE_FIFO_COMMAND; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_STOP_WRITE_INDEX ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = FALSE; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_ACTIVE_HIGH_INDEX ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_HIGH; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_ACTIVE_HIGH_INDEX ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_ACTIVE_HIGH_INDEX + 1 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_ACTIVE_HIGH_INDEX + 1 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + + // Set the variables for the next state bloodLeakUARTCmdIndex = 0; bloodLeakEmbModeNumOfCmdTries = 0; + bloodLeakEmbModeRespIndex = 0; + bloodLeakEmbModeCmdSeqLength = BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH; state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; - - areTempDone = FALSE; + // Clear the response buffer to able to receive fresh data + memset( bloodLeakEmbModeRespBuffer, 0x0, BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN ); break; case SP_EMB_MODE_CMD: prepareSetPointSeq( bloodLeakEmbModeSetPoint ); bloodLeakEmbModeNumOfCmdTries = 0; state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; + // Clear the response buffer to able to receive fresh data + memset( bloodLeakEmbModeRespBuffer, 0x0, BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN ); break; } @@ -943,32 +949,33 @@ case C_EMB_MODE_CMD: command = bloodLeakEmbModeCmdSquence[ bloodLeakUARTCmdIndex ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ]; isUARTCtrlCmd = bloodLeakEmbModeCmdSquence[ bloodLeakUARTCmdIndex ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ]; - isUARTCtrlDone = ( bloodLeakUARTCmdIndex > ( BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH - 1 ) ? TRUE : FALSE ); + isUARTCtrlDone = ( bloodLeakUARTCmdIndex > ( bloodLeakEmbModeCmdSeqLength - 1 ) ? TRUE : FALSE ); bloodLeakUARTCmdIndex++; break; case SP_EMB_MODE_CMD: - // Check if the current buffer index is less than the buffer length - if( bloodLeakUARTCmdIndex < bloodLeakSetPointSeqLength ) - { - // The active high index is the length - 2 they are the last two elements - U32 activeHighIndex = bloodLeakSetPointSeqLength - 2; - command = bloodLeakSetPointSequence[ bloodLeakUARTCmdIndex ]; - isUARTCtrlCmd = ( bloodLeakUARTCmdIndex >= activeHighIndex ? TRUE : FALSE ); - isUARTCtrlDone = ( bloodLeakUARTCmdIndex > bloodLeakSetPointSeqLength ? TRUE : FALSE ); - bloodLeakUARTCmdIndex++; - } + command = bloodLeakSetPointSequence[ bloodLeakUARTCmdIndex ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ]; + isUARTCtrlCmd = bloodLeakSetPointSequence[ bloodLeakUARTCmdIndex ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ]; + isUARTCtrlDone= ( bloodLeakUARTCmdIndex > bloodLeakSetPointSeqLength ? TRUE : FALSE ); + bloodLeakUARTCmdIndex++; break; } + if ( ( bloodLeakEmbModeRqstedCmd != CS_EMB_MODE_CMD ) && ( bloodLeakUARTCmdIndex - 1 > BLOOD_LEAK_EMB_MODE_RESET_INDEX ) && + ( bloodLeakUARTCmdIndex - 1 <= BLOOD_LEAK_EMB_MODE_RESET_INDEX + 1 ) ) + { + if ( BLOOD_LEAK_EMB_MODE_RX_BUFFER_EMPTY == getFPGABloodLeakRxFIFOCount() ) + { + // Continue. TODO what should I do if this is not empty? + } + } + // 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 == isUARTCtrlCmd ? setFPGABloodLeakUARTTransmit( command ) : setFPGABloodLeakUARTControl( command ); - U08 test = getFPGABloodLeakTxFIFOCount(); - if( FALSE == isUARTCtrlCmd ) { setFPGABloodLeakUARTTransmit( command ); @@ -983,12 +990,8 @@ // Reset the variables for the next bloodLeakEmbModeOpsStartTime = getMSTimerCount(); bloodLeakUARTCmdIndex = 0; - bloodLeakEmbModeRespIndex = 0; + bloodLeakEmbModeCmdSeqLength = 0; state = BLOOD_LEAK_CAL_WAIT_FOR_COMMAND_RESPONSE_STATE; - - areTempDone = TRUE; - - memset( bloodLeakEmbModeRespBuffer, 0x0, BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN ); } return state; @@ -998,156 +1001,195 @@ * @brief * The handleCalBloodLeakWaitForCommandResponseState function handles the * wait for command responses state. The state receives data in the buffer. - * @details Inputs: TODO fill up - * @details Outputs: TODo fill up + * @details Inputs: bloodLeakEmbModeCmd, bloodLeakEmbModeRespIndex + * @details Outputs: bloodLeakEmbModeRespBuffer, bloodLeakEmbModeRespIndex * @return next state *************************************************************************/ static BLOOD_LEAK_EMB_MODE_STATE_T handleCalBloodLeakWaitForCommandResponseState( void ) { BLOOD_LEAK_EMB_MODE_STATE_T state = BLOOD_LEAK_CAL_WAIT_FOR_COMMAND_RESPONSE_STATE; U08 rxFIFOCount = getFPGABloodLeakRxFIFOCount(); - U08 length = 0; + BOOL hasCharBeenReceived = FALSE; + U32 commandTimeoutMS = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].timeoutMS; + U32 length = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].length; - U08 data = getFPGABloodLeakRxFIFODataOut(); // TODO remove - - if ( ( rxFIFOCount > 0 ) && ( TRUE == areTempDone ) ) + 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 command = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].commandASCII; + U08 data = getFPGABloodLeakRxFIFODataOut(); + hasCharBeenReceived = TRUE; + processReceivedEmbModeChar( data ); + } - if ( ( expChar1 != NU_EMB_MODE_CMD ) && ( NU_EMB_MODE_CMD == expChar2 ) ) + // 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 == hasCharBeenReceived ) + { + if ( bloodLeakEmbModeRespIndex >= length ) { - // 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 ) + U08 i; + BOOL isNull = FALSE; + + for ( i = 0; i < length; i++ ) { - // 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 but it is not the echo of the command - // For instance, V has been inserted and XXXX is inserted that is followed by V. So V123 and not VVV12. - else if ( ( bloodLeakEmbModeRespIndex > 0 ) && ( data != expChar1 ) ) - { - bloodLeakEmbModeRespBuffer[ bloodLeakEmbModeRespIndex ] = data; - bloodLeakEmbModeRespIndex++; - } + // Loop through the elements of the buffer and make sure none of the elements are not NULL. + // The elements are checked until the specified length that is expected for a command + isNull |= ( bloodLeakEmbModeRespBuffer[ i ] != NU_EMB_MODE_CMD ? FALSE : TRUE ); } - } - else if ( ( expChar1 != NU_EMB_MODE_CMD ) && ( expChar2 != NU_EMB_MODE_CMD ) ) - { - // 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 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_EMB_MODE_CMD == bloodLeakEmbModeRqstedCmd ) && ( NU_EMB_MODE_CMD == bloodLeakEmbModeRespBuffer[ 0 ] ) ? FALSE : TRUE ); + + if ( TRUE == isNull ) { - // 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++; - } + // There is null in the characters that were supposed to be received and not be null but null was found + // Clear the response buffer and write the ASCII fail in the first element of the response buffer + // Set the length to be 1 because there is only 1 character (fail) is in the buffer + memset( bloodLeakEmbModeRespBuffer, 0x0, BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN ); + length = 1; + bloodLeakEmbModeRespBuffer[ 0 ] = BLOOD_LEAK_EMB_MODE_FAIL_ASCII; } - - if ( BLOOD_LEAK_SET_POINT_START_CHAR_ASCII == command ) + else if ( CS_EMB_MODE_CMD == bloodLeakEmbModeRqstedCmd ) { - // 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++; - } - } - } + memset( bloodLeakEmbModeRespBuffer, 0x0, BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN ); + length = 1; + bloodLeakEmbModeRespBuffer[ 0 ] = BLOOD_LEAK_EMB_MODE_PASS_ASCII; } - } - else if ( ( NU_EMB_MODE_CMD == expChar1 ) && ( NU_EMB_MODE_CMD == expChar2 ) ) - { - // This is the case that there are no expected characters and the received value are numbers - if ( bloodLeakEmbModeRespIndex < length ) + else if ( 1 == 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; - bloodLeakEmbModeRespIndex++; - } + U08 passChar = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].expChar1; + U08 data = bloodLeakEmbModeRespBuffer[ 0 ]; + bloodLeakEmbModeRespBuffer[ 0 ] = ( passChar == data ? BLOOD_LEAK_EMB_MODE_PASS_ASCII : BLOOD_LEAK_EMB_MODE_FAIL_ASCII ); } + + // Done with receiving the data + bloodLeakEmbModeRqstedCmd = NU_EMB_MODE_CMD; + state = BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE; + handleSendBloodLeakEmbeddedModeCommandResponse( length, bloodLeakEmbModeRespBuffer ); } + else if ( getFPGABloodLeakRxFIFOCount() > 0 ) + { + // First clear the buffer from the older data. Set to 2 times the length because the array is 2D + memset( bloodLeakEmbModeCmdSquence, 0x0, 2 * BLOOD_LEAK_EMB_MODE_CMD_SEQ_LENGTH ); - // Send another request to the FPGA to read the next data in the buffer - setFPGABloodLeakUARTControl( BLOOD_LEAK_EMB_MODE_COMM_READ_REQST ); - areTempDone = FALSE; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_REQUEST_RX_INDEX ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_READ_REQST; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_REQUEST_RX_INDEX ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_REQUEST_RX_INDEX + 1 ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW; + bloodLeakEmbModeCmdSquence[ BLOOD_LEAK_EMB_MODE_REQUEST_RX_INDEX + 1 ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + + // Set the variables for the next state + bloodLeakUARTCmdIndex = 0; + bloodLeakEmbModeCmdSeqLength = BLOOD_LEAK_EMB_MODE_RQST_RX_LENGTH; + state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; + } } - else if ( FALSE == areTempDone ) + + if ( TRUE == didTimeout( bloodLeakEmbModeOpsStartTime, commandTimeoutMS ) ) { - setFPGABloodLeakUARTControl( BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW ); - areTempDone = TRUE; + memset( bloodLeakEmbModeRespBuffer, 0x0, BLOOD_LEAK_EMB_MODE_RESP_BUFFER_LEN ); + length = 1; + bloodLeakEmbModeRespBuffer[ 0 ] = BLOOD_LEAK_EMB_MODE_FAIL_ASCII; + bloodLeakEmbModeRqstedCmd = NU_EMB_MODE_CMD; + state = BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE; + handleSendBloodLeakEmbeddedModeCommandResponse( length, bloodLeakEmbModeRespBuffer ); } + return state; +} - // 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 ) ) +/*********************************************************************//** + * @brief + * The processReceivedEmbModeChar function processes the character that + * has been received. + * @details Inputs: bloodLeakEmbModeCmd, bloodLeakEmbModeRespIndex + * @details Outputs: bloodLeakEmbModeRespBuffer, bloodLeakEmbModeRespIndex + * @param data which is the data that has been received from the BLD + * @return none + *************************************************************************/ +static void processReceivedEmbModeChar( U08 data ) +{ + /* + * 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) + */ + U08 length = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].length; + U08 expChar1 = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].expChar1; + U08 expChar2 = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].expChar2; + U08 command = bloodLeakEmbModeCmd[ bloodLeakEmbModeRqstedCmd ].commandASCII; + + if ( ( expChar1 != NU_EMB_MODE_CMD ) && ( NU_EMB_MODE_CMD == expChar2 ) ) { - // 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_EMB_MODE_CMD == bloodLeakEmbModeRespBuffer[ 0 ] ) && ( ++bloodLeakEmbModeNumOfCmdTries < BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) ) + // 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 ) { - state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; + // 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 but it is not the echo of the command + // For instance, V has been inserted and XXXX is inserted that is followed by V. So V123 and not VVV12. + else if ( ( bloodLeakEmbModeRespIndex > 0 ) && ( data != expChar1 ) ) + { + bloodLeakEmbModeRespBuffer[ bloodLeakEmbModeRespIndex ] = data; + bloodLeakEmbModeRespIndex++; + } } - else*/ + } + else if ( ( expChar1 != NU_EMB_MODE_CMD ) && ( expChar2 != NU_EMB_MODE_CMD ) ) + { + // This is the case that both expected chars are not null. Either of the chars are accepted like P or F + if ( bloodLeakEmbModeRespIndex < length ) { - U08 i; - BOOL isNull = FALSE; - - for ( i = 0; i < length; i++ ) + // Check if either of the expected chars are received and if they are insert it into the response buffer + if ( ( expChar1 == data ) || ( expChar2 == data ) ) { - // Loop through the elements of the buffer and make sure none of the elements are not NULL. - // The elements are checked until the specified length that is expected for a command - isNull |= ( bloodLeakEmbModeRespBuffer[ i ] != NU_EMB_MODE_CMD ? FALSE : TRUE ); + bloodLeakEmbModeRespBuffer[ bloodLeakEmbModeRespIndex ] = data; + bloodLeakEmbModeRespIndex++; } + } - // 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_EMB_MODE_CMD == bloodLeakEmbModeRqstedCmd ) && ( NU_EMB_MODE_CMD == bloodLeakEmbModeRespBuffer[ 0 ] ) ? FALSE : TRUE ); - - /* TODO the retries has been disabled for the systems team for their testing. - if ( ( TRUE == isNull ) && ( ++bloodLeakEmbModeNumOfCmdTries < BLOOD_LEAK_EMB_MODE_MAX_NUM_CMD_TRIES ) ) + 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 ) { - state = BLOOD_LEAK_CAL_SEND_COMMAND_STATE; + 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 */ + } + } + else if ( ( NU_EMB_MODE_CMD == expChar1 ) && ( NU_EMB_MODE_CMD == 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 ) ) { - bloodLeakEmbModeRqstedCmd = NU_EMB_MODE_CMD; - state = BLOOD_LEAK_CAL_WAIT_FOR_COMAND_STATE; - handleSendBloodLeakEmbeddedModeCommandResponse( length, bloodLeakEmbModeRespBuffer ); + bloodLeakEmbModeRespBuffer[ bloodLeakEmbModeRespIndex ] = data; + bloodLeakEmbModeRespIndex++; } } } - - return state; } /*********************************************************************//** @@ -1164,7 +1206,7 @@ U08 i; U32 digitCount; char tempCharBuffer[ BLOOD_LEAK_SET_POINT_MAX_CHAR_LENGTH ]; - + U08 command; U32 bufferIndex = BLOOD_LEAK_SET_POINT_START_CHAR_INDEX; memset( tempCharBuffer, 0x0, BLOOD_LEAK_SET_POINT_MAX_CHAR_LENGTH ); @@ -1175,39 +1217,54 @@ // Calculate the length of the character buffer. strlen does not count the null character. digitCount = strlen( tempCharBuffer ); + command = ( TRUE == bloodLeakSignalEmbModeReq ? BLOOD_LEAK_EMB_MODE_COMM_RESET : BLOOD_LEAK_RESET_TX_FIFO ); + bloodLeakSetPointSequence[ bufferIndex ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = command; + bloodLeakSetPointSequence[ bufferIndex ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + bufferIndex++; + + command = ( TRUE == bloodLeakSignalEmbModeReq ? BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW : BLOOD_LEAK_UART_COMM_ACTIVE_LOW ); + bloodLeakSetPointSequence[ bufferIndex ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = command; + bloodLeakSetPointSequence[ bufferIndex ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; + bufferIndex++; + // Set the first item to the ASCII character of S. The format to set the set point is // SXXXCR10. It starts with S followed by the characters up to 3 digits, carriage return and a 1 and a 0 to write to the buffer. - bloodLeakSetPointSequence[ bufferIndex ] = BLOOD_LEAK_SET_POINT_START_CHAR_ASCII; - - // Increment the buffer index + bloodLeakSetPointSequence[ bufferIndex ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_SET_POINT_START_CHAR_ASCII; + bloodLeakSetPointSequence[ bufferIndex ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = FALSE; bufferIndex++; // Loop through the number of digits and get each ASCII value for ( i = 0; i < digitCount; i++ ) { // Write the characters - bloodLeakSetPointSequence[ bufferIndex ] = tempCharBuffer[ i ]; + bloodLeakSetPointSequence[ bufferIndex ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = tempCharBuffer[ i ]; + bloodLeakSetPointSequence[ bufferIndex ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = FALSE; bufferIndex++; } // After the characters, insert the carriage return into the buffer - bloodLeakSetPointSequence[ bufferIndex ] = BLOOD_LEAK_CARRIAGE_RETURN_ASCII; + bloodLeakSetPointSequence[ bufferIndex ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_CARRIAGE_RETURN_ASCII; + bloodLeakSetPointSequence[ bufferIndex ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = FALSE; bufferIndex++; // After the characters, insert the stop write to FIFO character which is number 0 - bloodLeakSetPointSequence[ bufferIndex ] = BLOOD_LEAK_STOP_WRITE_FIFO_COMMAND; + bloodLeakSetPointSequence[ bufferIndex ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = BLOOD_LEAK_STOP_WRITE_FIFO_COMMAND; + bloodLeakSetPointSequence[ bufferIndex ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = FALSE; bufferIndex++; - // Set active high and active low into the buffer - bloodLeakSetPointSequence[ bufferIndex ] = ( TRUE == bloodLeakSignalEmbModeReq ? BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_HIGH : BLOOD_LEAK_UART_COMM_ACTIVE_HIGH ); + // Set active high into the buffer. + // If the mode is embedded mode, the active high (and active low) values are different than in the Ctrl U mode since the bit values are different + command = ( TRUE == bloodLeakSignalEmbModeReq ? BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_HIGH : BLOOD_LEAK_UART_COMM_ACTIVE_HIGH ); + bloodLeakSetPointSequence[ bufferIndex ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = command; + bloodLeakSetPointSequence[ bufferIndex ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; bufferIndex++; - bloodLeakSetPointSequence[ bufferIndex ] = ( TRUE == bloodLeakSignalEmbModeReq ? BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW : BLOOD_LEAK_UART_COMM_ACTIVE_LOW ); + command = ( TRUE == bloodLeakSignalEmbModeReq ? BLOOD_LEAK_EMB_MODE_COMM_ACTIVE_LOW : BLOOD_LEAK_UART_COMM_ACTIVE_LOW ); + bloodLeakSetPointSequence[ bufferIndex ][ BLOOD_LEAK_EMB_MODE_CMD_COL_INDEX ] = command; + bloodLeakSetPointSequence[ bufferIndex ][ BLOOD_LEAK_EMB_MODE_IS_UART_COL_INDEX ] = TRUE; // Update the sequence length for writing to the sensor bloodLeakSetPointSeqLength = bufferIndex + 1; - - // Get ready for the next write to the sensor bloodLeakUARTCmdIndex = 0; } @@ -1256,66 +1313,78 @@ bloodLeakEmbModeCmd[ NU_EMB_MODE_CMD ].expChar1 = NU_EMB_MODE_CMD; bloodLeakEmbModeCmd[ NU_EMB_MODE_CMD ].expChar2 = NU_EMB_MODE_CMD; bloodLeakEmbModeCmd[ NU_EMB_MODE_CMD ].length = 0; + bloodLeakEmbModeCmd[ NU_EMB_MODE_CMD ].timeoutMS = 0; // Control S command bloodLeakEmbModeCmd[ CS_EMB_MODE_CMD ].commandASCII = 19; // ASCII for Control S bloodLeakEmbModeCmd[ CS_EMB_MODE_CMD ].expChar1 = 69; // ASCII for E (Embedded ...) bloodLeakEmbModeCmd[ CS_EMB_MODE_CMD ].expChar2 = NU_EMB_MODE_CMD; bloodLeakEmbModeCmd[ CS_EMB_MODE_CMD ].length = 5; + bloodLeakEmbModeCmd[ CS_EMB_MODE_CMD ].timeoutMS = 5 * MS_PER_SECOND; // Set point command bloodLeakEmbModeCmd[ SP_EMB_MODE_CMD ].commandASCII = 83; // ASCII for S bloodLeakEmbModeCmd[ SP_EMB_MODE_CMD ].expChar1 = 88; // ASCII for X (Timeout) bloodLeakEmbModeCmd[ SP_EMB_MODE_CMD ].expChar2 = 70; // ASCII for F (Fail) bloodLeakEmbModeCmd[ SP_EMB_MODE_CMD ].length = 1; + bloodLeakEmbModeCmd[ SP_EMB_MODE_CMD ].timeoutMS = 10 * MS_PER_SECOND; + // Self test command bloodLeakEmbModeCmd[ T_EMB_MODE_CMD ].commandASCII = 84; // ASCII for T bloodLeakEmbModeCmd[ T_EMB_MODE_CMD ].expChar1 = 80; // ASCII for P bloodLeakEmbModeCmd[ T_EMB_MODE_CMD ].expChar2 = 70; // ASCII for F bloodLeakEmbModeCmd[ T_EMB_MODE_CMD ].length = 1; + bloodLeakEmbModeCmd[ T_EMB_MODE_CMD ].timeoutMS = 5 * MS_PER_SECOND; // Get self test command bloodLeakEmbModeCmd[ G_EMB_MODE_CMD ].commandASCII = 71; // ASCII for G bloodLeakEmbModeCmd[ G_EMB_MODE_CMD ].expChar1 = 71; bloodLeakEmbModeCmd[ G_EMB_MODE_CMD ].expChar2 = NU_EMB_MODE_CMD; bloodLeakEmbModeCmd[ G_EMB_MODE_CMD ].length = 5; + bloodLeakEmbModeCmd[ G_EMB_MODE_CMD ].timeoutMS = 10 * MS_PER_SECOND; // Intensity command bloodLeakEmbModeCmd[ I_EMB_MODE_CMD ].commandASCII = 73; // ASCII for I bloodLeakEmbModeCmd[ I_EMB_MODE_CMD ].expChar1 = 73; bloodLeakEmbModeCmd[ I_EMB_MODE_CMD ].expChar2 = NU_EMB_MODE_CMD; bloodLeakEmbModeCmd[ I_EMB_MODE_CMD ].length = 5; + bloodLeakEmbModeCmd[ I_EMB_MODE_CMD ].timeoutMS = 5 * MS_PER_SECOND; // Blood detection command bloodLeakEmbModeCmd[ V_EMB_MODE_CMD ].commandASCII = 86; // ASCII for V bloodLeakEmbModeCmd[ V_EMB_MODE_CMD ].expChar1 = 86; bloodLeakEmbModeCmd[ V_EMB_MODE_CMD ].expChar2 = NU_EMB_MODE_CMD; bloodLeakEmbModeCmd[ V_EMB_MODE_CMD ].length = 5; + bloodLeakEmbModeCmd[ V_EMB_MODE_CMD ].timeoutMS = 5 * MS_PER_SECOND; // Zero sensor command bloodLeakEmbModeCmd[ Z_EMB_MODE_CMD ].commandASCII = 90; // ASCII for Z bloodLeakEmbModeCmd[ Z_EMB_MODE_CMD ].expChar1 = 89; // ASCII for Y bloodLeakEmbModeCmd[ Z_EMB_MODE_CMD ].expChar2 = NU_EMB_MODE_CMD; bloodLeakEmbModeCmd[ Z_EMB_MODE_CMD ].length = 1; + bloodLeakEmbModeCmd[ Z_EMB_MODE_CMD ].timeoutMS = 10 * MS_PER_SECOND; // Zero confirm command bloodLeakEmbModeCmd[ Q_EMB_MODE_CMD ].commandASCII = 81; // ASCII for Q bloodLeakEmbModeCmd[ Q_EMB_MODE_CMD ].expChar1 = 80; // ASCII for P bloodLeakEmbModeCmd[ Q_EMB_MODE_CMD ].expChar2 = 70; // ASCII for F bloodLeakEmbModeCmd[ Q_EMB_MODE_CMD ].length = 1; + bloodLeakEmbModeCmd[ Q_EMB_MODE_CMD ].timeoutMS = 5 * MS_PER_SECOND; // Display blood detection command bloodLeakEmbModeCmd[ D_EMB_MODE_CMD ].commandASCII = 68; bloodLeakEmbModeCmd[ D_EMB_MODE_CMD ].expChar1 = 68; // ASCII for D bloodLeakEmbModeCmd[ D_EMB_MODE_CMD ].expChar2 = NU_EMB_MODE_CMD; bloodLeakEmbModeCmd[ D_EMB_MODE_CMD ].length = 5; + bloodLeakEmbModeCmd[ D_EMB_MODE_CMD ].timeoutMS = 5 * MS_PER_SECOND; // Calibrate command bloodLeakEmbModeCmd[ C_EMB_MODE_CMD ].commandASCII = 67; bloodLeakEmbModeCmd[ C_EMB_MODE_CMD ].expChar1 = 67; // ASCII for C bloodLeakEmbModeCmd[ C_EMB_MODE_CMD ].expChar2 = NU_EMB_MODE_CMD; bloodLeakEmbModeCmd[ C_EMB_MODE_CMD ].length = 4; + bloodLeakEmbModeCmd[ C_EMB_MODE_CMD ].timeoutMS = 5 * MS_PER_SECOND; }