Index: firmware/App/Modes/ModePreGenDialysate.c =================================================================== diff -u -rbd522c8ffdf75130571e5b6a79d1b1d6acd78b1c -re5c384741feb64828c1f4c32ff6daca07b20f46e --- firmware/App/Modes/ModePreGenDialysate.c (.../ModePreGenDialysate.c) (revision bd522c8ffdf75130571e5b6a79d1b1d6acd78b1c) +++ firmware/App/Modes/ModePreGenDialysate.c (.../ModePreGenDialysate.c) (revision e5c384741feb64828c1f4c32ff6daca07b20f46e) @@ -17,16 +17,21 @@ #include "BalancingChamber.h" #include "ConcentratePumps.h" +#include "Conductivity.h" #include "DialysatePumps.h" #include "DryBiCart.h" #include "Heaters.h" +#include "MixingControl.h" #include "ModePreGenDialysate.h" #include "ModeGenDialysate.h" #include "ModeFault.h" #include "Messaging.h" #include "OperationModes.h" +#include "PersistentAlarm.h" #include "Pressure.h" #include "TaskGeneral.h" +#include "TDInterface.h" +#include "TestSupport.h" #include "Timers.h" #include "Utilities.h" #include "Valves.h" @@ -42,6 +47,12 @@ #define PRE_GEN_DIALYSATE_DATA_PUB_INTERVAL ( 250 / TASK_GENERAL_INTERVAL ) ///< Interval (ms/task time) at which the pre-gen dialysate mode data published. #define HYD_CHAMBER_PRES_CHECK_TIME_OUT ( 30 * MS_PER_SECOND ) ///< Time out period when hydraulics chamber pressure check initiated #define NEG_PRES_PERSISTENCE_TIME_MS ( 1 * MS_PER_SECOND ) ///< Persistence time for Hydraulics chamber negative degassing pressure check. +#define PRE_GEN_CONDUCTIVITY_ALARM_ARM_MS ( 600 * MS_PER_SECOND ) ///< Arm conductivity alarms after this production runtime. +#define PRE_GEN_CONDUCTIVITY_SET_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Conductivity alarm set persistence timeout. +#define PRE_GEN_CONDUCTIVITY_CLEAR_TIMEOUT_MS ( 10 * MS_PER_SECOND ) ///< Conductivity alarm clear persistence timeout. +#define PRE_GEN_COND_TOL_RX_NOT_ENTERED_PCT 15.0F ///< Dial/acid conductivity tolerance before Rx entered. +#define PRE_GEN_COND_TOL_RX_ENTERED_PCT 5.0F ///< Dial/acid conductivity tolerance after Rx entered. +#define PRE_GEN_BICARB_COND_TOL_PCT 5.0F ///< Bicarb conductivity tolerance percent. // ********** private data ********** @@ -53,13 +64,15 @@ static BOOL pendingStopDDPreGenDialRequest; ///< Flag indicating TD has requested DD stop the pre generation dialysate. static U32 preGenDialysatePublishTimerCounter; ///< Pre-Gen Dialysate data broadcast timer counter used to schedule when to transmit data. static OVERRIDE_U32_T preGenDialysateModePublishInterval; ///< Interval (in task intervals) at which to publish pre-gen dialysate mode data to CAN bus. +static U32 preGenModeEntryTimeMS; ///< PreGen mode entry time for conductivity alarm arming (ms). // ********** private function prototypes ********** static void publishPreGenDialysateState( void ); static DD_PRE_GEN_DIALYSATE_STATE_T handlePreGenDialysateFillCompleteCheckState( void ); static DD_PRE_GEN_DIALYSATE_STATE_T handlePreGenWetSelfTestState( void ); static DD_PRE_GEN_DIALYSATE_STATE_T handleDryBicartInitialFillState( void ); +static void checkDialysateConductivity( void ); //Wet Self test static void setModePreGenWetSelfStateTransition( DD_WET_SELF_TEST_STATE_T state ); @@ -87,6 +100,15 @@ preGenDialysateModePublishInterval.ovData = PRE_GEN_DIALYSATE_DATA_PUB_INTERVAL; preGenDialysateModePublishInterval.ovInitData = 0; preGenDialysateModePublishInterval.override = OVERRIDE_RESET; + preGenModeEntryTimeMS = getMSTimerCount(); + + // Same conductivity persistent-alarm pattern as Gen Dialysate mode + initPersistentAlarm( ALARM_ID_DD_DIALYSATE_CONDUCTIVITY_LOW_DETECTED, PRE_GEN_CONDUCTIVITY_CLEAR_TIMEOUT_MS, PRE_GEN_CONDUCTIVITY_SET_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_DD_DIALYSATE_CONDUCTIVITY_HIGH_DETECTED, PRE_GEN_CONDUCTIVITY_CLEAR_TIMEOUT_MS, PRE_GEN_CONDUCTIVITY_SET_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_DD_ACID_CONCENTRATE_CONDUCTIVITY_LOW, PRE_GEN_CONDUCTIVITY_CLEAR_TIMEOUT_MS, PRE_GEN_CONDUCTIVITY_SET_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_DD_ACID_CONCENTRATE_CONDUCTIVITY_HIGH, PRE_GEN_CONDUCTIVITY_CLEAR_TIMEOUT_MS, PRE_GEN_CONDUCTIVITY_SET_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_DD_BICARBONATE_CONDUCTIVITY_LOW, PRE_GEN_CONDUCTIVITY_CLEAR_TIMEOUT_MS, PRE_GEN_CONDUCTIVITY_SET_TIMEOUT_MS ); + initPersistentAlarm( ALARM_ID_DD_BICARBONATE_CONDUCTIVITY_HIGH, PRE_GEN_CONDUCTIVITY_CLEAR_TIMEOUT_MS, PRE_GEN_CONDUCTIVITY_SET_TIMEOUT_MS ); } /*********************************************************************//** @@ -124,6 +146,9 @@ //Manage Inlet water control hydChamberWaterInletControl(); + // Same GenD-style conductivity checks (armed after 600 s in PreGen mode) + checkDialysateConductivity(); + //TODO: To be placed in correct states once states defined. if ( TRUE == pendingStartDDGenDialRequest ) { @@ -134,6 +159,7 @@ else if ( TRUE == pendingStopDDPreGenDialRequest ) { pendingStopDDPreGenDialRequest = FALSE; + requestBalChamberSwitching( FALSE ); requestNewOperationMode( DD_MODE_STAN ); } else @@ -154,7 +180,7 @@ break; case DD_PRE_GEN_DIALYSATE_WAIT_FOR_GEND: - // TODO : handle wait for Gen dialysate + // Wait for Dialin/TD Gen Dialysate start command break; default: @@ -293,6 +319,122 @@ /*********************************************************************//** * @brief + * The checkDialysateConductivity function checks dialysate, acid, and + * bicarbonate concentrate conductivity against theoretical values. + * Mirrors Gen Dialysate mode checking, with PreGen-specific arming and + * Rx-based dialysate/acid tolerances. + * @details \b Inputs: filtered conductivity sensor readings, theoretical values + * @details \b Outputs: none + * @details \b Alarms: ALARM_ID_DD_DIALYSATE_CONDUCTIVITY_LOW_DETECTED / + * HIGH_DETECTED, ALARM_ID_DD_ACID_CONCENTRATE_CONDUCTIVITY_LOW / HIGH, + * ALARM_ID_DD_BICARBONATE_CONDUCTIVITY_LOW / HIGH + * @return none + *************************************************************************/ +static void checkDialysateConductivity( void ) +{ + F32 measuredBicarbConductivity = getFilteredConductivity( D74_COND ); + F32 measuredDialysateConductivity = getFilteredConductivity( D29_COND ); + F32 measuredAcidConductivity = measuredDialysateConductivity - measuredBicarbConductivity; + F32 theoreticalBicarbConductivity = getBicarbConductivityPre(); + F32 theoreticalAcidConductivity = getAcidConducivityPost(); + F32 theoreticalDialysateConductivity = getTotalConductivity(); + F32 dialAcidTolerancePct = PRE_GEN_COND_TOL_RX_NOT_ENTERED_PCT; + F32 dialAcidPercentFactor = 0.0F; + F32 bicarbPercentFactor = ( PRE_GEN_BICARB_COND_TOL_PCT / 100.0F ); + F32 bicarbLowThreshold = 0.0F; + F32 bicarbHighThreshold = 0.0F; + F32 acidLowThreshold = 0.0F; + F32 acidHighThreshold = 0.0F; + F32 dialysateLowThreshold = 0.0F; + F32 dialysateHighThreshold = 0.0F; + BOOL isBicarbCondBelowTarget = FALSE; + BOOL isBicarbCondAboveTarget = FALSE; + BOOL isAcidCondBelowTarget = FALSE; + BOOL isAcidCondAboveTarget = FALSE; + BOOL isDialysateCondBelowTarget = FALSE; + BOOL isDialysateCondAboveTarget = FALSE; + BOOL alarmsArmed = FALSE; + + if ( TRUE == getTDRxEntered() ) + { + dialAcidTolerancePct = PRE_GEN_COND_TOL_RX_ENTERED_PCT; + } + + dialAcidPercentFactor = ( dialAcidTolerancePct / 100.0F ); + bicarbLowThreshold = theoreticalBicarbConductivity * ( 1.0F - bicarbPercentFactor ); + bicarbHighThreshold = theoreticalBicarbConductivity * ( 1.0F + bicarbPercentFactor ); + acidLowThreshold = theoreticalAcidConductivity * ( 1.0F - dialAcidPercentFactor ); + acidHighThreshold = theoreticalAcidConductivity * ( 1.0F + dialAcidPercentFactor ); + dialysateLowThreshold = theoreticalDialysateConductivity * ( 1.0F - dialAcidPercentFactor ); + dialysateHighThreshold = theoreticalDialysateConductivity * ( 1.0F + dialAcidPercentFactor ); + isBicarbCondBelowTarget = ( measuredBicarbConductivity < bicarbLowThreshold ? TRUE : FALSE ); + isBicarbCondAboveTarget = ( measuredBicarbConductivity > bicarbHighThreshold ? TRUE : FALSE ); + isAcidCondBelowTarget = ( measuredAcidConductivity < acidLowThreshold ? TRUE : FALSE ); + isAcidCondAboveTarget = ( measuredAcidConductivity > acidHighThreshold ? TRUE : FALSE ); + isDialysateCondBelowTarget = ( measuredDialysateConductivity < dialysateLowThreshold ? TRUE : FALSE ); + isDialysateCondAboveTarget = ( measuredDialysateConductivity > dialysateHighThreshold ? TRUE : FALSE ); + + // Arm after 600 sec in PreGen mode (GenD itself is started by Dialin/TD command) + if ( TRUE == didTimeout( preGenModeEntryTimeMS, PRE_GEN_CONDUCTIVITY_ALARM_ARM_MS ) ) + { + alarmsArmed = TRUE; + } + + if ( ( FALSE == alarmsArmed ) || + ( TRUE == getTestConfigStatus( TEST_CONFIG_DD_DISABLE_CONDUCTIVITY_ALARMS ) ) || + ( theoreticalBicarbConductivity <= 0.0F ) || + ( theoreticalAcidConductivity <= 0.0F ) || + ( theoreticalDialysateConductivity <= 0.0F ) ) + { + checkPersistentAlarm( ALARM_ID_DD_BICARBONATE_CONDUCTIVITY_LOW, FALSE, measuredBicarbConductivity, theoreticalBicarbConductivity ); + checkPersistentAlarm( ALARM_ID_DD_BICARBONATE_CONDUCTIVITY_HIGH, FALSE, measuredBicarbConductivity, theoreticalBicarbConductivity ); + checkPersistentAlarm( ALARM_ID_DD_ACID_CONCENTRATE_CONDUCTIVITY_LOW, FALSE, measuredAcidConductivity, theoreticalAcidConductivity ); + checkPersistentAlarm( ALARM_ID_DD_ACID_CONCENTRATE_CONDUCTIVITY_HIGH, FALSE, measuredAcidConductivity, theoreticalAcidConductivity ); + checkPersistentAlarm( ALARM_ID_DD_DIALYSATE_CONDUCTIVITY_LOW_DETECTED, FALSE, measuredDialysateConductivity, theoreticalDialysateConductivity ); + checkPersistentAlarm( ALARM_ID_DD_DIALYSATE_CONDUCTIVITY_HIGH_DETECTED, FALSE, measuredDialysateConductivity, theoreticalDialysateConductivity ); + } + else + { + if ( TRUE == isAlarmActive( ALARM_ID_DD_BICARBONATE_CONDUCTIVITY_LOW ) ) + { + isBicarbCondBelowTarget = ( measuredBicarbConductivity >= bicarbLowThreshold ? FALSE : TRUE ); + } + checkPersistentAlarm( ALARM_ID_DD_BICARBONATE_CONDUCTIVITY_LOW, isBicarbCondBelowTarget, measuredBicarbConductivity, theoreticalBicarbConductivity ); + + if ( TRUE == isAlarmActive( ALARM_ID_DD_BICARBONATE_CONDUCTIVITY_HIGH ) ) + { + isBicarbCondAboveTarget = ( measuredBicarbConductivity <= bicarbHighThreshold ? FALSE : TRUE ); + } + checkPersistentAlarm( ALARM_ID_DD_BICARBONATE_CONDUCTIVITY_HIGH, isBicarbCondAboveTarget, measuredBicarbConductivity, theoreticalBicarbConductivity ); + + if ( TRUE == isAlarmActive( ALARM_ID_DD_ACID_CONCENTRATE_CONDUCTIVITY_LOW ) ) + { + isAcidCondBelowTarget = ( measuredAcidConductivity >= acidLowThreshold ? FALSE : TRUE ); + } + checkPersistentAlarm( ALARM_ID_DD_ACID_CONCENTRATE_CONDUCTIVITY_LOW, isAcidCondBelowTarget, measuredAcidConductivity, theoreticalAcidConductivity ); + + if ( TRUE == isAlarmActive( ALARM_ID_DD_ACID_CONCENTRATE_CONDUCTIVITY_HIGH ) ) + { + isAcidCondAboveTarget = ( measuredAcidConductivity <= acidHighThreshold ? FALSE : TRUE ); + } + checkPersistentAlarm( ALARM_ID_DD_ACID_CONCENTRATE_CONDUCTIVITY_HIGH, isAcidCondAboveTarget, measuredAcidConductivity, theoreticalAcidConductivity ); + + if ( TRUE == isAlarmActive( ALARM_ID_DD_DIALYSATE_CONDUCTIVITY_LOW_DETECTED ) ) + { + isDialysateCondBelowTarget = ( measuredDialysateConductivity >= dialysateLowThreshold ? FALSE : TRUE ); + } + checkPersistentAlarm( ALARM_ID_DD_DIALYSATE_CONDUCTIVITY_LOW_DETECTED, isDialysateCondBelowTarget, measuredDialysateConductivity, theoreticalDialysateConductivity ); + + if ( TRUE == isAlarmActive( ALARM_ID_DD_DIALYSATE_CONDUCTIVITY_HIGH_DETECTED ) ) + { + isDialysateCondAboveTarget = ( measuredDialysateConductivity <= dialysateHighThreshold ? FALSE : TRUE ); + } + checkPersistentAlarm( ALARM_ID_DD_DIALYSATE_CONDUCTIVITY_HIGH_DETECTED, isDialysateCondAboveTarget, measuredDialysateConductivity, theoreticalDialysateConductivity ); + } +} + +/*********************************************************************//** + * @brief * The setModePreGenWetSelfStateTransition function sets the actuators and variables * for the state transition in pre-gen WetSlef test mode. * @details Inputs: Valve states, Pump speed