From 9aa3e9ce16b9f50d1046d8854e7a837878531d1d Mon Sep 17 00:00:00 2001 From: hebe Date: Tue, 4 Jun 2013 15:51:46 +0200 Subject: [PATCH] Dem Dcm, added support for subfunction 0x03 (reportDTCSnapshotIdentification) of UDS service 0x19 (ReadDTCInformation). This required adding Dem APIs Dem_SetDTCFilterForRecords and Dem_GetNextFilteredRecord. --- diagnostic/Dcm/Dcm_Dsp.c | 34 +++++++++++++++++++--- diagnostic/Dem/Dem.c | 63 ++++++++++++++++++++++++++++++++++++++++ include/Dem.h | 5 +++- 3 files changed, 97 insertions(+), 5 deletions(-) diff --git a/diagnostic/Dcm/Dcm_Dsp.c b/diagnostic/Dcm/Dcm_Dsp.c index 5774adfd..195e936b 100644 --- a/diagnostic/Dcm/Dcm_Dsp.c +++ b/diagnostic/Dcm/Dcm_Dsp.c @@ -62,7 +62,8 @@ #define SF_INDEX 1 #define SF_LEN 1 #define PID_BUFFER_SIZE 255 // OBD - +#define DTC_LEN 3 +#define FF_REC_NUM_LEN 1 /* Read/WriteMemeoryByAddress */ #define ALFID_INDEX 1 #define ALFID_LEN 1 @@ -864,8 +865,33 @@ static Dcm_NegativeResponseCodeType udsReadDtcInfoSub_0x03(const PduInfoType *pd { Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE; - // TODO: Not supported yet - responseCode = DCM_E_REQUESTOUTOFRANGE; + uint16 numFilteredRecords = 0; + uint32 dtc = 0; + uint8 recordNumber = 0; + uint16 nofBytesCopied = 0; + (void)pduRxData; + /* @req DCM298 */ + if( (DEM_FILTER_ACCEPTED == Dem_SetDTCFilterForRecords(&numFilteredRecords)) && + ( (SID_LEN + SF_LEN + (DTC_LEN + FF_REC_NUM_LEN)*numFilteredRecords) <= pduTxData->SduLength )) { + for( uint16 i = 0; (i < numFilteredRecords) && (DCM_E_POSITIVERESPONSE == responseCode); i++ ) { + /* @req DCM299 */ + if( DEM_FILTERED_OK == Dem_GetNextFilteredRecord(&dtc, &recordNumber) ) { + /* @req DCM300 */ + pduTxData->SduDataPtr[SID_LEN + SF_LEN + nofBytesCopied++] = DTC_HIGH_BYTE(dtc); + pduTxData->SduDataPtr[SID_LEN + SF_LEN + nofBytesCopied++] = DTC_MID_BYTE(dtc); + pduTxData->SduDataPtr[SID_LEN + SF_LEN + nofBytesCopied++] = DTC_LOW_BYTE(dtc); + pduTxData->SduDataPtr[SID_LEN + SF_LEN + nofBytesCopied++] = recordNumber; + } else { + responseCode = DCM_E_REQUESTOUTOFRANGE; + } + } + } else { + responseCode = DCM_E_REQUESTOUTOFRANGE; + } + + pduTxData->SduDataPtr[0] = 0x59; // positive response + pduTxData->SduDataPtr[1] = 0x03; // subid + pduTxData->SduLength = SID_LEN + SF_LEN + nofBytesCopied; return responseCode; } @@ -1018,7 +1044,7 @@ void DspUdsReadDtcInformation(const PduInfoType *pduRxData, PduInfoType *pduTxDa { /** @req DCM248 */ // Sub function number 0 1 2 3 4 5 6 7 8 9 A B C D E F 10 11 12 13 14 15 - const uint8 sduLength[0x16] = {0, 3, 3, 6, 6, 3, 6, 4, 4, 5, 2, 2, 2, 2, 2, 3, 6, 3, 3, 3, 2, 2}; + const uint8 sduLength[0x16] = {0, 3, 3, 2, 6, 3, 6, 4, 4, 5, 2, 2, 2, 2, 2, 3, 6, 3, 3, 3, 2, 2}; Dcm_NegativeResponseCodeType responseCode = DCM_E_POSITIVERESPONSE; diff --git a/diagnostic/Dem/Dem.c b/diagnostic/Dem/Dem.c index 38cd7fa9..8058c92c 100644 --- a/diagnostic/Dem/Dem.c +++ b/diagnostic/Dem/Dem.c @@ -235,6 +235,10 @@ static boolean FFIsModified = FALSE; */ static boolean AgingIsModified = FALSE; +/* Index for keeping track of ffRecordFilter */ +static uint16 FFRecordFilterIndex; + + static void getPidData(const Dem_PidOrDidType ***pidClassPtr, FreezeFrameRecType **freezeFrame, uint16 *storeIndexPtr); static void getDidData(const Dem_PidOrDidType ***didClassPtr, FreezeFrameRecType **freezeFrame, uint16 *storeIndexPtr); static void storeOBDFreezeFrameDataPreInit(const Dem_EventParameterType * eventParam, const FreezeFrameRecType * freezeFrame); @@ -2496,6 +2500,8 @@ void Dem_Init(void) disableDtcStorage.storageDisabled = FALSE; + FFRecordFilterIndex = DEM_MAX_NUMBER_FF_DATA_PRI_MEM; + demState = DEM_INITIALIZED; } @@ -3420,6 +3426,63 @@ Dem_ReturnGetSizeOfFreezeFrameType Dem_GetSizeOfFreezeFrame(uint32 dtc,Dem_DTCK } +/** @req DEM209 */ +Dem_ReturnSetDTCFilterType Dem_SetDTCFilterForRecords(uint16 *NumberOfFilteredRecords) +{ + Dem_ReturnSetDTCFilterType ret = DEM_WRONG_FILTER; + if (demState != DEM_INITIALIZED) { + DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_SETDTCFILTERFORRECORDS_ID, DEM_E_UNINIT); + } else { + uint16 nofRecords = 0; + for( uint16 i = 0; i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM; i++ ) { + /* @req DEM210 */ /* We are searching in priMem buffer */ + if( DEM_EVENT_ID_NULL != priMemFreezeFrameBuffer[i].eventId ) { + EventStatusRecType *eventStatusRecPtr = NULL; + lookupEventStatusRec(priMemFreezeFrameBuffer[i].eventId, &eventStatusRecPtr); + if( (NULL != eventStatusRecPtr) && (NULL != eventStatusRecPtr->eventParamRef->DTCClassRef) ) { + nofRecords++; + } + } + } + *NumberOfFilteredRecords = nofRecords; + FFRecordFilterIndex = 0; + ret = DEM_FILTER_ACCEPTED; + } + return ret; +} + +/** @req DEM224 */ +Dem_ReturnGetNextFilteredDTCType Dem_GetNextFilteredRecord(uint32 *DTC, uint8 *RecordNumber) +{ + Dem_ReturnGetNextFilteredDTCType ret = DEM_FILTERED_NO_MATCHING_DTC; + + EventStatusRecType *eventStatusRecPtr = NULL; + if (demState == DEM_INITIALIZED) { + + /* Find the next record which has a DTC */ + boolean found = FALSE; + for( uint16 i = FFRecordFilterIndex; (i < DEM_MAX_NUMBER_FF_DATA_PRI_MEM) && !found; i++ ) { + if( DEM_EVENT_ID_NULL != priMemFreezeFrameBuffer[i].eventId ) { + lookupEventStatusRec(priMemFreezeFrameBuffer[i].eventId, &eventStatusRecPtr); + if( (NULL != eventStatusRecPtr) && (NULL != eventStatusRecPtr->eventParamRef->DTCClassRef)) { + /* Found one! */ + /* @req DEM225 */ + *RecordNumber = priMemFreezeFrameBuffer[i].recordNumber; + *DTC = eventStatusRecPtr->eventParamRef->DTCClassRef->DTC; + /* @req DEM226 */ + FFRecordFilterIndex = i + 1; + found = TRUE; + ret = DEM_FILTERED_OK; + } + } + } + } else { + DET_REPORTERROR(MODULE_ID_DEM, 0, DEM_GETNEXTFILTEREDRECORD_ID, DEM_E_UNINIT); + } + + return ret; +} + #if (DEM_UNIT_TEST == STD_ON) void getFFDataPreInit(FreezeFrameRecType **buf) { diff --git a/include/Dem.h b/include/Dem.h index 1f66a4d6..58d5bb58 100644 --- a/include/Dem.h +++ b/include/Dem.h @@ -100,8 +100,10 @@ #define DEM_GETDTCOFOBDFREEZEFRAME_ID 0x28 #define DEM_GETOBDFREEZEFRAMEDATA_ID 0x29 +#define DEM_GETNEXTFILTEREDRECORD_ID 0x3a #define DEM_GETTRANSLATIONTYPE_ID 0x3c #define DEM_GETFAULTDETECTIONCOUNTER_ID 0x3E +#define DEM_SETDTCFILTERFORRECORDS_ID 0x3f #define DEM_MAINFUNCTION_ID 0x55 #define DEM_UPDATE_EVENT_STATUS_ID 0x80 @@ -185,7 +187,8 @@ Dem_GetFreezeFameDataIdentifierByDTCType Dem_GetFreezeFrameDataIdentifierByDTC(u uint8* arraySize, const uint16** dataId ); Dem_ReturnGetSizeOfFreezeFrameType Dem_GetSizeOfFreezeFrame(uint32 dtc,Dem_DTCKindType dtcKind,Dem_DTCOriginType dtcOrigin,uint8 recordNumber,uint16* sizeOfFreezeFrame); - +Dem_ReturnSetDTCFilterType Dem_SetDTCFilterForRecords(uint16 *NumberOfFilteredRecords); /** @req DEM209 */ +Dem_ReturnGetNextFilteredDTCType Dem_GetNextFilteredRecord(uint32 *DTC, uint8 *RecordNumber); /** @req DEM224 */ /* * OBD-specific Interfaces (8.3.6) -- 2.39.2