|

楼主 |
发表于 2025-3-13 16:25:25
|
显示全部楼层
while(1)
{
if ((read = comGetRxcount(COM3)) > 8)
{
if (comGetChar(COM3,&_byte))
{
switch(step)
{
/*接收数据包包头的状态*/
case 0:
if(_byte == 0xFC)
{
step++;
cnt = 0;
}
else
{
step = 0;
}
break;
case 1:
if(_byte == 0xFD)
{
step++;
}
else
{
step = 0;
}
break;
case 2:
if(_byte == 0xCF)
{
step++;
}
else
{
step = 0;
}
break;
case 3:
if(_byte == 0xDC)
{
step++;
}
else
{
step = 0;
}
break;
case 4:
if(_byte == 0x00)
{
k++;
if (k == 8)
{
k = 0;
step++;
}
}
else
{
step = 0;
}
break;
case 5:
if(_byte == 0x34)
{
cnt = 0;
step++;
len = 4;
}
else
{
count = 0;
step = 0;
// memset(net_buf,0,sizeof(net_buf));
}
break;
/*接收数据 接收4字节并进行处理 */
case 6:
len--;
_buf[cnt] = _byte;
cnt++;
if(len == 0)
{
// if (_buf[0] == 0x34)
// {
// step = 0;
// count = 0;
// }
net_buf[count] = (((uint32_t)_buf[0] << 24) | ((uint32_t)_buf[1] << 16) | ((uint32_t)_buf[2] << 8) | _buf[3]);
count++;
step = 5;
if (count == 237)
{
count = 0;
step = 0;
com3_buf.read_id = (com3_buf.read_id == 1) ? 0 : 1;
com3_buf.reading[com3_buf.read_id] = 1;
if (com3_buf.sending[com3_buf.read_id] == 1)
{
tx_thread_sleep(1);
}
for (int j = 0; j < 237; j++)
{
com3_buf.buf[com3_buf.read_id][j] = net_buf[j];
}
memset(net_buf,0,sizeof(net_buf));
com3_buf.reading[com3_buf.read_id] = 0;
// const char cmd[2] = {0x00, 0x8F};
// /* 发送485数据命令 */
// comSendBuf(COM3, (uint8_t *)cmd, 2);
tx_event_flags_set(&EventGroup, BIT_4, TX_OR);
}
}
break;
default:
step = 0;
break;
}
}
else
{
Error_Handler(__FILE__, __LINE__);
}
}
else
{
tx_thread_sleep(10);
} 丢数据 使用的安富莱的串口fifo的模式
|
|