Index: firmware/App/Modes/ModeTreatment.c =================================================================== diff -u -r054fa08b67ed2a31f7848b179fbcd1b4da501b0f -rd86855d12f5103fc16e2e06e267da237c8d549d7 --- firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision 054fa08b67ed2a31f7848b179fbcd1b4da501b0f) +++ firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision d86855d12f5103fc16e2e06e267da237c8d549d7) @@ -47,8 +47,9 @@ #define TREATMENT_TIME_DATA_PUB_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the treatment time & state data is published on the CAN bus -#define CALC_ELAPSED_TREAT_TIME_IN_SECS() ( treatmentTimeMS / MS_PER_SECOND ) ///< Macro to calculate the elapsed treatment time in seconds. -#define CALC_TREAT_TIME_REMAINING_IN_SECS() ( (S32)presTreatmentTimeSecs - (S32)( treatmentTimeMS / MS_PER_SECOND ) ) ///< Macro to calculate the remaining treatment time in seconds. +#define CALC_ELAPSED_TREAT_TIME_IN_SECS() ( treatmentTimeMS / MS_PER_SECOND ) ///< Macro to calculate the elapsed treatment time in seconds. +#define CALC_ELAPSED_TREAT_TIME_IN_MIN() ( ( treatmentTimeMS / MS_PER_SECOND ) / SEC_PER_MIN ) ///< Macro to calculate the elapsed treatment time in minutes. +#define CALC_TREAT_TIME_REMAINING_IN_SECS() ( (S32)presTreatmentTimeSecs - (S32)( treatmentTimeMS / MS_PER_SECOND ) ) ///< Macro to calculate the remaining treatment time in seconds. // ********** private data ********** @@ -367,13 +368,15 @@ OP_MODE currMode = getCurrentOperationMode(); // check if we are in an appropriate treatment state for settings adjustment - if ( ( MODE_TREA == currMode ) && ( currentTreatmentState > TREATMENT_START_STATE ) && ( currentTreatmentState < TREATMENT_DIALYSIS_END_STATE ) ) - { + if ( ( MODE_TREA == currMode ) && + ( currentTreatmentState > TREATMENT_START_STATE ) && ( currentTreatmentState < TREATMENT_DIALYSIS_END_STATE ) && + ( CALC_ELAPSED_TREAT_TIME_IN_MIN() < treatmentTime ) ) + { // TODO - reject if proposed time is < current time REQUEST_REJECT_REASON_TREATMENT_TIME_LESS_THAN_CURRENT F32 uFVolume; U32 dialVolume = presDialysateFlowRate * treatmentTime; // in mL // always adjust UF volume to accommodate treatment time change (not UF rate) - uFVolume = (F32)treatmentTime * presUFRate; + uFVolume = ( (F32)( treatmentTime - CALC_ELAPSED_TREAT_TIME_IN_MIN() ) * presUFRate ) + getUltrafiltrationVolumeCollected(); if ( ( treatmentTime <= MAX_TREATMENT_TIME_MINUTES ) && ( dialVolume <= MAX_DIALYSATE_VOLUME_ML ) ) { result = TRUE; @@ -400,10 +403,14 @@ { rejectReason = REQUEST_REJECT_REASON_TREATMENT_TIME_OUT_OF_RANGE; } - else + else if ( ( currentTreatmentState <= TREATMENT_START_STATE ) || ( currentTreatmentState >= TREATMENT_DIALYSIS_END_STATE ) ) { rejectReason = REQUEST_REJECT_REASON_INVALID_TREATMENT_STATE; } + else + { + rejectReason = REQUEST_REJECT_REASON_TREATMENT_TIME_LESS_THAN_CURRENT; + } } sendChangeUFSettingsResponse( result, rejectReason, pendingUFVolumeChange, pendingTreatmentTimeChange, pendingUFRateChange, timeDiff, rateDiff );