问题描述
我正在 TM570LC4357 上实施堆栈 LWIP。我做了一个应用程序来测试UDP通信。这是涉及的代码:
void sendUDP(void);
#define UDP_PORT 23
ip_addr_t srcaddrUDP;
ip_addr_t dstaddrUDP;
struct udp_pcb *pcb_u;
int main(void)
{
IP4_ADDR(&dstaddrUDP,160,2,168,192); // the bytes are flipped for some reason..
IP4_ADDR(&srcaddrUDP,44,192); // the bytes are flipped for some reason..
pcb_u = udp_new();
errorCode = udp_bind(pcb_u,&srcaddrUDP,UDP_PORT);
errorCode = udp_connect(pcb_u,&dstaddrUDP,UDP_PORT);
while(1)
{
if(flag500ms)
{
flag500ms = 0;
sendUDP();
}
}
}
void sendUDP(void){
//UDP
err_t error;
u16_t dst_port;
struct pbuf * pb;
char str[512]="CiaoOO";
pb = pbuf_alloc(PBUF_TRANSPORT,512,PBUF_REF);
pb->payload = str;
pb->len = pb->tot_len = 512;
error = udp_sendto(pcb_u,pb,UDP_PORT);
pbuf_free(pb);
}
问题是,如果我发送一个足够字节的数据包(在本例中为 512),一切正常(基本上,在wireshark 中,我收到了我想要的..) 但是如果我发送几个字节(即 10 而不是 512),sendUDP() 第一次工作,但第二次传输未初始化的数据(用wireshark检查)。
我没有使用免费的 RTOS,但我在互联网上读到必须在“lwip 计时器”的中断内调用发送函数,以防止出现意外结果。但是,我不明白在哪里可以找到这个中断。这可能是问题吗? 此外,rawapi.txt(文档)说
"lwIP started targeting single-threaded environments. When adding multi-
threading support,instead of making the core thread-safe,another
approach was chosen: there is one main thread running the lwIP core
(also kNown as the "tcpip_thread"). The raw API may only be used from
this thread! Application threads using the sequential- or socket API
communicate with this main thread through message passing."
可能暗指“lwip 计时器”……但我不确定
我在 flag500ms 下调用 main 中的 send 函数。该标志在定时器中断程序中每 500ms 设置为 1。
有谁遇到过同样的情况并且知道如何解决这个问题??
编辑:我发现 200 字节也存在问题。我正在使用 0 到 199 的计数器。第一次没有问题,但第二次只有 0 到 180 的数字被正确传输。 谢谢, 马可。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)