123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999 |
- /*
- * @Author : ChenJie
- * @Date : 2021-12-20 14:47:39
- * @Version : V3.0
- * @LastEditors : ChenJie
- * @LastEditTime : 2022-05-09 17:13:09
- * @Description : file content
- * @FilePath : \VehicleControl\VehicleControl\src\System\Vehicle\Communication\BleCanProtocolFunc.c
- */
- /*
- * CanProtocol.c
- * can协议转换
- * Created on: 2021年12月20日
- * Author: QiXiang_CHENJIE
- */
- #include "BleCanProtocolFunc.h"
- #include "HardwareLib.h"
- /**
- * @brief : EBC对ble的命令应答,AT指令,EBC(0x1CEE000X)->BLE(0x1CEF0000X)
- * @param {uint8} CmdIdx
- * @return {*}
- */
- void Can2EncodeFunction(UINT32 ID, UINT8 *rawData)
- {
- uint8 Crc = 0;
- static uint8 lifeTime = 0;
- switch(ID)
- {
- case 0x1C00EBEC:
- {
- lifeTime = lifeTime+1<15? lifeTime+1 : 0;
- *(rawData + 1) = lifeTime;
- *(rawData + 2) = rted_st_bleConnCtrlCmd;
- *(rawData + 3) = rted_st_blePwrCtrlCmd;
- *(rawData + 4) = rted_st_wifiConnCtrlCmd;
- *(rawData + 5) = rted_st_wifiPwrCtrlCmd;
- *(rawData + 6) = 0;
- *(rawData + 7) = 0;
- for(uint8 i=1;i<8;i++)
- {
- Crc = Crc^(*(rawData + i));
- }
- *(rawData + 0) = Crc;
- break;
- }
- case 0x1C01EBEC:
- {
- *(rawData + 0) = rted_st_ebcWorkMode;
- *(rawData + 1) = rted_st_ebcCommMode;
- *(rawData + 2) = rted_st_ebcManuMode;
- *(rawData + 3) = rted_st_ebcPlugType;
- *(rawData + 4) = rted_flg_ebcAllWOper;
- *(rawData + 5) = 0;
- *(rawData + 6) = 0;
- *(rawData + 7) = 0;
- break;
- }
- case 0x1C02EBEC:
- {
- break;
- }
- case 0x1C12EBEC:
- {
- break;
- }
- case 0x1C03EBEC:
- {
- break;
- }
- case 0x1C04EBEC:
- {
- break;
- }
- case 0x1C05EBEC:
- {
- break;
- }
- case 0x1C06EBEC:
- {
- break;
- }
- case 0x1C07EBEC:
- {
- break;
- }
- case 0x1C08EBEC:
- {
- break;
- }
- case 0x1C09EBEC:
- {
- break;
- }
- case 0x1C0AEBEC:
- {
- break;
- }
- case 0x1C0BEBEC:
- {
- break;
- }
- case 0x1C0CEBEC:
- {
- break;
- }
- case 0x1C0DEBEC:
- {
- break;
- }
- case 0x1C0EEBEC:
- {
- break;
- }
- default:
- break;
- }
- }
- /**
- * @brief : ebc对ble的数据应答,Ebc data ->Ble data
- * @param {*}
- * @return {*}
- */
- void Can2DataCode(uint8 DataIdx, uint8 Byte0Num, uint8 Data[])
- {
- switch (DataIdx)
- {
- case 0x01: //主机数据类型1的应答
- {
- Data[0] = 0x11;
- Data[1] = ebcd_st_ebcWork;
- Data[2] = ebcd_st_ebcConnect;
- Data[3] = ebcd_st_ebcLockWork;
- Data[4] = 0x00;
- Data[5] = 0x00;
- Data[6] = 0x00;
- Data[7] = 0x00;
- break;
- }
- case 0x02: //主机数据类型2的应答 共7条
- {
- switch (Byte0Num)
- {
- case 0x21:
- {
- vcud_st_keyOn = BattCD_stWakeupU.B.bLogic;
- bcud_st_bcuTmsLiquid = 0; // TBD
- ebcd_flg_pluginLockSig = m_flg_HVlock1 && m_flg_HVlock2;
- Data[0] = Byte0Num;
- Data[1] = ebcd_st_unlockSensor;
- Data[2] = ebcd_st_lockSensor;
- Data[3] = vcud_st_keyOn;
- Data[4] = ebcd_P_airSensor;
- Data[5] = bcud_st_bcuTmsLiquid;
- Data[6] = ebcd_flg_pluginLockSig;
- Data[7] = 0x00;
- break;
- }
- case 0x22:
- {
- ebcd_st_pluginLockSig = (m_flg_HVlock2 << 2) | (m_flg_HVlock1 << 1) | (m_flg_HVlock1 << 1);
- Data[0] = Byte0Num;
- Data[1] = 0x00;
- Data[2] = 0x00;
- Data[3] = 0x00;
- Data[4] = 0x00;
- Data[5] = ebcd_st_pedstSensor;
- Data[6] = ebcd_st_pluginLockSig;
- Data[7] = 0x00;
- break;
- }
- case 0x23:
- {
- Data[0] = Byte0Num;
- Data[1] = ebcd_st_unlockSucJug;
- Data[2] = ebcd_st_lockSucJug;
- Data[3] = 0x00;
- Data[4] = 0x00;
- Data[5] = 0x00;
- Data[6] = 0x00;
- Data[7] = 0x00;
- break;
- }
- case 0x24:
- {
- Data[0] = Byte0Num;
- Data[1] = 0x00;
- Data[2] = 0x00;
- Data[3] = 0x00;
- Data[4] = 0x00;
- Data[5] = ebcd_st_pedstSucJug;
- Data[6] = ebcd_flg_swapAdmit;
- Data[7] = 0x00;
- break;
- }
- case 0x25:
- {
- Data[0] = Byte0Num;
- Data[1] = ebcd_st_ebcWork;
- Data[2] = ebcd_st_ebcConnect;
- Data[3] = ebcd_st_ebcLockWork;
- Data[4] = ebcd_Nr_errMax;
- Data[5] = ebcd_Num_err1;
- Data[6] = ebcd_Num_err2;
- Data[7] = 0x00;
- break;
- }
- case 0x26:
- {
- Data[0] = Byte0Num;
- Data[1] = (ebcd_Nr_swapBatt >> 8) & 0xFF;
- Data[2] = ebcd_Nr_swapBatt & 0xFF;
- Data[3] = (ebcd_Nr_swapSucBatt >> 8) & 0xFF;
- Data[4] = ebcd_Nr_swapSucBatt;
- Data[5] = 0x00;
- Data[6] = 0x00;
- Data[7] = 0x00;
- break;
- }
- case 0x27:
- {
- Data[0] = Byte0Num;
- Data[1] = ebcd_st_errTable1;
- Data[2] = ebcd_st_errTable2;
- Data[3] = ebcd_st_errTable3;
- Data[4] = 0x00;
- Data[5] = 0x00;
- Data[6] = 0x00;
- Data[7] = 0x00;
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x03: //主机数据类型3的应答 共5条
- {
- vcud_st_handbrake = VCU_St_ParkBrakeSw;
- vcud_st_footbrake = (VCU_St_BrakePedal > 0);
- vcud_st_gear = VCU_St_Gear;
- vcud_st_vcuComun = (VcuRxLongError[0] != 1);
- vcud_st_carStart = VCU_State_Veh;
- vcud_st_Steer = 0x00; // TBD
- vcud_M_accDrv = 0 * 10; // TBD
- if (VCU_St_VinRecv == 0x07)
- {
- memcpy(vcuv_Num_vin, VCU_Num_VIN, 17);
- }
- switch (Byte0Num)
- {
- case 0x31:
- {
- Data[0] = Byte0Num;
- Data[1] = vcud_st_handbrake;
- Data[2] = vcud_st_footbrake;
- Data[3] = vcud_st_gear;
- Data[4] = vcud_st_vcuComun;
- Data[5] = vcud_st_carStart;
- Data[6] = vcud_st_Steer;
- Data[7] = 0x00;
- break;
- }
- case 0x32:
- {
- Data[0] = Byte0Num;
- Data[1] = vcuv_Num_vin[0];
- Data[2] = vcuv_Num_vin[1];
- Data[3] = vcuv_Num_vin[2];
- Data[4] = vcuv_Num_vin[3];
- Data[5] = vcuv_Num_vin[4];
- Data[6] = vcuv_Num_vin[5];
- Data[7] = 0x00;
- break;
- }
- case 0x33:
- {
- Data[0] = Byte0Num;
- Data[1] = vcuv_Num_vin[6];
- Data[2] = vcuv_Num_vin[7];
- Data[3] = vcuv_Num_vin[8];
- Data[4] = vcuv_Num_vin[9];
- Data[5] = vcuv_Num_vin[10];
- Data[6] = vcuv_Num_vin[11];
- Data[7] = 0x00;
- break;
- }
- case 0x34:
- {
- Data[0] = Byte0Num;
- Data[1] = vcuv_Num_vin[12];
- Data[2] = vcuv_Num_vin[13];
- Data[3] = vcuv_Num_vin[14];
- Data[4] = vcuv_Num_vin[15];
- Data[5] = vcuv_Num_vin[16];
- Data[6] = 0x00;
- Data[7] = 0x00;
- break;
- }
- case 0x35:
- {
- Data[0] = Byte0Num;
- Data[1] = (vcud_M_accDrv >> 24) & 0xFF;
- Data[2] = (vcud_M_accDrv >> 16) & 0xFF;
- Data[3] = (vcud_M_accDrv >> 8) & 0xFF;
- Data[4] = (vcud_M_accDrv)&0xFF;
- Data[5] = vcud_P_airSensorForward;
- Data[6] = vcud_P_airSensorBack;
- Data[7] = 0x00;
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x04: //主机数据类型4的应答 共16条
- {
- bcud_st_bcuComun = (BcuRxLongError[4] != 0x01);
- bcud_pct_bcuSoh = BMS_PackSOH;
- bcud_V_battU = BMS_BattVolt;
- if (BMS_Mode == 2)
- {
- bcud_st_hvWork = 2;
- }
- else if (BMS_Mode == 1)
- {
- bcud_st_hvWork = 0;
- }
- else
- {
- bcud_st_hvWork = 3;
- }
- bcud_st_bcuMainRelay = BMS_StPosRly;
- bcud_pct_soc = (UINT16)(BMS_PackSOC * 4);
- memcpy(bcuv_Num_battSn, BMS_SN, sizeof(BMS_SN));
- bcud_Q_snglChrg = BMS_SingleCharCapy;
- bcud_E_snglChrg = BMS_SingleCharEngy;
- bcud_Q_accRecovry = BMS_TotalBackCharCapy;
- bcud_E_accRecovry = BMS_TotalBackCharEngy;
- bcud_Q_accSwapBatt = BMS_TotalStaCharCapy;
- bcud_E_accSwapBatt = BMS_TotalStaCharEngy;
- bcud_Q_accPlugInChrg = BMS_TotalGunCharCapy;
- bcud_E_accPlugInChrg = BMS_TotalGunCharEngy;
- bcud_Q_accDischrg = BMS_TotalDisCharCapy;
- bcud_E_accDischrg = BMS_TotalDisCharEngy;
- bcud_Q_accChrg = BMS_TotalCharCapy;
- bcud_E_accChrg = BMS_TotalCharEngy;
- switch (Byte0Num)
- {
- case 0x40:
- {
- Data[0] = Byte0Num;
- Data[1] = (bcud_E_accPlugInChrg >> 24) & 0xFF;
- Data[2] = (bcud_E_accPlugInChrg >> 16) & 0xFF;
- Data[3] = (bcud_E_accPlugInChrg >> 8) & 0xFF;
- Data[4] = (bcud_E_accPlugInChrg)&0xFF;
- Data[5] = 0x00;
- Data[6] = 0x00;
- Data[7] = 0x00;
- break;
- }
- case 0x41:
- {
- Data[0] = Byte0Num;
- Data[1] = (bcud_Q_accChrg >> 24) & 0xFF;
- Data[2] = (bcud_Q_accChrg >> 16) & 0xFF;
- Data[3] = (bcud_Q_accChrg >> 8) & 0xFF;
- Data[4] = (bcud_Q_accChrg)&0xFF;
- Data[5] = bcud_st_bcuComun;
- Data[6] = bcud_st_hvWork;
- Data[7] = 0x00;
- break;
- }
- case 0x42:
- {
- Data[0] = Byte0Num;
- Data[1] = (bcud_Q_accDischrg >> 24) & 0xFF;
- Data[2] = (bcud_Q_accDischrg >> 16) & 0xFF;
- Data[3] = (bcud_Q_accDischrg >> 8) & 0xFF;
- Data[4] = (bcud_Q_accDischrg)&0xFF;
- Data[5] = bcud_st_bcuMainRelay;
- Data[6] = bcud_pct_bcuSoh;
- Data[7] = 0x00;
- break;
- }
- case 0x43:
- {
- Data[0] = Byte0Num;
- Data[1] = (bcud_E_accChrg >> 24) & 0xFF;
- Data[2] = (bcud_E_accChrg >> 16) & 0xFF;
- Data[3] = (bcud_E_accChrg >> 8) & 0xFF;
- Data[4] = (bcud_E_accChrg)&0xFF;
- Data[5] = (bcud_V_battU >> 8) & 0xFF;
- Data[6] = (bcud_V_battU)&0xFF;
- Data[7] = 0x00;
- break;
- }
- case 0x44:
- {
- Data[0] = Byte0Num;
- Data[1] = (bcud_E_accDischrg >> 24) & 0xFF;
- Data[2] = (bcud_E_accDischrg >> 16) & 0xFF;
- Data[3] = (bcud_E_accDischrg >> 8) & 0xFF;
- Data[4] = (bcud_E_accDischrg)&0xFF;
- Data[5] = (bcud_pct_soc >> 8) & 0xFF;
- Data[6] = (bcud_pct_soc)&0xFF;
- Data[7] = 0x00;
- break;
- }
- case 0x45:
- {
- Data[0] = Byte0Num;
- Data[1] = bcuv_Num_battSn[0];
- Data[2] = bcuv_Num_battSn[1];
- Data[3] = bcuv_Num_battSn[2];
- Data[4] = bcuv_Num_battSn[3];
- Data[5] = bcuv_Num_battSn[4];
- Data[6] = bcuv_Num_battSn[5];
- Data[7] = 0x00;
- break;
- }
- case 0x46:
- {
- Data[0] = Byte0Num;
- Data[1] = bcuv_Num_battSn[6];
- Data[2] = bcuv_Num_battSn[7];
- Data[3] = bcuv_Num_battSn[8];
- Data[4] = bcuv_Num_battSn[9];
- Data[5] = bcuv_Num_battSn[10];
- Data[6] = bcuv_Num_battSn[11];
- Data[7] = 0x00;
- break;
- }
- case 0x47:
- {
- Data[0] = Byte0Num;
- Data[1] = bcuv_Num_battSn[12];
- Data[2] = bcuv_Num_battSn[13];
- Data[3] = bcuv_Num_battSn[14];
- Data[4] = bcuv_Num_battSn[15];
- Data[5] = bcuv_Num_battSn[16];
- Data[6] = bcuv_Num_battSn[17];
- Data[7] = 0x00;
- break;
- }
- case 0x48:
- {
- Data[0] = Byte0Num;
- Data[1] = bcuv_Num_battSn[18];
- Data[2] = bcuv_Num_battSn[19];
- Data[3] = bcuv_Num_battSn[20];
- Data[4] = bcuv_Num_battSn[21];
- Data[5] = bcuv_Num_battSn[22];
- Data[6] = bcuv_Num_battSn[23];
- Data[7] = 0x00;
- break;
- }
- case 0x49:
- {
- Data[0] = Byte0Num;
- Data[1] = bcuv_Num_battSn[24];
- Data[2] = bcuv_Num_battSn[25];
- Data[3] = bcuv_Num_battSn[26];
- Data[4] = bcuv_Num_battSn[27];
- Data[5] = bcuv_Num_battSn[28];
- Data[6] = bcuv_Num_battSn[29];
- Data[7] = 0x00;
- break;
- }
- case 0x4A:
- {
- Data[0] = Byte0Num;
- Data[1] = bcuv_Num_battSn[30];
- Data[2] = bcuv_Num_battSn[31];
- Data[3] = 0x00;
- Data[4] = 0x00;
- Data[5] = 0x00;
- Data[6] = 0x00;
- Data[7] = 0x00;
- break;
- }
- case 0x4B:
- {
- Data[0] = Byte0Num;
- Data[1] = (bcud_Q_snglChrg >> 8) & 0xFF;
- Data[2] = (bcud_Q_snglChrg)&0xFF;
- Data[3] = (bcud_Q_accRecovry >> 24) & 0xFF;
- Data[4] = (bcud_Q_accRecovry >> 16) & 0xFF;
- Data[5] = (bcud_Q_accRecovry >> 8) & 0xFF;
- Data[6] = (bcud_Q_accRecovry)&0xFF;
- Data[7] = 0x00;
- break;
- }
- case 0x4C:
- {
- Data[0] = Byte0Num;
- Data[1] = (bcud_Q_accSwapBatt >> 24) & 0xFF;
- Data[2] = (bcud_Q_accSwapBatt >> 16) & 0xFF;
- Data[3] = (bcud_Q_accSwapBatt >> 8) & 0xFF;
- Data[4] = (bcud_Q_accSwapBatt)&0xFF;
- Data[5] = 0x00;
- Data[6] = 0x00;
- Data[7] = 0x00;
- break;
- }
- case 0x4D:
- {
- Data[0] = Byte0Num;
- Data[1] = (bcud_E_snglChrg >> 8) & 0xFF;
- Data[2] = (bcud_E_snglChrg)&0xFF;
- Data[3] = (bcud_E_accRecovry >> 24) & 0xFF;
- Data[4] = (bcud_E_accRecovry >> 16) & 0xFF;
- Data[5] = (bcud_E_accRecovry >> 8) & 0xFF;
- Data[6] = (bcud_E_accRecovry)&0xFF;
- Data[7] = 0x00;
- break;
- }
- case 0x4E:
- {
- Data[0] = Byte0Num;
- Data[1] = (bcud_E_accSwapBatt >> 24) & 0xFF;
- Data[2] = (bcud_E_accSwapBatt >> 16) & 0xFF;
- Data[3] = (bcud_E_accSwapBatt >> 8) & 0xFF;
- Data[4] = (bcud_E_accSwapBatt)&0xFF;
- Data[5] = 0x00;
- Data[6] = 0x00;
- Data[7] = 0x00;
- break;
- }
- case 0x4F:
- {
- Data[0] = Byte0Num;
- Data[1] = (bcud_Q_accPlugInChrg >> 24) & 0xFF;
- Data[2] = (bcud_Q_accPlugInChrg >> 16) & 0xFF;
- Data[3] = (bcud_Q_accPlugInChrg >> 8) & 0xFF;
- Data[4] = (bcud_Q_accPlugInChrg)&0xFF;
- Data[5] = 0x00;
- Data[6] = 0x00;
- Data[7] = 0x00;
- break;
- }
- default:
- break;
- }
- break;
- }
- case 0x05:
- {
- Data[0] = 0x51;
- Data[1] = 0x00;
- Data[2] = 0x00;
- Data[3] = 0x00;
- Data[4] = 0x00;
- Data[5] = 0x00;
- Data[6] = 0x00;
- Data[7] = 0x00;
- break;
- }
- default:
- Data[0] = 0x00;
- Data[1] = 0x00;
- Data[2] = 0x00;
- Data[3] = 0x00;
- Data[4] = 0x00;
- Data[5] = 0x00;
- Data[6] = 0x00;
- Data[7] = 0x00;
- break;
- }
- }
- /**
- * @brief : Ebc通过Can2接受到的协议解码
- * @param {uint8} CmdIdx
- * @return {*}
- */
- void Can2ProtocolDecode(uint32 Can2ID, uint8 Data[])
- {
- switch (Can2ID)
- {
- case 0x1CEF0000:
- {
- Can2DataDecode(Data);
- bled_flg_bleConn = 1;
- bled_flg_bleDisconn = 0;
- bled_st_dataTrans = 1;
- break;
- }
- case 0x1CEF0001:
- {
- bled_Nr_softVer = (Data[0] << 24) | (Data[1] << 16) | (Data[2] << 8) | (Data[3]);
- break;
- }
- case 0x1CEF0002:
- {
- if (Data[0] == 0x01 && Data[1] == 0x01)
- {
- bled_flg_bleConn = 1;
- bled_flg_bleDisconn = 0;
- }
- else if (Data[0] == 0x01 && Data[1] == 0x02)
- {
- bled_flg_bleConn = 0;
- bled_flg_bleDisconn = 1;
- }
- break;
- }
- case 0x1C00ECEA: // UDS检测ID
- {
- Uds_Service(Data);
- break;
- }
- default:
- break;
- }
- }
- /**
- * @brief : Ebc通过can2接收到的数据解码,Ble->Ebc
- * @param {*}
- * @return {*}
- */
- void Can2DataDecode(uint8 Data[])
- {
- uint8 CmdIndex = Data[0];
- ebcd_st_toBleAns = CmdIndex;
- ebcd_flg_Can2SendEnbale = TRUE; //所有的信息均立即回复
- switch (CmdIndex)
- {
- case 0x01: //心跳数据,为了维持通讯
- {
- bled_flg_Heart = 1;
- ebcd_flg_Can2SendEnbale = TRUE;
- break;
- }
- case 0x02: //获取换电控制器信息
- {
- bled_flg_getEbcData = 1;
- ebcd_flg_Can2SendEnbale = TRUE;
- break;
- }
- case 0x03: //获得车辆信息
- {
- bled_flg_getVcuData = 1;
- ebcd_flg_Can2SendEnbale = TRUE;
- break;
- }
- case 0x04: //获取电池信息
- {
- bled_flg_getBmsData = 1;
- ebcd_flg_Can2SendEnbale = TRUE;
- break;
- }
- case 0x05: //握手
- {
- bled_flg_handShake = 1;
- ebcd_flg_Can2SendEnbale = TRUE;
- break;
- }
- case 0x06: //解锁
- {
- bled_flg_unlockCmd = Data[1];
- bled_flg_lockCmd = 0;
- break;
- }
- case 0x07: //锁紧
- {
- bled_flg_lockCmd = Data[1];
- bled_flg_unlockCmd = 0;
- break;
- }
- case 0x08: //完成换电
- {
- bled_flg_swapBattDone = 1;
- break;
- }
- case 0x09: //强制解锁,强制上升
- {
- bled_flg_unlockCmdForce = Data[1];
- bled_flg_topAscendCmdForce = Data[2];
- break;
- }
- case 0x0A: //强制锁紧,强制下降
- {
- bled_flg_lockCmdForce = Data[1];
- bled_flg_topDescendCmdForce = Data[2];
- break;
- }
- case 0x0B: //回到行车状态
- {
- bled_flg_backToDrv = 1;
- break;
- }
- case 0x0C: //顶板举升
- {
- bled_flg_topAscendCmd = Data[1];
- break;
- }
- case 0x0D: //顶板下降
- {
- bled_flg_topDescendCmd = Data[1];
- break;
- }
- case 0x0E: //换电开始自动解锁
- {
- bled_flg_autoUnlock = 1;
- break;
- }
- case 0x0F: //换电完成自动锁紧
- {
- bled_flg_autoLock = 1;
- break;
- }
- case 0x10: //除尘开始
- {
- bled_flg_openDustReCmd = 1;
- break;
- }
- case 0x11: //除尘关闭
- {
- bled_flg_closeDustReCmd = 1;
- break;
- }
- case 0x12: //切换到无线通信状态
- {
- break;
- }
- case 0x13: //进入换电状态
- {
- bled_flg_toSwapMod = 1;
- break;
- }
- case 0x14: //急停指令
- {
- bled_flg_safeStopCmd = 1;
- break;
- } //新增需要改数组
- default:
- break;
- }
- }
- static uint8 udsMode = 0; // uds 模式
- uint32 EbcAppSw = 0x00000101;
- void Uds_Service(uint8 *Data)
- {
- UdsAnsType UdsAns;
- memset((uint8 *)&UdsAns, 0x00, sizeof(UdsAns));
- UdsAns.UdsSer = *(Data + 0);
- UdsAns.UdsSubSer = *(Data + 1);
- switch (UdsAns.UdsSer)
- {
- case 0x10: //模式选择
- {
- if (*(Data + 1) == 0x01)
- {
- udsMode = 1;
- UdsPosAns(UdsAns);
- }
- else if (*(Data + 1) == 0x02)
- {
- if (udsMode == 1 || udsMode == 2)
- {
- udsMode = 2;
- UdsPosAns(UdsAns);
- }
- else
- {
- udsMode = 0;
- UdsNegAns(UdsAns);
- }
- }
- else
- {
- udsMode = 0;
- UdsNegAns(UdsAns);
- }
- break;
- }
- case 0x22: //查询
- {
- if (udsMode == 2)
- {
- switch (UdsAns.UdsSubSer)
- {
- case 0x01: //版本号查询
- {
- UdsAns.Seq = 0;
- UdsAns.Data1 = EbcAppSw >> 24;
- UdsAns.Data2 = EbcAppSw >> 16;
- UdsAns.Data3 = EbcAppSw >> 8;
- UdsAns.Data4 = EbcAppSw;
- UdsPosAns(UdsAns);
- break;
- }
- case 0x02: //解锁状态查询
- {
- UdsAns.Seq = 0;
- UdsAns.Data1 = ebcd_st_unlockSensor;
- UdsAns.Data2 = 0x00;
- UdsAns.Data3 = 0x00;
- UdsAns.Data4 = 0x00;
- UdsPosAns(UdsAns);
- break;
- }
- case 0x03: //锁紧状态查询
- {
- UdsAns.Seq = 0;
- UdsAns.Data1 = ebcd_st_lockSensor;
- UdsAns.Data2 = 0x00;
- UdsAns.Data3 = 0x00;
- UdsAns.Data4 = 0x00;
- UdsPosAns(UdsAns);
- break;
- }
- case 0x04: //落座状态查询
- {
- UdsAns.Seq = 0;
- UdsAns.Data1 = ebcd_st_pedstSensor;
- UdsAns.Data2 = 0x00;
- UdsAns.Data3 = 0x00;
- UdsAns.Data4 = 0x00;
- UdsPosAns(UdsAns);
- break;
- }
- case 0x05: //互锁状态查询
- {
- UdsAns.Seq = 0;
- UdsAns.Data1 = ((m_flg_HVlock1 & 0x01) << 1) | (m_flg_HVlock2 & 0x01);
- UdsAns.Data2 = 0x00;
- UdsAns.Data3 = 0x00;
- UdsAns.Data4 = 0x00;
- UdsPosAns(UdsAns);
- break;
- }
- case 0x06: //气压值查询
- {
- UdsAns.Seq = 0;
- UdsAns.Data1 = ebcd_P_airSensor;
- UdsAns.Data2 = 0x00;
- UdsAns.Data3 = 0x00;
- UdsAns.Data4 = 0x00;
- UdsPosAns(UdsAns);
- break;
- }
- case 0x07: //锁紧压力查询
- {
- UdsAns.Seq = 0;
- UdsAns.Data1 = Test_LockPressure >> 8;
- UdsAns.Data2 = Test_LockPressure;
- UdsAns.Data3 = 0x00;
- UdsAns.Data4 = 0x00;
- UdsPosAns(UdsAns);
- break;
- }
- case 0x08: //锁紧次数查询
- {
- UdsAns.Seq = 0;
- UdsAns.Data1 = ManuControlTimes >> 8;
- UdsAns.Data2 = ManuControlTimes;
- UdsAns.Data3 = 0x00;
- UdsAns.Data4 = 0x00;
- UdsPosAns(UdsAns);
- break;
- }
- case 0x09: //温度数据查询
- {
- UdsAns.Seq = 0;
- UdsAns.Data1 = ebcd_T_plugin[0];
- UdsAns.Data2 = ebcd_T_plugin[1];
- UdsAns.Data3 = ebcd_T_plugin[2];
- UdsAns.Data4 = ebcd_T_plugin[3];
- UdsPosAns(UdsAns);
- break;
- }
- default:
- UdsNegAns(UdsAns);
- break;
- }
- }
- else
- {
- UdsNegAns(UdsAns);
- }
- break;
- }
- case 0x27: //控制
- {
- if (udsMode == 2)
- {
- switch (UdsAns.UdsSubSer)
- {
- case 0x01: //循环测试开启
- {
- ebcd_flg_ebcManCtrlEn = 1;
- ebcd_flg_ebcManCtrlMode = 1;
- UdsPosAns(UdsAns);
- break;
- }
- case 0x02:
- {
- ebcd_flg_ebcManCtrlEn = 1;
- ebcd_flg_ebcManCtrlMode = 2;
- UdsPosAns(UdsAns);
- break;
- }
- case 0x03:
- {
- ebcd_flg_ebcManCtrlEn = 1;
- ebcd_flg_ebcManCtrlMode = 3;
- UdsPosAns(UdsAns);
- break;
- }
- case 0x04:
- {
- ebcd_flg_ebcManCtrlEn = 0;
- UdsPosAns(UdsAns);
- break;
- }
- default:
- UdsNegAns(UdsAns);
- break;
- }
- }
- else
- {
- UdsNegAns(UdsAns);
- }
- break;
- }
- case 0x2E: //写入
- {
- if (udsMode == 2)
- {
- switch (UdsAns.UdsSubSer)
- {
- case 0x01:
- {
- LockDelayTime = (*(Data + 4) << 8) | *(Data + 5);
- UdsPosAns(UdsAns);
- EEPROMDrv_bSaveInstantUB = 1;
- break;
- }
- case 0x02:
- {
- UnlockDelayTime = (*(Data + 4) << 8) | *(Data + 5);
- UdsPosAns(UdsAns);
- EEPROMDrv_bSaveInstantUB = 1;
- break;
- }
- default:
- UdsNegAns(UdsAns);
- break;
- }
- }
- else
- {
- UdsNegAns(UdsAns);
- }
- break;
- }
- default:
- break;
- }
- }
- void UdsPosAns(UdsAnsType UdsAnsData)
- {
- MCANDrv_infoMsgS_TYPE infoMsgS;
- infoMsgS.infoConfS.infoMsgParU.B.CAN = 2;
- infoMsgS.infoConfS.infoMsgParU.B.DIR = _MCAN_DIR_TX;
- infoMsgS.infoConfS.infoMsgParU.B.DLC = 8;
- infoMsgS.infoConfS.infoMsgParU.B.IDE = _MCAN_IDE_EXT;
- infoMsgS.infoConfS.infoMsgIDUI = 0x1C00EAECUL;
- infoMsgS.datMsgUBA[0] = 0x78;
- infoMsgS.datMsgUBA[1] = UdsAnsData.UdsSer;
- infoMsgS.datMsgUBA[2] = UdsAnsData.UdsSubSer;
- infoMsgS.datMsgUBA[3] = UdsAnsData.Seq;
- infoMsgS.datMsgUBA[4] = UdsAnsData.Data1;
- infoMsgS.datMsgUBA[5] = UdsAnsData.Data2;
- infoMsgS.datMsgUBA[6] = UdsAnsData.Data3;
- infoMsgS.datMsgUBA[7] = UdsAnsData.Data4;
- MCANDrv_SendMsg(infoMsgS);
- }
- void UdsNegAns(UdsAnsType UdsAnsData)
- {
- MCANDrv_infoMsgS_TYPE infoMsgS;
- infoMsgS.infoConfS.infoMsgParU.B.CAN = 2;
- infoMsgS.infoConfS.infoMsgParU.B.DIR = _MCAN_DIR_TX;
- infoMsgS.infoConfS.infoMsgParU.B.DLC = 8;
- infoMsgS.infoConfS.infoMsgParU.B.IDE = _MCAN_IDE_EXT;
- infoMsgS.infoConfS.infoMsgIDUI = 0x1C00EAECUL;
- infoMsgS.datMsgUBA[0] = 0x7F;
- infoMsgS.datMsgUBA[1] = UdsAnsData.UdsSer;
- infoMsgS.datMsgUBA[2] = UdsAnsData.UdsSubSer;
- infoMsgS.datMsgUBA[3] = 0x00;
- infoMsgS.datMsgUBA[4] = 0x00;
- infoMsgS.datMsgUBA[5] = 0x00;
- infoMsgS.datMsgUBA[6] = 0x00;
- infoMsgS.datMsgUBA[7] = 0x00;
- MCANDrv_SendMsg(infoMsgS);
- }
|