void ICACHE_FLASH_ATTR network_check_ip(void) 
{
  
  struct ip_info ipconfig;
  os_timer_disarm(&network_timer);
  
  wifi_get_ip_info(STATION_IF, &ipconfig);
  
  if (wifi_station_get_connect_status() == STATION_GOT_IP && ipconfig.ip.addr != 0) 
  {
   
    //char page_buffer[20];
    //os_sprintf(page_buffer,"IP: %d.%d.%d.%d",IP2STR(&ipconfig.ip));
    //uart0_tx_buffer(page_buffer,strlen(page_buffer));
    
 	  os_timer_disarm(&led_timer);
	  os_timer_setfn(&led_timer, (os_timer_func_t *)LedTimer, NULL);
	  os_timer_arm(&led_timer, 500, 1);
    
    network_start();
  } 
  else 
  {
 	  //uart0_tx_buffer("!!NOIP!!",8); 
 	  
 	  os_timer_disarm(&led_timer);
	  os_timer_setfn(&led_timer, (os_timer_func_t *)LedTimer, NULL);
	  os_timer_arm(&led_timer, 2000, 1);

    os_timer_setfn(&network_timer, (os_timer_func_t *)network_check_ip, NULL);
    os_timer_arm(&network_timer, 1000, 0);
  }
}
Ejemplo n.º 2
0
int start_client()
{
	int server_len;
	struct sockaddr_in server_addr;

	LOGD("JNI NETWORK == start Client");
	server_addr.sin_family = AF_INET;
	server_addr.sin_port = htons(TCP_PORT);
	server_addr.sin_addr.s_addr = inet_addr(server_ip);
	server_len = sizeof (server_addr);

	LOGD("JNI NETWORK == connecting server, IP is %s", server_ip);

	sockfd = socket(AF_INET, SOCK_STREAM, 0);
	if (sockfd < 0)
	{
		LOGD("JNI NETWORK == cannot create sockfd: %d", sockfd);
		return -1;
	}

	if (connect(sockfd, (struct sockaddr *) &server_addr, server_len))
	{
		LOGD("JNI NETWORK == cannot connect to server, errno = %d, error = %s", errno, strerror(errno));
		return -1;
	}

	LOGD("JNI NETWORK == server connected");

	network_start();

	return 0;
}
Ejemplo n.º 3
0
int main (int argc, char *argv[]) {
	
	regulator_start();
	network_start("192.168.1.5", 3352);
	for(;;) {
		
		usleep(1000000);
	}
    return 0;
}
Ejemplo n.º 4
0
static void ICACHE_FLASH_ATTR timer_server(void *arg)
{
	static uint8_t state;
	os_timer_disarm(&timer_1);
#ifdef Debug
	ets_uart_printf("Tentando reconectar\n");
#endif
	if(!network_start()){
		return;
	}
}
Ejemplo n.º 5
0
int main (int argc, char *argv[])
{
    LOG_NOTE("============Start============");
    DBHUB->Init();
    ACCOUNTHUB->Init();
    network_start("../../bin/gate/netcfg.xml");
    static char * p = (char *)malloc(MAX_PACKET_SIZE);
    // 注册 
    p_near_register rpack;
    rpack.type = 1;
    rpack.index = server_index;
    get_client_ip_port(rpack.ip,rpack.port);
    send_one_packet((char*)&rpack);
    LOG_NOTE("============Loaded============");
    //
    u64 lastTime = 0;
    u64 elapse = 0;
    while (1)
    {
        packet * pack = proccess_packet(p);
        if (pack) dispatch_packet(pack);
        //=====================================
        //elapse += TIME->Elapse(lastTime);
        //if(elapse > 200)
        //{
        //    p_area_time pTime;
        //    TIME->SysNow();
        //    pTime.gid   = 1;
        //    pTime.guid  = 2;
        //    pTime.hour  = TIME->SysHour();
        //    pTime.min   = TIME->SysMin();
        //    pTime.sec   = TIME->SysSec();
        //    pTime.ms    = TIME->SysMs();
        //    send_one_packet((char *)&pTime);
        //    elapse = 0;
        //    LOG_INFO("gid:%d. sendTime[%d.%3d]",pTime.gid,pTime.sec,pTime.ms);
        //}
        sleep(1);
    }
    //
    network_close();
    getchar();
    return EXIT_SUCCESS;
}
Ejemplo n.º 6
0
//  Entry point
int WINAPI WinMain( HINSTANCE hInst, HINSTANCE prev, LPSTR cmdline, int show )
{
  HWND    hWnd;
  MSG     msg;
  BOOL    bRet;

  //  Detect previous instance, and bail if there is one.
  if ( FindWindow( THIS_CLASSNAME, THIS_TITLE ) )
      return 0;

  //  We have to have a window, even though we never show it.  This is
  //  because the tray icon uses window messages to send notifications to
  //  its owner.  Starting with Windows 2000, you can make some kind of
  //  "message target" window that just has a message queue and nothing
  //  much else, but we'll be backwardly compatible here.
  RegisterApplicationClass( hInst );

  hWnd = CreateWindow( THIS_CLASSNAME, THIS_TITLE,
                       0, 0, 0, 100, 100, NULL, NULL, hInst, NULL );

  if ( ! hWnd ) {
      MessageBox( NULL, _T("Ack! I can't create the window!"), THIS_TITLE,
                  MB_ICONERROR | MB_OK | MB_TOPMOST );
      return 1;
  }

  app_close_listener = &on_close_listener;
  WindowProc_fallback = &app_window_proc;

  network_start( hWnd, SOCKET_MESSAGE );

  //  Message loop
  while ( TRUE ) {
      bRet = GetMessage( &msg, NULL, 0, 0 );
      if ( bRet == 0 || bRet == -1)
        break;
      TranslateMessage( &msg );
      DispatchMessage( &msg );
  }

  UnregisterClass( THIS_CLASSNAME, hInst );

  return msg.wParam;
}
Ejemplo n.º 7
0
int wait_for_client()
{
	int server_sockfd = socket(AF_INET, SOCK_STREAM, 0);

	if (server_sockfd < 0)
	{
		LOGD("JNI LOG Network === cannot create server_sockfd: %d", server_sockfd);
		return -1;
	}

	struct sockaddr_in server_addr;
	server_addr.sin_family = AF_INET;
	server_addr.sin_port = htons(TCP_PORT);
	server_addr.sin_addr.s_addr = INADDR_ANY;
	int server_len = sizeof (server_addr);

	int reuse = 1;
	if (setsockopt(server_sockfd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof (int)) < 0)
	{
		LOGD("JNI LOG Network === setsockopt error: %d, %s", errno, strerror(errno));
		return -1;
	}

	if (bind(server_sockfd, (struct sockaddr *) &server_addr, server_len))
	{
		LOGD("JNI LOG Network === bind socket error: %d, %s", errno, strerror(errno));
		return -1;
	}

	listen(server_sockfd, 5);
	LOGD("JNI LOG Network === waiting for client");

	struct sockaddr_in client_addr;
	int client_len = sizeof (client_addr);

	sockfd = accept(server_sockfd, (struct sockaddr *) &client_addr, &client_len);
	LOGD("JNI LOG Network === client connected");

	network_start();

	close(server_sockfd);

	return 0;
}
Ejemplo n.º 8
0
int main (int argc, char *argv[])
{
    LOG_NOTE("============Start============");
    DBHUB->Init();
    network_start("../../bin/ctrl/netcfg.xml");
    LOG_NOTE("============Loaded============");
    static char * p = (char *)malloc(MAX_PACKET_SIZE);
    while (1)
    {
        packet *pack = proccess_packet(p);
        if (pack) 
            dispatch_packet(pack);
        sleep(1);
    }
    //
    network_close();
    getchar();
    return EXIT_SUCCESS;
}
Ejemplo n.º 9
0
void APL_TaskHandler(void)
{
	switch (network_get_state())
	{
		case APP_INITIAL_STATE:
			
			/* Init Led */
			init_led();
			
			/* Init Serial Interface for debug */ 
  			initSerialInterface();          
			
			uid = get_uid();
			
			/* Init network */
			uid = 2;
			network_init(uid);
			
 			network_set_state(APP_NETWORK_JOIN_REQUEST);
			break;
		case APP_NETWORK_JOIN_REQUEST:
			
			/* Activate the network status led blink */
			led_start_blink();
			
			/* St	art network */
			network_start();
			
			network_set_state(APP_NETWORK_JOINING_STATE);
			
		case APP_NETWORK_JOINING_STATE:
			break;
		case APP_NETWORK_LEAVING_STATE:
			break;
		case APP_NETWORK_JOINED_STATE:
			led_stop_blink();
			break;
		default:
			break;
	}
	SYS_PostTask(APL_TASK_ID);
}
Ejemplo n.º 10
0
int
main(int argc, char *argv[])  {

      /*
       * Check for error conditions that would
       * prevent us from working correctly
       */
    if (argc < 4)  {
          /* So we don't get debug output from dk_errx */
        fprintf(stderr, "Usage: %s path hostname ip [host ip]\n", argv[0]);
        exit(1);
    }

    if (geteuid() != 0)  {
        dk_errx("This program must be run as root");
    }

    if (getpid() == 1)  {
        dk_errx("This program will not function as a regular init(8)");
    }

/*  This breaks sometimes....
    if (check_ip_exists(argv[3]) == 0)  {
        dk_errx("The ip specified: %s, does not appear to exist on this system",
                argv[3]);
    }
*/

      /*
       * The ever-important process title change:
       * Set the title of the process (us) to the hostname
       * of the jail we are to become.
       */
    setproctitle(argv[2]);


      /* Setup signal handlers */
    init_signal_handlers();


      /* Oh yeah, throw ourselves in that cold wet concrete cell with bubba */
    start_jail(argv[1], argv[2], argv[3]);


      /* Make us go into ye-ole bg */
    daemonize();


      /* actually start the "virtual" machine. */
    start_system();


      /* Go into accept loop */
    if (argc == 5)  {
        network_start(argv[4]);
    }  else  {
        for ( ; ; )  sleep(100000);
    }

    return -1;
}