Browse Source

Merge branch 'V3-V31XX-7250' of http://git.fast-fun.cn:92/RuiLiWuLian/NB_APP_Code into V3-7250-QTF

# Conflicts:
#	src/EmbeddedCoder_src/BCU.c
LAPTOP-EG88H5BE\86151 2 years ago
parent
commit
d188541df1
8 changed files with 210 additions and 194 deletions
  1. 11 9
      inc/AppConfig.h
  2. 11 1
      inc/AppSignal.h
  3. 2 1
      src/AppSignal.c
  4. 6 3
      src/AppTaskMain.c
  5. 22 16
      src/AppTaskTcp.c
  6. 18 14
      src/EmbeddedCoder_src/BCU.c
  7. 25 26
      src/EmbeddedCoder_src/SFM.c
  8. 115 124
      src/EmbeddedCoder_src/SOH.c

+ 11 - 9
inc/AppConfig.h

@@ -2,7 +2,7 @@
  * @Author       : ChenJie
  * @Date         : 2021-10-14 09:27:15
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-12-24 09:58:01
+ * @LastEditTime : 2021-12-29 17:51:58
  * @Description  : App Config H file 配置文件,可以针对不同参数进行更改
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\inc\AppConfig.h
  */
@@ -14,15 +14,17 @@
 #define DATA_MODULE_TYPE (1)           // 1表示NB模块,2表示4G cat1
 #define EOLSTATE (0)                   // 1表示下线检测跳过,使用默认值,0表示使用下线检测
 #define DEFAULT_SN "RLTEST00000000001" //默认上传的SN编码
-#define APPSWVERSION 0x0301FA41        //数据模块软件版本号
-#define RELAYCONFIG 1                  //继电器配置
-#define TCP_ADD "iotp.fast-fun.cn"     //数据上传的地址
-#define TCP_PORT 8712                  //数据上传的端口
 
-#define NB_OTHER_TEMP_NUM (4)   // NB采集的温度个数
-#define HWVERSION 0x0102        //硬件主版本,现为V1.2板
-#define BLSWVERSION 0x01020000  // BootLoader版本号V1.2.0.0
-#define DRVSWVERSION 0x01050000 //驱动层版本号V1.4.0.0  驱动层1.5.0.0,增加了三轴
+#define APPSWRELEASE 0          //软件测试版本标志位,0-测试,1-发布
+#define APPSWVERSION 0x0301F641 //数据模块软件版本号
+
+#define RELAYCONFIG 1              //继电器配置
+#define TCP_ADD "iotp.fast-fun.cn" //数据上传的地址
+#define TCP_PORT 8712              //数据上传的端口
+#define NB_OTHER_TEMP_NUM (4)      // NB采集的温度个数
+#define HWVERSION 0x0102           //硬件主版本,现为V1.2板
+#define BLSWVERSION 0x01020000     // BootLoader版本号V1.2.0.0
+#define DRVSWVERSION 0x01050000    //驱动层版本号V1.4.0.0  驱动层1.5.0.0,增加了三轴
 
 #define APP_CONFIG_FILE_NAME "qxappconfig.nvm"
 #define APP_DATAINFO_FILE_NAME "qxappDataInfo3.nvm"

+ 11 - 1
inc/AppSignal.h

@@ -1,8 +1,17 @@
+/*
+ * @Author       : ChenJie
+ * @Date         : 2021-12-28 19:25:29
+ * @Version      : V3.0
+ * @LastEditors  : ChenJie
+ * @LastEditTime : 2021-12-29 16:52:03
+ * @Description  : file content
+ * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\inc\AppSignal.h
+ */
 /*
  * @Author       : ChenJie
  * @Date         : 2021-10-14 09:27:15
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-12-16 11:06:14
+ * @LastEditTime : 2021-12-29 10:36:02
  * @Description  : Global variable definition H file
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\inc\AppSignal.h
  */
@@ -88,6 +97,7 @@ extern UINT16 ErrorNum[ErrorNumLength];
 extern UINT16 updateDifferDataPackageCounter;
 extern INT16 xyzData[3];
 extern UINT8 otherTempAvg;
+extern UINT8 UnSleepFlag;
 // declear the UINT32 vars
 extern UINT32 battBalanceoInfo;
 extern UINT32 battProtectState;

+ 2 - 1
src/AppSignal.c

@@ -3,7 +3,7 @@
  * @Date         : 2021-10-14 09:27:15
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-12-16 11:06:25
+ * @LastEditTime : 2021-12-29 10:35:24
  * @Description  : Global variable definition c file,此文件存放App使用到的全局变量
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AppSignal.c
  */
@@ -72,6 +72,7 @@ UINT8 UDSSwitch = 0;                    //下线检测标志位
 UINT8 UartInterruptcount = 0;           //串口中断累加值
 UINT8 UDSDialogMode = 01;               // UDS诊断模式
 UINT8 SysResetFlag = 0;
+UINT8 UnSleepFlag = 0; //不休眠标志位查看
 /**declear the uint16 vars**/
 UINT16 avrgCellVol = 0;                    //平均单体电压
 UINT16 battCellU[28] = {0};                //电池包单体电压

+ 6 - 3
src/AppTaskMain.c

@@ -3,7 +3,7 @@
  * @Date         : 2021-10-14 09:27:15
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-12-14 11:33:29
+ * @LastEditTime : 2021-12-29 10:55:45
  * @Description  : 主要负责:1.工作模式转换2.定时器定时3.定时保存运行数据4.异常状态重启
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AppTaskMain.c
  */
@@ -55,7 +55,7 @@ static void MainTask(void *arg)
     LastResetReasonNum = appGetLastResetReason();
     SysResetFlag = 1;
 #ifdef DEBUGLOG
-    Debug_printf("[%d,%d,%d]\n", Wakeup_source, AppDataInfo.SysReStartCount, LastResetReasonNum);
+    Debug_printf("[SysRoot,%d,%d]\n", AppDataInfo.SysReStartCount, LastResetReasonNum);
 #endif
     //配置文件及运行数据加载
     if (Error_Mutex == NULL)
@@ -113,6 +113,7 @@ static void MainTask(void *arg)
             }
             if ((BMS_Fota_update_flag != FALSE) || (TCPWorkState != 0x00) || (BattWorkStateDelay != BATT_IDLE_SYM) || (battWorkState != BATT_IDLE_SYM) || (PadInterrupt != 0x00) || (AvgBattTemp >= (45 + 40)))
             {
+                UnSleepFlag = ((BMS_Fota_update_flag != FALSE) << 5) | ((TCPWorkState != 0x00) << 4) | ((BattWorkStateDelay != BATT_IDLE_SYM) << 3) | ((battWorkState != BATT_IDLE_SYM) << 2) | ((PadInterrupt != 0x00) << 1) | (AvgBattTemp >= (45 + 40));
                 xTimerReset(work_timer, 0);
             }
             if ((TcpErrorcount >= 100 && getbit(PadInterrupt, 0) == 0x00 && battWorkState != BATT_CHARGE_SYM) || (NB_Fota_update_flag == TRUE))
@@ -185,7 +186,9 @@ static void MainTask(void *arg)
                 printf("WORK:%d,%d,%d\n", PadInterrupt_clrCounter, PadInterrupt, UartInterruptcount);
 #endif
 #ifdef DEBUGLOG
-                Debug_printf("WORK:%d,%d,%d\n", PadInterrupt_clrCounter, PadInterrupt, UartInterruptcount);
+                UINT8 WakeUpFlg = 0;
+                WakeUpFlg = ((SleepTimerEnd) << 3) | ((TCPWorkState == 1) << 2) | ((PadInterrupt_clrCounter >= 1) << 1) | (otherTempAvg > (50 + 40));
+                Debug_printf("WORK:%d,%d,%d,%d\n", PadInterrupt_clrCounter, PadInterrupt, UartInterruptcount, WakeUpFlg);
 #endif
                 PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
                 xTimerStop(sleep_timer, 0);

+ 22 - 16
src/AppTaskTcp.c

@@ -258,7 +258,12 @@ static void TcpDataInfoAssembleSend()
     {
         BattSendFreq = AppDataInfo.BattInfoSendFreqNomal;
         GpsSendFreq = AppDataInfo.PosInfoSendFreqHigh;
+#if APPSWRELEASE == 1
+        DebugFeq = BattSendFreq;
+#else
         DebugFeq = 1;
+#endif
+
         break;
     }
     default:
@@ -321,7 +326,11 @@ static void TcpDataInfoAssembleSend()
         *(SendBuffer + 35) = UTC8TimeTcp.minute & 0xFF;                      // mins-36
         *(SendBuffer + 36) = UTC8TimeTcp.second & 0xFF;                      // sec-37
         *(SendBuffer + 37) = csq;                                            //信号强度-38
-        *(SendBuffer + 38) = sfmd_st_fltLevel;                               //故障等级-39
+#if APPSWRELEASE == 1
+        *(SendBuffer + 38) = sfmd_st_fltLevel; //故障等级-39
+#else
+        *(SendBuffer + 38) = 0; //故障等级-39
+#endif
         if (osOK == osMutexAcquire(Error_Mutex, 100))
         {
             ErrorTemp = GetErrorNum((UINT16 *)ErrorNum, ErrorNumLength);
@@ -569,24 +578,21 @@ static void TcpDataInfoAssembleSend()
         UINT16 BufferLen = 0;
         UINT8 rbuf[1000];
         static UINT8 Debugcounter = 0;
-        if (Debugcounter % 5 == 0)
-        {
-            sprintf((char *)rbuf, "A-%x,%d,%d,%x,%x,,%d,%d,,%d",
-                    battProtectState, AppDataInfo.RelayControl, chargerConnectState, BMSupdatestatus, PadInterrupt,
-                    AppDataInfo.ExpiryTimeArray[1], AppDataInfo.ExpiryTimeArray[2], SysResetFlag);
-        }
-        else
-        {
-            sprintf((char *)rbuf, "B-%d,%d,%d,%d,,\
+        sprintf((char *)rbuf, "B-%d,%d,%d,%d,,\
                                 %d,%d,%d,%d,%d,%d,,\
                                 %d,%d,%d,%d,,\
-                                %d,%d,%d,%d,%d,,\
+                                %d,%d,%d,%d,,\
                                 %d,%d,%d,%d,%d,%d",
-                    socd_pct_ahSoc, socd_pct_ekfSoc, socd_pct_battSoc, socd_pct_vcuSoc,
-                    sfmd_I_curr, maxCellVol, minCellVol, sfmv_V_cellU[0], sfmv_V_cellU[1], sfmv_V_cellU[2],
-                    cand_idx_cellNr, cand_Q_cellCap, ihd_tm_parkTime, sohd_Q_chrgEo,
-                    pimd_V_ocv, pimd_R_ohm, pimd_R_polar, pimd_F_polar,
-                    pimv_V_cellOcv[0],pimv_V_cellOcv[1],pimv_V_cellOcv[2],pimv_R_cellOhm[0],pimv_R_cellOhm[1],pimv_R_cellOhm[2]);
+                socd_pct_ahSoc, socd_pct_ekfSoc, socd_pct_battSoc, socd_pct_vcuSoc,
+                sfmd_I_curr, maxCellVol, minCellVol, sfmv_V_cellU[0], sfmv_V_cellU[1], sfmv_V_cellU[2],
+                cand_idx_cellNr, cand_Q_cellCap, ihd_tm_parkTime, sohd_Q_chrgEo,
+                pimd_V_ocv, pimd_R_ohm, pimd_R_polar, pimd_F_polar,
+                pimv_V_cellOcv[0], pimv_V_cellOcv[1], pimv_V_cellOcv[2], pimv_R_cellOhm[0], pimv_R_cellOhm[1], pimv_R_cellOhm[2]);
+        if (Debugcounter % 5 == 0)
+        {
+            sprintf((char *)rbuf + strlen(rbuf), ",A-%x,%d,%d,%x,%x,,%d,%d,,%x,%d",
+                    battProtectState, AppDataInfo.RelayControl, chargerConnectState, BMSupdatestatus, PadInterrupt,
+                    AppDataInfo.ExpiryTimeArray[1], AppDataInfo.ExpiryTimeArray[2], UnSleepFlag, sfmd_flg_heatCirOpenFltEo);
         }
         Debugcounter++;
         if (Debugcounter > 100)

+ 18 - 14
src/EmbeddedCoder_src/BCU.c

@@ -1,6 +1,5 @@
 
 #include "BCU.h"
-
 static StaticTask_t gProcess_Bcu_Task_t;
 static UINT8 gProcess_Bcu_TaskStack[PROC_BCU_TASK_STACK_SIZE];
 static osThreadId_t BcuTaskId = NULL;
@@ -92,7 +91,7 @@ void BCU(void)
                     }
                     // printf("time:%d\n",ihd_tm_parkTime);
                     //
-		
+
                     //数据获取
                     ihd_st_reSet = SysResetFlag;
                     ihd_I_curr = (int16_T)(-(battI - 10000));
@@ -113,26 +112,31 @@ void BCU(void)
                     ihd_flg_urtRecFlt = UartErrorFlag;
                     ihd_flg_urtRecFlg = UartRecvFlag;
                     ihd_st_chrgConnect = chargerConnectState;
-                    ihd_flg_cellULowFlt = ((battWarningState)&0x01) == 1;
-                    ihd_flg_battULowFlt = ((battWarningState >> 1) & 0x01) == 1;
-                    ihd_flg_cellUOverFlt = ((battWarningState >> 2) & 0x01) == 1;
-                    ihd_flg_battUOverFlt = ((battWarningState >> 3) & 0x01) == 1;
-                    ihd_flg_disChrgCurrOverFlt = ((battWarningState >> 4) & 0x01) == 1;
-                    ihd_flg_chrgCurrOverFlt = ((battWarningState >> 5) & 0x01) == 1;
-                    ihd_flg_disChrgModTOverFlt = ((battWarningState >> 6) & 0x01) == 1;
-                    ihd_flg_chrgModTOverFlt = ((battWarningState >> 7) & 0x01) == 1;
-                    ihd_flg_chrgMosTOverFlt = ((battWarningState >> 11) & 0x01) == 1;
+                    ihd_flg_cellULowFlt = (getbit(battProtectState, 8)) == 1;
+                    ihd_flg_battULowFlt = (getbit(battProtectState, 9)) == 1;
+                    ihd_flg_cellUOverFlt = (getbit(battProtectState, 24)) == 1;
+                    ihd_flg_battUOverFlt = (getbit(battProtectState, 25)) == 1;
+                    ihd_flg_disChrgCurrOverFlt = (getbit(battProtectState, 1)) == 1;
+                    ihd_flg_chrgCurrOverFlt = (getbit(battProtectState, 2)) == 1;
+                    ihd_flg_disChrgModTOverFlt = (getbit(battProtectState, 20)) == 1;
+                    ihd_flg_chrgModTOverFlt = (getbit(battProtectState, 16)) == 1;
+                    ihd_flg_chrgMosTOverFlt = (getbit(battProtectState, 18)) == 1;
                     ihd_flg_disChrgMosClosFlt = ((battWarningState >> 18) & 0x01) == 1;
                     ihd_flg_chrgMosClosFlt = ((battWarningState >> 19) & 0x01) == 1;
-                    ihd_flg_disChrgModTLowFlt = ((battWarningState >> 22) & 0x01) == 1;
-                    ihd_flg_chrgModTLowFlt = ((battWarningState >> 23) & 0x01) == 1;
+                    ihd_flg_disChrgModTLowFlt = (getbit(battProtectState, 21)) == 1;
+                    ihd_flg_chrgModTLowFlt = (getbit(battProtectState, 17)) == 1;
                     ihd_flg_currOpenFlt = 0;
                     ihd_st_heatForceControl = HeatForceControl;
                     ihd_st_chrgMosControl = ChargeForbiddenControl == 0;
                     ihd_st_disChrgMosControl = DisChargeForbiddenControl == 0;
                     ihd_st_relayControl = RelayForbiddenControl == 0;
+<<<<<<< HEAD
 					ihd_st_heatStat = battHeatEnableState;
                     // ihd_flg_DTCClear = 1;   //////clear
+=======
+                    ihd_st_heatStat = battHeatEnableState;
+                    // ihd_flg_DTCClear = 1; //////clear
+>>>>>>> ef04e418bc1d22392de11207d9dec0014c0c572e
                     //调用算法
                     SFM();
                     TMS();
@@ -174,7 +178,7 @@ void BCU(void)
                 if (TimeCounter % 10 == 0)
                 {
                     ihd_tm_parkTime++;
-                    //printf("time:%d\n",ihd_tm_parkTime);
+                    // printf("time:%d\n",ihd_tm_parkTime);
                 }
                 if (TimeCounter % 1000 == 0)
                 {

+ 25 - 26
src/EmbeddedCoder_src/SFM.c

@@ -12,8 +12,8 @@ void SFM_Init(void)
 
 void SFM(void)
 {
-	static uint8_T	 sfmn_num_Cnt;
-	boolean_T sfmn_flg_interComFlt;
+    static uint8_T sfmn_num_Cnt;
+    boolean_T sfmn_flg_interComFlt;
     boolean_T sfmn_flg_authFlt;
     boolean_T sfmn_flg_HVILFlt;
     boolean_T sfmn_flg_chrgMosClosFlt;
@@ -29,14 +29,13 @@ void SFM(void)
     static uint16_T heatT2Arr[10];
     static uint16_T SumT2;
 
-    
-    static uint16_T  CellUArry[4][cmnc_num_cellUNumMax];
-    static uint8_T   ErrNr[cmnc_num_cellUNumMax];
-    static uint8_T   RecNr[cmnc_num_cellUNumMax];
+    static uint16_T CellUArry[4][cmnc_num_cellUNumMax];
+    static uint8_T ErrNr[cmnc_num_cellUNumMax];
+    static uint8_T RecNr[cmnc_num_cellUNumMax];
     static boolean_T sfmv_flg_cellUOpenFlt[cmnc_num_cellUNumMax];
     static boolean_T ErrUFlg[cmnc_num_cellUNumMax];
-    uint32_T  SumU;
-    uint16_T  UNum;
+    uint32_T SumU;
+    uint16_T UNum;
     boolean_T sfmd_flg_volFlt;
     boolean_T Enable1;
     boolean_T Enable2;
@@ -53,8 +52,8 @@ void SFM(void)
     static uint16_T modTArr[cmnc_num_modTNumMax];
     uint16_T Tnum;
     uint32_T SumT;
-	
-	static uint8_T modTRatNr[cmnc_num_modTNumMax];
+
+    static uint8_T modTRatNr[cmnc_num_modTNumMax];
     boolean_T sfmd_flg_modTRatFlt;
     boolean_T sfmv_flg_modTRatFlt[cmnc_num_modTNumMax];
     boolean_T sfmd_flg_chrgMosTRatFlt;
@@ -77,7 +76,7 @@ void SFM(void)
     boolean_T sfmd_flg_modTAllFlt;
     boolean_T sfmd_flg_heatPanTAllFlt;
     boolean_T sfmd_flg_currOpenFlt;
-    uint16_T  sfmn_I_currAbs;
+    uint16_T sfmn_I_currAbs;
     static boolean_T sfmd_flg_cellUOverFlt2;
     static boolean_T sfmd_flg_cellUOverFlt1;
     static boolean_T sfmd_flg_cellULowFlt2;
@@ -88,7 +87,7 @@ void SFM(void)
     static boolean_T sfmd_flg_battUOverFlt1;
     static boolean_T sfmd_flg_battULowFlt2;
     static boolean_T sfmd_flg_battULowFlt1;
-	
+
     boolean_T chrgFlg;
     boolean_T disChrgFlg;
     static boolean_T sfmd_flg_chrgModTOverFlt2;
@@ -117,7 +116,7 @@ void SFM(void)
     boolean_T sfmd_flg_heatPanTOverFlt1;
     static boolean_T sfmd_flg_chrgCurrOverFlt;
     static boolean_T sfmd_flg_disChrgCurrOverFlt;
-	
+
     boolean_T sfmd_flg_chrgCurrOverMisFlt;
     boolean_T sfmd_flg_disChrgCurrOverMisFlt;
     boolean_T sfmd_flg_battULowMisFlt;
@@ -152,13 +151,13 @@ void SFM(void)
     int32_T SumRR;
     boolean_T sfmd_flg_deltRFlt;
     static uint8_T deltRFltNr[cmnc_num_cellUNumMax];
-	
+
     boolean_T FltFlg[FltArrLen];
-    uint16_T  FltLevel[FltArrLen];
-    uint8_T   FltAct[FltArrLen];
-    uint16_T  FltCodeArr[FltDispArrLen];
-    uint16_T  FltLevelArr[FltDispArrLen];
-    uint8_T   FltActArr[FltDispArrLen];
+    uint16_T FltLevel[FltArrLen];
+    uint8_T FltAct[FltArrLen];
+    uint16_T FltCodeArr[FltDispArrLen];
+    uint16_T FltLevelArr[FltDispArrLen];
+    uint8_T FltActArr[FltDispArrLen];
     uint16_T i;
     uint16_T j;
     uint16_T k;
@@ -705,7 +704,7 @@ void SFM(void)
     // 163 soc不匹配
     sfmd_flg_socMisFlt = 0 && !sfmd_flg_firstRun && (!sfmn_flg_interComFlt) && ((int16_T)(socd_pct_vcuSoc - ihd_pct_soc) > 100 || (int16_T)(socd_pct_vcuSoc - ihd_pct_soc) < -100);
     // 164 SOH 不匹配
-    sfmd_flg_sohMisFlt = !sfmd_flg_firstRun && (!sfmn_flg_interComFlt) && ((int16_T)(sohd_pct_bcuSoh - ihd_pct_soh) > 50 || (int16_T)(sohd_pct_bcuSoh - ihd_pct_soh) < -50);
+    sfmd_flg_sohMisFlt = 0 && !sfmd_flg_firstRun && (!sfmn_flg_interComFlt) && ((int16_T)(sohd_pct_bcuSoh - ihd_pct_soh) > 50 || (int16_T)(sohd_pct_bcuSoh - ihd_pct_soh) < -50);
 
     // 178
     sfmd_flg_deltRFlt = false;
@@ -715,7 +714,7 @@ void SFM(void)
         SumRR = 0;
         for (i = 0; i < cmnc_num_cellUNum; i++)
         {
-            if(!cdmv_flg_inval[i])
+            if (!cdmv_flg_inval[i])
             {
                 SumR = SumR + cdmv_R_deltOhm[i];
                 SumRR = SumRR + cdmv_R_deltOhm[i] * cdmv_R_deltOhm[i];
@@ -733,7 +732,7 @@ void SFM(void)
                 deltRFltNr[i] = 0;
             }
         }
-		
+
         for (i = 0; i < cmnc_num_cellUNum; i++)
         {
             if (deltRFltNr[i] > 60)
@@ -931,7 +930,8 @@ void SFM(void)
 
     // 33 加热回路常开故障
     Enable2 = JudgeTimeSystem(1, tmsd_st_heatAct == 1, &DiagTime.N33, 600);
-    sfmd_flg_heatCirOpenFltEo = (((int16_T)(heatT2Arr[9] - heatT2Arr[0]) < 5 && (int16_T)(heatT1Arr[9] - heatT1Arr[0]) < 5) && Enable2) || sfmd_flg_heatCirOpenFltEo || sfmd_flg_heatCirOpenFltEi;
+    Enable2 = (DiagTime.N33 == 600);
+    sfmd_flg_heatCirOpenFltEo = (((int16_T)(heatT2Arr[9] - heatT2Arr[0]) < 5 && (int16_T)(heatT1Arr[9] - heatT1Arr[0]) < 5) && (modTMaxArr[9] < modTMaxArr[0] + 4) && Enable2) || sfmd_flg_heatCirOpenFltEo || sfmd_flg_heatCirOpenFltEi;
 
     //================================================================================================================================================================
     //================================================================================================================================================================
@@ -1756,10 +1756,9 @@ void SFM(void)
     //======================================================================
 
     sfmd_flg_cellUInval = sfmn_flg_interComFlt || sfmd_flg_volFlt;
-    sfmd_flg_currInval  = sfmn_flg_interComFlt || sfmd_flg_currOpenFlt;
-    sfmd_flg_modTInval  = sfmn_flg_interComFlt || sfmd_flg_modTOpenFlt || sfmd_flg_modTRatFlt;
+    sfmd_flg_currInval = sfmn_flg_interComFlt || sfmd_flg_currOpenFlt;
+    sfmd_flg_modTInval = sfmn_flg_interComFlt || sfmd_flg_modTOpenFlt || sfmd_flg_modTRatFlt;
     sfmd_flg_firstRun = false;
 }
 
 //===============================================================================
-

+ 115 - 124
src/EmbeddedCoder_src/SOH.c

@@ -2,7 +2,7 @@
 
 void SOH_Init(void)
 {
-    sohd_flg_firstRun = true ;
+    sohd_flg_firstRun = true;
 }
 
 void SOH(void)
@@ -35,177 +35,171 @@ void SOH(void)
     static uint8_T sohn_st_workStat_Delay;
     //
     static real_T Ahincr;
-    int16_T  tmp_0; 
+    int16_T tmp_0;
     static boolean_T sfmn_flg_currFlt_keep;
     static boolean_T sohn_flg_currFlt;
     boolean_T DisEn;
 
-
-	//初值
-    if(sohd_flg_firstRun)
-    {   
+    //初值
+    if (sohd_flg_firstRun)
+    {
         sohn_flg_update = true;
         sfmn_flg_currFlt_keep = false;
         sohn_flg_currFlt = false;
         Ahincr = 0;
         sohn_st_workStat_Delay = 0;
-		if(ihd_st_reSet == 1)
-		{
-           memcpy(sohv_V_chrgStartStatEo,sohv_V_chrgStartStatEi, sizeof(sohv_V_chrgStartStatEo));
-	       sohd_Q_chrgEo = sohd_Q_chrgEi;
-	       sohd_flg_chrgEndEo = sohd_flg_chrgEndEi; 
-		}
-		else
-		{
-		   memset(sohv_V_chrgStartStatEo,0, sizeof(sohv_V_chrgStartStatEo));
-		   sohd_Q_chrgEo = 0 ;
-		   sohd_flg_chrgEndEo = 0; 
-		}	
+        if (ihd_st_reSet == 1)
+        {
+            memcpy(sohv_V_chrgStartStatEo, sohv_V_chrgStartStatEi, sizeof(sohv_V_chrgStartStatEo));
+            sohd_Q_chrgEo = sohd_Q_chrgEi;
+            sohd_flg_chrgEndEo = sohd_flg_chrgEndEi;
+        }
+        else
+        {
+            memset(sohv_V_chrgStartStatEo, 0, sizeof(sohv_V_chrgStartStatEo));
+            sohd_Q_chrgEo = 0;
+            sohd_flg_chrgEndEo = 0;
+        }
     }
-  
 
-    if(sohd_flg_firstRun)
+    if (sohd_flg_firstRun)
     {
         //=======================================================================================
         //--------------------------EE校验-------------------------------------------------------
         //=======================================================================================
-        cellCapArr_Min = ArrMin(sohv_Q_cellCapArrEi , cmnc_num_cellUNum);
-        cellCapArr_Max = ArrMax(sohv_Q_cellCapArrEi , cmnc_num_cellUNum);
-        packCapArr_Min = ArrMin(sohv_Q_packCapArrEi , 10);
-        packCapArr_Max = ArrMax(sohv_Q_packCapArrEi , 10);
-        if(sohd_Q_chrgEi > cmnc_Q_ratedCp || cellCapArr_Min < 10 || cellCapArr_Max > cmnc_Q_ratedCp + 100 || packCapArr_Min < 10 || packCapArr_Max > cmnc_Q_ratedCp + 100 )
+        cellCapArr_Min = ArrMin(sohv_Q_cellCapArrEi, cmnc_num_cellUNum);
+        cellCapArr_Max = ArrMax(sohv_Q_cellCapArrEi, cmnc_num_cellUNum);
+        packCapArr_Min = ArrMin(sohv_Q_packCapArrEi, 10);
+        packCapArr_Max = ArrMax(sohv_Q_packCapArrEi, 10);
+        if (sohd_Q_chrgEi > cmnc_Q_ratedCp || cellCapArr_Min < 10 || cellCapArr_Max > cmnc_Q_ratedCp + 100 || packCapArr_Min < 10 || packCapArr_Max > cmnc_Q_ratedCp + 100)
         {
-            memset(sohn_V_chrgStartStatEE, 0 , sizeof(sohn_V_chrgStartStatEE));
-			for(i=0 ; i < cmnc_num_cellUNum;i++)
-			{
-			   sohn_Q_cellCapArrEE[i] = cmnc_Q_ratedCp;
-			}
-			for(i=0 ; i < 10;i++)
-			{
-			   sohn_Q_packCapArrEE[i] = cmnc_Q_ratedCp;
-			}
-   
+            memset(sohn_V_chrgStartStatEE, 0, sizeof(sohn_V_chrgStartStatEE));
+            for (i = 0; i < cmnc_num_cellUNum; i++)
+            {
+                sohn_Q_cellCapArrEE[i] = cmnc_Q_ratedCp;
+            }
+            for (i = 0; i < 10; i++)
+            {
+                sohn_Q_packCapArrEE[i] = cmnc_Q_ratedCp;
+            }
+
             sohn_Q_chrgEE = 0;
             sohn_tm_chrgStartStatEE = 0;
             sohn_flg_chrgEndEE = 0;
         }
         else
         {
-            memcpy(sohn_V_chrgStartStatEE,sohv_V_chrgStartStatEi, sizeof(sohv_V_chrgStartStatEi));
-            memcpy(sohn_Q_cellCapArrEE,sohv_Q_cellCapArrEi, sizeof(sohv_Q_cellCapArrEi));
-            memcpy(sohn_Q_packCapArrEE,sohv_Q_packCapArrEi, sizeof(sohv_Q_packCapArrEi));
+            memcpy(sohn_V_chrgStartStatEE, sohv_V_chrgStartStatEi, sizeof(sohv_V_chrgStartStatEi));
+            memcpy(sohn_Q_cellCapArrEE, sohv_Q_cellCapArrEi, sizeof(sohv_Q_cellCapArrEi));
+            memcpy(sohn_Q_packCapArrEE, sohv_Q_packCapArrEi, sizeof(sohv_Q_packCapArrEi));
             sohn_Q_chrgEE = sohd_Q_chrgEi;
             sohn_tm_chrgStartStatEE = sohd_tm_chrgStartStatEi;
             sohn_flg_chrgEndEE = sohd_flg_chrgEndEi;
         }
- 		//=======================================================================================
+        //=======================================================================================
         //--------------------------计算使能-------------------------------------------------------
         //=======================================================================================
-        if(ihd_tm_parkTime >= cmnc_tm_parkTime && sohn_flg_chrgEndEE && sohn_Q_chrgEE > sohc_Q_countThr && !sfmd_flg_cellUInval && sfmd_I_curr < 10 && sfmd_I_curr > -10)
+        if (ihd_tm_parkTime >= cmnc_tm_parkTime && sohn_flg_chrgEndEE && sohn_Q_chrgEE > sohc_Q_countThr && !sfmd_flg_cellUInval && sfmd_I_curr < 10 && sfmd_I_curr > -10 && ArrMin(sohn_V_chrgStartStatEE, cmnc_num_cellUNum) > 3300)
         {
             sohn_flg_countEn = true;
+            sohd_flg_chrgEndEo = 0;
         }
         else
         {
             sohn_flg_countEn = false;
         }
-        
-		//=======================================================================================
+
+        //=======================================================================================
         //------------------------SOH 计算-------------------------------------------------------
         //=======================================================================================
-        if(sohn_flg_countEn)
+        if (sohn_flg_countEn)
         {
             sohn_flg_update = true;
-            for(i = 0;i < cmnc_num_cellUNum;i++)
+            for (i = 0; i < cmnc_num_cellUNum; i++)
             {
-                soc2[i] =  look1_u16tu16(sfmv_V_cellU[i],cmnm_V_ocv, cmnm_pct_soc, 13U);
-                soc1[i] =  look1_u16tu16(sohn_V_chrgStartStatEE[i],cmnm_V_ocv, cmnm_pct_soc, 13U);
+                soc2[i] = look1_u16tu16(sfmv_V_cellU[i], cmnm_V_ocv, cmnm_pct_soc, 13U);
+                soc1[i] = look1_u16tu16(sohn_V_chrgStartStatEE[i], cmnm_V_ocv, cmnm_pct_soc, 13U);
                 deltSoc[i] = soc2[i] - soc1[i];
-                sohv_Q_cellCapArrEo[i] = (uint16_T)( (real_T)(sohn_Q_chrgEE * 0.1) / (real_T)(deltSoc[i]  * 0.1/100)  * 10);
+                sohv_Q_cellCapArrEo[i] = (uint16_T)((real_T)(sohn_Q_chrgEE * 0.1) / (real_T)(deltSoc[i] * 0.1 / 100) * 10);
 
-                if( (int16_T)(sohv_Q_cellCapArrEo[i]) - sohn_Q_cellCapArrEE[i] > sohc_Q_updateDeltThr  ||  (int16_T)(sohv_Q_cellCapArrEo[i]) - sohn_Q_cellCapArrEE[i] < -sohc_Q_updateDeltThr  )
+                if ((int16_T)(sohv_Q_cellCapArrEo[i]) - sohn_Q_cellCapArrEE[i] > sohc_Q_updateDeltThr || (int16_T)(sohv_Q_cellCapArrEo[i]) - sohn_Q_cellCapArrEE[i] < -sohc_Q_updateDeltThr)
                 {
                     sohn_flg_update = false;
                     break;
                 }
             }
-            DisEn = (ArrMin(soc2 , cmnc_num_cellUNum) > sohc_pct_low &&  ArrMin(soc2 , cmnc_num_cellUNum) < sohc_pct_up) 
-                  ||(ArrMax(soc2 , cmnc_num_cellUNum) > sohc_pct_low &&  ArrMax(soc2 , cmnc_num_cellUNum) < sohc_pct_up)
-                  ||(ArrMin(soc1 , cmnc_num_cellUNum) > sohc_pct_low &&  ArrMin(soc1 , cmnc_num_cellUNum) < sohc_pct_up)
-                  ||(ArrMax(soc1 , cmnc_num_cellUNum) > sohc_pct_low &&  ArrMax(soc1 , cmnc_num_cellUNum) < sohc_pct_up);
-			//===================
-            if(sohn_flg_update && !DisEn)
-            {   
-				for(i = 0;i < cmnc_num_cellUNum;i++)
- 				{
-                     chrgCellCapArr[i] =    (uint16_T)((uint32_T)(sohv_Q_cellCapArrEo[i] * (1000 - soc2[i]))/1000);
-                     disChrgCellCapArr[i] = (uint16_T)((uint32_T)(sohv_Q_cellCapArrEo[i] * (        soc2[i]))/1000);
- 				} 
-                 chrgCap_Min    = ArrMin(chrgCellCapArr   , cmnc_num_cellUNum);
-                 disChrgCap_Min = ArrMin(disChrgCellCapArr, cmnc_num_cellUNum);
-                 for(i = 0; i < 9;i++)
-                 {
-                     sohv_Q_packCapArrEo[i] = sohn_Q_packCapArrEE[i+1];
-                 }
-                 sohv_Q_packCapArrEo[9] = chrgCap_Min + disChrgCap_Min;
-             }
-             else  //计算但结果偏差较大
-             {
-                 memcpy(sohv_Q_packCapArrEo,sohn_Q_packCapArrEE, sizeof(sohv_Q_packCapArrEo));
-                 memcpy(sohv_Q_cellCapArrEo,sohn_Q_cellCapArrEE, sizeof(sohv_Q_cellCapArrEo));
-             }   	
-         }
-         else  // 不计算
-         {
-             memcpy(sohv_Q_packCapArrEo,sohn_Q_packCapArrEE, sizeof(sohv_Q_packCapArrEo));
-             memcpy(sohv_Q_cellCapArrEo,sohn_Q_cellCapArrEE, sizeof(sohv_Q_cellCapArrEo));
-         }
-		 memcpy(sohv_Q_cellCap,sohv_Q_cellCapArrEo, sizeof(sohv_Q_cellCapArrEo));
+            DisEn = (ArrMin(soc2, cmnc_num_cellUNum) > sohc_pct_low && ArrMin(soc2, cmnc_num_cellUNum) < sohc_pct_up) || (ArrMax(soc2, cmnc_num_cellUNum) > sohc_pct_low && ArrMax(soc2, cmnc_num_cellUNum) < sohc_pct_up) || (ArrMin(soc1, cmnc_num_cellUNum) > sohc_pct_low && ArrMin(soc1, cmnc_num_cellUNum) < sohc_pct_up) || (ArrMax(soc1, cmnc_num_cellUNum) > sohc_pct_low && ArrMax(soc1, cmnc_num_cellUNum) < sohc_pct_up);
+            //===================
+            if (sohn_flg_update && !DisEn)
+            {
+                for (i = 0; i < cmnc_num_cellUNum; i++)
+                {
+                    chrgCellCapArr[i] = (uint16_T)((uint32_T)(sohv_Q_cellCapArrEo[i] * (1000 - soc2[i])) / 1000);
+                    disChrgCellCapArr[i] = (uint16_T)((uint32_T)(sohv_Q_cellCapArrEo[i] * (soc2[i])) / 1000);
+                }
+                chrgCap_Min = ArrMin(chrgCellCapArr, cmnc_num_cellUNum);
+                disChrgCap_Min = ArrMin(disChrgCellCapArr, cmnc_num_cellUNum);
+                for (i = 0; i < 9; i++)
+                {
+                    sohv_Q_packCapArrEo[i] = sohn_Q_packCapArrEE[i + 1];
+                }
+                sohv_Q_packCapArrEo[9] = chrgCap_Min + disChrgCap_Min;
+            }
+            else //计算但结果偏差较大
+            {
+                memcpy(sohv_Q_packCapArrEo, sohn_Q_packCapArrEE, sizeof(sohv_Q_packCapArrEo));
+                memcpy(sohv_Q_cellCapArrEo, sohn_Q_cellCapArrEE, sizeof(sohv_Q_cellCapArrEo));
+            }
+        }
+        else // 不计算
+        {
+            memcpy(sohv_Q_packCapArrEo, sohn_Q_packCapArrEE, sizeof(sohv_Q_packCapArrEo));
+            memcpy(sohv_Q_cellCapArrEo, sohn_Q_cellCapArrEE, sizeof(sohv_Q_cellCapArrEo));
+        }
+        memcpy(sohv_Q_cellCap, sohv_Q_cellCapArrEo, sizeof(sohv_Q_cellCapArrEo));
+
+        SumQ = 0;
+        for (i = 0; i < 10; i++)
+        {
+            SumQ = SumQ + sohv_Q_packCapArrEo[i];
+        }
+        sohd_pct_bcuSoh = (uint16_T)(((real_T)(SumQ * 0.1) / 10.0 / (real_T)(cmnc_Q_ratedCp * 0.1) * 100) * 10);
+        sohd_pct_bcuSoh = (sohd_pct_bcuSoh > 1000 ? 1000 : sohd_pct_bcuSoh);
+    }
+
+    //=======================================================================================
+    //----------------------充电前信息-------------------------------------------------------
+    //=======================================================================================
+    if (sohd_flg_firstRun)
+    {
+        memcpy(sohn_V_chrgStartStat, appv_V_cellU, sizeof(appv_V_cellU));
+    }
 
- 
-         SumQ = 0;
-         for(i = 0; i < 10;i++)
-         {
-             SumQ = SumQ + sohv_Q_packCapArrEo[i];
-         }
-         sohd_pct_bcuSoh = (uint16_T)(((real_T)(SumQ  * 0.1)/10.0/ (real_T)(cmnc_Q_ratedCp * 0.1) * 100) * 10);  
-         sohd_pct_bcuSoh = (sohd_pct_bcuSoh > 1000 ? 1000 : sohd_pct_bcuSoh);
-	  }
- 	 
-     //=======================================================================================
-     //----------------------充电前信息-------------------------------------------------------
-     //=======================================================================================
-     if (sohd_flg_firstRun)
-     {
-     	 memcpy(sohn_V_chrgStartStat,appv_V_cellU, sizeof(appv_V_cellU));
-     }
-     
-     if(sfmd_I_curr < 10 && sfmd_I_curr > -10 && !sfmd_flg_cellUInval)
-     {
-         memcpy(sohn_V_chrgStartStat,sfmv_V_cellU, sizeof(sfmv_V_cellU));
-     }
-     //
-     if((ihd_st_workStat == 2) && (sohn_st_workStat_Delay != 2))
-     {
-        memcpy(sohv_V_chrgStartStatEo,sohn_V_chrgStartStat, sizeof(sohv_V_chrgStartStatEo));
-     }
+    if (sfmd_I_curr < 10 && sfmd_I_curr > -10 && !sfmd_flg_cellUInval)
+    {
+        memcpy(sohn_V_chrgStartStat, sfmv_V_cellU, sizeof(sfmv_V_cellU));
+    }
+    //
+    if ((ihd_st_workStat == 2) && (sohn_st_workStat_Delay != 2))
+    {
+        memcpy(sohv_V_chrgStartStatEo, sohn_V_chrgStartStat, sizeof(sohv_V_chrgStartStatEo));
+    }
 
-	 
-    //printf("sohv_V_chrgStartStatEo[16]:%d\n",sohv_V_chrgStartStatEo[16]);
+    // printf("sohv_V_chrgStartStatEo[16]:%d\n",sohv_V_chrgStartStatEo[16]);
     //=======================================================================================
     //----------------------充电中信息-------------------------------------------------------
     //=======================================================================================
-    if(ihd_st_workStat == 2)
+    if (ihd_st_workStat == 2)
     {
         Ahincr = Ahincr + (real_T)sfmd_I_curr * 0.1;
-        tmp_0 = (int16_T)(Ahincr/3600 * 10);
-		
-        sohd_Q_chrgEo = tmp_0 > 0 ? (uint16_T)tmp_0 : 0;  
-        if(sfmd_flg_currInval)
+        tmp_0 = (int16_T)(Ahincr / 3600 * 10);
+
+        sohd_Q_chrgEo = tmp_0 > 0 ? (uint16_T)tmp_0 : 0;
+        if (sfmd_flg_currInval)
         {
             sfmn_flg_currFlt_keep = true;
         }
-        sohn_flg_currFlt = sfmn_flg_currFlt_keep;   
+        sohn_flg_currFlt = sfmn_flg_currFlt_keep;
     }
     else
     {
@@ -213,23 +207,20 @@ void SOH(void)
         Ahincr = 0;
     }
 
-	//=======================================================================================
+    //=======================================================================================
     //----------------------充电结速信息------------------------------------------------------
     //=======================================================================================
-    if((ihd_st_workStat != 2) && (sohn_st_workStat_Delay == 2))
+    if ((ihd_st_workStat != 2) && (sohn_st_workStat_Delay == 2))
     {
-       sohd_flg_chrgEndEo = true; 
+        sohd_flg_chrgEndEo = true;
     }
     else
     {
-      sohd_flg_chrgEndEo = ( sfmd_I_curr < 10 && sfmd_I_curr > -10) && sohd_flg_chrgEndEo;
+        sohd_flg_chrgEndEo = (sfmd_I_curr < 10 && sfmd_I_curr > -10) && sohd_flg_chrgEndEo;
     }
-    sohd_flg_chrgEndEo =  !sohn_flg_currFlt && sohd_flg_chrgEndEo;
+    sohd_flg_chrgEndEo = !sohn_flg_currFlt && sohd_flg_chrgEndEo;
 
     //
     sohn_st_workStat_Delay = ihd_st_workStat;
-	sohd_flg_firstRun = false;	
+    sohd_flg_firstRun = false;
 }
-
-
-