Index: firmware/App/Modes/ModeFill.c =================================================================== diff -u -rc230be1bd4296324bf5dfc288c212eb7c2ce5d2d -rff676a9640e5dfe162de78d2b24f356f63bad5bb --- firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision c230be1bd4296324bf5dfc288c212eb7c2ce5d2d) +++ firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision ff676a9640e5dfe162de78d2b24f356f63bad5bb) @@ -8,7 +8,7 @@ * @file ModeFill.c * * @author (last) Dara Navaei -* @date (last) 21-Mar-2023 +* @date (last) 28-Mar-2023 * * @author (original) Leonardo Baloa * @date (original) 19-Nov-2019 @@ -107,6 +107,13 @@ BOOL isThisFirstFill; ///< Fill flag to indicate whether it is the first fill or not. } FILL_CONDITION_STATUS_T; +/// Fill acid and bicarb types +typedef struct +{ + DG_ACID_TYPES_T acidType; ///< Acid type. + DG_BICARB_TYPES_T bicarbType; ///< Bicarb type. +} FILL_ACID_BICARB_TYPES_T; + static U32 dataPublishCounter; ///< Used to schedule dialysate fill data publication to CAN bus. static DG_FILL_MODE_STATE_T fillState; ///< Currently active fill state. static U32 dialysateFillStartTime; ///< Current time when starting to fill dialysate. @@ -139,6 +146,11 @@ static U32 pumpSpeedIndex; ///< Index used to access the desired pump speed in roPumpFlushBubblesSpeed table. static BOOL havePauseActuatorsBeenSet; ///< Flag to indicate the actuators have been set to pause for the first time. +static FILL_ACID_BICARB_TYPES_T chemicalsTypes; ///< Chemicals Types (acid and bicarb). + +// NOTE: This variable should be initialized here because the init function is called every time and then this variable is set to FALSE even if the settings from the +// UI wants the RO only mode. +static BOOL hasROOnlyModeBeenEnabled = FALSE; ///< Flag to indicate the RO only mode has been set or not. static OVERRIDE_F32_T usedAcidVolumeML = { 0.0, 0.0, 0.0, 0.0 }; ///< The integrated acid concentration volume has been used in mL. static OVERRIDE_F32_T usedBicarbVolumeML = { 0.0, 0.0, 0.0, 0.0 }; ///< The integrated bicarb concentration volume has been used in mL. static OVERRIDE_U32_T fillModeDataPublishInterval = { FILL_MODE_DATA_PUB_INTERVAL, @@ -157,6 +169,7 @@ static DG_FILL_MODE_STATE_T handlePausedState( void ); static BOOL areInletWaterConditionsAlarmsActive( void ); +static BOOL areConductivityAlarmsActive( void ); static void handleDialysateMixing( F32 measuredROFlowRate_mL_min, F32 acidMixingRatio, F32 bicarbMixingRatio ); static void setFillInfoToRTCRAM( void ); static BOOL isValueWithinPercentRange( F32 testValue, F32 baseValue, F32 percentFactor ); @@ -166,10 +179,7 @@ * @brief * The initFillMode function initializes the fill mode module. * @details Inputs: none - * @details Outputs: fillState, dialysateFillStartTime, reservoirBaseWeight, - * totalROFlowRateMLPM, concentrateTestStartTime, acidConductivityTotal, - * bicarbConductivityTotal, conductivitySampleCount, havePauseActuatorsBeenSet - * concentratePumpPrimeCount + * @details Outputs: fill mode variables initialized. * @return none *************************************************************************/ void initFillMode( void ) @@ -240,7 +250,10 @@ checkDialysateTemperatureSensors(); setHeaterTargetTemperature( DG_PRIMARY_HEATER, getPrimaryHeaterTargetTemperature() ); - fillState = ( TRUE == areInletWaterConditionsAlarmsActive() ? DG_FILL_MODE_STATE_PAUSED : fillState ); + if ( ( TRUE == areInletWaterConditionsAlarmsActive() ) || ( TRUE == areConductivityAlarmsActive() ) ) + { + fillState = DG_FILL_MODE_STATE_PAUSED; + } // Execute current Fill state switch ( fillState ) @@ -439,6 +452,7 @@ * @details Inputs: none * @details Outputs: none * @param flag to TRUE if prime is needed otherwise FALSE + * @return none *************************************************************************/ void setThisFisrtFillFlag( BOOL flag ) { @@ -447,6 +461,49 @@ /*********************************************************************//** * @brief + * The enableROOnlyMode function sets the boolean flag that indicates RO + * only mode has been enabled. + * @details Inputs: none + * @details Outputs: hasROOnlyModeBeenEnabled + * @param enableROOnlyMode TRUE if the RO only mode is requested otherwise, FALSE + * @return none + *************************************************************************/ +void setROMode( BOOL enableROOnlyMode ) +{ + hasROOnlyModeBeenEnabled = enableROOnlyMode; +} + +/*********************************************************************//** + * @brief + * The isROOnlyModeEnabled function returns the status of RO only mode. + * @details Inputs: none + * @details Outputs: none + * @return hasROOnlyModeBeenEnabled, TRUE if the RO only mode has been set + * otherwise, FALSE + *************************************************************************/ +BOOL isROOnlyModeEnabled( void ) +{ + return hasROOnlyModeBeenEnabled; +} + +/*********************************************************************//** + * @brief + * The setAcidAndBicarbType function sets the acid and bicarb types to be + * used in filling. + * @details Inputs: none + * @details Outputs: chemicalsTypes + * @param acid which is the type of acid + * @param bicarb which is the type of bicarb + * @return none + *************************************************************************/ +void setAcidAndBicarbType( U32 acid, U32 bicarb ) +{ + chemicalsTypes.acidType = (DG_ACID_TYPES_T)acid; + chemicalsTypes.bicarbType = (DG_BICARB_TYPES_T)bicarb; +} + +/*********************************************************************//** + * @brief * The handleTestInletWaterState function tests for inlet water quality * and if this is the first fill of a treatment, prime the acid and bicarb * lines before jumping to dialysate production state. @@ -586,10 +643,18 @@ if ( TRUE == didTimeout( concentrateTestStartTime, CONCENTRATE_TEST_TIME_OUT_MS ) ) { + DG_CHEMICALS_FILL_COND_CAL_RECORD_T chemicalsCond; + F32 bicarbCondUSPerCM = 0.0F; BOOL isConductivityInRange = FALSE; + + getFillChemicalCondRecord( &chemicalsCond ); + + // In the bicarb test, the acid value is 0, so it is not queried + bicarbCondUSPerCM = chemicalsCond.fillCondValues[ chemicalsTypes.acidType ][ FILL_COND_BICARB_TEST ].bicarbConduSPerCM; + averageBicarbConductivity = totalBicarbConductivity / bicarbConductivitySampleCount; - if ( TRUE == isValueWithinPercentRange( averageBicarbConductivity, BICARB_TEST_CD2_TCD, FIVE_PERCENT_FACTOR ) ) + if ( TRUE == isValueWithinPercentRange( averageBicarbConductivity, bicarbCondUSPerCM, FIVE_PERCENT_FACTOR ) ) { isConductivityInRange = TRUE; } @@ -652,27 +717,50 @@ if ( TRUE == didTimeout( concentrateTestStartTime, CONCENTRATE_TEST_TIME_OUT_MS ) ) { - BOOL haveTestsPassed = FALSE; + DG_CHEMICALS_FILL_COND_CAL_RECORD_T chemicalsCond; + F32 acidCondUSPerCM = 0.0F; + BOOL hasAcidTestPassed = FALSE; + BOOL hasCD1CD2TestPassed = FALSE; + getFillChemicalCondRecord( &chemicalsCond ); + + acidCondUSPerCM = chemicalsCond.fillCondValues[ chemicalsTypes.acidType ][ FILL_COND_ACID_TEST ].acidConduSPerCM; averageBicarbConductivity = totalBicarbConductivity / bicarbConductivitySampleCount; averageAcidConductivity = totalAcidConductivity / acidConductivitySampleCount; pctDiffInConductivity = fabs( 2.0F * ( averageAcidConductivity - averageBicarbConductivity ) / - ( averageAcidConductivity + averageBicarbConductivity ) ); + ( averageAcidConductivity + averageBicarbConductivity ) ); - if ( ( TRUE == isValueWithinPercentRange( averageAcidConductivity, ACID_TEST_CD2_TCD, FIVE_PERCENT_FACTOR ) ) && - ( pctDiffInConductivity < FIVE_PERCENT_FACTOR ) ) +#ifndef _RELEASE_ + if ( getSoftwareConfigStatus( SW_CONFIG_DISABLE_ACID_CONDUCTIVITY_TEST ) != SW_CONFIG_ENABLE_VALUE ) +#endif { - haveTestsPassed = TRUE; - } + if ( TRUE == isValueWithinPercentRange( averageAcidConductivity, acidCondUSPerCM, FIVE_PERCENT_FACTOR ) ) + { + hasAcidTestPassed = TRUE; + } + else + { + SET_ALARM_WITH_1_F32_DATA( ALARM_ID_ACID_CONDUCTIVITY_OUT_OF_RANGE, averageAcidConductivity ) + } + if ( pctDiffInConductivity < FIVE_PERCENT_FACTOR ) + { + hasCD1CD2TestPassed = TRUE; + } + else + { + SET_ALARM_WITH_1_F32_DATA( ALARM_ID_DG_CD1_CD2_CHECK_FAULT, pctDiffInConductivity ) + } + } #ifndef _RELEASE_ - if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_ACID_CONDUCTIVITY_TEST ) ) + else { - haveTestsPassed = TRUE; + hasAcidTestPassed = TRUE; + hasCD1CD2TestPassed = TRUE; } #endif - if ( TRUE == haveTestsPassed ) + if ( ( TRUE == hasAcidTestPassed ) && ( TRUE == hasCD1CD2TestPassed ) ) { DG_ACID_CONCENTRATES_RECORD_T acid; F32 acidMix; @@ -693,11 +781,6 @@ fillStatus.isThisFirstFill = FALSE; result = DG_FILL_MODE_STATE_PRODUCE_DIALYSATE; } - else - { - // Acid conductivity did not pass, fault - SET_ALARM_WITH_1_F32_DATA( ALARM_ID_ACID_CONDUCTIVITY_OUT_OF_RANGE, averageAcidConductivity ); - } } return result; @@ -822,12 +905,16 @@ // If we've reached our target fill to volume (by weight), we're done filling - go back to generation idle mode // SRSDG 398 if ( TRUE == hasTargetFillVolumeBeenReached( inactiveRsrvr ) ) { + DG_CHEMICALS_FILL_COND_CAL_RECORD_T chemicalsCond; + + getFillChemicalCondRecord( &chemicalsCond ); + F32 filledVolumeML = getReservoirWeight( inactiveRsrvr ) - reservoirBaseWeight; F32 integratedVolumeToLoadCellReadingPercent = fabs( 1.0F - ( filledVolumeML / getIntegratedVolumeML() ) ); F32 avgAcidConductivity = acidConductivityTotal / conductivitySampleCount; F32 avgBicarbConductivity = bicarbConductivityTotal / conductivitySampleCount; - F32 acidNormalConductivity = acid.acidConcentrate[ CAL_DATA_ACID_CONCENTRATE_1 ].acidConductivityUSPerCM; - F32 bicarbNormalConductivity = bicarb.bicarbConcentrate[ CAL_DATA_BICARB_CONCENTRATE_1 ].bicarbConductivityUSPerCM; + F32 acidNormalConductivity = chemicalsCond.fillCondValues[ chemicalsTypes.acidType ][ FILL_COND_NORMAL_OP ].acidConduSPerCM; + F32 bicarbNormalConductivity = chemicalsCond.fillCondValues[ chemicalsTypes.acidType ][ FILL_COND_NORMAL_OP ].bicarbConduSPerCM; SEND_EVENT_WITH_2_F32_DATA( DG_EVENT_AVG_DIALYSATE_FILL_COND_VALUES, avgAcidConductivity, avgBicarbConductivity ) SEND_EVENT_WITH_2_F32_DATA( DG_EVENT_RESERVOIR_FILL_VALUES, reservoirBaseWeight, filledVolumeML ) @@ -847,7 +934,7 @@ // Fault alarm per PRS 483 SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DG_OUTLET_PRIMARY_CONDUCTIVITY_OUT_OF_RANGE, avgCPo, MAX_CPO_CONDUCTIVITY_ALLOW ); } - if ( avgRR > MAX_RO_REJECTION_RATIO_ALLOW ) + if ( ( avgRR > MAX_RO_REJECTION_RATIO_ALLOW ) && ( isROOnlyModeEnabled() != TRUE ) ) { // Fault alarm per PRS 483 SET_ALARM_WITH_2_F32_DATA( ALARM_ID_RO_REJECTION_RATIO_OUT_OF_RANGE, avgRR, MAX_RO_REJECTION_RATIO_ALLOW ); @@ -929,7 +1016,7 @@ havePauseActuatorsBeenSet = TRUE; } - if ( FALSE == areInletWaterConditionsAlarmsActive() ) + if ( ( FALSE == areInletWaterConditionsAlarmsActive() ) && ( FALSE == areConductivityAlarmsActive() ) ) { havePauseActuatorsBeenSet = FALSE; result = DG_FILL_MODE_STATE_START; @@ -948,7 +1035,7 @@ *************************************************************************/ static BOOL areInletWaterConditionsAlarmsActive( void ) { - // Check inlet water conductivity, temperature, pressure, and RO rejection ratio + // Check inlet water conductivity, temperature, pressure BOOL status = FALSE; checkInletWaterConductivity(); checkInletWaterTemperature(); @@ -972,6 +1059,27 @@ /*********************************************************************//** * @brief + * The areConductivityAlarmsActive function checks whether the inlet + * acid/bicarb conductivity alarms are active. + * @details Inputs: none + * @details Outputs: None + * @return TRUE if any of the alarms are active, otherwise, FALSE + *************************************************************************/ +static BOOL areConductivityAlarmsActive( void ) +{ + BOOL status = FALSE; + + if ( ( TRUE == isAlarmActive( ALARM_ID_BICARB_CONDUCTIVITY_OUT_OF_RANGE ) ) || + ( TRUE == isAlarmActive( ALARM_ID_ACID_CONDUCTIVITY_OUT_OF_RANGE ) ) ) + { + status = TRUE; + } + + return status; +} + +/*********************************************************************//** + * @brief * The isValueWithinPercentRange function validates if the test value * is within the percentage range specified by the baseValue and * percentFactor. @@ -1063,6 +1171,7 @@ fillModeData.usedAcidVolumeML = getChemicalUsedVolumeML( ACID ); fillModeData.usedBicarbVolumeML = getChemicalUsedVolumeML( BICARB ); fillModeData.integratedVolumeML = getIntegratedVolumeML(); + fillModeData.roOnlyModeStatus = (U32)isROOnlyModeEnabled(); broadcastData( MSG_ID_DG_FILL_MODE_DATA, COMM_BUFFER_OUT_CAN_DG_BROADCAST, (U08*)&fillModeData, sizeof( DG_FILL_MODE_DATA_T ) );