Index: firmware/App/Controllers/BalancingChamber.c =================================================================== diff -u -ra414ca5b1458b0800e32672eeb7545a9dd575002 -r5126b79e4970ffe2ed9db4cccea18a1216c78570 --- firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision a414ca5b1458b0800e32672eeb7545a9dd575002) +++ firmware/App/Controllers/BalancingChamber.c (.../BalancingChamber.c) (revision 5126b79e4970ffe2ed9db4cccea18a1216c78570) @@ -39,8 +39,6 @@ #define BAL_CHAMBER_FILL_VOLUME_ML 30.0F ///< Balancing chamber fill/drain volume per batch operation. #define BAL_CHAMBER_DATA_PUBLISH_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the balancing chamber data published. -#define TEST_ACID_VOLUME_ML 0.67F ///< Acid concentrate volume in ml. -#define TEST_BICARB_VOLUME_ML 1.15F ///< Bicarb concentrate volume in ml. /// Payload record structure for balancing chamber switch only request typedef struct @@ -58,10 +56,13 @@ static U32 currentBalChamberSwitchingCounter; ///< Counter (in task interval) to monitor the timing spent during balancing chamber fill/drain operation. static BOOL isBalChamberFillInProgress; ///< Flag indicating balancing chamber fill/drain is in progress. static BOOL isPressureStalbilizedDuringFill; ///< Flag indicating that the pressure is stablized due to fill complete. +static BOOL isPressureDroppedDuringFill; ///< Flag indicating that the pressure is dropped due to BC fill (state 1 or state 2) in progress condition. static BAL_CHAMBER_SW_STATE_T balChamberSWState; ///< Current balancing chamber switching state ( state 1 or state 2). static U32 balChamberDataPublicationTimerCounter; ///< Used to schedule balancing chamber data publication to CAN bus. static OVERRIDE_U32_T balChamberDataPublishInterval; ///< Balancing chamber data publish interval. static BOOL balanceChamberSwitchingOnly; ///< Balancing chamber switching without any pressure check and dosing delivery. +static OVERRIDE_F32_T acidDoseVolume; ///< Acid concentrate volume in ml ( overrideable). +static OVERRIDE_F32_T bicarbDoseVolume; ///< Bicarb concentrate volume in ml ( overrideable). // ********** private function prototypes ********** @@ -92,6 +93,14 @@ balChamberDataPublishInterval.ovData = BAL_CHAMBER_DATA_PUBLISH_INTERVAL; balChamberDataPublishInterval.ovInitData = 0; balChamberDataPublishInterval.override = OVERRIDE_RESET; + acidDoseVolume.data = DEFAULT_ACID_VOLUME_ML; + acidDoseVolume.ovData = DEFAULT_ACID_VOLUME_ML; + acidDoseVolume.ovInitData = 0.0F; + acidDoseVolume.override = OVERRIDE_RESET; + bicarbDoseVolume.data = DEFAULT_BICARB_VOLUME_ML; + bicarbDoseVolume.ovData = DEFAULT_BICARB_VOLUME_ML; + bicarbDoseVolume.ovInitData = 0.0F; + bicarbDoseVolume.override = OVERRIDE_RESET; balanceChamberSwitchingOnly = FALSE; balChamberSwitchingPeriod = 0; balChamberValveClosePeriod = 0; @@ -351,6 +360,8 @@ * state 1 fill and time to fill chamber counter being updated. * @details \b Inputs: Pressure * @details \b Outputs: valve states + * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_START_PRESSURE_OUT_OF_RANGE + * when pressure is not in range during balacing chamber fill start. * @return next balancing chamber state. *************************************************************************/ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillStart( void ) @@ -359,11 +370,13 @@ currentBalChamberSwitchingCounter = 0; isBalChamberFillInProgress = FALSE; isPressureStalbilizedDuringFill = FALSE; + isPressureDroppedDuringFill = FALSE; balChamberSWState = BAL_CHAMBER_SW_STATE1; F32 freshDialPressure = getFilteredPressure( D18_PRES ); F32 spentDialPressure = getFilteredPressure( D51_PRES ); - + F32 acidVolume = getF32OverrideValue( &acidDoseVolume ); + F32 bicarbVolume = getF32OverrideValue( &bicarbDoseVolume ); // Check fresh and spent dialysate pressure in range or BC switch only flag set //TODO : comment the pressure check if ( 1 ) @@ -378,11 +391,11 @@ isBalChamberFillInProgress = TRUE; // Deliver dosing during generate dialysate mode - if ( FALSE == getBalChamberSwitchingOnlyStatus() ) + if ( TRUE != getBalChamberSwitchingOnlyStatus() ) { // start acid and bicarb pump with the expected quantity - setConcentratePumpTargetSpeed( D11_PUMP, CONCENTRATE_PUMP_MAX_SPEED, TEST_ACID_VOLUME_ML ); - setConcentratePumpTargetSpeed( D10_PUMP, CONCENTRATE_PUMP_MAX_SPEED, TEST_BICARB_VOLUME_ML ); + setConcentratePumpTargetSpeed( D11_PUMP, CONCENTRATE_PUMP_MAX_SPEED, acidVolume ); + setConcentratePumpTargetSpeed( D10_PUMP, CONCENTRATE_PUMP_MAX_SPEED, bicarbVolume ); requestConcentratePumpOn( D11_PUMP ); requestConcentratePumpOn( D10_PUMP ); } @@ -403,15 +416,26 @@ * The handleBalChamberConcentrateControl function handles the Acid and Bicarb * concentrate doisng and checks the conductivity of the dialysate for the treatment. * @details \b Inputs: balChamberSWState , Concentrate volume - * @details \b Outputs: state + * @details \b Outputs: isPressureDroppedDuringFill, state * @return next balancing chamber state. *************************************************************************/ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberConcentrateControl( void ) { BAL_CHAMBER_EXEC_STATE_T state; + F32 freshDialPressure = getFilteredPressure( D18_PRES ); + F32 spentDialPressure = getFilteredPressure( D51_PRES ); + + // Pressure drop check during fill process helps to find if there is any issue with valves opening + if ( ( freshDialPressure <= BC_FILL_PRESSURE_MIN_PSIG ) && ( spentDialPressure <= BC_FILL_PRESSURE_MIN_PSIG ) ) + { + isPressureDroppedDuringFill = TRUE; + } + // On dosing completion, transition to next state based on the current switching state - if ( TRUE == IsConcentratePumpDosingCompleted() ) + if ( ( ( TRUE == isConcentratePumpDosingCompleted( D11_PUMP ) ) && + ( TRUE == isConcentratePumpDosingCompleted( D10_PUMP ) ) ) || + ( TRUE == getBalChamberSwitchingOnlyStatus() ) ) { if ( BAL_CHAMBER_SW_STATE1 == balChamberSWState ) { @@ -432,6 +456,10 @@ * fill complete and close the currently opened valves. * @details \b Inputs: balChamberSWState, spent and fresh dialysate pressure * @details \b Outputs: isPressureStalbilizedDuringFill,isBalChamberFillInProgress + * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_PRESSURE_DROP_OUT_OF_RANGE + * when pressure drop is not in range during balacing chamber fill in progress. + * @details \b Alarm: ALARM_ID_DD_BC_STATE1_FILL_END_PRESSURE_OUT_OF_RANGE + * when pressure is not in range during balacing chamber fill complete. * @return next balancing chamber state. *************************************************************************/ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState1FillEnd( void ) @@ -450,6 +478,7 @@ { // stabilized pressure indicating fill is complete isPressureStalbilizedDuringFill = TRUE; + isBalChamberFillInProgress = FALSE; // isPressureStalbilizedDuringFill = FALSE; } @@ -464,19 +493,29 @@ // On completion of cycle time, transition to next state if ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) { - if ( ( TRUE != isPressureStalbilizedDuringFill ) && - ( FALSE == getBalChamberSwitchingOnlyStatus() ) ) + if ( TRUE != getBalChamberSwitchingOnlyStatus() ) { - // Alarm when switching time expired, but still pressure not in range, - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_END_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + if ( TRUE != isPressureDroppedDuringFill ) + { + // When fill initiated, pressure is not dropped to the expected range, possible valve failures. + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_PRESSURE_DROP_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + } + else if ( TRUE != isPressureStalbilizedDuringFill ) + { + // Alarm when switching time expired, but still pressure not in range to indicate fill is complete. + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE1_FILL_END_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + } + else + { + // Move to next state when pressure is in range. + state = BAL_CHAMBER_STATE2_FILL_START; + } //TODO : Temporarily allow to proceed next state even though pressure is not stabilized. - isBalChamberFillInProgress = FALSE; state = BAL_CHAMBER_STATE2_FILL_START; } else { - isBalChamberFillInProgress = FALSE; state = BAL_CHAMBER_STATE2_FILL_START; } } @@ -490,6 +529,8 @@ * state 2 fill and time to fill chamber counter being updated. * @details \b Inputs: fresh and spent dialysate pressure * @details \b Outputs: valve states + * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_START_PRESSURE_OUT_OF_RANGE + * when pressure is not in range during balacing chamber state 2 fill start. * @return next balancing chamber state. *************************************************************************/ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillStart( void ) @@ -498,10 +539,13 @@ currentBalChamberSwitchingCounter = 0; isBalChamberFillInProgress = FALSE; isPressureStalbilizedDuringFill = FALSE; + isPressureDroppedDuringFill = FALSE; balChamberSWState = BAL_CHAMBER_SW_STATE2; F32 freshDialPressure = getFilteredPressure( D18_PRES ); F32 spentDialPressure = getFilteredPressure( D51_PRES ); + F32 acidVolume = getF32OverrideValue( &acidDoseVolume ); + F32 bicarbVolume = getF32OverrideValue( &bicarbDoseVolume ); // Check fresh and spent dialysate pressure in range //TODO : comment the pressure check @@ -517,11 +561,11 @@ isBalChamberFillInProgress = TRUE; // Deliver dosing during generate dialysate mode - if ( FALSE == getBalChamberSwitchingOnlyStatus() ) + if ( TRUE != getBalChamberSwitchingOnlyStatus() ) { // start acid and bicarb pump with the expected quantity - setConcentratePumpTargetSpeed( D11_PUMP, CONCENTRATE_PUMP_MAX_SPEED, TEST_ACID_VOLUME_ML ); - setConcentratePumpTargetSpeed( D10_PUMP, CONCENTRATE_PUMP_MAX_SPEED, TEST_BICARB_VOLUME_ML ); + setConcentratePumpTargetSpeed( D11_PUMP, CONCENTRATE_PUMP_MAX_SPEED, acidVolume ); + setConcentratePumpTargetSpeed( D10_PUMP, CONCENTRATE_PUMP_MAX_SPEED, bicarbVolume ); requestConcentratePumpOn( D11_PUMP ); requestConcentratePumpOn( D10_PUMP ); } @@ -542,6 +586,10 @@ * fill complete and close the currently opened valves. * @details \b Inputs: balChamberSWState, spent and fresh dialysate pressure * @details \b Outputs: isPressureStalbilizedDuringFill,isBalChamberFillInProgress + * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_PRESSURE_DROP_OUT_OF_RANGE + * when pressure is not in range during balacing chamber state 2 fill in progress. + * @details \b Alarm: ALARM_ID_DD_BC_STATE2_FILL_END_PRESSURE_OUT_OF_RANGE + * when pressure is not in range during balacing chamber state 2 fill complete. * @return next balancing chamber state. *************************************************************************/ static BAL_CHAMBER_EXEC_STATE_T handleBalChamberState2FillEnd( void ) @@ -560,6 +608,7 @@ { // stabilized pressure indicating fill is complete isPressureStalbilizedDuringFill = TRUE; + isBalChamberFillInProgress = FALSE; //isPressureStalbilizedDuringFill = FALSE; } @@ -574,19 +623,30 @@ // On completion of cycle time, transition to next state if ( currentBalChamberSwitchingCounter >= balChamberSwitchingPeriod ) { - if ( ( TRUE != isPressureStalbilizedDuringFill ) && - ( FALSE == getBalChamberSwitchingOnlyStatus() ) ) + // Pressure alarm check + if ( TRUE != getBalChamberSwitchingOnlyStatus() ) { - // Alarm when switching time expired, but still pressure not in range, - SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_END_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + if ( TRUE != isPressureDroppedDuringFill ) + { + // When fill initiated, pressure is not dropped to the expected range, possible valve failures. + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_PRESSURE_DROP_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + } + else if ( TRUE != isPressureStalbilizedDuringFill ) + { + // Alarm when switching time expired, but still pressure not in range to indicate fill is complete. + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DD_BC_STATE2_FILL_END_PRESSURE_OUT_OF_RANGE, freshDialPressure, spentDialPressure ); + } + else + { + // Move to next state when pressure is in range. + state = BAL_CHAMBER_STATE1_FILL_START; + } //TODO : Temporarily allow to proceed next state even though pressure is not stabilized. - isBalChamberFillInProgress = FALSE; state = BAL_CHAMBER_STATE1_FILL_START; } else { - isBalChamberFillInProgress = FALSE; state = BAL_CHAMBER_STATE1_FILL_START; } } @@ -760,6 +820,40 @@ /*********************************************************************//** * @brief + * The testAcidDoseVolumeOverride function sets the override value + * of the acid concentrate dosing volume. + * @details Inputs: acidDoseVolume + * @details Outputs: acidDoseVolume + * @param message Override message from Dialin which includes the override + * value to override the acid concentrate dosing volume. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testAcidDoseVolumeOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &acidDoseVolume ); + + return result; +} + +/*********************************************************************//** + * @brief + * The testBicarbDoseVolumeOverride function sets the override value + * of the bicarb concentrate dosing volume. + * @details Inputs: bicarbDoseVolume + * @details Outputs: bicarbDoseVolume + * @param message Override message from Dialin which includes the override + * value to override the bicarb concentrate dosing volume. + * @return TRUE if override successful, FALSE if not + *************************************************************************/ +BOOL testBicarbDoseVolumeOverride( MESSAGE_T *message ) +{ + BOOL result = f32Override( message, &bicarbDoseVolume ); + + return result; +} + +/*********************************************************************//** + * @brief * The testBCSwitchOnlyStartStopOverride function starts/stops balancing * chamber switching only without dosing delivery and pressure check condition. * @details \b Inputs: tester logged in