soft_p_2_c.c 60 KB

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