Index: firmware/App/Modes/ModeTreatment.c =================================================================== diff -u -re63c54262fd4ccd8ffd9ef9bb49e66458893528f -r40e0116bbada6d1780bfa832a9c4684ba9fcfcc8 --- firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision e63c54262fd4ccd8ffd9ef9bb49e66458893528f) +++ firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision 40e0116bbada6d1780bfa832a9c4684ba9fcfcc8) @@ -60,9 +60,9 @@ /// Interval (ms/task time) at which updated, valid treatment setting ranges are published on the CAN bus. static const U32 TREATMENT_SETTINGS_RANGES_PUB_INTERVAL = ( ( 60 * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ); /// Interval (ms/task time) at which the treatment periodic data is published on the CAN bus. -static const U32 TREATMENT_PERIODIC_DATA_PUB_INTERVAL = ( ( 30 * SEC_PER_MIN * MS_PER_SECOND ) / TASK_GENERAL_INTERVAL ); +static const U32 TREATMENT_PERIODIC_DATA_PUB_INTERVAL = ( 30 * SEC_PER_MIN * MS_PER_SECOND ); /// Interval (ms/task time) at which the treatment periodic data is logged. -static const U32 TREATMENT_PERIODIC_DATA_LOG_INTERVAL = ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ); +static const U32 TREATMENT_PERIODIC_DATA_LOG_INTERVAL = ( MS_PER_SECOND ); #define CALC_ELAPSED_TREAT_TIME_IN_SECS() ( treatmentTimeMS / MS_PER_SECOND ) ///< Macro to calculate the elapsed treatment time in seconds. /// Macro to calculate the elapsed treatment time in minutes. @@ -89,7 +89,6 @@ static U32 treatmentTimeBroadcastTimerCtr; ///< Treatment time data broadcast timer counter used to schedule when to transmit data. static U32 treatmentStateBroadcastTimerCtr; ///< Treatment state data broadcast timer counter used to schedule when to transmit data. static U32 treatmentParamsRangesBroadcastTimerCtr; ///< Treatment parameter ranges broadcast timer counter used to schedule when to transmit updated ranges. -static U32 treatmentPeriodDataBroadcastTimerCtr; ///< Treatment 30 minutes periodic data broadcast timer counter used to schedule when to transmit data. static BOOL resumeTreatmentAlarmResponseRequest; ///< Flag indicates user has requested treatment resume. static BOOL initiateRinsebackAlarmResponseRequest; ///< Flag indicates user has requested rinseback. @@ -105,11 +104,13 @@ static F32 pendingUFRateChange; ///< An ultrafiltration rate change (mL/min) is pending user confirmation. static U32 pendingTreatmentTimeChange; ///< A treatment time change (min) is pending user confirmation. -static F32 bloodFlowRateTotal; ///< Blood flow rate total, used to calculate blood flow rate average over 30 minutes. -static F32 dialysateFlowRateTotal; ///< Dialysate flow rate total, used to calculate dialysate flow rate average over 30 minutes. -static F32 ultraFiltrationRateTotal; ///< UF rate total, used to calculate UF rate average over 30 minutes. -static F32 arterialPressureTotal; ///< Arterial pressure total, used to calculate arterial pressure average over 30 minutes. -static F32 venousPressureTotal; ///< Venous pressure total, used to calculate venous pressure average over 30 minutes. +static U32 lastTreatmentPeriodicDataPublishTimeStamp; ///< Last treatment 30 minutes periodic data publish time stamp. +static U32 lastTreatmentPeriodicDataCollectTimeStamp; ///< Last treatment periodic data collect time stamp. +static F32 lastUltraFiltrationVolume_mL; ///< Last 30 minutes ultra filtration volume in mL. +static F32 bloodFlowRateTotal_mL_min; ///< Blood flow rate total, used to calculate blood flow rate average over 30 minutes. +static F32 dialysateFlowRateTotal_mL_min; ///< Dialysate flow rate total, used to calculate dialysate flow rate average over 30 minutes. +static F32 arterialPressureTotal_mmHg; ///< Arterial pressure total, used to calculate arterial pressure average over 30 minutes. +static F32 venousPressureTotal_mmHg; ///< Venous pressure total, used to calculate venous pressure average over 30 minutes. // ********** private function prototypes ********** @@ -145,7 +146,6 @@ treatmentTimeBroadcastTimerCtr = TREATMENT_TIME_DATA_PUB_INTERVAL; // So we send time data immediately when we begin treatment mode treatmentStateBroadcastTimerCtr = TREATMENT_STATE_DATA_PUB_INTERVAL; // So we send state data immediately when we begin treatment mode treatmentParamsRangesBroadcastTimerCtr = TREATMENT_SETTINGS_RANGES_PUB_INTERVAL; // So we send ranges immediately when we begin treatment mode - treatmentPeriodDataBroadcastTimerCtr = 0; presTreatmentTimeSecs = 0; presBloodFlowRate = 0; @@ -161,11 +161,13 @@ pendingUFRateChange = 0.0; pendingTreatmentTimeChange = 0; - bloodFlowRateTotal = 0.0; - dialysateFlowRateTotal = 0.0; - ultraFiltrationRateTotal = 0.0; - arterialPressureTotal = 0.0; - venousPressureTotal = 0.0; + lastTreatmentPeriodicDataPublishTimeStamp = 0; + lastTreatmentPeriodicDataCollectTimeStamp = 0; + lastUltraFiltrationVolume_mL = 0.0; + bloodFlowRateTotal_mL_min = 0.0; + dialysateFlowRateTotal_mL_min = 0.0; + arterialPressureTotal_mmHg = 0.0; + venousPressureTotal_mmHg = 0.0; } /*********************************************************************//** @@ -217,8 +219,6 @@ initRinseback(); initTreatmentRecirc(); initTreatmentEnd(); - - setTreatmentDateTime( getRTCTimestamp() ); } /*********************************************************************//** @@ -1267,34 +1267,35 @@ *************************************************************************/ static void broadcastTreatmentPeriodicData( void ) { - if ( ( treatmentPeriodDataBroadcastTimerCtr % TREATMENT_PERIODIC_DATA_LOG_INTERVAL ) == 0 ) + U32 const timeElapsedSinceLastCollect_ms = calcTimeBetween( lastTreatmentPeriodicDataCollectTimeStamp, treatmentTimeMS ); + + if ( timeElapsedSinceLastCollect_ms >= TREATMENT_PERIODIC_DATA_LOG_INTERVAL ) { - bloodFlowRateTotal += getMeasuredBloodFlowRate(); - dialysateFlowRateTotal += getMeasuredDialInFlowRate(); - ultraFiltrationRateTotal += getTotalMeasuredUFVolumeInMl() / getActualTreatmentTimeMins(); - arterialPressureTotal += getMeasuredArterialPressure(); - venousPressureTotal += getMeasuredVenousPressure(); + lastTreatmentPeriodicDataCollectTimeStamp = treatmentTimeMS; + bloodFlowRateTotal_mL_min += getMeasuredBloodFlowRate(); + dialysateFlowRateTotal_mL_min += getMeasuredDialInFlowRate(); + arterialPressureTotal_mmHg += getMeasuredArterialPressure(); + venousPressureTotal_mmHg += getMeasuredVenousPressure(); } - if ( ++treatmentPeriodDataBroadcastTimerCtr >= TREATMENT_PERIODIC_DATA_PUB_INTERVAL ) + if ( calcTimeBetween( lastTreatmentPeriodicDataPublishTimeStamp, treatmentTimeMS ) >= TREATMENT_PERIODIC_DATA_PUB_INTERVAL ) { - U32 const numberOfDataPoint = TREATMENT_PERIODIC_DATA_PUB_INTERVAL / TREATMENT_PERIODIC_DATA_LOG_INTERVAL; TREATMENT_LOG_DATA_PERIODIC_T periodTreatmentData; + U32 const numberOfDataPoint = TREATMENT_PERIODIC_DATA_PUB_INTERVAL / TREATMENT_PERIODIC_DATA_LOG_INTERVAL; - periodTreatmentData.timestamp = getRTCTimestamp(); - periodTreatmentData.avgBloodFlowRate += bloodFlowRateTotal / numberOfDataPoint; - periodTreatmentData.avgDialysateFlowRate += dialysateFlowRateTotal / numberOfDataPoint; - periodTreatmentData.avgUFRate += ultraFiltrationRateTotal / numberOfDataPoint; - periodTreatmentData.avgArterialPressure += arterialPressureTotal / numberOfDataPoint; - periodTreatmentData.avgVenousPressure += venousPressureTotal / numberOfDataPoint; + periodTreatmentData.avgUFRate = ( getUltrafiltrationVolumeCollected() - lastUltraFiltrationVolume_mL ) / ( numberOfDataPoint / SEC_PER_MIN ); + periodTreatmentData.avgBloodFlowRate = bloodFlowRateTotal_mL_min / numberOfDataPoint; + periodTreatmentData.avgDialysateFlowRate = dialysateFlowRateTotal_mL_min / numberOfDataPoint; + periodTreatmentData.avgArterialPressure = arterialPressureTotal_mmHg / numberOfDataPoint; + periodTreatmentData.avgVenousPressure = venousPressureTotal_mmHg / numberOfDataPoint; - treatmentPeriodDataBroadcastTimerCtr = 0; - bloodFlowRateTotal = 0.0; - dialysateFlowRateTotal = 0.0; - ultraFiltrationRateTotal = 0.0; - arterialPressureTotal = 0.0; - venousPressureTotal = 0.0; - sendTreatmentPeriodDataToUI( &periodTreatmentData ); + lastTreatmentPeriodicDataPublishTimeStamp = treatmentTimeMS; + lastUltraFiltrationVolume_mL = getUltrafiltrationVolumeCollected(); + bloodFlowRateTotal_mL_min = 0.0; + dialysateFlowRateTotal_mL_min = 0.0; + arterialPressureTotal_mmHg = 0.0; + venousPressureTotal_mmHg = 0.0; + sendTreatmentPeriodicDataToUI( &periodTreatmentData ); } }