新手入门
- 积分
- 16
- 金钱
- 16
- 注册时间
- 2018-5-25
- 在线时间
- 4 小时
|
10金钱
FreeRTOS + LwIP
1. UDP线程监听8080端口,接收到数据以后发送信号量给发送任务
[mw_shl_code=applescript,true]while (1)
{
recv_err = netconn_recv(conn, &buf);
if (recv_err == ERR_OK)
{
pbuf = buf->p;
netconn_connect(conn, addr, port);
// Maximum of msg is 1024
if(buf->p->tot_len > 1024)
{
printf("the length is over Maximum(1024) ");
}
else
{
// Copy data from pbuf to recv_buf
while(pbuf != NULL)
{
MEMCPY(&recv_buf, pbuf->payload, pbuf->len);
i += pbuf->len; // start position for store pbuf->payload
pbuf = pbuf->next;
}
recv_len = i;
printf("Received data length: %d\r\n", i);
i = 0;
/* Release the Net message semaphore */
xSemaphoreGive(NetMsgSemaphore);
printf("Sent NetMsgSemaphore\r\n");
}
}
/* Release stored space */
netbuf_delete(buf);[/mw_shl_code]
2. 发送任务接收到信号量以后绑定80端口,然后对上位机进行应答
[mw_shl_code=applescript,true]while(1)
{
/* Wait NetMsgSemaphore for 10 ticks */
if(xSemaphoreTake(NetMsgSemaphore, ( portTickType ) 10) == pdTRUE)
{
if(netconn_connect(conn, &des_IPAddr, 8080) == ERR_OK)
{
/* Prepare data */
send_buf = netbuf_new();
if(send_buf != NULL)
{
send_data = netbuf_alloc(send_buf, ack_len);
if(send_data != NULL)
{
MEMCPY(send_data, ack_buf, ack_len);
/* Send the packet */
if(netconn_sendto(conn, send_buf, &des_IPAddr, 8080) != ERR_OK)
printf("[UDPSend_task] Sent send_buf failed!!!\r\n");
}
else
printf("[UDPSend_task] Get send_data failed!!!\r\n");
/* Free the buffer */
netbuf_delete(send_buf);
}
else
printf("[UDPSend_task] Get send_buf failed!!!\r\n");
}
else
printf("[UDPSend_task] netconn_connect failed!!!\r\n");
}
vTaskDelay(100);
}[/mw_shl_code]
其中,接收和发送为同一IP的不同端口,现在的情况是如果发送来的数据大于560字节,发送线程就无法发送
在512个字节的情况下,接收比较稳定。
现在想要实现一次接收1024,请问问题出在哪里?
|
|