CanProtocolFunc.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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\CanProtocolFunc.c
  9. */
  10. /*
  11. * CanProtocol.c
  12. * can协议转换
  13. * Created on: 2021年12月20日
  14. * Author: QiXiang_CHENJIE
  15. */
  16. #include <CanProtocolFunc.h>
  17. #include "HardwareLib.h"
  18. /******************************************
  19. *
  20. *Can0接收发送函数
  21. **************************************** */
  22. void Can0RxMsgSetInvalidValue(UINT32 ID);
  23. void Can0Encode(UINT32 ID, UINT8 *rawData)
  24. {
  25. }
  26. void Can0Decode(UINT32 ID, UINT8 *rawData)
  27. {
  28. switch(ID)
  29. {
  30. case 0x18FF5A51:
  31. {
  32. gashighLevel_gf1 = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF);
  33. gaslowLevel_gf1 = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0xFF);
  34. temp_gf1 = (UINT8)(((*(UINT8 *)(rawData + 2))) & 0xFF);
  35. warningLevel_gf1 = (UINT8)(((*(UINT8 *)(rawData + 4))) & 0xFF);
  36. workMode_gf1 = (UINT8)(((*(UINT8 *)(rawData + 5))) & 0xFF);
  37. fumesHigh_gf1 = (UINT8)(((*(UINT8 *)(rawData + 6))) & 0xFF);
  38. fumesLow_gf1 = (UINT8)(((*(UINT8 *)(rawData + 7))) & 0xFF);
  39. Can0RxFlag[0] = 0x01;
  40. break;
  41. }
  42. case 0x18FF5A52:
  43. {
  44. gashighLevel_gf2 = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF);
  45. gaslowLevel_gf2 = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0xFF);
  46. temp_gf2 = (UINT8)(((*(UINT8 *)(rawData + 2))) & 0xFF);
  47. warningLevel_gf2 = (UINT8)(((*(UINT8 *)(rawData + 4))) & 0xFF);
  48. workMode_gf2 = (UINT8)(((*(UINT8 *)(rawData + 5))) & 0xFF);
  49. fumesHigh_gf2 = (UINT8)(((*(UINT8 *)(rawData + 6))) & 0xFF);
  50. fumesLow_gf2 = (UINT8)(((*(UINT8 *)(rawData + 7))) & 0xFF);
  51. Can0RxFlag[1] = 0x01;
  52. break;
  53. }
  54. default:
  55. {
  56. break;
  57. }
  58. }
  59. }
  60. void Can0RxDiagnose(void)
  61. {
  62. static UINT32 TimeCounter = 0; // ms
  63. TimeCounter = TimeCounter + 10; //
  64. for (UINT8 i = 0; i < sizeof(Can0InTable) / 4; i++)
  65. {
  66. if (Can0RxFlag[i] == 1) // received msg, and clear the error conter
  67. {
  68. Can0RxErrorCounter[i] = 0;
  69. Can0RxFlag[i] = 0;
  70. continue;
  71. }
  72. if (Can0RxErrorCounter[i] < 3)
  73. {
  74. Can0RxShortError[i] = 0;
  75. Can0RxLongError[i] = 0;
  76. }
  77. else if (Can0RxErrorCounter[i] >= 3 && Can0RxErrorCounter[i] < 50)
  78. {
  79. Can0RxShortError[i] = 1;
  80. Can0RxLongError[i] = 0;
  81. }
  82. else if (Can0RxErrorCounter[i] >= 50)
  83. {
  84. Can0RxShortError[i] = 0;
  85. Can0RxLongError[i] = 1;
  86. Can0RxMsgSetInvalidValue(Can0InTable[i]);
  87. Can0RxErrorCounter[i] = 0;
  88. }
  89. else if (Can0RxErrorCounter[i] == 0xFF)
  90. {
  91. Can0RxErrorCounter[i] = 0xFE;
  92. }
  93. }
  94. if (TimeCounter % 100 == 0) // period <=100ms
  95. {
  96. Can0RxErrorCounter[0]++;
  97. }
  98. }
  99. void Can0RxMsgSetInvalidValue(UINT32 ID)
  100. {
  101. switch (ID)
  102. {
  103. case 0x18FF5A51:
  104. {
  105. gashighLevel_gf1 = 0xFF;
  106. gaslowLevel_gf1 = 0xFF;
  107. temp_gf1 = 0xFF;
  108. warningLevel_gf1 = 0xFF;
  109. workMode_gf1 = 0xFF;
  110. fumesHigh_gf1 = 0xFF;
  111. fumesLow_gf1 = 0xFF;
  112. break;
  113. }
  114. case 0x18FF5A52:
  115. {
  116. gashighLevel_gf2 = 0xFF;
  117. gaslowLevel_gf2 = 0xFF;
  118. temp_gf2 = 0xFF;
  119. warningLevel_gf2 = 0xFF;
  120. workMode_gf2 = 0xFF;
  121. fumesHigh_gf2 = 0xFF;
  122. fumesLow_gf2 = 0xFF;
  123. break;
  124. }
  125. default:
  126. break;
  127. }
  128. }
  129. /******************************************
  130. *
  131. *Can1接收发送函数
  132. **************************************** */
  133. /**
  134. * @brief : BMC发送
  135. * @param {uint8} CmdIdx
  136. * @return {*}
  137. */
  138. void Can1RxMsgSetInvalidValue(UINT32 ID);
  139. void Can1Encode(UINT32 ID, UINT8 *rawData)
  140. {
  141. switch(ID)
  142. {
  143. case 0x18FF1100:
  144. {
  145. *(rawData + 0) = connectorHvlock1;
  146. *(rawData + 1) = connectorHvlock2;
  147. *(rawData + 2) = chrgModuelPwrCtlFB;
  148. *(rawData + 3) = paraChrgCtlFB;
  149. *(rawData + 4) = outToChrgCtlFB_A;
  150. *(rawData + 5) = outToBaseCtlFB_A;
  151. *(rawData + 6) = outToChrgCtlFB_B;
  152. *(rawData + 7) = outToBaseCtlFB_B;
  153. break;
  154. }
  155. case 0x18FF1101:
  156. {
  157. *(rawData + 0) = fuseActionFB_A;
  158. *(rawData + 1) = fuseActionFB_B;
  159. *(rawData + 2) = sigSwitchReadyFB_A;
  160. *(rawData + 3) = sigSwitchReadyFB_B;
  161. *(rawData + 4) = ctrlFXFB1;
  162. *(rawData + 5) = ctrlFXFB2;
  163. *(rawData + 6) = 0xFF;
  164. *(rawData + 7) = 0xFF;
  165. break;
  166. }
  167. case 0x18FF1102:
  168. {
  169. *(rawData + 0) = conn1Temp1;
  170. *(rawData + 1) = conn1Temp2;
  171. *(rawData + 2) = conn2Temp1;
  172. *(rawData + 3) = conn2Temp2;
  173. *(rawData + 4) = chrgGunTemp1_A;
  174. *(rawData + 5) = chrgGunTemp2_A;
  175. *(rawData + 6) = chrgGunTemp1_B;
  176. *(rawData + 7) = chrgGunTemp2_B;
  177. break;
  178. }
  179. case 0x18FF1103:
  180. {
  181. *(rawData + 0) = chrgBoxTemp1;
  182. *(rawData + 1) = chrgBoxTemp2;
  183. *(rawData + 2) = chrgBoxGasOver1;
  184. *(rawData + 3) = chrgBoxGasOver2;
  185. *(rawData + 4) = chrgBoxFumesOver1;
  186. *(rawData + 5) = chrgBoxFumesOver2;
  187. *(rawData + 6) = chrgBox1Warning;
  188. *(rawData + 7) = chrgBox2Warning;
  189. break;
  190. }
  191. default:
  192. break;
  193. }
  194. }
  195. /**
  196. * @brief : BMC解析
  197. * @param {*}
  198. * @return {*}
  199. */
  200. void Can1Decode(UINT32 ID, UINT8 *rawData)
  201. {
  202. switch(ID)
  203. {
  204. case 0x18FF1200:
  205. {
  206. chrgModulePwrCtrl = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF);
  207. baseSwitchCtrl = (UINT8)(((*(UINT8 *)(rawData + 1))) & 0xFF);
  208. paraChrgCtrlState = (UINT8)(((*(UINT8 *)(rawData + 2))) & 0xFF);
  209. chrgStartState = (UINT8)(((*(UINT8 *)(rawData + 3))) & 0xFF);
  210. chrgStopState = (UINT8)(((*(UINT8 *)(rawData + 4))) & 0xFF);
  211. Can1RxFlag[0] = 0x01;
  212. break;
  213. }
  214. default:
  215. {
  216. break;
  217. }
  218. }
  219. }
  220. void Can1RxDiagnose(void)
  221. {
  222. static UINT32 TimeCounter = 0; // ms
  223. TimeCounter = TimeCounter + 10; //
  224. for (UINT8 i = 0; i < sizeof(Can1InTable) / 4; i++)
  225. {
  226. if (Can1RxFlag[i] == 1) // received msg, and clear the error conter
  227. {
  228. Can1RxErrorCounter[i] = 0;
  229. Can1RxFlag[i] = 0;
  230. continue;
  231. }
  232. if (Can1RxErrorCounter[i] < 3)
  233. {
  234. Can1RxShortError[i] = 0;
  235. Can1RxLongError[i] = 0;
  236. }
  237. else if (Can1RxErrorCounter[i] >= 3 && Can1RxErrorCounter[i] < 50)
  238. {
  239. Can1RxShortError[i] = 1;
  240. Can1RxLongError[i] = 0;
  241. }
  242. else if (Can1RxErrorCounter[i] >= 50)
  243. {
  244. Can1RxShortError[i] = 0;
  245. Can1RxLongError[i] = 1;
  246. Can1RxMsgSetInvalidValue(Can1InTable[i]);
  247. Can1RxErrorCounter[i] = 0;
  248. }
  249. else if (Can1RxErrorCounter[i] == 0xFF)
  250. {
  251. Can1RxErrorCounter[i] = 0xFE;
  252. }
  253. }
  254. if (TimeCounter % 100 == 0) // period <=100ms
  255. {
  256. Can1RxErrorCounter[0]++;
  257. }
  258. }
  259. void Can1RxMsgSetInvalidValue(UINT32 ID)
  260. {
  261. switch (ID)
  262. {
  263. case 0x18FF1200:
  264. chrgModulePwrCtrl = 0xFF;
  265. baseSwitchCtrl = 0xFF;
  266. paraChrgCtrlState = 0xFF;
  267. chrgStartState = 0xFF;
  268. chrgStopState = 0xFF;
  269. break;
  270. default:
  271. break;
  272. }
  273. }