Index: NVDataMgmt.c =================================================================== diff -u -r609288f4e51381408ce925ebb5a8c93b89bba08e -r3dd1f85edd2452b2de18e2938b3a0159e26f058b --- NVDataMgmt.c (.../NVDataMgmt.c) (revision 609288f4e51381408ce925ebb5a8c93b89bba08e) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision 3dd1f85edd2452b2de18e2938b3a0159e26f058b) @@ -1245,20 +1245,45 @@ } #endif -#ifdef _DG_ /*********************************************************************//** * @brief - * The getDGFiltersRecord function returns the DG filters record. + * The setServiceTime function sets the latest service time in epoch and updates + * the usage information after the service. * @details Inputs: none - * @details Outputs: none - * @return DG filters record + * @details Outputs: hdServiceGroup, hdUsageInfoGroup + * @return TRUE if the queue has sufficient space to enqueue all the changed + * records *************************************************************************/ -DG_FILTERS_CAL_RECORD_T getDGFiltersRecord( void ) +BOOL setServiceTime( void ) { - return dgCalibrationRecord.dgCalibrationGroups.filtersRecord; -} + BOOL status = FALSE; + + if ( getAvailableRecordQueueCount() >= ( MIN_JOBS_NEEDED_FOR_SECTOR_0 + 1 ) ) + { + // When the service record is changed, all the sector 0 must be re-written plus the stack's usage information must be updated. + // Therefore, at least 4 queues are needed to be able to update all the records. The usage records are changed: + // In HD the treatment time since last service is reset to 0 + // In DG the RO water generation since the last service in reset to 0 +#ifdef _HD_ + hdServiceGroup.hdServiceRecord.lastServiceEpochDate = getRTCTimestamp(); + hdServiceGroup.hdServiceRecord.crc = crc16( (U08*)&hdServiceGroup.hdServiceRecord, sizeof( HD_SERVICE_RECORD_T ) - sizeof( U16 ) ); + hdServiceGroup.crc = crc16( (U08*)&hdServiceGroup, sizeof( HD_SERVICE_GROUP_T ) - sizeof( U16 ) ); + // Update the HD usage info + hdUsageInfoGroup.hdUsageInfo.txTimeSinceLastSrvcHrs = 0; + hdUsageInfoGroup.hdUsageInfo.crc = crc16( (U08*)&hdUsageInfoGroup.hdUsageInfo, sizeof( HD_USAGE_INFO_RECORD_T ) - sizeof( U16 ) ); + hdUsageInfoGroup.crc = crc16( (U08*)&hdUsageInfoGroup, sizeof( HD_USAGE_INFO_GROUP_T ) - sizeof( U16 ) ); #endif +#ifdef _DG_ +#endif + + enqueueSector0Records(); + enqueueRecordJob( NVDATAMGMT_WRITE, RECORDS_SPECS[ NVDATAMGMT_USAGE_INFO_RECORD ].dataLoc, NVDATAMGMT_USAGE_INFO_RECORD ); + } + + return status; +} + /*********************************************************************//** * @brief * The writeLogData checks if the queue is not full and if it is not, it calls @@ -1312,29 +1337,19 @@ * @details Inputs: none * @details Outputs: hdUsageInfoGroup * @param hours treatment time in hours - * @param isServiceDone flag to indicate the service has been done * @return TRUE if the queue was not full so the job was scheduled successfully *************************************************************************/ -BOOL setTxTimeHours( F32 hours, BOOL isServiceDone ) +BOOL setTxTimeHours( F32 hours ) { BOOL status = FALSE; - if ( TRUE == isServiceDone ) + if ( FALSE == isQueueFull() ) { - hdUsageInfoGroup.hdUsageInfo.txTimeTotalHrs += hdUsageInfoGroup.hdUsageInfo.txTimeSinceLastSrvcHrs; - hdUsageInfoGroup.hdUsageInfo.txTimeSinceLastSrvcHrs = hours; - } - else - { hdUsageInfoGroup.hdUsageInfo.txTimeSinceLastSrvcHrs += hours; - hdUsageInfoGroup.hdUsageInfo.txTimeTotalHrs += hdUsageInfoGroup.hdUsageInfo.txTimeSinceLastSrvcHrs; - } + hdUsageInfoGroup.hdUsageInfo.txTimeTotalHrs += hdUsageInfoGroup.hdUsageInfo.txTimeSinceLastSrvcHrs;; + hdUsageInfoGroup.hdUsageInfo.crc = crc16( (U08*)&hdUsageInfoGroup.hdUsageInfo, sizeof( HD_USAGE_INFO_RECORD_T ) - sizeof( U16 ) ); + hdUsageInfoGroup.crc = crc16( (U08*)&hdUsageInfoGroup, sizeof( HD_USAGE_INFO_GROUP_T ) - sizeof( U16 ) ); - hdUsageInfoGroup.hdUsageInfo.crc = crc16( (U08*)&hdUsageInfoGroup.hdUsageInfo, sizeof( HD_USAGE_INFO_RECORD_T ) - sizeof( U16 ) ); - hdUsageInfoGroup.crc = crc16( (U08*)&hdUsageInfoGroup, sizeof( HD_USAGE_INFO_GROUP_T ) - sizeof( U16 ) ); - - if ( FALSE == isQueueFull() ) - { enqueue( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, HD_USAGE_INFO_START_ADDRESS, (U08*)&hdUsageInfoGroup, 0, sizeof( HD_USAGE_INFO_GROUP_T ) ); status = TRUE; } @@ -1351,13 +1366,14 @@ *************************************************************************/ BOOL setTxLastStartTimeEpoch( U32 epoch ) { - BOOL status = FALSE; - hdUsageInfoGroup.hdUsageInfo.txLastStartTimeEpoch = epoch; - hdUsageInfoGroup.hdUsageInfo.crc = crc16 ( (U08*)&hdUsageInfoGroup.hdUsageInfo, sizeof( HD_USAGE_INFO_RECORD_T ) - sizeof( U16 ) ); - hdUsageInfoGroup.crc = crc16 ( (U08*)&hdUsageInfoGroup, sizeof( HD_USAGE_INFO_GROUP_T ) - sizeof( U16 ) ); + BOOL status = FALSE; if ( FALSE == isQueueFull() ) { + hdUsageInfoGroup.hdUsageInfo.txLastStartTimeEpoch = epoch; + hdUsageInfoGroup.hdUsageInfo.crc = crc16 ( (U08*)&hdUsageInfoGroup.hdUsageInfo, sizeof( HD_USAGE_INFO_RECORD_T ) - sizeof( U16 ) ); + hdUsageInfoGroup.crc = crc16 ( (U08*)&hdUsageInfoGroup, sizeof( HD_USAGE_INFO_GROUP_T ) - sizeof( U16 ) ); + enqueue( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, HD_USAGE_INFO_START_ADDRESS, (U08*)&hdUsageInfoGroup, 0, sizeof( HD_USAGE_INFO_GROUP_T ) ); status = TRUE; } Index: NVDataMgmt.h =================================================================== diff -u -r7a8126075d566078097485bf4757f2a380a1ef98 -r3dd1f85edd2452b2de18e2938b3a0159e26f058b --- NVDataMgmt.h (.../NVDataMgmt.h) (revision 7a8126075d566078097485bf4757f2a380a1ef98) +++ NVDataMgmt.h (.../NVDataMgmt.h) (revision 3dd1f85edd2452b2de18e2938b3a0159e26f058b) @@ -140,10 +140,12 @@ BOOL setHeatersInfoRecord( U08 *addressPtr, U32 infoLength ); #endif #ifdef _HD_ -BOOL setTxTimeHours( F32 hours, BOOL isServiceDone ); +BOOL setTxTimeHours( F32 hours ); BOOL setTxLastStartTimeEpoch( U32 epoch ); #endif +BOOL setServiceTime( void ); + BOOL writeLogData( LOG_DATA_T* data ); // Phase 1B BOOL readLogData( READ_DATA_T* buffer, U32 length ); // Phase 1B