Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -ra14bc308c72272ce0275d263cf010c90d8a37355 -r322747d530c1b8205be257557e53dcfe9caad50a --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision a14bc308c72272ce0275d263cf010c90d8a37355) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 322747d530c1b8205be257557e53dcfe9caad50a) @@ -15,18 +15,17 @@ * ***************************************************************************/ -//#include "ConcentratePumps.h" -//#include "ConductivitySensors.h" -//#include "Heaters.h" +#include "BalancingChamber.h" +#include "ConcentratePumps.h" +#include "ConductivitySensors.h" +#include "Heaters.h" #include "ModeFault.h" -//#include "ModeHeatDisinfect.h" #include "ModeStandby.h" #include "MessageSupport.h" #include "Messaging.h" //#include "NVDataMgmt.h" #include "OperationModes.h" -//#include "Pressures.h" -//#include "ROPump.h" +#include "Pressure.h" #include "SystemCommDD.h" #include "TaskGeneral.h" //#include "Timers.h" @@ -39,39 +38,21 @@ // ********** private definitions ********** -#define FILTER_FLUSH_TIME_MS ( 120 * MS_PER_SECOND ) ///< Duration of filter flush state (in ms). -#define MAX_WATER_SAMPLE_TIME_MS ( 10 * MS_PER_SECOND ) ///< Maximum duration of water sample state (in ms). -#define FLUSH_EXPIRATION_TIME_MS ( 10 * SEC_PER_MIN * MS_PER_SECOND ) ///< Duration in which a filter flush is valid (in ms). -#define FILTER_FLUSH_DATA_PUBLISH_INTERVAL ( MS_PER_SECOND / TASK_GENERAL_INTERVAL ) ///< Filter flush data broadcast interval. // ********** private data ********** static DD_STANDBY_MODE_STATE_T standbyState; ///< Currently active standby state. -//static BOOL stopSampleWaterRequest; ///< Flag indicating TD has requested to stop sample water -//static BOOL startSampleWaterRequest; ///< Flag indicating TD has requested to start sample water -//static BOOL flushFilterRequest; ///< Flag indicating TD has requested to flush filters -//static BOOL endSampleWaterRequest; ///< Flag indicating TD has requested to end sample water -//static BOOL pendingStartDDRequest; ///< Flag indicating TD has requested DD start (go to generation idle mode). -//static U32 waterSampleStartTime; ///< Time stamp for start of water sample state. -//static U32 filterFlushStartTime; ///< Time stamp for start of filter flush state. -//static U32 filterFlushPublishTimerCounter; ///< Filter flush data publish timer counter. +static OVERRIDE_U32_T pendingStartDDRequest; ///< Flag indicating TD has requested DD start the dialysis delivery(Overridable). +static BOOL pendingBalanceChamberSwOnlyRequest; ///< Flag indicating balancing chamber switch only request. //static BOOL pendingStartDDFlushRequest; ///< Flag indicating TD has requested DD start flush. //static BOOL pendingStartDDHeatDisinfectRequest; ///< Flag indicating TD has requested DD start heat disinfect. //static BOOL pendingStartDDHeatDisinfectActiveCoolRequest; ///< Flag indicating TD has requested DD start heat disinfect active cool. -//static BOOL pendingStartDDROPermeateSampleRequest; ///< Flag indicating TD has requested DD start RO permeate sample. +//static BOOL pendingStartDGROPermeateSampleRequest; ///< Flag indicating TD has requested DD to command RO to start permeate sample. -static OVERRIDE_U32_T filterFlushTimePeriod = { FILTER_FLUSH_TIME_MS, - FILTER_FLUSH_TIME_MS, 0, 0 }; ///< Filter flush time period in ms. - // ********** private function prototypes ********** -static BOOL areInletWaterConditionsAlarmsActive( void ); - static DD_STANDBY_MODE_STATE_T handleStandbyIdleState( void ); -static DD_STANDBY_MODE_STATE_T handleStandbyFlushFilterState( void ); -static DD_STANDBY_MODE_STATE_T handleStandbyFlushFilterIdleState( void ); -static DD_STANDBY_MODE_STATE_T handleStandbySampleWaterState( void ); static DD_STANDBY_MODE_STATE_T handleStandbyPauseState( void ); /*********************************************************************//** @@ -84,21 +65,15 @@ void initStandbyMode( void ) { standbyState = DD_STANDBY_MODE_STATE_IDLE; -// stopSampleWaterRequest = FALSE; -// startSampleWaterRequest = FALSE; -// flushFilterRequest = FALSE; -// endSampleWaterRequest = FALSE; -// waterSampleStartTime = 0; -// filterFlushStartTime = 0; -// filterFlushPublishTimerCounter = 0; -// pendingStartDDRequest = FALSE; + pendingStartDDRequest.data = FALSE; + pendingStartDDRequest.ovData = FALSE; + pendingStartDDRequest.ovInitData = FALSE; + pendingStartDDRequest.override = OVERRIDE_RESET; + pendingBalanceChamberSwOnlyRequest = FALSE; // pendingStartDDFlushRequest = FALSE; // pendingStartDDHeatDisinfectRequest = FALSE; // pendingStartDDHeatDisinfectActiveCoolRequest = FALSE; // pendingStartDDROPermeateSampleRequest = FALSE; - - // Reset the heaters efficiency for another treatment - //resetHeatersEstimationGain(); } /*********************************************************************//** @@ -116,18 +91,13 @@ // re-initialize standby mode each time we transition to standby mode initStandbyMode(); -// deenergizeActuators( PARK_CONC_PUMPS ); -// -// + deenergizeActuators( PARK_CONC_PUMPS ); + // // Upon transition to mode standby set CD1 and CD2 calibration records to be picked to the normal // // table. If the chemical disinfect fails, the mode transitions back to mode standby. -// setCondcutivitySensorCalTable( CONDUCTIVITYSENSORS_CD1_SENSOR, CAL_DATA_CD1_COND_SENSOR ); -// setCondcutivitySensorCalTable( CONDUCTIVITYSENSORS_CD2_SENSOR, CAL_DATA_CD2_COND_SENSOR ); +// setCondcutivitySensorCalTable( D17_COND, CAL_DATA_CD1_COND_SENSOR ); +// setCondcutivitySensorCalTable( D27_COND, CAL_DATA_CD2_COND_SENSOR ); // -//#ifndef _RELEASE_ -// setHeatNelsonSupportMode( NELSON_NONE ); -// setChemNelsonSupportMode( NELSON_NONE ); -//#endif // // Send DD usage data to TD // The message ID will not be put here because the messages list script will pick this up for another send command @@ -151,7 +121,6 @@ { if ( TRUE == areInletWaterConditionsAlarmsActive() ) { - //setValveState( VSP, VALVE_STATE_CLOSED ); standbyState = DD_STANDBY_MODE_STATE_PAUSE; } @@ -162,18 +131,6 @@ standbyState = handleStandbyIdleState(); break; - case DD_STANDBY_MODE_STATE_FLUSH_FILTER: - standbyState = handleStandbyFlushFilterState(); - break; - - case DD_STANDBY_MODE_STATE_FLUSH_FILTER_IDLE: - standbyState = handleStandbyFlushFilterIdleState(); - break; - - case DD_STANDBY_MODE_STATE_SAMPLE_WATER: - standbyState = handleStandbySampleWaterState(); - break; - case DD_STANDBY_MODE_STATE_PAUSE: standbyState = handleStandbyPauseState(); break; @@ -190,27 +147,24 @@ /*********************************************************************//** * @brief * The areInletWaterConditionsAlarmsActive function checks whether the inlet - * water conditions are out of range and any of their alarms are active. - * @details \b Inputs: none + * water pressure conditions are out of range and any of their alarms are active. + * @details \b Inputs: Input and Output pressure of water inlet pressur regulator. * @details \b Outputs: None * @return TRUE if any of the alarms are active, otherwise, FALSE *************************************************************************/ -static BOOL areInletWaterConditionsAlarmsActive( void ) +BOOL areInletWaterConditionsAlarmsActive( void ) { - // Check inlet water conductivity, temperature, pressure, and RO rejection ratio BOOL status = FALSE; -// checkInletWaterConductivity(); -// checkInletWaterTemperature(); -// checkInletWaterPressure(); + //TODO: testing - Comment water pressure check + // Check Inlet Water Pressure - both Water inlet pressure Input, pressure Output after pressure regulator. + // checkInletWaterPressure(); -// status |= isAlarmConditionActive( ALARM_ID_DD_INLET_WATER_CONDUCTIVITY_IN_LOW_RANGE ); -// status |= isAlarmConditionActive( ALARM_ID_DD_INLET_WATER_CONDUCTIVITY_IN_HIGH_RANGE ); -// status |= isAlarmConditionActive( ALARM_ID_DD_INLET_WATER_TEMPERATURE_IN_HIGH_RANGE ); -// status |= isAlarmConditionActive( ALARM_ID_DD_INLET_WATER_TEMPERATURE_IN_LOW_RANGE ); -// status |= isAlarmConditionActive( ALARM_ID_DD_OUTLET_PRIMARY_CONDUCTIVITY_OUT_OF_RANGE ); -// status |= isAlarmConditionActive( ALARM_ID_DD_INLET_WATER_PRESSURE_IN_HIGH_RANGE ); -// status |= isAlarmConditionActive( ALARM_ID_DD_INLET_WATER_PRESSURE_IN_LOW_RANGE ); + // Check any active alarms + status |= isAlarmActive( ALARM_ID_DD_INLET_WATER_PRESSURE_OUT_LOW_RANGE ); + status |= isAlarmActive( ALARM_ID_DD_INLET_WATER_PRESSURE_OUT_HIGH_RANGE ); + status |= isAlarmActive( ALARM_ID_DD_INLET_WATER_PRESSURE_IN_HIGH_RANGE ); + status |= isAlarmActive( ALARM_ID_DD_INLET_WATER_PRESSURE_IN_LOW_RANGE ); return status; } @@ -225,31 +179,29 @@ * @details \b Outputs: Idle state of the standby mode executed, * pendingStartDDFlushRequest, pendingStartDDHeatDisinfectRequest, * pendingStartDDChemicalDisinfectRequest + * @details \b Message \Sent: DD_EVENT_TD_COMMUNICATION_LOSS ( Evend Id:8 ) + * updates TD communication loss. * @return the next state *************************************************************************/ static DD_STANDBY_MODE_STATE_T handleStandbyIdleState( void ) { DD_STANDBY_MODE_STATE_T state = DD_STANDBY_MODE_STATE_IDLE; - // go to standby solo mode if TD is turned off or stops communicating. - if ( FALSE == isTDCommunicating() ) - { // TODO if TD comm loss, should we wait an hour or so before going to solo standby? - //requestNewOperationMode( DD_MODE_SOLO ); - } - // if TD requests water sample, go to water sample state -// else if ( TRUE == flushFilterRequest ) + //TODO : Define comm loss alarm when TD is turned off or stops communicating +// if ( FALSE == isTDCommunicating() ) // { -// setValveState( VPI, VALVE_STATE_OPEN ); -// flushFilterRequest = FALSE; -// filterFlushStartTime = getMSTimerCount(); -// state = DD_STANDBY_MODE_STATE_FLUSH_FILTER; + // define the alarm // } -// else if ( TRUE == pendingStartDDRequest ) -// { -// pendingStartDDRequest = FALSE; -// signalSyncToHD(); -// requestNewOperationMode( DD_MODE_GENE ); -// } + if ( TRUE == getU32OverrideValue( &pendingStartDDRequest ) ) + { + pendingStartDDRequest.data = FALSE; + requestNewOperationMode( DD_MODE_GEND ); + } + //Test request to handle only balancing chamber switching + else if ( TRUE == pendingBalanceChamberSwOnlyRequest ) + { + execBalancingChamberControl(); + } // else if ( TRUE == pendingStartDDFlushRequest ) // { // pendingStartDDFlushRequest = FALSE; @@ -277,126 +229,28 @@ /*********************************************************************//** * @brief - * The handleStandbyFilterFlushState function executes the flush filter state - * of the standby mode state machine. - * @details \b Inputs: filterFLushStartTime - * @details \b Outputs: Flushed the filters + * The handleStandbyPauseState function executes the standby pause state. + * @details \b Inputs: Water inlet pressure alarms + * @details \b Outputs: state * @return the next state *************************************************************************/ -static DD_STANDBY_MODE_STATE_T handleStandbyFlushFilterState( void ) -{ - DD_STANDBY_MODE_STATE_T state = DD_STANDBY_MODE_STATE_FLUSH_FILTER; -// U32 filterFlushTimePeriod_ms = getU32OverrideValue( &filterFlushTimePeriod ); -// -// if ( TRUE == didTimeout( filterFlushStartTime, filterFlushTimePeriod_ms ) ) -// { -// setValveState( VPI, VALVE_STATE_CLOSED ); -// state = DD_STANDBY_MODE_STATE_FLUSH_FILTER_IDLE; -// } -// -// if ( ++filterFlushPublishTimerCounter >= FILTER_FLUSH_DATA_PUBLISH_INTERVAL ) -// { -// STANDBY_MODE_DATA_T data; -// -// data.timeout = filterFlushTimePeriod_ms / MS_PER_SECOND; -// data.countdown = data.timeout - ( calcTimeSince( filterFlushStartTime ) / MS_PER_SECOND ); -// filterFlushPublishTimerCounter = 0; -// -// broadcastData( MSG_ID_DD_FILTER_FLUSH_PROGRESS_DATA, COMM_BUFFER_OUT_CAN_DD_BROADCAST, (U08*)&data, sizeof( STANDBY_MODE_DATA_T ) ); -// } -// -// if ( TRUE == endSampleWaterRequest ) -// { -// endSampleWaterRequest = FALSE; -// setValveState( VPI, VALVE_STATE_CLOSED ); -// state = DD_STANDBY_MODE_STATE_IDLE; -// } - - return state; -} - -/*********************************************************************//** - * @brief - * The handleStandbyFlushFilterIdleState function executes the flush filter - * idle state of the standby mode state machine. - * @details \b Inputs: filterFLushStartTime, startSampleWaterRequest, endSampleWaterRequest - * @details \b Outputs: Flushed the filters, startSampleWaterRequest, endSampleWaterRequest, - * waterSampleStartTime - * @return the next state - *************************************************************************/ -static DD_STANDBY_MODE_STATE_T handleStandbyFlushFilterIdleState( void ) -{ - DD_STANDBY_MODE_STATE_T state = DD_STANDBY_MODE_STATE_FLUSH_FILTER_IDLE; - -// if ( TRUE == startSampleWaterRequest ) -// { -// waterSampleStartTime = getMSTimerCount(); -// setValveState( VPI, VALVE_STATE_OPEN ); -// setValveState( VSP, VALVE_STATE_OPEN ); -// state = DD_STANDBY_MODE_STATE_SAMPLE_WATER; -// } -// -// if ( TRUE == endSampleWaterRequest ) -// { -// endSampleWaterRequest = FALSE; -// setValveState( VPI, VALVE_STATE_CLOSED ); -// state = DD_STANDBY_MODE_STATE_IDLE; -// } -// -// startSampleWaterRequest = FALSE; - - return state; -} - -/*********************************************************************//** - * @brief - * The handleStandbySampleWaterState function executes the sample water state - * of the standby mode state machine. - * @details \b Inputs: stopSampleWaterRequest, waterSampleStartTime - * @details \b Outputs: Finished sample water and closed valve - * @return the next state - *************************************************************************/ -static DD_STANDBY_MODE_STATE_T handleStandbySampleWaterState( void ) -{ - DD_STANDBY_MODE_STATE_T state = DD_STANDBY_MODE_STATE_SAMPLE_WATER; - -// // After TD requests to stop or 10 seconds has elapsed, close and return to idle state -// if ( ( TRUE == stopSampleWaterRequest ) || ( TRUE == didTimeout( waterSampleStartTime, MAX_WATER_SAMPLE_TIME_MS ) ) ) -// { -// stopSampleWaterRequest = FALSE; -// setValveState( VSP, VALVE_STATE_CLOSED ); -// setValveState( VPI, VALVE_STATE_CLOSED ); -// state = DD_STANDBY_MODE_STATE_FLUSH_FILTER_IDLE; -// } - - return state; -} - -/*********************************************************************//** - * @brief - * The handleStandbyPauseState function executes the pause state. - * @details \b Inputs: none - * @details \b Outputs: filterFlushStartTime - * @return the next state - *************************************************************************/ static DD_STANDBY_MODE_STATE_T handleStandbyPauseState( void ) { DD_STANDBY_MODE_STATE_T state = DD_STANDBY_MODE_STATE_PAUSE; -// if ( FALSE == areInletWaterConditionsAlarmsActive() ) -// { -// filterFlushStartTime = getMSTimerCount(); -// state = DD_STANDBY_MODE_STATE_FLUSH_FILTER; -// } + if ( FALSE == areInletWaterConditionsAlarmsActive() ) + { + state = DD_STANDBY_MODE_STATE_IDLE; + } return state; } /*********************************************************************//** * @brief - * The requestDDStart function handles an TD request to start (go to generation idle mode). + * The requestDDStart function handles an TD request to start (go to generation dialysis mode). * @details \b Inputs: standbyState - * @details \b Outputs: pendingSampleWaterRequest + * @details \b Outputs: pendingStartDDRequest * @return TRUE if request accepted, FALSE if not. *************************************************************************/ BOOL requestDDStart( void ) @@ -405,41 +259,51 @@ if ( DD_STANDBY_MODE_STATE_IDLE == standbyState ) { - result = TRUE; - //pendingStartDDRequest = TRUE; - - // Reset the volume accumulator for the next run -// resetROGenerateVolumeL(); + result = TRUE; + pendingStartDDRequest.data = TRUE; } return result; } /*********************************************************************//** * @brief - * The signalAbortWaterSampling function handles an TD request to abort water - * sampling (return to standby idle state). - * @details \b Inputs: none - * @details \b Outputs: standby mode variable initialized - * @return TRUE if request accepted, FALSE if not + * The requestBCSwitchingOnlyStart function handles Balancing chamber switching + * only start request. + * @details \b Inputs: standbyState + * @details \b Outputs: pendingBalanceChamberSwOnlyRequest + * @return TRUE if request accepted, FALSE if not. *************************************************************************/ -BOOL signalAbortWaterSampling( void ) +BOOL requestBCSwitchingOnlyStart( void ) { BOOL result = FALSE; - if ( ( DD_MODE_STAN == getCurrentOperationMode() ) && ( standbyState != DD_STANDBY_MODE_STATE_IDLE ) ) + if ( DD_STANDBY_MODE_STATE_IDLE == standbyState ) { - result = TRUE; - initStandbyMode(); -// setValveState( VSP, VALVE_STATE_CLOSED ); -// setValveState( VPI, VALVE_STATE_CLOSED ); + result = TRUE; + pendingBalanceChamberSwOnlyRequest = TRUE; } return result; } /*********************************************************************//** * @brief + * The requestBCSwitchingOnlyStop function handles Balancing chamber switching + * only stop request. + * @details \b Inputs: standbyState + * @details \b Outputs: pendingBalanceChamberSwOnlyRequest + * @return none. + *************************************************************************/ +void requestBCSwitchingOnlyStop( void ) +{ + pendingBalanceChamberSwOnlyRequest = FALSE; + // Close all balancing chamber valves + valveControlForBCClosedState(); +} + +/*********************************************************************//** + * @brief * The startDDFlush function starts DD flush mode. * @details \b Inputs: standbyState * @details \b Outputs: none @@ -621,71 +485,6 @@ /*********************************************************************//** * @brief - * The startDDROPermeateSample function starts RO permeate sample mode. - * @details \b Inputs: standbyState - * @details \b Outputs: pendingStartDDChemicalDisinfectFlushRequest - * @return: TRUE if the switch was successful - *************************************************************************/ -BOOL startDDROPermeateSample( void ) -{ - BOOL status = FALSE; -// DD_CMD_RESPONSE_T cmdResponse; -// -// cmdResponse.commandID = DD_CMD_START_RO_PERMEATE_SAMPLE; -// cmdResponse.rejected = FALSE; -// cmdResponse.rejectCode = DD_CMD_REQUEST_REJECT_REASON_NONE; -// -// // If DD is in standby mode and the standby mode is in Idle, request RO permeate sample -// if ( ( DD_MODE_STAN == getCurrentOperationMode() ) && ( DD_STANDBY_MODE_STATE_IDLE == standbyState ) ) -// { -// DD_USAGE_INFO_RECORD_T usageInfo; -// OPN_CLS_STATE_T concCap = getSwitchStatus( CONCENTRATE_CAP ); -// OPN_CLS_STATE_T diaCap = getSwitchStatus( DIALYSATE_CAP ); -// -// getNVRecord2Driver( GET_USAGE_RECORD, (U08*)&usageInfo, sizeof( DD_USAGE_INFO_RECORD_T ), 0, ALARM_ID_NO_ALARM ); -// -//#ifndef _RELEASE_ -// if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_CAPS_MONITOR ) ) -// { -// concCap = STATE_CLOSED; -// diaCap = STATE_CLOSED; -// // Using the caps switch to disable the chemical disinfect date checks. -// // This is for debug builds only to simulate that a chem flush has been done after chem -// usageInfo.lastChemDisFlushCompleteDateEpoch = 40; -// usageInfo.lastChemDisStartDateEpoch = 32; -// } -//#endif -// -// if ( ( STATE_OPEN == concCap ) || ( STATE_OPEN == diaCap ) ) -// { -// cmdResponse.rejected = TRUE; -// cmdResponse.rejectCode = ( STATE_OPEN == getSwitchStatus( DIALYSATE_CAP ) ? REQUEST_REJECT_REASON_DD_DIALYSATE_CAP_OPEN : -// REQUEST_REJECT_REASON_DD_CONCENTRATE_CAP_OPEN ); -// } -// else if ( usageInfo.lastChemDisFlushCompleteDateEpoch < usageInfo.lastChemDisStartDateEpoch ) -// { -// cmdResponse.rejected = TRUE; -// cmdResponse.rejectCode = REQUEST_REJECT_REASON_DD_CHEM_FLUSH_NOT_COMPLETED; -// } -// else -// { -// pendingStartDDROPermeateSampleRequest = TRUE; -// status = TRUE; -// } -// } -// else -// { -// cmdResponse.rejected = TRUE; -// cmdResponse.rejectCode = REQUEST_REJECT_REASON_DD_NOT_IN_STANDBY_IDLE_STATE; -// } -// -// sendCommandResponseMsg( &cmdResponse ); - - return status; -} - -/*********************************************************************//** - * @brief * The getCurrentStandbyState function returns the current state of standby mode. * @details \b Inputs: standbyState * @details \b Outputs: none @@ -704,47 +503,19 @@ /*********************************************************************//** * @brief - * The testSetFilterFlushTimePeriodOverride function overrides the filter - * flush time period. - * @details \b Inputs: none - * @details \b Outputs: filterFlushTimePeriod - * @param value override concentrate pump data publish interval with (in ms) + * The testDDstartGenDialysateOverride function sets the override value + * to start the gen dialysate operation mode. + * @details Inputs: pendingStartDDRequest + * @details Outputs: pendingStartDDRequest + * @param message Override message from Dialin which includes the flag + * to override the operation mode. * @return TRUE if override successful, FALSE if not *************************************************************************/ -BOOL testSetFilterFlushTimePeriodOverride( U32 value ) +BOOL testDDstartGenDialysateOverride( MESSAGE_T *message ) { - BOOL result = FALSE; + BOOL result = u32Override( message, &pendingStartDDRequest, FALSE, TRUE ); - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - filterFlushTimePeriod.override = OVERRIDE_KEY; - filterFlushTimePeriod.ovData = value; - } - return result; } -/*********************************************************************//** - * @brief - * The testResetFilterFlushTimePeriodOverride function resets the - * override of the filter flush time period. - * @details \b Inputs: none - * @details \b Outputs: filterFlushTimePeriod - * @return TRUE if override reset successful, FALSE if not - *************************************************************************/ -BOOL testResetFilterFlushTimePeriodOverride( void ) -{ - BOOL result = FALSE; - - if ( TRUE == isTestingActivated() ) - { - result = TRUE; - filterFlushTimePeriod.override = OVERRIDE_RESET; - filterFlushTimePeriod.ovData = filterFlushTimePeriod.ovInitData; - } - - return result; -} - /**@}*/