Procházet zdrojové kódy

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

# Conflicts:
#	inc/AppConfig.h
#	src/AppTaskMain.c
CHENJIE-PC\QiXiang_CHENJIE před 3 roky
rodič
revize
ac69aa49ea

+ 1 - 0
ARMCC/Makefile

@@ -34,6 +34,7 @@ obj-y             += PLAT/project/$(TARGET)/apps/qx_app/src/app.o \
 						PLAT/project/$(TARGET)/apps/qx_app/src/EmbeddedCoder_src/BLC.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/BCUCal.o \

+ 4 - 2
inc/AppFunc.h

@@ -3,7 +3,7 @@
  * @Date         : 2021-10-14 09:27:15
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-10-29 16:23:13
+ * @LastEditTime : 2021-11-12 15:03:02
  * @Description  : file content
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\inc\AppFunc.h
  */
@@ -23,6 +23,7 @@
 #include "AppConfig.h"
 #include "ec_tcpip_api.h"
 #include "AppSignal.h"
+#include "BCUCal.h"
 typedef struct _Fota_Type
 {
     BOOL Fota_update_error;
@@ -67,4 +68,5 @@ void relayControlFunc(UINT16 BuzzerPeriod, float DutyRatio);
 void SaveAppConfig(void);
 void SaveAppData(void);
 void SaveBcuData(void);
-void UDS_Service(CAN_Msg_Type *CanRxMsg);
+void UDS_Service(CAN_Msg_Type *CanRxMsg);
+void BmsProtectStateDecode(UINT8 *DischargeProtect, UINT8 *ChargeProtect);

+ 2 - 1
inc/AppSignal.h

@@ -2,7 +2,7 @@
  * @Author       : ChenJie
  * @Date         : 2021-10-14 09:27:15
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-10-26 16:07:37
+ * @LastEditTime : 2021-11-12 16:11:45
  * @Description  : Global variable definition H file
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\inc\AppSignal.h
  */
@@ -86,6 +86,7 @@ extern UINT16 avrgCellVol;
 extern UINT16 ErrorNum[ErrorNumLength];
 extern UINT16 updateDifferDataPackageCounter;
 extern INT16 xyzData[3];
+extern UINT8 otherTempAvg;
 //declear the UINT32 vars
 extern UINT32 battBalanceoInfo;
 extern UINT32 battProtectState;

+ 83 - 83
inc/AppTaskUart.h

@@ -29,14 +29,14 @@
 #include "numeric.h"
 #include "AppSignal.h"
 #include "hal_uart.h"
-#define  PROC_UART_TASK_STACK_SIZE (2048)
+#define PROC_UART_TASK_STACK_SIZE (2048)
 
-#define BMS_ADDRESS_CODE    0x01
-#define UART_READ_CODE      0x03
-#define UART_WRITE_CODE     0x10
-#define UART_ENCRYPT_CODE   0x05
-#define UART_WRITE_FLAG     0x01
-#define UART_READ_FLAG      0x00
+#define BMS_ADDRESS_CODE 0x01
+#define UART_READ_CODE 0x03
+#define UART_WRITE_CODE 0x10
+#define UART_ENCRYPT_CODE 0x05
+#define UART_WRITE_FLAG 0x01
+#define UART_READ_FLAG 0x00
 typedef enum
 {
     PROCESS_UART_STATE_INTI = 0,
@@ -46,104 +46,104 @@ typedef enum
     PROCESS_UART_STATE_WRITE,
     PROCESS_UART_STATE_UPDATE,
     PROCESS_UART_STATE_SLEEP
-}process_Uart;
+} process_Uart;
 typedef struct _UartQueryType
 {
-    UINT8 Bms_Address; 
-    UINT8 Bms_Funcode; 
-    UINT8 Reg_Begin_H; 
-    UINT8 Reg_Begin_L; 
-    UINT8 Reg_Num_H; 
-    UINT8 Reg_Num_L; 
+    UINT8 Bms_Address;
+    UINT8 Bms_Funcode;
+    UINT8 Reg_Begin_H;
+    UINT8 Reg_Begin_L;
+    UINT8 Reg_Num_H;
+    UINT8 Reg_Num_L;
     UINT8 CRC_L;
     UINT8 CRC_H;
-}UartQueryType;
+} UartQueryType;
 typedef struct _UartWriteMsgType
 {
-    UINT8 Bms_Address; 
-    UINT8 Bms_Funcode; 
-    UINT8 Reg_Begin_H; 
-    UINT8 Reg_Begin_L; 
-    UINT8 Reg_Num_H; 
-    UINT8 Reg_Num_L; 
+    UINT8 Bms_Address;
+    UINT8 Bms_Funcode;
+    UINT8 Reg_Begin_H;
+    UINT8 Reg_Begin_L;
+    UINT8 Reg_Num_H;
+    UINT8 Reg_Num_L;
     UINT8 Data_Count;
     UINT8 Data[2];
     UINT8 CRC_L;
     UINT8 CRC_H;
-}UartWriteMsgType;
+} UartWriteMsgType;
 typedef struct _UartWriteDataType
 {
-    volatile UINT8 WriteCmd; 
+    volatile UINT8 WriteCmd;
     UINT8 Data[2];
-}UartWriteData_S;
+} UartWriteData_S;
 typedef enum
 {
-        UPDATE_STEP_CHECK_VERSION=0,
-        UPDATE_STEP_REQUEST_UPDATE,
-        UPDATE_STEP_START_UPDATE, 
-        UPDATE_STEP_CHECK_VERSION_AGAIN,       
-        UPDATE_STEP_SET_BAUD_RATE,
-        UPDATE_STEP_PREPARE_SEND_DATA_LEN,
-        UPDATE_STEP_SEND_DATA_LEN,
-        UPDATE_STEP_PREPARE_SEND_UPDATE_DATA,
-        UPDATE_STEP_SEND_UPDATE_DATA,
-        UPDATE_STEP_SEND_DATA_END,
-        UPDATE_STEP_START_INSTALL,
-        UPDATE_STEP_END,
-        UPDATE_STEP_RESET, //exit download, and go to before UPDATE_STEP_PREPARE_SEND_UPDATE_DATA
-        UPDATE_STEP_DOWNLOAD_BREAK_OFF,  //exite download, and return boot mode(not app mode)
-        UPDATE_STEP_ERROR
-}UpdateStep;
+    UPDATE_STEP_CHECK_VERSION = 0,
+    UPDATE_STEP_REQUEST_UPDATE,
+    UPDATE_STEP_START_UPDATE,
+    UPDATE_STEP_CHECK_VERSION_AGAIN,
+    UPDATE_STEP_SET_BAUD_RATE,
+    UPDATE_STEP_PREPARE_SEND_DATA_LEN,
+    UPDATE_STEP_SEND_DATA_LEN,
+    UPDATE_STEP_PREPARE_SEND_UPDATE_DATA,
+    UPDATE_STEP_SEND_UPDATE_DATA,
+    UPDATE_STEP_SEND_DATA_END,
+    UPDATE_STEP_START_INSTALL,
+    UPDATE_STEP_END,
+    UPDATE_STEP_RESET,              //exit download, and go to before UPDATE_STEP_PREPARE_SEND_UPDATE_DATA
+    UPDATE_STEP_DOWNLOAD_BREAK_OFF, //exite download, and return boot mode(not app mode)
+    UPDATE_STEP_ERROR
+} UpdateStep;
 typedef enum
-{        
-        MS_UPDATE_STEP_SEND_FIRMWARE_UPDATE_REQUEST_AND_JUMP_TO_BOOTLOADER = 1,
-        MS_UPDATE_STEP_FIRMWARE_UPDATE_REQUEST_ANSWER, 
-        MS_UPDATE_STEP_SEND_FIRMWARE_INFO,       
-        MS_UPDATE_STEP_FIRMWARE_INFO_CHECK_AND_UPDATE_REQEST_ANSWER,
-        MS_UPDATE_STEP_EREASE_APP_FLASH_REQUEST,
-        MS_UPDATE_STEP_EREASE_FLASH_ANSWER,        
-        MS_UPDATE_STEP_SEND_UPDATE_DATA,
-        MS_UPDATE_STEP_UPDATE_DATA_WRITE_ANSWER,
-        MS_UPDATE_STEP_SEND_UPDATE_DATA_END_AND_JUMP_TO_APP,
-        MS_UPDATE_STEP_JUMP_TO_APP_ANSWER,
-        MS_UPDATE_STEP_READ_CURRENT_RUNNING_MODE,
-        MS_UPDATE_STEP_CURRENT_RUNNING_MODE_ANSWER,
-        MS_UPDATE_STEP_END,
-        MS_UPDATE_STEP_ERROR
-}UpdateStep_MS_BMS;
+{
+    MS_UPDATE_STEP_SEND_FIRMWARE_UPDATE_REQUEST_AND_JUMP_TO_BOOTLOADER = 1,
+    MS_UPDATE_STEP_FIRMWARE_UPDATE_REQUEST_ANSWER,
+    MS_UPDATE_STEP_SEND_FIRMWARE_INFO,
+    MS_UPDATE_STEP_FIRMWARE_INFO_CHECK_AND_UPDATE_REQEST_ANSWER,
+    MS_UPDATE_STEP_EREASE_APP_FLASH_REQUEST,
+    MS_UPDATE_STEP_EREASE_FLASH_ANSWER,
+    MS_UPDATE_STEP_SEND_UPDATE_DATA,
+    MS_UPDATE_STEP_UPDATE_DATA_WRITE_ANSWER,
+    MS_UPDATE_STEP_SEND_UPDATE_DATA_END_AND_JUMP_TO_APP,
+    MS_UPDATE_STEP_JUMP_TO_APP_ANSWER,
+    MS_UPDATE_STEP_READ_CURRENT_RUNNING_MODE,
+    MS_UPDATE_STEP_CURRENT_RUNNING_MODE_ANSWER,
+    MS_UPDATE_STEP_END,
+    MS_UPDATE_STEP_ERROR
+} UpdateStep_MS_BMS;
 typedef struct BMS_Update_Recv_Msg_Type
 {
-        UINT8 startFlag;
-        UINT8 addrFlag;
-        UINT8 cmdRW;
-        UINT8 dataLen;
-        UINT8 cmd;
-        UINT8 data;
-        UINT8 checkSum;
-        UINT8 endFlag;
-}BMS_Update_Recv_Msg_Type;
+    UINT8 startFlag;
+    UINT8 addrFlag;
+    UINT8 cmdRW;
+    UINT8 dataLen;
+    UINT8 cmd;
+    UINT8 data;
+    UINT8 checkSum;
+    UINT8 endFlag;
+} BMS_Update_Recv_Msg_Type;
 typedef enum
 {
-	updateOK                 	= 0,         ///< update successfully.
-	updateErrorTimeout			= 1,         ///< update failed after try 3 times, so time out
-	updateErrorBMSPowerLow        	= 2,         ///update failed, because of bmp power low
-	updateErrorBMSWarningProtect           	= 3,         ///update failed, because there are some warning in bms which not allowed to update
-	updateErrorBMSNotSurport          	= 4,         ///update failed, because of bms not surpport
-	updateErrorBMSWorkState           	= 5,         ///update failed, because bms is charging or discharging
-	updateErrorFirmwareInfoError                	= 6, //update failed, the firmware info error
-	updateErrorFirmwareSizeError          	= 7,  ///update failed, the firmware size in firmware info is to large
-	updateErrorAppErease = 8,			///update failed, erease app flash failed
-	updateErrorPackageCRC = 9,			///the crc of some package is wrong
-	updateErrorPackageWrite = 10,		///package write in failed
-	updateErrorPackageNo = 11,			///package number is not right or not continues
-	updateErrorCheckSumError ,			// checksum != checksumcal
-	updateFailed = 0xFF					///					
-}updateBMSStatus;
+    updateOK = 0,                     ///< update successfully.
+    updateErrorTimeout = 1,           ///< update failed after try 3 times, so time out
+    updateErrorBMSPowerLow = 2,       ///update failed, because of bmp power low
+    updateErrorBMSWarningProtect = 3, ///update failed, because there are some warning in bms which not allowed to update
+    updateErrorBMSNotSurport = 4,     ///update failed, because of bms not surpport
+    updateErrorBMSWorkState = 5,      ///update failed, because bms is charging or discharging
+    updateErrorFirmwareInfoError = 6, //update failed, the firmware info error
+    updateErrorFirmwareSizeError = 7, ///update failed, the firmware size in firmware info is to large
+    updateErrorAppErease = 8,         ///update failed, erease app flash failed
+    updateErrorPackageCRC = 9,        ///the crc of some package is wrong
+    updateErrorPackageWrite = 10,     ///package write in failed
+    updateErrorPackageNo = 11,        ///package number is not right or not continues
+    updateErrorCheckSumError,         // checksum != checksumcal
+    updateFailed = 0xFF               ///
+} updateBMSStatus;
 void AppTaskUartInit(void *arg);
 void AppTaskUartDeInit(void *arg);
 //BMS升级函数声明
-UINT8 SP_BMS_Update_CheckSUM(UINT8* pSendData,UINT8 len);
+UINT8 SP_BMS_Update_CheckSUM(UINT8 *pSendData, UINT8 len);
 void SP_BMS_Update_Service();
 updateBMSStatus MS_BMS_Update_Service();
-UINT16 MS_BMS_Update_CRC16(UINT8* pSendData,UINT16 len);
-UINT8 UartAppTrasmit(UINT8* pSend,UINT32 sendLen, UINT8* pRead, UINT32 readLen, UINT32 timeout);
+UINT16 MS_BMS_Update_CRC16(UINT8 *pSendData, UINT16 len);
+UINT8 UartAppTrasmit(UINT8 *pSend, UINT32 sendLen, UINT8 *pRead, UINT32 readLen, UINT32 timeout);

+ 14 - 2
inc/EmbeddedCoder_inc/BCUDisp.h

@@ -2,15 +2,16 @@
 #include "rtwtypes.h"
 #include "BCUCal.h"
 
-extern uint8_T tmsd_st_heatAct;                          /*热管理请求状态; */
 extern uint16_T appv_V_cellU[cmnc_num_cellUNumMax];                        /* 静态电压 */
-extern boolean_T ihd_flg_HVILFlt;                        /* 保护板上传的高压互锁故障 */
+extern uint8_T appd_st_preCyc;
+
 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];                    /*累计均衡容量 读取量(数组); */
 extern uint32_T blcv_Q_totalCpEo[cmnc_num_cellUNumMax];                    /*累计均衡容量 写入量(数组); */
 extern boolean_T blcv_flg_excute[cmnc_num_cellUNumMax];                    /*均衡执行请求标志位 (数组); */
 
+extern boolean_T ihd_flg_HVILFlt;                        /* 保护板上传的高压互锁故障 */
 extern boolean_T ihd_flg_DTCClear;                       /* 上位机发送的故障清楚指令;*/
 extern uint8_T ihd_st_authFaild;                         /* 底层诊断的认证失败故障;*/
 extern int16_T ihd_I_curr;                               /*电池包电流; */
@@ -80,6 +81,8 @@ extern boolean_T sfmd_flg_heatCirOpenFltEi;              /*加热回路常开故
 extern boolean_T sfmd_flg_heatCirOpenFltEo;              /*加热回路常开故障写入量 */  
 extern boolean_T sfmd_flg_heatRunFltEi;
 extern boolean_T sfmd_flg_heatRunFltEo;
+extern boolean_T sfmd_flg_iscFltEi;
+extern boolean_T sfmd_flg_iscFltEo;
 
 extern uint16_T socd_pct_ahSoc;                          /*安时SOC; */
 extern uint16_T socd_pct_estSoc;                         /*估算SOC;*/
@@ -94,6 +97,7 @@ extern uint16_T socd_pct_bcuSocEo;                       /*电池显示SOC写入
 extern uint16_T socd_pct_bcuSoc_Delay;                   /*电池显示SOC延时; */
 extern uint16_T socv_pct_cellSoc[cmnc_num_cellUNumMax];
 extern uint16_T socd_pct_cellBattSoc;
+extern boolean_T socd_flg_cellSocDisable;
 
 extern uint16_T sohd_Q_chrgEi;                           /*充入容量读取量; */
 extern uint16_T sohd_Q_chrgEo;                           /*充入容量写入量; */
@@ -111,6 +115,14 @@ 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 boolean_T iscd_flg_flt;
+extern uint16_T iscv_Q_remainCpEi[cmnc_num_cellUNumMax];
+extern uint32_T iscd_tm_totalEi;
+extern uint16_T iscv_Q_remainCpEo[cmnc_num_cellUNumMax];
+extern uint32_T iscd_tm_totalEo;
+
+extern uint8_T tmsd_st_heatAct;                          /*热管理请求状态; */
+
 extern uint8_T cmd_st_chrgMod;                           /* 充电模式  */
 extern uint8_T cmd_st_chrgSt;                            /* 充电状态  */
 extern int16_T cmd_I_chrgCurrReq;                       /* 充电需求电流  */

+ 8 - 0
inc/EmbeddedCoder_inc/ISC.h

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

+ 118 - 10
src/AppFunc.c

@@ -1,16 +1,122 @@
 /*
  * @Author       : ChenJie
- * @Date         : 2021-10-14 09:27:15
+ * @Date         : 2021-11-09 12:08:17
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-11-03 11:59:55
- * @Description  : 应用层函数定义区,UTF-8
+ * @LastEditTime : 2021-11-12 18:25:36
+ * @Description  : file content
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AppFunc.c
  */
-
 #include "AppFunc.h"
 #include "numeric.h"
 #include "hal_module_adapter.h"
+/**
+ * @brief : 保护板保护状态解码
+ * @param {*}
+ * @return {*}
+ */
+void BmsProtectStateDecode(UINT8 *DischargeProtect, UINT8 *ChargeProtect)
+{
+	UINT8 ret = 0;
+	//battProtectState = (dataPtr[(0x03 + BATT_CELL_VOL_NUM) * 2 + 0] << 24) | (dataPtr[(0x04 + BATT_CELL_VOL_NUM) * 2 + 0] << 16) | (dataPtr[(0x04 + BATT_CELL_VOL_NUM) * 2 + 1] << 8) | (dataPtr[(0x05 + BATT_CELL_VOL_NUM) * 2 + 1]);
+	if (battProtectState == 0x00)
+	{
+		*DischargeProtect = 0;
+		*ChargeProtect = 0;
+		return;
+	}
+
+	ret = getbit(battProtectState, 0);
+	if (ret) //放电短路保护--0
+	{
+		*DischargeProtect = (*DischargeProtect) + 1;
+		//printf("protect[%d]\n", __LINE__);
+	}
+	ret = getbit(battProtectState, 1);
+	if (ret) //放电过流保护--1
+	{
+		*DischargeProtect = (*DischargeProtect) + 1;
+		//printf("protect[%d]\n", __LINE__);
+	}
+
+	ret = getbit(battProtectState, 2);
+	if (ret) //充电过流保护--2
+	{
+		*ChargeProtect = (*ChargeProtect) + 1;
+		//printf("protect[%d]\n", __LINE__);
+	}
+
+	ret = getbit(battProtectState, 8);
+	if (ret) //电芯欠压--8
+	{
+		*DischargeProtect = (*DischargeProtect) + 1;
+		//printf("protect[%d]\n", __LINE__);
+	}
+
+	ret = getbit(battProtectState, 9);
+	if (ret) //总压欠压--9
+	{
+		*DischargeProtect = (*DischargeProtect) + 1;
+		//printf("protect[%d]\n", __LINE__);
+	}
+
+	ret = getbit(battProtectState, 16);
+	if (ret) //充电高温--16
+	{
+		*ChargeProtect = (*ChargeProtect) + 1;
+		//printf("protect[%d]\n", __LINE__);
+	}
+
+	ret = getbit(battProtectState, 17);
+	if (ret) //充电低温--17
+	{
+		*ChargeProtect = (*ChargeProtect) + 1;
+		//printf("protect[%d]\n", __LINE__);
+	}
+
+	ret = getbit(battProtectState, 18);
+	if (ret) //mos高温--18
+	{
+		*ChargeProtect = (*ChargeProtect) + 1;
+		*DischargeProtect = (*DischargeProtect) + 1;
+		//printf("protect[%d]\n", __LINE__);
+	}
+
+	ret = getbit(battProtectState, 20);
+	if (ret) //放电高温--20
+	{
+		*DischargeProtect = (*DischargeProtect) + 1;
+		//printf("protect[%d]\n", __LINE__);
+	}
+
+	ret = getbit(battProtectState, 21);
+	if (ret) //放电低温--21
+	{
+		*DischargeProtect = (*DischargeProtect) + 1;
+		//printf("protect[%d]\n", __LINE__);
+	}
+
+	ret = getbit(battProtectState, 24);
+	if (ret) //电芯过压--24
+	{
+		*ChargeProtect = (*ChargeProtect) + 1;
+		//printf("protect[%d]\n", __LINE__);
+	}
+
+	ret = getbit(battProtectState, 25);
+	if (ret) //总压过压--25
+	{
+		*ChargeProtect = (*ChargeProtect) + 1;
+		//printf("protect[%d]\n", __LINE__);
+	}
+
+	ret = getbit(battProtectState, 28);
+	if (ret) //充满保护--28
+	{
+		//*ChargeProtect = (*ChargeProtect) + 1;
+		//printf("protect[%d]\n", __LINE__);
+	}
+}
 /**
  * @brief : 故障代码处理函数,将故障代码进行排序并输出
  * @param {*}
@@ -135,7 +241,7 @@ INT8 rentalEndDetectFunc(void)
 	UTCToBeijing((UTC8TimeType *)&UTC8Time, year, month, day, hour, minute, sec);
 	if (UTC8Time.year > 2000)
 	{
-#ifdef USING_PRINTF
+#ifdef USING_PRINTF1
 		printf("retal Jug:%d %d %d %d,%d %d %d %d\n", UTC8Time.year, UTC8Time.month, UTC8Time.day, UTC8Time.hour, AppDataInfo.ExpiryTimeArray[0], AppDataInfo.ExpiryTimeArray[1], AppDataInfo.ExpiryTimeArray[2], AppDataInfo.ExpiryTimeArray[3]);
 #endif
 		if (((UTC8Time.year - 0x07D0) & 0xFF) == AppDataInfo.ExpiryTimeArray[0]) //年份相等判定月份
@@ -1297,17 +1403,19 @@ static void setDefaultBcuDataInfo(void)
 {
 	memset(&BcuDataInfo, 0x00, sizeof(BcuDataInfo));
 	BcuDataInfo.appDataModify = false;
-	memset(BcuDataInfo.blcv_Q_totalCpE, 0x00, 28 * sizeof(UINT32));
-	memset(BcuDataInfo.blcv_Q_reqCpE, 0x00, 28 * sizeof(UINT16));
+	memset(BcuDataInfo.blcv_Q_totalCpE, 0x00, cmnc_num_cellUNumMax * sizeof(UINT32));
+	memset(BcuDataInfo.blcv_Q_reqCpE, 0x00, cmnc_num_cellUNumMax * sizeof(UINT16));
 	BcuDataInfo.socd_pct_bcuSocE = 1200;
 	BcuDataInfo.socd_pct_battSocE = 1200;
 	BcuDataInfo.sohd_tm_chrgStartStatE = 0;
 	BcuDataInfo.sohd_flg_chrgEndE = 0;
-	BcuDataInfo.sohv_Q_cellCapArrE[28];
-	memset(BcuDataInfo.sohv_Q_cellCapArrE, 0, 28 * sizeof(UINT16));
-	memset(BcuDataInfo.sohv_V_chrgStartStatE, 0, 28 * sizeof(UINT16));
+	memset(BcuDataInfo.sohv_Q_cellCapArrE, 0, cmnc_num_cellUNumMax * sizeof(UINT16));
+	memset(BcuDataInfo.sohv_V_chrgStartStatE, 0, cmnc_num_cellUNumMax * sizeof(UINT16));
 	BcuDataInfo.sohd_Q_chrgE = 0;
 	memset(BcuDataInfo.sohv_Q_packCapArrE, 0, 10 * sizeof(UINT16));
+	memset(BcuDataInfo.iscv_Q_remainCpEE, 0, cmnc_num_cellUNumMax * sizeof(UINT16));
+	BcuDataInfo.iscd_tm_totalEE = 0;
+	BcuDataInfo.sfmd_flg_iscFltEE = 0;
 	BcuDataInfo.sfmd_flg_mainCirClosFltE = 0;
 	BcuDataInfo.sfmd_flg_heatCirClosFltE = 0;
 	BcuDataInfo.sfmd_flg_heatCirOpenFltE = 0;

+ 2 - 2
src/AppSignal.c

@@ -3,7 +3,7 @@
  * @Date         : 2021-10-14 09:27:15
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-11-04 14:13:04
+ * @LastEditTime : 2021-11-12 16:11:30
  * @Description  : Global variable definition c file,此文件存放App使用到的全局变量
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AppSignal.c
  */
@@ -82,7 +82,7 @@ UINT16 minCellVol = 0;                     //最小单体电压
 UINT16 nbHwVersion = 0;                    //数据模块硬件状态
 UINT16 updateDifferDataPackageCounter = 0; //差分包升级计数器
 INT16 xyzData[3] = {0};                    //xyz三轴数据
-
+UINT8 otherTempAvg = 0;
 /**declear the uint32 vars**/
 UINT32 battBalanceoInfo = 0; //电池均衡状态
 UINT32 Battdesigncap = 0;    //battery design cap 电池包设计容量

+ 20 - 10
src/AppTaskControl.c

@@ -21,6 +21,7 @@ static void ControlTask(void *arg)
     PROC_CONTROL_STATE_SWITCH(PROCESS_CONTROL_STATE_IDLE);
     UINT32 CurrentTime = 0;
     UINT16 RingTimes = 0;
+    UINT8 AdcIndex = 1;
     while (true)
     {
         switch (gProcess_Control_Task)
@@ -40,7 +41,7 @@ static void ControlTask(void *arg)
         }
         case PROCESS_CONTROL_STATE_WORK:
         {
-            osDelay(100);
+            osDelayUntil(100);
             if (CurrentTime != TimeCounter)
             {
                 UINT16 Buzzerperiod = 400;
@@ -74,10 +75,12 @@ static void ControlTask(void *arg)
                     relayControl(FALSE);
                 }
                 CurrentTime = TimeCounter;
-            }
-            if (TimeCounter % 10 == 0)
-            {
-                GetAdcValue(1);
+                GetAdcValue(AdcIndex);
+                AdcIndex++;
+                if (AdcIndex > 5)
+                {
+                    AdcIndex = 0;
+                }
             }
             if (gProcess_app != WORK)
             {
@@ -98,7 +101,14 @@ static void ControlTask(void *arg)
             osDelay(100);
             if (TimeCounter % (10 * 600) == 0)
             {
-                GetAdcValue(1);
+                AdcIndex = 0;
+                while (AdcIndex < 5)
+                {
+                    GetAdcValue(AdcIndex + 1);
+                    AdcIndex++;
+                    osDelay(200);
+                }
+                otherTempAvg = (heatTemp1 + heatTemp2 + fastChargeTemp + normalChargeTemp) / 4;
             }
             if (gProcess_app == WORK)
             {
@@ -135,19 +145,19 @@ void GetAdcValue(UINT8 num)
     case FAST_CHARGE_TEMP:
         NB_ADC_Get(&adcValue, FAST_CHARGE_TEMP);
         fastChargeTemp = LookUpRTtable(adcValue);
-		osDelay(200);
+        break;
     case NORMAL_CHARGE_TEMP:
         NB_ADC_Get(&adcValue, NORMAL_CHARGE_TEMP);
         normalChargeTemp = LookUpRTtable(adcValue);
-		osDelay(200);
+        break;
     case OTHER_TEMP_1:
         NB_ADC_Get(&adcValue, OTHER_TEMP_1);
         heatTemp1 = LookUpRTtable(adcValue);
-		osDelay(200);
+        break;
     case OTHER_TEMP_2:
         NB_ADC_Get(&adcValue, OTHER_TEMP_2);
         heatTemp2 = LookUpRTtable(adcValue);
-		osDelay(200);
+        break;
     case VBAT:
         NB_ADC_Get(&adcValue, VBAT);
         PowerVoltage = adcValue;

+ 3 - 3
src/AppTaskMain.c

@@ -3,7 +3,7 @@
  * @Date         : 2021-10-14 09:27:15
  * @Version      : V3.0
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-11-05 14:47:02
+ * @LastEditTime : 2021-11-12 16:03:37
  * @Description  : 主要负责:1.工作模式转换2.定时器定时3.定时保存运行数据4.异常状态重启
  * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AppTaskMain.c
  */
@@ -104,7 +104,7 @@ static void MainTask(void *arg)
                 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))
+            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;
@@ -169,7 +169,7 @@ static void MainTask(void *arg)
             {
                 SaveBcuData();
             }
-            if ((SleepTimerEnd) || (TCPWorkState == 1) || (PadInterrupt_clrCounter >= 1)) //从监听转换为工作的条件
+            if ((SleepTimerEnd) || (TCPWorkState == 1) || (PadInterrupt_clrCounter >= 1) || (otherTempAvg > (50 + 40))) //从监听转换为工作的条件
             {
 #ifdef USING_PRINTF1
                 printf("WORK:%d,%d,%d\n", PadInterrupt_clrCounter, PadInterrupt, UartInterruptcount);

+ 11 - 4
src/AppTaskTcp.c

@@ -8,6 +8,7 @@
  ****************************************************************************/
 #include "AppTaskTcp.h"
 #include "BCUDisp.h"
+#include "numeric.h"
 //局部变量申请
 static StaticTask_t gProcess_Tcp_Task_t;
 static UINT8 gProcess_Tcp_TaskStack[PROC_TCP_TASK_STACK_SIZE];
@@ -342,7 +343,7 @@ static void TcpDataInfoAssembleSend()
         *(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 + 49) = (UINT8)(sohd_pct_bcuSoh / 10); //soh-50
         *(SendBuffer + 50) = (battBalanceoInfo >> 24) & 0xFF;
         *(SendBuffer + 51) = (battBalanceoInfo >> 16) & 0xFF;
         *(SendBuffer + 52) = (battBalanceoInfo >> 8) & 0xFF;
@@ -555,6 +556,7 @@ static void TcpDataInfoAssembleSend()
             if (len > 0)
             {
                 TcpSendLen = 0x01 | TcpSendLen;
+                BMSupdatestatus = 0xFF;
             }
             else
             {
@@ -577,10 +579,15 @@ static void TcpDataInfoAssembleSend()
         }
         else
         {
-            sprintf((char *)rbuf, "B-%d,%d,%d,%d,%d,%d,%d,\
+            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,
-                    battI, maxCellVol, minCellVol);
+                    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);
         }
         Debugcounter++;
         if (Debugcounter > 100)

+ 25 - 27
src/AppTaskUart.c

@@ -2,12 +2,12 @@
  * @Author       : ChenJie
  * @Date         : 2021-10-14 09:27:15
  * @LastEditors  : ChenJie
- * @LastEditTime : 2021-10-29 10:25:03
+ * @LastEditTime : 2021-11-16 12:17:51
  * @Description  : file content
- * @FilePath     : \undefinedc:\Work_Files\Files\4830\SDK\PLAT\project\ec616_0h00\apps\qx_app\src\AppTaskUart.c
+ * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\AppTaskUart.c
  */
-
 #include "AppTaskUart.h"
+// #include "AppFunc.h"
 extern QueueHandle_t uartDataHandle;
 static StaticTask_t gProcess_Uart_Task_t;
 static UINT8 gProcess_Uart_TaskStack[PROC_UART_TASK_STACK_SIZE];
@@ -36,6 +36,8 @@ static void UartTask(void *arg)
 	UartWriteData_S UartWriteDataHandleRecv;
 	PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_INTI);
 	UINT8 ret = 0x00;
+	UINT8 EncryptFlag = 0x00;
+	UINT8 EncryptCount = 0;
 	if (UartWriteCmdHandle == NULL) //Uart控制命令传输指针
 	{
 		UartWriteCmdHandle = osMessageQueueNew(1, sizeof(UartWriteData_S), NULL);
@@ -59,14 +61,13 @@ static void UartTask(void *arg)
 		}
 		case PROCESS_UART_STATE_ENCRYPT:
 		{
-			UINT8 EncryptFlag = 0x00;
-			UINT8 EncryptCount = 0;
+
 			while (EncryptFlag != 0x01 && EncryptCount <= 3)
 			{
 				EncryptFlag = Uart_Encrypt_Send();
 				EncryptCount++;
 			}
-#ifdef USING_PRINTF
+#ifdef USING_PRINTF1
 			printf("EncryptFlag:%d\n", EncryptFlag);
 #endif
 			if (EncryptFlag == 0x01)
@@ -90,7 +91,7 @@ static void UartTask(void *arg)
 
 			if (TimeCounter % 10 == 0 && gProcess_app == WORK)
 			{
-				ECOMM_TRACE(UNILOG_PLA_APP, UartAppTask_83, P_SIG, 0, "Uart work begin:%02x", PadInterrupt);
+				//ECOMM_TRACE(UNILOG_PLA_APP, UartAppTask_83, P_SIG, 0, "Uart work begin:%02x", PadInterrupt);
 				memset(&(UartWriteDataHandleRecv), 0x00, sizeof(UartWriteDataHandleRecv));
 				if (osMessageQueueGet(UartWriteCmdHandle, &UartWriteDataHandleRecv, 0, 10) == osOK && UartRecvFlag == 1)
 				{
@@ -146,19 +147,14 @@ static void UartTask(void *arg)
 #endif
 			if (Uart_Recv_LEN > 5)
 			{
-			    uartBattInfoDecode(UartAnswerData.data);
+				uartBattInfoDecode(UartAnswerData.data);
 				UartErrorFlag = 0;
 				UartRecvFlagCounter = 0;
 				UartRecvFlag = 1;
 				PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
 				break;
 			}
-			else if (Uart_Recv_LEN == 1) //接收的数据校验不过
-			{
-				UartRecvFlag = 0;
-				UartRecvFlagCounter++;
-			}
-			else //没有接收到数据
+			else //没有接收到数据或数据有误
 			{
 				UartRecvFlag = 0;
 				UartRecvFlagCounter++;
@@ -166,9 +162,8 @@ static void UartTask(void *arg)
 			if (UartRecvFlagCounter >= 10)
 			{
 				UartRecvFlagCounter = 0;
-				uartBattInfoDecode(UartAnswerData.data);
 				UartErrorFlag = 1;
-				PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_INTI);
+				uartBattInfoDecode(UartAnswerData.data);
 				break;
 			}
 			break;
@@ -287,6 +282,9 @@ void Uart_Cmd_Control(QueueHandle_t UartWriteCmdHandle, UartBuffer UartAnswerDat
 	UINT8 ChargePermitState = 1;
 	UINT8 DischargePermitState = 1;
 	UINT8 RelayControlState = 0;
+	UINT8 DischargeProtectState = 0;
+	UINT8 ChargeProtectState = 0;
+	BmsProtectStateDecode(&DischargeProtectState, &ChargeProtectState);
 	ChargePermitState = getbit((UartAnswerData.data[(0x1B + AppDataInfo.BattCellCount + AppDataInfo.BattTempCount + BMS_OTHER_TEMP) * 2 + 1]), 1);	  //充电允许状态,1-允许,0禁止
 	DischargePermitState = getbit((UartAnswerData.data[(0x1B + AppDataInfo.BattCellCount + AppDataInfo.BattTempCount + BMS_OTHER_TEMP) * 2 + 1]), 0); //放电允许状态,1-允许,0禁止
 	RelayControlState = getbit((UartAnswerData.data[(0x09 + AppDataInfo.BattCellCount + AppDataInfo.BattTempCount + BMS_OTHER_TEMP) * 2 + 1]), 0);	  //继电器状态,1-继电器断开,0-继电器吸合
@@ -374,7 +372,7 @@ void Uart_Cmd_Control(QueueHandle_t UartWriteCmdHandle, UartBuffer UartAnswerDat
 		UartWriteData.Data[1] = 0x00 | DischargePermitState;
 		osMessageQueuePut(UartWriteCmdHandle, &UartWriteData, 0, 10);
 	}
-	else if ((ChargeForbiddenControl == 0x00) && (ChargePermitState != 0x01)) //try to unlock lock the charge
+	else if ((ChargeForbiddenControl == 0x00) && (ChargePermitState != 0x01) && (ChargeProtectState == 0)) //try to unlock lock the charge,
 	{
 #ifdef USING_PRINTF1
 		printf("[%d]try to unlock charge \n", __LINE__);
@@ -391,7 +389,7 @@ void Uart_Cmd_Control(QueueHandle_t UartWriteCmdHandle, UartBuffer UartAnswerDat
 		UartWriteData.Data[1] = (ChargePermitState << 1) | 0x00;
 		osMessageQueuePut(UartWriteCmdHandle, &UartWriteData, 0, 10);
 	}
-	else if ((DisChargeForbiddenControl == 0) && (DischargePermitState) != 0x01) // try to unlock
+	else if ((DisChargeForbiddenControl == 0) && (DischargePermitState) != 0x01 && (DischargeProtectState == 0)) // try to unlock
 	{
 		UartWriteData.WriteCmd = 0x01;
 		UartWriteData.Data[0] = (RelayControlState << 7) | 0x00;
@@ -440,22 +438,22 @@ UINT8 UartAppTrasmit(UINT8 *pSend, UINT32 sendLen, UINT8 *pRead, UINT32 readLen,
 	{
 		UartBuffer UartData;
 		osStatus_t ret = osMessageQueueGet(uartDataHandle, &UartData, 0, timeout);
-		if (ret == osOK && readLen == UartData.len)
+		if (ret == osOK)
 		{
 			memcpy(pRead, (UINT8 *)&UartData, UartData.len);
 			CRC_Rece_buffer = *(pRead + UartData.len - 1) << 8 | *(pRead + UartData.len - 2);
 			CRC_chk_buffer = crc_chk(pRead, UartData.len - 2);
 			if (*(pRead + 0) != 0x01 || CRC_Rece_buffer != CRC_chk_buffer)
 			{
-				hal_uart_hardware_config_t hwConfig = {
-					ARM_POWER_FULL,
-					ARM_USART_MODE_ASYNCHRONOUS | ARM_USART_DATA_BITS_8 |
-						ARM_USART_PARITY_NONE | ARM_USART_STOP_BITS_1 |
-						ARM_USART_FLOW_CONTROL_NONE,
-					9600U};
+				hal_uart_hardware_config_t hwConfig = {ARM_POWER_FULL,
+													   ARM_USART_MODE_ASYNCHRONOUS | ARM_USART_DATA_BITS_8 |
+														   ARM_USART_PARITY_NONE | ARM_USART_STOP_BITS_1 |
+														   ARM_USART_FLOW_CONTROL_NONE,
+													   9600U};
 				HAL_UART_ResetUartSetting(PORT_USART_1, &hwConfig, TRUE);
+				osDelay(500);
 				memset(pRead, 0x00, readLen);
-				return 0;
+				return 1;
 			}
 #ifdef USING_PRINTF1
 			printf("Uart recv:%d-%d\n", UartData.len, readLen);
@@ -475,7 +473,7 @@ UINT8 UartAppTrasmit(UINT8 *pSend, UINT32 sendLen, UINT8 *pRead, UINT32 readLen,
 	}
 	else
 	{
-		return 1;
+		return 3;
 	}
 }
 UINT8 Uart_Encrypt_Send()

+ 149 - 112
src/EmbeddedCoder_src/BCU.c

@@ -17,8 +17,8 @@ void BCU(void)
     while (TRUE)
     {
         if (UartRecvFlag == 1 || RecvCounter >= 15)
-        {   
-            //osDelay(1000);
+        {
+            RecvCounter = 0;
             break;
         }
         else
@@ -26,133 +26,166 @@ 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));
-            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;
-            ihd_st_EOLState = AppNVMData.EOLState;
-
-            PROC_BCU_STATE_SWITCH(PROCESS_STATE_WORK);
-            break;
-        }
-        //============================工作模式==========================
-        case PROCESS_STATE_WORK:
-        {
-            while (TRUE)
+            //=========================初始化===============================
+            case PROCESS_STATE_INIT:
             {
-                if (TimeCounter % 10 == 0)
-                {
-                    if (gProcess_app == LISTEN)
-                    {
-                        PROC_BCU_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                        break;
-                    }
-                    //数据获取
-                    if (BattWorkStateDelay == 0 && battI == 10000)
+                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:
+            {
+                 while (TRUE)
+                 {
+                      if (UartRecvFlag == 1 || RecvCounter >= 15)
+                      {
+                           RecvCounter = 0;
+                           break;
+                       }
+                      else
+                     {
+                          RecvCounter++;
+                          osDelay(1000);
+                     }
+                 }
+			
+                while (TRUE)
+                {   			    
+                    if (TimeCounter % 10 == 0)
                     {
-                        memcpy(appv_V_cellU, battCellU, sizeof(appv_V_cellU));
+                        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;
+                        }
+     
                     }
-                    ihd_I_curr = (int16_T)(-(battI - 10000));
-                    memcpy(ihv_V_cellU, battCellU, sizeof(battCellU));
-                    for (i = 0; i < cmnc_num_modTNum; i++)
+                    osDelay(100);
+                }
+                break;
+            }
+            //======================休眠模式===============================
+            case PROCESS_STATE_SLEEP:
+            {
+                BCUEEDataSave();
+                ihd_tm_parkTime = 0;
+                while (TRUE)
+                {
+                    if (TimeCounter % 10 == 0)
                     {
-                        ihv_T_modT[i] = battCellTemp[i];
+                        ihd_tm_parkTime++;
+                       
                     }
-                    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 = ihd_flg_disChrgMosClosFlt;
-
-                    //调用算法
-                    SFM();
-                    TMS();
-                    CM();
-                    SPM();
-                    //实时存储
-                    if (socd_flg_EEsave == 1 || ihd_flg_DTCClear)
+                    if (gProcess_app == WORK)
                     {
-                        BCUEEDataSave();
-                        ihd_flg_DTCClear = false;
+                        PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
+                        break;
                     }
+                    osDelay(100);
                 }
-                osDelay(100);
+                break;
             }
-            break;
-        }
-        //======================休眠模式===============================
-        case PROCESS_STATE_SLEEP:
-        {
-            BCUEEDataSave();
-            ihd_tm_parkTime = 0;
-            while (TRUE)
+            default:
             {
-                if (TimeCounter % 10 == 0)
-                {
-                    ihd_tm_parkTime++;
-                }
-                if (gProcess_app == WORK)
-                {
-                    PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
-                    break;
-                }
-                osDelay(100);
+                PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
+                break;
             }
-            break;
-        }
-        default:
-        {
-            PROC_BCU_STATE_SWITCH(PROCESS_STATE_INIT);
-            break;
-        }
         }
     }
 }
@@ -164,6 +197,7 @@ void BCU_Init(void)
     TMS_Init();
     CM_Init();
     SPM_Init();
+    ISC_Init();
 }
 
 //==========================主线程调用======================================
@@ -193,9 +227,12 @@ 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;
     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.appDataModify = TRUE;
 }

+ 14 - 2
src/EmbeddedCoder_src/BCUDisp.c

@@ -2,15 +2,16 @@
 
 #include "BCUDisp.h"
 
-uint8_T tmsd_st_heatAct;                          /*热管理请求状态; */
 uint16_T appv_V_cellU[cmnc_num_cellUNumMax];
-boolean_T ihd_flg_HVILFlt;
+uint8_T appd_st_preCyc;
+
 uint16_T blcv_Q_reqCpEi[cmnc_num_cellUNumMax];                      /*均衡需求容量 读取量(数组); */
 uint16_T blcv_Q_reqCpEo[cmnc_num_cellUNumMax];                      /*均衡需求容量 写入量(数组); */
 uint32_T blcv_Q_totalCpEi[cmnc_num_cellUNumMax];                    /*累计均衡容量 读取量(数组); */
 uint32_T blcv_Q_totalCpEo[cmnc_num_cellUNumMax];                    /*累计均衡容量 写入量(数组); */
 boolean_T blcv_flg_excute[cmnc_num_cellUNumMax];                    /*均衡执行请求标志位 (数组) */
 
+boolean_T ihd_flg_HVILFlt;
 boolean_T ihd_flg_DTCClear;
 uint8_T ihd_st_authFaild;                         
 int16_T ihd_I_curr;                               /*电池包电流; */
@@ -80,6 +81,8 @@ boolean_T sfmd_flg_heatCirOpenFltEi;              /*加热回路常开故障读
 boolean_T sfmd_flg_heatCirOpenFltEo;              /*加热回路常开故障写入量 */  
 boolean_T sfmd_flg_heatRunFltEi;
 boolean_T sfmd_flg_heatRunFltEo;
+boolean_T sfmd_flg_iscFltEi;
+boolean_T sfmd_flg_iscFltEo;
 
 uint16_T socd_pct_ahSoc;                          /*安时SOC; */
 uint16_T socd_pct_estSoc;                         /*估算SOC;*/
@@ -94,6 +97,7 @@ uint16_T socd_pct_bcuSocEo;                       /*电池显示SOC写入量;
 uint16_T socd_pct_bcuSoc_Delay;                   /*电池显示SOC延时; */
 uint16_T socv_pct_cellSoc[cmnc_num_cellUNumMax];
 uint16_T socd_pct_cellBattSoc;
+boolean_T socd_flg_cellSocDisable;
 
 uint16_T sohd_Q_chrgEi;                           /*充入容量读取量; */
 uint16_T sohd_Q_chrgEo;                           /*充入容量写入量; */
@@ -111,6 +115,14 @@ uint16_T sohv_Q_packCapArrEo[10];                 /*10次整包容量(数组
 uint16_T sohv_V_chrgStartStatEi[cmnc_num_cellUNumMax];              /*充电开始时刻的单体电压(数组)读取量; */
 uint16_T sohv_V_chrgStartStatEo[cmnc_num_cellUNumMax];              /*充电开始时刻的单体电压(数组)写入量; */
 
+boolean_T iscd_flg_flt;
+uint16_T iscv_Q_remainCpEi[cmnc_num_cellUNumMax];
+uint32_T iscd_tm_totalEi;
+uint16_T iscv_Q_remainCpEo[cmnc_num_cellUNumMax];
+uint32_T iscd_tm_totalEo;
+
+uint8_T tmsd_st_heatAct;                          /*热管理请求状态; */
+
 uint8_T cmd_st_chrgMod;                           /* 充电模式  */
 uint8_T cmd_st_chrgSt;                            /* 充电状态  */
 int16_T cmd_I_chrgCurrReq;                       /* 充电需求电流  */

+ 1 - 1
src/EmbeddedCoder_src/BLC.c

@@ -66,7 +66,7 @@ void BLC(void)
     //=========================================================================
     if(FirstRun_BLC)
     {
-		blcn_flg_judge	= (ihd_tm_parkTime > cmnc_tm_parkTime)&& !sfmd_flg_cellUDisable && (sfmd_I_curr > -10 && sfmd_I_curr < 10);
+		blcn_flg_judge	= (ihd_tm_parkTime >= cmnc_tm_parkTime)&& !sfmd_flg_cellUDisable && (sfmd_I_curr > -10 && sfmd_I_curr < 10);
     }
     blcn_flg_enable = ((sfmd_st_fltAct >> 7) & 0x01) != 1;
 

+ 39 - 16
src/EmbeddedCoder_src/CDM.c

@@ -16,32 +16,39 @@ void CDM(void)
     static 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 deltaRS[cmnc_num_cellUNumMax];
     static real_T 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;
     //
-    if(ihd_st_workStat_Delay != 1 && ihd_st_workStat == 1)
+    if(ihd_st_workStat_Delay == 2 && ihd_st_workStat != 2)
     {
         FirstRun_CDM = true;
     }
     ihd_st_workStat_Delay = ihd_st_workStat;
+	//
     if (FirstRun_CDM)
     {
         for (i = 0;i < cmnc_num_cellUNum;i++)
         {
-            P[0][i] = 0.001;
+            P[0][i] = 10;
             P[1][i] = 0;
             P[2][i] = 0;
-            P[3][i] = 0.001;
-            Lambda = 1;
-            deltaE[i] = 0;
-            deltaR[i] = 0;
+            P[3][i] = 10;
+            Lambda = 0.991;
+            deltaE[i] =  0;
+            deltaR[i] =  0;
+			deltaES[i] = 0;
+            deltaRS[i] = 0;
+			Cnt = 0;
         }
     }
-    
-    if(ihd_st_workStat == 1)
+    //
+    if(ihd_st_workStat != 2)
     {
         for (i = 0;i < cmnc_num_cellUNum;i++)
         {
@@ -49,7 +56,7 @@ void CDM(void)
         }
         cdmn_I_curr = (real_T) sfmd_I_curr * 0.1;
         //
-   
+        cdmd_flg_deltOCVDisable = false;
         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);
@@ -61,23 +68,39 @@ void CDM(void)
             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)
+            {
+                cdmd_flg_deltOCVDisable = true;
+			   
+            }
 	    }
         //
-        cdmd_flg_deltOCVDisable = false;
+		Cnt = Cnt + 1;
+
         for (i = 0;i < cmnc_num_cellUNum;i++)
         {   
-            cdmv_V_deltOCV[i] = (int16_T) (deltaE[i]  * 1000);
-            cdmv_ohm_deltR[i] = (int16_T) (deltaR[i]  * 1000 * 1000);
-            if(arf[i] > 0.05 && arf[i] < -0.05)
-            {
-                cdmd_flg_deltOCVDisable = true;
-            }
+            deltaES[i] = deltaES[i] + deltaE[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;
+		}
     }
     else
     {
         cdmd_flg_deltOCVDisable = false;
     }
+	
     FirstRun_CDM = false;
 	
 }

+ 189 - 0
src/EmbeddedCoder_src/ISC.c

@@ -0,0 +1,189 @@
+#include "ISC.h"
+#include "look1_is16lu16n16tu16_binlcase.h"
+
+boolean_T FirstRun_ISC;
+
+void ISC_Init(void)
+{
+    FirstRun_ISC = true;
+}
+//-------------------------------------------------------------------------
+
+void ISC(void)
+{
+    uint16_T i;
+    static uint32_T iscd_tm_totalEE;
+    static uint16_T iscv_Q_remainCpEE[cmnc_num_cellUNumMax];
+    uint16_T iscn_pct_cellSoc1[cmnc_num_cellUNumMax];
+    uint16_T iscn_pct_cellSoc2[cmnc_num_cellUNumMax];
+    int16_T iscn_Q_deltAh[cmnc_num_cellUNumMax];
+    uint16_T iscn_Q_cellAh[cmnc_num_cellUNumMax];
+    static uint16_T iscn_Q_cellAh0[cmnc_num_cellUNumMax];
+    static boolean_T iscd_flg_timedWakeUpFlt;
+    static boolean_T iscd_flg_disChrgFlt;
+    static uint16_T TimeCtn;
+    static uint16_T RunCtn;
+    static uint16_T iscn_N_fltNr[cmnc_num_cellUNumMax];
+    static boolean_T iscd_flg_fulStat;
+    //初值
+    if(FirstRun_ISC)
+    {
+        iscd_flg_timedWakeUpFlt = false;
+        iscd_flg_disChrgFlt = false;
+        memset(iscn_Q_cellAh0,0, sizeof(iscn_Q_cellAh0));
+		memset(iscn_pct_cellSoc1,0, sizeof(iscn_pct_cellSoc1));
+		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));
+        TimeCtn = 0;
+        RunCtn = 0;
+    }
+    //=====================================================================
+    //================高端SOC点诊断=================================== 0.1A
+    //=====================================================================
+    RunCtn = (RunCtn + 1) > 60000 ? 60000 : (RunCtn + 1);
+    if(FirstRun_ISC)
+    {
+        //
+        if(ArrMax(iscv_Q_remainCpEi,cmnc_num_cellUNum) > cmnc_Q_ratedCp)
+        {
+            memset(iscv_Q_remainCpEE,0, sizeof(iscv_Q_remainCpEi));
+            iscd_tm_totalEE =  0;
+        }
+        else
+        {
+            memcpy(iscv_Q_remainCpEE,iscv_Q_remainCpEi, sizeof(iscv_Q_remainCpEi));
+            iscd_tm_totalEE = iscd_tm_totalEi;
+        }
+        //
+        if((iscd_tm_totalEE + ihd_tm_parkTime >= 20 * 3600 || iscd_tm_totalEE == 0) && ihd_tm_parkTime >= cmnc_tm_parkTime && socd_pct_battSoc > 900 && sfmd_I_curr > -10 && sfmd_I_curr < 10)
+        {
+            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_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)
+                {
+                    iscd_flg_fulStat = true && iscd_tm_totalEE !=0;
+                }
+            }
+            memcpy(iscv_Q_remainCpEo,iscn_Q_cellAh, sizeof(iscn_Q_cellAh));
+            iscd_tm_totalEE = 0 ;
+        }
+        else
+        {
+            memcpy(iscv_Q_remainCpEo,iscv_Q_remainCpEi, sizeof(iscv_Q_remainCpEi));
+            iscd_tm_totalEE = iscd_tm_totalEE + ihd_tm_parkTime;
+        }
+    }
+	if(iscv_Q_remainCpEo[0] != 0)
+	{
+        iscd_tm_totalEo = iscd_tm_totalEE + RunCtn;
+	}
+	
+    //=====================================================================
+    //================定时唤醒诊断======================================1A
+    //=====================================================================
+    if(appd_st_preCyc == 1 && ihd_tm_parkTime >= cmnc_tm_parkTime && sfmd_I_curr < 10 && sfmd_I_curr > -10 && FirstRun_ISC)
+    {
+        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_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)
+            {
+                iscd_flg_timedWakeUpFlt = true;
+            }
+        }
+		
+    }
+   
+	
+    
+    //=====================================================================
+    //================放电过程中诊断=================================== 2A
+    //=====================================================================
+    if(!socd_flg_cellSocDisable)
+    {
+        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);
+        }
+        if (TimeCtn == 60)
+        {
+            memcpy(iscn_Q_cellAh0,iscn_Q_cellAh, sizeof(iscn_Q_cellAh));
+        }
+        if (TimeCtn > 60 + 360)
+        {
+            for (i = 0; i < cmnc_num_cellUNum;i++)
+            {
+                iscn_Q_deltAh[i] = (int16_T)(iscn_Q_cellAh[i] - iscn_Q_cellAh0[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.01/(TimeCtn - 60) * 3600 > 2 )
+                {
+                    iscn_N_fltNr[i] =  (iscn_N_fltNr[i] + 1) > 60000 ? 60000 : (iscn_N_fltNr[i] + 1);
+                }
+                else
+                {
+                    iscn_N_fltNr[i] = 0;
+                }
+                if (iscn_N_fltNr[i] > 600)
+                {
+                    iscd_flg_disChrgFlt = true;
+                }
+            }
+        }
+		if(TimeCtn > 3600)
+		{
+		   TimeCtn =60;
+		}
+    }
+    else
+    {
+        TimeCtn = 0;
+    }
+	
+    /////
+    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;
+}

+ 50 - 11
src/EmbeddedCoder_src/SFM.c

@@ -17,12 +17,17 @@ void SFM(void)
     boolean_T sfmd_flg_chrgMosClosFlt;
     boolean_T sfmd_flg_disChrgMosClosFlt;
 
+	static uint16_T Time0Cntl;
+    static uint16_T modTMaxArr[10];
+    static uint16_T SumT0;
     static uint16_T Time1Cntl;
     static uint16_T heatT1Arr[10];
     static uint16_T SumT1;
     static uint16_T Time2Cntl;
     static uint16_T heatT2Arr[10];
     static uint16_T SumT2;
+    boolean_T deltaTEn1;
+	boolean_T deltaTEn2;
 
     static uint8_T Cntl;
     static uint16_T CellUArry[4][cmnc_num_cellUNumMax];
@@ -139,7 +144,7 @@ void SFM(void)
     static boolean_T sfmd_flg_modTOpenFlt_keep;
     static uint16_T CntB;
 	static boolean_T ihd_flg_urtRecFlt_Delay = false;
-
+	
     int32_T SumR;
 	int32_T SumRR;
     boolean_T sfmd_flg_deltRFlt;
@@ -174,6 +179,7 @@ void SFM(void)
         memset(RecNr, 0, sizeof(RecNr));
         memset(modTOpenNr, 0, sizeof(modTOpenNr));
         memset(modTRationNr, 0, sizeof(modTRationNr));
+		memset(deltRFltNr, 0, sizeof(deltRFltNr));
         sfmd_flg_cellUOverFlt2 = false;
         sfmd_flg_cellUOverFlt1 = false;
         sfmd_flg_cellULowFlt2 = false;
@@ -240,6 +246,8 @@ void SFM(void)
         sfmd_flg_heatCirClosFltEo = false;
         sfmd_flg_heatRunFltEi = false;
         sfmd_flg_heatRunFltEo = false;
+		sfmd_flg_iscFltEi = false;
+		sfmd_flg_iscFltEi = false;
     }
 
     //=======================================================================================
@@ -268,6 +276,8 @@ void SFM(void)
     {
         sfmd_flg_HVILFlt = false;
     }
+   //16
+    sfmd_flg_iscFltEo = iscd_flg_flt ||sfmd_flg_iscFltEi||sfmd_flg_iscFltEo;
 
     //22 充电Mos失效故障
     sfmd_flg_chrgMosClosFlt = JudgeTimeSystem(!sfmd_flg_interComFlt, ihd_flg_chrgMosClosFlt, &DiagTime.N22, 2);
@@ -376,7 +386,8 @@ void SFM(void)
         }
         else
         {
-            sfmd_V_cellUAvrg = SumU / UNum;
+            //sfmd_V_cellUAvrg = SumU / UNum;
+			sfmd_V_cellUAvrg = (SumU - sfmd_V_cellUMax - sfmd_V_cellUMin) / (UNum - 2);
         }
 
 
@@ -572,7 +583,7 @@ void SFM(void)
             }
         }
     }
-
+	
     //69 加热板温度全部开路故障
     sfmd_flg_heatPanTAllFlt = (sfmd_flg_heatPanT1OpenFlt || sfmd_flg_heatPanT1RationFlt) && (sfmd_flg_heatPanT2OpenFlt || sfmd_flg_heatPanT2RationFlt);
 
@@ -844,6 +855,31 @@ void SFM(void)
 
 	
     ////32 加热回路常闭故障
+    if(!sfmd_flg_modTAllFlt)
+    {
+	    if (FirstRun_SFM)
+	   {
+		   for (i = 0; i < 10; i++)
+		  {
+			modTMaxArr[i] = sfmd_T_modTMax;
+		  }
+		  Time0Cntl = 0;
+		  SumT0 = 0;
+	   }
+	   Time0Cntl++;
+	   SumT0 = SumT0 + sfmd_T_modTMax;
+	   if (Time0Cntl >= 60)
+	   {
+		  for (i = 0; i < 9; i++)
+		  {
+			 modTMaxArr[i] = modTMaxArr[i + 1];
+		  }
+		  modTMaxArr[9] = SumT0 / Time0Cntl;
+		  Time0Cntl = 0;
+		  SumT0 = 0;
+	    }
+    }	
+
     if (!sfmd_flg_heatPanT1OpenFlt && !sfmd_flg_heatPanT1RationFlt && (int16_T)(ihd_T_heatPanT1 - ihd_T_heatPanT1_Delay1) > -10 && (int16_T)(ihd_T_heatPanT1 - ihd_T_heatPanT1_Delay1) < 20 )
     {
         if (FirstRun_SFM)
@@ -895,15 +931,18 @@ void SFM(void)
         }
     }
     ihd_T_heatPanT2_Delay1 =ihd_T_heatPanT2;
+	
     //32 加热回路常闭故障
-    Enable1 = JudgeTimeSystem(1, tmsd_st_heatAct == 0, &DiagTime.N32, 600);
-    sfmd_flg_heatCirClosFltEo = (((int16_T)(heatT2Arr[9] - heatT2Arr[0]) > 5 || (int16_T)(heatT1Arr[9] - heatT1Arr[0]) > 5) && Enable1) || sfmd_flg_heatCirClosFltEo || sfmd_flg_heatCirClosFltEi;
+    //deltaTEn1  = !sfmd_flg_heatPanT1OpenFlt && !sfmd_flg_heatPanT1RationFlt && !sfmd_flg_ACPlugTOpenFlt &&!sfmd_flg_ACPlugTRationFlt && !sfmd_flg_DCPlugTOpenFlt &&!sfmd_flg_DCPlugTRationFlt && ((ihd_T_heatPanT1 > ihd_T_ACPlugT + 5) && (ihd_T_heatPanT1 > ihd_T_DCPlugT + 5));
+    //deltaTEn2  = !sfmd_flg_heatPanT2OpenFlt && !sfmd_flg_heatPanT2RationFlt && !sfmd_flg_ACPlugTOpenFlt &&!sfmd_flg_ACPlugTRationFlt && !sfmd_flg_DCPlugTOpenFlt &&!sfmd_flg_DCPlugTRationFlt && ((ihd_T_heatPanT2 > ihd_T_ACPlugT + 5) && (ihd_T_heatPanT2 > ihd_T_DCPlugT + 5));
+	Enable1 = JudgeTimeSystem(1, tmsd_st_heatAct == 0, &DiagTime.N32, 600);
+    sfmd_flg_heatCirClosFltEo = (((int16_T)(heatT2Arr[9] - heatT2Arr[0]) > 5 || (int16_T)(heatT1Arr[9] - heatT1Arr[0]) > 5) && (modTMaxArr[9] > modTMaxArr[0] + 4) && Enable1 ) || sfmd_flg_heatCirClosFltEo || sfmd_flg_heatCirClosFltEi;
 
+	
     //33 加热回路常开故障
     Enable2 = JudgeTimeSystem(1, tmsd_st_heatAct == 1, &DiagTime.N33, 600);
     sfmd_flg_heatCirOpenFltEo = (((int16_T)(heatT2Arr[9] - heatT2Arr[0]) < 5 && (int16_T)(heatT1Arr[9] - heatT1Arr[0]) < 5) && Enable2) || sfmd_flg_heatCirOpenFltEo || sfmd_flg_heatCirOpenFltEi;
 
-    //printf("%d   %d  %d   %d   %d  %d  %d\n",sfmd_flg_Udrop,sfmd_flg_volFlt_keep,sfmd_flg_Tup,sfmd_flg_modTOpenFlt_keep,CntB,sfmd_flg_heatclear,sfmd_flg_heatRunFltEo) ;
 
     //================================================================================================================================================================
     //================================================================================================================================================================
@@ -974,9 +1013,9 @@ void SFM(void)
     FltLevel[14] = 0;
     FltAct[14] = 0; //15 绝缘告警
     
-    FltFlg[15] = 0;
-    FltLevel[15] = 0;
-    FltAct[15] = 0; //16 预留5
+    FltFlg[15] = sfmd_flg_iscFltEo;
+    FltLevel[15] = 4;
+    FltAct[15] = 250; //16 
     
     FltFlg[16] = 0;
     FltLevel[16] = 0;
@@ -1039,7 +1078,7 @@ void SFM(void)
     FltAct[30] = 0;
 	
     FltFlg[31] = sfmd_flg_heatCirClosFltEo;
-    FltLevel[31] = 5;
+    FltLevel[31] = 4;
     FltAct[31] = 250; //32 加热回路常闭故障
     
     FltFlg[32] = sfmd_flg_heatCirOpenFltEo;
@@ -1047,7 +1086,7 @@ void SFM(void)
     FltAct[32] = 0; //33 加热回路常开故障
     
     FltFlg[33] = sfmd_flg_mainCirClosFltEo;
-    FltLevel[33] = 5;
+    FltLevel[33] = 4;
     FltAct[33] = 250; //34 主回路常闭故障
     
     FltFlg[34] = 0;

+ 11 - 10
src/EmbeddedCoder_src/SOC.c

@@ -123,7 +123,7 @@ void SOC(void)
     if (FirstRun_SOC)
     { //
         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))
+                (((int16_T)(socd_pct_battSocEi - socd_pct_bcuSocEi) > 300 || (int16_T)(socd_pct_battSocEi - socd_pct_bcuSocEi) < -300) && ihd_tm_parkTime >= cmnc_tm_parkTime))
         {
             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);
@@ -134,7 +134,7 @@ void SOC(void)
             socn_pct_bcuSocEE = socd_pct_bcuSocEi;
         }
         //
-        if (ihd_tm_parkTime > cmnc_tm_parkTime)
+        if (ihd_tm_parkTime >= cmnc_tm_parkTime)
         {
             socn_pct_battSocEE = look1_iu16lu16n16tu16_binlcase(sfmd_V_cellUAvrg, (&(cmnm_V_ocv[0])), (&(cmnm_pct_soc[0])), 12U);
         }
@@ -210,8 +210,8 @@ void SOC(void)
     //输出
     EKFSOCMin = (uint16_T)(soc_Min_Delay * 10);
     socn_flg_ekfInvalidMin = (deltU > 0.01) || (deltU < -0.01);
-    //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-----------------------------------
+    //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]);  
+	//------------------------EKFSOCmax-----------------------------------
     if (FirstRun_SOC)
     {
         soc_Max_Delay = (real_T)socn_pct_battSocEE * 0.1;
@@ -273,7 +273,7 @@ void SOC(void)
     //输出
     EKFSOCMax = (uint16_T)(soc_Max_Delay * 10);
     socn_flg_ekfInvalidMax = (deltU > 0.01) || (deltU < -0.01);
-    //printf("3----socmax:%f,Up:%f,sfmd_V_cellUMax:%d,deltU:%f,flg:%d\n",soc_Max_Delay,Up_Max_Delay,sfmd_V_cellUMax,deltU,socn_flg_ekfInvalidMax);
+    //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]);
     //-----------------------EKFSOC----------------------------------------
     socn_flg_ekfInvalid = socn_flg_ekfInvalidMax || socn_flg_ekfInvalidMin;
     if (EKFSOCMax > 800)
@@ -303,10 +303,10 @@ void SOC(void)
         P_avrg_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_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;
     A[0] = 1;
     A[1] = 0;
     A[2] = 0;
@@ -354,12 +354,13 @@ void SOC(void)
     //输出
     EKFSOCAvrg = (uint16_T)(soc_Avrg_Delay * 10);
     socn_flg_ekfInvalidAvrg = (deltU > 0.01) || (deltU < -0.01);
+	//printf("4----soc:%f,Up:%f,U:%d,deltU:%f,K[0]:%f,K[1]:%f\n\n",soc_Avrg_Delay,Up_Avrg_Delay,sfmd_V_cellUAvrg,deltU,K[0],K[1]);
     //
     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);
     }
-    //socn_flg_ekfInvalid = socn_flg_ekfInvalidAvrg || cdmd_flg_deltOCVDisable;
+    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);
     if (cellSocMax > 800)

+ 3 - 2
src/EmbeddedCoder_src/SOH.c

@@ -95,7 +95,7 @@ void SOH(void)
  		//=======================================================================================
         //--------------------------计算使能-------------------------------------------------------
         //=======================================================================================
-        if(ihd_tm_parkTime > cmnc_tm_parkTime && sohn_flg_chrgEndEE && sohn_Q_chrgEE > sohc_Q_countThr && !sfmd_flg_cellUDisable && sfmd_I_curr < 10 && sfmd_I_curr > -10)
+        if(ihd_tm_parkTime >= cmnc_tm_parkTime && sohn_flg_chrgEndEE && sohn_Q_chrgEE > sohc_Q_countThr && !sfmd_flg_cellUDisable && sfmd_I_curr < 10 && sfmd_I_curr > -10)
         {
             sohn_flg_countEn = true;
         }
@@ -152,7 +152,8 @@ void SOH(void)
              memcpy(sohv_Q_packCapArrEo,sohn_Q_packCapArrEE, sizeof(sohv_Q_packCapArrEo));
              memcpy(sohv_Q_cellCapArrEo,sohn_Q_cellCapArrEE, sizeof(sohv_Q_cellCapArrEo));
          }
- 
+		 memcpy(sohv_Q_cellCap,sohv_Q_cellCapArrEo, sizeof(sohv_Q_cellCapArrEo));
+
  
          SumQ = 0;
          for(i = 0; i < 10;i++)

+ 16 - 7
src/EmbeddedCoder_src/TMS.c

@@ -1,3 +1,12 @@
+/*
+ * @Author       : ChenJie
+ * @Date         : 2021-11-08 10:44:13
+ * @Version      : V3.0
+ * @LastEditors  : ChenJie
+ * @LastEditTime : 2021-11-08 14:34:38
+ * @Description  : file content
+ * @FilePath     : \PLAT\project\ec616_0h00\apps\qx_app\src\EmbeddedCoder_src\TMS.c
+ */
 
 #include "TMS.h"
 
@@ -12,7 +21,7 @@ void TMS(void)
     static uint8_T TminLowNr;
     static uint8_T TminOverNr;
     static uint8_T TmaxOverNr;
-    
+
     //初始值
     if (FirstRun_TMS)
     {
@@ -21,7 +30,7 @@ void TMS(void)
         TminOverNr = 0;
         TmaxOverNr = 0;
     }
-    
+
     //
     if (sfmd_T_modTMin < tmsc_T_openThr)
     {
@@ -49,11 +58,11 @@ void TMS(void)
     {
         TmaxOverNr = 0;
     }
-    
+
     //================================温度判定 开关热管理状态===============================
     if (tmsd_st_heatAct == 0)
     {
-        if (TminLowNr >= 5 && ( socd_pct_battSoc > 100 || ihd_st_chrgConnect == 1))
+        if (TminLowNr >= 5 && ((socd_pct_battSoc > 100 && ihd_st_disChrgMosControl == 1) || ihd_st_chrgConnect == 1))
         {
             tmsd_st_heatAct = 1;
         }
@@ -65,13 +74,13 @@ void TMS(void)
             tmsd_st_heatAct = 0;
         }
     }
-    
+
     //因故障关闭热管理
     if (((sfmd_st_fltAct >> 4) & 0x01) == 1)
     {
         tmsd_st_heatAct = 0;
     }
-    
+
     //强制控制加热回路
     if (ihd_st_heatForceControl == 1)
     {
@@ -81,6 +90,6 @@ void TMS(void)
     {
         tmsd_st_heatAct = 0;
     }
-    
+
     FirstRun_TMS = false;
 }