i15765app.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262
  1. #include "UDS.h"
  2. #include <string.h>
  3. uint8_t status_rq;
  4. const uint16_t TIMEOUT_TX_S = 70;// ((uint16_t)700/I15765CFG_TICK_PERIOD) /* tx of CAN frm */
  5. const uint16_t TIMEOUT_TX_R = 70;// ((uint16_t)700/I15765CFG_TICK_PERIOD) /* tx of CAN frm */
  6. const uint16_t TIMEOUT_FC_S = 150;//((uint16_t)1500/I15765CFG_TICK_PERIOD) /* rx of FC */
  7. const uint16_t TIMEOUT_FC_R = 20;//((uint16_t)200/I15765CFG_TICK_PERIOD) /* tx of FC */
  8. const uint16_t TIMEOUT_CF_S = 70;//((uint16_t)700/I15765CFG_TICK_PERIOD) /* tx of CF */
  9. const uint16_t TIMEOUT_CF_R = 150;//((uint16_t)1500/I15765CFG_TICK_PERIOD) /* rx of CF */
  10. /* update period (1 ms units) */
  11. const uint16_t I15765CFG_TICK_PERIOD = 1; //ms
  12. const uint8_t UDS_CAN_COM = 0;
  13. const uint32_t UDS_TX_MAILBOX = 0;
  14. const uint32_t UDS_ECU_RX_MAILBOX = 13;
  15. const uint32_t UDS_RX_MAILBOX_FUNCTION = 14; //UDS
  16. const uint32_t UDS_RX_MAILBOX_PHYSICAL = 15; //UDS mailbox 0x7DF
  17. const uint32_t UDS_RX_ID = 0x701;
  18. const uint32_t UDS_TX_ID = 0x709;
  19. const uint8_t BUFFER_DATA_LAST = 0x55;
  20. const uint8_t BS = 0;//0x08; //Block size
  21. const uint8_t STmin = 1;//0x14; //Minimum Separation Time
  22. const uint64_t Error_DTC_All = B0 | B1 | B2 | B3 | B4 | B5 | B6 | B7 | B8 | B9 | B10 | B11 | B12 | B13 | B14 | B15 | B16 | B17 | B18 | B19 | B20 | B21 | B22;
  23. /*
  24. ** Initialization routine.
  25. */
  26. void i15765app_init(void)
  27. {
  28. DiagnosticSessionType = 0x02;
  29. }
  30. /*
  31. ** Indicates a message has been received
  32. ** INPUT: msg - pointer to the message
  33. */
  34. #if 0
  35. void i15765app_process(i15765_t *msg)
  36. {
  37. //SID ������ж� data[1]
  38. switch (msg->buf[0])
  39. {
  40. //��ϻỰ����
  41. case 0x10:
  42. {
  43. SID_10_function(msg);
  44. break;
  45. }
  46. //��ص�Ԫ��λ
  47. case 0x11:
  48. {
  49. SID_11_function(msg);
  50. break;
  51. }
  52. //��������Ϣ
  53. case 0x14:
  54. {
  55. SID_14_function(msg);
  56. break;
  57. }
  58. //��ȡ DTC ��Ϣ
  59. case 0x19:
  60. {
  61. SID_19_function(msg);
  62. break;
  63. }
  64. //��ȡ����
  65. case 0x22:
  66. {
  67. SID_22_function(msg);
  68. break;
  69. }
  70. //��ȫ����
  71. case 0x27:
  72. {
  73. SID_27_function(msg);
  74. break;
  75. }
  76. //ͨ�ſ���
  77. case 0x28:
  78. {
  79. SID_28_function(msg);
  80. break;
  81. }
  82. //д������ �谲ȫ����
  83. case 0x2E:
  84. {
  85. SID_2E_function(msg);
  86. break;
  87. }
  88. /*
  89. //����������� �谲ȫ����
  90. case 0x2F:
  91. {
  92. SID_2F_function(msg);
  93. }
  94. */
  95. //���̿��� �谲ȫ����
  96. case 0x31:
  97. {
  98. SID_31_function(msg);
  99. break;
  100. }
  101. //�������� �谲ȫ����
  102. case 0x34:
  103. {
  104. SID_34_function(msg);
  105. break;
  106. }
  107. //���ݴ��� �谲ȫ����
  108. case 0x36:
  109. {
  110. SID_36_function(msg);
  111. break;
  112. }
  113. //�����˳����� �谲ȫ����
  114. case 0x37:
  115. {
  116. SID_37_function(msg);
  117. break;
  118. }
  119. //����豸���� �谲ȫ����
  120. case 0x3E:
  121. {
  122. SID_3E_function(msg);
  123. break;
  124. }
  125. //���� DTC ����
  126. case 0x85:
  127. {
  128. SID_85_function(msg);
  129. break;
  130. }
  131. default:
  132. {
  133. if (msg->tat == I15765_TAT_NP11)
  134. {
  135. NegativeResponse(msg->buf[0], 0x11); //���ij��ȴ�����߸�ʽ�Ƿ�
  136. break;
  137. }
  138. }
  139. }
  140. }
  141. #else
  142. #define MAX_MSG_LENGTH 4096
  143. i15765_t msg_new = {0};
  144. uint8_t msg_new_buf[MAX_MSG_LENGTH];
  145. uint8_t SID_11_flag = 0;
  146. uint8_t SID_2E_flag = 0;
  147. uint8_t SID_31_flag = 0;
  148. uint8_t SID_34_flag = 0;
  149. uint8_t SID_36_flag = 0;
  150. uint8_t SID_37_flag = 0;
  151. void i15765app_process(i15765_t *msg)
  152. {
  153. msg_new.buf_len = msg->buf_len;
  154. msg_new.ID = msg->ID;
  155. // 深拷贝缓冲区
  156. memcpy(msg_new_buf, msg->buf, msg->buf_len);
  157. msg_new.buf = msg_new_buf; // 指向我们的缓冲区
  158. switch (msg->buf[0])
  159. {
  160. case 0x11:
  161. {
  162. SID_11_flag = 1;
  163. // SID_11_function(msg);
  164. break;
  165. }
  166. case 0x2E:
  167. {
  168. SID_2E_flag = 1;
  169. // SID_2E_function(msg);
  170. break;
  171. }
  172. case 0x31:
  173. {
  174. SID_31_flag = 1;
  175. // SID_31_function(msg);
  176. break;
  177. }
  178. case 0x34:
  179. {
  180. SID_34_flag = 1;
  181. // SID_34_function(msg);
  182. break;
  183. }
  184. case 0x36:
  185. {
  186. SID_36_flag = 1;
  187. // SID_36_function(msg);
  188. break;
  189. }
  190. case 0x37:
  191. {
  192. SID_37_flag = 1;
  193. // SID_37_function(msg);
  194. break;
  195. }
  196. default:
  197. {
  198. if (msg->tat == I15765_TAT_NP11)
  199. {
  200. NegativeResponse(msg->buf[0], 0x11);
  201. break;
  202. }
  203. }
  204. }
  205. }
  206. void check_SID_run(void)
  207. {
  208. if(SID_11_flag == 1)
  209. {
  210. SID_11_flag = 0;
  211. SID_11_function(&msg_new);
  212. }
  213. if(SID_31_flag == 1)
  214. {
  215. SID_31_flag = 0;
  216. SID_31_function(&msg_new);
  217. }
  218. if(SID_34_flag == 1)
  219. {
  220. SID_34_flag = 0;
  221. SID_34_function(&msg_new);
  222. }
  223. if(SID_36_flag == 1)
  224. {
  225. SID_36_flag = 0;
  226. SID_36_function(&msg_new);
  227. }
  228. if(SID_37_flag == 1)
  229. {
  230. SID_37_flag = 0;
  231. SID_37_function(&msg_new);
  232. }
  233. }
  234. #endif