|
@@ -196,7 +196,7 @@ void SendCmdData(USART_Buf_TypeDef * ptTx, uint8_t Mode, uint16_t ID, uint16_t C
|
|
|
void Uart1_RxData_Process(USART_Buf_TypeDef* ptUartRx, uint16_t TimeOut)
|
|
|
{
|
|
|
uint8_t Mode, DataLength, Addr;
|
|
|
- static uint8_t Data[255], Sum_Buf[255];
|
|
|
+ static uint8_t Data[255];
|
|
|
uint16_t Cmd, i, ID;
|
|
|
uint16_t CheckSumResult=0, CheckSumData=0;
|
|
|
uint8_t FrameBegin, FrameEnd1, FrameEnd2;
|
|
@@ -207,24 +207,20 @@ void Uart1_RxData_Process(USART_Buf_TypeDef* ptUartRx, uint16_t TimeOut)
|
|
|
{
|
|
|
//读取帧头
|
|
|
FrameBegin = UART_ReadChar(ptUartRx, 0);
|
|
|
- Sum_Buf[0] = FrameBegin;
|
|
|
|
|
|
if(FrameBegin == UARTFRAME_BEGIN)
|
|
|
{
|
|
|
Addr = UART_ReadChar(ptUartRx, 1);//读取地址ID
|
|
|
- Sum_Buf[1] = Addr;
|
|
|
|
|
|
if(Addr == UARTID_MC_TO_CDL)
|
|
|
{
|
|
|
//读取帧模式
|
|
|
Mode = UART_ReadChar(ptUartRx, 2);
|
|
|
- Sum_Buf[2] = Mode;
|
|
|
|
|
|
if((Mode == UARTMODE_READ) || (Mode == UARTMODE_WRITE) || (Mode == UARTMODE_REPORT))
|
|
|
{
|
|
|
//读取数据段长度
|
|
|
DataLength = UART_ReadChar(ptUartRx, 3);
|
|
|
- Sum_Buf[3] = DataLength;
|
|
|
|
|
|
if(ptUartRx->ucBufCnt < (DataLength + 8))//帧头1byte + 地址1byte + 模式1byte + 长度1byte + 校验位2bytes + 帧尾2bytes
|
|
|
{
|
|
@@ -244,16 +240,15 @@ void Uart1_RxData_Process(USART_Buf_TypeDef* ptUartRx, uint16_t TimeOut)
|
|
|
{
|
|
|
IsWaitRX_Flag = FALSE;
|
|
|
//接收到完整正确数据包
|
|
|
- for(i=0; i<DataLength; i++)//读取数据段
|
|
|
+ for(i=0; i<(DataLength+4); i++)//读取数据段
|
|
|
{
|
|
|
- Data[i] = UART_ReadChar(ptUartRx, 4 + i);
|
|
|
- Sum_Buf[4 + i] = Data[i];
|
|
|
+ Data[i] = UART_ReadChar(ptUartRx, i);
|
|
|
}
|
|
|
CheckSumData = (UART_ReadChar(ptUartRx, 4 + DataLength)) + \
|
|
|
(UART_ReadChar(ptUartRx, 5 + DataLength) << 8);
|
|
|
for(i = 1; i<(DataLength+4); i++)
|
|
|
{
|
|
|
- CheckSumResult = (uint16_t)(Sum_Buf[i] + CheckSumResult);
|
|
|
+ CheckSumResult = (uint16_t)(Data[i] + CheckSumResult);
|
|
|
}
|
|
|
|
|
|
FrameEnd1 = UART_ReadChar(ptUartRx, 6 + DataLength);
|
|
@@ -262,13 +257,13 @@ void Uart1_RxData_Process(USART_Buf_TypeDef* ptUartRx, uint16_t TimeOut)
|
|
|
if((CheckSumData == CheckSumResult) && (FrameEnd1 == UARTFRAME_END1) && (FrameEnd2 == UARTFRAME_END2))// 比较校验和帧尾
|
|
|
{
|
|
|
//数据处理
|
|
|
- UART1_DataProcess(Mode, Cmd, Data);//Mode为帧模式,Cmd为命令字,Data为数据段
|
|
|
+ UART1_DataProcess(Mode, Cmd, &Data[4]);//Mode为帧模式,Cmd为命令字,Data为数据段
|
|
|
|
|
|
if(DataLength >= 4)//数据段包含ID+Cmd,至少4bytes
|
|
|
{
|
|
|
- ID = (uint16_t)((Data[0]<<8) + Data[1]);
|
|
|
- Cmd = (uint16_t)((Data[2]<<8) + Data[3]);
|
|
|
- SendCmdData(&UART_TxBuff_Struct3, Mode, ID, Cmd, &Data[4]);
|
|
|
+ ID = (uint16_t)((Data[4]<<8) + Data[5]);
|
|
|
+ Cmd = (uint16_t)((Data[6]<<8) + Data[7]);
|
|
|
+ SendCmdData(&UART_TxBuff_Struct3, Mode, ID, Cmd, &Data[8]);
|
|
|
}
|
|
|
|
|
|
//清除缓存
|
|
@@ -375,7 +370,7 @@ void Uart3_RxData_Process(USART_Buf_TypeDef* ptUartRx, uint16_t TimeOut)
|
|
|
CRC_Buf[8 + DataLength] = UART_ReadChar(ptUartRx, 10 + DataLength);
|
|
|
CRC_Buf[9 + DataLength] = UART_ReadChar(ptUartRx, 11 + DataLength);
|
|
|
CRC_Buf[10 + DataLength] = FRAME_END;
|
|
|
- CAN_SendData(ID, CRC_Buf, DataLength + 11);
|
|
|
+ //CAN_SendData(ID, CRC_Buf, DataLength + 11);
|
|
|
|
|
|
UART_TransferData(&UART_TxBuff_Struct1, UARTID_CDL_TO_MC, Mode, ID, Cmd, Data);
|
|
|
//清除缓存
|