dev_can.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. #include "dev_can.h"
  2. #include "J1939.H"
  3. #include "core_cmFunc.h"
  4. #include "dev_can_id.h"
  5. #include "dev_iap.h"
  6. #include "hal_can.h"
  7. #include "hal_conf.h"
  8. #include "queue.h"
  9. #include <stdint.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. queue_entry(pdu_tag, 40) can_rx_queue;
  13. queue_entry(pdu_tag, 40) can_tx_queue;
  14. uint8_t PGN_00B000H_Ary[20] = {0};
  15. extern void j1939_msg_push_queue(p_pdu_tag rec_msg);
  16. double pow_branch(double x, long long N)
  17. {
  18. double ans = 1.0;
  19. // 贡献的初始值为 x
  20. double x_contribute = x;
  21. // 在对 N 进行二进制拆分的同时计算答案
  22. while (N > 0)
  23. {
  24. if (N % 2 == 1)
  25. {
  26. // 如果 N 二进制表示的最低位为 1,那么需要计入贡献
  27. ans *= x_contribute;
  28. }
  29. // 将贡献不断地平方
  30. x_contribute *= x_contribute;
  31. // 舍弃 N 二进制表示的最低位,这样我们每次只要判断最低位即可
  32. N = N >> 1;
  33. }
  34. return ans;
  35. }
  36. double pow(double x, double N)
  37. {
  38. return N >= 0 ? pow_branch(x, N) : 1.0 / pow_branch(x, -N);
  39. }
  40. uint8_t recv_can_id = 0;
  41. static uint64_t base_data;
  42. void data_bit_move(uint8_t start_bit, uint8_t bit_len, uint64_t data)
  43. {
  44. uint64_t mask = 0;
  45. uint64_t source_data = (uint64_t)data;
  46. mask = pow(2, bit_len) - 1;
  47. base_data |= (mask & source_data) << start_bit;
  48. }
  49. void product_array(uint8_t send_array[8])
  50. {
  51. send_array[0] = (uint8_t)base_data;
  52. send_array[1] = (uint8_t)(base_data >> 8);
  53. send_array[2] = (uint8_t)(base_data >> 16);
  54. send_array[3] = (uint8_t)(base_data >> 24);
  55. send_array[4] = (uint8_t)(base_data >> 32);
  56. send_array[5] = (uint8_t)(base_data >> 40);
  57. send_array[6] = (uint8_t)(base_data >> 48);
  58. send_array[7] = (uint8_t)(base_data >> 56);
  59. base_data = 0;
  60. }
  61. uint8_t push_can_message_to_queue(uint32_t id, uint8_t len, uint8_t *p_data)
  62. {
  63. pdu_tag response_msg;
  64. QUEUE_STATUS result_status;
  65. response_msg.id.r = id;
  66. response_msg.reg.dlc = len;
  67. memcpy(&response_msg.data.u8_buf[0], p_data, len);
  68. if (id > 0x7FF)
  69. {
  70. response_msg.reg.ide = CAN_Id_Extended;
  71. }
  72. else
  73. {
  74. response_msg.reg.ide = CAN_Id_Standard;
  75. }
  76. #if 1
  77. __disable_irq();
  78. en_queue(&can_tx_queue, response_msg, result_status);
  79. // result_status = en_queue(&can_tx_queue, response_msg);
  80. __enable_irq();
  81. if (result_status != Q_OK)
  82. {
  83. return 0;
  84. }
  85. #else
  86. en_queue(can_tx, &response_msg, 1);
  87. #endif
  88. return 1;
  89. }
  90. static uint8_t can_tx_frame(pdu_tag can_message)
  91. {
  92. uint8_t result = CAN_TxStatus_NoMailBox;
  93. result = hal_can_msg_tx(can_message.id.r, can_message.reg.ide, can_message.data.u8_buf, can_message.reg.dlc);
  94. return result;
  95. }
  96. // void can_tx_stop(CAN_TypeDef *can_perpiph, u8 mailbox_number)
  97. // {
  98. // can_tx_mail_box_stop(can_perpiph, mailbox_number);
  99. // }
  100. // QUEUE_STATUS can_tx_process(p_can_queue_tag p_queue)
  101. // {
  102. // u8 mailbox_number = 0;
  103. // u8 query_result = CAN_TxStatus_NoMailBox;
  104. // if (queue_empty(p_queue))
  105. // return Q_OK;
  106. // mailbox_number = can_tx_frame(p_queue->can_message[p_queue->tail]);
  107. // if (mailbox_number == CAN_TxStatus_NoMailBox)
  108. // return Q_OK;
  109. // query_result = can_tx_mail_box_state(CAN1, mailbox_number);
  110. // if (query_result == CAN_TxStatus_Ok || query_result == CAN_TxStatus_Pending)
  111. // {
  112. // p_queue->tail = (p_queue->tail + 1) % MAX_QSIZE;
  113. // p_queue->count--;
  114. // return Q_OK;
  115. // }
  116. // return Q_ERR;
  117. // }
  118. void can_tx_callback(void)
  119. {
  120. pdu_tag tx_data;
  121. // de_queue(can_tx, &tx_data);
  122. QUEUE_STATUS result_status;
  123. de_queue(&can_tx_queue, tx_data, result_status);
  124. if (result_status == Q_OK) // 返回值为1代表读取成功
  125. {
  126. can_tx_frame(tx_data);
  127. CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
  128. }
  129. else
  130. {
  131. CAN_ITConfig(CAN1, CAN_IT_TME, DISABLE);
  132. }
  133. }
  134. void can_rx_callback(CanRxMsg rx_message)
  135. {
  136. pdu_tag data;
  137. uint8_t ps;
  138. uint8_t pf;
  139. QUEUE_STATUS result;
  140. switch (rx_message.ExtId)
  141. {
  142. case 0x18011801:
  143. data.id.r = 0x18011801;
  144. data.reg.dlc = rx_message.DLC;
  145. memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
  146. // en_queue(&can_rx_queue, data);
  147. en_queue(&can_rx_queue, data, result);
  148. // case 0x18DFF4E1:
  149. // data.id.r = 0x18DFF4E1;
  150. // data.reg.dlc = rx_message.DLC;
  151. // memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
  152. // // en_queue(&can_rx_queue, data);
  153. // en_queue(&can_rx_queue, data, result);
  154. case 0x18011802:
  155. data.id.r = 0x18011802;
  156. data.reg.dlc = rx_message.DLC;
  157. memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
  158. #if 1
  159. // en_queue(&can_rx_queue, data);
  160. en_queue(&can_rx_queue, data, result);
  161. #else
  162. en_queue(can_rx, &data, 1);
  163. #endif
  164. break;
  165. default:
  166. pf = (rx_message.ExtId & CAN_PGN_PF) >> 16;
  167. if (pf >= 0xF0)
  168. {
  169. data.id.r = rx_message.ExtId;
  170. recv_can_id = data.id.b.sa;
  171. memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
  172. en_queue(&can_rx_queue, data, result);
  173. }
  174. else
  175. {
  176. ps = (rx_message.ExtId & CAN_PGN_PS) >> 8;
  177. if (ps == 0xF4)
  178. {
  179. data.id.r = rx_message.ExtId;
  180. recv_can_id = data.id.b.sa;
  181. data.reg.dlc = rx_message.DLC;
  182. memcpy(&data.data.u8_buf[0], rx_message.Data, rx_message.DLC);
  183. if (data.id.b.pf == g_can_iap)
  184. {
  185. en_queue(&can_rx_queue, data, result);
  186. }
  187. else
  188. {
  189. en_queue(&can_rx_queue, data, result);
  190. }
  191. }
  192. else
  193. {
  194. en_queue(&can_rx_queue, data, result);
  195. }
  196. }
  197. }
  198. }
  199. uint8_t tx_flag = 0;
  200. void can_rx_ctl(pdu_tag rec_msg)
  201. {
  202. // rec_msg.data.u8_buf[0];
  203. // LED2 = !LED2;
  204. J1939_TP_TX_Message(0x00B300, 0xE1, PGN_00B000H_Ary, 20, 1);
  205. }
  206. uint8_t tx_data[8] = {0};
  207. uint8_t flag = 0;
  208. void can_rx_param(pdu_tag rec_msg)
  209. {
  210. // LED2 = !LED2;
  211. tx_data[0] = rec_msg.data.u8_buf[0];
  212. tx_data[1] = rec_msg.data.u8_buf[1];
  213. tx_data[2] = rec_msg.data.u8_buf[2];
  214. tx_data[3] = rec_msg.data.u8_buf[3];
  215. if (tx_data[1] = 0xFF)
  216. {
  217. tx_flag = 1;
  218. }
  219. else
  220. {
  221. flag = 1;
  222. }
  223. // push_can_message_to_queue(rec_msg.id.r, rec_msg.reg.dlc, rec_msg.data.u8_buf);
  224. }
  225. void can_rx_update(pdu_tag rec_msg)
  226. {
  227. if ((rec_msg.data.u8_buf[0] == 'A') && (rec_msg.data.u8_buf[1] == 'P') && (rec_msg.data.u8_buf[2] == 'P') && (rec_msg.data.u8_buf[3] == 'L') && (rec_msg.data.u8_buf[4] == 'O') && (rec_msg.data.u8_buf[5] == 'A') && (rec_msg.data.u8_buf[6] == 'D') && (rec_msg.data.u8_buf[7] == 0x01))
  228. {
  229. __set_FAULTMASK(1); // 关闭所有中断
  230. NVIC_SystemReset(); // 复位
  231. }
  232. }
  233. #define ota_id 0xDF
  234. can_rx_tab can_tab[] = {
  235. 0x18011802,
  236. can_rx_param,
  237. 0x18011801,
  238. can_rx_ctl,
  239. ota_id,
  240. iap_rec_handler,
  241. };
  242. #define REG32(addr) (*(volatile uint32_t *)(uint32_t)(addr))
  243. #define CAN_INTEN(canx) REG32((canx) + 0x14U)
  244. void can_start_send(void)
  245. {
  246. pdu_tag tx_msg;
  247. QUEUE_STATUS result_status;
  248. // if (RESET == CAN_GetITStatus(CAN1, CAN_IT_TME))
  249. if (0 == ((CAN1->IER) & 0x1))
  250. {
  251. #if 0
  252. de_queue(can_tx, &tx_msg);
  253. if (can_tx.ret == 1) // 返回值为1代表读取成功
  254. {
  255. can_tx_frame(tx_msg);
  256. CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
  257. }
  258. #else
  259. de_queue(&can_tx_queue, tx_msg, result_status);
  260. if (result_status == Q_OK) // 返回值为1代表读取成功
  261. {
  262. can_tx_frame(tx_msg);
  263. CAN_ITConfig(CAN1, CAN_IT_TME, ENABLE);
  264. }
  265. #endif
  266. }
  267. }
  268. static uint8_t can_rx_process(void)
  269. {
  270. uint8_t i;
  271. uint8_t flg = 0;
  272. pdu_tag rec_msg;
  273. QUEUE_STATUS result;
  274. for (uint8_t j = 0; j < 15; j++)
  275. {
  276. #if 1
  277. __disable_irq();
  278. de_queue(&can_rx_queue, rec_msg, result);
  279. // result = de_queue(&can_rx_queue, rec_msg);
  280. __enable_irq();
  281. if (Q_OK == result)
  282. {
  283. for (i = 0; i < ARR_SIZE(can_tab); i++)
  284. {
  285. if (can_tab[i].id == rec_msg.id.r)
  286. {
  287. can_tab[i].p_func(rec_msg);
  288. flg = 1;
  289. break;
  290. }
  291. else if (can_tab[i].id == (rec_msg.id.b.pf << 8 | rec_msg.id.b.ps))
  292. {
  293. can_tab[i].p_func(rec_msg);
  294. flg = 1;
  295. break;
  296. }
  297. else if (can_tab[i].id == rec_msg.id.b.pf)
  298. {
  299. can_tab[i].p_func(rec_msg);
  300. flg = 1;
  301. break;
  302. }
  303. }
  304. if (flg == 0)
  305. {
  306. j1939_msg_push_queue(&rec_msg);
  307. }
  308. flg = 0;
  309. }
  310. #else
  311. de_queue(can_rx, &rec_msg);
  312. if (can_rx.ret == 1) // 返回值为1代表读取成功
  313. {
  314. for (i = 0; i < ARR_SIZE(can_tab); i++)
  315. {
  316. if (can_tab[i].id == rec_msg.id.r)
  317. {
  318. can_tab[i].p_func(rec_msg);
  319. break;
  320. }
  321. }
  322. }
  323. #endif
  324. }
  325. }
  326. void can_tx_0x18010000_message(void)
  327. {
  328. uint8_t data[8] = {0};
  329. data[2] = 0xFF;
  330. push_can_message_to_queue(0x18010000, 8, data);
  331. }
  332. void can_tx_0x18010001_message(void)
  333. {
  334. uint8_t data[8] = {0};
  335. push_can_message_to_queue(0x18010001, 8, data);
  336. }
  337. void can_tx_0x18030001_message(void)
  338. {
  339. uint8_t data[8] = {0};
  340. data[1] = 8;
  341. push_can_message_to_queue(0x18030001, 8, data);
  342. }
  343. void can_tx_0x18010002_message(void)
  344. {
  345. uint8_t data[8] = {0};
  346. data[0] = 0x02;
  347. push_can_message_to_queue(0x18010002, 8, data);
  348. }
  349. void can_tx_0x18030003_message(void)
  350. {
  351. uint8_t data[8] = {0};
  352. data[0] = 0x02;
  353. push_can_message_to_queue(0x18030003, 8, data);
  354. }
  355. void can_tx_0x18010004_message(void)
  356. {
  357. uint8_t data[8] = {0};
  358. data[4] = 33;
  359. data[5] = 22;
  360. push_can_message_to_queue(0x18010004, 8, data);
  361. }
  362. void can_tx_0x18010005_message(void)
  363. {
  364. uint8_t data[8] = {0};
  365. data[4] = 33;
  366. data[5] = 22;
  367. push_can_message_to_queue(0x18010005, 8, data);
  368. }
  369. void can_tx_0x18010006_message(void)
  370. {
  371. uint8_t data[8] = {0};
  372. data[4] = 33;
  373. data[5] = 22;
  374. push_can_message_to_queue(0x18010006, 8, data);
  375. }
  376. void can_tx_0x18010007_message(void)
  377. {
  378. uint8_t data[8] = {0};
  379. data[4] = 33;
  380. data[5] = 22;
  381. push_can_message_to_queue(0x18010007, 8, data);
  382. }
  383. void can_tx_0x18010008_message(void)
  384. {
  385. uint8_t data[8] = {0};
  386. data[4] = 33;
  387. data[5] = 22;
  388. push_can_message_to_queue(0x18010008, 8, data);
  389. }
  390. void can_tx_0x18010009_message(void)
  391. {
  392. uint8_t data[8] = {0};
  393. data[4] = 33;
  394. data[5] = 22;
  395. push_can_message_to_queue(0x18010009, 8, data);
  396. }
  397. void can_tx_0x1801000F_message(void)
  398. {
  399. uint8_t data[8] = {0};
  400. data[0] = 1;
  401. data[1] = 5;
  402. data[2] = 3000 & 0xFF;
  403. data[3] = 3000 >> 8;
  404. data[4] = 3000 & 0xFF;
  405. data[5] = 3000 >> 8;
  406. push_can_message_to_queue(0x1801000F, 8, data);
  407. }
  408. void can_tx_0x18010010_message(void)
  409. {
  410. uint8_t data[8] = {0};
  411. // data_bit_move(0, 8, 1);
  412. // data_bit_move(8, 8, 1);
  413. // data_bit_move(32, 8, 0);
  414. // data_bit_move(40, 8, 0);
  415. // product_array(data);
  416. data[0] = 1;
  417. data[1] = 1;
  418. data[4] = 0;
  419. data[5] = 0;
  420. // push_can_message_to_queue(0x18010010, 8, data);
  421. // data[1] = 5;
  422. // push_can_message_to_queue(0x18010010, 8, data);
  423. // data[1] = 10;
  424. push_can_message_to_queue(0x18010010, 8, data);
  425. }
  426. void can_tx_0x1801000A_message(void)
  427. {
  428. uint8_t data[8] = {0};
  429. data[4] = 33;
  430. data[5] = 22;
  431. push_can_message_to_queue(0x1801000A, 8, data);
  432. }
  433. void can_tx_0x1801000B_message(void)
  434. {
  435. uint8_t data[8] = {0};
  436. data[4] = 33;
  437. data[5] = 22;
  438. push_can_message_to_queue(0x1801000B, 8, data);
  439. }
  440. void can_tx_0x1801000C_message(void)
  441. {
  442. uint8_t data[8] = {0};
  443. data[4] = 33;
  444. data[5] = 22;
  445. push_can_message_to_queue(0x1801000C, 8, data);
  446. }
  447. void can_tx_0x1801000D_message(void)
  448. {
  449. uint8_t data[8] = {0};
  450. data[4] = 33;
  451. data[5] = 22;
  452. push_can_message_to_queue(0x1801000D, 8, data);
  453. }
  454. void can_tx_0x18010012_message(void)
  455. {
  456. uint8_t data[8] = {0};
  457. data[0] = 24;
  458. data[1] = 1;
  459. data[2] = 3;
  460. data[3] = 11;
  461. data[4] = 12;
  462. data[5] = 13;
  463. data[6] = 12;
  464. data[7] = 13;
  465. push_can_message_to_queue(0x18010012, 8, data);
  466. }
  467. void can_tx_0x18010017_message(void)
  468. {
  469. uint8_t data[8] = {0};
  470. data[0] = 24;
  471. data[1] = 1;
  472. data[0] = 3;
  473. data[1] = 11;
  474. data[0] = 12;
  475. data[1] = 13;
  476. push_can_message_to_queue(0x18010017, 8, data);
  477. }
  478. void can_tx_0x18010018_message(void)
  479. {
  480. uint8_t data[8] = {0};
  481. data[0] = 2;
  482. data[1] = 0xFF;
  483. push_can_message_to_queue(0x18010018, 8, data);
  484. }
  485. void can_tx_0x18010019_message(void)
  486. {
  487. uint8_t data[8] = {0};
  488. data[0] = 2;
  489. data[1] = 0xFF;
  490. push_can_message_to_queue(0x18010019, 8, data);
  491. }
  492. void can_tx_0x1801001A_message(void)
  493. {
  494. volatile static int i = 0;
  495. uint8_t data[8] = {0};
  496. data[0] = 2 + i;
  497. data[1] = 0x12 >> i;
  498. i++;
  499. if (i > 7)
  500. {
  501. i = 0;
  502. }
  503. push_can_message_to_queue(0x1801001A, 8, data);
  504. }
  505. void can_tx_0x1801001B_message(void)
  506. {
  507. uint8_t data[8] = {0};
  508. data[0] = 2;
  509. data[1] = 0xFF;
  510. push_can_message_to_queue(0x1801001B, 8, data);
  511. }
  512. void can_tx_0x1801001C_message(void)
  513. {
  514. uint8_t data[8] = {0};
  515. data[0] = 2;
  516. data[4] = 0xFF;
  517. push_can_message_to_queue(0x1801001C, 8, data);
  518. }
  519. void can_tx_0x1801001D_message(void)
  520. {
  521. uint8_t data[8] = {0};
  522. data[0] = 3;
  523. data[2] = 0xFF;
  524. push_can_message_to_queue(0x1801001D, 8, data);
  525. }
  526. void can_tx_0x18010023_message(void)
  527. {
  528. uint8_t send_data[8] = {0};
  529. // data[0] = 'A';
  530. // data[1] = 'A';
  531. // data[2] = 'A';
  532. // data[3] = 'A';
  533. // data[4] = 'A';
  534. // data[5] = 'A';
  535. // data[6] = 'A';
  536. // data[7] = 'A';
  537. data_bit_move(0, 8, 'A');
  538. data_bit_move(8, 8, 'A');
  539. data_bit_move(16, 8, 'A');
  540. data_bit_move(24, 8, 'C');
  541. data_bit_move(32, 8, 'A');
  542. data_bit_move(40, 8, '-');
  543. data_bit_move(48, 8, 'A');
  544. data_bit_move(56, 8, 'B');
  545. product_array(send_data);
  546. push_can_message_to_queue(0x18010023, 8, send_data);
  547. }
  548. void can_tx_0x18011802_message(void)
  549. {
  550. static uint8_t fdf = 0;
  551. if (flag == 1)
  552. {
  553. push_can_message_to_queue(0x18011802, 8, tx_data);
  554. flag = 0;
  555. }
  556. uint8_t data[8] = {0};
  557. uint16_t addr = 0xA000;
  558. if (tx_flag == 1)
  559. {
  560. data[0] = (addr + fdf) & 0xFF;
  561. data[1] = (addr + fdf) >> 8;
  562. data[2] = rand() & 0xFF;
  563. data[3] = rand() >> 8;
  564. fdf++;
  565. if (fdf == 80)
  566. {
  567. tx_flag = 0;
  568. }
  569. push_can_message_to_queue(0x18011802, 8, data);
  570. }
  571. }
  572. void can_tx_0x18011803_message(void)
  573. {
  574. uint8_t data[8] = {0};
  575. uint16_t addr = 0xB000;
  576. static uint8_t fdf = 0;
  577. static int16_t a = -263;
  578. data[0] = (addr + fdf) & 0xFF;
  579. data[1] = (addr + fdf) >> 8;
  580. data[2] = a & 0xFF;
  581. data[3] = a >> 8;
  582. fdf++;
  583. a++;
  584. if (fdf > 6)
  585. {
  586. fdf = 0;
  587. }
  588. push_can_message_to_queue(0x18011803, 8, data);
  589. }
  590. void can_tx_0x18011803_2_message(void)
  591. {
  592. uint8_t data[8] = {0};
  593. static uint8_t fdf_2 = 0;
  594. uint16_t addr_vol = 0xB110;
  595. data[0] = (addr_vol + fdf_2) & 0xFF;
  596. data[1] = (addr_vol + fdf_2) >> 8;
  597. data[2] = 1;
  598. data[3] = -2 & 0xFF;
  599. data[4] = -2 >> 8;
  600. fdf_2++;
  601. if (fdf_2 > 80)
  602. {
  603. fdf_2 = 0;
  604. }
  605. push_can_message_to_queue(0x18011803, 8, data);
  606. }
  607. void can_tx_0x18180003_message(void)
  608. {
  609. uint8_t data[8] = {0};
  610. data_bit_move(0, 16, 0);
  611. data_bit_move(16, 16, 0x2710);
  612. data_bit_move(32, 16, 0x4E20);
  613. data_bit_move(48, 16, 0x7530);
  614. product_array(data);
  615. push_can_message_to_queue(0x18190006, 8, data);
  616. }
  617. void can_tx_0x18190007_message(void)
  618. {
  619. uint8_t data[8] = {0};
  620. data_bit_move(0, 16, 0xDFFF);
  621. data_bit_move(16, 16, 0xF000);
  622. data_bit_move(32, 16, 0xE800);
  623. data_bit_move(48, 16, 0xE13D);
  624. product_array(data);
  625. push_can_message_to_queue(0x18190005, 8, data);
  626. }
  627. void send_message(void)
  628. {
  629. static volatile uint8_t times = 0;
  630. if (times >= 100)
  631. {
  632. times = 0;
  633. }
  634. if (times % 100 == 0)
  635. {
  636. can_tx_0x18010001_message();
  637. can_tx_0x18010002_message();
  638. can_tx_0x18010004_message();
  639. can_tx_0x18010005_message();
  640. }
  641. else if (times % 100 == 5)
  642. {
  643. can_tx_0x18010006_message();
  644. can_tx_0x18010007_message();
  645. can_tx_0x18010008_message();
  646. can_tx_0x18010009_message();
  647. can_tx_0x1801000A_message();
  648. }
  649. else if (times % 100 == 10)
  650. {
  651. can_tx_0x1801000B_message();
  652. can_tx_0x1801000C_message();
  653. can_tx_0x1801000D_message();
  654. can_tx_0x18010023_message();
  655. can_tx_0x18010010_message();
  656. }
  657. else if (times % 100 == 15)
  658. {
  659. can_tx_0x18010018_message();
  660. can_tx_0x18010019_message();
  661. can_tx_0x1801001A_message();
  662. can_tx_0x1801001B_message();
  663. can_tx_0x1801001C_message();
  664. }
  665. else if (times % 100 == 20)
  666. {
  667. can_tx_0x1801001D_message();
  668. can_tx_0x1801000F_message();
  669. can_tx_0x18030003_message();
  670. can_tx_0x18030001_message();
  671. can_tx_0x18010000_message();
  672. }
  673. else if (times % 100 == 25)
  674. {
  675. can_tx_0x18010017_message();
  676. can_tx_0x18010012_message();
  677. can_tx_0x18011802_message();
  678. can_tx_0x18011803_message();
  679. // can_tx_0x18011803_2_message();
  680. can_tx_0x18180003_message();
  681. can_tx_0x18190007_message();
  682. }
  683. else
  684. {
  685. // return;
  686. }
  687. times++;
  688. }
  689. void dev_can_network_init(void)
  690. {
  691. hal_can_init();
  692. queue_init(&can_rx_queue);
  693. queue_init(&can_tx_queue);
  694. hal_can_rx_back_init(can_rx_callback);
  695. hal_can_tx_back_init(can_tx_callback);
  696. }
  697. void can_process(void)
  698. {
  699. can_rx_process();
  700. // send_message();
  701. can_start_send();
  702. }