Index: firmware/App/Modes/ModeTreatment.c =================================================================== diff -u -rf861c4c5ab64f429e0b8b9cc456e2ed14e472f2b -ra60ec05d359c0d3f014015e9080b6dbcef0fea28 --- firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision f861c4c5ab64f429e0b8b9cc456e2ed14e472f2b) +++ firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision a60ec05d359c0d3f014015e9080b6dbcef0fea28) @@ -701,7 +701,9 @@ /*********************************************************************//** * @brief * The broadcastTreatmentSettingsRanges function computes and broadcasts \n - * updated treatment parameter ranges that the user may change during treatment. + * updated treatment parameter ranges that the user may change during treatment. \n + * It is assumed that prescription settings have already been set prior to calling \n + * this function. * @details * Inputs : current operating mode, treatment states and parameters * Outputs : valid ranges message sent on interval @@ -712,21 +714,24 @@ if ( ++treatmentParamsRangesBroadcastTimerCtr >= TREATMENT_SETTINGS_RANGES_PUB_INTERVAL ) { // compute minimum treatment duration - U32 elapseTime = CALC_ELAPSED_TREAT_TIME_IN_MIN() + 2; // add two minutes to cover rounding and ensure it's valid for next minute - U32 minTime = MAX( elapseTime, MIN_TREATMENT_TIME_MINUTES ); // treatment duration cannot be < 1 hour + U32 presTime = ( presTreatmentTimeSecs / SEC_PER_MIN ); + U32 elapseTime = CALC_ELAPSED_TREAT_TIME_IN_MIN(); + U32 minTime = MAX( (elapseTime + 2), MIN_TREATMENT_TIME_MINUTES ); // treatment duration cannot be < 1 hour. add two minutes to cover rounding and ensure it's valid for next minute // compute maximum treatment duration (from both UF and dialysate volume perspectives) U32 maxTimeRem = ( MAX_UF_VOLUME_ML - (U32)getUltrafiltrationVolumeCollected() ) / ( presUFRate > 0.0 ? (U32)presUFRate : 1 ); U32 maxTime1 = minTime + maxTimeRem; U32 maxTime2 = MAX_DIALYSATE_VOLUME_ML / presDialysateFlowRate; - U32 maxTime = MIN( maxTime1, maxTime2 ); + U32 maxTime = MAX( maxTime1, maxTime2 ); // compute minimum UF volume F32 minUFVol = getUltrafiltrationVolumeCollected() + presUFRate; - // compute maximum UF volume (considering from adjustment of UF rate perspective) - F32 maxUFVol = ( presUFRate > 0.0 ? minUFVol + ( (F32)( MAX_TREATMENT_TIME_MINUTES - CALC_ELAPSED_TREAT_TIME_IN_MIN() - 1 ) * presUFRate ) : (F32)MAX_UF_VOLUME_ML ); + // compute maximum UF volume (considering from adjustment of UF rate and time perspectives) + F32 maxUFVol1 = minUFVol + ( (F32)( presTime - elapseTime ) * MAX_UF_RATE_ML_MIN ); + F32 maxUFVol2 = ( presUFRate > 0.0 ? minUFVol + ( (F32)( MAX_TREATMENT_TIME_MINUTES - elapseTime - 1 ) * presUFRate ) : minUFVol ); + F32 maxUFVol = MAX( maxUFVol1, maxUFVol2 ); // compute minimum dialysate flow rate U32 minDialRate = MIN_DIAL_IN_FLOW_RATE; // compute maximum dialysate flow rate from max dialysate volume perspective - U32 maxDialRate = MAX_DIALYSATE_VOLUME_ML / ( presTreatmentTimeSecs / SEC_PER_MIN ); + U32 maxDialRate = MAX_DIALYSATE_VOLUME_ML / presTime; // now ensure maximums do not exceed the literal maximums maxTime = MIN( maxTime, MAX_TREATMENT_TIME_MINUTES );