Browse Source

大版改动:增加网络休眠,增加malloc动态申请内存,增加串口一次性接收,减少变量,数据拆分完成

CHENJIE-PC\QiXiang_CHENJIE 4 years ago
parent
commit
ecad344072
1 changed files with 171 additions and 242 deletions
  1. 171 242
      app.c

+ 171 - 242
app.c

@@ -29,23 +29,18 @@
 
 //define
 // app task static stack and control block
-#define PROC_TASK_STACK_SIZE    (1024)
+#define PROC_TASK_STACK_SIZE    (1536)
 
 
 //uart def
 #define Uart_Send_LEN         (8)
-#define Uart_Rece_LEN         (16)
+#define Uart_Rece_LEN         (40)//串口读取的最大数量,40个字节,能满足一次性读取17个单体
 #define RTE_UART_RX_IO_MODE      RTE_UART1_RX_IO_MODE
 
 //statement variable
 extern ARM_DRIVER_USART Driver_USART1;
 static ARM_DRIVER_USART *USARTdrv = &Driver_USART1;
 
-/** \brief usart receive buffer */
-uint8_t Uart_Data_buffer[8];
-
-/** \brief usart send buffer */
-
 /** \brief receive timeout flag */
 volatile bool isRecvTimeout = false;
 
@@ -57,22 +52,24 @@ uint8_t process1SlpHandler     = 0xff;
 uint8_t process2SlpHandler     = 0xff;
 uint8_t deepslpTimerID         = 7;
 
-/** \brief 电压传输 */
-
-uint8_t Uart_Rece_BattCellU1_U4[8];
-uint8_t Uart_Rece_BattCellU5_U8[8];
-uint8_t Uart_Rece_BattCellU9_U12[8];
-uint8_t Uart_Rece_BattCellU13_U14[8];
-uint8_t Uart_Rece_BattT[8];
-int16_t Uart_Rece_BattI=0x0000;
-uint8_t Uart_Rece_Batt_states[6];
-uint16_t Uart_Rece_BattU;
-uint16_t Uart_Rece_Batt_MaxcellU;
-uint16_t Uart_Rece_Batt_MincellU;
 uint8_t Can_Rece_buffer[8];
-
-uint8_t battbuffer[67];
+uint16_t Batt_Cell_Num = 14;//默认数值
+uint16_t Batt_Cell_Num_2 ;//默认数值
+uint16_t Batt_Temp_Num = 5;//默认数值
+int16_t Uart_Rece_BattI;
+uint8_t battbuffer[73];//电池数据都存在此数组中————电压14,温度5
+/**
+ *  存放规则如下:
+ * 位置:   0       1       2       3       4       5       6       7       8       9       10      11      12      13      14      15              16             
+ * 数据:   年      月      日      时      分      秒    信息体标志  年      月      日      时      分       秒    网络信号  故障等级  故障代码高     故障代码低
+ * 
+ *         17      18       19          20          21          22         23       24      25      26 27 28 29   30       30+1 .... 30+X*2      31+X*2       31+1...31+X*2+N
+ *         电流H    电流L  Link电压H    Link电压L   Pack电压H   Pack电压L   开关状态   SOC     SOH    均衡状态      单体个数X    单体v1...单体vX   温度个数N     温度1..温度N    
+ *          32+X*2+N     33+X*2+N 
+ *          电池状态    是否加热
+ * */
 uint16_t data_index = 0x0000;
+
 typedef enum
 {
     PROCESS_STATE_IDLE = 0,
@@ -111,6 +108,7 @@ process_NB	    gProc3State = PROCESS_NB_STATE_IDLE;
 #define PROC_Can_STATE_SWITCH(a)  (gProc2State = a) //can 状态切换
 #define PROC_NB_STATE_SWITCH(a)  (gProc3State = a) //NB状态切换
 
+//-------------------------------------------------------------------------------------------------------------------------------------------------------
 unsigned int crc_chk(uint8_t* data, uint8_t length)
 {  
     int j;
@@ -132,10 +130,9 @@ unsigned int crc_chk(uint8_t* data, uint8_t length)
     }
     return reg_crc;
 }
-uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg)
+uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t *Uart_Rece_buffer)
 {
-    uint8_t Uart_Rece_buffer[Uart_Rece_LEN];
-    uint16_t CRC_Reve_buffer;
+    uint16_t CRC_Rece_buffer;
     uint16_t CRC_chk_buffer;
     uint8_t Uart_Send_buffer[8];
     uint8_t Rece_Data_Len;
@@ -148,11 +145,10 @@ uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg)
     CRC_chk_buffer = crc_chk(Uart_Send_buffer,6);
     Uart_Send_buffer[6] = CRC_chk_buffer;
     Uart_Send_buffer[7] = CRC_chk_buffer>>8;
-    Uart_Rece_buffer[0]=0xfe;
     uint32_t timeout=0;
     USARTdrv->Send(Uart_Send_buffer,8);
-    USARTdrv->Receive(Uart_Rece_buffer,13);
-    Rece_Data_Len = 11;
+    Rece_Data_Len = Uart_Receive_Msg.Reg_Num_L<<1;//读取几个寄存器的值,数据长度乘以二
+    USARTdrv->Receive(Uart_Rece_buffer,Rece_Data_Len+5);
     while((isRecvTimeout == false) && (isRecvComplete == false))// 未收到数据不叫时间超时,收到数据但是不全叫时间超时
     {
         timeout++;
@@ -163,42 +159,44 @@ uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg)
             break;
         }
     }
+    Rece_Data_Len = *(Uart_Rece_buffer+2);
+
+    // #ifdef USING_PRINTF
+    //     for(int i=0;i<8;i++)
+    //     {
+    //     printf("%x ",Uart_Send_buffer[i]);
+    //     }
+    //     printf("\n");
+    //     for(int i=0;i<Rece_Data_Len+5;i++)
+    //     {
+    //     printf("%x ",*(Uart_Rece_buffer+i));
+    //     }
+    //     printf("\n");
+    // #endif
     if (isRecvComplete == true)
     {
         isRecvComplete = false;
-        CRC_chk_buffer =Uart_Rece_buffer[12]<<8|Uart_Rece_buffer[11];
-        CRC_Reve_buffer = crc_chk(Uart_Rece_buffer,11);
-        if (CRC_Reve_buffer == CRC_chk_buffer)//满足校验
+        CRC_Rece_buffer =*(Uart_Rece_buffer+Rece_Data_Len+4)<<8|*(Uart_Rece_buffer+Rece_Data_Len+3);
+        CRC_chk_buffer = crc_chk(Uart_Rece_buffer,Rece_Data_Len+3);
+
+        if (CRC_Rece_buffer == CRC_chk_buffer)//满足校验
         {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=Uart_Rece_buffer[i+3];
-            }
-            return Uart_Data_buffer;
+            return Uart_Rece_buffer+3;
         }
         else //接收数据的校验不过暂时屏蔽
         {
-            for (uint8_t i = 0; i < 8; i++)
-            {
-                Uart_Data_buffer[i]=0xff;
-            }
-            return Uart_Data_buffer;
+            memset(Uart_Rece_buffer,0xff,Uart_Rece_LEN);
+            return Uart_Rece_buffer;
         }
     }
     if (isRecvTimeout == true)//没收到数据,全部为空值
     {
-        Uart_Data_buffer[0] = 0x00;
-        Uart_Data_buffer[1] = 0x00;
-        Uart_Data_buffer[2] = 0x00;
-        Uart_Data_buffer[3] = 0x00;
-        Uart_Data_buffer[4] = 0x00;
-        Uart_Data_buffer[5] = 0x00;
-        Uart_Data_buffer[6] = 0x00;
-        Uart_Data_buffer[7] = 0xff;
+        memset(Uart_Rece_buffer,0x00,Uart_Rece_LEN);
         isRecvTimeout = false;
         osDelay(1000);
-        return Uart_Data_buffer;
+        return Uart_Rece_buffer;
     }
+    return Uart_Rece_buffer;
 }
 void USART_callback(uint32_t event)
 {
@@ -214,18 +212,15 @@ void USART_callback(uint32_t event)
 
 static void process0AppTask(void* arg)
 {
-    uint32_t inParam = 0xAABBCCDD;
-    uint32_t cnt;
     UINT8 Can_index = 0;
     UINT8 Uart_index = 0;
     uint32_t sleep_index = 0;
     PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
-    NetSocDisplay(0,LED_TURN_OFF);
-    NetSocDisplay(1,LED_TURN_OFF);
-    NetSocDisplay(2,LED_TURN_OFF);
-    NetSocDisplay(3,LED_TURN_OFF);
-    NetSocDisplay(4,LED_TURN_OFF);
-
+    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);
 
     slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
     slpManApplyPlatVoteHandle("process0slp",&process0SlpHandler);
@@ -247,7 +242,7 @@ static void process0AppTask(void* arg)
             case PROCESS_STATE_IDLE:
             {   
                 PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_CHECK);
-                NetSocDisplay(0,LED_TURN_ON);
+                NetSocDisplay(LED_SOC_0,LED_TURN_ON);
                 osDelay(100);//delay 100ms
                 if(Uart_Rece_BattI!=0x0000)
                 {
@@ -256,7 +251,7 @@ static void process0AppTask(void* arg)
                 sleep_index++;
                 if(sleep_index>=100)
                 {
-                    NetSocDisplay(0,LED_TURN_OFF);
+                    NetSocDisplay(LED_SOC_0,LED_TURN_OFF);
                     sleep_index=0;
                     PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
                 }
@@ -275,7 +270,7 @@ static void process0AppTask(void* arg)
                 if (Can_index >=100)//Can 1000ms 调用一次
                 {
                     PROC_Can_STATE_SWITCH(PROCESS_STATE_WORK);
-                    PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_CONNECT);
+                    PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_WORK);
                     Can_index = 0;
                 }
                 if((Uart_Rece_BattI==0x0000)&&(Can_Rece_buffer[0]==0xff))
@@ -287,7 +282,7 @@ static void process0AppTask(void* arg)
                     sleep_index = 0;
                 }
 
-                if (sleep_index >=6000)
+                if (sleep_index >=60000)
                 {
                     PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
                     sleep_index = 0;
@@ -297,9 +292,7 @@ static void process0AppTask(void* arg)
             }
             case PROCESS_STATE_SLEEP:
             {
-
-                slpManSlpState_t State;
-                uint8_t cnt;
+                PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_SLEEP);
                 PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_SLEEP);
                 PROC_Can_STATE_SWITCH(PROCESS_STATE_SLEEP);
                 slpManPlatVoteEnableSleep(process0SlpHandler,SLP_SLP2_STATE);
@@ -327,125 +320,125 @@ static void process1AppTask(void* arg)
     uint8_t *Uart_Reve_Point = NULL;
     Uart_Receive_Type Uart_Receive_Msg;
 	PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
-    slpManPlatVoteDisableSleep(process2SlpHandler, SLP_SLP2_STATE);
     Uart_Receive_Msg.Bms_Address = 0x01;
     Uart_Receive_Msg.Bms_Read_Funcode = 0x03;
+    uint8_t *Uart_Rece_buffer;
+    Batt_Cell_Num_2 = Batt_Cell_Num<<1;
     while(1)
     {
         switch(gProc1State)
         {
             case PROCESS_Uart_STATE_IDLE:
             {   
-                NetSocDisplay(1,LED_TURN_OFF);     
+                NetSocDisplay(LED_SOC_1,LED_TURN_OFF);     
                 Rece_index = 0;
-                
                 break;
             }
-            case PROCESS_Uart_STATE_CHECK:
+            case PROCESS_Uart_STATE_CHECK://检查电流数值
             {
+                #ifdef USING_PRINTF
+                        printf("监测电流:%x\n ");
+                #endif
                 Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                Uart_Receive_Msg.Reg_Begin_L= 0x10;
+                Uart_Receive_Msg.Reg_Begin_L= 0x02+Batt_Cell_Num;
                 Uart_Receive_Msg.Reg_Num_H = 0x00;
-                Uart_Receive_Msg.Reg_Num_L = 0x04;
-                Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
+                Uart_Receive_Msg.Reg_Num_L = 0x01;
+                Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
+                Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 |*(Uart_Reve_Point+1);
                 PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
                 break;
             }
             case PROCESS_Uart_STATE_WORK:
             {
-                NetSocDisplay(1,LED_TURN_ON);
+                NetSocDisplay(LED_SOC_1,LED_TURN_ON);
+                Uart_Rece_buffer = (uint8_t *)malloc(Uart_Rece_LEN);
+                memset(Uart_Rece_buffer,0xff,Uart_Rece_LEN);
                 switch(Rece_index)
                 {
-                    case 0://读取电压1-4
+                    case 0://读取电
                     {
                         Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L = 0x02;
+                        Uart_Receive_Msg.Reg_Begin_L= 0x02+Batt_Cell_Num;
                         Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU1_U4[i] = *(Uart_Reve_Point+i);
-                        }
+                        Uart_Receive_Msg.Reg_Num_L = 0x01;
+                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
+                        Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 |*(Uart_Reve_Point+1);
+                        battbuffer[17] = *(Uart_Reve_Point+0);
+                        battbuffer[18] = *(Uart_Reve_Point+1);
                         break;
                     }
-                    case 1://读取电压5-8
+                    case 1://读取单体电压
                     {
                         Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x06;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU5_U8[i] = *(Uart_Reve_Point+i);
-                        }
-                        break;
-                    }
-                    case 2:
-                    {
-                        Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0A;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattCellU9_U12[i] = *(Uart_Reve_Point+i);
-                        }
+                        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;
+                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
+                        // #ifdef USING_PRINTF
+                        //     for (size_t i = 0; i < Batt_Cell_Num_2; i++)
+                        //     {
+                        //         printf("%x ",*(Uart_Reve_Point+i));
+                        //     }
+                        //     printf("\n");
+                        // #endif
+                        battbuffer[30] = Batt_Cell_Num;
+                        memcpy(&battbuffer[31],Uart_Reve_Point,Batt_Cell_Num_2);
                         break;
                     }
-                    case 3:
+                    case 2://读取温度
                     {
                         Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x0E;
-                        Uart_Receive_Msg.Reg_Num_H = 0x00;
-                        Uart_Receive_Msg.Reg_Num_L = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
+                        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;
+                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
+                        battbuffer[31+Batt_Cell_Num_2] = Batt_Temp_Num;
+                        for (int i = 0; i < Batt_Temp_Num; i++)
                         {
-                            Uart_Rece_BattCellU13_U14[i] = *(Uart_Reve_Point+i);
+                            battbuffer[32+Batt_Cell_Num_2+i] = *(Uart_Reve_Point+2*i+1);
                         }
+                        // #ifdef USING_PRINTF
+                        //     for (size_t i = 0; i < Batt_Temp_Num; i++)
+                        //     {
+                        //         printf("%x ",*(Uart_Reve_Point+i));
+                        //     }
+                        //     printf("\n");
+                        // #endif
                         break;
                     }
-                    case 4:
+                    case 3://读取总电压,目前保护板只有一个电压
                     {
                         Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x14;
+                        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 = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        for(int i =0;i<8;i++)
-                        {
-                            Uart_Rece_BattT[i] = *(Uart_Reve_Point+i);
-                        }
+                        Uart_Receive_Msg.Reg_Num_L = 0x01;
+                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
+                        battbuffer[19] = *(Uart_Reve_Point+0);//Link U
+                        battbuffer[20] = *(Uart_Reve_Point+1);
+                        battbuffer[21] = *(Uart_Reve_Point+0);//Pack U
+                        battbuffer[22] = *(Uart_Reve_Point+1);
                         break;
                     }
-                    case 5:
+                    case 4://读取状态及SOC
                     {
                         Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x10;
+                        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;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        for (int i = 0; i < 6; i++)
-                        {
-                            Uart_Rece_Batt_states[i] = *(Uart_Reve_Point+2+i);
-                        }
+                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
+                        battbuffer[23] = *(Uart_Reve_Point+0)>>1;//mos状态
+                        battbuffer[24] = *(Uart_Reve_Point+5);//SOC
+                        battbuffer[25] = *(Uart_Reve_Point+7);//SOH
                         break;
                     }
-                    case 6:
+                    case 5://读取均衡状态
                     {
                         Uart_Receive_Msg.Reg_Begin_H = 0x00;
-                        Uart_Receive_Msg.Reg_Begin_L= 0x2B;
+                        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 = 0x04;
-                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg);
-                        Uart_Rece_BattU = *(Uart_Reve_Point+0)<<8 | *(Uart_Reve_Point+1);
-                        Uart_Rece_Batt_MaxcellU = *(Uart_Reve_Point+2)<<8 | *(Uart_Reve_Point+3);
-                        Uart_Rece_Batt_MincellU = *(Uart_Reve_Point+4)<<8 | *(Uart_Reve_Point+5);
+                        Uart_Receive_Msg.Reg_Num_L = 0x02;
+                        Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
+                        memcpy(&battbuffer[26],Uart_Reve_Point,4);
                         break;
                     }
                     default:
@@ -454,13 +447,12 @@ static void process1AppTask(void* arg)
                         break;
                     }
                 }
+                free(Uart_Rece_buffer);
                 Rece_index++;
                 break;
             }
             case PROCESS_Uart_STATE_SLEEP:
-            {	
-                slpManPlatVoteEnableSleep(process2SlpHandler, SLP_SLP2_STATE);  
-                slpManPlatVoteDisableSleep(process2SlpHandler, SLP_HIB_STATE);  
+            {	 
                 while(1)
                 {
                     osDelay(3000);
@@ -502,7 +494,6 @@ static void process2AppTask(void* arg)
     param.packType = STD_PACK;
     HAL_Can_Init(param);
     int send_index = 0;
-    slpManPlatVoteDisableSleep(process1SlpHandler, SLP_SLP2_STATE);
     while(1)
     {
         switch(gProc2State)
@@ -522,12 +513,11 @@ static void process2AppTask(void* arg)
                         Can_ID = 0x001;
                         for (int i = 0; i < 8; i++)
                         {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU1_U4[i];
+                            Can_TxMsg.Data[i] = battbuffer[i+31+send_index*8];
                         }
                         Can_TxMsg.stdIDH = Can_ID>>3;
                         Can_TxMsg.stdIDL = Can_ID<<5;
                         Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
                         break;
                     }
                     case 1:
@@ -535,12 +525,11 @@ static void process2AppTask(void* arg)
                         Can_ID = 0x013;
                         for (int i = 0; i < 8; i++)
                         {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU5_U8[i];
+                            Can_TxMsg.Data[i] = battbuffer[i+31+send_index*8];
                         }
                         Can_TxMsg.stdIDH = Can_ID>>3;
                         Can_TxMsg.stdIDL = Can_ID<<5;
                         Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
                         break;
                     }
                     case 2:
@@ -548,12 +537,11 @@ static void process2AppTask(void* arg)
                         Can_ID = 0x021;
                         for (int i = 0; i < 8; i++)
                         {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU9_U12[i];
+                            Can_TxMsg.Data[i] = battbuffer[i+31+send_index*8];
                         }
                         Can_TxMsg.stdIDH = Can_ID>>3;
                         Can_TxMsg.stdIDL = Can_ID<<5;
                         Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
                         break;
                     }
                     case 3:
@@ -561,7 +549,7 @@ static void process2AppTask(void* arg)
                         Can_ID = 0x031;
                         for (int i = 0; i < 4; i++)
                         {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattCellU13_U14[i];
+                            Can_TxMsg.Data[i] = battbuffer[i+31+send_index*8];
                         }
                         Can_TxMsg.Data[4] = 0x00;
                         Can_TxMsg.Data[5] = 0x00;
@@ -570,71 +558,44 @@ static void process2AppTask(void* arg)
                         Can_TxMsg.stdIDH = Can_ID>>3;
                         Can_TxMsg.stdIDL = Can_ID<<5;
                         Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
                         break;
                     }
                     case 4:
                     {
                         Can_ID  = 0x101;
                         for (int i = 0; i < 4; i++)
-                        {
-                            Can_TxMsg.Data[i] = Uart_Rece_BattT[i*2+1];
+                        { 
+                            Can_TxMsg.Data[2*i] = 0x00;
+                            Can_TxMsg.Data[2*i+1] = battbuffer[i+32+Batt_Cell_Num_2];
                         }
                         Can_TxMsg.stdIDH = Can_ID>>3;
                         Can_TxMsg.stdIDL = Can_ID<<5;
                         Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
                         break;
                     }
-                    case 5:
-                    {
-                        Can_ID = 0x201;
-                        Can_TxMsg.Data[0] = Uart_Rece_BattU>>8;
-                        Can_TxMsg.Data[1] = Uart_Rece_BattU;
-                        Can_TxMsg.Data[2] = 0x00;
-                        Can_TxMsg.Data[3] = 0x00;//外电压
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;//累加电压
-                        Can_TxMsg.Data[6] = Uart_Rece_BattI>>8;
-                        Can_TxMsg.Data[7] = Uart_Rece_BattI;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-
-                    }
-                    case 6:
-                    {
-                        Can_ID = 0x211;
-                        Can_TxMsg.Data[0] = Uart_Rece_Batt_MaxcellU>>8;
-                        Can_TxMsg.Data[1] = Uart_Rece_Batt_MaxcellU;
-                        Can_TxMsg.Data[2] = Uart_Rece_Batt_MincellU>>8;
-                        Can_TxMsg.Data[3] = Uart_Rece_Batt_MincellU;
-                        Can_TxMsg.Data[4] = 0x00;
-                        Can_TxMsg.Data[5] = 0x00;
-                        Can_TxMsg.Data[6] = 0x00;
-                        Can_TxMsg.Data[7] = 0x00;
-                        Can_TxMsg.stdIDH = Can_ID>>3;
-                        Can_TxMsg.stdIDL = Can_ID<<5;
-                        Can_TxMsg.DLC  = 8;
-                        HAL_Can_Transmit(Can_TxMsg);
-                        break;
-
-                    }
                     default:
                     {
                        PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
                        Can_Rece_buffer[0]=0xff;
                     }
                 }
+                // #ifdef USING_PRINTF
+                //     printf("CANID:%#x  Msg:  ",Can_ID);
+                //     for (size_t i = 0; i < 8; i++)
+                //     {
+                //         printf("%x ",Can_TxMsg.Data[i]);
+                //     }
+                //     printf("\n");
+                // #endif
+                HAL_Can_Transmit(Can_TxMsg);
+                #ifdef USING_PRINTF
+                        printf("CAN发送:%x\n ",Can_ID);
+                #endif
                 send_index ++;	
                 break;
             }
             case PROCESS_STATE_SLEEP:
-            {   
-                slpManPlatVoteEnableSleep(process1SlpHandler, SLP_SLP2_STATE); 
-                slpManPlatVoteDisableSleep(process1SlpHandler, SLP_HIB_STATE);   
+            {    
                 while(1)
                 {
                     osDelay(3000);
@@ -667,7 +628,6 @@ void Tcp_Data_Assemble(uint8_t datatype)
     appGetSystemTimeUtcSync(&timestracture);
     battbuffer[0] = timestracture.UTCtimer1>>16;
     battbuffer[0] = battbuffer[0] - 0x07D0;
-    battbuffer[0] = battbuffer[0];
     battbuffer[1] = timestracture.UTCtimer1>>8;
     battbuffer[2] = timestracture.UTCtimer1;
     battbuffer[3] = timestracture.UTCtimer2>>24;
@@ -689,36 +649,8 @@ void Tcp_Data_Assemble(uint8_t datatype)
         battbuffer[14] = 0x00;//故障等级
         battbuffer[15] = 0x00;//故障代码高
         battbuffer[16] = 0x00;//故障代码低
-        battbuffer[17] = 0x00;//电池电流高
-        battbuffer[18] = 0x00;//电池电流低
-        battbuffer[19] = 0x00;//电池电压(内)高
-        battbuffer[20] = 0x00;//电池电压(内)低
-        battbuffer[21] = 0x00;//电池电压(外)高
-        battbuffer[22] = 0x00;//电池电压(外)低
-        battbuffer[23] = 0x03;//开关状态
-        battbuffer[24] = 0x43;//SOC
-        battbuffer[25] = 0x64;//SOH
-        battbuffer[26] = 0x00;//均衡状态25-32
-        battbuffer[27] = 0x00;//均衡状态17-24
-        battbuffer[28] = 0x00;//均衡状态9-16
-        battbuffer[29] = 0x00;//均衡状态1-8
-        battbuffer[30] = 0x0E;//单体个数
-        data_index = 31;
-        for (size_t i = 0; i < 0x0e; i++)
-        {
-            battbuffer[data_index] = 0x0E;
-            data_index ++;
-            battbuffer[data_index] = 0x53;
-            data_index ++;
-            
-        }
-        battbuffer[data_index] = 0x05;//温度采集个数
-        data_index++;
-        for (size_t i = 0; i < 0x05; i++)
-        {
-            battbuffer[data_index] = 0x00;
-            data_index++;
-        }
+
+        data_index = 32+Batt_Cell_Num_2+Batt_Temp_Num;
         battbuffer[data_index] = 0x00;//电池状态
         data_index++;
         battbuffer[data_index] = 0x00;//是否加热
@@ -738,7 +670,7 @@ static void process3AppTask(void* arg)
     UINT16 serverport = 8712;
     int TcpConnectID = -1;
     int TcpSendID = -1;
-    int NB_send_len=92;
+    int NB_send_len=59+Batt_Cell_Num_2+Batt_Temp_Num;//设定网络发送最大数值
 	PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
 
     while(1)
@@ -776,34 +708,32 @@ static void process3AppTask(void* arg)
                 memcpy(TcpSendBuffer+4,SN,17);
                 *(TcpSendBuffer+21) = 0x01;//不加密
                 Tcp_Data_Assemble(0x80);
-
                 
                 *(TcpSendBuffer+22) = data_index>>8;//数据长度
                 *(TcpSendBuffer+23) = data_index;//数据长度
 
                 memcpy(TcpSendBuffer+24,battbuffer,data_index);
-                *(TcpSendBuffer+91) = bcc_chk(TcpSendBuffer,NB_send_len-1);
-                #ifdef USING_PRINTF
-                    printf("[%d]sizeof:%d \r\n",__LINE__,sizeof(TcpSendBuffer)-1);
-                #endif
-                #ifdef USING_PRINTF
-                    printf("[%d]Tcpchk:%#X \r\n",__LINE__,*(TcpSendBuffer+91));
-                #endif
-                #ifdef USING_PRINTF
-                    printf("[%d]datalen:%#X \r\n",__LINE__,data_index);
-                #endif
-
-                for (int i = 0; i < 92; i++)
-                {
-                    #ifdef USING_PRINTF
-                        printf("%X ",*(TcpSendBuffer+i));
-                    #endif
-                }
+                *(TcpSendBuffer+NB_send_len-1) = bcc_chk(TcpSendBuffer,NB_send_len-1);
+                // #ifdef USING_PRINTF
+                //     printf("[%d]sizeof:%d \r\n",__LINE__,sizeof(TcpSendBuffer)-1);
+                // #endif
+                // #ifdef USING_PRINTF
+                //     printf("[%d]Tcpchk:%#X \r\n",__LINE__,*(TcpSendBuffer+91));
+                // #endif
+                // #ifdef USING_PRINTF
+                //     printf("TcpSend:");
+                //     for (int i = 0; i < NB_send_len; i++)
+                //     {
+                //         printf("%x ",*(TcpSendBuffer+i));
+                //     }
+                // #endif
+                // #ifdef USING_PRINTF
+                //         printf("\n ");
+                // #endif
+                TcpSendID  = tcpipConnectionSend(TcpConnectID,TcpSendBuffer,NB_send_len,PNULL,PNULL,PNULL);
                 #ifdef USING_PRINTF
-                        printf("\r\n ");
+                        printf("网络发送:%d\n ",TcpSendID);
                 #endif
-                TcpSendID  = tcpipConnectionSend(TcpConnectID,TcpSendBuffer,NB_send_len,PNULL,PNULL,PNULL);
-
                 PROC_NB_STATE_SWITCH(PROCESS_STATE_IDLE);
                 free(TcpSendBuffer);
                 break;
@@ -814,7 +744,6 @@ static void process3AppTask(void* arg)
                 {
                     osDelay(3000);
                 }                                     
-                break;
             }
         }
     }
@@ -935,4 +864,4 @@ void main_entry(void) {
         osKernelStart();
     }
     while(1);
-}
+}