UDSInterface.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /********************************************************************************
  2. * 常州易控汽车电子股份有限公司
  3. * (c) Copyright 2009-2015 ECTEK
  4. * 保留所有权利
  5. ********************************************************************************
  6. * 工程名称:整车管理
  7. * 文件名: UDSInterface.h
  8. * 功能描述 : UDS管理头文件
  9. * 引用记录:
  10. * 备注:
  11. * 修订记录:
  12. * 日期 版本 作者 描述
  13. * 2017.07.03 00.01.00 李中 第一版
  14. *******************************************************************************/
  15. #ifndef __UDSINTERFACE_G
  16. #define __UDSINTERFACE_G
  17. //#include "Std_Types.h" //19.12.16day, This is a bad move due to unknown error 把uint16的定义copy于此
  18. typedef unsigned char boolean;
  19. typedef signed char sint8;
  20. typedef unsigned char uint8;
  21. typedef signed short sint16;
  22. typedef unsigned short uint16;
  23. typedef signed long sint32;
  24. typedef unsigned long uint32;
  25. typedef float float32;
  26. typedef unsigned long uint8_least;
  27. typedef unsigned long uint16_least;
  28. typedef unsigned long uint32_least;
  29. typedef signed long sint8_least;
  30. typedef signed long sint16_least;
  31. typedef signed long sint32_least;
  32. //******************************This is a bad move due to unknown error 把uint16的定义copy于此
  33. /*UDS错误消息定义*/
  34. #define _UDS_INDEX_ERROR_GENERALREJECT 0x10
  35. #define _UDS_INDEX_ERROR_SERVICENOTSUPPORTED 0x11
  36. #define _UDS_INDEX_ERROR_SUBFUNCTIONNOTSUPPORTED 0x12
  37. #define _UDS_INDEX_ERROR_INVALIDFORMAT 0x13
  38. #define _UDS_INDEX_ERROR_BUSYREPEATREQUEST 0x21
  39. #define _UDS_INDEX_ERROR_CONDITIONNOTCORRECT 0x22
  40. #define _UDS_INDEX_ERROR_ROUTINENOTCOMPLETEORSERVICEINPROCESS 0x23
  41. #define _UDS_INDEX_ERROR_REQUESTSEQUENCEERROR 0x24
  42. #define _UDS_INDEX_ERROR_REQUESTOUTOFRANGE 0x31
  43. #define _UDS_INDEX_ERROR_SECURITYACCESSDENIED 0x33
  44. #define _UDS_INDEX_ERROR_INVALIDKEY 0x35
  45. #define _UDS_INDEX_ERROR_EXCEEDNUMBEROFATTEMPS 0x36
  46. #define _UDS_INDEX_ERROR_TIMEDELAYNOTEXPIRED 0x37
  47. #define _UDS_INDEX_ERROR_DOWNLOADNOTACCEPTED 0x40
  48. #define _UDS_INDEX_ERROR_IMPROPERDOWNLOADTYPE 0x41
  49. #define _UDS_INDEX_ERROR_CANNOTDOWNLOADTOSPECIFIEDADDRESS 0x42
  50. #define _UDS_INDEX_ERROR_CANNOTDOWNLOADNUMBEROFBYTESREQUESTED 0x43
  51. #define _UDS_INDEX_ERROR_UPLOADNOTACCEPTED 0x50
  52. #define _UDS_INDEX_ERROR_IMPROPERUPLOADTYPE 0x51
  53. #define _UDS_INDEX_ERROR_CANNOTUPLOADTOSPECIFIEDADDRESS 0x52
  54. #define _UDS_INDEX_ERROR_CANNOTUPLOADNUMBEROFBYTESREQUESTED 0x53
  55. #define _UDS_INDEX_ERROR_BLOCKTRANSFERDATACHECKSUMERROR 0x77
  56. #define _UDS_INDEX_ERROR_SUBFUNCTIONNOTSUPPORTEDINACTIVESESSION 0x7E
  57. #define _UDS_INDEX_ERROR_SERVICENOTSUPPORTEDINACTIVESESSION 0x7F
  58. #define _UDS_INDEX_ERROR_SERVICENOTSUPPORTEDINACTIVEDIAGNOSTICMODE 0x80
  59. #define _UDS_INDEX_ERROR_CHECKSUMERROR 0xFA
  60. #define _UDS_INDEX_ERROR_ECUERASINGFLASH 0xFB
  61. #define _UDS_INDEX_ERROR_ECUPROGRAMMINGFLASH 0xFC
  62. #define _UDS_INDEX_ERROR_ERASINGERROR 0xFD
  63. #define _UDS_INDEX_ERROR_PROGRAMMINGERROR 0xFE
  64. /*UDS安全等级定义*/
  65. #define _UDS_NUM_MODE_MAX 3
  66. #define _UDS_INDEX_SEC_LOCK 0
  67. #define _UDS_INDEX_SEC_EXTENTED 1
  68. #define _UDS_INDEX_SEC_ANTITHEFT 2
  69. #define _UDS_INDEX_SEC_PROGRAMMING 3
  70. /*UDS RoutineControl Control Type*/
  71. #define _UDS_ROUTINECONTROL_START 0x01
  72. #define _UDS_ROUTINECONTROL_STOP 0x02
  73. #define _UDS_ROUTINECONTROL_REQUESTRESULTS 0x03
  74. /*UDS 命令定义*/
  75. #define _UDS_INDEX_COMMAND_NULL 0
  76. /*Diagnostic Management*/
  77. #define _UDS_INDEX_COMMAND_STARTDIAGNOSTICSESSION 0x10U
  78. #define _UDS_INDEX_COMMAND_ECURESET 0x11U
  79. #define _UDS_INDEX_COMMAND_SECURITYACCESS 0x27U
  80. #define _UDS_INDEX_COMMAND_TESTERPRESENT 0x3EU
  81. #define _UDS_INDEX_COMMAND_ACCESSTIMINGPARAMERTERS 0x83U
  82. /*Data Transmission*/
  83. #define _UDS_INDEX_COMMAND_READDATABYIDENTIFIER 0x22U
  84. #define _UDS_INDEX_COMMAND_READMEMORYBYADDRESS 0x23U
  85. #define _UDS_INDEX_COMMAND_READSCALINGDATABYIDENTIFIER 0x24U
  86. #define _UDS_INDEX_COMMAND_READDATABYPERIODICIDENTIFIER 0x2AU
  87. #define _UDS_INDEX_COMMAND_DYNAMICALLYDEFINEDATAIDENTIFIER 0x2CU
  88. #define _UDS_INDEX_COMMAND_WRITEDATABYIDENTIFIER 0x2EU
  89. #define _UDS_INDEX_COMMAND_WRITEMEMORYBYADDRESS 0x3DU
  90. /*Input Output Control*/
  91. #define _UDS_INDEX_COMMAND_INPUTOUTPUTCONTROL 0x2FU
  92. /*Fault Memory*/
  93. #define _UDS_INDEX_COMMAND_READDTCINFORMATION 0x19U
  94. #define _UDS_INDEX_COMMAND_CLEARDIAGNOSTICINFORMATION 0x14U
  95. #define _UDS_INDEX_COMMAND_CONTROLDTCSETTING 0x85U
  96. /*Flash Memory Programming*/
  97. #define _UDS_INDEX_COMMAND_REQUESTUPLOAD 0x35U
  98. #define _UDS_INDEX_COMMAND_REQUESTDOWNLOAD 0x34U
  99. #define _UDS_INDEX_COMMAND_TRANSFERDATA 0x36U
  100. #define _UDS_INDEX_COMMAND_REQUESTTRANSFEREXIT 0x37U
  101. /*Remote Activation of Routine*/
  102. #define _UDS_INDEX_COMMAND_ROUTINECONTROL 0x31U
  103. /*Communication*/
  104. #define _UDS_INDEX_COMMAND_COMMUNICATIONCONTROL 0x28U
  105. #define _UDS_INDEX_POSRESP_COMMAND 0x40U
  106. /*UDS DID信息上层配置*/
  107. #define _UDS_DID_MASK_READ 0x01 //Read Enable, 0x22
  108. #define _UDS_DID_MASK_WRITE 0x02 //Write Enable, 0x2E
  109. #define _UDS_DID_MASK_CONTROL 0x04 //Control Enable, 0x2F
  110. #define _UDS_DID_MASK_ENDIANNESS 0x80 //Endianness
  111. /*UDS Session Mode定义*/
  112. #define _UDS_INDEX_DIAG_DEFAULT 0x01
  113. #define _UDS_INDEX_DIAG_PROGRAMMING 0x02
  114. #define _UDS_INDEX_DIAG_EXTENDED 0x03
  115. typedef uint8 (*pFunc_UDSIOCtrlCallback)(uint16 numRecvLenUW, uint8 * datRecvBuffUBP, uint16 * numSendLenUWP, uint8 * datSendBuffUBP);
  116. typedef struct
  117. {
  118. uint8 DataTypeUB; ///该DID的数据类型
  119. uint16 idxDataIDUW; ///DID
  120. uint32 addrDataUI; ///数据地址
  121. float32 ConvertFactor; ///该DID的转换因子 B
  122. float32 ConvertOffset; ///该DID的转换偏移量 C
  123. uint16 ConvertnumSizeUW; ///转换后的字节数
  124. uint16 numSizeUW; ///物理值字节数
  125. boolean idxByteOrderUB; ///访问时的大小端方式,0Big/1Little
  126. uint8 infoMaskReadUW; ///0x22 readID权限
  127. uint8 infoMaskWriteUW; ///0x2E writeID权限
  128. uint8 infoMaskIOCtrlUW; ///0x2F IOCtrl权限
  129. pFunc_UDSIOCtrlCallback pIOCtrlCallback;
  130. } UDSInterface_infoDIDS_TYPE; /*环境信息*/
  131. typedef struct
  132. {
  133. uint16 numDIDUW;
  134. const UDSInterface_infoDIDS_TYPE * addrEnvDataSP;
  135. } UDSInterface_infoDIDConfS_TYPE;
  136. /*UDS Routine信息上层配置*/
  137. typedef uint8 (*pFunc_UDSRoutineCallback)(uint16 numRecvLenUW, uint8 * datRecvBuffUBP, uint16 * numSendLenUWP, uint8 * datSendBuffUBP);
  138. typedef struct
  139. {
  140. uint16 idxRoutineIDUW;
  141. uint16 infoMaskUW; //与DID的Mask定义一直,使用其Control部分
  142. pFunc_UDSRoutineCallback pRoutineCallback;
  143. } UDSInterface_infoRoutineS_TYPE; /*例程信息*/
  144. typedef struct
  145. {
  146. uint8 numRoutineUB;
  147. const UDSInterface_infoRoutineS_TYPE * addrRoutineSP;
  148. } UDSInterface_infoRoutineConfS_TYPE;
  149. typedef struct
  150. {
  151. uint8 numParamIDUB;
  152. const uint16 * addrSnapshotDIDSP;
  153. } UDSInterface_infoSnapshotConfS_TYPE;
  154. uint8 UDSInterface_CheckServiceCondition(uint8 idxSIDUB, uint8 stSubFuncUB);
  155. void UDSInterface_GetSeed(uint8 idxSecLvlUB, uint8 * dataSeedUBP);
  156. void UDSInterface_GetKey(uint8 idxSecLvlUB, uint8 * dataSeedUBP, uint8 * dataKeyUBP);
  157. uint8 UDSInterface_RoutineTestCallback(uint16 numRecvLenUW, uint8 * datRecvBuffUBP, uint16 * numSendLenUWP, uint8 * datSendBuffUBP);
  158. uint8 UDSInterface_IOControlCallback(uint16 numRecvLenUW, uint8 * datRecvBuffUBP, uint16 * numSendLenUWP, uint8 * datSendBuffUBP);
  159. extern const UDSInterface_infoDIDConfS_TYPE UDSInterface_infoDIDConfS;
  160. extern const UDSInterface_infoRoutineConfS_TYPE UDSInterface_infoRoutineConfS;
  161. extern const UDSInterface_infoSnapshotConfS_TYPE UDSInterface_infoSnapshotConfS;
  162. #endif