فهرست منبع

【V3.0.0.17】-修改了3.0.0.16的bug,

CHENJIE-PC\QiXiang_CHENJIE 3 سال پیش
والد
کامیت
b716092098

+ 2 - 2
inc/AppConfig.h

@@ -2,7 +2,7 @@
  * @Author       : ChenJie
  * @Date         : 2021-10-14 09:27:15
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-10-15 17:56:20
+ * @LastEditTime : 2021-10-18 13:52:56
  * @Description  : App Config H file 配置文件,可以针对不同参数进行更改
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\inc\AppConfig.h
  */
@@ -14,7 +14,7 @@
 #define DATA_MODULE_TYPE (1)           //1表示NB模块,2表示4G cat1
 #define EOLSTATE (0)                   //1表示下线检测跳过,使用默认值,0表示使用下线检测
 #define DEFAULT_SN "RLTEST00000000001" //默认上传的SN编码
-#define APPSWVERSION 0x03000010        //数据模块软件版本号
+#define APPSWVERSION 0x03000011        //数据模块软件版本号
 
 #define TCP_ADD "iotp.fast-fun.cn" //数据上传的地址
 #define TCP_PORT 8712              //数据上传的端口

+ 3 - 0
inc/EmbeddedCoder_inc/BCUDisp.h

@@ -44,6 +44,9 @@ extern uint8_T ihd_st_workStat;                          /*电池工作状态 */
 extern uint16_T ihd_tm_parkTime;                         /*驻车时间; */
 extern uint16_T ihv_T_modT[6];                           /*模组温度(数组)+40 */
 extern uint16_T ihv_V_cellU[28];                         /*电池单体电压(数组); */
+extern boolean_T ihd_st_chrgMosControl;    
+extern boolean_T ihd_st_disChrgMosControl; 
+extern boolean_T ihd_st_relayControl;    
 
 extern int16_T sfmd_I_curr;                              /*处理后整包电流 */
 extern uint16_T sfmd_T_modTMax;                          /*处理后模组温度最小 */

+ 2 - 2
src/AppFunc.c

@@ -3,7 +3,7 @@
  * @Date         : 2021-10-14 09:27:15
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-10-15 15:54:33
+ * @LastEditTime : 2021-10-18 10:10:55
  * @Description  : 应用层函数定义区,UTF-8
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AppFunc.c
  */
@@ -545,7 +545,7 @@ void LEDDisplay(void)
 				if ((((battWarningState >> 10) & 0x01) == 0x01) && ((battWarningState & 0xFFFFFBFF) == 0x00))
 					return;
 			}
-			if (getbit(sfmd_st_fltAct, 2) == 1) //电池存在故障
+			if (getbit(sfmd_st_fltAct, 1) == 1) //电池存在故障
 			{
 				if (ErrorLightTimer < (UINT8)(LEDFlashPeriod * DutyRatio))
 				{

+ 8 - 2
src/AppTaskUart.c

@@ -2,7 +2,7 @@
  * @Author       : ChenJie
  * @Date         : 2021-10-14 09:27:15
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-10-14 15:41:37
+ * @LastEditTime : 2021-10-18 11:39:42
  * @Description  : file content
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AppTaskUart.c
  */
@@ -385,13 +385,19 @@ void Uart_Cmd_Control(QueueHandle_t UartWriteCmdHandle, UartBuffer UartAnswerDat
 	}
 	if ((RelayForbiddenControl == 1) && (RelayControlState == 0x00)) //将继电器断开
 	{
+#ifdef USING_PRINTF1
+		printf("[%d]try to cut relay \n", __LINE__);
+#endif
 		UartWriteData.WriteCmd = 0x04;
 		UartWriteData.Data[0] = 0x80;
 		UartWriteData.Data[1] = 0x00 | (ChargePermitState << 1) | DischargePermitState;
 		osMessageQueuePut(UartWriteCmdHandle, &UartWriteData, 0, 10);
 	}
-	else if ((RelayForbiddenControl == 1) && (RelayControlState == 0x01)) //继电器闭合
+	else if ((RelayForbiddenControl == 0) && (RelayControlState == 0x01)) //继电器闭合
 	{
+#ifdef USING_PRINTF1
+		printf("[%d]try to close relay \n", __LINE__);
+#endif
 		UartWriteData.WriteCmd = 0x04;
 		UartWriteData.Data[0] = 0x00;
 		UartWriteData.Data[1] = 0x00 | (ChargePermitState << 1) | DischargePermitState;

+ 4 - 0
src/BCU.c

@@ -92,6 +92,10 @@ void BCU(void)
                     ihd_flg_disChrgModTLowFlt = ((battWarningState >> 22) & 0x01) == 1;
                     ihd_flg_chrgModTLowFlt = ((battWarningState >> 23) & 0x01) == 1;
                     ihd_flg_currOpenFlt = 0;
+					ihd_st_chrgMosControl    = ChargeForbiddenControl == 0;
+					ihd_st_disChrgMosControl = DisChargeForbiddenControl  == 0;
+				    ihd_st_relayControl      = RelayForbiddenControl  == 0;
+				   
 
                     //=============================================================================
                     SFM();

+ 5 - 10
src/EmbeddedCoder_src/BCUCal.c

@@ -10,16 +10,11 @@ const uint16_T cmnc_Q_ratedCp = 600U;                       /* 电池容量; *
 const uint16_T cmnc_num_cellUNum = 17U;                     /* 电压采样点实际个数; */
 const uint16_T cmnc_num_modTNum = 4U;                       /* 温度采样点实际个数; */
 const uint16_T cmnc_tm_parkTime = 1800U;                    /* 静置时间阈值; */
-const uint16_T cmnm_F_polar[13] = { 3880U, 5062U, 10906U, 10798U, 12885U, 12990U,
-  14331U, 10754U, 9378U, 10340U, 10592U, 11946U, 11515U } ; /* 电池放电参数的C数组; */
-const uint16_T cmnm_R_ohm[13] = { 2181U, 2043U, 2040U, 1927U, 1850U, 1802U,
-  1771U, 1743U, 1733U, 1728U, 1748U, 1762U, 1789U } ;       /* 电池放电参数的Ro数组; */
-const uint16_T cmnm_R_polar[13] = { 1837U, 1055U, 1352U, 1453U, 1181U, 1125U,
-  1205U, 1283U, 1228U, 1187U, 1104U, 1170U, 1049U } ;       /* 电池放电参数的Rp数组; */
-const uint16_T cmnm_V_ocv[13] = { 3234U, 3444U, 3476U, 3553U, 3610U, 3638U,
-  3674U, 3758U, 3845U, 3942U, 4051U, 4106U, 4175U } ;       /* 电池放电参数的OCV数组; */
-const uint16_T cmnm_pct_soc[13] = { 0U, 50U, 100U, 200U, 300U, 400U, 500U, 600U,
-  700U, 800U, 900U, 950U, 1000U } ;                         /* 电池放电参数的SOC数组; */
+const uint16_T cmnm_F_polar[13] = { 3880U, 5062U, 10906U, 10798U, 12885U, 12990U,14331U, 10754U, 9378U, 10340U, 10592U, 11946U, 11515U } ; /* 电池放电参数的C数组; */
+const uint16_T cmnm_R_ohm[13] = { 2181U, 2043U, 2040U, 1927U, 1850U, 1802U,1771U, 1743U, 1733U, 1728U, 1748U, 1762U, 1789U } ;       /* 电池放电参数的Ro数组; */
+const uint16_T cmnm_R_polar[13] = { 1837U, 1055U, 1352U, 1453U, 1181U, 1125U,1205U, 1283U, 1228U, 1187U, 1104U, 1170U, 1049U } ;       /* 电池放电参数的Rp数组; */
+const uint16_T cmnm_V_ocv[13] = { 3234U, 3444U, 3476U, 3553U, 3610U, 3638U,3674U, 3758U, 3845U, 3942U, 4051U, 4106U, 4175U } ;       /* 电池放电参数的OCV数组; */
+const uint16_T cmnm_pct_soc[13] = { 0U, 50U, 100U, 200U, 300U, 400U, 500U, 600U,700U, 800U, 900U, 950U, 1000U } ;                         /* 电池放电参数的SOC数组; */
 const uint16_T cmnc_V_chrgFulV = 4200U;                     /* 充满电的截至电压; */
 
 const uint16_T sfmc_I_chrgCurrOverThr = 600;                 /* 充电电流阈值 */

+ 4 - 0
src/EmbeddedCoder_src/BCUDisp.c

@@ -44,7 +44,11 @@ uint8_T ihd_st_workStat;                          /*电池工作状态 */
 uint16_T ihd_tm_parkTime;                         /*驻车时间; */
 uint16_T ihv_T_modT[6];                           /*模组温度(数组)+40 */
 uint16_T ihv_V_cellU[28];                         /*电池单体电压(数组); */
+boolean_T ihd_st_chrgMosControl;    
+boolean_T ihd_st_disChrgMosControl; 
+boolean_T ihd_st_relayControl;    
 
+					
 int16_T sfmd_I_curr;                              /*处理后整包电流 */
 uint16_T sfmd_T_modTMax;                          /*处理后模组温度最小 */
 uint16_T sfmd_T_modTMin;                          /*处理后模组温度最大 */

+ 3 - 4
src/EmbeddedCoder_src/BLC.c

@@ -16,9 +16,9 @@ void BLC(void)
     static uint32_T blcn_Q_totalCpEE[28];
     uint16_T MaxCp;
     
-    boolean_T blcn_flg_judge;
+    static boolean_T blcn_flg_judge;
     boolean_T blcn_flg_enable;
-    static boolean_T sfmd_flg_volFlt_keep;
+
     
     uint16_T blcn_pct_cellSoc[28];
     uint16_T blcn_pct_cellSocMin;
@@ -66,9 +66,8 @@ void BLC(void)
     //=========================================================================
     if(FirstRun_BLC)
     {
-        sfmd_flg_volFlt_keep =  sfmd_flg_cellUDisable;
+		blcn_flg_judge	= (ihd_tm_parkTime > cmnc_tm_parkTime)&& !sfmd_flg_cellUDisable && (sfmd_I_curr > -10 && sfmd_I_curr < 10);
     }
-    blcn_flg_judge  = (ihd_tm_parkTime > cmnc_tm_parkTime)&& !sfmd_flg_volFlt_keep;
     blcn_flg_enable = ((sfmd_st_fltAct >> 7) & 0x01) != 1;
 
     //=========================================================================

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 433 - 766
src/EmbeddedCoder_src/SFM.c


+ 281 - 276
src/EmbeddedCoder_src/SOC.c

@@ -2,12 +2,15 @@
 #include "look1_is16lu16n16tu16_binlcase.h"
 #include "look1_iu16lu16n16tu16_binlcase.h"
 
+
 boolean_T FirstRun_SOC;
 
+
 //---------------SOC初始化-----------------------------------------------
 void SOC_Init(void)
-{
+{   
     FirstRun_SOC = true;
+
 }
 //-------------------------------------------------------------------------
 
@@ -17,21 +20,21 @@ void SOC(void)
     static uint16_T socn_pct_bcuSocEE;
     static uint16_T socn_Q_cap;
     //
-    uint16_T EKFSOCMin;
-    uint16_T EKFSOCMax;
-    boolean_T socn_flg_ekfInvalidMin;
-    boolean_T socn_flg_ekfInvalidMax;
-    boolean_T socn_flg_ekfInvalid;
+    uint16_T   EKFSOCMin;
+    uint16_T   EKFSOCMax;
+    boolean_T  socn_flg_ekfInvalidMin;
+    boolean_T  socn_flg_ekfInvalidMax;
+    boolean_T  socn_flg_ekfInvalid;
     real_T ocv;
     real_T Ro;
     real_T Rp;
     real_T C;
-    real_T deltU;
+	real_T deltU;
     real_T A[4];
     real_T B[2];
     real_T H[2];
     real_T K[2];
-    real_T P1[4];
+	real_T P1[4];
     static real_T P_Min_Delay[4];
     static real_T P_Max_Delay[4];
     real_T soc1;
@@ -48,239 +51,241 @@ void SOC(void)
     static real_T ahDelay;
     int16_T ahSoc;
     //
-    static uint16_T ekfInvalidCntl;
+    static uint16_T  ekfInvalidCntl;
     static boolean_T onceFlg_est;
-    static int16_T ahSoc0_est;
-    static uint16_T ekfSoc0_est;
+    static int16_T   ahSoc0_est;
+    static uint16_T  ekfSoc0_est;
     //
     static boolean_T overFlg;
     static boolean_T fulFlg;
-    static uint8_T overCntl;
-    static uint8_T fulCntl;
+    static uint8_T   overCntl;
+    static uint8_T   fulCntl; 
     static boolean_T onceFlg_utrckOver;
-    static int16_T ahSoc0_utrckOver;
-    static uint16_T estSoc0_utrckOver;
-    static uint16_T Soc_Delay;
+    static int16_T   ahSoc0_utrckOver;
+    static uint16_T  estSoc0_utrckOver;
+    static uint16_T  Soc_Delay;
     static boolean_T lowFlg;
-    static uint8_T lowCntl;
+    static uint8_T   lowCntl;
     static boolean_T onceFlg_utrckLow;
-    static int16_T ahSoc0_utrckLow;
-    static uint16_T estSoc0_utrckLow;
+    static int16_T   ahSoc0_utrckLow;
+    static uint16_T  estSoc0_utrckLow;
     uint16_T socn_pct_utrackSoc;
-    uint16_T socTemp;
-    static uint8_T chrgCntl;
-    static uint8_T disChrgCntl;
+	uint16_T socTemp;
+	static uint8_T chrgCntl;
+	static uint8_T disChrgCntl;
     //
     static uint16_T socd_pct_battSoc_Delay;
     //
-    static uint8_T statCntl;
+    static uint8_T  statCntl;
     boolean_T statFlg;
-    static uint8_T ihd_st_chrgSta_Delay;
+    static uint8_T  ihd_st_chrgSta_Delay;
     static uint16_T socn_pct_utrackSoc_Delay;
     static uint16_T socd_pct_battSoc0;
     static uint16_T socd_pct_bcuSoc0;
     uint16_T delSOC;
     uint16_T bcuSoc;
-    int16_T coinSoc;
+    int16_T  coinSoc;
     uint16_T x[3];
     uint16_T y[3];
-    boolean_T Flg;
+	boolean_T Flg;
     static boolean_T onceFlg_chrg;
     static boolean_T onceFlg_dischrg;
-    //
-
-    if (FirstRun_SOC)
-    {
-        onceFlg_est = true;
-        ekfInvalidCntl = 0;
-        overCntl = 0;
-        fulCntl = 0;
-        lowCntl = 0;
-        overFlg = false;
-        fulFlg = false;
-        lowFlg = false;
-        Soc_Delay = 0;
-        onceFlg_utrckOver = true;
-        onceFlg_utrckLow = true;
-        ihd_st_chrgSta_Delay = 0;
-        socn_pct_utrackSoc_Delay = 0;
-        onceFlg_chrg = true;
-        onceFlg_dischrg = true;
-    }
 
+	
+	//
+    if(FirstRun_SOC)
+    { 
+      onceFlg_est  = true;	  
+      ekfInvalidCntl = 0;
+      overCntl = 0;
+      fulCntl = 0;
+      lowCntl = 0;
+      overFlg = false;
+      fulFlg = false;
+      lowFlg = false;
+	  Soc_Delay = 0 ;  
+      onceFlg_utrckOver = true;
+      onceFlg_utrckLow = true;
+      ihd_st_chrgSta_Delay = 0;
+      socn_pct_utrackSoc_Delay = 0;
+      onceFlg_chrg    = true;
+      onceFlg_dischrg = true;
+    }
+	
     //=====================================================================
     ////////////////////////初始值获取//////////////////////////////////////
     //=====================================================================
-    if (FirstRun_SOC)
-    { //
-        if ((socd_pct_battSocEi > 1000) || (socd_pct_bcuSocEi > 1000))
+    if(FirstRun_SOC)
+    {   //
+        if ((socd_pct_battSocEi > 1000) || (socd_pct_bcuSocEi > 1000) )
         {
-            socn_pct_battSocEE = look1_iu16lu16n16tu16_binlcase(sfmd_V_cellUAvrg, (&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
-            socn_pct_bcuSocEE = look1_iu16lu16n16tu16_binlcase(sfmd_V_cellUAvrg, (&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
+            socn_pct_battSocEE =  look1_iu16lu16n16tu16_binlcase(sfmd_V_cellUAvrg,(&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
+            socn_pct_bcuSocEE  =  look1_iu16lu16n16tu16_binlcase(sfmd_V_cellUAvrg,(&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
         }
         else
         {
             socn_pct_battSocEE = socd_pct_battSocEi;
-            socn_pct_bcuSocEE = socd_pct_bcuSocEi;
+            socn_pct_bcuSocEE  = socd_pct_bcuSocEi;
         }
         //
         if (ihd_tm_parkTime > cmnc_tm_parkTime && 0)
         {
-            socn_pct_battSocEE = look1_iu16lu16n16tu16_binlcase(sfmd_V_cellUAvrg, (&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
+            socn_pct_battSocEE =  look1_iu16lu16n16tu16_binlcase(sfmd_V_cellUAvrg,(&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
         }
-        socn_Q_cap = (uint16_T)((uint16_T)((uint32_T)sohd_pct_bcuSoh * cmnc_Q_ratedCp / 2000U) << 1);
+		socn_Q_cap = (uint16_T)((uint16_T)((uint32_T)sohd_pct_bcuSoh *cmnc_Q_ratedCp / 2000U) << 1);
     }
-    //printf("1----  battSocEi:%d,bcuSocEi:%d,battSocEE:%d,bcuSocEE:%d\n",socd_pct_battSocEi,socd_pct_bcuSocEi,socn_pct_battSocEE,socn_pct_bcuSocEE);
+	//printf("1----  battSocEi:%d,bcuSocEi:%d,battSocEE:%d,bcuSocEE:%d\n",socd_pct_battSocEi,socd_pct_bcuSocEi,socn_pct_battSocEE,socn_pct_bcuSocEE);
     //======================================================================
     ////////////////////////EKFSOC//////////////////////////////////////////
     //======================================================================
     battcurr = (real_T)sfmd_I_curr * 0.1;
-    Q = (real_T)socn_Q_cap * 0.1;
-
+    Q =        (real_T)socn_Q_cap  * 0.1;
+	
     //-------------------------EKFmin---------------------------------------
     if (FirstRun_SOC)
     {
         soc_Min_Delay = (real_T)socn_pct_battSocEE * 0.1;
-        Up_Min_Delay = 0;
+        Up_Min_Delay  = 0;
         P_Min_Delay[0] = 1000;
-        P_Min_Delay[1] = 0;
-        P_Min_Delay[2] = 0;
-        P_Min_Delay[3] = 1000;
+		P_Min_Delay[1] = 0;
+		P_Min_Delay[2] = 0;
+		P_Min_Delay[3] = 1000;
     }
     //参数查表
-    ocv = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])), 12U) * 0.001;
-    Ro = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])), 12U) * 0.001 * 0.001;
-    Rp = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_polar[0])), 12U) * 0.001 * 0.001;
-    C = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_F_polar[0])), 12U) * 0.001 * 1000;
+    ocv = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])),   12U) * 0.001;
+    Ro  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])),    12U) * 0.001 * 0.001;
+    Rp  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_R_polar[0])), 12U) * 0.001 * 0.001;
+    C   = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_F_polar[0])), 12U) * 0.001 * 1000;
     A[0] = 1;
     A[1] = 0;
     A[2] = 0;
-    A[3] = exp(-0.1 / (Rp * C));
-
-    B[0] = 0.1 / Q / 3600 * 100;
-    B[1] = Rp * (1 - exp(-0.1 / (Rp * C)));
-
+    A[3] = exp(-0.1/( Rp * C));
+	
+    B[0] = 0.1/Q/3600 * 100;
+    B[1] = Rp * (1- exp(-0.1/(Rp * C)));
+	
     H[0] = docvmath(soc_Min_Delay);
     H[1] = 1;
-
+	
     //先验
     soc1 = soc_Min_Delay * A[0] + B[0] * battcurr;
-    Up1 = Up_Min_Delay * A[3] + B[1] * battcurr;
-    UL = ocv + battcurr * Ro + Up1;
+    Up1  = Up_Min_Delay  * A[3] + B[1] * battcurr;
+    UL= ocv + battcurr * Ro + Up1;
     P1[0] = P_Min_Delay[0] + 0.002;
-    P1[1] = P_Min_Delay[1] * A[3] + 0.002;
-    P1[2] = P_Min_Delay[2] * A[3] + 0.002;
-    P1[3] = P_Min_Delay[3] * A[3] * A[3] + 0.002;
-
+    P1[1] = P_Min_Delay[1] * A[3] +0.002;
+    P1[2] = P_Min_Delay[2] * A[3] +0.002;
+    P1[3] = P_Min_Delay[3] * A[3] * A[3] +0.002;
+	
     //增益
-    K[0] = (P1[0] * H[0] + P1[2]) / (H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] + 0.5);
-    K[1] = (P1[1] * H[0] + P1[3]) / (H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] + 0.5);
-
+    K[0] = (P1[0] * H[0] + P1[2])/( H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] +0.5 );
+    K[1] = (P1[1] * H[0] + P1[3])/( H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] +0.5 );
+	
     //后验
-    deltU = (real_T)sfmd_V_cellUMin * 0.001 - UL;
+    deltU  = (real_T)sfmd_V_cellUMin * 0.001 - UL;
     soc_Min_Delay = soc1 + K[0] * deltU;
-
+	
     if (soc_Min_Delay < (real_T)socc_pct_battSocLow * 0.1)
     {
-        soc_Min_Delay = (real_T)socc_pct_battSocLow * 0.1;
+        soc_Min_Delay=  (real_T)socc_pct_battSocLow * 0.1;
     }
-    if (soc_Min_Delay > (real_T)socc_pct_battSocUp * 0.1)
+    if (soc_Min_Delay > (real_T)socc_pct_battSocUp  * 0.1)
     {
-        soc_Min_Delay = (real_T)socc_pct_battSocUp * 0.1;
+        soc_Min_Delay=  (real_T)socc_pct_battSocUp  * 0.1;
     }
-
-    Up_Min_Delay = Up1 + K[1] * deltU;
-
+	
+    Up_Min_Delay  = Up1 + K[1] * deltU;
+	
     //P更新
-    P_Min_Delay[0] = (1 - K[0] * H[0]) * P1[0] - K[0] * P1[1];
+    P_Min_Delay[0] = (1 - K[0] * H[0]) * P1[0] -K[0]* P1[1];
     P_Min_Delay[1] = -K[1] * H[0] * P1[0] + P1[1] * (1 - K[1]);
-    P_Min_Delay[2] = (1 - K[0] * H[0]) * P1[2] - K[0] * P1[3];
+    P_Min_Delay[2] = (1 - K[0] * H[0]) * P1[2] -K[0]* P1[3];
     P_Min_Delay[3] = -K[1] * H[0] * P1[2] + P1[3] * (1 - K[1]);
-
+	
     //输出
-    EKFSOCMin = (uint16_T)(soc_Min_Delay * 10);
-    socn_flg_ekfInvalidMin = (deltU > 0.005) || (deltU < -0.005);
-    //printf("2----socmin:%f,Up:%f,U1:%d,sfmd_V_cellUMin:%d,deltU:%f,flg:%d,soc1:%f,K[0]:%f,K[1]:%f\n",soc_Min_Delay,Up_Min_Delay,ihv_V_cellU[0],sfmd_V_cellUMin,deltU,socn_flg_ekfInvalidMin,soc1,K[0],K[1]);
+    EKFSOCMin = (uint16_T) (soc_Min_Delay * 10);
+    socn_flg_ekfInvalidMin= (deltU > 0.005)||(deltU < -0.005);
+	//printf("2----socmin:%f,Up:%f,U1:%d,sfmd_V_cellUMin:%d,deltU:%f,flg:%d,soc1:%f,K[0]:%f,K[1]:%f\n",soc_Min_Delay,Up_Min_Delay,ihv_V_cellU[0],sfmd_V_cellUMin,deltU,socn_flg_ekfInvalidMin,soc1,K[0],K[1]);
     //------------------------EKFSOCmax-----------------------------------
     if (FirstRun_SOC)
     {
-        soc_Max_Delay = (real_T)socn_pct_battSocEE * 0.1;
-        Up_Max_Delay = 0;
+        soc_Max_Delay  = (real_T)socn_pct_battSocEE * 0.1;
+        Up_Max_Delay   = 0;
         P_Max_Delay[0] = 1000;
-        P_Max_Delay[1] = 0;
-        P_Max_Delay[2] = 0;
-        P_Max_Delay[3] = 1000;
+		P_Max_Delay[1] = 0;
+		P_Max_Delay[2] = 0;
+		P_Max_Delay[3] = 1000;
     }
     // 参数查表
-    ocv = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])), 12U) * 0.001;
-    Ro = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])), 12U) * 0.001 * 0.001;
-    Rp = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_polar[0])), 12U) * 0.001 * 0.001;
-    C = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_F_polar[0])), 12U) * 0.001 * 1000;
+    ocv = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])),  12U) * 0.001;
+    Ro  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])),   12U) * 0.001 * 0.001;
+    Rp  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_R_polar[0])),12U) * 0.001 * 0.001;
+    C   = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_F_polar[0])),12U) * 0.001 * 1000;
     A[0] = 1;
     A[1] = 0;
     A[2] = 0;
-    A[3] = exp(-0.1 / (Rp * C));
-
-    B[0] = 0.1 / Q / 3600 * 100;
-    B[1] = Rp * (1 - exp(-0.1 / (Rp * C)));
-
+    A[3] = exp(-0.1/( Rp * C));
+	
+    B[0] = 0.1/Q/3600 * 100;
+    B[1] = Rp * (1- exp(-0.1/(Rp * C)));
+	
     H[0] = docvmath(soc_Max_Delay);
     H[1] = 1;
-
+	
     //先验
     soc1 = soc_Max_Delay * A[0] + B[0] * battcurr;
-    Up1 = Up_Max_Delay * A[3] + B[1] * battcurr;
-    UL = ocv + battcurr * Ro + Up1;
-
+    Up1  = Up_Max_Delay  * A[3] + B[1] * battcurr;
+    UL= ocv + battcurr * Ro + Up1;
+	
     P1[0] = P_Max_Delay[0] + 0.002;
-    P1[1] = P_Max_Delay[1] * A[3] + 0.002;
-    P1[2] = P_Max_Delay[2] * A[3] + 0.002;
-    P1[3] = P_Max_Delay[3] * A[3] * A[3] + 0.002;
-
+    P1[1] = P_Max_Delay[1] * A[3] +0.002;
+    P1[2] = P_Max_Delay[2] * A[3] +0.002;
+    P1[3] = P_Max_Delay[3] * A[3] * A[3] +0.002;
+	
     //增益
-    K[0] = (P1[0] * H[0] + P1[2]) / (H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] + 0.5);
-    K[1] = (P1[1] * H[0] + P1[3]) / (H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] + 0.5);
-
+    K[0] = (P1[0] * H[0] + P1[2])/( H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] +0.5 );
+    K[1] = (P1[1] * H[0] + P1[3])/( H[0] * P1[0] * H[0] + P1[1] * H[0] + H[0] * P1[2] + P1[3] +0.5 );
+	
     //后验
-    deltU = (real_T)sfmd_V_cellUMax * 0.001 - UL;
+    deltU  = (real_T)sfmd_V_cellUMax * 0.001 - UL;
     soc_Max_Delay = soc1 + K[0] * deltU;
-
+	
     if (soc_Max_Delay < (real_T)socc_pct_battSocLow * 0.1)
     {
-        soc_Max_Delay = (real_T)socc_pct_battSocLow * 0.1;
+        soc_Max_Delay =  (real_T)socc_pct_battSocLow * 0.1;
     }
     if (soc_Max_Delay > (real_T)socc_pct_battSocUp * 0.1)
     {
-        soc_Max_Delay = (real_T)socc_pct_battSocUp * 0.1;
+        soc_Max_Delay =  (real_T)socc_pct_battSocUp * 0.1;
     }
-    Up_Max_Delay = Up1 + K[1] * deltU;
+    Up_Max_Delay  = Up1 + K[1] * deltU;
 
+	
     //P更新
-    P_Max_Delay[0] = (1 - K[0] * H[0]) * P1[0] - K[0] * P1[1];
+    P_Max_Delay[0] = (1 - K[0] * H[0]) * P1[0] -K[0] * P1[1];
     P_Max_Delay[1] = -K[1] * H[0] * P1[0] + P1[1] * (1 - K[1]);
-    P_Max_Delay[2] = (1 - K[0] * H[0]) * P1[2] - K[0] * P1[3];
+    P_Max_Delay[2] = (1 - K[0] * H[0]) * P1[2] -K[0] * P1[3];
     P_Max_Delay[3] = -K[1] * H[0] * P1[2] + P1[3] * (1 - K[1]);
     //输出
-    EKFSOCMax = (uint16_T)(soc_Max_Delay * 10);
-    socn_flg_ekfInvalidMax = (deltU > 0.005) || (deltU < -0.005);
-    //printf("3----socmax:%f,Up:%f,sfmd_V_cellUMax:%d,deltU:%f,flg:%d\n",soc_Max_Delay,Up_Max_Delay,sfmd_V_cellUMax,deltU,socn_flg_ekfInvalidMax);
+    EKFSOCMax = (uint16_T) (soc_Max_Delay * 10);
+    socn_flg_ekfInvalidMax= (deltU > 0.005)||(deltU < -0.005);
+	//printf("3----socmax:%f,Up:%f,sfmd_V_cellUMax:%d,deltU:%f,flg:%d\n",soc_Max_Delay,Up_Max_Delay,sfmd_V_cellUMax,deltU,socn_flg_ekfInvalidMax);
     //-----------------------EKFSOC----------------------------------------
     socn_flg_ekfInvalid = socn_flg_ekfInvalidMax || socn_flg_ekfInvalidMin;
-    if (EKFSOCMax > 800)
+    if(EKFSOCMax > 800)
     {
         factor = 100;
     }
-    else if (EKFSOCMin < 200)
+    else if(EKFSOCMin < 200)
     {
         factor = 0;
     }
     else
     {
-        factor = (uint16_T)(((uint16_T)(((uint32_T)(EKFSOCMin - 200) << 6) / (800 - (EKFSOCMax - EKFSOCMin) - 200)) * 25U) >> 4);
+        factor=(uint16_T)(((uint16_T)((  (uint32_T)  (EKFSOCMin - 200)  << 6) / (800 - (EKFSOCMax-EKFSOCMin) - 200)) * 25U) >> 4);
     }
-    socd_pct_ekfSoc = (uint16_T)(((1 - (real_T)(factor * 0.01)) * (real_T)(EKFSOCMin * 0.1) + (real_T)(factor * 0.01) * (real_T)(EKFSOCMax * 0.1)) * 10);
+	socd_pct_ekfSoc = (uint16_T)( (  (1 - (real_T)(factor * 0.01)) * (real_T) (EKFSOCMin * 0.1) +  (real_T)(factor * 0.01) * (real_T)( EKFSOCMax * 0.1)  ) * 10); 
 
-    //printf("4----factor:%d,socd_pct_ekfSoc:%d,EKFSOCMax:%d,EKFSOCMin:%d,\n",factor,socd_pct_ekfSoc,EKFSOCMax,EKFSOCMin);
+	//printf("4----factor:%d,socd_pct_ekfSoc:%d,EKFSOCMax:%d,EKFSOCMin:%d,\n",factor,socd_pct_ekfSoc,EKFSOCMax,EKFSOCMin);
     //======================================================================
     ////////////////////////AhSOC//////////////////////////////////////////
     //======================================================================
@@ -290,9 +295,9 @@ void SOC(void)
     }
     else
     {
-        ahDelay = ahDelay + battcurr / (real_T)(cmnc_Q_ratedCp * 0.1) / 360.0;
+        ahDelay = ahDelay +  battcurr / (real_T)(cmnc_Q_ratedCp * 0.1) /360.0;
     }
-    ahSoc = (int16_T)(ahDelay * 10);
+    ahSoc =(int16_T)(ahDelay * 10);
     if (ahSoc > socc_pct_battSocUp)
     {
         socd_pct_ahSoc = socc_pct_battSocUp;
@@ -305,35 +310,35 @@ void SOC(void)
     {
         socd_pct_ahSoc = (uint16_T)ahSoc;
     }
-    //printf("5----ahDelay:%f,ahSoc:%d,battcurr:%f,sfmd_I_curr:%d\n",ahDelay,ahSoc,battcurr,sfmd_I_curr);
+	//printf("5----ahDelay:%f,ahSoc:%d,battcurr:%f,sfmd_I_curr:%d\n",ahDelay,ahSoc,battcurr,sfmd_I_curr);
     //======================================================================
     ///////////////////////estSOC//////////////////////////////////////////
     //======================================================================
-    if (!socn_flg_ekfInvalid)
+    if(!socn_flg_ekfInvalid)
     {
-        ekfInvalidCntl = (ekfInvalidCntl + 1) > 250 ? 250 : (ekfInvalidCntl + 1);
+        ekfInvalidCntl = (ekfInvalidCntl + 1) > 250 ? 250 :(ekfInvalidCntl + 1);
     }
     else
     {
         ekfInvalidCntl = 0;
     }
-
+    
     if (ekfInvalidCntl < 200)
     {
         if (onceFlg_est)
         {
-            ahSoc0_est = ahSoc;
+            ahSoc0_est  = ahSoc;
             ekfSoc0_est = socd_pct_ekfSoc;
-            onceFlg_est = false;
+			onceFlg_est = false;
         }
         socd_pct_estSoc = (int16_T)(ahSoc - ahSoc0_est + ekfSoc0_est) > 0 ? (uint16_T)(ahSoc - ahSoc0_est + ekfSoc0_est) : 0;
     }
     else
-    {
+    {   
         onceFlg_est = true;
         socd_pct_estSoc = socd_pct_ekfSoc;
     }
-
+	
     //
     if (socd_pct_estSoc > socc_pct_battSocUp)
     {
@@ -343,30 +348,30 @@ void SOC(void)
     {
         socd_pct_estSoc = socc_pct_battSocLow;
     }
-    //printf("6----ahSoc0_est:%d,ekfSoc0_est:%d,socd_pct_estSoc:%d\n",ahSoc0_est,ekfSoc0_est,socd_pct_estSoc);
+	//printf("6----ahSoc0_est:%d,ekfSoc0_est:%d,socd_pct_estSoc:%d\n",ahSoc0_est,ekfSoc0_est,socd_pct_estSoc);
     //======================================================================
     ////////////////////////UtrackSOC//////////////////////////////////////////
     //======================================================================
     if (ihd_st_workStat == 2)
     {
         disChrgCntl = 0;
-        chrgCntl = (chrgCntl + 1) > 250 ? 250 : (chrgCntl + 1);
-        lowCntl = 0;
-        lowFlg = false;
-        if (sfmd_V_cellUMax >= look1_is16lu16n16tu16_binlcase(sfmd_I_curr, (&(socm_I_chrgCor[0])), (&(socm_V_chrgCor[0])), 2U))
+		chrgCntl = (chrgCntl+1) > 250 ? 250 : (chrgCntl+1);
+		lowCntl = 0;
+        lowFlg  = false;
+        if(sfmd_V_cellUMax >= look1_is16lu16n16tu16_binlcase(sfmd_I_curr, (&(socm_I_chrgCor[0])),(&(socm_V_chrgCor[0])), 2U))
         {
             overCntl = (overCntl + 1) > 250 ? 250 : (overCntl + 1);
         }
         else
         {
-            overCntl = 0;
+            overCntl=0;
         }
-        if (overCntl > 20 || overFlg)
+        if(overCntl > 20 || overFlg)
         {
             overFlg = 1;
         }
         //
-        if (sfmd_V_cellUMax >= cmnc_V_chrgFulV)
+        if(sfmd_V_cellUMax >= cmnc_V_chrgFulV)
         {
             fulCntl = (fulCntl + 1) > 250 ? 250 : (fulCntl + 1);
         }
@@ -374,128 +379,129 @@ void SOC(void)
         {
             fulCntl = 0;
         }
-        if (fulCntl > 20 || fulFlg)
+        if(fulCntl > 20 || fulFlg)
         {
             fulFlg = 1;
         }
-
+        
         //
         if (overFlg)
         {
             if (onceFlg_utrckOver)
             {
                 onceFlg_utrckOver = false;
-                ahSoc0_utrckOver = ahSoc;
-                estSoc0_utrckOver = socd_pct_estSoc > socc_pct_chrgCor ? socd_pct_estSoc : socc_pct_chrgCor;
+                ahSoc0_utrckOver  = ahSoc;
+				estSoc0_utrckOver = socd_pct_estSoc > socc_pct_chrgCor ? socd_pct_estSoc : socc_pct_chrgCor;
             }
             socTemp = (uint16_T)(ahSoc - ahSoc0_utrckOver + estSoc0_utrckOver);
         }
-        else if (chrgCntl > 20)
-        {
+        else  if (chrgCntl > 20)
+        {   
             onceFlg_utrckOver = true;
             socTemp = socd_pct_estSoc > socc_pct_chrgCor ? socc_pct_chrgCor : socd_pct_estSoc;
         }
-        else
+		else
         {
             socTemp = socd_pct_estSoc;
         }
-        //
-        socn_pct_utrackSoc = Soc_Delay + (socTemp > Soc_Delay ? (socTemp - Soc_Delay) : 0);
+		// 
+        socn_pct_utrackSoc = Soc_Delay + (socTemp > Soc_Delay ?  (socTemp - Soc_Delay) : 0);
         Soc_Delay = socn_pct_utrackSoc;
-
+        
         if (fulFlg)
         {
             socn_pct_utrackSoc = socc_pct_battSocUp;
         }
         else
         {
-            socn_pct_utrackSoc = socn_pct_utrackSoc > (socc_pct_battSocUp - 1) ? (socc_pct_battSocUp - 1) : socn_pct_utrackSoc;
+           socn_pct_utrackSoc = socn_pct_utrackSoc > (socc_pct_battSocUp - 1) ? (socc_pct_battSocUp - 1) : socn_pct_utrackSoc;
         }
-
-        //printf("7----overCntl:%d,overFlg:%d,fulCntl:%d,fulFlg:%d,ahSoc0_utrckOver:%d,estSoc0_utrckOver:%d,socn_pct_utrackSoc:%d,socTemp:%d\n",overCntl,overFlg,fulCntl,fulFlg,ahSoc0_utrckOver,estSoc0_utrckOver,socn_pct_utrackSoc,socTemp);
+		
+		//printf("7----overCntl:%d,overFlg:%d,fulCntl:%d,fulFlg:%d,ahSoc0_utrckOver:%d,estSoc0_utrckOver:%d,socn_pct_utrackSoc:%d,socTemp:%d\n",overCntl,overFlg,fulCntl,fulFlg,ahSoc0_utrckOver,estSoc0_utrckOver,socn_pct_utrackSoc,socTemp);
     }
     else
-    {
+    {   
         chrgCntl = 0;
-        disChrgCntl = (disChrgCntl + 1) > 250 ? 250 : (disChrgCntl + 1);
+		disChrgCntl = (disChrgCntl + 1) > 250 ? 250 : (disChrgCntl + 1);
         Soc_Delay = 0;
         overCntl = 0;
-        overFlg = false;
-        fulFlg = false;
-        fulCntl = 0;
-        if (sfmd_V_cellUMin <= look1_is16lu16n16tu16_binlcase(sfmd_I_curr, (&(socm_I_disChrgCor[0])), (&(socm_V_disChrgCor[0])), 2U))
+        overFlg  = false;
+        fulFlg   = false;
+        fulCntl  = 0;
+        if(sfmd_V_cellUMin <= look1_is16lu16n16tu16_binlcase(sfmd_I_curr, (&(socm_I_disChrgCor[0])),(&(socm_V_disChrgCor[0])), 2U))
         {
             lowCntl = (lowCntl + 1) > 250 ? 250 : (lowCntl + 1);
         }
         else
         {
-            lowCntl = 0;
+            lowCntl=0;
         }
-        if (lowCntl > 20 || lowFlg)
+        if(lowCntl > 20 || lowFlg)
         {
             lowFlg = true;
         }
         //
         if (lowFlg)
         {
-            if (onceFlg_utrckLow)
+            if (onceFlg_utrckLow)	
             {
-                onceFlg_utrckLow = false;
-                ahSoc0_utrckLow = ahSoc;
-                estSoc0_utrckLow = socd_pct_estSoc < socc_pct_disChrgCor ? socd_pct_estSoc : socc_pct_disChrgCor;
+                onceFlg_utrckLow = false; 
+                ahSoc0_utrckLow  = ahSoc;
+				estSoc0_utrckLow = socd_pct_estSoc < socc_pct_disChrgCor ? socd_pct_estSoc : socc_pct_disChrgCor;
             }
-            socn_pct_utrackSoc = (int16_T)(ahSoc - ahSoc0_utrckLow + estSoc0_utrckLow) > 0 ? (uint16_T)(ahSoc - ahSoc0_utrckLow + estSoc0_utrckLow) : 0;
+            socn_pct_utrackSoc =  (int16_T)(ahSoc - ahSoc0_utrckLow + estSoc0_utrckLow) > 0 ? (uint16_T)(ahSoc - ahSoc0_utrckLow + estSoc0_utrckLow) : 0;
         }
-        else if (disChrgCntl > 20)
+        else if(disChrgCntl > 20)
         {
             onceFlg_utrckLow = true;
             socn_pct_utrackSoc = socd_pct_estSoc < socc_pct_disChrgCor ? socc_pct_disChrgCor : socd_pct_estSoc;
         }
-        else
-        {
-            socn_pct_utrackSoc = socd_pct_estSoc;
-        }
-        //printf("8----lowCntl:%d,lowFlg:%d,ahSoc0_utrckLow:%d,estSoc0_utrckLow:%d,socn_pct_utrackSoc:%d\n",lowCntl,lowFlg,ahSoc0_utrckLow,estSoc0_utrckLow,socn_pct_utrackSoc);
-    }
-    //===================================================================
-    //------------------EEsave
-    //==================================================================
-    socd_pct_battSoc = socn_pct_utrackSoc;
-    socd_pct_battSocEo = socn_pct_utrackSoc;
-    if ((int16_T)(socd_pct_battSoc - socd_pct_battSoc_Delay) > 10 || (int16_T)(socd_pct_battSoc - socd_pct_battSoc_Delay) < -10)
-    {
-        socd_flg_EEsave = 1;
-        socd_pct_battSoc_Delay = socd_pct_battSoc;
-    }
-    else
-    {
-        socd_flg_EEsave = 0;
-    }
-
-    //=====================================================================
+		else
+		{
+		    socn_pct_utrackSoc = socd_pct_estSoc;
+		}
+	// printf("8----lowCntl:%d,lowFlg:%d,ahSoc0_utrckLow:%d,estSoc0_utrckLow:%d,socn_pct_utrackSoc:%d\n",lowCntl,lowFlg,ahSoc0_utrckLow,estSoc0_utrckLow,socn_pct_utrackSoc);
+    }
+     //===================================================================
+     //------------------EEsave
+     //==================================================================
+     socd_pct_battSoc   = socn_pct_utrackSoc;
+     socd_pct_battSocEo = socn_pct_utrackSoc;
+     if ( (int16_T)(socd_pct_battSoc - socd_pct_battSoc_Delay) > 10 || (int16_T)(socd_pct_battSoc - socd_pct_battSoc_Delay) <- 10 )
+     {
+         socd_flg_EEsave =1;
+	     socd_pct_battSoc_Delay = socd_pct_battSoc;
+     }
+	 else
+	 {
+	     socd_flg_EEsave=0;
+	 }
+	 
+	//=====================================================================
     //////////////////////////////BCUSOC///////////////////////////////////
     //=====================================================================
 
-    if (sfmd_I_curr < 10 && sfmd_I_curr > -10)
+    if(sfmd_I_curr < 10 && sfmd_I_curr > -10)
     {
-        statCntl = (statCntl + 1) > 250 ? 250 : (statCntl + 1);
+        statCntl= (statCntl + 1) > 250 ? 250 :  (statCntl + 1);
     }
     else
     {
         statCntl = 0;
     }
     statFlg = statCntl > 20;
+	
+    Flg= (FirstRun_SOC || (ihd_st_chrgSta_Delay == 2 && ihd_st_workStat != 2) || (ihd_st_chrgSta_Delay!= 2 && ihd_st_workStat == 2)
+    || ((int16_T)(socn_pct_utrackSoc -socn_pct_utrackSoc_Delay) > 20 || (int16_T)(socn_pct_utrackSoc -socn_pct_utrackSoc_Delay) <- 20 ) || statFlg);
 
-    Flg = (FirstRun_SOC || (ihd_st_chrgSta_Delay == 2 && ihd_st_workStat != 2) || (ihd_st_chrgSta_Delay != 2 && ihd_st_workStat == 2) || ((int16_T)(socn_pct_utrackSoc - socn_pct_utrackSoc_Delay) > 20 || (int16_T)(socn_pct_utrackSoc - socn_pct_utrackSoc_Delay) < -20) || statFlg);
-
-    ihd_st_chrgSta_Delay = ihd_st_workStat;
+	ihd_st_chrgSta_Delay = ihd_st_workStat;
     socn_pct_utrackSoc_Delay = socn_pct_utrackSoc;
-
+	
     //
-    if (Flg)
+    if(Flg)
     {
         socd_pct_battSoc0 = socd_pct_battSoc;
-        if (FirstRun_SOC)
+        if(FirstRun_SOC)
         {
             socd_pct_bcuSoc0 = socn_pct_bcuSocEE;
         }
@@ -504,86 +510,85 @@ void SOC(void)
             socd_pct_bcuSoc0 = socd_pct_bcuSoc;
         }
     }
-
-    //printf("9----statCntl:%d,statFlg:%d,Flg:%d,socd_pct_bcuSoc0:%d,socd_pct_bcuSoc0:%d,Flg:%d\n",statCntl,statFlg,Flg,socd_pct_bcuSoc0,socd_pct_bcuSoc0,Flg);
+	
+	//printf("9----statCntl:%d,statFlg:%d,Flg:%d,socd_pct_bcuSoc0:%d,socd_pct_bcuSoc0:%d,Flg:%d\n",statCntl,statFlg,Flg,socd_pct_bcuSoc0,socd_pct_bcuSoc0,Flg);
     //
-    if (ihd_st_workStat == 2)
-    {
-        delSOC = socd_pct_battSoc0 > socd_pct_bcuSoc0 ? (socd_pct_battSoc0 - socd_pct_bcuSoc0) : (socd_pct_bcuSoc0 - socd_pct_battSoc0);
-        coinSoc = (socd_pct_battSoc0 > socd_pct_bcuSoc0 ? socd_pct_battSoc0 : socd_pct_bcuSoc0) + (delSOC > 50 ? 50 : delSOC);
-
-        x[0] = socd_pct_battSoc0;
-        x[1] = coinSoc > socc_pct_battSocUp ? socc_pct_battSocUp : (uint16_T)coinSoc;
-        x[2] = socc_pct_battSocUp;
-
-        y[0] = socd_pct_bcuSoc0;
-        y[1] = coinSoc > 1000 ? 1000 : (uint16_T)coinSoc;
-        y[2] = 1000;
-        bcuSoc = SOC_LookUp(socd_pct_battSoc, &x[0], &y[0]);
-
-        //
+    if(ihd_st_workStat == 2)
+    {
+        delSOC  =  socd_pct_battSoc0 > socd_pct_bcuSoc0 ? (socd_pct_battSoc0 - socd_pct_bcuSoc0) : (socd_pct_bcuSoc0 - socd_pct_battSoc0);
+        coinSoc = (socd_pct_battSoc0 > socd_pct_bcuSoc0 ?  socd_pct_battSoc0 : socd_pct_bcuSoc0) + (delSOC > 50 ? 50 : delSOC);
+		
+		x[0] = socd_pct_battSoc0;
+		x[1] = coinSoc > socc_pct_battSocUp ? socc_pct_battSocUp : (uint16_T)coinSoc;
+		x[2] = socc_pct_battSocUp;
+		
+		y[0] = socd_pct_bcuSoc0;
+		y[1] = coinSoc > 1000 ? 1000 : (uint16_T)coinSoc;
+		y[2] = 1000;
+        bcuSoc = SOC_LookUp( socd_pct_battSoc, &x[0], &y[0]);
+
+		//
         if (onceFlg_chrg)
         {
-            onceFlg_chrg = false;
+            onceFlg_chrg =false;
             onceFlg_dischrg = true;
-            socd_pct_bcuSoc = 2000;
+            socd_pct_bcuSoc = 2000;	
         }
-        socd_pct_bcuSoc = SOCfitSystem(bcuSoc, &socd_pct_bcuSoc, 1);
-
+        socd_pct_bcuSoc = SOCfitSystem(bcuSoc,&socd_pct_bcuSoc, 1);
+		
         //
         if (fulFlg)
         {
-            socd_pct_bcuSoc = socc_pct_battSocUp;
+            socd_pct_bcuSoc =socc_pct_battSocUp;
         }
         else
         {
-            socd_pct_bcuSoc = socd_pct_bcuSoc > socc_pct_battSocUp - 1 ? socc_pct_battSocUp - 1 : socd_pct_bcuSoc;
+            socd_pct_bcuSoc = socd_pct_bcuSoc > (socc_pct_battSocUp - 1) ? (socc_pct_battSocUp - 1) : socd_pct_bcuSoc;
         }
-        //printf("10-----x:[%d-%d-%d],y:[%d-%d-%d],bcusoc:%d,socd_pct_bcuSoc:%d\n",x[0],x[1],x[2],y[0],y[1],y[2],bcuSoc,socd_pct_bcuSoc);
+		//printf("10-----x:[%d-%d-%d],y:[%d-%d-%d],bcusoc:%d,socd_pct_bcuSoc:%d\n",x[0],x[1],x[2],y[0],y[1],y[2],bcuSoc,socd_pct_bcuSoc);
     }
     else
     {
         //
         delSOC = socd_pct_battSoc0 > socd_pct_bcuSoc0 ? (socd_pct_battSoc0 - socd_pct_bcuSoc0) : (socd_pct_bcuSoc0 - socd_pct_battSoc0);
-        coinSoc = (int16_T)((socd_pct_battSoc0 < socd_pct_bcuSoc0 ? socd_pct_battSoc0 : socd_pct_bcuSoc0) - (delSOC > 50 ? 50 : delSOC));
-
-        x[0] = socc_pct_battSocLow;
-        x[1] = coinSoc > socc_pct_battSocLow ? (uint16_T)coinSoc : socc_pct_battSocLow;
-        x[2] = socd_pct_battSoc0;
-        y[0] = 0;
-        y[1] = coinSoc > 0 ? (uint16_T)coinSoc : 0;
-        y[2] = socd_pct_bcuSoc0;
-        bcuSoc = SOC_LookUp(socd_pct_battSoc, &x[0], &y[0]);
-
-        //
-        if (onceFlg_dischrg)
+        coinSoc =(int16_T)((socd_pct_battSoc0 < socd_pct_bcuSoc0 ? socd_pct_battSoc0 : socd_pct_bcuSoc0) - (delSOC > 50 ? 50 : delSOC));
+        
+      	x[0] = socc_pct_battSocLow;
+		x[1] = coinSoc > socc_pct_battSocLow ? (uint16_T)coinSoc : socc_pct_battSocLow;
+		x[2] = socd_pct_battSoc0;
+		y[0] = 0;
+		y[1] = coinSoc > 0 ? (uint16_T)coinSoc : 0;
+		y[2] = socd_pct_bcuSoc0;
+        bcuSoc = SOC_LookUp( socd_pct_battSoc,  &x[0], &y[0]);
+		
+		//
+		if (onceFlg_dischrg)
         {
             onceFlg_chrg = true;
             onceFlg_dischrg = false;
             socd_pct_bcuSoc = 2000;
         }
-
-        socd_pct_bcuSoc = SOCfitSystem(bcuSoc, &socd_pct_bcuSoc, 1);
-        //printf("11-----x:[%d-%d-%d],y:[%d-%d-%d],bcusoc:%d,socd_pct_bcuSoc:%d\n",x[0],x[1],x[2],y[0],y[1],y[2],bcuSoc,socd_pct_bcuSoc);
+        
+		socd_pct_bcuSoc = SOCfitSystem(bcuSoc,&socd_pct_bcuSoc, 1);
+		//printf("11-----x:[%d-%d-%d],y:[%d-%d-%d],bcusoc:%d,socd_pct_bcuSoc:%d\n",x[0],x[1],x[2],y[0],y[1],y[2],bcuSoc,socd_pct_bcuSoc);
+	    
     }
     //
     socd_pct_bcuSocEo = socd_pct_bcuSoc;
-    FirstRun_SOC = false;
+    FirstRun_SOC= false;
     //printf("\n");
 }
 
+
 //-------------------------------------------------------------------------
 real_T docvmath(real_T soc)
-{
+{   
     real_T docv;
     docv = ((((((-2.8104E-13 * pow(soc, 7.0) + 1.0283E-10 * pow(soc, 6.0)) +
-                -1.5072E-8 * pow(soc, 5.0)) +
-               1.1295E-6 * pow(soc, 4.0)) +
-              -4.588E-5 * pow(soc, 3.0)) +
-             soc * soc * 0.000993) +
-            -0.010548 * soc) +
-           0.04876;
-    return docv;
+            -1.5072E-8 * pow(soc, 5.0)) + 1.1295E-6 * pow(soc, 4.0)) +
+            -4.588E-5 * pow(soc, 3.0)) + soc * soc * 0.000993) +
+            -0.010548 * soc) + 0.04876;
+	return docv;
 }
 ////
 uint16_T SOC_LookUp(uint16_T battsoc, uint16_T x[3], uint16_T y[3])
@@ -593,42 +598,42 @@ uint16_T SOC_LookUp(uint16_T battsoc, uint16_T x[3], uint16_T y[3])
     {
         bcusoc = y[0];
     }
-    //
+	//
     if (battsoc >= x[2])
     {
         bcusoc = y[2];
     }
-    //
-    if (battsoc > x[0] && battsoc < x[1]) //(x-x0)*(y1-y0)/(x1-x0)+y0
+	//
+    if (battsoc > x[0] && battsoc < x[1])   //(x-x0)*(y1-y0)/(x1-x0)+y0
     {
 
-        bcusoc = (uint16_T)((real_T)((battsoc - x[0]) * 0.1) * (real_T)((y[1] - y[0]) * 0.1) / (real_T)((x[1] - x[0]) * 0.1) * 10) + y[0];
-    }
-    //
+	   bcusoc =   (uint16_T) ((real_T)((battsoc - x[0]) * 0.1) * (real_T)((y[1] - y[0]) * 0.1) /(real_T)((x[1] - x[0]) * 0.1) * 10)+ y[0];
+	}
+	//
     if (battsoc >= x[1] && battsoc < x[2]) //(x-x1)*(y2-y1)/(x2-x1)+y1
     {
-        bcusoc = (uint16_T)((real_T)((battsoc - x[1]) * 0.1) * (real_T)((y[2] - y[1]) * 0.1) / (real_T)((x[2] - x[1]) * 0.1) * 10) + y[1];
+       bcusoc =   (uint16_T) ((real_T)((battsoc - x[1]) * 0.1) * (real_T)((y[2] - y[1]) * 0.1) /(real_T)((x[2] - x[1]) * 0.1) * 10)+ y[1];
     }
-    return bcusoc;
+	return bcusoc;
 }
 //-------------------------------------------------------------------------
 
-uint16_T SOCfitSystem(uint16_T SOC, uint16_T *SOCfit, uint16_T m)
+uint16_T SOCfitSystem(uint16_T SOC,uint16_T *SOCfit, uint16_T m)
 {
     int16_T socdelt;
-    socdelt = (int16_T)(SOC - *SOCfit);
-    if (socdelt > m)
+	socdelt = (int16_T)(SOC - *SOCfit);
+	if( socdelt > m)
     {
         *SOCfit = *SOCfit + (socdelt > m ? m : socdelt);
     }
-    if (socdelt < -m && socdelt > -1000)
-    {
-        *SOCfit = *SOCfit + (socdelt < -m ? -m : socdelt);
-    }
-    if ((socdelt <= m && socdelt >= -m) || socdelt <= -1000)
-    {
-        *SOCfit = SOC;
-    }
+	if(socdelt <- m && socdelt > -1000)
+	{
+	    *SOCfit = *SOCfit + (socdelt < -m ? -m : socdelt);
+	}
+	if((socdelt <= m && socdelt >= -m) || socdelt <= -1000)
+	{
+	    *SOCfit = SOC;
+	}
 
     return *SOCfit;
 }

+ 14 - 12
src/EmbeddedCoder_src/SOH.c

@@ -54,6 +54,9 @@ void SOH(void)
         Ahincr = 0;
         ihd_st_workStat_Delay = 0;
         sohn_flg_chrgEnd_Delay = false;
+		memset(sohv_V_chrgStartStatEo,0, sizeof(sohv_V_chrgStartStatEo));
+		sohd_Q_chrgEo = 0 ;
+		sohd_flg_chrgEndEo = false;
     }
 	
     if(FirstRun_SOH)
@@ -65,7 +68,7 @@ void SOH(void)
         ArrMax((&(sohv_Q_cellCapArrEi[0])), &cellCapArr_Max , cmnc_num_cellUNum);
         ArrMin((&(sohv_Q_packCapArrEi[0])), &packCapArr_Min , 10);
         ArrMax((&(sohv_Q_packCapArrEi[0])), &packCapArr_Max , 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 )
+        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++)
@@ -77,9 +80,9 @@ void SOH(void)
 			   sohn_Q_packCapArrEE[i] = cmnc_Q_ratedCp;
 			}
    
-            sohn_Q_chrgEE =0;
-            sohn_tm_chrgStartStatEE =0;
-            sohn_flg_chrgEndEE =0;
+            sohn_Q_chrgEE = 0;
+            sohn_tm_chrgStartStatEE = 0;
+            sohn_flg_chrgEndEE = 0;
         }
         else
         {
@@ -115,7 +118,7 @@ void SOH(void)
                 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);
 				
-                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;
@@ -128,9 +131,9 @@ void SOH(void)
 				for(i = 0;i < cmnc_num_cellUNum;i++)
  				{
  				     temp[i] = (real_T) (soc2[i] * 0.1) /100;
-                     chrgCellCapArr[i] =    (uint16_T)( (real_T)(sohv_Q_cellCapArrEo[i] * 0.1)*(1-temp[i]) *10);
-                     disChrgCellCapArr[i] = (uint16_T)( (real_T)(sohv_Q_cellCapArrEo[i] * 0.1)*(  temp[i]) *10);
- 				}
+                     chrgCellCapArr[i] =    (uint16_T)( (real_T)(sohv_Q_cellCapArrEo[i] * 0.1)*(1 - temp[i]) * 10);
+                     disChrgCellCapArr[i] = (uint16_T)( (real_T)(sohv_Q_cellCapArrEo[i] * 0.1)*(    temp[i]) * 10);
+ 				} 
                  ArrMin((&(chrgCellCapArr[0])), &chrgCap_Min , cmnc_num_cellUNum);
                  ArrMin((&(disChrgCellCapArr[0])), &disChrgCap_Min , cmnc_num_cellUNum);
                  for(i = 0; i < 9;i++)
@@ -185,15 +188,14 @@ void SOH(void)
     if(ihd_st_workStat == 2)
     {
         Ahincr = Ahincr + (real_T)sfmd_I_curr * 0.1;
-        tmp_0 = (int16_T)(Ahincr/36000 *10);
+        tmp_0 = (int16_T)(Ahincr/36000 * 10);
 		
-        sohd_Q_chrgEo =(tmp_0 > 0 ? (uint16_T)tmp_0 : 0);  
+        sohd_Q_chrgEo = tmp_0 > 0 ? (uint16_T)tmp_0 : 0;  
         if(sfmd_flg_currDisable)
         {
             sfmn_flg_currFlt_keep = true;
         }
-        sohn_flg_currFlt = sfmn_flg_currFlt_keep;
-        
+        sohn_flg_currFlt = sfmn_flg_currFlt_keep;   
     }
     else
     {

+ 11 - 14
src/EmbeddedCoder_src/SPM.c

@@ -1,14 +1,6 @@
-/*
- * @Author       : QTF
- * @Date         : 2021-10-14 09:22:10
- * @Version      : V3.0
- * @LastEditors  : ChenJie
- * @LastEditTime : 2021-10-14 16:50:54
- * @Description  : file content
- * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\EmbeddedCoder_src\SPM.c
- */
 #include "SPM.h"
 
+
 boolean_T FirstRun_SPM;
 
 void SPM_Init(void)
@@ -19,6 +11,7 @@ void SPM_Init(void)
   FirstRun_SPM = true;
 }
 
+
 void SPM(void)
 {
 
@@ -33,7 +26,7 @@ void SPM(void)
   spmd_Nr_cellNr = spmd_Nr_cellNr + 1;
   if (spmd_Nr_cellNr % (10 * Feq) == 0)
   {
-    cand_Nr_cellNr++;
+    cand_Nr_cellNr ++;
   }
   else if (spmd_Nr_cellNr > 60000)
   {
@@ -44,6 +37,7 @@ void SPM(void)
     cand_Nr_cellNr = 1;
   }
 
+  
   SOH();
   BLC();
   if (!ihd_flg_urtRecFlt)
@@ -51,9 +45,12 @@ void SPM(void)
     SOC();
   }
 
-  cand_Q_cellCap = sohv_Q_cellCapArrEo[cand_Nr_cellNr - 1];
-  cand_V_chrgStartStat = sohv_V_chrgStartStatEo[cand_Nr_cellNr - 1];
-  cand_Q_reqCp = blcv_Q_reqCpEo[cand_Nr_cellNr - 1];
-  cand_Q_totalCp = blcv_Q_totalCpEo[cand_Nr_cellNr - 1];
+  
+  cand_Q_cellCap = sohv_Q_cellCapArrEo[cand_Nr_cellNr-1];
+  cand_V_chrgStartStat = sohv_V_chrgStartStatEo[cand_Nr_cellNr-1];
+  cand_Q_reqCp   = blcv_Q_reqCpEo[cand_Nr_cellNr-1];
+  cand_Q_totalCp = blcv_Q_totalCpEo[cand_Nr_cellNr-1];
   FirstRun_SPM = false;
 }
+
+

+ 21 - 27
src/EmbeddedCoder_src/TMS.c

@@ -1,18 +1,10 @@
-/*
- * @Author       : ChenJie
- * @Date         : 2021-10-14 11:29:45
- * @Version      : V3.0
- * @LastEditors  : ChenJie
- * @LastEditTime : 2021-10-14 15:53:09
- * @Description  : file content
- * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\EmbeddedCoder_src\TMS.c
- */
 #include "TMS.h"
 
+
 boolean_T FirstRun_TMS;
 void TMS_Init(void)
 {
-    FirstRun_TMS = true;
+    FirstRun_TMS =true;
 }
 
 void TMS(void)
@@ -20,7 +12,7 @@ void TMS(void)
     static uint8_T TminLowNr;
     static uint8_T TminOverNr;
     static uint8_T TmaxOverNr;
-
+    
     //初始值
     if (FirstRun_TMS)
     {
@@ -29,11 +21,11 @@ void TMS(void)
         TminOverNr = 0;
         TmaxOverNr = 0;
     }
-
+    
     //
     if (sfmd_T_modTMin < tmsc_T_openThr)
     {
-        TminLowNr = ((TminLowNr + 1) > 200 ? 200 : (TminLowNr + 1));
+        TminLowNr = (TminLowNr + 1) > 200 ? 200 : (TminLowNr + 1);
     }
     else
     {
@@ -42,7 +34,7 @@ void TMS(void)
     //
     if (sfmd_T_modTMin >= tmsc_T_closeMinThr)
     {
-        TminOverNr = ((TminOverNr + 1) > 200 ? 200 : (TminOverNr + 1));
+        TminOverNr = (TminOverNr + 1) > 200 ? 200 : (TminOverNr + 1);
     }
     else
     {
@@ -51,44 +43,46 @@ void TMS(void)
     //
     if (sfmd_T_modTMax >= tmsc_T_closeMaxThr)
     {
-        TmaxOverNr = ((TmaxOverNr + 1) > 200 ? 200 : (TmaxOverNr + 1));
+        TmaxOverNr = (TmaxOverNr + 1) > 200 ? 200 : (TmaxOverNr + 1);
     }
     else
     {
         TmaxOverNr = 0;
     }
-
+    
     //================================温度判定 开关热管理状态===============================
     if (tmsd_st_heatAct == 0)
     {
-        if (TminLowNr >= 20 && ((ihd_st_chrgConnect == 0 && socd_pct_battSoc > 100) || ihd_st_chrgConnect == 1))
+        if(TminLowNr >= 20 && ((ihd_st_chrgConnect == 0 && socd_pct_battSoc > 100) || ihd_st_chrgConnect == 1))
         {
             tmsd_st_heatAct = 1;
         }
     }
     else
     {
-        if (TmaxOverNr >= 20 || TminOverNr >= 20 || (ihd_st_chrgConnect == 0 && socd_pct_battSoc < 50))
+        if(TmaxOverNr >= 20 || TminOverNr >= 20 || (ihd_st_chrgConnect == 0 && socd_pct_battSoc < 50))
         {
             tmsd_st_heatAct = 0;
         }
     }
-
+	 
     //因故障关闭热管理
-    if (((sfmd_st_fltAct >> 4) & 0x01) == 1)
-    {
-        tmsd_st_heatAct = 0;
-    }
-
+	if (((sfmd_st_fltAct >> 4) & 0x01) == 1)
+	{
+	    tmsd_st_heatAct = 0;
+	}
+	
     //强制控制加热回路
-    if (HeatForceControl == 1)
+    if(HeatForceControl == 1)
     {
         tmsd_st_heatAct = 1;
     }
-    if (HeatForceControl == 2)
+    if(HeatForceControl == 2)
     {
         tmsd_st_heatAct = 0;
     }
-
+        
     FirstRun_TMS = false;
+	//printf("TminLowNr:%d,TmaxOverNr:%d,TminOverNr:%d,ihd_st_chrgConnect:%d,socd_pct_battSoc:%d,sfmd_st_fltAct:%d,HeatForceControl:%d,tmsd_st_heatAct:%d\n",TminLowNr,TmaxOverNr,TminOverNr,ihd_st_chrgConnect,socd_pct_battSoc,sfmd_st_fltAct,HeatForceControl,tmsd_st_heatAct);
+
 }

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است