VcuCanProtocolFunc.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * @Author : ChenJie
  3. * @Date : 2021-12-24 15:26:57
  4. * @Version : V3.0
  5. * @LastEditors : ChenJie
  6. * @LastEditTime : 2022-05-09 16:13:46
  7. * @Description : file content
  8. * @FilePath : \VehicleControl\VehicleControl\src\System\Vehicle\Communication\VcuCanProtocolFunc.c
  9. */
  10. #include "VcuCanProtocolFunc.h"
  11. void VcuDecodeFunction(UINT32 ID, UINT8 *rawData)
  12. {
  13. switch (ID)
  14. {
  15. case 0x18F101D0:
  16. VCU_St_BattRly = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0x3);
  17. VCU_St_Check = (UINT8)(((*(UINT8 *)(rawData + 0)) >> 2) & 0x3);
  18. VCU_St_SysIntLock = (UINT8)(((*(UINT8 *)(rawData + 0)) >> 4) & 0x3);
  19. VCU_St_Veh = (UINT8)(((*(UINT8 *)(rawData + 0)) >> 6) & 0x3);
  20. VCU_St_Gear = (UINT8)(((*(UINT8 *)(rawData + 3))) & 0xFF);
  21. VCU_Ft_Sys = (UINT8)(((*(UINT8 *)(rawData + 4))) & 0x1);
  22. VCU_Ft_Tran = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 1) & 0x1);
  23. VCU_Ft_BattSys = (UINT8)(((*(UINT8 *)(rawData + 4)) >> 5) & 0x1);
  24. VCU_State_Veh = (UINT8)(((*(UINT8 *)(rawData + 6))) & 0xF);
  25. VCU_Counter = (UINT8)(((*(UINT8 *)(rawData + 7))) & 0xFF);
  26. VcuRxFlag[0] = 0x01;
  27. break;
  28. case 0x18F103D0:
  29. VCU_SoftVersion = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF);
  30. VCU_St_AccPedal = (UINT8)(((*(UINT8 *)(rawData + 3))) & 0xFF);
  31. VCU_St_BrakePedal = (UINT8)(((*(UINT8 *)(rawData + 4))) & 0xFF);
  32. VcuRxFlag[1] = 0x01;
  33. break;
  34. case 0x18E1F3D0:
  35. {
  36. UINT8 VinNum = 0;
  37. VinNum = (UINT8)(((*(UINT8 *)(rawData + 0))) & 0xFF);
  38. if (VinNum == 0 || VinNum > 3)
  39. {
  40. break;
  41. }
  42. VCU_St_VinRecv = ((VinNum == 1) | ((VinNum == 2) << 1) | ((VinNum == 3) << 2)) | VCU_St_VinRecv;
  43. for (UINT8 i = 0; i < 7; i++)
  44. {
  45. if(((VinNum - 1) * 7 + i) < 17)
  46. {
  47. VCU_Num_VIN[(VinNum - 1) * 7 + i] = (UINT8)(((*(UINT8 *)(rawData + i))) & 0xFF);;
  48. }
  49. }
  50. VcuRxFlag[2] = 0x01;
  51. break;
  52. }
  53. case 0x18FEF100:
  54. VCU_St_ParkBrakeSw = (UINT8)(((*(UINT8 *)(rawData + 0)) >> 2) & 0x3);
  55. VcuRxFlag[3] = 0x01;
  56. break;
  57. default:
  58. break;
  59. }
  60. }
  61. void VcuRxDiagnose(void)
  62. {
  63. static UINT16 TimeCounter = 0;
  64. TimeCounter = TimeCounter + 10;
  65. for (UINT8 i = 0; i < sizeof(VcuInTable) / 4; i++)
  66. {
  67. if (VcuRxFlag[i] == 1) // received msg, and clear the error conter
  68. {
  69. VcuRxErrorCounter[i] = 0;
  70. VcuRxFlag[i] = 0;
  71. continue;
  72. }
  73. if (VcuRxErrorCounter[i] < 3)
  74. {
  75. VcuRxShortError[i] = 0;
  76. VcuRxLongError[i] = 0;
  77. }
  78. else if (VcuRxErrorCounter[i] >= 3 && VcuRxErrorCounter[i] < 13)
  79. {
  80. VcuRxShortError[i] = 1;
  81. VcuRxLongError[i] = 0;
  82. }
  83. else if (VcuRxErrorCounter[i] >= 13)
  84. {
  85. VcuRxShortError[i] = 0;
  86. VcuRxLongError[i] = 1;
  87. VcuRxMsgSetInvalidValue(VcuInTable[i]);
  88. VcuRxErrorCounter[i] = 0;
  89. }
  90. else if (VcuRxErrorCounter[i] == 0xFF)
  91. {
  92. VcuRxErrorCounter[i] = 0xFE;
  93. }
  94. }
  95. if (TimeCounter % 100 == 0) // period <=100ms
  96. {
  97. VcuRxErrorCounter[0]++; // can msg 0x18F101D0
  98. // if(canRxErrorCounter[0]>=13)
  99. VcuRxErrorCounter[1]++; // can msg 0x18F103D0
  100. // if(canRxErrorCounter[1]>=13)
  101. }
  102. }
  103. void VcuRxMsgSetInvalidValue(UINT32 ID)
  104. {
  105. switch (ID)
  106. {
  107. case 0x18F101D0:
  108. VCU_St_BattRly = 0xFF;
  109. VCU_St_Check = 0xFF;
  110. VCU_St_SysIntLock = 0xFF;
  111. VCU_St_Veh = 0xFF;
  112. VCU_St_Gear = 0xFF;
  113. VCU_Ft_Sys = 0xFF;
  114. VCU_Ft_Tran = 0xFF;
  115. VCU_Ft_BattSys = 0xFF;
  116. VCU_State_Veh = 0xFF;
  117. VCU_Counter = 0xFF;
  118. break;
  119. case 0x18F103D0:
  120. VCU_SoftVersion = 0xFF;
  121. VCU_St_AccPedal = 0xFF;
  122. VCU_St_BrakePedal = 0xFF;
  123. break;
  124. case 0x18FEF100:
  125. break;
  126. default:
  127. break;
  128. }
  129. }