Browse Source

MLSLX:2.1.1.0 部分合并2.3.0.28

CHENJIE-PC\QiXiang_CHENJIE 3 years ago
parent
commit
7aaf564e7b
15 changed files with 356 additions and 151 deletions
  1. 1 1
      ARMCC/Makefile
  2. 27 1
      inc/Signal.h
  3. 1 1
      inc/app.h
  4. 1 0
      inc/bsp_custom.h
  5. 0 1
      inc/hal_module_adapter.h
  6. 16 16
      src/CANEncode.c
  7. 3 3
      src/CANTask.c
  8. 1 1
      src/Fota.c
  9. 6 6
      src/GpsTask.c
  10. 9 7
      src/MainTask.c
  11. 26 11
      src/Signal.c
  12. 63 28
      src/TcpTask.c
  13. 170 40
      src/UartTask.c
  14. 18 19
      src/hal_module_adapter.c
  15. 14 16
      src/sensor.c

+ 1 - 1
ARMCC/Makefile

@@ -10,7 +10,6 @@ THIRDPARTY_WAKAAMA_ENABLE   = n
 THIRDPARTY_ERCOAP_ENABLE    = y
 THIRDPARTY_ERCOAP_ENABLE    = y
 THIRDPARTY_TINYDTLS_ENABLE  = y
 THIRDPARTY_TINYDTLS_ENABLE  = y
 THIRDPARTY_MBEDTLS_ENABLE   = y
 THIRDPARTY_MBEDTLS_ENABLE   = y
-
 CFLAGS_INC        +=  -I ../inc
 CFLAGS_INC        +=  -I ../inc
 
 
 
 
@@ -31,4 +30,5 @@ obj-y             += PLAT/project/$(TARGET)/apps/qx_app/src/app.o \
 
 
 include $(TOP)/PLAT/tools/scripts/Makefile.rules
 include $(TOP)/PLAT/tools/scripts/Makefile.rules
 
 
+#enable wdt
 CFLAGS += -DWDT_FEATURE_ENABLE=1
 CFLAGS += -DWDT_FEATURE_ENABLE=1

+ 27 - 1
inc/Signal.h

@@ -30,7 +30,7 @@ extern	UINT8	reservedSignal7;
 extern	UINT8	reservedSignal8;
 extern	UINT8	reservedSignal8;
 extern  UINT8	CanMsgFlag;
 extern  UINT8	CanMsgFlag;
 extern  UINT8   RxFlag;
 extern  UINT8   RxFlag;
-
+extern  UINT8   chargerConnectState;
 
 
 //declear the UINT16 vars
 //declear the UINT16 vars
 extern	UINT16	battCellU[28];
 extern	UINT16	battCellU[28];
@@ -48,9 +48,35 @@ extern	UINT32	battWarningState;
 extern	UINT32	nbSwVersion;
 extern	UINT32	nbSwVersion;
 extern	UINT32	battBalanceoInfo;
 extern	UINT32	battBalanceoInfo;
 extern  UINT32  Battdesigncap;
 extern  UINT32  Battdesigncap;
+extern  UINT32  BattRemainCap;
+extern  UINT32  battProtectState;
+
+
 
 
 extern UINT16   ErrorNum[5];//故障代码
 extern UINT16   ErrorNum[5];//故障代码
 extern UINT8 	TcpSendLen;
 extern UINT8 	TcpSendLen;
 
 
 extern osMutexId_t Error_Mutex;
 extern osMutexId_t Error_Mutex;
 
 
+#define SOC_TEST
+#ifdef SOC_TEST
+extern UINT8 SOC1;
+extern UINT8 SOC2;
+extern UINT16 Data_33 ;
+extern UINT16 Data_34 ;
+extern UINT32 Data_35 ;
+extern UINT16 Data_37 ;
+extern UINT16 Data_38 ;
+extern UINT16 Data_39 ;
+extern UINT16 Data_3A ;
+extern UINT16 Data_3B ;
+extern UINT16 Data_3C ;
+extern UINT16 Data_3D ;
+extern UINT16 Data_3E ;
+extern UINT16 Data_3F ;
+extern UINT16 Data_40 ;
+extern UINT16 Data_41 ;
+extern UINT16 Data_42 ;
+extern UINT16 Data_43 ;
+extern INT16  Data_Current ;
+#endif

+ 1 - 1
inc/app.h

@@ -52,7 +52,7 @@ extern "C" {
 #define	DRVSWVERSION		0x01050000     //驱动层版本号V1.4.0.0  驱动层1.5.0.0,增加了三轴
 #define	DRVSWVERSION		0x01050000     //驱动层版本号V1.4.0.0  驱动层1.5.0.0,增加了三轴
 //#define	APPSWVERSION		0x01020209     
 //#define	APPSWVERSION		0x01020209     
 //#define	APPSWVERSION		0x02000103
 //#define	APPSWVERSION		0x02000103
-#define	APPSWVERSION		0x02010012
+#define	APPSWVERSION		0x02010013
 //--------------------------------------------------------------------------------
 //--------------------------------------------------------------------------------
 
 
 #define APP_CONFIG_FILE_LATEST_VERSION 0
 #define APP_CONFIG_FILE_LATEST_VERSION 0

+ 1 - 0
inc/bsp_custom.h

@@ -8,6 +8,7 @@ extern "C" {
 #include "bsp.h"
 #include "bsp.h"
 #include "hal_module_adapter.h"
 #include "hal_module_adapter.h"
 void BSP_CustomInit(void);
 void BSP_CustomInit(void);
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 }
 }
 #endif
 #endif

+ 0 - 1
inc/hal_module_adapter.h

@@ -7,7 +7,6 @@ extern "C" {
 #include "commontypedef.h"
 #include "commontypedef.h"
 #include "sensor.h"
 #include "sensor.h"
 #include "can.h"
 #include "can.h"
-
 #define USING_PRINTF
 #define USING_PRINTF
 #define DEBUGLOG
 #define DEBUGLOG
 
 

+ 16 - 16
src/CANEncode.c

@@ -97,14 +97,14 @@ void CANEncodeFunction(UINT32 ID,UINT8* rawData)
 			*(UINT8*)(rawData +5) =battHeatEnableState&0xFF;
 			*(UINT8*)(rawData +5) =battHeatEnableState&0xFF;
 			break;
 			break;
 		case	0x6C4:
 		case	0x6C4:
-			*(UINT8*)(rawData +0) =reservedSignal1&0xFF;
-			*(UINT8*)(rawData +1) =reservedSignal2&0xFF;
-			*(UINT8*)(rawData +2) =reservedSignal3&0xFF;
-			*(UINT8*)(rawData +3) =reservedSignal4&0xFF;
-			*(UINT8*)(rawData +4) =reservedSignal5&0xFF;
-			*(UINT8*)(rawData +5) =reservedSignal6&0xFF;
-			*(UINT8*)(rawData +6) =reservedSignal7&0xFF;
-			*(UINT8*)(rawData +7) =reservedSignal8&0xFF;
+			*(UINT8*)(rawData +0) =0xFF;
+			*(UINT8*)(rawData +1) =0xFF;
+			*(UINT8*)(rawData +2) =0xFF;
+			*(UINT8*)(rawData +3) =0xFF;
+			*(UINT8*)(rawData +4) =0xFF;
+			*(UINT8*)(rawData +5) =0xFF;
+			*(UINT8*)(rawData +6) =0xFF;
+			*(UINT8*)(rawData +7) =0xFF;
 			break;
 			break;
 		case	0x7C0:
 		case	0x7C0:
 			*(UINT16*)(rawData +0) = ((battCellU[0]>>8) & 0xFF) | (((battCellU[0]&0xFF)<<8)&0xFF00);
 			*(UINT16*)(rawData +0) = ((battCellU[0]>>8) & 0xFF) | (((battCellU[0]&0xFF)<<8)&0xFF00);
@@ -194,14 +194,14 @@ void CANEncodeFunction(UINT32 ID,UINT8* rawData)
 			*(UINT8*)(rawData +5) =battHeatEnableState&0xFF;
 			*(UINT8*)(rawData +5) =battHeatEnableState&0xFF;
 			break;
 			break;
 		case	0x7CD:
 		case	0x7CD:
-			*(UINT8*)(rawData +0) =reservedSignal1&0xFF;
-			*(UINT8*)(rawData +1) =reservedSignal2&0xFF;
-			*(UINT8*)(rawData +2) =reservedSignal3&0xFF;
-			*(UINT8*)(rawData +3) =reservedSignal4&0xFF;
-			*(UINT8*)(rawData +4) =reservedSignal5&0xFF;
-			*(UINT8*)(rawData +5) =reservedSignal6&0xFF;
-			*(UINT8*)(rawData +6) =reservedSignal7&0xFF;
-			*(UINT8*)(rawData +7) =reservedSignal8&0xFF;
+			*(UINT8*)(rawData +0) =battProtectState&0xFF;
+			*(UINT8*)(rawData +1) =(battProtectState>>8)&0xFF;
+			*(UINT8*)(rawData +2) =(battProtectState>>16)&0xFF;
+			*(UINT8*)(rawData +3) =(battProtectState>>24)&0xFF;
+			*(UINT8*)(rawData +4) =0xFF;
+			*(UINT8*)(rawData +5) =0xFF;
+			*(UINT8*)(rawData +6) =0xFF;
+			*(UINT8*)(rawData +7) =0xFF;
 			break;
 			break;
 		case	0x7B0:
 		case	0x7B0:
 			*(UINT8*)(rawData +0) = (AppNVMData.battSN[0])&0xFF;
 			*(UINT8*)(rawData +0) = (AppNVMData.battSN[0])&0xFF;

+ 3 - 3
src/CANTask.c

@@ -90,7 +90,7 @@ static void Can_Receive()
 				}
 				}
 				if(HAL_Can_Receive(CanRxMsg)>0)					
 				if(HAL_Can_Receive(CanRxMsg)>0)					
 				{
 				{
-					CanMsgFlag  = 1;
+					CanMsgFlag = 0x01;
 					delayconuter=0;						
 					delayconuter=0;						
 					for(i=0; i<2; i++)
 					for(i=0; i<2; i++)
 					{								
 					{								
@@ -139,10 +139,10 @@ static void Can_Receive()
 						delayconuter=0;
 						delayconuter=0;
 					}
 					}
 				}
 				}
-				if(delayconuter>100 && msgFlag==0)
+				if(delayconuter>100 && msgFlag ==0)
 				{
 				{
-					CanMsgFlag = 0;
 					delayconuter=0;
 					delayconuter=0;
+					CanMsgFlag = 0x00;
 					PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_IDLE);
 					PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_IDLE);
 				}
 				}
 				break;
 				break;

+ 1 - 1
src/Fota.c

@@ -76,7 +76,7 @@ void Fota_Func(UINT8 *DataPtr,INT32 connectId)
                     memset(Data_Read_Buffer,0x00,Fota_S.Fota_Recv_Data_Len);
                     memset(Data_Read_Buffer,0x00,Fota_S.Fota_Recv_Data_Len);
                     BSP_QSPI_Read_Safe(Data_Read_Buffer,Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
                     BSP_QSPI_Read_Safe(Data_Read_Buffer,Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
                     Data_Read_Crc = Fota_crc_chk(Data_Read_Buffer,Fota_S.Fota_Recv_Data_Len);
                     Data_Read_Crc = Fota_crc_chk(Data_Read_Buffer,Fota_S.Fota_Recv_Data_Len);
-                    #ifdef USING_PRINTF
+                    #ifdef USING_PRINTF1
                         printf("Data_Read_Buffer:\n");
                         printf("Data_Read_Buffer:\n");
                         for(int i=0;i<Fota_S.Fota_Recv_Data_Len;i++)
                         for(int i=0;i<Fota_S.Fota_Recv_Data_Len;i++)
                         {
                         {

+ 6 - 6
src/GpsTask.c

@@ -37,7 +37,7 @@ extern UINT8 WorkFlag;
 UINT8 GpsData[20];
 UINT8 GpsData[20];
 osMutexId_t GpsMutex = NULL;
 osMutexId_t GpsMutex = NULL;
 //线程定义区
 //线程定义区
-#define GPS_TASK_STACK_SIZE   								 (512)
+#define GPS_TASK_STACK_SIZE   								 (1024)
 static QueueHandle_t norGpsHandle = NULL;
 static QueueHandle_t norGpsHandle = NULL;
 static osThreadId_t gpsTaskHandle = NULL;
 static osThreadId_t gpsTaskHandle = NULL;
 static StaticTask_t gpsTask = NULL;
 static StaticTask_t gpsTask = NULL;
@@ -66,7 +66,7 @@ static void GpsTask(void* arg)
     while(1)
     while(1)
     {
     {
         //char temp[] = "$GNRMC,082626.000,A,2939.91801,N,10637.09500,E,0.543,30.254,261120,,,A,V*17";
         //char temp[] = "$GNRMC,082626.000,A,2939.91801,N,10637.09500,E,0.543,30.254,261120,,,A,V*17";
-        osStatus_t ret = osMessageQueueGet(norGpsHandle, &msg, 0, 1000);
+        osStatus_t ret = osMessageQueueGet(norGpsHandle, &msg, 0, 100);
         if(ret==0)
         if(ret==0)
         {
         {
             if (msg.dataPtr)
             if (msg.dataPtr)
@@ -135,12 +135,12 @@ static void GpsTask(void* arg)
                             }
                             }
 
 
                         }
                         }
-                        GpsData[16] = AppDataInfo.AccMileage>>24;
-                        GpsData[17] = AppDataInfo.AccMileage>>16;
-                        GpsData[18] = AppDataInfo.AccMileage>>8;
-                        GpsData[19] = AppDataInfo.AccMileage;
                     }
                     }
                 }
                 }
+                GpsData[16] = AppDataInfo.AccMileage>>24;
+                GpsData[17] = AppDataInfo.AccMileage>>16;
+                GpsData[18] = AppDataInfo.AccMileage>>8;
+                GpsData[19] = AppDataInfo.AccMileage;
                 osMutexRelease(GpsMutex);
                 osMutexRelease(GpsMutex);
             }
             }
             if(msg.dataPtr)
             if(msg.dataPtr)

+ 9 - 7
src/MainTask.c

@@ -82,11 +82,13 @@ static void appSaveDataInfo(void);
 //主线程任务区
 //主线程任务区
 static void MainTask(void* arg)
 static void MainTask(void* arg)
 {
 {
-
+    if(Error_Mutex == NULL)
+    {
+        Error_Mutex = osMutexNew(NULL);
+    }
     GsensorI2CHandler(GsensorI2CCallback);
     GsensorI2CHandler(GsensorI2CCallback);
     GsensorInit();
     GsensorInit();
-
-
+    
 
 
     int32_t inParam = 0xAABBCCDD;
     int32_t inParam = 0xAABBCCDD;
     UINT32  param;
     UINT32  param;
@@ -184,7 +186,7 @@ static void MainTask(void* arg)
             case PROCESS_STATE_WORK:
             case PROCESS_STATE_WORK:
             {
             {
 
 
-                if(Error_count>=5 && CanMsgFlag==0)
+                if(Error_count>=5 && CanMsgFlag==0x00 && UDSSwitch==0 &&BMS_Fota_update_flag==FALSE && battWorkState==0)
                 {
                 {
                     AppDataInfo.appDataModify = true;
                     AppDataInfo.appDataModify = true;
                     AppDataInfo.SysReStart = AppDataInfo.SysReStart +1;
                     AppDataInfo.SysReStart = AppDataInfo.SysReStart +1;
@@ -204,7 +206,7 @@ static void MainTask(void* arg)
                     osDelay(1000);
                     osDelay(1000);
                     EC_SystemReset();
                     EC_SystemReset();
                 }
                 }
-                osDelay(1000);
+                osDelay(100);
                 if(Work_timer_end)
                 if(Work_timer_end)
                 {
                 {
                     xTimerStop(montior_timer, 0);
                     xTimerStop(montior_timer, 0);
@@ -244,7 +246,7 @@ static void MainTask(void* arg)
                 #ifdef USING_PRINTF1
                 #ifdef USING_PRINTF1
                     printf("TcpService:%d,UDSSwitch:%d,BMS_Fota_update_flag:%d,battWorkState:%d,Can_Msg_Enble:%d\r\n",TcpService,UDSSwitch,BMS_Fota_update_flag,battWorkState,Can_Msg_Enble);
                     printf("TcpService:%d,UDSSwitch:%d,BMS_Fota_update_flag:%d,battWorkState:%d,Can_Msg_Enble:%d\r\n",TcpService,UDSSwitch,BMS_Fota_update_flag,battWorkState,Can_Msg_Enble);
                 #endif	
                 #endif	
-                if(TcpService!=0x00||UDSSwitch==1||BMS_Fota_update_flag||battWorkState!=0||CanMsgFlag==1)
+                if(TcpService!=0x00||UDSSwitch==1||BMS_Fota_update_flag||battWorkState!=0||CanMsgFlag==0x01)
                 {
                 {
                     xTimerReset(work_timer,0);
                     xTimerReset(work_timer,0);
                 }
                 }
@@ -298,7 +300,7 @@ static void MainTask(void* arg)
                     printf("which slpstate can go now :%d \n",slpstate);
                     printf("which slpstate can go now :%d \n",slpstate);
                 #endif
                 #endif
                 #ifdef DEBUGLOG
                 #ifdef DEBUGLOG
-                    Debug_printf("slp-%d,%d,%d,%d\n",slpstate,AppDataInfo.AccMileage,AppDataInfo.SysReStart,Battdesigncap);
+                    Debug_printf("slp-%d,%d\n",slpstate,AppDataInfo.SysReStart);
                 #endif
                 #endif
                 slpManDeepSlpTimerStart(deepslpTimerID, AppNVMData.sleepTime*1000*60);
                 slpManDeepSlpTimerStart(deepslpTimerID, AppNVMData.sleepTime*1000*60);
                 UINT8 sleeptime_count=0;
                 UINT8 sleeptime_count=0;

+ 26 - 11
src/Signal.c

@@ -15,7 +15,6 @@ UINT16	COMOutTable[28]	=	{
 0x6C2,
 0x6C2,
 0x6C3,
 0x6C3,
 0x6C4,
 0x6C4,
-
 0x7C0,
 0x7C0,
 0x7C1,
 0x7C1,
 0x7C2,
 0x7C2,
@@ -52,15 +51,9 @@ UINT8	bmsSwVersion = 0xFF;
 UINT8	bmsHwVersion = 0xFF;
 UINT8	bmsHwVersion = 0xFF;
 UINT8	battMOSSwitchState = 0xFF;
 UINT8	battMOSSwitchState = 0xFF;
 UINT8	battHeatEnableState = 0xFF;
 UINT8	battHeatEnableState = 0xFF;
-UINT8	reservedSignal1 = 0xFF;
-UINT8	reservedSignal2 = 0xFF;
-UINT8	reservedSignal3 = 0xFF;
-UINT8	reservedSignal4 = 0xFF;
-UINT8	reservedSignal5 = 0xFF;
-UINT8	reservedSignal6 = 0xFF;
-UINT8	reservedSignal7 = 0xFF;
-UINT8	reservedSignal8 = 0xFF;
 
 
+
+UINT8   chargerConnectState = 0x00;
 //declear the UINT16 vars
 //declear the UINT16 vars
 UINT16	battCellU[28] = {0xFFFF};
 UINT16	battCellU[28] = {0xFFFF};
 UINT16	minCellVol = 0xFFFF;
 UINT16	minCellVol = 0xFFFF;
@@ -77,8 +70,9 @@ UINT8 Error_count=0;
 UINT32	battWarningState = 0xFFFFFFFF;
 UINT32	battWarningState = 0xFFFFFFFF;
 UINT32	nbSwVersion = 0xFFFFFFFF;
 UINT32	nbSwVersion = 0xFFFFFFFF;
 UINT32	battBalanceoInfo = 0xFFFFFFFF;
 UINT32	battBalanceoInfo = 0xFFFFFFFF;
-
-UINT32 Battdesigncap =0xFFFFFFFF;
+UINT32  BattRemainCap = 0x00;
+UINT32  Battdesigncap =0x00;
+UINT32  battProtectState =0x00; 
 //Tcp
 //Tcp
 UINT8 	TcpSendLen = 0;
 UINT8 	TcpSendLen = 0;
 
 
@@ -86,3 +80,24 @@ UINT16 ErrorNum[5]={0};
 
 
 osMutexId_t Error_Mutex = NULL;
 osMutexId_t Error_Mutex = NULL;
 
 
+#ifdef SOC_TEST
+UINT8 SOC1 = 100;
+UINT8 SOC2 = 100;
+UINT16 Data_33 = 0;
+UINT16 Data_34 = 0;
+UINT32 Data_35 = 0;
+UINT16 Data_37 = 0;
+UINT16 Data_38 = 0;
+UINT16 Data_39 = 0;
+UINT16 Data_3A = 0;
+UINT16 Data_3B = 0;
+UINT16 Data_3C = 0;
+UINT16 Data_3D = 0;
+UINT16 Data_3E = 0;
+UINT16 Data_3F = 0;
+UINT16 Data_40 = 0;
+UINT16 Data_41 = 0;
+UINT16 Data_42 = 0;
+UINT16 Data_43 = 0;
+INT16  Data_Current = 0;
+#endif

+ 63 - 28
src/TcpTask.c

@@ -83,10 +83,6 @@ static void TcpTask(void* arg)
 	{
 	{
 		TcpRecvHandle = osMessageQueueNew(2,sizeof(TcpipConnectionRecvDataInd*), NULL);
 		TcpRecvHandle = osMessageQueueNew(2,sizeof(TcpipConnectionRecvDataInd*), NULL);
 	}
 	}
-    if(Error_Mutex == NULL)
-    {
-        Error_Mutex = osMutexNew(NULL);
-    }
     osDelay(5000);//等待驻网延时5s
     osDelay(5000);//等待驻网延时5s
     while (true)
     while (true)
     {
     {
@@ -162,6 +158,7 @@ static void TcpTask(void* arg)
                         osDelay(5000);
                         osDelay(5000);
                         appSetCFUN(1);
                         appSetCFUN(1);
                         osDelay(5000);
                         osDelay(5000);
+                        sendQueueMsg(QMSG_ID_NW_IP_READY, 0);
                     }
                     }
                     break;
                     break;
                 case QMSG_ID_SOCK_SENDPKG:
                 case QMSG_ID_SOCK_SENDPKG:
@@ -295,20 +292,20 @@ static void TcpDataInfoAssembleSend()
     switch(WorkFlag)
     switch(WorkFlag)
     {
     {
         case 0x00:
         case 0x00:
-            BattSendFreq = AppDataInfo.BmsDisChrgInfoSendFreq/5;
-            GpsSendFreq = AppDataInfo.GpsChrgInfoSendFreq/5;
+            BattSendFreq = 30/5;
+            GpsSendFreq = 30/5;
             break;
             break;
         case 0x01:
         case 0x01:
-            GpsSendFreq = AppDataInfo.GpsDisChrgInfoSendFreq/5;
-            BattSendFreq = AppDataInfo.BmsDisChrgInfoSendFreq/5;
+            GpsSendFreq = 10/5;
+            BattSendFreq = 30/5;
             break;
             break;
         case 0x02:
         case 0x02:
-            BattSendFreq = AppDataInfo.BmsChrgInfoSendFreq/5;
-            GpsSendFreq = AppDataInfo.GpsChrgInfoSendFreq/5;
+            BattSendFreq = 10/5;
+            GpsSendFreq = 30/5;
             break;
             break;
         default:
         default:
-            BattSendFreq = AppDataInfo.BmsDisChrgInfoSendFreq/5;
-            GpsSendFreq = AppDataInfo.GpsChrgInfoSendFreq/5;
+            BattSendFreq = 30/5;
+            GpsSendFreq = 30/5;
             break;
             break;
     }    
     }    
     if(send_counter%BattSendFreq==0)
     if(send_counter%BattSendFreq==0)
@@ -577,7 +574,57 @@ static void TcpDataInfoAssembleSend()
             }
             }
         }
         }
     }
     }
-    if(send_counter==0)//发送本次文件中的调试信息
+    if(send_counter%12==0 && send_counter!=0)//发送调试信息,此处发送参数信息/60s一次
+    {
+        DebugMsgtoTcpType DebugMsgInfo;
+        UINT8 *SendBuffer = NULL;
+        UINT8 BufferLen = 0;
+        UINT8 rbuf[100];
+        sprintf((char *)rbuf,"%d,%x,%x,%d,%d,%d,%d,---%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x,%x",
+        Data_Current,BattRemainCap,battProtectState,SOC2,SOC1,battSOC,0,
+        Data_33,Data_34,Data_35,Data_37,Data_38,Data_39,Data_3A,Data_3B,Data_3C,Data_3D,Data_3E,Data_3F,Data_40,Data_41,Data_42,Data_43);//累计里程,剩余容量,保护状态,BMS-SOC,acc_soc,disp-soc,relay,
+        BufferLen  = strlen(rbuf);
+        SendBuffer = malloc(BufferLen+sizeof(DebugMsgInfo));
+        memcpy(SendBuffer+sizeof(DebugMsgInfo)-1, rbuf,BufferLen);
+        appGetSystemTimeUtcSync(&TimeStracture);
+        year=(TimeStracture.UTCtimer1&0xffff0000)>>16;
+        month=(TimeStracture.UTCtimer1&0xff00)>>8;
+        day=TimeStracture.UTCtimer1&0xff;
+        hour=(TimeStracture.UTCtimer2&0xff000000)>>24;
+        minute=(TimeStracture.UTCtimer2&0xff0000)>>16;
+        sec=(TimeStracture.UTCtimer2&0xff00)>>8;
+        UTCToBeijing((UTC8TimeType *)&UTC8TimeTcp,year,month,day,hour,minute,sec);
+        DataLen=sizeof(DebugMsgInfo.DebugInfo) + BufferLen;
+        DebugMsgInfo.startSymbol[0] = TCP_START_SYM1;
+	    DebugMsgInfo.startSymbol[1] = TCP_START_SYM2;
+	    DebugMsgInfo.cmdSymbol = TCP_CMD_SYM;
+	    DebugMsgInfo.ansSymbol = TCP_ANS_SYM;
+        memcpy(DebugMsgInfo.SN, AppNVMData.battSN,BATT_SN_LEN);
+        DebugMsgInfo.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
+	    DebugMsgInfo.dataLength[0] = (DataLen>>8) & 0xFF;
+	    DebugMsgInfo.dataLength[1] = DataLen & 0xFF;
+        DebugMsgInfo.DebugInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF;	//year
+        DebugMsgInfo.DebugInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;								//month
+        DebugMsgInfo.DebugInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;									//day
+        DebugMsgInfo.DebugInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;  						    //hour
+        DebugMsgInfo.DebugInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;						    //mins
+        DebugMsgInfo.DebugInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF;							//sec
+        DebugMsgInfo.DebugInfo.msgMark = DEBUGMSG;
+        DebugMsgInfo.DebugInfo.DebugLen[0] = BufferLen>>8;
+        DebugMsgInfo.DebugInfo.DebugLen[1] = BufferLen;
+        memcpy(SendBuffer,(UINT8 *)&DebugMsgInfo,sizeof(DebugMsgInfo)-1);
+        DebugMsgInfo.CRC = bcc_chk(SendBuffer, BufferLen+sizeof(DebugMsgInfo)-1);
+        memcpy(SendBuffer+BufferLen+sizeof(DebugMsgInfo)-1,&DebugMsgInfo.CRC,1);
+        len = tcpipConnectionSend(socContext.id, SendBuffer, BufferLen+sizeof(DebugMsgInfo), 0, 0, 0);
+        #ifdef USING_PRINTF1
+            printf("\nDebugData!-%d-%s\n",len,rbuf);
+            UINT8* p = SendBuffer;
+            for(i =0 ;i<BufferLen+sizeof(DebugMsgInfo);i++)
+                printf("%x ",*(p+i));
+        #endif
+        free(SendBuffer);
+    }
+    if(send_counter==0)//发送本次文件中的调试信息,此处发送文件信息
     {
     {
         DebugMsgtoTcpType DebugMsgInfo;
         DebugMsgtoTcpType DebugMsgInfo;
         UINT8 *SendBuffer = NULL;
         UINT8 *SendBuffer = NULL;
@@ -629,7 +676,7 @@ static void TcpDataInfoAssembleSend()
             printf("DebugMsgInfo!\n");
             printf("DebugMsgInfo!\n");
             UINT8* p = SendBuffer;
             UINT8* p = SendBuffer;
             for(i =0 ;i<BufferLen+sizeof(DebugMsgInfo);i++)
             for(i =0 ;i<BufferLen+sizeof(DebugMsgInfo);i++)
-                printf("%x ",*(p+i));
+                printf("%x",*(p+i));
         #endif
         #endif
         Debug_Del_Logfile();
         Debug_Del_Logfile();
         free(SendBuffer);
         free(SendBuffer);
@@ -687,7 +734,6 @@ static void TcpDataInfoRecvHandle()
                     }
                     }
                     else if(*(Ptr+30)==0x80)//远程锁定命令
                     else if(*(Ptr+30)==0x80)//远程锁定命令
                     {
                     {
-                        //osMutexAcquire(UartMutex, osWaitForever);
                         TcpCmdAnswer[3] = 0x01;
                         TcpCmdAnswer[3] = 0x01;
                         memcpy(&TcpCmdAnswer[4],(Ptr+4),BATT_SN_LEN);
                         memcpy(&TcpCmdAnswer[4],(Ptr+4),BATT_SN_LEN);
                         TcpCmdAnswer[21] = TCP_ENCPT_DISABLE;
                         TcpCmdAnswer[21] = TCP_ENCPT_DISABLE;
@@ -699,29 +745,18 @@ static void TcpDataInfoRecvHandle()
                         {
                         {
                             AppNVMData.appDataModify = TRUE;
                             AppNVMData.appDataModify = TRUE;
                             AppNVMData.isBattLocked = TRUE;
                             AppNVMData.isBattLocked = TRUE;
-                            UartWriteCmd.WriteCmd = 0x01;
-                            UartWriteCmd.Data[0] = 0x00;
-                            UartWriteCmd.Data[1] = 0x00;
-                            if(battWorkState ==0x00)
-                            {
-                                osMessageQueuePut(UartWriteCmdHandle,&UartWriteCmd,0,1000);
-                            }
                             tcpipConnectionSend(socContext.id,TcpCmdAnswer,31,0,0,0);
                             tcpipConnectionSend(socContext.id,TcpCmdAnswer,31,0,0,0);
                         }
                         }
-                        else                //0x02代表解锁
+                        else if(*(Ptr+31)==0x02)              //0x02代表解锁
                         {
                         {
                             AppNVMData.appDataModify = TRUE;
                             AppNVMData.appDataModify = TRUE;
                             AppNVMData.isBattLocked = FALSE;
                             AppNVMData.isBattLocked = FALSE;
-                            UartWriteCmd.WriteCmd = 0x01;
-                            UartWriteCmd.Data[0] = 0x00;
-                            UartWriteCmd.Data[1] = 0x03;
-                            osMessageQueuePut(UartWriteCmdHandle,&UartWriteCmd,0,1000);
                             tcpipConnectionSend(socContext.id,TcpCmdAnswer,31,0,0,0);
                             tcpipConnectionSend(socContext.id,TcpCmdAnswer,31,0,0,0);
                         }
                         }
-                        //osMutexRelease(UartMutex);
                         TcpService=0x00;
                         TcpService=0x00;
                         
                         
                     }
                     }
+
                     else
                     else
                     {
                     {
                         TcpCmdAnswer[3] = 0x0f;
                         TcpCmdAnswer[3] = 0x0f;

+ 170 - 40
src/UartTask.c

@@ -39,6 +39,7 @@ extern volatile BOOL Sleep_flag;
 extern AppNVMDataType AppNVMData;
 extern AppNVMDataType AppNVMData;
 extern AppDataBody AppDataInfo;
 extern AppDataBody AppDataInfo;
 extern UINT8 WorkFlag;
 extern UINT8 WorkFlag;
+extern UINT8 	UDSSwitch;
 //全局变量输出区
 //全局变量输出区
 BOOL UartBattInfoRecvFlag  = false;
 BOOL UartBattInfoRecvFlag  = false;
 QueueHandle_t UartWriteCmdHandle = NULL;
 QueueHandle_t UartWriteCmdHandle = NULL;
@@ -77,6 +78,11 @@ UINT16  encryptionAlgorithm (UINT16 plainText);
 UINT8  decryptionAlgorithm (UINT16 cipherText);
 UINT8  decryptionAlgorithm (UINT16 cipherText);
 UINT8 Uart_Encrypt_Send(void);
 UINT8 Uart_Encrypt_Send(void);
 UINT8 BmsErrorDecode(UINT32 battWarningState);
 UINT8 BmsErrorDecode(UINT32 battWarningState);
+
+#ifdef SOC_TEST
+void Uart_Data_recv_SOC_test(void);
+#endif
+
 //BMS升级函数声明
 //BMS升级函数声明
 UINT8 SP_BMS_Update_CheckSUM(UINT8* pSendData,UINT8 len);
 UINT8 SP_BMS_Update_CheckSUM(UINT8* pSendData,UINT8 len);
 void SP_BMS_Update_Service();
 void SP_BMS_Update_Service();
@@ -109,9 +115,12 @@ static void UartTask(void* arg)
     memset(&(UartReadMsg.UartFlag),0x00,sizeof(UartReadMsgType));
     memset(&(UartReadMsg.UartFlag),0x00,sizeof(UartReadMsgType));
     if(UartWriteCmdHandle == NULL)//Uart控制命令传输指针
     if(UartWriteCmdHandle == NULL)//Uart控制命令传输指针
 	{
 	{
-		UartWriteCmdHandle = osMessageQueueNew(3,sizeof(Uart_Write_Data_Type), NULL);
+		UartWriteCmdHandle = osMessageQueueNew(1,sizeof(Uart_Write_Data_Type), NULL);
 	}
 	}
     //上电起始控制区域
     //上电起始控制区域
+	UINT8 ret = 0x00;
+	UINT8 HeatSwitch = 0;
+
     while (1)
     while (1)
     {
     {
         switch (gProcess_Uart_Task)
         switch (gProcess_Uart_Task)
@@ -134,22 +143,28 @@ static void UartTask(void* arg)
                 if(Sleep_flag)
                 if(Sleep_flag)
                 {
                 {
                     PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_SLEEP);
                     PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_SLEEP);
+					break;
                 }
                 }
                 else if(Timer_count%10==0)
                 else if(Timer_count%10==0)
                 {
                 {
                     #ifdef USING_PRINTF1
                     #ifdef USING_PRINTF1
                         printf("[%d]Uart Timer 1s:%d,uartReadSuccessFlag:%d\n",__LINE__,Timer_count,uartReadSuccessFlag);
                         printf("[%d]Uart Timer 1s:%d,uartReadSuccessFlag:%d\n",__LINE__,Timer_count,uartReadSuccessFlag);
                     #endif
                     #endif
-                    if(osMessageQueueGet(UartWriteCmdHandle,&UartWriteData,0,0)==osOK)
+                    if(osMessageQueueGet(UartWriteCmdHandle,&UartWriteData,0,0)==osOK && uartReadSuccessFlag==TRUE)
                     {
                     {
-                        #ifdef USING_PRINTF1
-                            printf("[%d]UartWriteCmdHandle :%x\n",__LINE__,UartWriteData.WriteCmd);
+                        #ifdef USING_PRINTF
+                            printf("[%d]UartWriteCmdHandle :%x-%X%X\n",__LINE__,UartWriteData.WriteCmd,UartWriteData.Data[0],UartWriteData.Data[1]);
                         #endif
                         #endif
                         PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_WRITE);
                         PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_WRITE);
+						break;
                     }
                     }
                     else
                     else
-                        PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_READ);
+					{
+						PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_READ);
+						break;
+					}
                 }
                 }
+
 				if(UartReadMsg.Header[2]>0)
 				if(UartReadMsg.Header[2]>0)
 				{
 				{
 					uartReadSuccessFlag = true;
 					uartReadSuccessFlag = true;
@@ -180,31 +195,43 @@ static void UartTask(void* arg)
 					if(WorkFlag==0x00)
 					if(WorkFlag==0x00)
 					{
 					{
 						PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_UPDATE);
 						PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_UPDATE);
+						break;
 					}
 					}
-					
 				}
 				}
-				if(AppNVMData.isBattLocked==TRUE && ((UartReadMsg.data[(0x09+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+2)*2+1])>>1)&0x03!=0x00 && Timer_count%10==0)//try to lock
+				if(battWorkState ==0x00 && AppNVMData.isBattLocked==TRUE && ((UartReadMsg.data[(0x1B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2+1])&0x03)!=0x02)//try to lock lock the discharge 
 				{
 				{
+					#ifdef USING_PRINTF
+                        printf("[%d]try to lock:%X-%X\n",__LINE__,AppNVMData.isBattLocked,(UartReadMsg.data[(0x1B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2+1])&0x03);
+                    #endif
 					UartWriteData.WriteCmd = 0x01;
 					UartWriteData.WriteCmd = 0x01;
-					UartWriteData.Data[0] = 0x00;
-					UartWriteData.Data[1] = 0x00;
-					osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,1000);
-					PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_READ);
+					UartWriteData.Data[0] = 0x00|(UartReadMsg.data[(0x1B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2]);
+					UartWriteData.Data[1] = 0x02;
+					osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,0);
 				}
 				}
-				else if (AppNVMData.isBattLocked==FALSE && ((UartReadMsg.data[(0x09+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+2)*2+1])>>1)&0x03==0x00 && Timer_count%10==0 ) // try to unlock
+				else if (battWorkState ==0x00 && AppNVMData.isBattLocked==FALSE && ((UartReadMsg.data[(0x1B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2+1])&0x03)!=0x03) // try to unlock
 				{
 				{
+					#ifdef USING_PRINTF
+                        printf("[%d]try to unlock:%X-%X\n",__LINE__,AppNVMData.isBattLocked,(UartReadMsg.data[(0x1B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2+1])&0x03);
+                    #endif
 					UartWriteData.WriteCmd = 0x01;
 					UartWriteData.WriteCmd = 0x01;
-					UartWriteData.Data[0] = 0x00;
+					UartWriteData.Data[0] = 0x00|(UartReadMsg.data[(0x1B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2]);
 					UartWriteData.Data[1] = 0x03;
 					UartWriteData.Data[1] = 0x03;
-					osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,1000);
-					PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_READ);
+					osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,0);
+				}
+
+				if(BattHeaterSwitch(&HeatSwitch)==TRUE)
+				{
+					UartWriteData.WriteCmd = 0x02;
+					UartWriteData.Data[0] = 0x00;
+					UartWriteData.Data[1] = HeatSwitch&0xFF;
+					osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,0);
 				}
 				}
                 break;
                 break;
             }
             }
             case PROCESS_UART_STATE_READ:
             case PROCESS_UART_STATE_READ:
             {
             {
                 UINT16 CRC_chk_buffer;
                 UINT16 CRC_chk_buffer;
-                Reg_Num = 0x21+BATT_CELL_VOL_NUM+BATT_TEMP_NUM + 2;//按照协议里面的0x21+X+N的结束地址
+                Reg_Num = 0x21+BATT_CELL_VOL_NUM+BATT_TEMP_NUM + BATT_OTHER_TEMP_NUM;//按照协议里面的0x21+X+N的结束地址
                 Uart_Read_Msg.Bms_Address = BMS_ADDRESS_CODE;
                 Uart_Read_Msg.Bms_Address = BMS_ADDRESS_CODE;
                 Uart_Read_Msg.Bms_Funcode = UART_READ_CODE;
                 Uart_Read_Msg.Bms_Funcode = UART_READ_CODE;
                 Uart_Read_Msg.Reg_Begin_H = 0x00;
                 Uart_Read_Msg.Reg_Begin_H = 0x00;
@@ -238,19 +265,22 @@ static void UartTask(void* arg)
                     BattChrgEndFlag=FALSE;
                     BattChrgEndFlag=FALSE;
                 }
                 }
 				#ifdef USING_PRINTF1
 				#ifdef USING_PRINTF1
-					printf("\nUart_Recv_buffer:  ");
-					for(int i=0;i<Uart_Recv_LEN;i++)
-					{
-						printf("%x ",*((UINT8 *)&UartReadMsg.Header+i));
+                    printf("[%d]lock:%X,permit:%X,Mos:%x\n",__LINE__,AppNVMData.isBattLocked,(UartReadMsg.data[(0x1B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2+1])&0x03,((UartReadMsg.data[(0x09+BATT_CELL_VOL_NUM+BATT_OTHER_TEMP_NUM)*2+1])>>1)&0x03);
+                #endif
+				//SOC问题测试
+				#ifdef SOC_TEST
+					if(bmsSwVersion==8)
+					{	
+						Uart_Data_recv_SOC_test();
 					}
 					}
-					printf("\n");
 				#endif
 				#endif
                 break;
                 break;
             }
             }
             case PROCESS_UART_STATE_WRITE:
             case PROCESS_UART_STATE_WRITE:
             {
             {
-                Uart_WriteCmd_func(UartWriteData);
-                PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
+                ret = Uart_WriteCmd_func(UartWriteData);
+				osDelay(500);
+                PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_READ);
                 break;
                 break;
             }
             }
 			case PROCESS_UART_STATE_UPDATE:
 			case PROCESS_UART_STATE_UPDATE:
@@ -343,12 +373,15 @@ static BOOL uartBattInfoDecode(UINT8* dataPtr)
 	battI = Batt_current*AppDataInfo.BattCurrentNegFlag + 0x2710;
 	battI = Batt_current*AppDataInfo.BattCurrentNegFlag + 0x2710;
     //bit0 ~ bit31 represent cell0 ~ cell31
     //bit0 ~ bit31 represent cell0 ~ cell31
     battBalanceoInfo  = dataPtr[(0x06+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1] | (dataPtr[(0x06+BATT_CELL_VOL_NUM+TEMP_NUM)*2] <<8) + (dataPtr[(0x07+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]<<16) | (dataPtr[(0x07+BATT_CELL_VOL_NUM+TEMP_NUM)*2] <<24);
     battBalanceoInfo  = dataPtr[(0x06+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1] | (dataPtr[(0x06+BATT_CELL_VOL_NUM+TEMP_NUM)*2] <<8) + (dataPtr[(0x07+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]<<16) | (dataPtr[(0x07+BATT_CELL_VOL_NUM+TEMP_NUM)*2] <<24);
-
+	chargerConnectState = (dataPtr[(0x03+BATT_CELL_VOL_NUM)*2+1]>>2)&0x01;//充电器连接状态,0表示未连接,1表示已连接
     bmsHwVersion = dataPtr[(0x08+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]; 
     bmsHwVersion = dataPtr[(0x08+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]; 
     bmsSwVersion = dataPtr[(0x08+BATT_CELL_VOL_NUM+TEMP_NUM)*2];    
     bmsSwVersion = dataPtr[(0x08+BATT_CELL_VOL_NUM+TEMP_NUM)*2];    
 
 
     temp = ((dataPtr[(0x09+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1])>>1)&0x03;    
     temp = ((dataPtr[(0x09+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1])>>1)&0x03;    
     battMOSSwitchState = ((temp&0x01)<<1)|((temp&0x02)>>1);	
     battMOSSwitchState = ((temp&0x01)<<1)|((temp&0x02)>>1);	
+	#ifdef USING_PRINTF1
+		printf("[%d]battMOSSwitchState :%x\n",__LINE__,battMOSSwitchState);
+	#endif
     if(AppNVMData.isBattLocked==TRUE)
     if(AppNVMData.isBattLocked==TRUE)
     {
     {
         battMOSSwitchState = battMOSSwitchState |(0x01<<2);
         battMOSSwitchState = battMOSSwitchState |(0x01<<2);
@@ -358,14 +391,61 @@ static BOOL uartBattInfoDecode(UINT8* dataPtr)
         battMOSSwitchState = battMOSSwitchState |(0x00<<2);
         battMOSSwitchState = battMOSSwitchState |(0x00<<2);
     }
     }
 	battWarningState = (dataPtr[(0x09+BATT_CELL_VOL_NUM+TEMP_NUM)*2+0]<<16) | (dataPtr[(0x0A+BATT_CELL_VOL_NUM+TEMP_NUM)*2+0] << 8) |(dataPtr[(0x0A+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]);
 	battWarningState = (dataPtr[(0x09+BATT_CELL_VOL_NUM+TEMP_NUM)*2+0]<<16) | (dataPtr[(0x0A+BATT_CELL_VOL_NUM+TEMP_NUM)*2+0] << 8) |(dataPtr[(0x0A+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]);
-    battSOC = dataPtr[(0x0B+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1];
+    battSOC = dataPtr[(0x0B+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1];	
     battSOH = dataPtr[(0x0C+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1];
     battSOH = dataPtr[(0x0C+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1];
 	Battdesigncap = (dataPtr[(0x0E+BATT_CELL_VOL_NUM+TEMP_NUM)*2])<<24|(dataPtr[(0x0E+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1])<<16|(dataPtr[(0x0F+BATT_CELL_VOL_NUM+TEMP_NUM)*2])<<8|(dataPtr[(0x0F+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]);
 	Battdesigncap = (dataPtr[(0x0E+BATT_CELL_VOL_NUM+TEMP_NUM)*2])<<24|(dataPtr[(0x0E+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1])<<16|(dataPtr[(0x0F+BATT_CELL_VOL_NUM+TEMP_NUM)*2])<<8|(dataPtr[(0x0F+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]);
+	BattRemainCap = (dataPtr[(0x12+BATT_CELL_VOL_NUM+TEMP_NUM)*2])<<24|(dataPtr[(0x12+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1])<<16|(dataPtr[(0x13+BATT_CELL_VOL_NUM+TEMP_NUM)*2])<<8|(dataPtr[(0x13+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]);
+	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]);
 	battPackVol =((dataPtr[(0x18+BATT_CELL_VOL_NUM+TEMP_NUM)*2])<<8|(dataPtr[(0x18+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]))/10;  //uint 100mV
 	battPackVol =((dataPtr[(0x18+BATT_CELL_VOL_NUM+TEMP_NUM)*2])<<8|(dataPtr[(0x18+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]))/10;  //uint 100mV
 	maxCellVol = (dataPtr[(0x19+BATT_CELL_VOL_NUM+TEMP_NUM)*2] << 8) | dataPtr[(0x19+BATT_CELL_VOL_NUM+TEMP_NUM)*2 + 1];
 	maxCellVol = (dataPtr[(0x19+BATT_CELL_VOL_NUM+TEMP_NUM)*2] << 8) | dataPtr[(0x19+BATT_CELL_VOL_NUM+TEMP_NUM)*2 + 1];
 	minCellVol = (dataPtr[(0x1A+BATT_CELL_VOL_NUM+TEMP_NUM)*2] << 8) | dataPtr[(0x1A+BATT_CELL_VOL_NUM+TEMP_NUM)*2 + 1];
 	minCellVol = (dataPtr[(0x1A+BATT_CELL_VOL_NUM+TEMP_NUM)*2] << 8) | dataPtr[(0x1A+BATT_CELL_VOL_NUM+TEMP_NUM)*2 + 1];
+	// RelayControlState  = (dataPtr[(0x1B+BATT_CELL_VOL_NUM+TEMP_NUM)*2])&0x80;
     battHeatEnableState = dataPtr[(0x1C+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]&0x01;
     battHeatEnableState = dataPtr[(0x1C+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]&0x01;
 
 
+	//SOC问题紧急修复
+	#ifdef SOC_TEST
+	Data_Current = (dataPtr[(0x02+BATT_CELL_VOL_NUM)*2]<<8)|(dataPtr[(0x02+BATT_CELL_VOL_NUM)*2+1]);
+	static UINT8 Soc_change_flag = 0;//0-BMS原始值,1-计算值
+	if((battI>10200U)||(battWorkState==2))//放电电流超过20A,使用上一时刻值,//如果有充电,使用计算值,最大不超过100
+	{
+		SOC1 = max((battPackVol*45-27000)/100,SOC1);
+		SOC1 = min(100,SOC1);
+	}
+	else
+	{
+		SOC1 = min((battPackVol*45-27000)/100,SOC1);
+	}
+	SOC2 = battSOC;
+	if(Soc_change_flag == 0)//使用原始值
+	{
+		if((SOC2 - SOC1>=10)&&(battPackVol>500)&&(battPackVol<900))
+		{
+			Soc_change_flag = 1;
+		}		
+	}
+	else
+	{
+		if((SOC2 - SOC1<5)||(battPackVol<500)||(battPackVol>900))
+		{
+			Soc_change_flag = 0;
+		}
+	}
+	if(Soc_change_flag==0)
+	{
+		battSOC = SOC2;
+	}
+	else
+	{
+		battSOC = SOC1;
+		if(osOK==osMutexAcquire(Error_Mutex, 100))
+		{
+			UINT8 ErrorNumTemp = 238;
+			PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
+		}
+		osMutexRelease(Error_Mutex);
+	}
+	#endif
+    //SOC紧急修复
 	maxCellTemp = 0x00;
 	maxCellTemp = 0x00;
 	minCellTemp = 0xFF;
 	minCellTemp = 0xFF;
 	for(i=0;i<BATT_TEMP_NUM;i++)
 	for(i=0;i<BATT_TEMP_NUM;i++)
@@ -378,9 +458,50 @@ static BOOL uartBattInfoDecode(UINT8* dataPtr)
 	BmsErrorDecode(battWarningState);
 	BmsErrorDecode(battWarningState);
     return true;
     return true;
 }
 }
+#ifdef SOC_TEST
+void Uart_Data_recv_SOC_test(void)
+{
 
 
-
-
+	UINT16 CRC_chk_buffer;
+	Uart_Read_Msg_Type Uart_Read_Msg;
+	memset(&(Uart_Read_Msg),0x00,sizeof(Uart_Read_Msg_Type));
+	UartReadMsgType UartReadMsg;
+	memset(&(UartReadMsg.UartFlag),0x00,sizeof(UartReadMsgType));
+	UINT8 Reg = 0,Uart_Uds_LEN = 0,Uart_Recv_LEN;
+	Reg = 0x33+BATT_CELL_VOL_NUM+BATT_TEMP_NUM + BATT_OTHER_TEMP_NUM;
+	Uart_Read_Msg.Bms_Address = BMS_ADDRESS_CODE;
+	Uart_Read_Msg.Bms_Funcode = UART_READ_CODE;
+	Uart_Read_Msg.Reg_Begin_H = Reg>>8;
+	Uart_Read_Msg.Reg_Begin_L= Reg;
+	Uart_Read_Msg.Reg_Num_H = 0;
+	Uart_Read_Msg.Reg_Num_L = 16;
+	Uart_Uds_LEN = 17*2;
+	memset(UartReadMsg.Header,0x00,Uart_Uds_LEN);
+	CRC_chk_buffer = crc_chk((UINT8 *)&Uart_Read_Msg,6);
+	Uart_Read_Msg.CRC_L = CRC_chk_buffer;
+	Uart_Read_Msg.CRC_H = CRC_chk_buffer>>8;
+	Uart_Recv_LEN = Uart_DataRecv_func(Uart_Read_Msg,(UINT8*)(UartReadMsg.Header));
+	if(Uart_Recv_LEN>0)
+	{
+		Data_33 = (UartReadMsg.data[0]<<8|UartReadMsg.data[1]);
+		Data_34 = (UartReadMsg.data[2]<<8|UartReadMsg.data[3]);
+		Data_35 = (UartReadMsg.data[4]<<24|UartReadMsg.data[5]<<16|UartReadMsg.data[6]<<8|UartReadMsg.data[7]);
+		Data_37 = (UartReadMsg.data[8]<<8|UartReadMsg.data[9]);
+		Data_38 = (UartReadMsg.data[10]<<8|UartReadMsg.data[11]);
+		Data_39 = (UartReadMsg.data[12]<<8|UartReadMsg.data[13]);
+		Data_3A = (UartReadMsg.data[14]<<8|UartReadMsg.data[15]);
+		Data_3B = (UartReadMsg.data[16]<<8|UartReadMsg.data[17]);
+		Data_3C = (UartReadMsg.data[18]<<8|UartReadMsg.data[19]);
+		Data_3D = (UartReadMsg.data[20]<<8|UartReadMsg.data[21]);
+		Data_3E = (UartReadMsg.data[22]<<8|UartReadMsg.data[23]);
+		Data_3F = (UartReadMsg.data[24]<<8|UartReadMsg.data[25]);
+		Data_40 = (UartReadMsg.data[26]<<8|UartReadMsg.data[27]);
+		Data_41 = (UartReadMsg.data[28]<<8|UartReadMsg.data[29]);
+		Data_42 = (UartReadMsg.data[30]<<8|UartReadMsg.data[31]);
+		Data_43 = (UartReadMsg.data[32]<<8|UartReadMsg.data[33]);
+	}
+}
+#endif
 
 
 
 
 
 
@@ -446,6 +567,9 @@ UINT8 Uart_WriteCmd_func(Uart_Write_Data_Type UartWriteData)
     UINT16 CRC_chk_buffer;
     UINT16 CRC_chk_buffer;
     UINT8 timeout = 0x00;
     UINT8 timeout = 0x00;
     UINT8 Uart_Recv_Buffer[8];
     UINT8 Uart_Recv_Buffer[8];
+	#ifdef USING_PRINTF
+		printf("\nUart_WriteCmd_func: %x ",UartWriteData.WriteCmd);
+	#endif
     switch (UartWriteData.WriteCmd)
     switch (UartWriteData.WriteCmd)
     {
     {
         case 0x01://是否锁定
         case 0x01://是否锁定
@@ -636,29 +760,31 @@ UINT8 Uart_DataRecv_func(Uart_Read_Msg_Type Uart_Read_Msg_Fun,UINT8* Uart_Recv_B
 */
 */
 BOOL BattHeaterSwitch(UINT8* heaterSwitch)
 BOOL BattHeaterSwitch(UINT8* heaterSwitch)
 {
 {
-	BOOL isNeedtoSwitch = FALSE;
-	
-	UINT8 i =0;	
-	UINT8 currentSwitchState = 0;
-	//get the current switch state and the cell temp
-	currentSwitchState = battMOSSwitchState & 0x01;
-	if(currentSwitchState==0) 	//当前状态为关闭,判断是否应该开启
+ BOOL isNeedtoSwitch = FALSE;
+ 
+ UINT8 i =0; 
+ UINT8 currentSwitchState = 0;
+
+ //get the current switch state and the cell temp
+ currentSwitchState = battHeatEnableState & 0x01;
+
+	if(currentSwitchState==0)  //当前状态为关闭,判断是否应该开启
 	{
 	{
-		if(minCellTemp<=5+40 && maxCellTemp<25+40 && battSOC>=12)//温度偏移为40 
+		if((chargerConnectState == 1 && minCellTemp<5+40 && minCellTemp>=-29+40 && maxCellTemp<25+40)||(chargerConnectState==0 && minCellTemp<5+40 && minCellTemp>=-29+40 && battSOC>=10 && (((battProtectState>> 21)&0x01) == 0)))//温度偏移为40 
 		{
 		{
 			*heaterSwitch = 1;
 			*heaterSwitch = 1;
 			isNeedtoSwitch = true;
 			isNeedtoSwitch = true;
 		}
 		}
 	}
 	}
-	else  						//当前状态为开启,判断是否应该关闭
+	else        //当前状态为开启,判断是否应该关闭
 	{
 	{
-		if(minCellTemp>10+40 || maxCellTemp>30+40 || battSOC<10)
+		if((minCellTemp>=10+40 || maxCellTemp>=30+40)||(chargerConnectState == 0 && minCellTemp<5+40 && minCellTemp>=-29+40 && battSOC<5))
 		{
 		{
 			*heaterSwitch = 0;
 			*heaterSwitch = 0;
 			isNeedtoSwitch= true;
 			isNeedtoSwitch= true;
 		}
 		}
 	}
 	}
-	return isNeedtoSwitch;
+ return isNeedtoSwitch;
 }
 }
 
 
 void battSOCDisplay()
 void battSOCDisplay()
@@ -870,8 +996,12 @@ void battErrorStateDisplay()
 	{	
 	{	
 	
 	
 		errorLightTimer++;
 		errorLightTimer++;
-
-		if(battWarningState != 0)
+		if(battWorkState  == 0x02)  //充电模式下,如果只有“SOC低故障”,那么就不显示故障灯   zhengchao20210713 add
+		{
+			if((((battWarningState >> 10) & 0x01) == 0x01) &&  ((battWarningState & 0xFFFFFBFF) == 0x00))
+				return;
+		}
+		if(battWarningState != 0 )
 		{
 		{
 			if(errorLightTimer<(UINT8)(errorLEDFlashPeriod*errorDutyRatio)) 
 			if(errorLightTimer<(UINT8)(errorLEDFlashPeriod*errorDutyRatio)) 
 			{	
 			{	

+ 18 - 19
src/hal_module_adapter.c

@@ -1477,18 +1477,17 @@ void GsensorTriggerEvent(UINT32 event ,UINT32 data)
 static INT32 	I2CEvtProcess(uint32_t evt)
 static INT32 	I2CEvtProcess(uint32_t evt)
 {
 {
     INT32 ret;
     INT32 ret;
-#if SL_SC7A20_16BIT_8BIT
-    INT16 xyzData[7];
-#else
-    INT8 xyzData[7];
-#endif
+	#if SL_SC7A20_16BIT_8BIT
+		INT16 xyzData[7];
+	#else
+		INT8 xyzData[7];
+	#endif
     HAL_I2C_RecvControl(true);
     HAL_I2C_RecvControl(true);
 
 
     if(evt & I2C_INT1_REQ_BITMAP)
     if(evt & I2C_INT1_REQ_BITMAP)
     {
     {
 
 
     }
     }
-
     if(evt & I2C_INT2_REQ_BITMAP)
     if(evt & I2C_INT2_REQ_BITMAP)
     {
     {
 	SL_SC7A20_Read_XYZ_Data(xyzData);
 	SL_SC7A20_Read_XYZ_Data(xyzData);
@@ -1509,18 +1508,18 @@ static void HAL_I2C_RecvTaskEntry(void)
 
 
  		EC_ASSERT(flag == I2C_RECV_CONTROL_FLAG, flag, 0, 0);
  		EC_ASSERT(flag == I2C_RECV_CONTROL_FLAG, flag, 0, 0);
 
 
-		status = osMessageQueueGet(i2c_recv_msgqueue, &msg, 0 , osWaitForever);
+		status = osMessageQueueGet(i2c_recv_msgqueue, &msg, 0 , 1000);
 		if(status == osOK)
 		if(status == osOK)
 		{
 		{
 
 
-		      mask = SaveAndSetIRQMask();
+		    mask = SaveAndSetIRQMask();
 			//handle data
 			//handle data
-			//I2CEvtProcess(msg.event);
-#ifdef USING_PRINTF
-			//printf("[%d]i2c recv event\r\n",__LINE__);
-#else				
-    			ECOMM_TRACE(UNILOG_PLA_DRIVER, I2C_GSENSOR_D, P_INFO, 0, "i2c recv event");
-#endif
+			I2CEvtProcess(msg.event);
+			#ifdef USING_PRINTF
+				printf("[%d]i2c recv event\r\n",__LINE__);
+			#else				
+				ECOMM_TRACE(UNILOG_PLA_DRIVER, I2C_GSENSOR_D, P_INFO, 0, "i2c recv event");
+			#endif
 			RestoreIRQMask(mask);  
 			RestoreIRQMask(mask);  
 		}
 		}
 	}
 	}
@@ -1658,11 +1657,11 @@ void GsensorI2CHandler(ARM_I2C_SignalEvent_t cb_event)
      i2cDrvInstance->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_STANDARD);
      i2cDrvInstance->Control(ARM_I2C_BUS_SPEED, ARM_I2C_BUS_SPEED_STANDARD);
      i2cDrvInstance->Control(ARM_I2C_BUS_CLEAR, 0);
      i2cDrvInstance->Control(ARM_I2C_BUS_CLEAR, 0);
      HAL_I2C_CreateRecvTaskAndQueue();	 
      HAL_I2C_CreateRecvTaskAndQueue();	 
-#ifdef USING_PRINTF
-   //printf("[%d] i2c config ok\r\n",__LINE__);
-#else	 
-     ECOMM_TRACE(UNILOG_PLA_DRIVER, I2C_GSENSOR_I, P_INFO, 0, "i2c config ok");
-#endif
+	#ifdef USING_PRINTF
+		printf("[%d] i2c config ok\r\n",__LINE__);
+	#else	 
+		ECOMM_TRACE(UNILOG_PLA_DRIVER, I2C_GSENSOR_I, P_INFO, 0, "i2c config ok");
+	#endif
 }
 }
 
 
 /**
 /**

+ 14 - 16
src/sensor.c

@@ -278,13 +278,13 @@ INT8  SL_SC7A20_INT_Config(void)
 
 
     //HPF SET
     //HPF SET
   //  GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg); 
   //  GSENSOR_ReadReg(SL_SC7A20_CTRL_REG2,1, &SL_Read_Reg); 
-    SL_Read_Reg=0xcf;//SL_Read_Reg|0x81;//Normal HP , HPF TO AOI1 
+    SL_Read_Reg=0x00;//SL_Read_Reg|0x81;//Normal HP , HPF TO AOI1 
     GSENSOR_WriteReg(SL_SC7A20_CTRL_REG2, SL_Read_Reg);
     GSENSOR_WriteReg(SL_SC7A20_CTRL_REG2, SL_Read_Reg);
     
     
     //�ж���ֵ����
     //�ж���ֵ����
     GSENSOR_WriteReg(SL_SC7A20_INT1_THS, SL_SC7A20_INT_THS_20PERCENT);	
     GSENSOR_WriteReg(SL_SC7A20_INT1_THS, SL_SC7A20_INT_THS_20PERCENT);	
     //������ֵ����ʱ�䴥���ж�
     //������ֵ����ʱ�䴥���ж�
-    GSENSOR_WriteReg(SL_SC7A20_INT1_DURATION, SL_SC7A20_INT_DURATION_30CLK);
+    GSENSOR_WriteReg(SL_SC7A20_INT1_DURATION, SL_SC7A20_INT_DURATION_10CLK);
         
         
     //AOI1 TO INT1
     //AOI1 TO INT1
    // GSENSOR_ReadReg(SL_SC7A20_CTRL_REG3,1, &SL_Read_Reg);
    // GSENSOR_ReadReg(SL_SC7A20_CTRL_REG3,1, &SL_Read_Reg);
@@ -313,9 +313,9 @@ INT8  SL_SC7A20_INT_Config(void)
 //    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG2, SL_Read_Reg);
 //    GSENSOR_WriteReg(SL_SC7A20_CTRL_REG2, SL_Read_Reg);
 
 
     //�ж���ֵ����
     //�ж���ֵ����
-    GSENSOR_WriteReg(SL_SC7A20_INT2_THS, SL_SC7A20_INT_THS_5PERCENT);	
+    GSENSOR_WriteReg(SL_SC7A20_INT2_THS, SL_SC7A20_INT_THS_20PERCENT);	
     //������ֵ����ʱ�䴥���ж�
     //������ֵ����ʱ�䴥���ж�
-    GSENSOR_WriteReg(SL_SC7A20_INT2_DURATION, SL_SC7A20_INT_DURATION_2CLK);
+    GSENSOR_WriteReg(SL_SC7A20_INT2_DURATION, SL_SC7A20_INT_DURATION_10CLK);
     
     
     //AOI2 TO INT2
     //AOI2 TO INT2
     GSENSOR_ReadReg(SL_SC7A20_CTRL_REG6,1, &SL_Read_Reg);
     GSENSOR_ReadReg(SL_SC7A20_CTRL_REG6,1, &SL_Read_Reg);
@@ -501,7 +501,6 @@ void  SL_SC7A20_Reg_read_all(void)
 		GSENSOR_ReadReg(adr,1, &SL_Read_Reg);
 		GSENSOR_ReadReg(adr,1, &SL_Read_Reg);
 		printf("%#x = %#x\r\n",adr,SL_Read_Reg);	
 		printf("%#x = %#x\r\n",adr,SL_Read_Reg);	
 	}
 	}
-	
     printf("SL_SC7A20_Reg_readall --------\r\n");	
     printf("SL_SC7A20_Reg_readall --------\r\n");	
 }
 }
 
 
@@ -559,23 +558,22 @@ INT8  SL_SC7A20_Read_XYZ_Data(INT8 *SL_SC7A20_Data_XYZ_Buf)
 INT8  SL_SC7A20_Read_XYZ_Data(INT16 *SL_SC7A20_Data_XYZ_Buf)
 INT8  SL_SC7A20_Read_XYZ_Data(INT16 *SL_SC7A20_Data_XYZ_Buf)
 {
 {
     UINT8 SL_Read_Buf[7];
     UINT8 SL_Read_Buf[7];
-    
     GSENSOR_ReadReg(SL_SC7A20_STATUS_REG,1, &SL_Read_Buf[0]);
     GSENSOR_ReadReg(SL_SC7A20_STATUS_REG,1, &SL_Read_Buf[0]);
-    #ifdef USING_PRINTF	
-		printf("SL_SC7A20_STATUS_REG = %#x\r\n",SL_Read_Buf[0]);
-	#endif
     if((SL_Read_Buf[0]&0x0f)==0x0f)
     if((SL_Read_Buf[0]&0x0f)==0x0f)
     {
     {
-        GSENSOR_ReadReg(SL_SC7A20_DATA_OUT,6, &SL_Read_Buf[1]);
-        #ifdef USING_PRINTF	
-			printf("SL_SC7A20_DATA_OUT22 = %#x\r\n",SL_Read_Buf[1]);
-		#endif
+        for (UINT8 i = 1; i < 7; i++)
+        {
+            GSENSOR_ReadReg(SL_SC7A20_STATUS_REG+i,1, &SL_Read_Buf[i]);
+        }
         SL_SC7A20_Data_XYZ_Buf[0]=(INT16)((SL_Read_Buf[2]<<8) + SL_Read_Buf[1]);
         SL_SC7A20_Data_XYZ_Buf[0]=(INT16)((SL_Read_Buf[2]<<8) + SL_Read_Buf[1]);
         SL_SC7A20_Data_XYZ_Buf[1]=(INT16)((SL_Read_Buf[4]<<8) + SL_Read_Buf[3]);
         SL_SC7A20_Data_XYZ_Buf[1]=(INT16)((SL_Read_Buf[4]<<8) + SL_Read_Buf[3]);
         SL_SC7A20_Data_XYZ_Buf[2]=(INT16)((SL_Read_Buf[6]<<8) + SL_Read_Buf[5]);
         SL_SC7A20_Data_XYZ_Buf[2]=(INT16)((SL_Read_Buf[6]<<8) + SL_Read_Buf[5]);
-        #ifdef USING_PRINTF	
-			printf("SL_SC7A20_DATA_OUT BUF:X = %d,Y = %d,Z = %d\r\n",SL_SC7A20_Data_XYZ_Buf[0],SL_SC7A20_Data_XYZ_Buf[1],SL_SC7A20_Data_XYZ_Buf[2]);
-		#endif
+        SL_SC7A20_Data_XYZ_Buf[0] = SL_SC7A20_Data_XYZ_Buf[0]>>4;
+        SL_SC7A20_Data_XYZ_Buf[1] = SL_SC7A20_Data_XYZ_Buf[1]>>4;
+        SL_SC7A20_Data_XYZ_Buf[2] = SL_SC7A20_Data_XYZ_Buf[2]>>4;
+        SL_SC7A20_Data_XYZ_Buf[0] = SL_SC7A20_Data_XYZ_Buf[0]*2;
+        SL_SC7A20_Data_XYZ_Buf[1] = SL_SC7A20_Data_XYZ_Buf[1]*2;
+        SL_SC7A20_Data_XYZ_Buf[2] = SL_SC7A20_Data_XYZ_Buf[2]*2;
         return  1;
         return  1;
     }
     }
     else
     else