浏览代码

【V3.0.0.15】 在14的基础上修改了蜂鸣器问题,LED闪灯问题,Uart中断唤不醒问题以及异常唤醒问题,soc策略更改,变为可变区间控制,soc进行了替换,新增了整包容量观测量

CHENJIE-PC\QiXiang_CHENJIE 3 年之前
父节点
当前提交
edd9b8bccc

+ 7 - 7
inc/AppConfig.h

@@ -2,19 +2,19 @@
  * @Author       : ChenJie
  * @Date         : 2021-10-14 09:27:15
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-10-14 15:56:31
+ * @LastEditTime : 2021-10-15 16:46:35
  * @Description  : App Config H file 配置文件,可以针对不同参数进行更改
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\inc\AppConfig.h
  */
 
 #ifndef APPCONFIG_H
 #define APPCONFIG_H
-#define BMS_MANUFACTURE (2)           //BMS制造商表示1-超力源,2-美顺
-#define BMS_INFO (3)                  //1-1表示超力源4830,1-2表示超力源6060,2-1表示美顺4830,2-2表示美顺6060 2-3表示美顺7250
-#define DATA_MODULE_TYPE (1)          //1表示NB模块,2表示4G cat1
-#define EOLSTATE (0)                  //1表示下线检测跳过,使用默认值,0表示使用下线检测
-#define DEFAULT_SN "RRRRRR0000000003" //默认上传的SN编码
-#define APPSWVERSION 0x0300000E       //数据模块软件版本号
+#define BMS_MANUFACTURE (2)            //BMS制造商表示1-超力源,2-美顺
+#define BMS_INFO (3)                   //1-1表示超力源4830,1-2表示超力源6060,2-1表示美顺4830,2-2表示美顺6060 2-3表示美顺7250
+#define DATA_MODULE_TYPE (1)           //1表示NB模块,2表示4G cat1
+#define EOLSTATE (0)                   //1表示下线检测跳过,使用默认值,0表示使用下线检测
+#define DEFAULT_SN "RLTEST00000000001" //默认上传的SN编码
+#define APPSWVERSION 0x0300000F        //数据模块软件版本号
 
 #define TCP_ADD "iotp.fast-fun.cn" //数据上传的地址
 #define TCP_PORT 8712              //数据上传的端口

+ 33 - 24
inc/AppFunc.h

@@ -1,3 +1,12 @@
+/*
+ * @Author       : ChenJie
+ * @Date         : 2021-10-14 09:27:15
+ * @Version      : V3.0
+ * @LastEditors  : ChenJie
+ * @LastEditTime : 2021-10-14 18:15:45
+ * @Description  : file content
+ * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\inc\AppFunc.h
+ */
 /****************************************************************************
  *
  * Copy right:   RL.Chen J and Zhen C
@@ -13,30 +22,30 @@
 #include "mem_map.h"
 #include "AppConfig.h"
 #include "ec_tcpip_api.h"
-#include "AppSignal.h"  
+#include "AppSignal.h"
 typedef struct _Fota_Type
 {
-    BOOL    Fota_update_error ;
-    UINT32  Fota_All_Data_Len ;
-    UINT32  Fota_Current_Addres ;
-    UINT8   Fota_Recv_Data_Len ;
-    UINT8   Fota_Recv_Data[100] ;
-    UINT32  Fota_Flash_Addres;
-    UINT8   Fota_CRC ;
+    BOOL Fota_update_error;
+    UINT32 Fota_All_Data_Len;
+    UINT32 Fota_Current_Addres;
+    UINT8 Fota_Recv_Data_Len;
+    UINT8 Fota_Recv_Data[100];
+    UINT32 Fota_Flash_Addres;
+    UINT8 Fota_CRC;
 
-}Fota_Type;
-void ExpiryTimeCal(UINT8 *StartTimeArray,UINT16 rentalDays,UINT8 *ExpiryTimeArray);
+} Fota_Type;
+void ExpiryTimeCal(UINT8 *StartTimeArray, UINT16 rentalDays, UINT8 *ExpiryTimeArray);
 INT8 rentalEndDetectFunc(void);
 void BattLockFunc(void);
 void BattWorkDelayFunc(UINT8 battWorkCurrentState);
-UINT8 bcc_chk(UINT8* data, UINT16 length);
+UINT8 bcc_chk(UINT8 *data, UINT16 length);
 void LEDDisplay(void);
-BOOL uartBattInfoDecode(UINT8* dataPtr);
+BOOL uartBattInfoDecode(UINT8 *dataPtr);
 static UINT8 BmsErrorDecode(UINT32 battWarningState);
-UINT16 GetErrorNum(UINT16 *ErrorArray,UINT8 Errorlen);
-UINT8 PutErrorNum(UINT16 *ErrorArray,UINT8 Errorlen,UINT16 ErrorNum);
+UINT16 GetErrorNum(UINT16 *ErrorArray, UINT8 Errorlen);
+UINT8 PutErrorNum(UINT16 *ErrorArray, UINT8 Errorlen, UINT16 ErrorNum);
 UINT8 LookUpRTtable(UINT32 R_value);
-BOOL BattHeaterSwitch(UINT8* heaterSwitch,UINT8 HeatForceControl);
+BOOL BattHeaterSwitch(UINT8 *heaterSwitch, UINT8 HeatForceControl);
 void SaveAppData(void);
 void LoadAppData(void);
 void SaveBcuData(void);
@@ -47,18 +56,18 @@ static void setDefaultAppConfigData(void);
 static void setDefaultAppDataInfo(void);
 static void setDefaultBcuDataInfo(void);
 void CanMsgTx1000ms(void);
-void UDS_Service(CAN_Msg_Type* CanRxMsg);
-void CANEncodeFunction(UINT32 ID,UINT8* msgData);
-void relayControlFunc(float DutyRatio);
+void UDS_Service(CAN_Msg_Type *CanRxMsg);
+void CANEncodeFunction(UINT32 ID, UINT8 *msgData);
+void relayControlFunc(UINT8 BuzzerPeriod, float DutyRatio);
 BOOL UDSClearFotaDownloadRegion();
 BOOL UDSAskforDownLoadData();
-UINT8 UDSNegtiveAnswer(UINT8 answerLen,UINT8 messageIndex, UINT32 negCode);
-UINT8 UDSPositiveAnswer(UINT8 answerLen,UINT8 messageIndex,UINT32 posCode);
+UINT8 UDSNegtiveAnswer(UINT8 answerLen, UINT8 messageIndex, UINT32 negCode);
+UINT8 UDSPositiveAnswer(UINT8 answerLen, UINT8 messageIndex, UINT32 posCode);
 
-UINT16  encryptionAlgorithm (UINT16 plainText);
+UINT16 encryptionAlgorithm(UINT16 plainText);
 
-void Fota_Func(UINT8 *DataPtr,INT32 connectId);
-static UINT8 bcc_chk_fota(UINT8* data, UINT8 length);
-static UINT8 Fota_crc_chk(UINT8* data,UINT8 length);
+void Fota_Func(UINT8 *DataPtr, INT32 connectId);
+static UINT8 bcc_chk_fota(UINT8 *data, UINT8 length);
+static UINT8 Fota_crc_chk(UINT8 *data, UINT8 length);
 
 void ErrorNumHandleFunc(void);

+ 72 - 73
inc/AppSignal.h

@@ -2,7 +2,7 @@
  * @Author       : ChenJie
  * @Date         : 2021-10-14 09:27:15
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-10-14 13:54:12
+ * @LastEditTime : 2021-10-15 10:26:39
  * @Description  : Global variable definition H file
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\inc\AppSignal.h
  */
@@ -22,85 +22,84 @@ extern UINT32 ErrFlg;
 extern BOOL downloadReady;
 
 //extern declear the UINT8 vars
-extern UINT8	battCellTemp[8];
-extern UINT8	battHeatEnableState;
-extern UINT8	battMOSSwitchState;
-extern UINT8	battSOC;
-extern UINT8	battSOH;
-extern UINT8	battWorkState;
-extern UINT8	bmsHwVersion;
-extern UINT8	bmsSwVersion;
-extern UINT8	fastChargeTemp;
-extern UINT8	heatTemp1;
-extern UINT8	heatTemp2;
-extern UINT8	maxCellTemp;
-extern UINT8	minCellTemp;
-extern UINT8	MOSTemp;
-extern UINT8	nbReservedTemp1;
-extern UINT8	nbReservedTemp2;
-extern UINT8	normalChargeTemp;
-extern UINT8	packTemp;
-extern UINT8	reservedSignal1;
-extern UINT8	reservedSignal2;
-extern UINT8	reservedSignal3;
-extern UINT8	reservedSignal4;
-extern UINT8	reservedSignal5;
-extern UINT8	reservedSignal6;
-extern UINT8	reservedSignal7;
-extern UINT8	reservedSignal8;
-extern UINT8	UDSService[2];           //uds 服务
-extern UINT8	UDSSubService[2];       // uds 子服务
-extern UINT8	UDSSubServiceActionCode[2];  // uds 子服务状态
-extern UINT8 	PosFlag ;     
-extern UINT8 	UDSSwitch ;
-extern UINT8 	UDSSwitch;
-extern UINT8    AvgBattTemp;
-extern UINT8    BattWorkStateDelay;
-extern UINT8    BMSupdatestatus;
-extern UINT8    BuzzerControl;
-extern UINT8    CanMsgEnble;
-extern UINT8    ChargeForbiddenControl ;
-extern UINT8    chargerConnectState;
-extern UINT8    DisChargeForbiddenControl ;
-extern UINT8    GpsFlag;
-extern UINT8    HeatForceControl;  
-extern UINT8    Lockstatus;
-extern UINT8    PadInterrupt ;
-extern UINT8    RelayForbiddenControl ;
-extern UINT8    TcpErrorcount;
-extern UINT8    TcpSendLen;
-extern UINT8    TCPWorkState;
-extern UINT8    UartCmdRecvFlag;
-extern UINT8    UartErrorFlag ;
-extern UINT8    UartRecvFlag ;
+extern UINT8 AvgBattTemp;
+extern UINT8 battCellTemp[8];
+extern UINT8 battHeatEnableState;
+extern UINT8 battMOSSwitchState;
+extern UINT8 battSOC;
+extern UINT8 battSOH;
+extern UINT8 battWorkState;
+extern UINT8 BattWorkStateDelay;
+extern UINT8 bmsHwVersion;
+extern UINT8 bmsSwVersion;
+extern UINT8 BMSupdatestatus;
+extern UINT8 BuzzerControl;
+extern UINT8 CanMsgEnble;
+extern UINT8 ChargeForbiddenControl;
+extern UINT8 chargerConnectState;
+extern UINT8 DisChargeForbiddenControl;
+extern UINT8 fastChargeTemp;
+extern UINT8 GpsFlag;
+extern UINT8 HeatForceControl;
+extern UINT8 heatTemp1;
+extern UINT8 heatTemp2;
+extern UINT8 Lockstatus;
+extern UINT8 maxCellTemp;
+extern UINT8 minCellTemp;
+extern UINT8 MOSTemp;
+extern UINT8 nbReservedTemp1;
+extern UINT8 nbReservedTemp2;
+extern UINT8 normalChargeTemp;
+extern UINT8 packTemp;
+extern UINT8 PadInterrupt;
+extern UINT8 PosFlag;
+extern UINT8 RelayForbiddenControl;
+extern UINT8 reservedSignal1;
+extern UINT8 reservedSignal2;
+extern UINT8 reservedSignal3;
+extern UINT8 reservedSignal4;
+extern UINT8 reservedSignal5;
+extern UINT8 reservedSignal6;
+extern UINT8 reservedSignal7;
+extern UINT8 reservedSignal8;
+extern UINT8 TcpErrorcount;
+extern UINT8 TcpSendLen;
+extern UINT8 TCPWorkState;
+extern UINT8 UartCmdRecvFlag;
+extern UINT8 UartErrorFlag;
+extern UINT8 UartInterruptcount;
+extern UINT8 UartRecvFlag;
+extern UINT8 UDSService[2];              //uds 服务
+extern UINT8 UDSSubService[2];           // uds 子服务
+extern UINT8 UDSSubServiceActionCode[2]; // uds 子服务状态
+extern UINT8 UDSSwitch;
+extern UINT8 UDSSwitch;
 //declear the UINT16 vars
-extern UINT16	battCellU[28];
-extern UINT16	battI;
-extern UINT16	battPackVol;
-extern UINT16	maxCellVol;
-extern UINT16	minCellVol;
-extern UINT16	nbHwVersion;
-extern UINT16   avrgCellVol;
-extern UINT16   ErrorNum[ErrorNumLength];
-extern UINT16   updateDifferDataPackageCounter;
-
+extern UINT16 battCellU[28];
+extern UINT16 battI;
+extern UINT16 battPackVol;
+extern UINT16 maxCellVol;
+extern UINT16 minCellVol;
+extern UINT16 nbHwVersion;
+extern UINT16 avrgCellVol;
+extern UINT16 ErrorNum[ErrorNumLength];
+extern UINT16 updateDifferDataPackageCounter;
 
 //declear the UINT32 vars
-extern UINT32	battBalanceoInfo;
-extern UINT32	battProtectState;
-extern UINT32	battWarningState;
-extern UINT32	nbSwVersion ;
-extern UINT32   Battdesigncap;
-extern UINT32   PowerVoltage;
-extern volatile UINT32  TimeCounter;
-
+extern UINT32 battBalanceoInfo;
+extern UINT32 battProtectState;
+extern UINT32 battWarningState;
+extern UINT32 nbSwVersion;
+extern UINT32 Battdesigncap;
+extern UINT32 PowerVoltage;
+extern volatile UINT32 TimeCounter;
 
 //declear other vars
-extern AppAlgorithmData   BcuDataInfo;
+extern AppAlgorithmData BcuDataInfo;
 extern AppConfigDataType AppNVMData;
 extern AppDataBody AppDataInfo;
-extern AppSocketConnectionContext socContext;  //网络连接状态
+extern AppSocketConnectionContext socContext; //网络连接状态
 extern osMutexId_t Error_Mutex;
-extern process_app 		    gProcess_app;
+extern process_app gProcess_app;
 extern QueueHandle_t GpsRecvHandle;
 extern QueueHandle_t UartWriteCmdHandle;

+ 2 - 0
inc/EmbeddedCoder_inc/BCUCal.h

@@ -90,6 +90,8 @@ 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 uint16_T tmsc_T_openThr;                         /* 热管理开启温度; */
 extern const uint16_T tmsc_T_closeMinThr;                     /* 热管理关闭温度(最低模组); */

+ 3 - 5
inc/EmbeddedCoder_inc/SOC.h

@@ -9,9 +9,7 @@ extern void SOC(void);
 extern boolean_T FirstRun_SOC;
 
 
-extern void docvmath(real_T soc ,real_T *docv);
-extern void SOC_LookUp(uint16_T battsoc, uint16_T x[3], uint16_T y[3],uint16_T *bcusoc);
-extern void SOC_MATLABFunction(real_T soc, real_T *docv);
-extern void SOCfit_IfActionSubsystem1(uint16_T SOC, uint16_T SOCfit, uint16_T *SOCout, uint16_T m);
-extern void SOCfit_IfActionSubsystem2(uint16_T SOC, uint16_T SOCfit, uint16_T *SOCout, uint16_T m);
+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);
 

+ 22 - 18
src/AppFunc.c

@@ -3,7 +3,7 @@
  * @Date         : 2021-10-14 09:27:15
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-10-14 15:36:12
+ * @LastEditTime : 2021-10-15 15:54:33
  * @Description  : 应用层函数定义区,UTF-8
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AppFunc.c
  */
@@ -428,15 +428,17 @@ BOOL BattHeaterSwitch(UINT8 *heaterSwitch, UINT8 HeatForceControl)
 	return isNeedtoSwitch;
 }
 /**
- * @brief : 蜂鸣器控制函数,采用占空比形式
- * @param {float} DutyRatio
- * @return {*}
- */
-void relayControlFunc(float DutyRatio)
+  * @brief : 蜂鸣器控制函数
+  * @param {UINT8} BuzzerPeriod
+  * @param {float} DutyRatio
+  * @return {*}
+  */
+void relayControlFunc(UINT8 BuzzerPeriod, float DutyRatio)
 {
+
 	static UINT8 BuzzerTimer = 0;
-	UINT8 BuzzerPeriod = 10; //1000ms
 	BuzzerTimer++;
+
 	if (BuzzerTimer < (UINT8)(BuzzerPeriod * DutyRatio))
 	{
 		relayControl(TRUE);
@@ -458,6 +460,8 @@ void relayControlFunc(float DutyRatio)
  */
 void LEDDisplay(void)
 {
+	UINT8 LedBattSoc = 0;
+	LedBattSoc = socd_pct_bcuSoc / 10;
 	static UINT8 currentState = 0;
 	static UINT8 LightTimer = 0;
 	static UINT8 ErrorLightTimer = 0;
@@ -505,7 +509,7 @@ void LEDDisplay(void)
 			currentState = AppDataInfo.BattLock;
 			LightTimer = 0;
 		}
-		else if (UartRecvFlag == 0) //电池未收到UART信息
+		else if (UartErrorFlag == 1) //电池未收到UART信息,出现Uart故障
 		{
 			if (LightTimer < (UINT8)(LEDFlashPeriod * DutyRatio))
 			{
@@ -568,7 +572,7 @@ void LEDDisplay(void)
 
 			if (battWorkState == 0 || battWorkState == 1) //静置或放电状态
 			{
-				if (battSOC <= 10)
+				if (LedBattSoc <= 10)
 				{
 					if (LightTimer < (UINT8)(LEDFlashPeriod * DutyRatio))
 					{
@@ -593,7 +597,7 @@ void LEDDisplay(void)
 						LightTimer = 0;
 					}
 				}
-				else if (battSOC > 10 && battSOC <= 25)
+				else if (LedBattSoc > 10 && LedBattSoc <= 25)
 				{
 					NetSocDisplay(LED_SOC_0, LED_TURN_ON);
 					NetSocDisplay(LED_SOC_1, LED_TURN_OFF);
@@ -601,7 +605,7 @@ void LEDDisplay(void)
 					NetSocDisplay(LED_SOC_3, LED_TURN_OFF);
 					LightTimer = 0;
 				}
-				else if (battSOC > 25 && battSOC <= 50)
+				else if (LedBattSoc > 25 && LedBattSoc <= 50)
 				{
 					NetSocDisplay(LED_SOC_0, LED_TURN_ON);
 					NetSocDisplay(LED_SOC_1, LED_TURN_ON);
@@ -609,7 +613,7 @@ void LEDDisplay(void)
 					NetSocDisplay(LED_SOC_3, LED_TURN_OFF);
 					LightTimer = 0;
 				}
-				else if (battSOC > 50 && battSOC <= 75)
+				else if (LedBattSoc > 50 && LedBattSoc <= 75)
 				{
 					NetSocDisplay(LED_SOC_0, LED_TURN_ON);
 					NetSocDisplay(LED_SOC_1, LED_TURN_ON);
@@ -617,7 +621,7 @@ void LEDDisplay(void)
 					NetSocDisplay(LED_SOC_3, LED_TURN_OFF);
 					LightTimer = 0;
 				}
-				else if (battSOC > 75 && battSOC <= 100)
+				else if (LedBattSoc > 75 && LedBattSoc <= 100)
 				{
 					NetSocDisplay(LED_SOC_0, LED_TURN_ON);
 					NetSocDisplay(LED_SOC_1, LED_TURN_ON);
@@ -628,7 +632,7 @@ void LEDDisplay(void)
 			}
 			else if (battWorkState == 2)
 			{
-				if (battSOC <= 25)
+				if (LedBattSoc <= 25)
 				{
 					if (LightTimer < (UINT8)(LEDFlashPeriod * DutyRatio))
 					{
@@ -653,7 +657,7 @@ void LEDDisplay(void)
 						LightTimer = 0;
 					}
 				}
-				else if (battSOC > 25 && battSOC <= 50)
+				else if (LedBattSoc > 25 && LedBattSoc <= 50)
 				{
 					if (LightTimer < (UINT8)(LEDFlashPeriod * DutyRatio))
 					{
@@ -678,7 +682,7 @@ void LEDDisplay(void)
 						LightTimer = 0;
 					}
 				}
-				else if (battSOC > 50 && battSOC <= 75)
+				else if (LedBattSoc > 50 && LedBattSoc <= 75)
 				{
 					if (LightTimer < (UINT8)(LEDFlashPeriod * DutyRatio))
 					{
@@ -703,7 +707,7 @@ void LEDDisplay(void)
 						LightTimer = 0;
 					}
 				}
-				else if (battSOC > 75 && battSOC <= 97)
+				else if (LedBattSoc > 75 && LedBattSoc <= 97)
 				{
 					if (LightTimer < (UINT8)(LEDFlashPeriod * DutyRatio))
 					{
@@ -728,7 +732,7 @@ void LEDDisplay(void)
 						LightTimer = 0;
 					}
 				}
-				else if (battSOC > 97 && battSOC <= 100)
+				else if (LedBattSoc > 97 && LedBattSoc <= 100)
 				{
 					NetSocDisplay(LED_SOC_0, LED_TURN_ON);
 					NetSocDisplay(LED_SOC_1, LED_TURN_ON);

+ 2 - 2
src/AppSignal.c

@@ -3,7 +3,7 @@
  * @Date         : 2021-10-14 09:27:15
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-10-14 15:52:41
+ * @LastEditTime : 2021-10-15 10:26:16
  * @Description  : Global variable definition c file,此文件存放App使用到的全局变量
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AppSignal.c
  */
@@ -68,7 +68,7 @@ UINT8 UDSService[2] = {0};              //uds 服务
 UINT8 UDSSubService[2] = {0};           // uds 子服务
 UINT8 UDSSubServiceActionCode[2] = {0}; // uds 子服务状态
 UINT8 UDSSwitch = 0;                    //下线检测标志位
-
+UINT8 UartInterruptcount = 0;           //串口中断累加值
 /**declear the uint16 vars**/
 UINT16 avrgCellVol = 0;                    //平均单体电压
 UINT16 battCellU[28] = {0};                //电池包单体电压

+ 10 - 9
src/AppTaskControl.c

@@ -28,7 +28,7 @@ static void ControlTask(void *arg)
     PROC_CONTROL_STATE_SWITCH(PROCESS_CONTROL_STATE_IDLE);
     UINT32 CurrentTime = 0;
     UINT8 AdcOrder = 1;
-    UINT8 RingTimes = 0;
+    UINT16 RingTimes = 0;
     while (true)
     {
         switch (gProcess_Control_Task)
@@ -45,12 +45,12 @@ static void ControlTask(void *arg)
             if (CurrentTime != TimeCounter)
             {
                 LEDDisplay();
-                CurrentTime = TimeCounter;
+                UINT8 Buzzerperiod = 5; //500ms
                 if (AppDataInfo.BattLock == FALSE && getbit(UartCmdRecvFlag, 0) == 1)
                 {
-                    relayControlFunc(0.4);
-                    RingTimes++;
-                    if (RingTimes >= 3)
+                    relayControlFunc(Buzzerperiod, 0.6);
+                    RingTimes = RingTimes + 100;
+                    if (RingTimes >= 3 * Buzzerperiod * 100)
                     {
                         RingTimes = 0;
                         clrbit(UartCmdRecvFlag, 0);
@@ -58,9 +58,9 @@ static void ControlTask(void *arg)
                 }
                 else if (AppDataInfo.BattLock == TRUE && getbit(UartCmdRecvFlag, 0) == 1)
                 {
-                    relayControlFunc(0.4);
-                    RingTimes++;
-                    if (RingTimes >= 2)
+                    relayControlFunc(Buzzerperiod, 0.4);
+                    RingTimes = RingTimes + 100;
+                    if (RingTimes >= 2 * Buzzerperiod * 100)
                     {
                         RingTimes = 0;
                         clrbit(UartCmdRecvFlag, 0);
@@ -68,8 +68,9 @@ static void ControlTask(void *arg)
                 }
                 else if (BuzzerControl == TRUE || getbit(sfmd_st_fltAct, 2) == 1)
                 {
-                    relayControlFunc(0.4);
+                    relayControlFunc(Buzzerperiod, 0.4);
                 }
+                CurrentTime = TimeCounter;
             }
             if (TimeCounter % 10 == 0)
             {

+ 37 - 36
src/AppTaskMain.c

@@ -3,7 +3,7 @@
  * @Date         : 2021-10-14 09:27:15
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-10-14 15:38:00
+ * @LastEditTime : 2021-10-15 16:33:43
  * @Description  : 主要负责:1.工作模式转换2.定时器定时3.定时保存运行数据4.异常状态重启
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AppTaskMain.c
  */
@@ -64,7 +64,6 @@ static void MainTask(void *arg)
         AppDataInfo.SysReStartCount = AppDataInfo.SysReStartCount + 1;
     }
     xTimerStart(monitor_timer, 0);
-    UINT8 Temp = 0;
     while (true)
     {
         switch (gProcess_Main_Task)
@@ -72,6 +71,7 @@ static void MainTask(void *arg)
         case PROCESS_STATE_IDLE:
         {
             LoadAppData();
+            LoadBcuData();
             PROC_APP_STATE_SWITCH(IDLE);
             xTimerStart(work_timer, 0);
             PROC_MAIN_STATE_SWITCH(PROCESS_STATE_WORK);
@@ -92,19 +92,17 @@ static void MainTask(void *arg)
                 {
                     BattLockFunc();
                 }
-                if (AppDataInfo.appDataModify)
-                {
-                    SaveAppData();
-                }
             }
             if (WorkTimerEnd == TRUE) //从工作转换为监听的条件,定时器结束
             {
-                PROC_MAIN_STATE_SWITCH(PROCESS_STATE_LISTEN);
                 xTimerStop(work_timer, 0);
                 xTimerStart(sleep_timer, 0);
                 WorkTimerEnd = FALSE;
                 NVIC_EnableIRQ(PadWakeup1_IRQn);
                 PadInterrupt = 0x00;
+                UartInterruptcount = 0;
+                PadInterrupt_clrCounter = 0;
+                PROC_MAIN_STATE_SWITCH(PROCESS_STATE_LISTEN);
                 break;
             }
             if ((BMS_Fota_update_flag != FALSE) || (TCPWorkState != 0x00) || (BattWorkStateDelay != BATT_IDLE_SYM) || (PadInterrupt != 0x00))
@@ -135,21 +133,43 @@ static void MainTask(void *arg)
             {
                 SaveBcuData();
             }
+            if (AppDataInfo.appDataModify)
+            {
+                SaveAppData();
+            }
             break;
         }
         case PROCESS_STATE_LISTEN:
         {
             PROC_APP_STATE_SWITCH(LISTEN);
-            if (getbit(PadInterrupt, 1) == 0x01)
+            if (NB_Fota_update_flag)
             {
-                clrbit(PadInterrupt, 1);
-                osDelay(10);
-                PadInterrupt_clrCounter = PadInterrupt_clrCounter + 1;
-                Temp = PadInterrupt;
+                if (AppDataInfo.appDataModify)
+                {
+                    SaveAppData();
+                }
+                if (BcuDataInfo.appDataModify)
+                {
+                    SaveBcuData();
+                }
+                appSetCFUN(0);
+                osDelay(1000);
+                EC_SystemReset();
             }
-            else if (getbit(PadInterrupt, 1) == 0x00 && PadInterrupt != 0x00)
+            if (UartInterruptcount > 1)
             {
-                PadInterrupt_clrCounter = PadInterrupt_clrCounter + 3;
+                if (UartInterruptcount > 10)
+                {
+                    UartInterruptcount = 0;
+                }
+                else
+                {
+                    PadInterrupt_clrCounter = PadInterrupt_clrCounter + 1;
+                }
+            }
+            else if ((getbit(PadInterrupt, 1) == 0x00 && PadInterrupt != 0x00))
+            {
+                PadInterrupt_clrCounter = PadInterrupt_clrCounter + 1;
             }
             else
             {
@@ -163,40 +183,21 @@ static void MainTask(void *arg)
             {
                 SaveBcuData();
             }
-#ifdef USING_PRINTF1
-            printf("[%d]%x - %x - %x - %x\n", __LINE__, SleepTimerEnd, BMS_Fota_update_flag, TCPWorkState, PadInterrupt);
-#endif
-            if ((SleepTimerEnd) || (TCPWorkState == 1) || (PadInterrupt_clrCounter >= 3)) //从监听转换为工作的条件
+            if ((SleepTimerEnd) || (TCPWorkState == 1) || (PadInterrupt_clrCounter >= 1)) //从监听转换为工作的条件
             {
 #ifdef USING_PRINTF1
-                printf("[%d]-%x", __LINE__, battWorkState);
-                printf("[%d]%x - %x - %x - %x - %x-%d\n", __LINE__, WorkTimerEnd, BMS_Fota_update_flag, TCPWorkState, BattWorkStateDelay, Temp, PadInterrupt_clrCounter);
+                printf("WORK:%d,%d,%d\n", PadInterrupt_clrCounter, PadInterrupt, UartInterruptcount);
 #endif
 #ifdef DEBUGLOG
-                Debug_printf("WORK:%d,%d\n", PadInterrupt_clrCounter, PadInterrupt);
+                Debug_printf("WORK:%d,%d,%d\n", PadInterrupt_clrCounter, PadInterrupt, UartInterruptcount);
 #endif
                 PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
                 xTimerStop(sleep_timer, 0);
                 SleepTimerEnd = FALSE;
                 PadInterrupt = 0x00;
-                PadInterrupt_clrCounter = 0;
                 NVIC_DisableIRQ(PadWakeup1_IRQn);
                 break;
             }
-            if (NB_Fota_update_flag)
-            {
-                if (AppDataInfo.appDataModify)
-                {
-                    SaveAppData();
-                }
-                if (BcuDataInfo.appDataModify)
-                {
-                    SaveBcuData();
-                }
-                appSetCFUN(0);
-                osDelay(1000);
-                EC_SystemReset();
-            }
             break;
         }
         default:

+ 14 - 14
src/AppTaskTcp.c

@@ -331,17 +331,17 @@ static void TcpDataInfoAssembleSend()
             ErrorTemp = 0x0000;
         }
         osMutexRelease(Error_Mutex);
-        *(SendBuffer + 39) = ErrorTemp >> 8;     //故障代码H-40
-        *(SendBuffer + 40) = ErrorTemp & 0xFF;   //故障代码L-41
-        *(SendBuffer + 41) = battI >> 8;         //电流-42
-        *(SendBuffer + 42) = battI & 0xFF;       //电流-43
-        *(SendBuffer + 43) = battPackVol >> 8;   //电压-44
-        *(SendBuffer + 44) = battPackVol & 0xFF; //电压-45
-        *(SendBuffer + 45) = battPackVol >> 8;   //电压-46
-        *(SendBuffer + 46) = battPackVol & 0xFF; //电压-47
-        *(SendBuffer + 47) = battMOSSwitchState; //mos状态-48
-        *(SendBuffer + 48) = battSOC;            //soc-49
-        *(SendBuffer + 49) = battSOH;            //soh-50
+        *(SendBuffer + 39) = ErrorTemp >> 8;                //故障代码H-40
+        *(SendBuffer + 40) = ErrorTemp & 0xFF;              //故障代码L-41
+        *(SendBuffer + 41) = battI >> 8;                    //电流-42
+        *(SendBuffer + 42) = battI & 0xFF;                  //电流-43
+        *(SendBuffer + 43) = battPackVol >> 8;              //电压-44
+        *(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) = battSOH;                       //soh-50
         *(SendBuffer + 50) = (battBalanceoInfo >> 24) & 0xFF;
         *(SendBuffer + 51) = (battBalanceoInfo >> 16) & 0xFF;
         *(SendBuffer + 52) = (battBalanceoInfo >> 8) & 0xFF;
@@ -546,12 +546,12 @@ static void TcpDataInfoAssembleSend()
         UINT8 rbuf[1000];
         sprintf((char *)rbuf, "%x,%d,%d,%d,,\
                                 %d,%d,%d,%d,,\
-                                %d,%d,%d,%d,%d,,\
+                                %d,%d,%d,%d,%d,%d,%d,,\
                                 %d,%d,%d,%d,%d,%d,%d,,\
                                 %d,%d",
                 battProtectState, AppDataInfo.RelayControl, chargerConnectState, PowerVoltage,
                 tmsd_st_heatAct, sfmd_num_fltNum, sfmd_st_fltAct, sfmd_st_fltLevel,
-                socd_pct_ahSoc, socd_pct_ekfSoc, socd_pct_estSoc, socd_pct_battSoc, socd_pct_bcuSoc,
+                socd_pct_ahSoc, socd_pct_ekfSoc, socd_pct_estSoc, socd_pct_battSoc, socd_pct_bcuSoc, battSOC * 10, sohv_Q_packCapArrEo[9],
                 sohd_Q_chrgEo, sohd_flg_chrgEndEo, cand_Nr_cellNr, cand_Q_cellCap, cand_V_chrgStartStat, cand_Q_reqCp, cand_Q_totalCp,
                 AppDataInfo.ExpiryTimeArray[1], AppDataInfo.ExpiryTimeArray[2]);
         BufferLen = strlen(rbuf);
@@ -669,7 +669,7 @@ static void TcpDataInfoAssembleSend()
         }
         SendBuffer = NULL;
     }
-    if (send_counter > 0xffff)
+    if (send_counter > 4000000000U)
     {
         send_counter = 0;
     }

+ 96 - 88
src/EmbeddedCoder_src/BCUCal.c

@@ -1,102 +1,110 @@
 
 #include "rtwtypes.h"
 
-const uint16_T blcc_R_esr = 1000U;  /* 均衡电阻 */
-const uint16_T blcc_T_close = 125U; /* 均衡暂停温度; */
-const uint16_T blcc_T_open = 100U;  /* 均衡暂停恢复温度; */
-const uint16_T blcc_V_low = 10U;    /* 均衡开启电压阈值 */
+const uint16_T blcc_R_esr = 1000U;                          /* 均衡电阻 */
+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, 4454U, 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, 7352U, 1453U, 1181U, 1125U,
-                                   1205U, 1283U, 1228U, 1187U, 1104U, 1170U, 1049U}; /* 电池放电参数的Rp数组; */
-const uint16_T cmnm_V_ocv[13] = {3311U, 3411U, 3476U, 3553U, 3610U, 3638U,
-                                 3674U, 3758U, 3845U, 3942U, 4051U, 4106U, 4175U}; /* 电池放电参数的OCV数组; */
-const uint16_T cmnm_pct_soc[13] = {0U, 50U, 100U, 200U, 300U, 400U, 500U, 600U,
-                                   700U, 800U, 900U, 950U, 1000U}; /* 电池放电参数的SOC数组; */
-const uint16_T cmnc_V_chrgFulV = 4200U;                            /* 充满电的截至电压; */
+const uint16_T 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_chrgFulV = 4200U;                     /* 充满电的截至电压; */
 
-const uint16_T sfmc_I_chrgCurrOverThr = 600;      /* 充电电流阈值 */
-const uint16_T sfmc_I_disChrgCurrOverThr = 600;   /* 放电电流阈值 */
-const uint16_T sfmc_T_ACPlugTOverThrFlt1 = 120;   /* 慢充插头温度过高1级故障诊断阈值 */
-const uint16_T sfmc_T_ACPlugTOverThrFlt2 = 125;   /* 慢充插头温度过高2级故障诊断阈值 */
-const uint16_T sfmc_T_ACPlugTOverThrRec1 = 110;   /* 慢充插头温度过高1级故障恢复阈值 */
-const uint16_T sfmc_T_ACPlugTOverThrRec2 = 110;   /* 慢充插头温度过高2级故障恢复阈值 */
-const uint16_T sfmc_T_DCPlugTOverThrFlt1 = 120;   /* 快充插头温度过高1级故障诊断阈值 */
-const uint16_T sfmc_T_DCPlugTOverThrFlt2 = 125;   /* 快充插头温度过高2级故障诊断阈值 */
-const uint16_T sfmc_T_DCPlugTOverThrRec1 = 110;   /* 快充插头温度过高1级故障恢复阈值 */
-const uint16_T sfmc_T_DCPlugTOverThrRec2 = 110;   /* 快充插头温度过高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 = 120;              /* 慢充插头温度过高1级故障诊断阈值 */
+const uint16_T sfmc_T_ACPlugTOverThrFlt2 = 125;              /* 慢充插头温度过高2级故障诊断阈值 */
+const uint16_T sfmc_T_ACPlugTOverThrRec1 = 110;              /* 慢充插头温度过高1级故障恢复阈值 */
+const uint16_T sfmc_T_ACPlugTOverThrRec2 = 110;              /* 慢充插头温度过高2级故障恢复阈值 */
+const uint16_T sfmc_T_DCPlugTOverThrFlt1 = 120;              /* 快充插头温度过高1级故障诊断阈值 */
+const uint16_T sfmc_T_DCPlugTOverThrFlt2 = 125;              /* 快充插头温度过高2级故障诊断阈值 */
+const uint16_T sfmc_T_DCPlugTOverThrRec1 = 110;              /* 快充插头温度过高1级故障恢复阈值 */
+const uint16_T sfmc_T_DCPlugTOverThrRec2 = 110;              /* 快充插头温度过高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_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 = 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_disChrgMosTOverThrFlt1 = 120U;
 const uint16_T sfmc_T_disChrgMosTOverThrRec1 = 110U;
 const uint16_T sfmc_T_disChrgMosTOverThrFlt2 = 125U;
 const uint16_T sfmc_T_disChrgMosTOverThrRec2 = 110U;
 
-const uint16_T sfmc_T_heatPanTOverThrFlt1 = 125; /* 加热板温度过高1级故障诊断阈值 */
-const uint16_T sfmc_T_heatPanTOverThrFlt2 = 130; /* 加热板温度过高2级故障诊断阈值 */
-const uint16_T sfmc_T_heatPanTOverThrRec1 = 120; /* 加热板温度过高1级故障恢复阈值 */
-const uint16_T sfmc_T_heatPanTOverThrRec2 = 120; /* 加热板温度过高2级故障恢复阈值 */
-const uint16_T sfmc_T_modTDiffThrFlt1 = 20;      /* 模组温差过大1级故障诊断阈值 */
-const uint16_T sfmc_T_modTDiffThrFlt2 = 25;      /* 模组温差过大2级故障诊断阈值 */
-const uint16_T sfmc_T_modTDiffThrRec1 = 15;      /* 模组温差过大1级故障恢复阈值 */
-const uint16_T sfmc_T_modTDiffThrRec2 = 15;      /* 模组温差过大2级故障恢复阈值 */
+const uint16_T sfmc_T_heatPanTOverThrFlt1 = 125;             /* 加热板温度过高1级故障诊断阈值 */
+const uint16_T sfmc_T_heatPanTOverThrFlt2 = 130;             /* 加热板温度过高2级故障诊断阈值 */
+const uint16_T sfmc_T_heatPanTOverThrRec1 = 120;             /* 加热板温度过高1级故障恢复阈值 */
+const uint16_T sfmc_T_heatPanTOverThrRec2 = 120;             /* 加热板温度过高2级故障恢复阈值 */
+const uint16_T sfmc_T_modTDiffThrFlt1 = 20;                  /* 模组温差过大1级故障诊断阈值 */
+const uint16_T sfmc_T_modTDiffThrFlt2 = 25;                  /* 模组温差过大2级故障诊断阈值 */
+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_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_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_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_cellUOverThrRec1 = 4200U;  /* 单体电压过压1级故障恢复阈值 */
-const uint16_T sfmc_V_cellUOverThrRec2 = 4200U;  /* 单体电压过压2级故障恢复阈值 */
-const uint16_T sfmc_flg_cellUDiffThrFlt1 = 250U; /* 压差过大1级故障诊断阈值 */
-const uint16_T sfmc_flg_cellUDiffThrFlt2 = 300U; /* 压差过大2级故障诊断阈值 */
-const uint16_T sfmc_flg_cellUDiffThrRec1 = 250U; /* 压差过大1级故障恢复阈值 */
-const uint16_T sfmc_flg_cellUDiffThrRec2 = 250U; /* 压差过大2级故障恢复阈值 */
+const uint16_T sfmc_V_battULowThrFlt1 = 590U;               /* 总压欠压1级故障诊断阈值 */
+const uint16_T sfmc_V_battULowThrFlt2 = 580U;               /* 总压欠压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_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_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_cellUOverThrRec1 = 4200U;             /* 单体电压过压1级故障恢复阈值 */
+const uint16_T sfmc_V_cellUOverThrRec2 = 4200U;             /* 单体电压过压2级故障恢复阈值 */
+const uint16_T sfmc_flg_cellUDiffThrFlt1 = 250U;            /* 压差过大1级故障诊断阈值 */
+const uint16_T sfmc_flg_cellUDiffThrFlt2 = 300U;            /* 压差过大2级故障诊断阈值 */
+const uint16_T sfmc_flg_cellUDiffThrRec1 = 250U;            /* 压差过大1级故障恢复阈值 */
+const uint16_T sfmc_flg_cellUDiffThrRec2 = 250U;            /* 压差过大2级故障恢复阈值 */
+
+const uint16_T sohc_Q_countThr = 60U;                       /*                    */
+const uint16_T sohc_Q_updateDeltThr = 200U;                 /*                    */
+
+const uint16_T socc_pct_battSocLow = 0U;                    /* SOC下限值; */
+const uint16_T socc_pct_battSocUp = 1000U;                  /* SOC上限值; */
+const int16_T socm_I_chrgCor[3] = { 50, 100, 150 } ;   /* 充电CCV对应的电流数据; */
+const int16_T socm_I_disChrgCor[3] = { -300, -100, -60 } ; /* 放电CCV对应的电流数据; */
+const uint16_T socm_V_chrgCor[3] = { 4160U, 4175U, 4188U } ;/* 充电CCV对应的电压; */
+const uint16_T socm_V_disChrgCor[3] = { 3303U, 3359U, 3368U } ; /* 放电CCV对应的电压; */
+const uint16_T socc_pct_chrgCor = 980;
+const uint16_T socc_pct_disChrgCor = 50;
+
+
+
+
+const uint16_T tmsc_T_openThr = 45U;                         /* 热管理开启温度; */
+const uint16_T tmsc_T_closeMinThr = 50U;                     /* 热管理关闭温度(最低模组); */
+const uint16_T tmsc_T_closeMaxThr = 70U;                     /* 热管理开启温度(最高模组); */
 
-const uint16_T sohc_Q_countThr = 60U;                            /*                    */
-const uint16_T sohc_Q_updateDeltThr = 200U;                      /*                    */
-const uint16_T socc_pct_battSocLow = 0U;                         /* SOC下限值; */
-const uint16_T socc_pct_battSocUp = 1000U;                       /* SOC上限值; */
-const int16_T socm_I_chrgCor[4] = {50, 100, 200, 400};           /* 充电CCV对应的电流数据; */
-const int16_T socm_I_disChrgCor[3] = {-400, -200, -100};         /* 放电CCV对应的电流数据; */
-const uint16_T socm_V_chrgCor[4] = {4125U, 4128U, 4132U, 4137U}; /* 充电CCV对应的电压; */
-const uint16_T socm_V_disChrgCor[3] = {3100U, 3270U, 3380U};     /* 放电CCV对应的电压; */
 
-const uint16_T tmsc_T_openThr = 45U;     /* 热管理开启温度; */
-const uint16_T tmsc_T_closeMinThr = 50U; /* 热管理关闭温度(最低模组); */
-const uint16_T tmsc_T_closeMaxThr = 70U; /* 热管理开启温度(最高模组); */

文件差异内容过多而无法显示
+ 760 - 417
src/EmbeddedCoder_src/SFM.c


+ 158 - 206
src/EmbeddedCoder_src/SOC.c

@@ -43,7 +43,6 @@ void SOC(void)
     real_T Up1;
     static real_T Up_Min_Delay;
     static real_T Up_Max_Delay;
-    real_T docv;
     real_T Q;
     real_T battcurr;
     real_T UL;
@@ -59,48 +58,43 @@ void SOC(void)
     //
     static boolean_T overFlg;
     static boolean_T fulFlg;
-    static uint16_T overCntl;
-    static uint16_T fulCntl; 
+    static uint8_T overCntl;
+    static uint8_T fulCntl; 
     static boolean_T onceFlg_utrckOver;
     static int16_T ahSoc0_utrckOver;
     static uint16_T estSoc0_utrckOver;
     static uint16_T Soc_Delay;
     static boolean_T lowFlg;
-    static uint16_T lowCntl;
+    static uint8_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 uint16_T chrgCntl;
-	static uint16_T disChrgCntl;
+	static uint8_T chrgCntl;
+	static uint8_T disChrgCntl;
     //
     static uint16_T socd_pct_battSoc_Delay;
     //
-    static uint16_T  statCntl;
-    static boolean_T statFlg;
+    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 socd_pct_bcuSoc_Delay;
     uint16_T delSOC;
     uint16_T bcuSoc;
     int16_T coinSoc;
     uint16_T x[3];
     uint16_T y[3];
 	boolean_T Flg;
-    static uint16_T SocFitChrg_Delay;
-    static uint16_T SocFitdisChrg_Delay;
     static boolean_T onceFlg_chrg;
     static boolean_T onceFlg_dischrg;
-    uint16_T SocFitChrg;
-    uint16_T SocFitdisChrg;
 	//
 
     if(FirstRun_SOC)
     { 
-      onceFlg_est  = true;
+      onceFlg_est  = true;	  
       ekfInvalidCntl = 0;
       overCntl = 0;
       fulCntl = 0;
@@ -108,13 +102,13 @@ void SOC(void)
       overFlg = false;
       fulFlg = false;
       lowFlg = false;
+	  Soc_Delay = 0 ;  
       onceFlg_utrckOver = true;
       onceFlg_utrckLow = true;
       ihd_st_chrgSta_Delay = 0;
       socn_pct_utrackSoc_Delay = 0;
       onceFlg_chrg    = true;
       onceFlg_dischrg = true;
-	  socd_pct_battSoc_Delay = 0;
     }
 	
     //=====================================================================
@@ -122,7 +116,7 @@ void SOC(void)
     //=====================================================================
     if(FirstRun_SOC)
     {   //
-        if ((socd_pct_battSocEi > 1000) || (socd_pct_bcuSocEi > 1000) || (socd_pct_bcuSocEi == 0 && socd_pct_battSocEi == 0))
+        if ((socd_pct_battSocEi > 1000) || (socd_pct_bcuSocEi > 1000) )
         {
             socn_pct_battSocEE =  look1_iu16lu16n16tu16_binlcase(sfmd_V_cellUAvrg,(&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
             socn_pct_bcuSocEE  =  look1_iu16lu16n16tu16_binlcase(sfmd_V_cellUAvrg,(&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
@@ -133,7 +127,7 @@ void SOC(void)
             socn_pct_bcuSocEE  = socd_pct_bcuSocEi;
         }
         //
-        if (ihd_tm_parkTime > cmnc_tm_parkTime)
+        if (ihd_tm_parkTime > cmnc_tm_parkTime && 0)
         {
             socn_pct_battSocEE =  look1_iu16lu16n16tu16_binlcase(sfmd_V_cellUAvrg,(&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
         }
@@ -144,21 +138,21 @@ void SOC(void)
     ////////////////////////EKFSOC//////////////////////////////////////////
     //======================================================================
     battcurr = (real_T)sfmd_I_curr * 0.1;
-    Q =        (real_T) socn_Q_cap * 0.1;
+    Q =        (real_T)socn_Q_cap  * 0.1;
 	
     //-------------------------EKFmin---------------------------------------
     if (FirstRun_SOC)
     {
         soc_Min_Delay = (real_T)socn_pct_battSocEE * 0.1;
         Up_Min_Delay  = 0;
-        P_Min_Delay[0]=1000;
-		P_Min_Delay[1]=0;
-		P_Min_Delay[2]=0;
-		P_Min_Delay[3]=1000;
+        P_Min_Delay[0] = 1000;
+		P_Min_Delay[1] = 0;
+		P_Min_Delay[2] = 0;
+		P_Min_Delay[3] = 1000;
     }
     //参数查表
-    ocv = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])), 12U) * 0.001;
-    Ro  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])),  12U) * 0.001 * 0.001;
+    ocv = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])),   12U) * 0.001;
+    Ro  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])),    12U) * 0.001 * 0.001;
     Rp  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_R_polar[0])), 12U) * 0.001 * 0.001;
     C   = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Min_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_F_polar[0])), 12U) * 0.001 * 1000;
     A[0] = 1;
@@ -169,8 +163,7 @@ void SOC(void)
     B[0] = 0.1/Q/3600 * 100;
     B[1] = Rp * (1- exp(-0.1/(Rp * C)));
 	
-    docvmath(soc_Min_Delay ,&docv);
-    H[0] = docv;
+    H[0] = docvmath(soc_Min_Delay);
     H[1] = 1;
 	
     //先验
@@ -189,17 +182,17 @@ 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)
+    if (soc_Min_Delay > (real_T)socc_pct_battSocUp  * 0.1)
     {
-        soc_Min_Delay=  (real_T)socc_pct_battSocUp * 0.1;
+        soc_Min_Delay=  (real_T)socc_pct_battSocUp  * 0.1;
     }
 	
     Up_Min_Delay  = Up1 + K[1] * deltU;
-    //Up_Min_Delay  = (Up_Min_Delay > 0 ? Up_Min_Delay : 0);
 	
     //P更新
     P_Min_Delay[0] = (1 - K[0] * H[0]) * P1[0] -K[0]* P1[1];
@@ -212,21 +205,20 @@ void SOC(void)
     socn_flg_ekfInvalidMin= (deltU > 0.005)||(deltU < -0.005);
 	//printf("2----socmin:%f,Up:%f,U1:%d,sfmd_V_cellUMin:%d,deltU:%f,flg:%d,soc1:%f,K[0]:%f,K[1]:%f\n",soc_Min_Delay,Up_Min_Delay,ihv_V_cellU[0],sfmd_V_cellUMin,deltU,socn_flg_ekfInvalidMin,soc1,K[0],K[1]);
     //------------------------EKFSOCmax-----------------------------------
-    
     if (FirstRun_SOC)
     {
-        soc_Max_Delay = (real_T)socn_pct_battSocEE * 0.1;
-        Up_Max_Delay  = 0;
-        P_Max_Delay[0]=1000;
-		P_Max_Delay[1]=0;
-		P_Max_Delay[2]=0;
-		P_Max_Delay[3]=1000;
+        soc_Max_Delay  = (real_T)socn_pct_battSocEE * 0.1;
+        Up_Max_Delay   = 0;
+        P_Max_Delay[0] = 1000;
+		P_Max_Delay[1] = 0;
+		P_Max_Delay[2] = 0;
+		P_Max_Delay[3] = 1000;
     }
     // 参数查表
-    ocv = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])), 12U) * 0.001;
-    Ro  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])),  12U) * 0.001 * 0.001;
-    Rp  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_R_polar[0])), 12U) * 0.001 * 0.001;
-    C   = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_F_polar[0])), 12U) * 0.001 * 1000;
+    ocv = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_V_ocv[0])),  12U) * 0.001;
+    Ro  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_R_ohm[0])),   12U) * 0.001 * 0.001;
+    Rp  = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_R_polar[0])),12U) * 0.001 * 0.001;
+    C   = (real_T)look1_iu16lu16n16tu16_binlcase((uint16_T)(soc_Max_Delay * 10),(&(cmnm_pct_soc[0])), (&(cmnm_F_polar[0])),12U) * 0.001 * 1000;
     A[0] = 1;
     A[1] = 0;
     A[2] = 0;
@@ -235,14 +227,14 @@ void SOC(void)
     B[0] = 0.1/Q/3600 * 100;
     B[1] = Rp * (1- exp(-0.1/(Rp * C)));
 	
-    docvmath(soc_Max_Delay ,&docv);
-    H[0] = docv;
+    H[0] = docvmath(soc_Max_Delay);
     H[1] = 1;
 	
     //先验
     soc1 = soc_Max_Delay * A[0] + B[0] * battcurr;
     Up1  = Up_Max_Delay  * A[3] + B[1] * battcurr;
     UL= ocv + battcurr * Ro + Up1;
+	
     P1[0] = P_Max_Delay[0] + 0.002;
     P1[1] = P_Max_Delay[1] * A[3] +0.002;
     P1[2] = P_Max_Delay[2] * A[3] +0.002;
@@ -255,21 +247,22 @@ 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)
+	
+    if (soc_Max_Delay < (real_T)socc_pct_battSocLow * 0.1)
     {
-        soc_Max_Delay=  (real_T)socc_pct_battSocLow * 0.1;
+        soc_Max_Delay =  (real_T)socc_pct_battSocLow * 0.1;
     }
     if (soc_Max_Delay > (real_T)socc_pct_battSocUp * 0.1)
     {
-        soc_Max_Delay=  (real_T)socc_pct_battSocUp * 0.1;
+        soc_Max_Delay =  (real_T)socc_pct_battSocUp * 0.1;
     }
     Up_Max_Delay  = Up1 + K[1] * deltU;
-    //Up_Max_Delay  = (Up_Max_Delay > 0 ? Up_Max_Delay : 0);
+
 	
     //P更新
-    P_Max_Delay[0] = (1 - K[0] * H[0]) * P1[0] -K[0]* P1[1];
+    P_Max_Delay[0] = (1 - K[0] * H[0]) * P1[0] -K[0] * P1[1];
     P_Max_Delay[1] = -K[1] * H[0] * P1[0] + P1[1] * (1 - K[1]);
-    P_Max_Delay[2] = (1 - K[0] * H[0]) * P1[2] -K[0]* P1[3];
+    P_Max_Delay[2] = (1 - K[0] * H[0]) * P1[2] -K[0] * P1[3];
     P_Max_Delay[3] = -K[1] * H[0] * P1[2] + P1[3] * (1 - K[1]);
     //输出
     EKFSOCMax = (uint16_T) (soc_Max_Delay * 10);
@@ -279,25 +272,17 @@ void SOC(void)
     socn_flg_ekfInvalid = socn_flg_ekfInvalidMax || socn_flg_ekfInvalidMin;
     if(EKFSOCMax > 800)
     {
-        factor=100;
+        factor = 100;
     }
-    else if(EKFSOCMin<200)
+    else if(EKFSOCMin < 200)
     {
-        factor=0;
+        factor = 0;
     }
     else
     {
         factor=(uint16_T)(((uint16_T)((  (uint32_T)  (EKFSOCMin - 200)  << 6) / (800 - (EKFSOCMax-EKFSOCMin) - 200)) * 25U) >> 4);
     }
 	socd_pct_ekfSoc = (uint16_T)( (  (1 - (real_T)(factor * 0.01)) * (real_T) (EKFSOCMin * 0.1) +  (real_T)(factor * 0.01) * (real_T)( EKFSOCMax * 0.1)  ) * 10); 
-    if (socd_pct_ekfSoc < socc_pct_battSocLow)
-    {
-        socd_pct_ekfSoc=  socc_pct_battSocLow ;
-    }
-    if (socd_pct_ekfSoc > socc_pct_battSocUp)
-    {
-        socd_pct_ekfSoc=  socc_pct_battSocUp ;
-    }
 
 	//printf("4----factor:%d,socd_pct_ekfSoc:%d,EKFSOCMax:%d,EKFSOCMin:%d,\n",factor,socd_pct_ekfSoc,EKFSOCMax,EKFSOCMin);
     //======================================================================
@@ -309,14 +294,14 @@ void SOC(void)
     }
     else
     {
-          ahDelay = ahDelay +  battcurr / (real_T)(cmnc_Q_ratedCp *0.1) /360.0;
-     }
-    ahSoc =(int16_T)(ahDelay *10);
-    if (ahSoc >= socc_pct_battSocUp)
+        ahDelay = ahDelay +  battcurr / (real_T)(cmnc_Q_ratedCp * 0.1) /360.0;
+    }
+    ahSoc =(int16_T)(ahDelay * 10);
+    if (ahSoc > socc_pct_battSocUp)
     {
         socd_pct_ahSoc = socc_pct_battSocUp;
     }
-    else if (ahSoc <= socc_pct_battSocLow)
+    else if (ahSoc < socc_pct_battSocLow)
     {
         socd_pct_ahSoc = socc_pct_battSocLow;
     }
@@ -324,13 +309,13 @@ void SOC(void)
     {
         socd_pct_ahSoc = (uint16_T)ahSoc;
     }
-	// printf("5----ahDelay:%f,ahSoc:%d,battcurr:%f,sfmd_I_curr:%d\n",ahDelay,ahSoc,battcurr,sfmd_I_curr);
+	//printf("5----ahDelay:%f,ahSoc:%d,battcurr:%f,sfmd_I_curr:%d\n",ahDelay,ahSoc,battcurr,sfmd_I_curr);
     //======================================================================
     ///////////////////////estSOC//////////////////////////////////////////
     //======================================================================
     if(!socn_flg_ekfInvalid)
     {
-        ekfInvalidCntl = ( (ekfInvalidCntl + 1) > 60000 ? 60000 :(ekfInvalidCntl + 1));
+        ekfInvalidCntl = (ekfInvalidCntl + 1) > 250 ? 250 :(ekfInvalidCntl + 1);
     }
     else
     {
@@ -343,21 +328,22 @@ void SOC(void)
         {
             ahSoc0_est  = ahSoc;
             ekfSoc0_est = socd_pct_ekfSoc;
+			onceFlg_est = false;
         }
-        socd_pct_estSoc = (((int16_T)(ahSoc - ahSoc0_est) + ekfSoc0_est)>0 ? (uint16_T)((int16_T)(ahSoc - ahSoc0_est) + ekfSoc0_est) : 0);
-        onceFlg_est = false;
+        socd_pct_estSoc = (int16_T)(ahSoc - ahSoc0_est + ekfSoc0_est) > 0 ? (uint16_T)(ahSoc - ahSoc0_est + ekfSoc0_est) : 0;
     }
     else
     {   
         onceFlg_est = true;
         socd_pct_estSoc = socd_pct_ekfSoc;
     }
-    
-    if (socd_pct_estSoc >= socc_pct_battSocUp)
+	
+    //
+    if (socd_pct_estSoc > socc_pct_battSocUp)
     {
         socd_pct_estSoc = socc_pct_battSocUp;
     }
-    if (socd_pct_estSoc <= socc_pct_battSocLow)
+    if (socd_pct_estSoc < socc_pct_battSocLow)
     {
         socd_pct_estSoc = socc_pct_battSocLow;
     }
@@ -367,13 +353,13 @@ void SOC(void)
     //======================================================================
     if (ihd_st_workStat == 2)
     {
-        disChrgCntl=0;
-		chrgCntl = ((chrgCntl+1) >60000 ? 60000 : (chrgCntl+1));
-		lowCntl=0;
-        lowFlg = 0;
-        if(sfmd_V_cellUMax >= look1_is16lu16n16tu16_binlcase(sfmd_I_curr, (&(socm_I_chrgCor[0])),(&(socm_V_chrgCor[0])), 3U))
+        disChrgCntl = 0;
+		chrgCntl = (chrgCntl+1) > 250 ? 250 : (chrgCntl+1);
+		lowCntl = 0;
+        lowFlg  = false;
+        if(sfmd_V_cellUMax >= look1_is16lu16n16tu16_binlcase(sfmd_I_curr, (&(socm_I_chrgCor[0])),(&(socm_V_chrgCor[0])), 2U))
         {
-            overCntl = ( (overCntl + 1) > 60000 ? 60000 : (overCntl + 1));
+            overCntl = (overCntl + 1) > 250 ? 250 : (overCntl + 1);
         }
         else
         {
@@ -386,11 +372,11 @@ void SOC(void)
         //
         if(sfmd_V_cellUMax >= cmnc_V_chrgFulV)
         {
-            fulCntl = ( (fulCntl + 1) > 60000 ? 60000 : (fulCntl + 1));
+            fulCntl = (fulCntl + 1) > 250 ? 250 : (fulCntl + 1);
         }
         else
         {
-            fulCntl=0;
+            fulCntl = 0;
         }
         if(fulCntl > 20 || fulFlg)
         {
@@ -402,45 +388,48 @@ void SOC(void)
         {
             if (onceFlg_utrckOver)
             {
+                onceFlg_utrckOver = false;
                 ahSoc0_utrckOver  = ahSoc;
-                estSoc0_utrckOver = socd_pct_estSoc;
+				estSoc0_utrckOver = socd_pct_estSoc > socc_pct_chrgCor ? socd_pct_estSoc : socc_pct_chrgCor;
             }
-            estSoc0_utrckOver = (estSoc0_utrckOver > 950 ? estSoc0_utrckOver : 950);
-            socTemp = (uint16_T)((int16_T)(ahSoc - ahSoc0_utrckOver) + estSoc0_utrckOver);
-            onceFlg_utrckOver = false;
+            socTemp = (uint16_T)(ahSoc - ahSoc0_utrckOver + estSoc0_utrckOver);
         }
-        else  if (chrgCntl >20)
+        else  if (chrgCntl > 20)
         {   
-           
             onceFlg_utrckOver = true;
-            socTemp = (socd_pct_estSoc > 950 ? 950 : socd_pct_estSoc);
+            socTemp = socd_pct_estSoc > socc_pct_chrgCor ? socc_pct_chrgCor : socd_pct_estSoc;
         }
 		else
         {
             socTemp = socd_pct_estSoc;
         }
-		
-        socn_pct_utrackSoc = Soc_Delay + ( (int16_T) (socTemp - Soc_Delay) > 0 ?  (socTemp - Soc_Delay) :0);
+		// 
+        socn_pct_utrackSoc = Soc_Delay + (socTemp > Soc_Delay ?  (socTemp - Soc_Delay) : 0);
         Soc_Delay = socn_pct_utrackSoc;
-        socn_pct_utrackSoc =(socn_pct_utrackSoc > 999 ? 999 : socn_pct_utrackSoc);
+        
         if (fulFlg)
         {
-            socn_pct_utrackSoc= 1000;
+            socn_pct_utrackSoc = socc_pct_battSocUp;
+        }
+        else
+        {
+           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\n",overCntl,overFlg,fulCntl,fulFlg,ahSoc0_utrckOver,estSoc0_utrckOver,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);
     }
     else
-    {   chrgCntl=0;
-		disChrgCntl = ((disChrgCntl+1) >60000 ? 60000 : (disChrgCntl+1));
+    {   
+        chrgCntl = 0;
+		disChrgCntl = (disChrgCntl + 1) > 250 ? 250 : (disChrgCntl + 1);
         Soc_Delay = 0;
         overCntl = 0;
-        overFlg  = 0;
-        fulFlg   = 0;
+        overFlg  = false;
+        fulFlg   = false;
         fulCntl  = 0;
-        if(sfmd_V_cellUMin <=look1_is16lu16n16tu16_binlcase(sfmd_I_curr, (&(socm_I_disChrgCor[0])),(&(socm_V_disChrgCor[0])), 2U))
+        if(sfmd_V_cellUMin <= look1_is16lu16n16tu16_binlcase(sfmd_I_curr, (&(socm_I_disChrgCor[0])),(&(socm_V_disChrgCor[0])), 2U))
         {
-            lowCntl = ( (lowCntl + 1) > 60000 ? 60000 : (lowCntl + 1));
+            lowCntl = (lowCntl + 1) > 250 ? 250 : (lowCntl + 1);
         }
         else
         {
@@ -448,35 +437,34 @@ void SOC(void)
         }
         if(lowCntl > 20 || lowFlg)
         {
-            lowFlg = 1;
+            lowFlg = true;
         }
         //
         if (lowFlg)
         {
-            if (onceFlg_utrckLow)
+            if (onceFlg_utrckLow)	
             {
+                onceFlg_utrckLow = false; 
                 ahSoc0_utrckLow  = ahSoc;
-                estSoc0_utrckLow = socd_pct_estSoc;
+				estSoc0_utrckLow = socd_pct_estSoc < socc_pct_disChrgCor ? socd_pct_estSoc : socc_pct_disChrgCor;
             }
-            estSoc0_utrckLow = (estSoc0_utrckLow < 50 ? estSoc0_utrckLow : 50);
-            socn_pct_utrackSoc = (((int16_T)(ahSoc - ahSoc0_utrckLow) + estSoc0_utrckLow)>0 ? (uint16_T)((int16_T)(ahSoc - ahSoc0_utrckLow) + estSoc0_utrckLow) : 0);
-            onceFlg_utrckLow = false;
+            socn_pct_utrackSoc =  (int16_T)(ahSoc - ahSoc0_utrckLow + estSoc0_utrckLow) > 0 ? (uint16_T)(ahSoc - ahSoc0_utrckLow + estSoc0_utrckLow) : 0;
         }
         else if(disChrgCntl > 20)
         {
             onceFlg_utrckLow = true;
-            socn_pct_utrackSoc = (socd_pct_estSoc < 50 ? 50 :socd_pct_estSoc);
+            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);
+	 //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_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 )
      {
@@ -492,21 +480,22 @@ void SOC(void)
     //////////////////////////////BCUSOC///////////////////////////////////
     //=====================================================================
 
-    
     if(sfmd_I_curr < 100 && sfmd_I_curr > -100)
     {
-        statCntl= (statCntl >60000 ? 60000 :statCntl);
+        statCntl= (statCntl + 1) > 250 ? 250 :  (statCntl + 1);
     }
     else
     {
-        statCntl=0;
+        statCntl = 0;
     }
-    statFlg = statCntl > 20 || statFlg;
+    statFlg = statCntl > 20;
 	
-    Flg= (FirstRun_SOC ||((ihd_st_chrgSta_Delay == 2) && (ihd_st_workStat != 2)) ||((ihd_st_chrgSta_Delay!= 2) && (ihd_st_workStat == 2))
-    || ((int16_T)(socn_pct_utrackSoc -socn_pct_utrackSoc_Delay) > 20 ||(int16_T)(socn_pct_utrackSoc -socn_pct_utrackSoc_Delay) <- 20 )||statFlg);
-    ihd_st_chrgSta_Delay = ihd_st_workStat;
+    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;
+	
     //
     if(Flg)
     {
@@ -517,170 +506,133 @@ void SOC(void)
         }
         else
         {
-            socd_pct_bcuSoc0 = socd_pct_bcuSoc_Delay;
+            socd_pct_bcuSoc0 = socd_pct_bcuSoc;
         }
     }
-	//printf("9------socd_pct_battSoc:%d\n",socd_pct_battSoc);
-	//printf("9----statCntl:%d,statFlg:%d,Flg:%d,socd_pct_bcuSoc0:%d,socd_pct_bcuSoc0:%d\n",statCntl,statFlg,Flg,socd_pct_bcuSoc0,socd_pct_bcuSoc0);
+	
+	//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 =  ((int16_T) (socd_pct_battSoc0 - socd_pct_bcuSoc0) > 0 ? (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 =  socd_pct_battSoc0 > socd_pct_bcuSoc0 ? (socd_pct_battSoc0 - socd_pct_bcuSoc0) : (socd_pct_bcuSoc0 - socd_pct_battSoc0);
+        coinSoc = (socd_pct_battSoc0 > socd_pct_bcuSoc0 ? socd_pct_battSoc0 : socd_pct_bcuSoc0)+ (delSOC > 50 ? 50 : delSOC);
 		
 		x[0] = socd_pct_battSoc0;
-		x[1] = (coinSoc> 1000 ? 1000 : (uint16_T)coinSoc);;
-		x[2] = 1000;
+		x[1] = coinSoc > socc_pct_battSocUp ? socc_pct_battSocUp : (uint16_T)coinSoc;
+		x[2] = socc_pct_battSocUp;
+		
 		y[0] = socd_pct_bcuSoc0;
-		y[1] = (coinSoc> 1000 ? 1000 : (uint16_T)coinSoc);;
+		y[1] = coinSoc > 1000 ? 1000 : (uint16_T)coinSoc;
 		y[2] = 1000;
-		
-        SOC_LookUp( socd_pct_battSoc, &x[0], &y[0], &bcuSoc);
-
+        bcuSoc = SOC_LookUp( socd_pct_battSoc, &x[0], &y[0]);
 
 		//
-        onceFlg_dischrg = true;
         if (onceFlg_chrg)
         {
-            SocFitChrg_Delay = 2000;
-        }
-		//printf("onceFlg_chrg:%d,SocFitChrg_Delay:%d\n",onceFlg_chrg,SocFitChrg_Delay);
-        onceFlg_chrg =false;
-        if ((int16_T)(bcuSoc - SocFitChrg_Delay ) > 1)
-        {
-            SOCfit_IfActionSubsystem1( bcuSoc,  SocFitChrg_Delay,  &SocFitChrg, 1);
-        }
-        if ((int16_T)(bcuSoc - SocFitChrg_Delay ) <-1 && (int16_T)(bcuSoc - SocFitChrg_Delay ) > -1000)
-        {
-            SOCfit_IfActionSubsystem2( bcuSoc,  SocFitChrg_Delay,  &SocFitChrg, 1);
+            onceFlg_chrg =false;
+            onceFlg_dischrg = true;
+            socd_pct_bcuSoc = 2000;	
         }
-		if (((int16_T)(bcuSoc - SocFitChrg_Delay ) <=1 &&(int16_T)(bcuSoc - SocFitChrg_Delay ) >=-1 )||((int16_T)(bcuSoc - SocFitChrg_Delay ) <=-1000))
-		{
-
-		    SocFitChrg = bcuSoc;
-		}
-        SocFitChrg_Delay =  SocFitChrg;
+        socd_pct_bcuSoc = SOCfitSystem(bcuSoc,&socd_pct_bcuSoc, 1);
 		
         //
         if (fulFlg)
         {
-            socd_pct_bcuSoc =1000;
+            socd_pct_bcuSoc =socc_pct_battSocUp;
         }
         else
         {
-            socd_pct_bcuSoc =(SocFitChrg > 999 ? 999 : SocFitChrg);
+            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,SocFitChrg:%d,socd_pct_bcuSoc:%d\n",x[0],x[1],x[2],y[0],y[1],y[2],bcuSoc,SocFitChrg,socd_pct_bcuSoc);
+		//printf("10-----x:[%d-%d-%d],y:[%d-%d-%d],bcusoc:%d,socd_pct_bcuSoc:%d\n",x[0],x[1],x[2],y[0],y[1],y[2],bcuSoc,socd_pct_bcuSoc);
     }
     else
     {
-    
         //
-        delSOC = ((int16_T) (socd_pct_battSoc0 - socd_pct_bcuSoc0) > 0 ? (socd_pct_battSoc0 - socd_pct_bcuSoc0) : (socd_pct_bcuSoc0 - socd_pct_battSoc0));
+        delSOC = socd_pct_battSoc0 > socd_pct_bcuSoc0 ? (socd_pct_battSoc0 - socd_pct_bcuSoc0) : (socd_pct_bcuSoc0 - socd_pct_battSoc0);
         coinSoc =(int16_T)((socd_pct_battSoc0 < socd_pct_bcuSoc0 ? socd_pct_battSoc0 : socd_pct_bcuSoc0) - (delSOC > 50 ? 50 : delSOC));
         
-      	x[0] = 0;
-		x[1] = (coinSoc > 0 ? (uint16_T)coinSoc : 0);
+      	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[1] = coinSoc > 0 ? (uint16_T)coinSoc : 0;
 		y[2] = socd_pct_bcuSoc0;
-        SOC_LookUp( socd_pct_battSoc,  &x[0], &y[0], &bcuSoc);
+        bcuSoc = SOC_LookUp( socd_pct_battSoc,  &x[0], &y[0]);
 		
-
-
 		//
-		onceFlg_chrg = true;
-        if (onceFlg_dischrg)
-        {
-            SocFitdisChrg_Delay = 2000;
-        }
-        onceFlg_dischrg =false;
-
-		
-        if ((int16_T)(bcuSoc - SocFitdisChrg_Delay ) > 1)
-        {
-            SOCfit_IfActionSubsystem1( bcuSoc,  SocFitdisChrg_Delay,  &SocFitdisChrg, 1);
-        }
-        if ((int16_T)(bcuSoc - SocFitdisChrg_Delay ) <-1 && (int16_T)(bcuSoc - SocFitdisChrg_Delay ) > -1000)
+		if (onceFlg_dischrg)
         {
-            SOCfit_IfActionSubsystem2( bcuSoc,  SocFitdisChrg_Delay,  &SocFitdisChrg, 1);
+            onceFlg_chrg = true;
+            onceFlg_dischrg = false;
+            socd_pct_bcuSoc = 2000;
         }
-		if (((int16_T)(bcuSoc - SocFitdisChrg_Delay ) <=1 &&(int16_T)(bcuSoc - SocFitdisChrg_Delay ) >=-1 )||((int16_T)(bcuSoc - SocFitdisChrg_Delay ) <=-1000))
-		{
-
-		    SocFitdisChrg = bcuSoc;
-		}
-        SocFitdisChrg_Delay = SocFitdisChrg;
-
-
-		socd_pct_bcuSoc = SocFitdisChrg;
+        
+		socd_pct_bcuSoc = SOCfitSystem(bcuSoc,&socd_pct_bcuSoc, 1);
 		//printf("11-----x:[%d-%d-%d],y:[%d-%d-%d],bcusoc:%d,socd_pct_bcuSoc:%d\n",x[0],x[1],x[2],y[0],y[1],y[2],bcuSoc,socd_pct_bcuSoc);
 	    
     }
     //
     socd_pct_bcuSocEo = socd_pct_bcuSoc;
-    socd_pct_bcuSoc_Delay = socd_pct_bcuSoc; 
     FirstRun_SOC= false;
-    
+    //printf("\n");
 }
 
 
 //-------------------------------------------------------------------------
-void docvmath(real_T soc ,real_T *docv)
-{
-    *docv = ((((((-2.8104E-13 * pow(soc, 7.0) + 1.0283E-10 * pow(soc, 6.0)) +
+real_T docvmath(real_T soc)
+{   
+    real_T docv;
+    docv = ((((((-2.8104E-13 * pow(soc, 7.0) + 1.0283E-10 * pow(soc, 6.0)) +
             -1.5072E-8 * pow(soc, 5.0)) + 1.1295E-6 * pow(soc, 4.0)) +
             -4.588E-5 * pow(soc, 3.0)) + soc * soc * 0.000993) +
             -0.010548 * soc) + 0.04876;
+	return docv;
 }
 ////
-void SOC_LookUp(uint16_T battsoc, uint16_T x[], uint16_T y[],uint16_T *bcusoc)
+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];
+        bcusoc = y[0];
     }
 	//
     if (battsoc >= x[2])
     {
-        *bcusoc = y[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];
+	   bcusoc =   (uint16_T) ((real_T)((battsoc - x[0]) * 0.1) * (real_T)((y[1] - y[0]) * 0.1) /(real_T)((x[1] - x[0]) * 0.1) * 10)+ y[0];
 	}
 	//
     if (battsoc >= x[1] && battsoc < x[2]) //(x-x1)*(y2-y1)/(x2-x1)+y1
     {
-       *bcusoc =   (uint16_T) ((real_T)((battsoc - x[1]) * 0.1) * (real_T)((y[2] - y[1]) * 0.1) /(real_T)((x[2] - x[1]) * 0.1) * 10)+ y[1];
+       bcusoc =   (uint16_T) ((real_T)((battsoc - x[1]) * 0.1) * (real_T)((y[2] - y[1]) * 0.1) /(real_T)((x[2] - x[1]) * 0.1) * 10)+ y[1];
     }
+	return bcusoc;
 }
 //-------------------------------------------------------------------------
 
-void SOCfit_IfActionSubsystem1(uint16_T SOC, uint16_T SOCfit_Delay, uint16_T *SOCfit, uint16_T m)
+uint16_T SOCfitSystem(uint16_T SOC,uint16_T *SOCfit, uint16_T m)
 {
-    if ((int16_T)(SOC - SOCfit_Delay) > m)
+    int16_T socdelt;
+	socdelt = (int16_T)(SOC - *SOCfit);
+	if( socdelt > m)
     {
-        *SOCfit = SOCfit_Delay + m;
-    }
-    else
-    {
-        *SOCfit = SOC;
-    }
-}
-//-------------------------------------------------------------------------
-  void SOCfit_IfActionSubsystem2(uint16_T SOC, uint16_T SOCfit_Delay, uint16_T *SOCfit, uint16_T m)
-{
-    if ((int16_T)(SOC - SOCfit_Delay) < -m)
-    {
-        *SOCfit = SOCfit_Delay - m;
-    }
-    else
-    {
-        *SOCfit = SOC;
+        *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;
 }

+ 27 - 15
src/EmbeddedCoder_src/SPM.c

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

+ 1 - 0
src/bsp_custom.c

@@ -266,6 +266,7 @@ void Pad0_WakeupIntHandler(void)
 
 void Pad1_WakeupIntHandler(void)
 {
+    UartInterruptcount++;
     if (slpManExtIntPreProcess(PadWakeup1_IRQn) == false)
     {
         return;

部分文件因为文件数量过多而无法显示