|
发表于 2013-7-2 15:44:59
|
显示全部楼层
我用的uip0.9 的客户端模式,感觉什么都没改,1.0不一样么?
/* Initialize the ARP 初始化ARP*/
uip_arp_init();
/* Initialize the uIP TCP/IP stack. 初始化uIP的TCP/ IP协议栈*/
uip_init();
/*set host MAC addr设置主机的MAC地址*/
uip_ethaddr.addr[0] = 0x12;
uip_ethaddr.addr[1] = 0x34;
uip_ethaddr.addr[2] = 0x56;
uip_ethaddr.addr[3] = 0x78;
uip_ethaddr.addr[4] = 0x90;
uip_ethaddr.addr[5] = 0xAB;
#if UIP_FIXEDADDR == 0
/*host ip addr主机IP地址*/
uip_ipaddr(ipaddr, 192,169,13,201);
uip_sethostaddr(ipaddr);
/*netmask addr网络掩码地址*/
uip_ipaddr(ipaddr, 255,255,255,0);
uip_setnetmask(ipaddr);
/*router ip addr路由器的IP地址*/
uip_ipaddr(ipaddr, 192,169,13,1);
uip_setdraddr(ipaddr);
#endif
/*connect to server连接服务器*/
uip_ipaddr(ipaddr, 192,169,13,14);
uip_connect(ipaddr, HTONS(SERVER_PORT));
// SFRPAGE = SMB0_PAGE; //设置从机地址
SMB0ADR = (0x01<<1)&0xFE; //不使能全局呼叫地址(0x00)识别
while(1)
{
TaskA();
}
}
void TaskA(void)
{
uint8 xdata i, arptimer,Ledtimer;
//while (1)
{
// SFRPAGE = CONFIG_PAGE;
Delayms(50);
Ledtimer++;
if(Ledtimer%10==0)
LedState = ~LedState;
// if(I2CErrCnt>100)
// LedState3=~LedState3;
// if(I2CErrCnt>0)
// LedState2=~LedState2;
// for(TestCnt=0;TestCnt<TESTNUM;TestCnt++)
// {
// RiOrder[TestCnt] = TestData[TestCnt];
// }
// RevOrderCnt = TESTNUM;
// OSTaskResume(ID_COMMANDPARSING);
// SFRPAGE = SMB0_PAGE;
// STA = 1;
uip_len = dev_poll();
if(uip_len == 0)
{
for(i = 0; i < UIP_CONNS; i++)
{
uip_periodic(i);
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0.
如果以上函数调用的数据应该被发送到网络
全局变量uip_len设置为>0的值。*/
if(uip_len > 0)
{
uip_arp_out();
dev_send();
}
}
/* Call the ARP timer function every 10 seconds.
每10秒调用一次ARP定时器功能*/
if(++arptimer == 20)
{
uip_arp_timer();
arptimer = 0;
}
Delayms(1);
}
else
{
if(BUF->type == htons(UIP_ETHTYPE_IP))
{
uip_arp_ipin();
uip_input();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0.
如果以上函数调用的数据应该被发送到网络
全局变量uip_len设置为>0的值。 */
if(uip_len > 0)
{
uip_arp_out();
dev_send();
}
}
else if(BUF->type == htons(UIP_ETHTYPE_ARP))
{
uip_arp_arpin();
/* If the above function invocation resulted in data that
should be sent out on the network, the global variable
uip_len is set to a value > 0.
如果以上函数调用的数据应该被发送到网络
全局变量uip_len设置为>0的值。*/
if(uip_len > 0)
{
dev_send();
}
}
}
}
}
/*uIP call back func回调函数*/
void uip_appcall(void)
{
switch(uip_conn->rport) {
case HTONS(SERVER_PORT):
if(uip_timedout()||uip_aborted()||uip_closed()){
#if AUTO_RECONNECT
/*reconnect to server重新连接到服务器*/
Delayms(1000);
//NetIni();
uip_connect(ipaddr, HTONS(SERVER_PORT));
#endif
}else if(uip_connected()){
#if 1
/*is connected ok 是否连接OK*/
uip_send(uip_appdata,sprintf((char*)uip_appdata,"%s",
"Hello,I connected to you! thanks."));
#endif
}else if(uip_rexmit()){
#if 1
/*need retransmission last packet需要重传最后一个包*/
// uip_send(uip_appdata,sprintf((char*)uip_appdata,"%s",
// "this is retransmission packet"));
uip_send("this is retransmission packet",30);
#endif
}else if(uip_poll()){
/*poll connecte is idle 轮询连接处于闲置状态*/
#if 1
// uip_send(uip_appdata,sprintf((char*)uip_appdata,"%s",
// "Hi, we are idle"));
//uip_send("idle",4);
#endif
}else if(uip_acked()){
/*get a ack for send packet ok得到一个ACK发送包OK*/
#if 0
uip_send(uip_appdata,sprintf((char*)uip_appdata,"%s",
"this is a second packet."));
#endif
if(uip_newdata()){
goto newdata_with_acked;
}
}else if(uip_newdata()){
newdata_with_acked:
#if 1
/*receving a new data接收一个新的数据*/
// uip_appdata[uip_len+0] = ((char*)&uip_len)[0];
// uip_appdata[uip_len+1] = ((char*)&uip_len)[1];
// uip_send(uip_appdata,uip_len+2);
uip_send("OK thanks",10);
#endif
}else{
/*error*/
}
break;
default:
/*discard packet丢弃数据包*/
break;
}
} |
|