soft_engine.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755
  1. #include "soft_engine.h"
  2. #include "soft_crc.h"
  3. #include "crc.h"
  4. #include "string.h"
  5. #include "soft_p_2_c.h"
  6. #include "soft_test.h"
  7. #include "soft_uart.h"
  8. #include "math.h"
  9. struct ENGINE_DATA engine_data;
  10. //串口接收奥安发动机数据
  11. AOAN_TYPE aoan_data = {0, .engin_warn = 0xffff};
  12. Connect_check aoan_engine_Link;
  13. //解析奥安油电混传感器数据
  14. short decode_aoan_engine(uint8_t *pdata, uint16_t length)
  15. {
  16. short rst = 0;
  17. if (pdata[0] == 0x5A && pdata[1] == 0xA5 && pdata[2] == 0x1A && pdata[3] == 0x02)
  18. {
  19. unsigned char dNum = pdata[2];
  20. //校验通过。
  21. if (Get_Crc16(pdata, dNum + 5) == 0)
  22. {
  23. rst = 1;
  24. aoan_engine_Link.connect_status = COMP_NORMAL;
  25. //赋值数据
  26. memcpy(&aoan_data, &pdata[3], dNum);
  27. aoan_engine_Link.recv_time = HAL_GetTick();
  28. }
  29. }
  30. return rst;
  31. }
  32. // //串口接收VKV3发动机数据
  33. VKV3_TYPE vkv3_data = {0, .engin_warn = 0xffff};
  34. // VKV3_TYPE vkv3_data2 = {0, .engin_warn = 0xffff};
  35. Connect_check vkv3_engine_link;
  36. // Connect_check vkv3_engine2_link;
  37. //解析V3协议油电混传感器数据
  38. short decode_vkv3_engine(uint8_t *pdata, uint16_t length)
  39. {
  40. short rst = 0;
  41. uint32_t engine_sn_temp = 0;
  42. static uint32_t engine_sn1 = 0;
  43. VKV3_TYPE *ptr = NULL;
  44. if (pdata[0] == 0x5A && pdata[1] == 0xA5 && pdata[2] == 0X27 && pdata[4] == 0X03)
  45. {
  46. unsigned char dLEN = pdata[2];
  47. unsigned char comID = pdata[3];
  48. //校验通过。
  49. if (Get_Crc16(pdata, dLEN + 6) == 0)
  50. {
  51. memcpy(&engine_sn_temp, &pdata[12], 4);
  52. rst = 1;
  53. if(engine_sn1 == 0 || engine_sn_temp == engine_sn1)
  54. {
  55. ptr = &vkv3_data;
  56. vkv3_engine_link.connect_status = COMP_NORMAL;
  57. vkv3_engine_link.recv_time = HAL_GetTick();
  58. if(engine_sn1 == 0)
  59. engine_sn1 = engine_sn_temp;
  60. }
  61. else
  62. {
  63. // ptr = &vkv3_data2;
  64. // vkv3_engine2_link.connect_status = COMP_NORMAL;
  65. // vkv3_engine2_link.recv_time = HAL_GetTick();
  66. }
  67. switch (comID)
  68. {
  69. case 0X01:
  70. //赋值数据
  71. memcpy(&ptr->engin_ver, &pdata[4], dLEN);
  72. break;
  73. default:
  74. break;
  75. }
  76. }
  77. }
  78. return rst;
  79. }
  80. bool geely_set_tcd = false,geely_set_tcd_re = false,
  81. geely_set_tlock = false, geely_set_tlock_re = false, geely_set_protect = false,
  82. geely_send_BJtime = false,geely_get_version = false,geely_get_time = false;
  83. GEELY2 geely_data2;
  84. //解析吉利发动机
  85. GEELY geely_data = {0};
  86. GEELY_MONI geely_moni = {0};
  87. Connect_check geely_engin_link;
  88. int geely_version2_count = 0;
  89. void EngGeelyCanRecvHookFunction(uint32_t cellCanID, uint8_t data[], uint8_t len)
  90. {
  91. if(cellCanID == 0x100) //第二版协议识别
  92. {
  93. geely_engin_link.connect_status = COMP_NORMAL;
  94. geely_engin_link.recv_time = HAL_GetTick();
  95. }
  96. else if (cellCanID == 0x1c0)
  97. {
  98. memcpy(&geely_data.engine_ver, &data[0], len);
  99. }
  100. else if (cellCanID == 0x1c1)
  101. {
  102. //木牛防地雷达会异常进入发动机识别
  103. geely_engin_link.connect_status = COMP_NORMAL;
  104. memcpy(&geely_data.engine_rev, &data[0], len);
  105. }
  106. else if (cellCanID == 0x1c2)
  107. {
  108. memcpy(&geely_data.engine_vol, &data[0], len);
  109. }
  110. else if (cellCanID == 0x1c3)
  111. {
  112. uint8_t checkSum = 0;
  113. for (uint8_t i = 0; i < 8; i++)
  114. {
  115. checkSum += data[i];
  116. }
  117. geely_moni.recv_1c3++;
  118. if (checkSum == 0)
  119. {
  120. memcpy(&geely_data.engine_control, &data[0], len);
  121. if (geely_moni.msg1c3_last + 1 != geely_data.engine_counts)
  122. {
  123. geely_moni.msg1c3_indexerr++;
  124. }
  125. geely_moni.msg1c3_last = geely_data.engine_counts;
  126. if(geely_data.engine_set == 0x11)
  127. {
  128. //接收保养时间反馈
  129. if(geely_set_tcd == true)
  130. {
  131. geely_set_tcd = false;
  132. geely_set_counts = 0;
  133. geely_set_tcd_re = true;
  134. }
  135. }
  136. if(geely_data.engine_set == 0x12)
  137. {
  138. //接收保养时间复位反馈
  139. if(geely_set_tcd_re == true)
  140. {
  141. geely_set_tcd_re = false;
  142. geely_set_counts = 0;
  143. }
  144. }
  145. if(geely_data.engine_set == 0x14)
  146. {
  147. //接收锁机时间反馈
  148. if(geely_set_tlock == true)
  149. {
  150. geely_set_tlock = false;
  151. geely_set_counts = 0;
  152. geely_set_tlock_re = true;
  153. }
  154. }
  155. if(geely_data.engine_set == 0x15)
  156. {
  157. //接收锁机时间复位反馈
  158. if(geely_set_tlock_re == true)
  159. {
  160. geely_set_tlock_re = false;
  161. geely_set_counts = 0;
  162. }
  163. }
  164. if(geely_data.engine_set == 0x17)
  165. {
  166. }
  167. }
  168. else
  169. {
  170. geely_moni.msg1c3_sumerr++;
  171. }
  172. }
  173. else if (cellCanID == 0x1c4)
  174. {
  175. memcpy(&geely_data.engine_runtime, &data[0], len);
  176. }
  177. else
  178. {
  179. if(cellCanID >= 0x1E1 && cellCanID <= 0x1EF)
  180. {
  181. geely_engin_link.connect_status = COMP_NORMAL;
  182. geely_version2_count++;
  183. if(geely_data2.version2_flag != true && (geely_version2_count > 10))
  184. {
  185. geely_data2.version2_flag = true;
  186. } //作为第二版协议标志
  187. }
  188. //第二版协议
  189. switch (cellCanID)
  190. {
  191. case 0x031:
  192. geely_send_BJtime = true;
  193. break;
  194. case 0x1E1:
  195. break;
  196. case 0x1E2:
  197. geely_get_version = true;
  198. geely_count = 10;
  199. memcpy(&geely_data2.engine_ver,&data[0],8);
  200. break;
  201. case 0x1E3:
  202. geely_get_time = true;
  203. //geely_count = 10;
  204. memcpy(&geely_data2.engine_runtime,&data[0],8);
  205. break;
  206. case 0x1E4:
  207. memcpy(&geely_data2.Bit1E4,&data[0],6);
  208. break;
  209. case 0x1E8:
  210. memcpy(&geely_data2.engine_time,&data[0],8);
  211. geely_data2.engine_time = ((data[4] >> 6) & 0x3);
  212. break;
  213. case 0x1E9:
  214. memcpy(&geely_data2.engine_rev,&data[0],8);
  215. break;
  216. case 0x1EA:
  217. memcpy(&geely_data2.Bit1EA,&data[0],8);
  218. break;
  219. case 0x1EB:
  220. memcpy(&geely_data2.FuelConsumption,&data[0],8);
  221. break;
  222. case 0x1EC:
  223. memcpy(&geely_data2.EmgST0,&data[0],2);
  224. break;
  225. case 0x1ED:
  226. memcpy(&geely_data2.AlmST0,&data[0],8);
  227. break;
  228. case 0x1EE:
  229. memcpy(&geely_data2.Gear1Position,&data[0],7);
  230. break;
  231. default:
  232. break;
  233. }
  234. }
  235. geely_engin_link.recv_time = HAL_GetTick();
  236. }
  237. short geely_set_counts = 0;
  238. #pragma pack(1)
  239. typedef struct
  240. {
  241. uint32_t time;
  242. uint8_t nodecode:4;
  243. uint8_t message_conut0:4;
  244. int8_t check_sum0;
  245. uint8_t client_cmd;
  246. uint8_t syscontrol;
  247. uint8_t reserve0;
  248. uint8_t reserve1;
  249. uint32_t reserve2:20;
  250. uint8_t message_conut1:4;
  251. int8_t check_sum1;
  252. }geely_info2;
  253. geely_info2 geely_sendinfo2;
  254. #pragma pack()
  255. uint8_t geely_count = 15;
  256. uint8_t start_engine = 0; // 0x80启动 0停止
  257. void Geely_version2_init(void)
  258. {
  259. uint8_t can_buf[8] = {0};
  260. static uint8_t geely_init_count = 15;
  261. if(geely_data2.version2_flag != true && geely_init_count > 1)
  262. {
  263. geely_sendinfo2.client_cmd = 0x12;
  264. geely_sendinfo2.syscontrol = 0;
  265. geely_sendinfo2.check_sum1 = geely_sendinfo2.client_cmd + geely_sendinfo2.syscontrol + (geely_sendinfo2.message_conut1 << 4);
  266. geely_sendinfo2.check_sum1 = 0 - geely_sendinfo2.check_sum1;
  267. memcpy(&can_buf[0],&geely_sendinfo2.client_cmd,8);
  268. geely_sendinfo2.message_conut1++;
  269. can_send_msg_normalstd(&can_buf[0],8,0x1E0);
  270. geely_init_count--;
  271. }
  272. }
  273. void Geely_version2_send_info( void )
  274. {
  275. uint8_t can_buf[8] = {0};
  276. //发送北京时间
  277. if(geely_send_BJtime == false && (beijing_time.ui8Year != 0)) //上点发送,CANID不在过滤器中 不等反馈
  278. {
  279. geely_sendinfo2.time = 0;
  280. geely_sendinfo2.time += beijing_time.ui8Second / 2;
  281. geely_sendinfo2.time += beijing_time.ui8Minute *( 0x1 << 5);
  282. geely_sendinfo2.time += beijing_time.ui8Hour *( 0x1 << 11);
  283. geely_sendinfo2.time += beijing_time.ui8DayOfMonth *( 0x1 << 16);
  284. geely_sendinfo2.time += beijing_time.ui8Month *( 0x1 << 21);
  285. geely_sendinfo2.time += (beijing_time.ui8Year - 2000) *( 0x1 << 25);
  286. geely_sendinfo2.nodecode = 0;
  287. geely_sendinfo2.check_sum0 = geely_sendinfo2.time + geely_sendinfo2.nodecode + (geely_sendinfo2.message_conut0 << 4);
  288. geely_sendinfo2.check_sum0 = 0 - geely_sendinfo2.check_sum0;
  289. memcpy(&can_buf[0],&geely_sendinfo2,6);
  290. geely_sendinfo2.message_conut0++;
  291. can_send_msg_normalstd(&can_buf[0],6,0x030);
  292. }
  293. //上电读取信息
  294. if(geely_get_version == false || geely_get_time == false)
  295. {
  296. if(geely_get_version == false)
  297. {
  298. geely_sendinfo2.client_cmd = 0x16;
  299. }
  300. else if(geely_get_time == false)
  301. {
  302. geely_sendinfo2.client_cmd = 0x17;
  303. }
  304. geely_sendinfo2.syscontrol = 0;
  305. geely_sendinfo2.check_sum1 = geely_sendinfo2.client_cmd + geely_sendinfo2.syscontrol + (geely_sendinfo2.message_conut1 << 4);
  306. geely_sendinfo2.check_sum1 = 0 - geely_sendinfo2.check_sum1;
  307. memcpy(&can_buf[0],&geely_sendinfo2.client_cmd,8);
  308. geely_sendinfo2.message_conut1++;
  309. can_send_msg_normalstd(&can_buf[0],8,0x1E0);
  310. geely_count--;
  311. if(geely_count == 0)
  312. {
  313. geely_count = 10;
  314. if(geely_get_version == false)
  315. {
  316. geely_get_version = true;
  317. }
  318. else if(geely_get_time == false)
  319. {
  320. geely_get_time = true;
  321. }
  322. }
  323. }
  324. //控制发动机启停
  325. else
  326. {
  327. geely_sendinfo2.client_cmd = 0x12;
  328. geely_sendinfo2.syscontrol = start_engine;
  329. geely_sendinfo2.check_sum1 = geely_sendinfo2.client_cmd + geely_sendinfo2.syscontrol + (geely_sendinfo2.message_conut1 << 4) ;
  330. geely_sendinfo2.check_sum1 = 0 - geely_sendinfo2.check_sum1;
  331. memcpy(&can_buf[0],&geely_sendinfo2.client_cmd,8);
  332. geely_sendinfo2.message_conut1++;
  333. can_send_msg_normalstd(&can_buf[0],8,0x1E0);
  334. }
  335. // else
  336. // {
  337. // geely_sendinfo2.client_cmd = 0x11;
  338. // geely_sendinfo2.syscontrol = 0;
  339. // geely_sendinfo2.check_sum1 = geely_sendinfo2.client_cmd + geely_sendinfo2.syscontrol + (geely_sendinfo2.message_conut1 << 4);
  340. // geely_sendinfo2.check_sum1 = 0 - geely_sendinfo2.check_sum1;
  341. // memcpy(&can_buf[0],&geely_sendinfo2.client_cmd,8);
  342. // geely_sendinfo2.message_conut1++;
  343. // can_send_msg_normalstd(&can_buf[0],8,0x1E0);
  344. // }
  345. }
  346. #define SENDTO_GEELY_STATUS_ID (0X1A0)
  347. STO_GEELY sendto_geely = {.ExtenderControl = 0,
  348. .ExtenderSetting = 0x10,
  349. .SettingParameter = 0,
  350. .ExtenderBak = 0,
  351. .MessageCount = 0
  352. };
  353. uint8_t vkv3_buf[20] = {0};
  354. void send_msg_to_vk3(void)
  355. {
  356. if(vkv3_engine_link.connect_status == COMP_NORMAL &&
  357. uart_send_is_ok(USART_3) == true)
  358. {
  359. uint16_t crc = 0;
  360. uint8_t index = 0;
  361. vkv3_buf[index++] = 0x5A;
  362. vkv3_buf[index++] = 0xA5;
  363. vkv3_buf[index++] = 4;
  364. vkv3_buf[index++] = 0x0A;
  365. if(start_engine == 0x80)
  366. {
  367. vkv3_buf[index++] = 1;
  368. }
  369. else
  370. {
  371. vkv3_buf[index++] = 0;
  372. }
  373. vkv3_buf[index++] = planep.lock_status;
  374. vkv3_buf[index++] = planep.thr_pwm;
  375. vkv3_buf[index++] = planep.thr_pwm >> 8;
  376. crc = Get_Crc16(vkv3_buf, index);
  377. memcpy(&vkv3_buf[index], &crc, 2);
  378. index +=2;
  379. uart3_send_msg(vkv3_buf,index);
  380. }
  381. }
  382. void send_msg_to_geely(void)
  383. {
  384. static uint32_t sendto_geely_lasttime = 0;
  385. static uint32_t sendto_bro_lasttime = 0;
  386. if (geely_engin_link.connect_status == COMP_NORMAL && engine_data.engine_type == ENGINE_BRO && HAL_GetTick() - sendto_bro_lasttime > 222)
  387. {
  388. uint8_t can_buf[8] = {0};
  389. short temp = 0;
  390. sendto_bro_lasttime = HAL_GetTick();
  391. memcpy(&can_buf[0],&planep.alt,2);
  392. temp = sqrtf(planep.E_vel * planep.E_vel + planep.N_vel * planep.N_vel);
  393. memcpy(&can_buf[2],&temp,2);
  394. memcpy(&can_buf[4],&planep.yaw,2);
  395. memcpy(&can_buf[6],&planep.lock_status,2);
  396. can_send_msg_normalstd(&can_buf[0],8,0x1F0);
  397. memcpy(&can_buf[0],&planep.pos_x1,4);
  398. memcpy(&can_buf[4],&planep.pos_y1,4);
  399. can_send_msg_normalstd(&can_buf[0],8,0x1F1);
  400. }
  401. if (geely_engin_link.connect_status == COMP_NORMAL && HAL_GetTick() - sendto_geely_lasttime > 100)
  402. {
  403. uint8_t geely[8] = {0};
  404. sendto_geely_lasttime = HAL_GetTick();
  405. Geely_version2_init();
  406. if(geely_data2.version2_flag == true)
  407. {
  408. Geely_version2_send_info();
  409. }
  410. else
  411. {
  412. sendto_geely.ExtenderBak = planep.thr_pwm;
  413. sendto_geely.DroneStatus = (planep.lock_status == 4? 1: 0); //(thr_lock_status == LOCKED ? 0 : 1);
  414. sendto_geely.MessageCount++;
  415. if(geely_set_tcd == true)
  416. {
  417. geely_set_counts++;
  418. if(geely_set_counts > 5){
  419. geely_set_tcd = false;
  420. geely_set_counts = 0;
  421. }
  422. sendto_geely.ExtenderSetting = 0x11;
  423. //sendto_geely.SettingParameter = 0;
  424. }
  425. else if(geely_set_tcd_re == true)
  426. {
  427. geely_set_counts++;
  428. if(geely_set_counts > 5){
  429. geely_set_tcd_re = false;
  430. geely_set_counts = 0;
  431. }
  432. sendto_geely.ExtenderSetting = 0x12;
  433. sendto_geely.SettingParameter = 0;
  434. }
  435. else if(geely_set_tlock == true)
  436. {
  437. geely_set_counts++;
  438. if(geely_set_counts > 5){
  439. geely_set_tlock = false;
  440. geely_set_counts = 0;
  441. }
  442. sendto_geely.ExtenderSetting = 0x14;
  443. //sendto_geely.SettingParameter = 0;
  444. }
  445. else if(geely_set_tlock_re == true)
  446. {
  447. geely_set_counts++;
  448. if(geely_set_counts > 5){
  449. geely_set_tlock_re = false;
  450. geely_set_counts = 0;
  451. }
  452. sendto_geely.ExtenderSetting = 0x15;
  453. sendto_geely.SettingParameter = 0;
  454. }
  455. else if(geely_set_protect == true)
  456. {
  457. geely_set_counts++;
  458. if(geely_set_counts > 5){
  459. geely_set_protect = false;
  460. geely_set_counts = 0;
  461. }
  462. sendto_geely.ExtenderSetting = 0x17;
  463. sendto_geely.SettingParameter = 0;
  464. }
  465. else
  466. {
  467. sendto_geely.ExtenderSetting = 0x10;
  468. sendto_geely.SettingParameter = 0;
  469. geely_set_counts = 0;
  470. }
  471. memcpy(geely, (uint8_t *)&sendto_geely.ExtenderControl, 7);
  472. sendto_geely.CheckSum = 0;
  473. for (uint8_t i = 0; i < 7; i++)
  474. {
  475. sendto_geely.CheckSum += geely[i];
  476. }
  477. sendto_geely.CheckSum = -sendto_geely.CheckSum;
  478. can_send_msg_normalstd(&sendto_geely.ExtenderControl, sizeof(sendto_geely), SENDTO_GEELY_STATUS_ID);
  479. geely_moni.send_1a0++;
  480. }
  481. }
  482. }
  483. comp_status engine_link_status = COMP_NOEXIST;
  484. /*
  485. 发动机类型 uint8 1-瑞深 2-中飞
  486. 发动机转速 uint16_t RPM
  487. 发动机油门 uint16_t
  488. 发动机电压 uint16_t 0.1v
  489. 充电电流 uint16_t 0.1A
  490. 发动机运行时间 uint32_t Min 总运行时间不清零
  491. 剩余保养时间 uint16_t Min 保养后清零
  492. 剩余锁机时间 uint16_t Min 锁机倒计时
  493. 运行状态 uint8_t 0:停止,1:等待,2:运行, 3:锁机
  494. 报警信息 uint16_t 按位来表示可同时容纳16种警报
  495. 剩余油量 uint8_t % 0%-100%
  496. 气缸1温度 uint16_t ℃ 0℃~300℃
  497. 气缸2温度 uint16_t ℃ 0℃~300℃
  498. PCB温度 uint8_t ℃ 0℃~255℃
  499. */
  500. /*
  501. 检查智能电池的连接及数据获取,主要解决兼容多厂家设备接入时的选用优先级问题。
  502. 更新速度至少要 5hz
  503. 缺少放电电流数据
  504. */
  505. void update_engine_data(void)
  506. {
  507. //监测中飞发动机
  508. Check_dev_link(&aoan_engine_Link,5000,(char *)&aoan_data,sizeof(AOAN_TYPE));
  509. //监测VKV3的发动机
  510. Check_dev_link(&vkv3_engine_link,5000,(char *)&vkv3_data,sizeof(VKV3_TYPE));
  511. //监测VKV3 2的发动机
  512. //Check_dev_link(&vkv3_engine2_link,5000,(char *)&vkv3_data,sizeof(VKV3_TYPE));
  513. //检测GEELY发动机
  514. Check_dev_link(&geely_engin_link,5000,(char *)&geely_data,sizeof(GEELY));
  515. if (aoan_engine_Link.connect_status == COMP_NORMAL)
  516. {
  517. engine_link_status = COMP_NORMAL;
  518. //数字显示,显示9位数
  519. engine_data.engine_type = ENGINE_AOAN;
  520. engine_data.engine_rev = aoan_data.engin_rev;
  521. engine_data.engine_thr = aoan_data.engin_thr;
  522. engine_data.engine_vol = aoan_data.engin_vol;
  523. engine_data.engine_elect = aoan_data.engin_elect;
  524. engine_data.engine_rtime = aoan_data.engin_rtime;
  525. engine_data.engine_tcd = aoan_data.engin_tcd;
  526. engine_data.engine_lcd = aoan_data.engin_lcd;
  527. engine_data.engine_rsta = aoan_data.engin_rsta;
  528. engine_data.engine_warn = aoan_data.engin_warn;
  529. engine_data.engine_roil = aoan_data.engin_roil;
  530. engine_data.engine_cyl1temp = aoan_data.engin_cyl1temp;
  531. engine_data.engine_cyl2temp = aoan_data.engin_cyl2temp;
  532. engine_data.engine_pcbtemp = aoan_data.engin_pcbtemp;
  533. memcpy(engine_data.engine_brand, "AOAN", 4);
  534. }
  535. else if (vkv3_engine_link.connect_status == COMP_NORMAL)
  536. {
  537. engine_link_status = COMP_NORMAL;
  538. //数字显示,显示9位数
  539. engine_data.engine_type = ENGINE_VK;
  540. engine_data.engine_rev = vkv3_data.engin_rev;
  541. engine_data.engine_thr = vkv3_data.engin_thr;
  542. engine_data.engine_vol = vkv3_data.engin_vol;
  543. engine_data.engine_elect = vkv3_data.engin_elect;
  544. engine_data.engine_rtime = vkv3_data.engin_rtime;
  545. engine_data.engine_tcd = vkv3_data.engin_tcd;
  546. engine_data.engine_lcd = vkv3_data.engin_lcd;
  547. engine_data.engine_rsta = vkv3_data.engin_rsta;
  548. engine_data.engine_warn = vkv3_data.engin_warn;
  549. engine_data.engine_roil = vkv3_data.engin_roil;
  550. engine_data.engine_cyl1temp = vkv3_data.engin_cyl1temp;
  551. engine_data.engine_cyl2temp = vkv3_data.engin_cyl2temp;
  552. engine_data.engine_pcbtemp = vkv3_data.engin_pcbtemp;
  553. engine_data.engine_sn = vkv3_data.engin_sn;
  554. memcpy(engine_data.engine_brand, vkv3_data.engin_brand, 8);
  555. // if(vkv3_engine2_link.connect_status == COMP_NORMAL)
  556. // {
  557. // }
  558. }
  559. else if (geely_engin_link.connect_status == COMP_NORMAL)
  560. {
  561. engine_link_status = COMP_NORMAL;
  562. engine_data.engine_type = ENGINE_GEELY;
  563. //数字显示,显示9位数
  564. if(geely_data2.version2_flag != true)
  565. {
  566. engine_data.engine_rev = geely_data.engine_rev;
  567. engine_data.engine_thr = geely_data.engine_thrposition * 0.1f;
  568. engine_data.engine_vol = geely_data.engine_vol * 2;
  569. engine_data.engine_elect = (short)(geely_data.engine_elect - 1000) * 2;
  570. engine_data.engine_rtime = geely_data.engine_runtime;
  571. engine_data.engine_tcd = geely_data.engine_tcd;
  572. engine_data.engine_lcd = geely_data.engine_tlock;
  573. engine_data.engine_rsta = geely_data.engine_status;
  574. engine_data.engine_warn = geely_data.engine_warn & 0xffef;//屏蔽总线系统异常
  575. engine_data.engine_roil = geely_data.engine_fuelposition * 0.5f;
  576. engine_data.engine_cyl1temp = geely_data.engine_cyltemp - 40;
  577. engine_data.engine_cyl2temp = 0;
  578. engine_data.engine_pcbtemp = geely_data.engine_cooltemp - 40;
  579. memcpy(engine_data.engine_brand, geely_data.engine_brand, 3);
  580. memcpy(&engine_data.engine_brand[3],"-", 1);
  581. snprintf((char *)&engine_data.engine_brand[4],4,"%d",(int)geely_data.engine_ver);
  582. engine_data.engine_sn = geely_data.engine_sn[0] * 10000000 + geely_data.engine_sn[1] * 100000 +
  583. geely_data.engine_sn[2] * 1000 + geely_data.engine_sn[3];
  584. engine_data.engine_lockstatus = geely_data.engine_control;
  585. engine_data.engine_fault = geely_data.engine_fault;
  586. }
  587. else
  588. {
  589. if(geely_data2.engine_brand[0] == 'B' && geely_data2.engine_brand[1] =='R' && geely_data2.engine_brand[2] =='O')
  590. {
  591. engine_data.engine_type = ENGINE_BRO;
  592. }
  593. engine_data.engine_rev = geely_data2.engine_rev;
  594. engine_data.engine_thr = geely_data2.Bit1EA.engine_ATP1 * 0.05f;
  595. engine_data.engine_vol = geely_data2.engine_vol * 0.1f;
  596. engine_data.engine_elect = (short)(geely_data2.engine_elect * 0.05f - 400) * 10;
  597. engine_data.engine_rtime = geely_data2.engine_runtime;
  598. engine_data.engine_tcd = geely_data2.engine_tcd;
  599. engine_data.engine_lcd = geely_data2.engine_tlock;
  600. engine_data.engine_rsta = geely_data2.engine_state;
  601. engine_data.engine_warn = geely_data2.EmgST0;
  602. engine_data.engine_roil = geely_data2.GPS * 0.5f;
  603. engine_data.engine_cyl1temp = geely_data2.engine_cooltemp - 40;
  604. engine_data.engine_cyl2temp = geely_data2. engine_cooltemp1 - 40;
  605. engine_data.engine_pcbtemp = geely_data2.engine_GWT - 40;
  606. memcpy(engine_data.engine_brand, geely_data2.engine_brand, 3);
  607. memcpy(&engine_data.engine_brand[3],"-", 1);
  608. snprintf((char *)&engine_data.engine_brand[4],4,"%d",(int)geely_data2.engine_ver);
  609. engine_data.engine_sn = geely_data2.engine_sn[0] * 10000000 + geely_data2.engine_sn[1] * 100000 +
  610. geely_data2.engine_sn[2] * 1000 + geely_data2.engine_sn[3];
  611. //engine_data.engine_lockstatus = geely_data2.engine_state == 0? 0 : 1;
  612. engine_data.engine_lockstatus = geely_data2.engine_controlcmd;
  613. //engine_data.engine_fault = geely_data2.engine_fault;
  614. }
  615. }
  616. else
  617. {
  618. if (engine_link_status == COMP_NORMAL)
  619. {
  620. engine_link_status = COMP_LOST;
  621. memset(&engine_data, 0, sizeof(engine_data));
  622. //状态未置异常
  623. engine_data.engine_type = 0xFF;
  624. }
  625. }
  626. }
  627. /******************void engine_function(void)********************
  628. * ****************发动机检测函数*********************************
  629. * **************************************************************/
  630. void engine_function(void)
  631. {
  632. static uint32_t engine_time = 0;
  633. if(Check_Timer_Ready(&engine_time,_10_HZ_))
  634. {
  635. update_engine_data();
  636. //发送飞控状态给发动机
  637. send_msg_to_vk3();
  638. }
  639. //给吉利发动机发送信息
  640. send_msg_to_geely();
  641. }