main_task.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886
  1. #include "main_task.h"
  2. #include "soft_led.h"
  3. #include "stdio.h"
  4. #include "stdbool.h"
  5. #include "string.h"
  6. #include "main.h"
  7. #include "soft_usart.h"
  8. #include "usart_data_handle.h"
  9. #include "soft_flash.h"
  10. #include "soft_crc.h"
  11. #include "soft_radar_handle.h"
  12. #include "soft_engine.h"
  13. #include "soft_device.h"
  14. #include "soft_timer.h"
  15. #include "config.h"
  16. #include "soft_can.h"
  17. #include "soft_bms.h"
  18. #include "soft_adc.h"
  19. #include "soft_version.h"
  20. #include "soft_update.h"
  21. #include "soft_obstacle.h"
  22. //#include "can_debug.h"
  23. uint8_t msg_buf[256] = {0};
  24. bool terrain_is_link = false;
  25. bool obs_f_is_link = false;
  26. bool obs_b_is_link = false;
  27. /**
  28. * @file Update_ack_func
  29. * @brief PMU回复ACK 回复升级工具
  30. * @param 组件ID,消息ID,ACK数据
  31. * @details 升级应答FMU透传,协议和升级工具一致,和FMU不一样
  32. * @author Zhang Sir
  33. **/
  34. void Update_ack_func(uint8_t group_id, uint8_t msg_id, uint8_t *ackbuf)
  35. {
  36. int index = 0;
  37. msg_buf[index++] = 0xFE;
  38. msg_buf[index++] = 0;
  39. msg_buf[index++] = 0;
  40. msg_buf[index++] = 0x00;
  41. msg_buf[index++] = group_id;
  42. msg_buf[index++] = _MSGID_ACK;
  43. msg_buf[index++] = msg_id;
  44. msg_buf[index++] = *ackbuf;
  45. msg_buf[index++] = *(ackbuf + 1);
  46. msg_buf[index++] = 1;
  47. msg_buf[1] = index - 6;
  48. uint16_t uart_crc = Get_Crc16(msg_buf, index);
  49. memcpy(&msg_buf[index], &uart_crc, 2);
  50. index += 2;
  51. usart1_send_msg(msg_buf, index);
  52. }
  53. /**
  54. * @file pmu_set_ack
  55. * @brief PMU应答FMU
  56. * @param 命令 命令内容 123
  57. * @details
  58. * @author Zhang Sir
  59. **/
  60. char ack_id = 0;
  61. short ack_content = 0;
  62. short ack_content1 = 0;
  63. short ack_content2 = 0;
  64. void pmu_set_ack(uint8_t id,short content1, short content2,short content3)
  65. {
  66. pmu_send = PMU_SEND_ACK;
  67. ack_id = id;
  68. ack_content = content1;
  69. ack_content1 = content2;
  70. ack_content2 = content3;
  71. }
  72. /**
  73. * @file pmu_to_con_voltage_data
  74. * @brief PMU发送电压、温度信息
  75. * @param none
  76. * @details
  77. * @author Zhang Sir
  78. **/
  79. void pmu_to_con_voltage_data()
  80. {
  81. int index = 0;
  82. uint16_t temp_16t = 0;
  83. msg_buf[index++] = 0xFE;
  84. msg_buf[index++] = 0;
  85. msg_buf[index++] = 0; //组件计数
  86. msg_buf[index++] = 0x00;
  87. msg_buf[index++] = 0x00;
  88. msg_buf[index++] = _MSGID_VOL;
  89. temp_16t = Adc_Get(ADC_Bms) / 10.0f + cur_par.voltage * 10; // 获取当前板子电压
  90. memcpy(&msg_buf[index], &temp_16t, 2);
  91. index += 2;
  92. temp_16t = Adc_Get(ADC_Tempture);
  93. memcpy(&msg_buf[index], &temp_16t, 2);
  94. index += 2;
  95. msg_buf[index++] = 0;
  96. msg_buf[index++] = 0;
  97. temp_16t = (uint16_t)stor_par.abnormal_outage_flag;
  98. memcpy(&msg_buf[index], &temp_16t, 2);
  99. index += 2;
  100. msg_buf[1] = index - 6;
  101. uint16_t crc = Get_Crc16(msg_buf, index);
  102. msg_buf[index++] = crc;
  103. msg_buf[index++] = (crc >> 8) & 0xff;
  104. usart1_send_msg(msg_buf, index);
  105. }
  106. /**
  107. * @file pmu_to_con_heart_data
  108. * @brief PMU_发送心跳
  109. * @param none
  110. * @details
  111. * @author Zhang Sir
  112. **/
  113. void pmu_to_con_heart_data()
  114. {
  115. int index = 0;
  116. msg_buf[index++] = 0xFE;
  117. msg_buf[index++] = 0;
  118. msg_buf[index++] = 0;
  119. msg_buf[index++] = 0x00;
  120. msg_buf[index++] = 0x00;
  121. msg_buf[index++] = 21;
  122. msg_buf[index++] = _MSGID_HEART;
  123. ack_content = 0x56;
  124. memcpy(&msg_buf[index],&ack_content,2);
  125. index += 2;
  126. memcpy(&msg_buf[index],&ack_content1,2);
  127. index += 2;
  128. memcpy(&msg_buf[index],&ack_content2,2);
  129. index += 2;
  130. msg_buf[1] = index - 6;
  131. uint16_t crc = Get_Crc16(msg_buf, index);
  132. memcpy(&msg_buf[index], &crc, 2);
  133. index += 2;
  134. usart1_send_msg(msg_buf, index);
  135. }
  136. /**
  137. * @file pmu_to_con_engin_data
  138. * @brief PMU发送发动机信息
  139. * @param none
  140. * @details
  141. * @author Zhang Sir
  142. **/
  143. void pmu_to_con_engine_data(void)
  144. {
  145. uint8_t index = 0;
  146. if(engine_link_status == COMP_NORMAL)
  147. {
  148. msg_buf[index++] = 0xFE;
  149. msg_buf[index++] = 0;
  150. msg_buf[index++] = 0; //组件计数
  151. msg_buf[index++] = 0x00;
  152. msg_buf[index++] = 0x00;
  153. msg_buf[index++] = _MSG_ENGIN;
  154. memcpy(&msg_buf[index],&engine_data.engine_type,sizeof(engine_data));
  155. index += (sizeof(engine_data));
  156. msg_buf[1] = index - 6;
  157. uint16_t crc = Get_Crc16(msg_buf, index);
  158. msg_buf[index++] = crc;
  159. msg_buf[index++] = (crc >> 8) & 0xff;
  160. usart1_send_msg(msg_buf, index);
  161. }
  162. }
  163. /**
  164. * @file pmu_to_con_devtype_data
  165. * @brief PMU发送播撒、称重、水泵、离心喷头、在位传感器信息
  166. * @param none
  167. * @details
  168. * @author Zhang Sir
  169. **/
  170. void check_and_put_msg(uint8_t *buf, uint16_t len)
  171. {
  172. buf[1] = len - 6;
  173. uint16_t crc = Get_Crc16(buf, len);
  174. msg_buf[len++] = crc;
  175. msg_buf[len++] = (crc >> 8) & 0xff;
  176. usart1_send_msg(msg_buf, len);
  177. }
  178. void pmu_to_con_devtype_data(void)
  179. {
  180. uint16_t index = 0;
  181. msg_buf[index++] = 0xFE;
  182. msg_buf[index++] = 0;
  183. msg_buf[index++] = 0; //组件计数
  184. msg_buf[index++] = 0x00;
  185. msg_buf[index++] = 0x00;
  186. msg_buf[index++] = _MSGID_DEV_INFO;
  187. if(send_devinfo_time.flow == true)
  188. {
  189. msg_buf[index++] = DEV_FLOW;
  190. memcpy(&msg_buf[index],&Dev.Flow.facid,sizeof(Flow_info));
  191. index += sizeof(Flow_info);
  192. check_and_put_msg(msg_buf, index);
  193. index = 6;
  194. send_devinfo_time.flow = false;
  195. }
  196. if (send_devinfo_time.radar == true)
  197. {
  198. msg_buf[index++] = DEV_RADAR;
  199. memcpy(&msg_buf[index],&Dev.Radar.facid_T,sizeof(Radar_info));
  200. index += sizeof(Radar_info);
  201. check_and_put_msg(msg_buf, index);
  202. index = 6;
  203. send_devinfo_time.radar = false;
  204. }
  205. if(send_devinfo_time.checklow == true)
  206. {
  207. msg_buf[index++] = DEV_CHECKLOW;
  208. memcpy(&msg_buf[index],&Dev.Checklow.facid,sizeof(CheckLow_info));
  209. index += sizeof(CheckLow_info);
  210. check_and_put_msg(msg_buf, index);
  211. index = 6;
  212. send_devinfo_time.checklow = false;
  213. }
  214. if(Dev.L_pump1_Link.connect_status == COMP_NORMAL && send_devinfo_time.L_pump1 == true)
  215. {
  216. msg_buf[index++] = DEV_L_PUMP1;
  217. memcpy(&msg_buf[index],&Dev.L_pump1.facid,sizeof(Linear_pump_info));
  218. index += sizeof(Linear_pump_info);
  219. check_and_put_msg(msg_buf, index);
  220. index = 6;
  221. send_devinfo_time.L_pump1 = false;
  222. }
  223. if(Dev.L_pump2_Link.connect_status == COMP_NORMAL && send_devinfo_time.L_pump2 == true)
  224. {
  225. msg_buf[index++] = DEV_L_PUMP2;
  226. memcpy(&msg_buf[index],&Dev.L_pump2.facid,sizeof(Linear_pump_info));
  227. index += sizeof(Linear_pump_info);
  228. check_and_put_msg(msg_buf, index);
  229. index = 6;
  230. send_devinfo_time.L_pump2 = false;
  231. }
  232. if(Dev.Weight_Link.connect_status == COMP_NORMAL && send_devinfo_time.weight == true)
  233. {
  234. msg_buf[index++] = DEV_WEIGHT;
  235. memcpy(&msg_buf[index],&Dev.Weight.facid,sizeof(Weight_info));
  236. index += sizeof(Weight_info);
  237. check_and_put_msg(msg_buf, index);
  238. index = 6;
  239. send_devinfo_time.weight = false;
  240. }
  241. if(Dev.Part_Tradar_Link.connect_status == COMP_NORMAL && send_devinfo_time.part_radar == true)
  242. {
  243. msg_buf[index++] = DEV_PART_RADAR;
  244. memcpy(&msg_buf[index],&Dev.Part_radarT.facid,sizeof(Part_Tradar));
  245. index += sizeof(Part_Tradar);
  246. check_and_put_msg(msg_buf, index);
  247. index = 6;
  248. send_devinfo_time.part_radar = false;
  249. }
  250. if(Dev.Part_Fradar_Link.connect_status == COMP_NORMAL && send_devinfo_time.part_Fradar == true)
  251. {
  252. msg_buf[index++] = DEV_PART_FRADAR;
  253. memcpy(&msg_buf[index],&Dev.Part_radarF.facid,sizeof(Part_FBradar));
  254. index += sizeof(Part_FBradar);
  255. check_and_put_msg(msg_buf, index);
  256. index = 6;
  257. send_devinfo_time.part_Fradar = false;
  258. }
  259. if(Dev.Part_Bradar_Link.connect_status == COMP_NORMAL && send_devinfo_time.part_Bradar == true)
  260. {
  261. msg_buf[index++] = DEV_PART_BRADAR;
  262. memcpy(&msg_buf[index],&Dev.Part_radarB.facid,sizeof(Part_FBradar));
  263. index += sizeof(Part_FBradar);
  264. check_and_put_msg(msg_buf, index);
  265. index = 6;
  266. send_devinfo_time.part_Bradar = false;
  267. }
  268. if(Dev.Bms_Link.connect_status == COMP_NORMAL && send_devinfo_time.bms == true)
  269. {
  270. msg_buf[index++] = DEV_BMS;
  271. memcpy(&msg_buf[index],&Dev.Bms.facid,Dev.Bms.index + 1);
  272. index += Dev.Bms.index + 1;
  273. check_and_put_msg(msg_buf, index);
  274. index = 6;
  275. send_devinfo_time.bms = false;
  276. }
  277. if(Dev.Seed_Link.connect_status == COMP_NORMAL && send_devinfo_time.seed == true)
  278. {
  279. msg_buf[index++] = DEV_SEED;
  280. memcpy(&msg_buf[index],&Dev.Seed.facid,sizeof(Seed_info));
  281. index += sizeof(Seed_info);
  282. check_and_put_msg(msg_buf, index);
  283. index = 6;
  284. send_devinfo_time.seed = false;
  285. }
  286. if (Dev.Pump_Link.connect_status == COMP_NORMAL && send_devinfo_time.pump == true)
  287. {
  288. msg_buf[index++] = DEV_PUMP;
  289. memcpy(&msg_buf[index],&Dev.Pump.facid,sizeof(Pump_info));
  290. index += sizeof(Pump_info);
  291. check_and_put_msg(msg_buf, index);
  292. index = 6;
  293. send_devinfo_time.pump = false;
  294. }
  295. if (Dev.Nozzle_Link.connect_status == COMP_NORMAL && send_devinfo_time.nozzle == true)
  296. {
  297. msg_buf[index++] = DEV_NOZZLE;
  298. memcpy(&msg_buf[index],&Dev.Nozzle.facid,sizeof(Nozzle_info));
  299. index += sizeof(Nozzle_info);
  300. check_and_put_msg(msg_buf, index);
  301. index = 6;
  302. send_devinfo_time.nozzle = false;
  303. }
  304. if (Dev.Arm_Link.connect_status == COMP_NORMAL && send_devinfo_time.arm == true)
  305. {
  306. msg_buf[index++] = DEV_ARM;
  307. memcpy(&msg_buf[index],&Dev.Arm.facid,sizeof(Arm_info));
  308. index += sizeof(Arm_info);
  309. check_and_put_msg(msg_buf, index);
  310. index = 6;
  311. send_devinfo_time.arm = false;
  312. }
  313. // else if(Dev.L_pump2_Link.connect_status == COMP_NORMAL && send_devinfo_time.L_pump2 == true)
  314. // {
  315. // msg_buf[index++] = DEV_L_PUMP2;
  316. // memcpy(&msg_buf[index],&Dev.L_pump2.facid,sizeof(Linear_pump_info));
  317. // index += sizeof(Linear_pump_info);
  318. // send_devinfo_time.L_pump2 = false;
  319. // }
  320. // msg_buf[1] = index - 6;
  321. // uint16_t crc = Get_Crc16(msg_buf, index);
  322. // msg_buf[index++] = crc;
  323. // msg_buf[index++] = (crc >> 8) & 0xff;
  324. // usart1_send_msg(msg_buf, index);
  325. }
  326. /**
  327. * @file pmu_to_con_version_data
  328. * @brief PMU发送版本信息
  329. * @param none
  330. * @details
  331. * @author Zhang Sir
  332. **/
  333. void pmu_to_con_version_data()
  334. {
  335. //版本信息 0 - 5 硬件版本 IAP版本 APP版本
  336. uint32_t ver_msg_buf[4] = {0};
  337. int index = 0;
  338. ver_msg_buf[0] = cur_par.pmu_serial; //硬件版本号
  339. ver_msg_buf[1] = IAP_VERSION; //IAP版本号
  340. ver_msg_buf[2] = APP_VERSION; //APP版本号
  341. ver_msg_buf[3] = cur_par.pmu_serial;//serial.num;
  342. msg_buf[index++] = 0xFE;
  343. msg_buf[index++] = 0;
  344. msg_buf[index++] = 0;
  345. msg_buf[index++] = 0x00;
  346. msg_buf[index++] = 0x00;
  347. msg_buf[index++] = MSGID_REQ_VERSION;
  348. radar_version_check();
  349. memcpy(&msg_buf[index], ver_msg_buf, 16);
  350. index += 16;
  351. memcpy(&msg_buf[index], &radar_version[0][0], 10);
  352. index += 10;
  353. memcpy(&msg_buf[index], &radar_version[1][0], 10);
  354. index += 10;
  355. memcpy(&msg_buf[index], &radar_version[2][0], 10);
  356. index += 10;
  357. msg_buf[1] = index - 6;
  358. uint16_t crc = Get_Crc16(msg_buf, index);
  359. memcpy(&msg_buf[index], &crc, 2);
  360. index += 2;
  361. usart1_send_msg(msg_buf, index);
  362. }
  363. /**
  364. * @file pmu_to_fcu_version_data
  365. * @brief 版本信息发送,新协议还没用
  366. * @param none
  367. * @details
  368. * @author Zhang Sir
  369. **/
  370. void pmu_to_fcu_version_data()
  371. {
  372. //short dev_num = 40;
  373. uint8_t i = 0;
  374. dev_version_content *ptr = NULL;
  375. for(i = 0;i < dev_num;i++)
  376. {
  377. ptr = dev_ptr[i];
  378. if(ptr->send_times > 0)
  379. {
  380. break;
  381. }
  382. if(i == dev_num - 1)
  383. {
  384. return;
  385. }
  386. }
  387. uint8_t index = 0;
  388. msg_buf[index++] = 0xFE;
  389. msg_buf[index++] = 0;
  390. msg_buf[index++] = 0;
  391. msg_buf[index++] = 0x00;
  392. msg_buf[index++] = 0x00;
  393. msg_buf[index++] = _MSGID_DEV_LIST;
  394. memcpy(&msg_buf[index],&ptr->num,sizeof(dev_version_content) - sizeof(regist_type) - 1);
  395. index += sizeof(dev_version_content) - sizeof(regist_type) - 1;
  396. msg_buf[1] = index - 6;
  397. uint16_t crc = Get_Crc16(msg_buf, index);
  398. memcpy(&msg_buf[index], &crc, 2);
  399. index += 2;
  400. usart1_send_msg(msg_buf, index);
  401. }
  402. /**
  403. * @file pmu_to_fcu_key_data
  404. * @brief PMU发送秘钥信息
  405. * @param none
  406. * @details 格式电池秘钥匹配
  407. * @author Zhang Sir
  408. **/
  409. void pmu_to_fcu_key_data(void)
  410. {
  411. uint8_t index = 0;
  412. msg_buf[index++] = 0xFE;
  413. msg_buf[index++] = 0;
  414. msg_buf[index++] = 0;
  415. msg_buf[index++] = 0x00;
  416. msg_buf[index++] = 0x00;
  417. msg_buf[index++] = _MSGID_SHA1;
  418. msg_buf[index++] = start_msg.Dev_type;
  419. msg_buf[index++] = start_msg.Id;
  420. msg_buf[index++] = start_msg.Id_content;
  421. // if(start_msg.Id == 4)
  422. // {
  423. // start_msg.key_info_checking = false; //发送状态后结束发送
  424. // }
  425. memcpy(&msg_buf[index],&start_msg.key_data[0],20);
  426. index += 20;
  427. msg_buf[1] = index - 6;
  428. uint16_t crc = Get_Crc16(msg_buf, index);
  429. memcpy(&msg_buf[index], &crc, 2);
  430. index += 2;
  431. usart1_send_msg(msg_buf, index);
  432. }
  433. /**
  434. * @file pmu_to_con_request_data
  435. * @brief PMU发送请求信息
  436. * @param none
  437. * @details
  438. * @author Zhang Sir
  439. **/
  440. char request_id = 0;
  441. short request_1_content = 0;
  442. int request_2_content = 0;
  443. void pmu_to_con_request_data()
  444. {
  445. int index = 0;
  446. msg_buf[index++] = 0xFE;
  447. msg_buf[index++] = 0;
  448. msg_buf[index++] = 0;
  449. msg_buf[index++] = 0x00;
  450. msg_buf[index++] = 0x00;
  451. msg_buf[index++] = 20;
  452. msg_buf[index++] = request_id;
  453. memcpy(&msg_buf[index],&request_1_content,2);
  454. index += 2;
  455. memcpy(&msg_buf[index],&request_2_content,4);
  456. index += 4;
  457. msg_buf[1] = index - 6;
  458. uint16_t crc = Get_Crc16(msg_buf, index);
  459. memcpy(&msg_buf[index], &crc, 2);
  460. index += 2;
  461. usart1_send_msg(msg_buf, index);
  462. }
  463. /**
  464. * @file pmu_to_con_radar360_data
  465. * @brief PMU发送360信息
  466. * @param none
  467. * @details
  468. * @author Zhang Sir
  469. **/
  470. void pmu_to_con_radar360_data(void)
  471. {
  472. uint8_t index = 0;
  473. uint32_t send_byte = 0;
  474. uint16_t crc = 0;
  475. if(mimo_360_info.connect_status == COMP_NORMAL)
  476. {
  477. msg_buf[index++] = 0xFE;
  478. msg_buf[index++] = 0;
  479. msg_buf[index++] = 0;
  480. msg_buf[index++] = 0x00;
  481. msg_buf[index++] = 0x00;
  482. msg_buf[index++] = _MSGID_360RADAR;
  483. radar360_proflag = 1;
  484. send_byte = sizeof(mimo_360_data) * fmu_360info.total_tar + 2;
  485. memcpy(&msg_buf[index],&fmu_360info,send_byte);
  486. index += send_byte;
  487. radar360_proflag = 0;
  488. msg_buf[1] = index - 6;
  489. crc = Get_Crc16(msg_buf, index);
  490. msg_buf[index++] = crc;
  491. msg_buf[index++] = (crc >> 8) & 0xff;
  492. usart1_send_msg(msg_buf, index);
  493. }
  494. }
  495. /**
  496. * @file pmu_to_con_request_data
  497. * @brief PMU发送应答信息
  498. * @param none
  499. * @details
  500. * @author Zhang Sir
  501. **/
  502. void pmu_to_con_ack_data()
  503. {
  504. int index = 0;
  505. msg_buf[index++] = 0xFE;
  506. msg_buf[index++] = 0;
  507. msg_buf[index++] = 0;
  508. msg_buf[index++] = 0x00;
  509. msg_buf[index++] = 0x00;
  510. msg_buf[index++] = 21;
  511. msg_buf[index++] = ack_id;
  512. memcpy(&msg_buf[index],&ack_content,2);
  513. index += 2;
  514. memcpy(&msg_buf[index],&ack_content1,2);
  515. index += 2;
  516. memcpy(&msg_buf[index],&ack_content2,2);
  517. index += 2;
  518. msg_buf[1] = index - 6;
  519. uint16_t crc = Get_Crc16(msg_buf, index);
  520. memcpy(&msg_buf[index], &crc, 2);
  521. index += 2;
  522. usart1_send_msg(msg_buf, index);
  523. }
  524. /**
  525. * @file Can_send_debug_to_app
  526. * @brief can模拟
  527. * @param none
  528. * @details UART2
  529. * @author Zhang Sir
  530. **/
  531. /*
  532. void Can_send_debug_to_app(void)
  533. {
  534. int index = 0;
  535. uint16_t crc = 0;
  536. uint8_t send_time = debug_can.Total_Dev_num / 16 + 1;
  537. uint8_t element_num = 0,total_pack_num = 0;
  538. check_can_dev_connect();
  539. for(uint8_t i = 0;i < send_time; i++)
  540. {
  541. index = 0;
  542. crc = 0;
  543. msg_buf[index++] = 0xFE;
  544. msg_buf[index++] = 0;
  545. msg_buf[index++] = 0; //组件计数
  546. msg_buf[index++] = 0x00;
  547. msg_buf[index++] = 0x00;
  548. msg_buf[index++] = _MSGID_CANDEBUG;
  549. debug_can.Len = get_data_total_len;
  550. if(send_time > 1)
  551. {
  552. element_num = i * 15;
  553. total_pack_num = (send_time - 1 - i) == 0? debug_can.Total_Dev_num - (i *15) : 15;
  554. }
  555. else
  556. {
  557. element_num = 0;
  558. total_pack_num = debug_can.Total_Dev_num;
  559. }
  560. msg_buf[index++] = total_pack_num;
  561. for(uint8_t i=0;i<total_pack_num;i++)
  562. {
  563. memcpy(&msg_buf[index], &debug_can.ID_buf[i + element_num].ID, debug_can.Len(debug_can.ID_buf[i + element_num].len));
  564. index += debug_can.Len(debug_can.ID_buf[i + element_num].len);
  565. }
  566. msg_buf[1] = index - 6;
  567. crc = Get_Crc16(msg_buf, index);
  568. msg_buf[index++] = crc;
  569. msg_buf[index++] = (crc >> 8) & 0xff;
  570. usart1_send_msg(msg_buf, index);
  571. //uart3_send_msg(msg_buf, index);
  572. if(send_time > 1)
  573. {
  574. HAL_Delay(50);
  575. }
  576. }
  577. }
  578. */
  579. /**
  580. * @file pmu_to_fcu
  581. * @brief PMU发送信息给FMU
  582. * @param none
  583. * @details UART2
  584. * @author Zhang Sir
  585. **/
  586. uint8_t pmu_send = PMU_SEND_YAOCE;
  587. void pmu_to_fcu()
  588. {
  589. //串口阻塞 和雷达升级不发送
  590. if(update_info.vk_dev_update_flag != true && EZup_par.update_flag != true)
  591. {
  592. switch (pmu_send)
  593. {
  594. case PMU_SEND_YAOCE:
  595. //心跳包单独发
  596. if(pmu_heart_flag == true)
  597. {
  598. pmu_to_con_heart_data();
  599. pmu_heart_flag = false;
  600. }
  601. //发送电压信息
  602. else if (vol_flag == true)
  603. {
  604. pmu_to_con_voltage_data();
  605. vol_flag = false;
  606. }
  607. // //发动机信息
  608. // else if (engine_flag == true)
  609. // {
  610. // pmu_to_con_engine_data();
  611. // engine_flag = false;
  612. // }
  613. // //mimo360测试
  614. // else if (mimo360_radar_flag == true)
  615. // {
  616. // pmu_to_con_radar360_data();
  617. // mimo360_radar_flag = false;
  618. // }
  619. else if(devtype_flag == true)
  620. {
  621. pmu_to_con_devtype_data();
  622. devtype_flag = false;
  623. }
  624. //CAN调试信息
  625. // else if(can_debug_flag == true)
  626. // {
  627. // //Can_send_debug_to_app();
  628. // can_debug_flag = false;
  629. // }
  630. //设备SN号,软硬件号
  631. else if (dev_version_flag == true)
  632. {
  633. pmu_to_fcu_version_data();
  634. dev_version_flag = false;
  635. }
  636. break;
  637. case PMU_SEND_REQINFO:
  638. pmu_to_con_request_data();
  639. pmu_send = PMU_SEND_YAOCE;
  640. break;
  641. case PMU_SEND_ACK:
  642. pmu_to_con_ack_data();
  643. pmu_send = PMU_SEND_YAOCE;
  644. break;
  645. case PMU_SEND_VERSION:
  646. pmu_to_con_version_data();
  647. pmu_send = PMU_SEND_YAOCE;
  648. break;
  649. case PMU_SEND_SHA1:
  650. pmu_to_fcu_key_data();
  651. pmu_send = PMU_SEND_YAOCE;
  652. break;
  653. default:
  654. pmu_send = PMU_SEND_YAOCE;
  655. break;
  656. }
  657. }
  658. }
  659. /**
  660. * @file timer_check_other_func
  661. * @brief FMU异常断电检测
  662. * @param none
  663. * @details UART2
  664. * @author Zhang Sir
  665. **/
  666. void timer_check_other_func()
  667. {
  668. //static uint32_t time1 = 0;
  669. static uint32_t time2 = 0;
  670. // if(Check_Timer_Ready(&time1,_1_HZ_))
  671. // {
  672. // if((planep.lock_status != STA_LOCK) && (fcu.connect_status == COMP_NORMAL) &&
  673. // (HAL_GetTick() - fcu.recv_time > 500))
  674. // {
  675. // stor_par.abnormal_outage_flag = 1;
  676. // write_flash_flag = true;
  677. // fcu.connect_status = COMP_LOST;
  678. // }
  679. // }
  680. if(Check_Timer_Ready(&time2,_2_HZ_))
  681. {
  682. if(HAL_GetTick() > 10000 && start_msg.version_info == false)
  683. {
  684. pmu_send = PMU_SEND_VERSION;
  685. start_msg.version_info = true;
  686. }
  687. else if (start_msg.key_info_checking == true && Device1.Vkbms_Link.connect_status == COMP_NORMAL)
  688. {
  689. pmu_send = PMU_SEND_SHA1;
  690. }
  691. else
  692. {
  693. //给FMU发送雷达灵敏度信息
  694. send_mocib_radar_sensi();
  695. }
  696. }
  697. }
  698. extern CAN_HandleTypeDef hcan1;
  699. extern CAN_HandleTypeDef hcan2;
  700. void thread_main_task_handle(void *param)
  701. {
  702. // if(Check_Chip_Verified != true)
  703. // {
  704. // while (1)
  705. // {
  706. // rt_thread_mdelay(5);
  707. // }
  708. // }
  709. while(1)
  710. {
  711. //数据发送定时器
  712. timer_function();
  713. //ADC采集
  714. ADC_GET_DATA();
  715. //点亮pmu内部led灯
  716. pmu_inside_led();
  717. // /*测试发送rkprintf*/
  718. // static uint32_t lastPrintTime = 0;
  719. // if( HAL_GetTick() - lastPrintTime > 1000){
  720. // rt_kprintf("this is a test!\r\n");
  721. // lastPrintTime = HAL_GetTick();
  722. // }
  723. //发送数据给主控制器 雷达升级不发送数据
  724. pmu_to_fcu();
  725. //更新播撒,称重,水泵,离心喷头,流量计等设备信息
  726. update_device_type_data();
  727. //智能电池相关功能
  728. bms_function();
  729. //雷达相关功能
  730. lidar_function();
  731. //判断异常断电,上电发送版本信息
  732. timer_check_other_func();
  733. //液位计相关功能
  734. L1L2_GPIO_check();
  735. //获取设备版本和SN号
  736. get_device_version_and_sn();
  737. //写flash
  738. write_flash_function();
  739. #ifdef mimo_update
  740. mimo_obs_update_func();
  741. #else
  742. //设备升级
  743. Vk_Update_Device_Protocol();
  744. #endif
  745. eft_dev_update_func();
  746. send_uartfifo_msg();
  747. //CAN DEBUG
  748. // if(planep.Candebug_flag == true)
  749. // {
  750. // seek_can_debug_buf_adr();
  751. // }
  752. rt_thread_mdelay(2);
  753. }
  754. }