Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -rfe7cf171a4c7736ee5c342cf33b7b44869c0826b -rc376fe2c3af7990d421201ab6b9b3ba7f3acbceb --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision fe7cf171a4c7736ee5c342cf33b7b44869c0826b) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision c376fe2c3af7990d421201ab6b9b3ba7f3acbceb) @@ -52,22 +52,35 @@ #define FLUSH_TIME_INTERVAL_S ( 30 * SEC_PER_MIN * MS_PER_SECOND ) ///< Flush time interval in seconds. #define MAX_ALLOWED_RO_FILTER_TEMP_FOR_TX_C 44.0F ///< Maximum allowed temperature to start a treatment in C. +typedef struct +{ + BOOL startCleaningMode; + DG_COMMAND_T startCommand; + DG_DISINFECT_STATE_T cleaningModeState; + ALARM_ID_T alarmID; + DG_OP_MODE_T dgOpMode; + BOOL sampleAlarmTrgrd; + GENERIC_CONFIRM_ID_T sampleID; +} DG_CLEANING_MODE_STATUS_T; + // ********** private data ********** static HD_STANDBY_STATE_T currentStandbyState; ///< Current state (sub-mode) of standby mode. static BOOL treatStartReqReceived; ///< Flag indicates user has requested initiation of a treatment. -static BOOL flushStartReqReceived; ///< Flag indicates user has requested initiation of flush mode. -static BOOL heatDisinfectStartReqReceived; ///< Flag indicates user has requested initiation of heat disinfect mode. -static BOOL chemDisinfectStartReqReceived; ///< Flag indicates user has requested initiation of chemical disinfect mode. -static BOOL chemDisinfectFlushStartReqReceived; ///< Flag indicates user has requested initiation of chemical disinfect flush mode. -static BOOL roPermeateSampleStartReqReceived; ///< Flag indicates user has requested initiation of RO permeate sample mode. +static BOOL flushStartReqReceived; // TODO remove ///< Flag indicates user has requested initiation of flush mode. +static BOOL heatDisinfectStartReqReceived; // TODO remove ///< Flag indicates user has requested initiation of heat disinfect mode. +static BOOL chemDisinfectStartReqReceived; // TODO remove ///< Flag indicates user has requested initiation of chemical disinfect mode. +static BOOL chemDisinfectFlushStartReqReceived; // TODO remove ///< Flag indicates user has requested initiation of chemical disinfect flush mode. +static BOOL roPermeateSampleStartReqReceived; // TODO remove ///< Flag indicates user has requested initiation of RO permeate sample mode. static GENERIC_CONFIRM_ID_T disinfectCancelReqID; ///< ID of requested cancel disinfect mode. -static DG_DISINFECT_STATE_T dgDisinfectState; ///< DG disinfect state to be boadcast to UI. +static DG_DISINFECT_STATE_T dgDisinfectState; // TODO remove ///< DG disinfect state to be boadcast to UI. static U32 dataPublishCounter; ///< Disinfects data publish counter. static BOOL homingInitiated; ///< Boolean flag to indicate homing is initiated. -static BOOL hasChemFlushSampleAlarmBeenTrgrd; ///< Boolean flag to indicate whether chem flush sample alarm has been triggered or not. -static GENERIC_CONFIRM_ID_T chemFlushSampleID; ///< Chemical disinfect flush sample ID. +static BOOL hasChemFlushSampleAlarmBeenTrgrd; // TODO remove ///< Boolean flag to indicate whether chem flush sample alarm has been triggered or not. +static GENERIC_CONFIRM_ID_T chemFlushSampleID; // TODO remove ///< Chemical disinfect flush sample ID. +static DG_CLEANING_MODE_STATUS_T currentDGCleaningMode; + /// Interval (in task intervals) at which to publish standby mode data to CAN bus. static OVERRIDE_U32_T standbyModePublishInterval = { DISINFECTS_DATA_PUB_INTERVAL, DISINFECTS_DATA_PUB_INTERVAL, DISINFECTS_DATA_PUB_INTERVAL, 0 }; @@ -97,6 +110,13 @@ static HD_STANDBY_STATE_T handleStandbyModeWaitForDGChemDisinfectFlushStartState( void ); static HD_STANDBY_STATE_T handleStandbyModeDGChemDisininfectFlushInProgressState( void ); +static HD_STANDBY_STATE_T handleStandbyModeWaitForDGCleaningModeCmdResponseState( void ); +static HD_STANDBY_STATE_T handleStandbyModeWaitForDGCleaningModeStartState( void ); +static HD_STANDBY_STATE_T handleStandbyModeDGCleaningModeInProgressState( void ); + +static void setRequestedCleaningMode( DG_OP_MODE_T opMode ); +static void clearCurrentCleaningModeStatus( void ); +static void handleChemFlushSampleCollection( void ); static BOOL isDGDisinfectValid( void ); static BOOL haveHDDGServicesBeenExpired( REQUEST_REJECT_REASON_CODE_T* rejReason ); static void publishDisinfectData( void ); @@ -150,6 +170,7 @@ setVenousBubbleDetectionEnabled( FALSE ); setCurrentSubState( NO_SUB_STATE ); clearNoRetriggerFlag(); + clearCurrentCleaningModeStatus(); // Set user alarm recovery actions allowed in this mode setAlarmUserActionEnabled( ALARM_USER_ACTION_RESUME, FALSE ); @@ -276,6 +297,18 @@ currentStandbyState = handleStandbyModeDGChemDisininfectFlushInProgressState(); break; + case STANDBY_WAIT_FOR_DG_CLEANING_MODE_CMD_RESPONSE_STATE: + currentStandbyState = handleStandbyModeWaitForDGCleaningModeCmdResponseState(); + break; + + case STANDBY_WAIT_FOR_DG_CLEANING_MODE_TO_START_STATE: + currentStandbyState = handleStandbyModeWaitForDGCleaningModeStartState(); + break; + + case STANDBY_CLEANING_MODE_IN_PROGRESS_STATE: + currentStandbyState = handleStandbyModeDGCleaningModeInProgressState(); + break; + default: SET_ALARM_WITH_2_U32_DATA( ALARM_ID_HD_SOFTWARE_FAULT, SW_FAULT_ID_MODE_STANDBY_INVALID_STATE, currentStandbyState ); currentStandbyState = STANDBY_START_STATE; @@ -456,10 +489,11 @@ { if ( TRUE == isDGCommunicating() ) { - heatDisinfectStartReqReceived = TRUE; - result = TRUE; - currentStandbyState = STANDBY_WAIT_FOR_DISINFECT_STATE; - rejReason = REQUEST_REJECT_REASON_NONE; + //heatDisinfectStartReqReceived = TRUE; + setRequestedCleaningMode( DG_MODE_HEAT ); + result = TRUE; + currentStandbyState = STANDBY_WAIT_FOR_DISINFECT_STATE; + rejReason = REQUEST_REJECT_REASON_NONE; } else { @@ -564,10 +598,13 @@ { if ( TRUE == isDGCommunicating() ) { - roPermeateSampleStartReqReceived = TRUE; - result = TRUE; - currentStandbyState = STANDBY_WAIT_FOR_DISINFECT_STATE; - rejReason = REQUEST_REJECT_REASON_NONE; + //roPermeateSampleStartReqReceived = TRUE; + currentDGCleaningMode.startCleaningMode = TRUE; + currentDGCleaningMode.startCommand = DG_CMD_START_RO_PERMEATE_SAMPLE; + currentDGCleaningMode.dgOpMode = DG_MODE_ROPS; + result = TRUE; + currentStandbyState = STANDBY_WAIT_FOR_DISINFECT_STATE; + rejReason = REQUEST_REJECT_REASON_NONE; } else { @@ -886,8 +923,8 @@ } else if ( TRUE == heatDisinfectStartReqReceived ) { - cmdStartDGHeatDisinfect(); - state = STANDBY_WAIT_FOR_DG_HEAT_DISINFECT_CMD_RESPONSE_STATE; + //cmdStartDGHeatDisinfect(); + //state = STANDBY_WAIT_FOR_DG_HEAT_DISINFECT_CMD_RESPONSE_STATE; } else if ( TRUE == chemDisinfectStartReqReceived ) { @@ -900,6 +937,34 @@ state = STANDBY_WAIT_FOR_DG_CHEM_DISINFECT_FLUSH_CMD_RESPONSE_STATE; } + if ( TRUE == currentDGCleaningMode.startCleaningMode ) + { + switch( currentDGCleaningMode.startCommand ) + { + case DG_CMD_START_FLUSH: + cmdStartDGFlush(); + break; + + case DG_CMD_START_HEAT_DISINFECT: + cmdStartDGHeatDisinfect(); + break; + + case DG_CMD_START_CHEM_DISINFECT: + cmdStartDGChemicalDisinfect(); + break; + + case DG_CMD_START_CHEM_DISINFECT_FLUSH: + cmdStartDGChememicalFlushDisinfect(); + break; + + case DG_CMD_START_RO_PERMEATE_SAMPLE: + // TODO implement the start command + break; + } + + state = STANDBY_WAIT_FOR_DG_CLEANING_MODE_CMD_RESPONSE_STATE; + } + return state; } @@ -1263,6 +1328,142 @@ return state; } +static HD_STANDBY_STATE_T handleStandbyModeWaitForDGCleaningModeCmdResponseState( void ) +{ + DG_CMD_RESPONSE_T dgCmdResp; + HD_STANDBY_STATE_T state = STANDBY_WAIT_FOR_DG_CLEANING_MODE_CMD_RESPONSE_STATE; + BOOL result = FALSE; + + if ( TRUE == getDGCommandResponse( currentDGCleaningMode.startCommand, &dgCmdResp ) ) + { + // Assume the command will be rejected and it goes back to wait for disinfect command + state = STANDBY_WAIT_FOR_DISINFECT_STATE; + currentDGCleaningMode.startCleaningMode = FALSE; + + if ( DG_CMD_REQUEST_REJECT_REASON_NONE == dgCmdResp.rejectCode ) + { + // If the command has not been rejected, transition to the next state + dgDisinfectState = DG_DISINFECT_FLUSH_STATE; // TODO is this needed? + state = STANDBY_WAIT_FOR_DG_CLEANING_MODE_TO_START_STATE; + result = TRUE; + } + + sendDisinfectConfirmResponse( result, dgCmdResp.rejectCode ); + } + + return state; +} + +static HD_STANDBY_STATE_T handleStandbyModeWaitForDGCleaningModeStartState( void ) +{ + HD_STANDBY_STATE_T state = STANDBY_WAIT_FOR_DG_CLEANING_MODE_TO_START_STATE; + + if ( currentDGCleaningMode.dgOpMode == getDGOpMode() ) + { + dgDisinfectState = DG_DISINFECT_NOT_RUNNING_STATE; // TODO is this needed? + state = STANDBY_CLEANING_MODE_IN_PROGRESS_STATE; + activateAlarmNoData( currentDGCleaningMode.alarmID ); + } + + return state; +} + +static HD_STANDBY_STATE_T handleStandbyModeDGCleaningModeInProgressState( void ) +{ + HD_STANDBY_STATE_T state = STANDBY_CLEANING_MODE_IN_PROGRESS_STATE; + + if ( DG_MODE_CHFL == currentDGCleaningMode.dgOpMode ) + { + handleChemFlushSampleCollection(); + } + else if ( DG_MODE_ROPS == currentDGCleaningMode.dgOpMode ) + { + // TODO a function to handle the ROPS sampling message + } + + if ( getDGOpMode() != currentDGCleaningMode.dgOpMode ) + { + dgDisinfectState = DG_DISINFECT_NOT_RUNNING_STATE;// TODO is this needed? + state = STANDBY_WAIT_FOR_TREATMENT_STATE; + clearAlarm( currentDGCleaningMode.alarmID ); + clearCurrentCleaningModeStatus(); + } + + publishDisinfectData(); + + return state; +} + +static void setRequestedCleaningMode( DG_OP_MODE_T opMode ) +{ + switch ( opMode ) + { + case DG_MODE_HEAT: + currentDGCleaningMode.startCleaningMode = TRUE; + currentDGCleaningMode.startCommand = DG_CMD_START_HEAT_DISINFECT; + currentDGCleaningMode.dgOpMode = DG_MODE_HEAT; + currentDGCleaningMode.alarmID = ALARM_ID_HD_DISINFECT_HEAT; + break; + } +} + +static void clearCurrentCleaningModeStatus( void ) +{ + currentDGCleaningMode.startCleaningMode = FALSE; + currentDGCleaningMode.cleaningModeState = DG_DISINFECT_NOT_RUNNING_STATE; + currentDGCleaningMode.alarmID = ALARM_ID_NO_ALARM; + currentDGCleaningMode.startCommand = DG_CMD_NONE; + currentDGCleaningMode.dgOpMode = DG_MODE_FAUL; + currentDGCleaningMode.sampleAlarmTrgrd = FALSE; + currentDGCleaningMode.sampleID = GENERIC_CONFIRM_ID_NONE; +} + +static void handleChemFlushSampleCollection( void ) +{ + if ( ( FALSE == currentDGCleaningMode.sampleAlarmTrgrd ) && ( TRUE == isAlarmActive( ALARM_ID_DG_CHEM_DISINFECT_FLUSH_FLUSH_SAMPLE ) ) ) + { + // Check if the flush sample alarm has been raised for the first time in the sample flush state + currentDGCleaningMode.sampleAlarmTrgrd = TRUE; + } + else if ( ( TRUE == currentDGCleaningMode.sampleAlarmTrgrd ) && ( FALSE == isAlarmActive( ALARM_ID_DG_CHEM_DISINFECT_FLUSH_FLUSH_SAMPLE ) ) ) + { + // Sample flush alarm has been triggered and the user has cleared the alarm by pressing Ok. The user is collecting sample. + // Send the notification to the UI to prompt the pass/fail screen so the user can choose whether the sampling after flush passed or failed + currentDGCleaningMode.sampleAlarmTrgrd = FALSE; + currentDGCleaningMode.sampleID = addConfirmationRequest( GENERIC_CONFIRM_ID_DISINFECT_CHEM_FLUSH_SAMPLE_PASS_FAIL, GENERIC_CONFIRM_CMD_REQUEST_OPEN, 0 ); + } + + if ( currentDGCleaningMode.sampleID != GENERIC_CONFIRM_ID_NONE ) + { + // There is a user confirm + CONFIRMATION_REQUEST_STATUS_T status = getConfirmationRequestStatus( currentDGCleaningMode.sampleID ); + U32 sampleStatus = 0; + + switch( status ) + { + // If the request status is accepted send a 1 to DG + case CONFIRMATION_REQUEST_STATUS_ACCEPTED: + sampleStatus = (U32)CONFIRMATION_REQUEST_STATUS_ACCEPTED; + currentDGCleaningMode.sampleID = GENERIC_CONFIRM_ID_NONE; + handleSendChemFlushPassFailToDG( sampleStatus ); + break; + + // If the request timed out or rejected, it is 0 or failure to DG + case CONFIRMATION_REQUEST_STATUS_TIMEOUT: + case CONFIRMATION_REQUEST_STATUS_REJECTED: + currentDGCleaningMode.sampleID = GENERIC_CONFIRM_ID_NONE; + handleSendChemFlushPassFailToDG( sampleStatus ); + break; + + case CONFIRMATION_REQUEST_STATUS_PENDING: + case CONFIRMATION_REQUEST_STATUS_UNUSED: + default: + // Nothing to do + break; + } + } +} + /*********************************************************************//** * @brief * The isDGDisinfectValid function checks whether the DG disinfects is