从网站下的,试跑了一下,可以运行,稳定性还在测试中,注意下载后代码优化的选择,如果选择速度快,代码就要很多,我选择
(1) c/c++ compile--->optimization--->size-medium
(2) #define NET_BUF_CFG_NBR_LARGE 0 (原来20)
这样代码量会减少很多
查看ucos插件方法 Debugger---->plugins--->ucos-II
下面是我写的一个UDP测试程序,放在任务中就可以了,回发端口9000(其实只要你用过VC编写TCP/IP,ucos函数定义都一样,拿来用都一样)
NET_ERR UDP_Err;
int MySockID;
struct sockaddr_in MySockAddr;
int bind_status;
int sock_addr_len;
int rx_msg_len;
MySockAddr.sin_family = AF_INET;
MySockAddr.sin_port = htons(9000);
MySockAddr.sin_addr.s_addr = htonl(INADDR_ANY);
sock_addr_len = sizeof(MySockAddr);
MySockID = socket(PF_INET,SOCK_DGRAM,IPPROTO_UDP);
bind_status = bind(MySockID,(struct sockaddr *)&MySockAddr,sizeof(struct sockaddr_in));
NetOS_Sock_RxQ_TimeoutSet(MySockID, NET_TMR_TIME_INFINITE, &UDP_Err);//阻塞式
while ( 1 )
{
rx_msg_len = recvfrom(MySockID,(void *)UDP_Buf,sizeof(TTCP_Buf),0,(struct sockaddr *)&MySockAddr,&sock_addr_len);
if(rx_msg_len>0)
{
sendto(MySockID,(void *)UDP_Buf,rx_msg_len,0,(struct sockaddr *)&MySockAddr,sizeof(struct sockaddr));
}
else
{
}
//OSTimeDlyHMSM(0, 0, 0, 250);
}