BleCanProtocolFunc.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999
  1. /*
  2. * @Author : ChenJie
  3. * @Date : 2021-12-20 14:47:39
  4. * @Version : V3.0
  5. * @LastEditors : ChenJie
  6. * @LastEditTime : 2022-05-09 17:13:09
  7. * @Description : file content
  8. * @FilePath : \VehicleControl\VehicleControl\src\System\Vehicle\Communication\BleCanProtocolFunc.c
  9. */
  10. /*
  11. * CanProtocol.c
  12. * can协议转换
  13. * Created on: 2021年12月20日
  14. * Author: QiXiang_CHENJIE
  15. */
  16. #include "BleCanProtocolFunc.h"
  17. #include "HardwareLib.h"
  18. /**
  19. * @brief : EBC对ble的命令应答,AT指令,EBC(0x1CEE000X)->BLE(0x1CEF0000X)
  20. * @param {uint8} CmdIdx
  21. * @return {*}
  22. */
  23. void Can2EncodeFunction(UINT32 ID, UINT8 *rawData)
  24. {
  25. uint8 Crc = 0;
  26. static uint8 lifeTime = 0;
  27. switch(ID)
  28. {
  29. case 0x1C00EBEC:
  30. {
  31. lifeTime = lifeTime+1<15? lifeTime+1 : 0;
  32. *(rawData + 1) = lifeTime;
  33. *(rawData + 2) = rted_st_bleConnCtrlCmd;
  34. *(rawData + 3) = rted_st_blePwrCtrlCmd;
  35. *(rawData + 4) = rted_st_wifiConnCtrlCmd;
  36. *(rawData + 5) = rted_st_wifiPwrCtrlCmd;
  37. *(rawData + 6) = 0;
  38. *(rawData + 7) = 0;
  39. for(uint8 i=1;i<8;i++)
  40. {
  41. Crc = Crc^(*(rawData + i));
  42. }
  43. *(rawData + 0) = Crc;
  44. break;
  45. }
  46. case 0x1C01EBEC:
  47. {
  48. *(rawData + 0) = rted_st_ebcWorkMode;
  49. *(rawData + 1) = rted_st_ebcCommMode;
  50. *(rawData + 2) = rted_st_ebcManuMode;
  51. *(rawData + 3) = rted_st_ebcPlugType;
  52. *(rawData + 4) = rted_flg_ebcAllWOper;
  53. *(rawData + 5) = 0;
  54. *(rawData + 6) = 0;
  55. *(rawData + 7) = 0;
  56. break;
  57. }
  58. case 0x1C02EBEC:
  59. {
  60. break;
  61. }
  62. case 0x1C12EBEC:
  63. {
  64. break;
  65. }
  66. case 0x1C03EBEC:
  67. {
  68. break;
  69. }
  70. case 0x1C04EBEC:
  71. {
  72. break;
  73. }
  74. case 0x1C05EBEC:
  75. {
  76. break;
  77. }
  78. case 0x1C06EBEC:
  79. {
  80. break;
  81. }
  82. case 0x1C07EBEC:
  83. {
  84. break;
  85. }
  86. case 0x1C08EBEC:
  87. {
  88. break;
  89. }
  90. case 0x1C09EBEC:
  91. {
  92. break;
  93. }
  94. case 0x1C0AEBEC:
  95. {
  96. break;
  97. }
  98. case 0x1C0BEBEC:
  99. {
  100. break;
  101. }
  102. case 0x1C0CEBEC:
  103. {
  104. break;
  105. }
  106. case 0x1C0DEBEC:
  107. {
  108. break;
  109. }
  110. case 0x1C0EEBEC:
  111. {
  112. break;
  113. }
  114. default:
  115. break;
  116. }
  117. }
  118. /**
  119. * @brief : ebc对ble的数据应答,Ebc data ->Ble data
  120. * @param {*}
  121. * @return {*}
  122. */
  123. void Can2DataCode(uint8 DataIdx, uint8 Byte0Num, uint8 Data[])
  124. {
  125. switch (DataIdx)
  126. {
  127. case 0x01: //主机数据类型1的应答
  128. {
  129. Data[0] = 0x11;
  130. Data[1] = ebcd_st_ebcWork;
  131. Data[2] = ebcd_st_ebcConnect;
  132. Data[3] = ebcd_st_ebcLockWork;
  133. Data[4] = 0x00;
  134. Data[5] = 0x00;
  135. Data[6] = 0x00;
  136. Data[7] = 0x00;
  137. break;
  138. }
  139. case 0x02: //主机数据类型2的应答 共7条
  140. {
  141. switch (Byte0Num)
  142. {
  143. case 0x21:
  144. {
  145. vcud_st_keyOn = BattCD_stWakeupU.B.bLogic;
  146. bcud_st_bcuTmsLiquid = 0; // TBD
  147. ebcd_flg_pluginLockSig = m_flg_HVlock1 && m_flg_HVlock2;
  148. Data[0] = Byte0Num;
  149. Data[1] = ebcd_st_unlockSensor;
  150. Data[2] = ebcd_st_lockSensor;
  151. Data[3] = vcud_st_keyOn;
  152. Data[4] = ebcd_P_airSensor;
  153. Data[5] = bcud_st_bcuTmsLiquid;
  154. Data[6] = ebcd_flg_pluginLockSig;
  155. Data[7] = 0x00;
  156. break;
  157. }
  158. case 0x22:
  159. {
  160. ebcd_st_pluginLockSig = (m_flg_HVlock2 << 2) | (m_flg_HVlock1 << 1) | (m_flg_HVlock1 << 1);
  161. Data[0] = Byte0Num;
  162. Data[1] = 0x00;
  163. Data[2] = 0x00;
  164. Data[3] = 0x00;
  165. Data[4] = 0x00;
  166. Data[5] = ebcd_st_pedstSensor;
  167. Data[6] = ebcd_st_pluginLockSig;
  168. Data[7] = 0x00;
  169. break;
  170. }
  171. case 0x23:
  172. {
  173. Data[0] = Byte0Num;
  174. Data[1] = ebcd_st_unlockSucJug;
  175. Data[2] = ebcd_st_lockSucJug;
  176. Data[3] = 0x00;
  177. Data[4] = 0x00;
  178. Data[5] = 0x00;
  179. Data[6] = 0x00;
  180. Data[7] = 0x00;
  181. break;
  182. }
  183. case 0x24:
  184. {
  185. Data[0] = Byte0Num;
  186. Data[1] = 0x00;
  187. Data[2] = 0x00;
  188. Data[3] = 0x00;
  189. Data[4] = 0x00;
  190. Data[5] = ebcd_st_pedstSucJug;
  191. Data[6] = ebcd_flg_swapAdmit;
  192. Data[7] = 0x00;
  193. break;
  194. }
  195. case 0x25:
  196. {
  197. Data[0] = Byte0Num;
  198. Data[1] = ebcd_st_ebcWork;
  199. Data[2] = ebcd_st_ebcConnect;
  200. Data[3] = ebcd_st_ebcLockWork;
  201. Data[4] = ebcd_Nr_errMax;
  202. Data[5] = ebcd_Num_err1;
  203. Data[6] = ebcd_Num_err2;
  204. Data[7] = 0x00;
  205. break;
  206. }
  207. case 0x26:
  208. {
  209. Data[0] = Byte0Num;
  210. Data[1] = (ebcd_Nr_swapBatt >> 8) & 0xFF;
  211. Data[2] = ebcd_Nr_swapBatt & 0xFF;
  212. Data[3] = (ebcd_Nr_swapSucBatt >> 8) & 0xFF;
  213. Data[4] = ebcd_Nr_swapSucBatt;
  214. Data[5] = 0x00;
  215. Data[6] = 0x00;
  216. Data[7] = 0x00;
  217. break;
  218. }
  219. case 0x27:
  220. {
  221. Data[0] = Byte0Num;
  222. Data[1] = ebcd_st_errTable1;
  223. Data[2] = ebcd_st_errTable2;
  224. Data[3] = ebcd_st_errTable3;
  225. Data[4] = 0x00;
  226. Data[5] = 0x00;
  227. Data[6] = 0x00;
  228. Data[7] = 0x00;
  229. break;
  230. }
  231. default:
  232. break;
  233. }
  234. break;
  235. }
  236. case 0x03: //主机数据类型3的应答 共5条
  237. {
  238. vcud_st_handbrake = VCU_St_ParkBrakeSw;
  239. vcud_st_footbrake = (VCU_St_BrakePedal > 0);
  240. vcud_st_gear = VCU_St_Gear;
  241. vcud_st_vcuComun = (VcuRxLongError[0] != 1);
  242. vcud_st_carStart = VCU_State_Veh;
  243. vcud_st_Steer = 0x00; // TBD
  244. vcud_M_accDrv = 0 * 10; // TBD
  245. if (VCU_St_VinRecv == 0x07)
  246. {
  247. memcpy(vcuv_Num_vin, VCU_Num_VIN, 17);
  248. }
  249. switch (Byte0Num)
  250. {
  251. case 0x31:
  252. {
  253. Data[0] = Byte0Num;
  254. Data[1] = vcud_st_handbrake;
  255. Data[2] = vcud_st_footbrake;
  256. Data[3] = vcud_st_gear;
  257. Data[4] = vcud_st_vcuComun;
  258. Data[5] = vcud_st_carStart;
  259. Data[6] = vcud_st_Steer;
  260. Data[7] = 0x00;
  261. break;
  262. }
  263. case 0x32:
  264. {
  265. Data[0] = Byte0Num;
  266. Data[1] = vcuv_Num_vin[0];
  267. Data[2] = vcuv_Num_vin[1];
  268. Data[3] = vcuv_Num_vin[2];
  269. Data[4] = vcuv_Num_vin[3];
  270. Data[5] = vcuv_Num_vin[4];
  271. Data[6] = vcuv_Num_vin[5];
  272. Data[7] = 0x00;
  273. break;
  274. }
  275. case 0x33:
  276. {
  277. Data[0] = Byte0Num;
  278. Data[1] = vcuv_Num_vin[6];
  279. Data[2] = vcuv_Num_vin[7];
  280. Data[3] = vcuv_Num_vin[8];
  281. Data[4] = vcuv_Num_vin[9];
  282. Data[5] = vcuv_Num_vin[10];
  283. Data[6] = vcuv_Num_vin[11];
  284. Data[7] = 0x00;
  285. break;
  286. }
  287. case 0x34:
  288. {
  289. Data[0] = Byte0Num;
  290. Data[1] = vcuv_Num_vin[12];
  291. Data[2] = vcuv_Num_vin[13];
  292. Data[3] = vcuv_Num_vin[14];
  293. Data[4] = vcuv_Num_vin[15];
  294. Data[5] = vcuv_Num_vin[16];
  295. Data[6] = 0x00;
  296. Data[7] = 0x00;
  297. break;
  298. }
  299. case 0x35:
  300. {
  301. Data[0] = Byte0Num;
  302. Data[1] = (vcud_M_accDrv >> 24) & 0xFF;
  303. Data[2] = (vcud_M_accDrv >> 16) & 0xFF;
  304. Data[3] = (vcud_M_accDrv >> 8) & 0xFF;
  305. Data[4] = (vcud_M_accDrv)&0xFF;
  306. Data[5] = vcud_P_airSensorForward;
  307. Data[6] = vcud_P_airSensorBack;
  308. Data[7] = 0x00;
  309. break;
  310. }
  311. default:
  312. break;
  313. }
  314. break;
  315. }
  316. case 0x04: //主机数据类型4的应答 共16条
  317. {
  318. bcud_st_bcuComun = (BcuRxLongError[4] != 0x01);
  319. bcud_pct_bcuSoh = BMS_PackSOH;
  320. bcud_V_battU = BMS_BattVolt;
  321. if (BMS_Mode == 2)
  322. {
  323. bcud_st_hvWork = 2;
  324. }
  325. else if (BMS_Mode == 1)
  326. {
  327. bcud_st_hvWork = 0;
  328. }
  329. else
  330. {
  331. bcud_st_hvWork = 3;
  332. }
  333. bcud_st_bcuMainRelay = BMS_StPosRly;
  334. bcud_pct_soc = (UINT16)(BMS_PackSOC * 4);
  335. memcpy(bcuv_Num_battSn, BMS_SN, sizeof(BMS_SN));
  336. bcud_Q_snglChrg = BMS_SingleCharCapy;
  337. bcud_E_snglChrg = BMS_SingleCharEngy;
  338. bcud_Q_accRecovry = BMS_TotalBackCharCapy;
  339. bcud_E_accRecovry = BMS_TotalBackCharEngy;
  340. bcud_Q_accSwapBatt = BMS_TotalStaCharCapy;
  341. bcud_E_accSwapBatt = BMS_TotalStaCharEngy;
  342. bcud_Q_accPlugInChrg = BMS_TotalGunCharCapy;
  343. bcud_E_accPlugInChrg = BMS_TotalGunCharEngy;
  344. bcud_Q_accDischrg = BMS_TotalDisCharCapy;
  345. bcud_E_accDischrg = BMS_TotalDisCharEngy;
  346. bcud_Q_accChrg = BMS_TotalCharCapy;
  347. bcud_E_accChrg = BMS_TotalCharEngy;
  348. switch (Byte0Num)
  349. {
  350. case 0x40:
  351. {
  352. Data[0] = Byte0Num;
  353. Data[1] = (bcud_E_accPlugInChrg >> 24) & 0xFF;
  354. Data[2] = (bcud_E_accPlugInChrg >> 16) & 0xFF;
  355. Data[3] = (bcud_E_accPlugInChrg >> 8) & 0xFF;
  356. Data[4] = (bcud_E_accPlugInChrg)&0xFF;
  357. Data[5] = 0x00;
  358. Data[6] = 0x00;
  359. Data[7] = 0x00;
  360. break;
  361. }
  362. case 0x41:
  363. {
  364. Data[0] = Byte0Num;
  365. Data[1] = (bcud_Q_accChrg >> 24) & 0xFF;
  366. Data[2] = (bcud_Q_accChrg >> 16) & 0xFF;
  367. Data[3] = (bcud_Q_accChrg >> 8) & 0xFF;
  368. Data[4] = (bcud_Q_accChrg)&0xFF;
  369. Data[5] = bcud_st_bcuComun;
  370. Data[6] = bcud_st_hvWork;
  371. Data[7] = 0x00;
  372. break;
  373. }
  374. case 0x42:
  375. {
  376. Data[0] = Byte0Num;
  377. Data[1] = (bcud_Q_accDischrg >> 24) & 0xFF;
  378. Data[2] = (bcud_Q_accDischrg >> 16) & 0xFF;
  379. Data[3] = (bcud_Q_accDischrg >> 8) & 0xFF;
  380. Data[4] = (bcud_Q_accDischrg)&0xFF;
  381. Data[5] = bcud_st_bcuMainRelay;
  382. Data[6] = bcud_pct_bcuSoh;
  383. Data[7] = 0x00;
  384. break;
  385. }
  386. case 0x43:
  387. {
  388. Data[0] = Byte0Num;
  389. Data[1] = (bcud_E_accChrg >> 24) & 0xFF;
  390. Data[2] = (bcud_E_accChrg >> 16) & 0xFF;
  391. Data[3] = (bcud_E_accChrg >> 8) & 0xFF;
  392. Data[4] = (bcud_E_accChrg)&0xFF;
  393. Data[5] = (bcud_V_battU >> 8) & 0xFF;
  394. Data[6] = (bcud_V_battU)&0xFF;
  395. Data[7] = 0x00;
  396. break;
  397. }
  398. case 0x44:
  399. {
  400. Data[0] = Byte0Num;
  401. Data[1] = (bcud_E_accDischrg >> 24) & 0xFF;
  402. Data[2] = (bcud_E_accDischrg >> 16) & 0xFF;
  403. Data[3] = (bcud_E_accDischrg >> 8) & 0xFF;
  404. Data[4] = (bcud_E_accDischrg)&0xFF;
  405. Data[5] = (bcud_pct_soc >> 8) & 0xFF;
  406. Data[6] = (bcud_pct_soc)&0xFF;
  407. Data[7] = 0x00;
  408. break;
  409. }
  410. case 0x45:
  411. {
  412. Data[0] = Byte0Num;
  413. Data[1] = bcuv_Num_battSn[0];
  414. Data[2] = bcuv_Num_battSn[1];
  415. Data[3] = bcuv_Num_battSn[2];
  416. Data[4] = bcuv_Num_battSn[3];
  417. Data[5] = bcuv_Num_battSn[4];
  418. Data[6] = bcuv_Num_battSn[5];
  419. Data[7] = 0x00;
  420. break;
  421. }
  422. case 0x46:
  423. {
  424. Data[0] = Byte0Num;
  425. Data[1] = bcuv_Num_battSn[6];
  426. Data[2] = bcuv_Num_battSn[7];
  427. Data[3] = bcuv_Num_battSn[8];
  428. Data[4] = bcuv_Num_battSn[9];
  429. Data[5] = bcuv_Num_battSn[10];
  430. Data[6] = bcuv_Num_battSn[11];
  431. Data[7] = 0x00;
  432. break;
  433. }
  434. case 0x47:
  435. {
  436. Data[0] = Byte0Num;
  437. Data[1] = bcuv_Num_battSn[12];
  438. Data[2] = bcuv_Num_battSn[13];
  439. Data[3] = bcuv_Num_battSn[14];
  440. Data[4] = bcuv_Num_battSn[15];
  441. Data[5] = bcuv_Num_battSn[16];
  442. Data[6] = bcuv_Num_battSn[17];
  443. Data[7] = 0x00;
  444. break;
  445. }
  446. case 0x48:
  447. {
  448. Data[0] = Byte0Num;
  449. Data[1] = bcuv_Num_battSn[18];
  450. Data[2] = bcuv_Num_battSn[19];
  451. Data[3] = bcuv_Num_battSn[20];
  452. Data[4] = bcuv_Num_battSn[21];
  453. Data[5] = bcuv_Num_battSn[22];
  454. Data[6] = bcuv_Num_battSn[23];
  455. Data[7] = 0x00;
  456. break;
  457. }
  458. case 0x49:
  459. {
  460. Data[0] = Byte0Num;
  461. Data[1] = bcuv_Num_battSn[24];
  462. Data[2] = bcuv_Num_battSn[25];
  463. Data[3] = bcuv_Num_battSn[26];
  464. Data[4] = bcuv_Num_battSn[27];
  465. Data[5] = bcuv_Num_battSn[28];
  466. Data[6] = bcuv_Num_battSn[29];
  467. Data[7] = 0x00;
  468. break;
  469. }
  470. case 0x4A:
  471. {
  472. Data[0] = Byte0Num;
  473. Data[1] = bcuv_Num_battSn[30];
  474. Data[2] = bcuv_Num_battSn[31];
  475. Data[3] = 0x00;
  476. Data[4] = 0x00;
  477. Data[5] = 0x00;
  478. Data[6] = 0x00;
  479. Data[7] = 0x00;
  480. break;
  481. }
  482. case 0x4B:
  483. {
  484. Data[0] = Byte0Num;
  485. Data[1] = (bcud_Q_snglChrg >> 8) & 0xFF;
  486. Data[2] = (bcud_Q_snglChrg)&0xFF;
  487. Data[3] = (bcud_Q_accRecovry >> 24) & 0xFF;
  488. Data[4] = (bcud_Q_accRecovry >> 16) & 0xFF;
  489. Data[5] = (bcud_Q_accRecovry >> 8) & 0xFF;
  490. Data[6] = (bcud_Q_accRecovry)&0xFF;
  491. Data[7] = 0x00;
  492. break;
  493. }
  494. case 0x4C:
  495. {
  496. Data[0] = Byte0Num;
  497. Data[1] = (bcud_Q_accSwapBatt >> 24) & 0xFF;
  498. Data[2] = (bcud_Q_accSwapBatt >> 16) & 0xFF;
  499. Data[3] = (bcud_Q_accSwapBatt >> 8) & 0xFF;
  500. Data[4] = (bcud_Q_accSwapBatt)&0xFF;
  501. Data[5] = 0x00;
  502. Data[6] = 0x00;
  503. Data[7] = 0x00;
  504. break;
  505. }
  506. case 0x4D:
  507. {
  508. Data[0] = Byte0Num;
  509. Data[1] = (bcud_E_snglChrg >> 8) & 0xFF;
  510. Data[2] = (bcud_E_snglChrg)&0xFF;
  511. Data[3] = (bcud_E_accRecovry >> 24) & 0xFF;
  512. Data[4] = (bcud_E_accRecovry >> 16) & 0xFF;
  513. Data[5] = (bcud_E_accRecovry >> 8) & 0xFF;
  514. Data[6] = (bcud_E_accRecovry)&0xFF;
  515. Data[7] = 0x00;
  516. break;
  517. }
  518. case 0x4E:
  519. {
  520. Data[0] = Byte0Num;
  521. Data[1] = (bcud_E_accSwapBatt >> 24) & 0xFF;
  522. Data[2] = (bcud_E_accSwapBatt >> 16) & 0xFF;
  523. Data[3] = (bcud_E_accSwapBatt >> 8) & 0xFF;
  524. Data[4] = (bcud_E_accSwapBatt)&0xFF;
  525. Data[5] = 0x00;
  526. Data[6] = 0x00;
  527. Data[7] = 0x00;
  528. break;
  529. }
  530. case 0x4F:
  531. {
  532. Data[0] = Byte0Num;
  533. Data[1] = (bcud_Q_accPlugInChrg >> 24) & 0xFF;
  534. Data[2] = (bcud_Q_accPlugInChrg >> 16) & 0xFF;
  535. Data[3] = (bcud_Q_accPlugInChrg >> 8) & 0xFF;
  536. Data[4] = (bcud_Q_accPlugInChrg)&0xFF;
  537. Data[5] = 0x00;
  538. Data[6] = 0x00;
  539. Data[7] = 0x00;
  540. break;
  541. }
  542. default:
  543. break;
  544. }
  545. break;
  546. }
  547. case 0x05:
  548. {
  549. Data[0] = 0x51;
  550. Data[1] = 0x00;
  551. Data[2] = 0x00;
  552. Data[3] = 0x00;
  553. Data[4] = 0x00;
  554. Data[5] = 0x00;
  555. Data[6] = 0x00;
  556. Data[7] = 0x00;
  557. break;
  558. }
  559. default:
  560. Data[0] = 0x00;
  561. Data[1] = 0x00;
  562. Data[2] = 0x00;
  563. Data[3] = 0x00;
  564. Data[4] = 0x00;
  565. Data[5] = 0x00;
  566. Data[6] = 0x00;
  567. Data[7] = 0x00;
  568. break;
  569. }
  570. }
  571. /**
  572. * @brief : Ebc通过Can2接受到的协议解码
  573. * @param {uint8} CmdIdx
  574. * @return {*}
  575. */
  576. void Can2ProtocolDecode(uint32 Can2ID, uint8 Data[])
  577. {
  578. switch (Can2ID)
  579. {
  580. case 0x1CEF0000:
  581. {
  582. Can2DataDecode(Data);
  583. bled_flg_bleConn = 1;
  584. bled_flg_bleDisconn = 0;
  585. bled_st_dataTrans = 1;
  586. break;
  587. }
  588. case 0x1CEF0001:
  589. {
  590. bled_Nr_softVer = (Data[0] << 24) | (Data[1] << 16) | (Data[2] << 8) | (Data[3]);
  591. break;
  592. }
  593. case 0x1CEF0002:
  594. {
  595. if (Data[0] == 0x01 && Data[1] == 0x01)
  596. {
  597. bled_flg_bleConn = 1;
  598. bled_flg_bleDisconn = 0;
  599. }
  600. else if (Data[0] == 0x01 && Data[1] == 0x02)
  601. {
  602. bled_flg_bleConn = 0;
  603. bled_flg_bleDisconn = 1;
  604. }
  605. break;
  606. }
  607. case 0x1C00ECEA: // UDS检测ID
  608. {
  609. Uds_Service(Data);
  610. break;
  611. }
  612. default:
  613. break;
  614. }
  615. }
  616. /**
  617. * @brief : Ebc通过can2接收到的数据解码,Ble->Ebc
  618. * @param {*}
  619. * @return {*}
  620. */
  621. void Can2DataDecode(uint8 Data[])
  622. {
  623. uint8 CmdIndex = Data[0];
  624. ebcd_st_toBleAns = CmdIndex;
  625. ebcd_flg_Can2SendEnbale = TRUE; //所有的信息均立即回复
  626. switch (CmdIndex)
  627. {
  628. case 0x01: //心跳数据,为了维持通讯
  629. {
  630. bled_flg_Heart = 1;
  631. ebcd_flg_Can2SendEnbale = TRUE;
  632. break;
  633. }
  634. case 0x02: //获取换电控制器信息
  635. {
  636. bled_flg_getEbcData = 1;
  637. ebcd_flg_Can2SendEnbale = TRUE;
  638. break;
  639. }
  640. case 0x03: //获得车辆信息
  641. {
  642. bled_flg_getVcuData = 1;
  643. ebcd_flg_Can2SendEnbale = TRUE;
  644. break;
  645. }
  646. case 0x04: //获取电池信息
  647. {
  648. bled_flg_getBmsData = 1;
  649. ebcd_flg_Can2SendEnbale = TRUE;
  650. break;
  651. }
  652. case 0x05: //握手
  653. {
  654. bled_flg_handShake = 1;
  655. ebcd_flg_Can2SendEnbale = TRUE;
  656. break;
  657. }
  658. case 0x06: //解锁
  659. {
  660. bled_flg_unlockCmd = Data[1];
  661. bled_flg_lockCmd = 0;
  662. break;
  663. }
  664. case 0x07: //锁紧
  665. {
  666. bled_flg_lockCmd = Data[1];
  667. bled_flg_unlockCmd = 0;
  668. break;
  669. }
  670. case 0x08: //完成换电
  671. {
  672. bled_flg_swapBattDone = 1;
  673. break;
  674. }
  675. case 0x09: //强制解锁,强制上升
  676. {
  677. bled_flg_unlockCmdForce = Data[1];
  678. bled_flg_topAscendCmdForce = Data[2];
  679. break;
  680. }
  681. case 0x0A: //强制锁紧,强制下降
  682. {
  683. bled_flg_lockCmdForce = Data[1];
  684. bled_flg_topDescendCmdForce = Data[2];
  685. break;
  686. }
  687. case 0x0B: //回到行车状态
  688. {
  689. bled_flg_backToDrv = 1;
  690. break;
  691. }
  692. case 0x0C: //顶板举升
  693. {
  694. bled_flg_topAscendCmd = Data[1];
  695. break;
  696. }
  697. case 0x0D: //顶板下降
  698. {
  699. bled_flg_topDescendCmd = Data[1];
  700. break;
  701. }
  702. case 0x0E: //换电开始自动解锁
  703. {
  704. bled_flg_autoUnlock = 1;
  705. break;
  706. }
  707. case 0x0F: //换电完成自动锁紧
  708. {
  709. bled_flg_autoLock = 1;
  710. break;
  711. }
  712. case 0x10: //除尘开始
  713. {
  714. bled_flg_openDustReCmd = 1;
  715. break;
  716. }
  717. case 0x11: //除尘关闭
  718. {
  719. bled_flg_closeDustReCmd = 1;
  720. break;
  721. }
  722. case 0x12: //切换到无线通信状态
  723. {
  724. break;
  725. }
  726. case 0x13: //进入换电状态
  727. {
  728. bled_flg_toSwapMod = 1;
  729. break;
  730. }
  731. case 0x14: //急停指令
  732. {
  733. bled_flg_safeStopCmd = 1;
  734. break;
  735. } //新增需要改数组
  736. default:
  737. break;
  738. }
  739. }
  740. static uint8 udsMode = 0; // uds 模式
  741. uint32 EbcAppSw = 0x00000101;
  742. void Uds_Service(uint8 *Data)
  743. {
  744. UdsAnsType UdsAns;
  745. memset((uint8 *)&UdsAns, 0x00, sizeof(UdsAns));
  746. UdsAns.UdsSer = *(Data + 0);
  747. UdsAns.UdsSubSer = *(Data + 1);
  748. switch (UdsAns.UdsSer)
  749. {
  750. case 0x10: //模式选择
  751. {
  752. if (*(Data + 1) == 0x01)
  753. {
  754. udsMode = 1;
  755. UdsPosAns(UdsAns);
  756. }
  757. else if (*(Data + 1) == 0x02)
  758. {
  759. if (udsMode == 1 || udsMode == 2)
  760. {
  761. udsMode = 2;
  762. UdsPosAns(UdsAns);
  763. }
  764. else
  765. {
  766. udsMode = 0;
  767. UdsNegAns(UdsAns);
  768. }
  769. }
  770. else
  771. {
  772. udsMode = 0;
  773. UdsNegAns(UdsAns);
  774. }
  775. break;
  776. }
  777. case 0x22: //查询
  778. {
  779. if (udsMode == 2)
  780. {
  781. switch (UdsAns.UdsSubSer)
  782. {
  783. case 0x01: //版本号查询
  784. {
  785. UdsAns.Seq = 0;
  786. UdsAns.Data1 = EbcAppSw >> 24;
  787. UdsAns.Data2 = EbcAppSw >> 16;
  788. UdsAns.Data3 = EbcAppSw >> 8;
  789. UdsAns.Data4 = EbcAppSw;
  790. UdsPosAns(UdsAns);
  791. break;
  792. }
  793. case 0x02: //解锁状态查询
  794. {
  795. UdsAns.Seq = 0;
  796. UdsAns.Data1 = ebcd_st_unlockSensor;
  797. UdsAns.Data2 = 0x00;
  798. UdsAns.Data3 = 0x00;
  799. UdsAns.Data4 = 0x00;
  800. UdsPosAns(UdsAns);
  801. break;
  802. }
  803. case 0x03: //锁紧状态查询
  804. {
  805. UdsAns.Seq = 0;
  806. UdsAns.Data1 = ebcd_st_lockSensor;
  807. UdsAns.Data2 = 0x00;
  808. UdsAns.Data3 = 0x00;
  809. UdsAns.Data4 = 0x00;
  810. UdsPosAns(UdsAns);
  811. break;
  812. }
  813. case 0x04: //落座状态查询
  814. {
  815. UdsAns.Seq = 0;
  816. UdsAns.Data1 = ebcd_st_pedstSensor;
  817. UdsAns.Data2 = 0x00;
  818. UdsAns.Data3 = 0x00;
  819. UdsAns.Data4 = 0x00;
  820. UdsPosAns(UdsAns);
  821. break;
  822. }
  823. case 0x05: //互锁状态查询
  824. {
  825. UdsAns.Seq = 0;
  826. UdsAns.Data1 = ((m_flg_HVlock1 & 0x01) << 1) | (m_flg_HVlock2 & 0x01);
  827. UdsAns.Data2 = 0x00;
  828. UdsAns.Data3 = 0x00;
  829. UdsAns.Data4 = 0x00;
  830. UdsPosAns(UdsAns);
  831. break;
  832. }
  833. case 0x06: //气压值查询
  834. {
  835. UdsAns.Seq = 0;
  836. UdsAns.Data1 = ebcd_P_airSensor;
  837. UdsAns.Data2 = 0x00;
  838. UdsAns.Data3 = 0x00;
  839. UdsAns.Data4 = 0x00;
  840. UdsPosAns(UdsAns);
  841. break;
  842. }
  843. case 0x07: //锁紧压力查询
  844. {
  845. UdsAns.Seq = 0;
  846. UdsAns.Data1 = Test_LockPressure >> 8;
  847. UdsAns.Data2 = Test_LockPressure;
  848. UdsAns.Data3 = 0x00;
  849. UdsAns.Data4 = 0x00;
  850. UdsPosAns(UdsAns);
  851. break;
  852. }
  853. case 0x08: //锁紧次数查询
  854. {
  855. UdsAns.Seq = 0;
  856. UdsAns.Data1 = ManuControlTimes >> 8;
  857. UdsAns.Data2 = ManuControlTimes;
  858. UdsAns.Data3 = 0x00;
  859. UdsAns.Data4 = 0x00;
  860. UdsPosAns(UdsAns);
  861. break;
  862. }
  863. case 0x09: //温度数据查询
  864. {
  865. UdsAns.Seq = 0;
  866. UdsAns.Data1 = ebcd_T_plugin[0];
  867. UdsAns.Data2 = ebcd_T_plugin[1];
  868. UdsAns.Data3 = ebcd_T_plugin[2];
  869. UdsAns.Data4 = ebcd_T_plugin[3];
  870. UdsPosAns(UdsAns);
  871. break;
  872. }
  873. default:
  874. UdsNegAns(UdsAns);
  875. break;
  876. }
  877. }
  878. else
  879. {
  880. UdsNegAns(UdsAns);
  881. }
  882. break;
  883. }
  884. case 0x27: //控制
  885. {
  886. if (udsMode == 2)
  887. {
  888. switch (UdsAns.UdsSubSer)
  889. {
  890. case 0x01: //循环测试开启
  891. {
  892. ebcd_flg_ebcManCtrlEn = 1;
  893. ebcd_flg_ebcManCtrlMode = 1;
  894. UdsPosAns(UdsAns);
  895. break;
  896. }
  897. case 0x02:
  898. {
  899. ebcd_flg_ebcManCtrlEn = 1;
  900. ebcd_flg_ebcManCtrlMode = 2;
  901. UdsPosAns(UdsAns);
  902. break;
  903. }
  904. case 0x03:
  905. {
  906. ebcd_flg_ebcManCtrlEn = 1;
  907. ebcd_flg_ebcManCtrlMode = 3;
  908. UdsPosAns(UdsAns);
  909. break;
  910. }
  911. case 0x04:
  912. {
  913. ebcd_flg_ebcManCtrlEn = 0;
  914. UdsPosAns(UdsAns);
  915. break;
  916. }
  917. default:
  918. UdsNegAns(UdsAns);
  919. break;
  920. }
  921. }
  922. else
  923. {
  924. UdsNegAns(UdsAns);
  925. }
  926. break;
  927. }
  928. case 0x2E: //写入
  929. {
  930. if (udsMode == 2)
  931. {
  932. switch (UdsAns.UdsSubSer)
  933. {
  934. case 0x01:
  935. {
  936. LockDelayTime = (*(Data + 4) << 8) | *(Data + 5);
  937. UdsPosAns(UdsAns);
  938. EEPROMDrv_bSaveInstantUB = 1;
  939. break;
  940. }
  941. case 0x02:
  942. {
  943. UnlockDelayTime = (*(Data + 4) << 8) | *(Data + 5);
  944. UdsPosAns(UdsAns);
  945. EEPROMDrv_bSaveInstantUB = 1;
  946. break;
  947. }
  948. default:
  949. UdsNegAns(UdsAns);
  950. break;
  951. }
  952. }
  953. else
  954. {
  955. UdsNegAns(UdsAns);
  956. }
  957. break;
  958. }
  959. default:
  960. break;
  961. }
  962. }
  963. void UdsPosAns(UdsAnsType UdsAnsData)
  964. {
  965. MCANDrv_infoMsgS_TYPE infoMsgS;
  966. infoMsgS.infoConfS.infoMsgParU.B.CAN = 2;
  967. infoMsgS.infoConfS.infoMsgParU.B.DIR = _MCAN_DIR_TX;
  968. infoMsgS.infoConfS.infoMsgParU.B.DLC = 8;
  969. infoMsgS.infoConfS.infoMsgParU.B.IDE = _MCAN_IDE_EXT;
  970. infoMsgS.infoConfS.infoMsgIDUI = 0x1C00EAECUL;
  971. infoMsgS.datMsgUBA[0] = 0x78;
  972. infoMsgS.datMsgUBA[1] = UdsAnsData.UdsSer;
  973. infoMsgS.datMsgUBA[2] = UdsAnsData.UdsSubSer;
  974. infoMsgS.datMsgUBA[3] = UdsAnsData.Seq;
  975. infoMsgS.datMsgUBA[4] = UdsAnsData.Data1;
  976. infoMsgS.datMsgUBA[5] = UdsAnsData.Data2;
  977. infoMsgS.datMsgUBA[6] = UdsAnsData.Data3;
  978. infoMsgS.datMsgUBA[7] = UdsAnsData.Data4;
  979. MCANDrv_SendMsg(infoMsgS);
  980. }
  981. void UdsNegAns(UdsAnsType UdsAnsData)
  982. {
  983. MCANDrv_infoMsgS_TYPE infoMsgS;
  984. infoMsgS.infoConfS.infoMsgParU.B.CAN = 2;
  985. infoMsgS.infoConfS.infoMsgParU.B.DIR = _MCAN_DIR_TX;
  986. infoMsgS.infoConfS.infoMsgParU.B.DLC = 8;
  987. infoMsgS.infoConfS.infoMsgParU.B.IDE = _MCAN_IDE_EXT;
  988. infoMsgS.infoConfS.infoMsgIDUI = 0x1C00EAECUL;
  989. infoMsgS.datMsgUBA[0] = 0x7F;
  990. infoMsgS.datMsgUBA[1] = UdsAnsData.UdsSer;
  991. infoMsgS.datMsgUBA[2] = UdsAnsData.UdsSubSer;
  992. infoMsgS.datMsgUBA[3] = 0x00;
  993. infoMsgS.datMsgUBA[4] = 0x00;
  994. infoMsgS.datMsgUBA[5] = 0x00;
  995. infoMsgS.datMsgUBA[6] = 0x00;
  996. infoMsgS.datMsgUBA[7] = 0x00;
  997. MCANDrv_SendMsg(infoMsgS);
  998. }