soft_engine.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  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 += beijing_time.ui8Second / 2;
  280. // geely_sendinfo2.time += beijing_time.ui8Minute *( 0x1 << 4);
  281. // geely_sendinfo2.time += beijing_time.ui8Hour *( 0x1 << 10);
  282. // geely_sendinfo2.time += beijing_time.ui8DayOfMonth *( 0x1 << 15);
  283. // geely_sendinfo2.time += beijing_time.ui8Month *( 0x1 << 20);
  284. // geely_sendinfo2.time += beijing_time.ui8Year *( 0x1 << 24);
  285. // geely_sendinfo2.nodecode = 0;
  286. // geely_sendinfo2.check_sum0 = geely_sendinfo2.time + geely_sendinfo2.nodecode + (geely_sendinfo2.message_conut0 << 4);
  287. // geely_sendinfo2.check_sum0 = 0 - geely_sendinfo2.check_sum0;
  288. // memcpy(&can_buf[0],&geely_sendinfo2,6);
  289. // geely_sendinfo2.message_conut0++;
  290. // can_send_msg_normalstd(&can_buf[0],6,0x030);
  291. // }
  292. //上电读取信息
  293. if(geely_get_version == false || geely_get_time == false)
  294. {
  295. if(geely_get_version == false)
  296. {
  297. geely_sendinfo2.client_cmd = 0x16;
  298. }
  299. else if(geely_get_time == false)
  300. {
  301. geely_sendinfo2.client_cmd = 0x17;
  302. }
  303. geely_sendinfo2.syscontrol = 0;
  304. geely_sendinfo2.check_sum1 = geely_sendinfo2.client_cmd + geely_sendinfo2.syscontrol + (geely_sendinfo2.message_conut1 << 4);
  305. geely_sendinfo2.check_sum1 = 0 - geely_sendinfo2.check_sum1;
  306. memcpy(&can_buf[0],&geely_sendinfo2.client_cmd,8);
  307. geely_sendinfo2.message_conut1++;
  308. can_send_msg_normalstd(&can_buf[0],8,0x1E0);
  309. geely_count--;
  310. if(geely_count == 0)
  311. {
  312. geely_count = 10;
  313. if(geely_get_version == false)
  314. {
  315. geely_get_version = true;
  316. }
  317. else if(geely_get_time == false)
  318. {
  319. geely_get_time = true;
  320. }
  321. }
  322. }
  323. //控制发动机启停
  324. else
  325. {
  326. geely_sendinfo2.client_cmd = 0x12;
  327. geely_sendinfo2.syscontrol = start_engine;
  328. geely_sendinfo2.check_sum1 = geely_sendinfo2.client_cmd + geely_sendinfo2.syscontrol + (geely_sendinfo2.message_conut1 << 4) ;
  329. geely_sendinfo2.check_sum1 = 0 - geely_sendinfo2.check_sum1;
  330. memcpy(&can_buf[0],&geely_sendinfo2.client_cmd,8);
  331. geely_sendinfo2.message_conut1++;
  332. can_send_msg_normalstd(&can_buf[0],8,0x1E0);
  333. }
  334. // else
  335. // {
  336. // geely_sendinfo2.client_cmd = 0x11;
  337. // geely_sendinfo2.syscontrol = 0;
  338. // geely_sendinfo2.check_sum1 = geely_sendinfo2.client_cmd + geely_sendinfo2.syscontrol + (geely_sendinfo2.message_conut1 << 4);
  339. // geely_sendinfo2.check_sum1 = 0 - geely_sendinfo2.check_sum1;
  340. // memcpy(&can_buf[0],&geely_sendinfo2.client_cmd,8);
  341. // geely_sendinfo2.message_conut1++;
  342. // can_send_msg_normalstd(&can_buf[0],8,0x1E0);
  343. // }
  344. }
  345. #define SENDTO_GEELY_STATUS_ID (0X1A0)
  346. STO_GEELY sendto_geely = {.ExtenderControl = 0,
  347. .ExtenderSetting = 0x10,
  348. .SettingParameter = 0,
  349. .ExtenderBak = 0,
  350. .MessageCount = 0
  351. };
  352. uint8_t vkv3_buf[20] = {0};
  353. void send_msg_to_vk3(void)
  354. {
  355. if(vkv3_engine_link.connect_status == COMP_NORMAL &&
  356. uart_send_is_ok(USART_3) == true)
  357. {
  358. uint16_t crc = 0;
  359. uint8_t index = 0;
  360. vkv3_buf[index++] = 0x5A;
  361. vkv3_buf[index++] = 0xA5;
  362. vkv3_buf[index++] = 4;
  363. vkv3_buf[index++] = 0x0A;
  364. if(start_engine == 0x80)
  365. {
  366. vkv3_buf[index++] = 1;
  367. }
  368. else
  369. {
  370. vkv3_buf[index++] = 0;
  371. }
  372. vkv3_buf[index++] = planep.lock_status;
  373. vkv3_buf[index++] = planep.thr_pwm;
  374. vkv3_buf[index++] = planep.thr_pwm >> 8;
  375. crc = Get_Crc16(vkv3_buf, index);
  376. memcpy(&vkv3_buf[index], &crc, 2);
  377. index +=2;
  378. uart3_send_msg(vkv3_buf,index);
  379. }
  380. }
  381. void send_msg_to_geely(void)
  382. {
  383. static uint32_t sendto_geely_lasttime = 0;
  384. static uint32_t sendto_bro_lasttime = 0;
  385. if (geely_engin_link.connect_status == COMP_NORMAL && engine_data.engine_type == ENGINE_BRO && HAL_GetTick() - sendto_bro_lasttime > 222)
  386. {
  387. uint8_t can_buf[8] = {0};
  388. short temp = 0;
  389. sendto_bro_lasttime = HAL_GetTick();
  390. memcpy(&can_buf[0],&planep.alt,2);
  391. temp = sqrtf(planep.E_vel * planep.E_vel + planep.N_vel * planep.N_vel);
  392. memcpy(&can_buf[2],&temp,2);
  393. memcpy(&can_buf[4],&planep.yaw,2);
  394. memcpy(&can_buf[6],&planep.lock_status,2);
  395. can_send_msg_normalstd(&can_buf[0],8,0x1F0);
  396. memcpy(&can_buf[0],&planep.pos_x1,4);
  397. memcpy(&can_buf[4],&planep.pos_y1,4);
  398. can_send_msg_normalstd(&can_buf[0],8,0x1F1);
  399. }
  400. if (geely_engin_link.connect_status == COMP_NORMAL && HAL_GetTick() - sendto_geely_lasttime > 100)
  401. {
  402. uint8_t geely[8] = {0};
  403. sendto_geely_lasttime = HAL_GetTick();
  404. Geely_version2_init();
  405. if(geely_data2.version2_flag == true)
  406. {
  407. Geely_version2_send_info();
  408. }
  409. else
  410. {
  411. sendto_geely.ExtenderBak = planep.thr_pwm;
  412. sendto_geely.DroneStatus = (planep.lock_status == 4? 1: 0); //(thr_lock_status == LOCKED ? 0 : 1);
  413. sendto_geely.MessageCount++;
  414. if(geely_set_tcd == true)
  415. {
  416. geely_set_counts++;
  417. if(geely_set_counts > 5){
  418. geely_set_tcd = false;
  419. geely_set_counts = 0;
  420. }
  421. sendto_geely.ExtenderSetting = 0x11;
  422. //sendto_geely.SettingParameter = 0;
  423. }
  424. else if(geely_set_tcd_re == true)
  425. {
  426. geely_set_counts++;
  427. if(geely_set_counts > 5){
  428. geely_set_tcd_re = false;
  429. geely_set_counts = 0;
  430. }
  431. sendto_geely.ExtenderSetting = 0x12;
  432. sendto_geely.SettingParameter = 0;
  433. }
  434. else if(geely_set_tlock == true)
  435. {
  436. geely_set_counts++;
  437. if(geely_set_counts > 5){
  438. geely_set_tlock = false;
  439. geely_set_counts = 0;
  440. }
  441. sendto_geely.ExtenderSetting = 0x14;
  442. //sendto_geely.SettingParameter = 0;
  443. }
  444. else if(geely_set_tlock_re == true)
  445. {
  446. geely_set_counts++;
  447. if(geely_set_counts > 5){
  448. geely_set_tlock_re = false;
  449. geely_set_counts = 0;
  450. }
  451. sendto_geely.ExtenderSetting = 0x15;
  452. sendto_geely.SettingParameter = 0;
  453. }
  454. else if(geely_set_protect == true)
  455. {
  456. geely_set_counts++;
  457. if(geely_set_counts > 5){
  458. geely_set_protect = false;
  459. geely_set_counts = 0;
  460. }
  461. sendto_geely.ExtenderSetting = 0x17;
  462. sendto_geely.SettingParameter = 0;
  463. }
  464. else
  465. {
  466. sendto_geely.ExtenderSetting = 0x10;
  467. sendto_geely.SettingParameter = 0;
  468. geely_set_counts = 0;
  469. }
  470. memcpy(geely, (uint8_t *)&sendto_geely.ExtenderControl, 7);
  471. sendto_geely.CheckSum = 0;
  472. for (uint8_t i = 0; i < 7; i++)
  473. {
  474. sendto_geely.CheckSum += geely[i];
  475. }
  476. sendto_geely.CheckSum = -sendto_geely.CheckSum;
  477. can_send_msg_normalstd(&sendto_geely.ExtenderControl, sizeof(sendto_geely), SENDTO_GEELY_STATUS_ID);
  478. geely_moni.send_1a0++;
  479. }
  480. }
  481. }
  482. comp_status engine_link_status = COMP_NOEXIST;
  483. /*
  484. 发动机类型 uint8 1-瑞深 2-中飞
  485. 发动机转速 uint16_t RPM
  486. 发动机油门 uint16_t
  487. 发动机电压 uint16_t 0.1v
  488. 充电电流 uint16_t 0.1A
  489. 发动机运行时间 uint32_t Min 总运行时间不清零
  490. 剩余保养时间 uint16_t Min 保养后清零
  491. 剩余锁机时间 uint16_t Min 锁机倒计时
  492. 运行状态 uint8_t 0:停止,1:等待,2:运行, 3:锁机
  493. 报警信息 uint16_t 按位来表示可同时容纳16种警报
  494. 剩余油量 uint8_t % 0%-100%
  495. 气缸1温度 uint16_t ℃ 0℃~300℃
  496. 气缸2温度 uint16_t ℃ 0℃~300℃
  497. PCB温度 uint8_t ℃ 0℃~255℃
  498. */
  499. /*
  500. 检查智能电池的连接及数据获取,主要解决兼容多厂家设备接入时的选用优先级问题。
  501. 更新速度至少要 5hz
  502. 缺少放电电流数据
  503. */
  504. void update_engine_data(void)
  505. {
  506. //监测中飞发动机
  507. Check_dev_link(&aoan_engine_Link,5000,(char *)&aoan_data,sizeof(AOAN_TYPE));
  508. //监测VKV3的发动机
  509. Check_dev_link(&vkv3_engine_link,5000,(char *)&vkv3_data,sizeof(VKV3_TYPE));
  510. //监测VKV3 2的发动机
  511. //Check_dev_link(&vkv3_engine2_link,5000,(char *)&vkv3_data,sizeof(VKV3_TYPE));
  512. //检测GEELY发动机
  513. Check_dev_link(&geely_engin_link,5000,(char *)&geely_data,sizeof(GEELY));
  514. if (aoan_engine_Link.connect_status == COMP_NORMAL)
  515. {
  516. engine_link_status = COMP_NORMAL;
  517. //数字显示,显示9位数
  518. engine_data.engine_type = ENGINE_AOAN;
  519. engine_data.engine_rev = aoan_data.engin_rev;
  520. engine_data.engine_thr = aoan_data.engin_thr;
  521. engine_data.engine_vol = aoan_data.engin_vol;
  522. engine_data.engine_elect = aoan_data.engin_elect;
  523. engine_data.engine_rtime = aoan_data.engin_rtime;
  524. engine_data.engine_tcd = aoan_data.engin_tcd;
  525. engine_data.engine_lcd = aoan_data.engin_lcd;
  526. engine_data.engine_rsta = aoan_data.engin_rsta;
  527. engine_data.engine_warn = aoan_data.engin_warn;
  528. engine_data.engine_roil = aoan_data.engin_roil;
  529. engine_data.engine_cyl1temp = aoan_data.engin_cyl1temp;
  530. engine_data.engine_cyl2temp = aoan_data.engin_cyl2temp;
  531. engine_data.engine_pcbtemp = aoan_data.engin_pcbtemp;
  532. memcpy(engine_data.engine_brand, "AOAN", 4);
  533. }
  534. else if (vkv3_engine_link.connect_status == COMP_NORMAL)
  535. {
  536. engine_link_status = COMP_NORMAL;
  537. //数字显示,显示9位数
  538. engine_data.engine_type = ENGINE_VK;
  539. engine_data.engine_rev = vkv3_data.engin_rev;
  540. engine_data.engine_thr = vkv3_data.engin_thr;
  541. engine_data.engine_vol = vkv3_data.engin_vol;
  542. engine_data.engine_elect = vkv3_data.engin_elect;
  543. engine_data.engine_rtime = vkv3_data.engin_rtime;
  544. engine_data.engine_tcd = vkv3_data.engin_tcd;
  545. engine_data.engine_lcd = vkv3_data.engin_lcd;
  546. engine_data.engine_rsta = vkv3_data.engin_rsta;
  547. engine_data.engine_warn = vkv3_data.engin_warn;
  548. engine_data.engine_roil = vkv3_data.engin_roil;
  549. engine_data.engine_cyl1temp = vkv3_data.engin_cyl1temp;
  550. engine_data.engine_cyl2temp = vkv3_data.engin_cyl2temp;
  551. engine_data.engine_pcbtemp = vkv3_data.engin_pcbtemp;
  552. engine_data.engine_sn = vkv3_data.engin_sn;
  553. memcpy(engine_data.engine_brand, vkv3_data.engin_brand, 8);
  554. // if(vkv3_engine2_link.connect_status == COMP_NORMAL)
  555. // {
  556. // }
  557. }
  558. else if (geely_engin_link.connect_status == COMP_NORMAL)
  559. {
  560. engine_link_status = COMP_NORMAL;
  561. engine_data.engine_type = ENGINE_GEELY;
  562. //数字显示,显示9位数
  563. if(geely_data2.version2_flag != true)
  564. {
  565. engine_data.engine_rev = geely_data.engine_rev;
  566. engine_data.engine_thr = geely_data.engine_thrposition * 0.1f;
  567. engine_data.engine_vol = geely_data.engine_vol * 2;
  568. engine_data.engine_elect = (short)(geely_data.engine_elect - 1000) * 2;
  569. engine_data.engine_rtime = geely_data.engine_runtime;
  570. engine_data.engine_tcd = geely_data.engine_tcd;
  571. engine_data.engine_lcd = geely_data.engine_tlock;
  572. engine_data.engine_rsta = geely_data.engine_status;
  573. engine_data.engine_warn = geely_data.engine_warn & 0xffef;//屏蔽总线系统异常
  574. engine_data.engine_roil = geely_data.engine_fuelposition * 0.5f;
  575. engine_data.engine_cyl1temp = geely_data.engine_cyltemp - 40;
  576. engine_data.engine_cyl2temp = 0;
  577. engine_data.engine_pcbtemp = geely_data.engine_cooltemp - 40;
  578. memcpy(engine_data.engine_brand, geely_data.engine_brand, 3);
  579. memcpy(&engine_data.engine_brand[3],"-", 1);
  580. snprintf((char *)&engine_data.engine_brand[4],4,"%d",(int)geely_data.engine_ver);
  581. engine_data.engine_sn = geely_data.engine_sn[0] * 10000000 + geely_data.engine_sn[1] * 100000 +
  582. geely_data.engine_sn[2] * 1000 + geely_data.engine_sn[3];
  583. engine_data.engine_lockstatus = geely_data.engine_control;
  584. engine_data.engine_fault = geely_data.engine_fault;
  585. }
  586. else
  587. {
  588. if(geely_data2.engine_brand[0] == 'B' && geely_data2.engine_brand[1] =='R' && geely_data2.engine_brand[2] =='O')
  589. {
  590. engine_data.engine_type = ENGINE_BRO;
  591. }
  592. engine_data.engine_rev = geely_data2.engine_rev;
  593. engine_data.engine_thr = geely_data2.Bit1EA.engine_ATP1 * 0.05f;
  594. engine_data.engine_vol = geely_data2.engine_vol * 0.1f;
  595. engine_data.engine_elect = (short)(geely_data2.engine_elect * 0.05f - 400) * 10;
  596. engine_data.engine_rtime = geely_data2.engine_runtime;
  597. engine_data.engine_tcd = geely_data2.engine_tcd;
  598. engine_data.engine_lcd = geely_data2.engine_tlock;
  599. engine_data.engine_rsta = geely_data2.engine_state;
  600. engine_data.engine_warn = geely_data2.EmgST0;
  601. engine_data.engine_roil = geely_data2.GPS * 0.5f;
  602. engine_data.engine_cyl1temp = geely_data2.engine_cooltemp - 40;
  603. engine_data.engine_cyl2temp = geely_data2. engine_cooltemp1 - 40;
  604. engine_data.engine_pcbtemp = geely_data2.engine_GWT - 40;
  605. memcpy(engine_data.engine_brand, geely_data2.engine_brand, 3);
  606. memcpy(&engine_data.engine_brand[3],"-", 1);
  607. snprintf((char *)&engine_data.engine_brand[4],4,"%d",(int)geely_data2.engine_ver);
  608. engine_data.engine_sn = geely_data2.engine_sn[0] * 10000000 + geely_data2.engine_sn[1] * 100000 +
  609. geely_data2.engine_sn[2] * 1000 + geely_data2.engine_sn[3];
  610. //engine_data.engine_lockstatus = geely_data2.engine_state == 0? 0 : 1;
  611. engine_data.engine_lockstatus = geely_data2.engine_controlcmd;
  612. //engine_data.engine_fault = geely_data2.engine_fault;
  613. }
  614. }
  615. else
  616. {
  617. if (engine_link_status == COMP_NORMAL)
  618. {
  619. engine_link_status = COMP_LOST;
  620. memset(&engine_data, 0, sizeof(engine_data));
  621. //状态未置异常
  622. engine_data.engine_type = 0xFF;
  623. }
  624. }
  625. }
  626. /******************void engine_function(void)********************
  627. * ****************发动机检测函数*********************************
  628. * **************************************************************/
  629. void engine_function(void)
  630. {
  631. static uint32_t engine_time = 0;
  632. if(Check_Timer_Ready(&engine_time,_10_HZ_))
  633. {
  634. update_engine_data();
  635. //发送飞控状态给发动机
  636. send_msg_to_vk3();
  637. }
  638. //给吉利发动机发送信息
  639. send_msg_to_geely();
  640. }