Index: NVDataMgmt.c =================================================================== diff -u -radc3cb0c0764f1ff7d6b4b069a7edc01f3af0d47 -r4ddbc7461f66587f1669f69662274f3c8e16cc8e --- NVDataMgmt.c (.../NVDataMgmt.c) (revision adc3cb0c0764f1ff7d6b4b069a7edc01f3af0d47) +++ NVDataMgmt.c (.../NVDataMgmt.c) (revision 4ddbc7461f66587f1669f69662274f3c8e16cc8e) @@ -1165,12 +1165,17 @@ break; case GET_SRR_RECORD: - nvDataStartPtr = (U08*)&dgScheduledRunsGroup; + nvDataStartPtr = (U08*)&dgScheduledRunsGroup.dgScheduledRun; nvDataLength = sizeof( dgScheduledRunsGroup.dgScheduledRun ); break; + case GET_USAGE_RECORD: + nvDataStartPtr = (U08*)&dgUsageInfoGroup.dgUsageInfo; + nvDataLength = sizeof( dgUsageInfoGroup.dgUsageInfo ); + break; + default: - // TODO software fault + SET_ALARM_WITH_2_U32_DATA( ALARM_ID_DG_SOFTWARE_FAULT, SW_FAULT_ID_INVALID_NV_RECORD_SELECTED, nvData ); break; #endif } @@ -1580,7 +1585,7 @@ haveCalGroupsPassed = isDGCalibrationRecordValid(); hasSystemRecordPassed = isDGSystemRecordValid(); hasServiceRecordPassed = isDGServiceRecordValid(); - hasUsageRecordPassed = isDGUsageRecordValid(); // TODO add an alarm once dialin is completed in DEN-13834 + hasUsageRecordPassed = isDGUsageRecordValid(); #ifndef _RELEASE_ hasSWConfigRecordPassed = isSWConfigRecordValid(); #endif @@ -1655,7 +1660,7 @@ if ( powerOffIsImminent != TRUE ) { // Check if the service record has to be updated - //updateServiceRecord(); // TODO what is this doing here? un-comment in DEN-13834 + updateServiceRecord(); // If the record processing queue is not empty, process the queues if ( ( FALSE == isRecordQueueEmpty() ) && ( TRUE == areResourcesAvailableForNextJob() ) ) @@ -1689,7 +1694,7 @@ } } } - // TODO add the log queue later in Phase 1B. + // Add the log queue later in Phase 1B. } // Check if a queue job is available @@ -1725,7 +1730,7 @@ else if ( ( NVDATAMGMT_READ == ops ) && ( NVDATAMGMT_RTC == location ) ) { readFromRAM( startAddress, maxBufferLength ); - //currentJob.externalAddress->status = NVDATAMGMT_READ_IN_PROGRESS; // TODO Phase 1B for logging + //currentJob.externalAddress->status = NVDATAMGMT_READ_IN_PROGRESS; // Phase 1B for logging currentTime = getMSTimerCount(); state = NVDATAMGMT_EXEC_STATE_READ_FROM_RTC; @@ -1795,7 +1800,6 @@ // If timed out, get back to Idle else if ( timeoutStatus == TRUE ) { - // TODO schedule another write? recordAddressOffset = 0; state = NVDATAMGMT_EXEC_STATE_IDLE; } @@ -1974,7 +1978,6 @@ // If timed out, get back to Idle else if ( timeoutStatus == TRUE ) { - // TODO schedule another write? recordAddressOffset = 0; state = NVDATAMGMT_EXEC_STATE_IDLE; } @@ -2579,7 +2582,7 @@ *************************************************************************/ static void updateServiceRecord( void ) { - // If a new calibration is available and the service record has not been updated, updated the service record + // If a new calibration is available and the service record has not been updated, update the service record // Right now, the last service date is updated once a new calibration record is received by the service personnel if ( ( TRUE == isNewCalAvailable ) && ( FALSE == hasServiceRecordBeenUpdated ) ) { @@ -2595,6 +2598,18 @@ hasServiceRecordBeenUpdated = TRUE; } #endif +#ifdef _DG_ + dgServiceGroup.dgServiceRecord.lastServiceEpochDate = getRTCTimestamp(); + dgServiceGroup.dgServiceRecord.serviceLoc = 0; + dgServiceGroup.dgServiceRecord.crc = crc16( (U08*)&dgServiceGroup.dgServiceRecord, sizeof( DG_SERVICE_RECORD_T ) - sizeof( U16 ) ); + dgServiceGroup.crc = crc16( (U08*)&dgServiceGroup, sizeof( DG_SERVICE_RECORD_T ) - sizeof( U16 ) ); + + if ( FALSE == isQueueFull() ) + { + enqueue( NVDATAMGMT_WRITE, NVDATAMGMT_RTC, SERVICE_RECORD_NV_MEM_START_ADDRESS, (U08*)&dgServiceGroup, 0, sizeof( DG_SERVICE_RECORD_T ) ); + hasServiceRecordBeenUpdated = TRUE; + } +#endif } } @@ -2722,22 +2737,20 @@ static BOOL isDGServiceRecordValid( void ) { BOOL status = TRUE; - U16 calcCRC = crc16( (U08*)&dgServiceGroup.dgServiceRecord, sizeof(DG_SERVICE_RECORD_T) - sizeof(U16) ); + 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 ) ); + //dgServiceGroup.dgServiceRecord.lastResetTimeEpoch = getRTCTimestamp(); + dgServiceGroup.dgServiceRecord.crc = crc16 ( (U08*)&dgServiceGroup.dgServiceRecord, sizeof( DG_SERVICE_RECORD_T ) - sizeof( U16 ) ); + status = FALSE; // Service record failure is also considered as RTC RAM failure activateAlarmNoData( ALARM_ID_DG_INVALID_SERVICE_RECORD_CRC ); - - // Set the to FALSE since the record is not valid - status = FALSE; } return status; @@ -2765,9 +2778,10 @@ dgUsageInfoGroup.dgUsageInfo.roWaterGenSinceLastServiceL = 0.0; dgUsageInfoGroup.dgUsageInfo.roWaterGenTotalL = 0.0; dgUsageInfoGroup.dgUsageInfo.lastResetTimeEpoch = getRTCTimestamp(); + dgUsageInfoGroup.dgUsageInfo.crc = crc16( (U08*)&dgUsageInfoGroup, sizeof( DG_USAGE_INFO_GROUP_T ) - sizeof( U16 ) ); status = FALSE; - //activateAlarmNoData( ALARM_ID_DG_INVALID_USAGE_RECORD ); // TODO remove when dialin is implemented + activateAlarmNoData( ALARM_ID_DG_INVALID_USAGE_RECORD_CRC ); } return status;