Index: firmware/App/Modes/ModeStandby.c =================================================================== diff -u -r3fbb3d538eae3e425c4fe8f4698cb4a185bd61c8 -rfc11115c26447a2da7b12f5f38ff0d4af06c579b --- firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision 3fbb3d538eae3e425c4fe8f4698cb4a185bd61c8) +++ firmware/App/Modes/ModeStandby.c (.../ModeStandby.c) (revision fc11115c26447a2da7b12f5f38ff0d4af06c579b) @@ -7,8 +7,8 @@ * * @file ModeStandby.c * -* @author (last) Dara Navaei -* @date (last) 31-May-2022 +* @author (last) Michael Garthwaite +* @date (last) 07-Sep-2022 * * @author (original) Dara Navaei * @date (original) 05-Nov-2019 @@ -44,6 +44,8 @@ #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. +// Milliseconds was too big, greater than U32 +#define DG_SRVC_TIME_INTERVAL_S ( 6 * 30 * SECONDS_IN_A_DAY ) ///< DG service interval in seconds. ( 6 months with 30 days each). // ********** private data ********** @@ -71,6 +73,9 @@ static DG_STANDBY_MODE_STATE_T handleStandbyFlushFilterIdleState( void ); static DG_STANDBY_MODE_STATE_T handleStandbySampleWaterState( void ); +static BOOL isDisinfectValid( void ); +static BOOL isServiceTimeValid( void ); + /*********************************************************************//** * @brief * The initStandbyMode function initializes the standby mode module. @@ -317,6 +322,60 @@ /*********************************************************************//** * @brief + * The isDisinfectValid function checks whether the last disinfect has been + * voided or not + * @details Inputs: none + * @details Outputs: none + * @return TRUE if the disinfect is still valid otherwise, FALSE + ***********************************************************************/ +static BOOL isDisinfectValid( void ) +{ + BOOL status = TRUE; + DG_USAGE_INFO_RECORD_T dgUsageInfo; + + // No need to check the CRC of the record because the record'sCRC has been checked in NV POST. + getNVRecord2Driver( GET_USAGE_RECORD, (U08*)&dgUsageInfo, sizeof( DG_USAGE_INFO_RECORD_T ), 0, ALARM_ID_NO_ALARM ); + + if ( FALSE == dgUsageInfo.isDisinfected ) + { + status = FALSE; + + activateAlarmNoData( ALARM_ID_DG_DISINFECT_HAS_BEEN_EXPIRED ); + } + + return status; +} + +/*********************************************************************//** + * @brief + * The isServiceTimeValid function checks whether the last service time is + * still within the interval or not. + * @details Inputs: none + * @details Outputs: none + * @return TRUE if the service time is still valid otherwise, FALSE + ***********************************************************************/ +static BOOL isServiceTimeValid( void ) +{ + BOOL status = TRUE; + DG_SERVICE_RECORD_T dgServiceRecord; + + // No need to check the CRC of the record because the record'sCRC has been checked in NV POST. + getNVRecord2Driver( GET_SRV_RECORD, (U08*)&dgServiceRecord, sizeof( DG_SERVICE_RECORD_T ), 0, ALARM_ID_NO_ALARM ); + + if ( ( ( getRTCTimestamp() - dgServiceRecord.lastServiceEpochDate ) / MS_PER_SECOND > DG_SRVC_TIME_INTERVAL_S ) || + ( 0 == dgServiceRecord.lastServiceEpochDate ) ) + { + // Compare the current time in epoch to the last service data in epoch and convert them to seconds + status = FALSE; + + activateAlarmNoData( ALARM_ID_DG_SERIVCE_TIME_INTERVAL_HAS_ELAPSED ); + } + + return status; +} + +/*********************************************************************//** + * @brief * The requestWaterSample function handles an HD request to sample water. * @details Inputs: standbyState * @details Outputs: pendingSampleWaterRequest @@ -385,8 +444,23 @@ *************************************************************************/ BOOL requestDGStart( void ) { - BOOL result = FALSE; + BOOL result = FALSE; + BOOL disinfectStatus = TRUE; + BOOL serviceStatus = TRUE; +/*#ifndef _RELEASE_ + if ( SW_CONFIG_ENABLE_VALUE == getSoftwareConfigStatus( SW_CONFIG_DISABLE_SERVICE_AND_DISINFECT_CHECK ) ) + { + disinfectStatus = TRUE; + serviceStatus = TRUE; + } + else +#endif + { + disinfectStatus = isDisinfectValid(); + serviceStatus = isServiceTimeValid(); + }*/ + if ( DG_STANDBY_MODE_STATE_IDLE == standbyState ) { result = TRUE;