Index: NVDataMgmt.c =================================================================== diff -u -r22c5403caee45b22397b67444e3ba14905d98594 -r087ae6de4dd6ffb50cf272e9d0aefaed062305ff --- NVDataMgmt.c (.../NVDataMgmt.c) (revision 22c5403caee45b22397b67444e3ba14905d98594) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision 087ae6de4dd6ffb50cf272e9d0aefaed062305ff) @@ -575,6 +575,7 @@ #ifdef _HD_ static BOOL isHDSystemRecordValid( void ); static BOOL isHDServiceRecordValid( void ); +static BOOL isHDUsageRecordValid( void ); static BOOL isHDCalibrationRecordValid( void ); static BOOL isHDValveRecordValid( HD_VALVE_CAL_PAYLOAD_T* record ); static BOOL isHDPumpRecordValid( HD_PUMP_CAL_PAYLOAD_T* record ); @@ -849,12 +850,12 @@ { // Define a pointer that points to the DG calibration record PROCESS_RECORD_SPECS_T recordSpec = RECORDS_SPECS[ job ]; - U08* ptr = recordSpec.structAddressPtr; + U08* ptr = recordSpec.structAddressPtr; // Offset the pointer to length that we should start writing from ptr += recordUpdateAddress; - memcpy(ptr, addressPtr, length); + memcpy( ptr, addressPtr, length ); // Check if the current message is total messages // and 0 everything out since we are done writing @@ -1362,7 +1363,7 @@ if ( FALSE == isQueueFull() ) { 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 ) ); @@ -1619,6 +1620,7 @@ haveCalGroupsPassed = isHDCalibrationRecordValid(); hasSystemRecordPassed = isHDSystemRecordValid(); hasServiceRecordPassed = isHDServiceRecordValid(); + hasUsageRecordPassed = isHDUsageRecordValid(); #ifndef _RELEASE_ hasSWConfigRecordPassed = isSWConfigRecordValid(); #endif @@ -3376,12 +3378,11 @@ memset( hdSystemGroup.hdsystemRecord.topLevelPN, RECORD_DEFAULT_CHARACTER, sizeof( hdSystemGroup.hdsystemRecord.topLevelPN ) ); memset( hdSystemGroup.hdsystemRecord.topLevelSN, RECORD_DEFAULT_CHARACTER, sizeof( hdSystemGroup.hdsystemRecord.topLevelSN ) ); // Recalculate the CRC with the default values - hdSystemGroup.hdsystemRecord.crc = crc16 ( (U08*)&hdSystemGroup.hdsystemRecord, sizeof( HD_SYSTEM_RECORD_T ) - sizeof( U16 ) ); + hdSystemGroup.hdsystemRecord.crc = crc16 ( (U08*)&hdSystemGroup.hdsystemRecord, sizeof( HD_SYSTEM_RECORD_T ) - sizeof( U16 ) ); + hdSystemGroup.crc = crc16 ( (U08*)&hdSystemGroup, sizeof( HD_SYSTEM_GROUP_T ) - sizeof( U16 ) ); + status = FALSE; activateAlarmNoData( ALARM_ID_HD_INVALID_SYSTEM_RECORD_CRC ); - - // Set the to FALSE since the record is not valid - status = FALSE; } return status; @@ -3406,14 +3407,42 @@ // CRC did not pass so set all values to default hdServiceGroup.hdServiceRecord.lastServiceEpochDate = 0; hdServiceGroup.hdServiceRecord.serviceIntervalSeconds = RECORD_DEFAULT_SERVICE_INTERVAL_S; - // Recalculate the CRC with the default values - hdServiceGroup.hdServiceRecord.crc = crc16 ( (U08*)&hdServiceGroup.hdServiceRecord, sizeof( HD_SERVICE_RECORD_T ) - sizeof( U16 ) ); + 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 ) ); + status = FALSE; // Service record failure is also considered as RTC RAM failure activateAlarmNoData( ALARM_ID_HD_INVALID_SERVICE_RECORD_CRC ); + } - // Set the to FALSE since the record is not valid - status = FALSE; + return status; +} + +/*********************************************************************//** + * @brief + * The isHDUsageRecordValid function checks whether the HD usage information + * is valid or not. + * @details Inputs: dgUsageInfoGroup + * @details Outputs: dgUsageInfoGroup + * @return TRUE if the DG usage record is valid otherwise FALSE + *************************************************************************/ +static BOOL isHDUsageRecordValid( void ) +{ + BOOL status = TRUE; + U16 calcCRC = crc16( (U08*)&hdUsageInfoGroup.hdUsageInfo, sizeof( HD_USAGE_INFO_RECORD_T ) - sizeof( U16 ) ); + U16 recordCRC = hdUsageInfoGroup.hdUsageInfo.crc; + + if ( calcCRC != recordCRC ) + { + hdUsageInfoGroup.hdUsageInfo.txLastStartTimeEpoch = 0; + hdUsageInfoGroup.hdUsageInfo.txTimeSinceLastSrvcHrs = 0; + hdUsageInfoGroup.hdUsageInfo.txTimeTotalHrs = 0; + hdUsageInfoGroup.hdUsageInfo.lastResetTimeEpoch = getRTCTimestamp(); + 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 ) ); + status = FALSE; + + activateAlarmNoData( ALARM_ID_HD_INVALID_USAGE_RECORD_CRC ); } return status;