Index: firmware/App/Modes/ModeTreatment.c =================================================================== diff -u -r8e08352e9e7d8749d8f093c6bc57e6dbc32605d5 -r3d5431d5aebe0c88c38a8732455a6dcf004fe6c2 --- firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision 8e08352e9e7d8749d8f093c6bc57e6dbc32605d5) +++ firmware/App/Modes/ModeTreatment.c (.../ModeTreatment.c) (revision 3d5431d5aebe0c88c38a8732455a6dcf004fe6c2) @@ -61,9 +61,9 @@ static const U32 TREATMENT_STATE_DATA_PUB_INTERVAL = ( 250 / TASK_GENERAL_INTERVAL ); /// 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. +/// Interval (ms) 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 ); -/// Interval (ms/task time) at which the treatment periodic data is logged. +/// Interval (ms) at which the treatment periodic data is logged. 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. @@ -109,11 +109,18 @@ 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. +static F32 bloodFlowRateSum_mL_min; ///< Blood flow rate sum logged every second. +static F32 dialysateFlowRateSum_mL_min; ///< Dialysate flow rate sum logged every second. +static F32 arterialPressureSum_mmHg; ///< Arterial pressure sum logged every second. +static F32 venousPressureSum_mmHg; ///< Venous pressure sum logged every second. +static F32 treatmentBloodFlowRateTotal_mL_min; ///< Blood flow rate total per treatment logged every second. +static F32 treatmentDialysateFlowRateTotal_mL_min; ///< Dialysate flow rate total per treatment logged every second. +static F32 treatmentDialysateTempTotal_degree_C; ///< Dialysate temperature total per treatment logged every second. +static BOOL sendLastTreatmentPeriodicData; ///< Flag determines if HD needs to send the last treatment periodic data. + +static U32 treatmentStartTimeStamp; ///< Treatment start timestampt for logging purpose. + // ********** private function prototypes ********** static void resetSignalFlags( void ); @@ -166,10 +173,16 @@ 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; + bloodFlowRateSum_mL_min = 0.0; + dialysateFlowRateSum_mL_min = 0.0; + arterialPressureSum_mmHg = 0.0; + venousPressureSum_mmHg = 0.0; + treatmentBloodFlowRateTotal_mL_min = 0.0; + treatmentDialysateFlowRateTotal_mL_min = 0.0; + treatmentDialysateTempTotal_degree_C = 0.0; + sendLastTreatmentPeriodicData = FALSE; + + treatmentStartTimeStamp = getRTCTimestamp(); } /*********************************************************************//** @@ -336,6 +349,64 @@ /*********************************************************************//** * @brief + * The getTreatmentAvgBloodFlowRate function returns the average blood flow + * rate collected through out the treatment. + * @details Inputs: treatmentTimeMS, treatmentBloodFlowRateTotal_mL_min + * @details Outputs: none + * @return the average blood flow rate + *************************************************************************/ +F32 getTreatmentAvgBloodFlowRate( void ) +{ + U32 const numberOfDataPoint = ( treatmentTimeMS / TREATMENT_PERIODIC_DATA_LOG_INTERVAL ); + + return ( treatmentBloodFlowRateTotal_mL_min / numberOfDataPoint ); +} + +/*********************************************************************//** + * @brief + * The getTreatmentAvgDialysateFlowRate function returns the average dialysate + * flow rate collected through out the treatment. + * @details Inputs: treatmentTimeMS, treatmentDialysateFlowRateTotal_mL_min + * @details Outputs: none + * @return the average dialysate flow rate + *************************************************************************/ +F32 getTreatmentAvgDialysateFlowRate( void ) +{ + U32 const numberOfDataPoint = ( treatmentTimeMS / TREATMENT_PERIODIC_DATA_LOG_INTERVAL ); + + return ( treatmentDialysateFlowRateTotal_mL_min / numberOfDataPoint ); +} + +/*********************************************************************//** + * @brief + * The getTreatmentAvgDialysateTemp function returns the average dialysate + * temperature collected through out the treatment. + * @details Inputs: treatmentTimeMS, treatmentDialysateTempTotal_degree_C + * @details Outputs: none + * @return the average dialysate temperature + *************************************************************************/ +F32 getTreatmentAvgDialysateTemp( void ) +{ + U32 const numberOfDataPoint = ( treatmentTimeMS / TREATMENT_PERIODIC_DATA_LOG_INTERVAL ); + + return ( treatmentDialysateTempTotal_degree_C / numberOfDataPoint ); +} + +/*********************************************************************//** + * @brief + * The getTreatmentStartTimeStamp function returns the treatment start + * time stamp. + * @details Inputs: treatmentStartTimeStamp + * @details Outputs: none + * @return the treatment start time stamp + *************************************************************************/ +U32 getTreatmentStartTimeStamp( void ) +{ + return treatmentStartTimeStamp; +} + +/*********************************************************************//** + * @brief * The signalAlarmActionToTreatmentMode function executes the given alarm action * as appropriate while in Treatment Mode. * @details Inputs: none @@ -598,6 +669,7 @@ if ( CALC_ELAPSED_TREAT_TIME_IN_SECS() >= presTreatmentTimeSecs ) { treatmentCompleted = TRUE; + sendLastTreatmentPeriodicData = TRUE; stopDialysis(); transitionToTreatmentEnd(); SET_ALARM_WITH_1_U32_DATA( ALARM_ID_END_OF_TREATMENT_WARNING, presTreatmentTimeSecs ); @@ -658,6 +730,7 @@ // If user requests treatment end, end treatment else if ( TRUE == endTreatmentAlarmResponseRequest ) { + sendLastTreatmentPeriodicData = TRUE; requestNewOperationMode( MODE_POST ); } // Otherwise execute state machine for treatment stop sub-mode @@ -1280,33 +1353,39 @@ static void broadcastTreatmentPeriodicData( void ) { U32 const timeElapsedSinceLastCollect_ms = calcTimeBetween( lastTreatmentPeriodicDataCollectTimeStamp, treatmentTimeMS ); + U32 const timeElapsedSinceLastPublish_ms = calcTimeBetween( lastTreatmentPeriodicDataPublishTimeStamp, treatmentTimeMS ); if ( timeElapsedSinceLastCollect_ms >= TREATMENT_PERIODIC_DATA_LOG_INTERVAL ) { lastTreatmentPeriodicDataCollectTimeStamp = treatmentTimeMS; - bloodFlowRateTotal_mL_min += getMeasuredBloodFlowRate(); - dialysateFlowRateTotal_mL_min += getMeasuredDialInFlowRate(); - arterialPressureTotal_mmHg += getMeasuredArterialPressure(); - venousPressureTotal_mmHg += getMeasuredVenousPressure(); + bloodFlowRateSum_mL_min += getMeasuredBloodFlowRate(); + dialysateFlowRateSum_mL_min += getMeasuredDialInFlowRate(); + arterialPressureSum_mmHg += getMeasuredArterialPressure(); + venousPressureSum_mmHg += getMeasuredVenousPressure(); + + treatmentBloodFlowRateTotal_mL_min += getMeasuredBloodFlowRate(); + treatmentDialysateFlowRateTotal_mL_min += getMeasuredDialInFlowRate(); + treatmentDialysateTempTotal_degree_C += getDialysateTemperature(); } - if ( calcTimeBetween( lastTreatmentPeriodicDataPublishTimeStamp, treatmentTimeMS ) >= TREATMENT_PERIODIC_DATA_PUB_INTERVAL ) + if ( ( timeElapsedSinceLastPublish_ms >= TREATMENT_PERIODIC_DATA_PUB_INTERVAL ) || ( TRUE == sendLastTreatmentPeriodicData ) ) { TREATMENT_LOG_DATA_PERIODIC_T periodTreatmentData; - U32 const numberOfDataPoint = TREATMENT_PERIODIC_DATA_PUB_INTERVAL / TREATMENT_PERIODIC_DATA_LOG_INTERVAL; + U32 const numberOfDataPoint = timeElapsedSinceLastPublish_ms / TREATMENT_PERIODIC_DATA_LOG_INTERVAL; 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; + periodTreatmentData.avgBloodFlowRate = bloodFlowRateSum_mL_min / numberOfDataPoint; + periodTreatmentData.avgDialysateFlowRate = dialysateFlowRateSum_mL_min / numberOfDataPoint; + periodTreatmentData.avgArterialPressure = arterialPressureSum_mmHg / numberOfDataPoint; + periodTreatmentData.avgVenousPressure = venousPressureSum_mmHg / numberOfDataPoint; + sendLastTreatmentPeriodicData = FALSE; lastTreatmentPeriodicDataPublishTimeStamp = treatmentTimeMS; lastUltraFiltrationVolume_mL = getUltrafiltrationVolumeCollected(); - bloodFlowRateTotal_mL_min = 0.0; - dialysateFlowRateTotal_mL_min = 0.0; - arterialPressureTotal_mmHg = 0.0; - venousPressureTotal_mmHg = 0.0; + bloodFlowRateSum_mL_min = 0.0; + dialysateFlowRateSum_mL_min = 0.0; + arterialPressureSum_mmHg = 0.0; + venousPressureSum_mmHg = 0.0; sendTreatmentPeriodicDataToUI( &periodTreatmentData ); } }