Index: firmware/App/Controllers/DGInterface.c =================================================================== diff -u -r44a100f8e5210a02c23b8fcc4527d8e96d577381 -r3d5431d5aebe0c88c38a8732455a6dcf004fe6c2 --- firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision 44a100f8e5210a02c23b8fcc4527d8e96d577381) +++ firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision 3d5431d5aebe0c88c38a8732455a6dcf004fe6c2) @@ -542,6 +542,18 @@ /*********************************************************************//** * @brief + * The getDialysateTemperature function gets the latest dialysate temperature. + * @details Inputs: dgDialysateTemp + * @details Outputs: none + * @return the current dialysate temperature + *************************************************************************/ +F32 getDialysateTemperature( void ) +{ + return dgDialysateTemp; +} + +/*********************************************************************//** + * @brief * The getReservoirWeight function gets the load cell weight of a given * reservoir. * @details Inputs: loadCellWeightInGrams[] Index: firmware/App/Controllers/DGInterface.h =================================================================== diff -u -r1240b612f790f931825aba86ec37f37eccce9336 -r3d5431d5aebe0c88c38a8732455a6dcf004fe6c2 --- firmware/App/Controllers/DGInterface.h (.../DGInterface.h) (revision 1240b612f790f931825aba86ec37f37eccce9336) +++ firmware/App/Controllers/DGInterface.h (.../DGInterface.h) (revision 3d5431d5aebe0c88c38a8732455a6dcf004fe6c2) @@ -133,6 +133,7 @@ F32 getLoadCellWeight( LOAD_CELL_ID_T loadCellID ); F32 getReservoirWeight( DG_RESERVOIR_ID_T resID ); F32 getReservoirWeightLargeFilter( DG_RESERVOIR_ID_T resID ); +F32 getDialysateTemperature( void ); void setDGOpMode( U32 opMode, U32 subMode ); void setDialysateTemperatureReadings( F32 temp1, F32 temp2 ); Index: firmware/App/Modes/ModePostTreat.c =================================================================== diff -u -rbd0ae373570f7f224bb9a6a4e86f805be77de192 -r3d5431d5aebe0c88c38a8732455a6dcf004fe6c2 --- firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision bd0ae373570f7f224bb9a6a4e86f805be77de192) +++ firmware/App/Modes/ModePostTreat.c (.../ModePostTreat.c) (revision 3d5431d5aebe0c88c38a8732455a6dcf004fe6c2) @@ -193,7 +193,6 @@ // Reset treatment log data memset( &treatmentLogData, 0x0, sizeof( TREATMENT_LOG_DATA_PAYLOAD_T ) ); - // TODO: Fill in missing log data treatmentLogData.bloodFlowRate_mL_min = getTreatmentParameterU32( TREATMENT_PARAM_BLOOD_FLOW ); treatmentLogData.dialysateFlowRate_mL_min = getTreatmentParameterU32( TREATMENT_PARAM_DIALYSATE_FLOW ); treatmentLogData.treatmentDuration_min = getTreatmentParameterU32( TREATMENT_PARAM_TREATMENT_DURATION ); @@ -204,11 +203,12 @@ treatmentLogData.dialysateTemperature_degC = getTreatmentParameterF32( TREATMENT_PARAM_DIALYSATE_TEMPERATURE ); treatmentLogData.dialyzerType = getTreatmentParameterU32( TREATMENT_PARAM_DIALYZER_TYPE ); + treatmentLogData.treatmentDateAndTime = getTreatmentStartTimeStamp(); -// treatmentLogData.avgBloodFlow_mL_min; -// treatmentLogData.avgDialysateFlow_mL_min; -// treatmentLogData.dialysateVolumeUsed_L; -// treatmentLogData.avgDialysateTemperature_degC; + treatmentLogData.avgBloodFlow_mL_min = getTreatmentAvgBloodFlowRate(); + treatmentLogData.avgDialysateFlow_mL_min = getTreatmentAvgDialysateFlowRate(); + treatmentLogData.dialysateVolumeUsed_L = treatmentLogData.actualTreatmentDur_min * treatmentLogData.avgDialysateFlow_mL_min; + treatmentLogData.avgDialysateTemperature_degC = getTreatmentAvgDialysateTemp(); if ( TRUE == isUFVolumeParamReceived() ) { 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 ); } } Index: firmware/App/Modes/ModeTreatment.h =================================================================== diff -u -r40e0116bbada6d1780bfa832a9c4684ba9fcfcc8 -r3d5431d5aebe0c88c38a8732455a6dcf004fe6c2 --- firmware/App/Modes/ModeTreatment.h (.../ModeTreatment.h) (revision 40e0116bbada6d1780bfa832a9c4684ba9fcfcc8) +++ firmware/App/Modes/ModeTreatment.h (.../ModeTreatment.h) (revision 3d5431d5aebe0c88c38a8732455a6dcf004fe6c2) @@ -111,6 +111,10 @@ void setRinsebackIsCompleted( BOOL flag ); // Set whether a rinseback has been completed (T blocks rinseback option) BOOL getBloodIsPrimed( void ); // Determine whether the blood-side circuit of the dialyzer has been primed with blood void setBloodIsPrimed( BOOL flag ); // Set whether the blood-side circuit of the dialyzer has been primed with blood (F causes Tx start/resume to do blood prime first) +F32 getTreatmentAvgBloodFlowRate( void ); // Get the treatment average blood flow rate during treatment +F32 getTreatmentAvgDialysateFlowRate( void ); // Get the treatment average dialysate flow rate during treatment +F32 getTreatmentAvgDialysateTemp( void ); // Get the treatment average dialysate temperature during treatment +U32 getTreatmentStartTimeStamp( void ); // Get the treatment start time stamp void broadcastTreatmentTimeAndState( void ); // Broadcast the times and states of this treatment