/*
 * The initialization function. We must explicitly call this function
 * from the system initialization code, some time after uip_init() is
 * called.
 */
void
iot_tcp_app_init(void)
{
    /* We start to listen for connections on TCP port 7681. */
    uip_listen(HTONS(IoTpAd.ComCfg.Local_TCP_Srv_Port));
#if CFG_SUPPORT_TCPIP_ROBUST_TEST
    uip_listen(HTONS(7684));
#endif

#if UIP_HTTP_CLIENT_SUPPORT
    //http client setting
    //webclient_get("192.168.1.100", HTTP_SERVER_DEFAULT_PORT, "/MT7681_sta_header.bin");
    webclient_get("192.168.2.1", HTTP_SERVER_DEFAULT_PORT, "/index.html");
    //printf_high("http client port:%d\n", http_clientPort);
    uip_listen(HTONS(http_clientPort));
#endif

#if TCP_CLI_APP1_ENABLE
    tcp_cli_app1_init();
#endif

#if TCP_SRV_APP1_ENABLE
    uip_listen(HTONS(TCP_SRV_APP1_LOCAL_PORT));
#endif

#if MY_TCP_SRV_APP_ENABLE
    uip_listen(HTONS(MY_TCP_SRV_APP_LOCAL_PORT));
#endif

#if UIP_CLOUD_SERVER_SUPPORT
    uip_listen(HTONS(CLOUD_TCP_SERVER_PORT));
    cloud_para_check_connect();
#endif

}
Beispiel #2
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(wget_process, ev, data)
{
  PROCESS_BEGIN();

  PRINTF("wget: fetching %s\n", file);
#if STATS
  fetch_counter = 0;
  fetch_started = clock_time();
#endif /* STATS */
  LEDS_ON(LEDS_YELLOW);
  if(webclient_get(server, port, file) == 0) {
    PRINTF("wget: failed to connect\n");
    LEDS_OFF(LEDS_YELLOW);
    fetch_running = 0;
    call_done(WGET_CONNECT_FAILED);
  } else {
    while(fetch_running) {
      PROCESS_WAIT_EVENT();
      if(ev == tcpip_event) {
        webclient_appcall(data);
      }
    }
  }

  PROCESS_END();
}
Beispiel #3
0
/*-----------------------------------------------------------------------------------*/
void
webclient_appcall(void)
{
  if(uip_connected()) {
    s.timer = 0;
    s.state = WEBCLIENT_STATE_STATUSLINE;
    senddata();
    webclient_connected();
    return;
  }

  if(s.state == WEBCLIENT_STATE_CLOSE) {
    webclient_closed();
    uip_abort();
    return;
  }

  if(uip_aborted()) {
    webclient_aborted();
  }
  if(uip_timedout()) {
    webclient_timedout();
  }

  
  if(uip_acked()) {
    s.timer = 0;
    acked();
  }
  if(uip_newdata()) {
    s.timer = 0;
    newdata();
  }
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked()) {
    senddata();
  } else if(uip_poll()) {
    ++s.timer;
    if(s.timer == WEBCLIENT_TIMEOUT) {
      webclient_timedout();
      uip_abort();
      return;
    }
        /*    senddata();*/
  }

  if(uip_closed()) {
    if(s.httpflag != HTTPFLAG_MOVED) {
      /* Send NULL data to signal EOF. */
      webclient_datahandler(NULL, 0);
    } else {
      if(resolv_lookup(s.host) == NULL) {
	resolv_query(s.host);
      }
      webclient_get(s.host, s.port, s.file);
    }
  }
}
Beispiel #4
0
int main(void)
{
	uint8_t i;
        
  P5DIR|=BIT1;
  //P5OUT&=~BIT1;
  P5OUT|=BIT1;
  _DINT();                                //Disable Interrupts   -- For initlization purposes
   WDTCTL = WDTPW + WDTHOLD;               //Stop WDT

   /*
   Set System Clock Frequency to (121+1) * 32786 * 2 = 7.995392Mhz
   This freq. allows for 2400 - 230400 bit rate UART operation with less than 0.86% error
   */
   FLL_CTL0 = (DCOPLUS | XCAP18PF);       //Enable Frequency Multiplier (DCO+) and XIN/XOUT caps to 18pF
   SCFI0 = (FLLD_2 | FN_8);               //Set Multiplier to 2, and DCO range to 8MHz nominal
   SCFQCTL = 121;                         //7.995392Mhz Operation with No Modulation
  
  //setup serial port 
  
#if DEBUG_SERIAL
    debug_serial_init();
    printf("asd  %i",23244);
#endif 
	
	for(i=0;i<6;i++)
		uNet_eth_address.addr[i]=_eth_addr[i];
	
  // init NIC device driver
#if DEBUG_SERIAL
 	
	printf("MAC address:%x:%x:%x:%x:%x:%x\r\n",\
			(int)_eth_addr[0],(int)_eth_addr[1],(int)_eth_addr[2],\
			(int)_eth_addr[3],(int)_eth_addr[4],(int)_eth_addr[5]);

        printf("Initializing NIC...\r\n");
  
#endif

  nic_init(_eth_addr);

  uip_ipaddr_t ipaddr;

  uip_setethaddr(uNet_eth_address);

#if DEBUG_SERIAL
  printf("Initializing uIP...\r\n");
#endif 
  //init uIP
  uip_init();

#if DEBUG_SERIAL
  printf("Initializing ARP...\r\n");
#endif 
  //init ARP cache
  uip_arp_init();

#if DEBUG_SERIAL
  printf("Initializing timer...\r\n");
#endif 
  // init periodic timer
  clock_init();

//#if DEBUG_SERIAL
  printf("Initializing webclient...\r\n");
//#endif 
    webclient_init();
    
  _EINT();                               // reenable interrupts


	if(!_enable_dhcp)
	{

#if DEBUG_SERIAL
  	printf("Initializing tcp/ip settings\r\n");
#endif
	
//#if DEBUG_SERIAL

  	printf("IP %i.%i.%i.%i\r\n",
			(int)_ip_addr[0],(int)_ip_addr[1],(int)_ip_addr[2],(int)_ip_addr[3]);

  	printf("NetMask %i.%i.%i.%i\r\n",
			(int)_net_mask[0],(int)_net_mask[1],(int)_net_mask[2],(int)_net_mask[3]);

  	printf("Gateway %i.%i.%i.%i\r\n",
			(int)_gateway[0],(int)_gateway[1],(int)_gateway[2],(int)_gateway[3]);

//#endif

		uip_ipaddr(ipaddr, _ip_addr[0], _ip_addr[1], _ip_addr[2], _ip_addr[3]);
    uip_sethostaddr(ipaddr);

    uip_ipaddr(ipaddr, _net_mask[0], _net_mask[1], _net_mask[2], _net_mask[3]);
    uip_setnetmask(ipaddr);

		uip_ipaddr(ipaddr, _gateway[0], _gateway[1], _gateway[2], _gateway[3]);
		uip_setdraddr(ipaddr);
	} else {
#if DEBUG_SERIAL
		printf("Going to query DHCP server...\r\n");
#endif

    uip_ipaddr(ipaddr, 0, 0, 0, 0);
    uip_sethostaddr(ipaddr);
    uip_setnetmask(ipaddr);
		uip_setdraddr(ipaddr);
	}

  timer_set(&periodic_timer, CLOCK_SECOND * 2 );
  timer_set(&arp_timer, CLOCK_SECOND * 10);

	
/*
	if(_enable_dhcp)
	{
		dhcpc_init(&uNet_eth_address.addr[0], 6);
		dhcpc_request();
	}
*/
	/* Initialize Scheduler so that it can be used */
	//Scheduler_Init();

	/* Initialize USB Subsystem */
	//USB_Init();

	//Scheduler_SetTaskMode(NetTask, TASK_RUN);


	/* Scheduling - routine never returns, so put this last in the main function */
	//Scheduler_Start();
//#if DEBUG_SERIAL
		printf("Starting main loop...\r\n");
//#endif
	while(1) {
		NetTask();
                webclient_get("www", SERVER_PORT,"/");
	}
}
Beispiel #5
0
/*-----------------------------------------------------------------------------------*/
void
webclient_appcall(void *state)
{
  char *dataptr;
  
  if(uip_connected()) {
    s.timer = 0;
    s.state = WEBCLIENT_STATE_STATUSLINE;
    senddata();
    webclient_connected();
    tcp_markconn(uip_conn, &s);
    return;
  }

  if(uip_timedout()) {
    webclient_timedout();
  }

  if(uip_aborted()) {
    webclient_aborted();
  }

  if(state == NULL) {
    uip_abort();
    return;
  }

  if(s.state == WEBCLIENT_STATE_CLOSE) {
    webclient_closed();
    uip_abort();
    return;
  }


  /* The acked() and newdata() functions may alter the uip_appdata
     ptr, so we need to store it in the "dataptr" variable so that we
     can restore it before the senddata() function is called. */  
  dataptr = uip_appdata;
  
  if(uip_acked()) {
    s.timer = 0;
    acked();
  }
  if(uip_newdata()) {
    s.timer = 0;
    newdata();
  }

  uip_appdata = dataptr;
  
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked()) {
    senddata();
  } else if(uip_poll()) {
    ++s.timer;
    if(s.timer == WEBCLIENT_TIMEOUT) {
      webclient_timedout();
      uip_abort();
      return;
    }
        /*    senddata();*/
  }

  if(uip_closed()) {
    tcp_markconn(uip_conn, NULL);
    if(s.httpflag != HTTPFLAG_MOVED) {
      /* Send NULL data to signal EOF. */
      webclient_datahandler(NULL, 0);
    } else {
      /*      conn = uip_connect(uip_conn->ripaddr, s.port);
      if(conn != NULL) {
	dispatcher_markconn(conn, NULL);
	init_connection();
	}*/
#if UIP_UDP
      if(resolv_lookup(s.host) == NULL) {
	resolv_query(s.host);
      }
#endif /* UIP_UDP */
      webclient_get(s.host, s.port, s.file);
    }
  }
}
Beispiel #6
0
/*---------------------------------------------------------------------------*/
static void
open_url(char *url)
{
  unsigned char i;
  static char host[32];
  char *file;
  register char *urlptr;
  static u16_t addr[2];

  /* Trim off any spaces in the end of the url. */
  urlptr = url + strlen(url) - 1;
  while(*urlptr == ' ' && urlptr > url) {
    *urlptr = 0;
    --urlptr;
  }

  /* Don't even try to go further if the URL is empty. */
  if(urlptr == url) {
    return;
  }

  /* See if the URL starts with http://, otherwise prepend it. */
  if(strncmp(url, http_http, 7) != 0) {
    while(urlptr >= url) {
      *(urlptr + 7) = *urlptr;
      --urlptr;
    }
    strncpy(url, http_http, 7);
  }

  /* Find host part of the URL. */
  urlptr = &url[7];
  for(i = 0; i < sizeof(host); ++i) {
    if(*urlptr == 0 ||
       *urlptr == '/' ||
       *urlptr == ' ' ||
       *urlptr == ':') {
      host[i] = 0;
      break;
    }
    host[i] = *urlptr;
    ++urlptr;
  }

  /* XXX: Here we should find the port part of the URL, but this isn't
     currently done because of laziness from the programmer's side
     :-) */
  
  /* Find file part of the URL. */
  while(*urlptr != '/' && *urlptr != 0) {
    ++urlptr;
  }
  if(*urlptr == '/') {
    file = urlptr;
  } else {
    file = "/";
  }
  
  /* Try to lookup the hostname. If it fails, we initiate a hostname
     lookup and print out an informative message on the statusbar. */
  if(uiplib_ipaddrconv(host, (unsigned char *)addr) == 0) {
    shell_output_str(&wget_command, "Not an IP address", "");
    if(resolv_lookup(host) == NULL) {
      shell_output_str(&wget_command, "Not resolved", "");
      resolv_query(host);
      return;
    }
  }

  /* The hostname we present in the hostname table, so we send out the
     initial GET request. */
  shell_output_str(&wget_command, "Host ", host);
  shell_output_str(&wget_command, "File ", file);

  if(webclient_get(host, 80, file) == 0) {
    shell_output_str(&wget_command, "Out of memory", "");
  } else {
    shell_output_str(&wget_command, "Connecting...", "");
  }
}
Beispiel #7
0
/* open_url():
 *
 * Called when the URL present in the global "url" variable should be
 * opened. It will call the hostname resolver as well as the HTTP
 * client requester.
 */
static void
open_url(void)
{
    unsigned char i;
    static char host[32];
    char *file;
    register char *urlptr;
    static uip_ipaddr_t addr;

    /* Trim off any spaces in the end of the url. */
    urlptr = url + strlen(url) - 1;
    while(*urlptr == ' ' && urlptr > url) {
        *urlptr = 0;
        --urlptr;
    }

    /* Don't even try to go further if the URL is empty. */
    if(urlptr == url) {
        return;
    }

    /* See if the URL starts with http://, otherwise prepend it. */
    if(strncmp(url, http_http, 7) != 0) {
        while(urlptr >= url) {
            *(urlptr + 7) = *urlptr;
            --urlptr;
        }
        strncpy(url, http_http, 7);
    }

    /* Find host part of the URL. */
    urlptr = &url[7];
    for(i = 0; i < sizeof(host); ++i) {
        if(*urlptr == 0 ||
                *urlptr == '/' ||
                *urlptr == ' ' ||
                *urlptr == ':') {
            host[i] = 0;
            break;
        }
        host[i] = *urlptr;
        ++urlptr;
    }

    /* XXX: Here we should find the port part of the URL, but this isn't
       currently done because of laziness from the programmer's side
       :-) */

    /* Find file part of the URL. */
    while(*urlptr != '/' && *urlptr != 0) {
        ++urlptr;
    }
    if(*urlptr == '/') {
        file = urlptr;
    } else {
        file = "/";
    }

#if UIP_UDP
    /* Try to lookup the hostname. If it fails, we initiate a hostname
       lookup and print out an informative message on the statusbar. */
    if(uiplib_ipaddrconv(host, &addr) == 0) {
        uip_ipaddr_t *addrptr;
        if(resolv_lookup(host, &addrptr) != RESOLV_STATUS_CACHED) {
            resolv_query(host);
            show_statustext("Resolving host...");
            return;
        }
        uip_ipaddr_copy(&addr, addrptr);
    }
#else /* UIP_UDP */
    uiplib_ipaddrconv(host, &addr);
#endif /* UIP_UDP */

    /* The hostname we present in the hostname table, so we send out the
       initial GET request. */
    if(webclient_get(host, 80, file) == 0) {
        show_statustext("Out of memory error");
    } else {
        show_statustext("Connecting...");
    }
    redraw_window();
}
Beispiel #8
0
/*-----------------------------------------------------------------------------------*/
void
webclient_appcall(void)
{
	//printf("%s() masuk\r\n", __FUNCTION__);
  if(uip_connected()) {
    s.timer = 0;
    s.state = WEBCLIENT_STATE_STATUSLINE;
    senddata();
    //webclient_connected();
    //printf("%s(): Connected\r\n", __FUNCTION__);
	return;
  }

  if(s.state == WEBCLIENT_STATE_CLOSE) {
    //webclient_closed();
    //printf("%s(): Closed\r\n", __FUNCTION__);
	uip_abort();
    return;
  }

  if(uip_aborted()) {	 
    //webclient_aborted();
	//printf("%s(): Aborted\r\n", __FUNCTION__);
  }
  if(uip_timedout()) {
    //webclient_timedout();
	 //printf("%s(): Timeout 1\r\n", __FUNCTION__);
  }

  
  if(uip_acked()) {
    s.timer = 0;
    acked();
  }
  if(uip_newdata()) {
	  //printf("%s() masuk .... ke f newdata\r\n", __FUNCTION__);
    s.timer = 0;
    newdata();
  }
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked()) {
    senddata();
  } else if(uip_poll()) {
    ++s.timer;
    if(s.timer == WEBCLIENT_TIMEOUT) {
      //webclient_timedout();
	 // printf("%s(): Timeout 2\r\n", __FUNCTION__);
      uip_abort();
      return;
    }
        /*    senddata();*/
  }

  if(uip_closed()) {
    if(s.httpflag != HTTPFLAG_MOVED) {
      /* Send NULL data to signal EOF. */
      webclient_datahandler(NULL, 0);
    } else {
	  /*
	  if(resolv_lookup(s.host) == NULL) {
		resolv_query(s.host);
      }*/
      webclient_get(s.host, s.port, s.file);
    }
  }
}
Beispiel #9
0
static portTASK_FUNCTION( tunggu, pvParameters )
{
	struct t_env *envx;
	envx = (char *) ALMT_ENV;
	
	portBASE_TYPE xARPTimer;
	uip_ipaddr_t xIPAddr;
	int loop;
	int mul;
	unsigned int timer_menit=0;
	unsigned int loop_menit=0;	
	static volatile portTickType xStartTime, xCurrentTime;
	
	vTaskDelay(200);
	
	/* baca environtment (dapat IP dll dulu) */
	baca_env(0);
	printf("UIP : uip_init\r\n");

	uip_init ();
	
	//uip_ipaddr( xIPAddr, uipIP_ADDR0, uipIP_ADDR1, uipIP_ADDR2, uipIP_ADDR3 );
	uip_ipaddr( xIPAddr, envx->IP0, envx->IP1, envx->IP2, envx->IP3 );
	uip_sethostaddr( xIPAddr );

	printf("ARP : arp_init\r\n");
	uip_arp_init ();
	
	printf("Init ENC28J .. ");

	if (enc28j60Init() == 1)	{
		 printf(" .. ENC OK\r\n");
	}	else
		printf("ENC tidak respons !\r\n");

	#ifdef PAKE_HTTP
	printf("SIMPLE HTTP : init\r\n");
	httpd_init ();
	#endif
	
	#ifdef PAKE_TELNETD
	printf("SIMPLE TELNET : init\r\n");
    telnetd_init ();
	#endif

#ifdef BOARD_KOMON
    printf("MONITA : monita init\r\n");
//    monita_init();
#endif
	
#if (PAKAI_KONTROL == 1)
	printf("MONITA : monita kontrol init\r\n");
	kontrol_init();
#endif

//#ifdef BOARD_TAMPILAN
//#ifdef CARI_SUMBERNYA
#ifdef SAMPURASUN_SERVER
	printf("MONITA : sambungan_aktif init\r\n");
	sambungan_init();
	mul = 0;
#endif

#ifdef SAMPURASUN_CLIENT
    //printf("MONITA : monita init\r\n");
    printf("Monita : sampurasun client init !\r\n");
    monita_init();
#endif

#ifdef PAKAI_WEBCLIENT
		int ngitung=0;
		webclient_init();
		printf("webclient inited !\r\n");
		unsigned char datakeserver[512];
		int wclient=0, jmlData=0, nos=0, flag_nos=0, flag_sumber=0, jmlsumbernya=0;
		//int noPMaktif[JML_SUMBER];
		char il[256], dl[256];
		char ipdest[15], angkaangka[5];
		extern int kirimURL;
		extern char terkirimURL;
		extern int  noawal;
		int tiapKirim=950;
		int maxkirim=12;
#endif

#ifdef PAKAI_KIRIM_BALIK
	
	int anginkecil=0;
	int giliran;
	extern int sumber_datanya;
	extern int target_kirim;
	target_kirim = 4-1;
	sumber_datanya=3-1;

	//giliran=1-1;
	
	printf("Kirim Balik inited, Target data: sumber %d, target kirim: %d !\r\n", sumber_datanya+1, target_kirim+1);
#endif

	/*  Initialise the local timers */
	xStartTime = xTaskGetTickCount ();
	xARPTimer = 0;
	
	/* supaya cukup waktu buat siap2 */
	loop = -1000;
	
	#ifdef BOARD_KOMON_420_SABANG
	vTaskDelay(200);
	#endif

	#ifdef PAKAI_WEBCLIENT
		vTaskDelay(2000);
		vTaskDelay(2000);
	#endif
	//printf("mau loop for\r\n");
	for (;;)
	{
		vTaskDelay(1);
		//portYIELD();
		#if 1
		#ifdef PAKAI_WEBCLIENT
		if (envx->statusWebClient==1) {
			wclient++;
			if (envx->burst==1) {
				jmlData=kirimModul(1, 0, 0, il, dl);
				//jmlsumbernya=1;
				tiapKirim = 500;
			} else 
			{			// kirim 1-1
				/*
				#ifdef BANYAK_SUMBER
					struct t_sumber *pmx;
					pmx = (char *) ALMT_SUMBER;
					jmlsumbernya=0;
					for(selang=0; selang<JML_SUMBER; selang++) {
						if (pmx[selang].status==1) {
							printf("selang: %d, status: %d\r\n", selang, pmx[selang].status);
							noPMaktif[jmlsumbernya]=selang;
							jmlsumbernya++;
						}
					}
					if (jmlsumbernya==0) {
						jmlsumbernya=1;
					}
					//jmlData=kirimModul(0, noPMaktif[sumbernya], 0, il, dl);
					printf("jml Data: %d, sumbernya: %d\r\n", jmlData, sumbernya);
					// kenapa ini ??? harusnya tiap detik, knapa jadi tiap 4 detik ????
					//tiapKirim = (int) (100/jmlsumbernya);
					tiapKirim = (int) (195/jmlsumbernya);
					//printf("wclient: %d\r\n", wclient);
				#endif
				//*/
			}	
			if (wclient == tiapKirim) {
				ngitung++;
				
				struct t_sumber *sumber;
				sumber = (char *) ALMT_SUMBER;
				if (!flag_nos) {
					nos++;
					while(sumber[nos-1].status!=1) {	// cari modul sumber aktif
						if (nos>JML_SUMBER) {
							nos=0;
							jmlsumbernya=0;
						}
						nos++;
					}
				}
				jmlsumbernya++;
				//printf("kirim: %5d, nos: %d, wclient: %d, sumber.status: %d, jmlsumbernya: %d\r\n", ngitung, nos-1, wclient, sumber[nos-1].status, jmlsumbernya);
				
				// cek datanya PM ?? // <--- ternyata gak cuma PM, modul lain juga bisa
				if (sumber[nos-1].tipe==0 || sumber[nos-1].tipe==1 || sumber[nos-1].tipe==100)	{	// PM710 || PM810
					jmlData=kirimModul(0, nos-1, noawal, il, dl);
					if (jmlData==12) {
						flag_nos=1;
					} else {		// sudah habis, reset ke 0
						flag_nos=0;
						noawal=0;
					}
					//printf("nilai noawal: %d, flagnos: %d\r\n", noawal, flag_nos);
				} else	{
					jmlData=kirimModul(0, nos-1, 0, il, dl);
					noawal=0;
				}
				
				// hitung jml loop kirim ke server
				if (flag_sumber<jmlsumbernya) {
					flag_sumber=jmlsumbernya;
					tiapKirim=950/jmlsumbernya;
				}
				
				
				wclient = 0;				

				if (jmlData>0) {
					
					sprintf(ipdest, "%d.%d.%d.%d", envx->GW0, envx->GW1, envx->GW2, envx->GW3);
					//portENTER_CRITICAL();
					//sprintf(datakeserver, "%s?i=%s&p=diesel&j=%d&%s&%s", envx->berkas, envx->SN, jmlData, il, dl);
					strcpy(datakeserver, envx->berkas);
					strcat(datakeserver, "?i=");
					strcat(datakeserver, envx->SN);
					strcat(datakeserver, "&p=diesel&j=");
					sprintf(angkaangka, "%d", jmlData);
					strcat(datakeserver, angkaangka);
					strcat(datakeserver, "&");
					strcat(datakeserver, il);
					strcat(datakeserver, "&");
					strcat(datakeserver, dl);
					//portEXIT_CRITICAL();
					//printf("datakeserver: %s\r\n",datakeserver);
					webclient_get(ipdest, 80, datakeserver);
					
				}
			}
		}
		#endif
		
		//#if defined(BOARD_TAMPILAN) || defined (TAMPILAN_MALINGPING) 
		#ifdef SAMPURASUN_SERVER
		//#ifdef CARI_SUMBERNYA
		loop++;
		if (loop > 200) 		// 50, 40, 80
		{
			loop = 0;
			
			sambungan_connect(mul);	
			
			mul++;
			if (mul > JML_SUMBER) mul = 0;
			
		}
		#endif
		
		#ifdef PAKAI_KIRIM_BALIK
			anginkecil++;
			if (anginkecil > 2000) {	/* tiap 2 detik */
				
				kirim_balik_connect(target_kirim);
				
				anginkecil=0;
				//giliran++;
				//if (giliran > JML_SUMBER) mul = 0;
			}
		#endif
		
		//if (enc28j60WaitForData (uipMAX_BLOCK_TIME) == pdTRUE)
		if (cek_paket())	{
			//printf("masuk cekpaket \r\n");
			#if 1
			  paket_per_menit++;
			  /* Let the network device driver read an entire IP packet
		         into the uip_buf. If it returns > 0, there is a packet in the
		         uip_buf buffer. */
		      if ((uip_len = enc28j60Receive ()) > 0)
		      {				  
				  if (pucUIP_Buffer->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. */
		    	            if (uip_len > 0)
		    	            {
		    	              uip_arp_out ();
		    	              enc28j60Send ();
							  paket_kita++;
		    	            }
		    	     }
		    	     else if (pucUIP_Buffer->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)
		    	              enc28j60Send ();
		    	     }

		      }
		      #endif
		}
		else		{
		      /* The poll function returned 0, so no packet was
		         received. Instead we check if it is time that we do the
		         periodic processing. */
		      xCurrentTime = xTaskGetTickCount ();

		      if ((xCurrentTime - xStartTime) >= RT_CLOCK_SECOND)
		      {
		        portBASE_TYPE i;

		        /* Reset the timer. */
		        xStartTime = xCurrentTime;

		        /* Periodic check of all connections. */
		        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)
		          {
		            //printf("S:%d", i);
					uip_arp_out ();
		            enc28j60Send ();
		          }
		        }

		#if UIP_UDP_KU
		        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 ();
		            enc28j60Send ();
		          }
		        }
		#endif /* UIP_UDP */

		        /* Periodically call the ARP timer function. */
		        if (++xARPTimer == uipARP_FREQUENCY)
		        {
		          uip_arp_timer ();
		          xARPTimer = 0;
		        }
		      }
			  
			  	if ((xCurrentTime - timer_menit) >= RT_MENIT)
			  	{
				  	extern unsigned int error_ENC;
					
					timer_menit = xCurrentTime;
					loop_menit++;				
					/*
					printf("%d menit, paket = %d, kita=%d, idle=%d\n", loop_menit, paket_per_menit, paket_kita, loop_idle);
					if (error_ENC != 0)
					{
						printf("ERR ENC = %X\n", error_ENC);	
					}*/
					
					paket_per_menit = 0;
					paket_kita = 0;
				}
		 }	// tanpa paket
		
		/*
		// proses ADC dipindah ke shell 1 Okt 2010// 
		#ifdef PAKAI_ADC
			#ifdef BOARD_KOMON_A_RTD
			proses_data_adc();
			#endif
			 
			#ifdef BOARD_KOMON_B_THERMO
			proses_data_adc();
			#endif
			 
			#ifdef BOARD_KOMON_420_SAJA
			proses_data_adc();
			#endif
		#endif
		//*/
	#endif
	}
}