soft_p_2_c.c 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902
  1. #include "soft_p_2_c.h"
  2. #include "soft_uart.h"
  3. #include "usart.h"
  4. #include "stdbool.h"
  5. #include "soft_timer.h"
  6. #include "soft_adc.h"
  7. #include "soft_flow.h"
  8. #include "soft_crc.h"
  9. #include <string.h>
  10. #include "stdbool.h"
  11. #include "tim.h"
  12. #include "hard_led.h"
  13. #include "soft_can.h"
  14. #include "stdio.h"
  15. #include "soft_bms.h"
  16. #include "soft_terrain.h"
  17. #include "soft_obstacle.h"
  18. #include "soft_okcell.h"
  19. #include "soft_adc.h"
  20. #include "config.h"
  21. #include "soft_calibration.h"
  22. #include "soft_flash.h"
  23. #include "bsp_serial.h"
  24. #include "rkfifo.h"
  25. #include "soft_engine.h"
  26. #include "soft_eft.h"
  27. #include "math.h"
  28. #include "stdlib.h"
  29. #include "soft_water_device.h"
  30. #include "soft_seed_device.h"
  31. #include "soft_test.h"
  32. #include "can_debug.h"
  33. #include "soft_version.h"
  34. #include "soft_update.h"
  35. #include "qingxie_bms.h"
  36. #include "soft_flash.h"
  37. uint8_t msg_buf[256] = {0};
  38. uint16_t crc = 0;
  39. pmu_data pmu;
  40. plane_para planep = {.Candebug_flag = 0};
  41. /**
  42. * @file Update_ack_func
  43. * @brief PMU回复ACK 回复升级工具
  44. * @param 组件ID,消息ID,ACK数据
  45. * @details 升级应答FMU透传,协议和升级工具一致,和FMU不一样
  46. * @author Zhang Sir
  47. **/
  48. void Update_ack_func(uint8_t group_id, uint8_t msg_id, uint8_t *ackbuf)
  49. {
  50. int index = 0;
  51. msg_buf[index++] = 0xFE;
  52. msg_buf[index++] = 0;
  53. msg_buf[index++] = 0;
  54. msg_buf[index++] = 0x00;
  55. msg_buf[index++] = group_id;
  56. msg_buf[index++] = 21;
  57. msg_buf[index++] = msg_id;
  58. msg_buf[index++] = *ackbuf;
  59. msg_buf[index++] = *(ackbuf + 1);
  60. msg_buf[index++] = 1;
  61. msg_buf[1] = index - 6;
  62. uint16_t uart_crc = Get_Crc16(msg_buf, index);
  63. memcpy(&msg_buf[index], &uart_crc, 2);
  64. index += 2;
  65. uart2_send_msg(msg_buf, index);
  66. }
  67. /**
  68. * @file pmu_set_ack
  69. * @brief PMU应答FMU
  70. * @param 命令 命令内容 123
  71. * @details
  72. * @author Zhang Sir
  73. **/
  74. void pmu_set_ack(uint8_t id,short content1, short content2,short content3)
  75. {
  76. pmu_send = PMU_SEND_ACK;
  77. ack_id = id;
  78. ack_content = content1;
  79. ack_content1 = content2;
  80. ack_content2 = content3;
  81. }
  82. /**
  83. * @file pmu_to_con_voltage_data
  84. * @brief PMU发送电压、温度信息
  85. * @param none
  86. * @details
  87. * @author Zhang Sir
  88. **/
  89. void pmu_to_con_voltage_data()
  90. {
  91. int index = 0;
  92. msg_buf[index++] = 0xFE;
  93. msg_buf[index++] = 0;
  94. msg_buf[index++] = 0; //组件计数
  95. msg_buf[index++] = 0x00;
  96. msg_buf[index++] = 0x00;
  97. msg_buf[index++] = _MSGID_VOL;
  98. pmu.voltage = ADC_gather() / 10.0f + volinf.cal_vol * 10; // 获取当前板子电压
  99. memcpy(&msg_buf[index], &pmu.voltage, 2);
  100. index += 2;
  101. pmu.temperature = ADC_read_temptrue();
  102. memcpy(&msg_buf[index], &pmu.temperature, 2);
  103. index += 2;
  104. msg_buf[index++] = 0;
  105. msg_buf[index++] = 0;
  106. memcpy(&msg_buf[index], &uavinf.abnormal_outage_flag, 2);
  107. index += 2;
  108. msg_buf[1] = index - 6;
  109. crc = Get_Crc16(msg_buf, index);
  110. msg_buf[index++] = crc;
  111. msg_buf[index++] = (crc >> 8) & 0xff;
  112. uart2_send_msg(msg_buf, index); //10
  113. //for(int i = 0;i<10;i++){
  114. //printf("%d ",msg_buf[6]);
  115. //printf("%d\n",msg_buf[7]);
  116. //}
  117. }
  118. /**
  119. * @file get_radar_info
  120. * @brief 获取雷达信息
  121. * @param Info_Type:避障雷达 X:1 Y:2
  122. * @details
  123. * @author Zhang Sir
  124. **/
  125. short get_radar_info(uint8_t Radar_Type,uint8_t Info_Type)
  126. {
  127. uavr_terrain *Ptr_T = NULL;
  128. uavr_obs *Ptr_O = NULL;
  129. if(Radar_Type == MSGID_SET_T_RADAR)
  130. {
  131. if(mimo_ter_info.Link.connect_status != COMP_NOEXIST)
  132. Ptr_T = &mimo_ter_info;
  133. else if(DM_ter_info.Link.connect_status != COMP_NOEXIST)
  134. Ptr_T = &DM_ter_info;
  135. else if(uavr56_info.Link.connect_status != COMP_NOEXIST)
  136. Ptr_T = &uavr56_info;
  137. if(Ptr_T->Link.connect_status == COMP_LOST) {return -2;}
  138. else if(Ptr_T == NULL) {return -1;}
  139. else {return Ptr_T->height;}
  140. }
  141. else if(Radar_Type == MSGID_SET_F_RADAR)
  142. {
  143. if(uavr11_info.Link.connect_status != COMP_NOEXIST)
  144. Ptr_O = &uavr11_info;
  145. else if(mimo_f_info.Link.connect_status != COMP_NOEXIST)
  146. Ptr_O = &mimo_f_info;
  147. else if(DM_f_info.Link.connect_status != COMP_NOEXIST)
  148. Ptr_O = &DM_f_info;
  149. if(Ptr_O->Link.connect_status == COMP_LOST) {return -2;}
  150. else if(Ptr_O == NULL) {return -1;}
  151. else
  152. {
  153. if(Info_Type == OBS_X)
  154. return Ptr_O->distance_x;
  155. else if((Info_Type == OBS_Y))
  156. return Ptr_O->distance_y;
  157. }
  158. }
  159. else if(Radar_Type == MSGID_SET_B_RADAR)
  160. {
  161. if(uavr12_info.Link.connect_status != COMP_NOEXIST)
  162. Ptr_O = &uavr12_info;
  163. else if(mimo_b_info.Link.connect_status != COMP_NOEXIST)
  164. Ptr_O = &mimo_b_info;
  165. if(Ptr_O->Link.connect_status == COMP_LOST) {return -2;}
  166. else if(Ptr_O == NULL) {return -1;}
  167. else
  168. {
  169. if(Info_Type == OBS_X)
  170. return Ptr_O->distance_x;
  171. else if((Info_Type == OBS_Y))
  172. return Ptr_O->distance_y;
  173. }
  174. }
  175. return 0;
  176. }
  177. /**
  178. * @file pmu_to_con_radar_data
  179. * @brief PMU发送雷达信息
  180. * @param none
  181. * @details
  182. * @author Zhang Sir
  183. **/
  184. void pmu_to_con_radar_data()
  185. {
  186. int index = 0;
  187. //检查各种雷达连接状态
  188. check_radar_link_status();
  189. msg_buf[index++] = 0xFE;
  190. msg_buf[index++] = 10;
  191. msg_buf[index++] = 0;
  192. msg_buf[index++] = 0x00;
  193. msg_buf[index++] = 0x00;
  194. msg_buf[index++] = _MSGID_RADAR;
  195. pmu.radar_buf[0] = get_radar_info(MSGID_SET_T_RADAR,0);
  196. pmu.radar_buf[1] = get_radar_info(MSGID_SET_F_RADAR,OBS_Y);
  197. pmu.radar_buf[2] = get_radar_info(MSGID_SET_F_RADAR,OBS_X);
  198. pmu.radar_buf[3] = get_radar_info(MSGID_SET_B_RADAR,OBS_Y);
  199. pmu.radar_buf[4] = get_radar_info(MSGID_SET_B_RADAR,OBS_X);
  200. terrain_is_link = pmu.radar_buf[0] > -1? true:false;
  201. obs_f_is_link = pmu.radar_buf[1] > -1? true:false;
  202. obs_b_is_link = pmu.radar_buf[3] > -1? true:false;
  203. // //发送木牛或者恩曌数据或者莫之比仿地
  204. // if ((muniu_ter_info.muniu_time == 0) && (mimo_ter_info.heart_time == 0) && (uavr56_info.heart_time == 0)) //上电没通讯
  205. // {
  206. // pmu.radar_buf[0] = -1;
  207. // terrain_is_link = false;
  208. // }
  209. // else if ((muniu_ter_info.muniu_heart_flag == false) && (mimo_ter_info.heart_flag == false) &&
  210. // (uavr56_info.heart_flag == false)) //持续3秒没有接收到数据 显示断开连接
  211. // {
  212. // pmu.radar_buf[0] = -2;
  213. // terrain_is_link = false;
  214. // }
  215. // else
  216. // {
  217. // if (muniu_ter_info.muniu_heart_flag == true)
  218. // {
  219. // pmu.radar_buf[0] = muniu_ter_info.muniu_hight;
  220. // terrain_height = muniu_ter_info.muniu_hight;
  221. // //printf("%d\n", muniu_hight);
  222. // }
  223. // else if (uavr56_info.heart_flag == true)
  224. // {
  225. // pmu.radar_buf[0] = uavr56_info.height;
  226. // terrain_height = uavr56_info.height;
  227. // // printf("%d\n",uavr56_info.height);
  228. // }
  229. // else if (mimo_ter_info.heart_flag == true)
  230. // {
  231. // pmu.radar_buf[0] = mimo_ter_info.height;
  232. // terrain_height = mimo_ter_info.height;
  233. // // printf("%d %d %d %d\n",mimo_ter_info.height,keep_time,ez_count,ez_count2);
  234. // }
  235. // terrain_is_link = true;
  236. // }
  237. // //前避障
  238. // if (uavr11_info.heart_time == 0 && mimo_f_info.heart_time == 0)
  239. // {
  240. // pmu.radar_buf[1] = -1;
  241. // obs_f_is_link = false;
  242. // }
  243. // else if (uavr11_info.heart_flag == false && mimo_f_info.heart_flag == false)
  244. // {
  245. // pmu.radar_buf[1] = -2;
  246. // obs_f_is_link = false;
  247. // }
  248. // else
  249. // {
  250. // if (uavr11_info.heart_flag == true)
  251. // {
  252. // if(Fobs_handle_function())
  253. // {
  254. // pmu.radar_buf[1] = uavr11_info.distance_y;
  255. // pmu.radar_buf[2] = uavr11_info.distance_x;
  256. // }
  257. // else
  258. // {
  259. // pmu.radar_buf[1] = 0;
  260. // pmu.radar_buf[2] = 0;
  261. // }
  262. // }
  263. // if (mimo_f_info.heart_flag == true)
  264. // {
  265. // if(Fobs_handle_function())
  266. // {
  267. // pmu.radar_buf[1] = mimo_f_info.distance_y;
  268. // pmu.radar_buf[2] = mimo_f_info.distance_x;
  269. // }
  270. // else
  271. // {
  272. // pmu.radar_buf[1] = 0;
  273. // pmu.radar_buf[2] = 0;
  274. // }
  275. // //printf("%d\n",ez_obs_distance_y);
  276. // // printf("%d %d %d %d\n",mimo_f_info.distance_y,keep_time,ez_count,ez_count2);
  277. // }
  278. // obs_f_is_link = true;
  279. // }
  280. // //后避障
  281. // if (uavr12_info.heart_time == 0 && mimo_b_info.heart_time == 0)
  282. // {
  283. // pmu.radar_buf[3] = -1;
  284. // obs_b_is_link = false;
  285. // }
  286. // else if (uavr12_info.heart_flag == false && mimo_b_info.heart_flag == false)
  287. // {
  288. // pmu.radar_buf[3] = -2;
  289. // obs_b_is_link = false;
  290. // }
  291. // else
  292. // {
  293. // if (uavr12_info.heart_flag == true)
  294. // {
  295. // if(Bobs_handle_function())
  296. // {
  297. // pmu.radar_buf[3] = uavr12_info.distance_y;
  298. // pmu.radar_buf[4] = uavr12_info.distance_x;
  299. // }
  300. // else
  301. // {
  302. // pmu.radar_buf[3] = 0;
  303. // pmu.radar_buf[4] = 0;
  304. // }
  305. // }
  306. // else if(mimo_b_info.heart_flag == true)
  307. // {
  308. // if(Bobs_handle_function())
  309. // {
  310. // pmu.radar_buf[3] = mimo_b_info.distance_y;
  311. // pmu.radar_buf[4] = mimo_b_info.distance_x;
  312. // }
  313. // else
  314. // {
  315. // pmu.radar_buf[3] = 0;
  316. // pmu.radar_buf[4] = 0;
  317. // }
  318. // }
  319. // obs_b_is_link = true;
  320. // }
  321. memcpy(&msg_buf[index], &pmu.radar_buf[0], 10);
  322. index += 10;
  323. msg_buf[1] = index - 6;
  324. crc = Get_Crc16(msg_buf, index);
  325. msg_buf[index++] = crc;
  326. msg_buf[index++] = (crc >> 8) & 0xff;
  327. uart2_send_msg(msg_buf, index);
  328. }
  329. /**
  330. * @file pmu_to_con_barttery_data
  331. * @brief PMU发送智能电池信息
  332. * @param none
  333. * @details
  334. * @author Zhang Sir
  335. **/
  336. void pmu_to_con_barttery_data()
  337. {
  338. int index = 0;
  339. if (Dev.Bms_Link.connect_status == COMP_NORMAL)
  340. {
  341. uint8_t size_elong = 3 + 1 + 1 + bms_data.bms_num * 2; //前5字节:协议版本3 电池串数1 电池组数1
  342. uint8_t size_elong2 = 1 + bms_data2.bms_num * 2; //电池串数 加 电压
  343. msg_buf[index++] = 0xFE;
  344. msg_buf[index++] = 0; // 31 电池ID后的变量字节数
  345. msg_buf[index++] = 0;
  346. msg_buf[index++] = 0x00;
  347. msg_buf[index++] = 0x00;
  348. msg_buf[index++] = _MSGID_BMS;
  349. bms_data.bms_version[0] = 'V';
  350. bms_data.bms_version[1] = 'K';
  351. bms_data.bms_version[2] = '3';
  352. bms_data.bms_group = group_num;
  353. //一组电池
  354. if (bms_data.bms_group == 1)
  355. {
  356. memcpy(&msg_buf[index], &bms_data, size_elong); //变长数组 赋值到最后一个电压
  357. index += size_elong;
  358. memcpy(&msg_buf[index], &bms_data.bms_ids, 45); //从id 到状态 31字节 + 2字节 厂商编号
  359. index += 45; //新加32字节 33+12=45
  360. msg_buf[1] = index - 6;
  361. crc = Get_Crc16(msg_buf, index);
  362. msg_buf[index++] = crc;
  363. msg_buf[index++] = (crc >> 8) & 0xff;
  364. uart2_send_msg(msg_buf, index);
  365. }
  366. //两组电池
  367. else if (bms_data.bms_group == 2)
  368. {
  369. memcpy(&msg_buf[index], &bms_data, size_elong); //变长数组 赋值到最后一个电压
  370. index += size_elong;
  371. memcpy(&msg_buf[index], &bms_data.bms_ids, 45); //从id 到状态 31字节
  372. index += 45;
  373. memcpy(&msg_buf[index], &bms_data2.bms_num, size_elong2);
  374. index += size_elong2;
  375. memcpy(&msg_buf[index], &bms_data2.bms_ids, 45);
  376. index += 45;
  377. msg_buf[1] = index - 6;
  378. crc = Get_Crc16(msg_buf, index);
  379. msg_buf[index++] = crc;
  380. msg_buf[index++] = (crc >> 8) & 0xff;
  381. uart2_send_msg(msg_buf, index);
  382. }
  383. }
  384. }
  385. /**
  386. * @file pmu_to_con_engin_data
  387. * @brief PMU发送发动机信息
  388. * @param none
  389. * @details
  390. * @author Zhang Sir
  391. **/
  392. void pmu_to_con_engine_data(void)
  393. {
  394. uint8_t index = 0;
  395. if(engine_link_status == COMP_NORMAL)
  396. {
  397. msg_buf[index++] = 0xFE;
  398. msg_buf[index++] = 0;
  399. msg_buf[index++] = 0; //组件计数
  400. msg_buf[index++] = 0x00;
  401. msg_buf[index++] = 0x00;
  402. msg_buf[index++] = _MSG_ENGIN;
  403. memcpy(&msg_buf[index],&engine_data.engine_type,sizeof(engine_data));
  404. index += (sizeof(engine_data));
  405. msg_buf[1] = index - 6;
  406. crc = Get_Crc16(msg_buf, index);
  407. msg_buf[index++] = crc;
  408. msg_buf[index++] = (crc >> 8) & 0xff;
  409. uart2_send_msg(msg_buf, index);
  410. }
  411. }
  412. // /**
  413. // * @file pmu_to_con_radar360_data
  414. // * @brief PMU发送360信息
  415. // * @param none
  416. // * @details
  417. // * @author Zhang Sir
  418. // **/
  419. // void pmu_to_con_radar360_data(void)
  420. // {
  421. // uint8_t index = 0;
  422. // uint32_t send_byte = 0;
  423. // if(mimo_360_info.connect_status == COMP_NORMAL)
  424. // {
  425. // msg_buf[index++] = 0xFE;
  426. // msg_buf[index++] = 0;
  427. // msg_buf[index++] = 0;
  428. // msg_buf[index++] = 0x00;
  429. // msg_buf[index++] = 0x00;
  430. // msg_buf[index++] = _MSGID_360RADAR;
  431. // radar360_proflag = 1;
  432. // send_byte = sizeof(mimo_360_data) * fmu_360info.total_tar + 2;
  433. // memcpy(&msg_buf[index],&fmu_360info,send_byte);
  434. // index += send_byte;
  435. // radar360_proflag = 0;
  436. // msg_buf[1] = index - 6;
  437. // crc = Get_Crc16(msg_buf, index);
  438. // msg_buf[index++] = crc;
  439. // msg_buf[index++] = (crc >> 8) & 0xff;
  440. // uart2_send_msg(msg_buf, index);
  441. // }
  442. // }
  443. /**
  444. * @file pmu_to_con_radar360_data
  445. * @brief PMU发送360信息
  446. * @param none
  447. * @details
  448. * @author Zhang Sir
  449. **/
  450. void pmu_to_con_DMradar_data(void)
  451. {
  452. uint8_t index = 0;
  453. if(DM_status.connect_status == COMP_NORMAL)
  454. {
  455. msg_buf[index++] = 0xFE;
  456. msg_buf[index++] = 0;
  457. msg_buf[index++] = 0;
  458. msg_buf[index++] = 0x00;
  459. msg_buf[index++] = 0x00;
  460. msg_buf[index++] = _MSGID_DMRADAR;
  461. DM_recv_flag = 1;
  462. memcpy(&msg_buf[index],&FMU_DM_info.target_num,3);
  463. index += 3;
  464. memcpy(&msg_buf[index],&FMU_DM_info.warn,2);
  465. index += 2;
  466. memcpy(&msg_buf[index],FMU_DM_info.buf,DM_T_info.target_num * 4);
  467. index += DM_T_info.target_num * 4;
  468. DM_recv_flag = 0;
  469. msg_buf[1] = index - 6;
  470. crc = Get_Crc16(msg_buf, index);
  471. msg_buf[index++] = crc;
  472. msg_buf[index++] = (crc >> 8) & 0xff;
  473. uart2_send_msg(msg_buf, index);
  474. }
  475. if(DM_4dstatus.connect_status == COMP_NORMAL && DM4d_to_fmu_flag == 1)
  476. {
  477. int8_t pack_count = 0;//需要发送包数
  478. int8_t remain_lastcount = 0; //余数
  479. uint8_t send_bytes = 0; //需要发送字节
  480. uint8_t send_pack = 1; //当前发送包数
  481. int16_t remain_target_num = 0; //剩余发送目标点
  482. int16_t complete_bytes_i= 0;
  483. DM4d_recv_flag = 1;
  484. remain_target_num = FMU_4D_info.target_num;
  485. while (remain_target_num >= 0)
  486. {
  487. index = 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++] = _MSGID_F4DRADAR;
  494. remain_lastcount = remain_target_num % 48;
  495. if( remain_lastcount != 0)
  496. {
  497. pack_count = remain_target_num / 48 + 1;
  498. if(pack_count == 1)
  499. send_bytes = remain_lastcount * 5;
  500. else
  501. send_bytes = 48 * 5;
  502. }
  503. else
  504. {
  505. if(remain_target_num == 0)
  506. send_bytes = 0;
  507. else
  508. send_bytes = 48 * 5;
  509. }
  510. msg_buf[index++] = send_pack;
  511. msg_buf[index++] = FMU_4D_info.target_num;
  512. memcpy(&msg_buf[index],&FMU_4D_info.buf[complete_bytes_i],send_bytes);
  513. index += send_bytes;
  514. complete_bytes_i += send_bytes;
  515. msg_buf[1] = index - 6;
  516. crc = Get_Crc16(msg_buf, index);
  517. msg_buf[index++] = crc;
  518. msg_buf[index++] = (crc >> 8) & 0xff;
  519. uart2_send_msg(msg_buf, index);
  520. remain_target_num -= send_bytes / 5;
  521. if(send_bytes < 48 * 5)
  522. break;
  523. send_pack++;
  524. }
  525. DM4d_recv_flag = 0;
  526. DM4d_to_fmu_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. uint32_t DMJZ = 0 ;
  1133. void uart_recv_con_msg()
  1134. {
  1135. check_fmu_link();
  1136. check_uart_data(&recv_rkfifo);
  1137. if (uart_info.fcu_buf_flag == true)
  1138. {
  1139. uint32_t tem_32t = 0;
  1140. FLASH_EraseInitTypeDef f;
  1141. fmu_link_time = HAL_GetTick();
  1142. recv_fmu_data = true;
  1143. switch (fcu_protocol.msg_id)
  1144. {
  1145. case _MSGID_PWM:
  1146. memcpy(&pmu_pin.pump1, &fcu_protocol.payload[6], sizeof(_pmu_pin));
  1147. if(set_HWesc_ESCid == true && setESCidInfo.setESCidStep == SETESCID_SET)
  1148. {
  1149. memset(&pmu_pin.pump1,0,4);
  1150. if(setESCidInfo.setESCidNum == 1)
  1151. pmu_pin.pump1 = 1000;
  1152. else if(setESCidInfo.setESCidNum == 2)
  1153. pmu_pin.pump2 = 1000;
  1154. }
  1155. __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, pmu_pin.pump1);
  1156. __HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_2, pmu_pin.pump2);
  1157. if(planep.UAV_type == VK_ALL_IN_ONE)
  1158. {
  1159. __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, pmu_pin.nozz1_fm);
  1160. __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, pmu_pin.nozz2_zp);
  1161. }
  1162. else
  1163. {
  1164. __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_2, pmu_pin.nozz1_fm);
  1165. __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, pmu_pin.nozz2_zp);
  1166. }
  1167. if(planep.UAV_type == VK_ALL_IN_ONE)
  1168. {
  1169. //分电板离心喷头
  1170. distributor.nozzle1 = pmu_pin.nozz1_fm;
  1171. distributor.nozzle2 = pmu_pin.nozz2_zp;
  1172. //离心喷头34
  1173. __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_4, pmu_pin.nozz3); // PB8 nozzle
  1174. __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, pmu_pin.nozz4); // PB9 nozzle
  1175. //前后灯
  1176. if((pmu_pin.aux_light & 0x1) > 0)
  1177. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_SET);
  1178. else
  1179. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_0,GPIO_PIN_RESET);
  1180. if((pmu_pin.aux_light & 0x2) > 0)
  1181. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_SET);
  1182. else
  1183. HAL_GPIO_WritePin(GPIOB,GPIO_PIN_1,GPIO_PIN_RESET);
  1184. //摄像头舵机
  1185. __HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_1, pmu_pin.aux_steer);
  1186. }
  1187. break;
  1188. case _MSGID_LED:
  1189. for(uint8_t i = 0; i < 7; i++)
  1190. {
  1191. if(planep.UAV_type != VK_ALL_IN_ONE ) //青岛机型不用LED
  1192. {
  1193. led_set_blink(i, fcu_protocol.payload[i*3+6], fcu_protocol.payload[i*3+7], fcu_protocol.payload[i*3+8]);
  1194. }
  1195. }
  1196. break;
  1197. //飞机姿态信息
  1198. case _MSGID_ATTITUDE:
  1199. memcpy(&planep.yaw, &fcu_protocol.payload[6], sizeof(plane_para));
  1200. if(uavinf.uavtype != planep.UAV_type)
  1201. {
  1202. write_uav_information = true;
  1203. }
  1204. break;
  1205. case _MSGID_TIME:
  1206. //tem_32t = 1684136124;
  1207. memcpy(&utc_time, &fcu_protocol.payload[6], 4);
  1208. covUnixTimeStp2Beijing(utc_time,&beijing_time);
  1209. pmu_set_ack(_MSGID_TIME,0,0,0);
  1210. break;
  1211. //eft播撒器
  1212. case _MSGID_EFT_CON:
  1213. recv_fmu_seed_info = true;
  1214. memcpy(&tppwm_value, &fcu_protocol.payload[6], 2);
  1215. memcpy(&sow_rotate_value, &fcu_protocol.payload[8], 2);
  1216. break;
  1217. //请求信息包
  1218. case _MSGID_REQ:
  1219. switch (fcu_protocol.payload[6])
  1220. {
  1221. case MSGID_REQ_VERSION:
  1222. pmu_send = PMU_SEND_VERSION;
  1223. break;
  1224. default:
  1225. break;
  1226. }
  1227. break;
  1228. //主控应答
  1229. case _MSGID_ACK:
  1230. msgidset.content1 = fcu_protocol.payload[7] + 256 * fcu_protocol.payload[8];
  1231. switch (fcu_protocol.payload[6])
  1232. {
  1233. case MSGID_ACK_HEART:
  1234. uavinf.abnormal_outage_flag = 0;
  1235. write_uav_information = true;
  1236. break;
  1237. case MSGID_ACK_VERSION:
  1238. start_msg.version_info = true;
  1239. break;
  1240. case MSGID_ACK_DEV:
  1241. {
  1242. if(msgidset.content1 < DEVICE_END - 1)
  1243. {
  1244. dev_version_content *Pt = dev_ptr[msgidset.content1];
  1245. if(Pt->send_times > 0)
  1246. Pt->send_times--;
  1247. }
  1248. }
  1249. break;
  1250. default:
  1251. break;
  1252. }
  1253. break;
  1254. //设置雷达灵敏度
  1255. case _MSGID_SET:
  1256. msgidset.num = fcu_protocol.payload[6];
  1257. msgidset.content1 = fcu_protocol.payload[7] + 256 * fcu_protocol.payload[8];
  1258. msgidset.content2 = fcu_protocol.payload[9] + 256 * fcu_protocol.payload[10];
  1259. msgidset.content3 = fcu_protocol.payload[11] + 256 * fcu_protocol.payload[12];
  1260. switch (msgidset.num)
  1261. {
  1262. //前雷达
  1263. case MSGID_SET_F_RADAR:
  1264. if(uavr12_info.fcu_set_sensi_flag != true && uavr56_info.fcu_set_sensi_flag != true && radar_update_flag == false)
  1265. {
  1266. uavr11_info.fcu_set_sensi_flag = true;
  1267. }
  1268. memcpy(&obsfradar_sensitivity, &fcu_protocol.payload[7], 2);
  1269. if(obsfradar_sensitivity == uavr11_info.get_radar_sensi)
  1270. {
  1271. uavr11_info.fcu_set_sensi_flag = false;
  1272. pmu_set_ack(_MSGID_SET,MSGID_SET_F_RADAR,uavr11_info.get_radar_sensi,0);
  1273. }
  1274. break;
  1275. //后雷达
  1276. case MSGID_SET_B_RADAR:
  1277. if(uavr11_info.fcu_set_sensi_flag != true && uavr56_info.fcu_set_sensi_flag != true && radar_update_flag == false)
  1278. {
  1279. uavr12_info.fcu_set_sensi_flag = true;
  1280. }
  1281. memcpy(&obsbradar_sensitivity, &fcu_protocol.payload[7], 2);
  1282. if(obsbradar_sensitivity == uavr12_info.get_radar_sensi)
  1283. {
  1284. uavr12_info.fcu_set_sensi_flag = false;
  1285. pmu_set_ack(_MSGID_SET,MSGID_SET_B_RADAR,uavr12_info.get_radar_sensi,0);
  1286. }
  1287. break;
  1288. //仿地
  1289. case MSGID_SET_T_RADAR:
  1290. if(uavr11_info.fcu_set_sensi_flag != true && uavr12_info.fcu_set_sensi_flag != true && radar_update_flag == false)
  1291. {
  1292. uavr56_info.fcu_set_sensi_flag = true;
  1293. }
  1294. memcpy(&uavr56_info.fcu_set_sensi, &fcu_protocol.payload[7], 2);
  1295. if(uavr56_info.fcu_set_sensi == uavr56_info.get_radar_sensi)
  1296. {
  1297. uavr56_info.fcu_set_sensi_flag = false;
  1298. pmu_set_ack(_MSGID_SET,MSGID_SET_T_RADAR,uavr56_info.get_radar_sensi,0);
  1299. }
  1300. break;
  1301. case MSGID_SET_TR_BLIND:
  1302. {
  1303. uint8_t can_buf[8] = {0};
  1304. uint32_t can_id = 0;
  1305. if(msgidset.content1 == 0x11)
  1306. can_id = 0xA81300;
  1307. else if (msgidset.content1 == 0x56)
  1308. can_id = 0x981300;
  1309. put_date_to_can(can_buf,0x5,(msgidset.content2 & 0xff),((msgidset.content2 >> 8) & 0xff),0,0,0,0,0X7);
  1310. can_send_msg_normal(&can_buf[0], 8, can_id);
  1311. }
  1312. break;
  1313. case MSGID_SET_BR_POWER:
  1314. {
  1315. uint8_t can_buf[8] = {0};
  1316. uint32_t can_id = 0;
  1317. if(msgidset.content1 == 0x11)
  1318. can_id = 0xA81300;
  1319. else if (msgidset.content1 == 0x56)
  1320. can_id = 0x981300;
  1321. put_date_to_can(can_buf,0x7,(msgidset.content2 & 0xff),((msgidset.content2 >> 8) & 0xff),0,0,0,0,0X7);
  1322. can_send_msg_normal(&can_buf[0], 8, can_id);
  1323. }
  1324. break;
  1325. case MSGID_SET_R_FUNC:
  1326. {
  1327. uint8_t can_buf[8] = {0};
  1328. uint32_t can_id = 0;
  1329. if(msgidset.content1 == 3)
  1330. can_id = 0x981300;
  1331. else if(msgidset.content1 == 5)
  1332. can_id = 0xA81300;
  1333. put_date_to_can(can_buf,0x4,(msgidset.content1 & 0xff),((msgidset.content1 >> 8) & 0xff),0,0,0,0,0X7);
  1334. can_send_msg_normal(&can_buf[0], 8, can_id);
  1335. }
  1336. break;
  1337. case MSGID_SET_RAW_SWITCH:
  1338. {
  1339. uint8_t can_buf[8] = {0};
  1340. uint32_t can_id = 0;
  1341. if(msgidset.content1 == 0x11)
  1342. can_id = 0xA81300;
  1343. else if (msgidset.content1 == 0x56)
  1344. can_id = 0x981300;
  1345. put_date_to_can(can_buf,0xA,(msgidset.content2 & 0xff),((msgidset.content2 >> 8) & 0xff),0,0,0,0,0X7);
  1346. can_send_msg_normal(&can_buf[0], 8, can_id);
  1347. }
  1348. break;
  1349. case MSGID_SET_GEELY:
  1350. switch (fcu_protocol.payload[7])
  1351. {
  1352. case SET_START_OR_STOP:
  1353. if(0x1 == fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00))
  1354. {
  1355. if (geely_engin_link.connect_status == COMP_NORMAL && geely_data.engine_control == 0)
  1356. {
  1357. sendto_geely.ExtenderControl = 1;
  1358. }
  1359. start_engine = 0x80;
  1360. }
  1361. else if(0x0 == fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00))
  1362. {
  1363. if (geely_engin_link.connect_status == COMP_NORMAL && geely_data.engine_control == 1)
  1364. {
  1365. sendto_geely.ExtenderControl = 0;
  1366. }
  1367. start_engine = 0;
  1368. }
  1369. break;
  1370. case SET_PROTECT_TIME:
  1371. if (geely_engin_link.connect_status == COMP_NORMAL)
  1372. {
  1373. geely_set_tcd = true;
  1374. sendto_geely.SettingParameter = fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00);
  1375. }
  1376. break;
  1377. case SET_LOCK_TIME:
  1378. if (geely_engin_link.connect_status == COMP_NORMAL)
  1379. {
  1380. geely_set_tlock = true;
  1381. sendto_geely.SettingParameter = fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00);
  1382. }
  1383. break;
  1384. case SET_LOWVOL_PROTECT:
  1385. if(0x1 == fcu_protocol.payload[9] + ((fcu_protocol.payload[10] << 8) & 0xff00))
  1386. {
  1387. if (geely_engin_link.connect_status == COMP_NORMAL)
  1388. {
  1389. sendto_geely.ExtenderControl = 1;
  1390. geely_set_protect = true;
  1391. }
  1392. }
  1393. else
  1394. {
  1395. geely_set_protect = false;
  1396. }
  1397. break;
  1398. default:
  1399. break;
  1400. }
  1401. break;
  1402. case MSGID_SET_VOL:
  1403. set_cali_voltage = (fcu_protocol.payload[7] + 256 * fcu_protocol.payload[8]) - (int)(ADC_gather() /100.0f) ;
  1404. write_vol_information = true;
  1405. pmu_set_ack(_MSGID_SET,MSGID_SET_VOL,0,0);
  1406. break;
  1407. case MSGID_SET_MIMO_FLOW:
  1408. if(msgidset.content1 != 0)
  1409. {
  1410. if(Dev.Flow.facid == FAC_MIMO_SIG || Dev.Flow.facid == FAC_MIMO_DOU)
  1411. {
  1412. tem_32t = flow_mimo1.flow_k * msgidset.content1 / 100;
  1413. if(tem_32t >= 500 && tem_32t <= 20000)
  1414. {
  1415. flow_mimo1.flow_calk = tem_32t;
  1416. }
  1417. else{
  1418. flow_mimo1.flow_calk = 10000;
  1419. }
  1420. flow_mimo1.send_k_count = 5;
  1421. }
  1422. else if(Dev.Flow.facid == FAC_QIFEI_SIG || Dev.Flow.facid == FAC_QIFEI_DOU)
  1423. {
  1424. tem_32t = flow_inf.ch1.k * msgidset.content1 / 100;
  1425. if(tem_32t >= 500 && tem_32t <= 20000)
  1426. {
  1427. flow_inf.ch1.cal_k = tem_32t;
  1428. }
  1429. else{
  1430. flow_inf.ch1.cal_k = 10000;
  1431. }
  1432. flow_inf.ch1.set_k = true;
  1433. }
  1434. }
  1435. if(msgidset.content2 != 0)
  1436. {
  1437. if(Dev.Flow.facid == FAC_MIMO_SIG || Dev.Flow.facid == FAC_MIMO_DOU)
  1438. {
  1439. tem_32t = flow_mimo2.flow_k * msgidset.content2 / 100;
  1440. if(tem_32t >= 500 && tem_32t <= 20000)
  1441. {
  1442. flow_mimo2.flow_calk = tem_32t;
  1443. }
  1444. else{
  1445. flow_mimo2.flow_calk = 10000;
  1446. }
  1447. flow_mimo2.send_k_count = 5;
  1448. }
  1449. else if(Dev.Flow.facid == FAC_QIFEI_SIG || Dev.Flow.facid == FAC_QIFEI_DOU)
  1450. {
  1451. tem_32t = flow_inf.ch2.k * msgidset.content2 / 100;
  1452. if(tem_32t >= 500 && tem_32t <= 20000)
  1453. {
  1454. flow_inf.ch2.cal_k = tem_32t;
  1455. }
  1456. else{
  1457. flow_inf.ch2.cal_k = 10000;
  1458. }
  1459. flow_inf.ch1.set_k = true;
  1460. }
  1461. }
  1462. break;
  1463. case MSGID_SET_FLOW_BACKGROUND:
  1464. if(Dev.Flow.facid == FAC_MIMO_SIG)
  1465. {
  1466. flow_inf.ch1.clear_background = true;
  1467. }
  1468. if(Dev.Flow.facid == FAC_MIMO_DOU)
  1469. {
  1470. flow_inf.ch1.clear_background = true;
  1471. flow_inf.ch2.clear_background = true;
  1472. }
  1473. break;
  1474. case MSGID_SET_WEIGHT_K:
  1475. //calib_aux = msgidset.content1 + (msgidset.content2 << 2); //bit 0-1 编号 2-15K值
  1476. weight_order.type = Weight_Set_K;
  1477. weight_order.order_con1 = msgidset.content1;
  1478. weight_order.order_con2 = msgidset.content2;
  1479. break;
  1480. case MSGID_SET_SEED_OUT_TYPE:
  1481. recv_fmu_seed_info = true;
  1482. seed_output_mode = msgidset.content1;
  1483. pmu_set_ack(_MSGID_SET,MSGID_SET_SEED_OUT_TYPE,0,0);
  1484. break;
  1485. case MSGID_SET_SEED_CAL_TYPE:
  1486. switch (msgidset.content1)
  1487. {
  1488. case Cal_Remove_Peel:
  1489. weight_order.type = Weight_Peer;
  1490. break;
  1491. case Cal_Weight:
  1492. weight_order.type = Weight_Kg;
  1493. weight_order.order_con2 = msgidset.content2;
  1494. weight_order.order_con3 = msgidset.content3;
  1495. break;
  1496. case Cal_Seed_Back:
  1497. weight_order.type = Weight_Bcak;
  1498. break;
  1499. default:
  1500. break;
  1501. }
  1502. break;
  1503. case MSGID_SET_WEIGHT_MODE:
  1504. weight_order.type = Weight_Mode;
  1505. weight_order.order_con1 = msgidset.content1;
  1506. break;
  1507. case MSGID_SET_MAX_RATE:
  1508. weight_order.type = Weight_Drug_Rate;
  1509. weight_order.order_con1 = msgidset.content1;
  1510. break;
  1511. case MSGID_SET_PMU_SERIAL:
  1512. set_pmu_serail = msgidset.content1 + ((msgidset.content2 << 16) & 0xffff0000);
  1513. if(serial.num == PMU_SERIAL || set_pmu_serail == PMU_SERIAL)
  1514. {
  1515. write_serial_information = true;
  1516. pmu_set_ack(_MSGID_SET,MSGID_SET_PMU_SERIAL,0,0);
  1517. dev_pmu.send_times += 5;
  1518. }
  1519. else if(set_pmu_serail == serial.num)
  1520. {
  1521. pmu_set_ack(_MSGID_SET,MSGID_SET_PMU_SERIAL,0,0);
  1522. }
  1523. break;
  1524. case MSGID_SET_RADAR_FB:
  1525. {
  1526. uint8_t can_buf[8] = {0};
  1527. if(msgidset.content1 == 0x11)
  1528. {
  1529. put_date_to_can(can_buf,0x55,0XAA,0X03,0X61,0X03,0X01,0X65,0X00);
  1530. can_send_msg_normalstd(can_buf,7,0xFA);
  1531. }
  1532. else if (msgidset.content1 == 0x12)
  1533. {
  1534. put_date_to_can(can_buf,0x55,0XAA,0X03,0X61,0X03,0X02,0X66,0X00);
  1535. can_send_msg_normalstd(can_buf,7,0xFA);
  1536. }
  1537. else if(msgidset.content1 == 0x100)
  1538. {
  1539. if(msgidset.content2 == 0x11 || msgidset.content2 == 0x12)
  1540. {
  1541. put_date_to_can(can_buf,0x55,0XAA,0X03,0X61,0X00,0X03,0X64,0X00);
  1542. can_send_msg_normalstd(can_buf,7,0xFA);
  1543. }
  1544. else if(msgidset.content2 == 0x56)
  1545. {
  1546. put_date_to_can(can_buf,0x55,0XAA,0X02,0X60,0X03,0X63,0X00,0X00);
  1547. can_send_msg_normalstd(can_buf,6,0xFA);
  1548. }
  1549. }
  1550. }
  1551. break;
  1552. case MSGID_SET_LACKLOSS_CAL:
  1553. {
  1554. uint8_t can_buf[8] = {0};
  1555. if(Dev.Lackloss_Link.connect_status == COMP_NORMAL && Dev.Checklow.facid == FAC_VK)
  1556. {
  1557. put_date_to_can(can_buf,0xFA,0x03,0x00,0xB2,0XE1,0x00,0X00,0X00);
  1558. can_buf[7] = (can_buf[1]+can_buf[2]+can_buf[3]+can_buf[4]+can_buf[5]+can_buf[6]) & 0xff;
  1559. can_send_msg_normalstd(can_buf,8,0xFA);
  1560. }
  1561. else if(Dev.Lackloss_Link.connect_status == COMP_NORMAL && Dev.Checklow.facid == FAC_DM_CHECKLOW)
  1562. {
  1563. if(HAL_GetTick()-DMJZ >= 6000)
  1564. {
  1565. put_date_to_can(can_buf,0x01,0x00,0x00,0x00,0X00,0x00,0X00,0X00);
  1566. can_send_msg_normal(can_buf,8,0x18F2AD0A);
  1567. DMJZ = HAL_GetTick();
  1568. }
  1569. }
  1570. }
  1571. break;
  1572. case MSGID_SET_PUMP_ID:
  1573. set_HWesc_ESCid = true;
  1574. setESCidInfo.setESCidNum = 1;
  1575. setESCidInfo.setESCidStep = SETESCID_INIT;
  1576. pmu_set_ack(_MSGID_SET,MSGID_SET_PUMP_ID,0,2);
  1577. break;
  1578. case MSGID_SET_RESIWIRE_BLOWN:
  1579. {
  1580. uint8_t can_buf[8] = {0};
  1581. put_date_to_can(can_buf,0xF7,fcu_protocol.payload[7],0x00,0x00,0x00,0xF1,0XF3,0X00);
  1582. can_send_msg_normal(&can_buf[0], 8, 0x88BB);
  1583. }
  1584. break;
  1585. case MSGID_SET_FRADAR_SN:
  1586. {
  1587. int radar_Sn = 0;
  1588. uint8_t can_buf[8] = {0};
  1589. radar_Sn = msgidset.content1 + (msgidset.content2 << 16);
  1590. can_buf[0] = 2;
  1591. memcpy(&can_buf[1],&radar_Sn,4);
  1592. can_buf[7] = 7;
  1593. can_send_msg_normal(can_buf,8,0xA81300);
  1594. DM_f_info.get_radar_ver_flag = false;
  1595. dev_obsf.regist.sn = false;
  1596. pmu_set_ack(_MSGID_SET,MSGID_SET_FRADAR_SN,msgidset.content1,msgidset.content2);
  1597. }
  1598. break;
  1599. case MSGID_SET_BRADAR_SN:
  1600. {
  1601. int radar_Sn = 0;
  1602. uint8_t can_buf[8] = {0};
  1603. radar_Sn = msgidset.content1 + (msgidset.content2 << 16);
  1604. can_buf[0] = 2;
  1605. memcpy(&can_buf[1],&radar_Sn,4);
  1606. can_buf[7] = 7;
  1607. can_send_msg_normal(can_buf,8,0xB81300);
  1608. dev_obsb.regist.sn = false;
  1609. //DM_b_info.get_radar_ver_flag = false;
  1610. pmu_set_ack(_MSGID_SET,MSGID_SET_BRADAR_SN,msgidset.content1,msgidset.content2);
  1611. }
  1612. break;
  1613. case MSGID_SET_TRADAR_SN:
  1614. {
  1615. int radar_Sn = 0;
  1616. uint8_t can_buf[8] = {0};
  1617. radar_Sn = msgidset.content1 + (msgidset.content2 << 16);
  1618. can_buf[0] = 2;
  1619. memcpy(&can_buf[1],&radar_Sn,4);
  1620. can_buf[7] = 7;
  1621. can_send_msg_normal(can_buf,8,0x981300);
  1622. DM_ter_info.get_radar_ver_flag = false;
  1623. dev_ter.regist.sn = false; //重新获取sn
  1624. pmu_set_ack(_MSGID_SET,MSGID_SET_TRADAR_SN,msgidset.content1,msgidset.content2);
  1625. }
  1626. break;
  1627. default:
  1628. break;
  1629. }
  1630. break;
  1631. case _MSGID_HEART:
  1632. time_heart[1] = HAL_GetTick();
  1633. time_count[1]++;
  1634. pmu_heart_flag = true;
  1635. break;
  1636. case _MSGID_SHA1:
  1637. //智能电池秘钥
  1638. if(fcu_protocol.payload[6] == 1)
  1639. {
  1640. //有秘钥
  1641. if(fcu_protocol.payload[7] == 2 && fcu_protocol.payload[8] == 1)
  1642. {
  1643. if(start_msg.key_info_checking == true)
  1644. {
  1645. memcpy(&start_msg.key_data[0],&fcu_protocol.payload[9],20);
  1646. start_msg.key_to_bms = true;//给电池发送秘钥
  1647. start_msg.key_info_checking = false;
  1648. }
  1649. }
  1650. //无秘钥
  1651. else if(fcu_protocol.payload[7] == 2 && fcu_protocol.payload[8] == 2)
  1652. {
  1653. start_msg.key_info_checking = false;
  1654. }
  1655. //回馈,防止PMU一直发
  1656. else if(fcu_protocol.payload[7] == 3 || fcu_protocol.payload[7] == 4)
  1657. {
  1658. start_msg.key_info_checking = false;
  1659. }
  1660. }
  1661. break;
  1662. //升级固件标志
  1663. case _MSGID_UPDATA:
  1664. {
  1665. __disable_irq();
  1666. HAL_FLASH_Unlock();
  1667. __HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP | FLASH_FLAG_WRPERR | FLASH_FLAG_PGERR);
  1668. f.TypeErase = FLASH_TYPEERASE_PAGES;
  1669. f.PageAddress = UPDATE_FLAG;
  1670. f.NbPages = 1;
  1671. uint32_t PageError = 0;
  1672. HAL_FLASHEx_Erase(&f, &PageError);
  1673. uint16_t TempBuf = 0x01;
  1674. HAL_FLASH_Program(FLASH_TYPEPROGRAM_HALFWORD, UPDATE_FLAG, TempBuf);
  1675. HAL_FLASH_Lock();
  1676. __enable_irq();
  1677. HAL_NVIC_DisableIRQ(USART2_IRQn);
  1678. HAL_Delay(100);
  1679. //软件复位
  1680. HAL_NVIC_SystemReset();
  1681. }
  1682. break;
  1683. default:
  1684. break;
  1685. }
  1686. uart_info.fcu_buf_flag = false;
  1687. memset(fcu_protocol.payload, 0, 256);
  1688. }
  1689. }
  1690. /******************void pmu_start_info()*******************
  1691. * ****************上电时PMU发送的信息*******************************
  1692. * ****************************************************************/
  1693. Start_info start_msg = {.key_info_checking = true,
  1694. .Dev_type = 1,
  1695. .Id = 1,
  1696. };
  1697. void pmu_start_info()
  1698. {
  1699. static uint32_t circu_time_2hz = 0;
  1700. if(Check_Timer_Ready(&circu_time_2hz,_2_HZ_))
  1701. {
  1702. if(HAL_GetTick() > 10000 && start_msg.version_info == false)
  1703. {
  1704. pmu_send = PMU_SEND_VERSION;
  1705. start_msg.version_info = true;
  1706. }
  1707. else if (start_msg.key_info_checking == true && Device1.Vkbms_Link.connect_status == COMP_NORMAL)
  1708. {
  1709. pmu_send = PMU_SEND_SHA1;
  1710. }
  1711. }
  1712. }