我正在使用 Cortex M3、Stellaris® LM3S6965 评估板。我正在尝试将 UDP 数据包发送到 NTP 服务器。我一直在寻找。
但它不起作用。有人能帮我吗?我认为回调函数没有被调用。
int main(void){
sendUDP();
}
void sendUDP(void){
//UDP
struct ip_addr dstaddr;
struct ip_addr srcaddr;
struct udp_pcb * pcb;
u16_t * dst_port;
struct pbuf * pb;
char str[512]="Test Sander";
IP4_ADDR(&dstaddr,65,55,21,24); // time.windows.com
IP4_ADDR(&srcaddr,192,168,1,10); // cortex
dst_port = 123;
pcb = udp_new();
RIT128x96x4Enable(1000000);
RIT128x96x4StringDraw("UDP CONNECT", 45, 45, 15);
udp_bind(pcb,&srcaddr,&dst_port);
udp_connect(pcb,&dstaddr,&dst_port);
pb = pbuf_alloc(PBUF_TRANSPORT, 512, PBUF_REF);
pb->payload = str;
pb->len = pb->tot_len = 512;
udp_sendto(pcb, &pb,&dstaddr,dst_port);
//udp_send(pcb, &pb);
udp_recv(pcb, RecvUTPCallBack, NULL);
pbuf_free(pb);
udp_remove(pcb);
}
// Function gets called when we recieve data
err_t RecvUTPCallBack(void *arg, struct udp_pcb *upcb, struct pbuf *p, struct ip_addr *addr, u16_t port){
RIT128x96x4Enable(1000000);
RIT128x96x4StringDraw("ENTERING CALLBACK", 40, 40, 11);
volatile int totaal_lengte=0;
totaal_lengte = p->tot_len;
volatile int line=40;
while(1){
RIT128x96x4Enable(1000000);
RIT128x96x4StringDraw(p->payload+1, 0, line, 15);
line+=8;
if(p->len != p->tot_len){
p=p->next;
}
else break;
}
pbuf_free(p);
}
程序完整代码: http: //codepaste.net/uuy8sg