工具与软件:
您好!
我们使用的 UART 波特率为9600、主机控制器将发送 1000-2000字节的数据、时间间隔为500ms。
我们必须使用 MTU 247通过空气传输相同的数据。
如果我们以1秒的间隔发送1000字节、则只能正确地查看所有数据、低于1秒时可以观察到数据包不匹配/缺失、
以下是我们的 UART 回调实现。
#define UART_MAX_READ_SIZE 1000
uint8_t uartReadBuffer[UART_MAX_READ_SIZE];
void UARTCallback(UART2_Handle handle, void *buffer, size_t count, void *userArg, int_fast16_t status)
{
uint8_t *idx = NULL;
uint8_t *data = BLEAppUtil_malloc(count + 2);
idx = data;
*idx = count;
idx++;
*idx = count >> 8;
idx++;
memcpy(idx, buffer, count);
BLEAppUtil_invokeFunction(HandlingFunction, data);
memset(uartReadBuffer,0,sizeof(uartReadBuffer));
UART2_flushRx(handle);
}
void HandlingFunction(char *pData)
{
//sending over the air
UART2_read(uart, &uartReadBuffer, UART_MAX_READ_SIZE,0);
}
这里、如果主机控制器发送的数据超过1000字节、我们希望忽略额外的字节、并希望处理新的数据包、
但我们观察到的是、下一次 UART 读取中将添加旧的额外字节、以及新的数据包数据。
请建议处理此场景的正确方法。
此致、
Vignesh。