CHENJIE-PC\QiXiang_CHENJIE 3 роки тому
батько
коміт
7fc8bb5ce5
21 змінених файлів з 344 додано та 7374 видалено
  1. 2 11
      ARMCC/Makefile
  2. 101 0
      inc/AppConfig.h
  3. 0 2
      inc/CANEncode.h
  4. 26 7
      inc/MainTask.h
  5. 65 43
      inc/Signal.h
  6. 0 12
      inc/UDSService.h
  7. 23 110
      inc/app.h
  8. 0 143
      inc/cisAsynEntry.h
  9. 0 234
      src/CANEncode.c
  10. 0 273
      src/CANTask.c
  11. 0 289
      src/Fota.c
  12. 0 210
      src/GpsTask.c
  13. 33 191
      src/MainTask.c
  14. 76 56
      src/Signal.c
  15. 0 950
      src/TcpTask.c
  16. 0 657
      src/UDSService.c
  17. 0 2919
      src/UartTask.c
  18. 14 36
      src/app.c
  19. 3 3
      src/bsp_custom.c
  20. 0 1227
      src/cisAsynEntry.c
  21. 1 1
      src/hal_module_adapter.c

+ 2 - 11
ARMCC/Makefile

@@ -15,18 +15,9 @@ CFLAGS_INC        +=  -I ../inc
 
 
 obj-y             += PLAT/project/$(TARGET)/apps/qx_app/src/app.o \
-                     PLAT/project/$(TARGET)/apps/qx_app/src/cisAsynEntry.o \
 		     		PLAT/project/$(TARGET)/apps/qx_app/src/bsp_custom.o \
 					PLAT/project/$(TARGET)/apps/qx_app/src/hal_module_adapter.o \
+					PLAT/project/$(TARGET)/apps/qx_app/src/sensor.o \
 					PLAT/project/$(TARGET)/apps/qx_app/src/MainTask.o \
-					PLAT/project/$(TARGET)/apps/qx_app/src/UartTask.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/Signal.o\
-					PLAT/project/$(TARGET)/apps/qx_app/src/CANEncode.o\
-					PLAT/project/$(TARGET)/apps/qx_app/src/sensor.o
-
+					PLAT/project/$(TARGET)/apps/qx_app/src/Signal.o
 include $(TOP)/PLAT/tools/scripts/Makefile.rules

+ 101 - 0
inc/AppConfig.h

@@ -0,0 +1,101 @@
+/****************************************************************************
+ *
+ * Copy right:   2021-, Copyrigths of RLWL Ltd.
+ * File name:    app.h
+ * Description:  App Config H file
+ * History:      Rev3.0   2021-07-06
+ *
+ ****************************************************************************/
+
+#define BMS_MANUFACTURE (2)         //BMS制造商表示1-超力源,2-美顺
+#define DATA_MODULE_TYPE (1)        //1表示NB模块,2表示4G cat1
+#define BMS_INFO  (1)               //1-1表示超力源4830,1-2表示超力源6060,2-1表示美顺6455
+#define EOLSTATE (0)                //1标识下线检测跳过,使用默认值
+#define DEFAULT_SN                "RLTEST00000000001"
+#if  BMS_MANUFACTURE==1
+    #if BMS_INFO==1
+        #define BATT_CELL_VOL_NUM  (14)
+        #define BATT_TEMP_NUM  (3)
+        #define BATT_OTHER_TEMP_NUM  (2)
+    #elif BMS_INFO==2
+        #define BATT_CELL_VOL_NUM  (17)
+        #define BATT_TEMP_NUM  (4)
+        #define BATT_OTHER_TEMP_NUM  (2)
+    #endif
+#elif  BMS_MANUFACTURE==2
+    #if BMS_INFO==1
+        #define BATT_CELL_VOL_NUM  (20)
+        #define BATT_TEMP_NUM  (3)
+        #define BATT_OTHER_TEMP_NUM  (2)
+    #elif BMS_INFO==2
+        #define BATT_CELL_VOL_NUM  (17)
+        #define BATT_TEMP_NUM  (4)
+        #define BATT_OTHER_TEMP_NUM  (2)
+    #elif BMS_INFO==3
+        #define BATT_CELL_VOL_NUM  (20)
+        #define BATT_TEMP_NUM  (4)
+        #define BATT_OTHER_TEMP_NUM  (2)
+    #endif
+#endif
+
+#define NB_OTHER_TEMP_NUM  (4)                      //NB采集的温度个数
+#define BATT_CELL_VOL_NUM_2 (BATT_CELL_VOL_NUM*2)
+
+#define HWVERSION		    0x0102              //硬件主版本,现为V1.2板
+#define	BLSWVERSION		0x01020000              //BootLoader版本号V1.2.0.0
+#define	DRVSWVERSION		0x01050000          //驱动层版本号V1.4.0.0  驱动层1.5.0.0,增加了三轴
+#define	APPSWVERSION		0x03000000          //数据模块软件版本号
+#define APP_CONFIG_FILE_LATEST_VERSION 0
+#define APP_CONFIG_FILE_NAME  "qxappconfig.nvm"
+#define APP_DATAINFO_FILE_NAME  "qxappDataInfo.nvm"
+#define BATT_SN_LEN           17
+
+//declear struct vars   结构体变量定义
+typedef struct AppNVMDataType
+{	
+    BOOL   appDataModify;		//数据更改标志位
+	UINT8  battSN[BATT_SN_LEN]; //电池SN号码
+   	BOOL   isBattLocked;		//电池锁定状态0:not locked;	1:locked
+    UINT8  chargEndWorkTime;   //the unit is min 充电结束持续发送时间
+    UINT8  wakeupWorkTime;     //the unit is min 唤醒工作时间
+    UINT8  sleepTime;           //睡眠时间
+    UINT16 HwVersion;
+    UINT32 BLSwVersion;
+    UINT32 DrvSwVersion;
+    UINT32 AppSwVersion;
+	UINT8  EOLState;            //下线检测状态
+}AppNVMDataType;
+
+typedef struct AppConfigHeader
+{
+    UINT16 fileBodySize; //file body size, not include size of header;
+    UINT8  version;
+    UINT8  checkSum;
+}AppConfigHeader;
+
+typedef struct AppDataType
+{	
+    BOOL   appDataModify;		//数据更改标志位
+    UINT8  BmsChrgInfoSendFreq;
+    UINT8  BmsDisChrgInfoSendFreq;
+    UINT8  GpsChrgInfoSendFreq;
+    UINT8  GpsDisChrgInfoSendFreq;
+    INT8  BattCurrentNegFlag;
+    UINT32 CumulativeCapacity;
+    UINT32 AccMileage;
+    UINT16 SysReStart;
+}AppDataBody;
+typedef struct _AppDataHeader
+{
+    UINT16 fileBodySize; //file body size, not include size of header;
+    UINT8  checkSum;
+}AppDataHeader;
+
+
+typedef struct _UartAnswerMsg
+{
+	BOOL UartFlag;
+    UINT8 dataPtr[8];
+    UINT16 len;
+}UartAnswerMsgType;
+

+ 0 - 2
inc/CANEncode.h

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

+ 26 - 7
inc/MainTask.h

@@ -6,13 +6,28 @@
  * History:      2021-03-05
  *
  ****************************************************************************/
-//全局变量
-#include "app.h"
-extern UINT32 Timer_count;//每100ms加1
-extern volatile BOOL Sleep_flag;//睡眠标志位
-extern AppNVMDataType AppNVMData;
-extern AppDataBody AppDataInfo;
-/*---------------------------------------------------------------------------*/
+#include "commontypedef.h"
+#include "bsp.h"
+#include "bsp_custom.h"
+#include "osasys.h"
+#include "ostask.h"
+#include "queue.h"
+#include "ps_event_callback.h"
+#include "cmisim.h"
+#include "cmimm.h"
+#include "cmips.h"
+#include "sockets.h"
+#include "psifevent.h"
+#include "ps_lib_api.h"
+#include "lwip/netdb.h"
+#include "debug_log.h"
+#include "slpman_ec616.h"
+#include "plat_config.h"
+#include "ec_tcpip_api.h"
+#include "hal_module_adapter.h"
+#include "timers.h"
+#include "Signal.h"
+
 #define PROC_MAIN_TASK_STACK_SIZE           (1024+512)
 typedef enum
 {
@@ -22,3 +37,7 @@ typedef enum
 }process_Main;
 void MainTaskInit(void* arg);
 void MainTaskDeInit(void* arg);
+extern void GsensorInit(void);
+extern void GsensorI2CHandler(ARM_I2C_SignalEvent_t cb_event);
+extern void GsensorI2CCallback(UINT32 event);
+

+ 65 - 43
inc/Signal.h

@@ -1,56 +1,78 @@
+/****************************************************************************
+ *
+ * Copy right:   2021-, Copyrigths of RLWL Ltd.
+ * File name:    Signal.h
+ * Description:  Global variable definition H file
+ * History:      Rev3.0   2021-07-06
+ *
+ ****************************************************************************/
 #include "commontypedef.h"
 #include "cmsis_os2.h"
-extern	UINT16	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;
-
+#include "AppConfig.h"
+//declear the bool vars
+extern volatile BOOL NB_Fota_update_flag;
+extern volatile BOOL BMS_Fota_update_flag;
 
 
+//extern 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;
 
+extern UINT8   Lockstatus;
+extern UINT8   TcpErrorcount;
+extern UINT8   TcpSendLen;
+extern UINT8   CanMsgEnble;
+extern UINT8 	UDSSwitch;
 //declear the UINT16 vars
-extern	UINT16	battCellU[28];
-extern	UINT16	minCellVol;
-extern	UINT16	maxCellVol;
-extern	UINT16	battPackVol;
-extern	UINT16	battI;
-extern	UINT16	nbHwVersion;
+extern UINT16	battCellU[28];
+extern UINT16	minCellVol;
+extern UINT16	maxCellVol;
+extern UINT16	battPackVol;
+extern UINT16	battI;
+extern UINT16	nbHwVersion;
+extern UINT16   ErrorNum[5];
+
 
-extern UINT8 Lockstatus;
-extern UINT8 Error_count;
 
 //declear the UINT32 vars
-extern	UINT32	battWarningState;
-extern	UINT32	nbSwVersion;
-extern	UINT32	battBalanceoInfo;
-extern  UINT32  Battdesigncap;
+extern UINT32	battWarningState;
+extern UINT32	nbSwVersion ;
+extern UINT32	battBalanceoInfo;
+extern UINT32   Battdesigncap;
+extern UINT32  TimeCounter;
 
-extern UINT16   ErrorNum[5];//故障代码
-extern UINT8 	TcpSendLen;
 
+//declear other vars
 extern osMutexId_t Error_Mutex;
 
+
+extern UINT16	COMOutTable[28];
+ 
+extern AppNVMDataType AppNVMData;
+extern AppDataBody AppDataInfo;
+
+

+ 0 - 12
inc/UDSService.h

@@ -1,12 +0,0 @@
-#include "TcpTask.h"
-extern UINT8 	UDSSwitch;
-extern CAN_Msg_Type CanRxMsg[2];
-
-extern UINT8   BattSN[BATT_SN_LEN];  //ASCII code
-extern AppNVMDataType AppNVMData;
-extern AppSocketConnectionContext socContext;
-extern UINT8 GpsData[16];
-
-
-extern void appSaveNVMData(void);
-extern void UDS_Service(void);

+ 23 - 110
inc/app.h

@@ -1,122 +1,35 @@
 /****************************************************************************
  *
- * Copy right:   2017-, Copyrigths of EigenComm Ltd.
+ * Copy right:   2021-, Copyrigths of RLWL Ltd.
  * File name:    app.h
- * Description:  EC616 onenet demo entry header file
- * History:      Rev1.0   2018-07-12
+ * Description:  App definition H file
+ * History:      Rev3.0   2021-07-06
  *
  ****************************************************************************/
 #include "commontypedef.h"
-#ifndef  APP_H
-#define  APP_H
+#include "bsp.h"
+#include "bsp_custom.h"
+#include "osasys.h"
+#include "ostask.h"
+#include "queue.h"
+#include "ps_event_callback.h"
+#include "cmisim.h"
+#include "cmimm.h"
+#include "cmips.h"
+#include "sockets.h"
+#include "psifevent.h"
+#include "ps_lib_api.h"
+#include "lwip/netdb.h"
+#include "debug_log.h"
+#include "slpman_ec616.h"
+#include "plat_config.h"
+#include "ec_tcpip_api.h"
+#include "hal_module_adapter.h"
+#include "timers.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
-//全局定义声明区
-#define BMS_MANUFACTURE (2) //BMS制造商表示1-超力源,2-美顺
-#define DATA_MODULE_TYPE (1) //1表示NB模块,2表示4G cat1
-#define BMS_INFO  (1)       //1-1表示超力源4830,1-2表示超力源6060,2-1表示美顺6455
-#define EOLSTATE (0) //1标识下线检测跳过,使用默认值
-
-#if  BMS_MANUFACTURE==1
-    #if BMS_INFO==1
-        #define BATT_CELL_VOL_NUM  (14)
-        #define BATT_TEMP_NUM  (3)
-        #define BATT_OTHER_TEMP_NUM  (2)
-    #elif BMS_INFO==2
-        #define BATT_CELL_VOL_NUM  (17)
-        #define BATT_TEMP_NUM  (4)
-        #define BATT_OTHER_TEMP_NUM  (2)
-    #endif
-#elif  BMS_MANUFACTURE==2
-    #if BMS_INFO==1
-        #define BATT_CELL_VOL_NUM  (20)
-        #define BATT_TEMP_NUM  (3)
-        #define BATT_OTHER_TEMP_NUM  (2)
-    #elif BMS_INFO==2
-        #define BATT_CELL_VOL_NUM  (17)
-        #define BATT_TEMP_NUM  (4)
-        #define BATT_OTHER_TEMP_NUM  (2)
-    #elif BMS_INFO==3
-        #define BATT_CELL_VOL_NUM  (20)
-        #define BATT_TEMP_NUM  (4)
-        #define BATT_OTHER_TEMP_NUM  (2)
-    #endif
-#endif
-
-#define NB_OTHER_TEMP_NUM  (4)  //NB采集的温度个数
-#define BATT_CELL_VOL_NUM_2 (BATT_CELL_VOL_NUM*2)
-
-#define HWVERSION		    0x0102    //硬件主版本,现为V1.2板
-#define	BLSWVERSION		0x01020000    //BootLoader版本号V1.2.0.0
-#define	DRVSWVERSION		0x01050000     //驱动层版本号V1.4.0.0  驱动层1.5.0.0,增加了三轴
-//#define	APPSWVERSION		0x01020209     
-//#define	APPSWVERSION		0x02000103
-#define	APPSWVERSION		0x0201000C
-//--------------------------------------------------------------------------------
-
-#define APP_CONFIG_FILE_LATEST_VERSION 0
-#define APP_CONFIG_FILE_NAME  "qxappconfig.nvm"
-#define APP_DATAINFO_FILE_NAME  "qxappDataInfo.nvm"
-#define BATT_SN_LEN           17
-typedef struct AppNVMDataType
-{	
-    BOOL   appDataModify;		//数据更改标志位
-	UINT8  battSN[BATT_SN_LEN]; //电池SN号码
-   	BOOL   isBattLocked;		//0:not locked;	1:locked
-    UINT8  chargEndWorkTime;   //the unit is min
-    UINT8  wakeupWorkTime;     //the unit is min
-    UINT8  sleepTime;
-    UINT16 HwVersion;
-    UINT32 BLSwVersion;
-    UINT32 DrvSwVersion;
-    UINT32 AppSwVersion;
-	UINT8  EOLState;
-}AppNVMDataType;
-
-typedef struct AppConfigHeader
-{
-    UINT16 fileBodySize; //file body size, not include size of header;
-    UINT8  version;
-    UINT8  checkSum;
-}AppConfigHeader;
-typedef struct _UartAnswerMsg
-{
-	BOOL UartFlag;
-    UINT8 dataPtr[8];
-    UINT16 len;
-}UartAnswerMsgType;
-
-typedef enum
-{
-    APP_INIT_STATE,
-    APP_DEACTIVE_STATE,
-    APP_IPREADY_STATE,
-    APP_REPORT_STATE,
-    APP_IDLE_STATE,
-    APP_WAIT_STATE
-} appRunningState_t;
-//uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t* Uart_Rece_buffer,uint8_t Data_Len);
-//累计数据结构体
-typedef struct AppDataType
-{	
-    BOOL   appDataModify;		//数据更改标志位
-    UINT8  BmsChrgInfoSendFreq;
-    UINT8  BmsDisChrgInfoSendFreq;
-    UINT8  GpsChrgInfoSendFreq;
-    UINT8  GpsDisChrgInfoSendFreq;
-    INT8  BattCurrentNegFlag;
-    UINT32 CumulativeCapacity;
-    UINT32 AccMileage;
-    UINT16 SysReStart;
-}AppDataBody;
-typedef struct _AppDataHeader
-{
-    UINT16 fileBodySize; //file body size, not include size of header;
-    UINT8  checkSum;
-}AppDataHeader;
-
 #ifdef __cplusplus
 }
 #endif
-#endif /* APP_H */

+ 0 - 143
inc/cisAsynEntry.h

@@ -1,143 +0,0 @@
-#ifndef _OBJECT_DEFS_H_
-#define _OBJECT_DEFS_H_
-
-#include "cis_api.h"
-#include "cis_internals.h"
-
-#define SAMPLE_OBJECT_MAX              1
-#define SAMPLE_OID_A                   (3306)
-#define SAMPLE_A_INSTANCE_COUNT        1
-#define SAMPLE_A_INSTANCE_BITMAP       "1"
-
-typedef struct st_sample_object
-{
-    cis_oid_t         oid;
-    cis_instcount_t   instCount;
-    const char*       instBitmap;
-    const cis_rid_t*  attrListPtr;
-    uint16_t          attrCount;
-    const cis_rid_t*  actListPtr;
-    uint16_t          actCount;
-} st_sample_object;
-
-
-//////////////////////////////////////////////////////////////////////////
-//a object
-
-typedef struct st_object_a{
-    int32_t intValue;
-    float   floatValue;
-    bool    boolValue;
-    char    strValue[1024];
-    uint8_t update;
-} st_object_a;
-
-
-typedef struct st_instance_a
-{
-    cis_iid_t   instId;
-    bool        enabled;
-    st_object_a instance;
-} st_instance_a;
-
-
-enum{
-    attributeA_intValue     = 5851,
-    attributeA_boolValue    = 5850,
-    attributeA_stringValue  = 5750,
-};
-
-enum{
-    actionA_1           = 100,
-};
-
-                        
-//at+mipldiscoverrsp=0,msgid1,1,14,"5750;5850;5851" string bool integer
-static const cis_rid_t const_AttrIds_a[] = {
-    attributeA_intValue,
-    attributeA_boolValue,
-    attributeA_stringValue,
-};
-
-
-static const cis_rid_t const_ActIds_a[] = {
-    actionA_1,
-};
-
-typedef enum{
-    CIS_CALLBACK_UNKNOWN = 0,
-    CIS_CALLBACK_READ,
-    CIS_CALLBACK_WRITE,
-    CIS_CALLBACK_EXECUTE,
-    CIS_CALLBACK_OBSERVE,
-    CIS_CALLBACK_SETPARAMS,
-    CIS_CALLBACK_DISCOVER,
-} et_callback_type_t1;
-
-
-
-struct st_observe_info
-{
-    struct st_observe_info* next;
-    cis_listid_t    mid;
-    cis_uri_t       uri;
-    cis_observe_attr_t params;
-};
-
-struct store_observe_info
-{
-    cis_listid_t    mid;
-    cis_uri_t       uri;
-    cis_observe_attr_t params;
-};
-
-struct st_callback_info
-{
-    struct st_callback_info* next;
-    cis_listid_t       mid;
-    et_callback_type_t flag; 
-    cis_uri_t          uri;
-
-    union
-    {
-        struct{
-            cis_data_t* value;
-            cis_attrcount_t count;
-        }asWrite;
-
-        struct{
-            uint8_t* buffer;
-            uint32_t length;
-        }asExec;
-        
-        struct  
-        {
-            bool flag;
-        }asObserve;
-        
-        struct  
-        {
-            cis_observe_attr_t params;
-        }asObserveParam;
-    }param;
-    
-};
-typedef struct {
-    et_client_state_t pumpState;
-    uint8_t observeObjNum;
-    observed_backup_t gObservedBackup[MAX_OBSERVED_COUNT]; // For CIS core save use
-} onenet_context_t;
-
-bool cisAsynGetShutdown(void);
-void cisAsynSetShutdown(bool shutdown);
-bool cisAsynGetNotifyOnceStatus(void);
-void cisAsynSetNotifyOnceStatus(bool success);
-
-bool cisAsyncCheckNotificationReady(void);
-
-void prvMakeUserdata(void);
-void cisOnenetInit(void);
-void cisDataObserveReport(void);
-
-
-#endif//_OBJECT_DEFS_H_

+ 0 - 234
src/CANEncode.c

@@ -1,234 +0,0 @@
-#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;
-	}
-}

+ 0 - 273
src/CANTask.c

@@ -1,273 +0,0 @@
-#include "bsp.h"
-#include "bsp_custom.h"
-#include "osasys.h"
-#include "ostask.h"
-#include "queue.h"
-#include "ps_event_callback.h"
-#include "cmisim.h"
-#include "cmimm.h"
-#include "cmips.h"
-#include "sockets.h"
-#include "psifevent.h"
-#include "ps_lib_api.h"
-#include "lwip/netdb.h"
-#include <cis_def.h>
-#include "debug_log.h"
-#include "slpman_ec616.h"
-#include "plat_config.h"
-#include "ec_tcpip_api.h"
-#include "hal_module_adapter.h"
-#include "UartTask.h"
-#include "MainTask.h"
-#include "app.h"
-#include "CANTask.h"
-#include "UDSService.h"
-#include "signal.h"
-
-extern UINT32 Timer_count;
-extern volatile BOOL Sleep_flag;
-
-CAN_Msg_Type CanRxMsg[2];
-/*线程声明*/
-#define 			PROC_CAN_RX_TASK_STACK_SIZE			(1024)
-static StaticTask_t gProcess_Can_Rx_Task_t;
-static UINT8 		gProcess_Can_Rx_TaskStack[PROC_CAN_RX_TASK_STACK_SIZE];
-
-
-static process_CAN	gProcess_CAN_Task = PROCESS_CAN_STATE_IDLE;
-#define 			PROC_CAN_STATE_SWITCH(a)  (gProcess_CAN_Task = a)
-volatile bool 		CAN_Sleep_State = false;
-UINT8 				CanSendSlpHandler	= 0xfd;
-
-extern updateBMSStatus MS_BMS_Update_Service();
-
-
-void CANTaskInit(void* arg)
-{
-    osThreadAttr_t task_rx_attr,task_tx_attr;
-    Can_InitType param;
-    param.baudrate = CAN_250Kbps;
-	param.mode = REQOP_NORMAL;	
-	param.packType = STD_PACK;
-	
-    memset(&task_rx_attr,0,sizeof(task_rx_attr));
-    memset(gProcess_Can_Rx_TaskStack, 0, PROC_CAN_RX_TASK_STACK_SIZE);
-    task_rx_attr.name = "Can_Task";
-    task_rx_attr.stack_mem = gProcess_Can_Rx_TaskStack;
-    task_rx_attr.stack_size = PROC_CAN_RX_TASK_STACK_SIZE;
-    task_rx_attr.priority = osPriorityBelowNormal7;
-    task_rx_attr.cb_mem = &gProcess_Can_Rx_Task_t;
-    task_rx_attr.cb_size = sizeof(StaticTask_t);
-	
-    HAL_Can_Init(param);
-    osDelay(1000);
-    osThreadNew(Can_Receive, NULL, &task_rx_attr);
-}
-
-
-static void Can_Receive()
-{    
-	slpManSlpState_t State;
-    uint8_t udsFlag,msgFlag=0;
-	UINT8 i = 0;
-	UINT16 delayconuter = 0;
-	CAN_Sleep_State = false;
-    while(true)
-    {
-		memset(CanRxMsg, 0, sizeof(CanRxMsg));    		
-		switch(gProcess_CAN_Task)
-		{
-			case PROCESS_CAN_STATE_IDLE:
-				osDelay(2000);
-				PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_WORK);
-				break;				
-			
-			case PROCESS_CAN_STATE_WORK:
-				
-				if(Sleep_flag)
-				{
-					PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_SLEEP);
-				}
-				if(HAL_Can_Receive(CanRxMsg)>0)					
-				{
-					delayconuter=0;						
-					for(i=0; i<2; i++)
-					{								
-						if(CanRxMsg[i].Id == 0x7A0)
-						{	
-							udsFlag = 1;
-							UDSService[i] =  CanRxMsg[i].Data[0];
-							UDSSubService[i] = CanRxMsg[i].Data[1];
-							UDSSubServiceActionCode[i] = CanRxMsg[i].Data[2];
-							if(UDSService[i] == 0x10)
-							{
-								if(UDSSubService[i] == 0x02)
-								{
-									UDSSwitch = 1;
-								}								
-							}
-						}
-						else if(CanRxMsg[i].Id == 0x7A1)
-						{
-							if(CanRxMsg[i].Data[0] != 0x00)
-							{
-								msgFlag = 1;	
-							}
-							else
-							{
-								msgFlag = 0;
-							}
-						}
-					}	
-					if(udsFlag==1)
-					{	
-						UDS_Service();
-						udsFlag = 0;
-					}
-					else if(msgFlag == 1)
-					{
-						CanMsgTx1000ms();							
-					}				
-				}
-				else
-				{
-					delayconuter++;
-					osDelay(10);
-					if(delayconuter>=0xfffe)
-					{
-						delayconuter=0;
-					}
-				}
-				if(delayconuter>100)
-				{
-					delayconuter=0;
-					PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_IDLE);
-				}
-				break;
-				
-	        case PROCESS_CAN_STATE_SLEEP:
-	        {	            
-	            HAL_Can_Sleep();	 
-	            
-	            CAN_Sleep_State = true;
-	            while(true)
-	            {
-	                osDelay(60000/portTICK_PERIOD_MS);
-	            }
-				osThreadExit();	            
-	            break;
-	       }
-	   }
-	   //osDelay(50);
-	}      
-}
-
-
-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;
-			
-		}
-	}
-}
-
-
-

+ 0 - 289
src/Fota.c

@@ -1,289 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   Qx.
- * File name:    Fota.c
- * Description:  Fota升级函数
- * History:      2021-03-15
- *
- ****************************************************************************/
-#include "Fota.h"
-#include "ec_tcpip_api.h"
-#include "ps_lib_api.h"
-#include "MainTask.h"
-#include "TcpTask.h"
-#include "os_exception.h"
-#include "flash_ec616_rt.h"
-extern AppNVMDataType AppNVMData;
-static Fota_Type Fota_S;
-static UINT8 bcc_chk_fota(UINT8* data, UINT8 length);
-static UINT8 Fota_crc_chk(UINT8* data,UINT8 length);
-volatile bool NB_Fota_update_flag = FALSE; //NB可以升级标志
-volatile bool BMS_Fota_update_flag = FALSE; //NB可以升级标志
-void Fota_Func(UINT8 *DataPtr,INT32 connectId)
-{
-    UINT8 Fota_Answer[43];
-    UINT8 Fota_Cmd;
-    INT8 ret;
-    UINT8* Data_Read_Buffer;
-    UINT8 Data_Read_Crc;
-    if(*(DataPtr+30)==0x01)
-    {
-        Fota_S.Fota_Flash_Addres = FLASH_FOTA_REGION_START;
-        Fota_Cmd = *(DataPtr+31);
-        Fota_Answer[0] = TCP_START_SYM1;
-        Fota_Answer[1] = TCP_START_SYM2;
-        Fota_Answer[2] = TCP_CONCMD_SYM;
-        switch (Fota_Cmd)
-        {
-            case 0x01:
-            {
-                Fota_S.Fota_All_Data_Len = *(DataPtr+33)<<24|*(DataPtr+34)<<16|*(DataPtr+35)<<8|*(DataPtr+36);
-                Fota_S.Fota_Current_Addres = *(DataPtr+37)<<24|*(DataPtr+38)<<16|*(DataPtr+39)<<8|*(DataPtr+40);
-                if(Fota_S.Fota_All_Data_Len>=(FLASH_BMS_FOTA_START_ADDR - FLASH_FOTA_REGION_START))
-                {
-                    Fota_Answer[3] = 0x02;
-                }
-                else
-                {
-                    Fota_Answer[3] = 0x01;
-                    BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres,Fota_S.Fota_All_Data_Len + 4 - (Fota_S.Fota_All_Data_Len%4)); //512k-32k = 480k -> 0x75300  0x78000
-                }
-                memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
-                Fota_Answer[21] = TCP_ENCPT_DISABLE;
-                Fota_Answer[22] = 0x00;
-                Fota_Answer[23] = 0x12;
-                memcpy(&Fota_Answer[24],(DataPtr+24),18);
-                Fota_Answer[42] =  bcc_chk_fota(Fota_Answer,42);
-                tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
-                break;
-            }
-            case 0x02:
-            {
-                Fota_S.Fota_All_Data_Len = *(DataPtr+33)<<24|*(DataPtr+34)<<16|*(DataPtr+35)<<8|*(DataPtr+36);
-                Fota_S.Fota_Current_Addres = *(DataPtr+37)<<24|*(DataPtr+38)<<16|*(DataPtr+39)<<8|*(DataPtr+40);
-                Fota_S.Fota_Recv_Data_Len = *(DataPtr+41);
-                memset(Fota_S.Fota_Recv_Data,0x00,100);
-                memcpy(Fota_S.Fota_Recv_Data,(DataPtr+42),*(DataPtr+41));
-                Fota_S.Fota_CRC = Fota_crc_chk(Fota_S.Fota_Recv_Data,Fota_S.Fota_Recv_Data_Len);
-                if(Fota_S.Fota_CRC == *(DataPtr+Fota_S.Fota_Recv_Data_Len+42))
-                {
-                    if(Fota_S.Fota_Recv_Data_Len%4!=0)
-                    {
-                    Fota_S.Fota_Recv_Data_Len = Fota_S.Fota_Recv_Data_Len + 4-(Fota_S.Fota_Recv_Data_Len%4);
-                    }
-                    BSP_QSPI_Write_Safe(Fota_S.Fota_Recv_Data,Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
-                    Data_Read_Buffer = malloc(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);
-                    #ifdef USING_PRINTF
-                        printf("\n\n\n");
-                        UINT8 temp[1];
-                        for(int i=0;i<Fota_S.Fota_Recv_Data_Len;i++)
-                        {
-                            printf("%x  ",*(Data_Read_Buffer+i));
-                        }    
-                        printf("\n\n\n");
-                    #endif
-                    free(Data_Read_Buffer);
-                    if(Data_Read_Crc==Fota_S.Fota_CRC )
-                    {
-                        Fota_Answer[3] = 0x01;
-                    }
-                    else
-                    {
-                        Fota_Answer[3] = 0x02;
-                        BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
-                    }
-                }
-                else//数据校验失败
-                {
-                    Fota_Answer[3] = 0x02;
-                }
-                memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
-                Fota_Answer[21] = TCP_ENCPT_DISABLE;
-                Fota_Answer[22] = 0x00;
-                Fota_Answer[23] = 0x12;
-                memcpy(&Fota_Answer[24],(DataPtr+24),18);
-                Fota_Answer[42] =  bcc_chk_fota(Fota_Answer,42);
-                tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
-                break;
-            }
-            case 0x03:
-            {
-                Fota_S.Fota_All_Data_Len = *(DataPtr+33)<<24|*(DataPtr+34)<<16|*(DataPtr+35)<<8|*(DataPtr+36);
-                Fota_S.Fota_Current_Addres = *(DataPtr+37)<<24|*(DataPtr+38)<<16|*(DataPtr+39)<<8|*(DataPtr+40);
-                Fota_Answer[3] = 0x01;
-                memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
-                Fota_Answer[21] = TCP_ENCPT_DISABLE;
-                Fota_Answer[22] = 0x00;
-                Fota_Answer[23] = 0x12;
-                memcpy(&Fota_Answer[24],(DataPtr+24),18);
-                Fota_Answer[42] =  bcc_chk_fota(Fota_Answer,42);
-                tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
-                if(Fota_S.Fota_All_Data_Len==Fota_S.Fota_Current_Addres)
-                {
-                    NB_Fota_update_flag = TRUE;
-                }
-                else
-                {
-                    NB_Fota_update_flag = FALSE;
-                }
-                break;
-            }
-            default:
-            {
-                Fota_Answer[3] = 0x02;
-                memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
-                Fota_Answer[21] = TCP_ENCPT_DISABLE;
-                Fota_Answer[22] = 0x00;
-                Fota_Answer[23] = 0x12;
-                memcpy(&Fota_Answer[24],(DataPtr+24),18);
-                Fota_Answer[42] =  bcc_chk_fota(Fota_Answer,42);
-                tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
-                break;
-            }
-                
-        }
-    }
-    else if(*(DataPtr+30)==0x88)//BMS升级文件存放
-    {
-        Fota_S.Fota_Flash_Addres = FLASH_BMS_FOTA_START_ADDR;
-        Fota_Cmd = *(DataPtr+31);
-        Fota_Answer[0] = TCP_START_SYM1;
-        Fota_Answer[1] = TCP_START_SYM2;
-        Fota_Answer[2] = TCP_CONCMD_SYM;
-        switch (Fota_Cmd)
-        {
-            case 0x01:
-            {
-                Fota_S.Fota_All_Data_Len = *(DataPtr+33)<<24|*(DataPtr+34)<<16|*(DataPtr+35)<<8|*(DataPtr+36);
-                Fota_S.Fota_Current_Addres = *(DataPtr+37)<<24|*(DataPtr+38)<<16|*(DataPtr+39)<<8|*(DataPtr+40);
-                if(Fota_S.Fota_All_Data_Len>=(FLASH_BMS_FOTA_END_ADDR - FLASH_BMS_FOTA_START_ADDR))
-                {
-                    Fota_Answer[3] = 0x02;
-                }
-                else
-                {
-                    Fota_Answer[3] = 0x01;
-                }
-                memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
-                Fota_Answer[21] = TCP_ENCPT_DISABLE;
-                Fota_Answer[22] = 0x00;
-                Fota_Answer[23] = 0x12;
-                memcpy(&Fota_Answer[24],(DataPtr+24),18);
-                Fota_Answer[42] =  bcc_chk_fota(Fota_Answer,42);
-                tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
-                if(Fota_Answer[3] == 0x01)
-                {
-                    BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres,Fota_S.Fota_All_Data_Len + 4 - (Fota_S.Fota_All_Data_Len%4)); //512k-32k = 480k -> 0x75300  0x78000
-                }
-                break;
-            }
-            case 0x02:
-            {
-                Fota_S.Fota_All_Data_Len = *(DataPtr+33)<<24|*(DataPtr+34)<<16|*(DataPtr+35)<<8|*(DataPtr+36);
-                Fota_S.Fota_Current_Addres = *(DataPtr+37)<<24|*(DataPtr+38)<<16|*(DataPtr+39)<<8|*(DataPtr+40);
-                Fota_S.Fota_Recv_Data_Len = *(DataPtr+41);
-                memset(Fota_S.Fota_Recv_Data,0x00,100);
-                memcpy(Fota_S.Fota_Recv_Data,(DataPtr+42),*(DataPtr+41));
-                Fota_S.Fota_CRC = Fota_crc_chk(Fota_S.Fota_Recv_Data,Fota_S.Fota_Recv_Data_Len);
-                if(Fota_S.Fota_CRC == *(DataPtr+Fota_S.Fota_Recv_Data_Len+42))
-                {
-                    if(Fota_S.Fota_Recv_Data_Len%4!=0)
-                    {
-                    Fota_S.Fota_Recv_Data_Len = Fota_S.Fota_Recv_Data_Len + 4-(Fota_S.Fota_Recv_Data_Len%4);
-                    }
-                    BSP_QSPI_Write_Safe(Fota_S.Fota_Recv_Data,Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
-                    Data_Read_Buffer = malloc(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);
-                    #ifdef USING_PRINTF1
-                        printf("\n\n\n");
-                        UINT8 temp[1];
-                        for(int i=0;i<Fota_S.Fota_Recv_Data_Len;i++)
-                        {
-                            printf("%x  ",*(Data_Read_Buffer+i));
-                        }    
-                        printf("\n\n\n");
-                    #endif
-                    free(Data_Read_Buffer);
-                    if(Data_Read_Crc==Fota_S.Fota_CRC )
-                    {
-                        Fota_Answer[3] = 0x01;
-                    }
-                    else
-                    {
-                        Fota_Answer[3] = 0x02;
-                        BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
-                    }
-                }
-                else//数据校验失败
-                {
-                    Fota_Answer[3] = 0x02;
-                }
-                memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
-                Fota_Answer[21] = TCP_ENCPT_DISABLE;
-                Fota_Answer[22] = 0x00;
-                Fota_Answer[23] = 0x12;
-                memcpy(&Fota_Answer[24],(DataPtr+24),18);
-                Fota_Answer[42] =  bcc_chk_fota(Fota_Answer,42);
-                tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
-                break;
-            }
-            case 0x03:
-            {
-                Fota_S.Fota_All_Data_Len = *(DataPtr+33)<<24|*(DataPtr+34)<<16|*(DataPtr+35)<<8|*(DataPtr+36);
-                Fota_S.Fota_Current_Addres = *(DataPtr+37)<<24|*(DataPtr+38)<<16|*(DataPtr+39)<<8|*(DataPtr+40);
-                Fota_Answer[3] = 0x01;
-                memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
-                Fota_Answer[21] = TCP_ENCPT_DISABLE;
-                Fota_Answer[22] = 0x00;
-                Fota_Answer[23] = 0x12;
-                memcpy(&Fota_Answer[24],(DataPtr+24),18);
-                Fota_Answer[42] =  bcc_chk_fota(Fota_Answer,42);
-                tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
-                if(Fota_S.Fota_All_Data_Len==Fota_S.Fota_Current_Addres)
-                {
-                    BMS_Fota_update_flag = TRUE;
-                }
-                else
-                {
-                    BMS_Fota_update_flag = FALSE;
-                }
-                break;
-            }
-            default:
-            {
-                Fota_Answer[3] = 0x02;
-                memcpy(&Fota_Answer[4],(DataPtr+4),BATT_SN_LEN);
-                Fota_Answer[21] = TCP_ENCPT_DISABLE;
-                Fota_Answer[22] = 0x00;
-                Fota_Answer[23] = 0x12;
-                memcpy(&Fota_Answer[24],(DataPtr+24),18);
-                Fota_Answer[42] =  bcc_chk_fota(Fota_Answer,42);
-                tcpipConnectionSend(connectId,Fota_Answer,43,0,0,0);
-                break;
-            }
-        }
-    }
-}
-static UINT8 bcc_chk_fota(UINT8* data, UINT8 length)
-{
-    UINT8 bcc_chk_return = 0x00;
-    UINT8 count = 0;
-    while (count<length)
-    {
-        bcc_chk_return^=data[count];
-        count++;
-    }
-    return  bcc_chk_return;
-}
-static UINT8 Fota_crc_chk(UINT8* data,UINT8 length)
-{  
-    UINT8 reg_crc=0x00;
-    while(length--)
-    { 
-        reg_crc ^= *data++;
-    }
-    return reg_crc;
-}

+ 0 - 210
src/GpsTask.c

@@ -1,210 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   Qx.Chen jie
- * File name:    GpsTask.c
- * Description:  Gps处理任务
- * History:      2021-03-07
- *
- ****************************************************************************/
-#include "bsp.h"
-#include "bsp_custom.h"
-#include "osasys.h"
-#include "ostask.h"
-#include "queue.h"
-#include "ps_event_callback.h"
-#include "app.h"
-#include "cmisim.h"
-#include "cmimm.h"
-#include "cmips.h"
-#include "sockets.h"
-#include "psifevent.h"
-#include "ps_lib_api.h"
-#include "lwip/netdb.h"
-//#include <cis_def.h>
-#include "debug_log.h"
-#include "slpman_ec616.h"
-#include "plat_config.h"
-#include "ec_tcpip_api.h"
-#include "app.h"
-#include "MainTask.h"
-#include "GpsTask.h"
-#include "TcpTask.h"
-//全局变量区输入
-extern volatile BOOL Sleep_flag; 
-extern AppDataBody AppDataInfo;
-extern UINT8 WorkFlag;
-//全局变量区输出
-UINT8 GpsData[20];
-osMutexId_t GpsMutex = NULL;
-//线程定义区
-#define GPS_TASK_STACK_SIZE   								 (512)
-static QueueHandle_t norGpsHandle = NULL;
-static osThreadId_t gpsTaskHandle = NULL;
-static StaticTask_t gpsTask = NULL;
-static UINT8 gpsTaskStack[GPS_TASK_STACK_SIZE];
-
-//函数声明区
-void strdel(char * str,char c);
-UINT32 location_handle(char *in1);
-
-static void GpsTask(void* arg)
-{
-    gpsReqMsg msg;
-	char *p=NULL;
-	const char *delim = "\n";
-	char *databuffer[14];
-    UINT32 speedtemp;
-    UINT32 latitude;
-	UINT32 longitude;
-    UINT16 direction;
-    posGGAServiceStart(norGpsHandle);
-    posGGAReset();
-    if(GpsMutex == NULL)
-    {
-        GpsMutex = osMutexNew(NULL);
-    }
-    while(1)
-    {
-        //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, osWaitForever);
-        if(ret==0)
-        {
-            if (msg.dataPtr)
-            {	
-                osStatus_t result = osMutexAcquire(GpsMutex, osWaitForever);//Gps数据锁	
-                p = strtok(msg.dataPtr,delim);//将信息进行分割
-                #ifdef USING_PRINTF1
-                    printf("\nP msgptr data:%s\r\n",p);
-                #endif
-                p = strtok(p,",");//只取第1行的信息RMC
-                //p = strtok(temp,",");//模拟测试
-                if (strcmp(p,"$GNRMC")==0)
-                {
-                    UINT8 i=0;			
-                    while (p)
-                    {	
-                        databuffer[i]=p;
-                        p = strtok(NULL,",");
-                        i++;;
-                    }
-                    if (strcmp(databuffer[1],"V")==0|strcmp(databuffer[2],"V")==0)
-                    {
-                        memset(GpsData,0x00,sizeof(GpsData));
-                    }
-                    else if (strcmp(databuffer[2],"A")==0)
-                    {
-                        GpsData[0] = 0x01;//有效,东经,北纬写定
-                        GpsData[1] = 03;//卫星数目写入1
-                        strdel(databuffer[3],'.');
-                        strdel(databuffer[5],'.');
-                        strdel(databuffer[7],'.');
-                        speedtemp = atol(databuffer[7])*1852/1e5;//节换算单位,1节=1.852km每小时
-                        GpsData[4] = (speedtemp>>8)&0xFF;
-                        GpsData[5] = speedtemp&0xFF; 
-                        latitude =location_handle(databuffer[3]);
-                        GpsData[8] = latitude>> 24;
-                        GpsData[9] = latitude>> 16;
-                        GpsData[10] = latitude>> 8;
-                        GpsData[11] = latitude;
-                        longitude = location_handle(databuffer[5]);
-                        GpsData[12] = longitude>>24;
-                        GpsData[13] = longitude>>16;
-                        GpsData[14] = longitude>>8;
-                        GpsData[15] = longitude;
-
-                        GpsData[6] = 0x03;
-                        GpsData[7] = 0xE8;
-                        if(speedtemp>=50)//大于5km/h才输出方位
-                        {
-                            direction = atol(databuffer[8]);
-                            GpsData[2] = direction>>8;
-                            GpsData[3] = direction;
-                        }
-                        else
-                        {
-                            GpsData[2] = 0xff;
-                            GpsData[3] = 0xfe;
-                        }
-                        if(speedtemp>=30 && speedtemp<=1500 && WorkFlag==0x01)
-                        {
-                            AppDataInfo.appDataModify = true;
-                            AppDataInfo.AccMileage = speedtemp/36 + AppDataInfo.AccMileage;
-                            if(AppDataInfo.AccMileage>=0xfffffffe)
-                            {
-                                AppDataInfo.AccMileage = 0;
-                            }
-
-                        }
-                        GpsData[16] = AppDataInfo.AccMileage>>24;
-                        GpsData[17] = AppDataInfo.AccMileage>>16;
-                        GpsData[18] = AppDataInfo.AccMileage>>8;
-                        GpsData[19] = AppDataInfo.AccMileage;
-                    }
-                }
-                osMutexRelease(GpsMutex);
-            }
-            if(msg.dataPtr)
-                free(msg.dataPtr);
-            msg.dataPtr=NULL;
-        }
-        if (Sleep_flag)
-		{
-            posGGAServiceStop();
-			osThreadExit();
-			break;
-		}
-    }
-}
-INT32 GpsTaskInit(void)
-{
-
-	if(norGpsHandle == NULL)
-	{
-		norGpsHandle = osMessageQueueNew(1,sizeof(gpsReqMsg), NULL);
-		if(norGpsHandle == NULL)
-			return 1;
-	}
-	if(gpsTaskHandle == NULL)
-	{
-		osThreadAttr_t task_attr;
-		memset(&task_attr , 0 , sizeof(task_attr));
-		task_attr.name = "GPS";
-		task_attr.priority = osPriorityBelowNormal6;
-		task_attr.cb_mem = &gpsTask;
-		task_attr.cb_size = sizeof(StaticTask_t);
-		task_attr.stack_mem = gpsTaskStack;
-		task_attr.stack_size =GPS_TASK_STACK_SIZE;
-		memset(& gpsTaskStack, 0xa5, GPS_TASK_STACK_SIZE);
-		gpsTaskHandle = osThreadNew(GpsTask , NULL,&task_attr);
-		if(gpsTaskHandle == NULL)
-			return 1;
-	}
-	
-	return 0;
-}
-/*----------------------------------------*/
-// 字符串删除函数
-void strdel(char * str,char c)
-{
-	char *p = str;
-	while(*str)
-	{
-		if(*str!=c)
-			*p++ = *str;
-		str++;
-	}
-	*p = '\0';
-}
-UINT32 location_handle(char *in1)
-{
-	UINT32 location_temp;
-	UINT32 location_degree;
-	UINT32 location_min;
-	location_temp = atol(in1);
-	location_degree = location_temp/(1e7);
-	location_degree = location_degree*(1e6);
-	location_min = location_temp-location_degree*10;
-	location_min = location_min/6;
-	location_temp = location_degree+location_min;
-	return location_temp;
-}

+ 33 - 191
src/MainTask.c

@@ -3,65 +3,17 @@
  * Copy right:   Qx.
  * File name:    MainTask.c
  * Description:  APP任务调取和异常处理
- * History:      2021-03-05
- * PS:主线程里面关闭了网络为了测试睡眠和唤醒
+ * History:      2021-07-05
+ * Version:      V3.0
  ****************************************************************************/
-#include "bsp.h"
-#include "bsp_custom.h"
-#include "osasys.h"
-#include "ostask.h"
-#include "queue.h"
-#include "ps_event_callback.h"
-#include "cmisim.h"
-#include "cmimm.h"
-#include "cmips.h"
-#include "sockets.h"
-#include "psifevent.h"
-#include "ps_lib_api.h"
-#include "lwip/netdb.h"
-//#include <cis_def.h>
-#include "debug_log.h"
-#include "slpman_ec616.h"
-#include "plat_config.h"
-#include "ec_tcpip_api.h"
-#include "hal_module_adapter.h"
-#include "timers.h"
-#include "app.h"
 #include "MainTask.h"
-#include "TcpTask.h"
-#include "Fota.h"
-#include "UartTask.h"
-#include "sensor.h"
-#include "Signal.h"
-extern UINT8 	UDSSwitch;
-extern volatile bool NB_Fota_update_flag;
-extern volatile bool BMS_Fota_update_flag;
-CHAR defaultBattSN[BATT_SN_LEN] = "RLTEST00000000001";//未进行下线检测的默认SN
-//全局变量
-UINT32 Timer_count;//每100ms加1
-volatile BOOL Sleep_flag = false;//睡眠标志位
-extern UINT32 TcpService;
-extern UINT8 BattChrgEndFlag;
-AppConfigHeader   AppConfigHr;   //4 bytes
-AppNVMDataType AppNVMData;
-AppDataHeader AppDataHr;
-AppDataBody AppDataInfo;
-
-BOOL Can_Msg_Enble = false;
-
-//主线程堆栈声明区
+
 static StaticTask_t           gProcess_Main_Task_t;
 static UINT8                  gProcess_Main_TaskStack[PROC_MAIN_TASK_STACK_SIZE];
 static osThreadId_t           MainTaskId = NULL;
-uint8_t MainSlpHandler          = 0xff;//主线程睡眠句柄
-uint8_t deepslpTimerID          = DEEPSLP_TIMER_ID7;//睡眠定时器ID
-static volatile bool Work_timer_end = false;
 static process_Main 		    gProcess_Main_Task;
 #define PROC_MAIN_STATE_SWITCH(a)  (gProcess_Main_Task = a)
 
-extern void GsensorInit(void);
-extern void GsensorI2CHandler(ARM_I2C_SignalEvent_t cb_event);
-extern void GsensorI2CCallback(UINT32 event);
 //函数声明区
 static void appBeforeHib(void *pdata, slpManLpState state);
 static void appAfterHib(void *pdata, slpManLpState state);
@@ -69,33 +21,33 @@ static void appBeforeSlp1(void *pdata, slpManLpState state);
 static void appAfterSlp1(void *pdata, slpManLpState state);
 static void appBeforeSlp2(void *pdata, slpManLpState state);
 static void appAfterSlp2(void *pdata, slpManLpState state);
-void montior_timer_callback(TimerHandle_t xTimer);
-void work_timer_callback(TimerHandle_t xTimer);
+static void montior_timer_callback(TimerHandle_t xTimer);
+static void work_timer_callback(TimerHandle_t xTimer);
 
 static void setDefaultAppDataValue(void);
-void appLoadConfig(void);
-void appSaveConfig(void);
+static void appLoadConfig(void);
+static void appSaveConfig(void);
 static void appGetNVMSavedData(void);
-void appSaveNVMData(void);
+static void appSaveNVMData(void);
 static void setDefaultAppDataInfo(void);
 static void LoadAppDataInfo(void);
 static void appSaveDataInfo(void);
 //主线程任务区
 static void MainTask(void* arg)
 {
-
+    /***GsensorInit***/
     GsensorI2CHandler(GsensorI2CCallback);
     GsensorInit();
-
-
-
-    int32_t inParam = 0xAABBCCDD;
-    UINT32  param;
-    UINT32 adcValue;
-    UINT8 i=0;
+    /***calibrate the ADC Collect***/
+    UINT32  param = 0;
+    AdcSendReq(ADC_REQ_BITMAP_VBAT_CALI,&param,1,ADC_GET_RESULT_TIMOUT);						
+	AdcSendReq(ADC_REQ_BITMAP_INRES_CALI,&param,1,ADC_GET_RESULT_TIMOUT);
+    /***Sleep***/
+    UINT32 inParam = 0xAABBCCDD;
     slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
+    UINT8 MainSlpHandler=0xff;
     slpManApplyPlatVoteHandle("MainSlp",&MainSlpHandler);
-    slpManPlatVoteDisableSleep(MainSlpHandler, SLP_SLP1_STATE);
+    slpManPlatVoteDisableSleep(MainSlpHandler, SLP_SLP2_STATE);
     slpManRegisterUsrdefinedBackupCb(appBeforeHib,&inParam,SLPMAN_HIBERNATE_STATE);
     slpManRegisterUsrdefinedRestoreCb(appAfterHib,NULL,SLPMAN_HIBERNATE_STATE);
     slpManRegisterUsrdefinedBackupCb(appBeforeSlp1,NULL,SLPMAN_SLEEP1_STATE);
@@ -116,6 +68,7 @@ static void MainTask(void* arg)
     #endif
 	appGetNVMSavedData();
     LoadAppDataInfo();
+    
     #ifdef USING_PRINTF1
     UINT8 *pReadAppConfig;
     UINT32 readCount;
@@ -154,14 +107,11 @@ static void MainTask(void* arg)
         AppNVMData.BLSwVersion = BLSWVERSION;
         AppNVMData.DrvSwVersion = DRVSWVERSION;
         AppNVMData.AppSwVersion = APPSWVERSION;
-        AppNVMData.appDataModify=TRUE;
+        AppNVMData.appDataModify = TRUE;
     }
     montior_timer = xTimerCreate("montior_timer", 100 / portTICK_RATE_MS, pdTRUE, NULL, montior_timer_callback);
     work_timer = xTimerCreate("work_timer", AppNVMData.wakeupWorkTime*60*1000 / portTICK_RATE_MS, pdTRUE, NULL, work_timer_callback);
 
-	/***calibrate the ADC Collect***/
-	AdcSendReq(ADC_REQ_BITMAP_VBAT_CALI,&param,1,ADC_GET_RESULT_TIMOUT);						
-	AdcSendReq(ADC_REQ_BITMAP_INRES_CALI,&param,1,ADC_GET_RESULT_TIMOUT);
 	
 	NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
 	NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
@@ -175,17 +125,16 @@ static void MainTask(void* arg)
         {
             case PROCESS_STATE_IDLE:
             {
-                Timer_count = 0;
+                TimeCounter = 0;
                 xTimerStart(montior_timer, 0);
                 xTimerStart(work_timer, 0);
-                Sleep_flag = false;
                 PROC_MAIN_STATE_SWITCH(PROCESS_STATE_WORK);
                 break;
             }
             case PROCESS_STATE_WORK:
             {
 
-                if(Error_count>=5)
+                if(TcpErrorcount>=5)
                 {
                     AppDataInfo.appDataModify = true;
                     AppDataInfo.SysReStart = AppDataInfo.SysReStart +1;
@@ -206,60 +155,10 @@ static void MainTask(void* arg)
                     EC_SystemReset();
                 }
                 osDelay(1000);
-                if(Work_timer_end)
-                {
-                    xTimerStop(montior_timer, 0);
-                    PROC_MAIN_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                    break;
-                }
-                else
-                {   
-                    switch (i)
-                    {
-                        case FAST_CHARGE_TEMP:
-                         NB_ADC_Get(&adcValue,FAST_CHARGE_TEMP);
-                         fastChargeTemp = LookUpRTtable(adcValue);
-                        break;
-                        case NORMAL_CHARGE_TEMP:
-                            NB_ADC_Get(&adcValue,NORMAL_CHARGE_TEMP);
-                            normalChargeTemp = LookUpRTtable(adcValue);
-                        break;
-                        case OTHER_TEMP_1:
-                            NB_ADC_Get(&adcValue,OTHER_TEMP_1);
-                            heatTemp1 = LookUpRTtable(adcValue);                      
-                        break;
-                        case OTHER_TEMP_2:
-                            NB_ADC_Get(&adcValue,OTHER_TEMP_2);
-                            heatTemp2 = LookUpRTtable(adcValue);                       
-                        break;
-                        case  VBAT:
-                            NB_ADC_Get(&adcValue,VBAT);                        
-                            i = 0;
-                        break;
-                        default:
-                            i=0;
-                            break;
-                    }
-                    i++;   
-                }
-                #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);
-                #endif	
-                if(TcpService!=0x00||UDSSwitch==1||BMS_Fota_update_flag||battWorkState!=0||Can_Msg_Enble==true)
-                {
-                    xTimerReset(work_timer,0);
-                    Can_Msg_Enble = false;
-                }
-                if(BattChrgEndFlag)
-                {
-                    xTimerChangePeriod(work_timer,AppNVMData.chargEndWorkTime*60*1000 / portTICK_RATE_MS,0);
-                    xTimerReset(work_timer,0);
-                }
                 break;
             }
             case PROCESS_STATE_SLEEP:
             {
-                Sleep_flag = true;
                 if(AppNVMData.appDataModify)
                 {
                     appSaveNVMData();
@@ -274,64 +173,11 @@ static void MainTask(void* arg)
                     osDelay(1000);
                     EC_SystemReset();
                 }
-                osDelay(1*1000);
-                xTimerStop(work_timer, 0);
-                slpManSlpState_t State;
-                uint8_t cnt;
-                if(slpManCheckVoteState(MainSlpHandler, &State, &cnt)==RET_TRUE)
-                {
-                    #ifdef USING_PRINTF
-                        printf("[%d]We Can Check Vote Main State, state=%d, cnt=%d\r\n",__LINE__,State,cnt);
-                    #endif						
-                }
-                slpManPlatVoteForceEnableSleep(MainSlpHandler, SLP_SLP1_STATE);
-                if(slpManCheckVoteState(MainSlpHandler, &State, &cnt)==RET_TRUE)
-                {
-                    #ifdef USING_PRINTF
-                        printf("[%d]We Can Check Vote Main State Again, state=%d, cnt=%d\r\n",__LINE__,State,cnt);
-                    #endif					
-                }
-                #ifdef USING_PRINTF
-                    printf("[%d]Waiting sleep\r\n",__LINE__);
-                #endif
-                FaultDisplay(LED_TURN_ON);
-                slpManSlpState_t slpstate = slpManPlatGetSlpState();
-                #ifdef USING_PRINTF
-                    printf("which slpstate can go now :%d \n",slpstate);
-                #endif
-                #ifdef DEBUGLOG
-                    Debug_printf("slp-%d,%d,%d,%d\n",slpstate,AppDataInfo.AccMileage,AppDataInfo.SysReStart,Battdesigncap);
-                #endif
-                slpManDeepSlpTimerStart(deepslpTimerID, AppNVMData.sleepTime*1000*60);
-                UINT8 sleeptime_count=0;
-                while(1)
-                {
-                    if(!slpManDeepSlpTimerIsRunning(deepslpTimerID))
-					    slpManDeepSlpTimerDel(deepslpTimerID);
-				    slpManDeepSlpTimerStart(deepslpTimerID, AppNVMData.sleepTime*1000*60);
-                    osDelay(1*60*1000/portTICK_PERIOD_MS);
-                    sleeptime_count++;
-                    #ifdef USING_PRINTF
-                        printf("sleeptime_count :%d \n",sleeptime_count);
-                    #endif
-                    if(sleeptime_count>10)
-                    {
-                        #ifdef DEBUGLOG
-                            Debug_printf("405\n");
-                        #endif
-                        appSetCFUN(0);
-                        osDelay(1000);
-                        EC_SystemReset();
-                    }
-                }
                 break;
             }
             default:
             {
                 PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
-                #ifdef USING_PRINTF
-                    printf("default!\n");
-                #endif
                 break;
             }
         }
@@ -365,21 +211,14 @@ void MainTaskDeInit(void *arg)
 //定时器回调函数区
 void montior_timer_callback(TimerHandle_t xTimer)
 {
-    #ifdef USING_PRINTF1
-        if (Timer_count%50==0)
-        {
-            printf("Main Task,Batt_Cell_Num:%d,%d!\n",BATT_CELL_VOL_NUM,Timer_count);
-        }
-    #endif
-    Timer_count++;
-    if(Timer_count>100000*100)
+    TimeCounter++;
+    if(TimeCounter>0xfffffffd)
     {
-        Timer_count=0;
+        TimeCounter=0;
     }
 }
 void work_timer_callback(TimerHandle_t xTimer)
 {
-    Work_timer_end = true;
     #ifdef USING_PRINTF
         printf("Hello work Timer!\n");
     #endif
@@ -388,7 +227,7 @@ void work_timer_callback(TimerHandle_t xTimer)
 //睡眠进出函数区
 static void appBeforeHib(void *pdata, slpManLpState state)
 {
-    uint32_t *p_param = (uint32_t *)pdata;
+    //uint32_t *p_param = (uint32_t *)pdata;
 
     #ifdef USING_PRINTF
         printf("Before Hibernate:%d \n",state);
@@ -508,7 +347,7 @@ void appLoadConfig(void)
 {
     OSAFILE fp = PNULL;
     UINT32  readCount = 0;
-    //AppConfigHeader    AppConfigHr;   //4 bytes
+    AppConfigHeader    AppConfigHr;   //4 bytes
     UINT8   crcCheck = 0;
     void    *pReadAppConfig = (void *)&AppNVMData;
     /*
@@ -535,7 +374,7 @@ void appLoadConfig(void)
         //ECOMM_TRACE(UNILOG_PLA_MIDWARE, AppLoadNvmConfig_header_e_1, P_ERROR, 1,
         //            "NVM: 'qxappconfig.nvm', can't read header, return: %d, use the defult value", readCount);
         #ifdef USING_PRINTF
-                    printf("NVM: 'qxappconfig.nvm', can't read header, return: %d, use the defult value \n");
+                    printf("NVM: 'qxappconfig.nvm', can't read header, return: %d, use the defult value \n",readtimes);
         #endif
         readtimes++;
         readCount = OsaFread(&AppConfigHr, sizeof(AppConfigHeader), 1, fp);
@@ -679,6 +518,7 @@ static void setDefaultAppDataValue(void)
 {
     UINT8  i = 0;
     memset(&AppNVMData, 0x00, sizeof(AppNVMDataType));
+    CHAR defaultBattSN[BATT_SN_LEN] = DEFAULT_SN;
 	for(i=0;i<BATT_SN_LEN;i++)
 	{
 		AppNVMData.battSN[i] = defaultBattSN[i];  //the defult sn is "0000..0000"(17 bytes ASCII)
@@ -698,6 +538,7 @@ static void setDefaultAppDataValue(void)
 static void appSaveDataInfo(void)
 {
     OSAFILE fp = PNULL;
+    AppDataHeader  AppDataHr;
     UINT32  writeCount = 0;
     fp = OsaFopen(APP_DATAINFO_FILE_NAME, "wb");   //read & write
     if(OsaFseek(fp, 0, SEEK_SET) != 0)
@@ -745,7 +586,8 @@ static void LoadAppDataInfo(void)
 {
     OSAFILE fp = PNULL;
     UINT32  readCount = 0;
-    UINT8   crcCheck = 0;
+    //UINT8   crcCheck = 0;
+    AppDataHeader  AppDataHr;
     void    *pReadAppConfig = (void *)&AppDataInfo;
     fp = OsaFopen(APP_DATAINFO_FILE_NAME, "rb");   //read only
     if (fp == PNULL)
@@ -781,7 +623,7 @@ static void LoadAppDataInfo(void)
         while (readtimes<=5 && readCount != 1)
         {
             readtimes++;
-            readCount = OsaFread(pReadAppConfig, AppConfigHr.fileBodySize, 1, fp);
+            readCount = OsaFread(pReadAppConfig, AppDataHr.fileBodySize, 1, fp);
             //crcCheck = OsaCalcCrcValue((UINT8 *)pReadAppConfig, sizeof(AppNVMData));
         }
     }
@@ -794,7 +636,7 @@ static void LoadAppDataInfo(void)
         while (readtimes<=5 && readCount != 1)
         {
             readtimes++;
-            readCount = OsaFread(pReadAppConfig, AppConfigHr.fileBodySize, 1, fp);
+            readCount = OsaFread(pReadAppConfig, AppDataHr.fileBodySize, 1, fp);
             //crcCheck = OsaCalcCrcValue((UINT8 *)pReadAppConfig, sizeof(AppNVMData));
         }
         appSaveDataInfo();

+ 76 - 56
src/Signal.c

@@ -1,4 +1,79 @@
+/****************************************************************************
+ *
+ * Copy right:   2021-, Copyrigths of RLWL Ltd.
+ * File name:    Signal.c
+ * Description:  Global variable definition c file
+ * History:      Rev3.0   2021-07-06
+ *
+ ****************************************************************************/
+
 #include "Signal.h"
+//declear the bool vars
+volatile BOOL NB_Fota_update_flag = FALSE;
+volatile BOOL BMS_Fota_update_flag = FALSE;
+
+//declear the UINT8 vars
+UINT8	battCellTemp[8] = {0xFF};       //Battery temperature 电池温度数值
+UINT8	MOSTemp = 0xFF;                 //mos temprature mos温度
+UINT8	packTemp = 0xFF;                //battery pack temprature   电池箱体温度
+UINT8	fastChargeTemp = 0xFF;          // fast charge plug temprature  快充插头温度
+UINT8	normalChargeTemp = 0xFF;        // normal charge plug temprature    慢充插头温度
+UINT8	heatTemp1 = 0xFF;               //Heating plate1 temperature    加热板温度1
+UINT8	heatTemp2 = 0xFF;               //Heating plate2 temperature    加热板温度2
+UINT8	nbReservedTemp1 = 0xFF;         //
+UINT8	nbReservedTemp2 = 0xFF;         //
+UINT8	maxCellTemp = 0xFF;             //最高单体温度
+UINT8	minCellTemp = 0xFF;             //最低单体温度
+UINT8	battSOC = 0xFF;                 //电池SOC
+UINT8	battSOH = 0xFF;                 //电池SOH
+UINT8	battWorkState = 0xFF;           //电池工作状态
+UINT8	bmsSwVersion = 0xFF;            //bms软件版本
+UINT8	bmsHwVersion = 0xFF;            //bms硬件版本
+UINT8	battMOSSwitchState = 0xFF;      //bms开关状态
+UINT8	battHeatEnableState = 0xFF;     //bms加热使能状态
+UINT8	reservedSignal1 = 0xFF;         //can信息保留信号1
+UINT8	reservedSignal2 = 0xFF;         //can信息保留信号2
+UINT8	reservedSignal3 = 0xFF;         //can信息保留信号3
+UINT8	reservedSignal4 = 0xFF;         //can信息保留信号4
+UINT8	reservedSignal5 = 0xFF;         //can信息保留信号5
+UINT8	reservedSignal6 = 0xFF;         //can信息保留信号6
+UINT8	reservedSignal7 = 0xFF;         //can信息保留信号7
+UINT8	reservedSignal8 = 0xFF;         //can信息保留信号8
+
+UINT8   Lockstatus = 0;             //Interlock status 高压互锁状态
+UINT8   TcpErrorcount=0;              //Error count TCP联网错误计数
+UINT8 	TcpSendLen = 0;             //Tcp send status Tcp发送状态
+UINT8   CanMsgEnble = 0;            //Can send status Can中断状态
+UINT8 	UDSSwitch = 0;
+//declear the UINT16 vars
+UINT16	battCellU[28] = {0xFFFF};    //电池包单体电压
+UINT16	minCellVol = 0xFFFF;    //最小单体电压
+UINT16	maxCellVol = 0xFFFF;    //最大单体电压
+UINT16	battPackVol = 0xFFFF;   //电池总压
+UINT16	battI = 0xFFFF;         //电池总电流
+UINT16	nbHwVersion = 0xFFFF;   //数据模块硬件状态
+UINT16  ErrorNum[5]={0};        //Error array,故障数组
+
+
+
+//declear the UINT32 vars
+UINT32	battWarningState = 0xFFFFFFFF;  //电池告警状态
+UINT32	nbSwVersion = 0xFFFFFFFF;       // 数据模块软件状态
+UINT32	battBalanceoInfo = 0xFFFFFFFF;  //电池均衡状态
+UINT32  Battdesigncap =0xFFFFFFFF;      //battery design cap 电池包设计容量
+UINT32  TimeCounter = 0x00;             //主任务定时器计数
+
+
+//declear other vars
+osMutexId_t Error_Mutex = NULL;         //故障互锁句柄
+
+
+
+//declear struct vars   结构体变量定义
+
+AppNVMDataType      AppNVMData;
+
+AppDataBody         AppDataInfo;
 
 UINT16	COMOutTable[28]	=	{
 0x6A0,
@@ -15,7 +90,6 @@ UINT16	COMOutTable[28]	=	{
 0x6C2,
 0x6C3,
 0x6C4,
-
 0x7C0,
 0x7C1,
 0x7C2,
@@ -30,59 +104,5 @@ UINT16	COMOutTable[28]	=	{
 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;
-
-
-UINT8 Lockstatus = 0;
-UINT8 Error_count=0;
-
-//declear the UINT32 vars
-UINT32	battWarningState = 0xFFFFFFFF;
-UINT32	nbSwVersion = 0xFFFFFFFF;
-UINT32	battBalanceoInfo = 0xFFFFFFFF;
-
-UINT32 Battdesigncap =0xFFFFFFFF;
-//Tcp
-UINT8 	TcpSendLen = 0;
-
-UINT16 ErrorNum[5]={0};
-
-osMutexId_t Error_Mutex = NULL;
+};
 

+ 0 - 950
src/TcpTask.c

@@ -1,950 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   Qx.Chen jie
- * File name:    TcpTask.c
- * Description:  网络发送接收任务
- * History:      2021-03-07
- *
- ****************************************************************************/
-#include "bsp.h"
-#include "bsp_custom.h"
-#include "osasys.h"
-#include "ostask.h"
-#include "queue.h"
-#include "ps_event_callback.h"
-#include "app.h"
-#include "cmisim.h"
-#include "cmimm.h"
-#include "cmips.h"
-#include "sockets.h"
-#include "psifevent.h"
-#include "ps_lib_api.h"
-#include "lwip/netdb.h"
-//#include <cis_def.h>
-#include "debug_log.h"
-#include "slpman_ec616.h"
-#include "plat_config.h"
-#include "ec_tcpip_api.h"
-#include "MainTask.h"
-#include "TcpTask.h"
-#include "UartTask.h"
-#include "GpsTask.h"
-#include "Fota.h"
-#include "Signal.h"
-//全局变量输出区
-UINT32 TcpService = 0;
-UINT8 WorkFlag=0;
-//全局变量输入区
-extern UINT32 Timer_count;
-extern volatile BOOL Sleep_flag;
-extern osMutexId_t GpsMutex;
-extern UINT8 GpsData[20];
-extern AppNVMDataType AppNVMData;
-extern AppDataBody AppDataInfo;
-extern QueueHandle_t UartWriteCmdHandle;
-extern BOOL UartBattInfoRecvFlag;
-
-
-//局部变量申请
-AppSocketConnectionContext socContext = {-1, APP_SOCKET_CONNECTION_CLOSED};
-static StaticTask_t             gProcess_Tcp_Task_t;
-static UINT8                  gProcess_Tcp_TaskStack[PROC_TCP_TASK_STACK_SIZE];
-static QueueHandle_t            psEventQueueHandle;//状态转换队列句柄
-static osThreadId_t           TcpTaskId = NULL;
-static process_TCP 		    gProcess_Tcp_Task = PROCESS_TCP_STATE_IDLE;
-#define PROC_TCP_STATE_SWITCH(a)  (gProcess_Tcp_Task = a)
-static   eventCallbackMessage_t *queueItem = NULL;
-static UINT8                    gImsi[16] = {0};
-static UINT32                   gCellID = 0;
-static QueueHandle_t TcpRecvHandle = NULL;
-static UINT8                   TcpRecvEnd = 0;
-//Tcp线程堆栈申请区
-
-//函数声明区
-static void sendQueueMsg(UINT32 msgId, UINT32 xTickstoWait);
-static INT32 socketRegisterPSUrcCallback(urcID_t eventID, void *param, UINT32 paramLen);
-static void socketAppConnectionCallBack(UINT8 connectionEventType, void *bodyEvent);
-static void TcpDataInfoAssembleSend();
-static void TcpDataInfoRecvHandle();
-UINT8 bcc_chk(UINT8* data, UINT8 length);
-//线程任务区
-static void TcpTask(void* arg)
-{
-    appSetEDRXSettingSync(0,5,1800000);
-    appSetPSMSettingSync(1,3*60*60,10);
-    appSetCFUN(1);
-    psEventQueueHandle = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(eventCallbackMessage_t*));
-    PROC_TCP_STATE_SWITCH(PROCESS_TCP_STATE_IDLE);
-    if (psEventQueueHandle == NULL)
-    {
-        return;
-    }
-    if(TcpRecvHandle == NULL)
-	{
-		TcpRecvHandle = osMessageQueueNew(1,sizeof(TcpipConnectionRecvDataInd*), NULL);
-	}
-    if(Error_Mutex == NULL)
-    {
-        Error_Mutex = osMutexNew(NULL);
-    }
-    osDelay(5000);//等待驻网延时5s
-    while (true)
-    {
-        osDelay(100);
-        if(Sleep_flag)
-        {
-            sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
-            sendQueueMsg(QMSG_ID_SOCK_EXIT, 0);
-        }
-        else if(Timer_count%50==0 && TcpService==0x00 && AppNVMData.EOLState==1)
-        {
-            sendQueueMsg(QMSG_ID_SOCK_SENDPKG, 0);
-        }
-        else if(Timer_count%10==0)
-        {
-            TcpRecvEnd++;
-        }
-        if(TcpRecvEnd>=20)
-        {
-            TcpService = 0x00;
-            TcpRecvEnd=0;
-        }
-        if (xQueueReceive(psEventQueueHandle, &queueItem, 0))
-        {
-            switch(queueItem->messageId)
-            {
-                case QMSG_ID_NW_IP_READY:
-                    if(socContext.id < 0)
-                    {
-                        struct addrinfo hints;
-                        struct addrinfo *servinfo = NULL;
-                        char *Tcp_ip_des;
-                        memset(&hints, 0, sizeof(hints));
-                        hints.ai_family = AF_INET;
-                        hints.ai_socktype = SOCK_STREAM;
-                        getaddrinfo(QX_TCP_ADD, NULL, &hints, &servinfo);
-                        Tcp_ip_des = ip4addr_ntoa((const ip4_addr_t *)(&(servinfo->ai_addr->sa_data[2])));
-                        #ifdef USING_PRINTF1
-                            printf("\nservinfo-%d:\n",servinfo->ai_addr->sa_len);
-                            for(int i=0;i<4;i++)
-                                printf("%d ",servinfo->ai_addr->sa_data[2+i]);
-                            printf("\nTcp_ip_des-%d:\n",sizeof(Tcp_ip_des));
-                            for(int i=0;i<16;i++)
-                                printf("%c",*(Tcp_ip_des+i));
-                        #endif
-                        socContext.id  = tcpipConnectionCreate(TCPIP_CONNECTION_PROTOCOL_TCP, PNULL, 0, Tcp_ip_des, QX_TCP_PORT, socketAppConnectionCallBack);
-                        if (NULL != servinfo) {
-                            freeaddrinfo(servinfo);
-                        }
-
-                    }
-                    if(socContext.id  >= 0)
-                    {
-                        socContext.status = APP_SOCKET_CONNECTION_CONNECTED;
-                        #ifdef USING_PRINTF
-                            printf("create connection %u success", socContext.id);
-                        #endif
-                        ECOMM_TRACE(UNILOG_PLA_APP, ecTestCaseTcpClient_2, P_INFO, 1, "create connection %u success", socContext.id);
-                    }
-                    else
-                    {
-                        sendQueueMsg(QMSG_ID_NW_IP_NOREACHABLE, 0);
-                        #ifdef USING_PRINTF
-                            printf("create connection fail\n");
-                        #endif
-                        ECOMM_TRACE(UNILOG_PLA_APP, ecTestCaseTcpClient_3, P_ERROR, 0, "create connection fail");
-                    }
-                    break;
-                case QMSG_ID_NW_IP_NOREACHABLE:
-                    {
-                        Error_count++;
-                        appSetCFUN(0);
-                        osDelay(5000);
-                        appSetCFUN(1);
-                        osDelay(5000);
-                    }
-                    break;
-                case QMSG_ID_SOCK_SENDPKG:
-                    if (socContext.id >= 0 && socContext.status == APP_SOCKET_CONNECTION_CONNECTED)
-                    {
-                        TcpDataInfoAssembleSend();
-                    }
-                    else
-                    {
-                        sendQueueMsg(QMSG_ID_NW_IP_READY, 0);
-                        #ifdef USING_PRINTF
-                            printf("connection %u or status invalid", socContext.id, socContext.status);
-                        #endif
-                        ECOMM_TRACE(UNILOG_PLA_APP, ecTestCaseTcpClient_9, P_ERROR, 2, "connection %u or status invalid", socContext.id, socContext.status); 
-                    }
-                    break;
-                case QMSG_ID_SOCK_RECVPKG:
-                    TcpDataInfoRecvHandle();
-                    osDelay(100);
-                    TcpRecvEnd = 0;
-                    break;
-                case QMSG_ID_NW_IP_SUSPEND:
-                    if (socContext.id >= 0 && socContext.status != APP_SOCKET_CONNECTION_CLOSED)
-                    {
-                        if(tcpipConnectionClose(socContext.id) < 0)
-                        {
-                            socContext.id = -1;
-                            socContext.status = APP_SOCKET_CONNECTION_CLOSED;
-                            #ifdef USING_PRINTF
-                                printf("close connection %u success", socContext.id);
-                            #endif
-                            ECOMM_TRACE(UNILOG_PLA_APP, ecTestCaseTcpClient_4, P_INFO, 1, "close connection %u success", socContext.id);                            
-                        }
-                        else
-                        {
-                            #ifdef USING_PRINTF
-                                printf("close connection %u fail", socContext.id);
-                            #endif
-                            ECOMM_TRACE(UNILOG_PLA_APP, ecTestCaseTcpClient_5, P_ERROR, 1, "close connection %u fail", socContext.id);
-                        }
-                    }
-                    else
-                    {
-                        #ifdef USING_PRINTF
-                            printf("connection %u or status invalid", socContext.id, socContext.status);
-                        #endif
-                        ECOMM_TRACE(UNILOG_PLA_APP, ecTestCaseTcpClient_6, P_ERROR, 2, "connection %u or status invalid", socContext.id, socContext.status); 
-                    }                    
-                    break;
-                case QMSG_ID_SOCK_EXIT:
-                    #ifdef USING_PRINTF
-                        printf("QMSG_ID_SOCK_EXIT queueItem->messageId:%x\n",queueItem->messageId);
-                    #endif
-                    #ifdef USING_PRINTF
-                        printf("socket exit\n");
-                    #endif
-                    appSetCFUN(0);
-                    free(queueItem);
-                    osDelay(1000);
-                    TcpTaskDeInit(arg);
-                    break;
-            }
-        free(queueItem);
-        }
-    }//while 循环
-}
-//Tcp线程初始化
-void TcpTaskInit(void *arg)
-{
-    osThreadAttr_t task_attr;
-    registerPSEventCallback(NB_GROUP_ALL_MASK, socketRegisterPSUrcCallback);
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcess_Tcp_TaskStack, 0xA5, PROC_TCP_TASK_STACK_SIZE);
-    task_attr.name = "Tcp_Task";
-    task_attr.stack_mem = gProcess_Tcp_TaskStack;
-    task_attr.stack_size = PROC_TCP_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityBelowNormal7;
-    task_attr.cb_mem = &gProcess_Tcp_Task_t;
-    task_attr.cb_size = sizeof(StaticTask_t);
-    TcpTaskId = osThreadNew(TcpTask, NULL, &task_attr);
-}
-void TcpTaskDeInit(void *arg)
-{
-    osThreadTerminate(TcpTaskId);
-    TcpTaskId = NULL;
-}
-/*------------------------------函数区域----------------------------------------------------------------------------------------------*/
-static void TcpDataInfoAssembleSend()
-{   static UINT32 send_counter = 0;
-    
-    
-    
-    OsaUtcTimeTValue TimeStracture;
-    UINT8 csq=0;
-    INT8 snr=0;
-    INT8 rsnr=0;
-    INT16 Batt_current=0;
-    UINT16 BattU=0;
-    UINT8 temp=0;
-
-    UINT16 DataLen=0;
-    UINT8 BattSendFreq=6;
-    UINT8 GpsSendFreq=1;
-    UINT8 WorkState=0;
-
-    UINT16 year;
-    UINT8 month,day,hour,minute,sec;
-    UINT16 ErrorTemp;
-    UTC8TimeType UTC8TimeTcp;
-	int i = 0;
-	INT8 len = -1;
-    WorkState = battWorkState;
-    if(WorkState==0x00 && WorkFlag==0x01)
-    {
-        if(send_counter%(RUN_END_DELAY/5)==0)
-        {
-            WorkFlag=0x00;
-        }
-    }
-    else if(WorkState==0x00 && WorkFlag==0x02)
-    {
-        if(send_counter%(CHRG_END_DELAY/5)==0)
-        {
-            WorkFlag=0x00;
-        }
-    }
-    else
-    {
-        WorkFlag=WorkState;
-    }
-    switch(WorkFlag)
-    {
-        case 0x00:
-            BattSendFreq = AppDataInfo.BmsDisChrgInfoSendFreq/5;
-            GpsSendFreq = AppDataInfo.GpsChrgInfoSendFreq/5;
-            break;
-        case 0x01:
-            GpsSendFreq = AppDataInfo.GpsDisChrgInfoSendFreq/5;
-            BattSendFreq = AppDataInfo.BmsDisChrgInfoSendFreq/5;
-            break;
-        case 0x02:
-            BattSendFreq = AppDataInfo.BmsChrgInfoSendFreq/5;
-            GpsSendFreq = AppDataInfo.GpsChrgInfoSendFreq/5;
-            break;
-        default:
-            BattSendFreq = AppDataInfo.BmsDisChrgInfoSendFreq/5;
-            GpsSendFreq = AppDataInfo.GpsChrgInfoSendFreq/5;
-            break;
-    }    
-    if(send_counter%BattSendFreq==0)
-    {
-        BattMsgtoTcpType BattToTcpInfo;
-        //osStatus_t result = osMutexAcquire(UartMutex, osWaitForever);
-        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);
-
-        appGetSignalInfoSync(&csq,&snr,&rsnr);
-        DataLen= (UINT16)sizeof(BattToTcpInfo.battInfo);
-        BattToTcpInfo.startSymbol[0] = TCP_START_SYM1;
-	    BattToTcpInfo.startSymbol[1] = TCP_START_SYM2;
-	    BattToTcpInfo.cmdSymbol = TCP_CMD_SYM;
-	    BattToTcpInfo.ansSymbol = TCP_ANS_SYM;
-        memcpy(BattToTcpInfo.SN, AppNVMData.battSN,BATT_SN_LEN);
-        BattToTcpInfo.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
-	    BattToTcpInfo.dataLength[0] = (DataLen>>8) & 0xFF;
-	    BattToTcpInfo.dataLength[1] = DataLen & 0xFF;
-       
-        #ifdef USING_PRINTF1
-            printf("year:%x,month:%d,day:%d,hour:%d,minute:%d,second:%d\n",UTC8TimeTcp.year,UTC8TimeTcp.month,UTC8TimeTcp.day,UTC8TimeTcp.hour,UTC8TimeTcp.minute,UTC8TimeTcp.second);
-        #endif
-        BattToTcpInfo.battInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; 	//year
-        BattToTcpInfo.battInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;							//month
-        BattToTcpInfo.battInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;									//day
-        BattToTcpInfo.battInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; 						    //hour
-        BattToTcpInfo.battInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;						    //mins
-        BattToTcpInfo.battInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF;							//sec
-        BattToTcpInfo.battInfo.msgMark = BATTMSG;
-        BattToTcpInfo.battInfo.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; 	//year
-        BattToTcpInfo.battInfo.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF;							//month
-        BattToTcpInfo.battInfo.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF;									//day
-        BattToTcpInfo.battInfo.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; 						    //hour
-        BattToTcpInfo.battInfo.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;					    //mins
-        BattToTcpInfo.battInfo.msgCollectionTimeUTC[5] = UTC8TimeTcp.second & 0xFF;							//sec
-        BattToTcpInfo.battInfo.signalStrength = csq ;
-        //故障等级故障代码上传
-        if(osOK==osMutexAcquire(Error_Mutex, 100))
-        {   
-            UINT16 ErrorTemp=0x00;
-            ErrorTemp = GetErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum));
-            #ifdef USING_PRINTF1
-                printf("Temp-Error:%d\n",ErrorTemp);
-            #endif
-            BattToTcpInfo.battInfo.errClass = 0x00;
-            BattToTcpInfo.battInfo.errCode[0] = ErrorTemp>>8;
-            BattToTcpInfo.battInfo.errCode[1] = ErrorTemp;
-        }
-        else
-        {
-            #ifdef USING_PRINTF1
-                printf("Temp-Error:%d\n",ErrorTemp);
-            #endif
-            BattToTcpInfo.battInfo.errClass = 0x00;
-            BattToTcpInfo.battInfo.errCode[0] = 0x00;
-            BattToTcpInfo.battInfo.errCode[1] = 0x00;
-        }
-        osMutexRelease(Error_Mutex);
-		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+NB_OTHER_TEMP_NUM;//其他温度编号(包含环境温度mos温度以及接插件温度)2021-03-24其他温度修改
-		BattToTcpInfo.battInfo.battotherTemp[0] = MOSTemp;
-		BattToTcpInfo.battInfo.battotherTemp[1] = packTemp;       
-        BattToTcpInfo.battInfo.battotherTemp[2] = fastChargeTemp;
-        BattToTcpInfo.battInfo.battotherTemp[3] = normalChargeTemp;
-        BattToTcpInfo.battInfo.battotherTemp[4] = heatTemp1;
-        BattToTcpInfo.battInfo.battotherTemp[5] = heatTemp2;
-        BattToTcpInfo.CRC = bcc_chk((UINT8 *)&BattToTcpInfo, sizeof(BattMsgtoTcpType)-1 );
-        //osMutexRelease(UartMutex);
-        if(UartBattInfoRecvFlag)
-        {
-            len = tcpipConnectionSend(socContext.id, (UINT8 *)&BattToTcpInfo, sizeof(BattToTcpInfo), 0, 0, 0);
-            if(len>0)
-            {
-                TcpSendLen = 0x02 | TcpSendLen;
-            }
-            else
-            {
-                TcpSendLen = 0xFD & TcpSendLen;
-                sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
-            }
-        }
-    }
-    if(send_counter%GpsSendFreq==0)
-    {
-        GPSMsgtoTcpType GpsToTcpInfo;
-        osStatus_t result = osMutexAcquire(GpsMutex, osWaitForever);
-        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= (UINT16)sizeof(GpsToTcpInfo.gpsInfo);
-        GpsToTcpInfo.startSymbol[0] = TCP_START_SYM1;
-	    GpsToTcpInfo.startSymbol[1] = TCP_START_SYM2;
-	    GpsToTcpInfo.cmdSymbol = TCP_CMD_SYM;
-	    GpsToTcpInfo.ansSymbol = TCP_ANS_SYM;
-        memcpy(GpsToTcpInfo.SN, AppNVMData.battSN,BATT_SN_LEN);
-        GpsToTcpInfo.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
-	    GpsToTcpInfo.dataLength[0] = (DataLen>>8) & 0xFF;
-	    GpsToTcpInfo.dataLength[1] = DataLen & 0xFF;
-        GpsToTcpInfo.gpsInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; 	//year
-        GpsToTcpInfo.gpsInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;						//month
-        GpsToTcpInfo.gpsInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;										//day
-        GpsToTcpInfo.gpsInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; 						    //hour
-        GpsToTcpInfo.gpsInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;						    //mins
-        GpsToTcpInfo.gpsInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF;							//sec
-        GpsToTcpInfo.gpsInfo.msgMark = GPSMSG;
-        GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; 	//year
-        GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF;								//month
-        GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF;									//day
-        GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF; 						    //hour
-        GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;						    //mins
-        GpsToTcpInfo.gpsInfo.msgCollectionTimeUTC[5] = UTC8TimeTcp.second & 0xFF;
-        memcpy((UINT8 *)&GpsToTcpInfo.gpsInfo.locateMark, GpsData,sizeof(GpsData));
-        GpsToTcpInfo.CRC = bcc_chk((UINT8 *)&GpsToTcpInfo, sizeof(GPSMsgtoTcpType)-1 );
-        osMutexRelease(GpsMutex);
-        //if(GpsToTcpInfo.gpsInfo.locateMark==0x01)
-        if(1)
-        {
-            len = tcpipConnectionSend(socContext.id, (UINT8 *)&GpsToTcpInfo, sizeof(GpsToTcpInfo), 0, 0, 0);
-            if(len>0)
-            {
-                TcpSendLen = 0x04 | TcpSendLen;
-            }
-            else
-            {
-                TcpSendLen = 0xFB & TcpSendLen;
-                sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
-            }
-        }
-        #ifdef USING_PRINTF1
-            printf("GpsMsg:\n");
-            UINT8* p = (UINT8 *)&GpsToTcpInfo;  
-            for(int i =0 ;i<sizeof(GpsToTcpInfo);i++)
-                printf("%x ",*(p+i));
-        #endif
-    }
-    if(send_counter==1)//版本信息上报
-    {
-        VersionMsgtoTcpType VerMsgToTcpInfo;
-        CHAR iccid[20];
-        CHAR imei[15];
-        appGetIccidNumSync(iccid);
-        appGetImeiNumSync(imei);
-        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= (UINT16)sizeof(VerMsgToTcpInfo.VerInfo);
-        VerMsgToTcpInfo.startSymbol[0] = TCP_START_SYM1;
-	    VerMsgToTcpInfo.startSymbol[1] = TCP_START_SYM2;
-	    VerMsgToTcpInfo.cmdSymbol = TCP_CMD_SYM;
-	    VerMsgToTcpInfo.ansSymbol = TCP_ANS_SYM;
-        memcpy(VerMsgToTcpInfo.SN, AppNVMData.battSN,BATT_SN_LEN);
-        VerMsgToTcpInfo.encryptMethod = TCP_ENCPT_DISABLE; //not encrypt
-	    VerMsgToTcpInfo.dataLength[0] = (DataLen>>8) & 0xFF;
-	    VerMsgToTcpInfo.dataLength[1] = DataLen & 0xFF;
-        VerMsgToTcpInfo.VerInfo.sendTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF;	//year
-        VerMsgToTcpInfo.VerInfo.sendTimeUTC[1] = UTC8TimeTcp.month & 0xFF;								//month
-        VerMsgToTcpInfo.VerInfo.sendTimeUTC[2] = UTC8TimeTcp.day & 0xFF;									//day
-        VerMsgToTcpInfo.VerInfo.sendTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;  						    //hour
-        VerMsgToTcpInfo.VerInfo.sendTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;						    //mins
-        VerMsgToTcpInfo.VerInfo.sendTimeUTC[5] = UTC8TimeTcp.second & 0xFF;							//sec
-        VerMsgToTcpInfo.VerInfo.msgMark = VERSIONMSG;
-        VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[0] = (UTC8TimeTcp.year - 0x07D0) & 0xFF; 	//year
-        VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[1] = UTC8TimeTcp.month & 0xFF;								//month
-        VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[2] = UTC8TimeTcp.day & 0xFF;									//day
-        VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[3] = UTC8TimeTcp.hour & 0xFF;  						    //hour
-        VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[4] = UTC8TimeTcp.minute & 0xFF;						    //mins
-        VerMsgToTcpInfo.VerInfo.msgCollectionTimeUTC[5] = UTC8TimeTcp.second & 0xFF;
-        memcpy(VerMsgToTcpInfo.VerInfo.ICCID,iccid,20);
-        memcpy(VerMsgToTcpInfo.VerInfo.IMEI,imei,15);
-        //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;
-        VerMsgToTcpInfo.VerInfo.BLVersion[1] = (BLSWVERSION>>16)& 0xFF;
-        VerMsgToTcpInfo.VerInfo.BLVersion[2] = (BLSWVERSION>>8)& 0xFF;
-        VerMsgToTcpInfo.VerInfo.BLVersion[3] = (BLSWVERSION)& 0xFF;
-        VerMsgToTcpInfo.VerInfo.DRVVersion[0] = (DRVSWVERSION>>24)& 0xFF;
-        VerMsgToTcpInfo.VerInfo.DRVVersion[1] = (DRVSWVERSION>>16)& 0xFF;
-        VerMsgToTcpInfo.VerInfo.DRVVersion[2] = (DRVSWVERSION>>8)& 0xFF;
-        VerMsgToTcpInfo.VerInfo.DRVVersion[3] = (DRVSWVERSION)& 0xFF;
-        VerMsgToTcpInfo.VerInfo.APPVersion[0] = (APPSWVERSION>>24)& 0xFF;
-        VerMsgToTcpInfo.VerInfo.APPVersion[1] = (APPSWVERSION>>16)& 0xFF;
-        VerMsgToTcpInfo.VerInfo.APPVersion[2] = (APPSWVERSION>>8)& 0xFF;
-        VerMsgToTcpInfo.VerInfo.APPVersion[3] = (APPSWVERSION)& 0xFF;
-        VerMsgToTcpInfo.VerInfo.BmsType = BMS_MANUFACTURE;
-        VerMsgToTcpInfo.VerInfo.BmsInfo = BMS_INFO;
-        VerMsgToTcpInfo.VerInfo.DataModuleType = DATA_MODULE_TYPE;
-        VerMsgToTcpInfo.CRC = bcc_chk((UINT8 *)&VerMsgToTcpInfo, sizeof(VerMsgToTcpInfo)-1 );
-        if(UartBattInfoRecvFlag==TRUE&&NB_Fota_update_flag==FALSE)
-        {
-            len = tcpipConnectionSend(socContext.id, (UINT8 *)&VerMsgToTcpInfo, sizeof(VerMsgToTcpInfo), 0, 0, 0);
-            if(len>0)
-            {
-                TcpSendLen = 0x01 | TcpSendLen;
-            }
-            else
-            {
-                TcpSendLen = 0xFE & TcpSendLen;
-                sendQueueMsg(QMSG_ID_NW_IP_SUSPEND, 0);
-            }
-        }
-        else
-        {
-            send_counter = 1;
-            return;
-        }
-    }
-    if(send_counter==0)//发送本次文件中的调试信息
-    {
-        DebugMsgtoTcpType DebugMsgInfo;
-        UINT8 *SendBuffer = PNULL;
-        UINT16 BufferLen = 0;
-        BufferLen = Debug_GetSize();
-        if(BufferLen>200)
-        {
-            Debug_Del_Logfile();
-            #ifdef DEBUGLOG
-                Debug_printf("Sys:%d\n",AppDataInfo.SysReStart);
-            #endif
-            BufferLen = Debug_GetSize();
-        }
-        UINT8 rbuf[BufferLen];
-        Debug_Read_Logfile(rbuf,BufferLen);
-        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("DebugMsgInfo!\n");
-            UINT8* p = SendBuffer;
-            for(i =0 ;i<BufferLen+sizeof(DebugMsgInfo);i++)
-                printf("%x ",*(p+i));
-        #endif
-        Debug_Del_Logfile();
-        free(SendBuffer);
-    }
-    if(send_counter>0xffff)
-    {
-        send_counter = 0;
-    }    
-    else
-    {
-        send_counter++;
-    }
-}
-//Tcp数据接收处理函数
-static void TcpDataInfoRecvHandle()
-{
-    TcpipConnectionRecvDataInd *TcpRecvData;
-    osMessageQueueGet(TcpRecvHandle,&TcpRecvData,0,0);
-    osDelay(100);
-    Uart_Write_Data_Type UartWriteCmd;
-    OsaUtcTimeTValue TimeStracture;
-    UINT8 DataLen;
-    UINT8 Tcp_Cmd;
-    UINT8 Control_Cmd;
-    UINT8 *Ptr;
-    UINT8 TcpCmdAnswer[31];
-    TcpCmdAnswer[0] = TCP_START_SYM1;
-    TcpCmdAnswer[1] = TCP_START_SYM1;
-    if(TcpRecvData != PNULL)
-    {
-        Ptr = TcpRecvData->data;
-        if((*(Ptr+0)==TCP_START_SYM1)&&(*(Ptr+1)==TCP_START_SYM2))//服务器起始信息
-        {
-            Tcp_Cmd = *(Ptr+2);//命令标志
-            if(*(Ptr+3)==0xFE)
-            {
-                TcpService=0x01;
-            }
-            switch (Tcp_Cmd)
-            {
-                case TCP_QUERY_SYM:
-                    break;
-                case TCP_SETCMD_SYM:
-                    break;
-                case TCP_CONCMD_SYM:
-                {
-                    TcpCmdAnswer[2] = TCP_CONCMD_SYM;
-                    if(*(Ptr+30)==0x01)//远程升级命令
-                    {
-                        Fota_Func(Ptr,socContext.id);
-                    }
-                    else if(*(Ptr+30)==0x88)//BMS远程升级数据传输命令
-                    {
-                        Fota_Func(Ptr,socContext.id);
-                    }
-                    else if(*(Ptr+30)==0x80)//远程锁定命令
-                    {
-                        //osMutexAcquire(UartMutex, osWaitForever);
-                        TcpCmdAnswer[3] = 0x01;
-                        memcpy(&TcpCmdAnswer[4],(Ptr+4),BATT_SN_LEN);
-                        TcpCmdAnswer[21] = TCP_ENCPT_DISABLE;
-                        TcpCmdAnswer[22] = 0x00;
-                        TcpCmdAnswer[23] = 0x06;
-                        memcpy(&TcpCmdAnswer[24],(Ptr+24),6);
-                        TcpCmdAnswer[30] = bcc_chk(TcpCmdAnswer,30);
-                        if(*(Ptr+31)==0x01)//0x01代表锁定
-                        {
-                            AppNVMData.appDataModify = 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);
-                        }
-                        else                //0x02代表解锁
-                        {
-                            AppNVMData.appDataModify = TRUE;
-                            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);
-                        }
-                        //osMutexRelease(UartMutex);
-                        TcpService=0x00;
-                        
-                    }
-                    else
-                    {
-                        TcpCmdAnswer[3] = 0x0f;
-                        memcpy(&TcpCmdAnswer[4],(Ptr+4),BATT_SN_LEN);
-                        TcpCmdAnswer[21] = TCP_ENCPT_DISABLE;
-                        TcpCmdAnswer[22] = 0x00;
-                        TcpCmdAnswer[23] = 0x06;
-                        memcpy(&TcpCmdAnswer[24],(Ptr+24),6);
-                        TcpCmdAnswer[30] = bcc_chk(TcpCmdAnswer,30);
-                        tcpipConnectionSend(socContext.id,TcpCmdAnswer,31,0,0,0);
-                    }
-                    break;
-                }
-                default:
-                {
-                    break;
-                }
-            }
-        }
-    free(TcpRecvData); 
-    }
-}
-//TCP发送校验函数
-UINT8 bcc_chk(UINT8* data, UINT8 length)
-{
-    UINT8 bcc_chk_return = 0x00;
-    UINT8 count = 0;
-    while (count<length)
-    {
-        bcc_chk_return^=data[count];
-        count++;
-    }
-    return  bcc_chk_return;
-}
-//Tcp 状态转换函数
-static void sendQueueMsg(UINT32 msgId, UINT32 xTickstoWait)
-{
-    eventCallbackMessage_t *queueMsg = NULL;
-    queueMsg = malloc(sizeof(eventCallbackMessage_t));
-    queueMsg->messageId = msgId;
-    if (psEventQueueHandle)
-    {
-        if (pdTRUE != xQueueSend(psEventQueueHandle, &queueMsg, xTickstoWait))
-        {
-            ECOMM_TRACE(UNILOG_PLA_APP, sendQueueMsg_1, P_ERROR, 0, "xQueueSend error");
-        }
-    }
-}
-//Tcp状态注册函数
-static INT32 socketRegisterPSUrcCallback(urcID_t eventID, void *param, UINT32 paramLen)
-{
-    CmiSimImsiStr *imsi = NULL;
-    CmiPsCeregInd *cereg = NULL;
-
-    UINT8 rssi = 0, index = 0;
-    NmAtiNetifInfo *netif = NULL;
-
-    switch(eventID)
-    {
-        case NB_URC_ID_SIM_READY:
-        {
-            imsi = (CmiSimImsiStr *)param;
-            memcpy(gImsi, imsi->contents, imsi->length);
-            #ifdef USING_PRINTF
-                printf("SIM ready(imsi=%s)\n",(UINT8 *)imsi->contents);
-            #endif
-            break;
-        }
-        case NB_URC_ID_MM_SIGQ:
-        {
-            rssi = *(UINT8 *)param;
-            #ifdef USING_PRINTF
-                printf("RSSI signal=%d\n",rssi);
-            #endif
-            break;
-        }
-        case NB_URC_ID_PS_BEARER_ACTED:
-        {
-            #ifdef USING_PRINTF
-                printf("Default bearer activated\n");
-            #endif
-            break;
-        }
-        case NB_URC_ID_PS_BEARER_DEACTED:
-        {
-            #ifdef USING_PRINTF
-                printf("Default bearer Deactivated\n");
-            #endif
-            break;
-        }
-        case NB_URC_ID_PS_CEREG_CHANGED:
-        {
-            cereg = (CmiPsCeregInd *)param;
-            gCellID = cereg->celId;
-            #ifdef USING_PRINTF
-                printf("URCCallBack:CEREG changed act:%d celId:%d locPresent:%d tac:%d\n", cereg->act, cereg->celId, cereg->locPresent, cereg->tac);
-            #endif
-            break;
-        }
-        case NB_URC_ID_PS_NETINFO:
-        {
-            netif = (NmAtiNetifInfo *)param;
-            if (netif->netStatus == NM_NETIF_ACTIVATED)
-                sendQueueMsg(QMSG_ID_NW_IP_READY, 0);
-            break;
-        }
-    }
-    return 0;
-}
-//Tcpz连接状态回调函数
-static void socketAppConnectionCallBack(UINT8 connectionEventType, void *bodyEvent)
-{
-    switch(connectionEventType)
-    {
-        case TCPIP_CONNECTION_STATUS_EVENT:
-        {
-            TcpipConnectionStatusInd *statusInd;
-            statusInd = (TcpipConnectionStatusInd *)bodyEvent;
-            if(statusInd != PNULL)
-            {
-                if(statusInd->status == TCPIP_CONNECTION_STATUS_CLOSED)
-                {
-                    #ifdef USING_PRINTF
-                        printf("socketAppConnectionCallBack socket connection %u closed,cause %u", statusInd->connectionId, statusInd->cause);
-                    #endif
-                    ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_1, P_ERROR, 2, "socketAppConnectionCallBack socket connection %u closed,cause %u", statusInd->connectionId, statusInd->cause);
-                    if(statusInd->connectionId == socContext.id)
-                    {
-                        socContext.id = -1;
-                        socContext.status = APP_SOCKET_CONNECTION_CLOSED;
-                    }
-                }
-                else if(statusInd->status == TCPIP_CONNECTION_STATUS_CONNECTING)
-                {
-                    #ifdef USING_PRINTF
-                        printf("socketAppConnectionCallBack socket connection %u is connecting", statusInd->connectionId);
-                    #endif
-                    ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_2, P_INFO, 1, "socketAppConnectionCallBack socket connection %u is connecting", statusInd->connectionId);
-                    if(statusInd->connectionId == socContext.id)
-                    {
-                        socContext.status = APP_SOCKET_CONNECTION_CONNECTING;
-                    }
-                }
-                else if(statusInd->status == TCPIP_CONNECTION_STATUS_CONNECTED)
-                {
-                    #ifdef USING_PRINTF
-                        printf("socketAppConnectionCallBack socket connection %u is connected", statusInd->connectionId);
-                    #endif
-                    ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_3, P_ERROR, 1, "socketAppConnectionCallBack socket connection %u is connected", statusInd->connectionId);
-                    if(statusInd->connectionId == socContext.id)
-                    {
-                        socContext.status = APP_SOCKET_CONNECTION_CONNECTED;
-                    }
-                }
-            }
-            else
-            {
-                #ifdef USING_PRINTF
-                    printf("socketAppConnectionCallBack invalid connection status event");
-                #endif
-                ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_4, P_ERROR, 0, "socketAppConnectionCallBack invalid connection status event");
-            }
-
-            break;
-        }
-        case TCPIP_CONNECTION_RECEIVE_EVENT:
-        {
-            TcpipConnectionRecvDataInd *rcvInd;
-            TcpipConnectionRecvDataInd *rcvbuffer = NULL;
-            rcvInd = (TcpipConnectionRecvDataInd *)bodyEvent;
-            if(rcvInd != PNULL)
-            {
-                rcvbuffer = malloc(sizeof(TcpipConnectionRecvDataInd));
-                memcpy(rcvbuffer,rcvInd,sizeof(TcpipConnectionRecvDataInd));
-                osMessageQueuePut(TcpRecvHandle,&rcvbuffer,0,1000);
-                sendQueueMsg(QMSG_ID_SOCK_RECVPKG, 0);
-                #ifdef USING_PRINTF
-                    uint8_t* Ptr;
-                    Ptr=rcvInd->data;
-                    printf("socket connection %u receive length %u data:", rcvInd->connectionId, rcvInd->length);
-                    for(int i = 0;i<rcvInd->length;i++)
-                        printf("%x  ",*(Ptr+i));
-                    printf("\n");
-                #endif
-                ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_5, P_INFO, 2, "socketAppConnectionCallBack socket connection %u receive length %u data", rcvInd->connectionId, rcvInd->length);
-            }
-            else
-            {
-                #ifdef USING_PRINTF
-                    printf( "socketAppConnectionCallBack invalid connection rcv event");
-                #endif
-                ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_6, P_ERROR, 0, "socketAppConnectionCallBack invalid connection rcv event");
-            }
-            break;
-        }
-        case TCPIP_CONNECTION_UL_STATUS_EVENT:
-        {
-            TcpipConnectionUlDataStatusInd *ulStatusInd;
-            ulStatusInd = (TcpipConnectionUlDataStatusInd *)bodyEvent;
-            if(ulStatusInd != PNULL)
-            {
-                if(ulStatusInd->status == Tcpip_Connection_UL_DATA_SUCCESS)
-                {
-                    #ifdef USING_PRINTF
-                        printf( "socketAppConnectionCallBack socket connection %u sequence %u data has sent success", ulStatusInd->connectionId, ulStatusInd->sequence);
-                    #endif
-                    ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_7, P_INFO, 2, "socketAppConnectionCallBack socket connection %u sequence %u data has sent success", ulStatusInd->connectionId, ulStatusInd->sequence);
-                }
-                else if(ulStatusInd->status == Tcpip_Connection_UL_DATA_FAIL)
-                {
-                    #ifdef USING_PRINTF
-                        printf("socketAppConnectionCallBack socket connection %u sequence %u data has sent fail", ulStatusInd->connectionId, ulStatusInd->sequence);
-                    #endif
-                    ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_8, P_WARNING, 2, "socketAppConnectionCallBack socket connection %u sequence %u data has sent fail", ulStatusInd->connectionId, ulStatusInd->sequence);
-                }
-            }
-            else
-            {
-                #ifdef USING_PRINTF
-                    printf("socketAppConnectionCallBack invalid connection ul status event");
-                #endif
-                ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_9, P_ERROR, 0, "socketAppConnectionCallBack invalid connection ul status event");
-            }
-            break;
-        }
-        default:
-            #ifdef USING_PRINTF
-                printf("socketAppConnectionCallBack invalid event type %u", connectionEventType);
-            #endif
-            ECOMM_TRACE(UNILOG_PLA_APP, socketAppConnectionCallBack_10, P_ERROR, 1, "socketAppConnectionCallBack invalid event type %u", connectionEventType);
-            break;
-    }
-    
-}

+ 0 - 657
src/UDSService.c

@@ -1,657 +0,0 @@
-#include "bsp.h"
-#include "bsp_custom.h"
-#include "osasys.h"
-#include "ostask.h"
-#include "queue.h"
-#include "ps_event_callback.h"
-#include "cmisim.h"
-#include "cmimm.h"
-#include "cmips.h"
-#include "sockets.h"
-#include "psifevent.h"
-#include "ps_lib_api.h"
-#include "lwip/netdb.h"
-#include <cis_def.h>
-#include "debug_log.h"
-#include "slpman_ec616.h"
-#include "plat_config.h"
-#include "ec_tcpip_api.h"
-#include "hal_module_adapter.h"
-#include "UartTask.h"
-#include "MainTask.h"
-#include "app.h"
-#include "CANTask.h"
-#include "flash_ec616_rt.h"
-#include "Signal.h"
-#include "UDSService.h"
-
-
-
-extern AppSocketConnectionContext socContext;
-extern UINT8 GpsData[16];
-extern UINT8 battInfo[8*14];
-
-
-void UDS_Service(void);
-void UDS_CAN_Update(void);
-BOOL UDSClearFotaDownloadRegion(void);
-BOOL UDSAskforDownLoadData(void);
-UINT8 UDSPositiveAnswer(UINT8 answerLen,UINT8 messageIndex,UINT32 posCode);
-UINT8 UDSNegtiveAnswer(UINT8 answerLen,UINT8 messageIndex, UINT32 negCode);
-extern void appSaveConfigValue(void);
-
-
-UINT8	UDSService[2];
-UINT8	UDSSubService[2];
-UINT8	UDSSubServiceActionCode[2];
-UINT8 	UDSSwitch = 0;
-UINT8   UDSDialogMode = 01;
-UINT8   UDSBattSN[BATT_SN_LEN];
-
-UINT32  updateDifferDataByteLen = 0;
-
-//each package means 100 bytes, max PackageCounter = updateDifferDataByteLen%100 + 1
-UINT16  updateDifferDataPackageCounter = 0;  
-
-//each slice means 4 bytes, max SliceCounter = 25;
-UINT32  updateDifferDataSliceCounter = 0;
-static BOOL downloadReady = FALSE;
-
-UINT8   updateDataBuffer[100];
-
-
-
-
-
-void UDS_Service()
-{
-	UINT8 i,j= 0;
-	UINT32 k=0;
-	INT8 ret,errorCount = 0;
-	BOOL boolRet = false;
-	static UINT8 snFlag = 0;
-	static UINT32 sliceCounterFlag = 0;
-	UINT32 tempSliceCounter=0;	
-	static UINT8 counter=0;  
-	CAN_Msg_Type UDSAnswer ={0};
-	
-	UINT32 posCode,negCode;
-	
-	
-	//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);
-	
-	//while(true)
-	//{
-		//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])
-						{
-							case 0x10:
-								if(UDSSubService[i] == 0x01)
-								{
-									if((UDSDialogMode == 0x01 || UDSDialogMode==0x02)||UDSSwitch == 0)
-									{									
-										UDSPositiveAnswer(0x04,i,0x00);
-										UDSSwitch = 0;
-										UDSDialogMode = 1;
-									}
-									else
-									{
-										UDSNegtiveAnswer(0x05,i,0xFF);
-									}
-								}
-								else if(UDSSubService[i] == 0x02)
-								{
-									UDSPositiveAnswer(0x04,i,0x00);
-									UDSSwitch = 1;
-									UDSDialogMode = 2;									
-								}
-								else if(UDSSubService[i] == 0x03)
-								{
-									if(UDSSwitch == 1)
-									{
-										UDSPositiveAnswer(0x04,i,0x00);
-										UDSSwitch = 1;
-										UDSDialogMode = 3;
-			                		}
-			                		else
-			                		{
-										UDSNegtiveAnswer(0x05,i,0xFF);
-			                		}
-
-								}
-								else if(UDSSubService[i] == 0x11)   //make NB software reset
-								{
-									if(UDSDialogMode == 2)
-									{
-										UDSPositiveAnswer(0x04,i,0x00);										
-										osDelay(100);
-										appSaveNVMData();
-										appSetCFUN(0);
-										osDelay(1000);
-			                			EC_SystemReset();
-			                		}
-			                		else
-			                		{
-										UDSNegtiveAnswer(0x05,i,0xFF);  
-			                		}
-								}								
-								else
-								{
-									UDSNegtiveAnswer(0x05,i,0xEE);
-								}
-								break;
-							case 0x22:
-								if(UDSDialogMode == 2)
-								{
-									if(UDSSubService[i] == 0x01)		//check the sw of NB
-									{
-										UDSPositiveAnswer(0x08,i,APPSWVERSION);
-									}
-									else if(UDSSubService[i] == 0x02)  //check the hw of NB
-									{
-										UDSPositiveAnswer(0x06,i,HWVERSION);										
-									}
-									else if(UDSSubService[i] == 0x03)  //check the SN number
-									{											
-										switch(UDSSubServiceActionCode[i])
-										{
-											case 00:
-												UDSAnswer.Id = 0x7B0;
-												
-												CANEncodeFunction(UDSAnswer.Id, UDSAnswer.Data);
-												ret = HAL_Can_Transmit(UDSAnswer);
-												
-												break;
-												
-											case 01:
-												UDSAnswer.Id = 0x7B1;
-												CANEncodeFunction(UDSAnswer.Id, UDSAnswer.Data);
-												ret = HAL_Can_Transmit(UDSAnswer);
-
-												break;
-
-											case 02:
-												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
-									{
-										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
-									{				
-										UINT32 temp = ((fastChargeTemp<<24)&0xFF000000) | ((normalChargeTemp<<16)&0xFF0000) | ((heatTemp1<<8)&0xFF00) | (heatTemp2&0xFF);				
-										UDSPositiveAnswer(0x08,i,temp);  //ntcvalue										
-									}									
-									else if(UDSSubService[i] == 0x06)	//check the tcp link of NB
-									{
-										UDSPositiveAnswer(0x06,i,TcpSendLen);  //TcpconnectStatus
-									}
-									else if(UDSSubService[i] == 0x07)  //check the GPS link of NB
-									{
-										posCode =(UINT32) GpsData[1];
-										UDSPositiveAnswer(0x05,i,posCode);  //gps satellite num(uint8), should be modified
-									}	
-									else
-									{
-										UDSNegtiveAnswer(0x05,i,0xEE);
-									}
-								}
-								else	//the service is not surpported in current dialog mode
-								{
-									UDSNegtiveAnswer(0x05,i,0xFF);
-								}
-								break;
-							case 0x2E:   //write service
-								if(UDSDialogMode == 2)
-								{
-									if(UDSSubService[i] == 0x03)  // write the battSN
-									{
-										if(UDSSubServiceActionCode[i] == 0x00 && snFlag == 0x00)
-										{
-											for(j=0; j<5; j++)
-											{
-												UDSBattSN[j+5*0] = CanRxMsg[i].Data[j+3];
-											}	
-											snFlag = snFlag|0x01;
-										}
-										else if(UDSSubServiceActionCode[i] == 0x01 && snFlag == 0x01)
-										{
-											for(j=0; j<5; j++)
-											{
-												UDSBattSN[j+5*1] = CanRxMsg[i].Data[j+3];
-											}
-											snFlag = snFlag|0x02;
-										}
-										else if(UDSSubServiceActionCode[i] == 0x02 && snFlag == 0x03)
-										{
-											for(j=0; j<5; j++)
-											{
-												UDSBattSN[j+5*2] = CanRxMsg[i].Data[j+3];
-											}
-											snFlag = snFlag|0x04;
-										}
-										else if(UDSSubServiceActionCode[i] == 0x03 && snFlag == 0x07)
-										{
-											for(j=0; j<2; j++)
-											{
-												UDSBattSN[j+5*3] = CanRxMsg[i].Data[j+3];
-											}
-											snFlag = snFlag|0x08;
-										}
-
-										if(snFlag == 0x0F)
-										{
-											snFlag = 0;
-											UDSPositiveAnswer(0x04,i,00);
-											MEMCPY(AppNVMData.battSN, UDSBattSN, BATT_SN_LEN);
-											AppNVMData.EOLState = 1; //SN号写入完成,表明已经进行过下线配置
-											appSaveNVMData();
-										}
-										else
-										{
-											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;	
-											
-											ret = HAL_Can_Transmit(UDSAnswer);
-										}										
-									}
-									else if(UDSSubService[i] == 0x0F) //write the update config:updateDifferDataByteLen
-									{										
-										updateDifferDataByteLen = (CanRxMsg[i].Data[2]<<16)|(CanRxMsg[i].Data[3]<<8)|CanRxMsg[i].Data[4];										
-										UDSPositiveAnswer(0x04,i,00);
-									}
-									else
-									{
-										UDSNegtiveAnswer(0x05,i,0xEE);
-										
-									}
-									break;
-								}								
-								else
-								{
-									UDSNegtiveAnswer(0x05,i,0xFF);
-								}
-								break;
-							case 0x31:  //clear the flash service
-								if(UDSDialogMode == 3)  
-								{
-									if(UDSSubService[i] == 0x0F)  //clear the fota flash
-									{
-										if(UDSSubServiceActionCode[i] == 0x01)
-										{
-											//Clear the Flash
-											boolRet = UDSClearFotaDownloadRegion();
-											//if ok											
-											UDSPositiveAnswer(0x05,i,(UINT32)boolRet);
-										}
-										else
-										{
-											UDSNegtiveAnswer(0x06,i,UDSSubServiceActionCode[i]<<8|0xFF);  //重点测试
-										}										
-									}
-									else
-									{
-										UDSNegtiveAnswer(0x05,i,0xEE);  //the subservice is not surpported
-									}
-								}
-								else
-								{
-									UDSNegtiveAnswer(0x05,i,0xFF);  //the survie is not surpported in current dialog mode
-								}
-								break;
-							case 0x34:  //prepare for some one process
-								if(UDSDialogMode == 3)
-								{
-									if(UDSSubService[i] == 0x0F)  //ask for download update data
-									{									
-										boolRet = UDSAskforDownLoadData();
-										//if ok											
-										UDSPositiveAnswer(0x05,i,(UINT32)boolRet);
-									}
-									else
-									{
-										UDSNegtiveAnswer(0x05,i,0xEE);
-									}
-								}
-								else
-								{
-									UDSNegtiveAnswer(0x05,i,0xFF);
-								}
-								break;
-							case 0x36:  //download the update data
-								if(UDSDialogMode == 3)
-								{
-									if(downloadReady == TRUE)
-									{
-										counter++;  //记录报文数量									
-										tempSliceCounter =  (CanRxMsg[i].Data[1]<<16)|(CanRxMsg[i].Data[2]<<8)|(CanRxMsg[i].Data[3]);
-									/*
-									#ifdef USING_PRINTF
-										printf("tempSliceCounter = %x\n",tempSliceCounter);
-									#endif
-									*/										
-										if(tempSliceCounter < (updateDifferDataPackageCounter+1)*25 && tempSliceCounter>=updateDifferDataPackageCounter*25)
-										{
-											updateDifferDataSliceCounter = tempSliceCounter % 25;
-											for(j=0;j<4;j++)
-											{
-												updateDataBuffer[updateDifferDataSliceCounter*4+j] = CanRxMsg[i].Data[4+j];
-											}								
-											
-											if(updateDifferDataSliceCounter>0)
-											{
-												sliceCounterFlag = sliceCounterFlag |(0x01<<updateDifferDataSliceCounter);
-											}
-											else
-											{
-												sliceCounterFlag = sliceCounterFlag |0x01;
-											}
-											/*
-										#ifdef USING_PRINTF
-											printf("sliceCounterFlag = %x  counter=%d\n",sliceCounterFlag,counter);
-										#endif
-										*/											
-										}
-										else
-										{
-											counter--;
-										}
-										
-										if(counter == 25)
-										{
-											counter = 0;											
-											if(sliceCounterFlag == 0x1FFFFFF)  //received all the 25 message of current package
-											{															
-												//write the buffer(100 byte) to flash
-												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)*100,100);
-													ret = (uint8_t)BSP_QSPI_Write_Safe(updateDataBuffer,FLASH_FOTA_REGION_START+(updateDifferDataPackageCounter)*100,100);
-												}
-												if(ret == QSPI_OK)  // write successed
-												{
-													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  //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
-													*/
-												}
-											}
-											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);
-												#ifdef USING_PRINTF
-														printf("ERROR: package lose one or mo message!! sliceCounterFlag = %x\n",sliceCounterFlag);
-												#endif
-												//sliceCounterFlag = 0x0;
-												/*
-											#ifdef USING_PRINTF
-												printf("updateDifferDataPackageCounter = %d\n",updateDifferDataPackageCounter+1);
-												printf("updateDataBuffer:\n");
-												for(k=0;k<100;k++)
-												{
-													printf("%x  ",updateDataBuffer[k]);
-												}
-												printf("\n");
-											#endif
-											*/
-												//memset(updateDataBuffer,0, 100);
-											}
-										}
-									}
-									else
-									{
-										UDSNegtiveAnswer(0x05,i,0xEF); //the download process is not ready
-										counter = 0;
-									}
-								}
-								else
-								{
-									UDSNegtiveAnswer(0x05,i,0xFF);  //the service is not surpported in current dialog mode
-								}
-								break;
-							case 0x37:  //exit some one process
-								if(UDSDialogMode == 3)
-								{
-									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
-									 {
-										UDSNegtiveAnswer(0x05,i,0xEE);
-									}
-								}
-								else
-								{
-									UDSNegtiveAnswer(0x05,i,0xFF);
-								}
-								break;
-							default:								
-								UDSNegtiveAnswer(0x04,i,0xFF);  //the service is not surpported
-								break;
-								
-						}
-					}
-				}
-			}
-	//}
-	for(i=0; i<2; i++)
-	{
-		UDSService[i] = 0;
-		UDSSubService[i] = 0;
-	}
-}
-
-UINT8 UDSPositiveAnswer(UINT8 answerLen,UINT8 messageIndex,UINT32 posCode)
-{
-	CAN_Msg_Type UDSAnswer;
-	UINT8 ret;
-	UDSAnswer.Id = 0x7A8;
-	UDSAnswer.DLC = 8;
-	UDSAnswer.Data[0] = answerLen;
-	UDSAnswer.Data[1] = 0x78;
-	UDSAnswer.Data[2] = UDSService[messageIndex];
-	UDSAnswer.Data[3] = UDSSubService[messageIndex];
-	if(answerLen == 4)
-	{
-		UDSAnswer.Data[4] = 0x00;
-		UDSAnswer.Data[5] = 0x00;
-		UDSAnswer.Data[6] = 0x00;
-		UDSAnswer.Data[7] = 0x00;
-	}
-	else if(answerLen==5)
-	{	UDSAnswer.Data[4] = posCode;
-		UDSAnswer.Data[5] = 0x00;
-		UDSAnswer.Data[6] = 0x00;
-		UDSAnswer.Data[7] = 0x00;
-	}
-	else if(answerLen==6)
-	{
-		UDSAnswer.Data[4] = posCode>>8;
-		UDSAnswer.Data[5] = posCode;
-		UDSAnswer.Data[6] = 0x00;
-		UDSAnswer.Data[7] = 0x00;
-	}
-	else if(answerLen==7)
-	{
-		UDSAnswer.Data[4] = posCode>>16;
-		UDSAnswer.Data[5] = posCode>>8;
-		UDSAnswer.Data[6] = posCode;
-		UDSAnswer.Data[7] = 0x00;
-	}
-	else if(answerLen==8)
-	{
-		UDSAnswer.Data[4] = posCode>>24;
-		UDSAnswer.Data[5] = posCode>>16;
-		UDSAnswer.Data[6] = posCode>>8;
-		UDSAnswer.Data[7] = posCode;
-	}
-	ret = HAL_Can_Transmit(UDSAnswer);
-	return ret;
-}
-
-UINT8 UDSNegtiveAnswer(UINT8 answerLen,UINT8 messageIndex, UINT32 negCode)
-{
-	CAN_Msg_Type UDSAnswer;
-	UINT8 ret;
-	UDSAnswer.Id = 0x7A8;
-	UDSAnswer.DLC = 8;
-	UDSAnswer.Data[0] = answerLen;
-	UDSAnswer.Data[1] = 0x7F;
-	UDSAnswer.Data[2] = UDSService[messageIndex];
-	UDSAnswer.Data[3] = UDSSubService[messageIndex];
-	if(answerLen==4)
-	{
-		UDSAnswer.Data[3] = negCode;
-		UDSAnswer.Data[4] = 0x00;
-		UDSAnswer.Data[5] = 0x00;
-		UDSAnswer.Data[6] = 0x00;
-		UDSAnswer.Data[7] = 0x00;
-	}
-	if(answerLen==5)
-	{	UDSAnswer.Data[4] = negCode;
-		UDSAnswer.Data[5] = 0x00;
-		UDSAnswer.Data[6] = 0x00;
-		UDSAnswer.Data[7] = 0x00;
-	}
-	else if(answerLen==6)
-	{
-		UDSAnswer.Data[4] = negCode>>8;
-		UDSAnswer.Data[5] = negCode;
-		UDSAnswer.Data[6] = 0x00;
-		UDSAnswer.Data[7] = 0x00;
-	}
-	else if(answerLen==7)
-	{
-		UDSAnswer.Data[4] = negCode>>16;
-		UDSAnswer.Data[5] = negCode>>8;
-		UDSAnswer.Data[6] = negCode;
-		UDSAnswer.Data[7] = 0x00;
-	}
-	else if(answerLen==8)
-	{
-		UDSAnswer.Data[4] = negCode>>24;
-		UDSAnswer.Data[5] = negCode>>16;
-		UDSAnswer.Data[6] = negCode>>8;
-		UDSAnswer.Data[7] = negCode;
-	}
-	ret = HAL_Can_Transmit(UDSAnswer);
-	return ret;
-}
-
-
-
-BOOL UDSAskforDownLoadData()
-{
-	updateDifferDataPackageCounter = 0;
-	downloadReady = true;
-	
-	return TRUE;
-}
-
-BOOL UDSClearFotaDownloadRegion()
-{
-	UINT8 ret = FALSE;
-	ret = BSP_QSPI_Erase_Safe(FLASH_FOTA_REGION_START, 0x46000); //512k-32k -200k = 280k -> 0x46000
-	
-	if(ret == QSPI_OK)
-	{
-		return TRUE;
-	}
-	else
-	{
-		return FALSE;
-	}
-}
-

+ 0 - 2919
src/UartTask.c

@@ -1,2919 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   Qx.
- * File name:    UartTask.c
- * Description:  串口任务
- * History:      2021-03-05
- *
- * 2021-04-11:可以通过Ota线路升级Bms保护板
- ****************************************************************************/
-#include "bsp.h"
-#include "bsp_custom.h"
-#include "osasys.h"
-#include "ostask.h"
-#include "queue.h"
-#include "ps_event_callback.h"
-#include "cmisim.h"
-#include "cmimm.h"
-#include "cmips.h"
-#include "sockets.h"
-#include "psifevent.h"
-#include "ps_lib_api.h"
-#include "lwip/netdb.h"
-//#include <cis_def.h>
-#include "debug_log.h"
-#include "slpman_ec616.h"
-#include "plat_config.h"
-#include "ec_tcpip_api.h"
-#include "hal_module_adapter.h"
-#include "UartTask.h"
-#include "MainTask.h"
-#include <stdlib.h>
-#include "app.h"
-#include "numeric.h"
-#include "Fota.h"
-#include "signal.h"
-//全局变量输入区
-extern UINT32 Timer_count;
-extern volatile BOOL Sleep_flag; 
-extern AppNVMDataType AppNVMData;
-extern AppDataBody AppDataInfo;
-extern UINT8 WorkFlag;
-//全局变量输出区
-BOOL UartBattInfoRecvFlag  = false;
-QueueHandle_t UartWriteCmdHandle = NULL;
-UINT8 BattChrgEndFlag;
-
-
-
-//
-
-extern ARM_DRIVER_USART Driver_USART1;
-static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-volatile bool isRecvTimeout = false;
-volatile bool isRecvComplete = false;
-
-//线程声明区
-static StaticTask_t             gProcess_Uart_Task_t;
-static UINT8                  gProcess_Uart_TaskStack[PROC_UART_TASK_STACK_SIZE];
-static osThreadId_t           UartTaskId = NULL;
-static process_Uart             gProcess_Uart_Task = PROCESS_UART_STATE_IDLE;
-#define PROC_UART_STATE_SWITCH(a)  (gProcess_Uart_Task = a)
-
-//函数声明区
-void USART_callback(uint32_t event);
-UINT8 Uart_DataRecv_func(Uart_Read_Msg_Type Uart_Read_Msg_Fun,UINT8* Uart_Recv_Buffer_Fun);
-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);
-UINT8  decryptionAlgorithm (UINT16 cipherText);
-UINT8 Uart_Encrypt_Send(void);
-UINT8 BmsErrorDecode(UINT32 battWarningState);
-//BMS升级函数声明
-UINT8 SP_BMS_Update_CheckSUM(UINT8* pSendData,UINT8 len);
-void SP_BMS_Update_Service();
-UINT8 SP_BMS_Update_Query(UINT8* pSend,UINT32 sendLen, UINT8* pRead, UINT32 readLen, UINT32 timeout);
-
-updateBMSStatus MS_BMS_Update_Service();
-UINT16 MS_BMS_Update_CRC16(UINT8* pSendData,UINT16 len);
-UINT8 MS_BMS_Update_Query(UINT8* pSend,UINT32 sendLen, UINT8* pRead, UINT32 readLen, UINT32 timeout);
-//Uart线程任务区
-static void UartTask(void* arg)
-{
-    USARTdrv->Initialize(USART_callback);
-    USARTdrv->PowerControl(ARM_POWER_FULL);
-    USARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS |
-                      ARM_USART_DATA_BITS_8 |
-                      ARM_USART_PARITY_NONE |
-                      ARM_USART_STOP_BITS_1 |
-                      ARM_USART_FLOW_CONTROL_NONE, 9600);
-    PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_ENCRYPT);
-    UINT16  Reg_Num = 0;
-    UINT16  Uart_Uds_LEN;
-    UINT16  Uart_Recv_LEN;
-	UINT32  currentTimerCount=0;
-	BOOL uartReadSuccessFlag = false;
-    Uart_Read_Msg_Type Uart_Read_Msg;
-	memset(&(Uart_Read_Msg),0x00,sizeof(Uart_Read_Msg_Type));
-    Uart_Write_Data_Type UartWriteData; //Uart控制命令
-	memset(&(UartWriteData),0x00,sizeof(Uart_Write_Data_Type));
-    UartReadMsgType UartReadMsg;
-    memset(&(UartReadMsg.UartFlag),0x00,sizeof(UartReadMsgType));
-    if(UartWriteCmdHandle == NULL)//Uart控制命令传输指针
-	{
-		UartWriteCmdHandle = osMessageQueueNew(3,sizeof(Uart_Write_Data_Type), NULL);
-	}
-    //上电起始控制区域
-    while (1)
-    {
-        switch (gProcess_Uart_Task)
-        {
-			case PROCESS_UART_STATE_ENCRYPT:
-			{
-				UINT8 EncryptFlag=0x00;
-				UINT8 EncryptCount=0;
-				while(EncryptFlag!=0x01&&EncryptCount<=3)
-				{
-					EncryptFlag = Uart_Encrypt_Send();
-					EncryptCount++;
-				}
-				PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
-				break;
-			}
-            case PROCESS_UART_STATE_IDLE:
-            {
-                osDelay(100);
-                if(Sleep_flag)
-                {
-                    PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_SLEEP);
-                }
-                else if(Timer_count%10==0)
-                {
-                    #ifdef USING_PRINTF1
-                        printf("[%d]Uart Timer 1s:%d,uartReadSuccessFlag:%d\n",__LINE__,Timer_count,uartReadSuccessFlag);
-                    #endif
-                    if(osMessageQueueGet(UartWriteCmdHandle,&UartWriteData,0,0)==osOK)
-                    {
-                        #ifdef USING_PRINTF1
-                            printf("[%d]UartWriteCmdHandle :%x\n",__LINE__,UartWriteData.WriteCmd);
-                        #endif
-                        PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_WRITE);
-                    }
-                    else
-                        PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_READ);
-                }
-				if(UartReadMsg.Header[2]>0)
-				{
-					uartReadSuccessFlag = true;
-				}
-				else
-				{
-					uartReadSuccessFlag = false;
-				}
-				if(Timer_count-currentTimerCount >= 1)
-				{
-					if(AppNVMData.isBattLocked != 0)
-					{
-						battLockStateDisplay(TRUE);
-					}
-					else if(uartReadSuccessFlag)
-					{
-						battSOCDisplay();
-						battErrorStateDisplay();
-					}
-					else
-					{
-						battWarningStateDisplay();
-					}
-				}
-				currentTimerCount = Timer_count;
-				if(BMS_Fota_update_flag)
-				{
-					if(WorkFlag==0x00)
-					{
-						PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_UPDATE);
-					}
-					
-				}
-				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
-				{
-					UartWriteData.WriteCmd = 0x01;
-					UartWriteData.Data[0] = 0x00;
-					UartWriteData.Data[1] = 0x00;
-					osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,1000);
-					PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_READ);
-				}
-				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
-				{
-					UartWriteData.WriteCmd = 0x01;
-					UartWriteData.Data[0] = 0x00;
-					UartWriteData.Data[1] = 0x03;
-					osMessageQueuePut(UartWriteCmdHandle,&UartWriteData,0,1000);
-					PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_READ);
-				}
-                break;
-            }
-            case PROCESS_UART_STATE_READ:
-            {
-                UINT16 CRC_chk_buffer;
-                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;
-                Uart_Read_Msg.Reg_Begin_H = 0x00;
-                Uart_Read_Msg.Reg_Begin_L= 0x00;
-                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);
-				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((UINT8 *)&Uart_Read_Msg,(UINT8*)UartReadMsg.Header);
-				Uart_Recv_LEN = Uart_DataRecv_func(Uart_Read_Msg,(UINT8*)(UartReadMsg.Header));
-				if(Uart_Recv_LEN>0)
-				{
-					UartBattInfoRecvFlag =  TRUE;
-					uartBattInfoDecode(UartReadMsg.data);
-				}
-				else
-				{
-					UartBattInfoRecvFlag =  FALSE;
-				}
-                UartReadMsg.len = Uart_Recv_LEN;
-                PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
-                if( battWorkState ==0x02)
-                {
-                    BattChrgEndFlag=TRUE;
-                }
-                else
-                {
-                    BattChrgEndFlag=FALSE;
-                }
-				#ifdef USING_PRINTF1
-					printf("\nUart_Recv_buffer:  ");
-					for(int i=0;i<Uart_Recv_LEN;i++)
-					{
-						printf("%x ",*((UINT8 *)&UartReadMsg.Header+i));
-					}
-					printf("\n");
-				#endif
-                break;
-            }
-            case PROCESS_UART_STATE_WRITE:
-            {
-                Uart_WriteCmd_func(UartWriteData);
-                PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
-                break;
-            }
-			case PROCESS_UART_STATE_UPDATE:
-				UartBattInfoRecvFlag =  FALSE;
-				#if  BMS_MANUFACTURE==1
-				{
-					SP_BMS_Update_Service();
-				}		
-				#elif BMS_MANUFACTURE==2
-					MS_BMS_Update_Service();
-				#endif
-
-				PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
-				BMS_Fota_update_flag = FALSE;
-				break;
-            case PROCESS_UART_STATE_SLEEP:
-            {
-                USARTdrv->PowerControl(ARM_POWER_LOW);
-                while(TRUE)
-                {
-                    osDelay(60000/portTICK_PERIOD_MS);
-                }
-				osThreadExit();
-                break;
-            }
-
-        }
-    }
-}
-
-
-
-
-//Uart 接收的数据解码
-static BOOL uartBattInfoDecode(UINT8* dataPtr)
-{
-	//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]);
-    //原始数据:充电为负,放电为正
-	if(battWorkState == 0x02) //充电过程
-	{
-		if(Batt_current >0x8000)// 数据为负
-		{			
-			//求补码,结果为负
-			Batt_current = (UINT16)((UINT16)(~(Batt_current))+1);
-        	Batt_current = Batt_current/10;
-			AppDataInfo.BattCurrentNegFlag = -1;
-		}
-		else
-		{
-			//源码,结果为负
-			Batt_current = Batt_current/10;
-			AppDataInfo.BattCurrentNegFlag = -1;
-		}
-	}
-	else //放电过程
-	{
-		if(Batt_current >0x8000)// 数据为负
-		{
-			//求补码,结果为正
-			Batt_current = (UINT16)((UINT16)(~(Batt_current))+1);
-        	Batt_current = Batt_current/10;
-			AppDataInfo.BattCurrentNegFlag = 1;
-		}
-		else
-		{
-			//源码,结果为正
-			Batt_current = Batt_current/10;
-			AppDataInfo.BattCurrentNegFlag = 1;
-		}
-	}
-
-	battI = Batt_current*AppDataInfo.BattCurrentNegFlag + 0x2710;
-    //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];
-	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]);
-	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;
-	BmsErrorDecode(battWarningState);
-    return true;
-}
-
-
-
-
-
-
-//Uart线程初始化
-void UartTaskInit(void *arg)
-{
-    osThreadAttr_t task_attr;
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcess_Uart_TaskStack, 0xA5, PROC_UART_TASK_STACK_SIZE);
-    task_attr.name = "Uart_Task";
-    task_attr.stack_mem = gProcess_Uart_TaskStack;
-    task_attr.stack_size = PROC_UART_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityBelowNormal7;
-    task_attr.cb_mem = &gProcess_Uart_Task_t;
-    task_attr.cb_size = sizeof(StaticTask_t);
-    UartTaskId = osThreadNew(UartTask, NULL, &task_attr);
-}
-void UartTaskDeInit(void *arg)
-{
-    osThreadTerminate(UartTaskId);
-    UartTaskId = NULL;
-}
-//函数区
-//Uart回调程序
-void USART_callback(uint32_t event)
-{
-    if(event & ARM_USART_EVENT_RX_TIMEOUT)
-    {
-        isRecvTimeout = true;
-    }
-    if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
-    {
-        isRecvComplete = true;
-    }
-}
-//Uart校验程序
-UINT16 crc_chk(UINT8* data, UINT8 length)
-{  
-    UINT8 j;
-    UINT16 reg_crc=0xFFFF;
-    while(length--)
-    { 
-        reg_crc ^= *data++;
-        for(j=0;j<8;j++)
-        { 
-            if(reg_crc & 0x01)
-            {
-                reg_crc=(reg_crc>>1) ^ 0xA001;
-            }
-            else
-            {
-                reg_crc=reg_crc >>1;
-            }
-        }
-    }
-    return reg_crc;
-}
-//Uart写命令函数
-UINT8 Uart_WriteCmd_func(Uart_Write_Data_Type UartWriteData)
-{
-    Uart_Write_Msg_Type Uart_Write_Msg;
-    UINT16 RegAddress = 0x0000;
-    UINT16 CRC_chk_buffer;
-    UINT8 timeout = 0x00;
-    UINT8 Uart_Recv_Buffer[8];
-    switch (UartWriteData.WriteCmd)
-    {
-        case 0x01://是否锁定
-        {   
-            RegAddress = 0x1B + BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM;
-            Uart_Write_Msg.Bms_Address = BMS_ADDRESS_CODE;
-            Uart_Write_Msg.Bms_Funcode = UART_WRITE_CODE;
-            Uart_Write_Msg.Reg_Begin_H = RegAddress>>8;
-            Uart_Write_Msg.Reg_Begin_L = RegAddress;
-            Uart_Write_Msg.Reg_Num_H = 0x00;
-            Uart_Write_Msg.Reg_Num_L = 0x01;
-            Uart_Write_Msg.Data_Count = 0x02;//要写入的字节数
-            memcpy(Uart_Write_Msg.Data,UartWriteData.Data,2);
-            CRC_chk_buffer = crc_chk((UINT8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg)-2);
-            Uart_Write_Msg.CRC_L = CRC_chk_buffer;
-            Uart_Write_Msg.CRC_H = CRC_chk_buffer>>8;
-            break;
-        }
-		case 0x02://是否加热
-		{
-			RegAddress = 0x1C + BATT_CELL_VOL_NUM+BATT_TEMP_NUM+BATT_OTHER_TEMP_NUM;
-            Uart_Write_Msg.Bms_Address = BMS_ADDRESS_CODE;
-            Uart_Write_Msg.Bms_Funcode = UART_WRITE_CODE;
-            Uart_Write_Msg.Reg_Begin_H = RegAddress>>8;
-            Uart_Write_Msg.Reg_Begin_L = RegAddress;
-            Uart_Write_Msg.Reg_Num_H = 0x00;
-            Uart_Write_Msg.Reg_Num_L = 0x01;
-            Uart_Write_Msg.Data_Count = 0x02;//要写入的字节数
-            memcpy(Uart_Write_Msg.Data,UartWriteData.Data,2);
-            CRC_chk_buffer = crc_chk((UINT8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg)-2);
-            Uart_Write_Msg.CRC_L = CRC_chk_buffer;
-            Uart_Write_Msg.CRC_H = CRC_chk_buffer>>8;
-            break;
-		}
-        default:
-        {
-            UartWriteData.WriteCmd = 0x00;
-            return 0;
-            break;
-        }
-    }
-    USARTdrv->Send((UINT8 *)&Uart_Write_Msg,sizeof(Uart_Write_Msg));
-    #ifdef USING_PRINTF1
-        printf("Uart_Send_buffer:  ");
-        for(int i=0;i<sizeof(Uart_Write_Msg);i++)
-        {
-            printf("%x ",*((UINT8 *)&Uart_Write_Msg+i));
-        }
-        printf("\n");
-    #endif
-    USARTdrv->Receive(Uart_Recv_Buffer,8);
-    while((isRecvTimeout == false) && (isRecvComplete == false))
-    {
-        timeout++;
-        osDelay(100);
-        if (timeout>=10)
-        {
-            timeout =0;
-            isRecvTimeout = true;
-            break;
-        }
-    }
-    if (isRecvComplete == true)
-    {
-        #ifdef USING_PRINTF1
-            printf("Uart_Rece_buffer: ");
-            for(int i=0;i<8;i++)
-            {
-            printf("%x ",Uart_Recv_Buffer[i]);
-            }
-            printf("\n");
-        #endif
-        isRecvComplete = false;
-        if(Uart_Recv_Buffer[1]==0x10)
-        {
-            return UartWriteData.WriteCmd;
-        }
-        else
-        {
-            return 0x00;
-        }
-    }
-    else
-    {
-        isRecvTimeout = false;
-        return 0x00;
-    }
-}
-//Uart发送接收函数
-UINT8 Uart_DataRecv_func(Uart_Read_Msg_Type Uart_Read_Msg_Fun,UINT8* Uart_Recv_Buffer_Fun)
-{
-    UINT16 CRC_Rece_buffer;
-    UINT16 CRC_chk_buffer;
-    UINT16 Data_Len ;
-    UINT8 timeout = 0x00;
-	UINT8 pSendCmd[8];
-	memcpy(pSendCmd,(UINT8*)(&Uart_Read_Msg_Fun),8);
-    //Data_Len = (*(Uart_Read_Msg_Fun+4)|*(Uart_Read_Msg_Fun+5))*2+5;
-	Data_Len  = ((Uart_Read_Msg_Fun.Reg_Num_H<<8)|(Uart_Read_Msg_Fun.Reg_Num_L))*2+5;
-
-    //USARTdrv->Send(Uart_Read_Msg_Fun,8);
-	USARTdrv->Send(pSendCmd,8);
-    #ifdef USING_PRINTF1
-		
-        printf("Uart_Send_buffer:  ");
-        for(int i=0;i<8;i++)
-        // {
-             printf("%x ",pSendCmd[i]);
-        // }
-        printf("end\n");
-		//printf("%x ",*(Uart_Read_Msg_Fun));
-	//UINT8 temp = *(Uart_Read_Msg_Fun);
-    #endif
-    USARTdrv->Receive(Uart_Recv_Buffer_Fun,Data_Len);
-	while(true)
-    {
-        timeout++;
-        if((isRecvTimeout == true) || (isRecvComplete == true))
-        {
-            break;
-        }
-        else
-        {
-            osDelay(100);
-            if (timeout>=10)
-            {
-				// Data_Len = 0;
-                timeout =0;
-                isRecvTimeout = true;
-            }
-        } 
-    }
-     #ifdef USING_PRINTF1
-         printf("Uart_Rece_buffer1: ");
-         for(int j=0;j<Data_Len;j++)
-         {
-         printf("%x ",*(Uart_Recv_Buffer_Fun+j));
-         }
-     #endif
-    if (isRecvComplete == true)
-    {
-        isRecvComplete = false;
-        CRC_Rece_buffer =*(Uart_Recv_Buffer_Fun+Data_Len-1)<<8|*(Uart_Recv_Buffer_Fun+Data_Len-2);
-        CRC_chk_buffer = crc_chk(Uart_Recv_Buffer_Fun,Data_Len-2);
-	    #ifdef USING_PRINTF1
-	         printf("Uart_Rece_buffer after Crc: ");
-	         for(int i=0;i<Data_Len;i++)
-	         {
-	         	printf("%x ",*(Uart_Recv_Buffer_Fun+i));
-	   	     }
-	         printf("\tcrcchk:%x,%x\n ",CRC_chk_buffer,CRC_Rece_buffer);
-	    #endif
-        if (CRC_Rece_buffer == CRC_chk_buffer)//满足校验
-        {
-            return Data_Len;//此处指针移位出现重启问题
-        }
-        else //接收数据的校验不过
-        {
-            USARTdrv->Uninitialize();
-            osDelay(1000);
-            USARTdrv->Initialize(USART_callback);
-            USARTdrv->PowerControl(ARM_POWER_FULL);
-            USARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS |
-                      ARM_USART_DATA_BITS_8 |
-                      ARM_USART_PARITY_NONE |
-                      ARM_USART_STOP_BITS_1 |
-                      ARM_USART_FLOW_CONTROL_NONE, 9600);
-            memset(Uart_Recv_Buffer_Fun,0xff,Data_Len);
-            return 0;
-        }
-    }
-    else
-    {
-        memset(Uart_Recv_Buffer_Fun,0x00,Data_Len);
-        isRecvTimeout = false;
-        return 0;
-    }
-	return 0;
-}
-
-
-/**
-  \fn   BOOL BattHeaterSwitch(UINT8* heaterSwitch)
-  \param[in]  (UINT8*) heaterSwitch: the heater switch state
-  \brief    according to the current switch state and all the cell temp, it will turn on/off the switch
-  \return   (BOOL) isNeedtoSwitch: true: need to send cmd to turn on/off the switch
-  								 false: do not need to do anything
-*/
-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) 	//当前状态为关闭,判断是否应该开启
-	{
-		if(minCellTemp<=5+40 && maxCellTemp<25+40 && battSOC>=12)//温度偏移为40 
-		{
-			*heaterSwitch = 1;
-			isNeedtoSwitch = true;
-		}
-	}
-	else  						//当前状态为开启,判断是否应该关闭
-	{
-		if(minCellTemp>10+40 || maxCellTemp>30+40 || battSOC<10)
-		{
-			*heaterSwitch = 0;
-			isNeedtoSwitch= true;
-		}
-	}
-	return isNeedtoSwitch;
-}
-
-void battSOCDisplay()
-{
-	
-	static UINT8 lightTimer = 0;
-	UINT8 socLowLEDFlashPeriod = 10;//10*100 = 1000ms
-	UINT8 chargeLEDFlashPeriod = 6;//6*100 = 600ms
-	float dutyRatio = 0.4;
-	UINT8 temp;
-
-	if(AppNVMData.isBattLocked == TRUE)
-	{
-		return;
-	}
-	if(UartBattInfoRecvFlag == true)
-	{ 
-		lightTimer++;
-		
-		if(battWorkState == 0||battWorkState == 1)  //静置或放电状态
-		{
-			if(battSOC<=10)
-			{
-				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);	
-				lightTimer = 0;
-			}
-			else if(battSOC>25&&battSOC<=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(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(battSOC>75&&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_ON);
-				lightTimer = 0;
-			}
-		}
-		else if(battWorkState == 2)
-		{
-			if(battSOC<=25)
-			{
-				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(battSOC>50&&battSOC<=75)
-			{
-				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 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_ON);	
-			}		
-		}
-	}
-	
-}
-
-void battErrorStateDisplay()
-{	
-	static UINT8  errorLightTimer = 0;
-	//static UINT32 currentTimerCount=0;
-	
-	UINT8  errorLEDFlashPeriod = 6;//600ms
-	float errorDutyRatio = 0.4;
-
-	if(AppNVMData.isBattLocked == TRUE)
-	{
-		return;
-	}
-	
-	if(UartBattInfoRecvFlag == true)
-	{	
-	
-		errorLightTimer++;
-
-		if(battWarningState != 0)
-		{
-			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;
-		}	
-	}
-}
-
-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)
-{
-	static UINT8 currentState = 0;
-	static UINT8  errorLightTimer = 0;
-	//static UINT32 currentTimerCount=0;
-	
-	UINT8  errorLEDFlashPeriod = 10;//1000ms
-	float errorDutyRatio = 0.4;
-	
-	//printf("lockState = %d\ncurrent State = %d\n",lockState,currentState);
-	if(lockState==0)//no error
-	{
-		if(currentState!=lockState)
-		{
-			NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
-			NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
-			NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
-			NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
-			FaultDisplay(LED_TURN_OFF);
-			currentState = lockState;
-			errorLightTimer = 0;
-		}
-		else
-		{
-			return;
-		}
-
-	}
-	else  // error occurred, errorState = 1
-	{
-		if(errorLightTimer<(UINT8)(errorLEDFlashPeriod*errorDutyRatio)) 
-		{	
-			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);
-			FaultDisplay(LED_TURN_ON);
-			
-		}
-		else if(errorLightTimer>=(UINT8)(errorLEDFlashPeriod*errorDutyRatio) && errorLightTimer<errorLEDFlashPeriod)
-		{
-			NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
-			NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
-			NetSocDisplay(LED_SOC_2,LED_TURN_OFF);
-			NetSocDisplay(LED_SOC_3,LED_TURN_OFF);
-			FaultDisplay(LED_TURN_OFF);			
-		}
-		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);
-			FaultDisplay(LED_TURN_OFF);
-			errorLightTimer = 0;			
-		}		
-	}	
-	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;	
-	UINT16 publicKeyD = 43;
-	UINT16 publicKeyN = 10961;
-	cipherText = cipherText % publicKeyN;
-	while(publicKeyD >0)
-	{
-		if(publicKeyD % 2 ==1)
-		{			
-			plainText = plainText * cipherText % publicKeyN;
-		}
-		publicKeyD = publicKeyD/2;		
-		cipherText = (cipherText * cipherText) % publicKeyN;
-	}
-	return (UINT8)plainText;
-}
-
-UINT16  encryptionAlgorithm (UINT16 plainText)
-{
-	UINT16 cipherText = 1; 
-	UINT16 privateKeyE = 37507;
-	UINT16 privateKeyN = 10961;
-	plainText = plainText % privateKeyN;
-	while(privateKeyE >0)
-	{
-	if(privateKeyE % 2 ==1)
-	{   
-	cipherText =  ( cipherText * plainText) % privateKeyN;
-	}
-	privateKeyE = privateKeyE/2;  
-	plainText = (plainText * plainText) % privateKeyN;
-	}
-	return cipherText;
-}
-UINT8 Uart_Encrypt_Send()
-{
-	UINT8 SeedNumberArrray[4]={0x38,0x56,0xfe,0xac};
-	UINT16 EncodeNumberArray[4];
-	UINT8 UartEncryptBuffer[17];
-	UINT8 UartDecryptBuffer[5];
-	UINT16 CRC_chk_buffer;
-	UINT8 timeCount = 0;
-	UartEncryptBuffer[0] = BMS_ADDRESS_CODE;
-	UartEncryptBuffer[1] = UART_ENCRYPT_CODE;
-	UartEncryptBuffer[2] = 0x0c;
-	for(int i=0;i<4;i++)
-	{
-		SeedNumberArrray[i]=rand();
-		EncodeNumberArray[i] = encryptionAlgorithm(SeedNumberArrray[i]);
-		UartEncryptBuffer[i+3] = SeedNumberArrray[i];
-		UartEncryptBuffer[i*2+7] = EncodeNumberArray[i]>>8;
-		UartEncryptBuffer[i*2+8] = EncodeNumberArray[i];
-	}
-	CRC_chk_buffer = crc_chk(UartEncryptBuffer,17-2);
-	UartEncryptBuffer[15] = CRC_chk_buffer;
-	UartEncryptBuffer[16] = CRC_chk_buffer>>8;
-	USARTdrv->Send(UartEncryptBuffer,17);
-	USARTdrv->Receive(UartDecryptBuffer,5); 
-	while((isRecvTimeout == false) && (isRecvComplete == false))
-	{
-		timeCount++;
-		osDelay(100);
-		if (timeCount>=10)
-		{
-			timeCount =0;
-			isRecvTimeout = true;
-			break;
-		}
-	}
-	#ifdef USING_PRINTF
-		printf("Uart_Rece_buffer: ");
-		for(int i=0;i<5;i++)
-		{
-		printf("%x ",UartDecryptBuffer[i]);
-		}
-    #endif	
-	if (isRecvComplete == true)
-	{
-		isRecvComplete = false;
-		return UartDecryptBuffer[2];
-	}
-	else
-	{
-		isRecvTimeout = false;
-		return 0x03;
-	}
-}
-
-
-
-
-/*-----------------------------------------------------------------------------*/
-void SP_BMS_Update_Service() //超力源BMS升级服务
-{
-	
-	UINT8 errorCount = 0;
-	UINT8 resetCount = 0;	
-	UINT16 currentPackage = 0;	
-	UINT32 updateDataTotalByteLen = 0;
-	UpdateStep updateStep = UPDATE_STEP_CHECK_VERSION;	
-	
-	UINT8 i,j,ret=0;
-	UINT8 dataLen = 0;
-		
-	UINT8 pUpdateMsgSend[80];
-	UINT32 updateMsgSendLen = 0;	
-	UINT32 currentPackageStartAddr = 0;
-	BMS_Update_Recv_Msg_Type pUpdateMsgRecv;
-	UINT8 bmsUpdateFlag = 1;
-	//BMS_Update_Recv_Msg_Type bmsMsg;
-	//static UpdateStep step = UPDATE_STEP_CHECK_VERSION;
-	UINT8 Cycle_conut = 0;
-	while(bmsUpdateFlag && Cycle_conut<2)
-	{
-		switch (updateStep)
-		{
-			case UPDATE_STEP_CHECK_VERSION:
-
-				dataLen = 0;
-				updateMsgSendLen = 7;
-				pUpdateMsgSend[0] = 0xEB; //start flag
-				pUpdateMsgSend[1] = 0x01;	//add flag
-				pUpdateMsgSend[2] = 0x01; //read
-				pUpdateMsgSend[3] = 0x03;	//data len
-				pUpdateMsgSend[4] = 0x90;	//cmd
-				pUpdateMsgSend[5] = 0x93;	//checksum
-				pUpdateMsgSend[6] = 0xF5;	//end flag		
-				//printf("updateMsgSendLen0 = %x\n",updateMsgSendLen);
-				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv),sizeof(BMS_Update_Recv_Msg_Type), 500);
-				//printf("updateMsgSendLen1 = %x\n",updateMsgSendLen);
-				if(ret!=0)
-				{
-					if(pUpdateMsgRecv.startFlag == 0xEB && pUpdateMsgRecv.endFlag == 0xF5)
-					{
-						if(pUpdateMsgRecv.cmd == 0x90)
-						{
-							if(pUpdateMsgRecv.data != 0xFF)
-							{
-								updateStep = UPDATE_STEP_REQUEST_UPDATE;
-								errorCount = 0;
-							}
-							else
-							{
-								updateStep = UPDATE_STEP_SET_BAUD_RATE;
-								errorCount = 0;
-							}
-						}
-						else
-						{
-							errorCount++;
-						}
-					}
-					else
-					{
-						errorCount++;
-					}
-				}			
-				else
-				{
-					errorCount++;
-				}
-				#ifdef USING_PRINTF1
-							//printf("update step:%d\n",updateStep);
-							printf("query:");
-							
-							for(j=0;j<updateMsgSendLen;j++)
-							{
-								printf("%x ",pUpdateMsgSend[j]);
-							}
-							
-							printf("\nanswer:");
-							for(j=0;j<sizeof(BMS_Update_Recv_Msg_Type);j++)
-							{
-								printf("%x ",*(((UINT8*)&pUpdateMsgRecv)+j));
-							}
-							printf("\n");
-							printf("next update step:%d\n",updateStep);
-				#endif
-				if(errorCount>10)
-				{
-					updateStep = UPDATE_STEP_RESET;
-					errorCount = 0;
-				}
-				osDelay(50);
-				break;
-			
-			case UPDATE_STEP_REQUEST_UPDATE:
-				dataLen = 1;
-				updateMsgSendLen = 8;
-				pUpdateMsgSend[0] = 0xEB; //start flag
-				pUpdateMsgSend[1] = 0x01;	//add flag
-				pUpdateMsgSend[2] = 0x00; //write
-				pUpdateMsgSend[3] = 0x04;	//data len
-				pUpdateMsgSend[4] = 0x80;	//cmd
-				pUpdateMsgSend[5] = 0x22;	//data
-				pUpdateMsgSend[6] = 0xA6;	//check
-				pUpdateMsgSend[7] = 0xF5;	//end flag
-				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
-				if(ret!=0)
-				{
-					if(pUpdateMsgRecv.startFlag == 0xEB && pUpdateMsgRecv.endFlag == 0xF5)
-					{
-						if(pUpdateMsgRecv.cmd == 0x80)
-						{
-							if(pUpdateMsgRecv.data == 0x33)
-							{
-								updateStep = UPDATE_STEP_START_UPDATE;
-								errorCount = 0;
-							}
-							else
-							{
-								errorCount++;
-							}						
-						}
-						else
-						{
-							errorCount++;
-						}
-					}
-					else
-					{
-						errorCount++;
-					}
-				}			
-				else
-				{
-					errorCount++;
-				}
-
-				if(errorCount>10)
-				{
-					updateStep = UPDATE_STEP_RESET;
-					errorCount = 0;
-				}
-				
-				#ifdef USING_PRINTF1
-							printf("update step:%d\n",updateStep);
-							printf("query:");
-							for(j=0;j<updateMsgSendLen;j++)
-							{
-								printf("%x ",pUpdateMsgSend[j]);
-							}
-							printf("\nanswer:");
-							for(j=0;j<sizeof(BMS_Update_Recv_Msg_Type);j++)
-							{
-								printf("%x ",*(((UINT8*)&pUpdateMsgRecv)+j));
-							}
-							printf("\n");
-							printf("next update step:%d\n",updateStep);
-				#endif
-				osDelay(50);
-				break;
-
-			case UPDATE_STEP_START_UPDATE:
-				dataLen = 1;
-				updateMsgSendLen = 8;
-				pUpdateMsgSend[0] = 0xEB; //start flag
-				pUpdateMsgSend[1] = 0x01;	//add flag
-				pUpdateMsgSend[2] = 0x00; //write
-				pUpdateMsgSend[3] = 0x04;	//data len
-				pUpdateMsgSend[4] = 0x80;	//cmd
-				pUpdateMsgSend[5] = 0x55;	//data
-				pUpdateMsgSend[6] = 0xD9;	//check
-				pUpdateMsgSend[7] = 0xF5;	//end flag
-				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), 0, 500);
-				//updateStep = UPDATE_STEP_SET_BAUD_RATE;
-				updateStep = UPDATE_STEP_CHECK_VERSION_AGAIN;//2021-04-09跳过波特率设置
-				#ifdef USING_PRINTF1
-							
-							printf("query:");
-							for(j=0;j<updateMsgSendLen;j++)
-							{
-								printf("%x ",pUpdateMsgSend[j]);
-							}
-							printf("\nanswer:");
-							for(j=0;j<sizeof(BMS_Update_Recv_Msg_Type);j++)
-							{
-								printf("%x ",*(((UINT8*)&pUpdateMsgRecv)+j));
-							}
-							
-							printf("\n");		
-							printf("next update step:%d\n",updateStep);
-				#endif
-				break;
-			case UPDATE_STEP_CHECK_VERSION_AGAIN:
-				dataLen = 0;
-				updateMsgSendLen = 7;
-				pUpdateMsgSend[0] = 0xEB; //start flag
-				pUpdateMsgSend[1] = 0x01;	//add flag
-				pUpdateMsgSend[2] = 0x01; //read
-				pUpdateMsgSend[3] = 0x03;	//data len
-				pUpdateMsgSend[4] = 0x90;	//cmd
-				pUpdateMsgSend[5] = 0x93;	//checksum
-				pUpdateMsgSend[6] = 0xF5;	//end flag		
-				//printf("updateMsgSendLen0 = %x\n",updateMsgSendLen);
-				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv),sizeof(BMS_Update_Recv_Msg_Type), 100);
-				//printf("updateMsgSendLen1 = %x\n",updateMsgSendLen);
-				if(ret!=0)
-				{
-					if(pUpdateMsgRecv.startFlag == 0xEB && pUpdateMsgRecv.endFlag == 0xF5)
-					{
-						if(pUpdateMsgRecv.cmd == 0x90)
-						{
-							if(pUpdateMsgRecv.data != 0xFF)
-							{
-								updateStep = UPDATE_STEP_RESET;
-								errorCount = 0;
-							}
-							else
-							{
-								updateStep = UPDATE_STEP_SET_BAUD_RATE;
-								errorCount = 0;
-							}
-						}
-						else
-						{
-							errorCount++;
-						}
-					}
-					else
-					{
-						errorCount++;
-					}
-				}			
-				else
-				{
-					errorCount++;
-				}
-				#ifdef USING_PRINTF1
-							//printf("update step:%d\n",updateStep);
-							printf("query:");
-							
-							for(j=0;j<updateMsgSendLen;j++)
-							{
-								printf("%x ",pUpdateMsgSend[j]);
-							}
-							
-							printf("\nanswer:");
-							for(j=0;j<sizeof(BMS_Update_Recv_Msg_Type);j++)
-							{
-								printf("%x ",*(((UINT8*)&pUpdateMsgRecv)+j));
-							}
-							printf("\n");
-							printf("next update step:%d\n",updateStep);
-				#endif
-				if(errorCount>10)
-				{
-					updateStep = UPDATE_STEP_RESET;
-					errorCount = 0;
-				}
-				osDelay(50);
-				break;
-			case UPDATE_STEP_SET_BAUD_RATE:
-				printf("start step %d\n",updateStep);
-				dataLen = 4;
-				updateMsgSendLen = 12;
-				pUpdateMsgSend[0] = 0xEB; //start flag
-				pUpdateMsgSend[1] = 0x01;	//add flag
-				pUpdateMsgSend[2] = 0x00; //write
-				pUpdateMsgSend[3] = 0x08;	//data len
-				pUpdateMsgSend[4] = 0x81;	//cmd
-				pUpdateMsgSend[5] = 0x33;	//data
-				pUpdateMsgSend[6] = 0x00;	//baud rate:9600
-				pUpdateMsgSend[7] = 0x00;
-				pUpdateMsgSend[8] = 0x25;
-				pUpdateMsgSend[9] = 0x80;
-				pUpdateMsgSend[10] = 0x61;	//check
-				pUpdateMsgSend[11] = 0xF5;	//end flag
-				#ifdef USING_PRINTF1
-				printf("query:");
-				for(j=0;j<updateMsgSendLen;j++)
-				{
-					printf("%x ",pUpdateMsgSend[j]);
-				}
-				printf("\n");
-				#endif
-				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
-				printf("ret = %d\n",ret);
-				if(ret!=0)
-				{
-					if(pUpdateMsgRecv.startFlag == 0xEB && pUpdateMsgRecv.endFlag == 0xF5)
-					{
-						if(pUpdateMsgRecv.cmd == 0x81)
-						{
-							if(pUpdateMsgRecv.data == 0x11)
-							{
-								updateStep = UPDATE_STEP_PREPARE_SEND_DATA_LEN;
-								errorCount = 0;
-							}
-							else
-							{
-								errorCount++;
-							}						
-						}
-						else
-						{
-							errorCount++;
-						}
-					}
-					else
-					{
-						errorCount++;
-					}
-				}			
-				else
-				{
-					errorCount++;
-				}
-
-				if(errorCount>10)
-				{
-					updateStep = UPDATE_STEP_RESET;
-					errorCount = 0;
-				}
-				
-				#ifdef USING_PRINTF1
-					//printf("update step:%d\n",updateStep);
-					printf("query:");
-					for(j=0;j<updateMsgSendLen;j++)
-					{
-						printf("%x ",pUpdateMsgSend[j]);
-					}
-					printf("\nanswer:");
-					for(j=0;j<sizeof(BMS_Update_Recv_Msg_Type);j++)
-					{
-						printf("%x ",*(((UINT8*)&pUpdateMsgRecv)+j));
-					}
-					printf("\n");
-					printf("next update step:%d\n",updateStep);
-				#endif
-				osDelay(50);
-				break;
-			
-			
-			case UPDATE_STEP_PREPARE_SEND_DATA_LEN:
-				printf("start step %d\n",updateStep);
-				dataLen = 1;
-				updateMsgSendLen = 8;
-				pUpdateMsgSend[0] = 0xEB; //start flag
-				pUpdateMsgSend[1] = 0x01;	//add flag
-				pUpdateMsgSend[2] = 0x00; //write
-				pUpdateMsgSend[3] = 0x04;	//data len
-				pUpdateMsgSend[4] = 0x81;	//cmd
-				pUpdateMsgSend[5] = 0x44;	//data
-				pUpdateMsgSend[6] = 0xC9;	//check
-				pUpdateMsgSend[7] = 0xF5;	//end flag
-				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
-				if(ret!=0)
-				{
-					if(pUpdateMsgRecv.startFlag == 0xEB && pUpdateMsgRecv.endFlag == 0xF5)
-					{
-						if(pUpdateMsgRecv.cmd == 0x81)
-						{
-							if(pUpdateMsgRecv.data == 0x11)
-							{
-								updateStep = UPDATE_STEP_SEND_DATA_LEN;
-								errorCount = 0;
-							}
-							else
-							{
-								errorCount++;
-							}						
-						}
-						else
-						{
-							errorCount++;
-						}
-					}
-					else
-					{
-						errorCount++;
-					}
-				}			
-				else
-				{
-					errorCount++;
-				}
-
-				if(errorCount>10)
-				{
-					updateStep = UPDATE_STEP_RESET;
-					errorCount = 0;
-				}
-				
-				#ifdef USING_PRINTF1
-					//printf("update step:%d\n",updateStep);
-					printf("query:");
-					for(j=0;j<updateMsgSendLen;j++)
-					{
-						printf("%x ",pUpdateMsgSend[j]);
-					}
-					printf("\nanswer:");
-					for(j=0;j<sizeof(BMS_Update_Recv_Msg_Type);j++)
-					{
-						printf("%x ",*(((UINT8*)&pUpdateMsgRecv)+j));
-					}
-					printf("\n");	
-					printf("next update step:%d\n",updateStep);
-				#endif
-				osDelay(50);
-				break;		
-			case UPDATE_STEP_SEND_DATA_LEN:
-				
-				dataLen = 4;
-				BSP_QSPI_Read_Safe(&updateDataTotalByteLen,FLASH_BMS_FOTA_START_ADDR,4);
-				updateDataTotalByteLen = (((updateDataTotalByteLen)&0xFF)<<24)|(((updateDataTotalByteLen>>8)&0xFF)<<16)|(((updateDataTotalByteLen>>16)&0xFF)<<8)|(((updateDataTotalByteLen>>24)&0xFF));
-				updateMsgSendLen = 11;
-				pUpdateMsgSend[0] = 0xEB; //start flag
-				pUpdateMsgSend[1] = 0x01;	//add flag
-				pUpdateMsgSend[2] = 0x00; //write
-				pUpdateMsgSend[3] = 0x07;	//data len
-				pUpdateMsgSend[4] = 0x82;	//cmd
-				pUpdateMsgSend[5] = (updateDataTotalByteLen>>24)&0xFF;	//data: package byte len
-				pUpdateMsgSend[6] = (updateDataTotalByteLen>>16)&0xFF;	
-				pUpdateMsgSend[7] = (updateDataTotalByteLen>>8)&0xFF;	
-				pUpdateMsgSend[8] = (updateDataTotalByteLen)&0xFF;
-				pUpdateMsgSend[9] = SP_BMS_Update_CheckSUM(&pUpdateMsgSend[3], dataLen+2);	//check sum
-				pUpdateMsgSend[10] = 0xF5;	//end flag
-				
-				memset((UINT8*)(&pUpdateMsgRecv),0,sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
-				if(ret!=0)
-				{
-					if(pUpdateMsgRecv.startFlag == 0xEB && pUpdateMsgRecv.endFlag == 0xF5)
-					{
-						if(pUpdateMsgRecv.cmd == 0x81)
-						{
-							if(pUpdateMsgRecv.data == 0x11)
-							{
-								updateStep = UPDATE_STEP_PREPARE_SEND_UPDATE_DATA;
-								errorCount = 0;
-							}
-							else
-							{
-								errorCount++;
-							}						
-						}
-						else
-						{
-							errorCount++;
-						}
-					}
-					else
-					{
-						errorCount++;
-					}
-				}			
-				else
-				{
-					errorCount++;
-				}
-
-				if(errorCount>10)
-				{
-					updateStep = UPDATE_STEP_RESET;
-					errorCount = 0;
-				}
-				
-				#ifdef USING_PRINTF1
-							//printf("update step:%d\n",updateStep);
-							printf("query:");
-							for(j=0;j<updateMsgSendLen;j++)
-							{
-								printf("%x ",pUpdateMsgSend[j]);
-							}
-							printf("\nanswer:");
-							for(j=0;j<sizeof(BMS_Update_Recv_Msg_Type);j++)
-							{
-								printf("%x ",*(((UINT8*)&pUpdateMsgRecv)+j));
-							}
-							printf("\n");
-							printf("next update step:%d\n",updateStep);
-				#endif
-				osDelay(50);
-				break;	
-				
-			case UPDATE_STEP_PREPARE_SEND_UPDATE_DATA:
-				dataLen = 1;
-				updateMsgSendLen = 8;
-				pUpdateMsgSend[0] = 0xEB; //start flag
-				pUpdateMsgSend[1] = 0x01;	//add flag
-				pUpdateMsgSend[2] = 0x00; //write
-				pUpdateMsgSend[3] = 0x04;	//data len
-				pUpdateMsgSend[4] = 0x81;	//cmd
-				pUpdateMsgSend[5] = 0x55;	//data
-				pUpdateMsgSend[6] = 0xDA;	//check
-				pUpdateMsgSend[7] = 0xF5;	//end flag
-				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen,(UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
-				if(ret!=0)
-				{
-					if(pUpdateMsgRecv.startFlag == 0xEB && pUpdateMsgRecv.endFlag == 0xF5)
-					{
-						if(pUpdateMsgRecv.cmd == 0x81)
-						{
-							if(pUpdateMsgRecv.data == 0x11)
-							{
-								updateStep = UPDATE_STEP_SEND_UPDATE_DATA;
-								errorCount = 0;
-							}
-							else
-							{
-								errorCount++;
-							}						
-						}
-						else
-						{
-							errorCount++;
-						}
-					}
-					else
-					{
-						errorCount++;
-					}
-				}			
-				else
-				{
-					errorCount++;
-				}
-
-				if(errorCount>10)
-				{
-					updateStep = UPDATE_STEP_RESET;
-					errorCount = 0;
-				}
-				
-				#ifdef USING_PRINTF1
-					//printf("update step:%d\n",updateStep);
-					printf("query:");
-					for(j=0;j<updateMsgSendLen;j++)
-					{
-						printf("%x ",pUpdateMsgSend[j]);
-					}
-					printf("\nanswer:");
-					for(j=0;j<sizeof(BMS_Update_Recv_Msg_Type);j++)
-					{
-						printf("%x ",*(((UINT8*)&pUpdateMsgRecv)+j));
-					}
-					printf("\n");	
-					printf("next update step:%d\n",updateStep);
-				#endif
-				osDelay(50);
-				break;
-			case UPDATE_STEP_SEND_UPDATE_DATA:
-				dataLen = 64;
-				updateMsgSendLen = 75;
-							
-				for(currentPackage=0;currentPackage<updateDataTotalByteLen/64;currentPackage++)
-				{
-					currentPackageStartAddr = currentPackage*64;
-				
-					pUpdateMsgSend[0] = 0xEB; //start flag
-					pUpdateMsgSend[1] = 0x01;	//add flag
-					pUpdateMsgSend[2] = 0x00; //write
-					pUpdateMsgSend[3] = 0x47;	//data len			
-					pUpdateMsgSend[4] = 0x82;	//cmd
-					pUpdateMsgSend[5] = (currentPackageStartAddr>>24)&0xFF;
-					pUpdateMsgSend[6] = (currentPackageStartAddr>>16)&0xFF;
-					pUpdateMsgSend[7] = (currentPackageStartAddr>>8)&0xFF;
-					pUpdateMsgSend[8] = currentPackageStartAddr&0xFF;
-					BSP_QSPI_Read_Safe(&pUpdateMsgSend[9], FLASH_BMS_FOTA_START_ADDR+4+currentPackage*dataLen, dataLen);  //data			
-					pUpdateMsgSend[8+dataLen+1] = SP_BMS_Update_CheckSUM(&pUpdateMsgSend[3], dataLen+6);  //check sum
-					pUpdateMsgSend[8+dataLen+2] = 0xF5;	//end flag
-					memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-					ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
-					if(ret!=0)
-					{
-						if(pUpdateMsgRecv.startFlag == 0xEB && pUpdateMsgRecv.endFlag == 0xF5)
-						{
-							if(pUpdateMsgRecv.cmd == 0x81)
-							{
-								if(pUpdateMsgRecv.data == 0x11)
-								{
-									if(currentPackage+1 == updateDataTotalByteLen/64)
-									{
-										updateStep = UPDATE_STEP_SEND_DATA_END;
-									}
-									errorCount = 0;
-								}
-								else
-								{
-									errorCount++;
-								}						
-							}
-							else
-							{
-								errorCount++;
-							}
-						}
-						else
-						{
-							errorCount++;
-						}
-					}			
-					else
-					{
-						errorCount++;
-					}
-
-					if(errorCount>10)
-					{					
-						updateStep = UPDATE_STEP_RESET;
-						errorCount = 0;
-						break;
-					}
-				#ifdef USING_PRINTF1
-							//printf("update step:%d\n",updateStep);
-							printf("query:");
-							for(j=0;j<updateMsgSendLen;j++)
-							{
-								printf("%x ",pUpdateMsgSend[j]);
-							}
-							printf("\nanswer:");
-							for(j=0;j<sizeof(BMS_Update_Recv_Msg_Type);j++)
-							{
-								printf("%x ",*(((UINT8*)&pUpdateMsgRecv)+j));
-							}
-							printf("\n");
-							printf("next update step:%d\n",updateStep);
-				#endif
-				}
-				osDelay(50);
-				break;
-
-			case UPDATE_STEP_SEND_DATA_END:
-				dataLen = 1;
-				updateMsgSendLen = 8;
-				pUpdateMsgSend[0] = 0xEB; //start flag
-				pUpdateMsgSend[1] = 0x01;	//add flag
-				pUpdateMsgSend[2] = 0x00; //write
-				pUpdateMsgSend[3] = 0x04;	//data len
-				pUpdateMsgSend[4] = 0x81;	//cmd
-				pUpdateMsgSend[5] = 0x66;	//data
-				pUpdateMsgSend[6] = 0xEB;	//check
-				pUpdateMsgSend[7] = 0xF5;	//end flag
-				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				ret = SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), sizeof(BMS_Update_Recv_Msg_Type), 500);
-				if(ret!=0)
-				{
-					if(pUpdateMsgRecv.startFlag == 0xEB && pUpdateMsgRecv.endFlag == 0xF5)
-					{
-						if(pUpdateMsgRecv.cmd == 0x81)
-						{
-							if(pUpdateMsgRecv.data == 0x11)
-							{
-								updateStep = UPDATE_STEP_START_INSTALL;
-								errorCount = 0;
-							}
-							else
-							{
-								errorCount++;
-							}						
-						}
-						else
-						{
-							errorCount++;
-						}
-					}
-					else
-					{
-						errorCount++;
-					}
-				}			
-				else
-				{
-					errorCount++;
-				}
-
-				if(errorCount>10)
-				{
-					updateStep = UPDATE_STEP_RESET;
-					errorCount = 0;
-				}
-				
-				#ifdef USING_PRINTF1
-							//printf("update step:%d\n",updateStep);
-							printf("query:");
-							for(j=0;j<updateMsgSendLen;j++)
-							{
-								printf("%x ",pUpdateMsgSend[j]);
-							}
-							printf("\nanswer:");
-							for(j=0;j<sizeof(BMS_Update_Recv_Msg_Type);j++)
-							{
-								printf("%x ",*(((UINT8*)&pUpdateMsgRecv)+j));
-							}
-							printf("\n");
-							printf("next update step:%d\n",updateStep);
-				#endif
-				osDelay(50);
-				break;			
-
-			case UPDATE_STEP_START_INSTALL:
-				dataLen = 1;
-				updateMsgSendLen = 8;
-				pUpdateMsgSend[0] = 0xEB; //start flag
-				pUpdateMsgSend[1] = 0x01;	//add flag
-				pUpdateMsgSend[2] = 0x00; //write
-				pUpdateMsgSend[3] = 0x04;	//data len
-				pUpdateMsgSend[4] = 0x81;	//cmd
-				pUpdateMsgSend[5] = 0x99;	//data
-				pUpdateMsgSend[6] = 0x1E;	//check
-				pUpdateMsgSend[7] = 0xF5;	//end flag
-				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), 0, 500);
-				
-				updateStep = UPDATE_STEP_END;
-				
-				#ifdef USING_PRINTF1
-							//printf("update step:%d\n",updateStep);
-							printf("query:");
-							for(j=0;j<updateMsgSendLen;j++)
-							{
-								printf("%x ",pUpdateMsgSend[j]);
-							}
-							printf("\nanswer:");
-							for(j=0;j<sizeof(BMS_Update_Recv_Msg_Type);j++)
-							{
-								printf("%x ",*(((UINT8*)&pUpdateMsgRecv)+j));
-							}
-							printf("\n");	
-							printf("next update step:%d\n",updateStep);
-				#endif
-				osDelay(50);
-				break;
-			case UPDATE_STEP_END:
-				updateStep = UPDATE_STEP_CHECK_VERSION;
-				printf("update end\n");
-				bmsUpdateFlag = 0;
-				break;
-			case UPDATE_STEP_RESET:
-				dataLen = 1;
-				updateMsgSendLen = 8;
-				pUpdateMsgSend[0] = 0xEB; //start flag
-				pUpdateMsgSend[1] = 0x01;	//add flag
-				pUpdateMsgSend[2] = 0x00; //write
-				pUpdateMsgSend[3] = 0x04;	//data len
-				pUpdateMsgSend[4] = 0x81;	//cmd
-				pUpdateMsgSend[5] = 0xAA;	//data
-				pUpdateMsgSend[6] = 0x2F;	//check
-				pUpdateMsgSend[7] = 0xF5;	//end flag
-				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), 0, 500);
-				osDelay(50);
-				
-				resetCount++;
-				if(resetCount>=2)
-				{
-					updateStep = UPDATE_STEP_DOWNLOAD_BREAK_OFF;
-					resetCount = 0;
-				}
-				else
-				{
-					updateStep = UPDATE_STEP_PREPARE_SEND_DATA_LEN;
-				}
-			#ifdef USING_PRINTF
-				printf("update error!!\n rest and start send data lenth again!!\n continue update!\n");
-			#endif
-				break;
-			case UPDATE_STEP_DOWNLOAD_BREAK_OFF:
-				dataLen = 1;
-				updateMsgSendLen = 8;
-				pUpdateMsgSend[0] = 0xEB; //start flag
-				pUpdateMsgSend[1] = 0x01;	//add flag
-				pUpdateMsgSend[2] = 0x00; //write
-				pUpdateMsgSend[3] = 0x04;	//data len
-				pUpdateMsgSend[4] = 0x81;	//cmd
-				pUpdateMsgSend[5] = 0xBB;	//data
-				pUpdateMsgSend[6] = 0x40;	//check
-				pUpdateMsgSend[7] = 0xF5;	//end flag
-				memset((UINT8*)(&pUpdateMsgRecv) , 0, sizeof(BMS_Update_Recv_Msg_Type));
-				SP_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(&pUpdateMsgRecv), 0, 500);
-				osDelay(50);
-				updateStep = UPDATE_STEP_CHECK_VERSION;
-				Cycle_conut++;
-				break;
-			case UPDATE_STEP_ERROR:
-				updateStep = UPDATE_STEP_CHECK_VERSION;
-				printf("update error end\n");
-				bmsUpdateFlag = 0;
-			break;
-
-			default:
-				updateStep = UPDATE_STEP_CHECK_VERSION;
-				printf("update default end\n");
-				bmsUpdateFlag = 0;
-			break;
-		}
-	}
-}
-
-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);
-	#ifdef USING_PRINTF
-		printf("query in:");
-		for(j=0;j<sendLen;j++)
-		{
-			printf("%x ",*(pSend+j));
-		}
-		printf("\n");	
-	#endif
-	if(readLen>0)
-	{
-		USARTdrv->Receive(pRead,readLen);         
-		while((isRecvTimeout == false) && (isRecvComplete == false))
-		{
-			timeCount++;
-			osDelay(100);
-			if (timeCount>=timeout/100)
-			{
-				timeCount =0;
-				isRecvTimeout = true;
-				break;
-			}
-		}
-		#ifdef USING_PRINTF
-			printf("\nanswer in:");
-			for(j=0;j<readLen;j++)
-			{
-				printf("%x ",*(pRead+j));
-			}
-			printf("\n");
-		#endif	
-		if (isRecvComplete == true)
-		{
-			isRecvComplete = false;
-			if(*(pRead+0)!=0xEB)
-			{
-				USARTdrv->Uninitialize();
-				osDelay(100);
-				USARTdrv->Initialize(USART_callback);
-				USARTdrv->PowerControl(ARM_POWER_FULL);
-				USARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS |
-						ARM_USART_DATA_BITS_8 |
-						ARM_USART_PARITY_NONE |
-						ARM_USART_STOP_BITS_1 |
-						ARM_USART_FLOW_CONTROL_NONE, 9600);
-				#ifdef USING_PRINTF
-					printf("\nuart reset in \n");	
-				#endif
-				return  0;
-			}
-			return readLen;
-		}
-		else
-		{
-			memset(pRead,0x00,readLen);
-			isRecvTimeout = false;
-			return 0;
-		}
-	}
-	else
-	{
-			return 1;
-	}
-}
-UINT8 SP_BMS_Update_CheckSUM(UINT8* pSendData,UINT8 len)
-{
-	UINT8 ret = 0;
-	UINT8 i=0;
-	for(i=0;i<len;i++)
-	{
-			ret +=*(pSendData+i);
-	}
-	return ret&0xFF;
-}
-//________________________________________________________________________________
-updateBMSStatus MS_BMS_Update_Service() //美顺BMS升级服务
-{
-	#ifdef USING_PRINTF
-		UINT8 ii = 0;
-	#endif
-	
-	UINT8 errorCount = 0;	
-	UINT16 currentPackage = 0;	
-	UINT32 updateDataTotalByteLen = 0;
-	UINT16 updateDataPackageCount = 0;
-	UINT8  ReadNVMTemp[64];
-	UpdateStep_MS_BMS updateStep = MS_UPDATE_STEP_SEND_FIRMWARE_UPDATE_REQUEST_AND_JUMP_TO_BOOTLOADER;	
-	
-	
-	UINT16 i,j=0;
-	UINT8 dataLen = 0;
-	UINT8 ret0 = 0;
-	updateBMSStatus ret = updateFailed;
-		
-	UINT8 pUpdateMsgSend[80];
-	UINT32 updateMsgSendLen = 0;
-	UINT32 updateMsgReadLen = 0;
-	
-	BOOL bmsUpdateFlag = TRUE;
-	UINT8 bmsAnswerMsg[8];
-	
-	//static UpdateStep step = UPDATE_STEP_CHECK_VERSION;
-	UINT8 Cycle_conut = 0;
-	UINT16 CRCtemp = 0;
-	UINT8 headerLen = 5;
-
-	UINT8 checkSum = 0x00;
-	UINT8 checkSumCal = 0x00;
-	UINT8 tempLen = 0x00;	
-
-	BSP_QSPI_Read_Safe(&checkSum,FLASH_BMS_FOTA_START_ADDR,1);
-
-	memset(ReadNVMTemp, 0, 64);
-	BSP_QSPI_Read_Safe(ReadNVMTemp, FLASH_BMS_FOTA_START_ADDR+1, 4);  //data
-
-	updateDataTotalByteLen = ((ReadNVMTemp[0]<<24)&0xFF000000) | ((ReadNVMTemp[1]<<16)&0xFF0000) | ((ReadNVMTemp[2]<<8)&0xFF00) | (ReadNVMTemp[3]&0xFF) ;
-	updateDataPackageCount = (updateDataTotalByteLen+(64-1))/64;  //进一法 e = (a+(b-1))/b	
-
-	for(i=0; i<((updateDataTotalByteLen+4)+(64-1))/64;i++)
-	{
-		memset(ReadNVMTemp, 0, 64);
-		if((i+1)*64 < (updateDataTotalByteLen+4))
-		{	
-			tempLen = 64;
-			BSP_QSPI_Read_Safe(ReadNVMTemp,FLASH_BMS_FOTA_START_ADDR+1+i*64,64);
-		}
-		else
-		{
-			tempLen = (updateDataTotalByteLen+4) - i*64;
-			BSP_QSPI_Read_Safe(ReadNVMTemp,FLASH_BMS_FOTA_START_ADDR+1+i*64,tempLen);
-		}
-		
-		for(j = 0; j< tempLen; j++)
-		{
-			checkSumCal = (checkSumCal + ReadNVMTemp[j]) & 0xFF;
-		}
-		//osDelay(10);
-	}
-	if(checkSum != checkSumCal)
-	{
-		#ifdef USING_PRINTF
-			printf("checksum error: checksum = %x, checksumCal = %x\n",checkSum,checkSumCal);
-		#endif
-		ret = updateErrorCheckSumError;	
-		return ret;
-	}
-	else
-	{
-		#ifdef USING_PRINTF
-			printf("checksum OK: checksum = %x, checksumCal = %x\n",checkSum,checkSumCal);
-		#endif
-	}
-
-	#ifdef USING_PRINTF
-		printf(" bmsUpdateFlag = %x, Cycle_conut = %x\n",bmsUpdateFlag,Cycle_conut);
-	#endif
-	while(bmsUpdateFlag && Cycle_conut<2)
-	{
-		#ifdef USING_PRINTF
-			printf("update ms bms step %d\n:",updateStep);				
-		#endif
-		switch (updateStep)
-		{
-			
-			case MS_UPDATE_STEP_SEND_FIRMWARE_UPDATE_REQUEST_AND_JUMP_TO_BOOTLOADER:  //0x01				
-				dataLen = 0x00;
-				updateMsgSendLen = 6+dataLen;
-				updateMsgReadLen = 8;
-				
-				pUpdateMsgSend[0] = 0x01; //node byte
-				pUpdateMsgSend[1] = 0x40;	//func byte
-				pUpdateMsgSend[2] = updateStep; //cmd byte
-				pUpdateMsgSend[3] = dataLen;	//data len
-											//no data type
-				CRCtemp = MS_BMS_Update_CRC16(pUpdateMsgSend, 4);
-				pUpdateMsgSend[4] = (CRCtemp>>8)&0xFF; // CRC High
-				pUpdateMsgSend[5] = CRCtemp&0xFF;		//CRC Low
-				
-				memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 500);
-				#ifdef USING_PRINTF
-				printf("update step 1 answer,updateMsgReadLen = %x:\n",updateMsgReadLen);
-				
-				 for(ii=0;ii<updateMsgReadLen;ii++)
-					printf("%x ",bmsAnswerMsg[ii]);
-
-					printf("\nret0 = %d",ret0);
-					printf("\n");
-				#endif
-				if(ret0!=0)
-				{
-					if(bmsAnswerMsg[0] == 0x01 && bmsAnswerMsg[1] == 0x40)  // node and func byte
-					{
-						if(bmsAnswerMsg[2] == MS_UPDATE_STEP_FIRMWARE_UPDATE_REQUEST_ANSWER && bmsAnswerMsg[3] == 0x02)	//answer cmd byte:0x02, answer data len:0x02
-						{
-							if(bmsAnswerMsg[4] == 0x00)	//answer data byte1
-							{
-								if(bmsAnswerMsg[5] == 0x00)	//answer data byte2
-								{
-									updateStep = MS_UPDATE_STEP_SEND_FIRMWARE_INFO;
-									errorCount = 0;
-								}
-							}
-							else if(bmsAnswerMsg[4] == 0x01) //不允许升级
-							{
-								if(bmsAnswerMsg[5] == 0x01)//电量过低
-								{
-									updateStep = MS_UPDATE_STEP_ERROR;
-									ret = updateErrorBMSPowerLow;
-								}
-								else if(bmsAnswerMsg[5] == 0x02)//电池存在保护状态不允许升级
-								{
-									updateStep = MS_UPDATE_STEP_ERROR;
-									ret = updateErrorBMSWarningProtect;
-								}
-								else if(bmsAnswerMsg[5] == 0x03) //不支持升级
-								{
-									updateStep = MS_UPDATE_STEP_ERROR;
-									ret = updateErrorBMSNotSurport;
-								}
-								else if(bmsAnswerMsg[5] == 0x04) //当前电池处于充放电状态
-								{
-									updateStep = MS_UPDATE_STEP_ERROR;
-									ret = updateErrorBMSWorkState;
-								}
-								else
-								{
-									errorCount++;
-								}
-							}						
-						}
-						else
-						{
-							errorCount++;
-						}
-					}
-					else
-					{
-						errorCount++;
-					}
-				}			
-				else
-				{
-					errorCount++;
-				}
-
-				if(errorCount>10)
-				{
-					updateStep = MS_UPDATE_STEP_ERROR;
-					errorCount = 0;
-				}								
-				osDelay(50);
-				printf(" step 1 ret = %d\n",ret);
-				break;
-			case MS_UPDATE_STEP_SEND_FIRMWARE_INFO:  //0x03
-				dataLen = 52;
-				updateMsgSendLen = 6+dataLen;
-				updateMsgReadLen = 7;
-				pUpdateMsgSend[0] = 0x01; //node byte
-				pUpdateMsgSend[1] = 0x40;	//func byte
-				pUpdateMsgSend[2] = updateStep; //cmd byte
-				pUpdateMsgSend[3] = dataLen;	//data len
-
-				memset(ReadNVMTemp, 0, 64);
-				BSP_QSPI_Read_Safe(ReadNVMTemp, FLASH_BMS_FOTA_START_ADDR+headerLen, 16);	//data
-				MEMCPY(&pUpdateMsgSend[4], ReadNVMTemp, 16);  //厂家信息,未开启校验
-				MEMCPY(&pUpdateMsgSend[4+16], ReadNVMTemp, 16);	//保护板硬件序列号,未开启校验
-				pUpdateMsgSend[4+16*2 + 0] = (updateDataTotalByteLen>>24)&0xFF;	//固件包大小
-				pUpdateMsgSend[4+16*2 + 1] = (updateDataTotalByteLen>>16)&0xFF;
-				pUpdateMsgSend[4+16*2 + 2] = (updateDataTotalByteLen>>8)&0xFF;
-				pUpdateMsgSend[4+16*2 + 3] = (updateDataTotalByteLen)&0xFF;				
-				MEMCPY(&pUpdateMsgSend[4+16*2+4], ReadNVMTemp, 16); // 固件包头信息,未开启校验
-				
-				CRCtemp = MS_BMS_Update_CRC16(pUpdateMsgSend, 4+dataLen);
-				
-				pUpdateMsgSend[4+dataLen] = (CRCtemp>>8)&0xFF; // CRC High
-				pUpdateMsgSend[5+dataLen] = CRCtemp&0xFF;		//CRC Low
-				
-				memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 500);
-				#ifdef USING_PRINTF
-				printf("update step 3 answer:\n");
-				 for(ii=0;ii<updateMsgReadLen;ii++)
-					printf("%x ",bmsAnswerMsg[ii]);
-
-					printf("\nret0 = %d",ret0);
-					printf("\n");
-				#endif
-				if(ret0!=0)
-				{
-					if(bmsAnswerMsg[0] == 0x01 && bmsAnswerMsg[1] == 0x40)  // node and func byte
-					{
-						if(bmsAnswerMsg[2] == MS_UPDATE_STEP_FIRMWARE_INFO_CHECK_AND_UPDATE_REQEST_ANSWER && bmsAnswerMsg[3] == 0x01)	//answer cmd byte:0x04, answer data len:0x01
-						{
-							if(bmsAnswerMsg[4] == 0x00)	//answer data byte1
-							{								
-								updateStep = MS_UPDATE_STEP_EREASE_APP_FLASH_REQUEST;
-								errorCount = 0;
-							}
-							else if(bmsAnswerMsg[4] == 0x01) //厂家信息错误
-							{
-								errorCount++;
-								ret = updateErrorFirmwareInfoError;
-							}		
-							else if(bmsAnswerMsg[4] == 0x02) //硬件序列号不匹配
-							{
-								errorCount++;
-								ret = updateErrorFirmwareInfoError;
-							}
-							else if(bmsAnswerMsg[4] == 0x03) //固件大小超出范围
-							{
-								errorCount++;
-								ret = updateErrorFirmwareSizeError;
-							}
-							else if(bmsAnswerMsg[4] == 0x04) //固件包头信息错误
-							{
-								errorCount++;
-								ret = updateErrorFirmwareInfoError;
-							}
-							else
-							{
-								errorCount++;
-							}
-						}
-						else
-						{
-							errorCount++;
-						}
-					}
-					else
-					{
-						errorCount++;
-					}
-				}			
-				else
-				{
-					errorCount++;
-				}
-
-				if(errorCount>10)
-				{
-					updateStep = MS_UPDATE_STEP_ERROR;
-					errorCount = 0;
-				}		
-				printf(" step 3 ret = %d\n",ret);
-				osDelay(50);
-				break;
-			case MS_UPDATE_STEP_EREASE_APP_FLASH_REQUEST:  //0x05
-				dataLen = 0;
-				updateMsgSendLen = 6+dataLen;
-				updateMsgReadLen = 8;
-				pUpdateMsgSend[0] = 0x01; //node byte
-				pUpdateMsgSend[1] = 0x40;	//func byte
-				pUpdateMsgSend[2] = updateStep; //cmd byte
-				pUpdateMsgSend[3] = dataLen;	//data len				
-				
-				CRCtemp = MS_BMS_Update_CRC16(pUpdateMsgSend, 4+dataLen);
-				
-				pUpdateMsgSend[4+dataLen] = (CRCtemp>>8)&0xFF; // CRC High
-				pUpdateMsgSend[5+dataLen] = CRCtemp&0xFF;		//CRC Low
-				
-				memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 500);
-				#ifdef USING_PRINTF
-				printf("update step 5 answer:\n");
-				 for(ii=0;ii<updateMsgReadLen;ii++)
-					printf("%x ",bmsAnswerMsg[ii]);
-
-					printf("\nret0 = %d",ret0);
-					printf("\n");
-				#endif
-				if(ret0!=0)
-				{
-					if(bmsAnswerMsg[0] == 0x01 && bmsAnswerMsg[1] == 0x40)  // node and func byte
-					{
-						if(bmsAnswerMsg[2] == MS_UPDATE_STEP_EREASE_FLASH_ANSWER && bmsAnswerMsg[3] == 0x02)	//answer cmd byte:0x06, answer data len:0x02
-						{
-							if(bmsAnswerMsg[4] == 0x00)	//answer data byte1, erease successed
-							{								
-								updateStep = MS_UPDATE_STEP_SEND_UPDATE_DATA; //0x07
-								errorCount = 0;
-							}
-							else if(bmsAnswerMsg[4] == 0x01) //擦除失败
-							{
-								errorCount++;
-								ret = updateErrorAppErease;
-							}							
-							else
-							{
-								errorCount++;
-							}
-						}
-						else
-						{
-							errorCount++;
-						}
-					}
-					else
-					{
-						errorCount++;
-					}
-				}			
-				else
-				{
-					errorCount++;
-				}
-
-				if(errorCount>10)
-				{
-					updateStep = MS_UPDATE_STEP_ERROR;
-					errorCount = 0;
-				}								
-				osDelay(50);
-				break;
-			case MS_UPDATE_STEP_SEND_UPDATE_DATA:  //0x07
-				
-				updateMsgReadLen = 7;
-				pUpdateMsgSend[0] = 0x01; //node byte
-				pUpdateMsgSend[1] = 0x40;	//func byte
-				pUpdateMsgSend[2] = updateStep; //cmd byte
-				
-				for(i = 0; i < updateDataPackageCount ; i++ )	
-				{					
-					
-
-					memset(ReadNVMTemp, 0, 64);
-					
-					if((i+1)*64 < (updateDataTotalByteLen))
-					{	
-						tempLen = 64;
-						BSP_QSPI_Read_Safe(ReadNVMTemp,FLASH_BMS_FOTA_START_ADDR+headerLen+i*64,64);
-					}
-					else
-					{
-						tempLen = (updateDataTotalByteLen+4) - i*64;
-						BSP_QSPI_Read_Safe(ReadNVMTemp,FLASH_BMS_FOTA_START_ADDR+headerLen+i*64,tempLen);
-					}
-
-					CRCtemp = MS_BMS_Update_CRC16(ReadNVMTemp, tempLen);
-
-					dataLen = tempLen+6;  //data len =count(2+2 byte) + crc(2byte) +  update data len
-					updateMsgSendLen = 6+dataLen; // updateMsgSendLen = data len + header len(6byte)
-
-					pUpdateMsgSend[3] = dataLen;	//data len
-					
-					pUpdateMsgSend[4] = ((i+1)>>8)&0xFF;  //当前包序号,大端模式
-					pUpdateMsgSend[5] = (i+1)&0xFF;
-
-					pUpdateMsgSend[6] = (updateDataPackageCount>>8)&0xFF;
-					pUpdateMsgSend[7] = updateDataPackageCount&0xFF;
-					pUpdateMsgSend[8] = (CRCtemp>>8)&0xFF; // data CRC High
-					pUpdateMsgSend[9] = CRCtemp&0xFF;		//data CRC Low					
-					
-					MEMCPY(&pUpdateMsgSend[4+6], ReadNVMTemp, 64);  //升级数据,64字节
-					
-					
-					CRCtemp = MS_BMS_Update_CRC16(pUpdateMsgSend, 4+dataLen);
-					
-					pUpdateMsgSend[4+dataLen] = (CRCtemp>>8)&0xFF; // CRC High
-					pUpdateMsgSend[5+dataLen] = CRCtemp&0xFF;		//CRC Low
-					
-					memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-					ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 500);
-					#ifdef USING_PRINTF
-						printf("update step 7 answer:\n");
-					 for(ii=0;ii<updateMsgReadLen;ii++)
-						printf("%x ",bmsAnswerMsg[ii]);
-
-						printf("\nret0 = %d",ret0);
-						printf("\n");
-					#endif
-					if(ret0!=0)
-					{
-						if(bmsAnswerMsg[0] == 0x01 && bmsAnswerMsg[1] == 0x40)  // node and func byte
-						{
-							if(bmsAnswerMsg[2] == MS_UPDATE_STEP_UPDATE_DATA_WRITE_ANSWER && bmsAnswerMsg[3] == 0x01)	//answer cmd byte:0x04, answer data len:0x01
-							{
-								if(bmsAnswerMsg[4] == 0x00)	//answer data byte1,接收并操作成功
-								{								
-									updateStep = MS_UPDATE_STEP_EREASE_APP_FLASH_REQUEST;
-									errorCount = 0;
-								}
-								else if(bmsAnswerMsg[4] == 0x01) //固件块校验失败
-								{
-									errorCount=10;
-									ret = updateErrorPackageCRC;
-								}		
-								else if(bmsAnswerMsg[4] == 0x02) //烧写失败
-								{
-									errorCount=10;
-									ret = updateErrorPackageWrite;
-								}
-								else if(bmsAnswerMsg[4] == 0x03) //固件块编号异常
-								{
-									errorCount=10;
-									ret = updateErrorPackageNo;
-								}								
-								else
-								{
-									errorCount=10;
-								}
-							}
-							else
-							{
-								errorCount=10;
-							}
-						}
-						else
-						{
-							errorCount=10;
-						}
-					}			
-					else
-					{
-						errorCount=10;
-					}
-
-					if(errorCount>=10)
-					{
-						updateStep = MS_UPDATE_STEP_ERROR;
-						errorCount = 0;
-						i--;
-						break;
-					}								
-					osDelay(50);
-				}
-				if(i == updateDataPackageCount)
-				{
-					updateStep = MS_UPDATE_STEP_SEND_UPDATE_DATA_END_AND_JUMP_TO_APP;
-				}
-				break;
-			case MS_UPDATE_STEP_SEND_UPDATE_DATA_END_AND_JUMP_TO_APP:  //0x09
-				dataLen = 0x00;
-				updateMsgSendLen = 6+dataLen;
-				updateMsgReadLen = 7;
-				
-				pUpdateMsgSend[0] = 0x01; //node byte
-				pUpdateMsgSend[1] = 0x40;	//func byte
-				pUpdateMsgSend[2] = updateStep; //cmd byte
-				pUpdateMsgSend[3] = dataLen;	//data len
-											//no data type
-				CRCtemp = MS_BMS_Update_CRC16(pUpdateMsgSend, 4);
-				pUpdateMsgSend[4] = (CRCtemp>>8)&0xFF; // CRC High
-				pUpdateMsgSend[5] = CRCtemp&0xFF;		//CRC Low
-				
-				memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 500);
-				#ifdef USING_PRINTF
-				printf("update step 9 answer:\n");
-				 for(ii=0;ii<updateMsgReadLen;ii++)
-					printf("%x ",bmsAnswerMsg[ii]);
-
-					printf("\nret0 = %d",ret0);
-					printf("\n");
-				#endif
-				if(ret0!=0)
-				{
-					if(bmsAnswerMsg[0] == 0x01 && bmsAnswerMsg[1] == 0x40)  // node and func byte
-					{
-						if(bmsAnswerMsg[2] == MS_UPDATE_STEP_JUMP_TO_APP_ANSWER && bmsAnswerMsg[3] == 0x01)	//answer cmd byte:0x0A, answer data len:0x01
-						{
-							if(bmsAnswerMsg[4] == 0x00)	//answer data byte1, update succeed
-							{
-								errorCount = 0;
-								updateStep = MS_UPDATE_STEP_READ_CURRENT_RUNNING_MODE; //0x0B
-							}
-							else if(bmsAnswerMsg[4] == 0x01) //升级失败
-							{
-								errorCount = 10;
-								ret = updateFailed;
-							}						
-						}
-						else
-						{
-							errorCount++;
-						}
-					}
-					else
-					{
-						errorCount++;
-					}
-				}			
-				else
-				{
-					errorCount++;
-				}
-
-				if(errorCount>=10)
-				{
-					updateStep = MS_UPDATE_STEP_ERROR;
-					errorCount = 0;
-				}								
-				osDelay(50);
-				break;
-			case MS_UPDATE_STEP_READ_CURRENT_RUNNING_MODE:  //0x0B
-				dataLen = 0x00;
-				updateMsgSendLen = 6+dataLen;
-				updateMsgReadLen = 8;
-				
-				pUpdateMsgSend[0] = 0x01; //node byte
-				pUpdateMsgSend[1] = 0x40;	//func byte
-				pUpdateMsgSend[2] = updateStep; //cmd byte
-				pUpdateMsgSend[3] = dataLen;	//data len
-											//no data type
-				CRCtemp = MS_BMS_Update_CRC16(pUpdateMsgSend, 4);
-				pUpdateMsgSend[4] = (CRCtemp>>8)&0xFF; // CRC High
-				pUpdateMsgSend[5] = CRCtemp&0xFF;		//CRC Low
-				
-				memset((UINT8*)(bmsAnswerMsg) , 0, 8);
-				ret0 = MS_BMS_Update_Query(pUpdateMsgSend, updateMsgSendLen, (UINT8*)(bmsAnswerMsg), updateMsgReadLen, 500);
-				#ifdef USING_PRINTF
-				printf("update step A answer:\n");
-				 for(ii=0;ii<updateMsgReadLen;ii++)
-					printf("%x ",bmsAnswerMsg[ii]);
-
-					printf("\nret0 = %d",ret0);
-					printf("\n");
-				#endif
-				if(ret0!=0)
-				{
-					if(bmsAnswerMsg[0] == 0x01 && bmsAnswerMsg[1] == 0x40)  // node and func byte
-					{
-						if(bmsAnswerMsg[2] == MS_UPDATE_STEP_CURRENT_RUNNING_MODE_ANSWER && bmsAnswerMsg[3] == 0x02)	//answer cmd byte:0x0C, answer data len:0x02
-						{
-							if(bmsAnswerMsg[4] == 0x01)	//answer data byte1, update succeed, app is running
-							{
-								errorCount = 0;
-								updateStep = MS_UPDATE_STEP_END;
-							}
-							else if(bmsAnswerMsg[4] == 0x00) //update failed , boot is running,error
-							{
-								errorCount = 10;
-							}						
-						}
-						else
-						{
-							errorCount++;
-						}
-					}
-					else
-					{
-						errorCount++;
-					}
-				}			
-				else
-				{
-					errorCount++;
-				}
-
-				if(errorCount>=3)
-				{
-					updateStep = MS_UPDATE_STEP_ERROR;
-					errorCount = 0;
-				}								
-				osDelay(50);
-				break;
-			case MS_UPDATE_STEP_END: //0x0D
-				errorCount = 0;
-				bmsUpdateFlag = FALSE;
-				ret = updateOK;
-				break;
-			case MS_UPDATE_STEP_ERROR:	//0x0E
-				errorCount = 0;
-				bmsUpdateFlag = true;
-				Cycle_conut++;
-				if(Cycle_conut>2)
-				{
-					ret = updateErrorTimeout;
-					bmsUpdateFlag = FALSE;
-				}
-				break;
-			default:
-				bmsUpdateFlag = FALSE;
-				break;
-		}
-	}
-	#ifdef USING_PRINTF
-		printf("last ret = %x\n",ret);
-	#endif
-	return ret;
-
-}
-UINT8 MS_BMS_Update_Query(UINT8* pSend,UINT32 sendLen, UINT8* pRead, UINT32 readLen, UINT32 timeout)
-{
-
-	UINT8 timeCount = 0;
-	UINT8 j=0;
-	USARTdrv->Send(pSend,sendLen);
-	#ifdef USING_PRINTF
-		printf("query in:");
-		for(j=0;j<sendLen;j++)
-		{
-			printf("%x ",*(pSend+j));
-		}
-		printf("\n");	
-	#endif
-	if(readLen>0)
-	{
-		USARTdrv->Receive(pRead,readLen);         
-		while((isRecvTimeout == false) && (isRecvComplete == false))
-		{
-			timeCount++;
-			osDelay(100);
-			if (timeCount>=timeout/100)
-			{
-				timeCount =0;
-				isRecvTimeout = true;
-				break;
-			}
-		}
-		#ifdef USING_PRINTF
-			printf("\nanswer in:");
-			for(j=0;j<readLen;j++)
-			{
-				printf("%x ",*(pRead+j));
-			}
-			printf("\n");
-		#endif	
-		if (isRecvComplete == true)
-		{
-			isRecvComplete = false;
-			if(*(pRead+0)!=0x01)
-			{
-				USARTdrv->Uninitialize();
-				osDelay(100);
-				USARTdrv->Initialize(USART_callback);
-				USARTdrv->PowerControl(ARM_POWER_FULL);
-				USARTdrv->Control(ARM_USART_MODE_ASYNCHRONOUS |
-						ARM_USART_DATA_BITS_8 |
-						ARM_USART_PARITY_NONE |
-						ARM_USART_STOP_BITS_1 |
-						ARM_USART_FLOW_CONTROL_NONE, 9600);
-				#ifdef USING_PRINTF
-					printf("\nuart reset in \n");	
-				#endif
-				return  0;
-			}
-			return readLen;
-		}
-		else
-		{
-			memset(pRead,0x00,readLen);
-			isRecvTimeout = false;
-			return 0;
-		}
-	}
-	else
-	{
-			return 1;
-	}
-}
-
-
-
-static void __invert_uint8(UINT8* dBuf, UINT8* srcBuf)
-{
-	 int i;
-	 UINT8 tmp[4];
-	 tmp[0] = 0;
-	 for (i = 0;i < 8;i++)
-	 {
-		  if(srcBuf[0] & (1 << i))
-		  {
-		   	tmp[0] |= 1<<(7-i);
-		  }
-	 }
-	 dBuf[0] = tmp[0];
-}
-
-
-static void __invert_uint16(UINT16* dBuf, UINT16* srcBuf)
-{
-	 int i;
-	 UINT16 tmp[4];
-	 tmp[0] = 0;
-	 for (i = 0;i < 16;i++)
-	 {
-		  if(srcBuf[0] & (1 << i))
-		  {
-		   	tmp[0] |= 1 << (15 - i);
-		  }
-	 }
-	 dBuf[0] = tmp[0];
-}
-
-UINT16 MS_BMS_Update_CRC16(UINT8* pSendData,UINT16 len)
-{
-	
-	UINT16 wCRCin = 0xFFFF;
-	UINT16 wCPoly = 0x8005;
-	UINT8 wChar = 0;
-	UINT16 crc_rslt = 0;
-	int i;
-	while (len--)
-	{
-		wChar = *(pSendData++);
-		__invert_uint8(&wChar, &wChar);
-		wCRCin ^= (wChar << 8);
-		for (i = 0;i < 8;i++)
-		{
-			if(wCRCin & 0x8000)
-			{
-				wCRCin = (wCRCin << 1) ^ wCPoly;
-			}
-			else
-			{
-				wCRCin = wCRCin << 1;
-			}
-		}
-	}
-	__invert_uint16(&wCRCin, &wCRCin);
-	crc_rslt = ((wCRCin << 8) & 0xFF00) | ((wCRCin >> 8) & 0x00FF);
-	return (crc_rslt);
-}
-
-UINT8 BmsErrorDecode(UINT32 battWarningState)
-{
-	UINT16 ErrorNumTemp;
-	UINT8 ret;
-	if(battWarningState==0)
-	{
-		return 0;
-	}
-	else
-	{
-		if(osOK==osMutexAcquire(Error_Mutex, 100))
-		{
-			ret = ((battWarningState) & 0x01) == 1 ;
-			if (ret)
-			{
-				ErrorNumTemp = 7;
-				PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
-				//str += "ERROR:存在电芯过放告警故障!!\n";单体电压过低
-			}
-
-			ret = ((battWarningState >> 1) & 0x01) == 1 ;
-			if (ret)
-			{
-				ErrorNumTemp = 10;
-				PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
-				//str += "ERROR:存在总电压过放告警故障!!\n";总电压过低
-			}
-
-			ret = ((battWarningState >> 2) & 0x01) == 1 ;
-			if (ret)
-			{
-				ErrorNumTemp = 8;
-				PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
-				//str += "ERROR:存在电芯过压告警故障!!\n";
-			}
-
-			ret = ((battWarningState >> 3) & 0x01) == 1 ;
-			if (ret)
-			{
-				ErrorNumTemp = 11;
-				PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
-				//str += "ERROR:存在总电压过压告警故障!!\n";
-			}
-
-			ret = ((battWarningState >> 4) & 0x01) == 1 ;
-			if (ret)
-			{
-				ErrorNumTemp = 12;
-				PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
-				//str += "ERROR:存在放电过流告警故障!!\n";
-			}
-
-			ret = ((battWarningState >> 5) & 0x01) == 1 ;
-			if (ret)
-			{
-				ErrorNumTemp = 13;
-				PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
-				//str += "ERROR:存在充电过流告警故障!!\n";
-			}
-
-			ret = ((battWarningState >> 6) & 0x01) == 1 ;
-			if (ret)
-			{
-				ErrorNumTemp = 2;
-				PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
-				//str += "ERROR:存在放电过温告警故障!!\n";
-			}
-
-			ret = ((battWarningState >> 7) & 0x01) == 1 ;
-			if (ret)
-			{
-				ErrorNumTemp = 2;
-				PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
-				//str += "ERROR:存在充电过温告警故障!!\n";
-			}
-
-			ret = ((battWarningState >> 8) & 0x01) == 1 ;
-			if (ret)
-			{
-				//str += "ERROR:存在环境高温告警故障!!\n";
-			}
-
-			ret = ((battWarningState >> 9) & 0x01) == 1 ;
-			if (ret)
-			{
-				//str += "ERROR:存在环境低温告警故障!!\n";
-			}
-
-			ret = ((battWarningState >> 10) & 0x01) == 1 ;
-			if (ret)
-			{
-				ErrorNumTemp = 27;
-				PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
-				//str += "ERROR:存在battSOC低告警故障!!\n";
-			}
-
-			ret = ((battWarningState >> 11) & 0x01) == 1 ;
-			if (ret)
-			{
-				ErrorNumTemp = 3;
-				PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
-				//str += "ERROR:存在MOS高温告警故障!!\n";
-			}
-
-			ret = ((battWarningState >> 16) & 0x01) == 1;
-			if (ret)
-			{
-				ErrorNumTemp = 18;
-				PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
-				//str += "ERROR:存在温度采集失效/传感器故障!!\n";
-			}
-
-			ret = ((battWarningState >> 17) & 0x01) == 1;
-			if (ret)
-			{
-				ErrorNumTemp = 19;
-				PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
-				//str += "ERROR:存在电压采集失效/断线故障!!\n";
-			}
-
-			ret = ((battWarningState >> 18) & 0x01) == 1;
-			if (ret)
-			{
-				ErrorNumTemp = 17;
-				PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
-				//str += "ERROR:存在放电MOS失效故障!!\n";
-			}
-
-			ret = ((battWarningState >> 19) & 0x01) == 1;
-			if (ret)
-			{
-				ErrorNumTemp = 16;
-				PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
-				//str += "ERROR:存在充电MOS失效故障!!\n";
-			}
-
-			ret = ((battWarningState >> 20) & 0x01) == 1;
-			if (ret)
-			{
-				ErrorNumTemp = 22;
-				PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
-				//str += "ERROR:存在电芯不均衡告警!!\n";
-			}
-
-			ret = ((battWarningState >> 22) & 0x01) == 1;
-			if (ret)
-			{
-				ErrorNumTemp = 1;
-				PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
-				//str += "ERROR:存在放电低温告警故障!!\n";
-			}
-
-			ret = ((battWarningState >> 23) & 0x01) == 1 ;
-			if (ret)
-			{
-				ErrorNumTemp = 1;
-				PutErrorNum((UINT16 *)ErrorNum,sizeof(ErrorNum),ErrorNumTemp);
-				//str += "ERROR:存在充电低温告警故障!!\n";
-			}
-		}
-		else
-		{
-			#ifdef USING_PRINTF
-				printf("get Muxtex error\n");
-			#endif
-		}
-		osMutexRelease(Error_Mutex);
-	}
-	return 1;
-}

+ 14 - 36
src/app.c

@@ -1,46 +1,24 @@
-/*******************************
- * 
- * 骑享V2大版本改动
- * 
- * ****************************/
-//基础定义
-#include "bsp.h"
-#include "bsp_custom.h"
-#include "osasys.h"
-#include "ostask.h"
-#include "queue.h"
-#include "ps_event_callback.h"
-#include "cmisim.h"
-#include "cmimm.h"
-#include "cmips.h"
-#include "sockets.h"
-#include "psifevent.h"
-#include "ps_lib_api.h"
-#include "lwip/netdb.h"
-//#include <cis_def.h>
-#include "debug_log.h"
-#include "slpman_ec616.h"
-#include "plat_config.h"
-#include "ec_tcpip_api.h"
-#include "hal_module_adapter.h"
-#include "timers.h"
+/****************************************************************************
+ *
+ * Copy right:   2021-, Copyrigths of RLWL Ltd.
+ * File name:    app.h
+ * Description:  App definition H file
+ * History:      Rev3.0   2021-07-06
+ *
+ ****************************************************************************/
 #include "app.h"
-#include "MainTask.h"
-#include "UartTask.h"
-#include "TcpTask.h"
 void appInit(void *arg)
 {
     #ifdef USING_PRINTF1	
     	printf("%s[%d]\r\n",__FUNCTION__, __LINE__);
     #endif
-    MainTaskInit(arg);
-    AdcTaskInit();
-    UartTaskInit(arg);
-    GpsTaskInit();
-	CANTaskInit(arg);
-    TcpTaskInit(arg);
+    // MainTaskInit(arg);
+    // AdcTaskInit();
+    // UartTaskInit(arg);
+    // GpsTaskInit();
+	// CANTaskInit(arg);
+    // TcpTaskInit(arg);
 }
-//主函数入口
 void main_entry(void) 
 {
     BSP_CommonInit();

+ 3 - 3
src/bsp_custom.c

@@ -13,7 +13,7 @@
 #include "slpman_ec616.h"
 #include "plat_config.h"
 #include "debug_log.h"
-
+#include "Signal.h"
 #ifdef BL_FILE_LOG
 extern uint8_t lockoutState;
 #endif
@@ -113,7 +113,7 @@ void CheckLockOutState(void){
     {
         Lockstatus = false;
 		#ifdef USING_PRINTF
-			printf("LOCK_OUT UP\r\n",__LINE__);
+			printf("LOCK_OUT UP\r\n");
 		#endif	
 		 #ifdef BL_FILE_LOG
 			 lockoutState=0;
@@ -208,7 +208,7 @@ void Pad0_WakeupIntHandler(void)
     }
     else
     {
-        Can_Msg_Enble = true;
+        CanMsgEnble = true;
     }
 #ifdef USING_PRINTF1
 	printf("[%d]PadWakeup0_IRQn\r\n",__LINE__);

+ 0 - 1227
src/cisAsynEntry.c

@@ -1,1227 +0,0 @@
-/****************************************************************************
- *
- * Copy right:   2017-, Copyrigths of EigenComm Ltd.
- * File name:    cisAsynEntry.c
- * Description:  EC616 onenet cis async entry source file
- * History:      Rev1.0   2018-10-12
- *
- ****************************************************************************/
-#include <cis_if_sys.h>
-#include <cis_list.h>
-#include "cisAsynEntry.h"
-#include "osasys.h"
-#include "task.h"
-#if defined CHIP_EC616 || defined CHIP_EC616_Z0
-#include "slpman_ec616.h"
-#include "Flash_ec616_rt.h"
-#elif defined CHIP_EC617
-#include "slpman_ec617.h"
-#include "Flash_ec617_rt.h"
-#endif
-#include "lfs_port.h"
-#include "debug_log.h"
-
-//#define DEBUG_SLEEP_BACKUP
-#define USE_PLAIN_BOOTSTRAP         (0)
-#define ONENET_TASK_STACK_SIZE      (1024*3)
-#define CIS_ENABLE_CONTEXT_RESTORE  (1)
-
-
-#if 0
-//authcode:EC616 psk:EIGENCOMM 183.230.40.39:5684
-static const uint8_t config_hex[] = {
-    0x13, 0x00, 0x53,
-    0xf1, 0x00, 0x03,
-    0xf2, 0x00, 0x45,
-    0x05, 0x00 /*mtu*/, 0x11 /*Link & bind type*/, 0xC0 /*BS DTLS ENABLED*/,
-    0x00, 0x05 /*apn length*/, 0x43, 0x4d, 0x49, 0x4f, 0x54 /*apn: CMIOT*/,
-    0x00, 0x00 /*username length*/, /*username*/
-    0x00, 0x00 /*password length*/, /*password*/
-    0x00, 0x12 /*host length*/, 0x31, 0x38, 0x33, 0x2e, 0x32, 0x33, 0x30, 0x2e,
-    0x34, 0x30, 0x2e, 0x33, 0x39, 0x3a, 0x35, 0x36, 0x38, 0x34 /*host: 183.230.40.39:5684*/,
-    0x00, 0x1D /*userdata length*/, 
-    0x41, 0x75, 0x74, 0x68, 0x43, 0x6f, 0x64, 0x65, 
-    0x3a, 0x45, 0x43, 0x36, 0x31, 0x36, 0x3b, 0x50, 
-    0x53, 0x4b, 0x3a, 0x45, 0x49, 0x47, 0x45, 0x4E, 
-    0x43, 0x4F, 0x4D, 0x4D,0x3b /*userdata: AuthCode:EC616;PSK:EIGENCOMM;*/,
-    0xf3, 0x00, 0x08,0xe4 /*log config*/, 0x00, 0xc8 /*LogBufferSize: 200*/,
-    0x00, 0x00 /*userdata length*//*userdata*/
-    
-};
-//authcode:EC616 psk:EIGENCOMM 183.230.40.40:5683 
-static const uint8_t config_hex[] = {
-    0x13, 0x00, 0x53,
-    0xf1, 0x00, 0x03,
-    0xf2, 0x00, 0x45,
-    0x05, 0x00 /*mtu*/, 0x11 /*Link & bind type*/, 0x00 /*BS DTLS DISABLED*/,
-    0x00, 0x05 /*apn length*/, 0x43, 0x4d, 0x49, 0x4f, 0x54 /*apn: CMIOT*/,
-    0x00, 0x00 /*username length*/, /*username*/
-    0x00, 0x00 /*password length*/, /*password*/
-    0x00, 0x12 /*host length*/,
-    0x31, 0x38, 0x33, 0x2e, 0x32, 0x33, 0x30, 0x2e,
-    0x34, 0x30, 0x2e, 0x34, 0x30, 0x3a, 0x35, 0x36, 0x38, 0x33 /*host: 183.230.40.40:5683*/,
-    0x00, 0x1D /*userdata length*/, 0x41, 0x75, 0x74, 0x68, 0x43, 0x6f, 0x64, 0x65, 
-    0x3a, 0x45, 0x43, 0x36, 0x31, 0x36, 0x3b, 0x50, 
-    0x53, 0x4b, 0x3a, 0x45, 0x49, 0x47, 0x45, 0x4E,
-    0x43, 0x4F, 0x4D, 0x4D,0x3b /*userdata: AuthCode:EC616;PSK:EIGENCOMM;*/,
-    0xf3, 0x00, 0x08,0xe4 /*log config*/, 0x00, 0xc8 /*LogBufferSize: 200*/,
-    0x00, 0x00 /*userdata length*//*userdata*/   
-};
-	
-#endif
-
-//authcode: psk: 183.230.40.39:5683 enable bootstrap
-static const uint8_t config_hex[] = {
-    0x13, 0x00, 0x45,
-    0xf1, 0x00, 0x03,
-    0xf2, 0x00, 0x37,
-    0x05, 0x00 /*mtu*/, 0x11 /*Link & bind type*/, 0x80 /*BS ENABLE DTLS DISABLED*/,
-    0x00, 0x05 /*apn length*/, 0x43, 0x4d, 0x49, 0x4f, 0x54 /*apn: CMIOT*/,
-    0x00, 0x00 /*username length*/, /*username*/
-    0x00, 0x00 /*password length*/, /*password*/
-    0x00, 0x12 /*host length*/,
-    0x31, 0x38, 0x33, 0x2e, 0x32, 0x33, 0x30, 0x2e,
-    0x34, 0x30, 0x2e, 0x33, 0x39, 0x3a, 0x35, 0x36, 0x38, 0x33 /*host: 183.230.40.40:5683*/,
-    0x00, 0x0f /*userdata length*/, 0x41, 0x75, 0x74, 0x68, 0x43, 0x6f, 0x64, 0x65, 
-    0x3a, 0x3b, 0x50, 0x53, 0x4b, 0x3a, 0x3b/*userdata: AuthCode:;PSK:;*/,
-    0xf3, 0x00, 0x08,0xe4 /*log config*/, 0x00, 0xc8 /*LogBufferSize: 200*/,
-    0x00, 0x00 /*userdata length*//*userdata*/   
-};
-	
-
-static StaticTask_t              onenetTask;
-static osThreadId_t              onenetTaskId = NULL;
-static uint8_t                   onenetTaskStack[ONENET_TASK_STACK_SIZE];
-static void*                     gCisContext = NULL;
-static bool                      g_shutdown = false;
-static cis_time_t                g_lifetimeLast = 0;
-static cis_time_t                g_lifetime = 0;
-static cis_time_t                g_notifyLast = 0;
-static bool                      gNotifyOngoing = false;
-static bool                      gNotifyOnceSuccess = false;
-static struct st_callback_info*  g_callbackList = NULL;
-static struct st_observe_info*   g_observeList  = NULL;
-static st_sample_object          g_objectList[SAMPLE_OBJECT_MAX];
-static st_instance_a             g_instList_a[SAMPLE_A_INSTANCE_COUNT];
-static CHAR *defaultLocalPort    = "40962";
-static onenet_context_t          gOnenetContextRunning;
-extern observed_backup_t         g_observed_backup[MAX_OBSERVED_COUNT];
-
-//////////////////////////////////////////////////////////////////////////
-//private funcation;
-static void prvObserveNotify(void* context,cis_uri_t* uri,cis_mid_t mid)
-{
-    uint8_t index;
-    st_sample_object* object = NULL;
-    cis_data_t value;
-    for (index = 0;index < SAMPLE_OBJECT_MAX;index++)
-    {
-        if(g_objectList[index].oid ==  uri->objectId){
-            object = &g_objectList[index];
-        }
-    }
-
-    if(object == NULL){
-        ECOMM_TRACE(UNILOG_PLA_APP, x1_prv_observeNotify_0, P_ERROR, 0, "prv_observeNotify return");
-        return;
-    }
-    ECOMM_TRACE(UNILOG_PLA_APP, x1_prv_observeNotify_1, P_INFO, 0, "prv_observeNotify called");
-
-    if(!CIS_URI_IS_SET_INSTANCE(uri) && !CIS_URI_IS_SET_RESOURCE(uri))
-    {
-        switch(uri->objectId)
-        {
-            case SAMPLE_OID_A:
-            {
-                for(index=0;index<SAMPLE_A_INSTANCE_COUNT;index++)
-                {                   
-                    st_instance_a *inst = &g_instList_a[index];
-                    if(inst != NULL &&  inst->enabled == true)
-                    {
-                        cis_data_t tmpdata[4];
-                        tmpdata[0].type = cis_data_type_integer;
-                        tmpdata[0].value.asInteger = inst->instance.intValue;
-                        uri->instanceId = inst->instId;
-                        uri->resourceId = attributeA_intValue;
-                        cis_uri_update(uri);
-                        cis_notify_ec(context,uri,&tmpdata[0],mid,CIS_NOTIFY_CONTINUE,true, PS_SOCK_RAI_NO_INFO);
-
-                        tmpdata[2].type = cis_data_type_bool;
-                        tmpdata[2].value.asBoolean = inst->instance.boolValue;
-                        uri->resourceId = attributeA_boolValue;
-                        uri->instanceId = inst->instId;
-                        cis_uri_update(uri);
-                        cis_notify_ec(context,uri,&tmpdata[2],mid,CIS_NOTIFY_CONTINUE,true, PS_SOCK_RAI_NO_INFO);
-
-                        tmpdata[3].type = cis_data_type_string;
-                        tmpdata[3].asBuffer.length = strlen(inst->instance.strValue);
-                        tmpdata[3].asBuffer.buffer = (uint8_t*)(inst->instance.strValue);
-                        uri->resourceId = attributeA_stringValue;
-                        uri->instanceId = inst->instId;
-                        cis_uri_update(uri);
-                        cis_notify_ec(context,uri,&tmpdata[3],mid,CIS_NOTIFY_CONTENT,true, PS_SOCK_RAI_NO_INFO);
-                    }
-                }
-            }
-            break;
-        }
-    }else if(CIS_URI_IS_SET_INSTANCE(uri))
-    {
-        switch(object->oid)
-        {
-            case SAMPLE_OID_A:
-            {
-                if(uri->instanceId > SAMPLE_A_INSTANCE_COUNT){
-                    return;
-                }
-                st_instance_a *inst = &g_instList_a[uri->instanceId];
-                if(inst == NULL || inst->enabled == false){
-                    return;
-                }
-
-                if(CIS_URI_IS_SET_RESOURCE(uri)){
-                    if(uri->resourceId == attributeA_intValue)
-                    {
-                        value.type = cis_data_type_integer;
-                        value.value.asInteger = inst->instance.intValue;
-                    }
-                    else if(uri->resourceId == attributeA_boolValue)
-                    {
-                        value.type = cis_data_type_bool;
-                        value.value.asBoolean = inst->instance.boolValue;
-                    }
-                    else if(uri->resourceId == attributeA_stringValue)
-                    {
-                        value.type = cis_data_type_string;
-                        value.asBuffer.length = strlen(inst->instance.strValue);
-                        value.asBuffer.buffer = (uint8_t*)(inst->instance.strValue);
-                    }else{
-                        return;
-                    }
-
-                    cis_notify_ec(context,uri,&value,mid,CIS_NOTIFY_CONTENT,true, PS_SOCK_RAI_NO_INFO);
-
-                }else{
-                    cis_data_t tmpdata[4];
-
-                    tmpdata[0].type = cis_data_type_integer;
-                    tmpdata[0].value.asInteger = inst->instance.intValue;
-                    uri->resourceId = attributeA_intValue;
-                    cis_uri_update(uri);
-                    cis_notify_ec(context,uri,&tmpdata[0],mid,CIS_NOTIFY_CONTINUE,true, PS_SOCK_RAI_NO_INFO);
-
-
-                    tmpdata[2].type = cis_data_type_bool;
-                    tmpdata[2].value.asBoolean = inst->instance.boolValue;
-                    uri->resourceId = attributeA_boolValue;
-                    cis_uri_update(uri);
-                    cis_notify_ec(context,uri,&tmpdata[2],mid,CIS_NOTIFY_CONTINUE,true, PS_SOCK_RAI_NO_INFO);
-
-                    tmpdata[3].type = cis_data_type_string;
-                    tmpdata[3].asBuffer.length = strlen(inst->instance.strValue);
-                    tmpdata[3].asBuffer.buffer = (uint8_t*)(inst->instance.strValue);
-                    uri->resourceId = attributeA_stringValue;
-                    cis_uri_update(uri);
-                    cis_notify_ec(context,uri,&tmpdata[3],mid,CIS_NOTIFY_CONTENT,true, PS_SOCK_RAI_NO_INFO);
-                }
-            }
-            break;
-        }
-    }
-}
-
-static void prvReadResponse(void* context,cis_uri_t* uri,cis_mid_t mid)
-{
-    uint8_t index;
-    st_sample_object* object = NULL;
-    cis_data_t value;
-    for (index = 0;index < SAMPLE_OBJECT_MAX;index++)
-    {
-        if(g_objectList[index].oid ==  uri->objectId){
-            object = &g_objectList[index];
-        }
-    }
-
-    if(object == NULL){
-        return;
-    }
-
-    if(!CIS_URI_IS_SET_INSTANCE(uri) && !CIS_URI_IS_SET_RESOURCE(uri)) // one object
-    {
-        switch(uri->objectId)
-        {
-            case SAMPLE_OID_A:
-            {
-                for(index=0;index<SAMPLE_A_INSTANCE_COUNT;index++)
-                {                   
-                    st_instance_a *inst = &g_instList_a[index];
-                    if(inst != NULL &&  inst->enabled == true)
-                    {
-                        cis_data_t tmpdata[4];
-                        tmpdata[0].type = cis_data_type_integer;
-                        tmpdata[0].value.asInteger = inst->instance.intValue;
-                        uri->instanceId = inst->instId;
-                        uri->resourceId = attributeA_intValue;
-                        cis_uri_update(uri);
-                        cis_response(context,uri,&tmpdata[0],mid,CIS_RESPONSE_CONTINUE, PS_SOCK_RAI_NO_INFO);
-
-
-                        tmpdata[2].type = cis_data_type_bool;
-                        tmpdata[2].value.asBoolean = inst->instance.boolValue;
-                        uri->resourceId = attributeA_boolValue;
-                        uri->instanceId = inst->instId;
-                        cis_uri_update(uri);
-                        cis_response(context,uri,&tmpdata[2],mid,CIS_RESPONSE_CONTINUE, PS_SOCK_RAI_NO_INFO);
-
-                        tmpdata[3].type = cis_data_type_string;
-                        tmpdata[3].asBuffer.length = strlen(inst->instance.strValue);
-                        tmpdata[3].asBuffer.buffer = (uint8_t*)strdup(inst->instance.strValue);
-                        uri->resourceId = attributeA_stringValue;
-                        uri->instanceId = inst->instId;
-                        cis_uri_update(uri);
-                        cis_response(context,uri,&tmpdata[3],mid,CIS_RESPONSE_CONTINUE, PS_SOCK_RAI_NO_INFO);
-                    }
-                }
-            }
-            break;
-        }
-        cis_response(context,NULL,NULL,mid,CIS_RESPONSE_READ, PS_SOCK_RAI_NO_INFO);
-
-    }else
-    {
-        switch(object->oid)
-        {
-            case SAMPLE_OID_A:
-            {
-                if(uri->instanceId > SAMPLE_A_INSTANCE_COUNT){
-                    return;
-                }
-                st_instance_a *inst = &g_instList_a[uri->instanceId];
-                if(inst == NULL || inst->enabled == false){
-                    return;
-                }
-
-                if(CIS_URI_IS_SET_RESOURCE(uri)){
-                    if(uri->resourceId == attributeA_intValue)
-                    {
-                        value.type = cis_data_type_integer;
-                        value.value.asInteger = inst->instance.intValue;
-                    }
-                    else if(uri->resourceId == attributeA_boolValue)
-                    {
-                        value.type = cis_data_type_bool;
-                        value.value.asBoolean = inst->instance.boolValue;
-                    }
-                    else if(uri->resourceId == attributeA_stringValue)
-                    {
-                        value.type = cis_data_type_string;
-                        value.asBuffer.length = strlen(inst->instance.strValue);
-                        value.asBuffer.buffer = (uint8_t*)strdup(inst->instance.strValue);
-                    }else{
-                        return;
-                    }
-
-                    cis_response(context,uri,&value,mid,CIS_RESPONSE_READ, PS_SOCK_RAI_NO_INFO);
-                }else{
-                    cis_data_t tmpdata[4];
-
-                    tmpdata[0].type = cis_data_type_integer;
-                    tmpdata[0].value.asInteger = inst->instance.intValue;
-                    uri->resourceId = attributeA_intValue;
-                    cis_uri_update(uri);
-                    cis_response(context,uri,&tmpdata[0],mid,CIS_RESPONSE_CONTINUE, PS_SOCK_RAI_NO_INFO);
-
-                    tmpdata[2].type = cis_data_type_bool;
-                    tmpdata[2].value.asBoolean = inst->instance.boolValue;
-                    uri->resourceId = attributeA_boolValue;
-                    cis_uri_update(uri);
-                    cis_response(context,uri,&tmpdata[2],mid,CIS_RESPONSE_CONTINUE, PS_SOCK_RAI_NO_INFO);
-
-                    tmpdata[3].type = cis_data_type_string;
-                    tmpdata[3].asBuffer.length = strlen(inst->instance.strValue);
-                    tmpdata[3].asBuffer.buffer = (uint8_t*)strdup(inst->instance.strValue);
-                    uri->resourceId = attributeA_stringValue;
-                    cis_uri_update(uri);
-                    cis_response(context,uri,&tmpdata[3],mid,CIS_RESPONSE_READ, PS_SOCK_RAI_NO_INFO);
-                }
-            }
-            break;
-        }
-    }
-}
-
-
-static void prvDiscoverResponse(void* context,cis_uri_t* uri,cis_mid_t mid)
-{
-    uint8_t index;
-    st_sample_object* object = NULL;
-
-    for (index = 0;index < SAMPLE_OBJECT_MAX;index++)
-    {
-        if(g_objectList[index].oid ==  uri->objectId){
-            object = &g_objectList[index];
-        }
-    }
-
-    if(object == NULL){
-        return;
-    }
-
-
-    switch(uri->objectId)
-    {
-        case SAMPLE_OID_A:
-        {
-            uri->objectId = SAMPLE_OID_A;
-            uri->instanceId = 0;
-            uri->resourceId = attributeA_intValue;
-            cis_uri_update(uri);
-            cis_response(context,uri,NULL,mid,CIS_RESPONSE_CONTINUE, PS_SOCK_RAI_NO_INFO);
-
-            uri->objectId = SAMPLE_OID_A;
-            uri->instanceId = 0;
-            uri->resourceId = attributeA_boolValue;
-            cis_uri_update(uri);
-            cis_response(context,uri,NULL,mid,CIS_RESPONSE_CONTINUE, PS_SOCK_RAI_NO_INFO);
-
-            uri->objectId = SAMPLE_OID_A;
-            uri->instanceId = 0;
-            uri->resourceId = attributeA_stringValue;
-            cis_uri_update(uri);
-            cis_response(context,uri,NULL,mid,CIS_RESPONSE_CONTINUE, PS_SOCK_RAI_NO_INFO);
-
-        }
-        break;
-    }
-    cis_response(context,NULL,NULL,mid,CIS_RESPONSE_DISCOVER, PS_SOCK_RAI_NO_INFO);
-}
-
-
-static void prvWriteResponse(void* context,cis_uri_t* uri,const cis_data_t* value,cis_attrcount_t count,cis_mid_t mid)
-{
-
-    uint8_t index;
-    st_sample_object* object = NULL;
-    
-
-    if(!CIS_URI_IS_SET_INSTANCE(uri))
-    {
-        return;
-    }
-
-    for (index = 0;index < SAMPLE_OBJECT_MAX;index++)
-    {
-        if(g_objectList[index].oid ==  uri->objectId){
-            object = &g_objectList[index];
-        }
-    }
-
-    if(object == NULL){
-        return;
-    }
-
-    switch(object->oid)
-    {
-        case SAMPLE_OID_A:
-        {
-            if(uri->instanceId > SAMPLE_A_INSTANCE_COUNT){
-                return;
-            }
-            st_instance_a *inst = &g_instList_a[uri->instanceId];
-            if(inst == NULL || inst->enabled == false){
-                return;
-            }
-
-            for (int i=0;i<count;i++)
-            {
-                ECOMM_TRACE(UNILOG_PLA_APP, prvWriteResponse_1, P_INFO, 3, "prvWriteResponse:write %d/%d/%d", uri->objectId,uri->instanceId,value[i].id);
-                switch(value[i].id)
-                {
-                case attributeA_intValue:
-                    {
-                        if(value[i].type == cis_data_type_string){
-                            inst->instance.intValue = atoi((const char*)value[i].asBuffer.buffer);
-                        }else{
-                            inst->instance.intValue = value[i].value.asInteger;
-                        }
-                    }
-                    break;
-                case attributeA_boolValue:
-                    {
-                        if(value[i].type == cis_data_type_string){
-                            inst->instance.boolValue = atoi((const char*)value[i].asBuffer.buffer);
-                        }else{
-                            inst->instance.boolValue = value[i].value.asBoolean;
-                        }
-                    }
-                    break;
-                case  attributeA_stringValue:
-                    {
-                        memset(inst->instance.strValue,0,sizeof(inst->instance.strValue));
-                        strncpy(inst->instance.strValue,(char*)value[i].asBuffer.buffer,value[i].asBuffer.length);
-                    }
-                    break;
-                }
-            }
-        }
-        break;
-    }
-
-    cis_response(context,NULL,NULL,mid,CIS_RESPONSE_WRITE, PS_SOCK_RAI_NO_INFO);
-}
-
-
-static void prvExecResponse(void* context,cis_uri_t* uri,const uint8_t* value,uint32_t length,cis_mid_t mid)
-{
-
-    uint8_t index;
-    st_sample_object* object = NULL;
-
-    for (index = 0;index < SAMPLE_OBJECT_MAX;index++)
-    {
-        if(g_objectList[index].oid ==  uri->objectId){
-            object = &g_objectList[index];
-        }
-    }
-
-    if(object == NULL){
-        return;
-    }
-
-
-    switch(object->oid)
-    {
-    case SAMPLE_OID_A:
-        {
-            if(uri->instanceId > SAMPLE_A_INSTANCE_COUNT){
-                return;
-            }
-            st_instance_a *inst = &g_instList_a[uri->instanceId];
-            if(inst == NULL || inst->enabled == false){
-                return;
-            }
-
-            if(uri->resourceId == actionA_1)
-            {
-                /*
-                *\call action;
-                */
-                ECOMM_TRACE(UNILOG_PLA_APP, prvExecResponse_1, P_INFO, 0, "exec actionA_action");
-                cis_response(context,NULL,NULL,mid,CIS_RESPONSE_EXECUTE, PS_SOCK_RAI_NO_INFO);
-            }else{
-                return;
-            }
-        }
-        break;
-    }
-};
-
-
-static void prvParamsResponse (void* context, cis_uri_t* uri, cis_observe_attr_t parameters, cis_mid_t mid)
-{
-    uint8_t index;
-    st_sample_object* object = NULL;
-
-    if(CIS_URI_IS_SET_RESOURCE(uri)){
-        ECOMM_TRACE(UNILOG_PLA_APP, prvParamsResponse_1, P_INFO, 3, "prvParamsResponse (%d/%d/%d)", uri->objectId,uri->instanceId,uri->resourceId);
-    }
-
-    if(!CIS_URI_IS_SET_INSTANCE(uri))
-    {
-        return;
-    }
-
-    for (index = 0;index < SAMPLE_OBJECT_MAX;index++)
-    {
-        if(g_objectList[index].oid ==  uri->objectId){
-            object = &g_objectList[index];
-        }
-    }
-
-    if(object == NULL){
-        return;
-    }
-
-    /*set parameter to observe resource*/
-    ECOMM_TRACE(UNILOG_PLA_APP, prvParamsResponse_2, P_INFO, 2, "prvParamsResponse set:%x,clr:%x", parameters.toSet, parameters.toClear);
-    ECOMM_TRACE(UNILOG_PLA_APP, prvParamsResponse_3, P_INFO, 5, "prvParamsResponse min:%d,max:%d,gt:%f,lt:%f,st:%f", parameters.minPeriod,parameters.maxPeriod,parameters.greaterThan,parameters.lessThan,parameters.step);
-
-    cis_response(context,NULL,NULL,mid,CIS_RESPONSE_OBSERVE_PARAMS, PS_SOCK_RAI_NO_INFO);
-
-}
-
-static cis_data_t* prvDataDup(const cis_data_t* value,cis_attrcount_t attrcount)
-{
-    cis_attrcount_t index;
-    cis_data_t* newData;
-    newData =(cis_data_t*)cissys_malloc(attrcount * sizeof(cis_data_t));
-    if(newData == NULL)
-    {
-        return NULL;
-    }
-    for (index =0;index < attrcount;index++)
-    {
-        newData[index].id = value[index].id;
-        newData[index].type = value[index].type;
-        newData[index].asBuffer.length = value[index].asBuffer.length;
-        newData[index].asBuffer.buffer = (uint8_t*)cissys_malloc(value[index].asBuffer.length);
-        memcpy(newData[index].asBuffer.buffer,value[index].asBuffer.buffer,value[index].asBuffer.length);
-        memcpy(&newData[index].value.asInteger,&value[index].value.asInteger,sizeof(newData[index].value));
-    }
-    return newData;
-}
-
-static void prvUpdateObserveContext()
-{
-    struct st_observe_info* node = g_observeList;
-    uint8_t i = 0;
-    while(node != NULL)
-    {
-        ECOMM_TRACE(UNILOG_PLA_APP, x1_prvUpdateObserveContext_0, P_INFO, 1, "prvUpdateObserveContext mid=%d", node->mid);
-        node = node->next;
-        i++;
-    }
-    gOnenetContextRunning.observeObjNum = i;
-    
- #ifdef DEBUG_SLEEP_BACKUP
-    printf("prvUpdateObserveContext:");
-    for(int j= 0; j < sizeof(observed_backup_t); j ++)
-        printf("%d ", ((UINT8*)&(g_observed_backup[0]))[j]);
-    printf("\n");
- #endif
- 
-    memcpy((uint8_t *)&(gOnenetContextRunning.gObservedBackup[0]), &(g_observed_backup[0]), MAX_OBSERVED_COUNT*sizeof(observed_backup_t));
-
-    if(BSP_QSPI_Erase_Safe(APP_BACKUP_NONXIP_ADDR, APP_BACKUP_SIZE) != QSPI_OK) //erase
-    {
-        ECOMM_TRACE(UNILOG_PLA_APP, x1_prvUpdateObserveContext_1, P_ERROR, 0, "erase flash error!!!");
-    }
-    ECOMM_TRACE(UNILOG_PLA_APP, x1_prvUpdateObserveContext_2, P_INFO, 0, "prvUpdateObserveContext BSP_QSPI_Write_Safe");
-    if(BSP_QSPI_Write_Safe((uint8_t *)&gOnenetContextRunning, APP_BACKUP_NONXIP_ADDR, sizeof(onenet_context_t))!=QSPI_OK) //programe
-    {
-        ECOMM_TRACE(UNILOG_PLA_APP, x1_prvUpdateObserveContext_3, P_ERROR, 0, "write flash error!!!");
-    }
-}
-void normal_prvMakeUserdata()
-{
-    int i = 0;
-    cis_instcount_t instIndex;
-    cis_instcount_t instCount;
-    for (i= 0;i < SAMPLE_OBJECT_MAX; i++)
-    {
-        st_sample_object* obj = &g_objectList[i];
-        switch(i){
-            case 0:
-            {
-                obj->oid = SAMPLE_OID_A;
-                obj->instBitmap = SAMPLE_A_INSTANCE_BITMAP;
-                instCount = SAMPLE_A_INSTANCE_COUNT;
-                for (instIndex = 0;instIndex < instCount;instIndex++)
-                {
-                    if(obj->instBitmap[instIndex] != '1'){
-                        g_instList_a[instIndex].instId = instIndex;
-                        g_instList_a[instIndex].enabled = false;
-                    }
-                    else
-                    {
-                        g_instList_a[instIndex].instId = instIndex;
-                        g_instList_a[instIndex].enabled = true;
-
-                        g_instList_a[instIndex].instance.boolValue = true;
-                        g_instList_a[instIndex].instance.intValue = cissys_rand() % 100;
-                        strcpy(g_instList_a[instIndex].instance.strValue,"temp test");
-                    }
-                }
-                obj->attrCount = sizeof(const_AttrIds_a) / sizeof(cis_rid_t);
-                obj->attrListPtr = const_AttrIds_a;
-
-                obj->actCount = 0;
-                obj->actListPtr = NULL;
-            }
-            break;
-
-        }
-    }
-}
-
-//////////////////////////////////////////////////////////////////////////
-cis_coapret_t cisAsynOnRead(void* context,cis_uri_t* uri,cis_mid_t mid)
-{
-    struct st_callback_info* newNode = (struct st_callback_info*)cissys_malloc(sizeof(struct st_callback_info));
-    newNode->next = NULL;
-    newNode->flag = (et_callback_type_t)CIS_CALLBACK_READ;
-    newNode->mid = mid;
-    newNode->uri = *uri;
-    g_callbackList = (struct st_callback_info*)CIS_LIST_ADD(g_callbackList,newNode);
-
-    ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnRead_1, P_SIG, 3, "cisAsynOnRead (%d/%d/%d)", uri->objectId,uri->instanceId,uri->resourceId);
-    return CIS_CALLBACK_CONFORM;
-}
-
-cis_coapret_t cisAsynOnDiscover(void* context,cis_uri_t* uri,cis_mid_t mid)
-{
-    struct st_callback_info* newNode = (struct st_callback_info*)cissys_malloc(sizeof(struct st_callback_info));
-    newNode->next = NULL;
-    newNode->flag = (et_callback_type_t)CIS_CALLBACK_DISCOVER;
-    newNode->mid = mid;
-    newNode->uri = *uri;
-    g_callbackList = (struct st_callback_info*)CIS_LIST_ADD(g_callbackList,newNode);
-
-    ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnDiscover_1, P_SIG, 3, "cisAsynOnDiscover (%d/%d/%d)", uri->objectId,uri->instanceId,uri->resourceId);
-    return CIS_CALLBACK_CONFORM;
-}
-
-cis_coapret_t cisAsynOnWrite(void* context,cis_uri_t* uri,const cis_data_t* value,cis_attrcount_t attrcount,cis_mid_t mid)
-{
-
-    if(CIS_URI_IS_SET_RESOURCE(uri)){      
-        ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnWrite_1, P_SIG, 3, "cisAsynOnWrite (%d/%d/%d)", uri->objectId,uri->instanceId,uri->resourceId);
-    }
-    else{     
-        ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnWrite_2, P_SIG, 2, "cisAsynOnWrite (%d/%d)", uri->objectId,uri->instanceId);
-    }
-
-    struct st_callback_info* newNode = (struct st_callback_info*)cissys_malloc(sizeof(struct st_callback_info));
-    newNode->next = NULL;
-    newNode->flag = (et_callback_type_t)CIS_CALLBACK_WRITE;
-    newNode->mid = mid;
-    newNode->uri = *uri;
-    newNode->param.asWrite.count = attrcount;
-    newNode->param.asWrite.value = prvDataDup(value,attrcount);
-    g_callbackList = (struct st_callback_info*)CIS_LIST_ADD(g_callbackList,newNode);
-
-
-    return CIS_CALLBACK_CONFORM;
-   
-}
-
-
-cis_coapret_t cisAsynOnExec(void* context,cis_uri_t* uri,const uint8_t* value,uint32_t length,cis_mid_t mid)
-{
-    if(CIS_URI_IS_SET_RESOURCE(uri))
-    {
-        ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnExec_1, P_SIG, 3, "cisAsynOnExec (%d/%d/%d)", uri->objectId,uri->instanceId,uri->resourceId);
-    }
-    else{
-        return CIS_CALLBACK_METHOD_NOT_ALLOWED;
-    }
-
-    if(!CIS_URI_IS_SET_INSTANCE(uri))
-    {
-        return CIS_CALLBACK_BAD_REQUEST;
-    }
-
-    struct st_callback_info* newNode = (struct st_callback_info*)cissys_malloc(sizeof(struct st_callback_info));
-    newNode->next = NULL;
-    newNode->flag = (et_callback_type_t)CIS_CALLBACK_EXECUTE;
-    newNode->mid = mid;
-    newNode->uri = *uri;
-    newNode->param.asExec.buffer = (uint8_t*)cissys_malloc(length);
-    newNode->param.asExec.length = length;
-    memcpy(newNode->param.asExec.buffer,value,length);
-    g_callbackList = (struct st_callback_info*)CIS_LIST_ADD(g_callbackList,newNode);
-
-
-    return CIS_CALLBACK_CONFORM;
-}
-
-
-cis_coapret_t cisAsynOnObserve(void* context,cis_uri_t* uri,bool flag,cis_mid_t mid)
-{
-
-    ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnObserve_1, P_SIG, 3, "cisAsynOnObserve mid:%d uri:(%d/%d/%d)",mid,uri->objectId,uri->instanceId,uri->resourceId);
-    if(!CIS_URI_IS_SET_INSTANCE(uri))
-    {
-        return CIS_CALLBACK_BAD_REQUEST;
-    }
-    
-    struct st_callback_info* newNode = (struct st_callback_info*)cissys_malloc(sizeof(struct st_callback_info));
-    newNode->next = NULL;
-    newNode->flag = (et_callback_type_t)CIS_CALLBACK_OBSERVE;
-    newNode->mid = mid;
-    newNode->uri = *uri;
-    newNode->param.asObserve.flag = flag;
-    
-    g_callbackList = (struct st_callback_info*)CIS_LIST_ADD(g_callbackList,newNode);
-
-    return CIS_CALLBACK_CONFORM;
-}
-
-
-cis_coapret_t cisAsynOnParams(void* context,cis_uri_t* uri,cis_observe_attr_t parameters,cis_mid_t mid)
-{
-    if(CIS_URI_IS_SET_RESOURCE(uri)){
-        ECOMM_TRACE(UNILOG_PLA_APP, cisAsynOnParams_0, P_SIG, 3, "cisAsynOnParams=(%d/%d/%d)", uri->objectId,uri->instanceId,uri->resourceId); 
-    }
-    
-    if(!CIS_URI_IS_SET_INSTANCE(uri))
-    {
-        return CIS_CALLBACK_BAD_REQUEST;
-    }
-
-    struct st_callback_info* newNode = (struct st_callback_info*)cissys_malloc(sizeof(struct st_callback_info));
-    newNode->next = NULL;
-    newNode->flag = (et_callback_type_t)CIS_CALLBACK_SETPARAMS;
-    newNode->mid = mid;
-    newNode->uri = *uri;
-    newNode->param.asObserveParam.params = parameters;
-    g_callbackList = (struct st_callback_info*)CIS_LIST_ADD(g_callbackList,newNode);
-
-    return CIS_CALLBACK_CONFORM;
-}
-
-
-
-void cisAsynOnEvent(void* context,cis_evt_t eid,void* param)
-{
-    ECOMM_TRACE(UNILOG_PLA_APP, x1_cisAsynOnEvent_0, P_SIG, 1, "cisAsynOnEvent=%d", eid); 
-    switch(eid)
-    {
-        case CIS_EVENT_RESPONSE_FAILED:
-        case CIS_EVENT_NOTIFY_FAILED:       
-            gNotifyOngoing = false;
-            ECOMM_TRACE(UNILOG_PLA_APP, x1_cisAsynOnEvent_2, P_INFO, 1, "cisAsynOnEvent response failed mid:%d", (int32_t)param); 
-            break;
-        case CIS_EVENT_NOTIFY_SUCCESS:
-            gNotifyOngoing = false;
-            cisAsynSetNotifyOnceStatus(true);
-            break;
-        case CIS_EVENT_UPDATE_NEED:
-            ECOMM_TRACE(UNILOG_PLA_APP, x1_cisAsynOnEvent_3, P_INFO, 1, "cisAsynOnEvent need to update,reserve time:%ds", (int32_t)param); 
-            cis_update_reg(gCisContext,LIFETIME_INVALID,false, PS_SOCK_RAI_NO_INFO);
-            break;
-        case CIS_EVENT_REG_SUCCESS:
-            {
-                ECOMM_TRACE(UNILOG_PLA_APP, x1_cisAsynOnEvent_4, P_INFO, 1, "cisAsynOnEvent=CIS_EVENT_REG_SUCCESS, will clean g_observeList"); 
-                struct st_observe_info* delnode;
-                while(g_observeList != NULL){
-                    g_observeList =(struct st_observe_info *)CIS_LIST_RM((cis_list_t *)g_observeList,g_observeList->mid,(cis_list_t **)&delnode);
-                    cissys_free(delnode);
-                }
-            }
-            break;
-         case CIS_EVENT_OBSERVE_ADD:
-         case CIS_EVENT_OBSERVE_CANCEL:
-            prvUpdateObserveContext();
-            break;
-        default:
-            break;
-    }
-    
-}
-
-bool cisAsynGetShutdown(void)
-{
-    return g_shutdown;
-}
-void cisAsynSetShutdown(bool shutdown)
-{
-    g_shutdown = shutdown;
-}
-
-bool cisAsynGetNotifyOnceStatus(void)
-{
-    return gNotifyOnceSuccess;
-}
-
-void cisAsynSetNotifyOnceStatus(bool success)
-{
-    gNotifyOnceSuccess = success;
-}
-
-static void cisAsyncProcessTask(void* lpParam)
-{
-
-    while(1)
-    {
-        struct st_callback_info* node;
-        if(g_callbackList == NULL || g_shutdown == TRUE)
-        {
-            cissys_sleepms(1000);
-            continue;
-        }
-        node = g_callbackList;
-        g_callbackList = g_callbackList->next;
-        
-        switch (node->flag)
-        {
-            case 0:
-                break;
-            case CIS_CALLBACK_READ:
-                {               
-                    ECOMM_TRACE(UNILOG_PLA_APP, cisProcessThread_0, P_SIG, 0, "cisProcessThread CIS_CALLBACK_READ");
-                    cis_uri_t uriLocal;
-                    uriLocal = node->uri;
-                    prvReadResponse(gCisContext,&uriLocal,node->mid);
-                }
-                break;
-            case CIS_CALLBACK_DISCOVER:
-                {                    
-                    ECOMM_TRACE(UNILOG_PLA_APP, cisProcessThread_1, P_SIG, 0, "cisProcessThread CIS_CALLBACK_DISCOVER");
-                    cis_uri_t uriLocal;
-                    uriLocal = node->uri;
-                    prvDiscoverResponse(gCisContext,&uriLocal,node->mid);
-                }
-                break;
-            case CIS_CALLBACK_WRITE:
-                {                   
-                    ECOMM_TRACE(UNILOG_PLA_APP, cisProcessThread_2, P_SIG, 0, "cisProcessThread CIS_CALLBACK_WRITE");
-                    prvWriteResponse(gCisContext,&node->uri,node->param.asWrite.value,node->param.asWrite.count,node->mid);
-                    cis_data_t* data = node->param.asWrite.value;
-                    cis_attrcount_t count = node->param.asWrite.count;
-
-                    for (int i=0;i<count;i++)
-                    {
-                        if(data[i].type == cis_data_type_string || data[i].type == cis_data_type_opaque)
-                        {
-                            if(data[i].asBuffer.buffer != NULL)
-                                cissys_free(data[i].asBuffer.buffer);
-                        }
-                    }
-                    cissys_free(data);
-                }
-                break;
-            case CIS_CALLBACK_EXECUTE:
-                {
-                    ECOMM_TRACE(UNILOG_PLA_APP, cisProcessThread_3, P_SIG, 0, "cisProcessThread CIS_CALLBACK_EXECUTE");
-                    prvExecResponse(gCisContext,&node->uri,node->param.asExec.buffer,node->param.asExec.length,node->mid);
-                    cissys_free(node->param.asExec.buffer);
-                }
-                break;
-            case CIS_CALLBACK_SETPARAMS:
-                {
-                    ECOMM_TRACE(UNILOG_PLA_APP, cisProcessThread_4, P_SIG, 0, "cisProcessThread CIS_CALLBACK_SETPARAMS");
-                    //set parameters and notify
-                    prvParamsResponse(gCisContext,&node->uri,node->param.asObserveParam.params,node->mid);
-                }
-                break;
-            case CIS_CALLBACK_OBSERVE:
-                {
-                    
-                    LOGD("observe callback mid=%d flag=%d\r\n", node->mid, node->param.asObserve.flag);
-                    if(node->param.asObserve.flag)
-                    {
-                        uint16_t count = 0;
-                        struct st_observe_info* observe_new = (struct st_observe_info*)cissys_malloc(sizeof(struct st_observe_info));
-                        observe_new->mid = node->mid;
-                        observe_new->uri = node->uri;
-                        observe_new->next = NULL;
-                        // mid change every time once register
-                        g_observeList = (struct st_observe_info*)cis_list_add((cis_list_t*)g_observeList,(cis_list_t*)observe_new);
-                        
-                        cis_response(gCisContext,NULL,NULL,node->mid,CIS_RESPONSE_OBSERVE, PS_SOCK_RAI_NO_INFO);
-
-                        ECOMM_TRACE(UNILOG_PLA_APP, cisProcessThread_5, P_INFO, 4, "cisProcessThread CIS_CALLBACK_OBSERVE set(%d): %d/%d/%d",
-                                        count,
-                                        observe_new->uri.objectId,
-                                        CIS_URI_IS_SET_INSTANCE(&observe_new->uri)?observe_new->uri.instanceId:-1,
-                                        CIS_URI_IS_SET_RESOURCE(&observe_new->uri)?observe_new->uri.resourceId:-1);
-
-                    }
-                    else
-                    {
-                        struct st_observe_info* delnode = g_observeList;
-
-                        while (delnode) {
-                            if (node->uri.flag == delnode->uri.flag && node->uri.objectId == delnode->uri.objectId) {
-                                if (node->uri.instanceId == delnode->uri.instanceId) {
-                                    if (node->uri.resourceId == delnode->uri.resourceId) {
-                                        break;
-                                    }
-                                }
-                            }
-                            delnode = delnode->next;
-                        }
-                        if (delnode != NULL) {
-                            g_observeList = (struct st_observe_info *)cis_list_remove((cis_list_t *)g_observeList, delnode->mid, (cis_list_t **)&delnode);
-
-                            ECOMM_TRACE(UNILOG_PLA_APP, cisProcessThread_6, P_INFO, 3, "cis_on_observe cancel: %d/%d/%d\n",
-                                        delnode->uri.objectId,
-                                        CIS_URI_IS_SET_INSTANCE(&delnode->uri) ? delnode->uri.instanceId : -1,
-                                        CIS_URI_IS_SET_RESOURCE(&delnode->uri) ? delnode->uri.resourceId : -1);
-
-                            cis_free(delnode);
-                            cis_response(gCisContext, NULL, NULL, node->mid, CIS_RESPONSE_OBSERVE, PS_SOCK_RAI_NO_INFO);
-                        }
-                        else {
-                            return;
-                        }
-                    }                    
-                }
-                break;
-            default:
-                break;
-        }
-
-        cissys_free(node);
-    }
-}
-
-
-void cisAsyncUpdatePumpState(et_client_state_t state)
-{
-    if(gOnenetContextRunning.pumpState != state)
-        gOnenetContextRunning.pumpState = state;
-}
-
-void cisAsyncAddObject()
-{
-    int index = 0;
-    for (index= 0;index < SAMPLE_OBJECT_MAX ; index++)
-    {
-        cis_inst_bitmap_t bitmap;
-        cis_res_count_t  rescount;
-        cis_instcount_t instCount,instBytes;
-        const char* instAsciiPtr;
-        uint8_t * instPtr;
-        cis_oid_t oid;
-        int16_t i;
-        st_sample_object* obj = &g_objectList[index];
-
-        oid = obj->oid;
-        instCount = strlen(obj->instBitmap);
-        instBytes = (instCount - 1) / 8 + 1;
-        instAsciiPtr = obj->instBitmap;
-
-        instPtr = (uint8_t*)cissys_malloc(instBytes);
-        memset(instPtr,0,instBytes);
-        
-        for (i = 0;i < instCount;i++)
-        {
-            cis_instcount_t instBytePos = i / 8;
-            cis_instcount_t instByteOffset = 7 - (i % 8);
-            if(instAsciiPtr[i] == '1'){
-                instPtr[instBytePos] += 0x01 << instByteOffset;
-            }
-        }
-
-        bitmap.instanceCount = instCount;
-        bitmap.instanceBitmap = instPtr;
-        bitmap.instanceBytes = instBytes;
-
-        rescount.attrCount = obj->attrCount;
-        rescount.actCount = obj->actCount;
-
-        cis_addobject(gCisContext,oid,&bitmap,&rescount);
-        cissys_free(instPtr);
-    }
-}
-
-void cisAsyncRegister()
-{
-    g_lifetime = 36000;
-    cis_callback_t callback;
-    callback.onRead = cisAsynOnRead;
-    callback.onWrite = cisAsynOnWrite;
-    callback.onExec = cisAsynOnExec;
-    callback.onObserve = cisAsynOnObserve;
-    callback.onSetParams = cisAsynOnParams;
-    callback.onEvent = cisAsynOnEvent;
-    callback.onDiscover = cisAsynOnDiscover;
-    cis_register(gCisContext,g_lifetime,&callback);
-}
-
-bool cisAsyncCheckNotificationReady()
-{
-    if (gCisContext == NULL)
-        return FALSE;
-    else
-        return ((((st_context_t*)gCisContext)->stateStep == PUMP_STATE_READY) &&
-                (((st_context_t*)gCisContext)->observedList != NULL));
-}
-void cisAsyncBackup(void *pdata, slpManLpState state)
-{
-    ECOMM_TRACE(UNILOG_PLA_APP, cisAsyncBackup_0, P_ERROR, 0, "Enter cisAsyncBackup");
-    memcpy((uint8_t *)&(gOnenetContextRunning.gObservedBackup[0]), &(g_observed_backup[0]), MAX_OBSERVED_COUNT*sizeof(observed_backup_t));
- #if USE_LITTLEFS
-    int32_t ret;
-    lfs_file_t file;
-    ret = LFS_FileOpen(&file, "cisSlpCntxt", LFS_O_WRONLY);
-    OsaCheck(ret == 0,0,0,0);
-
-
-    ret = LFS_FileWrite(&file, &gOnenetContextRunning, sizeof(onenet_context_t));  
-    OsaCheck(ret == sizeof(onenet_context_t),ret,0,0);
-
-    LFS_FileClose(&file);
-
-#endif
-}
-
-void cisAsyncRestore()
-{
-    uint8_t i;
-    ECOMM_TRACE(UNILOG_PLA_APP, cisAsyncRestore_0, P_SIG, 0, "Enter cisAsyncRestore");
-#if USE_LITTLEFS
-
-    int32_t ret;
-    lfs_file_t file;
-    ret = LFS_FileOpen(&file, "cisSlpCntxt", LFS_O_RDONLY | LFS_O_CREAT);
-    OsaCheck(ret == 0,0,0,0);
-
-    ret = LFS_FileRead(&file, &gOnenetContextRunning, sizeof(onenet_context_t));
-    OsaCheck(ret >= 0,ret,0,0);
-
-    LFS_FileClose(&file);
-#else
-    memcpy((uint8_t *)&gOnenetContextRunning,(void*)APP_BACKUP_XIP_ADDR,sizeof(onenet_context_t));
-    
-#endif
-    // Restore for cis core using
-    memcpy((uint8_t *)(&(g_observed_backup[0])), (uint8_t *)&(gOnenetContextRunning.gObservedBackup[0]),  MAX_OBSERVED_COUNT*sizeof(observed_backup_t));
-    // Restore for cis app using
-    LOGD("observeObjNum =%d\r\n", gOnenetContextRunning.observeObjNum);
-    for (i = 0; i < gOnenetContextRunning.observeObjNum; i++)
-    {
-        struct st_observe_info* observe_new = (struct st_observe_info*)cissys_malloc(sizeof(struct st_observe_info));
-        memset((uint8_t *)observe_new, 0, sizeof(struct st_observe_info));
-        observe_new->mid = g_observed_backup[i].msgid;
-        LOGD("mid=%d\r\n", observe_new->mid);
-        cis_memcpy(&(observe_new->uri), &(g_observed_backup[i].uri), sizeof(st_uri_t));
-        cis_memcpy(&(observe_new->params), &(g_observed_backup[i].params), sizeof(cis_observe_attr_t));
-        observe_new->next = NULL;
-        g_observeList = (struct st_observe_info*)cis_list_add((cis_list_t*)g_observeList,(cis_list_t*)observe_new);
-    }
-}
-
-void cisDataObserveReport()
-{
-    uint32_t nowtime;
-    /*data observe data report*/
-    nowtime = cissys_gettime();
-    struct st_observe_info* node = g_observeList;
-    if (node == NULL)
-        return;
-    ECOMM_TRACE(UNILOG_PLA_APP, x1_cisDataObserveReport_0, P_INFO, 2, "cisDataObserveReport g_notifyLast=%d nowtime=%d", g_notifyLast, nowtime);
-    // if diff time is more than 10S, continue to allow to report
-    if((nowtime - g_notifyLast > 10*1000) && (!gNotifyOngoing))
-    {
-        g_notifyLast = nowtime;
-        while(node != NULL)
-        {
-             if(node->mid == 0)
-             {
-                ECOMM_TRACE(UNILOG_PLA_APP, x1_cisDataObserveReport_1, P_INFO, 0, "cisDataObserveReport mid = 0");
-                node = node->next;
-                continue;
-             }
-             if(node->uri.flag == 0)
-             {
-                ECOMM_TRACE(UNILOG_PLA_APP, x1_cisDataObserveReport_2, P_INFO, 0, "cisDataObserveReport uri flag = 0");
-                node = node->next;
-                continue;
-             }
-             cis_uri_t uriLocal;
-             uriLocal = node->uri;
-             prvObserveNotify(gCisContext,&uriLocal,node->mid);
-             node = node->next;
-             ECOMM_TRACE(UNILOG_PLA_APP, x1_cisDataObserveReport_3, P_INFO, 0, "cisDataObserveReport");
-             gNotifyOngoing = true;
-        }
-    }
-    if ((nowtime - g_notifyLast > 20*100)&&(gNotifyOngoing))
-    {
-        ECOMM_TRACE(UNILOG_PLA_APP, x1_cisDataObserveReport_4, P_ERROR, 0, "cisDataObserveReport too long reset gNotifyOngoing");
-        gNotifyOngoing = false;
-    }
-    
-
-}
-
-
-void cisAsyncProcess(void *arg)
-{
-
-    if(cis_init(&gCisContext,(void *)config_hex,sizeof(config_hex),NULL, defaultLocalPort) != CIS_RET_OK){
-        ECOMM_TRACE(UNILOG_PLA_APP, cis_sample_entry_1, P_ERROR, 0, "cis entry init failed.");
-        LOGD("cis entry init failed.\n");
-        if (gCisContext != NULL)
-            cis_deinit(&gCisContext);
-
-        return;
-    }
-    
-    if(pmuBWakeupFromHib() || pmuBWakeupFromSleep2())
-    {
-        cisAsyncRestore();
-        ECOMM_TRACE(UNILOG_PLA_APP, cis_sample_entry_0, P_INFO, 1, "wakeup from hib continue pumpState=%d", gOnenetContextRunning.pumpState);
-        if (gOnenetContextRunning.pumpState == PUMP_STATE_READY || gOnenetContextRunning.pumpState == PUMP_STATE_CONNECTING)
-        {
-#if CIS_ENABLE_CONTEXT_RESTORE
-            ((st_context_t*)gCisContext)->ignoreRegistration = true;
-            ((st_context_t*)gCisContext)->stateStep = PUMP_STATE_CONNECTING;
-#else
-            ((st_context_t*)gCisContext)->stateStep = PUMP_STATE_INITIAL;
-#endif
-            cisAsyncUpdatePumpState(((st_context_t*)gCisContext)->stateStep);
-        }
-        
-        observe_read_retention_data(gCisContext);    
-        cisAsyncAddObject();
-        cisAsyncRegister();
-    }
-    else
-    {
-        cisAsyncAddObject();
-        cisAsyncRegister();
-    }
-    g_shutdown = false;
-    xTaskCreate(cisAsyncProcessTask,"cisAsyncProc", 512, NULL, osPriorityBelowNormal7, NULL);
-    while(1)
-    {
-        uint32_t nowtime;
-        if (g_shutdown)
-        {
-            cissys_sleepms(3000);
-            continue;
-        }
-           
-        /*pump function*/
-        cis_pump(gCisContext);
-        cisAsyncUpdatePumpState(((st_context_t*)gCisContext)->stateStep);
-        cissys_sleepms(1000);
-        /*update lifetime*/
-        nowtime = cissys_gettime();
-        if(nowtime - g_lifetimeLast > ((g_lifetime * 1000) * 0.6)){
-            g_lifetimeLast = cissys_gettime();
-            cis_update_reg(gCisContext,LIFETIME_INVALID,false, PS_SOCK_RAI_NO_INFO);
-        }
-    }
-}
-
-void cisAsyncTask(void *arg)
-{   
-    while(1)
-    {
-        cisAsyncProcess(arg);
-        cissys_sleepms(1000);
-    }
-}
-
-void cisOnenetInit()
-{
-    osThreadAttr_t task_attr;
-    slpManRet_t ret;
-    ret = slpManRegisterUsrdefinedBackupCb(cisAsyncBackup, NULL,SLPMAN_HIBERNATE_STATE);
-    OsaCheck(ret == RET_TRUE,0,0,0);
-
-    memset(&task_attr, 0, sizeof(osThreadAttr_t));
-    task_attr.name        = "cisAsyncTask";
-    task_attr.stack_mem   = onenetTaskStack;
-    task_attr.stack_size  = ONENET_TASK_STACK_SIZE;
-    task_attr.priority    = osPriorityBelowNormal7;
-    task_attr.cb_mem      = &onenetTask;
-    task_attr.cb_size     = sizeof(StaticTask_t);
-    memset(onenetTaskStack, 0xA5, ONENET_TASK_STACK_SIZE);
-    memset((uint8_t *)&gOnenetContextRunning, 0x00, sizeof(gOnenetContextRunning));
-    onenetTaskId = osThreadNew(cisAsyncTask, NULL,&task_attr);
-}
-
-void cisOnenetDeinit()
-{
-    slpManUnregisterUsrdefinedBackupCb(cisAsyncBackup);
-    osThreadTerminate(onenetTaskId);
-    onenetTaskId = NULL;
-}
-
-

+ 1 - 1
src/hal_module_adapter.c

@@ -2401,7 +2401,7 @@ void relayConfigInit()
 	PAD_SetPinConfig(32, &padConfig);
 	GPIO_PinConfig(1, AON_RELAY_DRV, &config);
 	GPIO_PinWrite(1, 1 << AON_RELAY_DRV, 0 << AON_RELAY_DRV);  //the relay default is off(disconnected)
-	printf("switch off\n");
+	//printf("switch off\n");
 }
 
 /**