单片机 FreeRTOS lwip 任务1接收数据放到队列,然后转给另一个设备,不丢数据,任务2从队列中取出数据,sendto发送到socket,sendto返回的size总数是正确的,但是到udp的接收到数据就缺失了,请问是什么问题,是板子的问题,还是程序的问题,tcp的话则不会丢失数据
附上发送代码
void can0_to_udp(int sockfd)
{
int can0_queue_size = uxQueueMessagesWaiting(can0_queue);
if (can0_queue_size > 0) {
if (can0_queue_size >= can0_config_data.subpackage_num
|| (xTaskGetTickCount() - can0_last_send_time >= can0_config_data.delay_time)) {
queue_recv_count += can0_queue_size;
uint8_t tmp_buf[650];
memset(tmp_buf, 0, sizeof(tmp_buf));
uint8_t* ptr = tmp_buf;
for (int i = 0; i < can0_queue_size;i++) {
xQueueReceive(can0_queue, ptr, 0);
ptr += 13;
}
int size = sendto(sockfd, (void*)&tmp_buf, can0_queue_size * 13, 0, (struct sockaddr*)&remote_can0_addr, sizeof(remote_can0_addr));
// printf("size = %d\n", size);
send_cout_test += size;
if (size < 0 || size != can0_queue_size * 13) {
printf("send error size = %d\n", size);
}
can0_last_send_time = xTaskGetTickCount();
}
} else {
vTaskDelay(1);
}
}