BcuCanProtocolFunc.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /*
  2. * @Author : ChenJie
  3. * @Date : 2021-12-22 17:09:09
  4. * @Version : V3.0
  5. * @LastEditors : ChenJie
  6. * @LastEditTime : 2022-05-10 18:53:29
  7. * @Description : CAN协议解析与组包
  8. * @FilePath : \VehicleControl\VehicleControl\src\System\Vehicle\Communication\BcuCanProtocolFunc.c
  9. */
  10. #include "BcuCanProtocolFunc.h"
  11. void BcuDecodeFunction(UINT32 ID, UINT8 *rawData)
  12. {
  13. switch (ID)
  14. {
  15. case 0x1801D0F3:
  16. BMS_ReqVIN = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0x3);
  17. BMS_ReqHVOff = (UINT8)(((*(UINT8 *)(rawData + 0)) >> 2) & 0x3);
  18. BcuRxFlag[0] = 0x01;
  19. break;
  20. case 0x1801D8F3:
  21. BMS_SoftwareVersion = (UINT16)(((*(UINT8 *)(rawData + 0)) | (*(UINT8 *)(rawData + 1) << 8)) & 0xFFFF);
  22. BMS_HardwareVersion = (UINT16)(((*(UINT8 *)(rawData + 2)) | (*(UINT8 *)(rawData + 3) << 8)) & 0xFFFF);
  23. BMS_ProtocolEditionH = (UINT8)(((*(UINT8 *)(rawData + 4))) & 0x3);
  24. BMS_ProtocolEditionL = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 2) & 0xF);
  25. BcuRxFlag[1] = 0x01;
  26. break;
  27. case 0x1880D0F3:
  28. BMS_CharDevNum = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xF);
  29. BMS_FtPosRly = (UINT8)(((*(UINT8 *)(rawData + 0)) >> 4) & 0x1);
  30. BMS_FtNegRly = (UINT8)(((*(UINT8 *)(rawData + 0)) >> 5) & 0x1);
  31. BMS_FtPosCharRly1 = (UINT8)(((*(UINT8 *)(rawData + 0)) >> 6) & 0x1);
  32. BMS_FtNegCharRly1 = (UINT8)(((*(UINT8 *)(rawData + 0)) >> 7) & 0x1);
  33. BMS_FtPosCharRly2 = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0x1);
  34. BMS_FtNegCharRly2 = (UINT8)(((*(UINT8 *)(rawData + 1)) >> 1) & 0x1);
  35. BMS_FtHeatRly1 = (UINT8)(((*(UINT8 *)(rawData + 1)) >> 2) & 0x1);
  36. BMS_FtHeatRly2 = (UINT8)(((*(UINT8 *)(rawData + 1)) >> 3) & 0x1);
  37. BMS_StPosRly = (UINT8)(((*(UINT8 *)(rawData + 1)) >> 4) & 0x3);
  38. BMS_StNegRly = (UINT8)(((*(UINT8 *)(rawData + 1)) >> 6) & 0x3);
  39. BMS_StPreCharRly = (UINT8)(((*(UINT8 *)(rawData + 2))) & 0x3);
  40. BMS_StPosCharRly1 = (UINT8)(((*(UINT8 *)(rawData + 2)) >> 2) & 0x3);
  41. BMS_StNegCharRly1 = (UINT8)(((*(UINT8 *)(rawData + 2)) >> 4) & 0x3);
  42. BMS_StPosCharRly2 = (UINT8)(((*(UINT8 *)(rawData + 2)) >> 6) & 0x3);
  43. BMS_StNegCharRly2 = (UINT8)(((*(UINT8 *)(rawData + 3))) & 0x3);
  44. BMS_FtAuxRelayWeld = (UINT8)(((*(UINT8 *)(rawData + 3)) >> 2) & 0x1);
  45. BMS_BraOpenCirc = (UINT8)(((*(UINT8 *)(rawData + 3)) >> 3) & 0x1);
  46. BMS_FtBackCharCurrOutLim = (UINT8)(((*(UINT8 *)(rawData + 3)) >> 4) & 0x3);
  47. BMS_FtPosRlyOpen = (UINT8)(((*(UINT8 *)(rawData + 3)) >> 6) & 0x1);
  48. BMS_FtNegRlyOpen = (UINT8)(((*(UINT8 *)(rawData + 3)) >> 7) & 0x1);
  49. BMS_FtPosCharRly1Open = (UINT8)(((*(UINT8 *)(rawData + 4))) & 0x1);
  50. BMS_FtPosCharRly2Open = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 1) & 0x1);
  51. BMS_FtNegCharRly1Open = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 2) & 0x1);
  52. BMS_FtNegCharRly2Open = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 3) & 0x1);
  53. BMS_FtTMSContClose = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 4) & 0x1);
  54. BMS_FtTMSContOpen = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 5) & 0x1);
  55. BMS_FtTMS = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 6) & 0x1);
  56. BMS_Ft24VSpy = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 7) & 0x1);
  57. BMS_FtPACKSelfProt = (UINT8)(((*(UINT8 *)(rawData + 5))) & 0x1);
  58. BMS_FtCharSockTempOver = (UINT8)(((*(UINT8 *)(rawData + 5)) >> 1) & 0x3);
  59. BMS_FtTempOutCtrl = (UINT8)(((*(UINT8 *)(rawData + 5)) >> 3) & 0x1);
  60. BMS_StPosHeatRly = (UINT8)(((*(UINT8 *)(rawData + 5)) >> 4) & 0x3);
  61. BMS_StNegHeatRly = (UINT8)(((*(UINT8 *)(rawData + 5)) >> 6) & 0x3);
  62. BMS_CharSysNum = (UINT8)(((*(UINT8 *)(rawData + 6))) & 0xF);
  63. BMS_FtCode = (UINT8)(((*(UINT8 *)(rawData + 7))) & 0xFF);
  64. BcuRxFlag[2] = 0x01;
  65. break;
  66. case 0x1881D0F3:
  67. BMS_ST1CheckSum = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF);
  68. BMS_ST1Counter = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0xF);
  69. BMS_Mode = (UINT8)(((*(UINT8 *)(rawData + 1)) >> 4) & 0x3);
  70. BMS_AuxRlySt = (UINT8)(((*(UINT8 *)(rawData + 1)) >> 6) & 0x1);
  71. BMS_BattBalaSt = (UINT8)(((*(UINT8 *)(rawData + 1)) >> 7) & 0x1);
  72. BMS_CharGunSt = (UINT8)(((*(UINT8 *)(rawData + 2))) & 0x1);
  73. BMS_CharMode = (UINT8)(((*(UINT8 *)(rawData + 2)) >> 1) & 0x3);
  74. BMS_CharSt = (UINT8)(((*(UINT8 *)(rawData + 2)) >> 3) & 0x3);
  75. BMS_FtLvl = (UINT8)(((*(UINT8 *)(rawData + 2)) >> 5) & 0x3);
  76. BMS_FtCellTempDiff = (UINT8)(((*(UINT8 *)(rawData + 3))) & 0x3);
  77. BMS_FtCellTempHigh = (UINT8)(((*(UINT8 *)(rawData + 3)) >> 2) & 0x3);
  78. BMS_FtPACKOverVolt = (UINT8)(((*(UINT8 *)(rawData + 3)) >> 4) & 0x3);
  79. BMS_FtPACKUndeVolt = (UINT8)(((*(UINT8 *)(rawData + 3)) >> 6) & 0x3);
  80. BMS_FtSOCLow = (UINT8)(((*(UINT8 *)(rawData + 4))) & 0x3);
  81. BMS_FtCellOverVolt = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 2) & 0x3);
  82. BMS_FtCellUndeVolt = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 4) & 0x3);
  83. BMS_FtIns = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 6) & 0x3);
  84. BMS_FtCellOverVoltDiff = (UINT8)(((*(UINT8 *)(rawData + 5))) & 0x3);
  85. BMS_FtCharCurrOver = (UINT8)(((*(UINT8 *)(rawData + 5)) >> 2) & 0x3);
  86. BMS_FtDisCharCurrOver = (UINT8)(((*(UINT8 *)(rawData + 5)) >> 4) & 0x3);
  87. BMS_FtCellTempLow = (UINT8)(((*(UINT8 *)(rawData + 5)) >> 6) & 0x3);
  88. BMS_FtBranVoltDifOver = (UINT8)(((*(UINT8 *)(rawData + 6))) & 0x3);
  89. BMS_FtBMSHardWare = (UINT8)(((*(UINT8 *)(rawData + 6)) >> 2) & 0x3);
  90. BMS_FtSOCHigh = (UINT8)(((*(UINT8 *)(rawData + 6)) >> 4) & 0x1);
  91. BMS_FtSOCJump = (UINT8)(((*(UINT8 *)(rawData + 6)) >> 5) & 0x1);
  92. BMS_FtInCom = (UINT8)(((*(UINT8 *)(rawData + 6)) >> 6) & 0x1);
  93. BMS_FtSysMism = (UINT8)(((*(UINT8 *)(rawData + 6)) >> 7) & 0x1);
  94. BMS_FtHvIntLock = (UINT8)(((*(UINT8 *)(rawData + 7))) & 0x1);
  95. BMS_FtSmoke = (UINT8)(((*(UINT8 *)(rawData + 7)) >> 1) & 0x1);
  96. BMS_FtFire = (UINT8)(((*(UINT8 *)(rawData + 7)) >> 2) & 0x1);
  97. BMS_FtNum = (UINT8)(((*(UINT8 *)(rawData + 7)) >> 3) & 0x1F);
  98. BcuRxFlag[3] = 0x01;
  99. break;
  100. case 0x1882D0F3:
  101. BMS_PackSOC = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF);
  102. BMS_PackSOH = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0xFF);
  103. BMS_PackCurr = (UINT16)(((*(UINT8 *)(rawData + 2)) | (*(UINT8 *)(rawData + 3) << 8)) & 0xFFFF);
  104. BMS_MaxCharCurr = (UINT16)(((*(UINT8 *)(rawData + 4)) | (*(UINT8 *)(rawData + 5) << 8)) & 0xFFFF);
  105. BMS_MaxDisCharCurr = (UINT16)(((*(UINT8 *)(rawData + 6)) | (*(UINT8 *)(rawData + 7) << 8)) & 0xFFFF);
  106. BcuRxFlag[4] = 0x01;
  107. break;
  108. case 0x1883D0F3:
  109. BMS_PosIns = (UINT16)(((*(UINT8 *)(rawData + 0)) | (*(UINT8 *)(rawData + 1) << 8)) & 0xFFFF);
  110. BMS_NegIns = (UINT16)(((*(UINT8 *)(rawData + 2)) | (*(UINT8 *)(rawData + 3) << 8)) & 0xFFFF);
  111. BMS_BattVolt = (UINT16)(((*(UINT8 *)(rawData + 4)) | (*(UINT8 *)(rawData + 5) << 8)) & 0xFFFF);
  112. BMS_LinkVolt = (UINT16)(((*(UINT8 *)(rawData + 6)) | (*(UINT8 *)(rawData + 7) << 8)) & 0xFFFF);
  113. BcuRxFlag[5] = 0x01;
  114. break;
  115. case 0x1884D0F3:
  116. BMS_MaxCellTemp = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF);
  117. BMS_MinCellTemp = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0xFF);
  118. BMS_AverCellTemp = (UINT8)(((*(UINT8 *)(rawData + 2))) & 0xFF);
  119. BMS_MaxCellTempCSC = (UINT8)(((*(UINT8 *)(rawData + 3))) & 0xFF);
  120. BMS_MaxCellTempNum = (UINT8)(((*(UINT8 *)(rawData + 4))) & 0xFF);
  121. BMS_MinCellTempCSC = (UINT8)(((*(UINT8 *)(rawData + 5))) & 0xFF);
  122. BMS_MinCellTempNum = (UINT8)(((*(UINT8 *)(rawData + 6))) & 0xFF);
  123. BcuRxFlag[6] = 0x01;
  124. break;
  125. case 0x1885D0F3:
  126. BMS_MaxCellVolt = (UINT16)(((*(UINT8 *)(rawData + 0)) | (*(UINT8 *)(rawData + 1) << 8)) & 0xFFFF);
  127. BMS_MaxCellVoltCSC = (UINT8)(((*(UINT8 *)(rawData + 2))) & 0xFF);
  128. BMS_MaxCellVoltNum = (UINT8)(((*(UINT8 *)(rawData + 3))) & 0xFF);
  129. BMS_AverCellVolt = (UINT16)(((*(UINT8 *)(rawData + 4)) | (*(UINT8 *)(rawData + 5) << 8)) & 0xFFFF);
  130. BcuRxFlag[7] = 0x01;
  131. break;
  132. case 0x1886D0F3:
  133. BMS_MinCellVolt = (UINT16)(((*(UINT8 *)(rawData + 0)) | (*(UINT8 *)(rawData + 1) << 8)) & 0xFFFF);
  134. BMS_MinCellVoltCSC = (UINT8)(((*(UINT8 *)(rawData + 2))) & 0xFF);
  135. BMS_MinCellVoltNum = (UINT8)(((*(UINT8 *)(rawData + 3))) & 0xFF);
  136. BMS_ContChrgCurr = (UINT16)(((*(UINT8 *)(rawData + 4)) | (*(UINT8 *)(rawData + 5) << 8)) & 0xFFFF);
  137. BMS_ContDisCharCurr = (UINT16)(((*(UINT8 *)(rawData + 6)) | (*(UINT8 *)(rawData + 7) << 8)) & 0xFFFF);
  138. BcuRxFlag[8] = 0x01;
  139. break;
  140. case 0x1887D0F3:
  141. BMS_CharReqVolt = (UINT16)(((*(UINT8 *)(rawData + 0)) | (*(UINT8 *)(rawData + 1) << 8)) & 0xFFFF);
  142. BMS_CharReqCurr = (UINT16)(((*(UINT8 *)(rawData + 2)) | (*(UINT8 *)(rawData + 3) << 8)) & 0xFFFF);
  143. BMS_SysInsRes = (UINT16)(((*(UINT8 *)(rawData + 4)) | (*(UINT8 *)(rawData + 5) << 8)) & 0xFFFF);
  144. BMS_InsDeteSt = (UINT8)(((*(UINT8 *)(rawData + 6))) & 0x1);
  145. BMS_FtCharInsLow = (UINT8)(((*(UINT8 *)(rawData + 6)) >> 1) & 0x1);
  146. BMS_FtCurrSenr = (UINT8)(((*(UINT8 *)(rawData + 6)) >> 2) & 0x1);
  147. BMS_FtHeatingFilm = (UINT8)(((*(UINT8 *)(rawData + 6)) >> 3) & 0x1);
  148. BMS_FtMainLoopPreChar = (UINT8)(((*(UINT8 *)(rawData + 6)) >> 4) & 0x1);
  149. BMS_FtAuxLoopPreChar = (UINT8)(((*(UINT8 *)(rawData + 6)) >> 5) & 0x1);
  150. BMS_FtACANLost = (UINT8)(((*(UINT8 *)(rawData + 6)) >> 6) & 0x1);
  151. BMS_FtDCDC = (UINT8)(((*(UINT8 *)(rawData + 6)) >> 7) & 0x1);
  152. BMS_FtSOCDif = (UINT8)(((*(UINT8 *)(rawData + 7))) & 0x1);
  153. BMS_FtCellOverDisChar = (UINT8)(((*(UINT8 *)(rawData + 7)) >> 1) & 0x1);
  154. BMS_FtCharOver = (UINT8)(((*(UINT8 *)(rawData + 7)) >> 2) & 0x3);
  155. BMS_FtContDisCharCurrOverLoad = (UINT8)(((*(UINT8 *)(rawData + 7)) >> 4) & 0x3);
  156. BMS_FtContCharCurrOverLoad = (UINT8)(((*(UINT8 *)(rawData + 7)) >> 6) & 0x3);
  157. BcuRxFlag[9] = 0x01;
  158. break;
  159. case 0x1888D0F3:
  160. BMS_MaxDisCharPwr = (UINT16)(((*(UINT8 *)(rawData + 0)) | (*(UINT8 *)(rawData + 1) << 8)) & 0xFFFF);
  161. BMS_MaxCharPwr = (UINT16)(((*(UINT8 *)(rawData + 2)) | (*(UINT8 *)(rawData + 3) << 8)) & 0xFFFF);
  162. BMS_ContDisCharPwr = (UINT16)(((*(UINT8 *)(rawData + 4)) | (*(UINT8 *)(rawData + 5) << 8)) & 0xFFFF);
  163. BMS_ContCharPwr = (UINT16)(((*(UINT8 *)(rawData + 6)) | (*(UINT8 *)(rawData + 7) << 8)) & 0xFFFF);
  164. BcuRxFlag[10] = 0x01;
  165. break;
  166. case 0x1889D0F3:
  167. BMS_InstEngyCons = (UINT16)(((*(UINT8 *)(rawData + 0)) | (*(UINT8 *)(rawData + 1) << 8)) & 0xFFFF);
  168. BMS_TotalEngyCons = (UINT16)(((*(UINT8 *)(rawData + 2)) | (*(UINT8 *)(rawData + 3) << 8)) & 0xFFFF);
  169. BMS_SOE = (UINT16)(((*(UINT8 *)(rawData + 4)) | (*(UINT8 *)(rawData + 5) << 8)) & 0xFFFF);
  170. BMS_RmanCharTime = (UINT16)(((*(UINT8 *)(rawData + 6)) | (*(UINT8 *)(rawData + 7) << 8)) & 0xFFFF);
  171. BcuRxFlag[11] = 0x01;
  172. break;
  173. case 0x188AD0F3:
  174. BMS_Gun1DCNegTemp = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF);
  175. BMS_Gun1DCPosTemp = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0xFF);
  176. BMS_Gun2DCNegTemp = (UINT8)(((*(UINT8 *)(rawData + 2))) & 0xFF);
  177. BMS_Gun2DCPosTemp = (UINT8)(((*(UINT8 *)(rawData + 3))) & 0xFF);
  178. BMS_CurrHeatSt = (UINT8)(((*(UINT8 *)(rawData + 4))) & 0x3);
  179. BMS_CurrCoolSt = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 2) & 0x3);
  180. BMS_FtCharCnct = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 4) & 0x1);
  181. BMS_FtOverDisCharCurrDuringChar = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 5) & 0x1);
  182. BMS_FtCharNTC = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 6) & 0x1);
  183. BMS_FtELock = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 7) & 0x1);
  184. BMS_CharNum = (UINT16)(((*(UINT8 *)(rawData + 5)) | (*(UINT8 *)(rawData + 6) << 8)) & 0xFFFF);
  185. BcuRxFlag[12] = 0x01;
  186. break;
  187. case 0x18C1D0F3:
  188. BMS_CellVoltFramNum = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF);
  189. BMS_CSC_Code = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0xFF);
  190. if (BMS_CellVoltFramNum == 0 || BMS_CellVoltFramNum > 128)
  191. {
  192. break;
  193. }
  194. for (UINT8 i = 0; i < 3; i++)
  195. {
  196. BMS_CellVolt[(BMS_CellVoltFramNum - 1) * 3 + i] = (UINT16)(((*(UINT8 *)(rawData + i * 2 + 2)) | (*(UINT8 *)(rawData + i * 2 + 3) << 8)) & 0xFFFF);
  197. }
  198. BcuRxFlag[13] = 0x01;
  199. break;
  200. case 0x18C2D0F3:
  201. BMS_CellTempFramNum = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF);
  202. BMS_CSC_Code = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0xFF);
  203. if (BMS_CellTempFramNum == 0 || BMS_CellTempFramNum > 12)
  204. {
  205. break;
  206. }
  207. for (UINT8 i = 0; i < 6; i++)
  208. {
  209. if (((BMS_CellTempFramNum - 1) * 6 + i) < sizeof(BMS_CellTemp))
  210. {
  211. BMS_CellTemp[(BMS_CellTempFramNum - 1) * 6 + i] = (UINT8)(((*(UINT8 *)(rawData + 2 + i))) & 0xFF);
  212. }
  213. }
  214. BcuRxFlag[14] = 0x01;
  215. break;
  216. case 0x18E1D0F3:
  217. BMS_Checksum = 0;
  218. for (UINT8 i = 1; i < 8; i++)
  219. {
  220. BMS_Checksum = (UINT8)(((*(UINT8 *)(rawData + i))) & 0xFF) ^ BMS_Checksum;
  221. }
  222. if (BMS_Checksum == (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF))
  223. {
  224. BMS_PackComp = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0x7);
  225. BMS_BattCodeLeng = (UINT8)(((*(UINT8 *)(rawData + 1)) >> 3) & 0x1F);
  226. BMS_SN[0] = (UINT8)(((*(UINT8 *)(rawData + 2))) & 0xFF);
  227. BMS_SN[1] = (UINT8)(((*(UINT8 *)(rawData + 3))) & 0xFF);
  228. BMS_SN[2] = (UINT8)(((*(UINT8 *)(rawData + 4))) & 0xFF);
  229. BMS_SN[3] = (UINT8)(((*(UINT8 *)(rawData + 5))) & 0xFF);
  230. BMS_SN[4] = (UINT8)(((*(UINT8 *)(rawData + 6))) & 0xFF);
  231. BMS_SN[5] = (UINT8)(((*(UINT8 *)(rawData + 7))) & 0xFF);
  232. }
  233. BcuRxFlag[15] = 0x01;
  234. break;
  235. case 0x18E2D0F3:
  236. BMS_Checksum = 0;
  237. for (UINT8 i = 1; i < 8; i++)
  238. {
  239. BMS_Checksum = (UINT8)(((*(UINT8 *)(rawData + i))) & 0xFF) ^ BMS_Checksum;
  240. }
  241. if (BMS_Checksum == (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF))
  242. {
  243. BMS_SN[6] = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0xFF);
  244. BMS_SN[7] = (UINT8)(((*(UINT8 *)(rawData + 2))) & 0xFF);
  245. BMS_SN[8] = (UINT8)(((*(UINT8 *)(rawData + 3))) & 0xFF);
  246. BMS_SN[9] = (UINT8)(((*(UINT8 *)(rawData + 4))) & 0xFF);
  247. BMS_SN[10] = (UINT8)(((*(UINT8 *)(rawData + 5))) & 0xFF);
  248. BMS_SN[11] = (UINT8)(((*(UINT8 *)(rawData + 6))) & 0xFF);
  249. BMS_SN[12] = (UINT8)(((*(UINT8 *)(rawData + 7))) & 0xFF);
  250. }
  251. BcuRxFlag[16] = 0x01;
  252. break;
  253. case 0x18E3D0F3:
  254. BMS_Checksum = 0;
  255. for (UINT8 i = 1; i < 8; i++)
  256. {
  257. BMS_Checksum = (UINT8)(((*(UINT8 *)(rawData + i))) & 0xFF) ^ BMS_Checksum;
  258. }
  259. if (BMS_Checksum == (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF))
  260. {
  261. BMS_SN[13] = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0xFF);
  262. BMS_SN[14] = (UINT8)(((*(UINT8 *)(rawData + 2))) & 0xFF);
  263. BMS_SN[15] = (UINT8)(((*(UINT8 *)(rawData + 3))) & 0xFF);
  264. BMS_SN[16] = (UINT8)(((*(UINT8 *)(rawData + 4))) & 0xFF);
  265. BMS_SN[17] = (UINT8)(((*(UINT8 *)(rawData + 5))) & 0xFF);
  266. BMS_SN[18] = (UINT8)(((*(UINT8 *)(rawData + 6))) & 0xFF);
  267. BMS_SN[19] = (UINT8)(((*(UINT8 *)(rawData + 7))) & 0xFF);
  268. }
  269. BcuRxFlag[17] = 0x01;
  270. break;
  271. case 0x18E4D0F3:
  272. BMS_Checksum = 0;
  273. for (UINT8 i = 1; i < 8; i++)
  274. {
  275. BMS_Checksum = (UINT8)(((*(UINT8 *)(rawData + i))) & 0xFF) ^ BMS_Checksum;
  276. }
  277. if (BMS_Checksum == (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF))
  278. {
  279. BMS_SN[20] = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0xFF);
  280. BMS_SN[21] = (UINT8)(((*(UINT8 *)(rawData + 2))) & 0xFF);
  281. BMS_SN[22] = (UINT8)(((*(UINT8 *)(rawData + 3))) & 0xFF);
  282. BMS_SN[23] = (UINT8)(((*(UINT8 *)(rawData + 4))) & 0xFF);
  283. BMS_SN[24] = (UINT8)(((*(UINT8 *)(rawData + 5))) & 0xFF);
  284. BMS_SN[25] = (UINT8)(((*(UINT8 *)(rawData + 6))) & 0xFF);
  285. BMS_SN[26] = (UINT8)(((*(UINT8 *)(rawData + 7))) & 0xFF);
  286. }
  287. BcuRxFlag[18] = 0x01;
  288. break;
  289. case 0x18E5D0F3:
  290. BMS_BattRateCap = (UINT16)(((*(UINT8 *)(rawData + 0)) | (*(UINT8 *)(rawData + 1) << 8)) & 0xFFFF);
  291. BMS_BattRateVolt = (UINT16)(((*(UINT8 *)(rawData + 2)) | (*(UINT8 *)(rawData + 3) << 8)) & 0xFFFF);
  292. BMS_BattRateEngy = (UINT16)(((*(UINT8 *)(rawData + 4)) | (*(UINT8 *)(rawData + 5) << 8)) & 0xFFFF);
  293. BMS_BattType = (UINT8)(((*(UINT8 *)(rawData + 6))) & 0xF);
  294. BMS_CoolType = (UINT8)(((*(UINT8 *)(rawData + 6)) >> 4) & 0x3);
  295. BcuRxFlag[19] = 0x01;
  296. break;
  297. case 0x18E6D0F3:
  298. BMS_CSC_Total = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF);
  299. BMS_CellTotal = (UINT16)(((*(UINT8 *)(rawData + 1)) | (*(UINT8 *)(rawData + 2) << 8)) & 0xFFFF);
  300. BMS_TempTotal = (UINT16)(((*(UINT8 *)(rawData + 3)) | (*(UINT8 *)(rawData + 4) << 8)) & 0xFFFF);
  301. BMS_CellVoltLevel = (UINT8)(((*(UINT8 *)(rawData + 5))) & 0xFF);
  302. BMS_CellMinVolt = (UINT8)(((*(UINT8 *)(rawData + 6))) & 0xFF);
  303. BMS_CellMaxVolt = (UINT8)(((*(UINT8 *)(rawData + 7))) & 0xFF);
  304. BcuRxFlag[20] = 0x01;
  305. break;
  306. case 0x18F1D0F3:
  307. BMS_TotalCharEngy = (UINT32)(((*(UINT8 *)(rawData + 0)) | (*(UINT8 *)(rawData + 1) << 8) |(*(UINT8 *)(rawData + 2) << 16) | (*(UINT8 *)(rawData + 3) << 24)) & 0xFFFFFF);
  308. BMS_TotalDisCharEngy = (UINT32)(((*(UINT8 *)(rawData + 3)) |(*(UINT8 *)(rawData + 4) << 8) | (*(UINT8 *)(rawData + 5) << 16) | (*(UINT8 *)(rawData + 6) << 24)) & 0xFFFFFF);
  309. BMS_SingleCharEngy = (UINT16)(((*(UINT8 *)(rawData + 6)) |(*(UINT8 *)(rawData + 7) << 8)) & 0xFFFF);
  310. BcuRxFlag[21] = 0x01;
  311. break;
  312. case 0x18F2D0F3:
  313. BMS_TotalBackCharEngy = (UINT32)(((*(UINT8 *)(rawData + 0)) | (*(UINT8 *)(rawData + 1) << 8) | (*(UINT8 *)(rawData + 2) << 16) | (*(UINT8 *)(rawData + 3) << 24)) & 0xFFFFFF);
  314. BMS_TotalStaCharEngy = (UINT32)(((*(UINT8 *)(rawData + 3)) |(*(UINT8 *)(rawData + 4) << 8) | (*(UINT8 *)(rawData + 5) << 16) | (*(UINT8 *)(rawData + 6) << 24)) & 0xFFFFFF);
  315. BcuRxFlag[22] = 0x01;
  316. break;
  317. case 0x18F3D0F3:
  318. BMS_TotalGunCharEngy = (UINT32)(((*(UINT8 *)(rawData + 0)) | (*(UINT8 *)(rawData + 1) << 8) | (*(UINT8 *)(rawData + 2) << 16) | (*(UINT8 *)(rawData + 3) << 24)) & 0xFFFFFF);
  319. BMS_TotalGunCharCapy = (UINT32)(((*(UINT8 *)(rawData + 3)) | (*(UINT8 *)(rawData + 4) << 8) | (*(UINT8 *)(rawData + 5) << 16) | (*(UINT8 *)(rawData + 6) << 24)) & 0xFFFFFF);
  320. BcuRxFlag[23] = 0x01;
  321. break;
  322. case 0x18F4D0F3:
  323. BMS_TotalCharCapy = (UINT32)(((*(UINT8 *)(rawData + 0)) | (*(UINT8 *)(rawData + 1) << 8) | (*(UINT8 *)(rawData + 2) << 16) | (*(UINT8 *)(rawData + 3) << 24)) & 0xFFFFFF);
  324. BMS_TotalDisCharCapy = (UINT32)(((*(UINT8 *)(rawData + 3)) | (*(UINT8 *)(rawData + 4) << 8) | (*(UINT8 *)(rawData + 5) << 16) | (*(UINT8 *)(rawData + 6) << 24)) & 0xFFFFFF);
  325. BMS_SingleCharCapy = (UINT16)(((*(UINT8 *)(rawData + 6)) | (*(UINT8 *)(rawData + 7) << 8)) & 0xFFFF);
  326. BcuRxFlag[24] = 0x01;
  327. break;
  328. case 0x18F5D0F3:
  329. BMS_TotalBackCharCapy = (UINT32)(((*(UINT8 *)(rawData + 0)) | (*(UINT8 *)(rawData + 1) << 8) | (*(UINT8 *)(rawData + 2) << 16) | (*(UINT8 *)(rawData + 3) << 24)) & 0xFFFFFF);
  330. BMS_TotalStaCharCapy = (UINT32)(((*(UINT8 *)(rawData + 3)) | (*(UINT8 *)(rawData + 4) << 8) | (*(UINT8 *)(rawData + 5) << 16) | (*(UINT8 *)(rawData + 6) << 24)) & 0xFFFFFF);
  331. BMS_HVBranNum = (UINT8)(((*(UINT8 *)(rawData + 6))) & 0xFF);
  332. BMS_SingleHVBranchCellNum = (UINT8)(((*(UINT8 *)(rawData + 7))) & 0xFF);
  333. BcuRxFlag[25] = 0x01;
  334. break;
  335. case 0x18FF45F4:
  336. BMS_ReqMode = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0x3);
  337. BMS_HVCmd = (UINT8)(((*(UINT8 *)(rawData + 0)) >> 2) & 0x3);
  338. BMS_ChgSts = (UINT8)(((*(UINT8 *)(rawData + 0)) >> 4) & 0x3);
  339. BMS_HVRelaySts = (UINT8)(((*(UINT8 *)(rawData + 0)) >> 6) & 0x3);
  340. BMS_HVVolt = (UINT16)(((*(UINT8 *)(rawData + 1)) | (*(UINT8 *)(rawData + 2) << 8)) & 0xFFFF);
  341. BMS_SetTemp = (UINT8)(((*(UINT8 *)(rawData + 4))) & 0xFF);
  342. BMS_Life = (UINT8)(((*(UINT8 *)(rawData + 6))) & 0xFF);
  343. BMS_CRC = (UINT8)(((*(UINT8 *)(rawData + 7))) & 0xFF);
  344. BcuRxFlag[26] = 0x01;
  345. break;
  346. case 0x18FFC13A:
  347. TMS_WorkStatus = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0x3);
  348. TMS_HVRelayST = (UINT8)(((*(UINT8 *)(rawData + 0)) >> 2) & 0x3);
  349. TMS_OutletTemp = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0xFF);
  350. TMS_InletTemp = (UINT8)(((*(UINT8 *)(rawData + 2))) & 0xFF);
  351. TMS_ReqPow = (UINT16)(((*(UINT8 *)(rawData + 5)) | (*(UINT8 *)(rawData + 6) << 8)) & 0xFFFF);
  352. TMS_ErrCode = (UINT8)(((*(UINT8 *)(rawData + 7))) & 0x3F);
  353. TMS_FaultLevel = (UINT8)(((*(UINT8 *)(rawData + 7)) >> 6) & 0x3);
  354. BcuRxFlag[27] = 0x01;
  355. break;
  356. default:
  357. break;
  358. }
  359. }
  360. void BcuRxDiagnose(void)
  361. {
  362. static UINT32 TimeCounter = 0; // ms
  363. TimeCounter = TimeCounter + 10; //
  364. for (UINT8 i = 0; i < sizeof(BcuInTable) / 4; i++)
  365. {
  366. if (BcuRxFlag[i] == 1) // received msg, and clear the error conter
  367. {
  368. BcuRxErrorCounter[i] = 0;
  369. BcuRxFlag[i] = 0;
  370. continue;
  371. }
  372. if (BcuRxErrorCounter[i] < 3)
  373. {
  374. BcuRxShortError[i] = 0;
  375. BcuRxLongError[i] = 0;
  376. }
  377. else if (BcuRxErrorCounter[i] >= 3 && BcuRxErrorCounter[i] < 13)
  378. {
  379. BcuRxShortError[i] = 1;
  380. BcuRxLongError[i] = 0;
  381. }
  382. else if (BcuRxErrorCounter[i] >= 13)
  383. {
  384. BcuRxShortError[i] = 0;
  385. BcuRxLongError[i] = 1;
  386. BcuRxMsgSetInvalidValue(BcuInTable[i]);
  387. BcuRxErrorCounter[i] = 0;
  388. }
  389. else if (BcuRxErrorCounter[i] == 0xFF)
  390. {
  391. BcuRxErrorCounter[i] = 0xFE;
  392. }
  393. }
  394. if (TimeCounter % 100 == 0) // period <=100ms
  395. {
  396. BcuRxErrorCounter[0]++; // can msg 0x1801D0F3
  397. // if(BcuRxErrorCounter[0]>=13)
  398. BcuRxErrorCounter[2]++; // can msg 0x1880D0F3
  399. // if(BcuRxErrorCounter[2]>=13)
  400. BcuRxErrorCounter[3]++; // can msg 0x1881D0F3
  401. // if(BcuRxErrorCounter[3]>=13)
  402. BcuRxErrorCounter[4]++; // can msg 0x1882D0F3
  403. // if(BcuRxErrorCounter[4]>=13)
  404. BcuRxErrorCounter[5]++; // can msg 0x1883D0F3
  405. // if(BcuRxErrorCounter[5]>=13)
  406. BcuRxErrorCounter[6]++; // can msg 0x1884D0F3
  407. // if(BcuRxErrorCounter[6]>=13)
  408. BcuRxErrorCounter[7]++; // can msg 0x1885D0F3
  409. // if(BcuRxErrorCounter[7]>=13)
  410. BcuRxErrorCounter[8]++; // can msg 0x1886D0F3
  411. // if(BcuRxErrorCounter[8]>=13)
  412. BcuRxErrorCounter[9]++; // can msg 0x1887D0F3
  413. // if(BcuRxErrorCounter[9]>=13)
  414. BcuRxErrorCounter[10]++; // can msg 0x1888D0F3
  415. // if(BcuRxErrorCounter[10]>=13)
  416. BcuRxErrorCounter[13]++; // can msg 0x18C1D0F3
  417. // if(BcuRxErrorCounter[13]>=13)
  418. BcuRxErrorCounter[14]++; // can msg 0x18C2D0F3
  419. // if(BcuRxErrorCounter[14]>=13)
  420. BcuRxErrorCounter[19]++; // can msg 0x18E5D0F3
  421. // if(BcuRxErrorCounter[19]>=13)
  422. BcuRxErrorCounter[20]++; // can msg 0x18E6D0F3
  423. // if(BcuRxErrorCounter[20]>=13)
  424. }
  425. if (TimeCounter % 1000 == 0) // period ==1000ms
  426. {
  427. BcuRxErrorCounter[11]++; // can msg 0x1889D0F3
  428. // if(BcuRxErrorCounter[11]>=13)
  429. // printf("can msg 0x%x lost,cycle time1000ms\n",COMInTable[11]);
  430. BcuRxErrorCounter[12]++; // can msg 0x188AD0F3
  431. // if(BcuRxErrorCounter[12]>=13)
  432. // printf("can msg 0x%x lost,cycle time1000ms\n",COMInTable[12]);
  433. BcuRxErrorCounter[15]++; // can msg 0x18E1D0F3
  434. // if(BcuRxErrorCounter[15]>=13)
  435. // printf("can msg 0x%x lost,cycle time1000ms\n",COMInTable[15]);
  436. BcuRxErrorCounter[16]++; // can msg 0x18E2D0F3
  437. // if(BcuRxErrorCounter[16]>=13)
  438. // printf("can msg 0x%x lost,cycle time1000ms\n",COMInTable[16]);
  439. BcuRxErrorCounter[17]++; // can msg 0x18E3D0F3
  440. // if(BcuRxErrorCounter[17]>=13)
  441. // printf("can msg 0x%x lost,cycle time1000ms\n",COMInTable[17]);
  442. BcuRxErrorCounter[18]++; // can msg 0x18E4D0F3
  443. // if(BcuRxErrorCounter[18]>=13)
  444. // printf("can msg 0x%x lost,cycle time1000ms\n",COMInTable[18]);
  445. BcuRxErrorCounter[26]++; // can msg 0x18FF45F4
  446. // if(BcuRxErrorCounter[26]>=13)
  447. // printf("can msg 0x%x lost,cycle time1000ms\n",COMInTable[26]);
  448. BcuRxErrorCounter[27]++; // can msg 0x18FFC13A
  449. // if(BcuRxErrorCounter[27]>=13)
  450. // printf("can msg 0x%x lost,cycle time1000ms\n",COMInTable[27]);
  451. }
  452. if (TimeCounter % 30000 == 0) // period ==30000ms
  453. {
  454. BcuRxErrorCounter[1]++; // can msg 0x1801D8F3
  455. // if(BcuRxErrorCounter[1]>=13)
  456. // printf("can msg 0x%x lost,cycle time30000ms\n",COMInTable[1]);
  457. }
  458. }
  459. void BcuRxMsgSetInvalidValue(UINT32 ID)
  460. {
  461. switch (ID)
  462. {
  463. case 0x1801D0F3:
  464. BMS_ReqVIN = 0xFF;
  465. BMS_ReqHVOff = 0xFF;
  466. break;
  467. case 0x1801D8F3:
  468. BMS_SoftwareVersion = 0xFFFF;
  469. BMS_HardwareVersion = 0xFFFF;
  470. BMS_ProtocolEditionH = 0xFF;
  471. BMS_ProtocolEditionL = 0xFF;
  472. break;
  473. case 0x1880D0F3:
  474. BMS_CharDevNum = 0xFF;
  475. BMS_FtPosRly = 0xFF;
  476. BMS_FtNegRly = 0xFF;
  477. BMS_FtPosCharRly1 = 0xFF;
  478. BMS_FtNegCharRly1 = 0xFF;
  479. BMS_FtPosCharRly2 = 0xFF;
  480. BMS_FtNegCharRly2 = 0xFF;
  481. BMS_FtHeatRly1 = 0xFF;
  482. BMS_FtHeatRly2 = 0xFF;
  483. BMS_StPosRly = 0xFF;
  484. BMS_StNegRly = 0xFF;
  485. BMS_StPreCharRly = 0xFF;
  486. BMS_StPosCharRly1 = 0xFF;
  487. BMS_StNegCharRly1 = 0xFF;
  488. BMS_StPosCharRly2 = 0xFF;
  489. BMS_StNegCharRly2 = 0xFF;
  490. BMS_FtAuxRelayWeld = 0xFF;
  491. BMS_BraOpenCirc = 0xFF;
  492. BMS_FtBackCharCurrOutLim = 0xFF;
  493. BMS_FtPosRlyOpen = 0xFF;
  494. BMS_FtNegRlyOpen = 0xFF;
  495. BMS_FtPosCharRly1Open = 0xFF;
  496. BMS_FtPosCharRly2Open = 0xFF;
  497. BMS_FtNegCharRly1Open = 0xFF;
  498. BMS_FtNegCharRly2Open = 0xFF;
  499. BMS_FtTMSContClose = 0xFF;
  500. BMS_FtTMSContOpen = 0xFF;
  501. BMS_FtTMS = 0xFF;
  502. BMS_Ft24VSpy = 0xFF;
  503. BMS_FtPACKSelfProt = 0xFF;
  504. BMS_FtCharSockTempOver = 0xFF;
  505. BMS_FtTempOutCtrl = 0xFF;
  506. BMS_StPosHeatRly = 0xFF;
  507. BMS_StNegHeatRly = 0xFF;
  508. BMS_CharSysNum = 0xFF;
  509. BMS_FtCode = 0xFF;
  510. break;
  511. case 0x1881D0F3:
  512. BMS_ST1CheckSum = 0xFF;
  513. BMS_ST1Counter = 0xFF;
  514. BMS_Mode = 0xFF;
  515. BMS_AuxRlySt = 0xFF;
  516. BMS_BattBalaSt = 0xFF;
  517. BMS_CharGunSt = 0xFF;
  518. BMS_CharMode = 0xFF;
  519. BMS_CharSt = 0xFF;
  520. BMS_FtLvl = 0xFF;
  521. BMS_FtCellTempDiff = 0xFF;
  522. BMS_FtCellTempHigh = 0xFF;
  523. BMS_FtPACKOverVolt = 0xFF;
  524. BMS_FtPACKUndeVolt = 0xFF;
  525. BMS_FtSOCLow = 0xFF;
  526. BMS_FtCellOverVolt = 0xFF;
  527. BMS_FtCellUndeVolt = 0xFF;
  528. BMS_FtIns = 0xFF;
  529. BMS_FtCellOverVoltDiff = 0xFF;
  530. BMS_FtCharCurrOver = 0xFF;
  531. BMS_FtDisCharCurrOver = 0xFF;
  532. BMS_FtCellTempLow = 0xFF;
  533. BMS_FtBranVoltDifOver = 0xFF;
  534. BMS_FtBMSHardWare = 0xFF;
  535. BMS_FtSOCHigh = 0xFF;
  536. BMS_FtSOCJump = 0xFF;
  537. BMS_FtInCom = 0xFF;
  538. BMS_FtSysMism = 0xFF;
  539. BMS_FtHvIntLock = 0xFF;
  540. BMS_FtSmoke = 0xFF;
  541. BMS_FtFire = 0xFF;
  542. BMS_FtNum = 0xFF;
  543. break;
  544. case 0x1882D0F3:
  545. BMS_PackSOC = 0xFF;
  546. BMS_PackSOH = 0xFF;
  547. BMS_PackCurr = 0xFFFF;
  548. BMS_MaxCharCurr = 0xFFFF;
  549. BMS_MaxDisCharCurr = 0xFFFF;
  550. break;
  551. case 0x1883D0F3:
  552. BMS_PosIns = 0xFFFF;
  553. BMS_NegIns = 0xFFFF;
  554. BMS_BattVolt = 0xFFFF;
  555. BMS_LinkVolt = 0xFFFF;
  556. break;
  557. case 0x1884D0F3:
  558. BMS_MaxCellTemp = 0xFF;
  559. BMS_MinCellTemp = 0xFF;
  560. BMS_AverCellTemp = 0xFF;
  561. BMS_MaxCellTempCSC = 0xFF;
  562. BMS_MaxCellTempNum = 0xFF;
  563. BMS_MinCellTempCSC = 0xFF;
  564. BMS_MinCellTempNum = 0xFF;
  565. break;
  566. case 0x1885D0F3:
  567. BMS_MaxCellVolt = 0xFFFF;
  568. BMS_MaxCellVoltCSC = 0xFF;
  569. BMS_MaxCellVoltNum = 0xFF;
  570. BMS_AverCellVolt = 0xFFFF;
  571. break;
  572. case 0x1886D0F3:
  573. BMS_MinCellVolt = 0xFFFF;
  574. BMS_MinCellVoltCSC = 0xFF;
  575. BMS_MinCellVoltNum = 0xFF;
  576. BMS_ContChrgCurr = 0xFFFF;
  577. BMS_ContDisCharCurr = 0xFFFF;
  578. break;
  579. case 0x1887D0F3:
  580. BMS_CharReqVolt = 0xFFFF;
  581. BMS_CharReqCurr = 0xFFFF;
  582. BMS_SysInsRes = 0xFFFF;
  583. BMS_InsDeteSt = 0xFF;
  584. BMS_FtCharInsLow = 0xFF;
  585. BMS_FtCurrSenr = 0xFF;
  586. BMS_FtHeatingFilm = 0xFF;
  587. BMS_FtMainLoopPreChar = 0xFF;
  588. BMS_FtAuxLoopPreChar = 0xFF;
  589. BMS_FtACANLost = 0xFF;
  590. BMS_FtDCDC = 0xFF;
  591. BMS_FtSOCDif = 0xFF;
  592. BMS_FtCellOverDisChar = 0xFF;
  593. BMS_FtCharOver = 0xFF;
  594. BMS_FtContDisCharCurrOverLoad = 0xFF;
  595. BMS_FtContCharCurrOverLoad = 0xFF;
  596. break;
  597. case 0x1888D0F3:
  598. BMS_MaxDisCharPwr = 0xFFFF;
  599. BMS_MaxCharPwr = 0xFFFF;
  600. BMS_ContDisCharPwr = 0xFFFF;
  601. BMS_ContCharPwr = 0xFFFF;
  602. break;
  603. case 0x1889D0F3:
  604. BMS_InstEngyCons = 0xFFFF;
  605. BMS_TotalEngyCons = 0xFFFF;
  606. BMS_SOE = 0xFFFF;
  607. BMS_RmanCharTime = 0xFFFF;
  608. break;
  609. case 0x188AD0F3:
  610. BMS_Gun1DCNegTemp = 0xFF;
  611. BMS_Gun1DCPosTemp = 0xFF;
  612. BMS_Gun2DCNegTemp = 0xFF;
  613. BMS_Gun2DCPosTemp = 0xFF;
  614. BMS_CurrHeatSt = 0xFF;
  615. BMS_CurrCoolSt = 0xFF;
  616. BMS_FtCharCnct = 0xFF;
  617. BMS_FtOverDisCharCurrDuringChar = 0xFF;
  618. BMS_FtCharNTC = 0xFF;
  619. BMS_FtELock = 0xFF;
  620. BMS_CharNum = 0xFFFF;
  621. break;
  622. case 0x18C1D0F3:
  623. BMS_CellVoltFramNum = 0xFF;
  624. for (UINT16 i = 0; i < sizeof(BMS_CellVolt) / 2; i++)
  625. {
  626. BMS_CellVolt[i] = 0xFFFF;
  627. }
  628. break;
  629. case 0x18C2D0F3:
  630. BMS_CellTempFramNum = 0xFF;
  631. BMS_CSC_Code = 0xFF;
  632. for (UINT8 i = 0; i < sizeof(BMS_CellTemp); i++)
  633. {
  634. BMS_CellTemp[i] = 0xFF;
  635. }
  636. break;
  637. case 0x18E1D0F3:
  638. BMS_Checksum = 0xFF;
  639. BMS_PackComp = 0xFF;
  640. BMS_BattCodeLeng = 0xFF;
  641. BMS_SN[0] = 0xFF;
  642. BMS_SN[1] = 0xFF;
  643. BMS_SN[2] = 0xFF;
  644. BMS_SN[3] = 0xFF;
  645. BMS_SN[4] = 0xFF;
  646. BMS_SN[5] = 0xFF;
  647. break;
  648. case 0x18E2D0F3:
  649. BMS_Checksum = 0xFF;
  650. BMS_SN[6] = 0xFF;
  651. BMS_SN[7] = 0xFF;
  652. BMS_SN[8] = 0xFF;
  653. BMS_SN[9] = 0xFF;
  654. BMS_SN[10] = 0xFF;
  655. BMS_SN[11] = 0xFF;
  656. BMS_SN[12] = 0xFF;
  657. break;
  658. case 0x18E3D0F3:
  659. BMS_Checksum = 0xFF;
  660. BMS_SN[13] = 0xFF;
  661. BMS_SN[14] = 0xFF;
  662. BMS_SN[15] = 0xFF;
  663. BMS_SN[16] = 0xFF;
  664. BMS_SN[17] = 0xFF;
  665. BMS_SN[18] = 0xFF;
  666. BMS_SN[19] = 0xFF;
  667. break;
  668. case 0x18E4D0F3:
  669. BMS_Checksum = 0xFF;
  670. BMS_SN[20] = 0xFF;
  671. BMS_SN[21] = 0xFF;
  672. BMS_SN[22] = 0xFF;
  673. BMS_SN[23] = 0xFF;
  674. BMS_SN[24] = 0xFF;
  675. BMS_SN[25] = 0xFF;
  676. BMS_SN[26] = 0xFF;
  677. break;
  678. case 0x18E5D0F3:
  679. BMS_BattRateCap = 0xFFFF;
  680. BMS_BattRateVolt = 0xFFFF;
  681. BMS_BattRateEngy = 0xFFFF;
  682. BMS_BattType = 0xFF;
  683. BMS_CoolType = 0xFF;
  684. break;
  685. case 0x18E6D0F3:
  686. BMS_CSC_Total = 0xFF;
  687. BMS_CellTotal = 0xFFFF;
  688. BMS_TempTotal = 0xFFFF;
  689. BMS_CellVoltLevel = 0xFF;
  690. BMS_CellMinVolt = 0xFF;
  691. BMS_CellMaxVolt = 0xFF;
  692. break;
  693. case 0x18F1D0F3:
  694. BMS_TotalCharEngy = 0xFFFFFFFF;
  695. BMS_TotalDisCharEngy = 0xFFFFFFFF;
  696. BMS_SingleCharEngy = 0xFFFF;
  697. break;
  698. case 0x18F2D0F3:
  699. BMS_TotalBackCharEngy = 0xFFFFFFFF;
  700. BMS_TotalStaCharEngy = 0xFFFFFFFF;
  701. break;
  702. case 0x18F3D0F3:
  703. BMS_TotalGunCharEngy = 0xFFFFFFFF;
  704. BMS_TotalGunCharCapy = 0xFFFFFFFF;
  705. break;
  706. case 0x18F4D0F3:
  707. BMS_TotalCharCapy = 0xFFFFFFFF;
  708. BMS_TotalDisCharCapy = 0xFFFFFFFF;
  709. BMS_SingleCharCapy = 0xFFFF;
  710. break;
  711. case 0x18F5D0F3:
  712. BMS_TotalBackCharCapy = 0xFFFFFFFF;
  713. BMS_TotalStaCharCapy = 0xFFFFFFFF;
  714. BMS_HVBranNum = 0xFF;
  715. BMS_SingleHVBranchCellNum = 0xFF;
  716. break;
  717. case 0x18FF45F4:
  718. BMS_ReqMode = 0xFF;
  719. BMS_HVCmd = 0xFF;
  720. BMS_ChgSts = 0xFF;
  721. BMS_HVRelaySts = 0xFF;
  722. BMS_HVVolt = 0xFFFF;
  723. BMS_SetTemp = 0xFF;
  724. BMS_Life = 0xFF;
  725. BMS_CRC = 0xFF;
  726. break;
  727. case 0x18FFC13A:
  728. TMS_WorkStatus = 0xFF;
  729. TMS_HVRelayST = 0xFF;
  730. TMS_OutletTemp = 0xFF;
  731. TMS_InletTemp = 0xFF;
  732. TMS_ReqPow = 0xFFFF;
  733. TMS_ErrCode = 0xFF;
  734. TMS_FaultLevel = 0xFF;
  735. break;
  736. default:
  737. break;
  738. }
  739. }
  740. void BcuEncodeFunction(UINT32 ID, UINT8 *rawData)
  741. {
  742. switch (ID)
  743. {
  744. case 0x18FFF8A7:
  745. {
  746. EBC_Counter = EBC_Counter + 1;
  747. if (EBC_Counter > 15)
  748. {
  749. EBC_Counter = 0;
  750. }
  751. EBC_CharCnctSt = m_flg_HVlock1;
  752. EBC_DisCharCnctSt = m_flg_HVlock2;
  753. EBC_CnctSt = (m_flg_HVlock1 && m_flg_HVlock2);
  754. if (ebcd_st_lockSucJug == 1)
  755. {
  756. EBC_LockSt = 2;
  757. }
  758. else if (ebcd_st_unlockSucJug == 1)
  759. {
  760. EBC_LockSt = 1;
  761. }
  762. else
  763. {
  764. EBC_LockSt = 0;
  765. }
  766. EBC_State = ebcd_st_ebcWork;
  767. EBC_AirPressure = ebcd_P_airSensor;
  768. UINT16 ErrTemp = 0;
  769. ErrTemp = GetErrorNum(ErrArray, sizeof(ErrArray) / 2);
  770. EBC_FtLvl = ErrTemp / 10000;
  771. EBC_FtCode = ErrTemp % 10000;
  772. /*Test*/
  773. EBC_LockSt = 0x02;
  774. EBC_CnctSt = 0x01;
  775. EBC_DisCharCnctSt = 0x01;
  776. EBC_CharCnctSt = 0x01;
  777. *(rawData + 0) = EBC_Counter;
  778. *(rawData + 1) = (EBC_CharCnctSt << 6) | (EBC_DisCharCnctSt << 4) | (EBC_CnctSt << 2) | (EBC_LockSt);
  779. *(rawData + 2) = 0x00;
  780. *(rawData + 3) = EBC_FtLvl;
  781. *(rawData + 4) = EBC_FtCode;
  782. *(rawData + 5) = 0x00;
  783. *(rawData + 6) = EBC_AirPressure;
  784. *(rawData + 7) = ((EBC_State << 5) & 0x03) | ((EBC_StopChgCmd << 4) & 0x01) | ((EBC_ReqHVOff << 3) & 0x01) | ((EBC_InhiHVOn << 2) & 0x01) | ((EBC_ActHeatReq << 1) & 0x01) | ((EBC_CharSt)&0x01);
  785. break;
  786. }
  787. case 0x18FEF8A7:
  788. {
  789. EBC_DisCharPos1Temp = ebcd_T_plugin[0];
  790. EBC_DischarNeg1Temp = ebcd_T_plugin[1];
  791. EBC_DisCharPos2Temp = ebcd_T_plugin[2];
  792. EBC_DisCharNeg2Temp = ebcd_T_plugin[3];
  793. *(rawData + 0) = EBC_DisCharPos1Temp;
  794. *(rawData + 1) = EBC_DischarNeg1Temp;
  795. *(rawData + 2) = EBC_DisCharPos2Temp;
  796. *(rawData + 3) = EBC_DisCharNeg2Temp;
  797. *(rawData + 4) = EBC_ChgPos1Temp;
  798. *(rawData + 5) = EBC_ChgNeg1Temp;
  799. *(rawData + 6) = EBC_ChgPos2Temp;
  800. *(rawData + 7) = EBC_ChgNeg2Temp;
  801. break;
  802. }
  803. default:
  804. break;
  805. }
  806. }