soft_p_2_c.c 58 KB

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