当我开始这个程序(见下文)时,一切正常。但是当我将返回数据禁用回TPCIP时,编程工作正常。
这是程序,工作正常:[1]:http://s27.postimg.org/seixg63hf/problem_2.jpg
static err_t prijata_data(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err)
{
void *data;
if (err == ERR_OK && p != NULL) {
// information of receive data
tcp_recved(pcb, p->tot_len);
//free buffer
pbuf_free(p);
data = p->payload; //copy value to send out of queue
xQueueSend(queue_ethernet, &data, 10); //send value to queue
//send data out
err = tcp_write(pcb, p->payload, p->len, TCP_WRITE_FLAG_COPY);
tcp_sent(pcb, NULL); // No need to call back
}
else
{
pbuf_free(p);
}
if (err == ERR_OK && p == NULL) {
close_conn(pcb);
}
return ERR_OK;
}
这个功能在这里: 小号
static err_t prijimani_dat(void *arg, struct tcp_pcb *pcb, err_t err){
LWIP_UNUSED_ARG(arg);
LWIP_UNUSED_ARG(err);
tcp_setprio(pcb, TCP_PRIO_MIN);
tcp_recv(pcb, prijata_data);
tcp_err(pcb, server_err);
tcp_poll(pcb, server_poll, 4);
return ERR_OK;
}
在任务FreeRTOS中实现完成通信:
extern void TCP_connection(void *pvParameters)
{
UNUSED(pvParameters);
const portTickType xDelayTime = 5 / portTICK_RATE_MS;
struct tcp_pcb *tcp_server;
tcp_server = tcp_new();
tcp_bind(tcp_server, IP_ADDR_ANY, TCP_PORT);
while (1){
tcp_server = tcp_listen(tcp_server);
tcp_accept(tcp_server, prijimani_dat);
vTaskDelay(xDelayTime);
}
}
但是当我只能从TCP读取数据时,我不希望将数据反馈给TCPIP,程序运行正常。 [2]:http://s21.postimg.org/wlhqh31g5/problem_1.jpg
static err_t prijata_data(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err){
void *data;
if (err == ERR_OK && p != NULL) {
/* information of receive data */
tcp_recved(pcb, p->tot_len);
//free buffer
pbuf_free(p);
data = p->payload; /*copy value to send out of queue*/
xQueueSend(queue_ethernet, &data, 10); //send value to queue
}
else
{
pbuf_free(p);
}
if (err == ERR_OK && p == NULL) {
close_conn(pcb);
}
return ERR_OK;
}
答案 0 :(得分:0)
有一个非常古老的例子,说明如何在FreeRTOS Interactive site中使用带有lwIP的FreeRTOS。尽管此示例中包含的许多代码现已被取代,但与lwIP的集成仍应有效并为您提供参考。
如果您使用FreeRTOS+TCP examples page上列出的处理器之一(FreeRTOS + TCP是FreeRTOS自己的TCP / IP堆栈),那么可能会提供进一步的参考。
答案 1 :(得分:0)
有任何错误,但是什么?当我尝试ping时,一切都正确完成。
C:\>ping 192.168.0.145 -n 10
Pinging 192.168.0.145 with 32 bytes of data:
Reply from 192.168.0.145: bytes=32 time=2ms TTL=255
Reply from 192.168.0.145: bytes=32 time=4ms TTL=255
Reply from 192.168.0.145: bytes=32 time<1ms TTL=255
Reply from 192.168.0.145: bytes=32 time=1ms TTL=255
Reply from 192.168.0.145: bytes=32 time<1ms TTL=255
Reply from 192.168.0.145: bytes=32 time<1ms TTL=255
Reply from 192.168.0.145: bytes=32 time<1ms TTL=255
Reply from 192.168.0.145: bytes=32 time=1ms TTL=255
Reply from 192.168.0.145: bytes=32 time<1ms TTL=255
Reply from 192.168.0.145: bytes=32 time<1ms TTL=255
Ping statistics for 192.168.0.145:
Packets: Sent = 10, Received = 10, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 4ms, Average = 0ms
答案 2 :(得分:0)
确定。我很蠢。错误在于:
我创建了freeRTOS任务,我每5毫秒在循环中调用两个函数。
这是错的:
extern void TCP_connection(void *pvParameters)
{
UNUSED(pvParameters);
const portTickType xDelayTime = 5 / portTICK_RATE_MS;
struct tcp_pcb *tcp_server;
tcp_server = tcp_new();
if (tcp_bind(tcp_server, IP_ADDR_ANY, TCP_PORT) != ERR_OK)
return;
while (1){
tcp_server = tcp_listen(tcp_server);
tcp_accept(tcp_server, server_accept);
vTaskDelay(xDelayTime);
}
}
这很好
extern void TCP_connection(void *pvParameters)
{
UNUSED(pvParameters);
const portTickType xDelayTime = 5 / portTICK_RATE_MS;
struct tcp_pcb *tcp_server;
tcp_server = tcp_new();
if (tcp_bind(tcp_server, IP_ADDR_ANY, TCP_PORT) != ERR_OK)
return;
tcp_server = tcp_listen(tcp_server);
tcp_accept(tcp_server, server_accept);
while (1){
vTaskDelay(xDelayTime);
}
}