Index: firmware/App/Controllers/DGInterface.c =================================================================== diff -u -ra69fcb7945b0300b47ce3287f8cb22c7c26171dc -r2a60f0eba906f0641e22a5d7f5c7ba1750911dcd --- firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision a69fcb7945b0300b47ce3287f8cb22c7c26171dc) +++ firmware/App/Controllers/DGInterface.c (.../DGInterface.c) (revision 2a60f0eba906f0641e22a5d7f5c7ba1750911dcd) @@ -23,6 +23,7 @@ #include "ModeTreatment.h" #include "ModeTreatmentParams.h" #include "OperationModes.h" +#include "PersistentAlarm.h" #include "SystemCommMessages.h" #include "Timers.h" @@ -33,15 +34,22 @@ // ********** private definitions ********** -#define START_DG_CMD TRUE ///< Parameter for DG start/stop command function. True = start. -#define STOP_DG_CMD FALSE ///< Parameter for DG start/stop command function. False = stop. +#define START_DG_CMD TRUE ///< Parameter for DG start/stop command function. True = start. +#define STOP_DG_CMD FALSE ///< Parameter for DG start/stop command function. False = stop. -#define RESERVOIR_SETTLE_TIME_MS 5000 ///< Time (in ms) allotted for reservoir to settle (after fill, before drain). +#define RESERVOIR_SETTLE_TIME_MS 5000 ///< Time (in ms) allotted for reservoir to settle (after fill, before drain). -#define MAX_RESERVOIR_VOLUME_ML 1950.0 ///< Maximum reservoir volume. Switch reservoirs if active reservoir exceeds this volume. +#define MAX_RESERVOIR_VOLUME_ML 1950.0 ///< Maximum reservoir volume. Switch reservoirs if active reservoir exceeds this volume. -#define SIZE_OF_LARGE_LOAD_CELL_AVG 32 ///< Large load cell moving average has 32 samples. +#define SIZE_OF_LARGE_LOAD_CELL_AVG 32 ///< Large load cell moving average has 32 samples. +#define DIALYSATE_TEMP_PERSISTENCE_PERIOD ( 3 * MS_PER_SECOND ) ///< Persistence period for dialysate temperature alarm. + +#define DIALYSATE_TEMP_RECOVERY_TOLERANCE_C 2.0 ///< Dialysate temperature recovery tolerance in degree C. +#define DIALYSATE_TEMP_TOLERANCE_C 4.0 ///< Dialysate temperature tolerance in degree C. +#define DIALYSATE_TEMP_HIGH_LIMIT_C 42.0 ///< Dialysate high temperature limit in degree C. +#define DIALYSATE_TEMP_LOW_LIMIT_C 33.0 ///< Dialysate low temperature limit in degree C. + /// States of the treatment reservoir management state machine. typedef enum TreatmentReservoirMgmt_States { @@ -161,6 +169,9 @@ lgLoadCellReadingsIdx = 0; lgLoadCellReadingsTotal[ DG_RESERVOIR_1 ] = 0.0; lgLoadCellReadingsTotal[ DG_RESERVOIR_2 ] = 0.0; + + initPersistentAlarm( ALARM_ID_DIALYSATE_TEMPERATURE_HIGH, DIALYSATE_TEMP_PERSISTENCE_PERIOD, DIALYSATE_TEMP_PERSISTENCE_PERIOD ); + initPersistentAlarm( ALARM_ID_DIALYSATE_TEMPERATURE_LOW, DIALYSATE_TEMP_PERSISTENCE_PERIOD, DIALYSATE_TEMP_PERSISTENCE_PERIOD ); } /*********************************************************************//** @@ -252,9 +263,9 @@ break; case TREATMENT_RESERVOIR_MGMT_FLUSH_DG_LINES_STATE: - if ( DG_MODE_CIRC == dgOpMode ) + if ( DG_MODE_GENE == dgOpMode ) { - if ( DG_RECIRCULATE_MODE_STATE_RECIRC_WATER == dgSubMode ) + if ( DG_GEN_IDLE_MODE_STATE_FLUSH_WATER == dgSubMode ) { cmdStartDGDrain( DRAIN_RESERVOIR_TO_VOLUME_ML, TRUE ); } @@ -270,7 +281,7 @@ break; case TREATMENT_RESERVOIR_MGMT_DRAIN_RESERVOIR_STATE: - if ( DG_MODE_CIRC == dgOpMode ) + if ( DG_MODE_GENE == dgOpMode ) { currentTrtResMgmtState = TREATMENT_RESERVOIR_MGMT_WAIT_TO_FILL_STATE; } @@ -280,9 +291,9 @@ // Delay fill start if we have paused treatment? if ( getTreatmentState() == TREATMENT_DIALYSIS_STATE ) { - if ( DG_MODE_CIRC == dgOpMode ) + if ( DG_MODE_GENE == dgOpMode ) { - if ( DG_RECIRCULATE_MODE_STATE_RECIRC_WATER == dgSubMode ) + if ( DG_GEN_IDLE_MODE_STATE_FLUSH_WATER == dgSubMode ) { U32 fillToVolume = FILL_RESERVOIR_TO_VOLUME_ML; @@ -305,7 +316,7 @@ break; case TREATMENT_RESERVOIR_MGMT_FILL_RESERVOIR_STATE: - if ( ( DG_MODE_CIRC == dgOpMode ) && ( DG_RECIRCULATE_MODE_STATE_RECIRC_WATER == getDGSubMode() ) ) + if ( ( DG_MODE_GENE == dgOpMode ) && ( DG_GEN_IDLE_MODE_STATE_FLUSH_WATER == getDGSubMode() ) ) { resMgmtTimer = getMSTimerCount(); currentTrtResMgmtState = TREATMENT_RESERVOIR_MGMT_WAIT_FOR_FILL_SETTLE_STATE; @@ -1113,6 +1124,47 @@ /*********************************************************************//** * @brief + * The checkDialysateTemperature function checks the dialysate temperature + * reported by DG and alarm if temperature is out of range. + * @details Inputs: dgTrimmerTempSet, dgDialysateTemp, dgRedundantDialysateTemp + * @details Outputs: alarm if dialysate temperature is out of accepted range + * @return none + *************************************************************************/ +void checkDialysateTemperature( void ) +{ + BOOL const dialysateHighTemp = ( ( ( dgDialysateTemp - dgTrimmerTempSet ) > DIALYSATE_TEMP_TOLERANCE_C ) || + ( dgDialysateTemp > DIALYSATE_TEMP_HIGH_LIMIT_C ) ); + + BOOL const dialysateLowTemp = ( ( ( dgTrimmerTempSet - dgDialysateTemp ) > DIALYSATE_TEMP_TOLERANCE_C ) || + ( dgDialysateTemp < DIALYSATE_TEMP_LOW_LIMIT_C ) ); + + BOOL const dialysateTempRecovered = fabs( dgDialysateTemp - dgTrimmerTempSet ) < DIALYSATE_TEMP_RECOVERY_TOLERANCE_C ? TRUE : FALSE; + +#ifndef DISABLE_DIALYSATE_TEMP_CHECK + if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_DIALYSATE_TEMPERATURE_HIGH, dialysateHighTemp ) ) + { + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DIALYSATE_TEMPERATURE_HIGH, dgTrimmerTempSet, dgDialysateTemp ); + } + + if ( TRUE == isPersistentAlarmTriggered( ALARM_ID_DIALYSATE_TEMPERATURE_LOW, dialysateLowTemp ) ) + { + SET_ALARM_WITH_2_F32_DATA( ALARM_ID_DIALYSATE_TEMPERATURE_LOW, dgTrimmerTempSet, dgDialysateTemp ); + } + + if ( TRUE == isPersistentAlarmConditionCleared( ALARM_ID_DIALYSATE_TEMPERATURE_HIGH, dialysateHighTemp ) ) + { + clearAlarmCondition( ALARM_ID_DIALYSATE_TEMPERATURE_HIGH ); + } + + if ( TRUE == isPersistentAlarmConditionCleared( ALARM_ID_DIALYSATE_TEMPERATURE_LOW, dialysateTempRecovered ) ) + { + clearAlarmCondition( ALARM_ID_DIALYSATE_TEMPERATURE_LOW ); + } +#endif +} + +/*********************************************************************//** + * @brief * The checkDGRestart function checks to see if DG has restarted after started * by HD and triggers appropriate alarm. * @details Inputs: dgStarted @@ -1121,15 +1173,15 @@ *************************************************************************/ static void checkDGRestart( void ) { - if ( ( dgStartCommandSent == TRUE ) && ( DG_MODE_CIRC == dgCurrentOpMode ) ) + if ( ( dgStartCommandSent == TRUE ) && ( DG_MODE_GENE == dgCurrentOpMode ) ) { dgStartCommandSent = FALSE; dgStarted = TRUE; } if ( TRUE == dgStarted ) { - if ( ( DG_MODE_FAUL != dgCurrentOpMode ) && ( DG_MODE_CIRC != dgCurrentOpMode ) && + if ( ( DG_MODE_FAUL != dgCurrentOpMode ) && ( DG_MODE_GENE != dgCurrentOpMode ) && ( DG_MODE_FILL != dgCurrentOpMode ) && ( DG_MODE_DRAI != dgCurrentOpMode ) ) { activateAlarmNoData( ALARM_ID_DG_RESTARTED_FAULT );