soft_p_2_c.c 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823
  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. uint32_t DMJZ=0;
  1071. void uart_recv_con_msg()
  1072. {
  1073. check_fmu_link();
  1074. check_uart_data(&recv_rkfifo);
  1075. if (uart_info.fcu_buf_flag == true)
  1076. {
  1077. uint32_t tem_32t = 0;
  1078. FLASH_EraseInitTypeDef f;
  1079. fmu_link_time = HAL_GetTick();
  1080. recv_fmu_data = true;
  1081. switch (fcu_protocol.msg_id)
  1082. {
  1083. case _MSGID_PWM:
  1084. memcpy(&pmu_pin.pump1, &fcu_protocol.payload[6], sizeof(_pmu_pin));
  1085. if(set_HWesc_ESCid == true && setESCidInfo.setESCidStep == SETESCID_SET)
  1086. {
  1087. memset(&pmu_pin.pump1,0,4);
  1088. if(setESCidInfo.setESCidNum == 1)
  1089. pmu_pin.pump1 = 1000;
  1090. else if(setESCidInfo.setESCidNum == 2)
  1091. pmu_pin.pump2 = 1000;
  1092. }
  1093. __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, pmu_pin.pump1);
  1094. __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_2, pmu_pin.pump2);
  1095. if(planep.UAV_type == VK_ALL_IN_ONE)
  1096. {
  1097. __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, pmu_pin.nozz1_fm);
  1098. __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, pmu_pin.nozz2_zp);
  1099. }
  1100. else
  1101. {
  1102. __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, pmu_pin.nozz1_fm);
  1103. __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, pmu_pin.nozz2_zp);
  1104. }
  1105. if(planep.UAV_type == VK_ALL_IN_ONE)
  1106. {
  1107. //分电板离心喷头
  1108. distributor.nozzle1 = pmu_pin.nozz1_fm;
  1109. distributor.nozzle2 = pmu_pin.nozz2_zp;
  1110. //离心喷头34
  1111. __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_4, pmu_pin.nozz3); // PB8 nozzle
  1112. __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, pmu_pin.nozz4); // PB9 nozzle
  1113. //前后灯
  1114. if((pmu_pin.aux_light & 0x1) > 0)
  1115. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_SET);
  1116. else
  1117. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_RESET);
  1118. if((pmu_pin.aux_light & 0x2) > 0)
  1119. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_SET);
  1120. else
  1121. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_RESET);
  1122. //摄像头舵机
  1123. __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, pmu_pin.aux_steer);
  1124. }
  1125. break;
  1126. case _MSGID_LED:
  1127. for(uint8_t i = 0; i < 7; i++)
  1128. {
  1129. if(planep.UAV_type != VK_ALL_IN_ONE ) //青岛机型不用LED
  1130. {
  1131. led_set_blink(i, fcu_protocol.payload[i*3+6], fcu_protocol.payload[i*3+7], fcu_protocol.payload[i*3+8]);
  1132. }
  1133. }
  1134. break;
  1135. //飞机姿态信息
  1136. case _MSGID_ATTITUDE:
  1137. memcpy(&planep.yaw, &fcu_protocol.payload[6], sizeof(plane_para));
  1138. if(uavinf.uavtype != planep.UAV_type)
  1139. {
  1140. write_uav_information = true;
  1141. }
  1142. break;
  1143. case _MSGID_TIME:
  1144. //tem_32t = 1684136124;
  1145. memcpy(&utc_time, &fcu_protocol.payload[6], 4);
  1146. covUnixTimeStp2Beijing(utc_time,&beijing_time);
  1147. pmu_set_ack(_MSGID_TIME,0,0,0);
  1148. break;
  1149. //eft播撒器
  1150. case _MSGID_EFT_CON:
  1151. recv_fmu_seed_info = true;
  1152. memcpy(&tppwm_value, &fcu_protocol.payload[6], 2);
  1153. memcpy(&sow_rotate_value, &fcu_protocol.payload[8], 2);
  1154. break;
  1155. //请求信息包
  1156. case _MSGID_REQ:
  1157. switch (fcu_protocol.payload[6])
  1158. {
  1159. case MSGID_REQ_VERSION:
  1160. pmu_send = PMU_SEND_VERSION;
  1161. break;
  1162. default:
  1163. break;
  1164. }
  1165. break;
  1166. //主控应答
  1167. case _MSGID_ACK:
  1168. msgidset.content1 = fcu_protocol.payload[7] + 256 * fcu_protocol.payload[8];
  1169. switch (fcu_protocol.payload[6])
  1170. {
  1171. case MSGID_ACK_HEART:
  1172. uavinf.abnormal_outage_flag = 0;
  1173. write_uav_information = true;
  1174. break;
  1175. case MSGID_ACK_VERSION:
  1176. start_msg.version_info = true;
  1177. break;
  1178. case MSGID_ACK_DEV:
  1179. {
  1180. if(msgidset.content1 < DEVICE_END - 1)
  1181. {
  1182. dev_version_content *Pt = dev_ptr[msgidset.content1];
  1183. if(Pt->send_times > 0)
  1184. Pt->send_times--;
  1185. }
  1186. }
  1187. break;
  1188. default:
  1189. break;
  1190. }
  1191. break;
  1192. //设置雷达灵敏度
  1193. case _MSGID_SET:
  1194. msgidset.num = fcu_protocol.payload[6];
  1195. msgidset.content1 = fcu_protocol.payload[7] + 256 * fcu_protocol.payload[8];
  1196. msgidset.content2 = fcu_protocol.payload[9] + 256 * fcu_protocol.payload[10];
  1197. msgidset.content3 = fcu_protocol.payload[11] + 256 * fcu_protocol.payload[12];
  1198. switch (msgidset.num)
  1199. {
  1200. //前雷达
  1201. case MSGID_SET_F_RADAR:
  1202. if(uavr12_info.fcu_set_sensi_flag != true && uavr56_info.fcu_set_sensi_flag != true && radar_update_flag == false)
  1203. {
  1204. uavr11_info.fcu_set_sensi_flag = true;
  1205. }
  1206. memcpy(&obsfradar_sensitivity, &fcu_protocol.payload[7], 2);
  1207. if(obsfradar_sensitivity == uavr11_info.get_radar_sensi)
  1208. {
  1209. uavr11_info.fcu_set_sensi_flag = false;
  1210. pmu_set_ack(_MSGID_SET,MSGID_SET_F_RADAR,uavr11_info.get_radar_sensi,0);
  1211. }
  1212. break;
  1213. //后雷达
  1214. case MSGID_SET_B_RADAR:
  1215. if(uavr11_info.fcu_set_sensi_flag != true && uavr56_info.fcu_set_sensi_flag != true && radar_update_flag == false)
  1216. {
  1217. uavr12_info.fcu_set_sensi_flag = true;
  1218. }
  1219. memcpy(&obsbradar_sensitivity, &fcu_protocol.payload[7], 2);
  1220. if(obsbradar_sensitivity == uavr12_info.get_radar_sensi)
  1221. {
  1222. uavr12_info.fcu_set_sensi_flag = false;
  1223. pmu_set_ack(_MSGID_SET,MSGID_SET_B_RADAR,uavr12_info.get_radar_sensi,0);
  1224. }
  1225. break;
  1226. //仿地
  1227. case MSGID_SET_T_RADAR:
  1228. if(uavr11_info.fcu_set_sensi_flag != true && uavr12_info.fcu_set_sensi_flag != true && radar_update_flag == false)
  1229. {
  1230. uavr56_info.fcu_set_sensi_flag = true;
  1231. }
  1232. memcpy(&uavr56_info.fcu_set_sensi, &fcu_protocol.payload[7], 2);
  1233. if(uavr56_info.fcu_set_sensi == uavr56_info.get_radar_sensi)
  1234. {
  1235. uavr56_info.fcu_set_sensi_flag = false;
  1236. pmu_set_ack(_MSGID_SET,MSGID_SET_T_RADAR,uavr56_info.get_radar_sensi,0);
  1237. }
  1238. break;
  1239. case MSGID_SET_TR_BLIND:
  1240. {
  1241. uint8_t can_buf[8] = {0};
  1242. uint32_t can_id = 0;
  1243. if(msgidset.content1 == 0x11)
  1244. can_id = 0xA81300;
  1245. else if (msgidset.content1 == 0x56)
  1246. can_id = 0x981300;
  1247. put_date_to_can(can_buf,0x5,(msgidset.content2 & 0xff),((msgidset.content2 >> 8) & 0xff),0,0,0,0,0X7);
  1248. can_send_msg_normal(&can_buf[0], 8, can_id);
  1249. }
  1250. break;
  1251. case MSGID_SET_BR_POWER:
  1252. {
  1253. uint8_t can_buf[8] = {0};
  1254. uint32_t can_id = 0;
  1255. if(msgidset.content1 == 0x11)
  1256. can_id = 0xA81300;
  1257. else if (msgidset.content1 == 0x56)
  1258. can_id = 0x981300;
  1259. put_date_to_can(can_buf,0x7,(msgidset.content2 & 0xff),((msgidset.content2 >> 8) & 0xff),0,0,0,0,0X7);
  1260. can_send_msg_normal(&can_buf[0], 8, can_id);
  1261. }
  1262. break;
  1263. case MSGID_SET_R_FUNC:
  1264. {
  1265. uint8_t can_buf[8] = {0};
  1266. uint32_t can_id = 0;
  1267. if(msgidset.content1 == 3)
  1268. can_id = 0x981300;
  1269. else if(msgidset.content1 == 5)
  1270. can_id = 0xA81300;
  1271. put_date_to_can(can_buf,0x4,(msgidset.content1 & 0xff),((msgidset.content1 >> 8) & 0xff),0,0,0,0,0X7);
  1272. can_send_msg_normal(&can_buf[0], 8, can_id);
  1273. }
  1274. break;
  1275. case MSGID_SET_RAW_SWITCH:
  1276. {
  1277. uint8_t can_buf[8] = {0};
  1278. uint32_t can_id = 0;
  1279. if(msgidset.content1 == 0x11)
  1280. can_id = 0xA81300;
  1281. else if (msgidset.content1 == 0x56)
  1282. can_id = 0x981300;
  1283. put_date_to_can(can_buf,0xA,(msgidset.content2 & 0xff),((msgidset.content2 >> 8) & 0xff),0,0,0,0,0X7);
  1284. can_send_msg_normal(&can_buf[0], 8, can_id);
  1285. }
  1286. break;
  1287. case MSGID_SET_GEELY:
  1288. switch (fcu_protocol.payload[7])
  1289. {
  1290. case SET_START_OR_STOP:
  1291. if(0x1 == fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00))
  1292. {
  1293. if (geely_engin_link.connect_status == COMP_NORMAL && geely_data.engine_control == 0)
  1294. {
  1295. sendto_geely.ExtenderControl = 1;
  1296. }
  1297. start_engine = 0x80;
  1298. }
  1299. else if(0x0 == fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00))
  1300. {
  1301. if (geely_engin_link.connect_status == COMP_NORMAL && geely_data.engine_control == 1)
  1302. {
  1303. sendto_geely.ExtenderControl = 0;
  1304. }
  1305. start_engine = 0;
  1306. }
  1307. break;
  1308. case SET_PROTECT_TIME:
  1309. if (geely_engin_link.connect_status == COMP_NORMAL)
  1310. {
  1311. geely_set_tcd = true;
  1312. sendto_geely.SettingParameter = fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00);
  1313. }
  1314. break;
  1315. case SET_LOCK_TIME:
  1316. if (geely_engin_link.connect_status == COMP_NORMAL)
  1317. {
  1318. geely_set_tlock = true;
  1319. sendto_geely.SettingParameter = fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00);
  1320. }
  1321. break;
  1322. case SET_LOWVOL_PROTECT:
  1323. if(0x1 == fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00))
  1324. {
  1325. if (geely_engin_link.connect_status == COMP_NORMAL)
  1326. {
  1327. sendto_geely.ExtenderControl = 1;
  1328. geely_set_protect = true;
  1329. }
  1330. }
  1331. else
  1332. {
  1333. geely_set_protect = false;
  1334. }
  1335. break;
  1336. default:
  1337. break;
  1338. }
  1339. break;
  1340. case MSGID_SET_VOL:
  1341. set_cali_voltage = (fcu_protocol.payload[7] + 256 * fcu_protocol.payload[8]) - (int)(ADC_gather() /100.0f) ;
  1342. write_vol_information = true;
  1343. pmu_set_ack(_MSGID_SET,MSGID_SET_VOL,0,0);
  1344. break;
  1345. case MSGID_SET_MIMO_FLOW:
  1346. if(msgidset.content1 != 0)
  1347. {
  1348. if(Dev.Flow.facid == FAC_MIMO_SIG || Dev.Flow.facid == FAC_MIMO_DOU)
  1349. {
  1350. tem_32t = flow_mimo1.flow_k * msgidset.content1 / 100;
  1351. if(tem_32t >= 500 && tem_32t <= 20000)
  1352. {
  1353. flow_mimo1.flow_calk = tem_32t;
  1354. }
  1355. else{
  1356. flow_mimo1.flow_calk = 10000;
  1357. }
  1358. flow_mimo1.send_k_count = 5;
  1359. }
  1360. else if(Dev.Flow.facid == FAC_QIFEI_SIG || Dev.Flow.facid == FAC_QIFEI_DOU)
  1361. {
  1362. tem_32t = flow_inf.ch1.k * msgidset.content1 / 100;
  1363. if(tem_32t >= 500 && tem_32t <= 20000)
  1364. {
  1365. flow_inf.ch1.cal_k = tem_32t;
  1366. }
  1367. else{
  1368. flow_inf.ch1.cal_k = 10000;
  1369. }
  1370. flow_inf.ch1.set_k = true;
  1371. }
  1372. }
  1373. if(msgidset.content2 != 0)
  1374. {
  1375. if(Dev.Flow.facid == FAC_MIMO_SIG || Dev.Flow.facid == FAC_MIMO_DOU)
  1376. {
  1377. tem_32t = flow_mimo2.flow_k * msgidset.content2 / 100;
  1378. if(tem_32t >= 500 && tem_32t <= 20000)
  1379. {
  1380. flow_mimo2.flow_calk = tem_32t;
  1381. }
  1382. else{
  1383. flow_mimo2.flow_calk = 10000;
  1384. }
  1385. flow_mimo2.send_k_count = 5;
  1386. }
  1387. else if(Dev.Flow.facid == FAC_QIFEI_SIG || Dev.Flow.facid == FAC_QIFEI_DOU)
  1388. {
  1389. tem_32t = flow_inf.ch2.k * msgidset.content2 / 100;
  1390. if(tem_32t >= 500 && tem_32t <= 20000)
  1391. {
  1392. flow_inf.ch2.cal_k = tem_32t;
  1393. }
  1394. else{
  1395. flow_inf.ch2.cal_k = 10000;
  1396. }
  1397. flow_inf.ch1.set_k = true;
  1398. }
  1399. }
  1400. break;
  1401. case MSGID_SET_FLOW_BACKGROUND:
  1402. if(Dev.Flow.facid == FAC_MIMO_SIG)
  1403. {
  1404. flow_inf.ch1.clear_background = true;
  1405. }
  1406. if(Dev.Flow.facid == FAC_MIMO_DOU)
  1407. {
  1408. flow_inf.ch1.clear_background = true;
  1409. flow_inf.ch2.clear_background = true;
  1410. }
  1411. break;
  1412. case MSGID_SET_WEIGHT_K:
  1413. //calib_aux = msgidset.content1 + (msgidset.content2 << 2); //bit 0-1 编号 2-15K值
  1414. weight_order.type = Weight_Set_K;
  1415. weight_order.order_con1 = msgidset.content1;
  1416. weight_order.order_con2 = msgidset.content2;
  1417. break;
  1418. case MSGID_SET_SEED_OUT_TYPE:
  1419. recv_fmu_seed_info = true;
  1420. seed_output_mode = msgidset.content1;
  1421. pmu_set_ack(_MSGID_SET,MSGID_SET_SEED_OUT_TYPE,0,0);
  1422. break;
  1423. case MSGID_SET_SEED_CAL_TYPE:
  1424. switch (msgidset.content1)
  1425. {
  1426. case Cal_Remove_Peel:
  1427. weight_order.type = Weight_Peer;
  1428. break;
  1429. case Cal_Weight:
  1430. weight_order.type = Weight_Kg;
  1431. weight_order.order_con2 = msgidset.content2;
  1432. weight_order.order_con3 = msgidset.content3;
  1433. break;
  1434. case Cal_Seed_Back:
  1435. weight_order.type = Weight_Bcak;
  1436. break;
  1437. default:
  1438. break;
  1439. }
  1440. break;
  1441. case MSGID_SET_WEIGHT_MODE:
  1442. weight_order.type = Weight_Mode;
  1443. weight_order.order_con1 = msgidset.content1;
  1444. break;
  1445. case MSGID_SET_MAX_RATE:
  1446. weight_order.type = Weight_Drug_Rate;
  1447. weight_order.order_con1 = msgidset.content1;
  1448. break;
  1449. case MSGID_SET_PMU_SERIAL:
  1450. set_pmu_serail = msgidset.content1 + ((msgidset.content2 << 16) & 0xffff0000);
  1451. if(serial.num == PMU_SERIAL || set_pmu_serail == PMU_SERIAL)
  1452. {
  1453. write_serial_information = true;
  1454. pmu_set_ack(_MSGID_SET,MSGID_SET_PMU_SERIAL,0,0);
  1455. dev_pmu.send_times += 5;
  1456. }
  1457. else if(set_pmu_serail == serial.num)
  1458. {
  1459. pmu_set_ack(_MSGID_SET,MSGID_SET_PMU_SERIAL,0,0);
  1460. }
  1461. break;
  1462. case MSGID_SET_RADAR_FB:
  1463. {
  1464. uint8_t can_buf[8] = {0};
  1465. if(msgidset.content1 == 0x11)
  1466. {
  1467. put_date_to_can(can_buf,0x55,0XAA,0X03,0X61,0X03,0X01,0X65,0X00);
  1468. can_send_msg_normalstd(can_buf,7,0xFA);
  1469. }
  1470. else if (msgidset.content1 == 0x12)
  1471. {
  1472. put_date_to_can(can_buf,0x55,0XAA,0X03,0X61,0X03,0X02,0X66,0X00);
  1473. can_send_msg_normalstd(can_buf,7,0xFA);
  1474. }
  1475. else if(msgidset.content1 == 0x100)
  1476. {
  1477. if(msgidset.content2 == 0x11 || msgidset.content2 == 0x12)
  1478. {
  1479. put_date_to_can(can_buf,0x55,0XAA,0X03,0X61,0X00,0X03,0X64,0X00);
  1480. can_send_msg_normalstd(can_buf,7,0xFA);
  1481. }
  1482. else if(msgidset.content2 == 0x56)
  1483. {
  1484. put_date_to_can(can_buf,0x55,0XAA,0X02,0X60,0X03,0X63,0X00,0X00);
  1485. can_send_msg_normalstd(can_buf,6,0xFA);
  1486. }
  1487. }
  1488. }
  1489. break;
  1490. case MSGID_SET_LACKLOSS_CAL:
  1491. {
  1492. uint8_t can_buf[8] = {0};
  1493. if(Dev.Lackloss_Link.connect_status == COMP_NORMAL)
  1494. {
  1495. mimo_lackloss.cal_distance = mimo_lackloss.distance / 10 + 5;
  1496. put_date_to_can(can_buf,0xFA,0x03,0x00,0xB1,0XC1,0x00,0X00,0X00);
  1497. can_buf[6] = mimo_lackloss.cal_distance & 0xff;
  1498. can_buf[5] = (mimo_lackloss.cal_distance >> 8) & 0xff;
  1499. can_buf[7] = (can_buf[1]+can_buf[2]+can_buf[3]+can_buf[4]+can_buf[5]+can_buf[6]) & 0xff;
  1500. can_send_msg_normalstd(can_buf,8,0xFA);
  1501. }
  1502. }
  1503. break;
  1504. case MSGID_SET_PUMP_ID:
  1505. set_HWesc_ESCid = true;
  1506. setESCidInfo.setESCidNum = 1;
  1507. setESCidInfo.setESCidStep = SETESCID_INIT;
  1508. pmu_set_ack(_MSGID_SET,MSGID_SET_PUMP_ID,0,2);
  1509. break;
  1510. case MSGID_SET_RESIWIRE_BLOWN:
  1511. {
  1512. uint8_t can_buf[8] = {0};
  1513. put_date_to_can(can_buf,0xF7,fcu_protocol.payload[7],0x00,0x00,0x00,0xF1,0XF3,0X00);
  1514. can_send_msg_normal(&can_buf[0], 8, 0x88BB);
  1515. }
  1516. break;
  1517. case MSGID_SET_FRADAR_SN:
  1518. {
  1519. int radar_Sn = 0;
  1520. uint8_t can_buf[8] = {0};
  1521. radar_Sn = msgidset.content1 + (msgidset.content2 << 16);
  1522. can_buf[0] = 2;
  1523. memcpy(&can_buf[1],&radar_Sn,4);
  1524. can_buf[7] = 7;
  1525. can_send_msg_normal(can_buf,8,0xA81300);
  1526. DM_f_info.get_radar_ver_flag = false;
  1527. dev_obsf.regist.sn = false;
  1528. pmu_set_ack(_MSGID_SET,MSGID_SET_FRADAR_SN,msgidset.content1,msgidset.content2);
  1529. }
  1530. break;
  1531. case MSGID_SET_BRADAR_SN:
  1532. {
  1533. int radar_Sn = 0;
  1534. uint8_t can_buf[8] = {0};
  1535. radar_Sn = msgidset.content1 + (msgidset.content2 << 16);
  1536. can_buf[0] = 2;
  1537. memcpy(&can_buf[1],&radar_Sn,4);
  1538. can_buf[7] = 7;
  1539. can_send_msg_normal(can_buf,8,0xB81300);
  1540. dev_obsb.regist.sn = false;
  1541. //DM_b_info.get_radar_ver_flag = false;
  1542. pmu_set_ack(_MSGID_SET,MSGID_SET_BRADAR_SN,msgidset.content1,msgidset.content2);
  1543. }
  1544. break;
  1545. case MSGID_SET_TRADAR_SN:
  1546. {
  1547. int radar_Sn = 0;
  1548. uint8_t can_buf[8] = {0};
  1549. radar_Sn = msgidset.content1 + (msgidset.content2 << 16);
  1550. can_buf[0] = 2;
  1551. memcpy(&can_buf[1],&radar_Sn,4);
  1552. can_buf[7] = 7;
  1553. can_send_msg_normal(can_buf,8,0x981300);
  1554. DM_ter_info.get_radar_ver_flag = false;
  1555. dev_ter.regist.sn = false; //重新获取sn
  1556. pmu_set_ack(_MSGID_SET,MSGID_SET_TRADAR_SN,msgidset.content1,msgidset.content2);
  1557. }
  1558. break;
  1559. default:
  1560. break;
  1561. }
  1562. break;
  1563. case _MSGID_HEART:
  1564. pmu_heart_flag = true;
  1565. break;
  1566. case _MSGID_SHA1:
  1567. //智能电池秘钥
  1568. if(fcu_protocol.payload[6] == 1)
  1569. {
  1570. //有秘钥
  1571. if(fcu_protocol.payload[7] == 2 && fcu_protocol.payload[8] == 1)
  1572. {
  1573. if(start_msg.key_info_checking == true)
  1574. {
  1575. memcpy(&start_msg.key_data[0],&fcu_protocol.payload[9],20);
  1576. start_msg.key_to_bms = true;//给电池发送秘钥
  1577. start_msg.key_info_checking = false;
  1578. }
  1579. }
  1580. //无秘钥
  1581. else if(fcu_protocol.payload[7] == 2 && fcu_protocol.payload[8] == 2)
  1582. {
  1583. start_msg.key_info_checking = false;
  1584. }
  1585. //回馈,防止PMU一直发
  1586. else if(fcu_protocol.payload[7] == 3 || fcu_protocol.payload[7] == 4)
  1587. {
  1588. start_msg.key_info_checking = false;
  1589. }
  1590. }
  1591. break;
  1592. //升级固件标志
  1593. case _MSGID_UPDATA:
  1594. {
  1595. __disable_irq();
  1596. HAL_FLASH_Unlock();
  1597. __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
  1598. f.TypeErase = FLASH_TYPEERASE_PAGES;
  1599. f.PageAddress = UPDATE_FLAG;
  1600. f.NbPages = 1;
  1601. uint32_t PageError = 0;
  1602. HAL_FLASHEx_Erase(&f, &PageError);
  1603. uint16_t TempBuf = 0x01;
  1604. HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, UPDATE_FLAG, TempBuf);
  1605. HAL_FLASH_Lock();
  1606. __enable_irq();
  1607. HAL_NVIC_DisableIRQ(USART2_IRQn);
  1608. HAL_Delay(100);
  1609. //软件复位
  1610. HAL_NVIC_SystemReset();
  1611. }
  1612. break;
  1613. default:
  1614. break;
  1615. }
  1616. uart_info.fcu_buf_flag = false;
  1617. memset(fcu_protocol.payload, 0, 256);
  1618. }
  1619. }
  1620. /******************void pmu_start_info()*******************
  1621. * ****************上电时PMU发送的信息*******************************
  1622. * ****************************************************************/
  1623. Start_info start_msg = {.key_info_checking = true,
  1624. .Dev_type = 1,
  1625. .Id = 1,
  1626. };
  1627. void pmu_start_info()
  1628. {
  1629. static uint32_t circu_time_2hz = 0;
  1630. if(Check_Timer_Ready(&circu_time_2hz,_2_HZ_))
  1631. {
  1632. if(HAL_GetTick() > 10000 && start_msg.version_info == false)
  1633. {
  1634. pmu_send = PMU_SEND_VERSION;
  1635. start_msg.version_info = true;
  1636. }
  1637. else if (start_msg.key_info_checking == true && Device1.Vkbms_Link.connect_status == COMP_NORMAL)
  1638. {
  1639. pmu_send = PMU_SEND_SHA1;
  1640. }
  1641. }
  1642. }