|
@@ -61,7 +61,7 @@ static process_Uart gProcess_Uart_Task = PROCESS_UART_STATE_IDLE;
|
|
|
|
|
|
//函数声明区
|
|
//函数声明区
|
|
void USART_callback(uint32_t event);
|
|
void USART_callback(uint32_t event);
|
|
-UINT8 Uart_DataRecv_func(UINT8* Uart_Read_Msg,UINT8* Uart_Recv_Buffer);
|
|
|
|
|
|
+UINT8 Uart_DataRecv_func(Uart_Read_Msg_Type Uart_Read_Msg_Fun,UINT8* Uart_Recv_Buffer_Fun);
|
|
static BOOL uartBattInfoDecode(UINT8* dataPtr);
|
|
static BOOL uartBattInfoDecode(UINT8* dataPtr);
|
|
UINT8 Uart_WriteCmd_func(Uart_Write_Data_Type UartWriteData);
|
|
UINT8 Uart_WriteCmd_func(Uart_Write_Data_Type UartWriteData);
|
|
UINT16 crc_chk(UINT8* data, UINT8 length);
|
|
UINT16 crc_chk(UINT8* data, UINT8 length);
|
|
@@ -101,7 +101,9 @@ static void UartTask(void* arg)
|
|
UINT32 currentTimerCount=0;
|
|
UINT32 currentTimerCount=0;
|
|
BOOL uartReadSuccessFlag = false;
|
|
BOOL uartReadSuccessFlag = false;
|
|
Uart_Read_Msg_Type Uart_Read_Msg;
|
|
Uart_Read_Msg_Type Uart_Read_Msg;
|
|
|
|
+ memset(&(Uart_Read_Msg),0x00,sizeof(Uart_Read_Msg_Type));
|
|
Uart_Write_Data_Type UartWriteData; //Uart控制命令
|
|
Uart_Write_Data_Type UartWriteData; //Uart控制命令
|
|
|
|
+ memset(&(UartWriteData),0x00,sizeof(Uart_Write_Data_Type));
|
|
UartReadMsgType UartReadMsg;
|
|
UartReadMsgType UartReadMsg;
|
|
memset(&(UartReadMsg.UartFlag),0x00,sizeof(UartReadMsgType));
|
|
memset(&(UartReadMsg.UartFlag),0x00,sizeof(UartReadMsgType));
|
|
if(UartWriteCmdHandle == NULL)//Uart控制命令传输指针
|
|
if(UartWriteCmdHandle == NULL)//Uart控制命令传输指针
|
|
@@ -196,7 +198,7 @@ static void UartTask(void* arg)
|
|
}
|
|
}
|
|
case PROCESS_UART_STATE_READ:
|
|
case PROCESS_UART_STATE_READ:
|
|
{
|
|
{
|
|
-
|
|
|
|
|
|
+ UINT16 CRC_chk_buffer;
|
|
Reg_Num = 0x21+BATT_CELL_VOL_NUM+BATT_TEMP_NUM + 2;//按照协议里面的0x21+X+N的结束地址
|
|
Reg_Num = 0x21+BATT_CELL_VOL_NUM+BATT_TEMP_NUM + 2;//按照协议里面的0x21+X+N的结束地址
|
|
Uart_Read_Msg.Bms_Address = BMS_ADDRESS_CODE;
|
|
Uart_Read_Msg.Bms_Address = BMS_ADDRESS_CODE;
|
|
Uart_Read_Msg.Bms_Funcode = UART_READ_CODE;
|
|
Uart_Read_Msg.Bms_Funcode = UART_READ_CODE;
|
|
@@ -206,7 +208,11 @@ static void UartTask(void* arg)
|
|
Uart_Read_Msg.Reg_Num_L = Reg_Num;
|
|
Uart_Read_Msg.Reg_Num_L = Reg_Num;
|
|
Uart_Uds_LEN = Reg_Num*2;
|
|
Uart_Uds_LEN = Reg_Num*2;
|
|
memset(UartReadMsg.Header,0x00,Uart_Uds_LEN);
|
|
memset(UartReadMsg.Header,0x00,Uart_Uds_LEN);
|
|
- Uart_Recv_LEN = Uart_DataRecv_func((UINT8 *)&Uart_Read_Msg,UartReadMsg.Header);
|
|
|
|
|
|
+ CRC_chk_buffer = crc_chk((UINT8 *)&Uart_Read_Msg,6);
|
|
|
|
+ Uart_Read_Msg.CRC_L = CRC_chk_buffer;
|
|
|
|
+ Uart_Read_Msg.CRC_H = CRC_chk_buffer>>8;
|
|
|
|
+ //Uart_Recv_LEN = Uart_DataRecv_func((UINT8 *)&Uart_Read_Msg,(UINT8*)UartReadMsg.Header);
|
|
|
|
+ Uart_Recv_LEN = Uart_DataRecv_func(Uart_Read_Msg,(UINT8*)(UartReadMsg.Header));
|
|
if(Uart_Recv_LEN>0)
|
|
if(Uart_Recv_LEN>0)
|
|
{
|
|
{
|
|
UartBattInfoRecvFlag = TRUE;
|
|
UartBattInfoRecvFlag = TRUE;
|
|
@@ -497,26 +503,31 @@ UINT8 Uart_WriteCmd_func(Uart_Write_Data_Type UartWriteData)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//Uart发送接收函数
|
|
//Uart发送接收函数
|
|
-UINT8 Uart_DataRecv_func(UINT8* Uart_Read_Msg,UINT8* Uart_Recv_Buffer)
|
|
|
|
|
|
+UINT8 Uart_DataRecv_func(Uart_Read_Msg_Type Uart_Read_Msg_Fun,UINT8* Uart_Recv_Buffer_Fun)
|
|
{
|
|
{
|
|
UINT16 CRC_Rece_buffer;
|
|
UINT16 CRC_Rece_buffer;
|
|
UINT16 CRC_chk_buffer;
|
|
UINT16 CRC_chk_buffer;
|
|
UINT16 Data_Len ;
|
|
UINT16 Data_Len ;
|
|
UINT8 timeout = 0x00;
|
|
UINT8 timeout = 0x00;
|
|
- Data_Len = (*(Uart_Read_Msg+4)|*(Uart_Read_Msg+5))*2+5;
|
|
|
|
- CRC_chk_buffer = crc_chk(Uart_Read_Msg,6);
|
|
|
|
- *(Uart_Read_Msg+6) = CRC_chk_buffer;
|
|
|
|
- *(Uart_Read_Msg+7) = CRC_chk_buffer>>8;
|
|
|
|
- USARTdrv->Send(Uart_Read_Msg,8);
|
|
|
|
|
|
+ UINT8 pSendCmd[8];
|
|
|
|
+ memcpy(pSendCmd,(UINT8*)(&Uart_Read_Msg_Fun),8);
|
|
|
|
+ //Data_Len = (*(Uart_Read_Msg_Fun+4)|*(Uart_Read_Msg_Fun+5))*2+5;
|
|
|
|
+ Data_Len = ((Uart_Read_Msg_Fun.Reg_Num_H<<8)|(Uart_Read_Msg_Fun.Reg_Num_L))*2+5;
|
|
|
|
+
|
|
|
|
+ //USARTdrv->Send(Uart_Read_Msg_Fun,8);
|
|
|
|
+ USARTdrv->Send(pSendCmd,8);
|
|
#ifdef USING_PRINTF1
|
|
#ifdef USING_PRINTF1
|
|
|
|
+
|
|
printf("Uart_Send_buffer: ");
|
|
printf("Uart_Send_buffer: ");
|
|
for(int i=0;i<8;i++)
|
|
for(int i=0;i<8;i++)
|
|
- {
|
|
|
|
- printf("%x ",*(Uart_Read_Msg+i));
|
|
|
|
- }
|
|
|
|
- printf("\n");
|
|
|
|
|
|
+ // {
|
|
|
|
+ printf("%x ",pSendCmd[i]);
|
|
|
|
+ // }
|
|
|
|
+ printf("end\n");
|
|
|
|
+ //printf("%x ",*(Uart_Read_Msg_Fun));
|
|
|
|
+ //UINT8 temp = *(Uart_Read_Msg_Fun);
|
|
#endif
|
|
#endif
|
|
- USARTdrv->Receive(Uart_Recv_Buffer,Data_Len);
|
|
|
|
|
|
+ USARTdrv->Receive(Uart_Recv_Buffer_Fun,Data_Len);
|
|
while(true)
|
|
while(true)
|
|
{
|
|
{
|
|
timeout++;
|
|
timeout++;
|
|
@@ -529,6 +540,7 @@ UINT8 Uart_DataRecv_func(UINT8* Uart_Read_Msg,UINT8* Uart_Recv_Buffer)
|
|
osDelay(100);
|
|
osDelay(100);
|
|
if (timeout>=10)
|
|
if (timeout>=10)
|
|
{
|
|
{
|
|
|
|
+ // Data_Len = 0;
|
|
timeout =0;
|
|
timeout =0;
|
|
isRecvTimeout = true;
|
|
isRecvTimeout = true;
|
|
}
|
|
}
|
|
@@ -536,21 +548,21 @@ UINT8 Uart_DataRecv_func(UINT8* Uart_Read_Msg,UINT8* Uart_Recv_Buffer)
|
|
}
|
|
}
|
|
#ifdef USING_PRINTF1
|
|
#ifdef USING_PRINTF1
|
|
printf("Uart_Rece_buffer1: ");
|
|
printf("Uart_Rece_buffer1: ");
|
|
- for(int i=0;i<Data_Len;i++)
|
|
|
|
|
|
+ for(int j=0;j<Data_Len;j++)
|
|
{
|
|
{
|
|
- printf("%x ",*(Uart_Recv_Buffer+i));
|
|
|
|
|
|
+ printf("%x ",*(Uart_Recv_Buffer_Fun+j));
|
|
}
|
|
}
|
|
#endif
|
|
#endif
|
|
if (isRecvComplete == true)
|
|
if (isRecvComplete == true)
|
|
{
|
|
{
|
|
isRecvComplete = false;
|
|
isRecvComplete = false;
|
|
- CRC_Rece_buffer =*(Uart_Recv_Buffer+Data_Len-1)<<8|*(Uart_Recv_Buffer+Data_Len-2);
|
|
|
|
- CRC_chk_buffer = crc_chk(Uart_Recv_Buffer,Data_Len-2);
|
|
|
|
|
|
+ CRC_Rece_buffer =*(Uart_Recv_Buffer_Fun+Data_Len-1)<<8|*(Uart_Recv_Buffer_Fun+Data_Len-2);
|
|
|
|
+ CRC_chk_buffer = crc_chk(Uart_Recv_Buffer_Fun,Data_Len-2);
|
|
#ifdef USING_PRINTF1
|
|
#ifdef USING_PRINTF1
|
|
printf("Uart_Rece_buffer after Crc: ");
|
|
printf("Uart_Rece_buffer after Crc: ");
|
|
for(int i=0;i<Data_Len;i++)
|
|
for(int i=0;i<Data_Len;i++)
|
|
{
|
|
{
|
|
- printf("%x ",*(Uart_Recv_Buffer+i));
|
|
|
|
|
|
+ printf("%x ",*(Uart_Recv_Buffer_Fun+i));
|
|
}
|
|
}
|
|
printf("\tcrcchk:%x,%x\n ",CRC_chk_buffer,CRC_Rece_buffer);
|
|
printf("\tcrcchk:%x,%x\n ",CRC_chk_buffer,CRC_Rece_buffer);
|
|
#endif
|
|
#endif
|
|
@@ -569,16 +581,17 @@ UINT8 Uart_DataRecv_func(UINT8* Uart_Read_Msg,UINT8* Uart_Recv_Buffer)
|
|
ARM_USART_PARITY_NONE |
|
|
ARM_USART_PARITY_NONE |
|
|
ARM_USART_STOP_BITS_1 |
|
|
ARM_USART_STOP_BITS_1 |
|
|
ARM_USART_FLOW_CONTROL_NONE, 9600);
|
|
ARM_USART_FLOW_CONTROL_NONE, 9600);
|
|
- memset(Uart_Recv_Buffer,0xff,Data_Len);
|
|
|
|
|
|
+ memset(Uart_Recv_Buffer_Fun,0xff,Data_Len);
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- memset(Uart_Recv_Buffer,0x00,Data_Len);
|
|
|
|
|
|
+ memset(Uart_Recv_Buffer_Fun,0x00,Data_Len);
|
|
isRecvTimeout = false;
|
|
isRecvTimeout = false;
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
+ return 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|