main_task.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015
  1. #include "main_task.h"
  2. #include "soft_led.h"
  3. #include "stdio.h"
  4. #include "stdbool.h"
  5. #include "string.h"
  6. #include "main.h"
  7. #include "soft_usart.h"
  8. #include "usart_data_handle.h"
  9. #include "soft_flash.h"
  10. #include "soft_crc.h"
  11. #include "soft_radar_handle.h"
  12. #include "soft_engine.h"
  13. #include "soft_device.h"
  14. #include "soft_timer.h"
  15. #include "config.h"
  16. #include "soft_can.h"
  17. #include "soft_bms.h"
  18. #include "soft_adc.h"
  19. #include "soft_version.h"
  20. #include "soft_update.h"
  21. #include "soft_obstacle.h"
  22. #include "soft_water.h"
  23. #include "soft_terrain.h"
  24. //#include "can_debug.h"
  25. uint8_t msg_buf[256] = {0};
  26. bool terrain_is_link = false;
  27. bool obs_f_is_link = false;
  28. bool obs_b_is_link = false;
  29. /**
  30. * @file Update_ack_func
  31. * @brief PMU回复ACK 回复升级工具
  32. * @param 组件ID,消息ID,ACK数据
  33. * @details 升级应答FMU透传,协议和升级工具一致,和FMU不一样
  34. * @author Zhang Sir
  35. **/
  36. void Update_ack_func(uint8_t group_id, uint8_t msg_id, uint8_t *ackbuf)
  37. {
  38. int index = 0;
  39. msg_buf[index++] = 0xFE;
  40. msg_buf[index++] = 0;
  41. msg_buf[index++] = 0;
  42. msg_buf[index++] = 0x00;
  43. msg_buf[index++] = group_id;
  44. msg_buf[index++] = _MSGID_ACK;
  45. msg_buf[index++] = msg_id;
  46. msg_buf[index++] = *ackbuf;
  47. msg_buf[index++] = *(ackbuf + 1);
  48. msg_buf[index++] = 1;
  49. msg_buf[1] = index - 6;
  50. uint16_t uart_crc = Get_Crc16(msg_buf, index);
  51. memcpy(&msg_buf[index], &uart_crc, 2);
  52. index += 2;
  53. usart1_send_msg(msg_buf, index);
  54. }
  55. /**
  56. * @file pmu_set_ack
  57. * @brief PMU应答FMU
  58. * @param 命令 命令内容 123
  59. * @details
  60. * @author Zhang Sir
  61. **/
  62. char ack_id = 0;
  63. short ack_content = 0;
  64. short ack_content1 = 0;
  65. short ack_content2 = 0;
  66. void pmu_set_ack(uint8_t id,short content1, short content2,short content3)
  67. {
  68. pmu_send = PMU_SEND_ACK;
  69. ack_id = id;
  70. ack_content = content1;
  71. ack_content1 = content2;
  72. ack_content2 = content3;
  73. }
  74. /**
  75. * @file pmu_to_con_voltage_data
  76. * @brief PMU发送电压、温度信息
  77. * @param none
  78. * @details
  79. * @author Zhang Sir
  80. **/
  81. void pmu_to_con_voltage_data()
  82. {
  83. int index = 0;
  84. uint16_t temp_16t = 0;
  85. msg_buf[index++] = 0xFE;
  86. msg_buf[index++] = 0;
  87. msg_buf[index++] = 0; //组件计数
  88. msg_buf[index++] = 0x00;
  89. msg_buf[index++] = 0x00;
  90. msg_buf[index++] = _MSGID_VOL;
  91. temp_16t = Adc_Get(ADC_Bms) / 10.0f + cur_par.voltage * 10; // 获取当前板子电压
  92. memcpy(&msg_buf[index], &temp_16t, 2);
  93. index += 2;
  94. temp_16t = Adc_Get(ADC_Tempture);
  95. memcpy(&msg_buf[index], &temp_16t, 2);
  96. index += 2;
  97. msg_buf[index++] = 0;
  98. msg_buf[index++] = 0;
  99. temp_16t = (uint16_t)stor_par.abnormal_outage_flag;
  100. memcpy(&msg_buf[index], &temp_16t, 2);
  101. index += 2;
  102. msg_buf[1] = index - 6;
  103. uint16_t crc = Get_Crc16(msg_buf, index);
  104. msg_buf[index++] = crc;
  105. msg_buf[index++] = (crc >> 8) & 0xff;
  106. usart1_send_msg(msg_buf, index);
  107. }
  108. /**
  109. * @file pmu_to_con_heart_data
  110. * @brief PMU_发送心跳
  111. * @param none
  112. * @details
  113. * @author Zhang Sir
  114. **/
  115. void pmu_to_con_heart_data()
  116. {
  117. int index = 0;
  118. msg_buf[index++] = 0xFE;
  119. msg_buf[index++] = 0;
  120. msg_buf[index++] = 0;
  121. msg_buf[index++] = 0x00;
  122. msg_buf[index++] = 0x00;
  123. msg_buf[index++] = 21;
  124. msg_buf[index++] = _MSGID_HEART;
  125. ack_content = 0x56;
  126. memcpy(&msg_buf[index],&ack_content,2);
  127. index += 2;
  128. memcpy(&msg_buf[index],&ack_content1,2);
  129. index += 2;
  130. memcpy(&msg_buf[index],&ack_content2,2);
  131. index += 2;
  132. msg_buf[1] = index - 6;
  133. uint16_t crc = Get_Crc16(msg_buf, index);
  134. memcpy(&msg_buf[index], &crc, 2);
  135. index += 2;
  136. usart1_send_msg(msg_buf, index);
  137. }
  138. /**
  139. * @file pmu_to_con_engin_data
  140. * @brief PMU发送发动机信息
  141. * @param none
  142. * @details
  143. * @author Zhang Sir
  144. **/
  145. void pmu_to_con_engine_data(void)
  146. {
  147. uint8_t index = 0;
  148. if(engine_link_status == COMP_NORMAL)
  149. {
  150. msg_buf[index++] = 0xFE;
  151. msg_buf[index++] = 0;
  152. msg_buf[index++] = 0; //组件计数
  153. msg_buf[index++] = 0x00;
  154. msg_buf[index++] = 0x00;
  155. msg_buf[index++] = _MSG_ENGIN;
  156. memcpy(&msg_buf[index],&engine_data.engine_type,sizeof(engine_data));
  157. index += (sizeof(engine_data));
  158. msg_buf[1] = index - 6;
  159. uint16_t crc = Get_Crc16(msg_buf, index);
  160. msg_buf[index++] = crc;
  161. msg_buf[index++] = (crc >> 8) & 0xff;
  162. usart1_send_msg(msg_buf, index);
  163. }
  164. }
  165. /**
  166. * @file pmu_to_con_devtype_data
  167. * @brief PMU发送播撒、称重、水泵、离心喷头、在位传感器信息
  168. * @param none
  169. * @details
  170. * @author Zhang Sir
  171. **/
  172. void check_and_put_msg(uint8_t *buf, uint16_t len)
  173. {
  174. buf[1] = len - 6;
  175. uint16_t crc = Get_Crc16(buf, len);
  176. msg_buf[len++] = crc;
  177. msg_buf[len++] = (crc >> 8) & 0xff;
  178. usart1_send_msg(msg_buf, len);
  179. }
  180. void pmu_to_con_devtype_data(void)
  181. {
  182. uint16_t index = 0;
  183. msg_buf[index++] = 0xFE;
  184. msg_buf[index++] = 0;
  185. msg_buf[index++] = 0; //组件计数
  186. msg_buf[index++] = 0x00;
  187. msg_buf[index++] = 0x00;
  188. msg_buf[index++] = _MSGID_DEV_INFO;
  189. if(send_devinfo_time.flow == true)
  190. {
  191. msg_buf[index++] = DEV_FLOW;
  192. memcpy(&msg_buf[index],&Dev.Flow.facid,sizeof(Flow_info));
  193. index += sizeof(Flow_info);
  194. check_and_put_msg(msg_buf, index);
  195. index = 6;
  196. send_devinfo_time.flow = false;
  197. }
  198. if (send_devinfo_time.radar == true)
  199. {
  200. msg_buf[index++] = DEV_RADAR;
  201. memcpy(&msg_buf[index],&Dev.Radar.facid_T,sizeof(Radar_info));
  202. index += sizeof(Radar_info);
  203. check_and_put_msg(msg_buf, index);
  204. index = 6;
  205. send_devinfo_time.radar = false;
  206. }
  207. if(send_devinfo_time.checklow == true)
  208. {
  209. msg_buf[index++] = DEV_CHECKLOW;
  210. memcpy(&msg_buf[index],&Dev.Checklow.facid,sizeof(CheckLow_info));
  211. index += sizeof(CheckLow_info);
  212. check_and_put_msg(msg_buf, index);
  213. index = 6;
  214. send_devinfo_time.checklow = false;
  215. }
  216. if(Dev.L_pump1_Link.connect_status == COMP_NORMAL && send_devinfo_time.L_pump1 == true)
  217. {
  218. msg_buf[index++] = DEV_L_PUMP1;
  219. memcpy(&msg_buf[index],&Dev.L_pump1.facid,sizeof(Linear_pump_info));
  220. index += sizeof(Linear_pump_info);
  221. check_and_put_msg(msg_buf, index);
  222. index = 6;
  223. send_devinfo_time.L_pump1 = false;
  224. }
  225. if(Dev.L_pump2_Link.connect_status == COMP_NORMAL && send_devinfo_time.L_pump2 == true)
  226. {
  227. msg_buf[index++] = DEV_L_PUMP2;
  228. memcpy(&msg_buf[index],&Dev.L_pump2.facid,sizeof(Linear_pump_info));
  229. index += sizeof(Linear_pump_info);
  230. check_and_put_msg(msg_buf, index);
  231. index = 6;
  232. send_devinfo_time.L_pump2 = false;
  233. }
  234. if(Dev.Weight_Link.connect_status == COMP_NORMAL && send_devinfo_time.weight == true)
  235. {
  236. msg_buf[index++] = DEV_WEIGHT;
  237. memcpy(&msg_buf[index],&Dev.Weight.facid,sizeof(Weight_info));
  238. index += sizeof(Weight_info);
  239. check_and_put_msg(msg_buf, index);
  240. index = 6;
  241. send_devinfo_time.weight = false;
  242. }
  243. if(Dev.Part_Tradar_Link.connect_status == COMP_NORMAL && send_devinfo_time.part_radar == true)
  244. {
  245. msg_buf[index++] = DEV_PART_RADAR;
  246. memcpy(&msg_buf[index],&Dev.Part_radarT.facid,sizeof(Part_Tradar));
  247. index += sizeof(Part_Tradar);
  248. check_and_put_msg(msg_buf, index);
  249. index = 6;
  250. send_devinfo_time.part_radar = false;
  251. }
  252. if ((Dev.Part_Fradar_Link.connect_status == COMP_NORMAL || Dev.DM_Part_Fradar_Link.connect_status == COMP_NORMAL) && send_devinfo_time.part_Fradar == true)
  253. {
  254. if (Dev.Part_Fradar_Link.connect_status == COMP_NORMAL)
  255. {
  256. msg_buf[index++] = DEV_PART_FRADAR;
  257. memcpy(&msg_buf[index], &Dev.Part_radarF.facid, sizeof(Part_FBradar));
  258. index += sizeof(Part_FBradar);
  259. check_and_put_msg(msg_buf, index);
  260. index = 6;
  261. send_devinfo_time.part_Fradar = false;
  262. }
  263. else if (Dev.DM_Part_Fradar_Link.connect_status == COMP_NORMAL)
  264. {
  265. msg_buf[index++] = DEV_PART_FRADAR;
  266. memcpy(&msg_buf[index], &Dev.DM_Part_radarF.facid, sizeof(Part_Fradar));
  267. index += sizeof(Part_Fradar);
  268. check_and_put_msg(msg_buf, index);
  269. index = 6;
  270. send_devinfo_time.part_Fradar = false;
  271. }
  272. }
  273. if((Dev.Part_Bradar_Link.connect_status == COMP_NORMAL || Dev.DM_Part_Bradar_Link.connect_status == COMP_NORMAL) && send_devinfo_time.part_Bradar == true)
  274. {
  275. if (Dev.Part_Bradar_Link.connect_status == COMP_NORMAL)
  276. {
  277. msg_buf[index++] = DEV_PART_BRADAR;
  278. memcpy(&msg_buf[index], &Dev.Part_radarB.facid, sizeof(Part_FBradar));
  279. index += sizeof(Part_FBradar);
  280. check_and_put_msg(msg_buf, index);
  281. index = 6;
  282. send_devinfo_time.part_Bradar = false;
  283. }
  284. else if (Dev.DM_Part_Bradar_Link.connect_status == COMP_NORMAL)
  285. {
  286. msg_buf[index++] = DEV_PART_BRADAR;
  287. memcpy(&msg_buf[index], &Dev.DM_Part_radarB.facid, sizeof(Part_Fradar));
  288. index += sizeof(Part_Fradar);
  289. check_and_put_msg(msg_buf, index);
  290. index = 6;
  291. send_devinfo_time.part_Bradar = false;
  292. }
  293. }
  294. if(Dev.Bms_Link.connect_status == COMP_NORMAL && send_devinfo_time.bms == true)
  295. {
  296. msg_buf[index++] = DEV_BMS;
  297. memcpy(&msg_buf[index],&Dev.Bms.facid,Dev.Bms.index + 1);
  298. index += Dev.Bms.index + 1;
  299. check_and_put_msg(msg_buf, index);
  300. index = 6;
  301. send_devinfo_time.bms = false;
  302. }
  303. if(Dev.Seed_Link.connect_status == COMP_NORMAL && send_devinfo_time.seed == true)
  304. {
  305. msg_buf[index++] = DEV_SEED;
  306. memcpy(&msg_buf[index],&Dev.Seed.facid,sizeof(Seed_info));
  307. index += sizeof(Seed_info);
  308. check_and_put_msg(msg_buf, index);
  309. index = 6;
  310. send_devinfo_time.seed = false;
  311. }
  312. if (Dev.Pump_Link.connect_status == COMP_NORMAL && send_devinfo_time.pump == true)
  313. {
  314. msg_buf[index++] = DEV_PUMP;
  315. memcpy(&msg_buf[index],&Dev.Pump.facid,sizeof(Pump_info));
  316. index += sizeof(Pump_info);
  317. check_and_put_msg(msg_buf, index);
  318. index = 6;
  319. send_devinfo_time.pump = false;
  320. }
  321. if (Dev.Nozzle_Link.connect_status == COMP_NORMAL && send_devinfo_time.nozzle == true)
  322. {
  323. msg_buf[index++] = DEV_NOZZLE;
  324. memcpy(&msg_buf[index],&Dev.Nozzle.facid,sizeof(Nozzle_info));
  325. index += sizeof(Nozzle_info);
  326. check_and_put_msg(msg_buf, index);
  327. index = 6;
  328. send_devinfo_time.nozzle = false;
  329. }
  330. if (Dev.Arm_Link.connect_status == COMP_NORMAL && send_devinfo_time.arm == true)
  331. {
  332. msg_buf[index++] = DEV_ARM;
  333. memcpy(&msg_buf[index],&Dev.Arm.facid,sizeof(Arm_info));
  334. index += sizeof(Arm_info);
  335. check_and_put_msg(msg_buf, index);
  336. index = 6;
  337. send_devinfo_time.arm = false;
  338. }
  339. if(Dev.Temperature_Sensor_Link.connect_status == COMP_NORMAL && send_devinfo_time.temperature == true)
  340. {
  341. msg_buf[index++] = DEV_TEMP_SENSOR;
  342. memcpy(&msg_buf[index],&Dev.Temperature_Sensor.facid,sizeof(Temperature_Sensor_info));
  343. index += sizeof(Temperature_Sensor_info);
  344. check_and_put_msg(msg_buf, index);
  345. index = 6;
  346. send_devinfo_time.temperature = false;
  347. }
  348. // else if(Dev.L_pump2_Link.connect_status == COMP_NORMAL && send_devinfo_time.L_pump2 == true)
  349. // {
  350. // msg_buf[index++] = DEV_L_PUMP2;
  351. // memcpy(&msg_buf[index],&Dev.L_pump2.facid,sizeof(Linear_pump_info));
  352. // index += sizeof(Linear_pump_info);
  353. // send_devinfo_time.L_pump2 = false;
  354. // }
  355. // msg_buf[1] = index - 6;
  356. // uint16_t crc = Get_Crc16(msg_buf, index);
  357. // msg_buf[index++] = crc;
  358. // msg_buf[index++] = (crc >> 8) & 0xff;
  359. // usart1_send_msg(msg_buf, index);
  360. }
  361. /**
  362. * @file pmu_to_con_version_data
  363. * @brief PMU发送版本信息
  364. * @param none
  365. * @details
  366. * @author Zhang Sir
  367. **/
  368. void pmu_to_con_version_data()
  369. {
  370. //版本信息 0 - 5 硬件版本 IAP版本 APP版本
  371. uint32_t ver_msg_buf[4] = {0};
  372. int index = 0;
  373. ver_msg_buf[0] = cur_par.pmu_serial; //硬件版本号
  374. ver_msg_buf[1] = IAP_VERSION; //IAP版本号
  375. ver_msg_buf[2] = APP_VERSION; //APP版本号
  376. ver_msg_buf[3] = cur_par.pmu_serial;//serial.num;
  377. msg_buf[index++] = 0xFE;
  378. msg_buf[index++] = 0;
  379. msg_buf[index++] = 0;
  380. msg_buf[index++] = 0x00;
  381. msg_buf[index++] = 0x00;
  382. msg_buf[index++] = MSGID_REQ_VERSION;
  383. radar_version_check();
  384. memcpy(&msg_buf[index], ver_msg_buf, 16);
  385. index += 16;
  386. memcpy(&msg_buf[index], &radar_version[0][0], 10);
  387. index += 10;
  388. memcpy(&msg_buf[index], &radar_version[1][0], 10);
  389. index += 10;
  390. memcpy(&msg_buf[index], &radar_version[2][0], 10);
  391. index += 10;
  392. msg_buf[1] = index - 6;
  393. uint16_t crc = Get_Crc16(msg_buf, index);
  394. memcpy(&msg_buf[index], &crc, 2);
  395. index += 2;
  396. usart1_send_msg(msg_buf, index);
  397. }
  398. /**
  399. * @file pmu_to_fcu_version_data
  400. * @brief 版本信息发送,新协议还没用
  401. * @param none
  402. * @details
  403. * @author Zhang Sir
  404. **/
  405. void pmu_to_fcu_version_data()
  406. {
  407. //short dev_num = 40;
  408. uint8_t i = 0;
  409. dev_version_content *ptr = NULL;
  410. for(i = 0;i < dev_num;i++)
  411. {
  412. ptr = dev_ptr[i];
  413. if(ptr->send_times > 0)
  414. {
  415. break;
  416. }
  417. if(i == dev_num - 1)
  418. {
  419. return;
  420. }
  421. }
  422. uint8_t index = 0;
  423. msg_buf[index++] = 0xFE;
  424. msg_buf[index++] = 0;
  425. msg_buf[index++] = 0;
  426. msg_buf[index++] = 0x00;
  427. msg_buf[index++] = 0x00;
  428. msg_buf[index++] = _MSGID_DEV_LIST;
  429. memcpy(&msg_buf[index],&ptr->num,sizeof(dev_version_content) - sizeof(regist_type) - 1);
  430. index += sizeof(dev_version_content) - sizeof(regist_type) - 1;
  431. msg_buf[1] = index - 6;
  432. uint16_t crc = Get_Crc16(msg_buf, index);
  433. memcpy(&msg_buf[index], &crc, 2);
  434. index += 2;
  435. usart1_send_msg(msg_buf, index);
  436. }
  437. /**
  438. * @file pmu_to_fcu_key_data
  439. * @brief PMU发送秘钥信息
  440. * @param none
  441. * @details 格式电池秘钥匹配
  442. * @author Zhang Sir
  443. **/
  444. void pmu_to_fcu_key_data(void)
  445. {
  446. uint8_t index = 0;
  447. msg_buf[index++] = 0xFE;
  448. msg_buf[index++] = 0;
  449. msg_buf[index++] = 0;
  450. msg_buf[index++] = 0x00;
  451. msg_buf[index++] = 0x00;
  452. msg_buf[index++] = _MSGID_SHA1;
  453. msg_buf[index++] = start_msg.Dev_type;
  454. msg_buf[index++] = start_msg.Id;
  455. msg_buf[index++] = start_msg.Id_content;
  456. // if(start_msg.Id == 4)
  457. // {
  458. // start_msg.key_info_checking = false; //发送状态后结束发送
  459. // }
  460. memcpy(&msg_buf[index],&start_msg.key_data[0],20);
  461. index += 20;
  462. msg_buf[1] = index - 6;
  463. uint16_t crc = Get_Crc16(msg_buf, index);
  464. memcpy(&msg_buf[index], &crc, 2);
  465. index += 2;
  466. usart1_send_msg(msg_buf, index);
  467. }
  468. /**
  469. * @file pmu_to_con_request_data
  470. * @brief PMU发送请求信息
  471. * @param none
  472. * @details
  473. * @author Zhang Sir
  474. **/
  475. char request_id = 0;
  476. short request_1_content = 0;
  477. int request_2_content = 0;
  478. void pmu_to_con_request_data()
  479. {
  480. int index = 0;
  481. msg_buf[index++] = 0xFE;
  482. msg_buf[index++] = 0;
  483. msg_buf[index++] = 0;
  484. msg_buf[index++] = 0x00;
  485. msg_buf[index++] = 0x00;
  486. msg_buf[index++] = 20;
  487. msg_buf[index++] = request_id;
  488. memcpy(&msg_buf[index],&request_1_content,2);
  489. index += 2;
  490. memcpy(&msg_buf[index],&request_2_content,4);
  491. index += 4;
  492. msg_buf[1] = index - 6;
  493. uint16_t crc = Get_Crc16(msg_buf, index);
  494. memcpy(&msg_buf[index], &crc, 2);
  495. index += 2;
  496. usart1_send_msg(msg_buf, index);
  497. }
  498. /**
  499. * @file pmu_to_con_radar360_data
  500. * @brief PMU发送360信息
  501. * @param none
  502. * @details
  503. * @author Zhang Sir
  504. **/
  505. void pmu_to_con_radar360_data(void)
  506. {
  507. uint8_t index = 0;
  508. uint32_t send_byte = 0;
  509. uint16_t crc = 0;
  510. if(mimo_360_info.connect_status == COMP_NORMAL)
  511. {
  512. msg_buf[index++] = 0xFE;
  513. msg_buf[index++] = 0;
  514. msg_buf[index++] = 0;
  515. msg_buf[index++] = 0x00;
  516. msg_buf[index++] = 0x00;
  517. msg_buf[index++] = _MSGID_360RADAR;
  518. radar360_proflag = 1;
  519. send_byte = sizeof(mimo_360_data) * fmu_360info.total_tar + 2;
  520. memcpy(&msg_buf[index],&fmu_360info,send_byte);
  521. index += send_byte;
  522. radar360_proflag = 0;
  523. msg_buf[1] = index - 6;
  524. crc = Get_Crc16(msg_buf, index);
  525. msg_buf[index++] = crc;
  526. msg_buf[index++] = (crc >> 8) & 0xff;
  527. usart1_send_msg(msg_buf, index);
  528. }
  529. }
  530. /**
  531. * @file pmu_to_con_request_data
  532. * @brief PMU发送应答信息
  533. * @param none
  534. * @details
  535. * @author Zhang Sir
  536. **/
  537. void pmu_to_con_ack_data()
  538. {
  539. int index = 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++] = ack_id;
  547. memcpy(&msg_buf[index],&ack_content,2);
  548. index += 2;
  549. memcpy(&msg_buf[index],&ack_content1,2);
  550. index += 2;
  551. memcpy(&msg_buf[index],&ack_content2,2);
  552. index += 2;
  553. msg_buf[1] = index - 6;
  554. uint16_t crc = Get_Crc16(msg_buf, index);
  555. memcpy(&msg_buf[index], &crc, 2);
  556. index += 2;
  557. usart1_send_msg(msg_buf, index);
  558. }
  559. //4D雷达回复fmu
  560. void pmu_to_con_DM4DBradar_msg(void)
  561. {
  562. uint8_t index = 0;
  563. msg_buf[index++] = 0xFE;
  564. msg_buf[index++] = 0;
  565. msg_buf[index++] = 0;
  566. msg_buf[index++] = 0x00;
  567. msg_buf[index++] = 0x00;
  568. msg_buf[index++] = _MSGID_GET4D;
  569. msg_buf[index++] = 'V';
  570. msg_buf[index++] = 'K';
  571. msg_buf[index++] = 'Z';
  572. msg_buf[index++] = '1';
  573. memcpy(&msg_buf[index],&DM_4DRADARMAG.angel_4DF,18);
  574. index += 18;
  575. msg_buf[1] = index - 6;
  576. uint16_t crc = Get_Crc16(msg_buf, index);
  577. msg_buf[index++] = crc;
  578. msg_buf[index++] = (crc >> 8) & 0xff;
  579. usart1_send_msg(msg_buf, index);
  580. }
  581. //4D仿地雷达分段高度
  582. void pmu_to_con_DM4DTradar_data(void)
  583. {
  584. uint8_t index = 0;
  585. msg_buf[index++] = 0xFE;
  586. msg_buf[index++] = 0;
  587. msg_buf[index++] = 0;
  588. msg_buf[index++] = 0x00;
  589. msg_buf[index++] = 0x00;
  590. msg_buf[index++] = _MSGID_FT4DRADAR;
  591. DM4dt_recv_flag = 1;
  592. memcpy(&msg_buf[index], &D4T_tofmu.target_num, 1);
  593. index += 1;
  594. memcpy(&msg_buf[index], &D4T_tofmu.time_delay, 2);
  595. index += 2;
  596. memcpy(&msg_buf[index], &D4T_tofmu.err_num, 2);
  597. index += 2;
  598. memcpy(&msg_buf[index], &D4T_tofmu.RawData, D4T_tofmu.target_num * 2);
  599. index += D4T_tofmu.target_num * 2;
  600. msg_buf[1] = index - 6;
  601. uint16_t crc = Get_Crc16(msg_buf, index);
  602. msg_buf[index++] = crc;
  603. msg_buf[index++] = (crc >> 8) & 0xff;
  604. usart1_send_msg(msg_buf, index);
  605. DM4dt_recv_flag = 0;
  606. }
  607. void pmu_to_con_DM4DBTradar_data(void)
  608. {
  609. uint8_t index = 0;
  610. msg_buf[index++] = 0xFE;
  611. msg_buf[index++] = 0;
  612. msg_buf[index++] = 0;
  613. msg_buf[index++] = 0x00;
  614. msg_buf[index++] = 0x00;
  615. msg_buf[index++] = _MSGID_BT4DRADAR;
  616. DM4dbt_recv_flag = 1;
  617. memcpy(&msg_buf[index], &D4BT_tofmu.target_num, 1);
  618. index += 1;
  619. memcpy(&msg_buf[index], &D4BT_tofmu.time_delay, 2);
  620. index += 2;
  621. memcpy(&msg_buf[index], &D4BT_tofmu.err_num, 2);
  622. index += 2;
  623. memcpy(&msg_buf[index], &D4BT_tofmu.RawData, D4BT_tofmu.target_num * 2);
  624. index += D4BT_tofmu.target_num * 2;
  625. msg_buf[1] = index - 6;
  626. uint16_t crc = Get_Crc16(msg_buf, index);
  627. msg_buf[index++] = crc;
  628. msg_buf[index++] = (crc >> 8) & 0xff;
  629. usart1_send_msg(msg_buf, index);
  630. DM4dbt_recv_flag = 0;
  631. }
  632. /**
  633. * @file Can_send_debug_to_app
  634. * @brief can模拟
  635. * @param none
  636. * @details UART2
  637. * @author Zhang Sir
  638. **/
  639. /*
  640. void Can_send_debug_to_app(void)
  641. {
  642. int index = 0;
  643. uint16_t crc = 0;
  644. uint8_t send_time = debug_can.Total_Dev_num / 16 + 1;
  645. uint8_t element_num = 0,total_pack_num = 0;
  646. check_can_dev_connect();
  647. for(uint8_t i = 0;i < send_time; i++)
  648. {
  649. index = 0;
  650. crc = 0;
  651. msg_buf[index++] = 0xFE;
  652. msg_buf[index++] = 0;
  653. msg_buf[index++] = 0; //组件计数
  654. msg_buf[index++] = 0x00;
  655. msg_buf[index++] = 0x00;
  656. msg_buf[index++] = _MSGID_CANDEBUG;
  657. debug_can.Len = get_data_total_len;
  658. if(send_time > 1)
  659. {
  660. element_num = i * 15;
  661. total_pack_num = (send_time - 1 - i) == 0? debug_can.Total_Dev_num - (i *15) : 15;
  662. }
  663. else
  664. {
  665. element_num = 0;
  666. total_pack_num = debug_can.Total_Dev_num;
  667. }
  668. msg_buf[index++] = total_pack_num;
  669. for(uint8_t i=0;i<total_pack_num;i++)
  670. {
  671. memcpy(&msg_buf[index], &debug_can.ID_buf[i + element_num].ID, debug_can.Len(debug_can.ID_buf[i + element_num].len));
  672. index += debug_can.Len(debug_can.ID_buf[i + element_num].len);
  673. }
  674. msg_buf[1] = index - 6;
  675. crc = Get_Crc16(msg_buf, index);
  676. msg_buf[index++] = crc;
  677. msg_buf[index++] = (crc >> 8) & 0xff;
  678. usart1_send_msg(msg_buf, index);
  679. //uart3_send_msg(msg_buf, index);
  680. if(send_time > 1)
  681. {
  682. HAL_Delay(50);
  683. }
  684. }
  685. }
  686. */
  687. uint32_t DM4d_to_fmu10s_flag = 0;
  688. /**
  689. * @file pmu_to_fcu
  690. * @brief PMU发送信息给FMU
  691. * @param none
  692. * @details UART2
  693. * @author Zhang Sir
  694. **/
  695. uint8_t pmu_send = PMU_SEND_YAOCE;
  696. void pmu_to_fcu()
  697. {
  698. //串口阻塞 和雷达升级不发送
  699. if(update_info.vk_dev_update_flag != true && EZup_par.update_flag != true)
  700. {
  701. switch (pmu_send)
  702. {
  703. case PMU_SEND_YAOCE:
  704. //心跳包单独发
  705. if(pmu_heart_flag == true)
  706. {
  707. pmu_to_con_heart_data();
  708. pmu_heart_flag = false;
  709. }
  710. //发送电压信息
  711. else if (vol_flag == true)
  712. {
  713. pmu_to_con_voltage_data();
  714. vol_flag = false;
  715. }
  716. // //发动机信息
  717. // else if (engine_flag == true)
  718. // {
  719. // pmu_to_con_engine_data();
  720. // engine_flag = false;
  721. // }
  722. // //mimo360测试
  723. // else if (mimo360_radar_flag == true)
  724. // {
  725. // pmu_to_con_radar360_data();
  726. // mimo360_radar_flag = false;
  727. // }
  728. else if(devtype_flag == true)
  729. {
  730. pmu_to_con_devtype_data();
  731. devtype_flag = false;
  732. }
  733. //CAN调试信息
  734. // else if(can_debug_flag == true)
  735. // {
  736. // //Can_send_debug_to_app();
  737. // can_debug_flag = false;
  738. // }
  739. //设备SN号,软硬件号
  740. else if (dev_version_flag == true)
  741. {
  742. pmu_to_fcu_version_data();
  743. dev_version_flag = false;
  744. }
  745. break;
  746. case PMU_SEND_REQINFO:
  747. pmu_to_con_request_data();
  748. pmu_send = PMU_SEND_YAOCE;
  749. break;
  750. case PMU_SEND_ACK:
  751. pmu_to_con_ack_data();
  752. pmu_send = PMU_SEND_YAOCE;
  753. break;
  754. case PMU_SEND_VERSION:
  755. pmu_to_con_version_data();
  756. pmu_send = PMU_SEND_YAOCE;
  757. break;
  758. case PMU_SEND_SHA1:
  759. pmu_to_fcu_key_data();
  760. pmu_send = PMU_SEND_YAOCE;
  761. break;
  762. default:
  763. pmu_send = PMU_SEND_YAOCE;
  764. break;
  765. }
  766. if (F4DT_send_flag == true)
  767. {
  768. pmu_to_con_DM4DTradar_data();
  769. F4DT_send_flag = false;
  770. }
  771. if(F4DB_send_flag == true)
  772. {
  773. pmu_to_con_DM4DBTradar_data();
  774. F4DB_send_flag = false;
  775. }
  776. if(DM4Dmsg_send_fmu == true || ((pmu_to_DM4Dmsg_flag == true && DM4d_to_fmu10s_flag <= 10000) &&
  777. (Dev.DM_Part_Fradar_Link.connect_status == COMP_NORMAL || Dev.DM_Part_Bradar_Link.connect_status == COMP_NORMAL)))
  778. {
  779. pmu_to_con_DM4DBradar_msg();
  780. pmu_to_DM4Dmsg_flag = false;
  781. DM4d_to_fmu10s_flag = HAL_GetTick();
  782. DM4Dmsg_send_fmu = false;
  783. }
  784. }
  785. }
  786. /**
  787. * @file timer_check_other_func
  788. * @brief FMU异常断电检测
  789. * @param none
  790. * @details UART2
  791. * @author Zhang Sir
  792. **/
  793. void timer_check_other_func()
  794. {
  795. //static uint32_t time1 = 0;
  796. static uint32_t time2 = 0;
  797. // if(Check_Timer_Ready(&time1,_1_HZ_))
  798. // {
  799. // if((planep.lock_status != STA_LOCK) && (fcu.connect_status == COMP_NORMAL) &&
  800. // (HAL_GetTick() - fcu.recv_time > 500))
  801. // {
  802. // stor_par.abnormal_outage_flag = 1;
  803. // write_flash_flag = true;
  804. // fcu.connect_status = COMP_LOST;
  805. // }
  806. // }
  807. if(Check_Timer_Ready(&time2,_2_HZ_))
  808. {
  809. if(HAL_GetTick() > 10000 && start_msg.version_info == false)
  810. {
  811. pmu_send = PMU_SEND_VERSION;
  812. start_msg.version_info = true;
  813. }
  814. else if (start_msg.key_info_checking == true && Device1.Vkbms_Link.connect_status == COMP_NORMAL)
  815. {
  816. pmu_send = PMU_SEND_SHA1;
  817. }
  818. else
  819. {
  820. //给FMU发送雷达灵敏度信息
  821. send_mocib_radar_sensi();
  822. }
  823. }
  824. }
  825. extern CAN_HandleTypeDef hcan1;
  826. extern CAN_HandleTypeDef hcan2;
  827. void thread_main_task_handle(void *param)
  828. {
  829. // if(Check_Chip_Verified != true)
  830. // {
  831. // while (1)
  832. // {
  833. // rt_thread_mdelay(5);
  834. // }
  835. // }
  836. while(1)
  837. {
  838. //数据发送定时器
  839. timer_function();
  840. //ADC采集
  841. ADC_GET_DATA();
  842. //点亮pmu内部led灯
  843. pmu_inside_led();
  844. // /*测试发送rkprintf*/
  845. // static uint32_t lastPrintTime = 0;
  846. // if( HAL_GetTick() - lastPrintTime > 1000){
  847. // rt_kprintf("this is a test!\r\n");
  848. // lastPrintTime = HAL_GetTick();
  849. // }
  850. //发送数据给主控制器 雷达升级不发送数据
  851. pmu_to_fcu();
  852. //更新播撒,称重,水泵,离心喷头,流量计等设备信息
  853. update_device_type_data();
  854. //智能电池相关功能
  855. bms_function();
  856. //雷达相关功能
  857. lidar_function();
  858. //判断异常断电,上电发送版本信息
  859. timer_check_other_func();
  860. //液位计相关功能
  861. //L1L2_GPIO_check();
  862. //获取设备版本和SN号
  863. get_device_version_and_sn();
  864. //电目雷达
  865. DM_obs_test();
  866. //写flash
  867. write_flash_function();
  868. #ifdef mimo_update
  869. mimo_obs_update_func();
  870. #else
  871. //设备升级
  872. Vk_Update_Device_Protocol();
  873. #endif
  874. eft_dev_update_func();
  875. send_uartfifo_msg();
  876. //CAN DEBUG
  877. // if(planep.Candebug_flag == true)
  878. // {
  879. // seek_can_debug_buf_adr();
  880. // }
  881. rt_thread_mdelay(2);
  882. }
  883. }