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 *************************************************************************/ Index: firmware/App/Drivers/BloodLeakDriver.h =================================================================== diff -u -rcf465d563d6f19d8eee4d4283b968694eb59ef94 -r86ea3cba20edaebf20fe2f9b82c7c73048c36f6c --- firmware/App/Drivers/BloodLeakDriver.h (.../BloodLeakDriver.h) (revision cf465d563d6f19d8eee4d4283b968694eb59ef94) +++ firmware/App/Drivers/BloodLeakDriver.h (.../BloodLeakDriver.h) (revision 86ea3cba20edaebf20fe2f9b82c7c73048c36f6c) @@ -126,6 +126,7 @@ void initBloodLeakDriver( void ); void execBloodLeakEmbModeCommand( void ); +BLOOD_LEAK_EMB_MODE_STATE_T getBloodLeakEmbModeState( void ); // Embedded mode command queue void enqueueEmbModeCmd( U08 cmd ); @@ -139,7 +140,6 @@ void resetEmbModeCmdRespConsumedFlag( U08 cmd ); void getBloodLeakEmbCmdMode( BLOOD_LEAK_EMB_MODE_CMD_T cmd, EMB_MODE_CMD_T* results ); U32 getEmbModeInfoValue( U08 cmd ); -void processReceivedEmbModeChar( U08 data ); BOOL testSetBloodLeak2EmbeddedMode( MESSAGE_T *message ); BOOL testSetBloodLeakEmbeddedModeCommand( MESSAGE_T *message ); Index: firmware/App/Monitors/BloodLeak.c =================================================================== diff -u -rcf465d563d6f19d8eee4d4283b968694eb59ef94 -r86ea3cba20edaebf20fe2f9b82c7c73048c36f6c --- firmware/App/Monitors/BloodLeak.c (.../BloodLeak.c) (revision cf465d563d6f19d8eee4d4283b968694eb59ef94) +++ firmware/App/Monitors/BloodLeak.c (.../BloodLeak.c) (revision 86ea3cba20edaebf20fe2f9b82c7c73048c36f6c) @@ -105,7 +105,6 @@ static BLOOD_LEAK_ZEROING_STATUS_T bloodLeakZeroingStatus; ///< Blood leak zeroing status. // Embedded mode variables -static BLOOD_LEAK_EMB_MODE_STATE_T bloodLeakEmbModeSubstate; ///< Blood leak embedded mode state. ///< Blood leak embedded mode set point command. static BOOL bloodLeakEmbModeHasZeroBeenRqustd; ///< Blood leak embedded mode flag to indicate zero has been requested. static U32 bloodLeakEmbModeCmdEnqueueCount; ///< Blood leak embedded mode command enqueue count @@ -147,19 +146,18 @@ { initBloodLeakDriver(); - bloodLeakDataPublicationCounter = DATA_PUBLISH_COUNTER_START_COUNT; - bloodLeakState = BLOOD_LEAK_WAIT_FOR_POST_STATE; - bloodLeakStatus.data = BLOOD_LEAK_NOT_DETECTED; - bloodLeakStatus.ovInitData = BLOOD_LEAK_NOT_DETECTED; - bloodLeakStatus.ovData = BLOOD_LEAK_NOT_DETECTED; - bloodLeakStatus.override = OVERRIDE_RESET; - bloodLeakSelfTestStatus = SELF_TEST_STATUS_IN_PROGRESS; - bloodLeakPersistenceCtr = 0; - bloodLeakEmbModeSubstate = BLOOD_LEAK_EMB_MODE_WAIT_FOR_COMAND_STATE; - bloodLeakExitNormalRequested = FALSE; - bloodLeakEmbModeHasZeroBeenRqustd = FALSE; - bloodLeakEmbModeCmdEnqueueCount = 0; - bloodLeakRecoveryStartTimeMS = getMSTimerCount(); + bloodLeakDataPublicationCounter = DATA_PUBLISH_COUNTER_START_COUNT; + bloodLeakState = BLOOD_LEAK_WAIT_FOR_POST_STATE; + bloodLeakStatus.data = BLOOD_LEAK_NOT_DETECTED; + bloodLeakStatus.ovInitData = BLOOD_LEAK_NOT_DETECTED; + bloodLeakStatus.ovData = BLOOD_LEAK_NOT_DETECTED; + bloodLeakStatus.override = OVERRIDE_RESET; + bloodLeakSelfTestStatus = SELF_TEST_STATUS_IN_PROGRESS; + bloodLeakPersistenceCtr = 0; + bloodLeakExitNormalRequested = FALSE; + bloodLeakEmbModeHasZeroBeenRqustd = FALSE; + bloodLeakEmbModeCmdEnqueueCount = 0; + bloodLeakRecoveryStartTimeMS = getMSTimerCount(); bloodLeakZeroingStatus.zeroingDriftIntervalTimeMS.data = BLD_ZERO_MIN_INTERVAL_MS; bloodLeakZeroingStatus.zeroingDriftIntervalTimeMS.ovInitData = BLD_ZERO_MIN_INTERVAL_MS; @@ -226,7 +224,7 @@ break; } - enqueueInfoEmbModeCmds( bloodLeakState); + enqueueInfoEmbModeCmds( bloodLeakState ); // Publish blood leak data if due publishBloodLeakData(); @@ -479,7 +477,7 @@ BLOOD_LEAK_STATE_T state = BLOOD_LEAK_CHECK_SET_POINT_STATE; EMB_MODE_CMD_T dCmdSpec; - getBloodLeakEmbCmdMode(D_EMB_MODE_CMD, &dCmdSpec); + getBloodLeakEmbCmdMode( D_EMB_MODE_CMD, &dCmdSpec ); BOOL isCommandRespReady = dCmdSpec.isCmdRespRdy; U08 commandDRqstCount = dCmdSpec.commandRqstCount; @@ -806,7 +804,7 @@ data.bloodLeakStatus = (U32)getBloodLeakStatus(); data.bloodLeakState = (U32)bloodLeakState; data.bloodLeakPersistentCounter = bloodLeakPersistenceCtr; - data.bloodLeakSerialCommState = bloodLeakEmbModeSubstate; + data.bloodLeakSerialCommState = (U32)getBloodLeakEmbModeState(); data.bloodLeakIntensity = getEmbModeInfoValue( I_EMB_MODE_CMD ); data.bloodLeakDetect = getEmbModeInfoValue( V_EMB_MODE_CMD ); data.bloodLeakIntensityMovingAvg = getF32OverrideValue( &bloodLeakZeroingStatus.intensityMovingAverage ); @@ -904,7 +902,7 @@ */ BOOL status = FALSE; BOOL isZeroingNeeded = TRUE; - getBloodLeakEmbCmdMode(D_EMB_MODE_CMD, &cmdSpec); + getBloodLeakEmbCmdMode( D_EMB_MODE_CMD, &cmdSpec ); U32 setPoint = cmdSpec.commandResp; F32 driftMinFromTop = BLD_NOMINAL_INTENSITY - ( setPoint * BLD_MAX_INTENSITY_OUT_OF_RANGE ); F32 driftMaxFromTop = BLD_NOMINAL_INTENSITY - ( setPoint * BLD_MIN_INTENSITY_OUT_OF_RANGE ); @@ -963,33 +961,7 @@ return status; } -/*********************************************************************//** - * @brief - * The sendBloodLeakEmbeddedModeCommandResponse function sends out - * the blood leak embedded mode command response. - * @details \b Inputs: none - * @details \b Outputs: blood leak embedded mode command response msg constructed and queued - * @details \b Message: MSG_ID_DD_SEND_BLOOD_LEAK_EMB_MODE_RESPONSE DD blood leak response command - * @param cmd: the command its response is being sent - * @param responseLen: the length of the buffer - * @param response: pointer to the response buffer - * @return TRUE if msg successfully queued for transmit, FALSE if not - *************************************************************************/ -static BOOL sendBloodLeakEmbeddedModeCommandResponse( U08 cmd, U32 responseLen, U08 *responseBuffer ) -{ - BLOOD_LEAK_EMB_MODE_RESP_T response; - BOOL result = FALSE; - response.command = cmd; - response.responseLen = responseLen; - memcpy( response.responseBuffer, responseBuffer, responseLen ); - - result = sendMessage( MSG_ID_DD_SEND_BLOOD_LEAK_EMB_MODE_RESPONSE, COMM_BUFFER_OUT_DD_CAN_PC, (U08*)&response, sizeof( BLOOD_LEAK_EMB_MODE_RESP_T ) ); - - return result; -} - - /************************************************************************* * TEST SUPPORT FUNCTIONS *************************************************************************/