soft_p_2_c.c 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813
  1. #include "soft_p_2_c.h"
  2. #include "soft_uart.h"
  3. #include "usart.h"
  4. #include "stdbool.h"
  5. #include "soft_timer.h"
  6. #include "soft_adc.h"
  7. #include "soft_flow.h"
  8. #include "soft_crc.h"
  9. #include <string.h>
  10. #include "stdbool.h"
  11. #include "tim.h"
  12. #include "hard_led.h"
  13. #include "soft_can.h"
  14. #include "stdio.h"
  15. #include "soft_bms.h"
  16. #include "soft_terrain.h"
  17. #include "soft_obstacle.h"
  18. #include "soft_okcell.h"
  19. #include "soft_adc.h"
  20. #include "config.h"
  21. #include "soft_calibration.h"
  22. #include "soft_flash.h"
  23. #include "bsp_serial.h"
  24. #include "rkfifo.h"
  25. #include "soft_engine.h"
  26. #include "soft_eft.h"
  27. #include "math.h"
  28. #include "stdlib.h"
  29. #include "soft_water_device.h"
  30. #include "soft_seed_device.h"
  31. #include "soft_test.h"
  32. #include "can_debug.h"
  33. #include "soft_version.h"
  34. #include "soft_update.h"
  35. #include "qingxie_bms.h"
  36. #include "soft_flash.h"
  37. uint8_t msg_buf[256] = {0};
  38. uint16_t crc = 0;
  39. pmu_data pmu;
  40. plane_para planep = {.Candebug_flag = 0};
  41. /**
  42. * @file Update_ack_func
  43. * @brief PMU回复ACK 回复升级工具
  44. * @param 组件ID,消息ID,ACK数据
  45. * @details 升级应答FMU透传,协议和升级工具一致,和FMU不一样
  46. * @author Zhang Sir
  47. **/
  48. void Update_ack_func(uint8_t group_id, uint8_t msg_id, uint8_t *ackbuf)
  49. {
  50. int index = 0;
  51. msg_buf[index++] = 0xFE;
  52. msg_buf[index++] = 0;
  53. msg_buf[index++] = 0;
  54. msg_buf[index++] = 0x00;
  55. msg_buf[index++] = group_id;
  56. msg_buf[index++] = 21;
  57. msg_buf[index++] = msg_id;
  58. msg_buf[index++] = *ackbuf;
  59. msg_buf[index++] = *(ackbuf + 1);
  60. msg_buf[index++] = 1;
  61. msg_buf[1] = index - 6;
  62. uint16_t uart_crc = Get_Crc16(msg_buf, index);
  63. memcpy(&msg_buf[index], &uart_crc, 2);
  64. index += 2;
  65. uart2_send_msg(msg_buf, index);
  66. }
  67. /**
  68. * @file pmu_set_ack
  69. * @brief PMU应答FMU
  70. * @param 命令 命令内容 123
  71. * @details
  72. * @author Zhang Sir
  73. **/
  74. void pmu_set_ack(uint8_t id,short content1, short content2,short content3)
  75. {
  76. pmu_send = PMU_SEND_ACK;
  77. ack_id = id;
  78. ack_content = content1;
  79. ack_content1 = content2;
  80. ack_content2 = content3;
  81. }
  82. /**
  83. * @file pmu_to_con_voltage_data
  84. * @brief PMU发送电压、温度信息
  85. * @param none
  86. * @details
  87. * @author Zhang Sir
  88. **/
  89. void pmu_to_con_voltage_data()
  90. {
  91. int index = 0;
  92. msg_buf[index++] = 0xFE;
  93. msg_buf[index++] = 0;
  94. msg_buf[index++] = 0; //组件计数
  95. msg_buf[index++] = 0x00;
  96. msg_buf[index++] = 0x00;
  97. msg_buf[index++] = _MSGID_VOL;
  98. pmu.voltage = ADC_gather() / 10.0f + volinf.cal_vol * 10; // 获取当前板子电压
  99. memcpy(&msg_buf[index], &pmu.voltage, 2);
  100. index += 2;
  101. pmu.temperature = ADC_read_temptrue();
  102. memcpy(&msg_buf[index], &pmu.temperature, 2);
  103. index += 2;
  104. msg_buf[index++] = 0;
  105. msg_buf[index++] = 0;
  106. memcpy(&msg_buf[index], &uavinf.abnormal_outage_flag, 2);
  107. index += 2;
  108. msg_buf[1] = index - 6;
  109. crc = Get_Crc16(msg_buf, index);
  110. msg_buf[index++] = crc;
  111. msg_buf[index++] = (crc >> 8) & 0xff;
  112. uart2_send_msg(msg_buf, index); //10
  113. //for(int i = 0;i<10;i++){
  114. //printf("%d ",msg_buf[6]);
  115. //printf("%d\n",msg_buf[7]);
  116. //}
  117. }
  118. /**
  119. * @file get_radar_info
  120. * @brief 获取雷达信息
  121. * @param Info_Type:避障雷达 X:1 Y:2
  122. * @details
  123. * @author Zhang Sir
  124. **/
  125. short get_radar_info(uint8_t Radar_Type,uint8_t Info_Type)
  126. {
  127. uavr_terrain *Ptr_T = NULL;
  128. uavr_obs *Ptr_O = NULL;
  129. if(Radar_Type == MSGID_SET_T_RADAR)
  130. {
  131. if(mimo_ter_info.Link.connect_status != COMP_NOEXIST)
  132. Ptr_T = &mimo_ter_info;
  133. else if(DM_ter_info.Link.connect_status != COMP_NOEXIST)
  134. Ptr_T = &DM_ter_info;
  135. else if(uavr56_info.Link.connect_status != COMP_NOEXIST)
  136. Ptr_T = &uavr56_info;
  137. if(Ptr_T->Link.connect_status == COMP_LOST) {return -2;}
  138. else if(Ptr_T == NULL) {return -1;}
  139. else {return Ptr_T->height;}
  140. }
  141. else if(Radar_Type == MSGID_SET_F_RADAR)
  142. {
  143. if(uavr11_info.Link.connect_status != COMP_NOEXIST)
  144. Ptr_O = &uavr11_info;
  145. else if(mimo_f_info.Link.connect_status != COMP_NOEXIST)
  146. Ptr_O = &mimo_f_info;
  147. else if(DM_f_info.Link.connect_status != COMP_NOEXIST)
  148. Ptr_O = &DM_f_info;
  149. if(Ptr_O->Link.connect_status == COMP_LOST) {return -2;}
  150. else if(Ptr_O == NULL) {return -1;}
  151. else
  152. {
  153. if(Info_Type == OBS_X)
  154. return Ptr_O->distance_x;
  155. else if((Info_Type == OBS_Y))
  156. return Ptr_O->distance_y;
  157. }
  158. }
  159. else if(Radar_Type == MSGID_SET_B_RADAR)
  160. {
  161. if(uavr12_info.Link.connect_status != COMP_NOEXIST)
  162. Ptr_O = &uavr12_info;
  163. else if(mimo_b_info.Link.connect_status != COMP_NOEXIST)
  164. Ptr_O = &mimo_b_info;
  165. if(Ptr_O->Link.connect_status == COMP_LOST) {return -2;}
  166. else if(Ptr_O == NULL) {return -1;}
  167. else
  168. {
  169. if(Info_Type == OBS_X)
  170. return Ptr_O->distance_x;
  171. else if((Info_Type == OBS_Y))
  172. return Ptr_O->distance_y;
  173. }
  174. }
  175. return 0;
  176. }
  177. /**
  178. * @file pmu_to_con_radar_data
  179. * @brief PMU发送雷达信息
  180. * @param none
  181. * @details
  182. * @author Zhang Sir
  183. **/
  184. void pmu_to_con_radar_data()
  185. {
  186. int index = 0;
  187. //检查各种雷达连接状态
  188. check_radar_link_status();
  189. msg_buf[index++] = 0xFE;
  190. msg_buf[index++] = 10;
  191. msg_buf[index++] = 0;
  192. msg_buf[index++] = 0x00;
  193. msg_buf[index++] = 0x00;
  194. msg_buf[index++] = _MSGID_RADAR;
  195. pmu.radar_buf[0] = get_radar_info(MSGID_SET_T_RADAR,0);
  196. pmu.radar_buf[1] = get_radar_info(MSGID_SET_F_RADAR,OBS_Y);
  197. pmu.radar_buf[2] = get_radar_info(MSGID_SET_F_RADAR,OBS_X);
  198. pmu.radar_buf[3] = get_radar_info(MSGID_SET_B_RADAR,OBS_Y);
  199. pmu.radar_buf[4] = get_radar_info(MSGID_SET_B_RADAR,OBS_X);
  200. terrain_is_link = pmu.radar_buf[0] > -1? true:false;
  201. obs_f_is_link = pmu.radar_buf[1] > -1? true:false;
  202. obs_b_is_link = pmu.radar_buf[3] > -1? true:false;
  203. // //发送木牛或者恩曌数据或者莫之比仿地
  204. // if ((muniu_ter_info.muniu_time == 0) && (mimo_ter_info.heart_time == 0) && (uavr56_info.heart_time == 0)) //上电没通讯
  205. // {
  206. // pmu.radar_buf[0] = -1;
  207. // terrain_is_link = false;
  208. // }
  209. // else if ((muniu_ter_info.muniu_heart_flag == false) && (mimo_ter_info.heart_flag == false) &&
  210. // (uavr56_info.heart_flag == false)) //持续3秒没有接收到数据 显示断开连接
  211. // {
  212. // pmu.radar_buf[0] = -2;
  213. // terrain_is_link = false;
  214. // }
  215. // else
  216. // {
  217. // if (muniu_ter_info.muniu_heart_flag == true)
  218. // {
  219. // pmu.radar_buf[0] = muniu_ter_info.muniu_hight;
  220. // terrain_height = muniu_ter_info.muniu_hight;
  221. // //printf("%d\n", muniu_hight);
  222. // }
  223. // else if (uavr56_info.heart_flag == true)
  224. // {
  225. // pmu.radar_buf[0] = uavr56_info.height;
  226. // terrain_height = uavr56_info.height;
  227. // // printf("%d\n",uavr56_info.height);
  228. // }
  229. // else if (mimo_ter_info.heart_flag == true)
  230. // {
  231. // pmu.radar_buf[0] = mimo_ter_info.height;
  232. // terrain_height = mimo_ter_info.height;
  233. // // printf("%d %d %d %d\n",mimo_ter_info.height,keep_time,ez_count,ez_count2);
  234. // }
  235. // terrain_is_link = true;
  236. // }
  237. // //前避障
  238. // if (uavr11_info.heart_time == 0 && mimo_f_info.heart_time == 0)
  239. // {
  240. // pmu.radar_buf[1] = -1;
  241. // obs_f_is_link = false;
  242. // }
  243. // else if (uavr11_info.heart_flag == false && mimo_f_info.heart_flag == false)
  244. // {
  245. // pmu.radar_buf[1] = -2;
  246. // obs_f_is_link = false;
  247. // }
  248. // else
  249. // {
  250. // if (uavr11_info.heart_flag == true)
  251. // {
  252. // if(Fobs_handle_function())
  253. // {
  254. // pmu.radar_buf[1] = uavr11_info.distance_y;
  255. // pmu.radar_buf[2] = uavr11_info.distance_x;
  256. // }
  257. // else
  258. // {
  259. // pmu.radar_buf[1] = 0;
  260. // pmu.radar_buf[2] = 0;
  261. // }
  262. // }
  263. // if (mimo_f_info.heart_flag == true)
  264. // {
  265. // if(Fobs_handle_function())
  266. // {
  267. // pmu.radar_buf[1] = mimo_f_info.distance_y;
  268. // pmu.radar_buf[2] = mimo_f_info.distance_x;
  269. // }
  270. // else
  271. // {
  272. // pmu.radar_buf[1] = 0;
  273. // pmu.radar_buf[2] = 0;
  274. // }
  275. // //printf("%d\n",ez_obs_distance_y);
  276. // // printf("%d %d %d %d\n",mimo_f_info.distance_y,keep_time,ez_count,ez_count2);
  277. // }
  278. // obs_f_is_link = true;
  279. // }
  280. // //后避障
  281. // if (uavr12_info.heart_time == 0 && mimo_b_info.heart_time == 0)
  282. // {
  283. // pmu.radar_buf[3] = -1;
  284. // obs_b_is_link = false;
  285. // }
  286. // else if (uavr12_info.heart_flag == false && mimo_b_info.heart_flag == false)
  287. // {
  288. // pmu.radar_buf[3] = -2;
  289. // obs_b_is_link = false;
  290. // }
  291. // else
  292. // {
  293. // if (uavr12_info.heart_flag == true)
  294. // {
  295. // if(Bobs_handle_function())
  296. // {
  297. // pmu.radar_buf[3] = uavr12_info.distance_y;
  298. // pmu.radar_buf[4] = uavr12_info.distance_x;
  299. // }
  300. // else
  301. // {
  302. // pmu.radar_buf[3] = 0;
  303. // pmu.radar_buf[4] = 0;
  304. // }
  305. // }
  306. // else if(mimo_b_info.heart_flag == true)
  307. // {
  308. // if(Bobs_handle_function())
  309. // {
  310. // pmu.radar_buf[3] = mimo_b_info.distance_y;
  311. // pmu.radar_buf[4] = mimo_b_info.distance_x;
  312. // }
  313. // else
  314. // {
  315. // pmu.radar_buf[3] = 0;
  316. // pmu.radar_buf[4] = 0;
  317. // }
  318. // }
  319. // obs_b_is_link = true;
  320. // }
  321. memcpy(&msg_buf[index], &pmu.radar_buf[0], 10);
  322. index += 10;
  323. msg_buf[1] = index - 6;
  324. crc = Get_Crc16(msg_buf, index);
  325. msg_buf[index++] = crc;
  326. msg_buf[index++] = (crc >> 8) & 0xff;
  327. uart2_send_msg(msg_buf, index);
  328. }
  329. /**
  330. * @file pmu_to_con_barttery_data
  331. * @brief PMU发送智能电池信息
  332. * @param none
  333. * @details
  334. * @author Zhang Sir
  335. **/
  336. void pmu_to_con_barttery_data()
  337. {
  338. int index = 0;
  339. if (Dev.Bms_Link.connect_status == COMP_NORMAL)
  340. {
  341. uint8_t size_elong = 3 + 1 + 1 + bms_data.bms_num * 2; //前5字节:协议版本3 电池串数1 电池组数1
  342. uint8_t size_elong2 = 1 + bms_data2.bms_num * 2; //电池串数 加 电压
  343. msg_buf[index++] = 0xFE;
  344. msg_buf[index++] = 0; // 31 电池ID后的变量字节数
  345. msg_buf[index++] = 0;
  346. msg_buf[index++] = 0x00;
  347. msg_buf[index++] = 0x00;
  348. msg_buf[index++] = _MSGID_BMS;
  349. bms_data.bms_version[0] = 'V';
  350. bms_data.bms_version[1] = 'K';
  351. bms_data.bms_version[2] = '3';
  352. bms_data.bms_group = group_num;
  353. //一组电池
  354. if (bms_data.bms_group == 1)
  355. {
  356. memcpy(&msg_buf[index], &bms_data, size_elong); //变长数组 赋值到最后一个电压
  357. index += size_elong;
  358. memcpy(&msg_buf[index], &bms_data.bms_ids, 45); //从id 到状态 31字节 + 2字节 厂商编号
  359. index += 45; //新加32字节 33+12=45
  360. msg_buf[1] = index - 6;
  361. crc = Get_Crc16(msg_buf, index);
  362. msg_buf[index++] = crc;
  363. msg_buf[index++] = (crc >> 8) & 0xff;
  364. uart2_send_msg(msg_buf, index);
  365. }
  366. //两组电池
  367. else if (bms_data.bms_group == 2)
  368. {
  369. memcpy(&msg_buf[index], &bms_data, size_elong); //变长数组 赋值到最后一个电压
  370. index += size_elong;
  371. memcpy(&msg_buf[index], &bms_data.bms_ids, 45); //从id 到状态 31字节
  372. index += 45;
  373. memcpy(&msg_buf[index], &bms_data2.bms_num, size_elong2);
  374. index += size_elong2;
  375. memcpy(&msg_buf[index], &bms_data2.bms_ids, 45);
  376. index += 45;
  377. msg_buf[1] = index - 6;
  378. crc = Get_Crc16(msg_buf, index);
  379. msg_buf[index++] = crc;
  380. msg_buf[index++] = (crc >> 8) & 0xff;
  381. uart2_send_msg(msg_buf, index);
  382. }
  383. }
  384. }
  385. /**
  386. * @file pmu_to_con_engin_data
  387. * @brief PMU发送发动机信息
  388. * @param none
  389. * @details
  390. * @author Zhang Sir
  391. **/
  392. void pmu_to_con_engine_data(void)
  393. {
  394. uint8_t index = 0;
  395. if(engine_link_status == COMP_NORMAL)
  396. {
  397. msg_buf[index++] = 0xFE;
  398. msg_buf[index++] = 0;
  399. msg_buf[index++] = 0; //组件计数
  400. msg_buf[index++] = 0x00;
  401. msg_buf[index++] = 0x00;
  402. msg_buf[index++] = _MSG_ENGIN;
  403. memcpy(&msg_buf[index],&engine_data.engine_type,sizeof(engine_data));
  404. index += (sizeof(engine_data));
  405. msg_buf[1] = index - 6;
  406. crc = Get_Crc16(msg_buf, index);
  407. msg_buf[index++] = crc;
  408. msg_buf[index++] = (crc >> 8) & 0xff;
  409. uart2_send_msg(msg_buf, index);
  410. }
  411. }
  412. // /**
  413. // * @file pmu_to_con_radar360_data
  414. // * @brief PMU发送360信息
  415. // * @param none
  416. // * @details
  417. // * @author Zhang Sir
  418. // **/
  419. // void pmu_to_con_radar360_data(void)
  420. // {
  421. // uint8_t index = 0;
  422. // uint32_t send_byte = 0;
  423. // if(mimo_360_info.connect_status == COMP_NORMAL)
  424. // {
  425. // msg_buf[index++] = 0xFE;
  426. // msg_buf[index++] = 0;
  427. // msg_buf[index++] = 0;
  428. // msg_buf[index++] = 0x00;
  429. // msg_buf[index++] = 0x00;
  430. // msg_buf[index++] = _MSGID_360RADAR;
  431. // radar360_proflag = 1;
  432. // send_byte = sizeof(mimo_360_data) * fmu_360info.total_tar + 2;
  433. // memcpy(&msg_buf[index],&fmu_360info,send_byte);
  434. // index += send_byte;
  435. // radar360_proflag = 0;
  436. // msg_buf[1] = index - 6;
  437. // crc = Get_Crc16(msg_buf, index);
  438. // msg_buf[index++] = crc;
  439. // msg_buf[index++] = (crc >> 8) & 0xff;
  440. // uart2_send_msg(msg_buf, index);
  441. // }
  442. // }
  443. /**
  444. * @file pmu_to_con_radar360_data
  445. * @brief PMU发送360信息
  446. * @param none
  447. * @details
  448. * @author Zhang Sir
  449. **/
  450. void pmu_to_con_DMradar_data(void)
  451. {
  452. uint8_t index = 0;
  453. if(DM_status.connect_status == COMP_NORMAL)
  454. {
  455. msg_buf[index++] = 0xFE;
  456. msg_buf[index++] = 0;
  457. msg_buf[index++] = 0;
  458. msg_buf[index++] = 0x00;
  459. msg_buf[index++] = 0x00;
  460. msg_buf[index++] = _MSGID_DMRADAR;
  461. DM_recv_flag = 1;
  462. memcpy(&msg_buf[index],&FMU_DM_info.target_num,3);
  463. index += 3;
  464. memcpy(&msg_buf[index],&FMU_DM_info.warn,2);
  465. index += 2;
  466. memcpy(&msg_buf[index],FMU_DM_info.buf,DM_T_info.target_num * 4);
  467. index += DM_T_info.target_num * 4;
  468. DM_recv_flag = 0;
  469. msg_buf[1] = index - 6;
  470. crc = Get_Crc16(msg_buf, index);
  471. msg_buf[index++] = crc;
  472. msg_buf[index++] = (crc >> 8) & 0xff;
  473. uart2_send_msg(msg_buf, index);
  474. }
  475. }
  476. /**
  477. * @file pmu_to_con_heart_data
  478. * @brief PMU_发送心跳
  479. * @param none
  480. * @details
  481. * @author Zhang Sir
  482. **/
  483. void pmu_to_con_heart_data()
  484. {
  485. int index = 0;
  486. uint32_t time = 0;
  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++] = 21;
  493. msg_buf[index++] = _MSGID_HEART;
  494. ack_content = 0x56;
  495. memcpy(&msg_buf[index],&ack_content,2);
  496. index += 2;
  497. ack_content1 = uavinf.reset_reason;
  498. memcpy(&msg_buf[index],&ack_content1,2);
  499. index += 2;
  500. memcpy(&msg_buf[index],&ack_content2,2);
  501. index += 2;
  502. time = HAL_GetTick();
  503. memcpy(&msg_buf[index],&time,4);
  504. index += 4;
  505. msg_buf[1] = index - 6;
  506. crc = Get_Crc16(msg_buf, index);
  507. memcpy(&msg_buf[index], &crc, 2);
  508. index += 2;
  509. uart2_send_msg(msg_buf, index);
  510. }
  511. /**
  512. * @file pmu_to_con_devtype_data
  513. * @brief PMU发送播撒、称重、水泵、离心喷头、在位传感器信息
  514. * @param none
  515. * @details
  516. * @author Zhang Sir
  517. **/
  518. // void check_and_put_msg(uint8_t *buf, uint16_t len)
  519. // {
  520. // buf[1] = len - 6;
  521. // uint16_t crc = Get_Crc16(buf, len);
  522. // msg_buf[len++] = crc;
  523. // msg_buf[len++] = (crc >> 8) & 0xff;
  524. // uart2_send_msg(msg_buf, len);
  525. // }
  526. void pmu_to_con_devtype_data(void)
  527. {
  528. uint16_t index = 0;
  529. bool send_flag = true;
  530. msg_buf[index++] = 0xFE;
  531. msg_buf[index++] = 0;
  532. msg_buf[index++] = 0; //组件计数
  533. msg_buf[index++] = 0x00;
  534. msg_buf[index++] = 0x00;
  535. msg_buf[index++] = _MSGID_DEV_INFO;
  536. if((Dev.Bms_Link.connect_status == COMP_NORMAL || _Aqx_bms_link.connect_status == COMP_NORMAL) &&
  537. devinfo_time.bms == true)
  538. {
  539. if(Dev.Bms.facid == FAC_QX_BMS)
  540. msg_buf[index++] = DEV_QQ_BMS;
  541. else
  542. msg_buf[index++] = DEV_BMS;
  543. memcpy(&msg_buf[index],&Dev.Bms.facid,Dev.Bms.index + 1);
  544. index += Dev.Bms.index + 1;
  545. devinfo_time.bms = false;
  546. }
  547. else if(devinfo_time.flow == true)
  548. {
  549. msg_buf[index++] = DEV_FLOW;
  550. memcpy(&msg_buf[index],&Dev.Flow.facid,sizeof(Flow_info));
  551. index += sizeof(Flow_info);
  552. devinfo_time.flow = false;
  553. }
  554. else if (devinfo_time.radar == true)
  555. {
  556. msg_buf[index++] = DEV_RADAR;
  557. memcpy(&msg_buf[index],&Dev.Radar.facid_T,sizeof(Radar_info));
  558. index += sizeof(Radar_info);
  559. devinfo_time.radar = false;
  560. }
  561. else if(devinfo_time.checklow == true)
  562. {
  563. msg_buf[index++] = DEV_CHECKLOW;
  564. memcpy(&msg_buf[index],&Dev.Checklow.facid,sizeof(CheckLow_info));
  565. index += sizeof(CheckLow_info);
  566. devinfo_time.checklow = false;
  567. }
  568. else if(Dev.Part_Tradar_Link.connect_status == COMP_NORMAL && devinfo_time.part_radar == true)
  569. {
  570. msg_buf[index++] = DEV_PART_RADAR;
  571. memcpy(&msg_buf[index],&Dev.Part_radarT.facid,sizeof(Part_Tradar));
  572. index += sizeof(Part_Tradar);
  573. devinfo_time.part_radar = false;
  574. }
  575. // else if(Dev.Bms_Link.connect_status == COMP_NORMAL && devinfo_time.bms == true)
  576. // {
  577. // msg_buf[index++] = DEV_BMS;
  578. // memcpy(&msg_buf[index],&Dev.Bms.facid,Dev.Bms.index + 1);
  579. // index += Dev.Bms.index + 1;
  580. // devinfo_time.bms = false;
  581. // }
  582. else if(Dev.L_pump1_Link.connect_status == COMP_NORMAL && devinfo_time.L_pump1 == true)
  583. {
  584. msg_buf[index++] = DEV_L_PUMP1;
  585. memcpy(&msg_buf[index],&Dev.L_pump1.facid,sizeof(Linear_pump_info));
  586. index += sizeof(Linear_pump_info);
  587. devinfo_time.L_pump1 = false;
  588. }
  589. else if(Dev.L_pump2_Link.connect_status == COMP_NORMAL && devinfo_time.L_pump2 == true)
  590. {
  591. msg_buf[index++] = DEV_L_PUMP2;
  592. memcpy(&msg_buf[index],&Dev.L_pump2.facid,sizeof(Linear_pump_info));
  593. index += sizeof(Linear_pump_info);
  594. devinfo_time.L_pump2 = false;
  595. }
  596. else if(Dev.Weight_Link.connect_status == COMP_NORMAL && devinfo_time.weight == true)
  597. {
  598. msg_buf[index++] = DEV_WEIGHT;
  599. memcpy(&msg_buf[index],&Dev.Weight.facid,sizeof(Weight_info));
  600. index += sizeof(Weight_info);
  601. devinfo_time.weight = false;
  602. }
  603. else if(Dev.Seed_Link.connect_status == COMP_NORMAL && devinfo_time.seed == true)
  604. {
  605. msg_buf[index++] = DEV_SEED;
  606. memcpy(&msg_buf[index],&Dev.Seed.facid,sizeof(Seed_info));
  607. index += sizeof(Seed_info);
  608. devinfo_time.seed = false;
  609. }
  610. else if (Dev.Pump_Link.connect_status == COMP_NORMAL && devinfo_time.pump == true)
  611. {
  612. msg_buf[index++] = DEV_PUMP;
  613. memcpy(&msg_buf[index],&Dev.Pump.facid,sizeof(Pump_info));
  614. index += sizeof(Pump_info);
  615. devinfo_time.pump = false;
  616. }
  617. else if (Dev.Nozzle_Link.connect_status == COMP_NORMAL && devinfo_time.nozzle == true)
  618. {
  619. msg_buf[index++] = DEV_NOZZLE;
  620. memcpy(&msg_buf[index],&Dev.Nozzle.facid,sizeof(Nozzle_info));
  621. index += sizeof(Nozzle_info);
  622. devinfo_time.nozzle = false;
  623. }
  624. else if (Dev.Arm_Link.connect_status == COMP_NORMAL && devinfo_time.arm == true)
  625. {
  626. msg_buf[index++] = DEV_ARM;
  627. memcpy(&msg_buf[index],&Dev.Arm.facid,sizeof(Arm_info));
  628. index += sizeof(Arm_info);
  629. devinfo_time.arm = false;
  630. }
  631. else if(Dev.Current_Link.connect_status == COMP_NORMAL && devinfo_time.current == true)
  632. {
  633. msg_buf[index++] = DEV_CURRENT;
  634. memcpy(&msg_buf[index],&Dev.Current.facid,sizeof(Current_info));
  635. index += sizeof(Current_info);
  636. devinfo_time.current = false;
  637. }
  638. else if(Dev.Temp_Sensor_Link.connect_status == COMP_NORMAL && devinfo_time.tempSensor == true)
  639. {
  640. msg_buf[index++] = DEV_TEMPSENSOR;
  641. memcpy(&msg_buf[index],&Dev.Temp_sensor.facid,sizeof(_Temp_sensor));
  642. index += sizeof(_Temp_sensor);
  643. devinfo_time.tempSensor = false;
  644. }
  645. else
  646. {
  647. send_flag = false;
  648. }
  649. msg_buf[1] = index - 6;
  650. crc = Get_Crc16(msg_buf, index);
  651. msg_buf[index++] = crc;
  652. msg_buf[index++] = (crc >> 8) & 0xff;
  653. if(send_flag == true)
  654. uart2_send_msg(msg_buf, index);
  655. }
  656. /**
  657. * @file radar_version_check
  658. * @brief 更改雷达版本格式
  659. * @param none
  660. * @details
  661. * @author Zhang Sir
  662. **/
  663. void radar_version_check(void)
  664. {
  665. //前避障
  666. if(uavr11_info.Link.connect_status == COMP_NORMAL || uavr11_info.Link.boot_flag == true)
  667. {
  668. if(uavr11_info.soft_verison == 0 && uavr11_info.get_radar_ver_flag == false)
  669. {
  670. uavr11_info.version[0] = 'M';
  671. uavr11_info.version[1] = '1';
  672. for(uint8_t i = 2;i < 10; i++)
  673. {
  674. uavr11_info.version[i] = '0';
  675. }
  676. }
  677. memcpy(&radar_version[0][0],&uavr11_info.version[0],10);
  678. }
  679. else if (mimo_f_info.Link.connect_status == COMP_NORMAL)
  680. {
  681. if(mimo_f_info.Link.boot_flag == true)
  682. {
  683. memcpy(&mimo_f_info.version,"E100000000",10);
  684. }
  685. memcpy(&radar_version[0][0],&mimo_f_info.version[0],10);
  686. }
  687. else if(DM_f_info.Link.connect_status == COMP_NORMAL)
  688. {
  689. memcpy(&radar_version[0][0],&DM_f_info.version[0],10);
  690. }
  691. //后避障
  692. if(uavr12_info.Link.connect_status == COMP_NORMAL )
  693. {
  694. if(uavr12_info.soft_verison == 0 && uavr12_info.get_radar_ver_flag == false)
  695. {
  696. uavr12_info.version[0] = 'M';
  697. uavr12_info.version[1] = '2';
  698. for(uint8_t i = 2;i < 10; i++)
  699. {
  700. uavr12_info.version[i] = '0';
  701. }
  702. }
  703. memcpy(&radar_version[1][0],&uavr12_info.version[0],10);
  704. }
  705. else if(mimo_b_info.Link.connect_status == COMP_NORMAL)
  706. {
  707. if(mimo_b_info.Link.boot_flag == true)
  708. {
  709. memcpy(&mimo_b_info.version,"E200000000",10);
  710. }
  711. memcpy(&radar_version[1][0],&mimo_b_info.version[0],10);
  712. }
  713. if(uavr56_info.Link.connect_status == COMP_NORMAL )
  714. {
  715. if(uavr56_info.soft_verison == 0 && uavr56_info.get_radar_ver_flag == false)
  716. {
  717. uavr56_info.version[0] = 'M';
  718. uavr56_info.version[1] = 'B';
  719. for(uint8_t i = 2;i < 10; i++)
  720. {
  721. uavr56_info.version[i] = '0';
  722. }
  723. }
  724. memcpy(&radar_version[2][0],&uavr56_info.version[0],10);
  725. }
  726. else if(mimo_ter_info.Link.connect_status == COMP_NORMAL)
  727. {
  728. if(mimo_ter_info.Link.boot_flag == true)
  729. {
  730. memcpy(&mimo_ter_info.version,"EB00000000",10);
  731. }
  732. memcpy(&radar_version[2][0],&mimo_ter_info.version[0],10);
  733. }
  734. else if(DM_ter_info.Link.connect_status == COMP_NORMAL)
  735. {
  736. memcpy(&radar_version[2][0],&DM_ter_info.version[0],10);
  737. }
  738. }
  739. /**
  740. * @file pmu_to_con_version_data
  741. * @brief PMU发送版本信息
  742. * @param none
  743. * @details
  744. * @author Zhang Sir
  745. **/
  746. char radar_version[3][10] = {0}; //0 前避障 1后避障 2仿地
  747. void pmu_to_con_version_data()
  748. {
  749. //版本信息 0 - 5 硬件版本 IAP版本 APP版本
  750. uint32_t ver_msg_buf[4] = {0};
  751. int index = 0;
  752. ver_msg_buf[0] = serial.num; //硬件版本号
  753. ver_msg_buf[1] = IAP_VERSION; //IAP版本号
  754. ver_msg_buf[2] = APP_VERSION; //APP版本号
  755. ver_msg_buf[3] = serial.num;//serial.num;
  756. msg_buf[index++] = 0xFE;
  757. msg_buf[index++] = 0;
  758. msg_buf[index++] = 0;
  759. msg_buf[index++] = 0x00;
  760. msg_buf[index++] = 0x00;
  761. msg_buf[index++] = MSGID_REQ_VERSION;
  762. radar_version_check();
  763. memcpy(&msg_buf[index], ver_msg_buf, 16);
  764. index += 16;
  765. memcpy(&msg_buf[index], &radar_version[0][0], 10);
  766. index += 10;
  767. memcpy(&msg_buf[index], &radar_version[1][0], 10);
  768. index += 10;
  769. memcpy(&msg_buf[index], &radar_version[2][0], 10);
  770. index += 10;
  771. msg_buf[1] = index - 6;
  772. crc = Get_Crc16(msg_buf, index);
  773. memcpy(&msg_buf[index], &crc, 2);
  774. index += 2;
  775. uart2_send_msg(msg_buf, index);
  776. }
  777. /**
  778. * @file pmu_to_fcu_version_data
  779. * @brief 版本信息发送,新协议还没用
  780. * @param none
  781. * @details
  782. * @author Zhang Sir
  783. **/
  784. void pmu_to_fcu_version_data()
  785. {
  786. dev_version_content *ptr = NULL;
  787. for(uint8_t i = 0;i < dev_num;i++)
  788. {
  789. ptr = dev_ptr[i];
  790. if(ptr->send_times > 0)
  791. {
  792. break;
  793. }
  794. if(i == dev_num - 1)
  795. {
  796. return;
  797. }
  798. }
  799. uint8_t index = 0;
  800. msg_buf[index++] = 0xFE;
  801. msg_buf[index++] = 0;
  802. msg_buf[index++] = 0;
  803. msg_buf[index++] = 0x00;
  804. msg_buf[index++] = 0x00;
  805. msg_buf[index++] = _MSGID_DEV_LIST;
  806. memcpy(&msg_buf[index],&ptr->num,sizeof(dev_version_content) - sizeof(regist_type) - 1);
  807. index += sizeof(dev_version_content) - sizeof(regist_type) - 1;
  808. msg_buf[1] = index - 6;
  809. crc = Get_Crc16(msg_buf, index);
  810. memcpy(&msg_buf[index], &crc, 2);
  811. index += 2;
  812. uart2_send_msg(msg_buf, index);
  813. }
  814. /**
  815. * @file pmu_to_fcu_key_data
  816. * @brief PMU发送秘钥信息
  817. * @param none
  818. * @details 格式电池秘钥匹配
  819. * @author Zhang Sir
  820. **/
  821. void pmu_to_fcu_key_data(void)
  822. {
  823. uint8_t index = 0;
  824. msg_buf[index++] = 0xFE;
  825. msg_buf[index++] = 0;
  826. msg_buf[index++] = 0;
  827. msg_buf[index++] = 0x00;
  828. msg_buf[index++] = 0x00;
  829. msg_buf[index++] = _MSGID_SHA1;
  830. msg_buf[index++] = start_msg.Dev_type;
  831. msg_buf[index++] = start_msg.Id;
  832. msg_buf[index++] = start_msg.Id_content;
  833. // if(start_msg.Id == 4)
  834. // {
  835. // start_msg.key_info_checking = false; //发送状态后结束发送
  836. // }
  837. memcpy(&msg_buf[index],&start_msg.key_data[0],20);
  838. index += 20;
  839. msg_buf[1] = index - 6;
  840. crc = Get_Crc16(msg_buf, index);
  841. memcpy(&msg_buf[index], &crc, 2);
  842. index += 2;
  843. uart2_send_msg(msg_buf, index);
  844. }
  845. /**
  846. * @file pmu_to_con_request_data
  847. * @brief PMU发送请求信息
  848. * @param none
  849. * @details
  850. * @author Zhang Sir
  851. **/
  852. char request_id = 0;
  853. short request_1_content = 0;
  854. int request_2_content = 0;
  855. void pmu_to_con_request_data()
  856. {
  857. int index = 0;
  858. msg_buf[index++] = 0xFE;
  859. msg_buf[index++] = 0;
  860. msg_buf[index++] = 0;
  861. msg_buf[index++] = 0x00;
  862. msg_buf[index++] = 0x00;
  863. msg_buf[index++] = 20;
  864. msg_buf[index++] = request_id;
  865. memcpy(&msg_buf[index],&request_1_content,2);
  866. index += 2;
  867. memcpy(&msg_buf[index],&request_2_content,4);
  868. index += 4;
  869. msg_buf[1] = index - 6;
  870. crc = Get_Crc16(msg_buf, index);
  871. memcpy(&msg_buf[index], &crc, 2);
  872. index += 2;
  873. uart2_send_msg(msg_buf, index);
  874. }
  875. /**
  876. * @file pmu_to_con_request_data
  877. * @brief PMU发送应答信息
  878. * @param none
  879. * @details
  880. * @author Zhang Sir
  881. **/
  882. char ack_id = 0;
  883. short ack_content = 0;
  884. short ack_content1 = 0;
  885. short ack_content2 = 0;
  886. void pmu_to_con_ack_data()
  887. {
  888. int index = 0;
  889. msg_buf[index++] = 0xFE;
  890. msg_buf[index++] = 0;
  891. msg_buf[index++] = 0;
  892. msg_buf[index++] = 0x00;
  893. msg_buf[index++] = 0x00;
  894. msg_buf[index++] = 21;
  895. msg_buf[index++] = ack_id;
  896. memcpy(&msg_buf[index],&ack_content,2);
  897. index += 2;
  898. memcpy(&msg_buf[index],&ack_content1,2);
  899. index += 2;
  900. memcpy(&msg_buf[index],&ack_content2,2);
  901. index += 2;
  902. msg_buf[1] = index - 6;
  903. crc = Get_Crc16(msg_buf, index);
  904. memcpy(&msg_buf[index], &crc, 2);
  905. index += 2;
  906. uart2_send_msg(msg_buf, index);
  907. }
  908. /******************void pmu_to_fcu()******************************
  909. * ****************PMU发送信息给主控********************************
  910. * ****************************************************************/
  911. /**
  912. * @file pmu_to_fcu
  913. * @brief PMU发送信息给FMU
  914. * @param none
  915. * @details UART2
  916. * @author Zhang Sir
  917. **/
  918. uint8_t pmu_send = PMU_SEND_YAOCE;
  919. uint32_t utc_time = 0;
  920. void pmu_to_fcu()
  921. {
  922. //串口阻塞 和雷达升级不发送
  923. if(uart_info.vk_dev_update_flag != true && EZup_par.update_flag != true && Rupdate.update_flag != true)
  924. {
  925. switch (pmu_send)
  926. {
  927. case PMU_SEND_YAOCE:
  928. //发送电压信息
  929. if (vol_flag == true)
  930. {
  931. pmu_to_con_voltage_data();
  932. vol_flag = false;
  933. }
  934. //发动机信息
  935. else if (engine_flag == true)
  936. {
  937. pmu_to_con_engine_data();
  938. engine_flag = false;
  939. }
  940. // //mimo360测试
  941. // else if (mimo360_radar_flag == true)
  942. // {
  943. // pmu_to_con_radar360_data();
  944. // mimo360_radar_flag = false;
  945. // }
  946. //电目雷达测试
  947. else if(DM_radar_flag == true)
  948. {
  949. pmu_to_con_DMradar_data();
  950. DM_radar_flag = false;
  951. }
  952. //CAN调试信息
  953. else if(can_debug_flag == true)
  954. {
  955. Can_send_debug_to_app();
  956. can_debug_flag = false;
  957. }
  958. //设备SN号,软硬件号
  959. else if (dev_version_flag == true)
  960. {
  961. pmu_to_fcu_version_data();
  962. dev_version_flag = false;
  963. }
  964. //设备信息
  965. else if (devtype_flag == true)
  966. {
  967. pmu_to_con_devtype_data();
  968. devtype_flag = false;
  969. }
  970. break;
  971. case PMU_SEND_REQINFO:
  972. pmu_to_con_request_data();
  973. pmu_send = PMU_SEND_YAOCE;
  974. break;
  975. case PMU_SEND_ACK:
  976. pmu_to_con_ack_data();
  977. pmu_send = PMU_SEND_YAOCE;
  978. break;
  979. case PMU_SEND_VERSION:
  980. pmu_to_con_version_data();
  981. pmu_send = PMU_SEND_YAOCE;
  982. break;
  983. case PMU_SEND_SHA1:
  984. pmu_to_fcu_key_data();
  985. pmu_send = PMU_SEND_YAOCE;
  986. break;
  987. case PMU_SEND_DEV_INFO:
  988. pmu_to_fcu_version_data();
  989. pmu_send = PMU_SEND_YAOCE;
  990. break;
  991. default:
  992. break;
  993. }
  994. //心跳包单独发
  995. if(pmu_heart_flag == true)
  996. {
  997. pmu_to_con_heart_data();
  998. pmu_heart_flag = false;
  999. }
  1000. }
  1001. }
  1002. void Check_Rst(void)
  1003. {
  1004. if(__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET ) // NRST 引脚复位
  1005. {
  1006. uavinf.reset_reason = R_NRST;
  1007. write_uav_information = true;
  1008. __HAL_RCC_CLEAR_RESET_FLAGS();
  1009. }
  1010. if(__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET ) // 上电掉电复位
  1011. {
  1012. uavinf.reset_reason = R_POWER;
  1013. write_uav_information = true;
  1014. __HAL_RCC_CLEAR_RESET_FLAGS();
  1015. }
  1016. if(__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET ) // 软件复位
  1017. {
  1018. uavinf.reset_reason = R_SOFT;
  1019. write_uav_information = true;
  1020. __HAL_RCC_CLEAR_RESET_FLAGS();
  1021. }
  1022. if(__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET ) // 独立看门狗复位
  1023. {
  1024. uavinf.reset_reason = R_IWD;
  1025. write_uav_information = true;
  1026. __HAL_RCC_CLEAR_RESET_FLAGS();
  1027. }
  1028. if(__HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST) != RESET ) // 窗口看门狗复位
  1029. {
  1030. uavinf.reset_reason = R_WWD;
  1031. write_uav_information = true;
  1032. __HAL_RCC_CLEAR_RESET_FLAGS();
  1033. }
  1034. if(__HAL_RCC_GET_FLAG(RCC_FLAG_LPWRRST) != RESET ) // 低功耗复位
  1035. {
  1036. uavinf.reset_reason = R_LOPWER;
  1037. write_uav_information = true;
  1038. __HAL_RCC_CLEAR_RESET_FLAGS();
  1039. }
  1040. }
  1041. /******************void check_fmu_link()************************
  1042. * ****************检查是否收到FMU信息************************************
  1043. * ****************************************************************/
  1044. static uint32_t fmu_link_time = 0;
  1045. void check_fmu_link()
  1046. {
  1047. //FMU串口通讯连接检测
  1048. if(HAL_GetTick() > 15000)
  1049. {
  1050. if(recv_fmu_data == true && HAL_GetTick() - fmu_link_time > 3000)
  1051. {
  1052. recv_fmu_data = false;
  1053. }
  1054. }
  1055. //FMU异常断电检测
  1056. if((planep.lock_status != STA_LOCK) && (recv_fmu_data == true) && (HAL_GetTick() - fmu_link_time > 500))
  1057. {
  1058. uavinf.abnormal_outage_flag = 1;
  1059. write_uav_information = true;
  1060. recv_fmu_data = false;
  1061. }
  1062. //Check_Rst();
  1063. }
  1064. /******************void uart_recv_con_msg()************************
  1065. * ****************PMU收控制消息************************************
  1066. * ****************************************************************/
  1067. _pmu_pin pmu_pin;
  1068. bool recv_fmu_data = false;
  1069. Set_info msgidset;
  1070. void uart_recv_con_msg()
  1071. {
  1072. check_fmu_link();
  1073. check_uart_data(&recv_rkfifo);
  1074. if (uart_info.fcu_buf_flag == true)
  1075. {
  1076. uint32_t tem_32t = 0;
  1077. FLASH_EraseInitTypeDef f;
  1078. fmu_link_time = HAL_GetTick();
  1079. recv_fmu_data = true;
  1080. switch (fcu_protocol.msg_id)
  1081. {
  1082. case _MSGID_PWM:
  1083. memcpy(&pmu_pin.pump1, &fcu_protocol.payload[6], sizeof(_pmu_pin));
  1084. if(set_HWesc_ESCid == true && setESCidInfo.setESCidStep == SETESCID_SET)
  1085. {
  1086. memset(&pmu_pin.pump1,0,4);
  1087. if(setESCidInfo.setESCidNum == 1)
  1088. pmu_pin.pump1 = 1000;
  1089. else if(setESCidInfo.setESCidNum == 2)
  1090. pmu_pin.pump2 = 1000;
  1091. }
  1092. __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, pmu_pin.pump1);
  1093. __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_2, pmu_pin.pump2);
  1094. if(planep.UAV_type == VK_ALL_IN_ONE)
  1095. {
  1096. __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, pmu_pin.nozz1_fm);
  1097. __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, pmu_pin.nozz2_zp);
  1098. }
  1099. else
  1100. {
  1101. __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, pmu_pin.nozz1_fm);
  1102. __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, pmu_pin.nozz2_zp);
  1103. }
  1104. if(planep.UAV_type == VK_ALL_IN_ONE)
  1105. {
  1106. //分电板离心喷头
  1107. distributor.nozzle1 = pmu_pin.nozz1_fm;
  1108. distributor.nozzle2 = pmu_pin.nozz2_zp;
  1109. //离心喷头34
  1110. __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_4, pmu_pin.nozz3); // PB8 nozzle
  1111. __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, pmu_pin.nozz4); // PB9 nozzle
  1112. //前后灯
  1113. if((pmu_pin.aux_light & 0x1) > 0)
  1114. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_SET);
  1115. else
  1116. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_RESET);
  1117. if((pmu_pin.aux_light & 0x2) > 0)
  1118. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_SET);
  1119. else
  1120. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_RESET);
  1121. //摄像头舵机
  1122. __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, pmu_pin.aux_steer);
  1123. }
  1124. break;
  1125. case _MSGID_LED:
  1126. for(uint8_t i = 0; i < 7; i++)
  1127. {
  1128. if(planep.UAV_type != VK_ALL_IN_ONE ) //青岛机型不用LED
  1129. {
  1130. led_set_blink(i, fcu_protocol.payload[i*3+6], fcu_protocol.payload[i*3+7], fcu_protocol.payload[i*3+8]);
  1131. }
  1132. }
  1133. break;
  1134. //飞机姿态信息
  1135. case _MSGID_ATTITUDE:
  1136. memcpy(&planep.yaw, &fcu_protocol.payload[6], sizeof(plane_para));
  1137. if(uavinf.uavtype != planep.UAV_type)
  1138. {
  1139. write_uav_information = true;
  1140. }
  1141. break;
  1142. case _MSGID_TIME:
  1143. //tem_32t = 1684136124;
  1144. memcpy(&utc_time, &fcu_protocol.payload[6], 4);
  1145. covUnixTimeStp2Beijing(utc_time,&beijing_time);
  1146. pmu_set_ack(_MSGID_TIME,0,0,0);
  1147. break;
  1148. //eft播撒器
  1149. case _MSGID_EFT_CON:
  1150. recv_fmu_seed_info = true;
  1151. memcpy(&tppwm_value, &fcu_protocol.payload[6], 2);
  1152. memcpy(&sow_rotate_value, &fcu_protocol.payload[8], 2);
  1153. break;
  1154. //请求信息包
  1155. case _MSGID_REQ:
  1156. switch (fcu_protocol.payload[6])
  1157. {
  1158. case MSGID_REQ_VERSION:
  1159. pmu_send = PMU_SEND_VERSION;
  1160. break;
  1161. default:
  1162. break;
  1163. }
  1164. break;
  1165. //主控应答
  1166. case _MSGID_ACK:
  1167. msgidset.content1 = fcu_protocol.payload[7] + 256 * fcu_protocol.payload[8];
  1168. switch (fcu_protocol.payload[6])
  1169. {
  1170. case MSGID_ACK_HEART:
  1171. uavinf.abnormal_outage_flag = 0;
  1172. write_uav_information = true;
  1173. break;
  1174. case MSGID_ACK_VERSION:
  1175. start_msg.version_info = true;
  1176. break;
  1177. case MSGID_ACK_DEV:
  1178. {
  1179. if(msgidset.content1 < DEVICE_END - 1)
  1180. {
  1181. dev_version_content *Pt = dev_ptr[msgidset.content1];
  1182. if(Pt->send_times > 0)
  1183. Pt->send_times--;
  1184. }
  1185. }
  1186. break;
  1187. default:
  1188. break;
  1189. }
  1190. break;
  1191. //设置雷达灵敏度
  1192. case _MSGID_SET:
  1193. msgidset.num = fcu_protocol.payload[6];
  1194. msgidset.content1 = fcu_protocol.payload[7] + 256 * fcu_protocol.payload[8];
  1195. msgidset.content2 = fcu_protocol.payload[9] + 256 * fcu_protocol.payload[10];
  1196. switch (msgidset.num)
  1197. {
  1198. //前雷达
  1199. case MSGID_SET_F_RADAR:
  1200. if(uavr12_info.fcu_set_sensi_flag != true && uavr56_info.fcu_set_sensi_flag != true && radar_update_flag == false)
  1201. {
  1202. uavr11_info.fcu_set_sensi_flag = true;
  1203. }
  1204. memcpy(&obsfradar_sensitivity, &fcu_protocol.payload[7], 2);
  1205. if(obsfradar_sensitivity == uavr11_info.get_radar_sensi)
  1206. {
  1207. uavr11_info.fcu_set_sensi_flag = false;
  1208. pmu_set_ack(_MSGID_SET,MSGID_SET_F_RADAR,uavr11_info.get_radar_sensi,0);
  1209. }
  1210. break;
  1211. //后雷达
  1212. case MSGID_SET_B_RADAR:
  1213. if(uavr11_info.fcu_set_sensi_flag != true && uavr56_info.fcu_set_sensi_flag != true && radar_update_flag == false)
  1214. {
  1215. uavr12_info.fcu_set_sensi_flag = true;
  1216. }
  1217. memcpy(&obsbradar_sensitivity, &fcu_protocol.payload[7], 2);
  1218. if(obsbradar_sensitivity == uavr12_info.get_radar_sensi)
  1219. {
  1220. uavr12_info.fcu_set_sensi_flag = false;
  1221. pmu_set_ack(_MSGID_SET,MSGID_SET_B_RADAR,uavr12_info.get_radar_sensi,0);
  1222. }
  1223. break;
  1224. //仿地
  1225. case MSGID_SET_T_RADAR:
  1226. if(uavr11_info.fcu_set_sensi_flag != true && uavr12_info.fcu_set_sensi_flag != true && radar_update_flag == false)
  1227. {
  1228. uavr56_info.fcu_set_sensi_flag = true;
  1229. }
  1230. memcpy(&uavr56_info.fcu_set_sensi, &fcu_protocol.payload[7], 2);
  1231. if(uavr56_info.fcu_set_sensi == uavr56_info.get_radar_sensi)
  1232. {
  1233. uavr56_info.fcu_set_sensi_flag = false;
  1234. pmu_set_ack(_MSGID_SET,MSGID_SET_T_RADAR,uavr56_info.get_radar_sensi,0);
  1235. }
  1236. break;
  1237. case MSGID_SET_TR_BLIND:
  1238. {
  1239. uint8_t can_buf[8] = {0};
  1240. uint32_t can_id = 0;
  1241. if(msgidset.content1 == 0x11)
  1242. can_id = 0xA81300;
  1243. else if (msgidset.content1 == 0x56)
  1244. can_id = 0x981300;
  1245. put_date_to_can(can_buf,0x5,(msgidset.content2 & 0xff),((msgidset.content2 >> 8) & 0xff),0,0,0,0,0X7);
  1246. can_send_msg_normal(&can_buf[0], 8, can_id);
  1247. }
  1248. break;
  1249. case MSGID_SET_BR_POWER:
  1250. {
  1251. uint8_t can_buf[8] = {0};
  1252. uint32_t can_id = 0;
  1253. if(msgidset.content1 == 0x11)
  1254. can_id = 0xA81300;
  1255. else if (msgidset.content1 == 0x56)
  1256. can_id = 0x981300;
  1257. put_date_to_can(can_buf,0x7,(msgidset.content2 & 0xff),((msgidset.content2 >> 8) & 0xff),0,0,0,0,0X7);
  1258. can_send_msg_normal(&can_buf[0], 8, can_id);
  1259. }
  1260. break;
  1261. case MSGID_SET_R_FUNC:
  1262. {
  1263. uint8_t can_buf[8] = {0};
  1264. uint32_t can_id = 0;
  1265. if(msgidset.content1 == 3)
  1266. can_id = 0x981300;
  1267. else if(msgidset.content1 == 5)
  1268. can_id = 0xA81300;
  1269. put_date_to_can(can_buf,0x4,(msgidset.content1 & 0xff),((msgidset.content1 >> 8) & 0xff),0,0,0,0,0X7);
  1270. can_send_msg_normal(&can_buf[0], 8, can_id);
  1271. }
  1272. break;
  1273. case MSGID_SET_RAW_SWITCH:
  1274. {
  1275. uint8_t can_buf[8] = {0};
  1276. uint32_t can_id = 0;
  1277. if(msgidset.content1 == 0x11)
  1278. can_id = 0xA81300;
  1279. else if (msgidset.content1 == 0x56)
  1280. can_id = 0x981300;
  1281. put_date_to_can(can_buf,0xA,(msgidset.content2 & 0xff),((msgidset.content2 >> 8) & 0xff),0,0,0,0,0X7);
  1282. can_send_msg_normal(&can_buf[0], 8, can_id);
  1283. }
  1284. break;
  1285. case MSGID_SET_GEELY:
  1286. switch (fcu_protocol.payload[7])
  1287. {
  1288. case SET_START_OR_STOP:
  1289. if(0x1 == fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00))
  1290. {
  1291. if (geely_engin_link.connect_status == COMP_NORMAL && geely_data.engine_control == 0)
  1292. {
  1293. sendto_geely.ExtenderControl = 1;
  1294. }
  1295. start_engine = 0x80;
  1296. }
  1297. else if(0x0 == fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00))
  1298. {
  1299. if (geely_engin_link.connect_status == COMP_NORMAL && geely_data.engine_control == 1)
  1300. {
  1301. sendto_geely.ExtenderControl = 0;
  1302. }
  1303. start_engine = 0;
  1304. }
  1305. break;
  1306. case SET_PROTECT_TIME:
  1307. if (geely_engin_link.connect_status == COMP_NORMAL)
  1308. {
  1309. geely_set_tcd = true;
  1310. sendto_geely.SettingParameter = fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00);
  1311. }
  1312. break;
  1313. case SET_LOCK_TIME:
  1314. if (geely_engin_link.connect_status == COMP_NORMAL)
  1315. {
  1316. geely_set_tlock = true;
  1317. sendto_geely.SettingParameter = fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00);
  1318. }
  1319. break;
  1320. case SET_LOWVOL_PROTECT:
  1321. if(0x1 == fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00))
  1322. {
  1323. if (geely_engin_link.connect_status == COMP_NORMAL)
  1324. {
  1325. sendto_geely.ExtenderControl = 1;
  1326. geely_set_protect = true;
  1327. }
  1328. }
  1329. else
  1330. {
  1331. geely_set_protect = false;
  1332. }
  1333. break;
  1334. default:
  1335. break;
  1336. }
  1337. break;
  1338. case MSGID_SET_VOL:
  1339. set_cali_voltage = (fcu_protocol.payload[7] + 256 * fcu_protocol.payload[8]) - (int)(ADC_gather() /100.0f) ;
  1340. write_vol_information = true;
  1341. pmu_set_ack(_MSGID_SET,MSGID_SET_VOL,0,0);
  1342. break;
  1343. case MSGID_SET_MIMO_FLOW:
  1344. if(msgidset.content1 != 0)
  1345. {
  1346. if(Dev.Flow.facid == FAC_MIMO_SIG || Dev.Flow.facid == FAC_MIMO_DOU)
  1347. {
  1348. tem_32t = flow_mimo1.flow_k * msgidset.content1 / 100;
  1349. if(tem_32t >= 500 && tem_32t <= 20000)
  1350. {
  1351. flow_mimo1.flow_calk = tem_32t;
  1352. }
  1353. else{
  1354. flow_mimo1.flow_calk = 10000;
  1355. }
  1356. flow_mimo1.send_k_count = 5;
  1357. }
  1358. else if(Dev.Flow.facid == FAC_QIFEI_SIG || Dev.Flow.facid == FAC_QIFEI_DOU)
  1359. {
  1360. tem_32t = flow_inf.ch1.k * msgidset.content1 / 100;
  1361. if(tem_32t >= 500 && tem_32t <= 20000)
  1362. {
  1363. flow_inf.ch1.cal_k = tem_32t;
  1364. }
  1365. else{
  1366. flow_inf.ch1.cal_k = 10000;
  1367. }
  1368. flow_inf.ch1.set_k = true;
  1369. }
  1370. }
  1371. if(msgidset.content2 != 0)
  1372. {
  1373. if(Dev.Flow.facid == FAC_MIMO_SIG || Dev.Flow.facid == FAC_MIMO_DOU)
  1374. {
  1375. tem_32t = flow_mimo2.flow_k * msgidset.content2 / 100;
  1376. if(tem_32t >= 500 && tem_32t <= 20000)
  1377. {
  1378. flow_mimo2.flow_calk = tem_32t;
  1379. }
  1380. else{
  1381. flow_mimo2.flow_calk = 10000;
  1382. }
  1383. flow_mimo2.send_k_count = 5;
  1384. }
  1385. else if(Dev.Flow.facid == FAC_QIFEI_SIG || Dev.Flow.facid == FAC_QIFEI_DOU)
  1386. {
  1387. tem_32t = flow_inf.ch2.k * msgidset.content2 / 100;
  1388. if(tem_32t >= 500 && tem_32t <= 20000)
  1389. {
  1390. flow_inf.ch2.cal_k = tem_32t;
  1391. }
  1392. else{
  1393. flow_inf.ch2.cal_k = 10000;
  1394. }
  1395. flow_inf.ch1.set_k = true;
  1396. }
  1397. }
  1398. break;
  1399. case MSGID_SET_FLOW_BACKGROUND:
  1400. if(Dev.Flow.facid == FAC_MIMO_SIG)
  1401. {
  1402. flow_inf.ch1.clear_background = true;
  1403. }
  1404. if(Dev.Flow.facid == FAC_MIMO_DOU)
  1405. {
  1406. flow_inf.ch1.clear_background = true;
  1407. flow_inf.ch2.clear_background = true;
  1408. }
  1409. break;
  1410. case MSGID_SET_WEIGHT_K:
  1411. //calib_aux = msgidset.content1 + (msgidset.content2 << 2); //bit 0-1 编号 2-15K值
  1412. weight_order.type = Weight_Set_K;
  1413. weight_order.order_con1 = msgidset.content1;
  1414. weight_order.order_con2 = msgidset.content2;
  1415. break;
  1416. case MSGID_SET_SEED_OUT_TYPE:
  1417. recv_fmu_seed_info = true;
  1418. seed_output_mode = msgidset.content1;
  1419. pmu_set_ack(_MSGID_SET,MSGID_SET_SEED_OUT_TYPE,0,0);
  1420. break;
  1421. case MSGID_SET_SEED_CAL_TYPE:
  1422. switch (msgidset.content1)
  1423. {
  1424. case Cal_Remove_Peel:
  1425. weight_order.type = Weight_Peer;
  1426. break;
  1427. case Cal_Weight:
  1428. weight_order.type = Weight_Kg;
  1429. weight_order.order_con2 = msgidset.content2;
  1430. break;
  1431. case Cal_Seed_Back:
  1432. weight_order.type = Weight_Bcak;
  1433. break;
  1434. default:
  1435. break;
  1436. }
  1437. break;
  1438. case MSGID_SET_WEIGHT_MODE:
  1439. weight_order.type = Weight_Mode;
  1440. weight_order.order_con1 = msgidset.content1;
  1441. break;
  1442. case MSGID_SET_MAX_RATE:
  1443. weight_order.type = Weight_Drug_Rate;
  1444. weight_order.order_con1 = msgidset.content1;
  1445. break;
  1446. case MSGID_SET_PMU_SERIAL:
  1447. set_pmu_serail = msgidset.content1 + ((msgidset.content2 << 16) & 0xffff0000);
  1448. if(serial.num == PMU_SERIAL || set_pmu_serail == PMU_SERIAL)
  1449. {
  1450. write_serial_information = true;
  1451. pmu_set_ack(_MSGID_SET,MSGID_SET_PMU_SERIAL,0,0);
  1452. dev_pmu.send_times += 5;
  1453. }
  1454. else if(set_pmu_serail == serial.num)
  1455. {
  1456. pmu_set_ack(_MSGID_SET,MSGID_SET_PMU_SERIAL,0,0);
  1457. }
  1458. break;
  1459. case MSGID_SET_RADAR_FB:
  1460. {
  1461. uint8_t can_buf[8] = {0};
  1462. if(msgidset.content1 == 0x11)
  1463. {
  1464. put_date_to_can(can_buf,0x55,0XAA,0X03,0X61,0X03,0X01,0X65,0X00);
  1465. can_send_msg_normalstd(can_buf,7,0xFA);
  1466. }
  1467. else if (msgidset.content1 == 0x12)
  1468. {
  1469. put_date_to_can(can_buf,0x55,0XAA,0X03,0X61,0X03,0X02,0X66,0X00);
  1470. can_send_msg_normalstd(can_buf,7,0xFA);
  1471. }
  1472. else if(msgidset.content1 == 0x100)
  1473. {
  1474. if(msgidset.content2 == 0x11 || msgidset.content2 == 0x12)
  1475. {
  1476. put_date_to_can(can_buf,0x55,0XAA,0X03,0X61,0X00,0X03,0X64,0X00);
  1477. can_send_msg_normalstd(can_buf,7,0xFA);
  1478. }
  1479. else if(msgidset.content2 == 0x56)
  1480. {
  1481. put_date_to_can(can_buf,0x55,0XAA,0X02,0X60,0X03,0X63,0X00,0X00);
  1482. can_send_msg_normalstd(can_buf,6,0xFA);
  1483. }
  1484. }
  1485. }
  1486. break;
  1487. case MSGID_SET_LACKLOSS_CAL:
  1488. {
  1489. uint8_t can_buf[8] = {0};
  1490. if(Dev.Lackloss_Link.connect_status == COMP_NORMAL)
  1491. {
  1492. mimo_lackloss.cal_distance = mimo_lackloss.distance / 10 + 5;
  1493. put_date_to_can(can_buf,0xFA,0x03,0x00,0xB1,0XC1,0x00,0X00,0X00);
  1494. can_buf[6] = mimo_lackloss.cal_distance & 0xff;
  1495. can_buf[5] = (mimo_lackloss.cal_distance >> 8) & 0xff;
  1496. can_buf[7] = (can_buf[1]+can_buf[2]+can_buf[3]+can_buf[4]+can_buf[5]+can_buf[6]) & 0xff;
  1497. can_send_msg_normalstd(can_buf,8,0xFA);
  1498. }
  1499. }
  1500. break;
  1501. case MSGID_SET_PUMP_ID:
  1502. set_HWesc_ESCid = true;
  1503. setESCidInfo.setESCidNum = 1;
  1504. setESCidInfo.setESCidStep = SETESCID_INIT;
  1505. pmu_set_ack(_MSGID_SET,MSGID_SET_PUMP_ID,0,2);
  1506. break;
  1507. case MSGID_SET_FRADAR_SN:
  1508. {
  1509. int radar_Sn = 0;
  1510. uint8_t can_buf[8] = {0};
  1511. radar_Sn = msgidset.content1 + (msgidset.content2 << 16);
  1512. can_buf[0] = 2;
  1513. memcpy(&can_buf[1],&radar_Sn,4);
  1514. can_buf[7] = 7;
  1515. can_send_msg_normal(can_buf,8,0xA81300);
  1516. DM_f_info.get_radar_ver_flag = false;
  1517. dev_obsf.regist.sn = false;
  1518. pmu_set_ack(_MSGID_SET,MSGID_SET_FRADAR_SN,msgidset.content1,msgidset.content2);
  1519. }
  1520. break;
  1521. case MSGID_SET_BRADAR_SN:
  1522. {
  1523. int radar_Sn = 0;
  1524. uint8_t can_buf[8] = {0};
  1525. radar_Sn = msgidset.content1 + (msgidset.content2 << 16);
  1526. can_buf[0] = 2;
  1527. memcpy(&can_buf[1],&radar_Sn,4);
  1528. can_buf[7] = 7;
  1529. can_send_msg_normal(can_buf,8,0xB81300);
  1530. dev_obsb.regist.sn = false;
  1531. //DM_b_info.get_radar_ver_flag = false;
  1532. pmu_set_ack(_MSGID_SET,MSGID_SET_BRADAR_SN,msgidset.content1,msgidset.content2);
  1533. }
  1534. break;
  1535. case MSGID_SET_TRADAR_SN:
  1536. {
  1537. int radar_Sn = 0;
  1538. uint8_t can_buf[8] = {0};
  1539. radar_Sn = msgidset.content1 + (msgidset.content2 << 16);
  1540. can_buf[0] = 2;
  1541. memcpy(&can_buf[1],&radar_Sn,4);
  1542. can_buf[7] = 7;
  1543. can_send_msg_normal(can_buf,8,0x981300);
  1544. DM_ter_info.get_radar_ver_flag = false;
  1545. dev_ter.regist.sn = false; //重新获取sn
  1546. pmu_set_ack(_MSGID_SET,MSGID_SET_TRADAR_SN,msgidset.content1,msgidset.content2);
  1547. }
  1548. break;
  1549. default:
  1550. break;
  1551. }
  1552. break;
  1553. case _MSGID_HEART:
  1554. pmu_heart_flag = true;
  1555. break;
  1556. case _MSGID_SHA1:
  1557. //智能电池秘钥
  1558. if(fcu_protocol.payload[6] == 1)
  1559. {
  1560. //有秘钥
  1561. if(fcu_protocol.payload[7] == 2 && fcu_protocol.payload[8] == 1)
  1562. {
  1563. if(start_msg.key_info_checking == true)
  1564. {
  1565. memcpy(&start_msg.key_data[0],&fcu_protocol.payload[9],20);
  1566. start_msg.key_to_bms = true;//给电池发送秘钥
  1567. start_msg.key_info_checking = false;
  1568. }
  1569. }
  1570. //无秘钥
  1571. else if(fcu_protocol.payload[7] == 2 && fcu_protocol.payload[8] == 2)
  1572. {
  1573. start_msg.key_info_checking = false;
  1574. }
  1575. //回馈,防止PMU一直发
  1576. else if(fcu_protocol.payload[7] == 3 || fcu_protocol.payload[7] == 4)
  1577. {
  1578. start_msg.key_info_checking = false;
  1579. }
  1580. }
  1581. break;
  1582. //升级固件标志
  1583. case _MSGID_UPDATA:
  1584. {
  1585. __disable_irq();
  1586. HAL_FLASH_Unlock();
  1587. __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
  1588. f.TypeErase = FLASH_TYPEERASE_PAGES;
  1589. f.PageAddress = UPDATE_FLAG;
  1590. f.NbPages = 1;
  1591. uint32_t PageError = 0;
  1592. HAL_FLASHEx_Erase(&f, &PageError);
  1593. uint16_t TempBuf = 0x01;
  1594. HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, UPDATE_FLAG, TempBuf);
  1595. HAL_FLASH_Lock();
  1596. __enable_irq();
  1597. HAL_NVIC_DisableIRQ(USART2_IRQn);
  1598. HAL_Delay(100);
  1599. //软件复位
  1600. HAL_NVIC_SystemReset();
  1601. }
  1602. break;
  1603. default:
  1604. break;
  1605. }
  1606. uart_info.fcu_buf_flag = false;
  1607. memset(fcu_protocol.payload, 0, 256);
  1608. }
  1609. }
  1610. /******************void pmu_start_info()*******************
  1611. * ****************上电时PMU发送的信息*******************************
  1612. * ****************************************************************/
  1613. Start_info start_msg = {.key_info_checking = true,
  1614. .Dev_type = 1,
  1615. .Id = 1,
  1616. };
  1617. void pmu_start_info()
  1618. {
  1619. static uint32_t circu_time_2hz = 0;
  1620. if(Check_Timer_Ready(&circu_time_2hz,_2_HZ_))
  1621. {
  1622. if(HAL_GetTick() > 10000 && start_msg.version_info == false)
  1623. {
  1624. pmu_send = PMU_SEND_VERSION;
  1625. start_msg.version_info = true;
  1626. }
  1627. else if (start_msg.key_info_checking == true && Device1.Vkbms_Link.connect_status == COMP_NORMAL)
  1628. {
  1629. pmu_send = PMU_SEND_SHA1;
  1630. }
  1631. }
  1632. }