Index: firmware/App/Modes/ModeTreatment.c =================================================================== diff -u -re2cf7feff54dad3fc5be72619fa64b5421fc6f9f -rcd5be724d5a3ba7457e761191d82f278654d7f5c --- firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision e2cf7feff54dad3fc5be72619fa64b5421fc6f9f) +++ firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision cd5be724d5a3ba7457e761191d82f278654d7f5c) @@ -1,14 +1,14 @@ /************************************************************************** * -* Copyright (c) 2019-2023 Diality Inc. - All Rights Reserved. +* Copyright (c) 2019-2024 Diality Inc. - All Rights Reserved. * * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * @file ModeTreatment.c * -* @author (last) Darren Cox -* @date (last) 19-Sep-2023 +* @author (last) Vinayakam Mani +* @date (last) 12-Oct-2023 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -713,7 +713,7 @@ * @brief * The handleTreatmentBloodPrimeState function handles the blood prime state of * the Treatment Mode state machine. - * @details Inputs: none + * @details Inputs: presUFRate * @details Outputs: none * @return next treatment mode state *************************************************************************/ @@ -740,7 +740,10 @@ // Kick dialysis sub-mode off setDialysisParams( getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ), getTreatmentParameterU32( TREATMENT_PARAM_DIALYSATE_FLOW ), presMaxUFVolumeML, presUFRate ); - sendTreatmentLogEventData( UF_START_RESUME_EVENT, 0.0, presUFRate ); + if ( presUFRate > 0.0 ) + { + sendTreatmentLogEventData( UF_START_RESUME_EVENT, 0.0, presUFRate ); + } transitionToDialysis(); result = TREATMENT_DIALYSIS_STATE; } @@ -791,7 +794,6 @@ // Handle alarm stoppage if ( TRUE == doesAlarmStatusIndicateStop() ) { - stopDialysis(); transitionToTreatmentStop(); result = TREATMENT_STOP_STATE; } @@ -1120,9 +1122,8 @@ DIALYSIS_STATE_T currDialysisState = getDialysisState(); UF_STATE_T currUFState = getUltrafiltrationState(); F32 remUFVol = uFVolume - colUFVol; // What would remaining UF volume be after subtracting UF volume already taken - F32 remUFVolCap = RANGE( remUFVol, 0.0F, (F32)MAX_UF_VOLUME_ML ); // Enforce valid range on remaining UF volume - F32 uFRate = remUFVolCap / txMinRem; // What UF rate would be if user selected to adjust it - U32 trtTime = ( fabs( presUFRate ) < NEARLY_ZERO ? txMinEla + 1 : (S32)( remUFVolCap / presUFRate ) + txMinEla + 1 ); // What the treatment duration would be if user selected to adjust it + F32 uFRate = remUFVol / txMinRem; // What UF rate would be if user selected to adjust it + U32 trtTime = ( fabs( presUFRate ) < NEARLY_ZERO ? txMinEla + 1 : (S32)( remUFVol / presUFRate ) + txMinEla + 1 ); // What the treatment duration would be if user selected to adjust it U32 dialVolume = getTreatmentParameterU32( TREATMENT_PARAM_DIALYSATE_FLOW ) * trtTime; // What dialysate volume would be if user selected to adjust time // UF should already be paused but let's make sure. @@ -1137,7 +1138,7 @@ pendingParamChangesTimer = getMSTimerCount(); // Verify UF rate change would be valid (leave zero if not valid - UI will disable option) - if ( ( uFRate <= (F32)MAX_UF_RATE_ML_MIN ) && ( uFRate >= MIN_UF_RATE_ML_MIN ) ) + if ( uFRate <= (F32)MAX_UF_RATE_ML_MIN ) { result = TRUE; pendingUFVolumeChange = uFVolume; @@ -1536,22 +1537,26 @@ if ( ( timeElapsedSinceLastPublish_ms >= TREATMENT_PERIODIC_DATA_PUB_INTERVAL ) || ( TRUE == sendLastTreatmentPeriodicData ) ) { TREATMENT_LOG_DATA_PERIODIC_T periodTreatmentData; + F32 const uFVolumeCollected = getUltrafiltrationVolumeCollected(); U32 const numberOfDataPoint = timeElapsedSinceLastPublish_ms / TREATMENT_PERIODIC_DATA_LOG_INTERVAL; - periodTreatmentData.avgUFRate = ( getUltrafiltrationVolumeCollected() - lastUltraFiltrationVolume_mL ) / ( numberOfDataPoint / SEC_PER_MIN ); - periodTreatmentData.avgBloodFlowRate = bloodFlowRateSum_mL_min / numberOfDataPoint; - periodTreatmentData.avgDialysateFlowRate = dialysateFlowRateSum_mL_min / numberOfDataPoint; - periodTreatmentData.avgArterialPressure = arterialPressureSum_mmHg / numberOfDataPoint; - periodTreatmentData.avgVenousPressure = venousPressureSum_mmHg / numberOfDataPoint; - + if ( numberOfDataPoint > 0 ) + { // don't send data if no data since last publish + periodTreatmentData.avgUFRate = ( uFVolumeCollected - lastUltraFiltrationVolume_mL ) / ( numberOfDataPoint / SEC_PER_MIN ); + periodTreatmentData.avgBloodFlowRate = bloodFlowRateSum_mL_min / numberOfDataPoint; + periodTreatmentData.avgDialysateFlowRate = dialysateFlowRateSum_mL_min / numberOfDataPoint; + periodTreatmentData.avgArterialPressure = arterialPressureSum_mmHg / numberOfDataPoint; + periodTreatmentData.avgVenousPressure = venousPressureSum_mmHg / numberOfDataPoint; + sendTreatmentPeriodicDataToUI( &periodTreatmentData ); + } + // reset for next round to publish sendLastTreatmentPeriodicData = FALSE; lastTreatmentPeriodicDataPublishTimeStamp = treatmentTimeMS; - lastUltraFiltrationVolume_mL = getUltrafiltrationVolumeCollected(); + lastUltraFiltrationVolume_mL = uFVolumeCollected; bloodFlowRateSum_mL_min = 0.0; dialysateFlowRateSum_mL_min = 0.0; arterialPressureSum_mmHg = 0.0; venousPressureSum_mmHg = 0.0; - sendTreatmentPeriodicDataToUI( &periodTreatmentData ); } }