BleCanProtocolFunc.c 27 KB

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