Index: firmware/App/Drivers/BloodLeakDriver.c =================================================================== diff -u -rcf465d563d6f19d8eee4d4283b968694eb59ef94 -r86ea3cba20edaebf20fe2f9b82c7c73048c36f6c --- firmware/App/Drivers/BloodLeakDriver.c (.../BloodLeakDriver.c) (revision cf465d563d6f19d8eee4d4283b968694eb59ef94) +++ firmware/App/Drivers/BloodLeakDriver.c (.../BloodLeakDriver.c) (revision 86ea3cba20edaebf20fe2f9b82c7c73048c36f6c) @@ -127,15 +127,17 @@ static void initEmbModeSpecs( void ); static U16 getBloodLeakRxBytesAvailable( void ); static BOOL sendBloodLeakEmbeddedModeCommandResponse( U08 cmd, U32 responseLen, U08 *responseBuffer ); +static void processReceivedEmbModeChar( U08 data ); + /*********************************************************************//** * @brief * The initBloodLeakDriver function initializes the Blood Leak module. * @details \b Inputs: none * @details \b Outputs: bloodLeakState, bloodLeakStatus, bloodLeakSelfTestStatus, * bloodLeakUARTCmdIndex, bloodLeakSetPointSequence - * bloodLeakDataPublicationTimerCounter, bloodLeakEmbModeHasZeroBeenRqustd - * bloodLeakEmbModeSubstate, bloodLeakEmbModeCmdEnqueueCount + * bloodLeakDataPublicationTimerCounter, + * bloodLeakEmbModeSubstate, * bloodLeakPersistenceCtr, bloodLeakSignalEmbModeReq, * bloodLeakEmbModeRqstedCmd, bloodLeakEmbModeOpsStartTime, * bloodLeakEmbModeRespBuffer, bloodLeakEmbModeRespIndex, @@ -234,72 +236,14 @@ /*********************************************************************//** * @brief - * The processReceivedEmbModeChar function processes the character that - * has been received. - * @details \b Inputs: bloodLeakEmbModeCmd, bloodLeakEmbModeRespIndex - * @details \b Outputs: bloodLeakEmbModeRespBuffer, bloodLeakEmbModeRespIndex - * @param data which is the data that has been received from the BLD - * @return none + * The getBloodLeakEmbModeState returns the blood leak embedded mode state. + * @details \b Inputs: bloodLeakEmbModeSubstate + * @details \b Outputs: none + * @return Blood leak embedded mode state *************************************************************************/ -void processReceivedEmbModeChar( U08 data ) +BLOOD_LEAK_EMB_MODE_STATE_T getBloodLeakEmbModeState( void ) { - /* - * 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; - - if ( expChar1 != NU_EMB_MODE_CMD ) - { - // 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 ) - { - if ( NU_EMB_MODE_CMD == expChar2 ) - { - // 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 cd ve> 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 - { - // 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++; - } - } - } - } - else - { - // 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; - bloodLeakEmbModeRespIndex++; - } - } - } + return bloodLeakEmbModeSubstate; } /*********************************************************************//** @@ -405,7 +349,7 @@ * bloodLeakEmbModeInfoCmdCounter * @return none *************************************************************************/ -void enqueueInfoEmbModeCmds( BLOOD_LEAK_STATE_T currentState ) +void enqueueInfoEmbModeCmds( BLOOD_LEAK_STATE_T currentState ) { if ( TRUE == didTimeout( bloodLeakEmbModeInfoCmdEnqLastTimeStamp, BLOOD_LEAK_EMB_MODE_INFO_CMD_TIMEOUT_MS ) ) { @@ -1072,6 +1016,77 @@ return result; } +/*********************************************************************//** + * @brief + * The processReceivedEmbModeChar function processes the character that + * has been received. + * @details \b Inputs: bloodLeakEmbModeCmd, bloodLeakEmbModeRespIndex + * @details \b 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; + + if ( expChar1 != NU_EMB_MODE_CMD ) + { + // 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 ) + { + if ( NU_EMB_MODE_CMD == expChar2 ) + { + // 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 cd ve> 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 + { + // 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++; + } + } + } + } + else + { + // 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; + bloodLeakEmbModeRespIndex++; + } + } + } +} + + /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/