Index: firmware/App/Modes/ModeFill.c =================================================================== diff -u -r16c0f816fadfa45b51467c5292ba9ecf7a3914bd -r35a1f7d58d013f95108e38674b01a283970e74a2 --- firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 16c0f816fadfa45b51467c5292ba9ecf7a3914bd) +++ firmware/App/Modes/ModeFill.c (.../ModeFill.c) (revision 35a1f7d58d013f95108e38674b01a283970e74a2) @@ -116,10 +116,13 @@ 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 dialysateFillStartTimeMS; ///< Current time when starting to fill dialysate in milliseconds. static F32 reservoirBaseWeight; ///< Fill reservoir base weight. static FILL_CONDITION_STATUS_T fillStatus; ///< Fill condition status. +static BOOL didFillRecoverFromPause; ///< Flag to indicate whether the previous state was pause or not. +static U32 dialysateFillStartTimeMS; ///< Current time when starting to fill dialysate in milliseconds. +static U32 dialysatePauseStartTimeMS; ///< Current time when starting a pause during fill dialysate in milliseconds. +static U32 dialysatePauseElapsedTimeMS; ///< Elapsed time in pause during fill dialysate in milliseconds. static U32 concentrateTestStartTime; ///< Starting time for concentrate test. static U32 concentratePrimingStartTime; ///< Starting time for concentrate priming. static U32 flushBubblesStartTime; ///< Starting time for flush bubbles. @@ -145,8 +148,6 @@ static U32 fillCPoConductivitySampleCnt; ///< Number of samples in sum of CPo and Rej. Ratio conductivity readings for fill. 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 BOOL didFillRecoverFromPause; ///< Flag to indicate whether the previous state was pause or not. static FILL_ACID_BICARB_TYPES_T chemicalsTypes; ///< Chemicals Types (acid and bicarb). static DG_CHEMICALS_FILL_COND_CAL_RECORD_T chemicalsCond; ///< Chemicals fill conductivity records. static F32 acidMixRatio; ///< Acid conductivity mix ratio. @@ -194,32 +195,33 @@ getAcidConcentrateCalRecord( &acid ); getBicarbConcentrateCalRecord( &bicarb ); + acidConductivitySampleCount = 0; + acidConductivityTotal = 0.0F; acidMixRatio = acid.acidConcentrate[ CAL_DATA_ACID_CONCENTRATE_1 ].acidConcMixRatio; + averageAcidConductivity = 0.0F; + averageBicarbConductivity = 0.0F; + bicarbConductivitySampleCount = 0; + bicarbConductivityTotal = 0.0F; bicarbMixRatio = bicarb.bicarbConcentrate[ CAL_DATA_BICARB_CONCENTRATE_1 ].bicarbConcMixRatio; - fillState = DG_FILL_MODE_STATE_TEST_INLET_WATER; - dialysateFillStartTimeMS = 0; - dataPublishCounter = DATA_PUBLISH_COUNTER_START_COUNT; - reservoirBaseWeight = 0.0F; - integratedVolumeML.data = 0.0F; - didFMPCheckStart = FALSE; concentrateTestStartTime = 0; - acidConductivityTotal = 0.0F; - bicarbConductivityTotal = 0.0F; - conductivitySampleCount = 0; concPumpPrimeStartTimeMS = getMSTimerCount(); - pumpSpeedIndex = 0; - averageBicarbConductivity = 0.0F; - averageAcidConductivity = 0.0F; + conductivitySampleCount = 0; + dataPublishCounter = DATA_PUBLISH_COUNTER_START_COUNT; + dialysateFillStartTimeMS = 0; + dialysatePauseElapsedTimeMS = 0; + dialysatePauseStartTimeMS = 0; + didFillRecoverFromPause = FALSE; + didFMPCheckStart = FALSE; + fillCPoConductivitySampleCnt = 0; + fillState = DG_FILL_MODE_STATE_TEST_INLET_WATER; + integratedVolumeML.data = 0.0F; pctDiffInConductivity = 0.0F; - bicarbConductivitySampleCount = 0; - acidConductivitySampleCount = 0; - totalBicarbConductivity = 0.0F; - totalAcidConductivity = 0.0F; - havePauseActuatorsBeenSet = FALSE; + pumpSpeedIndex = 0; + reservoirBaseWeight = 0.0F; sumFillCPoConductivity = 0.0F; sumFillRejRatio = 0.0F; - fillCPoConductivitySampleCnt = 0; - didFillRecoverFromPause = FALSE; + totalAcidConductivity = 0.0F; + totalBicarbConductivity = 0.0F; } /*********************************************************************//** @@ -233,17 +235,19 @@ { F32 targetFlowLPM = getTargetFillFlowRateLPM(); - if ( ( getTestConfigStatus( TEST_CONFIG_RECOVER_TREATMENT ) != TRUE ) || ( getPreviousOperationMode() != DG_MODE_FAUL ) ) - { - initFillMode(); - setCurrentSubState( NO_SUB_STATE ); + initFillMode(); + setCurrentSubState( NO_SUB_STATE ); + // Set initial actuator states + setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); + setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); +#ifdef 0 + // Reset the state machine + // Note: the substate timers, and operation flags need to be reset on recovery, consider + // reinitializing the state variables, the resetting the state, by calling setModeFillStateTransition() + if ( ( TRUE == getTestConfigStatus( TEST_CONFIG_RECOVER_TREATMENT ) ) && ( DG_MODE_FAUL == getPreviousOperationMode() ) ) + { // Restore the prior fillstate to a valid, running fill state, with timer state reset. + fillState = restoreFillState; - // Set initial actuator states - setValveState( VDR, VALVE_STATE_DRAIN_C_TO_NO ); - setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); - } - else - { setValveState( VPI, VALVE_STATE_OPEN ); setValveState( VPD, VALVE_STATE_OPEN_C_TO_NC ); @@ -290,20 +294,18 @@ requestConcentratePumpOn( CONCENTRATEPUMPS_CP1_ACID ); requestConcentratePumpOn( CONCENTRATEPUMPS_CP2_BICARB ); setValveState( VPO, VALVE_STATE_FILL_C_TO_NC ); - dialysateFillStartTimeMS = getMSTimerCount(); fillStatus.isThisFirstFill = FALSE; break; case DG_FILL_MODE_STATE_PAUSED: targetFlowLPM = TARGET_RO_FLOW_RATE_IN_PAUSE_L; - havePauseActuatorsBeenSet = FALSE; + dialysatePauseStartTimeMS = getMSTimerCount(); break; } } - +#endif getFillChemicalCondRecord( &chemicalsCond ); - turnOnUVReactor( INLET_UV_REACTOR ); turnOnUVReactor( OUTLET_UV_REACTOR ); @@ -330,9 +332,13 @@ checkDialysateTemperatureSensors(); setHeaterTargetTemperature( DG_PRIMARY_HEATER, getPrimaryHeaterTargetTemperature() ); - if ( ( TRUE == areInletWaterConditionsAlarmsActive() ) || ( TRUE == areConductivityAlarmsActive() ) ) + if ( fillState != DG_FILL_MODE_STATE_PAUSED ) { - fillState = DG_FILL_MODE_STATE_PAUSED; + if ( ( TRUE == areInletWaterConditionsAlarmsActive() ) || ( TRUE == areConductivityAlarmsActive() ) ) + { + setModeFillStateTransition( DG_FILL_MODE_STATE_PAUSED ); + fillState = DG_FILL_MODE_STATE_PAUSED; + } } // Execute current Fill state @@ -375,7 +381,6 @@ fillState = DG_FILL_MODE_STATE_TEST_INLET_WATER; break; } - publishFillModeData(); return fillState; @@ -430,6 +435,7 @@ F32 getIntegratedVolumeML( void ) { F32 integratedVolume = getF32OverrideValue( &integratedVolumeML ); + return integratedVolume; } @@ -600,7 +606,6 @@ { result = DG_FILL_MODE_STATE_PRODUCE_DIALYSATE; } - setModeFillStateTransition( result ); return result; @@ -872,7 +877,6 @@ didFMPCheckStart = TRUE; reservoirBaseWeight = getReservoirWeight( getInactiveReservoir() ); } - integratedVolumeML.data += getMeasuredROFlowRateWithConcPumpsLPM() * ML_PER_LITER * FLOW_INTEGRATOR; } @@ -888,8 +892,10 @@ fillStatus.fillTemperatureRunningSum += inletTemperature; // TODO: Check for open straw door status and alarm if closed - // Check if run out of time to fill the reservoir - if ( TRUE == didTimeout( dialysateFillStartTimeMS, DIALYSATE_FILL_TIME_OUT ) ) + // Check if run out of time to fill the reservoir, disregarding time paused, + // because pause time isn't the reservoir's, or loadcell's fault + // the 5 minutes DIALYSATE_FILL_TIME_OUT is a mystery number. + if ( TRUE == didTimeout( dialysateFillStartTimeMS, DIALYSATE_FILL_TIME_OUT+dialysatePauseElapsedTimeMS ) ) { activateAlarmNoData( ALARM_ID_DG_DIALYSATE_FILL_OUT_OF_TIME ); } @@ -971,21 +977,19 @@ * @brief * The handlePausedState function executes the paused state of the fill * mode state machine. - * @details Inputs: havePauseActuatorsBeenSet - * @details Outputs: havePauseActuatorsBeenSet, didFillRecoverFromPause + * @details Inputs: Inlet water conditions and conductivity + * @details Outputs: didFillRecoverFromPause * @return the next state *************************************************************************/ static DG_FILL_MODE_STATE_T handlePausedState( void ) { DG_FILL_MODE_STATE_T result = DG_FILL_MODE_STATE_PAUSED; - setModeFillStateTransition( result ); - if ( ( FALSE == areInletWaterConditionsAlarmsActive() ) && ( FALSE == areConductivityAlarmsActive() ) ) { didFillRecoverFromPause = TRUE; - havePauseActuatorsBeenSet = FALSE; result = DG_FILL_MODE_STATE_TEST_INLET_WATER; + setModeFillStateTransition( result ); } return result; @@ -995,17 +999,28 @@ * @brief * The setModeFillStateTransition function sets the actuators and variables * for the state transition in mode fill. - * @details Inputs: pumpSpeedIndex, havePauseActuatorsBeenSet, + * @details Inputs: pumpSpeedIndex, dialysatePauseStartTimeMS * didFillRecoverFromPause * @details Outputs: concPumpPrimeStartTimeMS, fillStatus, pumpSpeedIndex, * concentratePrimingStartTime, totalBicarbConductivity, averageBicarbConductivity, * bicarbConductivitySampleCount, concentrateTestStartTime, fillStatus, - * havePauseActuatorsBeenSet, flushBubblesStartTime, didFillRecoverFromPause + * flushBubblesStartTime, didFillRecoverFromPause + * dialysatePauseElapsedTimeMS, dialysatePauseStartTimeMS * @param state mode fill state enum * @return none *************************************************************************/ static void setModeFillStateTransition( DG_FILL_MODE_STATE_T state ) { + // Execute cleanup on exiting pause + if ( state != fillState ) + { + if (DG_FILL_MODE_STATE_PAUSED == fillState) + { // accumulate pause + dialysatePauseElapsedTimeMS += calcTimeSince(dialysatePauseStartTimeMS); + } + } + + // Execute on running state switch( state ) { case DG_FILL_MODE_STATE_TEST_INLET_WATER: @@ -1083,14 +1098,11 @@ break; case DG_FILL_MODE_STATE_PAUSED: - if ( FALSE == havePauseActuatorsBeenSet ) - { - setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); - setROPumpTargetFlowRateLPM( TARGET_RO_FLOW_RATE_IN_PAUSE_L, TARGET_RO_PRESSURE_PSI ); - requestConcentratePumpOff( CONCENTRATEPUMPS_CP1_ACID, NO_PARK_CONC_PUMPS ); - requestConcentratePumpOff( CONCENTRATEPUMPS_CP2_BICARB, NO_PARK_CONC_PUMPS ); - havePauseActuatorsBeenSet = TRUE; - } + dialysatePauseStartTimeMS = getMSTimerCount(); + setValveState( VPO, VALVE_STATE_NOFILL_C_TO_NO ); + setROPumpTargetFlowRateLPM( TARGET_RO_FLOW_RATE_IN_PAUSE_L, TARGET_RO_PRESSURE_PSI ); + requestConcentratePumpOff( CONCENTRATEPUMPS_CP1_ACID, NO_PARK_CONC_PUMPS ); + requestConcentratePumpOff( CONCENTRATEPUMPS_CP2_BICARB, NO_PARK_CONC_PUMPS ); break; default: