Browse Source

代码优化

LAPTOP-EG88H5BE\86151 3 years ago
parent
commit
0df1846367

+ 1 - 2
ARMCC/Makefile

@@ -38,8 +38,7 @@ obj-y             += PLAT/project/$(TARGET)/apps/qx_app/src/app.o \
 						PLAT/project/$(TARGET)/apps/qx_app/src/EmbeddedCoder_src/SOE.o \
 						PLAT/project/$(TARGET)/apps/qx_app/src/EmbeddedCoder_src/SOR.o \
 						PLAT/project/$(TARGET)/apps/qx_app/src/EmbeddedCoder_src/PIM.o \
-						PLAT/project/$(TARGET)/apps/qx_app/src/EmbeddedCoder_src/look1_is16lu16n16tu16_binlcase.o \
-						PLAT/project/$(TARGET)/apps/qx_app/src/EmbeddedCoder_src/look1_iu16lu16n16tu16_binlcase.o \
+						PLAT/project/$(TARGET)/apps/qx_app/src/EmbeddedCoder_src/funlib.o \
 						PLAT/project/$(TARGET)/apps/qx_app/src/EmbeddedCoder_src/BCUCal.o \
 						PLAT/project/$(TARGET)/apps/qx_app/src/EmbeddedCoder_src/BCUDisp.o 
 include $(TOP)/PLAT/tools/scripts/Makefile.rules 

+ 3 - 3
inc/EmbeddedCoder_inc/BCUCal.h

@@ -95,9 +95,9 @@ extern const uint16_T socm_V_disChrgCor[3]; /* 放电CCV对应的电压; */
 extern const uint16_T socc_pct_chrgCor;
 extern const uint16_T socc_pct_disChrgCor;
 
-extern const int16_T cmm_T_ChrgCurr[3];
-extern const int16_T cmm_V_ChrgCurr[6];
-extern const int16_T cmm_I_ChrgCurr[3][6];
+extern const uint16_T cmm_T_ChrgCurr[3];
+extern const uint16_T cmm_V_ChrgCurr[6];
+extern const uint16_T cmm_I_ChrgCurr[18];
 
 extern const uint16_T tmsc_T_openThr;     /* 热管理开启温度; */
 extern const uint16_T tmsc_T_closeMinThr; /* 热管理关闭温度(最低模组); */

+ 1 - 1
inc/EmbeddedCoder_inc/BCUDisp.h

@@ -156,6 +156,6 @@ extern uint16_T pimd_F_polar;
 extern uint16_T test_cellCap[cmnc_num_cellUNumMax];
 extern uint16_T test_countEn;
 
-extern real_T test_Data[614][2];
+
 
 

+ 1 - 1
inc/EmbeddedCoder_inc/BLC.h

@@ -1,7 +1,7 @@
 #include "rtwtypes.h"
 #include "BCUCal.h"
 #include "BCUDisp.h"
-
+#include "funlib.h"
 extern boolean_T FirstRun_BLC;
 extern void BLC_Init(void);
 extern void BLC(void);

+ 2 - 0
inc/EmbeddedCoder_inc/CDM.h

@@ -1,6 +1,8 @@
 #include "rtwtypes.h"
 #include "BCUCal.h"
 #include "BCUDisp.h"
+#include "funlib.h"
+
 extern boolean_T FirstRun_CDM;
 
 extern void CDM_Init(void);

+ 2 - 2
inc/EmbeddedCoder_inc/CM.h

@@ -2,10 +2,10 @@
 #include "BCUCal.h"
 #include "BCUDisp.h"
 #include "numeric.h"
+#include "funlib.h"
 
 extern boolean_T FirstRun_CM;
 extern void CM_Init(void);
 extern void CM(void);
 
-//extern boolean_T JudgeTimeSystem(boolean_T Enable,boolean_T Input, uint8_T *N,uint8_T Thr);
-extern int16_T lookupChrgCurr(int16_T X,int16_T Y,uint16_T xN,uint16_T yN);
+

+ 1 - 1
inc/EmbeddedCoder_inc/ISC.h

@@ -1,8 +1,8 @@
 #include <math.h>
 #include "BCUCal.h"
 #include "BCUDisp.h"
+#include "funlib.h"
 extern boolean_T FirstRun_ISC;
 extern void ISC_Init(void);
 extern void ISC(void);
 
-extern int16_T ArrMean(int16_T *Data, uint16_T m);

+ 2 - 0
inc/EmbeddedCoder_inc/PIM.h

@@ -2,6 +2,8 @@
 #include <math.h>
 #include "BCUCal.h"
 #include "BCUDisp.h"
+#include "funlib.h"
+
 extern boolean_T FirstRun_PIM;
 
 extern void PIM_Init(void);

+ 116 - 116
inc/EmbeddedCoder_inc/SFM.h

@@ -1,116 +1,116 @@
-#include "rtwtypes.h"
-#include "BCUCal.h"
-#include "BCUDisp.h"
-#include <math.h>
-extern boolean_T FirstRun_SFM;
-
-extern void SFM_Init(void);
-extern void SFM(void);
-
-typedef struct
-{
-    uint8_T fltNum81;
-    uint8_T recNum81;
-    uint8_T fltNum82;
-    uint8_T recNum82;
-    uint8_T fltNum83;
-    uint8_T recNum83;
-    uint8_T fltNum84;
-    uint8_T recNum84;
-    uint8_T fltNum85;
-    uint8_T recNum85;
-    uint8_T fltNum86;
-    uint8_T recNum86;
-    uint8_T fltNum87;
-    uint8_T recNum87;
-    uint8_T fltNum88;
-    uint8_T recNum88;
-    uint8_T fltNum89;
-    uint8_T recNum89;
-    uint8_T fltNum90;
-    uint8_T recNum90;
-    uint8_T fltNum97;
-    uint8_T recNum97;
-    uint8_T fltNum98;
-    uint8_T recNum98;
-    uint8_T fltNum99;
-    uint8_T recNum99;
-    uint8_T fltNum100;
-    uint8_T recNum100;
-    uint8_T fltNum101;
-    uint8_T recNum101;
-    uint8_T fltNum102;
-    uint8_T recNum102;
-    uint8_T fltNum103;
-    uint8_T recNum103;
-    uint8_T fltNum104;
-    uint8_T recNum104;
-    uint8_T fltNum105;
-    uint8_T recNum105;
-    uint8_T fltNum106;
-    uint8_T recNum106;
-    uint8_T fltNum107;
-    uint8_T recNum107;
-    uint8_T fltNum108;
-    uint8_T recNum108;
-    uint8_T fltNum109;
-    uint8_T recNum109;
-    uint8_T fltNum110;
-    uint8_T recNum110;
-    uint8_T fltNum111;
-    uint8_T recNum111;
-    uint8_T fltNum112;
-    uint8_T recNum112;
-    uint8_T fltNum113;
-    uint8_T recNum113;
-    uint8_T fltNum114;
-    uint8_T recNum114;
-    uint8_T fltNum115_1;
-    uint8_T recNum115_1;
-    uint8_T fltNum115_2;
-    uint8_T recNum115_2;
-    uint8_T fltNum116_1;
-    uint8_T recNum116_1;
-    uint8_T fltNum116_2;
-    uint8_T recNum116_2;
-    uint8_T fltNum131;
-    uint8_T recNum131;
-    uint8_T fltNum132;
-    uint8_T recNum132;
-} DiagThrstruct;
-
-typedef struct
-{
-    uint16_T N22;
-    uint16_T N24;
-    uint16_T N32;
-    uint16_T N33;
-    uint16_T N34;
-    uint16_T N54;
-    uint16_T N56;
-    uint16_T N57;
-    uint16_T N58;
-    uint16_T N59;
-    uint16_T N62;
-    uint16_T N64;
-    uint16_T N65;
-    uint16_T N66;
-    uint16_T N67;
-    uint16_T N151;
-    uint16_T N152;
-    uint16_T N153;
-    uint16_T N154;
-    uint16_T N155;
-    uint16_T N156;
-    uint16_T N157;
-    uint16_T N158;
-    uint16_T N159;
-    uint16_T N160;
-    uint16_T N161;
-    uint16_T N162;
-    uint16_T N179;
-} DiagTimestruct;
-
-extern boolean_T DiagThrSystem1(boolean_T Enable, boolean_T precondition, uint16_T Input, uint16_T fltThr, uint16_T recThr, uint8_T fltNumThr, uint8_T recNumThr, uint8_T *fltNum, uint8_T *recNum, boolean_T *fitFlg);
-extern boolean_T DiagThrSystem2(boolean_T Enable, boolean_T precondition, uint16_T Input, uint16_T fltThr, uint16_T recThr, uint8_T fltNumThr, uint8_T recNumThr, uint8_T *fltNum, uint8_T *recNum, boolean_T *fitFlg);
-extern boolean_T JudgeTimeSystem(boolean_T Enable, boolean_T Input, uint16_T *N, uint16_T Thr);

+#include "rtwtypes.h"
+#include "BCUCal.h"
+#include "BCUDisp.h"
+#include <math.h>
+#include "funlib.h"
+
+extern boolean_T FirstRun_SFM;
+
+extern void SFM_Init(void);
+extern void SFM(void);
+
+typedef struct
+{
+    uint8_T fltNum81;
+    uint8_T recNum81;
+    uint8_T fltNum82;
+    uint8_T recNum82;
+    uint8_T fltNum83;
+    uint8_T recNum83;
+    uint8_T fltNum84;
+    uint8_T recNum84;
+    uint8_T fltNum85;
+    uint8_T recNum85;
+    uint8_T fltNum86;
+    uint8_T recNum86;
+    uint8_T fltNum87;
+    uint8_T recNum87;
+    uint8_T fltNum88;
+    uint8_T recNum88;
+    uint8_T fltNum89;
+    uint8_T recNum89;
+    uint8_T fltNum90;
+    uint8_T recNum90;
+    uint8_T fltNum97;
+    uint8_T recNum97;
+    uint8_T fltNum98;
+    uint8_T recNum98;
+    uint8_T fltNum99;
+    uint8_T recNum99;
+    uint8_T fltNum100;
+    uint8_T recNum100;
+    uint8_T fltNum101;
+    uint8_T recNum101;
+    uint8_T fltNum102;
+    uint8_T recNum102;
+    uint8_T fltNum103;
+    uint8_T recNum103;
+    uint8_T fltNum104;
+    uint8_T recNum104;
+    uint8_T fltNum105;
+    uint8_T recNum105;
+    uint8_T fltNum106;
+    uint8_T recNum106;
+    uint8_T fltNum107;
+    uint8_T recNum107;
+    uint8_T fltNum108;
+    uint8_T recNum108;
+    uint8_T fltNum109;
+    uint8_T recNum109;
+    uint8_T fltNum110;
+    uint8_T recNum110;
+    uint8_T fltNum111;
+    uint8_T recNum111;
+    uint8_T fltNum112;
+    uint8_T recNum112;
+    uint8_T fltNum113;
+    uint8_T recNum113;
+    uint8_T fltNum114;
+    uint8_T recNum114;
+    uint8_T fltNum115_1;
+    uint8_T recNum115_1;
+    uint8_T fltNum115_2;
+    uint8_T recNum115_2;
+    uint8_T fltNum116_1;
+    uint8_T recNum116_1;
+    uint8_T fltNum116_2;
+    uint8_T recNum116_2;
+    uint8_T fltNum131;
+    uint8_T recNum131;
+    uint8_T fltNum132;
+    uint8_T recNum132;
+} DiagThrstruct;
+
+typedef struct
+{
+    uint16_T N22;
+    uint16_T N24;
+    uint16_T N32;
+    uint16_T N33;
+    uint16_T N34;
+    uint16_T N54;
+    uint16_T N56;
+    uint16_T N57;
+    uint16_T N58;
+    uint16_T N59;
+    uint16_T N62;
+    uint16_T N64;
+    uint16_T N65;
+    uint16_T N66;
+    uint16_T N67;
+    uint16_T N151;
+    uint16_T N152;
+    uint16_T N153;
+    uint16_T N154;
+    uint16_T N155;
+    uint16_T N156;
+    uint16_T N157;
+    uint16_T N158;
+    uint16_T N159;
+    uint16_T N160;
+    uint16_T N161;
+    uint16_T N162;
+    uint16_T N179;
+} DiagTimestruct;
+
+

+ 2 - 0
inc/EmbeddedCoder_inc/SOC.h

@@ -3,6 +3,8 @@
 #include <numeric.h>
 #include "BCUCal.h"
 #include "BCUDisp.h"
+#include "funlib.h"
+
 extern boolean_T FirstRun_SOC;
 extern void SOC_Init(void);
 extern void SOC(void);

+ 1 - 1
inc/EmbeddedCoder_inc/SOE.h

@@ -1,6 +1,6 @@
 #include "BCUCal.h"
 #include "BCUDisp.h"
-
+#include "funlib.h"
 
 extern boolean_T FirstRun_SOE;
 extern void SOE_Init(void);

+ 3 - 2
inc/EmbeddedCoder_inc/SOH.h

@@ -1,8 +1,9 @@
 #include "BCUCal.h"
 #include "BCUDisp.h"
+#include "funlib.h"
+
 extern boolean_T FirstRun_SOH;
 extern void SOH_Init(void);
 extern void SOH(void);
 //
-extern uint16_T  ArrMax(uint16_T *Data, uint16_T m);
-extern uint16_T  ArrMin(uint16_T *Data, uint16_T m);
+

+ 19 - 0
inc/EmbeddedCoder_inc/funlib.h

@@ -0,0 +1,19 @@
+#include "rtwtypes.h"
+#include <math.h>
+
+extern uint16_T  ArrMax(uint16_T *Data, uint16_T m);
+extern uint16_T  ArrMin(uint16_T *Data, uint16_T m);
+extern int16_T ArrMean(int16_T *Data, uint16_T n);
+
+extern uint16_T  DataFilt(uint16_T in, uint16_T *out, uint16_T Lim);
+
+extern uint16_T look1_i16tu16(int16_T u0, const int16_T *bp0,  const uint16_T *table, uint16_T MaxLen);
+extern uint16_T look1_u16tu16(uint16_T u0, const uint16_T *bp0,  const uint16_T *table, uint16_T MaxLen);
+extern uint16_T look2_u16u16tu16(uint16_T x, uint16_T y, const uint16_T xTable[], const uint16_T yTable[], const uint16_T zTable[], uint16_T xLen, uint16_T yLen);
+
+extern boolean_T DiagThrSystem1(boolean_T Enable, boolean_T precondition, uint16_T Input, uint16_T fltThr, uint16_T recThr, uint8_T fltNumThr, uint8_T recNumThr, uint8_T *fltNum, uint8_T *recNum, boolean_T *fitFlg);
+extern boolean_T DiagThrSystem2(boolean_T Enable, boolean_T precondition, uint16_T Input, uint16_T fltThr, uint16_T recThr, uint8_T fltNumThr, uint8_T recNumThr, uint8_T *fltNum, uint8_T *recNum, boolean_T *fitFlg);
+extern boolean_T JudgeTimeSystem(boolean_T Enable, boolean_T Input, uint16_T *N, uint16_T Thr);

+
+
+

+ 0 - 24
inc/EmbeddedCoder_inc/look1_is16lu16n16tu16_binlcase.h

@@ -1,24 +0,0 @@
-/*
- * File: look1_is16lu16n16tu16_binlcase.h
- *
- * Code generated for Simulink model 'SOC'.
- *
- * Model version                  : 1.51
- * Simulink Coder version         : 9.4 (R2020b) 29-Jul-2020
- * C/C++ source code generated on : Thu Sep  9 17:18:48 2021
- */
-
-#ifndef RTW_HEADER_look1_is16lu16n16tu16_binlcase_h_
-#define RTW_HEADER_look1_is16lu16n16tu16_binlcase_h_
-#include "rtwtypes.h"
-
-extern uint16_T look1_is16lu16n16tu16_binlcase(int16_T u0, const int16_T bp0[],
-  const uint16_T table[], uint32_T maxIndex);
-
-#endif                        /* RTW_HEADER_look1_is16lu16n16tu16_binlcase_h_ */
-
-/*
- * File trailer for generated code.
- *
- * [EOF]
- */

+ 0 - 24
inc/EmbeddedCoder_inc/look1_iu16lu16n16tu16_binlcase.h

@@ -1,24 +0,0 @@
-/*
- * File: look1_iu16lu16n16tu16_binlcase.h
- *
- * Code generated for Simulink model 'BLC'.
- *
- * Model version                  : 1.50
- * Simulink Coder version         : 9.4 (R2020b) 29-Jul-2020
- * C/C++ source code generated on : Thu Sep  9 17:18:08 2021
- */
-
-#ifndef RTW_HEADER_look1_iu16lu16n16tu16_binlcase_h_
-#define RTW_HEADER_look1_iu16lu16n16tu16_binlcase_h_
-#include "rtwtypes.h"
-
-extern uint16_T look1_iu16lu16n16tu16_binlcase(uint16_T u0, const uint16_T bp0[],
-  const uint16_T table[], uint32_T maxIndex);
-
-#endif                        /* RTW_HEADER_look1_iu16lu16n16tu16_binlcase_h_ */
-
-/*
- * File trailer for generated code.
- *
- * [EOF]
- */

+ 5 - 3
src/EmbeddedCoder_src/BCUCal.c

@@ -102,9 +102,11 @@ const uint16_T socm_V_chrgCor[3] = {4160U, 4175U, 4188U};    /* 充电CCV对应
 const uint16_T socm_V_disChrgCor[3] = {3238U, 3319U, 3369U}; /* 放电CCV对应的电压; */
 const uint16_T socc_pct_chrgCor = 910;                       /* 充电CCV对应的SOC; */
 const uint16_T socc_pct_disChrgCor = 50;                     /* 放电CCV对应的SOC; */
-const int16_T cmm_T_ChrgCurr[3] = {40, 60, 80};
-const int16_T cmm_V_ChrgCurr[6] = {3200, 3201, 3900, 3901, 4100, 4101};
-const int16_T cmm_I_ChrgCurr[3][6] = {{0, 100, 100, 100, 100, 50}, {50, 400, 400, 200, 200, 100}, {40, 300, 300, 150, 150, 80}};
+const uint16_T cmm_T_ChrgCurr[3] = {40, 60, 80};
+const uint16_T cmm_V_ChrgCurr[6] = {3200, 3201, 3900, 3901, 4100, 4101};
+const uint16_T cmm_I_ChrgCurr[18] = {0, 100, 100, 100, 100, 50,
+ 	                                50, 400, 400, 200, 200, 100,
+	                                40, 300, 300, 150, 150, 80};
 
 const uint16_T tmsc_T_openThr = 45U;     /* 热管理开启温度; */
 const uint16_T tmsc_T_closeMinThr = 50U; /* 热管理关闭温度(最低模组); */

+ 2 - 3
src/EmbeddedCoder_src/BLC.c

@@ -1,5 +1,4 @@
 #include "BLC.h"
-#include "look1_iu16lu16n16tu16_binlcase.h"
 
 boolean_T FirstRun_BLC;
 ////////////////////////////////////////////////////////////////////////////
@@ -78,10 +77,10 @@ void BLC(void)
         //压差法
         if(blcn_flg_judge)
         {
-            blcn_pct_cellSocMin = look1_iu16lu16n16tu16_binlcase(sfmd_V_cellUMin,(&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
+            blcn_pct_cellSocMin = look1_u16tu16(sfmd_V_cellUMin,cmnm_V_ocv, cmnm_pct_soc, 13);
             for (i = 0; i < cmnc_num_cellUNum; i++)
             {
-                blcn_pct_cellSoc[i] = look1_iu16lu16n16tu16_binlcase(sfmv_V_cellU[i], ( &(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
+                blcn_pct_cellSoc[i] = look1_u16tu16(sfmv_V_cellU[i], cmnm_V_ocv, cmnm_pct_soc, 13);
             }
             for (i = 0; i < cmnc_num_cellUNum; i++)
             {

+ 9 - 84
src/EmbeddedCoder_src/CM.c

@@ -14,10 +14,10 @@ void CM(void)
     static boolean_T cmn_flg_chrgFul;
     static uint16_T chrgCnt;
     static uint16_T noChrgCnt;
-    int16_T cmd_I_chrgCurrReq1 = 0;
-    int16_T cmd_I_chrgCurrReq2 = 0;
-    int16_T cmd_I_chrgCurrReq3 = 0;
-    int16_T cmd_I_chrgCurrReq4 = 0;
+    uint16_T cmd_I_chrgCurrReq1 = 0;
+    uint16_T cmd_I_chrgCurrReq2 = 0;
+    uint16_T cmd_I_chrgCurrReq3 = 0;
+    uint16_T cmd_I_chrgCurrReq4 = 0;
 	static boolean_T First;
     static uint8_T cmd_st_chrgSt_end;
 	static boolean_T chrgFul;
@@ -57,10 +57,10 @@ void CM(void)
         {
             cmn_V_cellUMax = sfmd_V_cellUMax;
         }
-        cmd_I_chrgCurrReq1 = lookupChrgCurr((int16_T)sfmd_T_modTMin,(int16_T)cmn_V_cellUMin,3,6);
-        cmd_I_chrgCurrReq2 = lookupChrgCurr((int16_T)sfmd_T_modTMax,(int16_T)cmn_V_cellUMin,3,6);
-        cmd_I_chrgCurrReq3 = lookupChrgCurr((int16_T)sfmd_T_modTMin,(int16_T)cmn_V_cellUMax,3,6);
-        cmd_I_chrgCurrReq4 = lookupChrgCurr((int16_T)sfmd_T_modTMax,(int16_T)cmn_V_cellUMax,3,6);
+        cmd_I_chrgCurrReq1 = look2_u16u16tu16(cmn_V_cellUMin,sfmd_T_modTMin,cmm_V_ChrgCurr,cmm_T_ChrgCurr,cmm_I_ChrgCurr,6,3);
+        cmd_I_chrgCurrReq2 = look2_u16u16tu16(cmn_V_cellUMax,sfmd_T_modTMin,cmm_V_ChrgCurr,cmm_T_ChrgCurr,cmm_I_ChrgCurr,6,3);
+        cmd_I_chrgCurrReq3 = look2_u16u16tu16(cmn_V_cellUMin,sfmd_T_modTMax,cmm_V_ChrgCurr,cmm_T_ChrgCurr,cmm_I_ChrgCurr,6,3);
+        cmd_I_chrgCurrReq4 = look2_u16u16tu16(cmn_V_cellUMax,sfmd_T_modTMax,cmm_V_ChrgCurr,cmm_T_ChrgCurr,cmm_I_ChrgCurr,6,3);
 		cmd_I_chrgCurrReq =  min( min(cmd_I_chrgCurrReq1, cmd_I_chrgCurrReq2),min(cmd_I_chrgCurrReq3,cmd_I_chrgCurrReq4));
     }
     else
@@ -154,79 +154,4 @@ void CM(void)
 
 //==============================================================================================================================
 //==============================================================================================================================
-int16_T lookupChrgCurr(int16_T X,int16_T Y,uint16_T cmm_T_ChrgCurrN,uint16_T cmm_V_ChrgCurrN)
-{
-    int16_T Z;
-    int16_T temp1;
-    int16_T temp2;
-    uint16_T i;
-    uint16_T j;
-	
-    //===================================
-    if (X <= cmm_T_ChrgCurr[0])
-    {
-        if(Y <= cmm_V_ChrgCurr[0])
-        {
-            Z = cmm_I_ChrgCurr[0][0];
-        }
-        for(j = 0;j < cmm_V_ChrgCurrN - 1;j++)
-        {
-            if (Y > cmm_V_ChrgCurr[j] && Y <= cmm_V_ChrgCurr[j+1])
-            {
-                Z = (int16_T) (     (int32_T)(Y - cmm_V_ChrgCurr[i]) * (cmm_I_ChrgCurr[0][j+1] -cmm_I_ChrgCurr[0][j]) /(cmm_V_ChrgCurr[j+1] - cmm_V_ChrgCurr[j])     ) + cmm_I_ChrgCurr[0][j];
-            }
-        }
-        if(Y > cmm_V_ChrgCurr[cmm_V_ChrgCurrN-1])
-        {
-            Z = cmm_I_ChrgCurr[0][cmm_V_ChrgCurrN-1];
-        }
-    }
-    //======================================================================
-    for (i = 0; i < cmm_T_ChrgCurrN - 1;i++ )
-    {
-        if (X > cmm_T_ChrgCurr[i] && X <= cmm_T_ChrgCurr[i+1])
-        {
-            if(Y <= cmm_V_ChrgCurr[0])
-            {
-                Z = (int16_T) ((int32_T)(X - cmm_T_ChrgCurr[i]) * (cmm_I_ChrgCurr[i+1][0] -cmm_I_ChrgCurr[i][0])/(cmm_T_ChrgCurr[i+1] - cmm_T_ChrgCurr[i])) + cmm_I_ChrgCurr[i][0]  ;
-            }
-            for(j = 0;j < cmm_V_ChrgCurrN - 1;j++)
-            { 
-                if (Y > cmm_V_ChrgCurr[j] && Y <= cmm_V_ChrgCurr[j+1])
-                {
-                    temp1 = (int16_T) ( (int32_T)(  (X - cmm_T_ChrgCurr[i]) * (cmm_I_ChrgCurr[i+1][j] - cmm_I_ChrgCurr[i][j])  )/(cmm_T_ChrgCurr[i+1] - cmm_T_ChrgCurr[i])) + cmm_I_ChrgCurr[i][j];
-                    temp2 = (int16_T) ( (int32_T)( (X - cmm_T_ChrgCurr[i]) * (cmm_I_ChrgCurr[i+1][j+1] - cmm_I_ChrgCurr[i][j+1]) )/(cmm_T_ChrgCurr[i+1] - cmm_T_ChrgCurr[i])) + cmm_I_ChrgCurr[i][j+1];
-                    Z =  (int16_T) ( (int32_T)( (Y - cmm_V_ChrgCurr[j]) * (temp2 -temp1)  )/(cmm_V_ChrgCurr[j+1] - cmm_V_ChrgCurr[j])) + temp1 ;
-		
-                    //break;
-                }
-            }
-            if(Y > cmm_V_ChrgCurr[cmm_V_ChrgCurrN-1])
-            {
-                Z = (int16_T) (  (int32_T)( (X - cmm_T_ChrgCurr[i]) * (cmm_I_ChrgCurr[i+1][cmm_V_ChrgCurrN-1] -cmm_I_ChrgCurr[i][cmm_V_ChrgCurrN-1])  )/(cmm_T_ChrgCurr[i+1] - cmm_T_ChrgCurr[i]))+ cmm_I_ChrgCurr[i][cmm_V_ChrgCurrN-1];
-            }
-           // break;
-        }
-    }
-    //=====================================================================
-    if (X > cmm_T_ChrgCurr[cmm_T_ChrgCurrN-1])
-    {
-        if(Y <= cmm_V_ChrgCurr[0])
-        {
-            Z = cmm_I_ChrgCurr[cmm_T_ChrgCurrN-1][0];
-        }
-        for(j = 0;j < cmm_V_ChrgCurrN - 1;j++)
-        {
-            if (Y > cmm_V_ChrgCurr[j] && Y <= cmm_V_ChrgCurr[j+1])
-            {
-                Z = (int16_T) (  (int32_T)( (Y - cmm_V_ChrgCurr[i]) * (cmm_I_ChrgCurr[cmm_T_ChrgCurrN-1][j+1] -cmm_I_ChrgCurr[cmm_T_ChrgCurrN-1][j]) )/(cmm_V_ChrgCurr[j+1] - cmm_V_ChrgCurr[j])) + cmm_I_ChrgCurr[cmm_T_ChrgCurrN-1][j];
-               //  break;
-            }
-        }
-        if(Y > cmm_V_ChrgCurr[cmm_V_ChrgCurrN-1])
-        {
-            Z = cmm_I_ChrgCurr[cmm_T_ChrgCurrN-1][cmm_V_ChrgCurrN-1];
-        }
-    }  
-	return Z;
-}
+

+ 9 - 33
src/EmbeddedCoder_src/ISC.c

@@ -1,5 +1,5 @@
 #include "ISC.h"
-#include "look1_iu16lu16n16tu16_binlcase.h"
+
 
 boolean_T FirstRun_ISC;
 
@@ -61,13 +61,13 @@ void ISC(void)
         {
             for(i = 0; i < cmnc_num_cellUNum;i++)
             {
-                iscn_pct_cellSoc1[i] = look1_iu16lu16n16tu16_binlcase(sfmv_V_cellU[i], (&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
+                iscn_pct_cellSoc1[i] = look1_u16tu16(sfmv_V_cellU[i], cmnm_V_ocv, cmnm_pct_soc, 13);
                 iscn_Q_cellAh[i] = (uint16_T)((uint16_T)((uint32_T) iscn_pct_cellSoc1[i]  * sohv_Q_cellCap[i] / 2000U) << 1);
                 iscn_Q_deltAh[i] = (int16_T) (iscn_Q_cellAh[i] - iscv_Q_remainCpEE[i]);
             }
             for(i = 0; i < cmnc_num_cellUNum;i++)
             {
-                if((real_T)(ArrMean(&iscn_Q_deltAh[0],cmnc_num_cellUNum) -  iscn_Q_deltAh[i]) * 0.1/(iscd_tm_totalEE + ihd_tm_parkTime) * 3600 > 0.1)
+                if((real_T)(ArrMean(iscn_Q_deltAh,cmnc_num_cellUNum) -  iscn_Q_deltAh[i]) * 0.1/(iscd_tm_totalEE + ihd_tm_parkTime) * 3600 > 0.1)
                 {
                     iscd_flg_fulStat = true && iscd_tm_totalEE !=0;
                 }
@@ -93,13 +93,13 @@ void ISC(void)
     {
         for (i = 0; i < cmnc_num_cellUNum;i++)
         {
-            iscn_pct_cellSoc1[i] = look1_iu16lu16n16tu16_binlcase(appv_V_cellU[i], (&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
-            iscn_pct_cellSoc2[i] = look1_iu16lu16n16tu16_binlcase(sfmv_V_cellU[i], (&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
+            iscn_pct_cellSoc1[i] = look1_u16tu16(appv_V_cellU[i], cmnm_V_ocv, cmnm_pct_soc, 13);
+            iscn_pct_cellSoc2[i] = look1_u16tu16(sfmv_V_cellU[i], cmnm_V_ocv, cmnm_pct_soc, 13);
             iscn_Q_deltAh[i] = (int16_T)((uint16_T)((uint32_T) iscn_pct_cellSoc2[i]  * sohv_Q_cellCap[i] / 2000U) << 1) - (int16_T)((uint16_T)((uint32_T) iscn_pct_cellSoc1[i]  * sohv_Q_cellCap[i] / 2000U) << 1);
         }
         for (i = 0; i < cmnc_num_cellUNum;i++)
         {
-            if(ArrMean(&iscn_Q_deltAh[0],cmnc_num_cellUNum) -  iscn_Q_deltAh[i] > 10)
+            if(ArrMean(iscn_Q_deltAh,cmnc_num_cellUNum) -  iscn_Q_deltAh[i] > 10)
             {
                 iscd_flg_timedWakeUpFlt = true;
             }
@@ -132,7 +132,7 @@ void ISC(void)
             }
             for (i = 0; i < cmnc_num_cellUNum;i++)
             {
-                if((real_T)(ArrMean(&iscn_Q_deltAh[0],cmnc_num_cellUNum) -  iscn_Q_deltAh[i]) * 0.01/(TimeCtn - 60) * 3600 > 2 )
+                if((real_T)(ArrMean(iscn_Q_deltAh,cmnc_num_cellUNum) -  iscn_Q_deltAh[i]) * 0.01/(TimeCtn - 60) * 3600 > 2 )
                 {
                     iscn_N_fltNr[i] =  (iscn_N_fltNr[i] + 1) > 60000 ? 60000 : (iscn_N_fltNr[i] + 1);
                 }
@@ -158,32 +158,8 @@ void ISC(void)
 	
     /////
     iscd_flg_flt = iscd_flg_disChrgFlt||iscd_flg_timedWakeUpFlt ||iscd_flg_fulStat;
-  /*
-    printf("R-%d,%d,%d\n",cdmv_ohm_deltR[0],cdmv_ohm_deltR[1],cdmv_ohm_deltR[2]);
-	printf("E-%d,%d,%d\n",cdmv_V_deltOCV[0],cdmv_V_deltOCV[1],cdmv_V_deltOCV[2]);
-	printf("S-%d,%d,%d\n",socv_pct_cellSoc[0],socv_pct_cellSoc[1],socv_pct_cellSoc[2]);
-	printf("a-%d,%d,%d\n",iscn_Q_cellAh[0],iscn_Q_cellAh[1],iscn_Q_cellAh[2]);
-    printf("a-%d,%d,%d\n",iscn_Q_cellAh0[0],iscn_Q_cellAh0[1],iscn_Q_cellAh0[2]);
-	for(i=0;i<3;i++)
-	{
-	    printf("%f    ",(real_T)(ArrMean(&iscn_Q_deltAh[0],cmnc_num_cellUNum) -  iscn_Q_deltAh[i]) * 0.01/(TimeCtn - 60) * 3600);
-	}
-    printf("\nTimeCtn:%d\n\n",TimeCtn);
-    */
+
 	FirstRun_ISC = false;
 }
 
-/////////////////////////////////////////////////////////////////////////////////
-int16_T ArrMean(int16_T *Data, uint16_T m)
-{
-    uint16_T i;
-    int32_T Sum = 0;
-    int16_T DataMean;
-    
-    for (i = 0;i < m ;i++)
-    {
-        Sum = Sum + Data[i];
-    }
-    DataMean = (int16_T)Sum /m;
-    return DataMean;
-}
+

+ 31 - 22
src/EmbeddedCoder_src/PIM.c

@@ -1,7 +1,7 @@
 #include "PIM.h"
 
 static boolean_T FirstRun_PIM;
-#define pimd_L_rls 101
+#define pimd_L_rls 51
 
 void PIM_Init(void)
 {
@@ -28,12 +28,29 @@ void PIM(void)
     real_T K[4];
     real_T S[4];
     real_T temp;
+	
     //重置
     if (pimn_st_workStat_Delay != 1 && ihd_st_workStat == 1)
     {
         FirstRun_PIM = true;
     }
     
+    //初值
+    if (FirstRun_PIM)
+    {
+        pimn_M_P[0][0] = 10; pimn_M_P[0][1] =  0;  pimn_M_P[0][2] =  0;  pimn_M_P[0][3] =  0;
+        pimn_M_P[1][0] =  0; pimn_M_P[1][1] = 10;  pimn_M_P[1][2] =  0;  pimn_M_P[1][3] =  0;
+        pimn_M_P[2][0] =  0; pimn_M_P[2][1] =  0;  pimn_M_P[2][2] = 10;  pimn_M_P[2][3] =  0;
+        pimn_M_P[3][0] =  0; pimn_M_P[3][1] =  0;  pimn_M_P[3][2] =  0;  pimn_M_P[3][3] = 10;
+        
+        pimn_V_ocv   = (real_T)look1_u16tu16(socd_pct_battSoc, cmnm_pct_soc, cmnm_V_ocv,    13) * 0.001;
+        pimn_R_ohm   = (real_T)look1_u16tu16(socd_pct_battSoc, cmnm_pct_soc, cmnm_R_ohm,    13) * 0.001 * 0.001;
+        pimn_R_polar = (real_T)look1_u16tu16(socd_pct_battSoc, cmnm_pct_soc, cmnm_R_polar,  13) * 0.001 * 0.001;
+        pimn_F_polar = 5;
+        pimn_N_ctn = 0;  
+		pimn_st_workStat_Delay = 0;
+    }
+
     //限定记忆长度
     if (FirstRun_PIM)
     {
@@ -53,22 +70,6 @@ void PIM(void)
         pimn_V_volt[i] = sfmv_V_cellU[0];
         pimn_I_curr[i] = sfmd_I_curr;
     }
-
-    
-    //初值
-    if (FirstRun_PIM)
-    {
-        pimn_M_P[0][0] = 10; pimn_M_P[0][1] =  0;  pimn_M_P[0][2] =  0;  pimn_M_P[0][3] =  0;
-        pimn_M_P[1][0] =  0; pimn_M_P[1][1] = 10;  pimn_M_P[1][2] =  0;  pimn_M_P[1][3] =  0;
-        pimn_M_P[2][0] =  0; pimn_M_P[2][1] =  0;  pimn_M_P[2][2] = 10;  pimn_M_P[2][3] =  0;
-        pimn_M_P[3][0] =  0; pimn_M_P[3][1] =  0;  pimn_M_P[3][2] =  0;  pimn_M_P[3][3] = 10;
-        
-        pimn_V_ocv   = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(socd_pct_battSoc * 10), (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])),    12U) * 0.001;
-        pimn_R_ohm   = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(socd_pct_battSoc * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])),    12U) * 0.001 * 0.001;
-        pimn_R_polar = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(socd_pct_battSoc * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_polar[0])), 12U) * 0.001 * 0.001;
-        pimn_F_polar = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(socd_pct_battSoc * 10), (&(cmnm_pct_soc[0])),  (&(cmnm_F_polar[0])), 12U) * 0.001;
-        pimn_N_ctn = 0;     
-    }
     //
     if(pimn_st_workStat_Delay == 1)
     {
@@ -79,10 +80,10 @@ void PIM(void)
         A[2] =-(real_T)pimn_I_curr[pimd_L_rls - 2] * 0.1;
         A[3] = 1;
         //参数形变
-        temp = exp(- (pimn_R_ohm + pimn_R_polar)/pimn_R_ohm/pimn_F_polar);
-        theta[0] = 1- pimn_R_ohm * (1 - temp)/(pimn_R_ohm + pimn_R_polar);
+        
+        theta[0] = exp(-1/pimn_F_polar);
         theta[1] = pimn_R_ohm;
-        theta[2] = pimn_R_ohm * temp;
+        theta[2] = pimn_R_ohm * exp(-1/pimn_F_polar) -pimn_R_polar * (1-exp(-1/pimn_F_polar));
         theta[3] = (1 -theta[0]) * pimn_V_ocv;
 
         //增益矩阵
@@ -160,14 +161,22 @@ void PIM(void)
         //参数求解
         pimn_V_ocv   = theta[3]/(1 - theta[0]);
         pimn_R_ohm   = theta[1];
-        pimn_R_polar = (theta[1] - theta[2])/(1 - theta[0]) - theta[1];
-        pimn_F_polar = theta[2] * theta[1] > 0 ?  (pimn_R_ohm + pimn_R_polar)/pimn_R_ohm/ (-log(theta[2]/theta[1])) : (pimn_R_ohm + pimn_R_polar)/pimn_R_ohm;
+        pimn_R_polar = (theta[0] * theta[1] -theta[2])/(1 -theta[0]);
+        pimn_F_polar = -1/log(theta[0]);
         
         pimd_V_ocv   = (uint16_T)(pimn_V_ocv   * 1000);
         pimd_R_ohm   = (uint16_T)(pimn_R_ohm   * 1000 * 1000);
         pimd_R_polar = (uint16_T)(pimn_R_polar * 1000 * 1000);
         pimd_F_polar = (uint16_T)(pimn_F_polar * 1000);
     }
+	else
+	{
+	    pimd_V_ocv   = 0;
+        pimd_R_ohm   = 0;
+        pimd_R_polar = 0;
+        pimd_F_polar = 0;
+	}
+
     //
     pimn_st_workStat_Delay = ihd_st_workStat;
     FirstRun_PIM = false; 

+ 0 - 85
src/EmbeddedCoder_src/SFM.c

@@ -1758,89 +1758,4 @@ void SFM(void)
 }
 
 //===============================================================================
-boolean_T DiagThrSystem1(boolean_T Enable, boolean_T precondition, uint16_T Input, uint16_T fltThr, uint16_T recThr, uint8_T fltNumThr, uint8_T recNumThr, uint8_T *fltNum, uint8_T *recNum, boolean_T *fitFlg)
-{
-
-    if (Enable && precondition && Input > fltThr)
-    {
-        *fltNum = (*fltNum + 1) > 200 ? 200 : (*fltNum + 1);
-    }
-    else
-    {
-        *fltNum = 0;
-    }
-
-    if (Enable && precondition && Input < recThr)
-    {
-        *recNum = (*recNum + 1) > 200 ? 200 : (*recNum + 1);
-    }
-    else
-    {
-        *recNum = 0;
-    }
-
-    if ((*fltNum > fltNumThr || (*fitFlg && *recNum < recNumThr)) && precondition)
-    {
-        *fitFlg = true;
-    }
-    else
-    {
-        *fitFlg = false;
-    }
-    return *fitFlg;
-}
-//=============================================================================
-boolean_T DiagThrSystem2(boolean_T Enable, boolean_T precondition, uint16_T Input, uint16_T fltThr, uint16_T recThr, uint8_T fltNumThr, uint8_T recNumThr, uint8_T *fltNum, uint8_T *recNum, boolean_T *fitFlg)
-{
-    if (Enable && precondition && Input < fltThr)
-    {
-        *fltNum = (*fltNum + 1) > 200 ? 200 : (*fltNum + 1);
-    }
-    else
-    {
-        *fltNum = 0;
-    }
 
-    if (Enable && precondition && Input > recThr)
-    {
-        *recNum = (*recNum + 1) > 200 ? 200 : (*recNum + 1);
-    }
-    else
-    {
-        *recNum = 0;
-    }
-
-    if ((*fltNum > fltNumThr || (*fitFlg && *recNum < recNumThr)) && precondition)
-    {
-        *fitFlg = true;
-    }
-    else
-    {
-        *fitFlg = false;
-    }
-
-    return *fitFlg;
-}
-
-//
-boolean_T JudgeTimeSystem(boolean_T Enable, boolean_T Input, uint16_T *N, uint16_T Thr)
-{
-    boolean_T fltFlg = false;
-    if (Input && Enable)
-    {
-        *N = (*N + 1) > 20000 ? 20000 : (*N + 1);
-    }
-    else
-    {
-        *N = 0;
-    }
-    if (*N > Thr && Enable)
-    {
-        fltFlg = true;
-    }
-    else
-    {
-        fltFlg = false;
-    }
-    return fltFlg;
-}

+ 34 - 76
src/EmbeddedCoder_src/SOC.c

@@ -1,6 +1,4 @@
 #include "SOC.h"
-#include "look1_is16lu16n16tu16_binlcase.h"
-#include "look1_iu16lu16n16tu16_binlcase.h"
 
 boolean_T FirstRun_SOC;
 
@@ -134,8 +132,8 @@ void SOC(void)
         if (socd_pct_battSocEi > 1000 || socd_pct_bcuSocEi > 1000 || ihd_st_EOLState == 0  ||
                 (((int16_T)(socd_pct_battSocEi - socd_pct_bcuSocEi) > 300 || (int16_T)(socd_pct_battSocEi - socd_pct_bcuSocEi) < -300) && ihd_tm_parkTime >= cmnc_tm_parkTime && sfmd_I_curr < 10 && sfmd_I_curr > -10))
         {
-            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_u16tu16(sfmd_V_cellUAvrg, cmnm_V_ocv, cmnm_pct_soc, 13);
+            socn_pct_bcuSocEE  = look1_u16tu16(sfmd_V_cellUAvrg, cmnm_V_ocv, cmnm_pct_soc, 13);
         }
         else
         {
@@ -145,7 +143,7 @@ void SOC(void)
         //
         if (ihd_tm_parkTime >= cmnc_tm_parkTime  && sfmd_I_curr < 10 && sfmd_I_curr > -10)
         {
-            socn_pct_battSocEE = look1_iu16lu16n16tu16_binlcase(sfmd_V_cellUAvrg, (&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
+            socn_pct_battSocEE = look1_u16tu16(sfmd_V_cellUAvrg, cmnm_V_ocv, cmnm_pct_soc, 13);
         }
         socn_Q_cap = (uint16_T)((uint16_T)((uint32_T)sohd_pct_bcuSoh * cmnc_Q_ratedCp / 2000U) << 1);
 		//socn_ohm_cellRAvrg = ArrMean(&sorv_ohm_cellREi[0], cmnc_num_cellUNum);
@@ -169,10 +167,10 @@ void SOC(void)
         P_Min_Delay[3] = 10;
     }
     //参数查表
-    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;
-    RC   = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_F_polar[0])), 12U) * 0.001;
+    ocv = (real_T)look1_u16tu16((uint16_T)(soc_Min_Delay * 10), cmnm_pct_soc, cmnm_V_ocv,  13) * 0.001;
+    Ro  = (real_T)look1_u16tu16((uint16_T)(soc_Min_Delay * 10), cmnm_pct_soc, cmnm_R_ohm,  13) * 0.001 * 0.001;
+    Rp  = (real_T)look1_u16tu16((uint16_T)(soc_Min_Delay * 10), cmnm_pct_soc, cmnm_R_polar,13) * 0.001 * 0.001;
+    RC  = (real_T)look1_u16tu16((uint16_T)(soc_Min_Delay * 10), cmnm_pct_soc, cmnm_F_polar,13) * 0.001;
     A[0] = 1;
     A[1] = 0;
     A[2] = 0;
@@ -232,10 +230,11 @@ void SOC(void)
         P_Max_Delay[3] = 10;
     }
     // 参数查表
-    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;
-    RC   = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_F_polar[0])), 12U) * 0.001;
+    ocv = (real_T)look1_u16tu16((uint16_T)(soc_Max_Delay * 10), cmnm_pct_soc, cmnm_V_ocv,  13) * 0.001;
+    Ro  = (real_T)look1_u16tu16((uint16_T)(soc_Max_Delay * 10), cmnm_pct_soc, cmnm_R_ohm,  13) * 0.001 * 0.001;
+    Rp  = (real_T)look1_u16tu16((uint16_T)(soc_Max_Delay * 10), cmnm_pct_soc, cmnm_R_polar,13) * 0.001 * 0.001;
+    RC  = (real_T)look1_u16tu16((uint16_T)(soc_Max_Delay * 10), cmnm_pct_soc, cmnm_F_polar,13) * 0.001;
+
     A[0] = 1;
     A[1] = 0;
     A[2] = 0;
@@ -313,10 +312,11 @@ void SOC(void)
         P_avrg_Delay[3] = 10;
     }
     //参数查表
-    ocv = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Avrg_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])),   12U) * 0.001;
-    Ro  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Avrg_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])),   12U) * 0.001 * 0.001;
-    Rp  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Avrg_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_R_polar[0])), 12U) * 0.001 * 0.001;
-    RC   = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Avrg_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_F_polar[0])), 12U) * 0.001 ;
+    ocv = (real_T)look1_u16tu16((uint16_T)(soc_Avrg_Delay * 10), cmnm_pct_soc, cmnm_V_ocv,  13) * 0.001;
+    Ro  = (real_T)look1_u16tu16((uint16_T)(soc_Avrg_Delay * 10), cmnm_pct_soc, cmnm_R_ohm,  13) * 0.001 * 0.001;
+    Rp  = (real_T)look1_u16tu16((uint16_T)(soc_Avrg_Delay * 10), cmnm_pct_soc, cmnm_R_polar,13) * 0.001 * 0.001;
+    RC  = (real_T)look1_u16tu16((uint16_T)(soc_Avrg_Delay * 10), cmnm_pct_soc, cmnm_F_polar,13) * 0.001;
+
     A[0] = 1;
     A[1] = 0;
     A[2] = 0;
@@ -368,11 +368,13 @@ void SOC(void)
     //
     for(i = 0;i < cmnc_num_cellUNum;i++)
     {
-        socv_pct_cellSoc[i] = look1_iu16lu16n16tu16_binlcase((look1_iu16lu16n16tu16_binlcase(EKFSOCAvrg, (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])), 12U) + cdmv_V_deltOCV[i]), (&(cmnm_V_ocv[0])),(&(cmnm_pct_soc[0])),12U);
+        socv_pct_cellSoc[i] = look1_u16tu16((look1_u16tu16(EKFSOCAvrg, cmnm_pct_soc, cmnm_V_ocv, 13) + cdmv_V_deltOCV[i]), cmnm_V_ocv, cmnm_pct_soc, 13);
     }
     socd_flg_cellSocDisable = socn_flg_ekfInvalidAvrg || cdmd_flg_deltOCVDisable;
-    cellSocMax = ArrMax(&socv_pct_cellSoc[0],cmnc_num_cellUNum);
-    cellSocMin = ArrMin(&socv_pct_cellSoc[0],cmnc_num_cellUNum);
+	
+    cellSocMax = ArrMax(socv_pct_cellSoc,cmnc_num_cellUNum);
+    cellSocMin = ArrMin(socv_pct_cellSoc,cmnc_num_cellUNum);
+	
     if (cellSocMax > 800)
     {
         factor = 100;
@@ -387,8 +389,6 @@ void SOC(void)
     }
     socd_pct_cellBattSoc = (uint16_T)(((1 - (real_T)(factor * 0.01)) * (real_T)(cellSocMin * 0.1) + (real_T)(factor * 0.01) * (real_T)(cellSocMax * 0.1)) * 10);
     
- 
-    
 
     //======================================================================
     ////////////////////////AhSOC//////////////////////////////////////////
@@ -415,6 +415,7 @@ 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);
+	
     //======================================================================
     ///////////////////////estSOC//////////////////////////////////////////
     //======================================================================
@@ -463,7 +464,7 @@ void SOC(void)
         chrgCntl = (chrgCntl + 1) > 250 ? 250 : (chrgCntl + 1);
         lowCntl = 0;
         lowFlg = false;
-	    socd_V_chrgCCV = look1_is16lu16n16tu16_binlcase(sfmd_I_curr,&socm_I_chrgCor[0],&socm_V_chrgCor[0],2U); 
+	    socd_V_chrgCCV = look1_i16tu16(sfmd_I_curr,socm_I_chrgCor,socm_V_chrgCor,3); 
 		if (sfmd_V_cellUMax >= socd_V_chrgCCV)
         {
             overCntl = (overCntl + 1) > 250 ? 250 : (overCntl + 1);
@@ -536,14 +537,14 @@ void SOC(void)
         fulCntl = 0;
 		if (!cdmd_flg_deltOCVDisable)
 		{
-		    socd_V_disChrgCCV = look1_is16lu16n16tu16_binlcase(sfmd_I_curr,&socm_I_disChrgCor[0],&socm_V_disChrgCor[0],2U) + (uint16_T)(sfmd_I_curr * (cdmv_ohm_deltR[sfmd_idx_cellUMin]) * 0.001 * 0.1);
+		    socd_V_disChrgCCV = look1_i16tu16(sfmd_I_curr,socm_I_disChrgCor,socm_V_disChrgCor,3) + (uint16_T)(sfmd_I_curr * (cdmv_ohm_deltR[sfmd_idx_cellUMin]) * 0.001 * 0.1);
 		}
 		else
 		{
-		    socd_V_disChrgCCV = look1_is16lu16n16tu16_binlcase(sfmd_I_curr,&socm_I_disChrgCor[0],&socm_V_disChrgCor[0],2U);
+		    socd_V_disChrgCCV = look1_i16tu16(sfmd_I_curr,socm_I_disChrgCor,socm_V_disChrgCor,3);
 		}
 		
-        if (sfmd_V_cellUMin <= socd_V_disChrgCCV)
+        if (sfmd_V_cellUMin <= socd_V_disChrgCCV) 
         {
             lowCntl = (lowCntl + 1) > 250 ? 250 : (lowCntl + 1);
         }
@@ -627,16 +628,16 @@ void SOC(void)
         y[0] = socd_pct_bcuSoc0;
         y[1] = coinSoc > socc_pct_battSocUp ? socc_pct_battSocUp : (uint16_T)coinSoc;
         y[2] = socc_pct_battSocUp;
-        bcuSoc = SOC_LookUp(socd_pct_battSoc, &x[0], &y[0]);
+        bcuSoc = look1_u16tu16(socd_pct_battSoc, x, y,3);
         
         //
         if (onceFlg_chrg)
         {
             onceFlg_chrg = false;
             onceFlg_dischrg = true;
-            socd_pct_bcuSoc = 2000;
+            socd_pct_bcuSoc = bcuSoc;
         }
-        socd_pct_bcuSoc = SOCfitSystem(bcuSoc, &socd_pct_bcuSoc, 1);
+        socd_pct_bcuSoc = DataFilt(bcuSoc, &socd_pct_bcuSoc, 1);
         
         //
         if (fulFlg)
@@ -661,16 +662,16 @@ void SOC(void)
         y[0] = socc_pct_battSocLow;
         y[1] = coinSoc > socc_pct_battSocLow ? (uint16_T)coinSoc : socc_pct_battSocLow;
         y[2] = socd_pct_bcuSoc0;
-        bcuSoc = SOC_LookUp(socd_pct_battSoc, &x[0], &y[0]);
+        bcuSoc = look1_u16tu16(socd_pct_battSoc, x, y,3);
         
         //
         if (onceFlg_dischrg)
         {
             onceFlg_chrg = true;
             onceFlg_dischrg = false;
-            socd_pct_bcuSoc = 2000;
+            socd_pct_bcuSoc = bcuSoc;
         }
-        socd_pct_bcuSoc = SOCfitSystem(bcuSoc, &socd_pct_bcuSoc, 1);
+        socd_pct_bcuSoc = DataFilt(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;
@@ -717,50 +718,7 @@ real_T docvmath(real_T soc)
 }
 
 ////
-uint16_T SOC_LookUp(uint16_T battsoc, uint16_T x[3], uint16_T y[3])
-{
-    uint16_T bcusoc;
-    if (battsoc <= x[0])
-    {
-        bcusoc = y[0];
-    }
-    //
-    if (battsoc >= x[2])
-    {
-        bcusoc = y[2];
-    }
-    //
-    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];
-    }
-    //
-    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];
-    }
-    return bcusoc;
-}
 
 //-------------------------------------------------------------------------
-uint16_T SOCfitSystem(uint16_T SOC, uint16_T *SOCfit, uint16_T m)
-{
-    int16_T socdelt;
-    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;
-    }
-    
-    return *SOCfit;
-}
+
 

+ 3 - 3
src/EmbeddedCoder_src/SOE.c

@@ -1,5 +1,5 @@
 #include "SOE.h"
-#include "look1_iu16lu16n16tu16_binlcase.h"
+
 
 boolean_T FirstRun_SOE;
 
@@ -20,7 +20,7 @@ void SOE(void)
         soen_V_battOcv = 0;
         for(i = socc_pct_battSocUp ;i >= socc_pct_battSocLow + 1;i--)
         {
-            soen_V_battOcv = soen_V_battOcv + look1_iu16lu16n16tu16_binlcase(i, (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])), 12U) * cmnc_num_cellUNum;
+            soen_V_battOcv = soen_V_battOcv + look1_u16tu16(i, cmnm_pct_soc, cmnm_V_ocv, 13) * cmnc_num_cellUNum;
         }
         soed_E_fullEng = (uint16_T) ( (real_T)(soen_V_battOcv * 0.001) * (real_T)(cmnc_Q_ratedCp * 0.1) * (real_T)(sohd_pct_bcuSoh * 0.1 * 0.01)/1000);
     }
@@ -30,7 +30,7 @@ void SOE(void)
         soen_V_battOcv = 0;
         for(i = socd_pct_battSoc;i >= socc_pct_battSocLow + 1;i--)
         {
-            soen_V_battOcv = soen_V_battOcv + look1_iu16lu16n16tu16_binlcase(i, (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])), 12U) * cmnc_num_cellUNum;
+            soen_V_battOcv = soen_V_battOcv + look1_u16tu16(i, cmnm_pct_soc, cmnm_V_ocv, 13)  * cmnc_num_cellUNum;
         }
         soed_E_nowEng = (uint16_T) ( (real_T)(soen_V_battOcv * 0.001) * (real_T)(cmnc_Q_ratedCp * 0.1) * (real_T)(sohd_pct_bcuSoh * 0.1 * 0.01) /1000);
     }

+ 13 - 43
src/EmbeddedCoder_src/SOH.c

@@ -1,5 +1,5 @@
 #include "SOH.h"
-#include "look1_iu16lu16n16tu16_binlcase.h"
+
 
 boolean_T FirstRun_SOH;
 
@@ -76,10 +76,10 @@ void SOH(void)
         //=======================================================================================
         //--------------------------EE校验-------------------------------------------------------
         //=======================================================================================
-        cellCapArr_Min = ArrMin((&(sohv_Q_cellCapArrEi[0])) , cmnc_num_cellUNum);
-        cellCapArr_Max = ArrMax((&(sohv_Q_cellCapArrEi[0])) , cmnc_num_cellUNum);
-        packCapArr_Min = ArrMin((&(sohv_Q_packCapArrEi[0])) , 10);
-        packCapArr_Max = ArrMax((&(sohv_Q_packCapArrEi[0])) , 10);
+        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));
@@ -125,8 +125,8 @@ void SOH(void)
             sohn_flg_update = true;
             for(i = 0;i < cmnc_num_cellUNum;i++)
             {
-                soc2[i] =  look1_iu16lu16n16tu16_binlcase(sfmv_V_cellU[i],(&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
-                soc1[i] =  look1_iu16lu16n16tu16_binlcase(sohn_V_chrgStartStatEE[i],(&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
+                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);
 				test_cellCap[i] = sohv_Q_cellCapArrEo[i];
@@ -136,10 +136,10 @@ void SOH(void)
                     break;
                 }
             }
-            DisEn = (ArrMin((&(soc2[0])) , cmnc_num_cellUNum) > sohc_pct_low &&   ArrMin((&(soc2[0])) , cmnc_num_cellUNum) < sohc_pct_up) 
-                  ||(ArrMax((&(soc2[0])) , cmnc_num_cellUNum) > sohc_pct_low &&   ArrMax((&(soc2[0])) , cmnc_num_cellUNum) < sohc_pct_up)
-                  ||(ArrMin((&(soc1[0])) , cmnc_num_cellUNum) > sohc_pct_low &&   ArrMin((&(soc1[0])) , cmnc_num_cellUNum) < sohc_pct_up)
-                  ||(ArrMax((&(soc1[0])) , cmnc_num_cellUNum) > sohc_pct_low &&   ArrMax((&(soc1[0])) , cmnc_num_cellUNum) < sohc_pct_up);
+            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)
             {   
@@ -149,8 +149,8 @@ void SOH(void)
                      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);
  				} 
-                 chrgCap_Min = ArrMin((&(chrgCellCapArr[0])) , cmnc_num_cellUNum);
-                 disChrgCap_Min = ArrMin((&(disChrgCellCapArr[0])) , cmnc_num_cellUNum);
+                 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];
@@ -240,35 +240,5 @@ void SOH(void)
 	
 }
 
-////////////////////////////////////////////////////////////////
-uint16_T  ArrMax(uint16_T *Data, uint16_T m)
-{
-    uint16_T i;
-	uint16_T DataMax;
-    DataMax = Data[0];
-    for(i = 0; i < m; i++)
-    {
-        if (DataMax < Data[i])
-        {
-            DataMax = Data[i];
-        }
-    }
-	return DataMax;
-}
 
-///////////////////////////////////////////////////////////////////
-uint16_T  ArrMin(uint16_T *Data, uint16_T m)
-{
-    uint16_T i;
-	uint16_T DataMin;
-    DataMin = Data[0];
-    for(i = 0; i < m; i++)
-    {
-        if (DataMin > Data[i])
-        {
-            DataMin = Data[i];
-        }
-    }
-	return DataMin;
-}
 

+ 424 - 0
src/EmbeddedCoder_src/funlib.c

@@ -0,0 +1,424 @@
+#include "funlib.h"
+
+
+
+//-------------------�啁��𡝗�憭�-------------------------------------
+uint16_T  ArrMax(uint16_T *Data, uint16_T n)
+{
+    uint16_T i;
+	uint16_T DataMax;
+    DataMax = Data[0];
+    for(i = 0; i < n; i++)
+    {
+        if (DataMax < Data[i])
+        {
+            DataMax = Data[i];
+        }
+    }
+	return DataMax;
+}
+
+//-----------------�啁��𡝗�撠�-------------------------------------
+uint16_T  ArrMin(uint16_T *Data, uint16_T n)
+{
+    uint16_T i;
+	uint16_T DataMin;
+    DataMin = Data[0];
+    for(i = 0; i < n; i++)
+    {
+        if (DataMin > Data[i])
+        {
+            DataMin = Data[i];
+        }
+    }
+	return DataMin;
+}
+//
+
+/////////////////////////////////////////////////////////////////////////////////
+int16_T ArrMean(int16_T *Data, uint16_T n)
+{
+    uint16_T i;
+    int32_T Sum = 0;
+    int16_T DataMean;
+    
+    for (i = 0;i < n ;i++)
+    {
+        Sum = Sum + Data[i];
+    }
+    DataMean = (int16_T)Sum /n;
+    return DataMean;
+}
+
+
+
+
+// 皛斗郭�批��睃𢆡�毺�
+uint16_T DataFilt(uint16_T in, uint16_T *out, uint16_T Lim)
+{
+    int16_T delt;
+    delt = (int16_T)(in - *out);
+    if (delt > Lim)
+    {
+        *out = *out + (delt > Lim ? Lim : delt);
+    }
+    if (delt < -Lim)
+    {
+        *out = *out + (delt < -Lim  ? -Lim  : delt);
+    }
+    if (delt <= Lim && delt >= -Lim)
+    {
+        *out = in;
+    }
+    return *out;
+}
+
+//-------------------uint16 to uint16���蝏湔䰻銵�--------------------------------------  
+uint16_T look1_u16tu16(uint16_T u0, const uint16_T *bp0, const uint16_T *table, uint16_T MaxLen)
+{
+	uint32_T bpIdx = 0;
+	uint32_T iLeft = 0;
+	uint32_T iRght = 0;
+	uint16_T y = 0;
+	uint32_T yL_0d0 = 0;
+	uint32_T yR_0d0 = 0;
+	uint32_T maxIndex = MaxLen - 1;
+	if (u0 <= bp0[0U])
+	{
+		iLeft = 0U;
+		iRght = 0U;
+	}
+	else if (u0 < bp0[maxIndex])
+	{
+		//勤殏楊扆梑u0腔弇离
+		bpIdx = maxIndex >> 1U;
+		iLeft = 0U;
+		iRght = maxIndex;
+		while ((iRght - iLeft) > 1)
+		{
+			if (u0 < bp0[bpIdx])
+			{
+				iRght = bpIdx;
+			}
+			else
+			{
+				iLeft = bpIdx;
+			}
+			bpIdx = (iRght + iLeft) >> 1U;
+		}
+	}
+	else
+	{
+		iLeft = maxIndex;
+		iRght = maxIndex;
+	}
+	//梑善弇离眕綴數呾脣硉
+	if (iLeft!=iRght)
+	{
+		//盄俶脣硉
+		yR_0d0 = table[iLeft + 1U];
+		yL_0d0 = table[iLeft];
+		if (yR_0d0 >= yL_0d0)
+		{
+			y = ((uint16_T)((uint32_T)(u0 - bp0[iLeft]) * (yR_0d0 - yL_0d0)) / (bp0[iLeft + 1] - bp0[iLeft]) + yL_0d0);
+		}
+		else
+		{
+			y = ((uint16_T)(yL_0d0 - ((uint32_T)(u0 - bp0[iLeft]) * (yL_0d0 - yR_0d0)) / (bp0[iLeft + 1] - bp0[iLeft])));
+		}
+	}
+	else
+	{
+		y = (uint16_T)table[iLeft];
+	}
+	return y;
+}
+
+
+//-------------------int16 to uint16���蝏湔䰻銵�--------------------------------------  
+uint16_T look1_i16tu16(int16_T u0, const int16_T *bp0, const uint16_T *table, uint16_T MaxLen)
+{
+	uint32_T bpIdx = 0;
+	uint32_T iLeft = 0;
+	uint32_T iRght = 0;
+	uint16_T y = 0;
+	uint32_T yL_0d0 = 0;
+	uint32_T yR_0d0 = 0;
+	uint32_T maxIndex = MaxLen - 1;
+	if (u0 <= bp0[0U])
+	{
+		iLeft = 0U;
+		iRght = 0U;
+	}
+	else if (u0 < bp0[maxIndex])
+	{
+		//勤殏楊扆梑u0腔弇离
+		bpIdx = maxIndex >> 1U;
+		iLeft = 0U;
+		iRght = maxIndex;
+		while ((iRght - iLeft) > 1)
+		{
+			if (u0 < bp0[bpIdx])
+			{
+				iRght = bpIdx;
+			}
+			else
+			{
+				iLeft = bpIdx;
+			}
+			bpIdx = (iRght + iLeft) >> 1U;
+		}
+	}
+	else
+	{
+		iLeft = maxIndex;
+		iRght = maxIndex;
+	}
+	//梑善弇离眕綴數呾脣硉
+	if (iLeft!=iRght)
+	{
+		//盄俶脣硉
+		yR_0d0 = table[iLeft + 1U];
+		yL_0d0 = table[iLeft];
+		if (yR_0d0 >= yL_0d0)
+		{
+			y = ((uint16_T)((uint32_T)(u0 - bp0[iLeft]) * (yR_0d0 - yL_0d0)) / (bp0[iLeft + 1] - bp0[iLeft]) + yL_0d0);
+		}
+		else
+		{
+			y = ((uint16_T)(yL_0d0 - ((uint32_T)(u0 - bp0[iLeft]) * (yL_0d0 - yR_0d0)) / (bp0[iLeft + 1] - bp0[iLeft])));
+		}
+	}
+	else
+	{
+		y = (uint16_T)table[iLeft];
+	}
+	return y;
+}
+
+
+//  uint16 鈭𣬚輕�亥”
+uint16_T look2_u16u16tu16(uint16_T x, uint16_T y, const uint16_T xTable[], const uint16_T yTable[], const uint16_T zTable[], uint16_T xLen, uint16_T yLen)
+{
+  uint16_T xMaxIndex;
+  uint16_T yMaxIndex;
+  uint16_T xIndexLeft;
+  uint16_T xIndexRight;
+  uint16_T yIndexLeft;
+  uint16_T yIndexRight;
+  uint16_T xValueLeft;
+  uint16_T xValueRight;
+  uint16_T yValueLeft;
+  uint16_T yValueRight;
+  uint16_T bpIdx;
+  uint32_T zIndex1;
+  uint32_T zIndex2;
+  uint32_T zValueMid_xLeft;
+  uint32_T zValueMid_xRight;
+  uint16_T z;
+  xMaxIndex = xLen - 1;
+  yMaxIndex = yLen - 1;
+  
+  if (x <= xTable[0U])
+  {
+    xIndexLeft = 0U;
+    xIndexRight = 0U;
+  }
+  else if (x >= xTable[xMaxIndex])
+  {
+    xIndexLeft = xMaxIndex;
+    xIndexRight = xMaxIndex;
+  }
+  else
+  {
+    bpIdx = xMaxIndex >> 1U;
+    xIndexLeft = 0;
+    xIndexRight = xMaxIndex;
+    while (xIndexRight - xIndexLeft > 1U)
+    {
+      if (x < xTable[bpIdx])
+      {
+        xIndexRight = bpIdx;
+      }
+      else
+      {
+        xIndexLeft = bpIdx;
+      }
+
+      bpIdx = (xIndexRight + xIndexLeft) >> 1U;
+    }
+  }
+  xValueLeft = xTable[xIndexLeft];
+  xValueRight = xTable[xIndexRight];
+
+
+  if (y <= yTable[0U])
+  {
+    yIndexLeft = 0U;
+    yIndexRight = 0U;
+  }
+  else if (y >= yTable[yMaxIndex])
+  {
+    yIndexLeft = yMaxIndex;
+    yIndexRight = yMaxIndex;
+  }
+  else
+  {
+    bpIdx = yMaxIndex >> 1U;
+    yIndexLeft = 0;
+    yIndexRight = yMaxIndex;
+    while (yIndexRight - yIndexLeft > 1U)
+    {
+      if (y < yTable[bpIdx])
+      {
+        yIndexRight = bpIdx;
+      }
+      else
+      {
+        yIndexLeft = bpIdx;
+      }
+
+      bpIdx = (yIndexRight + yIndexLeft) >> 1U;
+    }
+  }
+  yValueLeft = yTable[yIndexLeft];
+  yValueRight = yTable[yIndexRight];
+
+
+  zIndex1 = yIndexLeft * xLen + xIndexLeft;
+  zIndex2 = yIndexRight * xLen + xIndexLeft;
+  if (yIndexLeft != yIndexRight)
+  {
+    if (zTable[zIndex2] > zTable[zIndex1])
+    {
+      zValueMid_xLeft = (uint16_T)(((uint32_T)(y - yValueLeft) * (zTable[zIndex2] - zTable[zIndex1])) / (yValueRight - yValueLeft) + zTable[zIndex1]);
+    }
+    else
+    {
+      zValueMid_xLeft = (uint16_T)(zTable[zIndex1] - ((uint32_T)(y - yValueLeft) * (zTable[zIndex1] - zTable[zIndex2])) / (yValueRight - yValueLeft));
+    }
+
+    if (zTable[zIndex2 + 1] > zTable[zIndex1 + 1])
+    {
+      zValueMid_xRight = (uint16_T)(((uint32_T)(y - yValueLeft) * (zTable[zIndex2 + 1] - zTable[zIndex1 + 1])) / (yValueRight - yValueLeft) + zTable[zIndex1 + 1]);
+    }
+    else
+    {
+      zValueMid_xRight = (uint16_T)(zTable[zIndex1 + 1] - ((uint32_T)(y - yValueLeft) * (zTable[zIndex1 + 1] - zTable[zIndex2 + 1])) / (yValueRight - yValueLeft));
+    }
+  }
+  else
+  {
+    zValueMid_xLeft = (uint16_T)zTable[zIndex1];
+    zValueMid_xRight = (uint16_T)zTable[zIndex1 + 1];
+  }
+  if (xIndexLeft != xIndexRight)
+  {
+    if (zValueMid_xLeft < zValueMid_xRight)
+    {
+      z = (uint16_T)(((uint32_T)(x - xValueLeft) * (zValueMid_xRight - zValueMid_xLeft)) / ((uint16_T)(xValueRight - xValueLeft)) + zValueMid_xLeft);
+    }
+    else
+    {
+      z = (uint16_T)(zValueMid_xLeft - ((uint32_T)(x - xValueLeft) * (zValueMid_xLeft - zValueMid_xRight)) / ((uint16_T)(xValueRight - xValueLeft)));
+    }
+  }
+  else
+  {
+    z = (uint16_T)(zValueMid_xLeft);
+  }
+  return z;
+}
+
+
+//-----------------------------------------------霂𦠜鱏憭找�����     
+boolean_T DiagThrSystem1(boolean_T Enable, boolean_T precondition, uint16_T Input, uint16_T fltThr, uint16_T recThr, uint8_T fltNumThr, uint8_T recNumThr, uint8_T *fltNum, uint8_T *recNum, boolean_T *fitFlg)
+{
+
+    if (Enable && precondition && Input > fltThr)
+    {
+        *fltNum = (*fltNum + 1) > 200 ? 200 : (*fltNum + 1);
+    }
+    else
+    {
+        *fltNum = 0;
+    }
+
+    if (Enable && precondition && Input < recThr)
+    {
+        *recNum = (*recNum + 1) > 200 ? 200 : (*recNum + 1);
+    }
+    else
+    {
+        *recNum = 0;
+    }
+
+    if ((*fltNum > fltNumThr || (*fitFlg && *recNum < recNumThr)) && precondition)
+    {
+        *fitFlg = true;
+    }
+    else
+    {
+        *fitFlg = false;
+    }
+    return *fitFlg;
+}
+
+//================================霂𦠜鱏撠譍�����===================================
+boolean_T DiagThrSystem2(boolean_T Enable, boolean_T precondition, uint16_T Input, uint16_T fltThr, uint16_T recThr, uint8_T fltNumThr, uint8_T recNumThr, uint8_T *fltNum, uint8_T *recNum, boolean_T *fitFlg)
+{
+    if (Enable && precondition && Input < fltThr)
+    {
+        *fltNum = (*fltNum + 1) > 200 ? 200 : (*fltNum + 1);
+    }
+    else
+    {
+        *fltNum = 0;
+    }
+
+    if (Enable && precondition && Input > recThr)
+    {
+        *recNum = (*recNum + 1) > 200 ? 200 : (*recNum + 1);
+    }
+    else
+    {
+        *recNum = 0;
+    }
+
+    if ((*fltNum > fltNumThr || (*fitFlg && *recNum < recNumThr)) && precondition)
+    {
+        *fitFlg = true;
+    }
+    else
+    {
+        *fitFlg = false;
+    }
+
+    return *fitFlg;
+}
+
+//---------------------------�斗鱏�∩辣�鞟�甈⊥㺭
+boolean_T JudgeTimeSystem(boolean_T Enable, boolean_T Input, uint16_T *N, uint16_T Thr)
+{
+    boolean_T Flg = false;
+    if (Input && Enable)
+    {
+        *N = (*N + 1) > 20000 ? 20000 : (*N + 1);
+    }
+    else
+    {
+        *N = 0;
+    }
+    if (*N > Thr && Enable)
+    {
+        Flg = true;
+    }
+    else
+    {
+        Flg = false;
+    }
+    return Flg;
+}
+
+
+

+ 0 - 96
src/EmbeddedCoder_src/look1_is16lu16n16tu16_binlcase.c

@@ -1,96 +0,0 @@
-/*
- * File: look1_is16lu16n16tu16_binlcase.c
- *
- * Code generated for Simulink model 'SOC'.
- *
- * Model version                  : 1.51
- * Simulink Coder version         : 9.4 (R2020b) 29-Jul-2020
- * C/C++ source code generated on : Thu Sep  9 17:18:48 2021
- */
-
-#include "rtwtypes.h"
-#include "look1_is16lu16n16tu16_binlcase.h"
-
-uint16_T look1_is16lu16n16tu16_binlcase(int16_T u0, const int16_T bp0[], const
-  uint16_T table[], uint32_T maxIndex)
-{
-  uint32_T bpIdx;
-  uint32_T iLeft;
-  uint32_T iRght;
-  int16_T bpLeftVar;
-  uint16_T frac;
-  uint16_T y;
-  uint16_T yL_0d0;
-  uint16_T yR_0d0;
-
-  /* Column-major Lookup 1-D
-     Search method: 'binary'
-     Use previous index: 'off'
-     Interpolation method: 'Linear point-slope'
-     Extrapolation method: 'Clip'
-     Use last breakpoint for index at or above upper limit: 'on'
-     Remove protection against out-of-range input in generated code: 'off'
-     Rounding mode: 'simplest'
-   */
-  /* Prelookup - Index and Fraction
-     Index Search method: 'binary'
-     Extrapolation method: 'Clip'
-     Use previous index: 'off'
-     Use last breakpoint for index at or above upper limit: 'on'
-     Remove protection against out-of-range input in generated code: 'off'
-     Rounding mode: 'simplest'
-   */
-  if (u0 <= bp0[0U]) {
-    iLeft = 0U;
-    frac = 0U;
-  } else if (u0 < bp0[maxIndex]) {
-    /* Binary Search */
-    bpIdx = maxIndex >> 1U;
-    iLeft = 0U;
-    iRght = maxIndex;
-    while (iRght - iLeft > 1U) {
-      if (u0 < bp0[bpIdx]) {
-        iRght = bpIdx;
-      } else {
-        iLeft = bpIdx;
-      }
-
-      bpIdx = (iRght + iLeft) >> 1U;
-    }
-
-    bpLeftVar = bp0[iLeft];
-    frac = (uint16_T)(((uint32_T)(uint16_T)(u0 - bpLeftVar) << 16) / (uint16_T)
-                      (bp0[iLeft + 1U] - bpLeftVar));
-  } else {
-    iLeft = maxIndex;
-    frac = 0U;
-  }
-
-  /* Column-major Interpolation 1-D
-     Interpolation method: 'Linear point-slope'
-     Use last breakpoint for index at or above upper limit: 'on'
-     Rounding mode: 'simplest'
-     Overflow mode: 'wrapping'
-   */
-  if (iLeft == maxIndex) {
-    y = table[iLeft];
-  } else {
-    yR_0d0 = table[iLeft + 1U];
-    yL_0d0 = table[iLeft];
-    if (yR_0d0 >= yL_0d0) {
-      y = (uint16_T)((uint32_T)(uint16_T)(((uint32_T)(uint16_T)((uint32_T)yR_0d0
-        - yL_0d0) * frac) >> 16) + yL_0d0);
-    } else {
-      y = (uint16_T)((uint32_T)yL_0d0 - (uint16_T)(((uint32_T)(uint16_T)
-        ((uint32_T)yL_0d0 - yR_0d0) * frac) >> 16));
-    }
-  }
-
-  return y;
-}
-
-/*
- * File trailer for generated code.
- *
- * [EOF]
- */

+ 0 - 95
src/EmbeddedCoder_src/look1_iu16lu16n16tu16_binlcase.c

@@ -1,95 +0,0 @@
-/*
- * File: look1_iu16lu16n16tu16_binlcase.c
- *
- * Code generated for Simulink model 'BLC'.
- *
- * Model version                  : 1.50
- * Simulink Coder version         : 9.4 (R2020b) 29-Jul-2020
- * C/C++ source code generated on : Thu Sep  9 17:18:08 2021
- */
-
-#include "rtwtypes.h"
-#include "look1_iu16lu16n16tu16_binlcase.h"
-
-uint16_T look1_iu16lu16n16tu16_binlcase(uint16_T u0, const uint16_T bp0[], const
-  uint16_T table[], uint32_T maxIndex)
-{
-  uint32_T bpIdx;
-  uint32_T iLeft;
-  uint32_T iRght;
-  uint16_T frac;
-  uint16_T y;
-  uint16_T yL_0d0;
-  uint16_T yR_0d0;
-
-  /* Column-major Lookup 1-D
-     Search method: 'binary'
-     Use previous index: 'off'
-     Interpolation method: 'Linear point-slope'
-     Extrapolation method: 'Clip'
-     Use last breakpoint for index at or above upper limit: 'on'
-     Remove protection against out-of-range input in generated code: 'off'
-     Rounding mode: 'simplest'
-   */
-  /* Prelookup - Index and Fraction
-     Index Search method: 'binary'
-     Extrapolation method: 'Clip'
-     Use previous index: 'off'
-     Use last breakpoint for index at or above upper limit: 'on'
-     Remove protection against out-of-range input in generated code: 'off'
-     Rounding mode: 'simplest'
-   */
-  if (u0 <= bp0[0U]) {
-    iLeft = 0U;
-    frac = 0U;
-  } else if (u0 < bp0[maxIndex]) {
-    /* Binary Search */
-    bpIdx = maxIndex >> 1U;
-    iLeft = 0U;
-    iRght = maxIndex;
-    while (iRght - iLeft > 1U) {
-      if (u0 < bp0[bpIdx]) {
-        iRght = bpIdx;
-      } else {
-        iLeft = bpIdx;
-      }
-
-      bpIdx = (iRght + iLeft) >> 1U;
-    }
-
-    frac = bp0[iLeft];
-    frac = (uint16_T)(((uint32_T)(uint16_T)((uint32_T)u0 - frac) << 16) /
-                      (uint16_T)((uint32_T)bp0[iLeft + 1U] - frac));
-  } else {
-    iLeft = maxIndex;
-    frac = 0U;
-  }
-
-  /* Column-major Interpolation 1-D
-     Interpolation method: 'Linear point-slope'
-     Use last breakpoint for index at or above upper limit: 'on'
-     Rounding mode: 'simplest'
-     Overflow mode: 'wrapping'
-   */
-  if (iLeft == maxIndex) {
-    y = table[iLeft];
-  } else {
-    yR_0d0 = table[iLeft + 1U];
-    yL_0d0 = table[iLeft];
-    if (yR_0d0 >= yL_0d0) {
-      y = (uint16_T)((uint32_T)(uint16_T)(((uint32_T)(uint16_T)((uint32_T)yR_0d0
-        - yL_0d0) * frac) >> 16) + yL_0d0);
-    } else {
-      y = (uint16_T)((uint32_T)yL_0d0 - (uint16_T)(((uint32_T)(uint16_T)
-        ((uint32_T)yL_0d0 - yR_0d0) * frac) >> 16));
-    }
-  }
-
-  return y;
-}
-
-/*
- * File trailer for generated code.
- *
- * [EOF]
- */