void example2_init(void) {
uip_listen(HTONS(2345));
}
void example2_app(void) {
struct example2_state *s;
s = (struct example2_state *)uip_conn->appstate;
if(uip_connected()) {
s->state = WELCOME_SENT;
uip_send("Welcome!\n", 9);
//DBGMSG("app connected \n");
return;
}
if(uip_acked()) {
switch(s->state){
case(WELCOME_SENT):
s->state= WELCOME_ACKED;
uip_send("Wbcdefghijklmnopqrstuvwxyz", 26);
break;
case(WELCOME_ACKED):
s->state=TX_SYNC_ING;
uip_send("CBCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
break;
case(TX_SYNC_ING):
s->state=WELCOME_ACKED;
uip_send("Sbcdefghijklmnopqrstuvwxyz", 26);
break;
}
// DBGMSG("app acked \n");
}
if(uip_poll()){
DBGMSG("app poll \n");
}
if(uip_newdata()) {
if( s->state=WELCOME_ACKED){
s->state=TX_SYNC_ING;
uip_send("NSCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
}else{
s->state=WELCOME_ACKED;
uip_send("NAcdefghijklmnopqrstuvwxyz", 26);
}
//DBGMSG("app newdata \n");
}
if(uip_rexmit()) {
DBGMSG("rxm\n");
switch(s->state) {
case WELCOME_SENT:
uip_send("Welcome!\n", 9);
break;
case WELCOME_ACKED:
s->state=TX_SYNC_ING;
uip_send("RCcdefghijklmnopqrstuvwxyz", 26);
break;
case TX_SYNC_ING:
s->state=WELCOME_ACKED;
uip_send("RSCDEFGHIJKLMNOPQRSTUVWXYZ", 26);
break;
}
}
}
/*-------------------------------------------------------------------------*/
void uip_task_init()
{
uip_ipaddr_t ipaddr;
//tapdev_init();
uip_init();
uip_arp_init();
landev_init();
uip_ipaddr(ipaddr, 192,168,1,2);
uip_sethostaddr(ipaddr);
uip_ipaddr(ipaddr, 192,168,1,64);
uip_setdraddr(ipaddr);
uip_ipaddr(ipaddr, 255,255,255,0);
uip_setnetmask(ipaddr);
example2_init();
}
/*---------------------------------------------------------------------------*/
void uip_main(void *arg)
{
int i;
struct timer periodic_timer, arp_timer;
timer_set(&periodic_timer, 1000);
timer_set(&arp_timer, 1000* 10);
uip_task_init();
while(1) {
//uip_len = landev_read();
uip_len = landev_read();
if(uip_len > 0) {
if(BUF->type == htons(UIP_ETHTYPE_IP)) {
uip_arp_ipin();
uip_input();
//DBGMSG("ip input\n");
/* 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. */
if(uip_len > 0) {
uip_arp_out();
landev_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. */
if(uip_len > 0) {
landev_send();
}
}
} else if(timer_expired(&periodic_timer)) {
timer_reset(&periodic_timer);
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. */
if(uip_len > 0) {
uip_arp_out();
landev_send();
}
}
#if UIP_UDP
for(i = 0; i < UIP_UDP_CONNS; i++) {
uip_udp_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. */
if(uip_len > 0) {
uip_arp_out();
landev_send();
}
}
#endif /* UIP_UDP */
/* Call the ARP timer function every 10 seconds. */
if(timer_expired(&arp_timer)) {
timer_reset(&arp_timer);
uip_arp_timer();
}
}
}
//return 0;
}
|