|
@@ -1,13 +1,8 @@
|
|
|
-/****************************************************************************
|
|
|
- *
|
|
|
- * Copy right: 2020-, Copyrigths of QIXIANG TECH Ltd.
|
|
|
- * File name: app.c
|
|
|
- * Description: QX app source file
|
|
|
- * History: Rev1.0 2020-10-16
|
|
|
- * Athuor: chenjie
|
|
|
- *
|
|
|
- ****************************************************************************/
|
|
|
-//include
|
|
|
+/*******************************
|
|
|
+ *
|
|
|
+ * 骑享程序测试
|
|
|
+ *
|
|
|
+ * ****************************/
|
|
|
#include "bsp.h"
|
|
|
#include "bsp_custom.h"
|
|
|
#include "osasys.h"
|
|
@@ -27,90 +22,24 @@
|
|
|
#include "slpman_ec616.h"
|
|
|
#include "plat_config.h"
|
|
|
|
|
|
-//define
|
|
|
-// app task static stack and control block
|
|
|
-#define PROC0_TASK_STACK_SIZE (512)
|
|
|
-#define PROC1_TASK_STACK_SIZE (1024)
|
|
|
-#define PROC2_TASK_STACK_SIZE (1024)
|
|
|
-#define PROC3_TASK_STACK_SIZE (1536)
|
|
|
-
|
|
|
-
|
|
|
-//uart def
|
|
|
-#define Uart_Send_LEN (8)
|
|
|
-#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 receive timeout flag */
|
|
|
-volatile bool isRecvTimeout = false;
|
|
|
-
|
|
|
-/** \brief receive complete flag */
|
|
|
-volatile bool isRecvComplete = false;
|
|
|
+//空间及变量定义
|
|
|
+#define PROC_MAIN_TASK_STACK_SIZE (1024)
|
|
|
|
|
|
-uint8_t process0SlpHandler = 0x00;
|
|
|
-uint8_t process1SlpHandler = 0x01;
|
|
|
-uint8_t process2SlpHandler = 0x02;
|
|
|
-uint8_t process3SlpHandler = 0x03;
|
|
|
-uint8_t deepslpTimerID = 7;
|
|
|
-uint8_t Can_Rece_buffer[8];
|
|
|
-uint8_t Batt_Cell_Num = 14;//默认数值14、17
|
|
|
-uint8_t Batt_Cell_Num_2 ;//默认数值
|
|
|
-uint8_t Batt_Temp_Num = 5;//默认数值5、7
|
|
|
-int16_t Uart_Rece_BattI=0x0000;
|
|
|
-uint8_t battbuffer[100];//电池数据都存在此数组中————电压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 34+x*2+N 35 +X*2+N 36+X*2 +N 37+X*2+N
|
|
|
- * 电池状态 是否加热 最高单体H 最高单体L 最低单体H 最低单体L
|
|
|
- * */
|
|
|
-uint16_t data_index = 0x0000;
|
|
|
-
|
|
|
+uint8_t deepslpTimerID = DEEPSLP_TIMER_ID1;
|
|
|
+uint8_t MainSlpHandler = 0xff;
|
|
|
+//状态机定义
|
|
|
typedef enum
|
|
|
{
|
|
|
PROCESS_STATE_IDLE = 0,
|
|
|
PROCESS_STATE_WORK,
|
|
|
PROCESS_STATE_SLEEP
|
|
|
-}processSM;
|
|
|
-typedef enum
|
|
|
-{
|
|
|
- PROCESS_Uart_STATE_IDLE = 0,
|
|
|
- PROCESS_Uart_STATE_WORK,
|
|
|
- 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[PROC0_TASK_STACK_SIZE];
|
|
|
-static StaticTask_t gProcessTask1;
|
|
|
-static UINT8 gProcessTaskStack1[PROC1_TASK_STACK_SIZE];
|
|
|
-static StaticTask_t gProcessTask2;
|
|
|
-static UINT8 gProcessTaskStack2[PROC2_TASK_STACK_SIZE];
|
|
|
-static StaticTask_t gProcessTask3;
|
|
|
-static UINT8 gProcessTaskStack3[PROC3_TASK_STACK_SIZE];
|
|
|
-
|
|
|
-processSM gProc0State = PROCESS_STATE_IDLE;
|
|
|
-process_Uart gProc1State = PROCESS_Uart_STATE_IDLE;
|
|
|
-processSM gProc2State = PROCESS_STATE_IDLE;
|
|
|
-process_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 状态切换
|
|
|
-#define PROC_NB_STATE_SWITCH(a) (gProc3State = a) //NB状态切换
|
|
|
-//-------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
+}process_Main;
|
|
|
+static process_Main gProcess_Main_Task = PROCESS_STATE_IDLE;
|
|
|
+#define PROC_MAIN_STATE_SWITCH(a) (gProcess_Main_Task = a)
|
|
|
+//堆栈申请
|
|
|
+static StaticTask_t gProcess_Main_Task_t;
|
|
|
+static UINT8 gProcess_Main_TaskStack[PROC_MAIN_TASK_STACK_SIZE];
|
|
|
+//睡眠进出函数
|
|
|
static void appBeforeHib(void *pdata, slpManLpState state)
|
|
|
{
|
|
|
uint32_t *p_param = (uint32_t *)pdata;
|
|
@@ -118,7 +47,6 @@ static void appBeforeHib(void *pdata, slpManLpState state)
|
|
|
#ifdef USING_PRINTF
|
|
|
printf("Before Hibernate:%d \n",state);
|
|
|
#endif
|
|
|
- ECOMM_TRACE(UNILOG_PLA_APP, appBeforeHib_1, P_SIG, 1, "Before Hibernate = %x",*p_param);
|
|
|
slpManAONIOLatchEn(AonIOLatch_Enable);
|
|
|
|
|
|
}
|
|
@@ -128,7 +56,6 @@ static void appAfterHib(void *pdata, slpManLpState state)
|
|
|
#ifdef USING_PRINTF
|
|
|
printf("Try Hibernate Failed:%d \n",state);
|
|
|
#endif
|
|
|
- ECOMM_TRACE(UNILOG_PLA_APP, appAfterHib_1, P_SIG, 0, "Try Hibernate Failed, Interrupt Pending. Only sleep failed this function will excute");
|
|
|
}
|
|
|
|
|
|
|
|
@@ -137,7 +64,6 @@ static void appBeforeSlp1(void *pdata, slpManLpState state)
|
|
|
#ifdef USING_PRINTF
|
|
|
printf("Before Sleep1:%d \n",state);
|
|
|
#endif
|
|
|
- ECOMM_TRACE(UNILOG_PLA_APP, appBeforeSlp1_1, P_SIG, 0, "Before Sleep1");
|
|
|
slpManAONIOLatchEn(AonIOLatch_Enable);
|
|
|
}
|
|
|
|
|
@@ -146,8 +72,6 @@ static void appAfterSlp1(void *pdata, slpManLpState state)
|
|
|
#ifdef USING_PRINTF
|
|
|
printf("After Sleep1:%d \n",state);
|
|
|
#endif
|
|
|
- PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
|
|
|
- ECOMM_TRACE(UNILOG_PLA_APP, appAfterSlp1_1, P_SIG, 0, "After Sleep1, no matter sleep success or not this function will excute");
|
|
|
}
|
|
|
|
|
|
|
|
@@ -156,7 +80,6 @@ static void appBeforeSlp2(void *pdata, slpManLpState state)
|
|
|
#ifdef USING_PRINTF
|
|
|
printf("before sleep2:%d \n",state);
|
|
|
#endif
|
|
|
- ECOMM_TRACE(UNILOG_PLA_APP, appBeforeSlp2_1, P_SIG, 0, "Before Sleep2");
|
|
|
slpManAONIOLatchEn(AonIOLatch_Enable);
|
|
|
}
|
|
|
|
|
@@ -165,119 +88,16 @@ static void appAfterSlp2(void *pdata, slpManLpState state)
|
|
|
#ifdef USING_PRINTF
|
|
|
printf("sleep2 failed:%d \n",state);
|
|
|
#endif
|
|
|
- ECOMM_TRACE(UNILOG_PLA_APP, appAfterSlp2_1, P_SIG, 0, "Sleep2 Failed, Interrupt Pending. Only sleep failed this function will excute");
|
|
|
-}
|
|
|
-
|
|
|
-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;
|
|
|
-}
|
|
|
-uint8_t* Uart_Receive_func(Uart_Receive_Type Uart_Receive_Msg,uint8_t *Uart_Rece_buffer)
|
|
|
-{
|
|
|
- uint16_t CRC_Rece_buffer;
|
|
|
- uint16_t CRC_chk_buffer;
|
|
|
- uint8_t Uart_Send_buffer[8];
|
|
|
- uint8_t Rece_Data_Len;
|
|
|
- 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=0;
|
|
|
- USARTdrv->Send(Uart_Send_buffer,8);
|
|
|
- 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++;
|
|
|
- if (timeout>7000000)
|
|
|
- {
|
|
|
- timeout =0;
|
|
|
- isRecvTimeout = true;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- if (isRecvComplete == true)
|
|
|
- {
|
|
|
- //Rece_Data_Len = *(Uart_Rece_buffer+2);
|
|
|
- isRecvComplete = false;
|
|
|
- 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);
|
|
|
- // #ifdef USING_PRINTF
|
|
|
- // // printf("Uart_Send_buffer: ");
|
|
|
- // // for(int i=0;i<8;i++)
|
|
|
- // // {
|
|
|
- // // printf("%x ",Uart_Send_buffer[i]);
|
|
|
- // // }
|
|
|
- // // printf("\n");
|
|
|
- // printf("Uart_Rece_buffer: ");
|
|
|
- // for(int i=0;i<Rece_Data_Len+5;i++)
|
|
|
- // {
|
|
|
- // printf("%x ",*(Uart_Rece_buffer+i));
|
|
|
- // }
|
|
|
- // printf("crcchk:%x,%x ",CRC_chk_buffer,CRC_Rece_buffer);
|
|
|
- // #endif
|
|
|
- if (CRC_Rece_buffer == CRC_chk_buffer)//满足校验
|
|
|
- {
|
|
|
- return Uart_Rece_buffer+3;
|
|
|
- }
|
|
|
- else //接收数据的校验不过屏蔽
|
|
|
- {
|
|
|
- memset(Uart_Rece_buffer,0xff,Rece_Data_Len+5);
|
|
|
- return Uart_Rece_buffer+3;
|
|
|
- }
|
|
|
- }
|
|
|
- if (isRecvTimeout == true)//没收到数据,全部为空值
|
|
|
- {
|
|
|
- memset(Uart_Rece_buffer,0x00,Rece_Data_Len+5);
|
|
|
- isRecvTimeout = false;
|
|
|
- osDelay(1000);
|
|
|
- return Uart_Rece_buffer;
|
|
|
- }
|
|
|
- memset(Uart_Rece_buffer,0x00,Rece_Data_Len+5);
|
|
|
- return Uart_Rece_buffer;
|
|
|
}
|
|
|
-void USART_callback(uint32_t event)
|
|
|
-{
|
|
|
- if(event & ARM_USART_EVENT_RX_TIMEOUT)
|
|
|
- {
|
|
|
- isRecvTimeout = true;
|
|
|
- }
|
|
|
- if(event & ARM_USART_EVENT_RECEIVE_COMPLETE)
|
|
|
- {
|
|
|
- isRecvComplete = true;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static void process0AppTask(void* arg)//任务调度程序
|
|
|
+// 主任务线程
|
|
|
+static void Main_Task(void* arg)
|
|
|
{
|
|
|
UINT16 Can_index = 0;
|
|
|
UINT16 Uart_index = 0;
|
|
|
UINT16 NB_index = 0;
|
|
|
uint32_t sleep_index = 0;
|
|
|
int32_t inParam = 0xAABBCCDD;
|
|
|
- PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
|
|
|
+ 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);
|
|
@@ -285,8 +105,8 @@ static void process0AppTask(void* arg)//任务调度程序
|
|
|
FaultDisplay(LED_TURN_OFF);
|
|
|
NVIC_EnableIRQ(PadWakeup1_IRQn);
|
|
|
slpManSetPmuSleepMode(true,SLP_HIB_STATE,false);
|
|
|
- slpManApplyPlatVoteHandle("pro0",&process0SlpHandler);
|
|
|
- slpManPlatVoteDisableSleep(process0SlpHandler, SLP_SLP2_STATE);
|
|
|
+ slpManApplyPlatVoteHandle("MainSlp",&MainSlpHandler);
|
|
|
+ slpManPlatVoteDisableSleep(MainSlpHandler, SLP_SLP2_STATE);
|
|
|
|
|
|
slpManRegisterUsrdefinedBackupCb(appBeforeHib,&inParam,SLPMAN_HIBERNATE_STATE);
|
|
|
slpManRegisterUsrdefinedRestoreCb(appAfterHib,NULL,SLPMAN_HIBERNATE_STATE);
|
|
@@ -298,64 +118,72 @@ static void process0AppTask(void* arg)//任务调度程序
|
|
|
slpManRegisterUsrdefinedRestoreCb(appAfterSlp2,NULL,SLPMAN_SLEEP2_STATE);
|
|
|
|
|
|
slpManSlpState_t slpstate = slpManGetLastSlpState();
|
|
|
+
|
|
|
#ifdef USING_PRINTF
|
|
|
printf("slpstate:%d \n",slpstate);
|
|
|
#endif
|
|
|
if((slpstate == SLP_SLP2_STATE) || (slpstate == SLP_HIB_STATE))
|
|
|
{
|
|
|
- PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
|
|
|
+ PROC_MAIN_STATE_SWITCH(PROCESS_STATE_IDLE);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
|
|
|
+ PROC_MAIN_STATE_SWITCH(PROCESS_STATE_WORK);
|
|
|
}
|
|
|
-
|
|
|
- while(1)
|
|
|
+ //线程初始化完成
|
|
|
+ while (true)
|
|
|
{
|
|
|
- switch(gProc0State)
|
|
|
+ switch(gProcess_Main_Task)
|
|
|
{
|
|
|
case PROCESS_STATE_IDLE:
|
|
|
- {
|
|
|
+ {
|
|
|
#ifdef USING_PRINTF
|
|
|
- printf("wake up 5s \n");
|
|
|
+ printf("Main_IDLE \n");
|
|
|
#endif
|
|
|
- PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_CHECK);
|
|
|
- NetSocDisplay(LED_SOC_0,LED_TURN_ON);
|
|
|
- osDelay(100/portTICK_PERIOD_MS);//delay 100ms
|
|
|
- if(Uart_Rece_BattI!=0x0000)
|
|
|
+ osDelay(100/portTICK_PERIOD_MS);
|
|
|
+ if(true)
|
|
|
{
|
|
|
- PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
|
|
|
+ sleep_index++;
|
|
|
+ if(sleep_index>=50)
|
|
|
+ {
|
|
|
+ sleep_index=0;
|
|
|
+ PROC_MAIN_STATE_SWITCH(PROCESS_STATE_SLEEP);
|
|
|
+ }
|
|
|
}
|
|
|
- sleep_index++;
|
|
|
- if(sleep_index>=50)
|
|
|
+ else
|
|
|
{
|
|
|
- sleep_index=0;
|
|
|
- PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
|
|
|
+ PROC_Task_STATE_SWITCH(PROCESS_STATE_WORK);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
case PROCESS_STATE_WORK:
|
|
|
{
|
|
|
- osDelay(10/portTICK_PERIOD_MS);//10ms
|
|
|
+ osDelay(10/portTICK_PERIOD_MS);
|
|
|
Can_index++;
|
|
|
Uart_index++;
|
|
|
NB_index++;
|
|
|
if (Uart_index >10)//Uart 100ms 调用一次
|
|
|
{
|
|
|
- PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_WORK);
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("Uart_start \n");
|
|
|
+ #endif
|
|
|
Uart_index = 0;
|
|
|
}
|
|
|
if (Can_index >=100)//Can 1000ms 调用一次
|
|
|
{
|
|
|
- PROC_Can_STATE_SWITCH(PROCESS_STATE_WORK);
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("Can_start \n");
|
|
|
+ #endif
|
|
|
Can_index = 0;
|
|
|
}
|
|
|
if (NB_index >=100)//NB 10s 调用一次
|
|
|
{
|
|
|
- PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_CONNECT);
|
|
|
+ #ifdef USING_PRINTF
|
|
|
+ printf("NB_start \n");
|
|
|
+ #endif
|
|
|
NB_index = 0;
|
|
|
}
|
|
|
- if((Uart_Rece_BattI==0x0000)&&(Can_Rece_buffer[0]!=0x01))
|
|
|
+ if(true)
|
|
|
{
|
|
|
sleep_index++;
|
|
|
}
|
|
@@ -363,37 +191,25 @@ static void process0AppTask(void* arg)//任务调度程序
|
|
|
{
|
|
|
sleep_index = 0;
|
|
|
}
|
|
|
-
|
|
|
if (sleep_index >=6000)
|
|
|
{
|
|
|
- PROC_Task_STATE_SWITCH(PROCESS_STATE_SLEEP);
|
|
|
+ PROC_MAIN_STATE_SWITCH(PROCESS_STATE_SLEEP);
|
|
|
sleep_index = 0;
|
|
|
- #ifdef USING_PRINTF
|
|
|
- printf("sleep_index:%d,Current:%x,CAN:%x \n",sleep_index,Uart_Rece_BattI,Can_Rece_buffer[0]);
|
|
|
- #endif
|
|
|
}
|
|
|
break;
|
|
|
-
|
|
|
}
|
|
|
case PROCESS_STATE_SLEEP:
|
|
|
{
|
|
|
-
|
|
|
- slpManSlpState_t State;
|
|
|
+ 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);
|
|
|
- osDelay(1000/portTICK_PERIOD_MS);
|
|
|
- #if 1
|
|
|
- if(slpManCheckVoteState(process0SlpHandler, &State, &cnt)==RET_TRUE)
|
|
|
+ if(slpManCheckVoteState(MainSlpHandler, &State, &cnt)==RET_TRUE)
|
|
|
{
|
|
|
#ifdef USING_PRINTF
|
|
|
printf("[%d]We Can Check Vote State, state=%d, cnt=%d\r\n",__LINE__,State,cnt);
|
|
|
#endif
|
|
|
}
|
|
|
- //slpManPlatVoteEnableSleep(process0SlpHandler, SLP_SLP2_STATE); // cancel the prohibition of sleep2
|
|
|
- slpManPlatVoteEnableSleep(process0SlpHandler, SLP_SLP2_STATE);
|
|
|
- if(slpManCheckVoteState(process0SlpHandler, &State, &cnt)==RET_TRUE)
|
|
|
+ slpManPlatVoteEnableSleep(MainSlpHandler, SLP_SLP2_STATE);
|
|
|
+ if(slpManCheckVoteState(MainSlpHandler, &State, &cnt)==RET_TRUE)
|
|
|
{
|
|
|
#ifdef USING_PRINTF
|
|
|
printf("[%d]We Can Check Vote State Again, state=%d, cnt=%d\r\n",__LINE__,State,cnt);
|
|
@@ -401,679 +217,50 @@ static void process0AppTask(void* arg)//任务调度程序
|
|
|
}
|
|
|
#ifdef USING_PRINTF
|
|
|
printf("[%d]Waiting sleep\r\n",__LINE__);
|
|
|
- #endif
|
|
|
#endif
|
|
|
- FaultDisplay(LED_TURN_ON);
|
|
|
- slpManDeepSlpTimerStart(deepslpTimerID,60000);
|
|
|
- //osDelay(60000/portTICK_PERIOD_MS);
|
|
|
- while(1)
|
|
|
- {
|
|
|
- osDelay(3000);
|
|
|
- }
|
|
|
- PROC_Task_STATE_SWITCH(PROCESS_STATE_IDLE);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static void process1AppTask(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;
|
|
|
- uint8_t *Uart_Reve_Point = NULL;
|
|
|
- Uart_Receive_Type Uart_Receive_Msg;
|
|
|
- PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
|
|
|
- slpManApplyPlatVoteHandle("pro1",&process1SlpHandler);
|
|
|
- slpManPlatVoteDisableSleep(process1SlpHandler, 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;
|
|
|
- Uart_Rece_buffer = (uint8_t *)malloc(Uart_Rece_LEN);
|
|
|
- while(1)
|
|
|
- {
|
|
|
- switch(gProc1State)
|
|
|
- {
|
|
|
- case PROCESS_Uart_STATE_IDLE:
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_OFF);
|
|
|
- Rece_index = 0;
|
|
|
- break;
|
|
|
- }
|
|
|
- case PROCESS_Uart_STATE_CHECK://检查电流数值
|
|
|
- {
|
|
|
- memset(Uart_Rece_buffer,0x00,8);
|
|
|
- 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;
|
|
|
- Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
|
|
|
- Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 |*(Uart_Reve_Point+1);
|
|
|
#ifdef USING_PRINTF
|
|
|
- printf("Check_Current!\n");
|
|
|
+ printf("Main_Sleep\n");
|
|
|
#endif
|
|
|
- PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
|
|
|
- break;
|
|
|
- }
|
|
|
- case PROCESS_Uart_STATE_WORK:
|
|
|
- {
|
|
|
- NetSocDisplay(LED_SOC_1,LED_TURN_ON);
|
|
|
- memset(Uart_Rece_buffer,0xff,Uart_Rece_LEN);
|
|
|
- switch(Rece_index)
|
|
|
- {
|
|
|
- case 0://读取电流
|
|
|
- {
|
|
|
- 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;
|
|
|
- Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
|
|
|
- Uart_Rece_BattI = *(Uart_Reve_Point+0)<<8 |*(Uart_Reve_Point+1);
|
|
|
- break;
|
|
|
- }
|
|
|
- case 1://读取单体电压
|
|
|
- {
|
|
|
- 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;
|
|
|
- Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
|
|
|
- // #ifdef USING_PRINTF
|
|
|
- // printf("BattCellV: ");
|
|
|
- // 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 2://读取温度
|
|
|
- {
|
|
|
- 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;
|
|
|
- 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++)
|
|
|
- {
|
|
|
- battbuffer[32+Batt_Cell_Num_2+i] = *(Uart_Reve_Point+2*i+1);
|
|
|
- }
|
|
|
- // #ifdef USING_PRINTF
|
|
|
- // printf("BattCellT: ");
|
|
|
- // for (size_t i = 0; i < Batt_Temp_Num; i++)
|
|
|
- // {
|
|
|
- // printf("%x ",*(Uart_Reve_Point+2*i+1));
|
|
|
- // }
|
|
|
- // printf("\n");
|
|
|
- // #endif
|
|
|
- break;
|
|
|
- }
|
|
|
- case 3://读取总电压,目前保护板只有一个电压
|
|
|
- {
|
|
|
- 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;
|
|
|
- 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 4://读取状态及SOC
|
|
|
- {
|
|
|
- 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;
|
|
|
- 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 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;
|
|
|
- Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
|
|
|
- memcpy(&battbuffer[26],Uart_Reve_Point,4);
|
|
|
- break;
|
|
|
- }
|
|
|
- case 6:
|
|
|
- {
|
|
|
- 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 = 0x02;
|
|
|
- Uart_Reve_Point = Uart_Receive_func(Uart_Receive_Msg,Uart_Rece_buffer);
|
|
|
- memcpy(&battbuffer[34+Batt_Cell_Num_2+Batt_Temp_Num],Uart_Reve_Point,4);
|
|
|
- break;
|
|
|
- }
|
|
|
- default:
|
|
|
- {
|
|
|
- PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- Rece_index++;
|
|
|
- break;
|
|
|
- }
|
|
|
- case PROCESS_Uart_STATE_SLEEP:
|
|
|
- {
|
|
|
- free(Uart_Rece_buffer);
|
|
|
- slpManPlatVoteEnableSleep(process1SlpHandler, SLP_SLP2_STATE);
|
|
|
- //osDelay(60000);
|
|
|
- //此处休眠
|
|
|
+ FaultDisplay(LED_TURN_ON);
|
|
|
+ slpManDeepSlpTimerStart(deepslpTimerID,60000);
|
|
|
while(1);
|
|
|
- {
|
|
|
- osDelay(3000);
|
|
|
- }
|
|
|
- PROC_Uart_STATE_SWITCH(PROCESS_Uart_STATE_IDLE);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
-}
|
|
|
-static void process2AppTask(void* arg)
|
|
|
-{
|
|
|
- PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
|
|
|
- uint32_t Can_ID;
|
|
|
- NVIC_EnableIRQ(PadWakeup1_IRQn);
|
|
|
- Can_InitType param;
|
|
|
- Can_TxMsgType Can_TxMsg;
|
|
|
- param.baudrate = CAN_500Kbps;
|
|
|
- param.mode = REQOP_NORMAL;
|
|
|
- param.TxStdIDH = 0x00;
|
|
|
- param.TxStdIDL = 0x00;
|
|
|
- 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] = 0x00;
|
|
|
- param.RxStdIDL[5] =0xa0;
|
|
|
- param.packType = STD_PACK;
|
|
|
- HAL_Can_Init(param);
|
|
|
- int send_index = 0;
|
|
|
- uint16_t Batt_Cell_addU = 0x0000;
|
|
|
- Can_Rece_buffer[0]=0xff;
|
|
|
- slpManApplyPlatVoteHandle("pro2",&process2SlpHandler);
|
|
|
- slpManPlatVoteDisableSleep(process2SlpHandler, SLP_SLP2_STATE);
|
|
|
- while(1)
|
|
|
- {
|
|
|
- switch(gProc2State)
|
|
|
- {
|
|
|
- case PROCESS_STATE_IDLE:
|
|
|
- {
|
|
|
- HAL_Can_Receive(Can_Rece_buffer);
|
|
|
- osDelay(10);
|
|
|
- send_index = 0;
|
|
|
- break;
|
|
|
- }
|
|
|
- case PROCESS_STATE_WORK:
|
|
|
- {
|
|
|
- switch(send_index)
|
|
|
- {
|
|
|
- case 0:
|
|
|
- {
|
|
|
- Can_ID = 0x001;
|
|
|
- for (int i = 0; i < 8; 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:
|
|
|
- {
|
|
|
- Can_ID = 0x011;
|
|
|
- for (int i = 0; i < 8; 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:
|
|
|
- {
|
|
|
- Can_ID = 0x020;
|
|
|
- for (int i = 0; i < 8; 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:
|
|
|
- {
|
|
|
- Can_ID = 0x031;
|
|
|
- for (int i = 0; i < 4; i++)
|
|
|
- {
|
|
|
- Can_TxMsg.Data[i] = battbuffer[i+31+send_index*8];
|
|
|
- }
|
|
|
- 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;
|
|
|
- }
|
|
|
- case 4:
|
|
|
- {
|
|
|
- Can_ID = 0x101;
|
|
|
- for (int i = 0; i < Batt_Temp_Num; i++)
|
|
|
- {
|
|
|
- Can_TxMsg.Data[i] = 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:
|
|
|
- {
|
|
|
- Batt_Cell_addU = 0x0000;
|
|
|
- for (int i = 0; i < Batt_Cell_Num; i++)
|
|
|
- {
|
|
|
- Batt_Cell_addU = Batt_Cell_addU + (battbuffer[31+i*2]<<8|battbuffer[31+i*2+1]);
|
|
|
- }
|
|
|
-
|
|
|
- Can_ID = 0x201;
|
|
|
- Can_TxMsg.Data[0] = battbuffer[19];
|
|
|
- Can_TxMsg.Data[1] = battbuffer[20];
|
|
|
- Can_TxMsg.Data[2] = battbuffer[21];
|
|
|
- Can_TxMsg.Data[3] = battbuffer[22];//外电压
|
|
|
- Can_TxMsg.Data[4] = Batt_Cell_addU>>8;
|
|
|
- Can_TxMsg.Data[5] = Batt_Cell_addU;//累加电压
|
|
|
- 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] = battbuffer[34+Batt_Cell_Num_2+Batt_Temp_Num];
|
|
|
- Can_TxMsg.Data[1] = battbuffer[35+Batt_Cell_Num_2+Batt_Temp_Num];
|
|
|
- Can_TxMsg.Data[2] = battbuffer[36+Batt_Cell_Num_2+Batt_Temp_Num];
|
|
|
- Can_TxMsg.Data[3] = battbuffer[37+Batt_Cell_Num_2+Batt_Temp_Num];
|
|
|
- Can_TxMsg.Data[4] = 0x00;
|
|
|
- Can_TxMsg.Data[5] = 0x00;
|
|
|
- Can_TxMsg.Data[6] = battbuffer[24];
|
|
|
- Can_TxMsg.Data[7] = Batt_Temp_Num<<4|0;
|
|
|
- Can_TxMsg.stdIDH = Can_ID>>3;
|
|
|
- Can_TxMsg.stdIDL = Can_ID<<5;
|
|
|
- Can_TxMsg.DLC = 8;
|
|
|
- HAL_Can_Transmit(Can_TxMsg);
|
|
|
- break;
|
|
|
-
|
|
|
- }
|
|
|
- case 7:
|
|
|
- {
|
|
|
- Can_ID = 0x221;
|
|
|
- Can_TxMsg.Data[0] = battbuffer[25];//SOH
|
|
|
- Can_TxMsg.Data[1] = 0x00;
|
|
|
- Can_TxMsg.Data[2] = 0x00;
|
|
|
- Can_TxMsg.Data[3] = 0x00;
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
- send_index ++;
|
|
|
- break;
|
|
|
- }
|
|
|
- case PROCESS_STATE_SLEEP:
|
|
|
- {
|
|
|
- slpManPlatVoteEnableSleep(process2SlpHandler, SLP_SLP2_STATE);
|
|
|
- //osDelay(60000);
|
|
|
- while(1)
|
|
|
- {
|
|
|
- osDelay(3000);
|
|
|
- }
|
|
|
- PROC_Can_STATE_SWITCH(PROCESS_STATE_IDLE);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-uint8_t bcc_chk(uint8_t* data, uint8_t length)
|
|
|
-{
|
|
|
- uint8_t bcc_chk_return = 0x00;
|
|
|
- uint8_t count = 0;
|
|
|
- while (count<length)
|
|
|
- {
|
|
|
- bcc_chk_return^=data[count];
|
|
|
- count++;
|
|
|
- }
|
|
|
- return bcc_chk_return;
|
|
|
-}
|
|
|
-void TcpCallBack(void)
|
|
|
-{
|
|
|
- #ifdef USING_PRINTF
|
|
|
- printf("[%d]TcpCallBack\n",__LINE__);
|
|
|
- #endif
|
|
|
-}
|
|
|
-void Tcp_Data_Assemble(uint8_t datatype)
|
|
|
-{
|
|
|
- int16_t Batt_current;
|
|
|
- uint8_t csq=0;
|
|
|
- int8_t snr=0;
|
|
|
- int8_t rsnr=0;
|
|
|
- Batt_current = Uart_Rece_BattI;
|
|
|
- OsaUtcTimeTValue timestracture;
|
|
|
- appGetSystemTimeUtcSync(×tracture);
|
|
|
- battbuffer[0] = timestracture.UTCtimer1>>16;
|
|
|
- battbuffer[0] = battbuffer[0] - 0x07D0;
|
|
|
- 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];//秒
|
|
|
- appGetSignalInfoSync(&csq,&snr,&rsnr);//获取信号质量
|
|
|
- battbuffer[13] = csq;// 网络信号
|
|
|
- battbuffer[14] = 0x00;//故障等级
|
|
|
- battbuffer[15] = 0x00;//故障代码高
|
|
|
- battbuffer[16] = 0x00;//故障代码低
|
|
|
- //电流适应性更改,从int转换到uint,加1000的偏移量,100mA的单位
|
|
|
- if (Batt_current>0x8000)
|
|
|
- {
|
|
|
- Batt_current = Batt_current|0x7fff;
|
|
|
- Batt_current = 0x2710 - Batt_current;
|
|
|
- Batt_current = Batt_current;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Batt_current = Batt_current+0x2710;
|
|
|
- Batt_current = Batt_current;
|
|
|
- }
|
|
|
-
|
|
|
- battbuffer[17] = Batt_current>>8;
|
|
|
- battbuffer[18] = Batt_current;
|
|
|
-
|
|
|
- data_index = 32+Batt_Cell_Num_2+Batt_Temp_Num;
|
|
|
- battbuffer[data_index] = 0x00;//电池状态
|
|
|
- data_index++;
|
|
|
- battbuffer[data_index] = 0x00;//是否加热
|
|
|
- data_index++;
|
|
|
|
|
|
- break;
|
|
|
- }
|
|
|
- default:
|
|
|
- break;
|
|
|
}
|
|
|
- return;
|
|
|
-}
|
|
|
-void GGACallBack(UINT8 res, UINT8 * params)
|
|
|
-{
|
|
|
-#ifdef USING_PRINTF
|
|
|
- printf("GPSCallBack,len:%d,GPS:%s\n",res,params);
|
|
|
-#endif
|
|
|
-}
|
|
|
-static void process3AppTask(void* arg)
|
|
|
-{
|
|
|
- CHAR SN[] = "GYTEST00000000003";
|
|
|
- CHAR serverip[] = "47.97.127.222";
|
|
|
- UINT16 serverport = 8712;
|
|
|
- int TcpConnectID = 1;
|
|
|
- int TcpSendID = -1;
|
|
|
- int NB_send_len=59+Batt_Cell_Num_2+Batt_Temp_Num;//设定网络发送最大数值
|
|
|
- slpManApplyPlatVoteHandle("pro3",&process3SlpHandler);
|
|
|
- slpManPlatVoteDisableSleep(process3SlpHandler, SLP_SLP2_STATE);
|
|
|
- PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_IDLE);
|
|
|
- uint8_t* TcpSendBuffer;
|
|
|
- TcpSendBuffer = (uint8_t *)malloc(NB_send_len);//申请发送的数据内存
|
|
|
- while(1)
|
|
|
- {
|
|
|
- switch(gProc3State)
|
|
|
- {
|
|
|
- case PROCESS_NB_STATE_IDLE:
|
|
|
- {
|
|
|
- osDelay(100);
|
|
|
- break;
|
|
|
- }
|
|
|
- case PROCESS_NB_STATE_CONNECT:
|
|
|
- {
|
|
|
- while(TcpConnectID<0)
|
|
|
- {
|
|
|
-
|
|
|
- //TcpConnectID = tcpipConnectionCreate(1,PNULL,PNULL,serverip,serverport,TcpCallBack);
|
|
|
- osDelay(100);
|
|
|
- #ifdef USING_PRINTF
|
|
|
- printf("ConnectID:%d\n ",TcpConnectID);
|
|
|
- #endif
|
|
|
- }
|
|
|
- PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_WORK);
|
|
|
- break;
|
|
|
- }
|
|
|
- case PROCESS_NB_STATE_WORK:
|
|
|
- {
|
|
|
- posGGAServiceStart(GGACallBack);
|
|
|
- memset(TcpSendBuffer,0x00,92);
|
|
|
- *(TcpSendBuffer+0) = 0x23;
|
|
|
- *(TcpSendBuffer+1) = 0x23;
|
|
|
- *(TcpSendBuffer+2) = 0x02;
|
|
|
- *(TcpSendBuffer+3) = 0xfe;
|
|
|
- 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);
|
|
|
- #ifdef USING_PRINTF
|
|
|
- printf("battbuffer:");
|
|
|
- for (int i = 0; i < data_index; i++)
|
|
|
- {
|
|
|
- printf("%x ",battbuffer[i]);
|
|
|
- }
|
|
|
- printf("\n ");
|
|
|
- #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
|
|
|
+
|
|
|
|
|
|
- //TcpSendID = tcpipConnectionSend(TcpConnectID,TcpSendBuffer,NB_send_len,PNULL,PNULL,PNULL);
|
|
|
- // #ifdef USING_PRINTF
|
|
|
- // printf("ConnectID:%d,TcpSend:%d,data length:%d,Data: ",TcpConnectID,TcpSendID,NB_send_len);
|
|
|
- // for (int i = 0; i < NB_send_len; i++)
|
|
|
- // {
|
|
|
- // printf("%x ",*(TcpSendBuffer+i));
|
|
|
- // }
|
|
|
- // printf("\n ");
|
|
|
- // #endif
|
|
|
- PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_IDLE);
|
|
|
- break;
|
|
|
- }
|
|
|
- case PROCESS_NB_STATE_SLEEP:
|
|
|
- {
|
|
|
- tcpipConnectionClose(TcpConnectID);
|
|
|
- posGGAServiceStop();
|
|
|
- free(TcpSendBuffer);
|
|
|
- slpManPlatVoteEnableSleep(process3SlpHandler, SLP_SLP2_STATE); // cancel the prohibition of sleep2
|
|
|
- //osDelay(60000);
|
|
|
- while(1);
|
|
|
- PROC_NB_STATE_SWITCH(PROCESS_NB_STATE_IDLE);
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
-/**
|
|
|
- \fn process0Init(void)
|
|
|
- \brief process0Init function.
|
|
|
- \return
|
|
|
-*/
|
|
|
-void process0Init(void)
|
|
|
-{
|
|
|
- osThreadAttr_t task_attr;
|
|
|
-#ifndef USING_PRINTF
|
|
|
- if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
|
|
|
- {
|
|
|
- HAL_UART_RecvFlowControl(false);
|
|
|
- }
|
|
|
-#endif
|
|
|
|
|
|
- memset(&task_attr,0,sizeof(task_attr));
|
|
|
- memset(gProcessTaskStack0, 0xA5,PROC0_TASK_STACK_SIZE);
|
|
|
- task_attr.name = "Process0AppTask";
|
|
|
- task_attr.stack_mem = gProcessTaskStack0;
|
|
|
- task_attr.stack_size = PROC0_TASK_STACK_SIZE;
|
|
|
- task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
|
|
|
- task_attr.cb_mem = &gProcessTask0;//task control block
|
|
|
- task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
|
|
|
|
|
|
- osThreadNew(process0AppTask, NULL, &task_attr);
|
|
|
-}
|
|
|
-/**
|
|
|
- \fn process1Init(void)
|
|
|
- \brief process1Init function.
|
|
|
- \return
|
|
|
-*/
|
|
|
-void process1Init(void)
|
|
|
+//主任务线程初始化
|
|
|
+void Main_Task_Init()
|
|
|
{
|
|
|
- osThreadAttr_t task_attr;
|
|
|
-#ifndef USING_PRINTF
|
|
|
+ #ifndef USING_PRINTF
|
|
|
if(BSP_GetPlatConfigItemValue(PLAT_CONFIG_ITEM_LOG_CONTROL) != 0)
|
|
|
{
|
|
|
HAL_UART_RecvFlowControl(false);
|
|
|
}
|
|
|
-#endif
|
|
|
-
|
|
|
- memset(&task_attr,0,sizeof(task_attr));
|
|
|
- memset(gProcessTaskStack1, 0xA5,PROC1_TASK_STACK_SIZE);
|
|
|
- task_attr.name = "Process1AppTask";
|
|
|
- task_attr.stack_mem = gProcessTaskStack1;
|
|
|
- task_attr.stack_size = PROC1_TASK_STACK_SIZE;
|
|
|
- task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
|
|
|
- task_attr.cb_mem = &gProcessTask1;//task control block
|
|
|
- task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
|
|
|
-
|
|
|
- osThreadNew(process1AppTask, NULL, &task_attr);
|
|
|
-}
|
|
|
-/**
|
|
|
- \fn process2Init(void)
|
|
|
- \brief process2Init function.
|
|
|
- \return
|
|
|
-*/
|
|
|
-void process2Init(void)
|
|
|
-{
|
|
|
+ #endif
|
|
|
osThreadAttr_t task_attr;
|
|
|
-
|
|
|
memset(&task_attr,0,sizeof(task_attr));
|
|
|
- memset(gProcessTaskStack2, 0xA5,PROC2_TASK_STACK_SIZE);
|
|
|
- task_attr.name = "Process2AppTask";
|
|
|
- task_attr.stack_mem = gProcessTaskStack2;
|
|
|
- task_attr.stack_size = PROC2_TASK_STACK_SIZE;
|
|
|
- task_attr.priority = osPriorityNormal;//osPriorityBelowNormal;
|
|
|
- task_attr.cb_mem = &gProcessTask2;//task control block
|
|
|
- task_attr.cb_size = sizeof(StaticTask_t);//size of task control block
|
|
|
+ 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(process2AppTask, NULL, &task_attr);
|
|
|
-}
|
|
|
-void process3Init(void)
|
|
|
-{
|
|
|
- osThreadAttr_t task_attr;
|
|
|
-
|
|
|
- memset(&task_attr,0,sizeof(task_attr));
|
|
|
- memset(gProcessTaskStack3, 0xA5,PROC3_TASK_STACK_SIZE);
|
|
|
- task_attr.name = "Process3AppTask";
|
|
|
- task_attr.stack_mem = gProcessTaskStack3;
|
|
|
- task_attr.stack_size = PROC3_TASK_STACK_SIZE;
|
|
|
- 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
|
|
|
+ osThreadNew(Main_Task, NULL, &task_attr);
|
|
|
|
|
|
- osThreadNew(process3AppTask, NULL, &task_attr);
|
|
|
}
|
|
|
-/**
|
|
|
- \fn appInit(void)
|
|
|
- \brief appInit function.
|
|
|
- \return
|
|
|
-*/
|
|
|
void appInit(void *arg)
|
|
|
-{
|
|
|
- process0Init();//任务调度和检测程序
|
|
|
- process1Init();//Uart程序
|
|
|
- process2Init();//Can程序
|
|
|
- process3Init();//NB程序
|
|
|
+{
|
|
|
+ Main_Task_Init();
|
|
|
}
|
|
|
-
|
|
|
-/**
|
|
|
- \fn int main_entry(void)
|
|
|
- \brief main entry function.
|
|
|
- \return
|
|
|
-*/
|
|
|
+//主函数入口
|
|
|
void main_entry(void) {
|
|
|
|
|
|
BSP_CommonInit();
|