Index: firmware/App/Modes/ModeGenDialysate.c =================================================================== diff -u -r4cabd64c4ff295eb985f0a62132fef94c4e92921 -ra85a030e1a424b6546c57e5e80f21500103e13ea --- firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision 4cabd64c4ff295eb985f0a62132fef94c4e92921) +++ firmware/App/Modes/ModeGenDialysate.c (.../ModeGenDialysate.c) (revision a85a030e1a424b6546c57e5e80f21500103e13ea) @@ -26,6 +26,7 @@ #include "ModeGenDialysate.h" #include "ModeStandby.h" #include "OperationModes.h" +#include "PersistentAlarm.h" #include "Pressure.h" #include "TaskGeneral.h" #include "TDInterface.h" @@ -40,15 +41,23 @@ // ********** private definitions ********** -#define HYD_CHAMBER_FLUID_TEMP_C_MIN 35.0F ///< Minimum hydraulics fluid temperature in deg celcius -#define GEN_DIALYSATE_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the gen dialysate mode data published. +#define HYD_CHAMBER_FLUID_TEMP_C_MIN 35.0F ///< Minimum hydraulics fluid temperature in deg celcius +#define GEN_DIALYSATE_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the gen dialysate mode data published. +#define DIALYSATE_TEMP_OUT_OF_TARGET_CLEAR_TOL_C 2.0F ///< Dialysate temperature clear alarm tolerance C +#define DIALYSATE_TEMP_OUT_OF_TARGET_TOL_C 4.0F ///< Dialysate temperature out of target tolerance C. +#define DIALYSATE_TEMP_OUT_OF_TARGET_TIMEOUT_MS ( 90 * MS_PER_SECOND ) ///< Dialysate temperature out of target timeout in milliseconds. +#define DIALYSATE_TEMP_UPPER_MAX_SAFETY_LIMIT_C 46.0F ///< Dialysate upper bound maximum temperature limit in C. +#define DIALYSATE_TEMP_UPPER_MAX_SAFETY_TIMEOUT_MS ( 1 * MS_PER_SECOND ) ///< Dialysate temperature upper bound maximum safety timeout in milliseconds. +#define DIALYSATE_TEMP_UPPER_SAFETY_LIMIT_C 42.0F ///< Dialysate upper bound safety temperature limit in C. +#define DIALYSATE_TEMP_LOWER_SAFETY_LIMIT_C 33.0F ///< Dialysate lower bound safety temperature limit in C. +#define DIALYSATE_TEMP_CLEAR_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Dialysate temperature clear persistence timeout. //Testing -#define DELAY_BC_SWITCHING_AT_START_UP ( 3 * MS_PER_SECOND ) ///< Provide a balancing chamber switching start up delay to stabilize pump speed etc., +#define DELAY_BC_SWITCHING_AT_START_UP ( 3 * MS_PER_SECOND ) ///< Provide a balancing chamber switching start up delay to stabilize pump speed etc., /// Payload record structure for Gen dialysate execution state set request typedef struct { - U32 execStateSet; ///< Gen dialysate execution state machine set request + U32 execStateSet; ///< Gen dialysate execution state machine set request } GEND_EXEC_STATE_SET_CMD_PAYLOAD_T; // ********** private data ********** @@ -57,7 +66,7 @@ static OVERRIDE_F32_T targetHydChamberFluidTemp; ///< Target hydraulics chamber fluid temperature. static OVERRIDE_U32_T isDialDeliveryInProgress; ///< To indicate dialysate started delivering to dialyzer for treatment (overrideable) static OVERRIDE_U32_T isDialysateGoodtoDeliver; ///< Flag indicating whether ready to deliver dialysate or not. -static OVERRIDE_U32_T pendingStopDDGenDialRequest; ///< Flag indicating TD has requested DD stop the generate dialysate (Overridable). +static BOOL pendingStopDDGenDialRequest; ///< Flag indicating TD has requested DD stop the generate dialysate. static U32 genDialysateDataPublicationTimerCounter; ///< Used to schedule generate dialysate data publication to CAN bus. static OVERRIDE_U32_T genDialysateDataPublishInterval; ///< Generate dialysate mode data publish interval. static BOOL isTreatmentParamUpdated; ///< To indicate change in treatment parameters @@ -73,6 +82,7 @@ static DD_GEND_MODE_STATE_T handleGenDDialysateDeliveryPauseState( void ); static DD_GEND_MODE_STATE_T handleGenDDialysateIsolatedUFState( void ); static F32 getGenDialysateTargetTemperature( void ); +static void checkDialysateTemperature( void ); static void publishGenDialysateModeData( void ); /*********************************************************************//** @@ -97,10 +107,7 @@ isDialDeliveryInProgress.ovData = FALSE; isDialDeliveryInProgress.ovInitData = FALSE; isDialDeliveryInProgress.override = OVERRIDE_RESET; - pendingStopDDGenDialRequest.data = FALSE; - pendingStopDDGenDialRequest.ovData = FALSE; - pendingStopDDGenDialRequest.ovInitData = FALSE; - pendingStopDDGenDialRequest.override = OVERRIDE_RESET; + pendingStopDDGenDialRequest = FALSE; genDialysateDataPublishInterval.data = GEN_DIALYSATE_DATA_PUBLISH_INTERVAL; genDialysateDataPublishInterval.ovData = GEN_DIALYSATE_DATA_PUBLISH_INTERVAL; genDialysateDataPublishInterval.ovInitData = 0; @@ -113,6 +120,10 @@ //Initialize balancing chamber module initBalanceChamber(); + + initPersistentAlarm( ALARM_ID_DD_DIALYSATE_TEMP_ABOVE_TARGET_TEMP, DIALYSATE_TEMP_CLEAR_TIMEOUT_MS, DIALYSATE_TEMP_OUT_OF_TARGET_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_DD_DIALYSATE_TEMP_BELOW_TARGET_TEMP, DIALYSATE_TEMP_CLEAR_TIMEOUT_MS, DIALYSATE_TEMP_OUT_OF_TARGET_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_DD_DIALYSATE_TEMP_ABOVE_SAFETY_TEMP, DIALYSATE_TEMP_CLEAR_TIMEOUT_MS, DIALYSATE_TEMP_UPPER_MAX_SAFETY_TIMEOUT_MS ); } /*********************************************************************//** @@ -235,7 +246,7 @@ setValveState( D40_VALV, VALVE_STATE_CLOSED ); // VDO setValveState( D34_VALV, VALVE_STATE_OPEN ); // Bypass valve - //close the DD - water inlet and drain valves? + //TODO : close the DD - water inlet and drain valves? break; case DD_GEND_ISOLATED_UF_STATE: @@ -264,10 +275,13 @@ // Update any dynamic treatment parameter changes updateTreatmentSettings(); + //Check Dialysate Temperature + checkDialysateTemperature(); + //TODO: Transition to post gen dialysate then standby. - if ( TRUE == getU32OverrideValue( &pendingStopDDGenDialRequest ) ) + if ( TRUE == pendingStopDDGenDialRequest ) { - pendingStopDDGenDialRequest.data = FALSE; + pendingStopDDGenDialRequest = FALSE; requestNewOperationMode( DD_MODE_STAN ); } // Continuous water inlet pressure check @@ -449,7 +463,7 @@ if ( DD_MODE_GEND == getCurrentOperationMode() ) { - pendingStopDDGenDialRequest.data = TRUE; + pendingStopDDGenDialRequest = TRUE; status = TRUE; } @@ -591,6 +605,63 @@ /*********************************************************************//** * @brief + * The checkDialysateTemperature function checks the dialysate temperature + * against the target temperature and alarm if temperature is out of range. + * @details \b Inputs: targetTemp, dialysateTemp + * @details \b Outputs: none + * @details \b Alarms: ALARM_ID_DD_DIALYSATE_TEMP_ABOVE_SAFETY_TEMP when + * dialysate temp goes beyound high safety temperature limit + * @details \b Alarms: ALARM_ID_DD_DIALYSATE_TEMP_ABOVE_TARGET_TEMP when + * dialysate temp goes beyound high temperature limit + * @details \b Alarms: ALARM_ID_DD_DIALYSATE_TEMP_BELOW_TARGET_TEMP when + * dialysate temp goes beyound low temperature limit + * @return none + *************************************************************************/ +static void checkDialysateTemperature( void ) +{ + F32 dialysateTemp = getConductivityTemperatureValue( D29_COND ); // Assuming the closest temp sensor to dialyzer + F32 targetTemp = getTDTargetDialysateTemperature(); + BOOL isDialTempAboveHighSafety = ( dialysateTemp >= DIALYSATE_TEMP_UPPER_MAX_SAFETY_LIMIT_C ? TRUE : FALSE ); + BOOL isDialTempAboveLowSafety = ( dialysateTemp > DIALYSATE_TEMP_UPPER_SAFETY_LIMIT_C ? TRUE : FALSE ); + BOOL isDialTempBelowLowSafety = ( dialysateTemp < DIALYSATE_TEMP_LOWER_SAFETY_LIMIT_C ? TRUE : FALSE ); + F32 dialHigh = targetTemp + DIALYSATE_TEMP_OUT_OF_TARGET_TOL_C; + BOOL isDialTempAboveDialysateTarget = ( dialysateTemp > dialHigh ? TRUE : FALSE ); + F32 dialLow = targetTemp - DIALYSATE_TEMP_OUT_OF_TARGET_TOL_C; + BOOL isDialTempBelowDialysateTarget = ( dialysateTemp < dialLow ? TRUE : FALSE ); + BOOL isTempBelowTrigger = (BOOL)( isDialTempBelowLowSafety || isDialTempBelowDialysateTarget ); + BOOL isTempAboveTrigger = (BOOL)( isDialTempAboveLowSafety || isDialTempAboveDialysateTarget ); + + if ( DD_GEND_DIALYSATE_DELIVERY_STATE == genDialysateState ) + { + // check clear condition first + if ( TRUE == isAlarmActive( ALARM_ID_DD_DIALYSATE_TEMP_ABOVE_SAFETY_TEMP ) ) + { + isDialTempAboveHighSafety = ( dialysateTemp <= ( targetTemp + DIALYSATE_TEMP_OUT_OF_TARGET_CLEAR_TOL_C ) ? FALSE : TRUE ); + } + checkPersistentAlarm(ALARM_ID_DD_DIALYSATE_TEMP_ABOVE_SAFETY_TEMP, isDialTempAboveHighSafety, dialysateTemp, targetTemp ); + + if ( TRUE == isAlarmActive( ALARM_ID_DD_DIALYSATE_TEMP_ABOVE_TARGET_TEMP ) ) + { + isTempAboveTrigger = ( dialysateTemp <= ( targetTemp + DIALYSATE_TEMP_OUT_OF_TARGET_CLEAR_TOL_C ) ? FALSE : TRUE ); + } + checkPersistentAlarm(ALARM_ID_DD_DIALYSATE_TEMP_ABOVE_TARGET_TEMP, isTempAboveTrigger, dialysateTemp, targetTemp ); + + if ( TRUE == isAlarmActive( ALARM_ID_DD_DIALYSATE_TEMP_BELOW_TARGET_TEMP ) ) + { + isTempBelowTrigger = ( dialysateTemp >= ( targetTemp - DIALYSATE_TEMP_OUT_OF_TARGET_CLEAR_TOL_C ) ? FALSE : TRUE ); + } + checkPersistentAlarm(ALARM_ID_DD_DIALYSATE_TEMP_BELOW_TARGET_TEMP, isTempBelowTrigger, dialysateTemp, targetTemp ); + } + else + { + checkPersistentAlarm(ALARM_ID_DD_DIALYSATE_TEMP_ABOVE_SAFETY_TEMP, FALSE, dialysateTemp, targetTemp ); + checkPersistentAlarm(ALARM_ID_DD_DIALYSATE_TEMP_ABOVE_TARGET_TEMP, FALSE, dialysateTemp, targetTemp ); + checkPersistentAlarm(ALARM_ID_DD_DIALYSATE_TEMP_BELOW_TARGET_TEMP, FALSE, dialysateTemp, targetTemp ); + } +} + +/*********************************************************************//** + * @brief * The publishGenDialysateModeData function broadcasts the generate dialysate * mode data at defined interval. * @details \b Inputs: genDialysateDataPublicationTimerCounter @@ -697,23 +768,6 @@ /*********************************************************************//** * @brief - * The testDDStopGenDialysateOverride function sets the override value - * to stop the gen dialysate operation mode. - * @details Inputs: pendingStopDDGenDialRequest - * @details Outputs: pendingStopDDGenDialRequest - * @param message Override message from Dialin which includes the flag - * to override the operation mode. - * @return TRUE if override successful, FALSE if not - *************************************************************************/ -BOOL testDDStopGenDialysateOverride( MESSAGE_T *message ) -{ - BOOL result = u32Override( message, &pendingStopDDGenDialRequest, FALSE, TRUE ); - - return result; -} - -/*********************************************************************//** - * @brief * The testGenDExecStateOverride function sets the Gen dialysate execution state * machine to given state. * @details \b Inputs: tester logged in, execStateSet