Index: NVDataMgmt.c =================================================================== diff -u -r69a6c768a5427cc30111249e58b99f319bbb1062 -rf480c73cfca65442ee51d0189370f4d464f026e7 --- NVDataMgmt.c (.../NVDataMgmt.c) (revision 69a6c768a5427cc30111249e58b99f319bbb1062) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision f480c73cfca65442ee51d0189370f4d464f026e7) @@ -105,6 +105,9 @@ #define RECORD_DEFAULT_OFFSET 0.0 ///< Record default offset. #define RECORD_DEFAULT_CONST 0.0 ///< Record default constant. #define RECORD_DEFAULT_RATIO 1.0 ///< Record default ratio. +// The service record interval is equivalent to 6 months +#define RECORD_DEFAULT_SERVICE_INTERVAL_S 15768000U ///< Record default service interval in seconds. +#define RECORD_DEFAULT_CHARACTER '-' ///< Record default character. // Once a new calibration data is available the driver, sets a signal for the defined time. Once the time is out, it turns the signal off. #define NEW_CAL_AVAILABLE_SIGNAL_TIMEOUT_MS (1 * MS_PER_SECOND) ///< New calibration available signal timeout in milliseconds. @@ -451,7 +454,7 @@ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadCalibrationRecord( void ); static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadSystemRecord( void ); static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadServiceRecord( void ); -#ifdef _DG +#ifdef _DG_ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestReadScheduledRunsRecord( void ); #endif #ifdef _HD_ @@ -508,6 +511,8 @@ #endif #ifdef _DG_ +static BOOL isDGSystemRecordValid( void ); +static BOOL isDGServiceRecordValid( void ); static BOOL isDGCalibrationRecordValid( void ); static BOOL isDGConcPumpRecordValid( DG_CONC_PUMPS_CAL_DATA_T* record ); static BOOL isDGDrainPumpRecordValid( DG_DRAIN_PUMP_CAL_RECORD_T* record ); @@ -669,7 +674,7 @@ break; case NVDATAMGMT_SELF_TEST_STATE_READ_SCHEDULED_RUNS_RECORD: -#ifdef _DG +#ifdef _DG_ nvDataMgmtSelfTestState = handleSelfTestReadScheduledRunsRecord(); #endif break; @@ -1959,15 +1964,19 @@ static NVDATAMGMT_SELF_TEST_STATE_T handleSelfTestCheckCRC ( void ) { NVDATAMGMT_SELF_TEST_STATE_T state = NVDATAMGMT_SELF_TEST_STATE_COMPLETE; - BOOL haveCalGroupsPassed = TRUE; - BOOL haveRecordsPassed = TRUE; + BOOL haveCalGroupsPassed = TRUE; + BOOL haveRecordsPassed = TRUE; + BOOL hasSystemRecordPassed = TRUE; + BOOL hasServiceRecordPassed = TRUE; // Check the integrity of the records as a whole. Check the upper layer CRC haveRecordsPassed = areRecordsValid(); #ifdef _DG_ // Check all the calibration groups - haveCalGroupsPassed = isDGCalibrationRecordValid(); + haveCalGroupsPassed = isDGCalibrationRecordValid(); + hasSystemRecordPassed = isDGSystemRecordValid(); + hasServiceRecordPassed = isDGServiceRecordValid(); #endif #ifdef _HD_ haveCalGroupsPassed = isHDCalibrationRecordValid(); @@ -1982,7 +1991,8 @@ } // Check if the records' entire CRCs as well as the individual CRCs passed - if ( ( TRUE == haveCalGroupsPassed ) && ( TRUE == haveRecordsPassed ) ) + if ( ( TRUE == haveCalGroupsPassed ) && ( TRUE == haveRecordsPassed ) && + ( TRUE == hasSystemRecordPassed ) && ( TRUE == hasServiceRecordPassed ) ) { nvDataMgmtSelfTestResult = SELF_TEST_STATUS_PASSED; } @@ -3072,6 +3082,66 @@ #ifdef _DG_ /*********************************************************************//** * @brief + * The isDGSystemRecordValid function checks the validity of the DG system + * record. + * @details Inputs: dgSystemGroup.dgSystemRecord + * @details Outputs: none + * @return TRUE if the DG system record is valid otherwise FALSE + *************************************************************************/ +static BOOL isDGSystemRecordValid( void ) +{ + BOOL status = TRUE; + U16 calcCRC = crc16( (U08*)&dgSystemGroup.dgSystemRecord, sizeof( DG_SYSTEM_RECORD_T ) - sizeof( U16 ) ); + U16 recordCRC = dgSystemGroup.dgSystemRecord.crc; + + if ( calcCRC != recordCRC ) + { + // CRC did not pass so set all values to default + dgSystemGroup.dgSystemRecord.mfgDate = 0; + dgSystemGroup.dgSystemRecord.mfgLocation = 0; + memset( dgSystemGroup.dgSystemRecord.topLevelPN, RECORD_DEFAULT_CHARACTER, sizeof( dgSystemGroup.dgSystemRecord.topLevelPN ) ); + memset( dgSystemGroup.dgSystemRecord.topLevelPN, RECORD_DEFAULT_CHARACTER, sizeof( dgSystemGroup.dgSystemRecord.topLevelPN ) ); + // Recalculate the CRC with the default values + dgSystemGroup.dgSystemRecord.crc = crc16 ( (U08*)&dgSystemGroup.dgSystemRecord, sizeof( DG_SYSTEM_RECORD_T ) - sizeof( U16 ) ); + + // Set the to FALSE since the record is not valid + status = FALSE; + } + + return status; +} + +/*********************************************************************//** + * @brief + * The isDGServiceRecordValid function checks the validity of the DG service + * record. + * @details Inputs: dgServiceGroup.dgServiceRecord + * @details Outputs: none + * @return TRUE if the DG service record is valid otherwise FALSE + *************************************************************************/ +static BOOL isDGServiceRecordValid( void ) +{ + BOOL status = TRUE; + U16 calcCRC = crc16( (U08*)&dgServiceGroup.dgServiceRecord, sizeof( DG_SERVICE_RECORD_T ) - sizeof( U16 ) ); + U16 recordCRC = dgServiceGroup.dgServiceRecord.crc; + + if ( calcCRC != recordCRC ) + { + // CRC did not pass so set all values to default + dgServiceGroup.dgServiceRecord.lastServiceEpochDate = 0; + dgServiceGroup.dgServiceRecord.serviceIntervalSeconds = RECORD_DEFAULT_SERVICE_INTERVAL_S; + // Recalculate the CRC with the default values + dgServiceGroup.dgServiceRecord.crc = crc16 ( (U08*)&dgServiceGroup.dgServiceRecord, sizeof( DG_SERVICE_RECORD_T ) - sizeof( U16 ) ); + + // Set the to FALSE since the record is not valid + status = FALSE; + } + + return status; +} + +/*********************************************************************//** + * @brief * The isDGCalibrationRecordValid function calls other functions to check * the validity of DG calibration record. * @details Inputs: dgCalibrationRecord Index: NVDataMgmtDGRecords.h =================================================================== diff -u -rb5a078a245783d10796592bd7e96ff36a5fb5a03 -rf480c73cfca65442ee51d0189370f4d464f026e7 --- NVDataMgmtDGRecords.h (.../NVDataMgmtDGRecords.h) (revision b5a078a245783d10796592bd7e96ff36a5fb5a03) +++ NVDataMgmtDGRecords.h (.../NVDataMgmtDGRecords.h) (revision f480c73cfca65442ee51d0189370f4d464f026e7) @@ -16,6 +16,7 @@ // ********** public definitions ********** #define MAX_TOP_LEVEL_PN_CHARS 10U ///< Max number of characters for top level part number. +#define MAX_TOP_LEVEL_SN_CHARS 15U ///< Max number of characters for top level serial number. /// DG pressure sensors enumeration. typedef enum dg_pressure_sensors @@ -350,7 +351,8 @@ typedef struct { U08 serviceLoc; ///< DG service location. - U32 serviceDate; ///< DG service date. + U32 lastServiceEpochDate; ///< DG last service date in epoch. + U32 serviceIntervalSeconds; ///< DG service interval in seconds. U16 crc; ///< CRC for the DG service record structure. } DG_SERVICE_RECORD_T; Index: NVDataMgmtHDRecords.h =================================================================== diff -u -rb5a078a245783d10796592bd7e96ff36a5fb5a03 -rf480c73cfca65442ee51d0189370f4d464f026e7 --- NVDataMgmtHDRecords.h (.../NVDataMgmtHDRecords.h) (revision b5a078a245783d10796592bd7e96ff36a5fb5a03) +++ NVDataMgmtHDRecords.h (.../NVDataMgmtHDRecords.h) (revision f480c73cfca65442ee51d0189370f4d464f026e7) @@ -171,7 +171,7 @@ typedef struct { U08 serviceLoc; ///< HD service location. - U32 serviceDate; ///< HD service date. + U32 lastServiceDate; ///< HD last service date. U16 crc; ///< CRC for the HD service record structure. } HD_SERVICE_RECORD_T;