Browse Source

改动点:1.Uart解码单独进行,2.CAN协议进行了定义

CHENJIE-PC\QiXiang_CHENJIE 3 years ago
parent
commit
6d033124f1
18 changed files with 1070 additions and 410 deletions
  1. 4 2
      ARMCC/Makefile
  2. 2 0
      inc/CANEncode.h
  3. 1 0
      inc/CANTask.h
  4. 1 1
      inc/MainTask.h
  5. 53 0
      inc/Signal.h
  6. 1 1
      inc/TcpTask.h
  7. 1 2
      inc/UartTask.h
  8. 1 1
      inc/app.h
  9. 234 0
      src/CANEncode.c
  10. 131 16
      src/CANTask.c
  11. 1 1
      src/GpsTask.c
  12. 1 1
      src/MainTask.c
  13. 83 0
      src/Signal.c
  14. 60 75
      src/TcpTask.c
  15. 105 79
      src/UDSService.c
  16. 385 230
      src/UartTask.c
  17. 2 0
      src/bsp_custom.c
  18. 4 1
      src/hal_module_adapter.c

+ 4 - 2
ARMCC/Makefile

@@ -23,8 +23,10 @@ obj-y             += PLAT/project/$(TARGET)/apps/qx_app/src/app.o \
 					PLAT/project/$(TARGET)/apps/qx_app/src/TcpTask.o  \
 					PLAT/project/$(TARGET)/apps/qx_app/src/GpsTask.o \
 					PLAT/project/$(TARGET)/apps/qx_app/src/CANTask.o \
-					PLAT/project/$(TARGET)/apps/qx_app/src/UDSService.o \
-					PLAT/project/$(TARGET)/apps/qx_app/src/Fota.o \
+					PLAT/project/$(TARGET)/apps/qx_app/src/UDSService.o\
+					PLAT/project/$(TARGET)/apps/qx_app/src/Fota.o\
+					PLAT/project/$(TARGET)/apps/qx_app/src/Signal.o\
+					PLAT/project/$(TARGET)/apps/qx_app/src/CANEncode.o\
 					PLAT/project/$(TARGET)/apps/qx_app/src/sensor.o
 
 include $(TOP)/PLAT/tools/scripts/Makefile.rules

+ 2 - 0
inc/CANEncode.h

@@ -0,0 +1,2 @@
+#include 	 "commontypedef.h"
+extern void CANEncodeFunction(UINT32 ID,UINT8* rawData);

+ 1 - 0
inc/CANTask.h

@@ -19,6 +19,7 @@ typedef enum
 
 void CANTaskInit(void* arg);
 static void Can_Receive(void);
+void CanMsgTx1000ms(void);
 
 
 

+ 1 - 1
inc/MainTask.h

@@ -9,7 +9,7 @@
 //全局变量
 #include "app.h"
 extern UINT32 Timer_count;//每100ms加1
-extern volatile bool Sleep_flag;//睡眠标志位
+extern volatile BOOL Sleep_flag;//睡眠标志位
 extern AppNVMDataType AppNVMData;
 extern AppDataBody AppDataInfo;
 /*---------------------------------------------------------------------------*/

+ 53 - 0
inc/Signal.h

@@ -0,0 +1,53 @@
+#include "commontypedef.h"
+
+extern	UINT32	COMOutTable[28];
+//declear the UINT8 vars
+extern	UINT8	battCellTemp[8];
+extern	UINT8	MOSTemp;
+extern	UINT8	packTemp;
+extern	UINT8	fastChargeTemp;
+extern	UINT8	normalChargeTemp;
+extern	UINT8	heatTemp1;
+extern	UINT8	heatTemp2;
+extern	UINT8	nbReservedTemp1;
+extern	UINT8	nbReservedTemp2;
+extern	UINT8	maxCellTemp;
+extern	UINT8	minCellTemp;
+extern	UINT8	battSOC;
+extern	UINT8	battSOH;
+extern	UINT8	battWorkState;
+extern	UINT8	bmsSwVersion;
+extern	UINT8	bmsHwVersion;
+extern	UINT8	battMOSSwitchState;
+extern	UINT8	battHeatEnableState;
+extern	UINT8	reservedSignal1;
+extern	UINT8	reservedSignal2;
+extern	UINT8	reservedSignal3;
+extern	UINT8	reservedSignal4;
+extern	UINT8	reservedSignal5;
+extern	UINT8	reservedSignal6;
+extern	UINT8	reservedSignal7;
+extern	UINT8	reservedSignal8;
+
+
+
+
+//declear the UINT16 vars
+extern	UINT16	battCellU[28];
+extern	UINT16	minCellVol;
+extern	UINT16	maxCellVol;
+extern	UINT16	battPackVol;
+extern	UINT16	battI;
+extern	UINT16	nbHwVersion;
+
+
+
+
+//declear the UINT32 vars
+extern	UINT32	battWarningState;
+extern	UINT32	nbSwVersion;
+extern	UINT32	battBalanceoInfo;
+
+
+
+

+ 1 - 1
inc/TcpTask.h

@@ -69,7 +69,7 @@ typedef struct BattInfoType
 	UINT8	battTempNum;			//uint8 should change to uint16 (0~65535)
 	UINT8	battCellTemp[BATT_TEMP_NUM];
 	UINT8	battWorkState;
-	UINT8	battHeatState;
+	UINT8	battHeatEnableState;
 	UINT8 	battotherTempNum;
 	UINT8 	battotherTemp[BATT_OTHER_TEMP_NUM];
 }BattInfoType;

+ 1 - 2
inc/UartTask.h

@@ -10,7 +10,7 @@
 extern UINT8 BattChrgEndFlag;
 typedef struct _UartRedMsg
 {
-	volatile bool UartFlag;
+	volatile BOOL UartFlag;
     UINT8 Header[3];
     UINT8 data[120];
     UINT16 len;
@@ -21,7 +21,6 @@ typedef struct Uart_Write_Data_Type
     uint8_t Data[2];
 }Uart_Write_Data_Type;
 //全局变量输出区
-extern UartReadMsgType UartReadMsg;
 extern osMutexId_t UartMutex;
 extern QueueHandle_t UartWriteCmdHandle;
 //

+ 1 - 1
inc/app.h

@@ -74,7 +74,7 @@ typedef struct AppConfigHeader
 }AppConfigHeader;
 typedef struct _UartAnswerMsg
 {
-	bool UartFlag;
+	BOOL UartFlag;
     UINT8 dataPtr[8];
     UINT16 len;
 }UartAnswerMsgType;

+ 234 - 0
src/CANEncode.c

@@ -0,0 +1,234 @@
+#include  "CANEncode.h"
+#include  "Signal.h"
+#include  "mainTask.h"
+void CANEncodeFunction(UINT32 ID,UINT8* rawData);
+
+
+void CANEncodeFunction(UINT32 ID,UINT8* rawData)
+{
+	memset(rawData, 0xFF, 8);	
+	switch (ID)
+	{
+		case	0x6A0:
+			*(UINT16*)(rawData +0) = ((battCellU[0]>>8) & 0xFF) | (((battCellU[0]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +2) = ((battCellU[1]>>8) & 0xFF) | (((battCellU[1]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +4) = ((battCellU[2]>>8) & 0xFF) | (((battCellU[2]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +6) = ((battCellU[3]>>8) & 0xFF) | (((battCellU[3]&0xFF)<<8)&0xFF00);
+			break;
+		case	0x6A1:
+			*(UINT16*)(rawData +0) = ((battCellU[4]>>8) & 0xFF) | (((battCellU[4]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +2) = ((battCellU[5]>>8) & 0xFF) | (((battCellU[5]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +4) = ((battCellU[6]>>8) & 0xFF) | (((battCellU[6]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +6) = ((battCellU[7]>>8) & 0xFF) | (((battCellU[7]&0xFF)<<8)&0xFF00);
+			break;
+		case	0x6A2:
+			*(UINT16*)(rawData +0) = ((battCellU[8]>>8) & 0xFF) | (((battCellU[8]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +2) = ((battCellU[9]>>8) & 0xFF) | (((battCellU[9]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +4) = ((battCellU[10]>>8) & 0xFF) | (((battCellU[10]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +6) = ((battCellU[11]>>8) & 0xFF) | (((battCellU[11]&0xFF)<<8)&0xFF00);
+			break;
+		case	0x6A3:
+			*(UINT16*)(rawData +0) = ((battCellU[12]>>8) & 0xFF) | (((battCellU[12]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +2) = ((battCellU[13]>>8) & 0xFF) | (((battCellU[13]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +4) = ((battCellU[14]>>8) & 0xFF) | (((battCellU[14]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +6) = ((battCellU[15]>>8) & 0xFF) | (((battCellU[15]&0xFF)<<8)&0xFF00);
+			break;
+		case	0x6A4:
+			*(UINT16*)(rawData +0) = ((battCellU[16]>>8) & 0xFF) | (((battCellU[16]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +2) = ((battCellU[17]>>8) & 0xFF) | (((battCellU[17]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +4) = ((battCellU[18]>>8) & 0xFF) | (((battCellU[18]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +6) = ((battCellU[19]>>8) & 0xFF) | (((battCellU[19]&0xFF)<<8)&0xFF00);
+			break;
+		case	0x6A5:
+			*(UINT16*)(rawData +0) = ((battCellU[20]>>8) & 0xFF) | (((battCellU[20]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +2) = ((battCellU[21]>>8) & 0xFF) | (((battCellU[21]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +4) = ((battCellU[22]>>8) & 0xFF) | (((battCellU[22]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +6) = ((battCellU[23]>>8) & 0xFF) | (((battCellU[23]&0xFF)<<8)&0xFF00);
+			break;
+		case	0x6A6:
+			*(UINT16*)(rawData +0) = ((battCellU[24]>>8) & 0xFF) | (((battCellU[24]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +2) = ((battCellU[25]>>8) & 0xFF) | (((battCellU[25]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +4) = ((battCellU[26]>>8) & 0xFF) | (((battCellU[26]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +6) = ((battCellU[27]>>8) & 0xFF) | (((battCellU[27]&0xFF)<<8)&0xFF00);
+			break;
+		case	0x6B0:
+			*(UINT8*)(rawData +0) =battCellTemp[0]&0xFF;
+			*(UINT8*)(rawData +1) =battCellTemp[1]&0xFF;
+			*(UINT8*)(rawData +2) =battCellTemp[2]&0xFF;
+			*(UINT8*)(rawData +3) =battCellTemp[3]&0xFF;
+			*(UINT8*)(rawData +4) =battCellTemp[4]&0xFF;
+			*(UINT8*)(rawData +5) =battCellTemp[5]&0xFF;
+			*(UINT8*)(rawData +6) =battCellTemp[6]&0xFF;
+			*(UINT8*)(rawData +7) =battCellTemp[7]&0xFF;
+			break;
+		case	0x6BA:
+			*(UINT8*)(rawData +0) =MOSTemp&0xFF;
+			*(UINT8*)(rawData +1) =packTemp&0xFF;
+			*(UINT8*)(rawData +2) =fastChargeTemp&0xFF;
+			*(UINT8*)(rawData +3) =normalChargeTemp&0xFF;
+			*(UINT8*)(rawData +4) =heatTemp1&0xFF;
+			*(UINT8*)(rawData +5) =heatTemp2&0xFF;
+			*(UINT8*)(rawData +6) =nbReservedTemp1&0xFF;
+			*(UINT8*)(rawData +7) =nbReservedTemp2&0xFF;
+			break;
+		case	0x6C0:
+			*(UINT16*)(rawData +0) = ((minCellVol>>8) & 0xFF) | (((minCellVol&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +2) = ((maxCellVol>>8) & 0xFF) | (((maxCellVol&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +4) = ((battPackVol>>8) & 0xFF) | (((battPackVol&0xFF)<<8)&0xFF00);
+			*(UINT8*)(rawData +6) =maxCellTemp&0xFF;
+			*(UINT8*)(rawData +7) =minCellTemp&0xFF;
+			break;
+		case	0x6C1:
+			*(UINT8*)(rawData +0) =battSOC&0xFF;
+			*(UINT8*)(rawData +1) =battSOH&0xFF;
+			*(UINT16*)(rawData +2) = ((battI>>8) & 0xFF) | (((battI&0xFF)<<8)&0xFF00);
+			*(UINT8*)(rawData +4) =battWorkState&0xFF;
+			*(UINT32*)(rawData +5) = ((battWarningState>>16) & 0xFF)|((battWarningState)&0xFF00)|(((battWarningState&0xFF)<<16)&0xFF0000);
+			break;
+		case	0x6C2:
+			*(UINT32*)(rawData +0) = ((nbSwVersion>>24) & 0xFF)|((nbSwVersion>>8)&0xFF00)|((nbSwVersion<<8)&0xFF0000)|(((nbSwVersion&0xFF)<<24)&0xFF000000);
+			*(UINT16*)(rawData +4) = ((nbHwVersion>>8) & 0xFF) | (((nbHwVersion&0xFF)<<8)&0xFF00);
+			*(UINT8*)(rawData +6) =bmsSwVersion&0xFF;
+			*(UINT8*)(rawData +7) =bmsHwVersion&0xFF;
+			break;
+		case	0x6C3:
+			*(UINT32*)(rawData +0) = ((battBalanceoInfo>>24) & 0xFF)|((battBalanceoInfo>>8)&0xFF00)|((battBalanceoInfo<<8)&0xFF0000)|(((battBalanceoInfo&0xFF)<<24)&0xFF000000);
+			*(UINT8*)(rawData +4) =battMOSSwitchState&0xFF;
+			*(UINT8*)(rawData +5) =battHeatEnableState&0xFF;
+			break;
+		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;
+			break;
+		case	0x7C0:
+			*(UINT16*)(rawData +0) = ((battCellU[0]>>8) & 0xFF) | (((battCellU[0]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +2) = ((battCellU[1]>>8) & 0xFF) | (((battCellU[1]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +4) = ((battCellU[2]>>8) & 0xFF) | (((battCellU[2]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +6) = ((battCellU[3]>>8) & 0xFF) | (((battCellU[3]&0xFF)<<8)&0xFF00);
+			break;
+		case	0x7C1:
+			*(UINT16*)(rawData +0) = ((battCellU[4]>>8) & 0xFF) | (((battCellU[4]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +2) = ((battCellU[5]>>8) & 0xFF) | (((battCellU[5]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +4) = ((battCellU[6]>>8) & 0xFF) | (((battCellU[6]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +6) = ((battCellU[7]>>8) & 0xFF) | (((battCellU[7]&0xFF)<<8)&0xFF00);
+			break;
+		case	0x7C2:
+			*(UINT16*)(rawData +0) = ((battCellU[8]>>8) & 0xFF) | (((battCellU[8]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +2) = ((battCellU[9]>>8) & 0xFF) | (((battCellU[9]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +4) = ((battCellU[10]>>8) & 0xFF) | (((battCellU[10]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +6) = ((battCellU[11]>>8) & 0xFF) | (((battCellU[11]&0xFF)<<8)&0xFF00);
+			break;
+		case	0x7C3:
+			*(UINT16*)(rawData +0) = ((battCellU[12]>>8) & 0xFF) | (((battCellU[12]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +2) = ((battCellU[13]>>8) & 0xFF) | (((battCellU[13]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +4) = ((battCellU[14]>>8) & 0xFF) | (((battCellU[14]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +6) = ((battCellU[15]>>8) & 0xFF) | (((battCellU[15]&0xFF)<<8)&0xFF00);
+			break;
+		case	0x7C4:
+			*(UINT16*)(rawData +0) = ((battCellU[16]>>8) & 0xFF) | (((battCellU[16]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +2) = ((battCellU[17]>>8) & 0xFF) | (((battCellU[17]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +4) = ((battCellU[18]>>8) & 0xFF) | (((battCellU[18]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +6) = ((battCellU[19]>>8) & 0xFF) | (((battCellU[19]&0xFF)<<8)&0xFF00);
+			break;
+		case	0x7C5:
+			*(UINT16*)(rawData +0) = ((battCellU[20]>>8) & 0xFF) | (((battCellU[20]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +2) = ((battCellU[21]>>8) & 0xFF) | (((battCellU[21]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +4) = ((battCellU[22]>>8) & 0xFF) | (((battCellU[22]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +6) = ((battCellU[23]>>8) & 0xFF) | (((battCellU[23]&0xFF)<<8)&0xFF00);
+			break;
+		case	0x7C6:
+			*(UINT16*)(rawData +0) = ((battCellU[24]>>8) & 0xFF) | (((battCellU[24]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +2) = ((battCellU[25]>>8) & 0xFF) | (((battCellU[25]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +4) = ((battCellU[26]>>8) & 0xFF) | (((battCellU[26]&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +6) = ((battCellU[27]>>8) & 0xFF) | (((battCellU[27]&0xFF)<<8)&0xFF00);
+			break;
+		case	0x7C7:
+			*(UINT8*)(rawData +0) =battCellTemp[0]&0xFF;
+			*(UINT8*)(rawData +1) =battCellTemp[1]&0xFF;
+			*(UINT8*)(rawData +2) =battCellTemp[2]&0xFF;
+			*(UINT8*)(rawData +3) =battCellTemp[3]&0xFF;
+			*(UINT8*)(rawData +4) =battCellTemp[4]&0xFF;
+			*(UINT8*)(rawData +5) =battCellTemp[5]&0xFF;
+			*(UINT8*)(rawData +6) =battCellTemp[6]&0xFF;
+			*(UINT8*)(rawData +7) =battCellTemp[7]&0xFF;
+			break;
+		case	0x7C8:
+			*(UINT8*)(rawData +0) =MOSTemp&0xFF;
+			*(UINT8*)(rawData +1) =packTemp&0xFF;
+			*(UINT8*)(rawData +2) =fastChargeTemp&0xFF;
+			*(UINT8*)(rawData +3) =normalChargeTemp&0xFF;
+			*(UINT8*)(rawData +4) =heatTemp1&0xFF;
+			*(UINT8*)(rawData +5) =heatTemp2&0xFF;
+			*(UINT8*)(rawData +6) =nbReservedTemp1&0xFF;
+			*(UINT8*)(rawData +7) =nbReservedTemp2&0xFF;
+			break;
+		case	0x7C9:
+			*(UINT16*)(rawData +0) = ((minCellVol>>8) & 0xFF) | (((minCellVol&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +2) = ((maxCellVol>>8) & 0xFF) | (((maxCellVol&0xFF)<<8)&0xFF00);
+			*(UINT16*)(rawData +4) = ((battPackVol>>8) & 0xFF) | (((battPackVol&0xFF)<<8)&0xFF00);
+			*(UINT8*)(rawData +6) =maxCellTemp&0xFF;
+			*(UINT8*)(rawData +7) =minCellTemp&0xFF;
+			break;
+		case	0x7CA:
+			*(UINT8*)(rawData +0) =battSOC&0xFF;
+			*(UINT8*)(rawData +1) =battSOH&0xFF;
+			*(UINT16*)(rawData +2) = ((battI>>8) & 0xFF) | (((battI&0xFF)<<8)&0xFF00);
+			*(UINT8*)(rawData +4) =battWorkState&0xFF;
+			*(UINT32*)(rawData +5) = ((battWarningState>>16) & 0xFF)|((battWarningState)&0xFF00)|(((battWarningState&0xFF)<<16)&0xFF0000);
+			break;
+		case	0x7CB:
+			*(UINT32*)(rawData +0) = ((nbSwVersion>>24) & 0xFF)|((nbSwVersion>>8)&0xFF00)|((nbSwVersion<<8)&0xFF0000)|(((nbSwVersion&0xFF)<<24)&0xFF000000);
+			*(UINT16*)(rawData +4) = ((nbHwVersion>>8) & 0xFF) | (((nbHwVersion&0xFF)<<8)&0xFF00);
+			*(UINT8*)(rawData +6) =bmsSwVersion&0xFF;
+			*(UINT8*)(rawData +7) =bmsHwVersion&0xFF;
+			break;
+		case	0x7CC:
+			*(UINT32*)(rawData +0) = ((battBalanceoInfo>>24) & 0xFF)|((battBalanceoInfo>>8)&0xFF00)|((battBalanceoInfo<<8)&0xFF0000)|(((battBalanceoInfo&0xFF)<<24)&0xFF000000);
+			*(UINT8*)(rawData +4) =battMOSSwitchState&0xFF;
+			*(UINT8*)(rawData +5) =battHeatEnableState&0xFF;
+			break;
+		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;
+			break;
+		case	0x7B0:
+			*(UINT8*)(rawData +0) = (AppNVMData.battSN[0])&0xFF;
+			*(UINT8*)(rawData +1) = (AppNVMData.battSN[1])&0xFF;
+			*(UINT8*)(rawData +2) = (AppNVMData.battSN[2])&0xFF;
+			*(UINT8*)(rawData +3) = (AppNVMData.battSN[3])&0xFF;
+			*(UINT8*)(rawData +4) = (AppNVMData.battSN[4])&0xFF;
+			*(UINT8*)(rawData +5) = (AppNVMData.battSN[5])&0xFF;
+			*(UINT8*)(rawData +6) = (AppNVMData.battSN[6])&0xFF;
+			*(UINT8*)(rawData +7) = (AppNVMData.battSN[7])&0xFF;
+			break;
+		case	0x7B1:
+			*(UINT8*)(rawData +0) = (AppNVMData.battSN[8])&0xFF;
+			*(UINT8*)(rawData +1) = (AppNVMData.battSN[9])&0xFF;
+			*(UINT8*)(rawData +2) = (AppNVMData.battSN[10])&0xFF;
+			*(UINT8*)(rawData +3) = (AppNVMData.battSN[11])&0xFF;
+			*(UINT8*)(rawData +4) = (AppNVMData.battSN[12])&0xFF;
+			*(UINT8*)(rawData +5) = (AppNVMData.battSN[13])&0xFF;
+			*(UINT8*)(rawData +6) = (AppNVMData.battSN[14])&0xFF;
+			*(UINT8*)(rawData +7) = (AppNVMData.battSN[15])&0xFF;
+			break;
+		case	0x7B2:
+			*(UINT8*)(rawData +0) = (AppNVMData.battSN[16])&0xFF;
+			
+			break;
+		
+		default:
+			break;
+	}
+}

+ 131 - 16
src/CANTask.c

@@ -22,11 +22,11 @@
 #include "app.h"
 #include "CANTask.h"
 #include "UDSService.h"
+#include "signal.h"
 
-extern osMutexId_t UartMutex;
 extern UINT32 Timer_count;
-extern volatile bool Sleep_flag;
-extern UartReadMsgType UartReadMsg;
+extern volatile BOOL Sleep_flag;
+
 CAN_Msg_Type CanRxMsg[2];
 /*线程声明*/
 #define 			PROC_CAN_RX_TASK_STACK_SIZE			(1024)
@@ -67,9 +67,8 @@ void CANTaskInit(void* arg)
 static void Can_Receive()
 {    
 	slpManSlpState_t State;
-    uint8_t cnt,temp,udsFlag=0;
-	UINT8 i = 0;
-	CAN_Msg_Type CANSendBuffer ={0};
+    uint8_t cnt,temp,udsFlag,msgFlag=0;
+	UINT8 i,j = 0;
     while(true)
     {
 		memset(CanRxMsg, 0, sizeof(CanRxMsg));    		
@@ -93,14 +92,6 @@ static void Can_Receive()
 					{								
 						if(CanRxMsg[i].Id == 0x7A0)
 						{	
-							#ifdef USING_PRINTF1
-								printf("ID = 0x%x\n",CanRxMsg[i].Id);
-								for(UINT8 j = 0; j<8;j++)
-								{
-									printf("%x ",CanRxMsg[i].Data[j]);
-								}
-								printf("\n");
-							#endif
 							udsFlag = 1;
 							UDSService[i] =  CanRxMsg[i].Data[0];
 							UDSSubService[i] = CanRxMsg[i].Data[1];
@@ -113,12 +104,28 @@ static void Can_Receive()
 								}								
 							}
 						}
+						else if(CanRxMsg[i].Id == 0x7A1)
+						{
+							if(CanRxMsg[i].Data[0] != 0x00)
+							{
+								msgFlag = 1;	
+							}
+							else
+							{
+								msgFlag = 0;
+							}
+						}
 					}	
 					if(udsFlag==1)
 					{	
 						UDS_Service();
-						udsFlag = 0;							
-					}		
+						udsFlag = 0;
+					}
+					else if(msgFlag == 1)
+					{
+						CanMsgTx1000ms();
+						
+					}
 					break;
 				}
 	        case PROCESS_CAN_STATE_SLEEP:
@@ -139,3 +146,111 @@ static void Can_Receive()
 }
 
 
+void CanMsgTx1000ms()
+{
+	
+	static UINT32 timerRecord = 0;
+	UINT8 count = 0;
+	CAN_Msg_Type canMsg;
+	
+	if(Timer_count - timerRecord > 0)
+	{
+		timerRecord = Timer_count;
+		count = Timer_count%10;
+		switch (count)
+		{
+			case 0:  //send cell batt info 0x6A0、0x6A1	
+				canMsg.DLC = 8;
+				canMsg.Id = COMOutTable[count*2];
+				CANEncodeFunction( COMOutTable[count*2],  canMsg.Data);
+				HAL_Can_Transmit(canMsg);
+
+				canMsg.DLC = 8;
+				canMsg.Id = COMOutTable[count*2+1];
+				CANEncodeFunction( COMOutTable[count*2+1], canMsg.Data);
+				HAL_Can_Transmit(canMsg);
+				
+				break;
+
+			case 1:  //send cell batt info 0x6A2、0x6A3
+				canMsg.DLC = 8;
+				canMsg.Id = COMOutTable[count*2];
+				CANEncodeFunction( COMOutTable[count*2], canMsg.Data);
+				HAL_Can_Transmit(canMsg);
+
+				canMsg.DLC = 8;
+				canMsg.Id = COMOutTable[count*2+1];
+				CANEncodeFunction( COMOutTable[count*2+1], canMsg.Data);
+				HAL_Can_Transmit(canMsg);
+				break;
+
+			case 2: //send cell batt info 0x6A4、 0x6A5
+				canMsg.DLC = 8;
+				canMsg.Id = COMOutTable[count*2];
+				CANEncodeFunction( COMOutTable[count*2], canMsg.Data);
+				HAL_Can_Transmit(canMsg);
+
+				canMsg.DLC = 8;
+				canMsg.Id = COMOutTable[count*2+1];
+				CANEncodeFunction( COMOutTable[count*2+1], canMsg.Data);
+				HAL_Can_Transmit(canMsg);
+				break;
+			
+			case 3:	//send cell batt info 0x6A6、0x6B0
+				canMsg.DLC = 8;
+				canMsg.Id = COMOutTable[count*2];
+				CANEncodeFunction( COMOutTable[count*2], canMsg.Data);
+				HAL_Can_Transmit(canMsg);
+
+				canMsg.DLC = 8;
+				canMsg.Id = COMOutTable[count*2+1];
+				CANEncodeFunction( COMOutTable[count*2+1], canMsg.Data);
+				HAL_Can_Transmit(canMsg);
+				
+				break;
+			
+			case 4: //send batt temp info 0x6BA、0x6C0
+				canMsg.DLC = 8;
+				canMsg.Id = COMOutTable[count*2];
+				CANEncodeFunction( COMOutTable[count*2], canMsg.Data);
+				HAL_Can_Transmit(canMsg);
+
+				canMsg.DLC = 8;
+				canMsg.Id = COMOutTable[count*2+1];
+				CANEncodeFunction( COMOutTable[count*2+1], canMsg.Data);
+				HAL_Can_Transmit(canMsg);
+			break;
+			
+			case 5: //send batt other info 0x6C1、0x6C2
+				canMsg.DLC = 8;
+				canMsg.Id = COMOutTable[count*2];
+				CANEncodeFunction( COMOutTable[count*2],  canMsg.Data);
+				HAL_Can_Transmit(canMsg);
+
+				canMsg.DLC = 8;
+				canMsg.Id = COMOutTable[count*2+1];
+				CANEncodeFunction( COMOutTable[count*2+1], canMsg.Data);
+				HAL_Can_Transmit(canMsg);
+			break;
+
+			case 6:	//send batt other info 0x6C3、0x6C4
+				canMsg.DLC = 8;
+				canMsg.Id = COMOutTable[count*2];
+				CANEncodeFunction( COMOutTable[count*2],  canMsg.Data);
+				HAL_Can_Transmit(canMsg);
+
+				canMsg.DLC = 8;
+				canMsg.Id = COMOutTable[count*2+1];
+				CANEncodeFunction( COMOutTable[count*2+1], canMsg.Data);
+				HAL_Can_Transmit(canMsg);
+			break;
+			
+			default:
+			break;
+			
+		}
+	}
+}
+
+
+

+ 1 - 1
src/GpsTask.c

@@ -30,7 +30,7 @@
 #include "GpsTask.h"
 #include "TcpTask.h"
 //全局变量区输入
-extern volatile bool Sleep_flag; 
+extern volatile BOOL Sleep_flag; 
 //全局变量区输出
 UINT8 GpsData[16];
 osMutexId_t GpsMutex = NULL;

+ 1 - 1
src/MainTask.c

@@ -38,7 +38,7 @@ extern volatile bool BMS_Fota_update_flag;
 CHAR defaultBattSN[BATT_SN_LEN] = "GYTEST00000000003";//未进行下线检测的默认SN
 //全局变量
 UINT32 Timer_count;//每100ms加1
-volatile bool Sleep_flag = false;//睡眠标志位
+volatile BOOL Sleep_flag = false;//睡眠标志位
 extern UINT32 TcpService;
 extern UINT8 BattChrgEndFlag;
 AppConfigHeader   AppConfigHr;   //4 bytes

+ 83 - 0
src/Signal.c

@@ -0,0 +1,83 @@
+#include "Signal.h"
+
+UINT32	COMOutTable[28]	=	{
+0x6A0,
+0x6A1,
+0x6A2,
+0x6A3,
+0x6A4,
+0x6A5,
+0x6A6,
+0x6B0,
+0x6BA,
+0x6C0,
+0x6C1,
+0x6C2,
+0x6C3,
+0x6C4,
+
+0x7C0,
+0x7C1,
+0x7C2,
+0x7C3,
+0x7C4,
+0x7C5,
+0x7C6,
+0x7C7,
+0x7C8,
+0x7C9,
+0x7CA,
+0x7CB,
+0x7CC,
+0x7CD
+
+		};
+
+//declear the UINT8 vars
+UINT8	battCellTemp[8] = {0xFF};
+UINT8	MOSTemp = 0xFF;
+UINT8	packTemp = 0xFF;
+UINT8	fastChargeTemp = 0xFF;
+UINT8	normalChargeTemp = 0xFF;
+UINT8	heatTemp1 = 0xFF;
+UINT8	heatTemp2 = 0xFF;
+UINT8	nbReservedTemp1 = 0xFF;
+UINT8	nbReservedTemp2 = 0xFF;
+UINT8	maxCellTemp = 0xFF;
+UINT8	minCellTemp = 0xFF;
+UINT8	battSOC = 0xFF;
+UINT8	battSOH = 0xFF;
+UINT8	battWorkState = 0xFF;
+UINT8	bmsSwVersion = 0xFF;
+UINT8	bmsHwVersion = 0xFF;
+UINT8	battMOSSwitchState = 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;
+
+
+
+//declear the UINT16 vars
+UINT16	battCellU[28] = {0xFFFF};
+UINT16	minCellVol = 0xFFFF;
+UINT16	maxCellVol = 0xFFFF;
+UINT16	battPackVol = 0xFFFF;
+UINT16	battI = 0xFFFF;
+UINT16	nbHwVersion = 0xFFFF;
+
+
+
+
+//declear the UINT32 vars
+UINT32	battWarningState = 0xFFFFFFFF;
+UINT32	nbSwVersion = 0xFFFFFFFF;
+UINT32	battBalanceoInfo = 0xFFFFFFFF;
+
+
+

+ 60 - 75
src/TcpTask.c

@@ -30,18 +30,21 @@
 #include "UartTask.h"
 #include "GpsTask.h"
 #include "Fota.h"
+#include "Signal.h"
 //全局变量输出区
 UINT32 TcpService = 0;
 //全局变量输入区
 extern UINT32 Timer_count;
-extern volatile bool Sleep_flag;
-extern UartReadMsgType UartReadMsg;
+extern volatile BOOL Sleep_flag;
+//extern UartReadMsgType UartReadMsg;
 extern osMutexId_t UartMutex;
 extern osMutexId_t GpsMutex;
 extern UINT8 GpsData[16];
 extern AppNVMDataType AppNVMData;
 extern AppDataBody AppDataInfo;
 extern QueueHandle_t UartWriteCmdHandle;
+extern BOOL UartBattInfoRecvFlag;
+
 
 //局部变量申请
 AppSocketConnectionContext socContext = {-1, APP_SOCKET_CONNECTION_CLOSED};
@@ -192,7 +195,7 @@ static void TcpTask(void* arg)
                     TcpTaskDeInit(arg);
                     break;
             }
-            free(queueItem);
+        free(queueItem);
         }
     }//while 循环
 }
@@ -235,9 +238,9 @@ static void TcpDataInfoAssembleSend()
     UINT8 GpsSendFreq=0;
     UINT8 WorkState=0;
     static UINT8 WorkFlag;
-    osMutexAcquire(UartMutex, osWaitForever);
-    WorkState = (UartReadMsg.data[(0x03+BATT_CELL_VOL_NUM)*2+1]&0x03);
-    osMutexRelease(UartMutex); 
+	int i = 0;
+	UINT8 len = 0;
+    WorkState = battWorkState;
     if(WorkState==0x00 && WorkFlag==0x01)
     {
         if(send_counter%20==0)
@@ -275,12 +278,12 @@ static void TcpDataInfoAssembleSend()
             GpsSendFreq = AppDataInfo.GpsChrgInfoSendFreq/5;
             break;
     }    
-    #ifdef USING_PRINTF
+    #ifdef USING_PRINTF1
             printf("send_counter= %x,BattSendFreq= %x,GpsSendFreq= %x,UartReadMsg:%x\n",send_counter,BattSendFreq,GpsSendFreq,UartReadMsg.data[(0x03+BATT_CELL_VOL_NUM)*2+1]);
     #endif
     if(send_counter%BattSendFreq==0)
     {
-        osStatus_t result = osMutexAcquire(UartMutex, osWaitForever);
+        //osStatus_t result = osMutexAcquire(UartMutex, osWaitForever);
         appGetSystemTimeUtcSync(&TimeStracture);
         appGetSignalInfoSync(&csq,&snr,&rsnr);
         DataLen= (UINT16)sizeof(BattToTcpInfo.battInfo);
@@ -310,65 +313,46 @@ static void TcpDataInfoAssembleSend()
         BattToTcpInfo.battInfo.errClass = 0x00;
         BattToTcpInfo.battInfo.errCode[0] = 0x00;
 	    BattToTcpInfo.battInfo.errCode[1] = 0x00;
-        Batt_current = (UartReadMsg.data[(0x02+BATT_CELL_VOL_NUM)*2]<<8)|(UartReadMsg.data[(0x02+BATT_CELL_VOL_NUM)*2+1]);
-        if (Batt_current>0x8000)//放电为正,充电为负
-        {
-            Batt_current = Batt_current|0x7fff;
-            Batt_current = Batt_current/10;
-            Batt_current = 0x2710 + Batt_current;
-            Batt_current = Batt_current;
-        }
-        else
-        {
-            Batt_current = Batt_current/10;
-            Batt_current = 0x2710 - Batt_current;
-            Batt_current = Batt_current;
-        }
-        BattToTcpInfo.battInfo.battI[0] = Batt_current>>8;
-	    BattToTcpInfo.battInfo.battI[1] = Batt_current & 0xFF;
-        BattU =( (UartReadMsg.data[(0x18+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2])<<8|(UartReadMsg.data[(0x18+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2+1]))/10;
-        //电池内外电压保持一致
-        BattToTcpInfo.battInfo.battLinkVol[0] = BattU >> 8;
-	    BattToTcpInfo.battInfo.battLinkVol[1] = BattU & 0xFF;
-	    BattToTcpInfo.battInfo.battPackVol[0] = BattU >> 8;
-	    BattToTcpInfo.battInfo.battPackVol[1] = BattU & 0xFF;
-        temp = ((UartReadMsg.data[(0x09+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2+1])>>1)&0x03;
-        if(AppNVMData.isBattLocked==TRUE)
-        {
-            BattToTcpInfo.battInfo.switchState = ((temp&0x01)<<1)|((temp&0x02)>>1)|0x01<<2;
-        }
-        else
-        {
-            BattToTcpInfo.battInfo.switchState = ((temp&0x01)<<1)|((temp&0x02)>>1)|0x00<<2;
-        }
-        BattToTcpInfo.battInfo.battSOC = UartReadMsg.data[(0x0B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2+1];
-        BattToTcpInfo.battInfo.battSOH = UartReadMsg.data[(0x0C+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2+1];
-        memcpy(BattToTcpInfo.battInfo.batCellBalenceState,&UartReadMsg.data[(0x06+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2],4);
-        BattToTcpInfo.battInfo.battCellNum= BATT_CELL_VOL_NUM ;
-        memcpy(BattToTcpInfo.battInfo.battCellU,&UartReadMsg.data[0x04],BATT_CELL_VOL_NUM_2);
-        BattToTcpInfo.battInfo.battTempNum = BATT_TEMP_NUM;
-        for(int i=0; i<BATT_TEMP_NUM; i++)
-	    {
-		    BattToTcpInfo.battInfo.battCellTemp[i] = UartReadMsg.data[(0x06+BATT_CELL_VOL_NUM+i)*2+1];
-	    }
-        BattToTcpInfo.battInfo.battWorkState =UartReadMsg.data[(0x03+BATT_CELL_VOL_NUM)*2+1]&0x03;//电池状态,0表示静置,1表示放电,2表示充电
-        BattToTcpInfo.battInfo.battHeatState = UartReadMsg.data[(0x1C+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2+1];
-        BattToTcpInfo.battInfo.battotherTempNum = BATT_OTHER_TEMP_NUM;//其他温度编号(包含环境温度mos温度以及接插件温度)2021-03-24其他温度修改
-        BattToTcpInfo.battInfo.battotherTemp[0] = UartReadMsg.data[(0x06+BATT_CELL_VOL_NUM+BATT_TEMP_NUM)*2+1];
-        BattToTcpInfo.battInfo.battotherTemp[1] = UartReadMsg.data[(0x06+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+1)*2+1];
+		
+		BattToTcpInfo.battInfo.battI[0] = battI>>8;
+		BattToTcpInfo.battInfo.battI[1] = battI & 0xFF;
+		
+		//电池内外电压保持一致
+		BattToTcpInfo.battInfo.battLinkVol[0] = battPackVol >> 8;
+		BattToTcpInfo.battInfo.battLinkVol[1] = battPackVol & 0xFF;
+		BattToTcpInfo.battInfo.battPackVol[0] = battPackVol >> 8;
+		BattToTcpInfo.battInfo.battPackVol[1] = battPackVol & 0xFF;
+		
+		BattToTcpInfo.battInfo.switchState = battMOSSwitchState;
+		
+		BattToTcpInfo.battInfo.battSOC = battSOC;
+		BattToTcpInfo.battInfo.battSOH = battSOH;
+		memcpy(BattToTcpInfo.battInfo.batCellBalenceState,&battBalanceoInfo,4);
+		BattToTcpInfo.battInfo.battCellNum= BATT_CELL_VOL_NUM ;
+
+		for(i=0;i<BATT_CELL_VOL_NUM;i++)
+		{
+			BattToTcpInfo.battInfo.battCellU[i*2] = (battCellU[i]>>8) & 0xFF;
+			BattToTcpInfo.battInfo.battCellU[i*2+1] = battCellU[i] & 0xFF;
+		}
+		
+		BattToTcpInfo.battInfo.battTempNum = BATT_TEMP_NUM;
+		for(i=0; i<BATT_TEMP_NUM; i++)
+		{
+			BattToTcpInfo.battInfo.battCellTemp[i] = battCellTemp[i];
+		}
+		BattToTcpInfo.battInfo.battWorkState = battWorkState;//电池状态,0表示静置,1表示放电,2表示充电
+		BattToTcpInfo.battInfo.battHeatEnableState = battHeatEnableState;
+		BattToTcpInfo.battInfo.battotherTempNum = BATT_OTHER_TEMP_NUM;//其他温度编号(包含环境温度mos温度以及接插件温度)2021-03-24其他温度修改
+		BattToTcpInfo.battInfo.battotherTemp[0] = MOSTemp;
+		BattToTcpInfo.battInfo.battotherTemp[1] = packTemp;       
+        
         BattToTcpInfo.CRC = bcc_chk((UINT8 *)&BattToTcpInfo, sizeof(BattMsgtoTcpType)-1 );
-        osMutexRelease(UartMutex);
-        UINT8 len;
-        if(UartReadMsg.UartFlag)
+        //osMutexRelease(UartMutex);
+        if(UartBattInfoRecvFlag)
         {
             len = tcpipConnectionSend(socContext.id, (UINT8 *)&BattToTcpInfo, sizeof(BattToTcpInfo), 0, 0, 0);
         }
-        #ifdef USING_PRINTF1
-            printf("Len = %d\n",len);
-            for(int i=0;i<sizeof(BattToTcpInfo);i++)
-                printf("%x  ",*((UINT8 *)&BattToTcpInfo+i));
-            printf("end V4! \n",len);
-        #endif
     }
     if(send_counter%GpsSendFreq==0)
     {
@@ -435,14 +419,15 @@ static void TcpDataInfoAssembleSend()
         VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[5] = ((TimeStracture.UTCtimer2) >> 8 ) & 0xFF;
         memcpy(VerMsgToTcpInfo.VerInfo.ICCID,iccid,20);
         memcpy(VerMsgToTcpInfo.VerInfo.IMEI,imei,15);
-        osMutexAcquire(UartMutex, osWaitForever);//Bms版本号上传2021-03-24修改
-        VerMsgToTcpInfo.VerInfo.BMSHwVersion[0] = UartReadMsg.data[(0x08+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2+1]/10;
-        VerMsgToTcpInfo.VerInfo.BMSHwVersion[1] = UartReadMsg.data[(0x08+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2+1]%10;
-        VerMsgToTcpInfo.VerInfo.BMSSwVersion[0] = 0;
-        VerMsgToTcpInfo.VerInfo.BMSSwVersion[1] = 0;
-        VerMsgToTcpInfo.VerInfo.BMSSwVersion[2] = UartReadMsg.data[(0x08+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2]/10;
-        VerMsgToTcpInfo.VerInfo.BMSSwVersion[3] = UartReadMsg.data[(0x08+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM)*2]%10;
-        osMutexRelease(UartMutex);
+        //osMutexAcquire(UartMutex, osWaitForever);//Bms版本号上传2021-03-24修改
+        
+		VerMsgToTcpInfo.VerInfo.BMSHwVersion[0] = bmsHwVersion /10;
+		VerMsgToTcpInfo.VerInfo.BMSHwVersion[1] = bmsHwVersion%10;
+		VerMsgToTcpInfo.VerInfo.BMSSwVersion[0] = 0;
+		VerMsgToTcpInfo.VerInfo.BMSSwVersion[1] = 0;
+		VerMsgToTcpInfo.VerInfo.BMSSwVersion[2] = bmsSwVersion/10;
+		VerMsgToTcpInfo.VerInfo.BMSSwVersion[3] = bmsSwVersion%10;
+        //osMutexRelease(UartMutex);
         VerMsgToTcpInfo.VerInfo.NBHwVersion[0] = (HWVERSION>>8)& 0xFF;
         VerMsgToTcpInfo.VerInfo.NBHwVersion[1] = (HWVERSION)& 0xFF;
         VerMsgToTcpInfo.VerInfo.BLVersion[0] = (BLSWVERSION>>24)& 0xFF;
@@ -461,7 +446,7 @@ static void TcpDataInfoAssembleSend()
         VerMsgToTcpInfo.VerInfo.BmsInfo = BMS_INFO;
         VerMsgToTcpInfo.VerInfo.DataModuleType = DATA_MODULE_TYPE;
         VerMsgToTcpInfo.CRC = bcc_chk((UINT8 *)&VerMsgToTcpInfo, sizeof(VerMsgToTcpInfo)-1 );
-        if(UartReadMsg.UartFlag)
+        if(UartBattInfoRecvFlag)
         {
             tcpipConnectionSend(socContext.id, (UINT8 *)&VerMsgToTcpInfo, sizeof(VerMsgToTcpInfo), 0, 0, 0);
         }
@@ -524,7 +509,7 @@ static void TcpDataInfoRecvHandle()
                 }
                 else if(*(Ptr+30)==0x80)//远程锁定命令
                 {
-                    osMutexAcquire(UartMutex, osWaitForever);
+                    //osMutexAcquire(UartMutex, osWaitForever);
                     TcpCmdAnswer[3] = 0x01;
                     memcpy(&TcpCmdAnswer[4],(Ptr+4),BATT_SN_LEN);
                     TcpCmdAnswer[21] = TCP_ENCPT_DISABLE;
@@ -539,7 +524,7 @@ static void TcpDataInfoRecvHandle()
                         UartWriteCmd.WriteCmd = 0x01;
                         UartWriteCmd.Data[0] = 0x00;
                         UartWriteCmd.Data[1] = 0x00;
-                        if((UartReadMsg.data[(0x03+BATT_CELL_VOL_NUM)*2+1]&0x03)==0x00)
+                        if(battWorkState ==0x00)
                         {
                             osMessageQueuePut(UartWriteCmdHandle,&UartWriteCmd,0,1000);
                         }
@@ -555,7 +540,7 @@ static void TcpDataInfoRecvHandle()
                         osMessageQueuePut(UartWriteCmdHandle,&UartWriteCmd,0,1000);
                         tcpipConnectionSend(socContext.id,TcpCmdAnswer,31,0,0,0);
                     }
-                    osMutexRelease(UartMutex);
+                    //osMutexRelease(UartMutex);
                     TcpService=0x00;
                     
                 }

+ 105 - 79
src/UDSService.c

@@ -26,11 +26,11 @@
 #include "UDSService.h"
 
 
-//
-extern UartReadMsgType UartReadMsg;
-extern osMutexId_t UartMutex;
+
 extern AppSocketConnectionContext socContext;
 extern UINT8 GpsData[16];
+extern UINT8 battInfo[8*14];
+
 
 void UDS_Service(void);
 void UDS_CAN_Update(void);
@@ -74,10 +74,10 @@ void UDS_Service()
 	UINT32 tempSliceCounter=0;	
 	static UINT8 counter=0;  
 	CAN_Msg_Type UDSAnswer ={0};
-	static UINT8 battInfo[8*14] = {0};
+	
 	UINT32 posCode,negCode;
 	
-	//UartReadMsg Uart_Recv_Msg;
+	
 	//UINT8 temp00[94] ={0x00,0x0E,0x00,0x05,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0D,0x7A,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x0E,0x42,0x0D,0xDE,0x0D,0xDE,0x0D,0xDE,0x13,0x38,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x21,0x00,0x24,0x00,0x26,0x00,0x22,0x00,0x24,0x00,0x00,0x00,0x00,0x6e,0x78,0x00,0x00,0x00,0x00,0x00,0x5F,0x00,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x13,0x74,0x0E,0x42,0x0D,0x7A,0x00,0x00};
 	//MEMCPY(battInfo, temp00, 94);
 	
@@ -85,8 +85,13 @@ void UDS_Service()
 	//{
 		//if(UDSSwitch == 1)
 		{
+			
+			
 			for(i=0; i<2; i++)
 			{
+				UDSAnswer.DLC = 8;
+				memset(UDSAnswer.Data, 0, UDSAnswer.DLC);
+				
 				if(CanRxMsg[i].Id == 0x7A0)
 					{
 					switch (UDSService[i])
@@ -158,62 +163,38 @@ void UDS_Service()
 										UDSPositiveAnswer(0x06,i,HWVERSION);										
 									}
 									else if(UDSSubService[i] == 0x03)  //check the SN number
-									{	
-										UDSAnswer.DLC = 8;
+									{											
 										switch(UDSSubServiceActionCode[i])
 										{
 											case 00:
-												UDSAnswer.Id = 0x20;
-												for(k=0; k<8; k++)
-												{
-													UDSAnswer.Data[k] = AppNVMData.battSN[k+8*0];
-												}
+												UDSAnswer.Id = 0x7B0;
+												
+												CANEncodeFunction(UDSAnswer.Id, UDSAnswer.Data);
 												ret = HAL_Can_Transmit(UDSAnswer);
+												
 												break;
 												
 											case 01:
-												UDSAnswer.Id = 0x21;
-												for(k=0; k<8; k++)
-												{
-													UDSAnswer.Data[k] = AppNVMData.battSN[k+8*1];
-												}
+												UDSAnswer.Id = 0x7B1;
+												CANEncodeFunction(UDSAnswer.Id, UDSAnswer.Data);
 												ret = HAL_Can_Transmit(UDSAnswer);
+
 												break;
 
 											case 02:
-												UDSAnswer.Id = 0x22;
-												UDSAnswer.Data[0] = AppNVMData.battSN[16];;
-												for(k=1; k<8; k++)
-												{
-													UDSAnswer.Data[k] = 0x00;
-												}
+												UDSAnswer.Id = 0x7B2;
+												CANEncodeFunction(UDSAnswer.Id, UDSAnswer.Data);
 												ret = HAL_Can_Transmit(UDSAnswer);
+												
 												break;
 											default:
 											break;											
 										}									
 									}
 									else if(UDSSubService[i] == 0x04)  //check the batt message
-									{									
-										osStatus_t result = osMutexAcquire(UartMutex, osWaitForever);
-										if(CanRxMsg[i].Data[2] == 0x00)
-										{
-											MEMCPY(battInfo,UartReadMsg.data,14*8);
-										/*
-											#ifdef USING_PRINTF
-											printf("battInfo=\n");
-											for(int jj = 0;jj<14*8;jj++)
-												printf("%x ",battInfo[jj]);
-											printf("\n");
-											#endif
-										*/
-										}
-										osMutexRelease(UartMutex);
-
-										UDSAnswer.Id = 0x30+UDSSubServiceActionCode[i];
-										UDSAnswer.DLC = 8;
-
-										MEMCPY(UDSAnswer.Data, &(battInfo[UDSSubServiceActionCode[i]*8]),8);
+									{
+										UDSAnswer.Id = 0x7C0+UDSSubServiceActionCode[i];
+										CANEncodeFunction(UDSAnswer.Id, UDSAnswer.Data);										
 										ret = HAL_Can_Transmit(UDSAnswer);										
 									}
 									else if(UDSSubService[i] == 0x05)  //check the enviroment temp of NB
@@ -287,16 +268,13 @@ void UDS_Service()
 										}
 										else
 										{
-											UDSAnswer.Id = 0x7A8;
-											UDSAnswer.DLC = 8;
+											UDSAnswer.Id = 0x7A8;											
 											UDSAnswer.Data[0] = 0x05;
 											UDSAnswer.Data[1] = 0x3E;
 											UDSAnswer.Data[2] = UDSService[i];
 											UDSAnswer.Data[3] = UDSSubService[i];
 											UDSAnswer.Data[4] = snFlag;	
-											UDSAnswer.Data[5] = 0x00;
-											UDSAnswer.Data[6] = 0x00;
-											UDSAnswer.Data[7] = 0x00;
+											
 											ret = HAL_Can_Transmit(UDSAnswer);
 										}										
 									}
@@ -397,55 +375,88 @@ void UDS_Service()
 										#endif
 										*/											
 										}
+										else
+										{
+											counter--;
+										}
+										
 										if(counter == 25)
 										{
-											counter = 0;
-											
+											counter = 0;											
 											if(sliceCounterFlag == 0x1FFFFFF)  //received all the 25 message of current package
-											{
-												sliceCounterFlag = 0x0;
-												updateDifferDataPackageCounter++;
-											/*
-											#ifdef USING_PRINTF
-												printf("updateDifferDataPackageCounter = %d\n",updateDifferDataPackageCounter);
-
-												printf("updateDataBuffer\n");
-												for(k=0;k<100;k++)
-												{
-													printf("%x  ",updateDataBuffer[k]);
-												}
-												printf("\n");
-												
-												printf("startAddr = 0x%x,endAddr = 0x%x\n",
-													FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter-1)*100,FLASH_FOTA_REGION_START+updateDifferDataPackageCounter*100-1);
-											#endif
-											*/			
+											{															
 												//write the buffer(100 byte) to flash
-												ret = (uint8_t)BSP_QSPI_Write_Safe(updateDataBuffer,FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter-1)*100,100);
+												ret = (uint8_t)BSP_QSPI_Write_Safe(updateDataBuffer,FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter)*100,100);
 												errorCount = 0;
 												while(ret != QSPI_OK && errorCount<3)  //try to write most 3 times
 												{
 													errorCount++;
-													BSP_QSPI_Erase_Safe(FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter-1)*100,100);
-													ret = (uint8_t)BSP_QSPI_Write_Safe(updateDataBuffer,FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter-1)*100,100);
+													BSP_QSPI_Erase_Safe(FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter)*100,100);
+													ret = (uint8_t)BSP_QSPI_Write_Safe(updateDataBuffer,FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter)*100,100);
 												}
-												if(ret == QSPI_OK)
+												if(ret == QSPI_OK)  // write successed
 												{
-													UDSPositiveAnswer(0x08,i,tempSliceCounter);												
+													UDSPositiveAnswer(0x08,i,tempSliceCounter);	
+				/*									
+													#if 0
+													#ifdef USING_PRINTF
+														UINT8 checksum0,checksum1=0;
+														printf("updateDifferDataPackageCounter = %d\n",updateDifferDataPackageCounter);
+														printf("updateDataBuffer write:\n");
+														for(k=0;k<100;k++)
+														{
+															printf("%x  ",updateDataBuffer[k]);
+															checksum0+=updateDataBuffer[k];
+														}
+														printf("\n");	
+														
+														UINT8 readFlash=0;
+														printf("updateDataBuffer read:\n");
+														
+														for(k=0;k<100;k++)
+														{
+															BSP_QSPI_Read_Safe(&readFlash,FLASH_FOTA_REGION_START+updateDifferDataPackageCounter*100+k, 1);
+															printf("%2x ",readFlash);
+															checksum1+=readFlash;
+														}
+														printf("\n");
+														if(checksum0 == checksum1)
+														{
+															printf("write succeed!\nchecksum0 = %2x,checksum1 = %2x\n",checksum0,checksum1);
+														}
+														else
+														{
+															printf("write fail!\nchecksum0 = %2x,checksum1 = %2x\n",checksum0,checksum1);
+														}
+														//printf("write succeed, next updateDifferDataPackageCounter = %x\n",updateDifferDataPackageCounter+1);
+													#endif
+													#endif
+*/
+													memset(updateDataBuffer,0, 100);
+													sliceCounterFlag = 0x0;
+													updateDifferDataPackageCounter++;
 												}
-												else
+												else  //write fail
 												{
 													UDSNegtiveAnswer(0x08,i,0xFFFFFFFF);  //failed to write this package to flash
+													/*
+													#if 0
+													#ifdef USING_PRINTF
+														printf("write flash fail!! updateDifferDataPackageCounter = %d\n",updateDifferDataPackageCounter);
+														printf("ERROR: sliceCounterFlag=%x\n",sliceCounterFlag);
+													#endif
+													#endif
+													*/
 												}
-												memset(updateDataBuffer,0, 100);
-												sliceCounterFlag = 0x0;
-												
 											}
 											else
 											{
 												//received 25 messages, but lose one or more messages
 												//in this case, updater will try to send the package again(most 4 times)
-												UDSNegtiveAnswer(0x08,i,sliceCounterFlag);  
+												UDSNegtiveAnswer(0x08,i,sliceCounterFlag);
+												#ifdef USING_PRINTF
+														printf("ERROR: package lose one or mo message!! sliceCounterFlag = %x\n",sliceCounterFlag);
+												#endif
 												//sliceCounterFlag = 0x0;
 												/*
 											#ifdef USING_PRINTF
@@ -465,6 +476,7 @@ void UDS_Service()
 									else
 									{
 										UDSNegtiveAnswer(0x05,i,0xEF); //the download process is not ready
+										counter = 0;
 									}
 								}
 								else
@@ -478,6 +490,20 @@ void UDS_Service()
 									if(UDSSubService[i] == 0x0F)  // exit the download 
 									 {
 										UDSPositiveAnswer(0x04,i,0x00);
+									/*
+									#if 0
+									#ifdef USING_PRINTF
+										printf("CAN update data:\n");
+										UINT8 ts=0;
+										for(UINT32 jjj =0;jjj<updateDifferDataByteLen;jjj++)
+										{											
+											BSP_QSPI_Read_Safe(&ts,FLASH_FOTA_REGION_START+jjj,1);
+											printf("%x ",ts);
+										}
+										printf("\n");
+									#endif
+									#endif
+									*/
 										downloadReady = FALSE;
 									 }
 									 else
@@ -616,7 +642,7 @@ BOOL UDSAskforDownLoadData()
 BOOL UDSClearFotaDownloadRegion()
 {
 	UINT8 ret = FALSE;
-	ret = BSP_QSPI_Erase_Safe(FLASH_FOTA_REGION_START, 0x78000); //512k-32k = 480k -> 0x75300
+	ret = BSP_QSPI_Erase_Safe(FLASH_FOTA_REGION_START, 0x46000); //512k-32k -200k = 280k -> 0x46000
 	
 	if(ret == QSPI_OK)
 	{

+ 385 - 230
src/UartTask.c

@@ -32,13 +32,19 @@
 #include "app.h"
 #include "numeric.h"
 #include "Fota.h"
-
+#include "signal.h"
 //全局变量输入区
 extern UINT32 Timer_count;
-extern volatile bool Sleep_flag; 
+extern volatile BOOL Sleep_flag; 
 extern AppNVMDataType AppNVMData;
 //全局变量输出区
-UartReadMsgType UartReadMsg;
+
+
+
+BOOL UartBattInfoRecvFlag  = false;
+
+
+
 osMutexId_t UartMutex = NULL;//Uart数据锁
 QueueHandle_t UartWriteCmdHandle = NULL;
 UINT8 BattChrgEndFlag;
@@ -59,11 +65,14 @@ static process_Uart             gProcess_Uart_Task = PROCESS_UART_STATE_IDLE;
 //函数声明区
 void USART_callback(uint32_t event);
 UINT8 Uart_DataRecv_func(UINT8* Uart_Read_Msg,UINT8* Uart_Recv_Buffer);
+static BOOL uartBattInfoDecode(UINT8* dataPtr);
 UINT8 Uart_WriteCmd_func(Uart_Write_Data_Type UartWriteData);
 UINT16 crc_chk(UINT8* data, UINT8 length);
 void battSOCDisplay(void);
 void battErrorStateDisplay(void);
+void battWarningStateDisplay(void);
 void battLockStateDisplay(UINT8 lockState);
+void relayPWMControl(void);
 void SP_BMS_Update_Service(void);
 BOOL BattHeaterSwitch(UINT8* heaterSwitch);
 UINT16  encryptionAlgorithm (UINT16 plainText);
@@ -93,6 +102,8 @@ static void UartTask(void* arg)
 	BOOL uartReadSuccessFlag = false;
     Uart_Read_Msg_Type Uart_Read_Msg;
     Uart_Write_Data_Type UartWriteData; //Uart控制命令
+    UartReadMsgType UartReadMsg;
+    memset(&(UartReadMsg.UartFlag),0x00,sizeof(UartReadMsgType));
     if(UartWriteCmdHandle == NULL)//Uart控制命令传输指针
 	{
 		UartWriteCmdHandle = osMessageQueueNew(3,sizeof(Uart_Write_Data_Type), NULL);
@@ -144,6 +155,13 @@ static void UartTask(void* arg)
 				{
 					uartReadSuccessFlag = true;
 				}
+				else
+				{
+					uartReadSuccessFlag = false;
+				}
+				#ifdef USING_PRINTF
+					printf("uartReadSuccessFlag = %d\n",uartReadSuccessFlag);
+				#endif
 				if(Timer_count-currentTimerCount >= 1)
 				{
 					if(AppNVMData.isBattLocked != 0)
@@ -155,6 +173,13 @@ static void UartTask(void* arg)
 						battSOCDisplay();
 						battErrorStateDisplay();
 					}
+					else
+					{
+						#ifdef USING_PRINTF
+							printf("battWarningStateDisplay\n");
+						#endif
+						battWarningStateDisplay();
+					}
 				}
 				currentTimerCount = Timer_count;
 				if(BMS_Fota_update_flag)
@@ -179,7 +204,7 @@ static void UartTask(void* arg)
             }
             case PROCESS_UART_STATE_READ:
             {
-				osStatus_t result = osMutexAcquire(UartMutex, osWaitForever);
+                
                 Reg_Num = 0x21+BATT_CELL_VOL_NUM+BATT_TEMP_NUM + 2;//按照协议里面的0x21+X+N的结束地址
                 Uart_Read_Msg.Bms_Address = BMS_ADDRESS_CODE;
                 Uart_Read_Msg.Bms_Funcode = UART_READ_CODE;
@@ -188,19 +213,21 @@ static void UartTask(void* arg)
                 Uart_Read_Msg.Reg_Num_H = Reg_Num>>8;
                 Uart_Read_Msg.Reg_Num_L = Reg_Num;
                 Uart_Uds_LEN = Reg_Num*2;
+                memset(UartReadMsg.Header,0x00,Uart_Uds_LEN);
                 Uart_Recv_LEN = Uart_DataRecv_func((UINT8 *)&Uart_Read_Msg,UartReadMsg.Header);
-				osMutexRelease(UartMutex);
+				//osMutexRelease(UartMutex);
 				if(Uart_Recv_LEN>0)
 				{
-					UartReadMsg.UartFlag = TRUE;
+					UartBattInfoRecvFlag =  TRUE;
+					uartBattInfoDecode(UartReadMsg.data);
 				}
 				else
 				{
-					UartReadMsg.UartFlag = FALSE;
+					UartBattInfoRecvFlag =  FALSE;
 				}
                 UartReadMsg.len = Uart_Recv_LEN;
                 PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
-                if((UartReadMsg.data[(0x03+BATT_CELL_VOL_NUM)*2+1]&0x03)==0x02)
+                if( battWorkState ==0x02)
                 {
                     BattChrgEndFlag=TRUE;
                 }
@@ -208,7 +235,7 @@ static void UartTask(void* arg)
                 {
                     BattChrgEndFlag=FALSE;
                 }
-				#ifdef USING_PRINTF1
+				#ifdef USING_PRINTF
 					printf("\nUart_Recv_buffer:  ");
 					for(int i=0;i<Uart_Recv_LEN;i++)
 					{
@@ -239,9 +266,103 @@ static void UartTask(void* arg)
 				osThreadExit();
                 break;
             }
+
         }
     }
 }
+
+
+
+
+//Uart 接收的数据解码
+static BOOL uartBattInfoDecode(UINT8* dataPtr)
+{
+	OsaUtcTimeTValue TimeStracture;
+	//BattInfoType battInfo;
+	UINT8 i,temp=0;
+    UINT8 TEMP_NUM = BATT_TEMP_NUM + BATT_OTHER_TEMP_NUM;
+    UINT16 Batt_current;
+    for(i=0;i<BATT_CELL_VOL_NUM;i++)
+    {
+		battCellU[i] = (dataPtr[(0x02+i)*2] << 8) | dataPtr[(0x02+i)*2 + 1];
+    }
+    
+    battWorkState = (dataPtr[(0x03+BATT_CELL_VOL_NUM)*2+1])&0x03;//电池状态(原始数据),0表示静置,1表示放电,2表示充电
+    
+    for(i=0; i<BATT_TEMP_NUM; i++)
+    {
+	    battCellTemp[i] = dataPtr[(0x06+BATT_CELL_VOL_NUM+i)*2+1];
+    }
+    MOSTemp = dataPtr[(0x06+BATT_CELL_VOL_NUM+BATT_TEMP_NUM)*2+1];
+   	packTemp = dataPtr[(0x06+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+1)*2+1];
+    
+    Batt_current = (dataPtr[(0x02+BATT_CELL_VOL_NUM)*2]<<8)|(dataPtr[(0x02+BATT_CELL_VOL_NUM)*2+1]);
+    #ifdef USING_PRINTF
+		printf("Batt_current = %x\n",Batt_current);
+	#endif
+    //原始数据:充电为负,放电为正
+    if (Batt_current>0x8000) //为负,充电数据
+    {
+        Batt_current = (UINT16)((UINT16)(~(Batt_current))+1);
+        Batt_current = Batt_current/10;
+        Batt_current = -Batt_current + 0x2710;//平台数据:充电为负
+        //Batt_current = Batt_current;
+    }
+    else  //为正,数据
+    {
+        Batt_current = Batt_current/10;
+        Batt_current = Batt_current + 0x2710;//平台数据:充电为负
+        //Batt_current = Batt_current;
+    }
+    battI = Batt_current;
+	#ifdef USING_PRINTF
+		printf("battI = %x\n",battI);
+	#endif
+    //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);
+
+    bmsHwVersion = dataPtr[(0x08+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]; 
+    bmsSwVersion = dataPtr[(0x08+BATT_CELL_VOL_NUM+TEMP_NUM)*2];    
+
+    temp = ((dataPtr[(0x09+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1])>>1)&0x03;    
+    battMOSSwitchState = ((temp&0x01)<<1)|((temp&0x02)>>1);	
+    if(AppNVMData.isBattLocked==TRUE)
+    {
+        battMOSSwitchState = battMOSSwitchState |(0x01<<2);
+    }
+    else
+    {
+        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]);
+    battSOC = dataPtr[(0x0B+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1];
+    battSOH = dataPtr[(0x0C+BATT_CELL_VOL_NUM+TEMP_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
+	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];
+
+    battHeatEnableState = dataPtr[(0x1C+BATT_CELL_VOL_NUM+TEMP_NUM)*2+1]&0x01;
+    
+	
+	
+	maxCellTemp = 0x00;
+	minCellTemp = 0xFF;
+	for(i=0;i<BATT_TEMP_NUM;i++)
+	{
+		maxCellTemp = max(maxCellTemp,battCellTemp[i]);
+		minCellTemp = min(minCellTemp,battCellTemp[i]);		
+	}
+	nbSwVersion = APPSWVERSION;
+	nbHwVersion = HWVERSION;
+	
+    return true;
+}
+
+
+
+
+
+
 //Uart线程初始化
 void UartTaskInit(void *arg)
 {
@@ -358,7 +479,7 @@ UINT8 Uart_WriteCmd_func(Uart_Write_Data_Type UartWriteData)
             {
             printf("%x ",Uart_Recv_Buffer[i]);
             }
-            printf("n");
+            printf("\n");
         #endif
         isRecvComplete = false;
         if(Uart_Recv_Buffer[1]==0x10)
@@ -416,30 +537,26 @@ UINT8 Uart_DataRecv_func(UINT8* Uart_Read_Msg,UINT8* Uart_Recv_Buffer)
             }
         } 
     }
-	#ifdef USING_PRINTF  
-             printf("%s[%d]\r\n",__FUNCTION__, __LINE__);
-             printf("timeout = %d\n",timeout);
-            #endif
-    #ifdef USING_PRINTF1
-        printf("Uart_Rece_buffer: ");
-        for(int i=0;i<Data_Len;i++)
-        {
-        printf("%x ",*(Uart_Recv_Buffer+i));
-        }
-    #endif
+     #ifdef USING_PRINTF
+         printf("Uart_Rece_buffer1: ");
+         for(int i=0;i<Data_Len;i++)
+         {
+         printf("%x ",*(Uart_Recv_Buffer+i));
+         }
+     #endif
     if (isRecvComplete == true)
     {
         isRecvComplete = false;
         CRC_Rece_buffer =*(Uart_Recv_Buffer+Data_Len-1)<<8|*(Uart_Recv_Buffer+Data_Len-2);
         CRC_chk_buffer = crc_chk(Uart_Recv_Buffer,Data_Len-2);
-        // #ifdef USING_PRINTF
-        //     printf("Uart_Rece_buffer after Crc: ");
-        //     for(int i=0;i<Data_Len;i++)
-        //     {
-        //     printf("%x ",*(Uart_Recv_Buffer+i));
-        //     }
-        //     printf("\tcrcchk:%x,%x\n ",CRC_chk_buffer,CRC_Rece_buffer);
-        // #endif
+	    #ifdef USING_PRINTF
+	         printf("Uart_Rece_buffer after Crc: ");
+	         for(int i=0;i<Data_Len;i++)
+	         {
+	         	printf("%x ",*(Uart_Recv_Buffer+i));
+	   	     }
+	         printf("\tcrcchk:%x,%x\n ",CRC_chk_buffer,CRC_Rece_buffer);
+	    #endif
         if (CRC_Rece_buffer == CRC_chk_buffer)//满足校验
         {
             return Data_Len;//此处指针移位出现重启问题
@@ -479,32 +596,17 @@ BOOL BattHeaterSwitch(UINT8* heaterSwitch)
 {
 	BOOL isNeedtoSwitch = FALSE;
 	
-	UINT8 battCellTemp[BATT_TEMP_NUM];
-	UINT8 maxCellTemp,minCellTemp;
-	
 	UINT8 i =0;	
 	UINT8 currentSwitchState = 0;
 
 	//get the current switch state and the cell temp
-	currentSwitchState = UartReadMsg.data[(0x1C+BATT_CELL_VOL_NUM+(BATT_TEMP_NUM+2))*2+1]&0x01;
-	for(int i=0; i<BATT_TEMP_NUM; i++)
-    {
-	    battCellTemp[i] = UartReadMsg.data[(0x06+BATT_CELL_VOL_NUM+i)*2+1];	    
-    }
-
-        //cal the maxtemp and mintemp
-        maxCellTemp = battCellTemp[0];
-        minCellTemp = battCellTemp[0];
-    for(i=1;i<BATT_TEMP_NUM;i++)
-    {
-		maxCellTemp = max(maxCellTemp,battCellTemp[i]);
-        minCellTemp = min(minCellTemp,battCellTemp[i]);
-    }
-
+	currentSwitchState = battMOSSwitchState & 0x01;
+	
+	
     
 	if(currentSwitchState==0) 	//当前状态为关闭,判断是否应该开启
 	{
-		if(minCellTemp<=5+40 && maxCellTemp<25+40)//温度偏移为40 
+		if(minCellTemp<=5+40 && maxCellTemp<25+40 && battSOC>=12)//温度偏移为40 
 		{
 			*heaterSwitch = 1;
 			isNeedtoSwitch = true;
@@ -512,7 +614,7 @@ BOOL BattHeaterSwitch(UINT8* heaterSwitch)
 	}
 	else  						//当前状态为开启,判断是否应该关闭
 	{
-		if(minCellTemp>10+40||maxCellTemp>30+40)
+		if(minCellTemp>10+40 || maxCellTemp>30+40 || battSOC<10)
 		{
 			*heaterSwitch = 0;
 			isNeedtoSwitch= true;
@@ -523,8 +625,7 @@ BOOL BattHeaterSwitch(UINT8* heaterSwitch)
 
 void battSOCDisplay()
 {
-	static UINT8 workState;
-	static UINT8 currentSoc;
+	
 	static UINT8 lightTimer = 0;
 	UINT8 socLowLEDFlashPeriod = 10;//10*100 = 1000ms
 	UINT8 chargeLEDFlashPeriod = 6;//6*100 = 600ms
@@ -536,195 +637,187 @@ void battSOCDisplay()
 		return;
 	}
 	
-	if(UartReadMsg.Header[2]>0)
-	{
-		temp = UartReadMsg.data[(0x03+BATT_CELL_VOL_NUM)*2+1]&0x03;
-	    workState = ((temp&0x01)<<01)|(temp>>0x01);
-	    currentSoc = UartReadMsg.data[(0x0B+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+2)*2+1];
-	}
-	#ifdef USING_PRINTF1
-		printf("current SOC = %d\n",currentSoc);
-		printf("work state = %d\n",workState);
-	#endif
-
-	lightTimer++;
-	
-	if(workState == 0||workState == 2)  //静置或放电状态
-	{
-		if(currentSoc<=10)
+	if(UartBattInfoRecvFlag == true)
+	{ 
+		lightTimer++;
+		
+		if(battWorkState == 0||battWorkState == 1)  //静置或放电状态
 		{
-			if(lightTimer<(UINT8)(socLowLEDFlashPeriod*dutyRatio))
-			{
-				NetSocDisplay(LED_SOC_0,LED_TURN_ON);
-				NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
-			}
-			else if(lightTimer>=(UINT8)(socLowLEDFlashPeriod*dutyRatio) && lightTimer<socLowLEDFlashPeriod)
-			{
-				NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
-			}
-			else
+			if(battSOC<=10)
 			{
-				NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
-				lightTimer = 0;
-			}			
-		}	
-		else if(currentSoc>10&&currentSoc<=25)
-		{
-			NetSocDisplay(LED_SOC_0,LED_TURN_ON);
-			NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
-			NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
-			NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
-			lightTimer = 0;
-		}
-		else if(currentSoc>25&&currentSoc<=50)
-		{
-			NetSocDisplay(LED_SOC_0,LED_TURN_ON);
-			NetSocDisplay(LED_SOC_1,LED_TURN_ON);
-			NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
-			NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
-			lightTimer = 0;
-		}
-		else if(currentSoc>50&&currentSoc<=75)
-		{
-			NetSocDisplay(LED_SOC_0,LED_TURN_ON);
-			NetSocDisplay(LED_SOC_1,LED_TURN_ON);
-			NetSocDisplay(LED_SOC_2,LED_TURN_ON);
-			NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
-			lightTimer = 0;
-		}
-		else if(currentSoc>75&&currentSoc<=100)
-		{
-			NetSocDisplay(LED_SOC_0,LED_TURN_ON);
-			NetSocDisplay(LED_SOC_1,LED_TURN_ON);
-			NetSocDisplay(LED_SOC_2,LED_TURN_ON);
-			NetSocDisplay(LED_SOC_3,LED_TURN_ON);
-			lightTimer = 0;
-		}
-	}
-	else if(workState == 1)
-	{
-		if(currentSoc<=25)
-		{
-			if(lightTimer<(UINT8)(chargeLEDFlashPeriod*dutyRatio))
+				if(lightTimer<(UINT8)(socLowLEDFlashPeriod*dutyRatio))
+				{
+					NetSocDisplay(LED_SOC_0,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
+				}
+				else if(lightTimer>=(UINT8)(socLowLEDFlashPeriod*dutyRatio) && lightTimer<socLowLEDFlashPeriod)
+				{
+					NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
+				}
+				else
+				{
+					NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
+					lightTimer = 0;
+				}			
+			}	
+			else if(battSOC>10&&battSOC<=25)
 			{
 				NetSocDisplay(LED_SOC_0,LED_TURN_ON);
 				NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
 				NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
 				NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
-			}
-			else if(lightTimer>=(UINT8)(chargeLEDFlashPeriod*dutyRatio) && lightTimer<chargeLEDFlashPeriod)
-			{
-				NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
-			}
-			else
-			{
-				NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
 				lightTimer = 0;
-			}			
-		}	
-		else if(currentSoc>25&&currentSoc<=50)
-		{
-			if(lightTimer<(UINT8)(chargeLEDFlashPeriod*dutyRatio))
-			{
-				NetSocDisplay(LED_SOC_0,LED_TURN_ON);
-				NetSocDisplay(LED_SOC_1,LED_TURN_ON);
-				NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
 			}
-			else if(lightTimer>=(UINT8)(chargeLEDFlashPeriod*dutyRatio) && lightTimer<chargeLEDFlashPeriod)
+			else if(battSOC>25&&battSOC<=50)
 			{
 				NetSocDisplay(LED_SOC_0,LED_TURN_ON);
-				NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
+				NetSocDisplay(LED_SOC_1,LED_TURN_ON);
 				NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
 				NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
-			}
-			else
-			{
-				NetSocDisplay(LED_SOC_0,LED_TURN_ON);
-				NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
 				lightTimer = 0;
 			}
-		}
-		else if(currentSoc>50&&currentSoc<=75)
-		{
-			if(lightTimer<(UINT8)(chargeLEDFlashPeriod*dutyRatio))
+			else if(battSOC>50&&battSOC<=75)
 			{
 				NetSocDisplay(LED_SOC_0,LED_TURN_ON);
 				NetSocDisplay(LED_SOC_1,LED_TURN_ON);
 				NetSocDisplay(LED_SOC_2,LED_TURN_ON);
 				NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
+				lightTimer = 0;
 			}
-			else if(lightTimer>=(UINT8)(chargeLEDFlashPeriod*dutyRatio) && lightTimer<chargeLEDFlashPeriod)
-			{
-				NetSocDisplay(LED_SOC_0,LED_TURN_ON);
-				NetSocDisplay(LED_SOC_1,LED_TURN_ON);
-				NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
-			}
-			else
+			else if(battSOC>75&&battSOC<=100)
 			{
 				NetSocDisplay(LED_SOC_0,LED_TURN_ON);
 				NetSocDisplay(LED_SOC_1,LED_TURN_ON);
-				NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
-				NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
+				NetSocDisplay(LED_SOC_2,LED_TURN_ON);
+				NetSocDisplay(LED_SOC_3,LED_TURN_ON);
 				lightTimer = 0;
 			}
-
 		}
-		else if(currentSoc>75&&currentSoc<=97)
+		else if(battWorkState == 2)
 		{
-			if(lightTimer<(UINT8)(chargeLEDFlashPeriod*dutyRatio))
+			if(battSOC<=25)
 			{
-				NetSocDisplay(LED_SOC_0,LED_TURN_ON);
-				NetSocDisplay(LED_SOC_1,LED_TURN_ON);
-				NetSocDisplay(LED_SOC_2,LED_TURN_ON);
-				NetSocDisplay(LED_SOC_3,LED_TURN_ON);	
+				if(lightTimer<(UINT8)(chargeLEDFlashPeriod*dutyRatio))
+				{
+					NetSocDisplay(LED_SOC_0,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
+				}
+				else if(lightTimer>=(UINT8)(chargeLEDFlashPeriod*dutyRatio) && lightTimer<chargeLEDFlashPeriod)
+				{
+					NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
+				}
+				else
+				{
+					NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
+					lightTimer = 0;
+				}			
+			}	
+			else if(battSOC>25&&battSOC<=50)
+			{
+				if(lightTimer<(UINT8)(chargeLEDFlashPeriod*dutyRatio))
+				{
+					NetSocDisplay(LED_SOC_0,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_1,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
+				}
+				else if(lightTimer>=(UINT8)(chargeLEDFlashPeriod*dutyRatio) && lightTimer<chargeLEDFlashPeriod)
+				{
+					NetSocDisplay(LED_SOC_0,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
+				}
+				else
+				{
+					NetSocDisplay(LED_SOC_0,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
+					lightTimer = 0;
+				}
 			}
-			else if(lightTimer>=(UINT8)(chargeLEDFlashPeriod*dutyRatio) && lightTimer<chargeLEDFlashPeriod)
+			else if(battSOC>50&&battSOC<=75)
 			{
-				NetSocDisplay(LED_SOC_0,LED_TURN_ON);
-				NetSocDisplay(LED_SOC_1,LED_TURN_ON);
-				NetSocDisplay(LED_SOC_2,LED_TURN_ON);
-				NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
+				if(lightTimer<(UINT8)(chargeLEDFlashPeriod*dutyRatio))
+				{
+					NetSocDisplay(LED_SOC_0,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_1,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_2,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
+				}
+				else if(lightTimer>=(UINT8)(chargeLEDFlashPeriod*dutyRatio) && lightTimer<chargeLEDFlashPeriod)
+				{
+					NetSocDisplay(LED_SOC_0,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_1,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
+				}
+				else
+				{
+					NetSocDisplay(LED_SOC_0,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_1,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
+					NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
+					lightTimer = 0;
+				}
+
 			}
-			else
+			else if(battSOC>75&&battSOC<=97)
+			{
+				if(lightTimer<(UINT8)(chargeLEDFlashPeriod*dutyRatio))
+				{
+					NetSocDisplay(LED_SOC_0,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_1,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_2,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_3,LED_TURN_ON);	
+				}
+				else if(lightTimer>=(UINT8)(chargeLEDFlashPeriod*dutyRatio) && lightTimer<chargeLEDFlashPeriod)
+				{
+					NetSocDisplay(LED_SOC_0,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_1,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_2,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
+				}
+				else
+				{
+					NetSocDisplay(LED_SOC_0,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_1,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_2,LED_TURN_ON);
+					NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
+					lightTimer = 0;
+				}
+			}
+			else if(battSOC>97&&battSOC<=100)
 			{
 				NetSocDisplay(LED_SOC_0,LED_TURN_ON);
 				NetSocDisplay(LED_SOC_1,LED_TURN_ON);
 				NetSocDisplay(LED_SOC_2,LED_TURN_ON);
-				NetSocDisplay(LED_SOC_3,LED_TURN_OFF);	
-				lightTimer = 0;
-			}
+				NetSocDisplay(LED_SOC_3,LED_TURN_ON);	
+			}		
 		}
-		else if(currentSoc>97&&currentSoc<=100)
-		{
-			NetSocDisplay(LED_SOC_0,LED_TURN_ON);
-			NetSocDisplay(LED_SOC_1,LED_TURN_ON);
-			NetSocDisplay(LED_SOC_2,LED_TURN_ON);
-			NetSocDisplay(LED_SOC_3,LED_TURN_ON);	
-		}		
 	}
 	
 }
+
 void battErrorStateDisplay()
-{
-	static UINT32 errorState;	
+{	
 	static UINT8  errorLightTimer = 0;
 	//static UINT32 currentTimerCount=0;
 	
@@ -736,46 +829,84 @@ void battErrorStateDisplay()
 		return;
 	}
 	
-	if(UartReadMsg.Header[2]>0)
-	{
-		errorState = ((UartReadMsg.data[(0x09+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+2)*2])<<8)|0|((UartReadMsg.data[(0x0A+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+2)*2])<<24)|((UartReadMsg.data[(0x0A+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+2)*2+1])<<16);
-		//MEMCPY(&errorState,&(UartReadMsg.data[(0x09+BATT_CELL_VOL_NUM+BATT_TEMP_NUM+2)*2]),4); 
-	}
+	if(UartBattInfoRecvFlag == true)
+	{	
 	
-	errorLightTimer++;
-	
-	//errorState = testErrorState;
-	#ifdef USING_PRINTF1
-		for(int k=0;k<UartReadMsg.Header[2];k++)
-			printf("%x  ",UartReadMsg.data[k]);
-		printf("error state = %x\n",errorState);
-	#endif
-	if(errorState != 0)
-	{
-		if(errorLightTimer<(UINT8)(errorLEDFlashPeriod*errorDutyRatio)) 
-		{				
-			FaultDisplay(LED_TURN_ON);
-			
-		}
-		else if(errorLightTimer>=(UINT8)(errorLEDFlashPeriod*errorDutyRatio) && errorLightTimer<errorLEDFlashPeriod)
+		errorLightTimer++;
+
+		if(battWarningState != 0)
 		{
-			FaultDisplay(LED_TURN_OFF);
+			if(errorLightTimer<(UINT8)(errorLEDFlashPeriod*errorDutyRatio)) 
+			{	
+				
+				FaultDisplay(LED_TURN_ON);
+				
+			}
+			else if(errorLightTimer>=(UINT8)(errorLEDFlashPeriod*errorDutyRatio) && errorLightTimer<errorLEDFlashPeriod)
+			{
+				
+				FaultDisplay(LED_TURN_OFF);
+				
+			}
+			else
+			{
+				
+				FaultDisplay(LED_TURN_OFF);
+				errorLightTimer = 0;			
+			}
 			
 		}
 		else
 		{
 			FaultDisplay(LED_TURN_OFF);
-			errorLightTimer = 0;			
-		}
-		
+			errorLightTimer = 0;
+		}	
 	}
-	else
-	{
-		FaultDisplay(LED_TURN_OFF);
-		errorLightTimer = 0;
-	}	
 }
 
+void battWarningStateDisplay()
+{
+	static UINT8  warningLightTimer = 0;
+	//static UINT32 currentTimerCount=0;
+	
+	UINT8  warningLEDFlashPeriod = 6;//600ms
+	float warningDutyRatio = 0.4;
+
+	if(AppNVMData.isBattLocked == TRUE)
+	{
+		return;
+	}
+	
+	if(UartBattInfoRecvFlag == false)
+	{		
+		warningLightTimer++;
+
+		//if(battWarningState != 0)
+		{
+			if(warningLightTimer<(UINT8)(warningLEDFlashPeriod*warningDutyRatio)) 
+			{			
+				NetSocDisplay(LED_SOC_0,LED_TURN_ON);
+				FaultDisplay(LED_TURN_ON);
+				
+			}
+			else if(warningLightTimer>=(UINT8)(warningLEDFlashPeriod*warningDutyRatio) && warningLightTimer<warningLEDFlashPeriod)
+			{
+				NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
+				FaultDisplay(LED_TURN_OFF);
+				
+			}
+			else
+			{
+				NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
+				FaultDisplay(LED_TURN_OFF);
+				warningLightTimer = 0;			
+			}
+			
+		}
+			
+	}
+
+}
 
 
 void battLockStateDisplay(UINT8 lockState)
@@ -837,7 +968,30 @@ void battLockStateDisplay(UINT8 lockState)
 	}	
 	errorLightTimer++;
 }
-  
+
+void relayPWMControl()
+{
+	static UINT8 timerCount=0;
+	//printf("timerCout=%d\n",timerCount);
+	if(timerCount<2)
+	{
+		relayControl(TRUE);
+		timerCount++;
+	}
+	else if(timerCount>=2 && timerCount<5)
+	{
+		relayControl(FALSE);
+		timerCount++;
+	}
+	else
+	{
+		relayControl(FALSE);
+		timerCount = 0;
+	}
+}
+
+
+
 UINT8  decryptionAlgorithm (UINT16 cipherText)
 {
 	UINT16 plainText = 1;	
@@ -1731,6 +1885,7 @@ void SP_BMS_Update_Service() //超力源BMS升级服务
 
 UINT8 SP_BMS_Update_Query(UINT8* pSend,UINT32 sendLen, UINT8* pRead, UINT32 readLen, UINT32 timeout)
 {
+
 	UINT8 timeCount = 0;
 	UINT8 j=0;
 	USARTdrv->Send(pSend,sendLen);

+ 2 - 0
src/bsp_custom.c

@@ -150,6 +150,7 @@ void BSP_CustomInit(void)
 
     BSP_LoadPlatConfigFromRawFlash();
     rawFlashPlatConfig = BSP_GetRawFlashPlatConfig();
+ #if 1
 #ifdef USING_PRINTF
 	SetPrintUart(PORT_USART_0);
 #else
@@ -159,6 +160,7 @@ void BSP_CustomInit(void)
         uniLogInitStart(UART_0_FOR_UNILOG);
         ECOMM_STRING(UNILOG_PLA_STRING, build_info, P_SIG, "%s", getBuildInfo());
     }
+#endif
 #endif
 
 	slpManGetPMUSettings();				

+ 4 - 1
src/hal_module_adapter.c

@@ -2143,6 +2143,9 @@ void PowerPinConfig(IOType iotype)
 	
       if(iotype == AON_IO)
 	{
+		slpManAONIOVoltSet(IOVOLT_3_30V);//zhengchao 20200412 add
+
+		
 		padConfig.mux = PAD_MuxAlt0;
 
 		PAD_SetPinConfig(35, &padConfig);
@@ -2155,7 +2158,7 @@ void PowerPinConfig(IOType iotype)
 
 		PAD_SetPinConfig(32, &padConfig);
 		GPIO_PinConfig(1, AON_RELAY_DRV, &config);
-		GPIO_PinWrite(1, 1 << AON_RELAY_DRV, 1 << AON_RELAY_DRV);
+		GPIO_PinWrite(1, 1 << AON_RELAY_DRV, 0 << AON_RELAY_DRV);  //zhengchao 20200412 modify 1-->0
 
 		PAD_SetPinConfig(35, &padConfig);
 		GPIO_PinConfig(1, AON_WAKEUP, &config);