Index: NVDataMgmt.c =================================================================== diff -u -r0d8af8f3b27be8190b1809f7b0d1fb1e59a315e6 -r793c9593c95fc6ecb33130a6b4a340c825ff01b8 --- NVDataMgmt.c (.../NVDataMgmt.c) (revision 0d8af8f3b27be8190b1809f7b0d1fb1e59a315e6) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision 793c9593c95fc6ecb33130a6b4a340c825ff01b8) @@ -75,7 +75,7 @@ // Data addresses and length in RTC RAM #define LOG_RECORD_START_ADDRESS 0x00000000 // 0 ///< Log record start address in RTC RAM (0). #define HD_TREATMENT_TIME_ADDRESS 0x00000010 // 16 ///< HD treatment time start address in RTC RAM (16). -#define DG_CONSUMED_WATER_ADDRESS 0x00000020 // 32 ///< DG water consumption start address in RTC RAM (32). +#define DG_USAGE_INFO_START_ADDRESS 0x00000020 // 32 ///< DG usage info start address in RTC RAM (32). #define SERVICE_RECORD_START_ADDRESS 0x00000030 // 48 ///< Service date record start address in RTC RAM (HD/DG) (48). #define DG_SCHEDULED_RUNS_START_ADDRESS (SERVICE_RECORD_START_ADDRESS + sizeof(DG_SERVICE_GROUP_T)) ///< DG scheduled runs start address in RTC RAM. #define DG_HEATERS_INFO_START_ADDRESS (DG_SCHEDULED_RUNS_START_ADDRESS + sizeof(DG_HEATERS_INFO_GROUP_T))///< DG heaters info start address in RTC RAM. @@ -428,16 +428,21 @@ static DG_SCHEDULED_RUNS_GROUP_T dgScheduledRunsGroup; ///< DG scheduled run structure (including padding and final CRC). static DG_USAGE_INFO_GROUP_T dgUsageInfoGroup; ///< DG usage info structure (including padding and final CRC). static DG_HEATERS_INFO_GROUP_T dgHeatersInfoGroup; ///< DG heaters info structure (including padding and final CRC). +#ifndef _RELEASE_ static DG_SW_CONFIG_GROUP_T dgSWConfigGroup; ///< DG Software configurations structure(including padding and final CRC). +#endif // Process records specifications const PROCESS_RECORD_SPECS_T RECORDS_SPECS[ NUM_OF_NVDATMGMT_RECORDS_JOBS ] = { {CAL_RECORD_NV_MEM_START_ADDRESS, sizeof(DG_CALIBRATION_RECORD_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(DG_CALIBRATION_RECORD_T), (U08*)&dgCalibrationRecord, (U08*)&dgCalibrationRecord.crc, NVDATAMGMT_EEPROM}, // NVDATAMGMT_CALIBRATION_RECORD {SYSTEM_RECORD_NV_MEM_START_ADDRESS, sizeof(DG_SYSTEM_GROUP_T), MAX_EEPROM_WRITE_BUFFER_BYTES, sizeof(DG_SYSTEM_GROUP_T), (U08*)&dgSystemGroup, (U08*)&dgSystemGroup.crc, NVDATAMGMT_EEPROM}, // NVDATAMGMT_SYSTEM_RECORD {SERVICE_RECORD_START_ADDRESS, sizeof(DG_SERVICE_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&dgServiceGroup, (U08*)&dgServiceGroup.crc, NVDATAMGMT_RTC}, // NVDATAMGMT_SERVICE_RECORD +#ifndef _RELEASE_ {SW_CONFIGS_START_ADDRESS, sizeof(DG_SW_CONFIG_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&dgSWConfigGroup, (U08*)&dgSWConfigGroup.crc, NVDATAMGMT_RTC}, // NVDATAMGMT_SW_CONFIG_RECORD +#endif {DG_SCHEDULED_RUNS_START_ADDRESS, sizeof(DG_SCHEDULED_RUNS_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&dgScheduledRunsGroup, (U08*)&dgScheduledRunsGroup.crc, NVDATAMGMT_RTC}, // NVDATAMGMT_SCHEDULER_RECORD - {DG_HEATERS_INFO_START_ADDRESS, sizeof(DG_HEATERS_INFO_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&dgHeatersInfoGroup, (U08*)&dgHeatersInfoGroup.crc, NVDATAMGMT_RTC} // NVDATAMGMT_HEATERS_INFO_RECORD + {DG_HEATERS_INFO_START_ADDRESS, sizeof(DG_HEATERS_INFO_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&dgHeatersInfoGroup, (U08*)&dgHeatersInfoGroup.crc, NVDATAMGMT_RTC}, // NVDATAMGMT_HEATERS_INFO_RECORD + {DG_USAGE_INFO_START_ADDRESS, sizeof(DG_USAGE_INFO_GROUP_T), MAX_RTC_RAM_OPS_BUFFER_BYTES, MAX_RTC_RAM_OPS_BUFFER_BYTES, (U08*)&dgUsageInfoGroup, (U08*)&dgUsageInfoGroup.crc, NVDATAMGMT_RTC} // NVDATAMGMT_USAGE_INFO_RECORD }; #endif @@ -1163,8 +1168,8 @@ break; case GET_CAL_FILTERS_RECORD: - nvDataStartPtr = (U08*)&dgCalibrationRecord.dgCalibrationGroups.filtersRecord; - nvDataLength = sizeof( dgCalibrationRecord.dgCalibrationGroups.filtersRecord ); + nvDataStartPtr = (U08*)&dgCalibrationRecord.dgCalibrationGroups.filtersRecord; + nvDataLength = sizeof( dgCalibrationRecord.dgCalibrationGroups.filtersRecord ); isNVDataValid |= ( 0 == dgCalibrationRecord.dgCalibrationGroups.filtersRecord.carbonFilter.calibrationTime ? FALSE : TRUE ); isNVDataValid |= ( 0 == dgCalibrationRecord.dgCalibrationGroups.filtersRecord.carbonPolishFilter.calibrationTime ? FALSE : TRUE ); isNVDataValid |= ( 0 == dgCalibrationRecord.dgCalibrationGroups.filtersRecord.roFilter.calibrationTime ? FALSE : TRUE ); @@ -1364,43 +1369,93 @@ #ifdef _DG_ /*********************************************************************//** * @brief - * The setWaterConsumption sets a queue job to write the amount of water - * that has been consumed in DG. - * @details Inputs: waterConsumptionRecord - * @details Outputs: waterConsumptionRecord + * The setROWaterGeneratedL sets a queue job to write the amount of generated + * RO water that has been generated in DG. + * @details Inputs: dgUsageInfoGroup + * @details Outputs: dgUsageInfoGroup * @param liters consumed water is liters + * @param isServiceDone TURE if service is done otherwise, FALSE * @return TRUE if queue is not full *************************************************************************/ -BOOL setWaterConsumption ( U32 liters ) +BOOL setROWaterGeneratedL( F32 liters, BOOL isServiceDone ) { BOOL status = FALSE; - dgUsageInfoGroup.dgUsageInfo.roWaterGenTotalL = liters; - dgUsageInfoGroup.crc = crc16 ( (U08*)&dgUsageInfoGroup.dgUsageInfo.roWaterGenTotalL, sizeof(U16) ); - if ( !isQueueFull() ) + if ( TRUE == isServiceDone ) { - enqueue( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, DG_CONSUMED_WATER_ADDRESS, - (U08*)&dgUsageInfoGroup, 0, sizeof(DG_USAGE_INFO_RECORD_T) ); - status = TRUE; //TODO this is not right use enqueueRecordJob function to schedule a write + dgUsageInfoGroup.dgUsageInfo.roWaterGenTotalL += dgUsageInfoGroup.dgUsageInfo.roWaterGenSinceLastServiceL; + dgUsageInfoGroup.dgUsageInfo.roWaterGenSinceLastServiceL = liters; } + else + { + dgUsageInfoGroup.dgUsageInfo.roWaterGenSinceLastServiceL += liters; + dgUsageInfoGroup.dgUsageInfo.roWaterGenTotalL += dgUsageInfoGroup.dgUsageInfo.roWaterGenSinceLastServiceL; + } + dgUsageInfoGroup.dgUsageInfo.crc = crc16( (U08*)&dgUsageInfoGroup.dgUsageInfo, sizeof( DG_USAGE_INFO_RECORD_T ) - sizeof( U16 ) ); + dgUsageInfoGroup.crc = crc16( (U08*)&dgUsageInfoGroup, sizeof( DG_USAGE_INFO_GROUP_T ) - sizeof( U16 ) ); + + if ( FALSE == isQueueFull() ) + { + enqueue( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, DG_USAGE_INFO_START_ADDRESS, (U08*)&dgUsageInfoGroup, 0, sizeof( DG_USAGE_INFO_GROUP_T ) ); + status = TRUE; + } + return status; } /*********************************************************************//** * @brief - * The getWaterConsumption returns the amount of consumed water. - * @details Inputs: none - * @details Outputs: none - * @return water consumption as a U32 + * The setLastDisinfectDate sets a queue job to write the last time that DG + * was disinfected. + * @details Inputs: dgUsageInfoGroup + * @details Outputs: dgUsageInfoGroup + * @param epochTime last disinfect time in epoch + * @return TRUE if queue is not full *************************************************************************/ -U32 getWaterConsumption ( void ) +BOOL setLastDisinfectDate( U32 epochTime ) { - return dgUsageInfoGroup.dgUsageInfo.roWaterGenTotalL; + BOOL status = FALSE; + dgUsageInfoGroup.dgUsageInfo.lastDisinfectDate = epochTime; + dgUsageInfoGroup.dgUsageInfo.crc = crc16( (U08*)&dgUsageInfoGroup.dgUsageInfo, sizeof( DG_USAGE_INFO_RECORD_T ) - sizeof( U16 ) ); + dgUsageInfoGroup.crc = crc16( (U08*)&dgUsageInfoGroup, sizeof( DG_USAGE_INFO_GROUP_T ) - sizeof( U16 ) ); + + if ( FALSE == isQueueFull() ) + { + enqueue( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, DG_USAGE_INFO_START_ADDRESS, (U08*)&dgUsageInfoGroup, 0, sizeof( DG_USAGE_INFO_GROUP_T ) ); + status = TRUE; + } + + return status; } /*********************************************************************//** * @brief + * The setDisinfectStatus sets a queue job to write whether the device is already + * disinfected or not. + * @details Inputs: dgUsageInfoGroup + * @details Outputs: dgUsageInfoGroup + * @param disinfectStatus disinfect status + * @return TRUE if queue is not full + *************************************************************************/ +BOOL setDisinfectStatus( BOOL disinfectStatus ) +{ + BOOL status = FALSE; + dgUsageInfoGroup.dgUsageInfo.isDisinfected = disinfectStatus; + dgUsageInfoGroup.dgUsageInfo.crc = crc16( (U08*)&dgUsageInfoGroup.dgUsageInfo, sizeof( DG_USAGE_INFO_RECORD_T ) - sizeof( U16 ) ); + dgUsageInfoGroup.crc = crc16( (U08*)&dgUsageInfoGroup, sizeof( DG_USAGE_INFO_GROUP_T ) - sizeof( U16 ) ); + + if ( FALSE == isQueueFull() ) + { + enqueue( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, DG_USAGE_INFO_START_ADDRESS, (U08*)&dgUsageInfoGroup, 0, sizeof( DG_USAGE_INFO_GROUP_T ) ); + status = TRUE; + } + + return status; +} + +/*********************************************************************//** + * @brief * The setHeatersInfoRecord sets a queue job to write the DG heaters info * back to the RTC RAM. * @details Inputs: none @@ -1698,12 +1753,18 @@ // If the RAM is ready, request a read for water consumption if ( ( RTC_RAM_STATUS_IDLE == getRTCRAMStatus() ) || ( TRUE == timeoutStatus ) ) { - getDataFromRAM ( (U08*)&dgUsageInfoGroup, sizeof(DG_USAGE_INFO_RECORD_T) ); + PROCESS_RECORD_SPECS_T specs = RECORDS_SPECS[ NVDATAMGMT_USAGE_INFO_RECORD ]; + U08* bufferAddress = specs.structAddressPtr; + U32 maxBufferLength = specs.maxReadBufferSize; + + getDataFromRAM ( bufferAddress, maxBufferLength ); + if ( RTC_RAM_STATE_READY == getRTCRAMState() ) { - readFromRAM ( LOG_RECORD_START_ADDRESS, sizeof(LOG_RECORD_T) ); - currentTime = getMSTimerCount(); - state = NVDATAMGMT_SELF_TEST_STATE_READ_LOG_RECORD; + // TODO Phase 1B + //readFromRAM ( LOG_RECORD_START_ADDRESS, sizeof(LOG_RECORD_T) ); + //currentTime = getMSTimerCount(); + state = NVDATAMGMT_SELF_TEST_STATE_CHECK_CRC; } } @@ -1764,7 +1825,17 @@ getDataFromRAM( bufferAddress, maxBufferLength ); - state = NVDATAMGMT_SELF_TEST_STATE_CHECK_CRC; + if ( RTC_RAM_STATE_READY == getRTCRAMState() ) + { + PROCESS_RECORD_SPECS_T specs = RECORDS_SPECS[ NVDATAMGMT_USAGE_INFO_RECORD ]; + U32 startAddress = specs.startAddress; + U32 maxBufferLength = specs.maxReadBufferSize; + + currentTime = getMSTimerCount(); + readFromRAM( startAddress, maxBufferLength ); + + state = NVDATAMGMT_SELF_TEST_STATE_READ_WATER_CONSUMPTION; + } } #else // It is a release so set all the software configurations to 0 to be considered as disable @@ -2416,6 +2487,14 @@ #endif break; + case NVDATAMGMT_USAGE_INFO_RECORD: +#ifdef _DG_ + sendDGUsageInfoRecord( calPublishMessageCount + 1, calPublishTotalMessages, length, startPtr ); +#endif +#ifdef _HD_ +#endif + break; + default: //Ignore break; Index: NVDataMgmt.h =================================================================== diff -u -re2611bd03c4a86fae5d4f525b91d6fbfb597a8e0 -r793c9593c95fc6ecb33130a6b4a340c825ff01b8 --- NVDataMgmt.h (.../NVDataMgmt.h) (revision e2611bd03c4a86fae5d4f525b91d6fbfb597a8e0) +++ NVDataMgmt.h (.../NVDataMgmt.h) (revision 793c9593c95fc6ecb33130a6b4a340c825ff01b8) @@ -76,6 +76,7 @@ NVDATAMGMT_SCHEDULED_RUNS_RECORD, ///< NVDataMgmt process scheduled runs record. NVDATAMGMT_HEATERS_INFO_RECORD, ///< NVDataMgmt process heaters info record. #endif + NVDATAMGMT_USAGE_INFO_RECORD, ///< NVDataMgmt process usage info record. NUM_OF_NVDATMGMT_RECORDS_JOBS ///< Number of NVDataMgmt records jobs. } RECORD_JOBS_STATE_T; @@ -101,13 +102,13 @@ } LOG_DATA_T; #pragma pack(pop) -void initNVDataMgmt ( void ); +void initNVDataMgmt( void ); void signalPowerOffWarning( void ); -void execNVDataMgmt ( void ); +void execNVDataMgmt( void ); -SELF_TEST_STATUS_T execNVDataMgmtSelfTest ( void ); +SELF_TEST_STATUS_T execNVDataMgmtSelfTest( void ); void execNVDataMgmtProcessRecord( void ); @@ -120,8 +121,9 @@ #endif #ifdef _DG_ -BOOL setWaterConsumption ( U32 liters ); -U32 getWaterConsumption ( void ); +BOOL setROWaterGeneratedL( F32 liters, BOOL isServiceDone ); +BOOL setLastDisinfectDate( U32 epochTime ); +BOOL setDisinfectStatus( BOOL disinfectStatus ); BOOL setHeatersInfoRecord( U08 *addressPtr, U32 infoLength ); #endif #ifdef _HD_ Index: NVDataMgmtDGRecords.h =================================================================== diff -u -rafb0fcafdbfe0b57b79c330e37b504b8acc2b137 -r793c9593c95fc6ecb33130a6b4a340c825ff01b8 --- NVDataMgmtDGRecords.h (.../NVDataMgmtDGRecords.h) (revision afb0fcafdbfe0b57b79c330e37b504b8acc2b137) +++ NVDataMgmtDGRecords.h (.../NVDataMgmtDGRecords.h) (revision 793c9593c95fc6ecb33130a6b4a340c825ff01b8) @@ -38,8 +38,8 @@ /// Software configuration enums typedef enum software_configurations { - SW_CONFIG_DISABLE_TRIMMER_HEATER = 0, - SW_CONFIG_DISABLE_ACCELS, + SW_CONFIG_DISABLE_TRIMMER_HEATER = 0, ///< Software configuration disable trimmer heater. + SW_CONFIG_DISABLE_ACCELS, ///< Software configuration disable accelerometers. SW_CONFIG_DISABLE_CAL_CHECK, ///< Software configuration disable calibration check. SW_CONFIG_DISABLE_HEATERS_MONITOR, ///< Software configuration disable heaters monitor. SW_CONFIG_DISABLE_DRAIN_PUMP_MONITOR, @@ -86,7 +86,6 @@ GET_CAL_PRE_RO_PURGE_VOLUME_RECORD, ///< Get pre RO purge volume record. GET_CAL_FILTERS_RECORD, ///< Get filters record. GET_INF_HEATERS_RECORD, ///< Get heaters information form the the last run. - GET_INF_DG_USAGE_RECORD, ///< Get DG usage record. GET_SYS_RECORD, ///< Get system record. GET_SRV_RECORD, ///< Get service record. GET_SRR_RECORD, ///< Get scheduled runs record. @@ -469,8 +468,10 @@ /// DG usage info structure. typedef struct { - U32 roWaterGenTotalL; ///< Total RO water generated in liters. (Cannot be reset) - U32 roWaterGenSinceLastTxL; ///< RO water generated since last treatment in liters. + F32 roWaterGenTotalL; ///< Total RO water generated in liters. (Cannot be reset) + F32 roWaterGenSinceLastServiceL; ///< RO water generated since last treatment in liters. + U32 lastDisinfectDate; ///< Last disinfect date in epoch. + U32 isDisinfected; ///< Disinfect status boolean flag. U16 crc; ///< CRC for the DG usage info structure. } DG_USAGE_INFO_RECORD_T; Index: NVDataMgmtHDRecords.h =================================================================== diff -u -rce9c43081997fda665170fc2b07815706db77666 -r793c9593c95fc6ecb33130a6b4a340c825ff01b8 --- NVDataMgmtHDRecords.h (.../NVDataMgmtHDRecords.h) (revision ce9c43081997fda665170fc2b07815706db77666) +++ NVDataMgmtHDRecords.h (.../NVDataMgmtHDRecords.h) (revision 793c9593c95fc6ecb33130a6b4a340c825ff01b8) @@ -254,7 +254,9 @@ /// HD usage info structure. typedef struct { - U32 treatmentTime; ///< Treatment time. + F32 txTimeTotalHrs; ///< Treatment time total in hours (never reset). + F32 txTimeSinceLastSrvcHrs; ///< Treatment time since last service in hours. + U32 txLastEpochDate; ///< Last tretment time in epoch. U16 crc; ///< CRC for the HD usage info structure. } HD_USAGE_INFO_RECORD_T;