Index: firmware/App/Controllers/BloodLeak.c =================================================================== diff -u -r2c9bbece8057254f8389c26a818081002fb69a77 -r1e323172095bb1ca6969f65976049c9fbe19c489 --- firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 2c9bbece8057254f8389c26a818081002fb69a77) +++ firmware/App/Controllers/BloodLeak.c (.../BloodLeak.c) (revision 1e323172095bb1ca6969f65976049c9fbe19c489) @@ -19,6 +19,7 @@ #include "AlarmMgmt.h" #include "BloodLeak.h" #include "FPGA.h" +#include "NVDataMgmtHDRecords.h" #include "OperationModes.h" #include "SystemCommMessages.h" #include "TaskPriority.h" @@ -81,19 +82,16 @@ static U32 bloodLeakSetPointSeqLength = 0; ///< 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 bloodLeakWait2ReadSetPointCounter = 0; ///< Blood leak wait to read delay counter. -static U32 bloodLeakCurrentSetPointWriteTry = 0; +static U32 bloodLeakCurrentSetPointWriteTry = 0; ///< Blood leak current set point write try number. +static HD_BLOOD_LEAK_SENSOR_CAL_RECORD_T bloodLeakCalRecord; ///< Blood leak calibration record structure. - /// Blood leak start up sequence array. static const U08 BLOOD_LEAK_START_UP_SEQUENCE[ BLOOD_LEAK_STARTUP_SEQ_LENGTH ] = { BLOOD_LEAK_RESET_TX_FIFO, BLOOD_LEAK_UART_COMM_ACTIVE_LOW, BLOOD_LEAK_START_COMM_CTRL_U_ASCII, BLOOD_LEAK_UART_COMM_ACTIVE_HIGH, BLOOD_LEAK_UART_COMM_ACTIVE_LOW }; -static const U32 REMOVE_LATER_SET_POINT = 38; // TODO remove this later -static U32 test = 38; - // ********** private function prototypes ********** static BLOOD_LEAK_STATES_T handleBloodLeakStartupState( void ); @@ -148,6 +146,22 @@ *************************************************************************/ void execBloodLeak( void ) { + // Check if there is a new calibration data available + if ( TRUE == isNewCalibrationRecordAvailable() ) + { + // TODO figure out a way to process this data + // TODO for testing only remove + bloodLeakCalRecord.setPoint = 123; + // TODO for testing only remove the top + + U32 length = sizeof( HD_BLOOD_LEAK_SENSOR_CAL_RECORD_T ); + getCalibrationRecord2Driver( CAL_GET_BLOOD_LEAK_SENSOR, (U08*)&bloodLeakCalRecord, length, ALARM_ID_HD_BLOOD_LEAK_INVALID_CAL_RECORD ); + + // Force the state machine to go back to set the set point that has been received from + // the calibration data + bloodLeakState = BLOOD_LEAK_SET_SET_POINT_STATE; + } + if ( getCurrentOperationMode() != MODE_INIT ) { // Execute blood leak state machine @@ -207,6 +221,33 @@ /*********************************************************************//** * @brief + * The execBloodLeakSelfTest function executes the blood leak self-test. + * @details Inputs: none + * @details Outputs: none + * @return blood leak self test results (SELF_TEST_STATUS_T) + *************************************************************************/ +SELF_TEST_STATUS_T execBloodLeakSelfTest( void ) +{ + SELF_TEST_STATUS_T result = SELF_TEST_STATUS_IN_PROGRESS; + + U32 length = sizeof( HD_BLOOD_LEAK_SENSOR_CAL_RECORD_T ); + ALARM_ID_T alarm = ALARM_ID_HD_BLOOD_LEAK_INVALID_CAL_RECORD; + BOOL calStatus = getCalibrationRecord2Driver( CAL_GET_BLOOD_LEAK_SENSOR, (U08*)&bloodLeakCalRecord, length, alarm ); + + if ( TRUE == calStatus ) + { + result = SELF_TEST_STATUS_PASSED; + } + else + { + result = SELF_TEST_STATUS_FAILED; + } + + return result; +} + +/*********************************************************************//** + * @brief * The handleBloodLeakStartupState function handles the startup state of the * of blood leak state machine. * @details Inputs: bloodLeakUARTCmdIndex @@ -255,13 +296,12 @@ U32 bloodLeakSetPoint = (U32)getFPGABloodLeakDetectSetPoint(); - if ( bloodLeakSetPoint != REMOVE_LATER_SET_POINT ) + if ( bloodLeakSetPoint != bloodLeakCalRecord.crc ) { if ( bloodLeakCurrentSetPointWriteTry < BLOOD_LEAK_MAX_SET_POINT_WRITE_TRIALS ) { prepareSetPointSeq(); - bloodLeakUARTCmdIndex = 0; state = BLOOD_LEAK_SET_SET_POINT_STATE; } else @@ -529,7 +569,7 @@ // The set point can be maximum 3 digits and when it is converted to string, the null character // is the extra character at the end of the buffer so it maximum length is 4 bytes. U32 digitCount = 0; - U32 setPoint = test; // TODO make the origin of the number right + U32 setPoint = bloodLeakCalRecord.setPoint; U32 bufferIndex = BLOOD_LEAK_SET_POINT_START_CHAR_INDEX; char tempCharBuffer[ BLOOD_LEAK_SET_POINT_MAX_CHAR_LENGTH ]; memset( tempCharBuffer, 0x0, BLOOD_LEAK_SET_POINT_MAX_CHAR_LENGTH ); @@ -543,8 +583,9 @@ digitCount++; } - // - setPoint = test; + // Set point was divided up for find out the number of digits + // so it is reinstated again for the rest of the calculations + setPoint = bloodLeakCalRecord.crc; // Convert the set point number to the equivalent ASCII number with the unsigned integer data type sprintf( tempCharBuffer, "%u", setPoint ); @@ -571,8 +612,12 @@ bufferIndex++; bloodLeakSetPointSequence[ bufferIndex ] = BLOOD_LEAK_UART_COMM_ACTIVE_LOW; + // Update the sequence length for writing to the sensor bloodLeakSetPointSeqLength = bufferIndex + 1; + + // Get ready for the next write to the sensor + bloodLeakUARTCmdIndex = 0; } /*********************************************************************//**