Преглед на файлове

Merge branch 'V3-V31XX-7250' into V3-V30XX-6060

# Conflicts:
#	inc/AppConfig.h
#	src/AppTaskUart.c
#	src/EmbeddedCoder_src/BCUCal.c
#	src/EmbeddedCoder_src/CDM.c
#	src/EmbeddedCoder_src/SOC.c
CHENJIE-PC\QiXiang_CHENJIE преди 2 години
родител
ревизия
883ce9e592
променени са 45 файла, в които са добавени 2612 реда и са изтрити 2042 реда
  1. 5 2
      ARMCC/Makefile
  2. 4 4
      inc/AppFunc.h
  3. 9 8
      inc/AppSignal.h
  4. 1 1
      inc/AppTaskControl.h
  5. 93 87
      inc/EmbeddedCoder_inc/BCUCal.h
  6. 43 8
      inc/EmbeddedCoder_inc/BCUDisp.h
  7. 1 1
      inc/EmbeddedCoder_inc/BLC.h
  8. 1 1
      inc/EmbeddedCoder_inc/CDM.h
  9. 2 3
      inc/EmbeddedCoder_inc/CM.h
  10. 2 2
      inc/EmbeddedCoder_inc/ISC.h
  11. 9 0
      inc/EmbeddedCoder_inc/PIM.h
  12. 2 4
      inc/EmbeddedCoder_inc/SFM.h
  13. 4 3
      inc/EmbeddedCoder_inc/SOC.h
  14. 7 0
      inc/EmbeddedCoder_inc/SOE.h
  15. 3 3
      inc/EmbeddedCoder_inc/SOH.h
  16. 9 0
      inc/EmbeddedCoder_inc/SOP.h
  17. 6 0
      inc/EmbeddedCoder_inc/SOR.h
  18. 4 4
      inc/EmbeddedCoder_inc/SPM.h
  19. 22 0
      inc/EmbeddedCoder_inc/funlib.h
  20. 0 24
      inc/EmbeddedCoder_inc/look1_is16lu16n16tu16_binlcase.h
  21. 0 24
      inc/EmbeddedCoder_inc/look1_iu16lu16n16tu16_binlcase.h
  22. 231 222
      src/AppFunc.c
  23. 35 34
      src/AppSignal.c
  24. 18 17
      src/AppTaskControl.c
  25. 15 5
      src/AppTaskMain.c
  26. 88 89
      src/AppTaskTcp.c
  27. 155 144
      src/EmbeddedCoder_src/BCU.c
  28. 65 53
      src/EmbeddedCoder_src/BCUCal.c
  29. 47 14
      src/EmbeddedCoder_src/BCUDisp.c
  30. 14 22
      src/EmbeddedCoder_src/BLC.c
  31. 63 59
      src/EmbeddedCoder_src/CDM.c
  32. 13 90
      src/EmbeddedCoder_src/CM.c
  33. 19 47
      src/EmbeddedCoder_src/ISC.c
  34. 193 0
      src/EmbeddedCoder_src/PIM.c
  35. 435 453
      src/EmbeddedCoder_src/SFM.c
  36. 188 312
      src/EmbeddedCoder_src/SOC.c
  37. 42 0
      src/EmbeddedCoder_src/SOE.c
  38. 52 79
      src/EmbeddedCoder_src/SOH.c
  39. 143 0
      src/EmbeddedCoder_src/SOP.c
  40. 65 0
      src/EmbeddedCoder_src/SOR.c
  41. 29 22
      src/EmbeddedCoder_src/SPM.c
  42. 465 0
      src/EmbeddedCoder_src/funlib.c
  43. 0 96
      src/EmbeddedCoder_src/look1_is16lu16n16tu16_binlcase.c
  44. 0 95
      src/EmbeddedCoder_src/look1_iu16lu16n16tu16_binlcase.c
  45. 10 10
      src/bsp_custom.c

+ 5 - 2
ARMCC/Makefile

@@ -35,8 +35,11 @@ obj-y             += PLAT/project/$(TARGET)/apps/qx_app/src/app.o \
 						PLAT/project/$(TARGET)/apps/qx_app/src/EmbeddedCoder_src/CM.o \
 						PLAT/project/$(TARGET)/apps/qx_app/src/EmbeddedCoder_src/CDM.o \
 						PLAT/project/$(TARGET)/apps/qx_app/src/EmbeddedCoder_src/ISC.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/SOE.o \
+						PLAT/project/$(TARGET)/apps/qx_app/src/EmbeddedCoder_src/SOR.o \
+						PLAT/project/$(TARGET)/apps/qx_app/src/EmbeddedCoder_src/SOP.o \
+						PLAT/project/$(TARGET)/apps/qx_app/src/EmbeddedCoder_src/PIM.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 

+ 4 - 4
inc/AppFunc.h

@@ -3,7 +3,7 @@
  * @Date         : 2021-10-14 09:27:15
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-11-12 15:03:02
+ * @LastEditTime : 2021-12-16 11:10:28
  * @Description  : file content
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\inc\AppFunc.h
  */
@@ -48,13 +48,14 @@ static void setDefaultAppDataInfo(void);
 static void setDefaultBcuDataInfo(void);
 UINT16 encryptionAlgorithm(UINT16 plainText);
 UINT16 GetErrorNum(UINT16 *ErrorArray, UINT8 Errorlen);
+UINT16 LookRT_u32u16(UINT32 u0);
 UINT8 bcc_chk(UINT8 *data, UINT16 length);
-UINT8 LookUpRTtable(UINT32 R_value);
 UINT8 PutErrorNum(UINT16 *ErrorArray, UINT8 Errorlen, UINT16 ErrorNum);
 UINT8 UDSNegtiveAnswer(UINT8 answerLen, UINT8 messageIndex, UINT32 negCode);
 UINT8 UDSPositiveAnswer(UINT8 answerLen, UINT8 messageIndex, UINT32 posCode);
 void BattLockFunc(void);
 void BattWorkDelayFunc(UINT8 battWorkCurrentState);
+void BmsProtectStateDecode(UINT8 *DischargeProtect, UINT8 *ChargeProtect);
 void CANEncodeFunction(UINT32 ID, UINT8 *msgData);
 void CanMsgTx1000ms(void);
 void ErrorNumHandleFunc(void);
@@ -68,5 +69,4 @@ void relayControlFunc(UINT16 BuzzerPeriod, float DutyRatio);
 void SaveAppConfig(void);
 void SaveAppData(void);
 void SaveBcuData(void);
-void UDS_Service(CAN_Msg_Type *CanRxMsg);
-void BmsProtectStateDecode(UINT8 *DischargeProtect, UINT8 *ChargeProtect);
+void UDS_Service(CAN_Msg_Type *CanRxMsg);

+ 9 - 8
inc/AppSignal.h

@@ -2,7 +2,7 @@
  * @Author       : ChenJie
  * @Date         : 2021-10-14 09:27:15
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-11-12 16:11:45
+ * @LastEditTime : 2021-12-16 11:06:14
  * @Description  : Global variable definition H file
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\inc\AppSignal.h
  */
@@ -14,14 +14,14 @@
 #include "bsp_custom.h"
 #include "lwip_config_ec6160h00.h"
 #include "BCUDisp.h"
-//declear the bool vars
+// declear the bool vars
 extern volatile BOOL NB_Fota_update_flag;
 extern volatile BOOL BMS_Fota_update_flag;
 extern UINT32 ErrFlg;
 
 extern BOOL downloadReady;
 
-//extern declear the UINT8 vars
+// extern declear the UINT8 vars
 extern UINT8 AvgBattTemp;
 extern UINT8 battCellTemp[8];
 extern UINT8 battHeatEnableState;
@@ -70,12 +70,13 @@ extern UINT8 UartCmdRecvFlag;
 extern UINT8 UartErrorFlag;
 extern UINT8 UartInterruptcount;
 extern UINT8 UartRecvFlag;
-extern UINT8 UDSService[2];              //uds 服务
+extern UINT8 UDSService[2];              // uds 服务
 extern UINT8 UDSSubService[2];           // uds 子服务
 extern UINT8 UDSSubServiceActionCode[2]; // uds 子服务状态
 extern UINT8 UDSSwitch;
 extern UINT8 UDSDialogMode;
-//declear the UINT16 vars
+extern UINT8 SysResetFlag;
+// declear the UINT16 vars
 extern UINT16 battCellU[28];
 extern UINT16 battI;
 extern UINT16 battPackVol;
@@ -87,7 +88,7 @@ extern UINT16 ErrorNum[ErrorNumLength];
 extern UINT16 updateDifferDataPackageCounter;
 extern INT16 xyzData[3];
 extern UINT8 otherTempAvg;
-//declear the UINT32 vars
+// declear the UINT32 vars
 extern UINT32 battBalanceoInfo;
 extern UINT32 battProtectState;
 extern UINT32 battWarningState;
@@ -96,7 +97,7 @@ extern UINT32 Battdesigncap;
 extern UINT32 PowerVoltage;
 extern volatile UINT32 TimeCounter;
 
-//declear other vars
+// declear other vars
 extern AppAlgorithmData BcuDataInfo;
 extern AppConfigDataType AppNVMData;
 extern AppDataBody AppDataInfo;
@@ -104,4 +105,4 @@ extern AppSocketConnectionContext socContext; //网络连接状态
 extern osMutexId_t Error_Mutex;
 extern process_app gProcess_app;
 extern QueueHandle_t GpsRecvHandle;
-extern QueueHandle_t UartWriteCmdHandle;
+extern QueueHandle_t UartWriteCmdHandle;

+ 1 - 1
inc/AppTaskControl.h

@@ -30,7 +30,7 @@
 #include "AppSignal.h"
 #include "AppConfig.h"
 #include "hal_module_adapter.h"
-#define PROC_CONTROL_TASK_STACK_SIZE           (1024)
+#define PROC_CONTROL_TASK_STACK_SIZE           (1024+512)
 typedef enum
 {
     PROCESS_CONTROL_STATE_IDLE = 0,

+ 93 - 87
inc/EmbeddedCoder_inc/BCUCal.h

@@ -1,106 +1,112 @@
 
 #include "rtwtypes.h"
-#define cmnc_num_cellUNumMax  28
-#define cmnc_num_modTNumMax  8
-extern const uint16_T blcc_R_esr;                          /* 均衡电阻 */
-extern const uint16_T blcc_T_close;                         /* 均衡暂停温度; */
-extern const uint16_T blcc_T_open;                          /* 均衡暂停恢复温度; */
-extern const uint16_T blcc_V_low;                            /* 均衡开启电压阈值 */
+#define cmnc_num_cellUNumMax 28
+#define cmnc_num_modTNumMax 8
+extern const uint16_T blcc_R_esr;   /* 均衡电阻 */
+extern const uint16_T blcc_T_close; /* 均衡暂停温度; */
+extern const uint16_T blcc_T_open;  /* 均衡暂停恢复温度; */
+extern const uint16_T blcc_V_low;   /* 均衡开启电压阈值 */
 
-extern const uint16_T cmnc_Q_ratedCp;                       /* 电池容量; */
-extern const uint16_T cmnc_num_cellUNum;                     /* 电压采样点实际个数; */
-extern const uint16_T cmnc_num_modTNum;                       /* 温度采样点实际个数; */
-extern const uint16_T cmnc_tm_parkTime;                    /* 静置时间阈值; */
-extern const uint16_T cmnm_F_polar[13]; /* 电池放电参数的C数组; */
-extern const uint16_T cmnm_R_ohm[13];       /* 电池放电参数的Ro数组; */
-extern const uint16_T cmnm_R_polar[13];       /* 电池放电参数的Rp数组; */
-extern const uint16_T cmnm_V_ocv[13];       /* 电池放电参数的OCV数组; */
-extern const uint16_T cmnm_pct_soc[13];                         /* 电池放电参数的SOC数组; */
-extern const uint16_T cmnc_V_chrgFul;                     /* 充满电的截至电压; */
+extern const uint16_T cmnc_Q_ratedCp;                /* 电池容量; */
+extern uint16_T cmnc_num_cellUNum;                   /* 电压采样点实际个数; */
+extern uint16_T cmnc_num_modTNum;                    /* 温度采样点实际个数; */
+extern const uint16_T cmnc_tm_parkTime;              /* 静置时间阈值; */
+extern const uint16_T cmnm_F_polar[13];              /* 电池放电参数的C数组; */
+extern const uint16_T cmnm_R_ohm[13];                /* 电池放电参数的Ro数组; */
+extern const uint16_T cmnm_R_polar[13];              /* 电池放电参数的Rp数组; */
+extern const uint16_T cmnm_V_ocv[13];                /* 电池放电参数的OCV数组; */
+extern const uint16_T cmnm_pct_soc[13];              /* 电池放电参数的SOC数组; */
+extern const uint16_T cmnc_V_chrgFul;                /* 充满电的截至电压; */
+extern const uint16_T cmnm_R_voloffset[28];          /*电压铜牌阻值补偿,单位moh*/
+extern const uint16_T cmnc_V_disChrgLim; 
 
-extern const int16_T sfmc_I_chrgCurrOverThr;                 /* 充电电流阈值 */
-extern const int16_T sfmc_I_disChrgCurrOverThr;              /* 放电电流阈值 */
-extern const int16_T sfmc_T_ACPlugTOverThrFlt1;              /* 慢充插头温度过高1级故障诊断阈值 */
-extern const int16_T sfmc_T_ACPlugTOverThrFlt2;              /* 慢充插头温度过高2级故障诊断阈值 */
-extern const int16_T sfmc_T_ACPlugTOverThrRec1;              /* 慢充插头温度过高1级故障恢复阈值 */
-extern const int16_T sfmc_T_ACPlugTOverThrRec2;              /* 慢充插头温度过高2级故障恢复阈值 */
-extern const int16_T sfmc_T_DCPlugTOverThrFlt1;              /* 快充插头温度过高1级故障诊断阈值 */
-extern const int16_T sfmc_T_DCPlugTOverThrFlt2;              /* 快充插头温度过高2级故障诊断阈值 */
-extern const int16_T sfmc_T_DCPlugTOverThrRec1;              /* 快充插头温度过高1级故障恢复阈值 */
-extern const int16_T sfmc_T_DCPlugTOverThrRec2;              /* 快充插头温度过高2级故障恢复阈值 */
-extern const uint16_T sfmc_T_chrgModTLowThrFlt1;             /* 充电模组温度过低1级故障诊断阈值 */
-extern const uint16_T sfmc_T_chrgModTLowThrFlt2;             /* 充电模组温度过低2级故障诊断阈值 */
-extern const uint16_T sfmc_T_chrgModTLowThrRec1;             /* 充电模组温度过低1级故障恢复阈值 */
-extern const uint16_T sfmc_T_chrgModTLowThrRec2;             /* 充电模组温度过低2级故障恢复阈值 */
-extern const uint16_T sfmc_T_chrgModTOverThrFlt1;            /* 充电模组温度过高1级故障诊断阈值 */
-extern const uint16_T sfmc_T_chrgModTOverThrFlt2;           /* 充电模组温度过高2级故障诊断阈值 */
-extern const uint16_T sfmc_T_chrgModTOverThrRec1;            /* 充电模组温度过高1级故障恢复阈值 */
-extern const uint16_T sfmc_T_chrgModTOverThrRec2;            /* 充电模组温度过高2级故障恢复阈值 */
-extern const int16_T sfmc_T_chrgMosTOverThrFlt1;             /* 充电Mos温度过高1级故障诊断阈值 */
-extern const int16_T sfmc_T_chrgMosTOverThrFlt2;             /* 充电Mos温度过高2级故障诊断阈值 */
-extern const int16_T sfmc_T_chrgMosTOverThrRec1;             /* 充电Mos温度过高1级故障恢复阈值 */
-extern const int16_T sfmc_T_chrgMosTOverThrRec2;             /* 充电Mos温度过高2级故障恢复阈值 */
-extern const uint16_T sfmc_T_disChrgModTLowThrFlt1;          /* 放电模组温度过低1级故障诊断阈值 */
-extern const uint16_T sfmc_T_disChrgModTLowThrFlt2;          /* 放电模组温度过低2级故障诊断阈值 */
-extern const uint16_T sfmc_T_disChrgModTLowThrRec1;          /* 放电模组温度过低1级故障恢复阈值 */
-extern const uint16_T sfmc_T_disChrgModTLowThrRec2;          /* 放电模组温度过低2级故障恢复阈值 */
-extern const uint16_T sfmc_T_disChrgModTOverThrFlt1;         /* 放电模组温度过高1级故障诊断阈值 */
-extern const uint16_T sfmc_T_disChrgModTOverThrFlt2;        /* 放电模组温度过高2级故障诊断阈值 */
-extern const uint16_T sfmc_T_disChrgModTOverThrRec1;         /* 放电模组温度过高1级故障恢复阈值 */
-extern const uint16_T sfmc_T_disChrgModTOverThrRec2;         /* 放电模组温度过高2级故障恢复阈值 */
-extern const int16_T sfmc_T_heatPanTOverThrFlt1;             /* 加热板温度过高1级故障诊断阈值 */
-extern const int16_T sfmc_T_heatPanTOverThrFlt2;             /* 加热板温度过高2级故障诊断阈值 */
-extern const int16_T sfmc_T_heatPanTOverThrRec1;             /* 加热板温度过高1级故障恢复阈值 */
-extern const int16_T sfmc_T_heatPanTOverThrRec2;             /* 加热板温度过高2级故障恢复阈值 */
-extern const int16_T sfmc_T_modTDiffThrFlt1;                  /* 模组温差过大1级故障诊断阈值 */
-extern const int16_T sfmc_T_modTDiffThrFlt2;                  /* 模组温差过大2级故障诊断阈值 */
-extern const int16_T sfmc_T_modTDiffThrRec1;                  /* 模组温差过大1级故障恢复阈值 */
-extern const int16_T sfmc_T_modTDiffThrRec2;                  /* 模组温差过大2级故障恢复阈值 */
-extern const uint16_T sfmc_V_battULowThrFlt1;               /* 总压欠压1级故障诊断阈值 */
-extern const uint16_T sfmc_V_battULowThrFlt2;               /* 总压欠压2级故障诊断阈值 */
-extern const uint16_T sfmc_V_battULowThrRec1;               /* 总压欠压1级故障恢复阈值 */
-extern const uint16_T sfmc_V_battULowThrRec2;               /* 总压欠压2级故障恢复阈值 */
-extern const uint16_T sfmc_V_battUOverThrFlt1;              /* 总压过压1级故障诊断阈值 */
-extern const uint16_T sfmc_V_battUOverThrFlt2;              /* 总压过压2级故障诊断阈值 */
-extern const uint16_T sfmc_V_battUOverThrRec1;              /* 总压过压1级故障恢复阈值 */
-extern const uint16_T sfmc_V_battUOverThrRec2;              /* 总压过压2级故障恢复阈值 */
+
+
+extern const int16_T sfmc_I_chrgCurrOverThr;         /* 充电电流阈值 */
+extern const int16_T sfmc_I_disChrgCurrOverThr;      /* 放电电流阈值 */
+extern const int16_T sfmc_T_ACPlugTOverThrFlt1;      /* 慢充插头温度过高1级故障诊断阈值 */
+extern const int16_T sfmc_T_ACPlugTOverThrFlt2;      /* 慢充插头温度过高2级故障诊断阈值 */
+extern const int16_T sfmc_T_ACPlugTOverThrRec1;      /* 慢充插头温度过高1级故障恢复阈值 */
+extern const int16_T sfmc_T_ACPlugTOverThrRec2;      /* 慢充插头温度过高2级故障恢复阈值 */
+extern const int16_T sfmc_T_DCPlugTOverThrFlt1;      /* 快充插头温度过高1级故障诊断阈值 */
+extern const int16_T sfmc_T_DCPlugTOverThrFlt2;      /* 快充插头温度过高2级故障诊断阈值 */
+extern const int16_T sfmc_T_DCPlugTOverThrRec1;      /* 快充插头温度过高1级故障恢复阈值 */
+extern const int16_T sfmc_T_DCPlugTOverThrRec2;      /* 快充插头温度过高2级故障恢复阈值 */
+extern const uint16_T sfmc_T_chrgModTLowThrFlt1;     /* 充电模组温度过低1级故障诊断阈值 */
+extern const uint16_T sfmc_T_chrgModTLowThrFlt2;     /* 充电模组温度过低2级故障诊断阈值 */
+extern const uint16_T sfmc_T_chrgModTLowThrRec1;     /* 充电模组温度过低1级故障恢复阈值 */
+extern const uint16_T sfmc_T_chrgModTLowThrRec2;     /* 充电模组温度过低2级故障恢复阈值 */
+extern const uint16_T sfmc_T_chrgModTOverThrFlt1;    /* 充电模组温度过高1级故障诊断阈值 */
+extern const uint16_T sfmc_T_chrgModTOverThrFlt2;    /* 充电模组温度过高2级故障诊断阈值 */
+extern const uint16_T sfmc_T_chrgModTOverThrRec1;    /* 充电模组温度过高1级故障恢复阈值 */
+extern const uint16_T sfmc_T_chrgModTOverThrRec2;    /* 充电模组温度过高2级故障恢复阈值 */
+extern const int16_T sfmc_T_chrgMosTOverThrFlt1;     /* 充电Mos温度过高1级故障诊断阈值 */
+extern const int16_T sfmc_T_chrgMosTOverThrFlt2;     /* 充电Mos温度过高2级故障诊断阈值 */
+extern const int16_T sfmc_T_chrgMosTOverThrRec1;     /* 充电Mos温度过高1级故障恢复阈值 */
+extern const int16_T sfmc_T_chrgMosTOverThrRec2;     /* 充电Mos温度过高2级故障恢复阈值 */
+extern const uint16_T sfmc_T_disChrgModTLowThrFlt1;  /* 放电模组温度过低1级故障诊断阈值 */
+extern const uint16_T sfmc_T_disChrgModTLowThrFlt2;  /* 放电模组温度过低2级故障诊断阈值 */
+extern const uint16_T sfmc_T_disChrgModTLowThrRec1;  /* 放电模组温度过低1级故障恢复阈值 */
+extern const uint16_T sfmc_T_disChrgModTLowThrRec2;  /* 放电模组温度过低2级故障恢复阈值 */
+extern const uint16_T sfmc_T_disChrgModTOverThrFlt1; /* 放电模组温度过高1级故障诊断阈值 */
+extern const uint16_T sfmc_T_disChrgModTOverThrFlt2; /* 放电模组温度过高2级故障诊断阈值 */
+extern const uint16_T sfmc_T_disChrgModTOverThrRec1; /* 放电模组温度过高1级故障恢复阈值 */
+extern const uint16_T sfmc_T_disChrgModTOverThrRec2; /* 放电模组温度过高2级故障恢复阈值 */
+extern const int16_T sfmc_T_heatPanTOverThrFlt1;     /* 加热板温度过高1级故障诊断阈值 */
+extern const int16_T sfmc_T_heatPanTOverThrFlt2;     /* 加热板温度过高2级故障诊断阈值 */
+extern const int16_T sfmc_T_heatPanTOverThrRec1;     /* 加热板温度过高1级故障恢复阈值 */
+extern const int16_T sfmc_T_heatPanTOverThrRec2;     /* 加热板温度过高2级故障恢复阈值 */
+extern const int16_T sfmc_T_modTDiffThrFlt1;         /* 模组温差过大1级故障诊断阈值 */
+extern const int16_T sfmc_T_modTDiffThrFlt2;         /* 模组温差过大2级故障诊断阈值 */
+extern const int16_T sfmc_T_modTDiffThrRec1;         /* 模组温差过大1级故障恢复阈值 */
+extern const int16_T sfmc_T_modTDiffThrRec2;         /* 模组温差过大2级故障恢复阈值 */
+extern const uint16_T sfmc_V_battULowThrFlt1;        /* 总压欠压1级故障诊断阈值 */
+extern const uint16_T sfmc_V_battULowThrFlt2;        /* 总压欠压2级故障诊断阈值 */
+extern const uint16_T sfmc_V_battULowThrRec1;        /* 总压欠压1级故障恢复阈值 */
+extern const uint16_T sfmc_V_battULowThrRec2;        /* 总压欠压2级故障恢复阈值 */
+extern const uint16_T sfmc_V_battUOverThrFlt1;       /* 总压过压1级故障诊断阈值 */
+extern const uint16_T sfmc_V_battUOverThrFlt2;       /* 总压过压2级故障诊断阈值 */
+extern const uint16_T sfmc_V_battUOverThrRec1;       /* 总压过压1级故障恢复阈值 */
+extern const uint16_T sfmc_V_battUOverThrRec2;       /* 总压过压2级故障恢复阈值 */
 extern const uint16_T sfmc_V_cellULowThrFlt1;        /* 单体电压欠压1级故障诊断阈值 */
-extern const uint16_T sfmc_V_cellULowThrFlt2;              /* 单体电压欠压2级故障诊断阈值 */
-extern const uint16_T sfmc_V_cellULowThrRec1;              /* 单体电压欠压1级故障恢复阈值 */
-extern const uint16_T sfmc_V_cellULowThrRec2;              /* 单体电压欠压2级故障恢复阈值 */
-extern const uint16_T sfmc_V_cellUOverThrFlt1;             /* 单体电压过压1级故障诊断阈值 */
-extern const uint16_T sfmc_V_cellUOverThrFlt2;             /* 单体电压过压2级故障诊断阈值 */
-extern const uint16_T sfmc_V_cellUOverThrRec1;             /* 单体电压过压1级故障恢复阈值 */
-extern const uint16_T sfmc_V_cellUOverThrRec2;             /* 单体电压过压2级故障恢复阈值 */
-extern const uint16_T sfmc_flg_cellUDiffThrFlt1;            /* 压差过大1级故障诊断阈值 */
-extern const uint16_T sfmc_flg_cellUDiffThrFlt2;            /* 压差过大2级故障诊断阈值 */
-extern const uint16_T sfmc_flg_cellUDiffThrRec1;            /* 压差过大1级故障恢复阈值 */
-extern const uint16_T sfmc_flg_cellUDiffThrRec2;            /* 压差过大2级故障恢复阈值 */
+extern const uint16_T sfmc_V_cellULowThrFlt2;        /* 单体电压欠压2级故障诊断阈值 */
+extern const uint16_T sfmc_V_cellULowThrRec1;        /* 单体电压欠压1级故障恢复阈值 */
+extern const uint16_T sfmc_V_cellULowThrRec2;        /* 单体电压欠压2级故障恢复阈值 */
+extern const uint16_T sfmc_V_cellUOverThrFlt1;       /* 单体电压过压1级故障诊断阈值 */
+extern const uint16_T sfmc_V_cellUOverThrFlt2;       /* 单体电压过压2级故障诊断阈值 */
+extern const uint16_T sfmc_V_cellUOverThrRec1;       /* 单体电压过压1级故障恢复阈值 */
+extern const uint16_T sfmc_V_cellUOverThrRec2;       /* 单体电压过压2级故障恢复阈值 */
+extern const uint16_T sfmc_flg_cellUDiffThrFlt1;     /* 压差过大1级故障诊断阈值 */
+extern const uint16_T sfmc_flg_cellUDiffThrFlt2;     /* 压差过大2级故障诊断阈值 */
+extern const uint16_T sfmc_flg_cellUDiffThrRec1;     /* 压差过大1级故障恢复阈值 */
+extern const uint16_T sfmc_flg_cellUDiffThrRec2;     /* 压差过大2级故障恢复阈值 */
 extern const uint16_T sfmc_T_disChrgMosTOverThrFlt1;
 extern const uint16_T sfmc_T_disChrgMosTOverThrRec1;
 extern const uint16_T sfmc_T_disChrgMosTOverThrFlt2;
 extern const uint16_T sfmc_T_disChrgMosTOverThrRec2;
 
-extern const uint16_T sohc_Q_countThr;                       /*                    */
-extern const uint16_T sohc_Q_updateDeltThr;                 /*                    */
+extern const uint16_T sohc_Q_countThr;      /*                    */
+extern const uint16_T sohc_Q_updateDeltThr; /*                    */
 extern const uint16_T sohc_pct_low;
 extern const uint16_T sohc_pct_up;
 
+extern const int16_T sopc_I_currUp;
+extern const int16_T sopc_I_currLow;
 
-extern const uint16_T socc_pct_battSocLow;                    /* SOC下限值; */
-extern const uint16_T socc_pct_battSocUp;                  /* SOC上限值; */
-extern const int16_T socm_I_chrgCor[4];   /* 充电CCV对应的电流数据; */
-extern const int16_T socm_I_disChrgCor[3]; /* 放电CCV对应的电流数据; */
-extern const uint16_T socm_V_chrgCor[4];/* 充电CCV对应的电压; */
+
+extern const uint16_T socc_pct_battSocLow;  /* SOC下限值; */
+extern const uint16_T socc_pct_battSocUp;   /* SOC上限值; */
+extern const int16_T socm_I_chrgCor[4];     /* 充电CCV对应的电流数据; */
+extern const int16_T socm_I_disChrgCor[3];  /* 放电CCV对应的电流数据; */
+extern const uint16_T socm_V_chrgCor[4];    /* 充电CCV对应的电压; */
 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 tmsc_T_openThr;                         /* 热管理开启温度; */
-extern const uint16_T tmsc_T_closeMinThr;                     /* 热管理关闭温度(最低模组); */
-extern const uint16_T tmsc_T_closeMaxThr;                     /* 热管理开启温度(最高模组); */
+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; /* 热管理关闭温度(最低模组); */
+extern const uint16_T tmsc_T_closeMaxThr; /* 热管理开启温度(最高模组); */

+ 43 - 8
inc/EmbeddedCoder_inc/BCUDisp.h

@@ -5,6 +5,20 @@
 extern uint16_T appv_V_cellU[cmnc_num_cellUNumMax];                        /* 静态电压 */
 extern uint8_T appd_st_preCyc;
 
+extern boolean_T  spmd_flg_firstRun;
+extern boolean_T  socd_flg_firstRun;
+extern boolean_T  sohd_flg_firstRun;
+extern boolean_T  blcd_flg_firstRun;
+extern boolean_T  sord_flg_firstRun;
+extern boolean_T  soed_flg_firstRun;
+extern boolean_T  iscd_flg_firstRun;
+extern boolean_T  pimd_flg_firstRun;
+extern boolean_T  sfmd_flg_firstRun;
+extern boolean_T  tmsd_flg_firstRun;
+extern boolean_T  cdmd_flg_firstRun;
+extern boolean_T  cmd_flg_firstRun;
+extern boolean_T sopd_flg_firstRun;
+
 extern uint16_T blcv_Q_reqCpEi[cmnc_num_cellUNumMax];                      /*均衡需求容量 读取量(数组); */
 extern uint16_T blcv_Q_reqCpEo[cmnc_num_cellUNumMax];                      /*均衡需求容量 写入量(数组); */
 extern uint32_T blcv_Q_totalCpEi[cmnc_num_cellUNumMax];                    /*累计均衡容量 读取量(数组); */
@@ -52,6 +66,7 @@ extern boolean_T ihd_st_relayControl;
 extern uint8_T ihd_st_heatForceControl;
 extern uint8_T ihd_st_EOLState;
 extern boolean_T ihd_flg_urtRecFlg;
+extern uint8_T ihd_st_reSet;
 
 extern int16_T sfmd_I_curr;                              /*处理后整包电流 */
 extern uint16_T sfmd_T_modTMax;                          /*处理后模组温度最小 */
@@ -84,6 +99,7 @@ extern boolean_T sfmd_flg_heatRunFltEo;
 extern boolean_T sfmd_flg_iscFltEi;
 extern boolean_T sfmd_flg_iscFltEo;
 
+extern uint16_T socd_pct_vcuSoc;                          /*vcuSOC; */
 extern uint16_T socd_pct_ahSoc;                          /*安时SOC; */
 extern uint16_T socd_pct_estSoc;                         /*估算SOC;*/
 extern uint16_T socd_flg_EEsave;                         /*实时存储标志位;*/
@@ -115,6 +131,19 @@ extern uint16_T sohv_Q_packCapArrEo[10];                 /*10次整包容量(
 extern uint16_T sohv_V_chrgStartStatEi[cmnc_num_cellUNumMax];              /*充电开始时刻的单体电压(数组)读取量; */
 extern uint16_T sohv_V_chrgStartStatEo[cmnc_num_cellUNumMax];              /*充电开始时刻的单体电压(数组)写入量; */
 
+extern uint16_T soed_E_nowEng;
+extern uint16_T soed_pct_nowStat;
+extern uint16_T soed_E_fullEng;
+
+extern uint16_T sopd_P_chrgPMax;
+extern uint16_T sopd_P_disChrgPMax;
+extern int16_T sopd_I_chrgCurrMax;
+extern int16_T sopd_I_disChrgCurrMax;
+
+extern uint16_T sorv_ohm_cellREi[cmnc_num_cellUNumMax];
+extern uint16_T sorv_ohm_cellREo[cmnc_num_cellUNumMax];
+extern uint16_T sorv_ohm_cellR[cmnc_num_cellUNumMax];
+
 extern boolean_T iscd_flg_flt;
 extern uint16_T iscv_Q_remainCpEi[cmnc_num_cellUNumMax];
 extern uint32_T iscd_tm_totalEi;
@@ -128,18 +157,24 @@ extern uint8_T cmd_st_chrgSt;                            /* 充电状态  */
 extern int16_T cmd_I_chrgCurrReq;                       /* 充电需求电流  */
 extern uint8_T cmd_idx_chrgEndReason;                    /* 充电结束原因  */
 
-extern uint16_T cand_Nr_cellNr;                          /*循环发送的单体编号; */
+extern uint16_T cand_idx_cellNr;                          /*循环发送的单体编号; */
 extern uint16_T cand_Q_cellCap;                          /*循环发送的单体容量; */
 extern uint16_T cand_V_chrgStartStat;                    /*循环发送的充电前单体电压; */
-extern uint16_T cand_Q_reqCp;                            /*循环发送的单体需求均衡容量; */
-extern uint16_T cand_Q_totalCp;                          /*循环发送的单体累计均衡容量; */
+extern uint16_T cand_Q_blcReqCp;                            /*循环发送的单体需求均衡容量; */
+extern uint16_T cand_Q_blcTotalCp;                          /*循环发送的单体累计均衡容量; */
 
 extern int16_T  cdmv_V_deltOCV[cmnc_num_cellUNumMax];
 extern int16_T  cdmv_ohm_deltR[cmnc_num_cellUNumMax];
 extern boolean_T cdmd_flg_deltOCVDisable;
 
-extern uint16_T test_efkSocMin;
-extern uint16_T test_efkSocMax;
-extern real_T test_UpMin;
-extern real_T test_UpMax;
-
+extern uint16_T pimd_V_ocv;
+extern uint16_T pimd_R_ohm;
+extern uint16_T pimd_R_polar;
+extern uint16_T pimd_F_polar;
+
+extern uint16_T test_cellCap[cmnc_num_cellUNumMax];
+extern uint16_T test_countEn;
+extern int16_T test_deltU;
+
+
+


+ 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);

+ 1 - 1
inc/EmbeddedCoder_inc/CDM.h

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

+ 2 - 3
inc/EmbeddedCoder_inc/CM.h

@@ -2,10 +2,9 @@
 #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);
+

+ 2 - 2
inc/EmbeddedCoder_inc/ISC.h

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

+ 9 - 0
inc/EmbeddedCoder_inc/PIM.h

@@ -0,0 +1,9 @@
+#include "rtwtypes.h"
+#include <math.h>
+#include "BCUCal.h"
+#include "BCUDisp.h"
+#include "funlib.h"
+
+extern void PIM_Init(void);
+extern void PIM(void);
+

+ 2 - 4
inc/EmbeddedCoder_inc/SFM.h

@@ -2,7 +2,7 @@
 #include "BCUCal.h"
 #include "BCUDisp.h"
 #include <math.h>
-extern boolean_T FirstRun_SFM;
+#include "funlib.h"
 
 extern void SFM_Init(void);
 extern void SFM(void);
@@ -111,6 +111,4 @@ typedef struct
     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);
+

+ 4 - 3
inc/EmbeddedCoder_inc/SOC.h

@@ -1,12 +1,13 @@
 
 #include <math.h>
+#include <numeric.h>
 #include "BCUCal.h"
 #include "BCUDisp.h"
-extern boolean_T FirstRun_SOC;
+#include "funlib.h"
+
 extern void SOC_Init(void);
 extern void SOC(void);
 //
 extern real_T docvmath(real_T soc );
-extern uint16_T SOC_LookUp(uint16_T battsoc, uint16_T x[3], uint16_T y[3]);
-extern uint16_T SOCfitSystem(uint16_T SOC,uint16_T *SOCfit, uint16_T m);
+
 

+ 7 - 0
inc/EmbeddedCoder_inc/SOE.h

@@ -0,0 +1,7 @@
+#include "BCUCal.h"
+#include "BCUDisp.h"
+#include "funlib.h"
+
+extern void SOE_Init(void);
+extern void SOE(void);
+

+ 3 - 3
inc/EmbeddedCoder_inc/SOH.h

@@ -1,8 +1,8 @@
 #include "BCUCal.h"
 #include "BCUDisp.h"
-extern boolean_T FirstRun_SOH;
+#include "funlib.h"
+
 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);
+

+ 9 - 0
inc/EmbeddedCoder_inc/SOP.h

@@ -0,0 +1,9 @@
+#include <math.h>
+#include "BCUCal.h"
+#include "BCUDisp.h"
+#include "funlib.h"
+
+extern void SOP_Init(void);
+extern void SOP(void);
+extern void predSystem(real_T ocv,real_T Ro,real_T Rp,real_T RC,real_T sopn_I_currPred,real_T sopn_V_up,real_T *sopn_pct_socPred10,real_T *sopn_V_battPred10);
+

+ 6 - 0
inc/EmbeddedCoder_inc/SOR.h

@@ -0,0 +1,6 @@
+#include "BCUCal.h"
+#include "BCUDisp.h"
+#include "funlib.h"
+extern void SOR_Init(void);
+extern void SOR(void);
+

+ 4 - 4
inc/EmbeddedCoder_inc/SPM.h

@@ -5,10 +5,10 @@
 #include "SOC.h"
 #include "BLC.h"
 #include "CDM.h"
-
-
-
-extern boolean_T FirstRun_SPM;
+#include "SOE.h"
+#include "SOR.h"
+#include "PIM.h"
+#include "SOP.h"
 
 extern void SPM_Init(void);
 extern void SPM(void);

+ 22 - 0
inc/EmbeddedCoder_inc/funlib.h

@@ -0,0 +1,22 @@
+#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 real_T Saturation_r(real_T in,real_T LowLim,real_T UpLim);
+extern uint16_T Saturation_u(uint16_T in,uint16_T LowLim,uint16_T UpLim);
+
+extern uint16_T  DataFilt(uint16_T in, uint16_T *out, uint16_T Lim);
+extern uint8_T DataFilt8(uint8_T in, uint8_T *out, uint8_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]
- */

Файловите разлики са ограничени, защото са твърде много
+ 231 - 222
src/AppFunc.c


+ 35 - 34
src/AppSignal.c

@@ -3,7 +3,7 @@
  * @Date         : 2021-10-14 09:27:15
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-11-12 16:11:30
+ * @LastEditTime : 2021-12-16 11:06:25
  * @Description  : Global variable definition c file,此文件存放App使用到的全局变量
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AppSignal.c
  */
@@ -19,73 +19,74 @@ BOOL downloadReady = FALSE;
 
 /**declear the uint8 vars**/
 UINT8 AvgBattTemp = 0;
-UINT8 battCellTemp[8] = {0};            //Battery temperature 电池温度数值
-UINT8 battHeatEnableState = 0x00;       //bms加热使能状态
-UINT8 battMOSSwitchState = 0x00;        //bms开关状态
+UINT8 battCellTemp[8] = {0};            // Battery temperature 电池温度数值
+UINT8 battHeatEnableState = 0x00;       // bms加热使能状态
+UINT8 battMOSSwitchState = 0x00;        // bms开关状态
 UINT8 battSOC = 0;                      //电池SOC
 UINT8 battSOH = 0;                      //电池SOH
 UINT8 battWorkState = 0x00;             //电池工作状态
 UINT8 BattWorkStateDelay = 0;           //电池工作状态(延时处理后的)
-UINT8 bmsHwVersion = 0;                 //bms硬件版本
-UINT8 bmsSwVersion = 0;                 //bms软件版本
+UINT8 bmsHwVersion = 0;                 // bms硬件版本
+UINT8 bmsSwVersion = 0;                 // bms软件版本
 UINT8 BMSupdatestatus = 0xFF;           //保护板更新状态 0xFF表示未更新,00表示更新成功,c表示校验不过
 UINT8 BuzzerControl = 0;                //蜂鸣器控制状态
-UINT8 CanMsgEnble = 0;                  //Can send status Can中断状态
+UINT8 CanMsgEnble = 0;                  // Can send status Can中断状态
 UINT8 ChargeForbiddenControl = 0x00;    //充电禁止控制
 UINT8 chargerConnectState = 0x00;       //充电器连接状态
 UINT8 DisChargeForbiddenControl = 0x00; //放电禁止控制
 UINT8 fastChargeTemp = 0;               // fast charge plug temprature  快充插头温度
-UINT8 GpsFlag = 0;                      //GPS 数据有效标志位
+UINT8 GpsFlag = 0;                      // GPS 数据有效标志位
 UINT8 HeatForceControl = 0;             //加热强制控制使能
-UINT8 heatTemp1 = 0;                    //Heating plate1 temperature    加热板温度1
-UINT8 heatTemp2 = 0;                    //Heating plate2 temperature    加热板温度2
-UINT8 Lockstatus = 0;                   //Interlock status 高压互锁状态
+UINT8 heatTemp1 = 0;                    // Heating plate1 temperature    加热板温度1
+UINT8 heatTemp2 = 0;                    // Heating plate2 temperature    加热板温度2
+UINT8 Lockstatus = 0;                   // Interlock status 高压互锁状态
 UINT8 maxCellTemp = 0;                  //最高单体温度
 UINT8 minCellTemp = 0;                  //最低单体温度
-UINT8 MOSTemp = 0;                      //mos temprature mos温度
+UINT8 MOSTemp = 0;                      // mos temprature mos温度
 UINT8 nbReservedTemp1 = 0;              //
 UINT8 nbReservedTemp2 = 0;              //
 UINT8 normalChargeTemp = 0;             // normal charge plug temprature    慢充插头温度
-UINT8 packTemp = 0;                     //battery pack temprature   电池箱体温度
+UINT8 packTemp = 0;                     // battery pack temprature   电池箱体温度
 UINT8 PadInterrupt = 0x00;              //每个bit代表一个中断标志
 UINT8 PosFlag = 0;                      //定位信息是否有效标志位
 UINT8 RelayForbiddenControl = 0x00;     //继电器禁止控制
 UINT8 RelayForceControl = 0x00;         //继电器强制控制
-UINT8 reservedSignal1 = 0;              //can信息保留信号1
-UINT8 reservedSignal2 = 0;              //can信息保留信号2
-UINT8 reservedSignal3 = 0;              //can信息保留信号3
-UINT8 reservedSignal4 = 0;              //can信息保留信号4
-UINT8 reservedSignal5 = 0;              //can信息保留信号5
-UINT8 reservedSignal6 = 0;              //can信息保留信号6
-UINT8 reservedSignal7 = 0;              //can信息保留信号7
-UINT8 reservedSignal8 = 0;              //can信息保留信号8
-UINT8 TcpErrorcount = 0;                //Error count TCP联网错误计数
-UINT8 TcpSendLen = 0;                   //Tcp send status Tcp发送状态
-UINT8 TCPWorkState = 0;                 //Tcp工作状态,0-表示发送,1-表示应答,2-表示监听以及心跳发送
-UINT8 UartCmdRecvFlag = 0;              //Uart控制应答回复
-UINT8 UartErrorFlag = 0;                //Uart故障标志位0表示正常,1表示故障
-UINT8 UartRecvFlag = 0;                 //Uart收到消息标志位0表示未收到,1表示收到
-UINT8 UDSService[2] = {0};              //uds 服务
+UINT8 reservedSignal1 = 0;              // can信息保留信号1
+UINT8 reservedSignal2 = 0;              // can信息保留信号2
+UINT8 reservedSignal3 = 0;              // can信息保留信号3
+UINT8 reservedSignal4 = 0;              // can信息保留信号4
+UINT8 reservedSignal5 = 0;              // can信息保留信号5
+UINT8 reservedSignal6 = 0;              // can信息保留信号6
+UINT8 reservedSignal7 = 0;              // can信息保留信号7
+UINT8 reservedSignal8 = 0;              // can信息保留信号8
+UINT8 TcpErrorcount = 0;                // Error count TCP联网错误计数
+UINT8 TcpSendLen = 0;                   // Tcp send status Tcp发送状态
+UINT8 TCPWorkState = 0;                 // Tcp工作状态,0-表示发送,1-表示应答,2-表示监听以及心跳发送
+UINT8 UartCmdRecvFlag = 0;              // Uart控制应答回复
+UINT8 UartErrorFlag = 0;                // Uart故障标志位0表示正常,1表示故障
+UINT8 UartRecvFlag = 0;                 // Uart收到消息标志位0表示未收到,1表示收到
+UINT8 UDSService[2] = {0};              // uds 服务
 UINT8 UDSSubService[2] = {0};           // uds 子服务
 UINT8 UDSSubServiceActionCode[2] = {0}; // uds 子服务状态
 UINT8 UDSSwitch = 0;                    //下线检测标志位
 UINT8 UartInterruptcount = 0;           //串口中断累加值
-UINT8 UDSDialogMode = 01;               //UDS诊断模式
+UINT8 UDSDialogMode = 01;               // UDS诊断模式
+UINT8 SysResetFlag = 0;
 /**declear the uint16 vars**/
 UINT16 avrgCellVol = 0;                    //平均单体电压
 UINT16 battCellU[28] = {0};                //电池包单体电压
 UINT16 battI = 0;                          //电池总电流
 UINT16 battPackVol = 0;                    //电池总压
-UINT16 ErrorNum[ErrorNumLength] = {0};     //Error array,故障数组
+UINT16 ErrorNum[ErrorNumLength] = {0};     // Error array,故障数组
 UINT16 maxCellVol = 0;                     //最大单体电压
 UINT16 minCellVol = 0;                     //最小单体电压
 UINT16 nbHwVersion = 0;                    //数据模块硬件状态
 UINT16 updateDifferDataPackageCounter = 0; //差分包升级计数器
-INT16 xyzData[3] = {0};                    //xyz三轴数据
+INT16 xyzData[3] = {0};                    // xyz三轴数据
 UINT8 otherTempAvg = 0;
 /**declear the uint32 vars**/
 UINT32 battBalanceoInfo = 0; //电池均衡状态
-UINT32 Battdesigncap = 0;    //battery design cap 电池包设计容量
+UINT32 Battdesigncap = 0;    // battery design cap 电池包设计容量
 UINT32 battProtectState = 0; //电池保护状态
 UINT32 battWarningState = 0; //电池告警状态
 UINT32 nbSwVersion = 0;      // 数据模块软件状态
@@ -95,7 +96,7 @@ volatile UINT32 TimeCounter = 0x00; //主任务定时器计数
 /**declear the Handle vars**/
 osMutexId_t Error_Mutex = NULL;          //故障互锁句柄
 QueueHandle_t GpsRecvHandle = NULL;      //定位信息队列句柄
-QueueHandle_t UartWriteCmdHandle = NULL; //Uart写命令队列句柄
+QueueHandle_t UartWriteCmdHandle = NULL; // Uart写命令队列句柄
 
 /**declear other vars**/
 
@@ -105,4 +106,4 @@ AppAlgorithmData BcuDataInfo;
 
 AppSocketConnectionContext socContext = {-1, 0}; //网络连接状态
 
-process_app gProcess_app; //全局工作状态
+process_app gProcess_app; //全局工作状态

+ 18 - 17
src/AppTaskControl.c

@@ -41,7 +41,7 @@ static void ControlTask(void *arg)
         }
         case PROCESS_CONTROL_STATE_WORK:
         {
-            osDelayUntil(100);
+            osDelay(10);
             if (CurrentTime != TimeCounter)
             {
                 UINT16 Buzzerperiod = 400;
@@ -81,19 +81,20 @@ static void ControlTask(void *arg)
                 {
                     AdcIndex = 0;
                 }
+
+                if (gProcess_app != WORK)
+                {
+                    NetSocDisplay(LED_SOC_0, LED_TURN_OFF);
+                    NetSocDisplay(LED_SOC_1, LED_TURN_OFF);
+                    NetSocDisplay(LED_SOC_2, LED_TURN_OFF);
+                    NetSocDisplay(LED_SOC_3, LED_TURN_OFF);
+                    FaultDisplay(LED_TURN_OFF);
+                    PROC_CONTROL_STATE_SWITCH(PROCESS_CONTROL_STATE_SLEEP);
+                    break;
+                }
+                //临时故障诊断函数--改为模型诊断
+                ErrorNumHandleFunc();
             }
-            if (gProcess_app != WORK)
-            {
-                NetSocDisplay(LED_SOC_0, LED_TURN_OFF);
-                NetSocDisplay(LED_SOC_1, LED_TURN_OFF);
-                NetSocDisplay(LED_SOC_2, LED_TURN_OFF);
-                NetSocDisplay(LED_SOC_3, LED_TURN_OFF);
-                FaultDisplay(LED_TURN_OFF);
-                PROC_CONTROL_STATE_SWITCH(PROCESS_CONTROL_STATE_SLEEP);
-                break;
-            }
-            //临时故障诊断函数--改为模型诊断
-            ErrorNumHandleFunc();
             break;
         }
         case PROCESS_CONTROL_STATE_SLEEP:
@@ -144,19 +145,19 @@ void GetAdcValue(UINT8 num)
     {
     case FAST_CHARGE_TEMP:
         NB_ADC_Get(&adcValue, FAST_CHARGE_TEMP);
-        fastChargeTemp = LookUpRTtable(adcValue);
+        fastChargeTemp = (UINT8)LookRT_u32u16(adcValue);
         break;
     case NORMAL_CHARGE_TEMP:
         NB_ADC_Get(&adcValue, NORMAL_CHARGE_TEMP);
-        normalChargeTemp = LookUpRTtable(adcValue);
+        normalChargeTemp = (UINT8)LookRT_u32u16(adcValue);
         break;
     case OTHER_TEMP_1:
         NB_ADC_Get(&adcValue, OTHER_TEMP_1);
-        heatTemp1 = LookUpRTtable(adcValue);
+        heatTemp1 = (UINT8)LookRT_u32u16(adcValue);
         break;
     case OTHER_TEMP_2:
         NB_ADC_Get(&adcValue, OTHER_TEMP_2);
-        heatTemp2 = LookUpRTtable(adcValue);
+        heatTemp2 = (UINT8)LookRT_u32u16(adcValue);
         break;
     case VBAT:
         NB_ADC_Get(&adcValue, VBAT);

+ 15 - 5
src/AppTaskMain.c

@@ -3,7 +3,7 @@
  * @Date         : 2021-10-14 09:27:15
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-11-12 16:03:37
+ * @LastEditTime : 2021-12-14 11:33:29
  * @Description  : 主要负责:1.工作模式转换2.定时器定时3.定时保存运行数据4.异常状态重启
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AppTaskMain.c
  */
@@ -51,6 +51,12 @@ static void MainTask(void *arg)
     slpManRegisterUsrdefinedRestoreCb(appAfterSlp2, NULL, SLPMAN_SLEEP2_STATE);
     slpManWakeSrc_e Wakeup_source;
     Wakeup_source = slpManGetWakeupSrc(); //获取唤醒源
+    LastResetState_e LastResetReasonNum;
+    LastResetReasonNum = appGetLastResetReason();
+    SysResetFlag = 1;
+#ifdef DEBUGLOG
+    Debug_printf("[%d,%d,%d]\n", Wakeup_source, AppDataInfo.SysReStartCount, LastResetReasonNum);
+#endif
     //配置文件及运行数据加载
     if (Error_Mutex == NULL)
     {
@@ -101,15 +107,15 @@ static void MainTask(void *arg)
                 NVIC_EnableIRQ(PadWakeup1_IRQn);
                 UartInterruptcount = 0;
                 PadInterrupt_clrCounter = 0;
+                SysResetFlag = 0;
                 PROC_MAIN_STATE_SWITCH(PROCESS_STATE_LISTEN);
                 break;
             }
             if ((BMS_Fota_update_flag != FALSE) || (TCPWorkState != 0x00) || (BattWorkStateDelay != BATT_IDLE_SYM) || (battWorkState != BATT_IDLE_SYM) || (PadInterrupt != 0x00) || (AvgBattTemp >= (45 + 40)))
             {
                 xTimerReset(work_timer, 0);
-                PadInterrupt = 0x00;
             }
-            if ((TcpErrorcount >= 10 && getbit(PadInterrupt, 0) == 0x00 && battWorkState != BATT_CHARGE_SYM) || (NB_Fota_update_flag == TRUE))
+            if ((TcpErrorcount >= 100 && getbit(PadInterrupt, 0) == 0x00 && battWorkState != BATT_CHARGE_SYM) || (NB_Fota_update_flag == TRUE))
             {
                 AppDataInfo.appDataModify = true;
                 AppDataInfo.SysReStartCount = AppDataInfo.SysReStartCount + 1;
@@ -129,7 +135,11 @@ static void MainTask(void *arg)
                 osDelay(1000);
                 EC_SystemReset();
             }
-            if (BcuDataInfo.appDataModify) //BCU数据实时保存
+            if (PadInterrupt != 0x00)
+            {
+                PadInterrupt = 0x00;
+            }
+            if (BcuDataInfo.appDataModify) // BCU数据实时保存
             {
                 SaveBcuData();
             }
@@ -153,7 +163,7 @@ static void MainTask(void *arg)
                     PadInterrupt_clrCounter = PadInterrupt_clrCounter + 1;
                 }
             }
-            else if ((getbit(PadInterrupt, 1) == 0x00 && PadInterrupt != 0x00))
+            else if (PadInterrupt != 0x00)
             {
                 PadInterrupt_clrCounter = PadInterrupt_clrCounter + 1;
             }

+ 88 - 89
src/AppTaskTcp.c

@@ -42,11 +42,6 @@ static void TcpTask(void *arg)
         TcpRecvHandle = osMessageQueueNew(3, sizeof(TcpipConnectionRecvDataInd *), NULL);
     }
     osDelay(5000); //等待驻网延时5s
-    slpManWakeSrc_e Wakeup_source;
-    Wakeup_source = slpManGetWakeupSrc(); //获取唤醒源
-#ifdef DEBUGLOG
-    Debug_printf("[%d,%d]\n", Wakeup_source, AppDataInfo.SysReStartCount);
-#endif
     while (true)
     {
         osDelay(100);
@@ -217,15 +212,15 @@ static void TcpTask(void *arg)
                 break;
             }
             free(queueItem);
-        } //if
-    }     //while 循环
+        } // if
+    }     // while 循环
 }
 /***********************************************************************************************************************
  * 网络组包发送函数
  * 输入:空
  * 输出:空
  * 处理:将相关信息组包之后进行按一定频率发送,每次调用间隔为1s
-***********************************************************************************************************************/
+ ***********************************************************************************************************************/
 static void TcpDataInfoAssembleSend()
 {
     OsaUtcTimeTValue TimeStracture;
@@ -236,7 +231,7 @@ static void TcpDataInfoAssembleSend()
     UINT16 DataLen = 0;
     UINT8 BattSendFreq = 30;
     UINT8 GpsSendFreq = 30;
-    UINT8 DebugFeq = 10;
+    UINT8 DebugFeq = 10; // zhengchao 20211128 10-> 1 just for test
     UINT16 year;
     UINT8 month, day, hour, minute, sec;
     UTC8TimeType UTC8TimeTcp;
@@ -249,24 +244,28 @@ static void TcpDataInfoAssembleSend()
     {
         BattSendFreq = AppDataInfo.BattInfoSendFreqLow;
         GpsSendFreq = AppDataInfo.PosInfoSendFreqLow;
+        DebugFeq = BattSendFreq;
         break;
     }
     case BATT_CHARGE_SYM:
     {
         BattSendFreq = AppDataInfo.BattInfoSendFreqHigh;
         GpsSendFreq = AppDataInfo.PosInfoSendFreqLow;
+        DebugFeq = BattSendFreq;
         break;
     }
     case BATT_DISCHARGE_SYM:
     {
         BattSendFreq = AppDataInfo.BattInfoSendFreqNomal;
         GpsSendFreq = AppDataInfo.PosInfoSendFreqHigh;
+        DebugFeq = 1;
         break;
     }
     default:
     {
         BattSendFreq = AppDataInfo.BattInfoSendFreqNomal;
         GpsSendFreq = AppDataInfo.PosInfoSendFreqNormal;
+        DebugFeq = BattSendFreq;
         break;
     }
     }
@@ -279,7 +278,6 @@ static void TcpDataInfoAssembleSend()
             clrbit(PadInterrupt, 4);
         }
     }
-    DebugFeq = BattSendFreq;
     if (send_counter % BattSendFreq == 0 && send_counter != 0)
     {
         UINT16 ErrorTemp = 0x00;
@@ -304,24 +302,24 @@ static void TcpDataInfoAssembleSend()
         *(SendBuffer + 1) = TCP_START_SYM2;                                  //起始码-2
         *(SendBuffer + 2) = TCP_CMD_SYM;                                     //命令标识-3
         *(SendBuffer + 3) = TCP_ANS_SYM;                                     //应答标识-4
-        memcpy(SendBuffer + 4, AppNVMData.battSN, BATT_SN_LEN);              //SN码 5-21
+        memcpy(SendBuffer + 4, AppNVMData.battSN, BATT_SN_LEN);              // SN码 5-21
         *(SendBuffer + 21) = TCP_ENCPT_DISABLE;                              //加密方式-22
         DataLen = ProtocolFixedLen + ProtocolFluctedLen - ProtocolHeaderLen; //电池信息单元协议固定长度
         *(SendBuffer + 22) = (DataLen >> 8) & 0xFF;                          //数据长度H-23
         *(SendBuffer + 23) = DataLen & 0xFF;                                 //数据长度L-24
-        *(SendBuffer + 24) = (UTC8TimeTcp.year - 0x07D0) & 0xFF;             //year-25
-        *(SendBuffer + 25) = UTC8TimeTcp.month & 0xFF;                       //month-26
-        *(SendBuffer + 26) = UTC8TimeTcp.day & 0xFF;                         //day-27
-        *(SendBuffer + 27) = UTC8TimeTcp.hour & 0xFF;                        //hour-28
-        *(SendBuffer + 28) = UTC8TimeTcp.minute & 0xFF;                      //mins-29
-        *(SendBuffer + 29) = UTC8TimeTcp.second & 0xFF;                      //sec-30
+        *(SendBuffer + 24) = (UTC8TimeTcp.year - 0x07D0) & 0xFF;             // year-25
+        *(SendBuffer + 25) = UTC8TimeTcp.month & 0xFF;                       // month-26
+        *(SendBuffer + 26) = UTC8TimeTcp.day & 0xFF;                         // day-27
+        *(SendBuffer + 27) = UTC8TimeTcp.hour & 0xFF;                        // hour-28
+        *(SendBuffer + 28) = UTC8TimeTcp.minute & 0xFF;                      // mins-29
+        *(SendBuffer + 29) = UTC8TimeTcp.second & 0xFF;                      // sec-30
         *(SendBuffer + 30) = BATTMSG;                                        //电池信息发送-31
-        *(SendBuffer + 31) = (UTC8TimeTcp.year - 0x07D0) & 0xFF;             //year-32
-        *(SendBuffer + 32) = UTC8TimeTcp.month & 0xFF;                       //month-33
-        *(SendBuffer + 33) = UTC8TimeTcp.day & 0xFF;                         //day-34
-        *(SendBuffer + 34) = UTC8TimeTcp.hour & 0xFF;                        //hour-35
-        *(SendBuffer + 35) = UTC8TimeTcp.minute & 0xFF;                      //mins-36
-        *(SendBuffer + 36) = UTC8TimeTcp.second & 0xFF;                      //sec-37
+        *(SendBuffer + 31) = (UTC8TimeTcp.year - 0x07D0) & 0xFF;             // year-32
+        *(SendBuffer + 32) = UTC8TimeTcp.month & 0xFF;                       // month-33
+        *(SendBuffer + 33) = UTC8TimeTcp.day & 0xFF;                         // day-34
+        *(SendBuffer + 34) = UTC8TimeTcp.hour & 0xFF;                        // hour-35
+        *(SendBuffer + 35) = UTC8TimeTcp.minute & 0xFF;                      // mins-36
+        *(SendBuffer + 36) = UTC8TimeTcp.second & 0xFF;                      // sec-37
         *(SendBuffer + 37) = csq;                                            //信号强度-38
         *(SendBuffer + 38) = sfmd_st_fltLevel;                               //故障等级-39
         if (osOK == osMutexAcquire(Error_Mutex, 100))
@@ -341,9 +339,9 @@ static void TcpDataInfoAssembleSend()
         *(SendBuffer + 44) = battPackVol & 0xFF;            //电压-45
         *(SendBuffer + 45) = battPackVol >> 8;              //电压-46
         *(SendBuffer + 46) = battPackVol & 0xFF;            //电压-47
-        *(SendBuffer + 47) = battMOSSwitchState;            //mos状态-48
-        *(SendBuffer + 48) = (UINT8)(socd_pct_bcuSoc / 10); //soc-49
-        *(SendBuffer + 49) = (UINT8)(sohd_pct_bcuSoh / 10); //soh-50
+        *(SendBuffer + 47) = battMOSSwitchState;            // mos状态-48
+        *(SendBuffer + 48) = (UINT8)(socd_pct_vcuSoc / 10); // soc-49
+        *(SendBuffer + 49) = (UINT8)(sohd_pct_bcuSoh / 10); // soh-50
         *(SendBuffer + 50) = (battBalanceoInfo >> 24) & 0xFF;
         *(SendBuffer + 51) = (battBalanceoInfo >> 16) & 0xFF;
         *(SendBuffer + 52) = (battBalanceoInfo >> 8) & 0xFF;
@@ -359,7 +357,7 @@ static void TcpDataInfoAssembleSend()
         *(SendBuffer + 56 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount) = battWorkState;                                                                                       //电池工作状态
         *(SendBuffer + 57 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount) = battHeatEnableState;                                                                                 //电池加热使能
         *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount) = BMS_OTHER_TEMP + NB_OTHER_TEMP_NUM;                                                                  //其他温度个数
-        *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 1) = MOSTemp;                                                                                         //mos温度
+        *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 1) = MOSTemp;                                                                                         // mos温度
         *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 2) = packTemp;                                                                                        //环境温度
         *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 3) = fastChargeTemp;                                                                                  //快充温度
         *(SendBuffer + 58 + AppDataInfo.BattCellCount * 2 + AppDataInfo.BattTempCount + 4) = normalChargeTemp;                                                                                //慢充温度
@@ -409,21 +407,21 @@ static void TcpDataInfoAssembleSend()
         GpsToTcpInfo.cmdSymbol = TCP_CMD_SYM;
         GpsToTcpInfo.ansSymbol = TCP_ANS_SYM;
         memcpy(GpsToTcpInfo.SN, AppNVMData.battSN, BATT_SN_LEN);
-        GpsToTcpInfo.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
+        GpsToTcpInfo.encryptMethod = TCP_ENCPT_DISABLE; // not encrypt
         GpsToTcpInfo.dataLength[0] = (DataLen >> 8) & 0xFF;
         GpsToTcpInfo.dataLength[1] = DataLen & 0xFF;
-        GpsToTcpInfo.gpsInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; //year
-        GpsToTcpInfo.gpsInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;           //month
-        GpsToTcpInfo.gpsInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;             //day
-        GpsToTcpInfo.gpsInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;            //hour
-        GpsToTcpInfo.gpsInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;          //mins
-        GpsToTcpInfo.gpsInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF;          //sec
+        GpsToTcpInfo.gpsInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; // year
+        GpsToTcpInfo.gpsInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;           // month
+        GpsToTcpInfo.gpsInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;             // day
+        GpsToTcpInfo.gpsInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;            // hour
+        GpsToTcpInfo.gpsInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;          // mins
+        GpsToTcpInfo.gpsInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF;          // sec
         GpsToTcpInfo.gpsInfo.msgMark = GPSMSG;
-        GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; //year
-        GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF;           //month
-        GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF;             //day
-        GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;            //hour
-        GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;          //mins
+        GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; // year
+        GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF;           // month
+        GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF;             // day
+        GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;            // hour
+        GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;          // mins
         GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[5] = UTC8TimeTcp.second & 0xFF;
         osStatus_t ret = osMessageQueueGet(GpsRecvHandle, (UINT8 *)&GpsRecvData, 0, 1000);
         if (ret == 0)
@@ -508,21 +506,21 @@ static void TcpDataInfoAssembleSend()
         VerMsgToTcpInfo.cmdSymbol = TCP_CMD_SYM;
         VerMsgToTcpInfo.ansSymbol = TCP_ANS_SYM;
         memcpy(VerMsgToTcpInfo.SN, AppNVMData.battSN, BATT_SN_LEN);
-        VerMsgToTcpInfo.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
+        VerMsgToTcpInfo.encryptMethod = TCP_ENCPT_DISABLE; // not encrypt
         VerMsgToTcpInfo.dataLength[0] = (DataLen >> 8) & 0xFF;
         VerMsgToTcpInfo.dataLength[1] = DataLen & 0xFF;
-        VerMsgToTcpInfo.VerInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; //year
-        VerMsgToTcpInfo.VerInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;           //month
-        VerMsgToTcpInfo.VerInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;             //day
-        VerMsgToTcpInfo.VerInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;            //hour
-        VerMsgToTcpInfo.VerInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;          //mins
-        VerMsgToTcpInfo.VerInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF;          //sec
+        VerMsgToTcpInfo.VerInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; // year
+        VerMsgToTcpInfo.VerInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;           // month
+        VerMsgToTcpInfo.VerInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;             // day
+        VerMsgToTcpInfo.VerInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;            // hour
+        VerMsgToTcpInfo.VerInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;          // mins
+        VerMsgToTcpInfo.VerInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF;          // sec
         VerMsgToTcpInfo.VerInfo.msgMark = VERSIONMSG;
-        VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; //year
-        VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF;           //month
-        VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF;             //day
-        VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;            //hour
-        VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;          //mins
+        VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; // year
+        VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF;           // month
+        VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF;             // day
+        VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;            // hour
+        VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;          // mins
         VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[5] = UTC8TimeTcp.second & 0xFF;
         memcpy(VerMsgToTcpInfo.VerInfo.ICCID, iccid, 20);
         memcpy(VerMsgToTcpInfo.VerInfo.IMEI, imei, 15);
@@ -573,21 +571,22 @@ static void TcpDataInfoAssembleSend()
         static UINT8 Debugcounter = 0;
         if (Debugcounter % 5 == 0)
         {
-            sprintf((char *)rbuf, "A-%x,%d,%d,%x,%x,,%d,%d",
+            sprintf((char *)rbuf, "A-%x,%d,%d,%x,%x,,%d,%d,,%d",
                     battProtectState, AppDataInfo.RelayControl, chargerConnectState, BMSupdatestatus, PadInterrupt,
-                    AppDataInfo.ExpiryTimeArray[1], AppDataInfo.ExpiryTimeArray[2]);
+                    AppDataInfo.ExpiryTimeArray[1], AppDataInfo.ExpiryTimeArray[2], SysResetFlag);
         }
         else
         {
-            INT16 temp = cdmv_ohm_deltR[0];
-            for (UINT8 i = 0; i < cmnc_num_cellUNum; i++)
-            {
-                temp = max(temp, cdmv_ohm_deltR[i]);
-            }
-            sprintf((char *)rbuf, "B-%d,%d,%d,%d,%d,%d,%d,%d,%d,,\
-                                %d,%d,%d",
-                    socd_pct_ahSoc, socd_pct_ekfSoc, socd_pct_estSoc, socd_pct_battSoc, socd_pct_bcuSoc, battSOC * 10, socd_pct_cellBattSoc, sohv_Q_packCapArrEo[9], temp,
-                    battI - 10000, maxCellVol, minCellVol);
+            sprintf((char *)rbuf, "B-%d,%d,%d,%d,%d,%d,%d,,\
+                                %d,%d,%d,%d,%d,,\
+                                %d,%d,%d,%d,%d,%d,,\
+                                %d,%d,%d,%d,%d,,\
+                                %d,%d,%d,%d",
+                    socd_pct_ahSoc, socd_pct_ekfSoc, socd_pct_battSoc, socd_pct_vcuSoc, socd_pct_cellBattSoc, sohv_Q_packCapArrEo[9], cdmv_ohm_deltR[cand_idx_cellNr - 1],
+                    sfmd_I_curr, maxCellVol, minCellVol, sfmd_V_cellUAvrg, sfmv_V_cellU[1],
+                    cand_idx_cellNr, cand_Q_cellCap, cand_V_chrgStartStat, ihd_tm_parkTime, sohd_Q_chrgEo, sohd_flg_chrgEndEo,
+                    pimd_V_ocv, pimd_R_ohm, pimd_R_polar, pimd_F_polar,test_deltU,
+                    sopd_I_chrgCurrMax,sopd_P_chrgPMax,sopd_I_disChrgCurrMax,sopd_P_disChrgPMax);
         }
         Debugcounter++;
         if (Debugcounter > 100)
@@ -611,15 +610,15 @@ static void TcpDataInfoAssembleSend()
         DebugMsgInfo.cmdSymbol = TCP_CMD_SYM;
         DebugMsgInfo.ansSymbol = TCP_ANS_SYM;
         memcpy(DebugMsgInfo.SN, AppNVMData.battSN, BATT_SN_LEN);
-        DebugMsgInfo.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
+        DebugMsgInfo.encryptMethod = TCP_ENCPT_DISABLE; // not encrypt
         DebugMsgInfo.dataLength[0] = (DataLen >> 8) & 0xFF;
         DebugMsgInfo.dataLength[1] = DataLen & 0xFF;
-        DebugMsgInfo.DebugInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; //year
-        DebugMsgInfo.DebugInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;           //month
-        DebugMsgInfo.DebugInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;             //day
-        DebugMsgInfo.DebugInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;            //hour
-        DebugMsgInfo.DebugInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;          //mins
-        DebugMsgInfo.DebugInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF;          //sec
+        DebugMsgInfo.DebugInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; // year
+        DebugMsgInfo.DebugInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;           // month
+        DebugMsgInfo.DebugInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;             // day
+        DebugMsgInfo.DebugInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;            // hour
+        DebugMsgInfo.DebugInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;          // mins
+        DebugMsgInfo.DebugInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF;          // sec
         DebugMsgInfo.DebugInfo.msgMark = DEBUGMSG;
         DebugMsgInfo.DebugInfo.DebugLen[0] = BufferLen >> 8;
         DebugMsgInfo.DebugInfo.DebugLen[1] = BufferLen;
@@ -676,15 +675,15 @@ static void TcpDataInfoAssembleSend()
         DebugMsgInfo.cmdSymbol = TCP_CMD_SYM;
         DebugMsgInfo.ansSymbol = TCP_ANS_SYM;
         memcpy(DebugMsgInfo.SN, AppNVMData.battSN, BATT_SN_LEN);
-        DebugMsgInfo.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
+        DebugMsgInfo.encryptMethod = TCP_ENCPT_DISABLE; // not encrypt
         DebugMsgInfo.dataLength[0] = (DataLen >> 8) & 0xFF;
         DebugMsgInfo.dataLength[1] = DataLen & 0xFF;
-        DebugMsgInfo.DebugInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; //year
-        DebugMsgInfo.DebugInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;           //month
-        DebugMsgInfo.DebugInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;             //day
-        DebugMsgInfo.DebugInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;            //hour
-        DebugMsgInfo.DebugInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;          //mins
-        DebugMsgInfo.DebugInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF;          //sec
+        DebugMsgInfo.DebugInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; // year
+        DebugMsgInfo.DebugInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;           // month
+        DebugMsgInfo.DebugInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;             // day
+        DebugMsgInfo.DebugInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;            // hour
+        DebugMsgInfo.DebugInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;          // mins
+        DebugMsgInfo.DebugInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF;          // sec
         DebugMsgInfo.DebugInfo.msgMark = DEBUGMSG;
         DebugMsgInfo.DebugInfo.DebugLen[0] = BufferLen >> 8;
         DebugMsgInfo.DebugInfo.DebugLen[1] = BufferLen;
@@ -727,7 +726,7 @@ static void TcpHeartDataSend()
     HeartMsgToTcp.cmdSymbol = TCP_HEART_SYM;
     HeartMsgToTcp.ansSymbol = TCP_ANS_SYM;
     memcpy(HeartMsgToTcp.SN, AppNVMData.battSN, BATT_SN_LEN);
-    HeartMsgToTcp.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
+    HeartMsgToTcp.encryptMethod = TCP_ENCPT_DISABLE; // not encrypt
     HeartMsgToTcp.dataLength[0] = 0;
     HeartMsgToTcp.dataLength[1] = 0;
     HeartMsgToTcp.CRC = bcc_chk((UINT8 *)&HeartMsgToTcp, sizeof(HeartMsgToTcp) - 1);
@@ -774,7 +773,7 @@ static void TcpDataInfoRecvHandle()
                 {
                     Fota_Func(Ptr, socContext.id);
                 }
-                else if (*(Ptr + 30) == 0x88) //BMS远程升级数据传输命令
+                else if (*(Ptr + 30) == 0x88) // BMS远程升级数据传输命令
                 {
                     Fota_Func(Ptr, socContext.id);
                 }
@@ -787,13 +786,13 @@ static void TcpDataInfoRecvHandle()
                     TcpCmdAnswer[23] = 0x06;
                     memcpy(&TcpCmdAnswer[24], (Ptr + 24), 6);
                     TcpCmdAnswer[30] = bcc_chk(TcpCmdAnswer, 30);
-                    if (*(Ptr + 31) == 0x01) //0x01代表锁定
+                    if (*(Ptr + 31) == 0x01) // 0x01代表锁定
                     {
                         AppDataInfo.appDataModify = TRUE;
                         AppDataInfo.UserLock = TRUE;
                         tcpipConnectionSend(socContext.id, TcpCmdAnswer, 31, 0, 0, 0);
                     }
-                    else if (*(Ptr + 31) == 0x02) //0x02代表解锁
+                    else if (*(Ptr + 31) == 0x02) // 0x02代表解锁
                     {
                         AppDataInfo.appDataModify = TRUE;
                         AppDataInfo.UserLock = FALSE;
@@ -810,7 +809,7 @@ static void TcpDataInfoRecvHandle()
                     TcpCmdAnswer[23] = 0x06;
                     memcpy(&TcpCmdAnswer[24], (Ptr + 24), 6);
                     TcpCmdAnswer[30] = bcc_chk(TcpCmdAnswer, 30);
-                    if (*(Ptr + 31) == 0x01) //0x01代表断开
+                    if (*(Ptr + 31) == 0x01) // 0x01代表断开
                     {
 
                         AppDataInfo.appDataModify = TRUE;
@@ -821,7 +820,7 @@ static void TcpDataInfoRecvHandle()
                         AppDataInfo.BattForceLock = TRUE;
                         tcpipConnectionSend(socContext.id, TcpCmdAnswer, 31, 0, 0, 0);
                     }
-                    else if (*(Ptr + 31) == 0x00) //0x00代表关闭
+                    else if (*(Ptr + 31) == 0x00) // 0x00代表关闭
                     {
                         AppDataInfo.appDataModify = TRUE;
                         if (RelayForceControl == 0)
@@ -842,12 +841,12 @@ static void TcpDataInfoRecvHandle()
                     TcpCmdAnswer[23] = 0x06;
                     memcpy(&TcpCmdAnswer[24], (Ptr + 24), 6);
                     TcpCmdAnswer[30] = bcc_chk(TcpCmdAnswer, 30);
-                    if (*(Ptr + 31) == 0x01) //0x01代表断开
+                    if (*(Ptr + 31) == 0x01) // 0x01代表断开
                     {
                         BuzzerControl = TRUE;
                         tcpipConnectionSend(socContext.id, TcpCmdAnswer, 31, 0, 0, 0);
                     }
-                    else if (*(Ptr + 31) == 0x00) //0x00代表关闭
+                    else if (*(Ptr + 31) == 0x00) // 0x00代表关闭
                     {
                         BuzzerControl = FALSE;
                         tcpipConnectionSend(socContext.id, TcpCmdAnswer, 31, 0, 0, 0);
@@ -904,7 +903,7 @@ static void TcpDataInfoRecvHandle()
     }
     TcpRecvData = NULL;
 }
-//Tcp线程初始化
+// Tcp线程初始化
 void AppTaskTcpInit(void *arg)
 {
     osThreadAttr_t task_attr;
@@ -924,7 +923,7 @@ void AppTaskTcpDeInit(void *arg)
     osThreadTerminate(TcpTaskId);
     TcpTaskId = NULL;
 }
-//Tcp 状态转换函数
+// Tcp 状态转换函数
 static void sendQueueMsg(UINT32 msgId, UINT32 xTickstoWait)
 {
     eventCallbackMessage_t *queueMsg = NULL;
@@ -938,7 +937,7 @@ static void sendQueueMsg(UINT32 msgId, UINT32 xTickstoWait)
         }
     }
 }
-//Tcp状态注册函数
+// Tcp状态注册函数
 static INT32 socketRegisterPSUrcCallback(urcID_t eventID, void *param, UINT32 paramLen)
 {
     CmiSimImsiStr *imsi = NULL;
@@ -959,7 +958,7 @@ static INT32 socketRegisterPSUrcCallback(urcID_t eventID, void *param, UINT32 pa
     }
     case NB_URC_ID_MM_SIGQ:
     {
-//rssi = *(UINT8 *)param;
+// rssi = *(UINT8 *)param;
 #ifdef USING_PRINTF1
         printf("RSSI signal=%d\n", rssi);
 #endif
@@ -999,7 +998,7 @@ static INT32 socketRegisterPSUrcCallback(urcID_t eventID, void *param, UINT32 pa
     }
     return 0;
 }
-//Tcpz连接状态回调函数
+// Tcpz连接状态回调函数
 static void socketAppConnectionCallBack(UINT8 connectionEventType, void *bodyEvent)
 {
     switch (connectionEventType)

+ 155 - 144
src/EmbeddedCoder_src/BCU.c

@@ -26,166 +26,176 @@ void BCU(void)
             RecvCounter++;
             osDelay(1000);
         }
-        //printf("RecvCounter:%d\n ",RecvCounter);
+        // printf("RecvCounter:%d\n ",RecvCounter);
     }
-    
+
     PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
     while (TRUE)
     {
         switch (gProcess_Bcu_Task)
         {
-            //=========================初始化===============================
-            case PROCESS_STATE_INIT:
-            {
-                BCU_Init();
-                memcpy(blcv_Q_totalCpEi, BcuDataInfo.blcv_Q_totalCpE, sizeof(blcv_Q_totalCpEi));
-                memcpy(blcv_Q_reqCpEi, BcuDataInfo.blcv_Q_reqCpE, sizeof(blcv_Q_reqCpEi));
-                socd_pct_bcuSocEi = BcuDataInfo.socd_pct_bcuSocE;
-                socd_pct_battSocEi = BcuDataInfo.socd_pct_battSocE;
-                sohd_tm_chrgStartStatEi = BcuDataInfo.sohd_tm_chrgStartStatE;
-                sohd_flg_chrgEndEi = BcuDataInfo.sohd_flg_chrgEndE;
-                memcpy(sohv_V_chrgStartStatEi, BcuDataInfo.sohv_V_chrgStartStatE, sizeof(sohv_V_chrgStartStatEi));
-                sohd_Q_chrgEi = BcuDataInfo.sohd_Q_chrgE;
-                memcpy(sohv_Q_packCapArrEi, BcuDataInfo.sohv_Q_packCapArrE, sizeof(sohv_Q_packCapArrEi));
-                memcpy(sohv_Q_cellCapArrEi, BcuDataInfo.sohv_Q_cellCapArrE, sizeof(sohv_Q_cellCapArrEi));
-                memcpy((iscv_Q_remainCpEi), BcuDataInfo.iscv_Q_remainCpEE, sizeof(iscv_Q_remainCpEi));
-                iscd_tm_totalEi = BcuDataInfo.iscd_tm_totalEE;
-                sfmd_flg_mainCirClosFltEi = BcuDataInfo.sfmd_flg_mainCirClosFltE;
-                sfmd_flg_heatCirClosFltEi = BcuDataInfo.sfmd_flg_heatCirClosFltE;
-                sfmd_flg_heatCirOpenFltEi = BcuDataInfo.sfmd_flg_heatCirOpenFltE;
-                sfmd_flg_heatRunFltEi = BcuDataInfo.sfmd_flg_heatRunFltE;
-                sfmd_flg_iscFltEi = BcuDataInfo.sfmd_flg_iscFltEE;
-                ihd_st_EOLState = AppNVMData.EOLState;
-                
-                
-                PROC_BCU_STATE_SWITCH(PROCESS_STATE_WORK);
-                break;
-            }
-            //============================工作模式==========================
-            case PROCESS_STATE_WORK:
+        //=========================初始化===============================
+        case PROCESS_STATE_INIT:
+        {
+            BCU_Init();
+            cmnc_num_cellUNum = AppDataInfo.BattCellCount; /* 电压采样点实际个数; */
+            cmnc_num_modTNum = AppDataInfo.BattTempCount;  /* 温度采样点实际个数; */
+            memcpy(blcv_Q_totalCpEi, BcuDataInfo.blcv_Q_totalCpE, sizeof(blcv_Q_totalCpEi));
+            memcpy(blcv_Q_reqCpEi, BcuDataInfo.blcv_Q_reqCpE, sizeof(blcv_Q_reqCpEi));
+            socd_pct_bcuSocEi = BcuDataInfo.socd_pct_bcuSocE;
+            socd_pct_battSocEi = BcuDataInfo.socd_pct_battSocE;
+            sohd_tm_chrgStartStatEi = BcuDataInfo.sohd_tm_chrgStartStatE;
+            sohd_flg_chrgEndEi = BcuDataInfo.sohd_flg_chrgEndE;
+            memcpy(sohv_V_chrgStartStatEi, BcuDataInfo.sohv_V_chrgStartStatE, sizeof(sohv_V_chrgStartStatEi));
+            sohd_Q_chrgEi = BcuDataInfo.sohd_Q_chrgE;
+            memcpy(sohv_Q_packCapArrEi, BcuDataInfo.sohv_Q_packCapArrE, sizeof(sohv_Q_packCapArrEi));
+            memcpy(sohv_Q_cellCapArrEi, BcuDataInfo.sohv_Q_cellCapArrE, sizeof(sohv_Q_cellCapArrEi));
+            memcpy(iscv_Q_remainCpEi, BcuDataInfo.iscv_Q_remainCpE, sizeof(iscv_Q_remainCpEi));
+            memcpy(sorv_ohm_cellREi, BcuDataInfo.sorv_ohm_cellRE, sizeof(sorv_ohm_cellREi));
+            iscd_tm_totalEi = BcuDataInfo.iscd_tm_totalE;
+            sfmd_flg_mainCirClosFltEi = BcuDataInfo.sfmd_flg_mainCirClosFltE;
+            sfmd_flg_heatCirClosFltEi = BcuDataInfo.sfmd_flg_heatCirClosFltE;
+            sfmd_flg_heatCirOpenFltEi = BcuDataInfo.sfmd_flg_heatCirOpenFltE;
+            sfmd_flg_heatRunFltEi = BcuDataInfo.sfmd_flg_heatRunFltE;
+            sfmd_flg_iscFltEi = BcuDataInfo.sfmd_flg_iscFltE;
+            ihd_tm_parkTime = BcuDataInfo.ihd_tm_parkTimeE;
+            ihd_st_EOLState = AppNVMData.EOLState;
+            appd_st_preCyc = 1;
+            PROC_BCU_STATE_SWITCH(PROCESS_STATE_WORK);
+            break;
+        }
+        //============================工作模式==========================
+        case PROCESS_STATE_WORK:
+        {
+            while (TRUE)
             {
-                 while (TRUE)
-                 {
-                      if (UartRecvFlag == 1 || RecvCounter >= 15)
-                      {
-                           RecvCounter = 0;
-                           break;
-                       }
-                      else
-                     {
-                          RecvCounter++;
-                          osDelay(1000);
-                     }
-                 }
-			
-                while (TRUE)
-                {   			    
-                    if (TimeCounter % 10 == 0)
-                    {
-                        if (gProcess_app == LISTEN)
-                        {
-                            PROC_BCU_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                            break;
-                        }
-                        //
-                        
-                        //数据获取
-                        ihd_I_curr = (int16_T)(-(battI - 10000));
-                        memcpy(ihv_V_cellU, battCellU, sizeof(battCellU));
-                        for (i = 0; i < cmnc_num_modTNum; i++)
-                        {
-                            ihv_T_modT[i] = battCellTemp[i];
-                        }
-                        ihd_T_mosT = MOSTemp;
-                        ihd_T_DCPlugT = fastChargeTemp;
-                        ihd_T_ACPlugT = normalChargeTemp;
-                        ihd_T_heatPanT1 = heatTemp1;
-                        ihd_T_heatPanT2 = heatTemp2;
-                        ihd_pct_soc = battSOC * 10;
-                        ihd_pct_soh = battSOH * 10;
-                        ihd_flg_HVILFlt = Lockstatus;
-                        ihd_st_workStat = BattWorkStateDelay;
-                        ihd_flg_urtRecFlt = UartErrorFlag;
-                        ihd_flg_urtRecFlg = UartRecvFlag;
-                        ihd_st_chrgConnect = chargerConnectState;
-                        ihd_flg_cellULowFlt = ((battWarningState)&0x01) == 1;
-                        ihd_flg_battULowFlt = ((battWarningState >> 1) & 0x01) == 1;
-                        ihd_flg_cellUOverFlt = ((battWarningState >> 2) & 0x01) == 1;
-                        ihd_flg_battUOverFlt = ((battWarningState >> 3) & 0x01) == 1;
-                        ihd_flg_disChrgCurrOverFlt = ((battWarningState >> 4) & 0x01) == 1;
-                        ihd_flg_chrgCurrOverFlt = ((battWarningState >> 5) & 0x01) == 1;
-                        ihd_flg_disChrgModTOverFlt = ((battWarningState >> 6) & 0x01) == 1;
-                        ihd_flg_chrgModTOverFlt = ((battWarningState >> 7) & 0x01) == 1;
-                        ihd_flg_chrgMosTOverFlt = ((battWarningState >> 11) & 0x01) == 1;
-                        ihd_flg_disChrgMosClosFlt = ((battWarningState >> 18) & 0x01) == 1;
-                        ihd_flg_chrgMosClosFlt = ((battWarningState >> 19) & 0x01) == 1;
-                        ihd_flg_disChrgModTLowFlt = ((battWarningState >> 22) & 0x01) == 1;
-                        ihd_flg_chrgModTLowFlt = ((battWarningState >> 23) & 0x01) == 1;
-                        ihd_flg_currOpenFlt = 0;
-                        ihd_st_heatForceControl = HeatForceControl;
-                        ihd_st_chrgMosControl = ChargeForbiddenControl == 0;
-                        ihd_st_disChrgMosControl = DisChargeForbiddenControl == 0;
-                        ihd_st_relayControl = RelayForbiddenControl == 0;
-                        //ihd_flg_DTCClear = 1;   //////clear
-                        //调用算法
-                        SFM();
-                        TMS();
-                        CM();
-                        SPM();
-                        ISC();
-                        //实时存储
-                        if (socd_flg_EEsave == 1 || ihd_flg_DTCClear)
-                        {
-                            BCUEEDataSave();
-                            ihd_flg_DTCClear = false;
-                        }
-
-						//
-                        if (BattWorkStateDelay == 0 && battI == 10000)
-                        {
-                            memcpy(appv_V_cellU, battCellU, sizeof(appv_V_cellU));
-                        }
-                        
-                        if (ihd_tm_parkTime >= cmnc_tm_parkTime && battI == 10000)
-                        {
-                            appd_st_preCyc = 1 ;
-                        }
-                        else
-                        {
-                            appd_st_preCyc = 0;
-                        }
-     
-                    }
-                    osDelay(100);
+                if (UartRecvFlag == 1 || RecvCounter >= 15)
+                {
+                    RecvCounter = 0;
+                    break;
+                }
+                else
+                {
+                    RecvCounter++;
+                    osDelay(1000);
                 }
-                break;
             }
-            //======================休眠模式===============================
-            case PROCESS_STATE_SLEEP:
+
+            while (TRUE)
             {
-                BCUEEDataSave();
-                ihd_tm_parkTime = 0;
-                while (TRUE)
+                if (TimeCounter % 10 == 0)
                 {
-                    if (TimeCounter % 10 == 0)
+                    if (gProcess_app == LISTEN)
+                    {
+                        PROC_BCU_STATE_SWITCH(PROCESS_STATE_SLEEP);
+                        break;
+                    }
+                    // printf("time:%d\n",ihd_tm_parkTime);
+                    //
+		
+                    //数据获取
+                    ihd_st_reSet = SysResetFlag;
+                    ihd_I_curr = (int16_T)(-(battI - 10000));
+                    memcpy(ihv_V_cellU, battCellU, sizeof(battCellU));
+                    for (i = 0; i < cmnc_num_modTNum; i++)
                     {
-                        ihd_tm_parkTime++;
-                       
+                        ihv_T_modT[i] = battCellTemp[i];
                     }
-                    if (gProcess_app == WORK)
+                    ihd_T_mosT = MOSTemp;
+                    ihd_T_DCPlugT = fastChargeTemp;
+                    ihd_T_ACPlugT = normalChargeTemp;
+                    ihd_T_heatPanT1 = heatTemp1;
+                    ihd_T_heatPanT2 = heatTemp2;
+                    ihd_pct_soc = battSOC * 10;
+                    ihd_pct_soh = battSOH * 10;
+                    ihd_flg_HVILFlt = Lockstatus;
+                    ihd_st_workStat = BattWorkStateDelay;
+                    ihd_flg_urtRecFlt = UartErrorFlag;
+                    ihd_flg_urtRecFlg = UartRecvFlag;
+                    ihd_st_chrgConnect = chargerConnectState;
+                    ihd_flg_cellULowFlt = ((battWarningState)&0x01) == 1;
+                    ihd_flg_battULowFlt = ((battWarningState >> 1) & 0x01) == 1;
+                    ihd_flg_cellUOverFlt = ((battWarningState >> 2) & 0x01) == 1;
+                    ihd_flg_battUOverFlt = ((battWarningState >> 3) & 0x01) == 1;
+                    ihd_flg_disChrgCurrOverFlt = ((battWarningState >> 4) & 0x01) == 1;
+                    ihd_flg_chrgCurrOverFlt = ((battWarningState >> 5) & 0x01) == 1;
+                    ihd_flg_disChrgModTOverFlt = ((battWarningState >> 6) & 0x01) == 1;
+                    ihd_flg_chrgModTOverFlt = ((battWarningState >> 7) & 0x01) == 1;
+                    ihd_flg_chrgMosTOverFlt = ((battWarningState >> 11) & 0x01) == 1;
+                    ihd_flg_disChrgMosClosFlt = ((battWarningState >> 18) & 0x01) == 1;
+                    ihd_flg_chrgMosClosFlt = ((battWarningState >> 19) & 0x01) == 1;
+                    ihd_flg_disChrgModTLowFlt = ((battWarningState >> 22) & 0x01) == 1;
+                    ihd_flg_chrgModTLowFlt = ((battWarningState >> 23) & 0x01) == 1;
+                    ihd_flg_currOpenFlt = 0;
+                    ihd_st_heatForceControl = HeatForceControl;
+                    ihd_st_chrgMosControl = ChargeForbiddenControl == 0;
+                    ihd_st_disChrgMosControl = DisChargeForbiddenControl == 0;
+                    ihd_st_relayControl = RelayForbiddenControl == 0;
+                    // ihd_flg_DTCClear = 1;   //////clear
+                    //调用算法
+                    SFM();
+                    TMS();
+                    CM();
+                    SPM();
+                    ISC();
+                    //实时存储
+                    if (socd_flg_EEsave == 1 || ihd_flg_DTCClear)
                     {
-                        PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
-                        break;
+                        BCUEEDataSave();
+                        ihd_flg_DTCClear = false;
                     }
-                    osDelay(100);
+
+                    //
+                    if (BattWorkStateDelay == 0 && battI == 10000)
+                    {
+                        memcpy(appv_V_cellU, sfmv_V_cellU, sizeof(sfmv_V_cellU));
+                    }
+
+                    if (ihd_tm_parkTime < cmnc_tm_parkTime || battI != 10000)
+                    {
+                        appd_st_preCyc = 0;
+                    }
+
+                    BcuDataInfo.ihd_tm_parkTimeE = 0;
+                    BcuDataInfo.appDataModify = TRUE;
                 }
-                break;
+                osDelay(100);
             }
-            default:
+            break;
+        }
+        //======================休眠模式===============================
+        case PROCESS_STATE_SLEEP:
+        {
+            BCUEEDataSave();
+            ihd_tm_parkTime = 0;
+            while (TRUE)
             {
-                PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
-                break;
+                if (TimeCounter % 10 == 0)
+                {
+                    ihd_tm_parkTime++;
+                    //printf("time:%d\n",ihd_tm_parkTime);
+                }
+                if (TimeCounter % 1000 == 0)
+                {
+                    BcuDataInfo.ihd_tm_parkTimeE = ihd_tm_parkTime;
+                    BcuDataInfo.appDataModify = TRUE;
+                }
+                if (gProcess_app == WORK)
+                {
+                    BcuDataInfo.ihd_tm_parkTimeE = ihd_tm_parkTime;
+                    BcuDataInfo.appDataModify = TRUE;
+                    PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
+                    break;
+                }
+                osDelay(100);
             }
+            break;
+        }
+        default:
+        {
+            PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
+            break;
+        }
         }
     }
 }
@@ -227,12 +237,13 @@ void BCUEEDataSave(void)
     BcuDataInfo.sohd_Q_chrgE = sohd_Q_chrgEo;
     memcpy(BcuDataInfo.sohv_Q_packCapArrE, sohv_Q_packCapArrEo, sizeof(sohv_Q_packCapArrEo));
     memcpy(BcuDataInfo.sohv_Q_cellCapArrE, sohv_Q_cellCapArrEo, sizeof(sohv_Q_cellCapArrEo));
-    memcpy(BcuDataInfo.iscv_Q_remainCpEE, iscv_Q_remainCpEo, sizeof(iscv_Q_remainCpEo));
-    BcuDataInfo.iscd_tm_totalEE = iscd_tm_totalEo;
+    memcpy(BcuDataInfo.iscv_Q_remainCpE, iscv_Q_remainCpEo, sizeof(iscv_Q_remainCpEo));
+    memcpy(BcuDataInfo.sorv_ohm_cellRE, sorv_ohm_cellREo, sizeof(sorv_ohm_cellREo));
+    BcuDataInfo.iscd_tm_totalE = iscd_tm_totalEo;
     BcuDataInfo.sfmd_flg_mainCirClosFltE = sfmd_flg_mainCirClosFltEo;
     BcuDataInfo.sfmd_flg_heatCirClosFltE = sfmd_flg_heatCirClosFltEo;
     BcuDataInfo.sfmd_flg_heatCirOpenFltE = sfmd_flg_heatCirOpenFltEo;
     BcuDataInfo.sfmd_flg_heatRunFltE = sfmd_flg_heatRunFltEo;
-    BcuDataInfo.sfmd_flg_iscFltEE = sfmd_flg_iscFltEo;
+    BcuDataInfo.sfmd_flg_iscFltE = sfmd_flg_iscFltEo;
     BcuDataInfo.appDataModify = TRUE;
 }

+ 65 - 53
src/EmbeddedCoder_src/BCUCal.c

@@ -6,48 +6,55 @@ const uint16_T blcc_T_close = 125U; /* 均衡暂停温度; */
 const uint16_T blcc_T_open = 100U;  /* 均衡暂停恢复温度; */
 const uint16_T blcc_V_low = 10U;    /* 均衡开启电压阈值 */
 
-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 cmnc_V_chrgFul = 4200U;                                                                                                   /* 充满电的截至电压; */
+const uint16_T cmnc_Q_ratedCp = 500U;                                                                                                      /* 电池容量; */
+uint16_T cmnc_num_cellUNum = 20U;                                                                                                          /* 电压采样点实际个数; */
+uint16_T cmnc_num_modTNum = 4U;                                                                                                            /* 温度采样点实际个数; */
+const uint16_T cmnc_tm_parkTime = 1800U;                                                                                                   /* 静置时间阈值; */
+const uint16_T cmnm_F_polar[13] = {5708U, 10079U, 18901U, 24298U, 25621U, 24240U, 26329U, 29043U, 23753U, 25286U, 25622U, 25968U, 28782U}; /* 电池放电参数的RC数组; */
+const uint16_T cmnm_R_ohm[13] = {2364U, 2284U, 2234U, 2166U, 2128U, 2111U, 2090U, 2077U, 2077U, 2072U, 2085U, 2090U, 2077U};               /* 电池放电参数的Ro数组; */
+const uint16_T cmnm_R_polar[13] = {4955U, 2073U, 1504U, 1197U, 1098U, 1072U, 1141U, 1700U, 1637U, 1626U, 1496U, 1486U, 1436U};             /* 电池放电参数的Rp数组; */
+const uint16_T cmnm_V_ocv[13] = {3327U, 3453U, 3487U, 3563U, 3617U, 3652U, 3700U, 3791U, 3897U, 4006U, 4129U, 4197U, 4276U};               /* 电池放电参数的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_disChrgLim = 2900U;
+const uint16_T cmnc_V_chrgFul = 4200U; /* 充满电的截至电压; */
+const uint16_T cmnm_R_voloffset[28] = {0, 0, 0, 0, 0,
+                                       0, 770, 0, 0, 0,
+                                       0, 0, 0, 540, 0,
+                                       0, 0, 0, 0, 0,
+                                       0, 0, 0, 0, 0,
+                                       0, 0, 0}; /*电压铜牌阻值补偿,单位moh*/
 
-const uint16_T sfmc_I_chrgCurrOverThr = 600;      /* 充电电流阈值 */
-const uint16_T sfmc_I_disChrgCurrOverThr = 600;   /* 放电电流阈值 */
-const uint16_T sfmc_T_ACPlugTOverThrFlt1 = 90;    /* 慢充插头温度过高1级故障诊断阈值 */
-const uint16_T sfmc_T_ACPlugTOverThrFlt2 = 100;   /* 慢充插头温度过高2级故障诊断阈值 */
-const uint16_T sfmc_T_ACPlugTOverThrRec1 = 80;    /* 慢充插头温度过高1级故障恢复阈值 */
-const uint16_T sfmc_T_ACPlugTOverThrRec2 = 80;    /* 慢充插头温度过高2级故障恢复阈值 */
-const uint16_T sfmc_T_DCPlugTOverThrFlt1 = 90;    /* 快充插头温度过高1级故障诊断阈值 */
-const uint16_T sfmc_T_DCPlugTOverThrFlt2 = 100;   /* 快充插头温度过高2级故障诊断阈值 */
-const uint16_T sfmc_T_DCPlugTOverThrRec1 = 80;    /* 快充插头温度过高1级故障恢复阈值 */
-const uint16_T sfmc_T_DCPlugTOverThrRec2 = 80;    /* 快充插头温度过高2级故障恢复阈值 */
-const uint16_T sfmc_T_chrgModTLowThrFlt1 = 42U;   /* 充电模组温度过低1级故障诊断阈值 */
-const uint16_T sfmc_T_chrgModTLowThrFlt2 = 40U;   /* 充电模组温度过低2级故障诊断阈值 */
-const uint16_T sfmc_T_chrgModTLowThrRec1 = 45U;   /* 充电模组温度过低1级故障恢复阈值 */
-const uint16_T sfmc_T_chrgModTLowThrRec2 = 45U;   /* 充电模组温度过低2级故障恢复阈值 */
-const uint16_T sfmc_T_chrgModTOverThrFlt1 = 97U;  /* 充电模组温度过高1级故障诊断阈值 */
-const uint16_T sfmc_T_chrgModTOverThrFlt2 = 100U; /* 充电模组温度过高2级故障诊断阈值 */
-const uint16_T sfmc_T_chrgModTOverThrRec1 = 90U;  /* 充电模组温度过高1级故障恢复阈值 */
-const uint16_T sfmc_T_chrgModTOverThrRec2 = 90U;  /* 充电模组温度过高2级故障恢复阈值 */
-const uint16_T sfmc_T_chrgMosTOverThrFlt1 = 120;  /* 充电Mos温度过高1级故障诊断阈值 */
-const uint16_T sfmc_T_chrgMosTOverThrFlt2 = 125;  /* 充电Mos温度过高2级故障诊断阈值 */
-const uint16_T sfmc_T_chrgMosTOverThrRec1 = 110;  /* 充电Mos温度过高1级故障恢复阈值 */
-const uint16_T sfmc_T_chrgMosTOverThrRec2 = 110;  /* 充电Mos温度过高2级故障恢复阈值 */
+const uint16_T sfmc_I_chrgCurrOverThr = 600;     /* 充电电流阈值 */
+const uint16_T sfmc_I_disChrgCurrOverThr = 600;  /* 放电电流阈值 */
+const uint16_T sfmc_T_ACPlugTOverThrFlt1 = 90;   /* 慢充插头温度过高1级故障诊断阈值 */
+const uint16_T sfmc_T_ACPlugTOverThrFlt2 = 100;  /* 慢充插头温度过高2级故障诊断阈值 */
+const uint16_T sfmc_T_ACPlugTOverThrRec1 = 80;   /* 慢充插头温度过高1级故障恢复阈值 */
+const uint16_T sfmc_T_ACPlugTOverThrRec2 = 80;   /* 慢充插头温度过高2级故障恢复阈值 */
+const uint16_T sfmc_T_DCPlugTOverThrFlt1 = 90;   /* 快充插头温度过高1级故障诊断阈值 */
+const uint16_T sfmc_T_DCPlugTOverThrFlt2 = 100;  /* 快充插头温度过高2级故障诊断阈值 */
+const uint16_T sfmc_T_DCPlugTOverThrRec1 = 80;   /* 快充插头温度过高1级故障恢复阈值 */
+const uint16_T sfmc_T_DCPlugTOverThrRec2 = 80;   /* 快充插头温度过高2级故障恢复阈值 */
+const uint16_T sfmc_T_chrgModTLowThrFlt1 = 42U;  /* 充电模组温度过低1级故障诊断阈值 */
+const uint16_T sfmc_T_chrgModTLowThrFlt2 = 40U;  /* 充电模组温度过低2级故障诊断阈值 */
+const uint16_T sfmc_T_chrgModTLowThrRec1 = 45U;  /* 充电模组温度过低1级故障恢复阈值 */
+const uint16_T sfmc_T_chrgModTLowThrRec2 = 45U;  /* 充电模组温度过低2级故障恢复阈值 */
+const uint16_T sfmc_T_chrgModTOverThrFlt1 = 92U; /* 充电模组温度过高1级故障诊断阈值 */
+const uint16_T sfmc_T_chrgModTOverThrFlt2 = 95U; /* 充电模组温度过高2级故障诊断阈值 */
+const uint16_T sfmc_T_chrgModTOverThrRec1 = 90U; /* 充电模组温度过高1级故障恢复阈值 */
+const uint16_T sfmc_T_chrgModTOverThrRec2 = 90U; /* 充电模组温度过高2级故障恢复阈值 */
+const uint16_T sfmc_T_chrgMosTOverThrFlt1 = 120; /* 充电Mos温度过高1级故障诊断阈值 */
+const uint16_T sfmc_T_chrgMosTOverThrFlt2 = 125; /* 充电Mos温度过高2级故障诊断阈值 */
+const uint16_T sfmc_T_chrgMosTOverThrRec1 = 110; /* 充电Mos温度过高1级故障恢复阈值 */
+const uint16_T sfmc_T_chrgMosTOverThrRec2 = 110; /* 充电Mos温度过高2级故障恢复阈值 */
 
-const uint16_T sfmc_T_disChrgModTLowThrFlt1 = 25U;   /* 放电模组温度过低1级故障诊断阈值 */
-const uint16_T sfmc_T_disChrgModTLowThrFlt2 = 20U;   /* 放电模组温度过低2级故障诊断阈值 */
-const uint16_T sfmc_T_disChrgModTLowThrRec1 = 30U;   /* 放电模组温度过低1级故障恢复阈值 */
-const uint16_T sfmc_T_disChrgModTLowThrRec2 = 30U;   /* 放电模组温度过低2级故障恢复阈值 */
-const uint16_T sfmc_T_disChrgModTOverThrFlt1 = 97U;  /* 放电模组温度过高1级故障诊断阈值 */
-const uint16_T sfmc_T_disChrgModTOverThrFlt2 = 100U; /* 放电模组温度过高2级故障诊断阈值 */
-const uint16_T sfmc_T_disChrgModTOverThrRec1 = 90U;  /* 放电模组温度过高1级故障恢复阈值 */
-const uint16_T sfmc_T_disChrgModTOverThrRec2 = 90U;  /* 放电模组温度过高2级故障恢复阈值 */
+const uint16_T sfmc_T_disChrgModTLowThrFlt1 = 25U;  /* 放电模组温度过低1级故障诊断阈值 */
+const uint16_T sfmc_T_disChrgModTLowThrFlt2 = 20U;  /* 放电模组温度过低2级故障诊断阈值 */
+const uint16_T sfmc_T_disChrgModTLowThrRec1 = 30U;  /* 放电模组温度过低1级故障恢复阈值 */
+const uint16_T sfmc_T_disChrgModTLowThrRec2 = 30U;  /* 放电模组温度过低2级故障恢复阈值 */
+const uint16_T sfmc_T_disChrgModTOverThrFlt1 = 92U; /* 放电模组温度过高1级故障诊断阈值 */
+const uint16_T sfmc_T_disChrgModTOverThrFlt2 = 95U; /* 放电模组温度过高2级故障诊断阈值 */
+const uint16_T sfmc_T_disChrgModTOverThrRec1 = 90U; /* 放电模组温度过高1级故障恢复阈值 */
+const uint16_T sfmc_T_disChrgModTOverThrRec2 = 90U; /* 放电模组温度过高2级故障恢复阈值 */
 const uint16_T sfmc_T_disChrgMosTOverThrFlt1 = 120U;
 const uint16_T sfmc_T_disChrgMosTOverThrRec1 = 110U;
 const uint16_T sfmc_T_disChrgMosTOverThrFlt2 = 125U;
@@ -63,19 +70,19 @@ const uint16_T sfmc_T_modTDiffThrRec1 = 15;     /* 模组温差过大1级故障
 const uint16_T sfmc_T_modTDiffThrRec2 = 15;     /* 模组温差过大2级故障恢复阈值 */
 
 const uint16_T sfmc_V_battULowThrFlt1 = 590U;    /* 总压欠压1级故障诊断阈值 */
-const uint16_T sfmc_V_battULowThrFlt2 = 580U;    /* 总压欠压2级故障诊断阈值 */
+const uint16_T sfmc_V_battULowThrFlt2 = 560U;    /* 总压欠压2级故障诊断阈值 */
 const uint16_T sfmc_V_battULowThrRec1 = 600U;    /* 总压欠压1级故障恢复阈值 */
 const uint16_T sfmc_V_battULowThrRec2 = 600U;    /* 总压欠压2级故障恢复阈值 */
 const uint16_T sfmc_V_battUOverThrFlt1 = 850U;   /* 总压过压1级故障诊断阈值 */
-const uint16_T sfmc_V_battUOverThrFlt2 = 860U;   /* 总压过压2级故障诊断阈值 */
+const uint16_T sfmc_V_battUOverThrFlt2 = 870U;   /* 总压过压2级故障诊断阈值 */
 const uint16_T sfmc_V_battUOverThrRec1 = 840U;   /* 总压过压1级故障恢复阈值 */
 const uint16_T sfmc_V_battUOverThrRec2 = 840U;   /* 总压过压2级故障恢复阈值 */
 const uint16_T sfmc_V_cellULowThrFlt1 = 2950U;   /* 单体电压欠压1级故障诊断阈值 */
-const uint16_T sfmc_V_cellULowThrFlt2 = 2900U;   /* 单体电压欠压2级故障诊断阈值 */
+const uint16_T sfmc_V_cellULowThrFlt2 = 2800U;   /* 单体电压欠压2级故障诊断阈值 */
 const uint16_T sfmc_V_cellULowThrRec1 = 3000U;   /* 单体电压欠压1级故障恢复阈值 */
 const uint16_T sfmc_V_cellULowThrRec2 = 3000U;   /* 单体电压欠压2级故障恢复阈值 */
 const uint16_T sfmc_V_cellUOverThrFlt1 = 4250U;  /* 单体电压过压1级故障诊断阈值 */
-const uint16_T sfmc_V_cellUOverThrFlt2 = 4300U;  /* 单体电压过压2级故障诊断阈值 */
+const uint16_T sfmc_V_cellUOverThrFlt2 = 4350U;  /* 单体电压过压2级故障诊断阈值 */
 const uint16_T sfmc_V_cellUOverThrRec1 = 4200U;  /* 单体电压过压1级故障恢复阈值 */
 const uint16_T sfmc_V_cellUOverThrRec2 = 4200U;  /* 单体电压过压2级故障恢复阈值 */
 const uint16_T sfmc_flg_cellUDiffThrFlt1 = 250U; /* 压差过大1级故障诊断阈值 */
@@ -85,20 +92,25 @@ const uint16_T sfmc_flg_cellUDiffThrRec2 = 250U; /* 压差过大2级故障恢复
 
 const uint16_T sohc_Q_countThr = 60U;       /*soh计算需充入电量阈值*/
 const uint16_T sohc_Q_updateDeltThr = 200U; /*soh更新 偏差允许阈值*/
-const uint16_T sohc_pct_low = 300U;
-const uint16_T sohc_pct_up = 500U;
+const uint16_T sohc_pct_low = 0U;
+const uint16_T sohc_pct_up = 0U;
+
+const int16_T sopc_I_currUp = 500;
+const int16_T sopc_I_currLow = -500;
 
 const uint16_T socc_pct_battSocLow = 0U;                     /* SOC下限值; */
-const uint16_T socc_pct_battSocUp = 1000U;                   /* SOC上限值; */
+const uint16_T socc_pct_battSocUp = 930U;                    /* SOC上限值; */
 const int16_T socm_I_chrgCor[3] = {50, 100, 150};            /* 充电CCV对应的电流数据; */
-const int16_T socm_I_disChrgCor[3] = {-300, -100, -60};      /* 放电CCV对应的电流数据; */
+const int16_T socm_I_disChrgCor[3] = {-240, -160, -100};     /* 放电CCV对应的电流数据; */
 const uint16_T socm_V_chrgCor[3] = {4160U, 4175U, 4188U};    /* 充电CCV对应的电压; */
-const uint16_T socm_V_disChrgCor[3] = {3215U, 3265U, 3280U}; /* 放电CCV对应的电压; */
-const uint16_T socc_pct_chrgCor = 980;                       /* 充电CCV对应的SOC; */
+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; /* 热管理关闭温度(最低模组); */

+ 47 - 14
src/EmbeddedCoder_src/BCUDisp.c

@@ -4,6 +4,20 @@
 
 uint16_T appv_V_cellU[cmnc_num_cellUNumMax];
 uint8_T appd_st_preCyc;
+boolean_T  spmd_flg_firstRun;
+boolean_T  socd_flg_firstRun;
+boolean_T  sohd_flg_firstRun;
+boolean_T  blcd_flg_firstRun;
+boolean_T  sord_flg_firstRun;
+boolean_T  soed_flg_firstRun;
+boolean_T  iscd_flg_firstRun;
+boolean_T  pimd_flg_firstRun;
+boolean_T  sfmd_flg_firstRun;
+boolean_T  tmsd_flg_firstRun;
+boolean_T  cdmd_flg_firstRun;
+boolean_T sopd_flg_firstRun;
+
+boolean_T  cmd_flg_firstRun;
 
 uint16_T blcv_Q_reqCpEi[cmnc_num_cellUNumMax];                      /*均衡需求容量 读取量(数组); */
 uint16_T blcv_Q_reqCpEo[cmnc_num_cellUNumMax];                      /*均衡需求容量 写入量(数组); */
@@ -44,14 +58,15 @@ uint16_T ihd_pct_soc;                             /*保护板SOC */
 uint16_T ihd_pct_soh;                             /*保护板SOH */
 uint8_T ihd_st_workStat;                          /*电池工作状态 */
 uint16_T ihd_tm_parkTime;                         /*驻车时间; */
-uint16_T ihv_T_modT[cmnc_num_modTNumMax];                           /*模组温度(数组)+40 */
-uint16_T ihv_V_cellU[cmnc_num_cellUNumMax];                         /*电池单体电压(数组); */
+uint16_T ihv_T_modT[cmnc_num_modTNumMax];         /*模组温度(数组)+40 */
+uint16_T ihv_V_cellU[cmnc_num_cellUNumMax];       /*电池单体电压(数组); */
 boolean_T ihd_st_chrgMosControl;                  /* Mos控制指令 ;0-断开,1-导通*/
 boolean_T ihd_st_disChrgMosControl; 
 boolean_T ihd_st_relayControl;    
 uint8_T ihd_st_heatForceControl;             
 uint8_T ihd_st_EOLState;                   
 boolean_T ihd_flg_urtRecFlg;
+uint8_T ihd_st_reSet;
 
 int16_T sfmd_I_curr;                              /*处理后整包电流 */
 uint16_T sfmd_T_modTMax;                          /*处理后模组温度最小 */
@@ -84,6 +99,8 @@ boolean_T sfmd_flg_heatRunFltEo;
 boolean_T sfmd_flg_iscFltEi;
 boolean_T sfmd_flg_iscFltEo;
 
+
+uint16_T socd_pct_vcuSoc;                          /*vcuSOC; */
 uint16_T socd_pct_ahSoc;                          /*安时SOC; */
 uint16_T socd_pct_estSoc;                         /*估算SOC;*/
 uint16_T socd_flg_EEsave;                         /*实时存储标志位;*/
@@ -115,6 +132,20 @@ uint16_T sohv_Q_packCapArrEo[10];                 /*10次整包容量(数组
 uint16_T sohv_V_chrgStartStatEi[cmnc_num_cellUNumMax];              /*充电开始时刻的单体电压(数组)读取量; */
 uint16_T sohv_V_chrgStartStatEo[cmnc_num_cellUNumMax];              /*充电开始时刻的单体电压(数组)写入量; */
 
+uint16_T soed_E_nowEng;
+uint16_T soed_pct_nowStat;
+uint16_T soed_E_fullEng;
+
+uint16_T sopd_P_chrgPMax;
+uint16_T sopd_P_disChrgPMax;
+int16_T sopd_I_chrgCurrMax;
+int16_T sopd_I_disChrgCurrMax;
+
+	
+uint16_T sorv_ohm_cellREi[cmnc_num_cellUNumMax];
+uint16_T sorv_ohm_cellREo[cmnc_num_cellUNumMax];
+uint16_T sorv_ohm_cellR[cmnc_num_cellUNumMax];
+
 boolean_T iscd_flg_flt;
 uint16_T iscv_Q_remainCpEi[cmnc_num_cellUNumMax];
 uint32_T iscd_tm_totalEi;
@@ -124,24 +155,26 @@ uint32_T iscd_tm_totalEo;
 uint8_T tmsd_st_heatAct;                          /*热管理请求状态; */
 
 uint8_T cmd_st_chrgMod;                           /* 充电模式  */
-uint8_T cmd_st_chrgSt;                            /* 充电状态  */
+uint8_T cmd_st_chrgSt;                           /* 充电状态  */
 int16_T cmd_I_chrgCurrReq;                       /* 充电需求电流  */
 uint8_T cmd_idx_chrgEndReason;                    /* 充电结束原因  */
         
-uint16_T cand_Nr_cellNr;                          /*循环发送的单体编号; */
+uint16_T cand_idx_cellNr;                          /*循环发送的单体编号; */
 uint16_T cand_Q_cellCap;                          /*循环发送的单体容量; */
 uint16_T cand_V_chrgStartStat;                    /*循环发送的充电前单体电压; */
-uint16_T cand_Q_reqCp;                            /*循环发送的单体需求均衡容量; */
-uint16_T cand_Q_totalCp;                          /*循环发送的单体累计均衡容量; */
+uint16_T cand_Q_blcReqCp;                            /*循环发送的单体需求均衡容量; */
+uint16_T cand_Q_blcTotalCp;                          /*循环发送的单体累计均衡容量; */
 
-int16_T  cdmv_V_deltOCV[cmnc_num_cellUNumMax] ;
-int16_T  cdmv_ohm_deltR[cmnc_num_cellUNumMax] ;
+int16_T  cdmv_V_deltOCV[cmnc_num_cellUNumMax] = {0};
+int16_T  cdmv_ohm_deltR[cmnc_num_cellUNumMax] = {0};
 boolean_T cdmd_flg_deltOCVDisable;
 
-uint16_T test_efkSocMin;
-uint16_T test_efkSocMax;
-real_T test_UpMin;
-real_T test_UpMax;
-uint16_T test_ekfSoc;
-uint16_T test_ekfSoc0;
+uint16_T pimd_V_ocv;
+uint16_T pimd_R_ohm;
+uint16_T pimd_R_polar;
+uint16_T pimd_F_polar;
+
+uint16_T test_cellCap[cmnc_num_cellUNumMax] ;
+uint16_T test_countEn;
+int16_T test_deltU;
 

+ 14 - 22
src/EmbeddedCoder_src/BLC.c

@@ -1,11 +1,9 @@
 #include "BLC.h"
-#include "look1_iu16lu16n16tu16_binlcase.h"
 
-boolean_T FirstRun_BLC;
 ////////////////////////////////////////////////////////////////////////////
 void BLC_Init(void)
 {
-    FirstRun_BLC = true;
+    blcd_flg_firstRun = true;
 }
 
 ///////////////////////////////////////////////////////////////////////////
@@ -14,7 +12,6 @@ void BLC(void)
     uint16_T i;
     static uint16_T blcn_Q_reqCpEE[cmnc_num_cellUNumMax];
     static uint32_T blcn_Q_totalCpEE[cmnc_num_cellUNumMax];
-    uint16_T MaxCp;
     
     static boolean_T blcn_flg_judge;
     boolean_T blcn_flg_enable;
@@ -33,30 +30,25 @@ void BLC(void)
     static real_T temp[cmnc_num_cellUNumMax];
     uint16_T blcn_Q_impleCp[cmnc_num_cellUNumMax];
 
-	if(FirstRun_BLC)
+	if(blcd_flg_firstRun)
 	{
-	   for (i = 0; i < cmnc_num_cellUNum; i++)
-	   {
-	       temp[i] = 0;
-           blcn_Q_reqCpEo_Delay[i] = 0;
-	       blcn_Q_reqCpNow[i] = 0;
-	  }
+	  memset(blcn_Q_reqCpEo_Delay,0,sizeof(blcn_Q_reqCpEo_Delay));
+	  memset(temp,0,sizeof(temp)); 
 	}
     //=========================================================================
     //---------------------------------EE校验----------------------------------
     //=========================================================================
     
-    if(FirstRun_BLC)
+    if(blcd_flg_firstRun)
     {
-        MaxCp = ArrMax(&blcv_Q_reqCpEi[0], cmnc_num_cellUNum);
-        if(MaxCp > cmnc_Q_ratedCp * 100)
+        if(ArrMax(blcv_Q_reqCpEi, cmnc_num_cellUNum) > cmnc_Q_ratedCp)
         {
-            memset(blcn_Q_reqCpEE,0, sizeof(blcn_Q_reqCpEE));
+            memset(blcn_Q_reqCpEE,  0, sizeof(blcn_Q_reqCpEE));
             memset(blcn_Q_totalCpEE,0, sizeof(blcn_Q_totalCpEE));
         }
         else
         {
-            memcpy(blcn_Q_reqCpEE,blcv_Q_reqCpEi, sizeof(blcv_Q_reqCpEi));
+            memcpy(blcn_Q_reqCpEE,  blcv_Q_reqCpEi, sizeof(blcv_Q_reqCpEi));
             memcpy(blcn_Q_totalCpEE,blcv_Q_totalCpEi, sizeof(blcn_Q_totalCpEE));
         }	
     }
@@ -64,7 +56,7 @@ void BLC(void)
     //=========================================================================
     //---------------------------------使能判断--------------------------------
     //=========================================================================
-    if(FirstRun_BLC)
+    if(blcd_flg_firstRun)
     {
 		blcn_flg_judge	= (ihd_tm_parkTime >= cmnc_tm_parkTime)&& !sfmd_flg_cellUDisable && (sfmd_I_curr > -10 && sfmd_I_curr < 10);
     }
@@ -73,15 +65,15 @@ void BLC(void)
     //=========================================================================
     //---------------------------------需求计算--------------------------------
     //=========================================================================
-    if(FirstRun_BLC)
+    if(blcd_flg_firstRun)
     {
         //压差法
         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++)
             {
@@ -167,11 +159,11 @@ void BLC(void)
         }
 
 		blcn_Q_impleCp[i] = (uint16_T) (temp[i] /3600 * 1000);
-        blcv_Q_reqCpEo[i] = ( (int16_T)(blcn_Q_reqCpNow[i] - blcn_Q_impleCp[i]) < 0 ? 0 :blcn_Q_reqCpNow[i] - blcn_Q_impleCp[i]);
+        blcv_Q_reqCpEo[i] = ((int16_T)(blcn_Q_reqCpNow[i] - blcn_Q_impleCp[i]) < 0 ? 0 :blcn_Q_reqCpNow[i] - blcn_Q_impleCp[i]);
         blcv_Q_totalCpEo[i] = (uint32_T) (blcn_Q_totalCpEE[i] + blcn_Q_impleCp[i]);  
     }
     //
-    FirstRun_BLC = false;
+    blcd_flg_firstRun = false;
     memcpy(blcn_Q_reqCpEo_Delay,blcv_Q_reqCpEo, sizeof(blcn_Q_reqCpEE));
 
 }

+ 63 - 59
src/EmbeddedCoder_src/CDM.c

@@ -1,106 +1,110 @@
 #include "CDM.h"
 
-
-static boolean_T FirstRun_CDM;
-
 void CDM_Init(void)
 {
-    FirstRun_CDM = true;
+    cdmd_flg_firstRun = true;
 }
 
-
 void CDM(void)
 {
     real_T cmdn_V_cellUDelt[cmnc_num_cellUNumMax];
     real_T cdmn_I_curr;
-    static real_T P[4][cmnc_num_cellUNumMax];
+    static real_T cdmn_M_P[4][cmnc_num_cellUNumMax];
+    real_T P[4][cmnc_num_cellUNumMax];
     static real_T deltaE[cmnc_num_cellUNumMax];
     static real_T deltaR[cmnc_num_cellUNumMax];
-	static real_T deltaES[cmnc_num_cellUNumMax];
+    static real_T deltaES[cmnc_num_cellUNumMax];
     static real_T deltaRS[cmnc_num_cellUNumMax];
-    static real_T Lambda;
+    static real_T cdmn_f_Lambda;
     real_T K[2];
     real_T arf[cmnc_num_cellUNumMax];
     uint16_T i;
-    static uint8_T ihd_st_workStat_Delay;
-	static uint8_T Cnt;
+    static uint8_T cmdn_st_workStat_Delay;
+    static uint8_T cdmn_num_Cnt;
+
     //
-    if(ihd_st_workStat_Delay == 2 && ihd_st_workStat != 2)
+    if (cmdn_st_workStat_Delay != 1 && ihd_st_workStat == 1)
     {
-        FirstRun_CDM = true;
+        cdmd_flg_firstRun = true;
     }
-    ihd_st_workStat_Delay = ihd_st_workStat;
-	//
-    if (FirstRun_CDM)
+    
+    //
+    if (cdmd_flg_firstRun)
     {
-        for (i = 0;i < cmnc_num_cellUNum;i++)
+        for (i = 0; i < cmnc_num_cellUNum; i++)
         {
-            P[0][i] = 10;
-            P[1][i] = 0;
-            P[2][i] = 0;
-            P[3][i] = 10;
-            Lambda = 0.991;
-            deltaE[i] =  0;
-            deltaR[i] =  0;
-			deltaES[i] = 0;
+            cdmn_M_P[0][i] = 10;
+            cdmn_M_P[1][i] = 0;
+            cdmn_M_P[2][i] = 0;
+            cdmn_M_P[3][i] = 10;
+            cdmn_f_Lambda = 0.991;
+            deltaE[i] = 0;
+            deltaR[i] = 0;
+            deltaES[i] = 0;
             deltaRS[i] = 0;
-			Cnt = 0;
+            cdmn_num_Cnt = 0;
         }
     }
     //
-    if(ihd_st_workStat != 2)
+    if (ihd_st_workStat == 1) 
     {
-        for (i = 0;i < cmnc_num_cellUNum;i++)
+        for (i = 0; i < cmnc_num_cellUNum; i++)
         {
-            cmdn_V_cellUDelt[i] = (real_T)(sfmv_V_cellU[i]  - sfmd_V_cellUAvrg) * 0.001;
+            cmdn_V_cellUDelt[i] = (real_T)(sfmv_V_cellU[i] - sfmd_V_cellUAvrg) * 0.001;
         }
-        cdmn_I_curr = (real_T) sfmd_I_curr * 0.1;
+        cdmn_I_curr = (real_T)sfmd_I_curr * 0.1;
         //
         cdmd_flg_deltOCVDisable = false;
-        for (i = 0;i < cmnc_num_cellUNum;i++)
+        for (i = 0; i < cmnc_num_cellUNum; i++)
         {
-            K[0] = (P[0][i]  + cdmn_I_curr * P[1][i])/(Lambda + P[0][i] + cdmn_I_curr * P[2][i] + ( P[1][i] + cdmn_I_curr * P[3][i]) * cdmn_I_curr);
-            K[1] = (P[2][i]  + cdmn_I_curr * P[3][i])/(Lambda + P[0][i] + cdmn_I_curr * P[2][i] + ( P[1][i] + cdmn_I_curr * P[3][i]) * cdmn_I_curr);
+            K[0] = (cdmn_M_P[0][i] + cdmn_I_curr * cdmn_M_P[1][i]) / (cdmn_f_Lambda + cdmn_M_P[0][i] + cdmn_I_curr * cdmn_M_P[2][i] + (cdmn_M_P[1][i] + cdmn_I_curr * cdmn_M_P[3][i]) * cdmn_I_curr);
+            K[1] = (cdmn_M_P[2][i] + cdmn_I_curr * cdmn_M_P[3][i]) / (cdmn_f_Lambda + cdmn_M_P[0][i] + cdmn_I_curr * cdmn_M_P[2][i] + (cdmn_M_P[1][i] + cdmn_I_curr * cdmn_M_P[3][i]) * cdmn_I_curr);
             arf[i] = cmdn_V_cellUDelt[i] - (deltaE[i] + cdmn_I_curr * deltaR[i]);
             deltaE[i] = deltaE[i] + K[0] * arf[i];
             deltaR[i] = deltaR[i] + K[1] * arf[i];
-            P[0][i] = ((1 -K[0])* P[0][i] -P[2][i] * K[0] * cdmn_I_curr) /Lambda;
-            P[1][i] = ((1 -K[0])* P[1][i] -P[3][i] * K[0] * cdmn_I_curr) /Lambda;
-            P[2][i] = (-K[1] *P[0][i] +P[2][i] * (1 - K[1] * cdmn_I_curr))/Lambda;
-            P[3][i] = (-K[1] *P[1][i] +P[3][i] * (1 - K[1] * cdmn_I_curr))/Lambda;
-			
-			if(arf[i] > 0.04 || arf[i] < -0.04)
+            P[0][i] = ((1 - K[0]) * cdmn_M_P[0][i] - cdmn_M_P[2][i] * K[0] * cdmn_I_curr)  / cdmn_f_Lambda;
+            P[1][i] = ((1 - K[0]) * cdmn_M_P[1][i] - cdmn_M_P[3][i] * K[0] * cdmn_I_curr)  / cdmn_f_Lambda;
+            P[2][i] = (-K[1] * cdmn_M_P[0][i] + cdmn_M_P[2][i] * (1 - K[1] * cdmn_I_curr)) / cdmn_f_Lambda;
+            P[3][i] = (-K[1] * cdmn_M_P[1][i] + cdmn_M_P[3][i] * (1 - K[1] * cdmn_I_curr)) / cdmn_f_Lambda;
+
+            cdmn_M_P[0][i] = P[0][i];
+            cdmn_M_P[1][i] = P[1][i];
+            cdmn_M_P[2][i] = P[2][i];
+            cdmn_M_P[3][i] = P[3][i];
+            if (arf[i] > 0.04 || arf[i] < -0.04)
             {
                 cdmd_flg_deltOCVDisable = true;
-			   
             }
-	    }
+        }
         //
-		Cnt = Cnt + 1;
-
-        for (i = 0;i < cmnc_num_cellUNum;i++)
-        {   
+        cdmn_num_Cnt = cdmn_num_Cnt + 1;
+        for (i = 0; i < cmnc_num_cellUNum; i++)
+        {
             deltaES[i] = deltaES[i] + deltaE[i];
-			deltaRS[i] = deltaRS[i] + deltaR[i];
+            deltaRS[i] = deltaRS[i] + deltaR[i];
         }
 
-		if (Cnt >= 10)
-		{
-             for (i = 0;i < cmnc_num_cellUNum;i++)
-             {   
-                 cdmv_V_deltOCV[i] = (int16_T) (deltaES[i]/Cnt  * 1000);
-                 cdmv_ohm_deltR[i] = (int16_T) (deltaRS[i]/Cnt  * 1000 * 1000);
-			     deltaES[i] = 0;
-                 deltaRS[i] = 0;
-             }
-		     Cnt = 0;
-		}
+        if (cdmn_num_Cnt >= 10)
+        {
+            for (i = 0; i < cmnc_num_cellUNum; i++)
+            {
+                cdmv_V_deltOCV[i] = (int16_T)(deltaES[i] / cdmn_num_Cnt * 1000);
+                cdmv_ohm_deltR[i] = (int16_T)(deltaRS[i] / cdmn_num_Cnt * 1000 * 1000);
+                deltaES[i] = 0;
+                deltaRS[i] = 0;
+            }
+            cdmn_num_Cnt = 0;
+        }
     }
     else
     {
         cdmd_flg_deltOCVDisable = true;
+		memset(cdmv_V_deltOCV,0,sizeof(cdmv_V_deltOCV));
+		memset(cdmv_ohm_deltR,0,sizeof(cdmv_ohm_deltR));
     }
 	
-    FirstRun_CDM = false;
-	
-}
+    cdmd_flg_firstRun = false;
+	cmdn_st_workStat_Delay = ihd_st_workStat;
+}
+
+

+ 13 - 90
src/EmbeddedCoder_src/CM.c

@@ -1,9 +1,9 @@
 #include "CM.h"
 
-boolean_T FirstRun_CM;
+
 void CM_Init(void)
 {
-    FirstRun_CM = true;
+    cmd_flg_firstRun = true;
 }
 
 void CM(void)
@@ -14,14 +14,14 @@ 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;
-    if(FirstRun_CM)
+    if(cmd_flg_firstRun)
     {
         cmn_V_cellUMax = 0;
         cmn_V_cellUMin = 0;
@@ -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
@@ -137,8 +137,6 @@ void CM(void)
             cmd_idx_chrgEndReason = 2 ; // 因电池故障限制充电;
         }
 
-
-		
         First = false;
     }
     else
@@ -147,86 +145,11 @@ void CM(void)
         cmd_idx_chrgEndReason = 0;
     }
 
-    FirstRun_CM = false;
+    cmd_flg_firstRun = false;
 	//printf("fltAct:%d,chrgMod:%d,chrgSt:%d,chrgCurrReq:%d,chrgEndReason:%d\n\n",sfmd_st_fltAct,cmd_st_chrgMod,cmd_st_chrgSt,cmd_I_chrgCurrReq,cmd_idx_chrgEndReason);
 }
 
 
 //==============================================================================================================================
 //==============================================================================================================================
-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;
-}
+

+ 19 - 47
src/EmbeddedCoder_src/ISC.c

@@ -1,11 +1,8 @@
 #include "ISC.h"
-#include "look1_is16lu16n16tu16_binlcase.h"
-
-boolean_T FirstRun_ISC;
 
 void ISC_Init(void)
 {
-    FirstRun_ISC = true;
+    iscd_flg_firstRun = true;
 }
 //-------------------------------------------------------------------------
 
@@ -23,10 +20,10 @@ void ISC(void)
     static boolean_T iscd_flg_disChrgFlt;
     static uint16_T TimeCtn;
     static uint16_T RunCtn;
-    static uint16_T iscn_N_fltNr[cmnc_num_cellUNumMax];
+    static uint16_T iscn_num_fltNr[cmnc_num_cellUNumMax];
     static boolean_T iscd_flg_fulStat;
     //初值
-    if(FirstRun_ISC)
+    if(iscd_flg_firstRun)
     {
         iscd_flg_timedWakeUpFlt = false;
         iscd_flg_disChrgFlt = false;
@@ -35,7 +32,7 @@ void ISC(void)
 		memset(iscn_pct_cellSoc2,0, sizeof(iscn_pct_cellSoc2));
 		memset(iscn_Q_cellAh,0, sizeof(iscn_Q_cellAh));
 		memset(iscn_Q_deltAh,0, sizeof(iscn_Q_deltAh));
-        memset(iscn_N_fltNr,0, sizeof(iscn_N_fltNr));
+        memset(iscn_num_fltNr,0, sizeof(iscn_num_fltNr));
         TimeCtn = 0;
         RunCtn = 0;
     }
@@ -43,7 +40,7 @@ void ISC(void)
     //================高端SOC点诊断=================================== 0.1A
     //=====================================================================
     RunCtn = (RunCtn + 1) > 60000 ? 60000 : (RunCtn + 1);
-    if(FirstRun_ISC)
+    if(iscd_flg_firstRun)
     {
         //
         if(ArrMax(iscv_Q_remainCpEi,cmnc_num_cellUNum) > cmnc_Q_ratedCp)
@@ -61,13 +58,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;
                 }
@@ -89,17 +86,17 @@ void ISC(void)
     //=====================================================================
     //================定时唤醒诊断======================================1A
     //=====================================================================
-    if(appd_st_preCyc == 1 && ihd_tm_parkTime >= cmnc_tm_parkTime && sfmd_I_curr < 10 && sfmd_I_curr > -10 && FirstRun_ISC)
+    if(appd_st_preCyc == 1 && ihd_tm_parkTime >= cmnc_tm_parkTime && sfmd_I_curr < 10 && sfmd_I_curr > -10 && iscd_flg_firstRun)
     {
         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;
             }
@@ -117,8 +114,7 @@ void ISC(void)
         TimeCtn = TimeCtn + 1;
         for (i = 0; i < cmnc_num_cellUNum;i++)
         {
-            //Ah[i] =(int16_T)((uint16_T)((uint32_T) socv_pct_cellSoc[i]  * sohv_Q_cellCap[i] / 2000U) << 1);
-            iscn_Q_cellAh[i]=(uint16_T) ((real_T)( socv_pct_cellSoc[i] * 0.1) * (real_T)( sohv_Q_cellCap[i] * 0.1)/100 * 100);
+            iscn_Q_cellAh[i] = (uint16_T)((uint32_T)(socv_pct_cellSoc[i] * sohv_Q_cellCap[i])/1000);
         }
         if (TimeCtn == 60)
         {
@@ -132,15 +128,15 @@ 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.1/(TimeCtn - 60) * 3600 > 2 )
                 {
-                    iscn_N_fltNr[i] =  (iscn_N_fltNr[i] + 1) > 60000 ? 60000 : (iscn_N_fltNr[i] + 1);
+                    iscn_num_fltNr[i] =  (iscn_num_fltNr[i] + 1) > 60000 ? 60000 : (iscn_num_fltNr[i] + 1);
                 }
                 else
                 {
-                    iscn_N_fltNr[i] = 0;
+                    iscn_num_fltNr[i] = 0;
                 }
-                if (iscn_N_fltNr[i] > 600)
+                if (iscn_num_fltNr[i] > 600)
                 {
                     iscd_flg_disChrgFlt = true;
                 }
@@ -158,32 +154,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;
+	iscd_flg_firstRun = false;
 }
+
+

+ 193 - 0
src/EmbeddedCoder_src/PIM.c

@@ -0,0 +1,193 @@
+#include "PIM.h"
+
+#define pimd_L_rls 51
+
+void PIM_Init(void)
+{
+    pimd_flg_firstRun = true;
+}
+
+void PIM(void)
+{
+    static uint8_T pimn_st_workStat_Delay;
+    uint16_T i;
+    uint16_T j;
+    static uint16_T pimn_V_volt[pimd_L_rls];
+    static int16_T  pimn_I_curr[pimd_L_rls];
+    static real_T  pimn_V_ocv;
+    static real_T  pimn_R_ohm;
+    static real_T  pimn_R_polar;
+    static real_T  pimn_F_polar;
+    
+    static uint16_T pimn_N_ctn;
+    static real_T pimn_M_P[4][4];
+    static real_T theta[4];
+    real_T P[4][4];
+    real_T A[4];
+    real_T K[4];
+    real_T temp;
+	
+    //重置
+    if (pimn_st_workStat_Delay != 1 && ihd_st_workStat == 1)
+    {
+        pimd_flg_firstRun = true;
+    }
+    
+    //初值
+    if (pimd_flg_firstRun)
+    {
+        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 (pimd_flg_firstRun)
+    {
+        for (i = 0; i < pimd_L_rls; i++)
+        {
+            pimn_V_volt[i] = sfmv_V_cellU[0];
+            pimn_I_curr[i] = sfmd_I_curr;
+        }
+	}
+    else
+    {
+        for (i = 0; i < pimd_L_rls - 1; i++)
+        {
+            pimn_V_volt[i]  = pimn_V_volt[i+1];
+            pimn_I_curr[i] = pimn_I_curr[i+1];
+        }
+        pimn_V_volt[i] = sfmv_V_cellU[0];
+        pimn_I_curr[i] = sfmd_I_curr;
+    }
+    //
+    if(pimn_st_workStat_Delay == 1)
+    {
+        pimn_N_ctn = pimn_N_ctn + 1;
+        //输入
+        A[0] = (real_T)pimn_V_volt[pimd_L_rls - 2] * 0.001;
+        A[1] = (real_T)pimn_I_curr[pimd_L_rls - 1] * 0.1;
+        A[2] =-(real_T)pimn_I_curr[pimd_L_rls - 2] * 0.1;
+        A[3] = 1;
+        //参数形变
+        
+        theta[0] = exp(-1/pimn_F_polar);
+        theta[1] = pimn_R_ohm;
+        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;
+
+        //增益矩阵
+        temp =  (A[0] * pimn_M_P[0][0] +A[1] * pimn_M_P[1][0] + A[2] * pimn_M_P[2][0] + A[3] * pimn_M_P[3][0]) * A[0] +
+                (A[0] * pimn_M_P[0][1] +A[1] * pimn_M_P[1][1] + A[2] * pimn_M_P[2][1] + A[3] * pimn_M_P[3][1]) * A[1] +
+                (A[0] * pimn_M_P[0][2] +A[1] * pimn_M_P[1][2] + A[2] * pimn_M_P[2][2] + A[3] * pimn_M_P[3][2]) * A[2] +
+                (A[0] * pimn_M_P[0][3] +A[1] * pimn_M_P[1][3] + A[2] * pimn_M_P[2][3] + A[3] * pimn_M_P[3][3]) * A[3];
+        for(i = 0;i < 4;i++)
+        {
+            K[i] = (pimn_M_P[i][0] * A[0] + pimn_M_P[i][1] * A[1] + pimn_M_P[i][2] * A[2] + pimn_M_P[i][3] * A[3])/(1 + temp);
+        }
+        //参数更新
+        
+        temp = (real_T)pimn_V_volt[pimd_L_rls - 1] * 0.001 - (theta[0] * A[0] + theta[1] * A[1] + theta[2] * A[2] + theta[3] * A[3]);
+		test_deltU = (int16_T)(temp * 1000);
+        for(i = 0;i < 4;i++)
+        {
+            theta[i] = theta[i] + K[i] * temp;
+        }
+        //协方差更新
+        for(i = 0;i < 4;i++)
+        {
+            for(j = 0;j < 4;j++)
+            {
+                P[i][j] = pimn_M_P[i][j] - K[i] * (A[0] * pimn_M_P[0][j] + A[1] * pimn_M_P[1][j] + A[2] * pimn_M_P[2][j] + A[3] * pimn_M_P[3][j]);
+            }
+
+        }
+		
+        //传递下循环
+        for(i = 0;i < 4;i++)
+        {
+            for(j = 0;j < 4;j++)
+            {
+                pimn_M_P[i][j] = P[i][j];
+            }
+            
+        }
+        
+        //=======================================================================
+        if(pimn_N_ctn > pimd_L_rls)
+        {
+            //输入
+            A[0] = (real_T)pimn_V_volt[0] * 0.001;
+            A[1] = (real_T)pimn_I_curr[1] * 0.1;
+            A[2] =-(real_T)pimn_I_curr[0] * 0.1;
+            A[3] = 1;
+
+            //增益矩阵
+            temp =  (A[0] * pimn_M_P[0][0] +A[1] * pimn_M_P[1][0] + A[2] * pimn_M_P[2][0] + A[3] * pimn_M_P[3][0]) * A[0] +
+                    (A[0] * pimn_M_P[0][1] +A[1] * pimn_M_P[1][1] + A[2] * pimn_M_P[2][1] + A[3] * pimn_M_P[3][1]) * A[1] +
+                    (A[0] * pimn_M_P[0][2] +A[1] * pimn_M_P[1][2] + A[2] * pimn_M_P[2][2] + A[3] * pimn_M_P[3][2]) * A[2] +
+                    (A[0] * pimn_M_P[0][3] +A[1] * pimn_M_P[1][3] + A[2] * pimn_M_P[2][3] + A[3] * pimn_M_P[3][3]) * A[3];
+            for(i = 0;i <4;i++)
+            {
+                K[i] = (pimn_M_P[i][0] * A[0] + pimn_M_P[i][1] * A[1] + pimn_M_P[i][2] * A[2] + pimn_M_P[i][3] * A[3])/(1 + temp);
+            }
+
+            //协方差更新
+            for(i = 0;i < 4;i++)
+            {
+                for(j = 0;j < 4;j++)
+                {
+                    P[i][j] = pimn_M_P[i][j] + K[i] * (A[0] * pimn_M_P[0][j] + A[1] * pimn_M_P[1][j] + A[2] * pimn_M_P[2][j] + A[3] * pimn_M_P[3][j]);
+                }
+            }
+            //传递下一循环
+            for(i = 0;i < 4;i++)
+            {
+                for(j = 0;j < 4;j++)
+                {
+                    pimn_M_P[i][j] = P[i][j];
+                }
+                
+            }
+        }
+        //参数求解
+        pimn_V_ocv   = theta[3]/(1 - theta[0]);
+        pimn_R_ohm   = theta[1];
+        pimn_R_polar = (theta[0] * theta[1] -theta[2])/(1 -theta[0]);
+        pimn_F_polar = -1/log(theta[0]);
+
+        //pimn_V_ocv   = Saturation_r(pimn_V_ocv,3.2, 4.4);
+		//pimn_R_ohm   = Saturation_r(pimn_V_ocv,0.001, 1);
+		//pimn_R_polar = Saturation_r(pimn_V_ocv,0.0002, 1);
+		//pimn_F_polar = Saturation_r(pimn_V_ocv,0, 200);
+
+
+		
+        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;
+    pimd_flg_firstRun = false; 
+}
+
+
+

Файловите разлики са ограничени, защото са твърде много
+ 435 - 453
src/EmbeddedCoder_src/SFM.c


+ 188 - 312
src/EmbeddedCoder_src/SOC.c

@@ -1,25 +1,23 @@
 #include "SOC.h"
-#include "look1_is16lu16n16tu16_binlcase.h"
-#include "look1_iu16lu16n16tu16_binlcase.h"
-
-boolean_T FirstRun_SOC;
 
 //---------------SOC初始化-----------------------------------------------
 void SOC_Init(void)
 {
-    FirstRun_SOC = true;
+    socd_flg_firstRun = true;
 }
-//-------------------------------------------------------------------------
 
+
+//-------------------------------------------------------------------------
+//---------------------------SOC-------------------------------------------
+//-------------------------------------------------------------------------
 void SOC(void)
 {
     static uint16_T socn_pct_battSocEE;
     static uint16_T socn_pct_bcuSocEE;
     static uint16_T socn_Q_cap;
     //
-    uint16_T EKFSOCMin;
-    uint16_T EKFSOCMax;
-    uint16_T EKFSOCAvrg;
+    real_T Q;
+    real_T battcurr;
     boolean_T socn_flg_ekfInvalidMin;
     boolean_T socn_flg_ekfInvalidMax;
     boolean_T socn_flg_ekfInvalidAvrg;
@@ -27,8 +25,9 @@ void SOC(void)
     real_T ocv;
     real_T Ro;
     real_T Rp;
-    real_T C;
+    real_T RC;
     real_T deltU;
+	real_T UL;
     real_T A[4];
     real_T B[2];
     real_T H[2];
@@ -45,60 +44,61 @@ void SOC(void)
     static real_T Up_Min_Delay;
     static real_T Up_Max_Delay;
     static real_T Up_Avrg_Delay;
+	uint16_T EKFSOCMin;
+    uint16_T EKFSOCMax;
+	
+    uint16_T EKFSOCAvrg;
 	uint16_T cellSocMax;
     uint16_T cellSocMin;
-    real_T Q;
-    real_T battcurr;
-    real_T UL;
     uint16_T factor;
     //
     static real_T ahDelay;
     int16_T ahSoc;
     //
-    static uint16_T ekfInvalidCntl;
+    boolean_T socn_flg_ekfDisable;
+    static uint16_T  ekfInvalidCntl;
     static boolean_T onceFlg_est;
-    static int16_T ahSoc0_est;
-    static uint16_T ekfSoc0_est;
-    //
-    uint16_T socd_V_chrgCCV;
-	uint16_T socd_V_disChrgCCV;
+    static int16_T   ahSoc0_est;
+    static uint16_T  ekfSoc0_est;
+    // 
+    uint16_T socn_V_chrgCCV;
+	uint16_T socn_V_disChrgCCV;
     static boolean_T overFlg;
     static boolean_T fulFlg;
-    static uint8_T overCntl;
-    static uint8_T fulCntl;
+    static uint16_T overCntl;
+    static uint16_T fulCntl;
     static boolean_T onceFlg_utrckOver;
-    static int16_T ahSoc0_utrckOver;
-    static uint16_T estSoc0_utrckOver;
+    static int16_T   ahSoc0_utrckOver;
+    static uint16_T  estSoc0_utrckOver;
     static uint16_T Soc_Delay;
     static boolean_T lowFlg;
-    static uint8_T lowCntl;
+    static uint16_T lowCntl;
     static boolean_T onceFlg_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;
     //
-    static uint16_T socd_pct_battSoc_Delay;
     //
-    static uint8_T statCntl;
-    boolean_T statFlg;
-    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;
+    static uint16_T statCntl;
+    static uint8_T  socn_st_workStat_Delay;
+    static uint16_T socn_pct_battSoc_Delay;
+    static uint16_T socn_pct_battSoc0;
+    static uint16_T socn_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;
     static boolean_T onceFlg_chrg;
     static boolean_T onceFlg_dischrg;
+
+	static uint16_T socn_pct_battSoc_save;
+	static uint16_T socn_pct_bcuSoc_save;
     uint16_T i;
     //
-    if (FirstRun_SOC)
+    if (socd_flg_firstRun)
     {
         onceFlg_est = true;
         ekfInvalidCntl = 0;
@@ -108,39 +108,41 @@ void SOC(void)
         overFlg = false;
         fulFlg = false;
         lowFlg = false;
+		statCntl = 0;
         Soc_Delay = 0;
         onceFlg_utrckOver = true;
         onceFlg_utrckLow = true;
-        ihd_st_chrgSta_Delay = 0;
-        socn_pct_utrackSoc_Delay = 0;
+        socn_st_workStat_Delay = 0;
+        socn_pct_battSoc_Delay = 0;
         onceFlg_chrg = true;
         onceFlg_dischrg = true;
+		socn_pct_battSoc_save = 0;
+		socn_pct_bcuSoc_save = 0;
     }
     
     //=====================================================================
-    ////////////////////////初始值获取//////////////////////////////////////
+    ////////////////////////初始值获取/EE校验//////////////////////////////
     //=====================================================================
-    if (FirstRun_SOC)
+    if (socd_flg_firstRun)
     { //
-        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))
+        if (socd_pct_battSocEi > socc_pct_battSocUp || socd_pct_bcuSocEi > socc_pct_battSocUp || 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
         {
             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)
+        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);
     }
-	
     //printf("1----  battSocEi:%d,bcuSocEi:%d,battSocEE:%d,bcuSocEE:%d\n",socd_pct_battSocEi,socd_pct_bcuSocEi,socn_pct_battSocEE,socn_pct_bcuSocEE);
     //======================================================================
     ////////////////////////EKFSOC//////////////////////////////////////////
@@ -149,7 +151,7 @@ void SOC(void)
     Q = (real_T)socn_Q_cap * 0.1;
     
     //-------------------------EKFmin---------------------------------------
-    if (FirstRun_SOC)
+    if (socd_flg_firstRun)
     {
         soc_Min_Delay = (real_T)socn_pct_battSocEE * 0.1;
         Up_Min_Delay = 0;
@@ -159,17 +161,17 @@ 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;
-    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_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;
-    A[3] = exp(-1 / (Rp * C));
+    A[3] = exp(-1 / RC);
     
     B[0] = 1 / Q / 3600 * 100;
-    B[1] = Rp * (1 - exp(-1 / (Rp * C)));
+    B[1] = Rp * (1 - exp(-1 / RC));
     
     H[0] = docvmath(soc_Min_Delay);
     H[1] = 1;
@@ -190,16 +192,7 @@ void SOC(void)
     //后验
     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;
-    }
-    if (soc_Min_Delay > (real_T)socc_pct_battSocUp * 0.1)
-    {
-        soc_Min_Delay = (real_T)socc_pct_battSocUp * 0.1;
-    }
-    
+    soc_Min_Delay = Saturation_r(soc_Min_Delay, (real_T)socc_pct_battSocLow * 0.1, (real_T)socc_pct_battSocUp * 0.1);
     Up_Min_Delay = Up1 + K[1] * deltU;
     //P更新
     P_Min_Delay[0] = (1 - K[0] * H[0]) * P1[0] - K[0] * P1[1];
@@ -210,9 +203,9 @@ void SOC(void)
     //输出
     EKFSOCMin = (uint16_T)(soc_Min_Delay * 10);
     socn_flg_ekfInvalidMin = (deltU > 0.01) || (deltU < -0.01);
-    //printf("2----soc:%f,Up:%f,U:%d,deltU:%f,K[0]:%f,K[1]:%f\n",soc_Min_Delay,Up_Min_Delay,sfmd_V_cellUMin,deltU,K[0],K[1]);  
+    //printf("2----socmin:%f,U:%d,R:%f\n",soc_Min_Delay,sfmd_V_cellUMin,Ro);
 	//------------------------EKFSOCmax-----------------------------------
-    if (FirstRun_SOC)
+    if (socd_flg_firstRun)
     {
         soc_Max_Delay = (real_T)socn_pct_battSocEE * 0.1;
         Up_Max_Delay = 0;
@@ -222,17 +215,18 @@ 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;
-    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_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;
-    A[3] = exp(-1 / (Rp * C));
+    A[3] = exp(-1 / RC);
     
     B[0] = 1 / Q / 3600 * 100;
-    B[1] = Rp * (1 - exp(-1 / (Rp * C)));
+    B[1] = Rp * (1 - exp(-1 / RC));
     
     H[0] = docvmath(soc_Max_Delay);
     H[1] = 1;
@@ -254,15 +248,7 @@ void SOC(void)
     //后验
     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;
-    }
-    if (soc_Max_Delay > (real_T)socc_pct_battSocUp * 0.1)
-    {
-        soc_Max_Delay = (real_T)socc_pct_battSocUp * 0.1;
-    }
+	soc_Max_Delay = Saturation_r(soc_Max_Delay, (real_T)socc_pct_battSocLow * 0.1, (real_T)socc_pct_battSocUp * 0.1);
     Up_Max_Delay = Up1 + K[1] * deltU;
     
     //P更新
@@ -273,7 +259,7 @@ void SOC(void)
     //输出
     EKFSOCMax = (uint16_T)(soc_Max_Delay * 10);
     socn_flg_ekfInvalidMax = (deltU > 0.01) || (deltU < -0.01);
-    //printf("4----soc:%f,Up:%f,U:%d,deltU:%f,K[0]:%f,K[1]:%f\n",soc_Max_Delay,Up_Max_Delay,sfmd_V_cellUMax,deltU,K[0],K[1]);
+    //printf("3----socmax:%f,U:%d,R:%f\n\n",soc_Max_Delay,sfmd_V_cellUMax,Ro);
     //-----------------------EKFSOC----------------------------------------
     socn_flg_ekfInvalid = socn_flg_ekfInvalidMax || socn_flg_ekfInvalidMin;
     if (EKFSOCMax > 800)
@@ -290,10 +276,10 @@ void SOC(void)
     }
     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----socd_pct_ekfSoc:%d,EKFSOCMax:%d,EKFSOCMin:%d,\n",socd_pct_ekfSoc,EKFSOCMax,EKFSOCMin);
+   //printf("4----socd_pct_ekfSoc:%d,EKFSOCMax:%d,EKFSOCMin:%d,\n",socd_pct_ekfSoc,EKFSOCMax,EKFSOCMin);
 
    //-------------------------EKFavrg---------------------------------------
-    if (FirstRun_SOC)
+    if (socd_flg_firstRun)
     {
         soc_Avrg_Delay = (real_T)socn_pct_battSocEE * 0.1;
         Up_Avrg_Delay = 0;
@@ -303,17 +289,18 @@ 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;
-    C   = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Avrg_Delay * 10), (&(cmnm_pct_soc[0])), (&(cmnm_F_polar[0])), 12U) * 0.001 * 1000;
+    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;
-    A[3] = exp(-1 / (Rp * C));
+    A[3] = exp(-1 / RC);
     
     B[0] = 1 / Q / 3600 * 100;
-    B[1] = Rp * (1 - exp(-1 / (Rp * C)));
+    B[1] = Rp * (1 - exp(-1 / RC));
     
     H[0] = docvmath(soc_Avrg_Delay);
     H[1] = 1;
@@ -335,15 +322,7 @@ void SOC(void)
     deltU = (real_T)sfmd_V_cellUAvrg * 0.001 - UL;
     soc_Avrg_Delay = soc1 + K[0] * deltU;
     
-    if (soc_Avrg_Delay < (real_T)socc_pct_battSocLow * 0.1)
-    {
-        soc_Avrg_Delay = (real_T)socc_pct_battSocLow * 0.1;
-    }
-    if (soc_Avrg_Delay > (real_T)socc_pct_battSocUp * 0.1)
-    {
-        soc_Avrg_Delay = (real_T)socc_pct_battSocUp * 0.1;
-    }
-    
+    soc_Avrg_Delay = Saturation_r(soc_Avrg_Delay, (real_T)socc_pct_battSocLow * 0.1, (real_T)socc_pct_battSocUp * 0.1);
     Up_Avrg_Delay = Up1 + K[1] * deltU;
     //P更新
     P_avrg_Delay[0] = (1 - K[0] * H[0]) * P1[0] - K[0] * P1[1];
@@ -358,11 +337,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;
@@ -377,13 +358,11 @@ 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//////////////////////////////////////////
     //======================================================================
-    if (FirstRun_SOC)
+    if (socd_flg_firstRun)
     {
         ahDelay = (real_T)(socn_pct_battSocEE * 0.1);
     }
@@ -392,34 +371,15 @@ void SOC(void)
         ahDelay = ahDelay + battcurr / (real_T)(cmnc_Q_ratedCp * 0.1) / 36.0;//cmnc_Q_ratedCp
     }
     ahSoc = (int16_T)(ahDelay * 10);
-    if (ahSoc > socc_pct_battSocUp)
-    {
-        socd_pct_ahSoc = socc_pct_battSocUp;
-    }
-    else if (ahSoc < socc_pct_battSocLow)
-    {
-        socd_pct_ahSoc = socc_pct_battSocLow;
-    }
-    else
-    {
-        socd_pct_ahSoc = (uint16_T)ahSoc;
-    }
-	 //  printf("S_%d   %d   %d   %d   %d   %d   %d   %d\n",socd_pct_cellBattSoc,cellSocMax,cellSocMin,socd_pct_ekfSoc,EKFSOCMax,EKFSOCMin,ahSoc,EKFSOCAvrg);
-	 //  printf("E_%d   %d   %d   %d   %d   %d   %d   %d\n",cdmv_V_deltOCV[0],cdmv_V_deltOCV[1],cdmv_V_deltOCV[15],cdmv_V_deltOCV[16],cdmv_ohm_deltR[0],cdmv_ohm_deltR[1],cdmv_ohm_deltR[15],cdmv_ohm_deltR[16]);
-    //printf("5----ahDelay:%f,ahSoc:%d,battcurr:%f,sfmd_I_curr:%d\n",ahDelay,ahSoc,battcurr,sfmd_I_curr);
+	
+	socd_pct_ahSoc = Saturation_u(ahSoc < 0 ? 0 : (uint16_T)ahSoc, socc_pct_battSocLow, socc_pct_battSocUp);
+	//printf("5----ahDelay:%f,ahSoc:%d,battcurr:%f,sfmd_I_curr:%d\n",ahDelay,ahSoc,battcurr,sfmd_I_curr);
+	
     //======================================================================
     ///////////////////////estSOC//////////////////////////////////////////
     //======================================================================
-    if (!socn_flg_ekfInvalid)
-    {
-        ekfInvalidCntl = (ekfInvalidCntl + 1) > 250 ? 250 : (ekfInvalidCntl + 1);
-    }
-    else
-    {
-        ekfInvalidCntl = 0;
-    }
-    
-    if (ekfInvalidCntl < 20)
+    socn_flg_ekfDisable = !JudgeTimeSystem(1,!socn_flg_ekfInvalid,&ekfInvalidCntl,2);
+    if (socn_flg_ekfDisable)
     {
         if (onceFlg_est)
         {  
@@ -434,54 +394,21 @@ void SOC(void)
         onceFlg_est = true;
         socd_pct_estSoc = socd_pct_ekfSoc;
     }
-    
+    socd_pct_estSoc = Saturation_u(socd_pct_estSoc, socc_pct_battSocLow, socc_pct_battSocUp);
     //
-    if (socd_pct_estSoc > socc_pct_battSocUp)
-    {
-        socd_pct_estSoc = socc_pct_battSocUp;
-    }
-    if (socd_pct_estSoc < socc_pct_battSocLow)
-    {
-        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);
+	
     //======================================================================
     ////////////////////////UtrackSOC//////////////////////////////////////////
     //======================================================================
     if (ihd_st_workStat == 2)
     {
-        disChrgCntl = 0;
-        chrgCntl = (chrgCntl + 1) > 250 ? 250 : (chrgCntl + 1);
         lowCntl = 0;
         lowFlg = false;
-		//socd_V_chrgCCV = look1_iu16lu16n16tu16_binlcase(socc_pct_chrgCor, (&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])), 12U) + sfmd_I_curr * (look1_iu16lu16n16tu16_binlcase(socc_pct_chrgCor, (&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])), 12U) + cdmv_ohm_deltR[sfmd_idx_cellUMax]) * 0.001 * 0.1;
-		socd_V_chrgCCV = look1_is16lu16n16tu16_binlcase(sfmd_I_curr,&socm_I_chrgCor[0],&socm_V_chrgCor[0],2U); 
-		if (sfmd_V_cellUMax >= socd_V_chrgCCV)
-        {
-            overCntl = (overCntl + 1) > 250 ? 250 : (overCntl + 1);
-        }
-        else
-        {
-            overCntl = 0;
-        }
-        if (overCntl > 2 || overFlg)
-        {
-            overFlg = 1;
-        }
-        //
-        if (sfmd_V_cellUMax >= cmnc_V_chrgFul)
-        {
-            fulCntl = (fulCntl + 1) > 250 ? 250 : (fulCntl + 1);
-        }
-        else
-        {
-            fulCntl = 0;
-        }
-        if ((fulCntl > 2) || fulFlg)
-        {
-            fulFlg = 1;
-        }
-        
+		
+	    socn_V_chrgCCV = look1_i16tu16(sfmd_I_curr,socm_I_chrgCor,socm_V_chrgCor,3); 
+		overFlg = JudgeTimeSystem(1,sfmd_V_cellUMax >= socn_V_chrgCCV,&overCntl,2) || overFlg;
+        fulFlg  = JudgeTimeSystem(1,sfmd_V_cellUMax >= cmnc_V_chrgFul,&fulCntl ,2) || fulFlg;
         //
         if (overFlg)
         {
@@ -493,15 +420,11 @@ void SOC(void)
             }
             socTemp = (uint16_T)(ahSoc - ahSoc0_utrckOver + estSoc0_utrckOver);
         }
-        else if (chrgCntl > 2)
+        else
         {
             onceFlg_utrckOver = true;
             socTemp = socd_pct_estSoc > socc_pct_chrgCor ? socc_pct_chrgCor : socd_pct_estSoc;
         }
-        else
-        {
-            socTemp = socd_pct_estSoc;
-        }
         //
         socn_pct_utrackSoc = Soc_Delay + (socTemp > Soc_Delay ? (socTemp - Soc_Delay) : 0);
         Soc_Delay = socn_pct_utrackSoc;
@@ -515,124 +438,95 @@ void SOC(void)
             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);
         Soc_Delay = 0;
         overCntl = 0;
         overFlg = false;
         fulFlg = false;
         fulCntl = 0;
-		socd_V_disChrgCCV = look1_is16lu16n16tu16_binlcase(sfmd_I_curr,&socm_I_disChrgCor[0],&socm_V_disChrgCor[0],2U) + (int16_T)(int32_T)sfmd_I_curr * (cdmv_ohm_deltR[sfmd_idx_cellUMin]) * 0.001 * 0.1;
-        if (sfmd_V_cellUMin <= socd_V_disChrgCCV)
-        {
-            lowCntl = (lowCntl + 1) > 250 ? 250 : (lowCntl + 1);
-        }
-        else
-        {
-            lowCntl = 0;
-        }
-        if (lowCntl > 2 || lowFlg)
-        {
-            lowFlg = true;
-        }
+		if (!cdmd_flg_deltOCVDisable)
+		{
+		    socn_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
+		{
+		    socn_V_disChrgCCV = look1_i16tu16(sfmd_I_curr,socm_I_disChrgCor,socm_V_disChrgCor,3);
+		}
+		lowFlg = JudgeTimeSystem(1,sfmd_V_cellUMin <= socn_V_disChrgCCV,&lowCntl,2) || lowFlg;
         //
         if (lowFlg)
         {
             if (onceFlg_utrckLow)
             {
                 onceFlg_utrckLow = false;
-                ahSoc0_utrckLow = ahSoc;
-                estSoc0_utrckLow = socd_pct_estSoc < socc_pct_disChrgCor ? socd_pct_estSoc : socc_pct_disChrgCor;
+                ahSoc0_utrckLow  = ahSoc;
+                estSoc0_utrckLow = socc_pct_disChrgCor;
             }
             socn_pct_utrackSoc = (int16_T)(ahSoc - ahSoc0_utrckLow + estSoc0_utrckLow) > 0 ? (uint16_T)(ahSoc - ahSoc0_utrckLow + estSoc0_utrckLow) : 0;
         }
-        else if (disChrgCntl > 2)
+        else 
         {
             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;
+		
+        //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);
     }
+	socd_pct_battSoc = Saturation_u(socn_pct_utrackSoc, socc_pct_battSocLow, socc_pct_battSocUp);
+    socd_pct_battSocEo = socd_pct_battSoc;
+
     
     //===============================================================================================================================================================
-    ////////////////////////////////////////////////////////////////////BCUSOC///////////////////////////////////////////////////////////////////////////////////////
-    //===============================================================================================================================================================
-    
-    if (sfmd_I_curr < 10 && sfmd_I_curr > -10)
-    {
-        statCntl = (statCntl + 1) > 250 ? 250 : (statCntl + 1);
-    }
-    else
-    {
-        statCntl = 0;
-    }
-    statFlg = statCntl > 2;
-    
-    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;
-    socn_pct_utrackSoc_Delay = socn_pct_utrackSoc;
+    ////////////////////////////////////////////////BCUSOC///////////////////////////////////////////////////////////////////////////////////////////////////////////
+    //=============================================================================================================================================================== 
+    Flg = (socd_flg_firstRun || (socn_st_workStat_Delay == 2 && ihd_st_workStat != 2) || (socn_st_workStat_Delay != 2 && ihd_st_workStat == 2) ||
+          ((int16_T)(socd_pct_battSoc  - socn_pct_battSoc_Delay) > 5 || (int16_T)(socd_pct_battSoc - socn_pct_battSoc_Delay) < -5) ||
+          JudgeTimeSystem(1,sfmd_I_curr < 10 && sfmd_I_curr > -10,&statCntl ,3));
+	
+    socn_st_workStat_Delay = ihd_st_workStat;
+    socn_pct_battSoc_Delay = socd_pct_battSoc;
     
     //
     if (Flg)
     {
-        socd_pct_battSoc0 = socd_pct_battSoc;
-        if (FirstRun_SOC)
+        socn_pct_battSoc0 = socd_pct_battSoc;
+        if (socd_flg_firstRun)
         {
-            socd_pct_bcuSoc0 = socn_pct_bcuSocEE;
+            socn_pct_bcuSoc0 = socn_pct_bcuSocEE;
         }
         else
         {
-            socd_pct_bcuSoc0 = socd_pct_bcuSoc;
+            socn_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);
     //
     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);
+        delSOC = socn_pct_battSoc0 > socn_pct_bcuSoc0 ? (socn_pct_battSoc0 - socn_pct_bcuSoc0) : (socn_pct_bcuSoc0 - socn_pct_battSoc0);
+        coinSoc = (socn_pct_battSoc0 > socn_pct_bcuSoc0 ? socn_pct_battSoc0 : socn_pct_bcuSoc0) + (delSOC > 50 ? 50 : delSOC);
         
-        x[0] = socd_pct_battSoc0;
-        x[1] = coinSoc > socc_pct_battSocUp ? socc_pct_battSocUp : (uint16_T)coinSoc;
+        x[0] = socn_pct_battSoc0 > socc_pct_battSocUp - 2 ? socc_pct_battSocUp - 2 : socn_pct_battSoc0;
+        x[1] = coinSoc > socc_pct_battSocUp - 1 ? socc_pct_battSocUp - 1: (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]);
+        y[0] = socn_pct_bcuSoc0 > socc_pct_battSocUp - 2 ? socc_pct_battSocUp - 2 : socn_pct_bcuSoc0;;
+        y[1] = coinSoc > socc_pct_battSocUp - 1 ? socc_pct_battSocUp - 1: (uint16_T)coinSoc;
+        y[2] = socc_pct_battSocUp;
+        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)
@@ -643,97 +537,79 @@ void SOC(void)
         {
             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],battSOC:%d,bcusoc:%d,socd_pct_bcuSoc:%d\n",x[0],x[1],x[2],y[0],y[1],y[2],socd_pct_battSoc,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));
+        delSOC = socn_pct_battSoc0 > socn_pct_bcuSoc0 ? (socn_pct_battSoc0 - socn_pct_bcuSoc0) : (socn_pct_bcuSoc0 - socn_pct_battSoc0);
+        coinSoc = (int16_T)((socn_pct_battSoc0 < socn_pct_bcuSoc0 ? socn_pct_battSoc0 : socn_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]);
+        x[1] = coinSoc < socc_pct_battSocLow + 1 ? socc_pct_battSocLow + 1 : (uint16_T)coinSoc;
+        x[2] = socn_pct_battSoc0 < socc_pct_battSocLow + 2 ? socc_pct_battSocLow + 2 : (uint16_T)socn_pct_battSoc0;
+		
+        y[0] = socc_pct_battSocLow;
+        y[1] = coinSoc < socc_pct_battSocLow + 1 ? socc_pct_battSocLow + 1 : (uint16_T)coinSoc;
+        y[2] = socn_pct_bcuSoc0 < socc_pct_battSocLow + 2 ? socc_pct_battSocLow + 2 : (uint16_T)socn_pct_bcuSoc0;
+        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_bcuSoc = Saturation_u(socd_pct_bcuSoc, socc_pct_battSocLow, socc_pct_battSocUp);
     socd_pct_bcuSocEo = socd_pct_bcuSoc;
-    FirstRun_SOC = false;
-    //printf("\n");
+
+	//=======================================VCUSOC========================================================================================
+	
+    socd_pct_vcuSoc =  (uint16_T)((uint32_T)((socd_pct_bcuSoc - socc_pct_battSocLow) * 1000) / (socc_pct_battSocUp - socc_pct_battSocLow)); 
+	
+    //================================================================================================
+    //------------------EEsave-------------------------------------------=============================
+    //================================================================================================
+    if ((int16_T)(socd_pct_battSoc - socn_pct_battSoc_save) > 10 || (int16_T)(socd_pct_battSoc - socn_pct_battSoc_save) < -10 || (int16_T)(socd_pct_bcuSoc - socn_pct_bcuSoc_save) > 10 || (int16_T)(socd_pct_bcuSoc - socn_pct_bcuSoc_save) < -10 )
+    {
+        socd_flg_EEsave = 1;
+        socn_pct_battSoc_save = socd_pct_battSoc;
+	    socn_pct_bcuSoc_save  = socd_pct_bcuSoc;
+    }
+    else
+    {
+        socd_flg_EEsave = 0;
+    }
+
+	
+    socd_flg_firstRun = false;
+
+	//printf("\n");
 }
 
-//-------------------------------------------------------------------------
+
+
+//===================================================================================================================
+//----------------------------function-------------------------------------------------------------------------------
+//===================================================================================================================
 real_T docvmath(real_T soc)
 {
     real_T docv;
-    docv = ((((((-1.0936E-13 * pow(soc, 7.0) +
-            3.9249E-11 * pow(soc, 6.0)) +
-            -5.5776E-9 * pow(soc, 5.0)) +
-            3.996E-7 * pow(soc, 4.0)) +
-            -1.5332E-5 * pow(soc, 3.0)) +
-            soc * soc * 0.0003192) +
-            -0.00371 * soc) +
-            0.02732;
+    docv = ((((((-1.0936E-13 * pow(soc, 7.0) +3.9249E-11 * pow(soc, 6.0)) +
+            -5.5776E-9 * pow(soc, 5.0)) + 3.996E-7 * pow(soc, 4.0)) +
+            -1.5332E-5 * pow(soc, 3.0)) +soc * soc * 0.0003192) +
+           -0.00371 * soc) +0.02732;
     return docv;
 }
+
 ////
-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;
-}
+

+ 42 - 0
src/EmbeddedCoder_src/SOE.c

@@ -0,0 +1,42 @@
+#include "SOE.h"
+
+void SOE_Init(void)
+{
+    soed_flg_firstRun = true;
+}
+//-------------------------------------------------------------------------
+void SOE(void)
+{
+    uint32_T soen_V_battOcv;
+    uint16_T i;
+
+	
+	// 满电能量
+    if(soed_flg_firstRun)
+    {
+        soen_V_battOcv = 0;
+        for(i = socc_pct_battSocUp ;i >= socc_pct_battSocLow + 1;i--)
+        {
+            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);
+    }
+	//当前SOC的剩余能量
+    if(socd_pct_battSoc > socc_pct_battSocLow)
+    {
+        soen_V_battOcv = 0;
+        for(i = socd_pct_battSoc;i >= socc_pct_battSocLow + 1;i--)
+        {
+            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);
+    }
+    else
+    {
+        soed_E_nowEng = 0;
+    }
+    soed_pct_nowStat = (uint16_T)((uint32_T)(soed_E_nowEng * 1000)/soed_E_fullEng);
+    soed_flg_firstRun = false;   
+}
+
+

+ 52 - 79
src/EmbeddedCoder_src/SOH.c

@@ -1,11 +1,8 @@
 #include "SOH.h"
-#include "look1_iu16lu16n16tu16_binlcase.h"
-
-boolean_T FirstRun_SOH;
 
 void SOH_Init(void)
 {
-    FirstRun_SOH = true ;
+    sohd_flg_firstRun = true ;
 }
 
 void SOH(void)
@@ -35,38 +32,47 @@ void SOH(void)
     uint16_T SumQ;
     //
     static uint16_T sohn_V_chrgStartStat[cmnc_num_cellUNumMax];
-    static uint8_T ihd_st_workStat_Delay;
-    static boolean_T sohn_flg_chrgEnd_Delay;
-    boolean_T sohn_flg_chrgEnd;
+    static uint8_T sohn_st_workStat_Delay;
     //
     static real_T Ahincr;
-    int32_T  tmp_0; 
+    int16_T  tmp_0; 
     static boolean_T sfmn_flg_currFlt_keep;
     static boolean_T sohn_flg_currFlt;
     boolean_T DisEn;
-    
-    if(FirstRun_SOH)
+
+
+	//初值
+    if(sohd_flg_firstRun)
     {   
         sohn_flg_update = true;
         sfmn_flg_currFlt_keep = false;
         sohn_flg_currFlt = false;
         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;
+        sohn_st_workStat_Delay = 0;
+		if(ihd_st_reSet == 1)
+		{
+           memcpy(sohv_V_chrgStartStatEo,sohv_V_chrgStartStatEi, sizeof(sohv_V_chrgStartStatEo));
+	       sohd_Q_chrgEo = sohd_Q_chrgEi;
+	       sohd_flg_chrgEndEo = sohd_flg_chrgEndEi; 
+		}
+		else
+		{
+		   memset(sohv_V_chrgStartStatEo,0, sizeof(sohv_V_chrgStartStatEo));
+		   sohd_Q_chrgEo = 0 ;
+		   sohd_flg_chrgEndEo = 0; 
+		}	
     }
-	
-    if(FirstRun_SOH)
+  
+
+    if(sohd_flg_firstRun)
     {
         //=======================================================================================
         //--------------------------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));
@@ -112,32 +118,31 @@ 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);
-				
+
                 if( (int16_T)(sohv_Q_cellCapArrEo[i]) - sohn_Q_cellCapArrEE[i] > sohc_Q_updateDeltThr  ||  (int16_T)(sohv_Q_cellCapArrEo[i]) - sohn_Q_cellCapArrEE[i] < -sohc_Q_updateDeltThr  )
                 {
                     sohn_flg_update = false;
                     break;
                 }
             }
-            DisEn = (ArrMin((&(soc2[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)
             {   
 				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)((uint32_T)(sohv_Q_cellCapArrEo[i] * (1000 - soc2[i]))/1000);
+                     disChrgCellCapArr[i] = (uint16_T)((uint32_T)(sohv_Q_cellCapArrEo[i] * (        soc2[i]))/1000);
  				} 
-                 chrgCap_Min = ArrMin((&(chrgCellCapArr[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];
@@ -156,7 +161,7 @@ void SOH(void)
              memcpy(sohv_Q_cellCapArrEo,sohn_Q_cellCapArrEE, sizeof(sohv_Q_cellCapArrEo));
          }
 		 memcpy(sohv_Q_cellCap,sohv_Q_cellCapArrEo, sizeof(sohv_Q_cellCapArrEo));
-        // printf("sohv_Q_cellCapArrEo[16]:%d,update:%d,En:%d\n",sohv_Q_cellCapArrEo[16],sohn_flg_update,sohn_flg_countEn);
+
  
          SumQ = 0;
          for(i = 0; i < 10;i++)
@@ -170,9 +175,9 @@ void SOH(void)
      //=======================================================================================
      //----------------------充电前信息-------------------------------------------------------
      //=======================================================================================
-     if (FirstRun_SOH)
+     if (sohd_flg_firstRun)
      {
-     	memcpy(sohn_V_chrgStartStat,appv_V_cellU, sizeof(appv_V_cellU));
+     	 memcpy(sohn_V_chrgStartStat,appv_V_cellU, sizeof(appv_V_cellU));
      }
      
      if(sfmd_I_curr < 10 && sfmd_I_curr > -10 && !sfmd_flg_cellUDisable)
@@ -180,7 +185,7 @@ void SOH(void)
          memcpy(sohn_V_chrgStartStat,sfmv_V_cellU, sizeof(sfmv_V_cellU));
      }
      //
-     if((ihd_st_workStat == 2) && (ihd_st_workStat_Delay != 2))
+     if((ihd_st_workStat == 2) && (sohn_st_workStat_Delay != 2))
      {
         memcpy(sohv_V_chrgStartStatEo,sohn_V_chrgStartStat, sizeof(sohv_V_chrgStartStatEo));
      }
@@ -207,56 +212,24 @@ void SOH(void)
         sfmn_flg_currFlt_keep = false;
         Ahincr = 0;
     }
-	//printf("sohd_Q_chrgEo:%d\n",sohd_Q_chrgEo);
-	 //=======================================================================================
+
+	//=======================================================================================
     //----------------------充电结速信息------------------------------------------------------
     //=======================================================================================
-    if((ihd_st_workStat != 2) && (ihd_st_workStat_Delay == 2))
+    if((ihd_st_workStat != 2) && (sohn_st_workStat_Delay == 2))
     {
-       sohn_flg_chrgEnd = true; 
+       sohd_flg_chrgEndEo = true; 
     }
     else
     {
-      sohn_flg_chrgEnd = ( sfmd_I_curr < 10 && sfmd_I_curr > -10) && sohn_flg_chrgEnd_Delay;
+      sohd_flg_chrgEndEo = ( sfmd_I_curr < 10 && sfmd_I_curr > -10) && sohd_flg_chrgEndEo;
     }
-	
-    sohn_flg_chrgEnd_Delay = sohn_flg_chrgEnd;
-    sohd_flg_chrgEndEo =  !sohn_flg_currFlt && sohn_flg_chrgEnd;
-    ihd_st_workStat_Delay = ihd_st_workStat;
-	FirstRun_SOH = false;	
-	//printf("sohd_flg_chrgEndEo:%d\n",sohd_flg_chrgEndEo);
-}
-
+    sohd_flg_chrgEndEo =  !sohn_flg_currFlt && sohd_flg_chrgEndEo;
 
-////////////////////////////////////////////////////////////////
-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;
+    //
+    sohn_st_workStat_Delay = ihd_st_workStat;
+	sohd_flg_firstRun = false;	
 }
 
-///////////////////////////////////////////////////////////////////
-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;
-}
+
 

+ 143 - 0
src/EmbeddedCoder_src/SOP.c

@@ -0,0 +1,143 @@
+#include "SOP.h"
+
+void SOP_Init(void)
+{
+    sopd_flg_firstRun = true;
+}
+//-------------------------------------------------------------------------
+
+void SOP(void)
+{
+    static real_T sopn_V_up;
+    real_T sopn_I_currPred;
+    real_T sopn_V_battPred10;
+    real_T sopn_pct_socPred10;
+    real_T ocv;
+    real_T Ro;
+    real_T RC;
+    real_T Rp;
+    real_T ileft;
+    real_T iright;
+    real_T imid;
+    real_T sopn_V_battU;
+    if(sopd_flg_firstRun)
+    {
+        sopn_V_up = 0;
+    }
+    ocv = (real_T)look1_u16tu16(socd_pct_battSoc, cmnm_pct_soc, cmnm_V_ocv,  13) * 0.001;
+    Ro  = (real_T)look1_u16tu16(socd_pct_battSoc, cmnm_pct_soc, cmnm_R_ohm,  13) * 0.001 * 0.001;
+    Rp  = (real_T)look1_u16tu16(socd_pct_battSoc, cmnm_pct_soc, cmnm_R_polar,13) * 0.001 * 0.001;
+    RC  = (real_T)look1_u16tu16(socd_pct_battSoc, cmnm_pct_soc, cmnm_F_polar,13) * 0.001;
+	//printf("%f %f  %f  %f\n",ocv,Ro,Rp,RC);
+    sopn_V_up = (real_T)sfmd_V_cellUAvrg * 0.001 - ocv - (real_T)sfmd_I_curr * 0.1 * Ro;
+    //printf("soc:%d,I:%d,up:%f\n",socd_pct_battSoc,sfmd_I_curr,sopn_V_up);
+    //充电功率
+    sopn_I_currPred = 0;
+    predSystem(ocv,Ro,Rp,RC,sopn_I_currPred,sopn_V_up,&sopn_pct_socPred10,&sopn_V_battPred10);
+
+    if(sopn_V_battPred10 > (real_T)cmnc_V_chrgFul * 0.001 || sopn_pct_socPred10 > (real_T)socc_pct_battSocUp * 0.1)
+    {
+        sopn_I_currPred = 0;
+        
+    }
+    else
+    {
+        sopn_I_currPred = (real_T)sopc_I_currUp * 0.1;
+        predSystem(ocv,Ro,Rp,RC,sopn_I_currPred,sopn_V_up,&sopn_pct_socPred10,&sopn_V_battPred10);
+        if(sopn_V_battPred10 < (real_T)cmnc_V_chrgFul * 0.001 && sopn_pct_socPred10 < (real_T)socc_pct_battSocUp * 0.1)
+        {
+            sopn_I_currPred = (real_T)sopc_I_currUp * 0.1;;
+        }
+        else
+        {
+            iright = (real_T) sopc_I_currUp * 0.1;
+            ileft = 0;
+            imid = (iright + ileft)/2;
+            while(iright - ileft > 0.1)
+            {
+                predSystem(ocv,Ro,Rp,RC,imid,sopn_V_up,&sopn_pct_socPred10,&sopn_V_battPred10);
+                
+                if(sopn_V_battPred10 > (real_T)cmnc_V_chrgFul * 0.001 || sopn_pct_socPred10 > (real_T)socc_pct_battSocUp * 0.1)
+                {
+                    iright =  imid;
+                }
+                else
+                {
+                    ileft =  imid;
+                }
+                imid = (iright + ileft)/2;
+            }
+			sopn_I_currPred = ileft;
+        }
+    }
+    sopn_V_battU = (ocv +  sopn_I_currPred * Ro + sopn_V_up) * cmnc_num_cellUNum;
+	sopd_I_chrgCurrMax = (int16_T)(sopn_I_currPred * 10);
+    sopd_P_chrgPMax = (uint16_T)(sopn_V_battU * sopn_I_currPred);
+	predSystem(ocv,Ro,Rp,RC,sopn_I_currPred,sopn_V_up,&sopn_pct_socPred10,&sopn_V_battPred10);
+    //printf("%f,  %f, %f\n\n",sopn_I_currPred,sopn_pct_socPred10,sopn_V_battPred10);
+
+	
+    //放电功率
+    
+    sopn_I_currPred = 0;
+    predSystem(ocv,Ro,Rp,RC,sopn_I_currPred,sopn_V_up,&sopn_pct_socPred10,&sopn_V_battPred10);
+    if(sopn_V_battPred10 < (real_T)cmnc_V_disChrgLim * 0.001 || sopn_pct_socPred10 < (real_T)socc_pct_battSocLow * 0.1)
+    {
+        sopn_I_currPred = 0;
+    }
+    else
+    {
+        sopn_I_currPred = (real_T)sopc_I_currLow * 0.1;
+        predSystem(ocv,Ro,Rp,RC,sopn_I_currPred,sopn_V_up,&sopn_pct_socPred10,&sopn_V_battPred10);
+        if(sopn_V_battPred10 > (real_T)cmnc_V_disChrgLim * 0.001 && sopn_pct_socPred10 > (real_T)socc_pct_battSocLow * 0.1)
+        {
+            sopn_I_currPred = (real_T)sopc_I_currLow * 0.1;;
+        }
+        else
+        {
+            iright = 0;
+            ileft = (real_T) sopc_I_currLow * 0.1;
+            imid = (iright + ileft)/2;
+            while(iright - ileft > 0.1)
+            {
+                predSystem(ocv,Ro,Rp,RC,imid,sopn_V_up,&sopn_pct_socPred10,&sopn_V_battPred10);
+                if(sopn_V_battPred10 > (real_T)cmnc_V_disChrgLim * 0.001 && sopn_pct_socPred10 > (real_T)socc_pct_battSocLow * 0.1)
+                {
+                    iright =  imid;
+                }
+                else
+                {
+                    ileft =  imid;
+                }
+                imid = (iright + ileft)/2;
+            }
+            sopn_I_currPred = iright;
+        }
+    }
+    sopn_V_battU = sopn_V_battPred10 * cmnc_num_cellUNum;
+	sopd_I_disChrgCurrMax = (int16_T)(sopn_I_currPred * 10);
+    sopd_P_disChrgPMax = (uint16_T)(- sopn_V_battU * sopn_I_currPred);
+    
+    
+    //sopn_V_up = sopn_V_up * exp(-1/RC) + Rp * (1 - exp(-1/RC)) * sfmd_I_curr;
+    sopd_flg_firstRun = false;
+}
+
+void predSystem(real_T ocv,real_T Ro,real_T Rp,real_T RC,real_T sopn_I_currPred,real_T sopn_V_up,real_T *sopn_pct_socPred10,real_T *sopn_V_battPred10)
+{
+    uint8_T i;
+    real_T sopn_V_upPred;
+    real_T sopn_pct_socPred;
+    real_T sopn_Q_cellCap;
+    sopn_Q_cellCap = (real_T)sohd_pct_bcuSoh * cmnc_Q_ratedCp * 0.0001;
+    sopn_pct_socPred = (real_T) socd_pct_battSoc * 0.1;
+    sopn_V_upPred = sopn_V_up;
+    for(i = 0;i < 10;i++)
+    {
+        sopn_V_upPred = sopn_V_upPred * exp(-1/RC) + Rp * (1 - exp(-1/RC)) * sopn_I_currPred;
+        sopn_pct_socPred = sopn_pct_socPred + sopn_I_currPred/sopn_Q_cellCap/36;
+    }
+    *sopn_pct_socPred10 = sopn_pct_socPred;
+    *sopn_V_battPred10 = ocv +  sopn_I_currPred * Ro + sopn_V_upPred;
+}
+

+ 65 - 0
src/EmbeddedCoder_src/SOR.c

@@ -0,0 +1,65 @@
+#include "SOR.h"
+
+void SOR_Init(void)
+{
+    sord_flg_firstRun = true;
+}
+//-------------------------------------------------------------------------
+void SOR(void)
+{
+    static uint16_T sorn_ohm_cellREE[cmnc_num_cellUNumMax];
+    static uint16_T sorn_ohm_cellREEArr[5][cmnc_num_cellUNumMax];
+    uint16_T sorn_ohm_cellRSum[cmnc_num_cellUNumMax];
+	static uint16_T sorn_V_cellU[cmnc_num_cellUNumMax];
+	static uint8_T sorn_num_ctn;
+	static int16_T sorn_I_curr;
+    uint16_T i;
+    uint16_T j;
+	
+    //
+    if(sord_flg_firstRun)
+    {
+        sorn_num_ctn = 0;
+        sorn_I_curr = sfmd_I_curr;
+        memcpy(sorn_V_cellU,sfmv_V_cellU, sizeof(sfmv_V_cellU));
+    }
+    if(sord_flg_firstRun)
+    {
+        if(ArrMax(sorv_ohm_cellREi, cmnc_num_cellUNum) > 65000)
+        {
+            memset(sorn_ohm_cellREE,0, sizeof(sorn_ohm_cellREE));
+        }
+        else
+        {
+            memcpy(sorn_ohm_cellREE,sorv_ohm_cellREi, sizeof(sorv_ohm_cellREi));
+        }
+    }
+
+    
+    if(socd_pct_battSoc >= 550 && socd_pct_battSoc <= 700 && sorn_num_ctn < 5)
+    {
+        if(sfmd_I_curr - sorn_I_curr > 200 || sfmd_I_curr - sorn_I_curr < -200)
+        {
+            for(i = 0;i < cmnc_num_cellUNum;i++)
+            {
+                sorn_ohm_cellREEArr[sorn_num_ctn][i] = (uint16_T)( ((real_T)(sorn_V_cellU[i] - sfmv_V_cellU[i]) * 0.001) / ((real_T)(sorn_I_curr - sfmd_I_curr) * 0.1) * 1000000 );
+            }
+            sorn_num_ctn = sorn_num_ctn + 1;
+            memset(sorn_ohm_cellRSum,0, sizeof(sorn_ohm_cellRSum));
+            for(i = 0;i < cmnc_num_cellUNum;i++)
+            {
+                for(j = 0;j < sorn_num_ctn;j++)
+                {
+                    sorn_ohm_cellRSum[i] =  sorn_ohm_cellRSum[i] + sorn_ohm_cellREEArr[j][i];
+                }
+                sorn_ohm_cellREE[i] = sorn_ohm_cellRSum[i]/sorn_num_ctn;
+            }
+        } 
+    }
+	memcpy(sorv_ohm_cellR,sorn_ohm_cellREE, sizeof(sorn_ohm_cellREE));
+    memcpy(sorv_ohm_cellREo,sorn_ohm_cellREE, sizeof(sorn_ohm_cellREE));
+	
+	sorn_I_curr = sfmd_I_curr;
+    memcpy(sorn_V_cellU,sfmv_V_cellU, sizeof(sfmv_V_cellU));
+    sord_flg_firstRun = false;
+}

+ 29 - 22
src/EmbeddedCoder_src/SPM.c

@@ -1,52 +1,59 @@
 #include "SPM.h"
 
-boolean_T FirstRun_SPM;
-
 void SPM_Init(void)
 {
   SOH_Init();
   BLC_Init();
-  SOC_Init();
   CDM_Init();
-  FirstRun_SPM = true;
+  SOC_Init();
+  PIM_Init();
+  SOE_Init();
+  SOR_Init();
+  SOP_Init();
+  spmd_flg_firstRun = true;
 }
 
 void SPM(void)
 {
-  static uint16_T spmd_Nr_cellNr;
-  uint8_T Feq = 10;
-  if (FirstRun_SPM)
+  static uint16_T spmn_num_cellNr;
+  uint8_T Feq = 30;
+  if (spmd_flg_firstRun)
   {
-    spmd_Nr_cellNr = 0;
-    cand_Nr_cellNr = 1;
+    spmn_num_cellNr = 0;
+    cand_idx_cellNr = 1;
   }
-  spmd_Nr_cellNr = spmd_Nr_cellNr + 1;
-  if (spmd_Nr_cellNr % (10 * Feq) == 0)
+  spmn_num_cellNr = spmn_num_cellNr + 1;
+  if (spmn_num_cellNr % Feq == 0)
   {
-    cand_Nr_cellNr ++;
+    cand_idx_cellNr ++;
   }
-  else if (spmd_Nr_cellNr > 60000)
+  else if (spmn_num_cellNr > 60000)
   {
-    spmd_Nr_cellNr = 0;
+    spmn_num_cellNr = 0;
   }
-  if (cand_Nr_cellNr > cmnc_num_cellUNum)
+  if (cand_idx_cellNr > cmnc_num_cellUNum)
   {
-    cand_Nr_cellNr = 1;
+    cand_idx_cellNr = 1;
   }
   //调用SOX算法
   SOH();
   BLC();
-  if (ihd_flg_urtRecFlg)
+  if (ihd_flg_urtRecFlg && sfmd_V_cellUMin != 0)
   {
       CDM();
 	  SOC();
+	  PIM();
+	  SOE();
+	  SOR();
+	  SOP();
   }
   // 循环发送数组
-  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;
+  cand_Q_cellCap = sohv_Q_cellCapArrEo[cand_idx_cellNr-1];
+  cand_V_chrgStartStat = sohv_V_chrgStartStatEo[cand_idx_cellNr-1];
+  cand_Q_blcReqCp   = blcv_Q_reqCpEo[cand_idx_cellNr-1];
+  cand_Q_blcTotalCp = blcv_Q_totalCpEo[cand_idx_cellNr-1];
+  
+  spmd_flg_firstRun = false;
 }
 
 

+ 465 - 0
src/EmbeddedCoder_src/funlib.c

@@ -0,0 +1,465 @@
+#include "funlib.h"
+
+
+
+//-------------------uint16鏁扮粍鍙栨渶澶�-------------------------------------
+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鏁扮粍鍙栨渶灏�-------------------------------------
+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鏁扮粍姹傚潎鍊�////////////////////////////////////
+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;
+}
+
+//-----------------real_T 闄愬箙鍑芥暟
+real_T Saturation_r(real_T in,real_T LowLim,real_T UpLim)
+{
+   real_T out;
+
+   out = in > LowLim ? in : LowLim;
+   out = out > UpLim ? UpLim : out;
+   return out;
+}
+
+//-----------------uint16 闄愬箙鍑芥暟
+
+uint16_T Saturation_u(uint16_T in,uint16_T LowLim,uint16_T UpLim)
+{
+   uint16_T out;
+
+   out = in > LowLim ? in : LowLim;
+   out = out > UpLim ? UpLim : out;
+   return out;
+}
+
+
+// ---------------------婊ゆ尝鎺у埗鍙樺姩閫熺巼-------------------------------------- 
+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;
+}
+
+// ---------------------婊ゆ尝鎺у埗鍙樺姩閫熺巼-------------------------------------- 
+uint8_T DataFilt8(uint8_T in, uint8_T *out, uint8_T Lim)
+{
+    int8_T delt;
+    delt = (int8_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]
- */

+ 10 - 10
src/bsp_custom.c

@@ -192,7 +192,7 @@ void BSP_CustomInit(void)
     relayConfigInit();
 
 #if LOW_POWER_AT_TEST
-    //slpManRegisterUsrSlpDepthCb(CheckUsrdefSlpStatus);  //暂时屏蔽Rx拉低不允许睡眠的操作
+    // slpManRegisterUsrSlpDepthCb(CheckUsrdefSlpStatus);  //暂时屏蔽Rx拉低不允许睡眠的操作
 #endif
 
     plat_config_raw_flash_t *rawFlashPlatConfig;
@@ -221,12 +221,12 @@ void BSP_CustomInit(void)
     slpManGetPMUSettings();
     ResetReasonInit();
     PMU_WakeupPadInit();
-    NVIC_EnableIRQ(PadWakeup0_IRQn);  //can
-    NVIC_DisableIRQ(PadWakeup1_IRQn); //rx
-    NVIC_EnableIRQ(PadWakeup2_IRQn);  //lock
-    NVIC_DisableIRQ(PadWakeup3_IRQn); //gsensor
-    NVIC_DisableIRQ(PadWakeup4_IRQn); //gsensor
-    NVIC_EnableIRQ(PadWakeup5_IRQn);  //wakeup2
+    NVIC_EnableIRQ(PadWakeup0_IRQn);  // can
+    NVIC_DisableIRQ(PadWakeup1_IRQn); // rx
+    NVIC_EnableIRQ(PadWakeup2_IRQn);  // lock
+    NVIC_DisableIRQ(PadWakeup3_IRQn); // gsensor
+    NVIC_DisableIRQ(PadWakeup4_IRQn); // gsensor
+    NVIC_EnableIRQ(PadWakeup5_IRQn);  // wakeup2
     CheckLockOutState();
     slpManStartWaitATTimer();
 
@@ -266,17 +266,17 @@ void Pad0_WakeupIntHandler(void)
 
 void Pad1_WakeupIntHandler(void)
 {
-    UartInterruptcount++;
     if (slpManExtIntPreProcess(PadWakeup1_IRQn) == false)
     {
         return;
     }
     else
     {
-#ifdef USING_PRINTF
+#ifdef USING_PRINTF1
         printf("Pad1-[%d]\n", __LINE__);
 #endif
-        setbit(PadInterrupt, 1);
+        UartInterruptcount++;
+        // setbit(PadInterrupt, 1);
     }
 }
 

Някои файлове не бяха показани, защото твърде много файлове са промени