tags: diagnosis Protocol stack
1、01 child service -Find the number of faults that match it through the status mask.
By the service diagnostic, the number of faults in the DTC status in the ECU matches the DTC status mask. If the actual status bit of a fault code is 1, and the corresponding bit in the DTC state mask is 1, then the state of the fault code is considered to match the DTC state mask (ie: if the DTC state mask byte) The result is a non-zero value after logical "bit and" operation with the DTC actual status byte, then the two matches; at this time, the number of faults is +1. If the diagnostic defines a state mask, which contains the bits that the ECU is not supported, the ECU only uses the bits supported by itself to process fault information. The request format is as follows:

After receiving the request, the ECU's response packet format is as follows:

About 19 01 Service Code Substitution is as follows (help understand, for reference only):
UINT16 DTC_GETDTCVOUNTBYSTATUSMASK (uint8 status_mask) / * Data number * /
{
uint16 Dtc_count = 0;
uint8 Record_count;
For (record_count = 0; record_count <dtc_code_max_num; record_count ++) / * Retrieves all DTC * /
{
if((Dtc_dtc_status_record[Record_count].dtc_status.status_byte & status_mask) != 0)
{
Dtc_count++;
}
}
return Dtc_count;
}
FUNC(void,DCM_CODE) App_Fault_Memory_Read_Number(P2VAR(Dcm_MsgContextType,AUTOMATIC,DCM_APPL_DATA) pMsgContext)
{
uint16 Counter = 0U;
uint8 DtcStatus_Temp;
DTCSTATUS_TEMP = PMSGCONTEXT-> Reqdata [DCM_INDEX_2]; / * Send a state mask through the 1901 service third byte; * /
Counter = DTC_GetdtcountByStatusmask (DTCSTATUS_TEMP); / * Number of DTCs matching in the ECU according to the statistics of the state mask (code above) * /
PMSGCONTEXT-> Resdata [DCM_INDEX_2] = DTCSTATUSAVAILABILITYMASK; / * Returns the status bit supported by ECU * /
/* Change below data if necessary */
/* 0x00 ISO15031-6Format,0x01 ISO14229-1Format,0x02 J1939 Format */
PMSGCONTEXT-> Resdata [DCM_INDEX_3] = 0x00U; / * Returns the DTC format identifier used by the ECU,
00:15031-6;01:14229-1;02:J1939*/
PMSGCONTEXT-> Resdata [DCM_INDEX_4] = (uint8) (counter >> 8U); / * Return to the DTC number * /
pMsgContext->resData[DCM_INDEX_5] = (uint8)(Counter);
/* Always equals 6, don't change it */
pMsgContext->resDataLen = 6U;
DsdInternal_ProcessingDone(pMsgContext);
}
PS: The DTC status mask parameter contains 8 DTC status bits, and its bit is defined as follows:

2,02 child service
Find the matching fault in the form of the defined state mask, return the matching DTC identifier (3 bytes), DTC status (1 byte) information. The 01 sub-service of the last section is only statistically with the number of DTCs that match the status mask, and the 02 sub-service returns these matching DTC information. The request format is as follows:

After receiving the request, the ECU's response packet format is as follows:

About 19 02 service code part is, for example, (help understand, for reference only):
UINT16 DTC_GETDTCBYSTATUSMASK (uint8 * p_dtc, uint8 status_mask) / * Returns the DTC information * /
{
uint16 dtc_count = 0;
uint8 record_count;
for(record_count = 0; record_count < DTC_CODE_MAX_NUM; record_count++)
{
if((Dtc_dtc_status_record[record_count].dtc_status.status_byte & status_mask) != 0)
{
*p_dtc++ = Dtc_dtc_code_data[record_count].dtc_high_byte;
*p_dtc++ = Dtc_dtc_code_data[record_count].dtc_middle_byte;
*p_dtc++ = Dtc_dtc_code_data[record_count].dtc_low_byte;
*p_dtc++ = Dtc_dtc_status_record[record_count].dtc_status.status_byte;
dtc_count++;
}
}
return dtc_count;
}
FUNC(void,DCM_CODE) App_Fault_Memory_Read_identified_errors(P2VAR(Dcm_MsgContextType,AUTOMATIC,DCM_APPL_DATA) pMsgContext)
{
uint16 counter = 0U;
uint8 DtcStatus_Temp;
DTCSTATUS_TEMP = PMSGCONTEXT-> Reqdata [DCM_INDEX_2]; / * Send a state mask through the 1902 service third byte; * /
/ * Follow the statistics of the state mask statistics ECU to match the DTC, return to its DTC information (code as above) * /
counter = DTC_GetDtcByStatusMask(&(pMsgContext->resData[DCM_INDEX_3]),DtcStatus_Temp);
PMSGCONTEXT-> Resdata [DCM_INDEX_2] = DTCSTATUSAVAILABILITYMASK; / * Returns the status bit supported by ECU * /
PMSGCONTEXT-> Resdatalen = DCM_INDEX_3 + (Counter * 4U); / * Update the length of the response message; * /
DsdInternal_ProcessingDone(pMsgContext);
}
3,04 sub-service
In order to facilitate finding the cause, the vehicle factory generally defines some information as snapshot information, such as the time of failure, voltage, driving mileage, speed, etc. When the corresponding fault occurs, the ECU end is to record the snapshot information when the fault occurs; and the 04 service is the snapshot information for requesting a specified fault code (DTC), and analyzes the cause of the failure by looking up the fault time. The request format is as follows:

Among them, DTCSNAPShotRecordNumber represents the DTC snapshot record code, accounting for one byte, indicating a specific DTC snapshot data record number. OE Snapshot information.
If the ECU supports multiple DTC snapshot data records, the record code should use the value within the range of 0x01 ~ 0xFe. When the parameter value is ff HEX, the ECU is required to report all stored DTC snapshot data records at once.
After receiving the request, the ECU's response packet format is as follows:

As above, the response packets DTCSNAPSHOTRECORDNUMBER indicates which snapshot record of the DTC; DTCSNAPShotRecordNumberOfidentifiers indicates the number of members defined in the snapshot information; if the defined snapshot data has four information, voltage, speed, and mileage; 4.
As described below, it is assumed that there are two snapshot record information, and the number of members of the snapshot record has four; the diagnostic code design of the corresponding 19 04 service is as follows (help understand, for reference only):
FUNC(void,DCM_CODE) App_Fault_Memory_Read_snapshot(P2VAR(Dcm_MsgContextType,AUTOMATIC,DCM_APPL_DATA) pMsgContext)
{
uint8 error = 0U;
uint32 Dtc;
uint32 i;
uint8 DTCSnapshotRecordNumber;
uint8 DTCSnapshotRecordLength = 0U;
uint8 status = 0U;
uint8 snap_data_len = 0U;
DTCSnapshotRecordNumber = pMsgContext->reqData[DCM_INDEX_5];
Dtc = Make32Bit(pMsgContext->reqData[DCM_INDEX_2], pMsgContext->reqData[DCM_INDEX_3], pMsgContext->reqData[DCM_INDEX_4]);
/* Check DTC */
Error = DTC_GetStatusBydtcNumber (DTC, & status); / * Get the status bit of the DTC, stored in Status * /
if(error == 0U)
{
PMSGCONTEXT-> Resdata [DCM_INDEX_5] = status; / * Returns the status bit of the DTC * /
if(Dtc_Fault_IsConfirmed(status))
{
switch(DTCSnapshotRecordNumber)
{
/* Add your code here. Below codes should be changed as Spec */
Case 0x01: / * Returns the snapshot record information of the corresponding number * /
case 0x02:
{
PMSGCONTEXT-> Resdata [DCM_INDEX_6] = DTCSNAPSHOTRECORDNUMBER; / * Snapshot record code * /
PMSGCONTEXT-> Resdata [DCM_INDEX_7] = 4U; / * The number of snapshot members * /
/ * Get the ID information of the snapshot member, value information; from PMSGCONTEXT-> Resdata [DCM_INDEX_8], start storage * /
DTC_GetDtcSnapData(DTCSnapshotRecordNumber, &pMsgContext->resData[DCM_INDEX_8], Dtc, &snap_data_len);
DTCSNAPSHOTRECORDLENGTH = DCM_INDEX_8 + SNAP_DATA_LEN; / * Update Response Packet Length * /
break;
}
Case 0xff: / * Return to all snapshot record information * /
{
PMSGCONTEXT-> Resdata [DCM_INDEX_6] = 0x01; / * The first snapshot record * /
PMSGCONTEXT-> Resdata [DCM_INDEX_7] = 4U; / * The number of snapshot members * /
DTCSnapshotRecordLength = DCM_INDEX_8;
/ * Get the ID information, numerical information of the first snapshot member; * /
DTC_GetDtcSnapData(0x01, &pMsgContext->resData[DTCSnapshotRecordLength], Dtc, &snap_data_len);
DTCSnapshotRecordLength += snap_data_len;
PMSGCONTEXT-> Resdata [DTCSNAPSHOTRECORDLENGTH ++] = 0x02; / * Second snapshot record * /
pMsgContext->resData[DTCSnapshotRecordLength++] = 4U;
/ * Get the ID information, numerical information of the second snapshot member; * /
DTC_GetDtcSnapData(0x02, &pMsgContext->resData[DTCSnapshotRecordLength], Dtc, &snap_data_len);
DTCSNAPSHOTRECORDLENGTH + = SNAP_DATA_LEN; / * Update the length of the response message * /
break;
}
default:
{
DsdInternal_SetNegResponse(pMsgContext,DCM_E_REQUESTOUTOFRANGE);
error = 1U;
break;
}
}
}
else
{
DTCSnapshotRecordLength = 6u;
}
}
else
{
DsdInternal_SetNegResponse(pMsgContext,DCM_E_REQUESTOUTOFRANGE);
}
if(error == 0U)
{
pMsgContext->resDataLen = DTCSnapshotRecordLength;
DsdInternal_ProcessingDone(pMsgContext);
}
else
{
DsdInternal_ProcessingDone(pMsgContext);
}
}
4,06 child service
In addition to the snapshot information introduced in the previous 04 service; generally define an extension information, some other information used to record the fault, such as the number of times of failure, number of aging, number of ages, etc. The 06 service that will be introduced is to request an extension information for the specified fault code (DTC). The request format is as follows:

Among them, DTCEXTendedDataRecordNumber represents the extended data record code, accounting for one byte, indicating the number of specified fault code extended data records for the diagnostic request. (I.e., the proportional data specified in the fault code to be requested)
After receiving the request, the ECU's response packet format is as follows:

Take the first expansion data record as an example, about 19 06 service code part is, for example, (help understand, for reference only):
FUNC(void,DCM_CODE) App_Fault_Memory_Read_DTC_Extended_Data_Records_By_DTC_Number(P2VAR(Dcm_MsgContextType,AUTOMATIC,DCM_APPL_DATA) pMsgContext)
{
uint8 error = 0U;
uint32 Dtc;
uint8 status = 0;
uint8 extern_data_len = 0;
/* change below length according to App*/
if(pMsgContext->reqData[DCM_INDEX_5] >= 1U)
{
Dtc = Make32Bit(pMsgContext->reqData[DCM_INDEX_2], pMsgContext->reqData[DCM_INDEX_3], pMsgContext->reqData[DCM_INDEX_4]);
/* Check DTC */
Error = DTC_GetStatusBydtcNumber (DTC, & status); / * Get the status bit of the DTC, stored in Status * /
if(error == 0U)
{
PMSGCONTEXT-> Resdata [DCM_INDEX_5] = status; / * Returns the status bit of the DTC * /
}
else
{
DsdInternal_SetNegResponse(pMsgContext,DCM_E_REQUESTOUTOFRANGE);
}
}
else
{
error = 1U;
DsdInternal_SetNegResponse(pMsgContext,DCM_E_REQUESTOUTOFRANGE);
}
if(error == 0U)
{
PMSGCONTEXT-> Resdata [DCM_INDEX_6] = 0x01; / * Extended data record code, DTCEXTENDDATARECORDNUMBER * /
DTC_GetdTCEXTERNDATA (& (PMSGCONTEXT-> Resdata [DCM_INDEX_7]), DTC, & Extern_Data_len; / * This function goes to get extended data information, you define * /
PMSGCONTEXT-> Resdatalern = DCM_INDEX_7 + EXTERN_DATA_LEN; / * Update Return Packet length * /
DsdInternal_ProcessingDone(pMsgContext);
}
else
{
DsdInternal_ProcessingDone(pMsgContext);
}
}
5,0a child service
This service is used to request all supported DTC information (3-byte DTC identifier +1 byte DTC status bit), its response message is consistent with the 02 service; but to distinguish, the service returns all DTC information The 02 service is a DTC information that returns a state mask phase with the request when the request is not 0. The request format is as follows:

After receiving the request, the ECU's response packet format is as follows:

About 19 0A service code part is, for example, (help understand, for reference only):
Void DTC_GetsupportedDTC (uint8 * p_dtc, uint16 * pcount) / * Returns all supported DTC information * /
{
uint8 record_count;
uint8 *pDtc = NULL;
if((p_dtc == NULL) || (pCount == NULL))
{
return;
}
pDtc = p_dtc;
*pCount = 0;
for(record_count = 0; record_count < DTC_CODE_MAX_NUM; record_count++)
{
*pDtc++ = DTC_dtc_code_data[record_count].dtc_high_byte;
*pDtc++ = DTC_dtc_code_data[record_count].dtc_middle_byte;
*pDtc++ = DTC_dtc_code_data[record_count].dtc_low_byte;
*pDtc++ = DTC_dtc_status_record[record_count].dtc_status.status_byte;
(*pCount)++;
}
}
FUNC(void,DCM_CODE) App_Fault_Memory_Read_supported_errors(P2VAR(Dcm_MsgContextType,AUTOMATIC,DCM_APPL_DATA) pMsgContext)
{
uint16 count = 0;
PMSGCONTEXT-> Resdata [DCM_INDEX_2] = DTCSTATUSAVAILABILITYMASK; / * Returns the status bit supported by ECU * /
DTC_GETSUPPORTEDDTC (& PMSGCONTEXT-> Resdata [DCM_INDEX_3], & Count); / * Returns all supported DTC information * /
PMSGCONTEXT-> Resdatalen = 3u + Count * 4u; / * Update the length of the response message * /
DsdInternal_ProcessingDone(pMsgContext);
}
2,14 Service --- Clear DiagnosticInformation
14 Services is used to clear the stored troubleshooting information, which is simple. The request format is as follows:

GroupOfDTC represents a certain type of diagnosis fault code (such as power P, body B, and chassis C) to be cleared), or a particular fault code to be cleared; consist of 3 bytes.
After receiving the request, the ECU's response packet format is as follows:

Service fault tolerance background In the micro service architecture, we divide the business into one service, and serve the services can be called each other, but due to the network reasons or their ...
Table of contents 1 OBD DTC format structure 2 UDS DTC format structure 3 Body system groupings Body system groupings 4 Chassis system groupings Chassis system group 5 Powertrain system groupings Powe...
First look at the initScheduledTasks function of DiscoveryClient, you can see that there are two timed tasks, namely "service acquisition" and "service renewal". From the source co...
DiagnosticSessionControl(0x10) Client request control with a diagnostic session of a server Support child function Some diagnostic services of the ECU must be performed in the specified diagnostic ses...
Service fault Service fault tolerance background: The service fault is highly distributed. In the micro service structure, the service can be called between services, but because of the reason or thei...
4. Diagnostic typical services (3)—Read fault information functional unit (storage data transmission functional unit) I have compiled a table myself.No points download, corresponding learning, b...
Judgment of the negative response code of the unified diagnosis service NRC and priority for all diagnostic services NRC and priority for diagnostic services with functional parameters The NRC priorit...
ClearDiagnosticInformationIt is to clear the diagnostic information service. Simply put, the client can use this service to clear the diagnostic information in the memory of one or more servers. Table...
What is a service downgrade? When the server pressure is increased, according to the actual business situation and traffic. Treatment of non-processing or transformation of some services and pages wit...
Article directory Service downgrade Service blow Hystrix in Feign Monitoring (Hystrix Dashboard) In the microservices architecture, there are usually multiple service layer calls. When a service layer...