Browse Source

V2大版本改动,拆分各个任务为文件,MainTask调试完成

CHENJIE-PC\QiXiang_CHENJIE 4 years ago
parent
commit
9f1c5b1a9a
8 changed files with 326 additions and 1775 deletions
  1. 3 2
      ARMCC/Makefile
  2. 19 0
      inc/MainTask.h
  3. 0 27
      inc/app.h
  4. 246 0
      src/MainTask.c
  5. 28 0
      src/UartTask.c
  6. 18 0
      src/UartTask.h
  7. 11 1745
      src/app.c
  8. 1 1
      src/bsp_custom.c

+ 3 - 2
ARMCC/Makefile

@@ -16,7 +16,8 @@ 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/bsp_custom.o \
+					PLAT/project/$(TARGET)/apps/qx_app/src/hal_module_adapter.o \
+					PLAT/project/$(TARGET)/apps/qx_app/src/MainTask.o
 
 include $(TOP)/PLAT/tools/scripts/Makefile.rules

+ 19 - 0
inc/MainTask.h

@@ -0,0 +1,19 @@
+/****************************************************************************
+ *
+ * Copy right:   Qx.
+ * File name:    MainTask.h
+ * Description:  APP任务调取和异常处理
+ * History:      2021-03-05
+ *
+ ****************************************************************************/
+
+#define PROC_MAIN_TASK_STACK_SIZE           (512)
+typedef enum
+{
+    PROCESS_STATE_IDLE = 0,
+    PROCESS_STATE_WORK,
+    PROCESS_STATE_SLEEP
+}process_Main;
+
+void MainTaskInit(void* arg);
+void MainTaskDeInit(void* arg);

+ 0 - 27
inc/app.h

@@ -8,13 +8,10 @@
  ****************************************************************************/
 #ifndef  APP_H
 #define  APP_H
-
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-#include "cisAsynEntry.h"
-
 #define QMSG_ID_BASE               (0x160) 
 #define QMSG_ID_NW_IP_READY        (QMSG_ID_BASE)
 #define QMSG_ID_NW_IP_SUSPEND      (QMSG_ID_BASE + 1)
@@ -73,16 +70,6 @@ extern UINT8 BattSN[BATT_SN_LEN];
 extern CHAR  TcpServerIpV4Address[16];
 extern CHAR  TcpServerPort[5];
 
-
-
-
-typedef enum
-{
-    PROCESS_STATE_IDLE = 0,
-    PROCESS_STATE_WORK,
-    PROCESS_STATE_SLEEP
-}process_Main;
-
 typedef enum
 {
     PROCESS_UART_STATE_IDLE = 0,
@@ -200,20 +187,6 @@ typedef struct AppSocketConnectionContext_Tag
     INT32 status;
 }AppSocketConnectionContext;
 
-typedef struct Uart_Receive_Type
-{
-    uint8_t Bms_Address; 
-    uint8_t Bms_Read_Funcode; 
-    uint8_t Reg_Begin_H; 
-    uint8_t Reg_Begin_L; 
-    uint8_t Reg_Num_H; 
-    uint8_t Reg_Num_L; 
-}Uart_Receive_Type;
-
-
-
-
-
 typedef struct Fota_Type
 {
     bool Fota_update_flag ;

+ 246 - 0
src/MainTask.c

@@ -0,0 +1,246 @@
+/****************************************************************************
+ *
+ * Copy right:   Qx.
+ * File name:    MainTask.c
+ * Description:  APP任务调取和异常处理
+ * History:      2021-03-05
+ *
+ ****************************************************************************/
+#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"
+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
+volatile bool Work_timer_end = false;
+static process_Main 		    gProcess_Main_Task;
+#define PROC_MAIN_STATE_SWITCH(a)  (gProcess_Main_Task = a)
+//全局变量
+static uint32_t Timer_count = 0;//每100ms加1
+volatile bool Sleep_flag = false;//睡眠标志位
+
+//函数声明区
+static void appBeforeHib(void *pdata, slpManLpState state);
+static void appAfterHib(void *pdata, slpManLpState state);
+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 MainTask(void* arg)
+{
+
+    appSetEDRXSettingSync(0,5,1800000);
+    appSetPSMSettingSync(0,3*60*60,10);
+    appSetCFUN(0);
+
+    int32_t inParam = 0xAABBCCDD;
+    slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
+    slpManApplyPlatVoteHandle("MainSlp",&MainSlpHandler);
+    slpManPlatVoteDisableSleep(MainSlpHandler, SLP_SLP2_STATE);
+    slpManRegisterUsrdefinedBackupCb(appBeforeHib,&inParam,SLPMAN_HIBERNATE_STATE);
+    slpManRegisterUsrdefinedRestoreCb(appAfterHib,NULL,SLPMAN_HIBERNATE_STATE);
+    slpManRegisterUsrdefinedBackupCb(appBeforeSlp1,NULL,SLPMAN_SLEEP1_STATE);
+    slpManRegisterUsrdefinedRestoreCb(appAfterSlp1,NULL,SLPMAN_SLEEP1_STATE);
+    slpManRegisterUsrdefinedBackupCb(appBeforeSlp2,NULL,SLPMAN_SLEEP2_STATE);
+    slpManRegisterUsrdefinedRestoreCb(appAfterSlp2,NULL,SLPMAN_SLEEP2_STATE);
+    slpManSlpState_t slpstate = slpManGetLastSlpState(); 
+
+    TimerHandle_t montior_timer = NULL;
+    TimerHandle_t work_timer = NULL;
+    slpManWakeSrc_e Wakeup_source;
+    
+    static UINT8 work_time;
+    static UINT8 Sleep_Time;
+    Sleep_Time = 1;//睡眠时长 min
+    work_time = 1;//工作时长 min
+
+    montior_timer = xTimerCreate("montior_timer", 100 / portTICK_RATE_MS, pdTRUE, NULL, montior_timer_callback);
+    work_timer = xTimerCreate("work_timer", work_time*60*1000 / portTICK_RATE_MS, pdFALSE, NULL, work_timer_callback);
+    PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
+    while(true)
+    {
+        switch(gProcess_Main_Task)
+        {
+            case PROCESS_STATE_IDLE:
+            {
+                xTimerStart(montior_timer, 0);
+                xTimerStart(work_timer, 0);
+                Sleep_flag = false;
+                PROC_MAIN_STATE_SWITCH(PROCESS_STATE_WORK);
+                break;
+            }
+            case PROCESS_STATE_WORK:
+            {
+                osDelay(1000);
+                if(Work_timer_end)
+                {
+                    PROC_MAIN_STATE_SWITCH(PROCESS_STATE_SLEEP);
+                }
+                break;
+            }
+            case PROCESS_STATE_SLEEP:
+            {
+                Sleep_flag = true;
+                xTimerStop(montior_timer, 0);
+                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_SLP2_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
+                slpManDeepSlpTimerStart(deepslpTimerID, Sleep_Time*1000*60);
+                while(1)
+                {
+                    osDelay(20*60*1000/portTICK_PERIOD_MS);
+                    break;
+                }
+                PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
+                break;
+            }
+            default:
+            {
+                PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
+                #ifdef USING_PRINTF
+                    printf("default!\n");
+                #endif
+                break;
+            }
+        }
+    }
+}
+void MainTaskInit(void *arg)
+{
+    #ifndef USING_PRINTF
+    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
+    {
+        HAL_UART_RecvFlowControl(false);
+    }
+    #endif
+    osThreadAttr_t task_attr;
+    memset(&task_attr,0,sizeof(task_attr));
+    memset(gProcess_Main_TaskStack, 0xA5, PROC_MAIN_TASK_STACK_SIZE);
+    task_attr.name = "Main_Task";
+    task_attr.stack_mem = gProcess_Main_TaskStack;
+    task_attr.stack_size = PROC_MAIN_TASK_STACK_SIZE;
+    task_attr.priority = osPriorityNormal;
+    task_attr.cb_mem = &gProcess_Main_Task_t;
+    task_attr.cb_size = sizeof(StaticTask_t);
+    MainTaskId = osThreadNew(MainTask, NULL, &task_attr);
+
+}
+void MainTaskDeInit(void *arg)
+{
+    osThreadTerminate(MainTaskId);
+    MainTaskId = NULL;
+}
+//定时器回调函数区
+void montior_timer_callback(TimerHandle_t xTimer)
+{
+    // #ifdef USING_PRINTF
+    //     printf("Hello montior Timer!\n");
+    // #endif
+    Timer_count++;
+    if(Timer_count>100000*100)
+    {
+        Timer_count=0;
+    }
+}
+void work_timer_callback(TimerHandle_t xTimer)
+{
+    Work_timer_end = true;
+    #ifdef USING_PRINTF
+        printf("Hello work Timer!\n");
+    #endif
+}
+
+//睡眠进出函数区
+static void appBeforeHib(void *pdata, slpManLpState state)
+{
+    uint32_t *p_param = (uint32_t *)pdata;
+
+    #ifdef USING_PRINTF
+        printf("Before Hibernate:%d \n",state);
+    #endif
+	slpManAONIOLatchEn(AonIOLatch_Enable);
+
+}
+static void appAfterHib(void *pdata, slpManLpState state)
+{
+    #ifdef USING_PRINTF
+        printf("Try Hibernate Failed:%d \n",state);
+    #endif
+}
+static void appBeforeSlp1(void *pdata, slpManLpState state)
+{
+    #ifdef USING_PRINTF
+        printf("Before Sleep1:%d \n",state);
+    #endif
+	slpManAONIOLatchEn(AonIOLatch_Enable);
+}
+static void appAfterSlp1(void *pdata, slpManLpState state)
+{
+    #ifdef USING_PRINTF
+        printf("After Sleep1:%d \n",state);
+    #endif
+}
+static void appBeforeSlp2(void *pdata, slpManLpState state)
+{
+    #ifdef USING_PRINTF
+        printf("before sleep2:%d \n",state);
+    #endif
+	slpManAONIOLatchEn(AonIOLatch_Enable);
+}
+static void appAfterSlp2(void *pdata, slpManLpState state)
+{
+    #ifdef USING_PRINTF
+        printf("sleep2 failed:%d \n",state);
+    #endif
+}
+
+
+

+ 28 - 0
src/UartTask.c

@@ -0,0 +1,28 @@
+/****************************************************************************
+ *
+ * Copy right:   Qx.
+ * File name:    UartTask.c
+ * Description:  串口任务
+ * History:      2021-03-05
+ *
+ ****************************************************************************/
+#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"
+

+ 18 - 0
src/UartTask.h

@@ -0,0 +1,18 @@
+/****************************************************************************
+ *
+ * Copy right:   Qx.
+ * File name:    UartTask.h
+ * Description:  串口任务
+ * History:      2021-03-05
+ *
+ ****************************************************************************/
+
+typedef struct Uart_Receive_Type
+{
+    uint8_t Bms_Address; 
+    uint8_t Bms_Read_Funcode; 
+    uint8_t Reg_Begin_H; 
+    uint8_t Reg_Begin_L; 
+    uint8_t Reg_Num_H; 
+    uint8_t Reg_Num_L; 
+}Uart_Receive_Type;

+ 11 - 1745
src/app.c

@@ -1,15 +1,15 @@
 /*******************************
  * 
- * 骑享V2版本集成
+ * 骑享V2大版本改动
  * 
  * ****************************/
+//基础定义
 #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"
@@ -23,7 +23,11 @@
 #include "plat_config.h"
 #include "ec_tcpip_api.h"
 #include "hal_module_adapter.h"
-//基础定义
+#include "timers.h"
+#include "app.h"
+
+#include "MainTask.h"
+
 #define BAT4830
 #ifdef  BAT4830
     #define Batt_Cell_Num  (14)
@@ -37,1750 +41,12 @@
 #define	SwVersion		0xA21
 #define HwVersion		0xB22
 
-// UINT8 IH_appChargEndWorkTime;
-// UINT8 IH_appWakeupWorkTime;
-// UINT8 IH_appSleepTime;
-// UINT8 IH_isBattLocked;
-
-// UINT8 OH_appChargEndWorkTime;
-// UINT8 OH_appWakeupWorkTime;
-// UINT8 OH_appSleepTime;
-// UINT8 OH_isBattLocked;
-// UINT8 BattSN[BATT_SN_LEN];
-// CHAR  TcpServerIpV4Address[16];
-// CHAR  TcpServerPort[5];
-
-CAN_Msg_Type CanRxMsg[2];
-UINT8	UDSCmd[2];
-UINT8	UDSService[2];
-UINT8   UDSSubService[2];
-UINT8 	UDSSwitch = 0;
-UINT8   Can_Enable = 0;
-UINT8   UDSBattSN[BATT_SN_LEN];
-UINT8 SNFlag=0;
-
-//Main Area
-#define PROC_MAIN_TASK_STACK_SIZE           (1024)//主线程堆栈大小
-uint8_t deepslpTimerID          = DEEPSLP_TIMER_ID7;//睡眠定时器ID
-uint8_t MainSlpHandler          = 0xff;//主线程睡眠句柄
-static StaticTask_t             gProcess_Main_Task_t;
-static UINT8                  gProcess_Main_TaskStack[PROC_MAIN_TASK_STACK_SIZE];
-
-static process_Main 		    gProcess_Main_Task = PROCESS_STATE_IDLE;
-#define PROC_MAIN_STATE_SWITCH(a)  (gProcess_Main_Task = a)
-volatile bool Sleep_Flag = false;//主线程睡眠标志位
-
-//uart Area
-#define PROC_UART_TASK_STACK_SIZE           (1024)
-static StaticTask_t             gProcess_Uart_Task_t;
-static UINT8                  gProcess_Uart_TaskStack[PROC_UART_TASK_STACK_SIZE];
-
-#define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (104)
-#define battbuffer_len         (110)
-#define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
-extern ARM_DRIVER_USART Driver_USART1;
-ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
-volatile bool isRecvTimeout = false;
-volatile bool isRecvComplete = false;
-static process_Uart             gProcess_Uart_Task = PROCESS_UART_STATE_IDLE;
-#define PROC_UART_STATE_SWITCH(a)  (gProcess_Uart_Task = a)
-volatile bool Uart_Sleep_Flag = false;
-//Can Area
-/*接收*/
-#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];
-CAN_Msg_Type CAN_Rx_Struct;
-
-static process_CAN             gProcess_CAN_Task = PROCESS_CAN_STATE_IDLE;
-#define PROC_CAN_STATE_SWITCH(a)  (gProcess_CAN_Task = a)
-volatile bool CAN_Rx_Sleep_State = false;
-//tcp area
-#define PROC_TCP_TASK_STACK_SIZE           (1024*2)
-static StaticTask_t             gProcess_Tcp_Task_t;
-static UINT8                  gProcess_Tcp_TaskStack[PROC_TCP_TASK_STACK_SIZE];
-static volatile UINT32          Event;
-static UINT8                    gImsi[16] = {0};
-static UINT32                   gCellID = 0;
-static UINT8  Tcp_serviece;
-static UINT8 Tcp_Send_anwser_buffer[10];
-static QueueHandle_t            psEventQueueHandle;//队列句柄
-#define APP_EVENT_QUEUE_SIZE    (10)//队列大小
-static AppSocketConnectionContext socContext = {-1, APP_SOCKET_CONNECTION_CLOSED};
-volatile bool Tcp_Sleep_Flag = false;
-//Gps area
-#define GPS_TASK_STACK_SIZE   								 (2048)
-static QueueHandle_t norGpsHandle = NULL;
-static osThreadId_t gpsTaskHandle = NULL;
-static StaticTask_t gpsTask = NULL;
-static UINT8 gpsTaskStack[GPS_TASK_STACK_SIZE];
-//fota area
-Fota_Type Fota_S={0,0,0,0,0,0,0,0};
-//函数声明
-void Tcp_Recv_info(uint8_t* p);
-void Tcp_Recv_fota(uint8_t* p);
-uint8_t Fota_crc_chk(uint8_t* data,uint8_t length);
-void Tcp_Send_info();
-void Tcp_Send_anwser();
-//睡眠进出函数
-static void appBeforeHib(void *pdata, slpManLpState state)
-{
-    uint32_t *p_param = (uint32_t *)pdata;
-
-    #ifdef USING_PRINTF
-        printf("Before Hibernate:%d \n",state);
-    #endif
-	slpManAONIOLatchEn(AonIOLatch_Enable);
-
-}
-
-static void appAfterHib(void *pdata, slpManLpState state)
-{
-    #ifdef USING_PRINTF
-        printf("Try Hibernate Failed:%d \n",state);
-    #endif
-}
-
-static void appBeforeSlp1(void *pdata, slpManLpState state)
-{
-    #ifdef USING_PRINTF
-        printf("Before Sleep1:%d \n",state);
-    #endif
-	slpManAONIOLatchEn(AonIOLatch_Enable);
-}
-
-static void appAfterSlp1(void *pdata, slpManLpState state)
-{
-    #ifdef USING_PRINTF
-        printf("After Sleep1:%d \n",state);
-    #endif
-}
-
-
-static void appBeforeSlp2(void *pdata, slpManLpState state)
-{
-    #ifdef USING_PRINTF
-        printf("before sleep2:%d \n",state);
-    #endif
-	slpManAONIOLatchEn(AonIOLatch_Enable);
-}
-
-static void appAfterSlp2(void *pdata, slpManLpState state)
-{
-    #ifdef USING_PRINTF
-        printf("sleep2 failed:%d \n",state);
-    #endif
-}
-//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");
-        }
-    }
-}
-// 主任务线程
-static void Main_Task(void* arg)
-{
-    UINT16 Can_index = 0;
-    UINT16 Uart_index = 0;
-    UINT16 Tcp_index  = 0;
-    uint8_t Tcp_index_temp = 5;
-    uint32_t sleep_index = 0;
-    uint32_t sleep_time_flag;
-    int32_t inParam = 0xAABBCCDD;
-    uint32_t Chrgend_Work_time = 1800;
-    uint32_t Wakeup_Work_time = 120;
-    uint32_t Sleep_Time = 120;
-    //上述参数应写入文件里
-    slpManWakeSrc_e Wakeup_source;
-    PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
-    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);
-    NVIC_EnableIRQ(PadWakeup1_IRQn);
-
-    slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
-    slpManApplyPlatVoteHandle("MainSlp",&MainSlpHandler);
-    slpManPlatVoteDisableSleep(MainSlpHandler, SLP_SLP2_STATE); 
-    slpManRegisterUsrdefinedBackupCb(appBeforeHib,&inParam,SLPMAN_HIBERNATE_STATE);
-    slpManRegisterUsrdefinedRestoreCb(appAfterHib,NULL,SLPMAN_HIBERNATE_STATE);
-    slpManRegisterUsrdefinedBackupCb(appBeforeSlp1,NULL,SLPMAN_SLEEP1_STATE);
-    slpManRegisterUsrdefinedRestoreCb(appAfterSlp1,NULL,SLPMAN_SLEEP1_STATE);
-    slpManRegisterUsrdefinedBackupCb(appBeforeSlp2,NULL,SLPMAN_SLEEP2_STATE);
-    slpManRegisterUsrdefinedRestoreCb(appAfterSlp2,NULL,SLPMAN_SLEEP2_STATE);
-
-    slpManSlpState_t slpstate = slpManGetLastSlpState();
-
-    #ifdef USING_PRINTF
-            printf("slpstate:%d \n",slpstate);
-    #endif
-    Wakeup_source =  slpManGetWakeupSrc();//获取唤醒源
-    #ifdef USING_PRINTF
-            printf("Wakeup_source:%d \n",Wakeup_source);
-    #endif
-    if (Wakeup_source==0)
-    {
-        sleep_time_flag = Wakeup_Work_time;
-    }
-    else if (Wakeup_source==1)
-    {
-        sleep_time_flag = Wakeup_Work_time;
-    }
-    else
-    {
-        sleep_time_flag = Chrgend_Work_time;
-    }
-    if((slpstate == SLP_SLP2_STATE) || (slpstate == SLP_HIB_STATE))
-    {
-        PROC_MAIN_STATE_SWITCH(PROCESS_STATE_WORK);
-    }
-    else
-    {
-        PROC_MAIN_STATE_SWITCH(PROCESS_STATE_WORK);
-    }
-    while (true)
-    {
-        switch(gProcess_Main_Task)
-        {
-            case PROCESS_STATE_IDLE:
-            {
-                // 暂时不区分唤醒
-                PROC_MAIN_STATE_SWITCH(PROCESS_STATE_WORK);
-                break;
-            }
-            case PROCESS_STATE_WORK:
-            {
-                osDelay(10/portTICK_PERIOD_MS);
-                Can_index++;
-                Uart_index++;
-                Tcp_index++;
-                sleep_index++;
-                if(Tcp_index>Tcp_index_temp*100)
-                {
-                    #ifdef USING_PRINTF
-                        printf("[%d]work flag V2\r\n",__LINE__);
-                    #endif
-                    sendQueueMsg(QMSG_ID_SOCK_SENDPKG, 0);
-                    Tcp_index = 0;
-                    PROC_CAN_STATE_SWITCH(PROCESS_STATE_WORK);
-                }
-                if (Uart_index >100)//Uart 1s 调用一次
-                {
-                    PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_WORK);
-                    Uart_index = 0;
-                }
-                PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_WORK);
-                if (Can_index >=100)//Can 1s 调用一次
-                {
-                    Can_index = 0;
-                }
-                if (Tcp_serviece==1)//Tcp应答 2s 调用一次
-                {
-                    sleep_index = 0;
-                    Tcp_index_temp = 2;
-                }
-                else//Tcp发送10s 调用一次
-                {
-                    Tcp_index_temp = 10;
-                }
-                if (sleep_index >=sleep_time_flag*100 &&Tcp_serviece==0)
-                {
-                    PROC_MAIN_STATE_SWITCH(PROCESS_STATE_SLEEP);
-                    sleep_index = 0;
-                }
-                break;
-            }
-            case PROCESS_STATE_SLEEP:
-            {
-                while(true)
-                {
-                    PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_SLEEP);
-                    PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_SLEEP);
-                    sendQueueMsg(QMSG_ID_SOCK_EXIT, 0);
-                    Sleep_Flag = TRUE;
-                    if((Uart_Sleep_Flag)&&(CAN_Rx_Sleep_State)&&(Tcp_Sleep_Flag))
-                        break;
-                }
-                osDelay(1000);
-                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_SLP2_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
-                slpManDeepSlpTimerStart(deepslpTimerID, Sleep_Time);
-                while(1)
-                {
-                    if(!slpManDeepSlpTimerIsRunning(deepslpTimerID))
-                    {
-                        slpManDeepSlpTimerDel(deepslpTimerID);
-                    }
-                    slpManDeepSlpTimerStart(deepslpTimerID, Sleep_Time*1000);
-                    osDelay(60000/portTICK_PERIOD_MS);
-                }
-                break;
-            }
-        }
-
-    }
-    
-
-}
-//Uart校验程序
-unsigned int crc_chk(uint8_t* data, uint8_t length)
-{  
-    int j;
-    uint16_t 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回调程序
-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发送接收函数
-uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t* Uart_Rece_buffer,uint8_t Data_Len)
-{
-    uint16_t CRC_Rece_buffer;
-    uint16_t CRC_chk_buffer;
-    uint8_t Uart_Send_buffer[8];
-    Uart_Send_buffer[0] = Uart_Receive_Msg.Bms_Address;
-    Uart_Send_buffer[1] = Uart_Receive_Msg.Bms_Read_Funcode;
-    Uart_Send_buffer[2] = Uart_Receive_Msg.Reg_Begin_H;
-    Uart_Send_buffer[3] = Uart_Receive_Msg.Reg_Begin_L;
-    Uart_Send_buffer[4] = Uart_Receive_Msg.Reg_Num_H;
-    Uart_Send_buffer[5] = Uart_Receive_Msg.Reg_Num_L;
-    CRC_chk_buffer = crc_chk(Uart_Send_buffer,6);
-    Uart_Send_buffer[6] = CRC_chk_buffer;
-    Uart_Send_buffer[7] = CRC_chk_buffer>>8;
-    uint32_t timeout = 0x00000000;
-    USARTdrv->Send(Uart_Send_buffer,8);
-    // #ifdef USING_PRINTF
-    // printf("Uart_Send_buffer:  ");
-    // for(int i=0;i<8;i++)
-    // {
-    //     printf("%x ",Uart_Send_buffer[i]);
-    // }
-    //  printf("\n");
-    // #endif
-    USARTdrv->Receive(Uart_Rece_buffer,Data_Len);
-    while((isRecvTimeout == false) && (isRecvComplete == false))
-    {
-        timeout++;
-        osDelay(100);
-        if (timeout>=10)
-        {
-            timeout =0;
-            isRecvTimeout = true;
-            break;
-        }
-    }
-    // #ifdef USING_PRINTF
-    //     printf("Uart_Rece_buffer1: ");
-    //     for(int i=0;i<Data_Len;i++)
-    //     {
-    //     printf("%x ",*(Uart_Rece_buffer+i));
-    //     }
-    // #endif
-    if (isRecvComplete == true)
-    {
-        isRecvComplete = false;
-        CRC_Rece_buffer =*(Uart_Rece_buffer+Data_Len-1)<<8|*(Uart_Rece_buffer+Data_Len-2);
-        CRC_chk_buffer = crc_chk(Uart_Rece_buffer,Data_Len-2);
-        // #ifdef USING_PRINTF
-        //     printf("Uart_Rece_buffer2: ");
-        //     for(int i=0;i<Data_Len;i++)
-        //     {
-        //     printf("%x ",*(Uart_Rece_buffer+i));
-        //     }
-        //     printf("\ncrcchk:%x,%x\n ",CRC_chk_buffer,CRC_Rece_buffer);
-        // #endif
-        if (CRC_Rece_buffer == CRC_chk_buffer)//满足校验
-        {
-            return Uart_Rece_buffer;//此处指针移位出现重启问题
-        }
-        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_Rece_buffer,0xff,Data_Len);
-            return Uart_Rece_buffer;
-        }
-    }
-    else
-    {
-        osDelay(100);
-        memset(Uart_Rece_buffer,0x00,Data_Len);
-        isRecvTimeout = false;
-        return Uart_Rece_buffer;
-    }
-}
-//Uart线程
-static void Uart_Task(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);
-    int Rece_index = 0;
-    volatile  uint8_t Data_Len;
-    Uart_Receive_Type Uart_Receive_Msg;
-    memset(&battbuffer[0],0x00,battbuffer_len);
-	PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
-    Uart_Receive_Msg.Bms_Address = 0x01;
-    Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
-    uint8_t *Uart_Rece_buffer = NULL;
-    volatile bool Uart_task = false;
-    while (true)
-    {
-        switch (gProcess_Uart_Task)
-        {
-            case PROCESS_UART_STATE_IDLE:
-            {    
-                Rece_index = 0;
-                break;
-            }
-            case PROCESS_UART_STATE_CHECK:
-            {
-                Uart_Rece_buffer = (uint8_t *)malloc(Uart_Rece_LEN);
-                Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                Uart_Receive_Msg.Reg_Begin_L= 0x02+Batt_Cell_Num;
-                Uart_Receive_Msg.Reg_Num_H = 0x00;
-                Uart_Receive_Msg.Reg_Num_L = 0x01;
-                Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
-                memset(Uart_Rece_buffer,0x00,Data_Len);
-                Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
-                Uart_Rece_BattI = *(Uart_Rece_buffer+3+0)<<8 |*(Uart_Rece_buffer+3+1);
-                #ifdef USING_PRINTF
-                        printf("Check_Current!\n");
-                #endif
-                PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
-                free(Uart_Rece_buffer);
-                break;
-            }
-            case PROCESS_UART_STATE_WORK:
-            {
-                #ifdef USING_PRINTF
-                        //printf("UART_STATE_WORK!\n");
-                #endif
-                Uart_task = false;
-                Uart_Rece_buffer = (uint8_t *)malloc(Uart_Rece_LEN);
-                while(!Uart_task)
-                {
-                    switch (Rece_index)
-                    {
-                        case 0://current
-                        {
-                            Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                            Uart_Receive_Msg.Reg_Begin_L= 0x02+Batt_Cell_Num;
-                            Uart_Receive_Msg.Reg_Num_H = 0x00;
-                            Uart_Receive_Msg.Reg_Num_L = 0x01;
-                            Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
-                            memset(Uart_Rece_buffer,0x00,Data_Len);
-                            Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
-
-                            Uart_Rece_BattI = *(Uart_Rece_buffer+3+0)<<8 |*(Uart_Rece_buffer+3+1);
-                            break;
-                        }
-                        case 1://cell votage
-                        {
-                            Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                            Uart_Receive_Msg.Reg_Begin_L = 0x02;
-                            Uart_Receive_Msg.Reg_Num_H = Batt_Cell_Num>>8;
-                            Uart_Receive_Msg.Reg_Num_L = Batt_Cell_Num;
-                            Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
-                            memset(Uart_Rece_buffer,0x00,Data_Len);
-                            Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
-                            battbuffer[30] = Batt_Cell_Num;
-                            memcpy(&battbuffer[31],Uart_Rece_buffer+3,Batt_Cell_Num_2);
-                            break;
-                        }
-                        case 2://temprature
-                        {
-                            Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                            Uart_Receive_Msg.Reg_Begin_L = 0x06+Batt_Cell_Num;
-                            Uart_Receive_Msg.Reg_Num_H = Batt_Temp_Num>>8;
-                            Uart_Receive_Msg.Reg_Num_L = Batt_Temp_Num;
-                            Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
-                            memset(Uart_Rece_buffer,0x00,Data_Len);
-                            Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
-                            battbuffer[31+Batt_Cell_Num_2] = Batt_Temp_Num;
-                            for (int i = 0; i < Batt_Temp_Num; i++)
-                            {
-                                battbuffer[32+Batt_Cell_Num_2+i] = *(Uart_Rece_buffer+3+2*i+1);
-                            }
-                            break;
-                        }
-                        case 3://batt votage
-                        {
-                            Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                            Uart_Receive_Msg.Reg_Begin_L = 0x18+Batt_Cell_Num+Batt_Temp_Num;
-                            Uart_Receive_Msg.Reg_Num_H = 0x00;
-                            Uart_Receive_Msg.Reg_Num_L = 0x01;
-                            Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
-                            memset(Uart_Rece_buffer,0x00,Data_Len);
-                            Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
-                            battbuffer[19] = *(Uart_Rece_buffer+3+0);//Link U
-                            battbuffer[20] = *(Uart_Rece_buffer+3+1);
-                            battbuffer[21] = *(Uart_Rece_buffer+3+0);//Pack U
-                            battbuffer[22] = *(Uart_Rece_buffer+3+1);
-                            break;
-                        }
-                        case 4://soc,soh
-                        {
-                            Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                            Uart_Receive_Msg.Reg_Begin_L = 0x09+Batt_Cell_Num+Batt_Temp_Num;
-                            Uart_Receive_Msg.Reg_Num_H = 0x00;
-                            Uart_Receive_Msg.Reg_Num_L = 0x04;
-                            Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
-                            memset(Uart_Rece_buffer,0x00,Data_Len);
-                            Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
-                            battbuffer[23] = *(Uart_Rece_buffer+3+0)>>1;//mos状态
-                            battbuffer[24] = *(Uart_Rece_buffer+3+5);//SOC
-                            battbuffer[25] = *(Uart_Rece_buffer+3+7);//SOH
-                            break;
-                        }
-                        case 5://均衡
-                        {
-                            Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                            Uart_Receive_Msg.Reg_Begin_L = 0x06+Batt_Cell_Num+Batt_Temp_Num;
-                            Uart_Receive_Msg.Reg_Num_H = 0x00;
-                            Uart_Receive_Msg.Reg_Num_L = 0x02;
-                            Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
-                            memset(Uart_Rece_buffer,0x00,Data_Len);
-                            Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
-                            memcpy(&battbuffer[26],Uart_Rece_buffer+3,4);
-                            break;
-                        }
-                        case 6://最高最低温度和加热和充放电MOS控制
-                        {
-                            Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                            Uart_Receive_Msg.Reg_Begin_L = 0x19+Batt_Cell_Num+Batt_Temp_Num;
-                            Uart_Receive_Msg.Reg_Num_H = 0x00;
-                            Uart_Receive_Msg.Reg_Num_L = 0x04;
-                            Data_Len = Uart_Receive_Msg.Reg_Num_L*2+5;
-                            memset(Uart_Rece_buffer,0x00,Data_Len);
-                            Uart_Rece_buffer = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer,Data_Len);
-                            memcpy(&battbuffer[34+Batt_Cell_Num_2+Batt_Temp_Num],Uart_Rece_buffer+3,4);
-                            memcpy(&battbuffer[32+Batt_Cell_Num_2+Batt_Temp_Num],Uart_Rece_buffer+3+6,2);
-                            break; 
-                        }
-                        default:
-                        {
-                            PROC_UART_STATE_SWITCH(PROCESS_UART_STATE_IDLE);
-                            Uart_task = true;
-                            break;
-                        }
-                    }
-                    Rece_index++;
-                }
-                free(Uart_Rece_buffer);
-                break;
-            }
-            case PROCESS_UART_STATE_SLEEP:
-            {
-                USARTdrv->PowerControl(ARM_POWER_LOW);
-                #ifdef USING_PRINTF
-                    printf("UART_STATE_SLEEP\n");
-                #endif
-                Uart_Sleep_Flag = true;
-                while(1)
-                {
-                    osDelay(60000/portTICK_PERIOD_MS);
-                }
-            }
-        }
-    }
-
-}
-//CAN 接收线程
-static void Can_Receive_Task()
-{
-    
-	slpManSlpState_t State;
-    uint8_t cnt,temp,udsFlag=0;
-	UINT8 i = 0;
-	UINT16 timeCounter = 0;
-	CAN_Msg_Type CanTxMsg;
-	
-	//static CANRxSignalTableType CanRxSignalTable;
-	//void* pBattMsgQueue;
-	
-	//uint8_t* pCANMsgQ = NULL;
-	
-	
-
-   // slpManApplyPlatVoteHandle("CanRecvSlp",&CanRecvSlpHandler);
-   // slpManPlatVoteDisableSleep(CanRecvSlpHandler, SLP_SLP2_STATE);
-
-	//memset(&CanRxSignalTable,0x00,sizeof(CANRxSignalTableType));
-	//pBattMsgQueue = malloc(sizeof(CANRxSignalTableType));
-    //static UINT16 CAN_ID = 0;
-	//Can_TxMsgType Can_TxMsg;
-	
-    while(true)
-    {		
-    		//USARTdrv->Send(&SNFlag,1);
-    		memset(CanRxMsg, 0, sizeof(CanRxMsg));    		
-        	switch(gProcess_CAN_Task)
-       		{
-				case PROCESS_CAN_STATE_IDLE:
-
-					PROC_CAN_STATE_SWITCH(PROCESS_CAN_STATE_WORK);
-					break;				
-				
-				case PROCESS_CAN_STATE_WORK:
-       			{
-       				//if(battMsgQueue == NULL)
-	    			//{
-		     		//	battMsgQueue = osMessageQueueNew(1,sizeof(CANRxSignalTableType), NULL);
-	    			//}
-	    	   
-					//osDelay(10);
-					///CanTxMsg.Id = 0x225;
-					//CanTxMsg.DLC = 8;
-					//memset(CanTxMsg.Data,0x23,8);
-					//HAL_Can_Transmit(CanTxMsg);
-					//HAL_Can_Transmit(CanTxMsg);
-					//UINT8 ret = slpManGetWakeupPinValue();
-					//USARTdrv->Send(&ret,1);
-			        //if((ret&0x1) == 0)  //INT中断发生(wakeup0 = 0)
-			        {			        	
-			        	Can_Enable = TRUE;
-			        	//SNFlag = 0xAA;
-						//USARTdrv->Send(&SNFlag,1);
-						//printf("test CAN receive before \n");
-					
-						//printf("test CAN receive ok \n");
-						/*
-						CAN_ReadReg(CANINTE,1,&temp);
-						//printf("CANINTE = %d\n",temp);
-						CanTxMsg.Data[0] = temp;
-
-						CAN_ReadReg(CANINTF,1,&temp);
-						CanTxMsg.Data[1] = temp;
-						//printf("CANINTF = %d\n",temp);
-
-						CAN_ReadReg(CANCTRL,1,&temp);
-						CanTxMsg.Data[2] = temp;
-						//printf("CANCTRL = %d\n",temp);
-
-						CAN_ReadReg(CANSTAT,1,&temp);
-						CanTxMsg.Data[3] = temp;
-						//printf("CANSTAT = %d\n",temp);
-
-						CAN_ReadReg(EFLG,1,&temp);
-						CanTxMsg.Data[4] = temp;
-						//printf("EFLG = %d\n",temp);
-						//CAN_ReadReg(RXB1CTRL,1,&temp);
-						CanTxMsg.Data[5] = 0x99;
-						
-						CanTxMsg.Data[6] = 0x99;
-						CanTxMsg.Data[7] = 0x99;
-						*/
-						//printf("CAN send\n");
-						//USARTdrv->Send(&CanTxMsg,13);
-						
-						HAL_Can_Receive(CanRxMsg);
-						//osDelay(100);
-						//HAL_Can_Transmit(CanTxMsg);
-						//CAN_WriteReg(CANINTF, 0);
-						//USARTdrv->Send(CanRxMsg,26);
-						//CANDecodeFunction(CanRxMsg,&CanRxSignalTable );	
-						for(i=0; i<2; i++)
-						{								
-							if(CanRxMsg[i].Id == 0x7A0)
-							{	
-								udsFlag = 1;
-								UDSCmd[i] =  CanRxMsg[i].Data[0];
-								UDSService[i] = CanRxMsg[i].Data[1];
-								UDSSubService[i] = CanRxMsg[i].Data[2];
-								if(UDSCmd[i] == 0x10)
-								{
-									if(UDSService[i] == 0x02)
-									{
-										UDSSwitch = 1;
-									}								
-								}
-							}							
-						}
-						//if((udsFlag[0]==1) || (udsFlag[1]==1))
-						//{
-							//MEMCPY(CanTxMsg.Data, CanRxMsg[0].Data, 8);
-							//HAL_Can_Transmit(CanTxMsg);
-							
-						if(udsFlag==1)
-						{	
-							//printf("udsCmd[0] = %d\tudsCmd[1] = %d\n",UDSCmd[0],UDSCmd[1]);
-							//printf("UDSService[0] = %d\tUDSService[1] = %d\n",UDSService[0],UDSService[1]);
-							UDS_Service_Task();
-							udsFlag = 0;
-							/*osDelay(50);
-							printf("id=%d\n",CanRxMsg[0].Id);
-							printf("Data=\n");
-							for(i=0;i<8;i++)
-							{
-								printf("%d\t",CanRxMsg[0].Data[i]);
-							}
-							printf("\n");
-							*/
-						}
-                        else
-                        {
-                            osDelay(2000);
-                        }
-						
-						
-					//USARTdrv->Send(&CanRxSignalTable,17);
-					}
-					/*
-					else
-					{
-						Can_Enable = false;
-					}
-					*/
-					//MEMCPY(pBattMsgQueue,&CanRxSignalTable,sizeof(CANRxSignalTableType));
-					break;
-				}
-	            case PROCESS_CAN_STATE_SLEEP:
-	            {
-	                
-	                HAL_Can_Sleep();	 
-	                /*
-	                if(slpManCheckVoteState(CanRecvSlpHandler, &State, &cnt)==RET_TRUE)
-	                {
-	                    #ifdef USING_PRINTF
-	                        printf("[%d]We Can Check Vote Can State, state=%d, cnt=%d\r\n",__LINE__,State,cnt);
-	                    #endif						
-	                }
-	                slpManPlatVoteEnableSleep(CanRecvSlpHandler, SLP_SLP2_STATE); 
-	                if(slpManCheckVoteState(CanRecvSlpHandler, &State, &cnt)==RET_TRUE)
-	                {
-	                    #ifdef USING_PRINTF
-	                        printf("[%d]We Can Check Vote can State Again, state=%d, cnt=%d\r\n",__LINE__,State,cnt);
-	                    #endif					
-	                }
-                    */
-	                Can_Recv_Sleep_Flag = true;
-	                while(true)
-	                {
-	                    osDelay(60000/portTICK_PERIOD_MS);
-	                }
-	                break;
-	           }
-	       }
-	       osDelay(50);
-        }
-}
-
-void UDS_Service_Task()
-{
-	UINT8 i,j,k = 0;
-	INT8 ret = 0;
-	static UINT8 snFlag = 0;
-	CAN_Msg_Type UDSAnswer ={0};
-	UINT8 battInfo[8*14] = {0};
-	UINT8 temp00[94] ={0x0,0x0E,0x0,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,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x21,0x0,0x24,0x0,0x26,0x0,0x22,0x0,0x24,0x0,0x0,0x0,0x0,0x6e,0x78,0x0,0x0,0x0,0x0,0x0,0x5F,0x0,0x62,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x13,0x74,0x0E,0x42,0x0D,0x7A,0x0,0x0};
-	MEMCPY(battInfo, temp00, 94);
-	//while(true)
-	//{
-		//if(UDSSwitch == 1)
-		{
-			for(i=0; i<2; i++)
-			{
-				if(CanRxMsg[i].Id == 0x7A0)
-					{
-					switch (UDSCmd[i])
-						{
-							case 0x10:
-								if(UDSService[i] == 0x01)
-								{
-									UDSAnswer.Id = 0x7A8;
-									UDSAnswer.DLC = 8;
-									UDSAnswer.Data[0] = 0x04;
-									UDSAnswer.Data[1] = 0x78;
-									UDSAnswer.Data[2] = UDSCmd[i];
-									UDSAnswer.Data[3] = UDSService[i];
-									UDSAnswer.Data[4] = 0x00;
-									UDSAnswer.Data[5] = 0x00;
-									UDSAnswer.Data[6] = 0x00;
-									UDSAnswer.Data[7] = 0x00;
-									ret = HAL_Can_Transmit(UDSAnswer);
-									UDSSwitch = 0;
-								}
-								else if(UDSService[i] == 0x02)
-								{
-									UDSAnswer.Id = 0x7A8;
-									UDSAnswer.DLC = 8;
-									UDSAnswer.Data[0] = 0x04;
-									UDSAnswer.Data[1] = 0x78;
-									UDSAnswer.Data[2] = UDSCmd[i];
-									UDSAnswer.Data[3] = UDSService[i];
-									UDSAnswer.Data[4] = 0x00;
-									UDSAnswer.Data[5] = 0x00;
-									UDSAnswer.Data[6] = 0x00;
-									UDSAnswer.Data[7] = 0x00;
-									//printf("ID = 0x%x\n",UDSAnswer.Id);
-									//printf("Data=\n");
-									// for(i=0;i<8;i++)
-									// {
-									// 	printf("0x%x\t",UDSAnswer.Data[i]);
-									// }
-									// printf("\n");
-									ret = HAL_Can_Transmit(UDSAnswer);
-								}
-								else if(UDSService[i] == 0x11)   //make NB software reset
-								{
-									UDSAnswer.Id = 0x7A8;
-									UDSAnswer.DLC = 8;
-									UDSAnswer.Data[0] = 0x04;
-									UDSAnswer.Data[1] = 0x78;
-									UDSAnswer.Data[2] = UDSCmd[i];
-									UDSAnswer.Data[3] = UDSService[i];
-									UDSAnswer.Data[4] = 0x00;
-									UDSAnswer.Data[5] = 0x00;
-									UDSAnswer.Data[6] = 0x00;
-									UDSAnswer.Data[7] = 0x00;
-									ret = HAL_Can_Transmit(UDSAnswer);
-									osDelay(100);
-									mwSetAndSaveAppDataValue();
-									osDelay(1000);
-		                			EC_SystemReset();
-								}
-								else
-								{
-									UDSAnswer.Id = 0x7A8;
-									UDSAnswer.DLC = 8;
-									UDSAnswer.Data[0] = 0x05;
-									UDSAnswer.Data[1] = 0x7F;
-									UDSAnswer.Data[2] = UDSCmd[i];
-									UDSAnswer.Data[3] = UDSService[i];
-									UDSAnswer.Data[4] = 0xEE;  //the sub service is not surported
-									UDSAnswer.Data[5] = 0x00;
-									UDSAnswer.Data[6] = 0x00;
-									UDSAnswer.Data[7] = 0x00;
-									ret = HAL_Can_Transmit(UDSAnswer);
-								}
-								break;
-							case 0x22:
-								if(UDSSwitch == 1)
-								{
-									if(UDSService[i] == 0x01)		//check the sw of NB
-									{
-										UDSAnswer.Id = 0x7A8;
-										UDSAnswer.DLC = 8;
-										UDSAnswer.Data[0] = 0x06;
-										UDSAnswer.Data[1] = 0x78;
-										UDSAnswer.Data[2] = UDSCmd[i];
-										UDSAnswer.Data[3] = UDSService[i];
-										UDSAnswer.Data[4] = SwVersion>>8;
-										UDSAnswer.Data[5] = SwVersion;
-										UDSAnswer.Data[6] = 0x00;
-										UDSAnswer.Data[7] = 0x00;
-										ret = HAL_Can_Transmit(UDSAnswer);
-									}
-									else if(UDSService[i] == 0x02)  //check the hw of NB
-									{
-										UDSAnswer.Id = 0x7A8;
-										UDSAnswer.DLC = 8;
-										UDSAnswer.Data[0] = 0x06;
-										UDSAnswer.Data[1] = 0x78;
-										UDSAnswer.Data[2] = UDSCmd[i];
-										UDSAnswer.Data[3] = UDSService[i];
-										UDSAnswer.Data[4] = HwVersion>>8;
-										UDSAnswer.Data[5] = HwVersion;
-										UDSAnswer.Data[6] = 0x00;
-										UDSAnswer.Data[7] = 0x00;
-										ret = HAL_Can_Transmit(UDSAnswer);
-									}
-									else if(UDSService[i] == 0x03)  //check the SN number
-									{	
-										UDSAnswer.DLC = 8;
-										switch(UDSSubService[i])
-										{
-											case 00:
-												UDSAnswer.Id = 0x20;
-												for(k=0; k<8; k++)
-												{
-													UDSAnswer.Data[k] = BattSN[k+8*0];
-												}
-												ret = HAL_Can_Transmit(UDSAnswer);
-												break;
-												
-											case 01:
-												UDSAnswer.Id = 0x21;
-												for(k=0; k<8; k++)
-												{
-													UDSAnswer.Data[k] = BattSN[k+8*1];
-												}
-												ret = HAL_Can_Transmit(UDSAnswer);
-												break;
-
-											case 02:
-												UDSAnswer.Id = 0x22;
-												UDSAnswer.Data[0] = BattSN[16];;
-												for(k=1; k<8; k++)
-												{
-													UDSAnswer.Data[k] = 0x00;
-												}
-												ret = HAL_Can_Transmit(UDSAnswer);
-												break;
-											default:
-											break;
-											
-										}
-										
-									}
-									else if(UDSService[i] == 0x04)  //check the batt message
-									{
-										UDSAnswer.Id = 0x30+UDSSubService[i];
-										UDSAnswer.DLC = 8;
-										MEMCPY(UDSAnswer.Data, &(battInfo[UDSSubService[i]*8]) , 8);
-										//UDSAnswer.Data[3] = 0x30+UDSSubService[i];//just for test  zhengchao 20210228
-										ret = HAL_Can_Transmit(UDSAnswer);
-										//osDelay(50);
-									}
-									else if(UDSService[i] == 0x05)  //check the enviroment temp of NB
-									{
-										UDSAnswer.Id = 0x7A8;
-										UDSAnswer.DLC = 8;
-										UDSAnswer.Data[0] = 0x08;
-										UDSAnswer.Data[1] = 0x78;
-										UDSAnswer.Data[2] = UDSCmd[i];
-										UDSAnswer.Data[3] = UDSService[i];
-										UDSAnswer.Data[4] = 0x55;//gNtcDev.NTCvalue[2+NTC_Channel2];
-										UDSAnswer.Data[5] = 0x66;//gNtcDev.NTCvalue[2+NTC_Channel3];
-										UDSAnswer.Data[6] = 0x77;//gNtcDev.NTCvalue[2+NTC_Channel4];
-										UDSAnswer.Data[7] = 0x88;//gNtcDev.NTCvalue[2+NTC_Channel5];
-										ret = HAL_Can_Transmit(UDSAnswer);
-										
-									}
-									else if(UDSService[i] == 0x06)	//check the tcp link of NB
-									{
-										UDSAnswer.Id = 0x7A8;
-										UDSAnswer.DLC = 8;
-										UDSAnswer.Data[0] = 0x06;
-										UDSAnswer.Data[1] = 0x78;
-										UDSAnswer.Data[2] = UDSCmd[i];
-										UDSAnswer.Data[3] = UDSService[i];
-										//UDSAnswer.Data[4] = TcpconnectID>>8;
-										//UDSAnswer.Data[5] = TcpconnectID;
-										UDSAnswer.Data[6] = 0x00;
-										UDSAnswer.Data[7] = 0x00;
-										ret = HAL_Can_Transmit(UDSAnswer);
-									}
-									else if(UDSService[i] == 0x07)  //check the GPS link of NB
-									{
-										UDSAnswer.Id = 0x7A8;
-										UDSAnswer.DLC = 8;
-										UDSAnswer.Data[0] = 0x05;
-										UDSAnswer.Data[1] = 0x78;
-										UDSAnswer.Data[2] = UDSCmd[i];
-										UDSAnswer.Data[3] = UDSService[i];
-										UDSAnswer.Data[4] = 0x12;  //gps satellite num(uint8), should be modified
-										UDSAnswer.Data[5] = 0x00;
-										UDSAnswer.Data[6] = 0x00;
-										UDSAnswer.Data[7] = 0x00;
-										ret = HAL_Can_Transmit(UDSAnswer);
-									}	
-									else
-									{
-										UDSAnswer.Id = 0x7A8;
-										UDSAnswer.DLC = 8;
-										UDSAnswer.Data[0] = 0x05;
-										UDSAnswer.Data[1] = 0x7F;
-										UDSAnswer.Data[2] = UDSCmd[i];
-										UDSAnswer.Data[3] = UDSService[i];
-										UDSAnswer.Data[4] = 0xEE;  //the sub service is not surported
-										UDSAnswer.Data[5] = 0x00;
-										UDSAnswer.Data[6] = 0x00;
-										UDSAnswer.Data[7] = 0x00;
-										ret = HAL_Can_Transmit(UDSAnswer);
-									}
-								}
-								else	//当前会话模式错误
-								{
-									UDSAnswer.Id = 0x7A8;
-									UDSAnswer.DLC = 8;
-									UDSAnswer.Data[0] = 0x05;
-									UDSAnswer.Data[1] = 0x7F;
-									UDSAnswer.Data[2] = UDSCmd[i];
-									UDSAnswer.Data[3] = UDSService[i];
-									UDSAnswer.Data[4] = 0xFF;
-									UDSAnswer.Data[5] = 0x00;
-									UDSAnswer.Data[6] = 0x00;
-									UDSAnswer.Data[7] = 0x00;
-									ret = HAL_Can_Transmit(UDSAnswer);
-								}
-								break;
-							case 0x2E:
-								if(UDSSwitch == 1)
-								{
-									if(UDSService[i] == 0x03)
-									{
-										if(CanRxMsg[i].Data[2] == 0x00 && snFlag == 0x00)
-										{
-											for(j=0; j<5; j++)
-											{
-												UDSBattSN[j+5*0] = CanRxMsg[i].Data[j+3];
-											}	
-											snFlag = snFlag|0x01;
-										}
-										else if(CanRxMsg[i].Data[2] == 0x01 && snFlag == 0x01)
-										{
-											for(j=0; j<5; j++)
-											{
-												UDSBattSN[j+5*1] = CanRxMsg[i].Data[j+3];
-											}
-											snFlag = snFlag|0x02;
-										}
-										else if(CanRxMsg[i].Data[2] == 0x02 && snFlag == 0x03)
-										{
-											for(j=0; j<5; j++)
-											{
-												UDSBattSN[j+5*2] = CanRxMsg[i].Data[j+3];
-											}
-											snFlag = snFlag|0x04;
-										}
-										else if(CanRxMsg[i].Data[2] == 0x03 && snFlag == 0x07)
-										{
-											for(j=0; j<2; j++)
-											{
-												UDSBattSN[j+5*3] = CanRxMsg[i].Data[j+3];
-											}
-											snFlag = snFlag|0x08;
-										}
-
-										if(snFlag == 0x0F)
-										{
-											UDSAnswer.Id = 0x7A8;
-											UDSAnswer.DLC = 8;
-											UDSAnswer.Data[0] = 0x04;
-											UDSAnswer.Data[1] = 0x78;
-											UDSAnswer.Data[2] = UDSCmd[i];
-											UDSAnswer.Data[3] = UDSService[i];
-											UDSAnswer.Data[4] = 0x00;
-											UDSAnswer.Data[5] = 0x00;
-											UDSAnswer.Data[6] = 0x00;
-											UDSAnswer.Data[7] = 0x00;
-											snFlag = 0;
-											for(j=0; j<BATT_SN_LEN; j++)
-											{
-												BattSN[j] = UDSBattSN[j];
-											}
-										}
-										else
-										{
-											UDSAnswer.Id = 0x7A8;
-											UDSAnswer.DLC = 8;
-											UDSAnswer.Data[0] = 0x05;
-											UDSAnswer.Data[1] = 0x3E;
-											UDSAnswer.Data[2] = UDSCmd[i];
-											UDSAnswer.Data[3] = UDSService[i];
-											UDSAnswer.Data[4] = snFlag;	
-											UDSAnswer.Data[5] = 0x00;
-											UDSAnswer.Data[6] = 0x00;
-											UDSAnswer.Data[7] = 0x00;
-										}
-										ret = HAL_Can_Transmit(UDSAnswer);
-									}
-									else
-									{
-										UDSAnswer.Id = 0x7A8;
-										UDSAnswer.DLC = 8;
-										UDSAnswer.Data[0] = 0x05;
-										UDSAnswer.Data[1] = 0x7F;
-										UDSAnswer.Data[2] = UDSCmd[i];
-										UDSAnswer.Data[3] = UDSService[i];
-										UDSAnswer.Data[4] = 0xEE;			//the sub service is not surported
-										UDSAnswer.Data[5] = 0x00;
-										UDSAnswer.Data[6] = 0x00;
-										UDSAnswer.Data[7] = 0x00;
-										ret = HAL_Can_Transmit(UDSAnswer);
-									}
-									break;
-								}
-								else
-								{
-									UDSAnswer.Id = 0x7A8;
-									UDSAnswer.DLC = 8;
-									UDSAnswer.Data[0] = 0x05;
-									UDSAnswer.Data[1] = 0x7F;
-									UDSAnswer.Data[2] = UDSCmd[i];
-									UDSAnswer.Data[3] = UDSService[i];
-									UDSAnswer.Data[4] = 0xFF;				//the dialog mode error
-									UDSAnswer.Data[5] = 0x00;
-									UDSAnswer.Data[6] = 0x00;
-									UDSAnswer.Data[7] = 0x00;
-									ret = HAL_Can_Transmit(UDSAnswer);
-								}
-									break;
-							default:
-								UDSAnswer.Id = 0x7A8;
-								UDSAnswer.DLC = 8;
-								UDSAnswer.Data[0] = 0x04;
-								UDSAnswer.Data[1] = 0x7F;
-								UDSAnswer.Data[2] = UDSCmd[i];	//the serviece is not surpoted
-								UDSAnswer.Data[3] = 0xFF;
-								UDSAnswer.Data[4] = 0x00;				
-								UDSAnswer.Data[5] = 0x00;
-								UDSAnswer.Data[6] = 0x00;
-								UDSAnswer.Data[7] = 0x00;
-								ret = HAL_Can_Transmit(UDSAnswer);
-								break;
-								
-						}
-
-					}
-
-
-				}
-			}
-
-	//}
-	for(i=0; i<2; i++)
-	{
-		UDSCmd[i] = 0;
-		UDSService[i] = 0;
-	}
-
-}
-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;
-}
-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;
-            rcvInd = (TcpipConnectionRecvDataInd *)bodyEvent;
-            if(rcvInd != PNULL)
-            {
-                uint8_t* Ptr;
-                #ifdef USING_PRINTF
-                
-                    Ptr=rcvInd->data;
-                    printf("socketAppConnectionCallBack socket connection %u receive length %u data:", rcvInd->connectionId, rcvInd->length);
-                    for(int i = 0;i<rcvInd->length;i++)
-                        printf("%x  ",*(Ptr+i));
-                #endif
-                Tcp_Recv_info(Ptr);//Tcp 接收
-                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;
-    }
-    
-}
-void Tcp_Recv_fota(uint8_t* P)
-{
-    Fota_S.Fota_Flash_Addres = 0x2A0000;
-    uint8_t Fota_Crc = 00;
-    uint8_t send_temp[10];
-    uint8_t temp[1];
-    #ifdef USING_PRINTF
-        printf("fota data handle\n");
-    #endif
-    if(*(P+3)==0x01)
-    {
-        Fota_S.Fota_All_Data_Len = *(P+4)<<24|*(P+5)<<16|*(P+6)<<8|*(P+7);
-        send_temp[0]=0x82;
-        send_temp[1]=0x01;
-        memcpy(Tcp_Send_anwser_buffer,send_temp,2);
-    }
-    else if(*(P+3)==0x02)
-    {
-        Fota_S.Fota_Current_Addres = *(P+8)<<24|*(P+9)<<16|*(P+10)<<8|*(P+11);
-        Fota_S.Fota_Recv_Data_Len = *(P+12);
-        memcpy(Fota_S.Fota_Recv_Data,(P+13),*(P+12));
-        Fota_Crc = Fota_crc_chk(Fota_S.Fota_Recv_Data,Fota_S.Fota_Recv_Data_Len);
-        #ifdef USING_PRINTF
-            printf("Crc:%x,%x!,data_len:%d\n",Fota_Crc,*(P+Fota_S.Fota_Recv_Data_Len+13),Fota_S.Fota_Recv_Data_Len);
-        #endif
-        if(Fota_Crc==*(P+Fota_S.Fota_Recv_Data_Len+13))
-        {
-            BSP_QSPI_Erase_Safe(Fota_S.Fota_Flash_Addres+Fota_S.Fota_Current_Addres,Fota_S.Fota_Recv_Data_Len);
-            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);
-            send_temp[0]=0x82;
-            send_temp[1]=0x01;
-            memcpy(Tcp_Send_anwser_buffer,send_temp,2);
-        }
-    }
-    else if(*(P+3)==0x03)
-    {
-        send_temp[0]=0x82;
-        send_temp[1]=0x01;
-        memcpy(Tcp_Send_anwser_buffer,send_temp,2);
-        #ifdef USING_PRINTF
-            printf("Done!\n");
-        #endif
-        close(socContext.id);
-        appSetCFUN(0);
-        #ifdef USING_PRINTF
-            for(int i=0;i<Fota_S.Fota_All_Data_Len;i++)
-            {
-                BSP_QSPI_Read_Safe(temp,Fota_S.Fota_Flash_Addres+i,1);
-                printf("%X ",temp[0]);
-            }
-        #endif
-        osDelay(5000);
-        EC_SystemReset();
-    }
-    #ifdef USING_PRINTF
-        printf("updating\n");
-    #endif
-}
-void Tcp_Recv_info(uint8_t* P)
-{
-    uint8_t send_temp[10],switch_flag;
-    int len;
-    #ifdef USING_PRINTF
-        printf("P0:0x%x !\n",*(P+0));
-        printf("P1:0x%x !\n",*(P+1));
-        printf("P2:0x%x !\n",*(P+2));
-    #endif
-    switch_flag = *(P+0);
-    #ifdef USING_PRINTF
-        printf("switch_flag:%x !\n",switch_flag);
-    #endif
-    switch(switch_flag)
-    {
-        case 0x80://查询
-            Tcp_serviece=01;
-            if(*(P+2)==0x08)
-            {
-                send_temp[0] = 0x80;
-                send_temp[1] = 0x01;
-                send_temp[2] = 0x08;
-                send_temp[3] = 0x02;
-                memcpy(Tcp_Send_anwser_buffer,send_temp,4);
-            }
-            break;
-        case 0x82://控制
-            Tcp_serviece=01;
-            if(*(P+2)==0x01)
-            {
-                Fota_S.Fota_update_flag=true;
-                Tcp_Recv_fota(P);    
-            }
-            break;
-        default:
-            P = NULL;
-            Tcp_serviece=00;
-            break;
-    }
-}
-uint8_t Fota_crc_chk(uint8_t* data,uint8_t length)
-{  
-    uint8_t reg_crc=0x00;
-    while(length--)
-    { 
-        reg_crc ^= *data++;
-    }
-    return reg_crc;
-}
-void Tcp_Send_anwser()
-{
-    int len;
-    len = tcpipConnectionSend(socContext.id, Tcp_Send_anwser_buffer, 10, 0, 0, 0);
-    if(len > 0)
-    {
-        #ifdef USING_PRINTF
-            printf("connection %u send anwser len %u success\n", socContext.id, len);
-        #endif
-    }
-    #ifdef USING_PRINTF
-        printf("connection %u send anwser len %u end\n", socContext.id, len);
-    #endif
-    Tcp_serviece=00;
-}
-void Tcp_Send_info()
-{
-    static UINT8 send_counter=0;   
-    int len;
-    uint8_t send_temp[10];
-    if(send_counter%1==0)
-    {
-        send_temp[0] = 0x02;
-        send_temp[1] = 0x00;
-        send_temp[2] = 0x80;
-        len = tcpipConnectionSend(socContext.id, send_temp, 3, 0, 0, 0);
-    }
-    if(send_counter%6==0)
-    {
-        send_temp[0] = 0x01;
-        send_temp[1] = 0x00;
-        len = tcpipConnectionSend(socContext.id, send_temp, 2, 0, 0, 0);
-    }
-    if(send_counter>=6*10+1)
-    {
-        send_counter=1;
-    }
-    else 
-    {
-        send_counter++;
-    }
-    if(len > 0)
-    {
-        #ifdef USING_PRINTF
-            printf("connection %u send len %u success\n", socContext.id, len);
-        #endif
-        ECOMM_TRACE(UNILOG_PLA_APP, ecTestCaseTcpClient_7, P_INFO, 2, "connection %u send len %u success", socContext.id, len);  
-    }
-    else
-    {
-        #ifdef USING_PRINTF
-            printf("connection %u sent data fail\n", socContext.id);
-        #endif
-        ECOMM_TRACE(UNILOG_PLA_APP, ecTestCaseTcpClient_8, P_ERROR, 1, "connection %u sent data fail", socContext.id);
-    }
-}
-static void Tcp_Task(void* arg)
-{
-    uint16 send_counter;
-    eventCallbackMessage_t *queueItem = NULL;
-    appSetEDRXSettingSync(0,5,1800000);
-    appSetPSMSettingSync(1,3*60*60,10);
-    CHAR   APP_SOCKET_DAEMON_SERVER_IP[] = "120.26.68.165";
-    uint16_t   APP_SOCKET_DAEMON_SERVER_PORT = 14319;
-    INT32 connectionId = -1;
-    INT32 len;
-    UINT8 data[8] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};
-    psEventQueueHandle = xQueueCreate(APP_EVENT_QUEUE_SIZE, sizeof(eventCallbackMessage_t*));
-    if (psEventQueueHandle == NULL)
-    {
-        return;
-    }
-    appSetCFUN(1);
-    while(1){
-        if (xQueueReceive(psEventQueueHandle, &queueItem, portMAX_DELAY))
-        {
-            #ifdef USING_PRINTF
-                //printf("Queue receive->0x%x\n", queueItem->messageId);
-            #endif
-            switch(queueItem->messageId)
-            {
-                case QMSG_ID_NW_IP_READY:
-                    connectionId = tcpipConnectionCreate(TCPIP_CONNECTION_PROTOCOL_TCP, PNULL, 0, APP_SOCKET_DAEMON_SERVER_IP, APP_SOCKET_DAEMON_SERVER_PORT, socketAppConnectionCallBack);
-                    if(connectionId >= 0)
-                    {
-                        socContext.id = connectionId;
-                        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
-                    {
-                        #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:
-                    break;
-                case QMSG_ID_SOCK_SENDPKG:
-                    if (socContext.id >= 0 && socContext.status == APP_SOCKET_CONNECTION_CONNECTED)
-                    {
-                        if(Tcp_serviece==0)
-                        {
-                            Tcp_Send_info();
-                        }
-                        else if(Tcp_serviece==1)
-                        {
-                            Tcp_Send_anwser();
-                        }
-                        #ifdef USING_PRINTF
-                            printf("QMSG_ID_SOCK_SENDPKG Running\n");
-                        #endif
-                    }
-                    else
-                    {
-                        #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_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("socket disconnect\n");
-                    #endif
-                    if (socContext.id >= 0)
-                    {
-                       close(socContext.id);
-                    }
-                    appSetCFUN(0);
-                    free(queueItem);
-                    osThreadExit();
-            }
-            free(queueItem);
-        }
-    }
-}
-//主任务线程初始化
-void Main_Task_Init()
-{
-    #ifndef USING_PRINTF
-    if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
-    {
-        HAL_UART_RecvFlowControl(false);
-    }
-    #endif
-    osThreadAttr_t task_attr;
-    memset(&task_attr,0,sizeof(task_attr));
-    memset(gProcess_Main_TaskStack, 0xA5, PROC_MAIN_TASK_STACK_SIZE);
-    task_attr.name = "Main_Task";
-    task_attr.stack_mem = gProcess_Main_TaskStack;
-    task_attr.stack_size = PROC_MAIN_TASK_STACK_SIZE;
-    task_attr.priority = osPriorityNormal;
-    task_attr.cb_mem = &gProcess_Main_Task_t;
-    task_attr.cb_size = sizeof(StaticTask_t);
-    osThreadNew(Main_Task, NULL, &task_attr);
-}
-//Uart线程初始化
-void Uart_Task_Init()
-{
-    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);
-    osThreadNew(Uart_Task, NULL, &task_attr);
-}
-//CAN 线程初始化
-void Can_Task_Init()
-{
-    osThreadAttr_t task_rx_attr,task_tx_attr;
-    Can_InitType param;
-    param.baudrate = CAN_250Kbps;
-	param.mode = REQOP_NORMAL;
-    param.RxStdIDH[0] = 0x00;
-    param.RxStdIDL[0] = 0x00;
-    /*stdid 0000 0000 001x*/
-    param.RxStdIDH[1] = 0x00;
-    param.RxStdIDL[1] = 0x20;
-    /*stdid 0000 0000 010x */
-    param.RxStdIDH[2] = 0x00;
-    param.RxStdIDL[2] = 0x40;
-    /*stdid 0000 0000 011x*/
-    param.RxStdIDH[3] = 0x00;
-    param.RxStdIDL[3] =0x60;
-    /*stdid 0000 0000 100x */
-    param.RxStdIDH[4] = 0x00;
-    param.RxStdIDL[4] = 0x80;
-    /*stdid 0000 0000 101x*/
-    param.RxStdIDH[5] = 0xA0;
-    param.RxStdIDL[5] =0x00;
-	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_Receive_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_Task, NULL, &task_rx_attr);
-}
-//Tcp线程初始化
-void Tcp_Task_Init()
-{
-    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);
-    osThreadNew(Tcp_Task, NULL, &task_attr);
-}
-
-//Gps线程初始化
-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 = osPriorityBelowNormal7;
-		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(GpsProcess , NULL,&task_attr);
-		if(gpsTaskHandle == NULL)
-			return 1;
-	}
-	return 0;
-}
 void appInit(void *arg)
 {
-    Main_Task_Init();
-    Uart_Task_Init();
-    Can_Task_Init();
-    Tcp_Task_Init();
-    Gps_Task_Init();
+    #ifdef USING_PRINTF	
+    	printf("%s[%d]\r\n",__FUNCTION__, __LINE__);
+    #endif
+    MainTaskInit(arg);
 }
 //主函数入口
 void main_entry(void) 

+ 1 - 1
src/bsp_custom.c

@@ -150,7 +150,7 @@ void BSP_CustomInit(void)
     BSP_LoadPlatConfigFromRawFlash();
     rawFlashPlatConfig = BSP_GetRawFlashPlatConfig();
 #ifdef USING_PRINTF
-	SetPrintUart(PORT_USART_1);
+	SetPrintUart(PORT_USART_0);
 #else
     if(rawFlashPlatConfig && (rawFlashPlatConfig->logControl != 0 ))
     {