soft_p_2_c.c 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806
  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
  639. {
  640. send_flag = false;
  641. }
  642. msg_buf[1] = index - 6;
  643. crc = Get_Crc16(msg_buf, index);
  644. msg_buf[index++] = crc;
  645. msg_buf[index++] = (crc >> 8) & 0xff;
  646. if(send_flag == true)
  647. uart2_send_msg(msg_buf, index);
  648. }
  649. /**
  650. * @file radar_version_check
  651. * @brief 更改雷达版本格式
  652. * @param none
  653. * @details
  654. * @author Zhang Sir
  655. **/
  656. void radar_version_check(void)
  657. {
  658. //前避障
  659. if(uavr11_info.Link.connect_status == COMP_NORMAL || uavr11_info.Link.boot_flag == true)
  660. {
  661. if(uavr11_info.soft_verison == 0 && uavr11_info.get_radar_ver_flag == false)
  662. {
  663. uavr11_info.version[0] = 'M';
  664. uavr11_info.version[1] = '1';
  665. for(uint8_t i = 2;i < 10; i++)
  666. {
  667. uavr11_info.version[i] = '0';
  668. }
  669. }
  670. memcpy(&radar_version[0][0],&uavr11_info.version[0],10);
  671. }
  672. else if (mimo_f_info.Link.connect_status == COMP_NORMAL)
  673. {
  674. if(mimo_f_info.Link.boot_flag == true)
  675. {
  676. memcpy(&mimo_f_info.version,"E100000000",10);
  677. }
  678. memcpy(&radar_version[0][0],&mimo_f_info.version[0],10);
  679. }
  680. else if(DM_f_info.Link.connect_status == COMP_NORMAL)
  681. {
  682. memcpy(&radar_version[0][0],&DM_f_info.version[0],10);
  683. }
  684. //后避障
  685. if(uavr12_info.Link.connect_status == COMP_NORMAL )
  686. {
  687. if(uavr12_info.soft_verison == 0 && uavr12_info.get_radar_ver_flag == false)
  688. {
  689. uavr12_info.version[0] = 'M';
  690. uavr12_info.version[1] = '2';
  691. for(uint8_t i = 2;i < 10; i++)
  692. {
  693. uavr12_info.version[i] = '0';
  694. }
  695. }
  696. memcpy(&radar_version[1][0],&uavr12_info.version[0],10);
  697. }
  698. else if(mimo_b_info.Link.connect_status == COMP_NORMAL)
  699. {
  700. if(mimo_b_info.Link.boot_flag == true)
  701. {
  702. memcpy(&mimo_b_info.version,"E200000000",10);
  703. }
  704. memcpy(&radar_version[1][0],&mimo_b_info.version[0],10);
  705. }
  706. if(uavr56_info.Link.connect_status == COMP_NORMAL )
  707. {
  708. if(uavr56_info.soft_verison == 0 && uavr56_info.get_radar_ver_flag == false)
  709. {
  710. uavr56_info.version[0] = 'M';
  711. uavr56_info.version[1] = 'B';
  712. for(uint8_t i = 2;i < 10; i++)
  713. {
  714. uavr56_info.version[i] = '0';
  715. }
  716. }
  717. memcpy(&radar_version[2][0],&uavr56_info.version[0],10);
  718. }
  719. else if(mimo_ter_info.Link.connect_status == COMP_NORMAL)
  720. {
  721. if(mimo_ter_info.Link.boot_flag == true)
  722. {
  723. memcpy(&mimo_ter_info.version,"EB00000000",10);
  724. }
  725. memcpy(&radar_version[2][0],&mimo_ter_info.version[0],10);
  726. }
  727. else if(DM_ter_info.Link.connect_status == COMP_NORMAL)
  728. {
  729. memcpy(&radar_version[2][0],&DM_ter_info.version[0],10);
  730. }
  731. }
  732. /**
  733. * @file pmu_to_con_version_data
  734. * @brief PMU发送版本信息
  735. * @param none
  736. * @details
  737. * @author Zhang Sir
  738. **/
  739. char radar_version[3][10] = {0}; //0 前避障 1后避障 2仿地
  740. void pmu_to_con_version_data()
  741. {
  742. //版本信息 0 - 5 硬件版本 IAP版本 APP版本
  743. uint32_t ver_msg_buf[4] = {0};
  744. int index = 0;
  745. ver_msg_buf[0] = serial.num; //硬件版本号
  746. ver_msg_buf[1] = IAP_VERSION; //IAP版本号
  747. ver_msg_buf[2] = APP_VERSION; //APP版本号
  748. ver_msg_buf[3] = serial.num;//serial.num;
  749. msg_buf[index++] = 0xFE;
  750. msg_buf[index++] = 0;
  751. msg_buf[index++] = 0;
  752. msg_buf[index++] = 0x00;
  753. msg_buf[index++] = 0x00;
  754. msg_buf[index++] = MSGID_REQ_VERSION;
  755. radar_version_check();
  756. memcpy(&msg_buf[index], ver_msg_buf, 16);
  757. index += 16;
  758. memcpy(&msg_buf[index], &radar_version[0][0], 10);
  759. index += 10;
  760. memcpy(&msg_buf[index], &radar_version[1][0], 10);
  761. index += 10;
  762. memcpy(&msg_buf[index], &radar_version[2][0], 10);
  763. index += 10;
  764. msg_buf[1] = index - 6;
  765. crc = Get_Crc16(msg_buf, index);
  766. memcpy(&msg_buf[index], &crc, 2);
  767. index += 2;
  768. uart2_send_msg(msg_buf, index);
  769. }
  770. /**
  771. * @file pmu_to_fcu_version_data
  772. * @brief 版本信息发送,新协议还没用
  773. * @param none
  774. * @details
  775. * @author Zhang Sir
  776. **/
  777. void pmu_to_fcu_version_data()
  778. {
  779. dev_version_content *ptr = NULL;
  780. for(uint8_t i = 0;i < dev_num;i++)
  781. {
  782. ptr = dev_ptr[i];
  783. if(ptr->send_times > 0)
  784. {
  785. break;
  786. }
  787. if(i == dev_num - 1)
  788. {
  789. return;
  790. }
  791. }
  792. uint8_t index = 0;
  793. msg_buf[index++] = 0xFE;
  794. msg_buf[index++] = 0;
  795. msg_buf[index++] = 0;
  796. msg_buf[index++] = 0x00;
  797. msg_buf[index++] = 0x00;
  798. msg_buf[index++] = _MSGID_DEV_LIST;
  799. memcpy(&msg_buf[index],&ptr->num,sizeof(dev_version_content) - sizeof(regist_type) - 1);
  800. index += sizeof(dev_version_content) - sizeof(regist_type) - 1;
  801. msg_buf[1] = index - 6;
  802. crc = Get_Crc16(msg_buf, index);
  803. memcpy(&msg_buf[index], &crc, 2);
  804. index += 2;
  805. uart2_send_msg(msg_buf, index);
  806. }
  807. /**
  808. * @file pmu_to_fcu_key_data
  809. * @brief PMU发送秘钥信息
  810. * @param none
  811. * @details 格式电池秘钥匹配
  812. * @author Zhang Sir
  813. **/
  814. void pmu_to_fcu_key_data(void)
  815. {
  816. uint8_t index = 0;
  817. msg_buf[index++] = 0xFE;
  818. msg_buf[index++] = 0;
  819. msg_buf[index++] = 0;
  820. msg_buf[index++] = 0x00;
  821. msg_buf[index++] = 0x00;
  822. msg_buf[index++] = _MSGID_SHA1;
  823. msg_buf[index++] = start_msg.Dev_type;
  824. msg_buf[index++] = start_msg.Id;
  825. msg_buf[index++] = start_msg.Id_content;
  826. // if(start_msg.Id == 4)
  827. // {
  828. // start_msg.key_info_checking = false; //发送状态后结束发送
  829. // }
  830. memcpy(&msg_buf[index],&start_msg.key_data[0],20);
  831. index += 20;
  832. msg_buf[1] = index - 6;
  833. crc = Get_Crc16(msg_buf, index);
  834. memcpy(&msg_buf[index], &crc, 2);
  835. index += 2;
  836. uart2_send_msg(msg_buf, index);
  837. }
  838. /**
  839. * @file pmu_to_con_request_data
  840. * @brief PMU发送请求信息
  841. * @param none
  842. * @details
  843. * @author Zhang Sir
  844. **/
  845. char request_id = 0;
  846. short request_1_content = 0;
  847. int request_2_content = 0;
  848. void pmu_to_con_request_data()
  849. {
  850. int index = 0;
  851. msg_buf[index++] = 0xFE;
  852. msg_buf[index++] = 0;
  853. msg_buf[index++] = 0;
  854. msg_buf[index++] = 0x00;
  855. msg_buf[index++] = 0x00;
  856. msg_buf[index++] = 20;
  857. msg_buf[index++] = request_id;
  858. memcpy(&msg_buf[index],&request_1_content,2);
  859. index += 2;
  860. memcpy(&msg_buf[index],&request_2_content,4);
  861. index += 4;
  862. msg_buf[1] = index - 6;
  863. crc = Get_Crc16(msg_buf, index);
  864. memcpy(&msg_buf[index], &crc, 2);
  865. index += 2;
  866. uart2_send_msg(msg_buf, index);
  867. }
  868. /**
  869. * @file pmu_to_con_request_data
  870. * @brief PMU发送应答信息
  871. * @param none
  872. * @details
  873. * @author Zhang Sir
  874. **/
  875. char ack_id = 0;
  876. short ack_content = 0;
  877. short ack_content1 = 0;
  878. short ack_content2 = 0;
  879. void pmu_to_con_ack_data()
  880. {
  881. int index = 0;
  882. msg_buf[index++] = 0xFE;
  883. msg_buf[index++] = 0;
  884. msg_buf[index++] = 0;
  885. msg_buf[index++] = 0x00;
  886. msg_buf[index++] = 0x00;
  887. msg_buf[index++] = 21;
  888. msg_buf[index++] = ack_id;
  889. memcpy(&msg_buf[index],&ack_content,2);
  890. index += 2;
  891. memcpy(&msg_buf[index],&ack_content1,2);
  892. index += 2;
  893. memcpy(&msg_buf[index],&ack_content2,2);
  894. index += 2;
  895. msg_buf[1] = index - 6;
  896. crc = Get_Crc16(msg_buf, index);
  897. memcpy(&msg_buf[index], &crc, 2);
  898. index += 2;
  899. uart2_send_msg(msg_buf, index);
  900. }
  901. /******************void pmu_to_fcu()******************************
  902. * ****************PMU发送信息给主控********************************
  903. * ****************************************************************/
  904. /**
  905. * @file pmu_to_fcu
  906. * @brief PMU发送信息给FMU
  907. * @param none
  908. * @details UART2
  909. * @author Zhang Sir
  910. **/
  911. uint8_t pmu_send = PMU_SEND_YAOCE;
  912. uint32_t utc_time = 0;
  913. void pmu_to_fcu()
  914. {
  915. //串口阻塞 和雷达升级不发送
  916. if(uart_info.vk_dev_update_flag != true && EZup_par.update_flag != true && Rupdate.update_flag != true)
  917. {
  918. switch (pmu_send)
  919. {
  920. case PMU_SEND_YAOCE:
  921. //发送电压信息
  922. if (vol_flag == true)
  923. {
  924. pmu_to_con_voltage_data();
  925. vol_flag = false;
  926. }
  927. //发动机信息
  928. else if (engine_flag == true)
  929. {
  930. pmu_to_con_engine_data();
  931. engine_flag = false;
  932. }
  933. // //mimo360测试
  934. // else if (mimo360_radar_flag == true)
  935. // {
  936. // pmu_to_con_radar360_data();
  937. // mimo360_radar_flag = false;
  938. // }
  939. //电目雷达测试
  940. else if(DM_radar_flag == true)
  941. {
  942. pmu_to_con_DMradar_data();
  943. DM_radar_flag = false;
  944. }
  945. //CAN调试信息
  946. else if(can_debug_flag == true)
  947. {
  948. Can_send_debug_to_app();
  949. can_debug_flag = false;
  950. }
  951. //设备SN号,软硬件号
  952. else if (dev_version_flag == true)
  953. {
  954. pmu_to_fcu_version_data();
  955. dev_version_flag = false;
  956. }
  957. //设备信息
  958. else if (devtype_flag == true)
  959. {
  960. pmu_to_con_devtype_data();
  961. devtype_flag = false;
  962. }
  963. break;
  964. case PMU_SEND_REQINFO:
  965. pmu_to_con_request_data();
  966. pmu_send = PMU_SEND_YAOCE;
  967. break;
  968. case PMU_SEND_ACK:
  969. pmu_to_con_ack_data();
  970. pmu_send = PMU_SEND_YAOCE;
  971. break;
  972. case PMU_SEND_VERSION:
  973. pmu_to_con_version_data();
  974. pmu_send = PMU_SEND_YAOCE;
  975. break;
  976. case PMU_SEND_SHA1:
  977. pmu_to_fcu_key_data();
  978. pmu_send = PMU_SEND_YAOCE;
  979. break;
  980. case PMU_SEND_DEV_INFO:
  981. pmu_to_fcu_version_data();
  982. pmu_send = PMU_SEND_YAOCE;
  983. break;
  984. default:
  985. break;
  986. }
  987. //心跳包单独发
  988. if(pmu_heart_flag == true)
  989. {
  990. pmu_to_con_heart_data();
  991. pmu_heart_flag = false;
  992. }
  993. }
  994. }
  995. void Check_Rst(void)
  996. {
  997. if(__HAL_RCC_GET_FLAG(RCC_FLAG_PINRST) != RESET ) // NRST 引脚复位
  998. {
  999. uavinf.reset_reason = R_NRST;
  1000. write_uav_information = true;
  1001. __HAL_RCC_CLEAR_RESET_FLAGS();
  1002. }
  1003. if(__HAL_RCC_GET_FLAG(RCC_FLAG_PORRST) != RESET ) // 上电掉电复位
  1004. {
  1005. uavinf.reset_reason = R_POWER;
  1006. write_uav_information = true;
  1007. __HAL_RCC_CLEAR_RESET_FLAGS();
  1008. }
  1009. if(__HAL_RCC_GET_FLAG(RCC_FLAG_SFTRST) != RESET ) // 软件复位
  1010. {
  1011. uavinf.reset_reason = R_SOFT;
  1012. write_uav_information = true;
  1013. __HAL_RCC_CLEAR_RESET_FLAGS();
  1014. }
  1015. if(__HAL_RCC_GET_FLAG(RCC_FLAG_IWDGRST) != RESET ) // 独立看门狗复位
  1016. {
  1017. uavinf.reset_reason = R_IWD;
  1018. write_uav_information = true;
  1019. __HAL_RCC_CLEAR_RESET_FLAGS();
  1020. }
  1021. if(__HAL_RCC_GET_FLAG(RCC_FLAG_WWDGRST) != RESET ) // 窗口看门狗复位
  1022. {
  1023. uavinf.reset_reason = R_WWD;
  1024. write_uav_information = true;
  1025. __HAL_RCC_CLEAR_RESET_FLAGS();
  1026. }
  1027. if(__HAL_RCC_GET_FLAG(RCC_FLAG_LPWRRST) != RESET ) // 低功耗复位
  1028. {
  1029. uavinf.reset_reason = R_LOPWER;
  1030. write_uav_information = true;
  1031. __HAL_RCC_CLEAR_RESET_FLAGS();
  1032. }
  1033. }
  1034. /******************void check_fmu_link()************************
  1035. * ****************检查是否收到FMU信息************************************
  1036. * ****************************************************************/
  1037. static uint32_t fmu_link_time = 0;
  1038. void check_fmu_link()
  1039. {
  1040. //FMU串口通讯连接检测
  1041. if(HAL_GetTick() > 15000)
  1042. {
  1043. if(recv_fmu_data == true && HAL_GetTick() - fmu_link_time > 3000)
  1044. {
  1045. recv_fmu_data = false;
  1046. }
  1047. }
  1048. //FMU异常断电检测
  1049. if((planep.lock_status != STA_LOCK) && (recv_fmu_data == true) && (HAL_GetTick() - fmu_link_time > 500))
  1050. {
  1051. uavinf.abnormal_outage_flag = 1;
  1052. write_uav_information = true;
  1053. recv_fmu_data = false;
  1054. }
  1055. Check_Rst();
  1056. }
  1057. /******************void uart_recv_con_msg()************************
  1058. * ****************PMU收控制消息************************************
  1059. * ****************************************************************/
  1060. _pmu_pin pmu_pin;
  1061. bool recv_fmu_data = false;
  1062. Set_info msgidset;
  1063. void uart_recv_con_msg()
  1064. {
  1065. check_fmu_link();
  1066. check_uart_data(&recv_rkfifo);
  1067. if (uart_info.fcu_buf_flag == true)
  1068. {
  1069. uint32_t tem_32t = 0;
  1070. FLASH_EraseInitTypeDef f;
  1071. fmu_link_time = HAL_GetTick();
  1072. recv_fmu_data = true;
  1073. switch (fcu_protocol.msg_id)
  1074. {
  1075. case _MSGID_PWM:
  1076. memcpy(&pmu_pin.pump1, &fcu_protocol.payload[6], sizeof(_pmu_pin));
  1077. if(set_HWesc_ESCid == true && setESCidInfo.setESCidStep == SETESCID_SET)
  1078. {
  1079. memset(&pmu_pin.pump1,0,4);
  1080. if(setESCidInfo.setESCidNum == 1)
  1081. pmu_pin.pump1 = 1000;
  1082. else if(setESCidInfo.setESCidNum == 2)
  1083. pmu_pin.pump2 = 1000;
  1084. }
  1085. __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, pmu_pin.pump1);
  1086. __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_2, pmu_pin.pump2);
  1087. if(planep.UAV_type == VK_ALL_IN_ONE)
  1088. {
  1089. __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, pmu_pin.nozz1_fm);
  1090. __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, pmu_pin.nozz2_zp);
  1091. }
  1092. else
  1093. {
  1094. __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, pmu_pin.nozz1_fm);
  1095. __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, pmu_pin.nozz2_zp);
  1096. }
  1097. if(planep.UAV_type == VK_ALL_IN_ONE)
  1098. {
  1099. //分电板离心喷头
  1100. distributor.nozzle1 = pmu_pin.nozz1_fm;
  1101. distributor.nozzle2 = pmu_pin.nozz2_zp;
  1102. //离心喷头34
  1103. __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_4, pmu_pin.nozz3); // PB8 nozzle
  1104. __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, pmu_pin.nozz4); // PB9 nozzle
  1105. //前后灯
  1106. if((pmu_pin.aux_light & 0x1) > 0)
  1107. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_SET);
  1108. else
  1109. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_RESET);
  1110. if((pmu_pin.aux_light & 0x2) > 0)
  1111. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_SET);
  1112. else
  1113. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_RESET);
  1114. //摄像头舵机
  1115. __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, pmu_pin.aux_steer);
  1116. }
  1117. break;
  1118. case _MSGID_LED:
  1119. for(uint8_t i = 0; i < 7; i++)
  1120. {
  1121. if(planep.UAV_type != VK_ALL_IN_ONE ) //青岛机型不用LED
  1122. {
  1123. led_set_blink(i, fcu_protocol.payload[i*3+6], fcu_protocol.payload[i*3+7], fcu_protocol.payload[i*3+8]);
  1124. }
  1125. }
  1126. break;
  1127. //飞机姿态信息
  1128. case _MSGID_ATTITUDE:
  1129. memcpy(&planep.yaw, &fcu_protocol.payload[6], sizeof(plane_para));
  1130. if(uavinf.uavtype != planep.UAV_type)
  1131. {
  1132. write_uav_information = true;
  1133. }
  1134. break;
  1135. case _MSGID_TIME:
  1136. //tem_32t = 1684136124;
  1137. memcpy(&utc_time, &fcu_protocol.payload[6], 4);
  1138. covUnixTimeStp2Beijing(utc_time,&beijing_time);
  1139. pmu_set_ack(_MSGID_TIME,0,0,0);
  1140. break;
  1141. //eft播撒器
  1142. case _MSGID_EFT_CON:
  1143. recv_fmu_seed_info = true;
  1144. memcpy(&tppwm_value, &fcu_protocol.payload[6], 2);
  1145. memcpy(&sow_rotate_value, &fcu_protocol.payload[8], 2);
  1146. break;
  1147. //请求信息包
  1148. case _MSGID_REQ:
  1149. switch (fcu_protocol.payload[6])
  1150. {
  1151. case MSGID_REQ_VERSION:
  1152. pmu_send = PMU_SEND_VERSION;
  1153. break;
  1154. default:
  1155. break;
  1156. }
  1157. break;
  1158. //主控应答
  1159. case _MSGID_ACK:
  1160. msgidset.content1 = fcu_protocol.payload[7] + 256 * fcu_protocol.payload[8];
  1161. switch (fcu_protocol.payload[6])
  1162. {
  1163. case MSGID_ACK_HEART:
  1164. uavinf.abnormal_outage_flag = 0;
  1165. write_uav_information = true;
  1166. break;
  1167. case MSGID_ACK_VERSION:
  1168. start_msg.version_info = true;
  1169. break;
  1170. case MSGID_ACK_DEV:
  1171. {
  1172. if(msgidset.content1 < DEVICE_END - 1)
  1173. {
  1174. dev_version_content *Pt = dev_ptr[msgidset.content1];
  1175. if(Pt->send_times > 0)
  1176. Pt->send_times--;
  1177. }
  1178. }
  1179. break;
  1180. default:
  1181. break;
  1182. }
  1183. break;
  1184. //设置雷达灵敏度
  1185. case _MSGID_SET:
  1186. msgidset.num = fcu_protocol.payload[6];
  1187. msgidset.content1 = fcu_protocol.payload[7] + 256 * fcu_protocol.payload[8];
  1188. msgidset.content2 = fcu_protocol.payload[9] + 256 * fcu_protocol.payload[10];
  1189. switch (msgidset.num)
  1190. {
  1191. //前雷达
  1192. case MSGID_SET_F_RADAR:
  1193. if(uavr12_info.fcu_set_sensi_flag != true && uavr56_info.fcu_set_sensi_flag != true && radar_update_flag == false)
  1194. {
  1195. uavr11_info.fcu_set_sensi_flag = true;
  1196. }
  1197. memcpy(&obsfradar_sensitivity, &fcu_protocol.payload[7], 2);
  1198. if(obsfradar_sensitivity == uavr11_info.get_radar_sensi)
  1199. {
  1200. uavr11_info.fcu_set_sensi_flag = false;
  1201. pmu_set_ack(_MSGID_SET,MSGID_SET_F_RADAR,uavr11_info.get_radar_sensi,0);
  1202. }
  1203. break;
  1204. //后雷达
  1205. case MSGID_SET_B_RADAR:
  1206. if(uavr11_info.fcu_set_sensi_flag != true && uavr56_info.fcu_set_sensi_flag != true && radar_update_flag == false)
  1207. {
  1208. uavr12_info.fcu_set_sensi_flag = true;
  1209. }
  1210. memcpy(&obsbradar_sensitivity, &fcu_protocol.payload[7], 2);
  1211. if(obsbradar_sensitivity == uavr12_info.get_radar_sensi)
  1212. {
  1213. uavr12_info.fcu_set_sensi_flag = false;
  1214. pmu_set_ack(_MSGID_SET,MSGID_SET_B_RADAR,uavr12_info.get_radar_sensi,0);
  1215. }
  1216. break;
  1217. //仿地
  1218. case MSGID_SET_T_RADAR:
  1219. if(uavr11_info.fcu_set_sensi_flag != true && uavr12_info.fcu_set_sensi_flag != true && radar_update_flag == false)
  1220. {
  1221. uavr56_info.fcu_set_sensi_flag = true;
  1222. }
  1223. memcpy(&uavr56_info.fcu_set_sensi, &fcu_protocol.payload[7], 2);
  1224. if(uavr56_info.fcu_set_sensi == uavr56_info.get_radar_sensi)
  1225. {
  1226. uavr56_info.fcu_set_sensi_flag = false;
  1227. pmu_set_ack(_MSGID_SET,MSGID_SET_T_RADAR,uavr56_info.get_radar_sensi,0);
  1228. }
  1229. break;
  1230. case MSGID_SET_TR_BLIND:
  1231. {
  1232. uint8_t can_buf[8] = {0};
  1233. uint32_t can_id = 0;
  1234. if(msgidset.content1 == 0x11)
  1235. can_id = 0xA81300;
  1236. else if (msgidset.content1 == 0x56)
  1237. can_id = 0x981300;
  1238. put_date_to_can(can_buf,0x5,(msgidset.content2 & 0xff),((msgidset.content2 >> 8) & 0xff),0,0,0,0,0X7);
  1239. can_send_msg_normal(&can_buf[0], 8, can_id);
  1240. }
  1241. break;
  1242. case MSGID_SET_BR_POWER:
  1243. {
  1244. uint8_t can_buf[8] = {0};
  1245. uint32_t can_id = 0;
  1246. if(msgidset.content1 == 0x11)
  1247. can_id = 0xA81300;
  1248. else if (msgidset.content1 == 0x56)
  1249. can_id = 0x981300;
  1250. put_date_to_can(can_buf,0x7,(msgidset.content2 & 0xff),((msgidset.content2 >> 8) & 0xff),0,0,0,0,0X7);
  1251. can_send_msg_normal(&can_buf[0], 8, can_id);
  1252. }
  1253. break;
  1254. case MSGID_SET_R_FUNC:
  1255. {
  1256. uint8_t can_buf[8] = {0};
  1257. uint32_t can_id = 0;
  1258. if(msgidset.content1 == 3)
  1259. can_id = 0x981300;
  1260. else if(msgidset.content1 == 5)
  1261. can_id = 0xA81300;
  1262. put_date_to_can(can_buf,0x4,(msgidset.content1 & 0xff),((msgidset.content1 >> 8) & 0xff),0,0,0,0,0X7);
  1263. can_send_msg_normal(&can_buf[0], 8, can_id);
  1264. }
  1265. break;
  1266. case MSGID_SET_RAW_SWITCH:
  1267. {
  1268. uint8_t can_buf[8] = {0};
  1269. uint32_t can_id = 0;
  1270. if(msgidset.content1 == 0x11)
  1271. can_id = 0xA81300;
  1272. else if (msgidset.content1 == 0x56)
  1273. can_id = 0x981300;
  1274. put_date_to_can(can_buf,0xA,(msgidset.content2 & 0xff),((msgidset.content2 >> 8) & 0xff),0,0,0,0,0X7);
  1275. can_send_msg_normal(&can_buf[0], 8, can_id);
  1276. }
  1277. break;
  1278. case MSGID_SET_GEELY:
  1279. switch (fcu_protocol.payload[7])
  1280. {
  1281. case SET_START_OR_STOP:
  1282. if(0x1 == fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00))
  1283. {
  1284. if (geely_engin_link.connect_status == COMP_NORMAL && geely_data.engine_control == 0)
  1285. {
  1286. sendto_geely.ExtenderControl = 1;
  1287. }
  1288. start_engine = 0x80;
  1289. }
  1290. else if(0x0 == fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00))
  1291. {
  1292. if (geely_engin_link.connect_status == COMP_NORMAL && geely_data.engine_control == 1)
  1293. {
  1294. sendto_geely.ExtenderControl = 0;
  1295. }
  1296. start_engine = 0;
  1297. }
  1298. break;
  1299. case SET_PROTECT_TIME:
  1300. if (geely_engin_link.connect_status == COMP_NORMAL)
  1301. {
  1302. geely_set_tcd = true;
  1303. sendto_geely.SettingParameter = fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00);
  1304. }
  1305. break;
  1306. case SET_LOCK_TIME:
  1307. if (geely_engin_link.connect_status == COMP_NORMAL)
  1308. {
  1309. geely_set_tlock = true;
  1310. sendto_geely.SettingParameter = fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00);
  1311. }
  1312. break;
  1313. case SET_LOWVOL_PROTECT:
  1314. if(0x1 == fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00))
  1315. {
  1316. if (geely_engin_link.connect_status == COMP_NORMAL)
  1317. {
  1318. sendto_geely.ExtenderControl = 1;
  1319. geely_set_protect = true;
  1320. }
  1321. }
  1322. else
  1323. {
  1324. geely_set_protect = false;
  1325. }
  1326. break;
  1327. default:
  1328. break;
  1329. }
  1330. break;
  1331. case MSGID_SET_VOL:
  1332. set_cali_voltage = (fcu_protocol.payload[7] + 256 * fcu_protocol.payload[8]) - (int)(ADC_gather() /100.0f) ;
  1333. write_vol_information = true;
  1334. pmu_set_ack(_MSGID_SET,MSGID_SET_VOL,0,0);
  1335. break;
  1336. case MSGID_SET_MIMO_FLOW:
  1337. if(msgidset.content1 != 0)
  1338. {
  1339. if(Dev.Flow.facid == FAC_MIMO_SIG || Dev.Flow.facid == FAC_MIMO_DOU)
  1340. {
  1341. tem_32t = flow_mimo1.flow_k * msgidset.content1 / 100;
  1342. if(tem_32t >= 500 && tem_32t <= 20000)
  1343. {
  1344. flow_mimo1.flow_calk = tem_32t;
  1345. }
  1346. else{
  1347. flow_mimo1.flow_calk = 10000;
  1348. }
  1349. flow_mimo1.send_k_count = 5;
  1350. }
  1351. else if(Dev.Flow.facid == FAC_QIFEI_SIG || Dev.Flow.facid == FAC_QIFEI_DOU)
  1352. {
  1353. tem_32t = flow_inf.ch1.k * msgidset.content1 / 100;
  1354. if(tem_32t >= 500 && tem_32t <= 20000)
  1355. {
  1356. flow_inf.ch1.cal_k = tem_32t;
  1357. }
  1358. else{
  1359. flow_inf.ch1.cal_k = 10000;
  1360. }
  1361. flow_inf.ch1.set_k = true;
  1362. }
  1363. }
  1364. if(msgidset.content2 != 0)
  1365. {
  1366. if(Dev.Flow.facid == FAC_MIMO_SIG || Dev.Flow.facid == FAC_MIMO_DOU)
  1367. {
  1368. tem_32t = flow_mimo2.flow_k * msgidset.content2 / 100;
  1369. if(tem_32t >= 500 && tem_32t <= 20000)
  1370. {
  1371. flow_mimo2.flow_calk = tem_32t;
  1372. }
  1373. else{
  1374. flow_mimo2.flow_calk = 10000;
  1375. }
  1376. flow_mimo2.send_k_count = 5;
  1377. }
  1378. else if(Dev.Flow.facid == FAC_QIFEI_SIG || Dev.Flow.facid == FAC_QIFEI_DOU)
  1379. {
  1380. tem_32t = flow_inf.ch2.k * msgidset.content2 / 100;
  1381. if(tem_32t >= 500 && tem_32t <= 20000)
  1382. {
  1383. flow_inf.ch2.cal_k = tem_32t;
  1384. }
  1385. else{
  1386. flow_inf.ch2.cal_k = 10000;
  1387. }
  1388. flow_inf.ch1.set_k = true;
  1389. }
  1390. }
  1391. break;
  1392. case MSGID_SET_FLOW_BACKGROUND:
  1393. if(Dev.Flow.facid == FAC_MIMO_SIG)
  1394. {
  1395. flow_inf.ch1.clear_background = true;
  1396. }
  1397. if(Dev.Flow.facid == FAC_MIMO_DOU)
  1398. {
  1399. flow_inf.ch1.clear_background = true;
  1400. flow_inf.ch2.clear_background = true;
  1401. }
  1402. break;
  1403. case MSGID_SET_WEIGHT_K:
  1404. //calib_aux = msgidset.content1 + (msgidset.content2 << 2); //bit 0-1 编号 2-15K值
  1405. weight_order.type = Weight_Set_K;
  1406. weight_order.order_con1 = msgidset.content1;
  1407. weight_order.order_con2 = msgidset.content2;
  1408. break;
  1409. case MSGID_SET_SEED_OUT_TYPE:
  1410. recv_fmu_seed_info = true;
  1411. seed_output_mode = msgidset.content1;
  1412. pmu_set_ack(_MSGID_SET,MSGID_SET_SEED_OUT_TYPE,0,0);
  1413. break;
  1414. case MSGID_SET_SEED_CAL_TYPE:
  1415. switch (msgidset.content1)
  1416. {
  1417. case Cal_Remove_Peel:
  1418. weight_order.type = Weight_Peer;
  1419. break;
  1420. case Cal_Weight:
  1421. weight_order.type = Weight_Kg;
  1422. weight_order.order_con2 = msgidset.content2;
  1423. break;
  1424. case Cal_Seed_Back:
  1425. weight_order.type = Weight_Bcak;
  1426. break;
  1427. default:
  1428. break;
  1429. }
  1430. break;
  1431. case MSGID_SET_WEIGHT_MODE:
  1432. weight_order.type = Weight_Mode;
  1433. weight_order.order_con1 = msgidset.content1;
  1434. break;
  1435. case MSGID_SET_MAX_RATE:
  1436. weight_order.type = Weight_Drug_Rate;
  1437. weight_order.order_con1 = msgidset.content1;
  1438. break;
  1439. case MSGID_SET_PMU_SERIAL:
  1440. set_pmu_serail = msgidset.content1 + ((msgidset.content2 << 16) & 0xffff0000);
  1441. if(serial.num == PMU_SERIAL || set_pmu_serail == PMU_SERIAL)
  1442. {
  1443. write_serial_information = true;
  1444. pmu_set_ack(_MSGID_SET,MSGID_SET_PMU_SERIAL,0,0);
  1445. dev_pmu.send_times += 5;
  1446. }
  1447. else if(set_pmu_serail == serial.num)
  1448. {
  1449. pmu_set_ack(_MSGID_SET,MSGID_SET_PMU_SERIAL,0,0);
  1450. }
  1451. break;
  1452. case MSGID_SET_RADAR_FB:
  1453. {
  1454. uint8_t can_buf[8] = {0};
  1455. if(msgidset.content1 == 0x11)
  1456. {
  1457. put_date_to_can(can_buf,0x55,0XAA,0X03,0X61,0X03,0X01,0X65,0X00);
  1458. can_send_msg_normalstd(can_buf,7,0xFA);
  1459. }
  1460. else if (msgidset.content1 == 0x12)
  1461. {
  1462. put_date_to_can(can_buf,0x55,0XAA,0X03,0X61,0X03,0X02,0X66,0X00);
  1463. can_send_msg_normalstd(can_buf,7,0xFA);
  1464. }
  1465. else if(msgidset.content1 == 0x100)
  1466. {
  1467. if(msgidset.content2 == 0x11 || msgidset.content2 == 0x12)
  1468. {
  1469. put_date_to_can(can_buf,0x55,0XAA,0X03,0X61,0X00,0X03,0X64,0X00);
  1470. can_send_msg_normalstd(can_buf,7,0xFA);
  1471. }
  1472. else if(msgidset.content2 == 0x56)
  1473. {
  1474. put_date_to_can(can_buf,0x55,0XAA,0X02,0X60,0X03,0X63,0X00,0X00);
  1475. can_send_msg_normalstd(can_buf,6,0xFA);
  1476. }
  1477. }
  1478. }
  1479. break;
  1480. case MSGID_SET_LACKLOSS_CAL:
  1481. {
  1482. uint8_t can_buf[8] = {0};
  1483. if(Dev.Lackloss_Link.connect_status == COMP_NORMAL)
  1484. {
  1485. mimo_lackloss.cal_distance = mimo_lackloss.distance / 10 + 5;
  1486. put_date_to_can(can_buf,0xFA,0x03,0x00,0xB1,0XC1,0x00,0X00,0X00);
  1487. can_buf[6] = mimo_lackloss.cal_distance & 0xff;
  1488. can_buf[5] = (mimo_lackloss.cal_distance >> 8) & 0xff;
  1489. can_buf[7] = (can_buf[1]+can_buf[2]+can_buf[3]+can_buf[4]+can_buf[5]+can_buf[6]) & 0xff;
  1490. can_send_msg_normalstd(can_buf,8,0xFA);
  1491. }
  1492. }
  1493. break;
  1494. case MSGID_SET_PUMP_ID:
  1495. set_HWesc_ESCid = true;
  1496. setESCidInfo.setESCidNum = 1;
  1497. setESCidInfo.setESCidStep = SETESCID_INIT;
  1498. pmu_set_ack(_MSGID_SET,MSGID_SET_PUMP_ID,0,2);
  1499. break;
  1500. case MSGID_SET_FRADAR_SN:
  1501. {
  1502. int radar_Sn = 0;
  1503. uint8_t can_buf[8] = {0};
  1504. radar_Sn = msgidset.content1 + (msgidset.content2 << 16);
  1505. can_buf[0] = 2;
  1506. memcpy(&can_buf[1],&radar_Sn,4);
  1507. can_buf[7] = 7;
  1508. can_send_msg_normal(can_buf,8,0xA81300);
  1509. DM_f_info.get_radar_ver_flag = false;
  1510. dev_obsf.regist.sn = false;
  1511. pmu_set_ack(_MSGID_SET,MSGID_SET_FRADAR_SN,msgidset.content1,msgidset.content2);
  1512. }
  1513. break;
  1514. case MSGID_SET_BRADAR_SN:
  1515. {
  1516. int radar_Sn = 0;
  1517. uint8_t can_buf[8] = {0};
  1518. radar_Sn = msgidset.content1 + (msgidset.content2 << 16);
  1519. can_buf[0] = 2;
  1520. memcpy(&can_buf[1],&radar_Sn,4);
  1521. can_buf[7] = 7;
  1522. can_send_msg_normal(can_buf,8,0xB81300);
  1523. dev_obsb.regist.sn = false;
  1524. //DM_b_info.get_radar_ver_flag = false;
  1525. pmu_set_ack(_MSGID_SET,MSGID_SET_BRADAR_SN,msgidset.content1,msgidset.content2);
  1526. }
  1527. break;
  1528. case MSGID_SET_TRADAR_SN:
  1529. {
  1530. int radar_Sn = 0;
  1531. uint8_t can_buf[8] = {0};
  1532. radar_Sn = msgidset.content1 + (msgidset.content2 << 16);
  1533. can_buf[0] = 2;
  1534. memcpy(&can_buf[1],&radar_Sn,4);
  1535. can_buf[7] = 7;
  1536. can_send_msg_normal(can_buf,8,0x981300);
  1537. DM_ter_info.get_radar_ver_flag = false;
  1538. dev_ter.regist.sn = false; //重新获取sn
  1539. pmu_set_ack(_MSGID_SET,MSGID_SET_TRADAR_SN,msgidset.content1,msgidset.content2);
  1540. }
  1541. break;
  1542. default:
  1543. break;
  1544. }
  1545. break;
  1546. case _MSGID_HEART:
  1547. pmu_heart_flag = true;
  1548. break;
  1549. case _MSGID_SHA1:
  1550. //智能电池秘钥
  1551. if(fcu_protocol.payload[6] == 1)
  1552. {
  1553. //有秘钥
  1554. if(fcu_protocol.payload[7] == 2 && fcu_protocol.payload[8] == 1)
  1555. {
  1556. if(start_msg.key_info_checking == true)
  1557. {
  1558. memcpy(&start_msg.key_data[0],&fcu_protocol.payload[9],20);
  1559. start_msg.key_to_bms = true;//给电池发送秘钥
  1560. start_msg.key_info_checking = false;
  1561. }
  1562. }
  1563. //无秘钥
  1564. else if(fcu_protocol.payload[7] == 2 && fcu_protocol.payload[8] == 2)
  1565. {
  1566. start_msg.key_info_checking = false;
  1567. }
  1568. //回馈,防止PMU一直发
  1569. else if(fcu_protocol.payload[7] == 3 || fcu_protocol.payload[7] == 4)
  1570. {
  1571. start_msg.key_info_checking = false;
  1572. }
  1573. }
  1574. break;
  1575. //升级固件标志
  1576. case _MSGID_UPDATA:
  1577. {
  1578. __disable_irq();
  1579. HAL_FLASH_Unlock();
  1580. __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
  1581. f.TypeErase = FLASH_TYPEERASE_PAGES;
  1582. f.PageAddress = UPDATE_FLAG;
  1583. f.NbPages = 1;
  1584. uint32_t PageError = 0;
  1585. HAL_FLASHEx_Erase(&f, &PageError);
  1586. uint16_t TempBuf = 0x01;
  1587. HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, UPDATE_FLAG, TempBuf);
  1588. HAL_FLASH_Lock();
  1589. __enable_irq();
  1590. HAL_NVIC_DisableIRQ(USART2_IRQn);
  1591. HAL_Delay(100);
  1592. //软件复位
  1593. HAL_NVIC_SystemReset();
  1594. }
  1595. break;
  1596. default:
  1597. break;
  1598. }
  1599. uart_info.fcu_buf_flag = false;
  1600. memset(fcu_protocol.payload, 0, 256);
  1601. }
  1602. }
  1603. /******************void pmu_start_info()*******************
  1604. * ****************上电时PMU发送的信息*******************************
  1605. * ****************************************************************/
  1606. Start_info start_msg = {.key_info_checking = true,
  1607. .Dev_type = 1,
  1608. .Id = 1,
  1609. };
  1610. void pmu_start_info()
  1611. {
  1612. static uint32_t circu_time_2hz = 0;
  1613. if(Check_Timer_Ready(&circu_time_2hz,_2_HZ_))
  1614. {
  1615. if(HAL_GetTick() > 10000 && start_msg.version_info == false)
  1616. {
  1617. pmu_send = PMU_SEND_VERSION;
  1618. start_msg.version_info = true;
  1619. }
  1620. else if (start_msg.key_info_checking == true && Device1.Vkbms_Link.connect_status == COMP_NORMAL)
  1621. {
  1622. pmu_send = PMU_SEND_SHA1;
  1623. }
  1624. }
  1625. }