|
@@ -69,8 +69,16 @@ 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] = { 0x14,0x0B,0x07,0x0E,0x39,0x37,
|
|
|
+ 0x80,0x14,0x0B,0x07,0x0E,0x39,0x37,
|
|
|
+ 0x1A,0x00,0x00,0x00,0x00,0x00,0x02,0x15,0x02,0x15,0x03,0x43,0x64,
|
|
|
+ 0x00,0x00,0x00,0x00,0x0E,
|
|
|
+ 0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,
|
|
|
+ 0x05,0x13,0x13,0x13,0x13,0x13,0x00,
|
|
|
+ 0x00};
|
|
|
+uint16_t data_len = 0x0000;
|
|
|
typedef enum
|
|
|
{
|
|
|
PROCESS_STATE_IDLE = 0,
|
|
@@ -84,7 +92,13 @@ typedef enum
|
|
|
PROCESS_Uart_STATE_CHECK,
|
|
|
PROCESS_Uart_STATE_SLEEP
|
|
|
}process_Uart;
|
|
|
-
|
|
|
+typedef enum
|
|
|
+{
|
|
|
+ PROCESS_NB_STATE_IDLE = 0,
|
|
|
+ PROCESS_NB_STATE_WORK,
|
|
|
+ PROCESS_NB_STATE_CONNECT,
|
|
|
+ PROCESS_NB_STATE_SLEEP
|
|
|
+}process_NB;
|
|
|
static StaticTask_t gProcessTask0;
|
|
|
static UINT8 gProcessTaskStack0[PROC_TASK_STACK_SIZE];
|
|
|
static StaticTask_t gProcessTask1;
|
|
@@ -97,7 +111,7 @@ static UINT8 gProcessTaskStack3[PROC_TASK_STACK_SIZE];
|
|
|
processSM gProc0State = PROCESS_STATE_IDLE;
|
|
|
process_Uart gProc1State = PROCESS_Uart_STATE_IDLE;
|
|
|
processSM gProc2State = PROCESS_STATE_IDLE;
|
|
|
-processSM gProc3State = PROCESS_STATE_IDLE;
|
|
|
+processSM_NB gProc3State = PROCESS_NB_STATE_IDLE;
|
|
|
#define PROC_Task_STATE_SWITCH(a) (gProc0State = a) //任务调度切换
|
|
|
#define PROC_Uart_STATE_SWITCH(a) (gProc1State = a) //uart 状态切换
|
|
|
#define PROC_Can_STATE_SWITCH(a) (gProc2State = a) //can 状态切换
|
|
@@ -278,7 +292,7 @@ static void process0AppTask(void* arg)
|
|
|
if (Can_index >=100)//Can 1000ms 调用一次
|
|
|
{
|
|
|
PROC_Can_STATE_SWITCH(PROCESS_STATE_WORK);
|
|
|
- PROC_NB_STATE_SWITCH(PROCESS_STATE_WORK);
|
|
|
+ PROC_NB_STATE_SWITCH(PROCESS_STATE_CONNECT);
|
|
|
Can_index = 0;
|
|
|
}
|
|
|
if((Uart_Rece_BattI==0x0000)&&(Can_Rece_buffer[0]==0xff))
|
|
@@ -653,6 +667,73 @@ void TcpCallBack(void)
|
|
|
printf("[%d]TcpCallBacl\n",__LINE__);
|
|
|
#endif
|
|
|
}
|
|
|
+void Tcp_Data_Assemble(uint8_t datatype)
|
|
|
+{
|
|
|
+ uint8_t data_index;//数据位置索引
|
|
|
+ appGetSystemTimeUtcSync(×tracture);
|
|
|
+ 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;
|
|
|
+ battbuffer[4] = timestracture.UTCtimer2>>16;
|
|
|
+ battbuffer[5] = timestracture.UTCtimer2>>8;
|
|
|
+ switch (datatype)
|
|
|
+ {
|
|
|
+ case 0x80:
|
|
|
+ {
|
|
|
+ battbuffer[6] = 0x80;//信息体标志,此处为电池信息
|
|
|
+ battbuffer[7] = battbuffer[0];//年
|
|
|
+ battbuffer[8] = battbuffer[1];//月
|
|
|
+ battbuffer[9] = battbuffer[2];//日
|
|
|
+ battbuffer[10] = battbuffer[3];//时 0时区时间
|
|
|
+ battbuffer[11] = battbuffer[4];//分
|
|
|
+ battbuffer[12] = battbuffer[5];//秒
|
|
|
+
|
|
|
+ battbuffer[13] = 0x1A;// 网络信号
|
|
|
+ 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 = 30;
|
|
|
+ for (size_t i = 0; i < 0x0e; i++)
|
|
|
+ {
|
|
|
+ battbuffer[31+i] = 0x00;
|
|
|
+ data_index ++;
|
|
|
+ }
|
|
|
+ battbuffer[31+2*14] = 0x05;//温度采集个数
|
|
|
+ data_index++;
|
|
|
+ for (size_t i = 0; i < 0x05; i++)
|
|
|
+ {
|
|
|
+ battbuffer[32+2*14+i] = 0x00;
|
|
|
+ data_index++;
|
|
|
+ }
|
|
|
+ battbuffer[data_index] = 0x00;//电池状态
|
|
|
+ data_index++;
|
|
|
+ battbuffer[data_index] = 0x00;//是否加热
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ data_len = sizeof(battbuffer);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
static void process3AppTask(void* arg)
|
|
|
{
|
|
|
CHAR SN[] = "GYTEST00000000001";
|
|
@@ -660,16 +741,9 @@ static void process3AppTask(void* arg)
|
|
|
UINT16 serverport = 8712;
|
|
|
int TcpConnectID = -1;
|
|
|
int TcpSendID = -1;
|
|
|
- uint16_t data_len = 0x0000;
|
|
|
PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
|
|
|
OsaUtcTimeTValue timestracture;
|
|
|
- uint8_t battbuffer[67] = { 0x14,0x0B,0x07,0x0E,0x39,0x37,
|
|
|
- 0x80,0x14,0x0B,0x07,0x0E,0x39,0x37,
|
|
|
- 0x1A,0x00,0x00,0x00,0x00,0x00,0x02,0x15,0x02,0x15,0x03,0x43,0x64,
|
|
|
- 0x00,0x00,0x00,0x00,0x0E,
|
|
|
- 0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,0x0E,0x53,
|
|
|
- 0x05,0x13,0x13,0x13,0x13,0x13,0x00,
|
|
|
- 0x00};
|
|
|
+
|
|
|
uint8_t TcpSendBuffer[92];
|
|
|
memset(TcpSendBuffer,0,92);
|
|
|
TcpSendBuffer[0] = 0x23;
|
|
@@ -677,44 +751,31 @@ static void process3AppTask(void* arg)
|
|
|
TcpSendBuffer[2] = 0x02;
|
|
|
TcpSendBuffer[3] = 0xfe;
|
|
|
memcpy(&TcpSendBuffer[4],SN,17);
|
|
|
-
|
|
|
+ TcpSendBuffer[21] = 0x01;//不加密
|
|
|
while(1)
|
|
|
{
|
|
|
switch(gProc3State)
|
|
|
{
|
|
|
- case PROCESS_STATE_IDLE:
|
|
|
+ case PROCESS_NB_STATE_IDLE:
|
|
|
{
|
|
|
break;
|
|
|
}
|
|
|
- case PROCESS_STATE_WORK:
|
|
|
+ case PROCESS_NB_STATE_CONNECT:
|
|
|
{
|
|
|
while(TcpConnectID<0)
|
|
|
{
|
|
|
TcpConnectID = tcpipConnectionCreate(1,PNULL,PNULL,serverip,serverport,TcpCallBack);
|
|
|
}
|
|
|
-
|
|
|
- appGetSystemTimeUtcSync(×tracture);
|
|
|
- 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;
|
|
|
- battbuffer[4] = timestracture.UTCtimer2>>16;
|
|
|
- battbuffer[5] = timestracture.UTCtimer2>>8;
|
|
|
- battbuffer[6] = 0x80;//信息体标志,此处为电池信息
|
|
|
- battbuffer[7] = battbuffer[0];
|
|
|
- battbuffer[8] = battbuffer[1];
|
|
|
- battbuffer[9] = battbuffer[2];
|
|
|
- battbuffer[10] = battbuffer[3];
|
|
|
- battbuffer[11] = battbuffer[4];
|
|
|
- battbuffer[12] = battbuffer[5];
|
|
|
- data_len = sizeof(battbuffer);
|
|
|
-
|
|
|
-
|
|
|
- TcpSendBuffer[21] = 0x01;
|
|
|
- TcpSendBuffer[22] = data_len>>8;//数据长度未指定
|
|
|
- TcpSendBuffer[23] = data_len;//数据长度未指定
|
|
|
+ PROC_NB_STATE_SWITCH(PROCESS_STATE_WORK);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case PROCESS_NB_STATE_WORK:
|
|
|
+ {
|
|
|
+ Tcp_Data_Assemble(0x80);
|
|
|
+
|
|
|
+
|
|
|
+ TcpSendBuffer[22] = data_len>>8;//数据长度
|
|
|
+ TcpSendBuffer[23] = data_len;//数据长度
|
|
|
|
|
|
memcpy(&TcpSendBuffer[24],battbuffer,data_len);
|
|
|
TcpSendBuffer[91] = bcc_chk(TcpSendBuffer,sizeof(TcpSendBuffer)-1);
|
|
@@ -739,13 +800,12 @@ static void process3AppTask(void* arg)
|
|
|
#ifdef USING_PRINTF
|
|
|
printf("\r\n ");
|
|
|
#endif
|
|
|
- TcpSendID = tcpipConnectionSend(TcpConnectID,TcpSendBuffer,sizeof(TcpSendBuffer),PNULL,PNULL,PNULL);
|
|
|
+ //TcpSendID = tcpipConnectionSend(TcpConnectID,TcpSendBuffer,sizeof(TcpSendBuffer),PNULL,PNULL,PNULL);
|
|
|
|
|
|
PROC_NB_STATE_SWITCH(PROCESS_STATE_IDLE);
|
|
|
- osDelay(100);
|
|
|
break;
|
|
|
}
|
|
|
- case PROCESS_STATE_SLEEP:
|
|
|
+ case PROCESS_NB_STATE_SLEEP:
|
|
|
{
|
|
|
while(1)
|
|
|
{
|
|
@@ -833,10 +893,10 @@ void process3Init(void)
|
|
|
osThreadAttr_t task_attr;
|
|
|
|
|
|
memset(&task_attr,0,sizeof(task_attr));
|
|
|
- memset(gProcessTaskStack3, 0xA5,PROC_TASK_STACK_SIZE);
|
|
|
+ memset(gProcessTaskStack3, 0xA5,2048);
|
|
|
task_attr.name = "Process3AppTask";
|
|
|
task_attr.stack_mem = gProcessTaskStack3;
|
|
|
- task_attr.stack_size = PROC_TASK_STACK_SIZE;
|
|
|
+ task_attr.stack_size = 2048;
|
|
|
task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
|
|
|
task_attr.cb_mem = &gProcessTask3;//task control block
|
|
|
task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
|