main_task.c 24 KB

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