soft_engine.c 24 KB

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