Virtual Box 7.0 Ubuntu 18.04 cmake version 3.10.2 gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
DCM的功能,主要是接收Tcp/IP传入的数据,从中提取服务ID,然后处理对应的服务,这里以0x19服务为例进行说明,sub-function:0x01
1、定义所需变量
定义服务:
//define SID #define UDS_SESSION_CONTROL 0x10 #define UDS_ECU_RESET 0x11 #define UDS_CLEAR_DIAGNOSTIC_INFOR 0x14 #define UDS_READ_DTC_INFOR 0x19 #define UDS_READ_DATA_BY_IDENTIFIER 0x22 #define UDS_READ_MEMORY_BY_ADDRESS 0x23 #define UDS_SECURITY_ACCESS 0x27 #define UDS_COMMUNICATION_CONTROL 0x28 #define UDS_WRITE_DATA_BY_IDENTIFIER 0x2E #define UDS_ROUTINE_CONTROL 0x31 #define UDS_REQUEST_DOWNLOAD 0x34 #define UDS_TRANSFER_DATA 0x36 #define UDS_REQUEST_TRANSFER_EXIT 0x37 #define UDS_TESTER_PRESENT 0x3E #define UDS_CONTROL_DTC_SETTING 0x85
定义sub-function:
//define 0x19 subfunction typedef enum { R_NUMBER_DTC_BY_STATUS_MASK = 0x01, R_DTC_BY_STATUS_MASK = 0x02, R_DTC_SNAPSHOT_IDENTIFICATION = 0x03, R_DTC_SNAPSHOT_RECORD_BY_DTC_NEMUBER = 0x04, R_DTC_EXT_DATA_RECORD_BY_DTC_NEMUBER = 0x06, R_SUPPORTED_DTC = 0x0A, }Sever_0x19_SubFunction;
2、实现API
SelectionSID实现:
void SelectionSID(u_uint8_t *buffer, u_uint16_t len) { u_uint8_t sid = buffer[0]; printf("SelectionSID:0x%02X\r\n", sid); switch(sid) {
//其它服务的实现 #ifdef SEVER_READ_DTC_INFORMATION case UDS_READ_DTC_INFOR: ReadDTCInformation_0x19(buffer, len); break; #endif
//其它服务的实现
default: break; } }
ReadDTCInformation_0x19的实现:
#ifdef SEVER_READ_DTC_INFORMATION void ReadDTCInformation_0x19(u_uint8_t *buffer, u_uint16_t len) { u_uint8_t DTCStatusMask; u_uint16_t dataLen = 0; u_uint32_t DTC = 0; UDS_State_Flag res; switch (buffer[1]) { #ifdef REPORT_NO_OF_DTC_BY_STATUS_MASK case R_NUMBER_DTC_BY_STATUS_MASK: if (3 == len) { DTCStatusMask = buffer[2]; res = CallBack_ReportNumberOfDTCByStatusMask(DTCStatusMask, &buffer[2]); dataLen = 6; } else { res = SE_LORF; } break; #endif //其它sub-function的实现 default: res = SE_FS; break; } } #endif
至于CallBack_ReportNumberOfDTCByStatusMask,在后面的配置文件中,有介绍。
标签:UDS,DCM,0x19,--,DTC,buffer,READ,define From: https://www.cnblogs.com/liuqiongcn/p/17265618.html