AppFunc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600
  1. /*
  2. * @Author : ChenJie
  3. * @Date : 2021-12-15 10:40:06
  4. * @Version : V3.0
  5. * @LastEditors : ChenJie
  6. * @LastEditTime : 2022-05-10 19:26:35
  7. * @Description : AppFunc
  8. * @FilePath : \VehicleControl\VehicleControl\src\System\Vehicle\AppFunc.c
  9. */
  10. #include "string.h"
  11. #include "stdlib.h"
  12. #include "HardwareLib.h"
  13. #include "CanVar.h"
  14. #include "math.h"
  15. #include "AppFunc.h"
  16. #include "Std_Types.h"
  17. #define Lock 0
  18. #define Unlock 1
  19. #define LockCtrl() PSwtDrv_Interface(_PSWT_INDEX_HBAK1_CHAN, Lock)
  20. #define UnlockCtrl() PSwtDrv_Interface(_PSWT_INDEX_HBAK1_CHAN, Unlock)
  21. void LockAndUnlockCtrl()
  22. {
  23. static uint16 LockDelay = 0;
  24. static uint16 UnlockDelay = 0;
  25. static uint16 BleConCounter = 0;
  26. static uint16 battSwpeModeCounter = 0;
  27. if (ebcd_flg_ebcManCtrlEn) //手动控制使能
  28. {
  29. if (ebcd_flg_ebcManCtrlMode == 1) //循环控制模式
  30. {
  31. if (ebcd_st_lockSensor == 1) //处于锁紧状态,传感器判定一个
  32. {
  33. LockDelay = LockDelay + 10;
  34. if (LockDelay > LockDelayTime) //锁紧状态超时就解锁
  35. {
  36. ManuControlTimes++;
  37. LockDelay = 0;
  38. ebcd_st_SwitchCtrlFlg = Unlock;
  39. }
  40. }
  41. else if (ebcd_st_unlockSensor == 1) //处于解锁状态,传感器判定一个
  42. {
  43. UnlockDelay = UnlockDelay + 10;
  44. if (UnlockDelay > UnlockDelayTime)
  45. {
  46. UnlockDelay = 0;
  47. ebcd_st_SwitchCtrlFlg = Lock;
  48. }
  49. }
  50. }
  51. else if (ebcd_flg_ebcManCtrlMode == 2) //控制锁紧
  52. {
  53. ebcd_st_SwitchCtrlFlg = Lock;
  54. }
  55. else if (ebcd_flg_ebcManCtrlMode == 3) //控制解锁
  56. {
  57. ebcd_st_SwitchCtrlFlg = Unlock;
  58. }
  59. }
  60. else //正常工作模式
  61. {
  62. switch (ebcd_st_ebcWork)
  63. {
  64. case DriveMode: //行车状态,自动进入,默认状态
  65. {
  66. PSwtDrv_Interface(_PSWT_INDEX_EBCLEDCONTROL, 0); //行车状态换电指示灯关闭
  67. if (bled_flg_handShake == 1)
  68. {
  69. ebcd_st_ebcWork = CommuMode; //进入通讯状态
  70. bled_flg_handShake = 0;
  71. break;
  72. }
  73. break;
  74. }
  75. case CommuMode: //通讯状态,握手才能进入
  76. {
  77. BleConCounter = BleConCounter + 10;
  78. if ((BleConCounter % 1000) < 500) //换电指示灯闪烁
  79. {
  80. PSwtDrv_Interface(_PSWT_INDEX_EBCLEDCONTROL, 1);
  81. }
  82. else
  83. {
  84. PSwtDrv_Interface(_PSWT_INDEX_EBCLEDCONTROL, 0);
  85. }
  86. if (BleConCounter >= 60 * 1000 || bled_flg_backToDrv == 1)
  87. {
  88. ebcd_st_ebcWork = DriveMode; //切换到行车状态
  89. BleConCounter = 0;
  90. bled_flg_backToDrv = 0;
  91. break;
  92. }
  93. else if (BattCD_stWakeupU.B.bLogic == 0 && BattCD_stWakeupU.B.bWkpSig1 == 1)
  94. {
  95. ebcd_st_ebcWork = SwapMode; //切换到换电状态
  96. BleConCounter = 0;
  97. break;
  98. }
  99. if (bled_st_dataTrans == 1)
  100. {
  101. BleConCounter = 0;
  102. bled_st_dataTrans = 0;
  103. }
  104. break;
  105. }
  106. case SwapMode: //换电状态
  107. {
  108. PSwtDrv_Interface(_PSWT_INDEX_EBCLEDCONTROL, 1); //换电状态换电指示灯常亮
  109. battSwpeModeCounter = battSwpeModeCounter + 10;
  110. if (bled_flg_swapBattDone == 1)
  111. {
  112. ebcd_Nr_swapBatt++;
  113. ebcd_Nr_swapSucBatt++;
  114. bled_flg_swapBattDone = 0;
  115. ebcd_st_ebcWork = CommuMode; //切换到通讯状态
  116. break;
  117. }
  118. else if (battSwpeModeCounter >= 60 * 1000)
  119. {
  120. ebcd_Nr_swapBatt++;
  121. battSwpeModeCounter = DriveMode; //切换到行车状态
  122. ebcd_st_ebcWork = 0;
  123. break;
  124. }
  125. if (bled_st_dataTrans == 1)
  126. {
  127. battSwpeModeCounter = 0;
  128. bled_st_dataTrans = 0;
  129. }
  130. if (bled_flg_unlockCmdForce)
  131. {
  132. ebcd_st_SwitchCtrlFlg = Unlock;
  133. bled_flg_unlockCmdForce = 0;
  134. }
  135. if (bled_flg_lockCmdForce)
  136. {
  137. ebcd_st_SwitchCtrlFlg = Lock;
  138. bled_flg_lockCmdForce = 0;
  139. }
  140. break;
  141. }
  142. }
  143. }
  144. //锁紧解锁执行
  145. if (ebcd_st_SwitchCtrlFlg == Unlock)
  146. {
  147. UnlockCtrl();
  148. }
  149. else
  150. {
  151. LockCtrl();
  152. }
  153. }
  154. /**
  155. * @brief : 互锁检测函数
  156. * @param {*}
  157. * @return {*}
  158. */
  159. void GetHVLockState(void)
  160. {
  161. // PWM输出,互锁1检测,频率100HZ,占空比30%
  162. uint16 VehCo_fTestUI = 1000;
  163. uint16 VehCo_rTestUW = 3000;
  164. uint32 PwmFreAcq = 0;
  165. uint16 PwmDutyAcq = 0;
  166. PPWMDrv_Interface(_PPWM_INDEX_HVLOCK2, VehCo_fTestUI, VehCo_rTestUW);
  167. PulseAcqDrv_GetChanFreq(_PULSEACQ_INDEX_HVLOCK2, &PwmFreAcq, &PwmDutyAcq);
  168. if (abs(PwmFreAcq - VehCo_fTestUI) < 100 && abs(PwmDutyAcq - VehCo_rTestUW) < 500)
  169. {
  170. m_flg_HVlock1 = 1;
  171. }
  172. else
  173. {
  174. m_flg_HVlock1 = 0;
  175. }
  176. //互锁2检测,配置高有效,悬空为0则未接入,高电平为1则接入,
  177. // DINDrv_SetChanThres(_DIN_INDEX_PLUGHVLOCK, 0, 4095 * 3);
  178. m_flg_HVlock2 = DINDrv_GetChanState(_DIN_INDEX_PLUGHVLOCK);
  179. }
  180. /**
  181. * @brief : 数字量传感器信号检测函数
  182. * @param {*}
  183. * @return {*}
  184. */
  185. void GetDIOState(void)
  186. {
  187. uint8 temp[4];
  188. //松开传感器检测,配置低有效,底层悬空为1,触发为0,应用层输出悬空为0,触发为1
  189. memset(temp, 0x00, 4);
  190. ebcd_st_unlockSensor = 0;
  191. DINDrv_SetChanThres(_DIN_INDEX_UNLOCKSENSOR1, 1, 4095U);
  192. DINDrv_SetChanThres(_DIN_INDEX_UNLOCKSENSOR2, 1, 4095U);
  193. DINDrv_SetChanThres(_DIN_INDEX_UNLOCKSENSOR3, 1, 4095U);
  194. DINDrv_SetChanThres(_DIN_INDEX_UNLOCKSENSOR4, 1, 4095U);
  195. temp[0] = !DINDrv_GetChanState(_DIN_INDEX_UNLOCKSENSOR1);
  196. temp[1] = !DINDrv_GetChanState(_DIN_INDEX_UNLOCKSENSOR2);
  197. temp[2] = !DINDrv_GetChanState(_DIN_INDEX_UNLOCKSENSOR3);
  198. temp[3] = !DINDrv_GetChanState(_DIN_INDEX_UNLOCKSENSOR4);
  199. ebcd_st_unlockSensor = (getbit(temp[3], 0) << 3) | (getbit(temp[2], 0) << 2) | (getbit(temp[1], 0) << 1) | (getbit(temp[0], 0) << 0);
  200. //夹紧传感器检测,配置低有效,底层悬空为1,触发为0,应用层输出悬空为0,触发为1
  201. memset(temp, 0x00, 4);
  202. ebcd_st_lockSensor = 0;
  203. DINDrv_SetChanThres(_DIN_INDEX_LOCKSENSOR1, 1, 4095U);
  204. DINDrv_SetChanThres(_DIN_INDEX_LOCKSENSOR2, 1, 4095U);
  205. DINDrv_SetChanThres(_DIN_INDEX_LOCKSENSOR3, 1, 4095U);
  206. DINDrv_SetChanThres(_DIN_INDEX_LOCKSENSOR4, 1, 4095U);
  207. temp[0] = !DINDrv_GetChanState(_DIN_INDEX_LOCKSENSOR1);
  208. temp[1] = !DINDrv_GetChanState(_DIN_INDEX_LOCKSENSOR2);
  209. temp[2] = !DINDrv_GetChanState(_DIN_INDEX_LOCKSENSOR3);
  210. temp[3] = !DINDrv_GetChanState(_DIN_INDEX_LOCKSENSOR4);
  211. ebcd_st_lockSensor = (getbit(temp[3], 0) << 3) | (getbit(temp[2], 0) << 2) | (getbit(temp[1], 0) << 1) | (getbit(temp[0], 0) << 0);
  212. //落座传感器检测,高有效,悬空为0则未接入,高电平为1则接入
  213. memset(temp, 0x00, 4);
  214. temp[0] = !DINDrv_GetChanState(_DIN_INDEX_READYSENSOR1);
  215. temp[1] = !DINDrv_GetChanState(_DIN_INDEX_READYSENSOR2);
  216. ebcd_st_pedstSensor = (getbit(temp[1], 0) << 1) | (getbit(temp[0], 0) << 0);
  217. }
  218. /**
  219. * @brief : 获取模拟量输入值,并进行转换
  220. * @param {*}
  221. * @return {*}
  222. */
  223. void GetAIOValue(void)
  224. {
  225. uint16 AirPressureTemp_Vol = 0;
  226. uint16 PluginTemp1_Vol = 0;
  227. uint32 PluginTemp1_R = 0;
  228. uint16 PluginTemp2_Vol = 0;
  229. uint32 PluginTemp2_R = 0;
  230. uint16 PluginTemp3_Vol = 0;
  231. uint32 PluginTemp3_R = 0;
  232. uint16 PluginTemp4_Vol = 0;
  233. uint32 PluginTemp4_R = 0;
  234. AirPressureTemp_Vol = ATDDrv_GetChanResult(_ATD_INDEX_AIRPRESSURE);
  235. AirPressureTemp_Vol = (uint16)(AirPressureTemp_Vol * 1000 / 4095.0);
  236. Test_LockPressure = AirPressureTemp_Vol; //锁紧力测试变量
  237. /*气压数据转换*/
  238. AirPressureTemp_Vol = MAX(AirPressureTemp_Vol, 500);
  239. AirPressureTemp_Vol = MIN(AirPressureTemp_Vol, 4500);
  240. ebcd_P_airSensor = (uint8)((AirPressureTemp_Vol - 500) / 40);
  241. /*温度采集获取*/
  242. PluginTemp1_Vol = ATDDrv_GetChanResult(_ATD_INDEX_PLUGINTEMP1);
  243. PluginTemp2_Vol = ATDDrv_GetChanResult(_ATD_INDEX_PLUGINTEMP2);
  244. PluginTemp3_Vol = ATDDrv_GetChanResult(_ATD_INDEX_PLUGINTEMP3);
  245. PluginTemp4_Vol = ATDDrv_GetChanResult(_ATD_INDEX_PLUGINTEMP4);
  246. PluginTemp1_R = (uint32)((PluginTemp1_Vol / (5.0 * 4095 - PluginTemp1_Vol)) * 1000.0);
  247. PluginTemp2_R = (uint32)((PluginTemp2_Vol / (5.0 * 4095 - PluginTemp2_Vol)) * 1000.0);
  248. PluginTemp3_R = (uint32)((PluginTemp3_Vol / (5.0 * 4095 - PluginTemp3_Vol)) * 1000.0);
  249. PluginTemp4_R = (uint32)((PluginTemp4_Vol / (5.0 * 4095 - PluginTemp4_Vol)) * 1000.0);
  250. ebcd_T_plugin[0] = (uint8)Look1_u32u8(PluginTemp1_R, R_table, T_table, 240);
  251. ebcd_T_plugin[1] = (uint8)Look1_u32u8(PluginTemp2_R, R_table, T_table, 240);
  252. ebcd_T_plugin[2] = (uint8)Look1_u32u8(PluginTemp3_R, R_table, T_table, 240);
  253. ebcd_T_plugin[3] = (uint8)Look1_u32u8(PluginTemp4_R, R_table, T_table, 240);
  254. }
  255. /**
  256. * @brief : lookUp Table Fun
  257. * @param {uint32} u0 x
  258. * @param {uint32} bp0 x_table
  259. * @param {uint16} table y_table
  260. * @param {uint16} maxIndex
  261. * @return {*}
  262. */
  263. uint16 Look1_u32u8(uint32 u0, uint32 *bp0, uint8 *table, uint16 MaxLen)
  264. {
  265. uint32 bpIdx = 0;
  266. uint32 iLeft = 0;
  267. uint32 iRght = 0;
  268. uint16 y = 0;
  269. uint32 yL_0d0 = 0;
  270. uint32 yR_0d0 = 0;
  271. uint32 maxIndex = MaxLen - 1;
  272. if (u0 <= bp0[0U])
  273. {
  274. iLeft = 0U;
  275. iRght = 0U;
  276. }
  277. else if (u0 < bp0[maxIndex])
  278. {
  279. //对折法寻找u0的位置
  280. bpIdx = maxIndex >> 1U;
  281. iLeft = 0U;
  282. iRght = maxIndex;
  283. while ((iRght - iLeft) > 1)
  284. {
  285. if (u0 < bp0[bpIdx])
  286. {
  287. iRght = bpIdx;
  288. }
  289. else
  290. {
  291. iLeft = bpIdx;
  292. }
  293. bpIdx = (iRght + iLeft) >> 1U;
  294. }
  295. }
  296. else
  297. {
  298. iLeft = maxIndex;
  299. iRght = maxIndex;
  300. }
  301. //找到位置以后计算插值
  302. if (iLeft != iRght)
  303. {
  304. //线性插值
  305. yR_0d0 = table[iLeft + 1U];
  306. yL_0d0 = table[iLeft];
  307. if (yR_0d0 >= yL_0d0)
  308. {
  309. y = (uint16)(((uint32)(u0 - bp0[iLeft]) * (yR_0d0 - yL_0d0)) / (bp0[iLeft + 1] - bp0[iLeft]) + yL_0d0);
  310. }
  311. else
  312. {
  313. y = (uint16)(yL_0d0 - ((uint32)(u0 - bp0[iLeft]) * (yL_0d0 - yR_0d0)) / (bp0[iLeft + 1] - bp0[iLeft]));
  314. }
  315. }
  316. else
  317. {
  318. y = (uint16)table[iLeft];
  319. }
  320. return y;
  321. }
  322. /**
  323. * @brief : 故障诊断函数,运行时间100ms
  324. * @param {*}
  325. * @return {*}
  326. */
  327. void FaultDiagnosisFunc(void)
  328. {
  329. UINT8 ErrorNumTemp = 0, ErrRank = 0;
  330. static BOOL FuncFirstRun = TRUE;
  331. static BOOL sfmd_flg_Temp1Over2;
  332. static BOOL sfmd_flg_Temp2Over2;
  333. static BOOL sfmd_flg_Temp3Over2;
  334. static BOOL sfmd_flg_Temp4Over2;
  335. static BOOL sfmd_flg_Temp1Over3;
  336. static BOOL sfmd_flg_Temp2Over3;
  337. static BOOL sfmd_flg_Temp3Over3;
  338. static BOOL sfmd_flg_Temp4Over3;
  339. BOOL sfmd_flg_Temp1Openflt = FALSE;
  340. BOOL sfmd_flg_Temp2Openflt = FALSE;
  341. BOOL sfmd_flg_Temp3Openflt = FALSE;
  342. BOOL sfmd_flg_Temp4Openflt = FALSE;
  343. if (FuncFirstRun)
  344. {
  345. FuncFirstRun = FALSE;
  346. sfmd_flg_Temp1Over2 = FALSE;
  347. sfmd_flg_Temp2Over2 = FALSE;
  348. sfmd_flg_Temp3Over2 = FALSE;
  349. sfmd_flg_Temp4Over2 = FALSE;
  350. sfmd_flg_Temp1Over3 = getbit(sfmv_Num_FltEEsave,0);
  351. sfmd_flg_Temp2Over3 = getbit(sfmv_Num_FltEEsave,1);
  352. sfmd_flg_Temp3Over3 = getbit(sfmv_Num_FltEEsave,2);
  353. sfmd_flg_Temp4Over3 = getbit(sfmv_Num_FltEEsave,3);
  354. }
  355. /*锁紧与解锁诊断*/
  356. if (ebcd_st_SwitchCtrlFlg == Unlock) //解锁诊断
  357. {
  358. if (ebcd_st_unlockSensor == 0x0F)
  359. {
  360. ebcd_st_unlockSucJug = 1;
  361. }
  362. else if (ebcd_st_unlockSensor == 0x00)
  363. {
  364. ebcd_st_unlockSucJug = 0;
  365. }
  366. else
  367. {
  368. ebcd_st_unlockSucJug = 2;
  369. }
  370. }
  371. else //锁紧诊断
  372. {
  373. if (ebcd_st_lockSensor == 0x0F)
  374. {
  375. ebcd_st_lockSucJug = 1;
  376. }
  377. else if (ebcd_st_lockSensor == 0x00)
  378. {
  379. ebcd_st_lockSucJug = 0;
  380. }
  381. else
  382. {
  383. ebcd_st_lockSucJug = 2;
  384. }
  385. }
  386. /*底座到位判断*/
  387. if (ebcd_st_pedstSucJug == 0x03)
  388. {
  389. ebcd_st_pedstSucJug = 1;
  390. }
  391. else if (ebcd_st_pedstSucJug == 0x00)
  392. {
  393. ebcd_st_pedstSucJug = 0;
  394. }
  395. else
  396. {
  397. ebcd_st_pedstSucJug = 2;
  398. }
  399. /*温度传感器开路诊断*/
  400. sfmd_flg_Temp1Openflt = JudgeTimeSystem(1U, (ebcd_T_plugin[0] == 0), DiagErrFaulNum.DiagErrFaulN25, 5U);
  401. sfmd_flg_Temp2Openflt = JudgeTimeSystem(1U, (ebcd_T_plugin[1] == 0), DiagErrFaulNum.DiagErrFaulN26, 5U);
  402. sfmd_flg_Temp3Openflt = JudgeTimeSystem(1U, (ebcd_T_plugin[2] == 0), DiagErrFaulNum.DiagErrFaulN27, 5U);
  403. sfmd_flg_Temp4Openflt = JudgeTimeSystem(1U, (ebcd_T_plugin[3] == 0), DiagErrFaulNum.DiagErrFaulN28, 5U);
  404. /*温度传感器三级过温诊断*/
  405. sfmd_flg_Temp1Over3 = DiagThrSystem1(1, !sfmd_flg_Temp1Openflt, ebcd_T_plugin[0], sfmd_Th_Temp1Over3Faul, sfmd_Th_Temp1Over3Reco, 30, 30, DiagErrFaulNum.DiagErrFaulN17, DiagErrRecoNum.DiagErrRecoN17, sfmd_flg_Temp1Over3);
  406. sfmd_flg_Temp2Over3 = DiagThrSystem1(1, !sfmd_flg_Temp2Openflt, ebcd_T_plugin[1], sfmd_Th_Temp2Over3Faul, sfmd_Th_Temp2Over3Reco, 30, 30, DiagErrFaulNum.DiagErrFaulN18, DiagErrRecoNum.DiagErrRecoN18, sfmd_flg_Temp2Over3);
  407. sfmd_flg_Temp3Over3 = DiagThrSystem1(1, !sfmd_flg_Temp3Openflt, ebcd_T_plugin[2], sfmd_Th_Temp3Over3Faul, sfmd_Th_Temp3Over3Reco, 30, 30, DiagErrFaulNum.DiagErrFaulN19, DiagErrRecoNum.DiagErrRecoN19, sfmd_flg_Temp3Over3);
  408. sfmd_flg_Temp4Over3 = DiagThrSystem1(1, !sfmd_flg_Temp4Openflt, ebcd_T_plugin[3], sfmd_Th_Temp4Over3Faul, sfmd_Th_Temp4Over3Reco, 30, 30, DiagErrFaulNum.DiagErrFaulN20, DiagErrRecoNum.DiagErrRecoN20, sfmd_flg_Temp4Over3);
  409. /*温度传感器二级过温诊断*/
  410. sfmd_flg_Temp1Over2 = DiagThrSystem1(1, !sfmd_flg_Temp1Over3 && !sfmd_flg_Temp1Openflt, ebcd_T_plugin[0], sfmd_Th_Temp1Over2Faul, sfmd_Th_Temp1Over2Reco, 30, 30, DiagErrFaulNum.DiagErrFaulN9, DiagErrRecoNum.DiagErrRecoN9, sfmd_flg_Temp1Over2);
  411. sfmd_flg_Temp2Over2 = DiagThrSystem1(1, !sfmd_flg_Temp2Over3 && !sfmd_flg_Temp2Openflt, ebcd_T_plugin[1], sfmd_Th_Temp2Over2Faul, sfmd_Th_Temp2Over2Reco, 30, 30, DiagErrFaulNum.DiagErrFaulN10, DiagErrRecoNum.DiagErrRecoN10, sfmd_flg_Temp2Over2);
  412. sfmd_flg_Temp3Over2 = DiagThrSystem1(1, !sfmd_flg_Temp3Over3 && !sfmd_flg_Temp3Openflt, ebcd_T_plugin[2], sfmd_Th_Temp3Over2Faul, sfmd_Th_Temp3Over2Reco, 30, 30, DiagErrFaulNum.DiagErrFaulN11, DiagErrRecoNum.DiagErrRecoN11, sfmd_flg_Temp3Over2);
  413. sfmd_flg_Temp4Over2 = DiagThrSystem1(1, !sfmd_flg_Temp4Over3 && !sfmd_flg_Temp4Openflt, ebcd_T_plugin[3], sfmd_Th_Temp4Over2Faul, sfmd_Th_Temp4Over2Reco, 30, 30, DiagErrFaulNum.DiagErrFaulN12, DiagErrRecoNum.DiagErrRecoN12, sfmd_flg_Temp4Over2);
  414. sfmv_Num_FltEEsave = ((sfmd_flg_Temp4Over3&0x01)<<3)|((sfmd_flg_Temp3Over3&0x01)<<2)|((sfmd_flg_Temp2Over3&0x01)<<1)|(sfmd_flg_Temp1Over3);
  415. /*故障代码写入*/
  416. if (sfmd_flg_Temp1Openflt)
  417. {
  418. ErrorNumTemp = 25;
  419. ErrRank = 2;
  420. PutErrorNum(ErrArray, sizeof(ErrArray) / 2, ErrorNumTemp + ErrRank * 1000);
  421. }
  422. if (sfmd_flg_Temp2Openflt)
  423. {
  424. ErrorNumTemp = 26;
  425. ErrRank = 2;
  426. PutErrorNum(ErrArray, sizeof(ErrArray) / 2, ErrorNumTemp + ErrRank * 1000);
  427. }
  428. if (sfmd_flg_Temp3Openflt)
  429. {
  430. ErrorNumTemp = 27;
  431. ErrRank = 2;
  432. PutErrorNum(ErrArray, sizeof(ErrArray) / 2, ErrorNumTemp + ErrRank * 1000);
  433. }
  434. if (sfmd_flg_Temp4Openflt)
  435. {
  436. ErrorNumTemp = 28;
  437. ErrRank = 2;
  438. PutErrorNum(ErrArray, sizeof(ErrArray) / 2, ErrorNumTemp + ErrRank * 1000);
  439. }
  440. if (sfmd_flg_Temp1Over3)
  441. {
  442. ErrorNumTemp = 17;
  443. ErrRank = 3;
  444. PutErrorNum(ErrArray, sizeof(ErrArray) / 2, ErrorNumTemp + ErrRank * 1000);
  445. }
  446. if (sfmd_flg_Temp2Over3)
  447. {
  448. ErrorNumTemp = 18;
  449. ErrRank = 3;
  450. PutErrorNum(ErrArray, sizeof(ErrArray) / 2, ErrorNumTemp + ErrRank * 1000);
  451. }
  452. if (sfmd_flg_Temp3Over3)
  453. {
  454. ErrorNumTemp = 19;
  455. ErrRank = 3;
  456. PutErrorNum(ErrArray, sizeof(ErrArray) / 2, ErrorNumTemp + ErrRank * 1000);
  457. }
  458. if (sfmd_flg_Temp4Over3)
  459. {
  460. ErrorNumTemp = 20;
  461. ErrRank = 3;
  462. PutErrorNum(ErrArray, sizeof(ErrArray) / 2, ErrorNumTemp + ErrRank * 1000);
  463. }
  464. if (sfmd_flg_Temp1Over2)
  465. {
  466. ErrorNumTemp = 9;
  467. ErrRank = 2;
  468. PutErrorNum(ErrArray, sizeof(ErrArray) / 2, ErrorNumTemp + ErrRank * 1000);
  469. }
  470. if (sfmd_flg_Temp2Over2)
  471. {
  472. ErrorNumTemp = 10;
  473. ErrRank = 2;
  474. PutErrorNum(ErrArray, sizeof(ErrArray) / 2, ErrorNumTemp + ErrRank * 1000);
  475. }
  476. if (sfmd_flg_Temp3Over2)
  477. {
  478. ErrorNumTemp = 11;
  479. ErrRank = 2;
  480. PutErrorNum(ErrArray, sizeof(ErrArray) / 2, ErrorNumTemp + ErrRank * 1000);
  481. }
  482. if (sfmd_flg_Temp4Over2)
  483. {
  484. ErrorNumTemp = 12;
  485. ErrRank = 2;
  486. PutErrorNum(ErrArray, sizeof(ErrArray) / 2, ErrorNumTemp + ErrRank * 1000);
  487. }
  488. }
  489. /**
  490. * @brief : 故障判断函数
  491. * @param {BOOL} Enable 使能状态
  492. * @param {BOOL} Input 判断输入
  493. * @param {UINT16} *N 判断次数累计
  494. * @param {UINT16} Thr 判断次数阈值
  495. * @return {*}
  496. */
  497. BOOL JudgeTimeSystem(BOOL Enable, BOOL Input, UINT8 *N, UINT8 Thr)
  498. {
  499. BOOL Flg = FALSE;
  500. if (Input && Enable)
  501. {
  502. *N = (*N + 1) > 2008 ? 2008 : (*N + 1);
  503. }
  504. else
  505. {
  506. *N = 0;
  507. }
  508. if (*N > Thr && Enable)
  509. {
  510. Flg = TRUE;
  511. }
  512. else
  513. {
  514. Flg = FALSE;
  515. }
  516. return Flg;
  517. }
  518. BOOL DiagThrSystem1(BOOL Enable, BOOL precondition, UINT16 Input, UINT16 fltThr, UINT16 recThr, UINT16 fltNumThr, UINT16 recNumThr, UINT16 *fltNum, UINT16 *recNum, UINT8 *fitFlg)
  519. {
  520. if (Enable && precondition && Input > fltThr)
  521. {
  522. *fltNum = (*fltNum + 1) > 20000 ? 20000 : (*fltNum + 1);
  523. }
  524. else
  525. {
  526. *fltNum = 0;
  527. }
  528. if (Enable && precondition && Input < recThr)
  529. {
  530. *recNum = (*recNum + 1) > 20000 ? 20000 : (*recNum + 1);
  531. }
  532. else
  533. {
  534. *recNum = 0;
  535. }
  536. if ((*fltNum > fltNumThr || (*fitFlg && *recNum < recNumThr)) && precondition)
  537. {
  538. *fitFlg = TRUE;
  539. }
  540. else
  541. {
  542. *fitFlg = FALSE;
  543. }
  544. return *fitFlg;
  545. }
  546. /**
  547. * @brief : 获取故障码函数,从故障数组中获取故障码,并将之前的故障码向前移动
  548. * @param {UINT16} *ErrorArray
  549. * @param {UINT8} Errorlen
  550. * @return {*}
  551. */
  552. UINT16 GetErrorNum(UINT16 *ErrorArray, UINT8 Errorlen)
  553. {
  554. UINT16 OutNum;
  555. OutNum = *(ErrorArray);
  556. for (UINT8 i = 0; i < Errorlen - 1; i++)
  557. {
  558. *(ErrorArray + i) = *(ErrorArray + i + 1);
  559. if (*(ErrorArray + i + 1) == 0)
  560. break;
  561. }
  562. return OutNum;
  563. }
  564. /**
  565. * @brief : 故障码注入函数,将故障码写入到故障数组中,如果存在则不写入,如果存在则不写入
  566. * @param {UINT16} *ErrorArray
  567. * @param {UINT8} Errorlen
  568. * @param {UINT16} ErrorNum
  569. * @return {*}
  570. */
  571. UINT8 PutErrorNum(UINT16 *ErrorArray, UINT8 Errorlen, UINT16 ErrorNum)
  572. {
  573. for (UINT8 i = 0; i < Errorlen; i++)
  574. {
  575. if (*(ErrorArray + i) == 0)
  576. {
  577. *(ErrorArray + i) = ErrorNum;
  578. return 0;
  579. }
  580. else
  581. {
  582. if (*(ErrorArray + i) == ErrorNum)
  583. {
  584. return 1;
  585. }
  586. else
  587. {
  588. continue;
  589. }
  590. }
  591. }
  592. return 2;
  593. }