コード例 #1
0
ファイル: mobile_main.c プロジェクト: johnboiles/KinectWings
DEFINE_THREAD_ROUTINE(mobile_main, data)
{
	C_RESULT res = C_FAIL;
	vp_com_wifi_config_t *config = NULL;
	
	mobile_main_param_t *param = (mobile_main_param_t *)data;

	ardroneEngineCallback callback = param->callback;
	vp_os_memset(drone_address, 0x0, sizeof(drone_address));

  // TODO(johnb): Make this autodetect based on network interfaces
	while(((config = (vp_com_wifi_config_t *)wifi_config()) != NULL) && (strcmp(config->itfName, WIFI_ITFNAME) != 0))
	{
		PRINT("Wait WIFI connection !\n");
		vp_os_delay(250);
	}
	
	// Get drone_address
	vp_os_memcpy(drone_address, config->server, strlen(config->server));
	PRINT("Drone address %s\n", drone_address);
	
	// Get iphone_mac_address
	get_iphone_mac_address(config->itfName);
	PRINT("Iphone MAC Address %s\n", iphone_mac_address);
	
	res = ardrone_tool_setup_com( NULL );
	
	if( FAILED(res) )
	{
		PRINT("Wifi initialization failed. It means either:\n");
		PRINT("\t* you're not root (it's mandatory because you can set up wifi connection only as root)\n");
		PRINT("\t* wifi device is not present (on your pc or on your card)\n");
		PRINT("\t* you set the wrong name for wifi interface (for example rausb0 instead of wlan0) \n");
		PRINT("\t* ap is not up (reboot card or remove wifi usb dongle)\n");
		PRINT("\t* wifi device has no antenna\n");
	}
	else
	{
		START_THREAD(video_stage, NULL);
		
		res = ardrone_tool_init(drone_address, strlen(drone_address), NULL, param->appName, param->usrName);
		
		callback(ARDRONE_ENGINE_INIT_OK);
		
		ardrone_tool_set_refresh_time(1000 / kAPS);

		while( SUCCEED(res) && bContinue == TRUE )
		{
			ardrone_tool_update();
		}
		
		JOIN_THREAD(video_stage);

		res = ardrone_tool_shutdown();
	}
	
	vp_os_free (data);
	
	return (THREAD_RET)res;
}
コード例 #2
0
ファイル: app.c プロジェクト: lxy0816/Ardrone_video
void parrot_ardrone_notify_exit()
{
	parrot_ardrone_notify_pause();
	bContinue = FALSE;

	ardrone_tool_shutdown();

	LOGD(TAG, "AR.Drone Tool Stop [OK]");
}
コード例 #3
0
ファイル: mobile_main.c プロジェクト: ericyao2013/ARdroneUAV
DEFINE_THREAD_ROUTINE(mobile_main, data)
{
	C_RESULT res = C_FAIL;
    char drone_address[64];
	unsigned long theAddr;
	ardroneEngineCallback callback = (ardroneEngineCallback)data;
	vp_os_memset(drone_address, 0x0, sizeof(drone_address));
	
	while((theAddr = deviceIPAddress(WIFI_ITFNAME, iphone_mac_address)) == LOCALHOST)
	{
		PRINT("Wait WIFI connection !\n");
		vp_os_delay(250);
	}
	
	struct in_addr drone_addr;
	drone_addr.s_addr = htonl( ntohl((in_addr_t)theAddr) - 1 );
	vp_os_memcpy(drone_address, inet_ntoa(drone_addr), strlen(inet_ntoa(drone_addr)));
	PRINT("Drone address %s\n", drone_address);
	PRINT("Iphone MAC Address %s\n", iphone_mac_address);
	res = ardrone_tool_setup_com( NULL );
	
	if( FAILED(res) )
	{
		PRINT("Wifi initialization failed. It means either:\n");
		PRINT("\t* you're not root (it's mandatory because you can set up wifi connection only as root)\n");
		PRINT("\t* wifi device is not present (on your pc or on your card)\n");
		PRINT("\t* you set the wrong name for wifi interface (for example rausb0 instead of wlan0) \n");
		PRINT("\t* ap is not up (reboot card or remove wifi usb dongle)\n");
		PRINT("\t* wifi device has no antenna\n");
	}
	else
	{
		res = ardrone_tool_init(drone_address, strlen(drone_address), NULL);
		
		callback(ARDRONE_ENGINE_INIT_OK);
		
		if(SUCCEED(res))
		{   
			START_THREAD(video_stage, NULL);
			
			res = ardrone_tool_set_refresh_time(1000 / kAPS);

			while( SUCCEED(res) && bContinue == TRUE )
			{
				res = ardrone_tool_update();
			}

			JOIN_THREAD(video_stage);
		}
		
		res = ardrone_tool_shutdown();
	}
	
	return (THREAD_RET)0;
}
コード例 #4
0
ファイル: app.c プロジェクト: Aidsy/ARDroneSDK
DEFINE_THREAD_ROUTINE(mobile_main, data)
{
	__android_log_print( ANDROID_LOG_INFO, "ARDrone", "Enter in mobile_main thread\n" );
	C_RESULT res = C_OK;
	char drone_address[24];

	vp_os_memset(drone_address, 0x0, sizeof(drone_address));
	sprintf(drone_address, WIFI_ARDRONE_IP);

	res = ardrone_tool_setup_com( NULL );

	if( FAILED(res) )
	{
		__android_log_print( ANDROID_LOG_INFO, "ARDrone", "Setup com failed\n" );
		INFO("Wifi initialization failed. It means either:\n");
		INFO("\t* you're not root (it's mandatory because you can set up wifi connection only as root)\n");
		INFO("\t* wifi device is not present (on your pc or on your card)\n");
		INFO("\t* you set the wrong name for wifi interface (for example rausb0 instead of wlan0) \n");
		INFO("\t* ap is not up (reboot card or remove wifi usb dongle)\n");
		INFO("\t* wifi device has no antenna\n");
	}
	else
	{
		START_THREAD(video_stage, NULL);

		__android_log_print( ANDROID_LOG_INFO, "ARDrone", "Processing ardrone_tool_init\n" );
		res = ardrone_tool_init(drone_address, strlen(drone_address), NULL);

      control_ack_init();
      control_ack_configure_navdata_demo( FALSE );

		if(SUCCEED(res))
		{   
			res = ardrone_tool_set_refresh_time(25);

			while( SUCCEED(res) && bContinue == TRUE )
			{
				res = ardrone_tool_update();
			}
		}

		JOIN_THREAD(video_stage);

		res = ardrone_tool_shutdown();
	}

	__android_log_print( ANDROID_LOG_INFO, "ARDrone", "Exit mobile_main thread\n" );
	return (THREAD_RET)0;
}
コード例 #5
0
/*void test(void * null){
	while(1){
		printf("将来在这里处理无人机控制事件");
		//sleep(2);
	}}*/
int main(int argc, char **argv)
{
    C_RESULT res;
    const char* appname = argv[0];
    WSADATA wsaData = {0};
    int iResult = 0;
    iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
    if (iResult != 0) {
        wprintf(L"WSAStartup failed: %d\n", iResult);
        return 1;
    }


#include <VP_Os/vp_os_signal.h>
#if defined USE_PTHREAD_FOR_WIN32
#pragma comment (lib,"pthreadVC2.lib")
#endif

    res = test_drone_connection();//检测WiFi连接
    if(res!=0) {
        printf("%s","Could not detect the drone version ... press <Enter> to try connecting anyway.\n");
        getchar();
        WSACleanup();
        exit(-1);
    }

    init_client();
    res = ardrone_tool_setup_com( NULL );//配置AT命令,视频传输
    if( FAILED(res) ) {
        PRINT("Wifi initialization failed.\n");
        return -1;
    }

    res = ardrone_tool_init(argc, argv);//调用ardrone_tool_init_custom()函数
    while( VP_SUCCEEDED(res) && ardrone_tool_exit() == FALSE ) {
        res = ardrone_tool_update();
    }//循环调用ardrone_too_update()函数

    res = ardrone_tool_shutdown();
    closesocket(ConnectSocket);
    WSACleanup();
    system("cls");
    printf("End of SDK Demo for Windows\n");
    getchar();
    return VP_SUCCEEDED(res) ? 0 : -1;
}
コード例 #6
0
	BOOL _stdcall ShutdownDrone()
	{
      C_RESULT res = ardrone_tool_shutdown();
    
	  WSACleanup();



		//start^=1; 
		//ardrone_tool_set_ui_pad_start(start);  
		//printf("Sending start %i.%s\n",start,linefiller); 

     	// * @param enable 1,with pitch,roll and 0,without pitch,roll.
		// * @param pitch Using floating value between -1 to +1. 
		// * @param roll Using floating value between -1 to +1.
		// * @param gaz Using floating value between -1 to +1.
		// * @param yaw Using floating value between -1 to +1.

		//ardrone_at_set_progress_cmd((hovering)? 0:1, roll, pitch, gaz, yaw);
	  
	  
	  return VP_SUCCEEDED(res) ? 0 : -1;
	}
コード例 #7
0
ファイル: DroneControlC.c プロジェクト: SaiVineethKS/BioMAV
int drone_free() {
  pthread_mutex_lock(&drone_sharedDataMutex);
  pthread_mutex_lock(&drone_navdataCallbackMutex);
  drone_doRun = 0;
  drone_navdataCallback = NULL;
  pthread_mutex_unlock(&drone_navdataCallbackMutex);
  pthread_mutex_unlock(&drone_sharedDataMutex);

  printf("Joining main thread\n");
  JOIN_THREAD(drone_main_thread);

  drone_doRunArdrone = 0;

  if (drone_receivedFirstNavdata) {
    ardrone_tool_shutdown();
  } else {
    fprintf(stderr, "Warning! Did not shut down ardrone_tool because there was never a connection with the drone (freeze protection)!");
  }

  drone_userdata = NULL;

  return 1;
}
コード例 #8
0
int main(int argc, char **argv)
{
  C_RESULT res;
  const char* old_locale;
  const char* appname = argv[0];
  int argc_backup = argc;
  char** argv_backup = argv;

  bool_t show_usage = FAILED( ardrone_tool_check_argc_custom(argc) ) ? TRUE : FALSE;

  argc--; argv++;
  while( argc && *argv[0] == '-' )
  {
    if( !strcmp(*argv, "-?") || !strcmp(*argv, "-h") || !strcmp(*argv, "-help") || !strcmp(*argv, "--help") )
    {
      ardrone_tool_usage( appname );
      exit( 0 );
    }
    else if( !ardrone_tool_parse_cmd_line_custom( *argv ) )
    {
      printf("Option %s not recognized\n", *argv);
      show_usage = TRUE;
    }

    argc--; argv++;
  }

  if( show_usage || (argc != 0) )
  {
    ardrone_tool_usage( appname );
    exit(-1);
  }
  
  /* After a first analysis, the arguments are restored so they can be passed to the user-defined functions */
  argc=argc_backup;
  argv=argv_backup;
  
  old_locale = setlocale(LC_NUMERIC, "en_GB.UTF-8");

  if( old_locale == NULL )
  {
    PRINT("You have to install new locales in your dev environment! (avoid the need of conv_coma_to_dot)\n");
    PRINT("As root, do a \"dpkg-reconfigure locales\" and add en_GB.UTF8 to your locale settings\n");
    PRINT("If you have any problem, feel free to contact Pierre Eline ([email protected])\n");
  }
  else
  {
    PRINT("Setting locale to %s\n", old_locale);
  }

  vp_com_wifi_config_t *config = (vp_com_wifi_config_t*)wifi_config();
  if(config)
  {
	  vp_os_memset( &wifi_ardrone_ip[0], 0, sizeof(wifi_ardrone_ip) );
	  printf("===================+> %s\n", config->server);
	  strcpy( &wifi_ardrone_ip[0], config->server);
  }

  if( &custom_main )
  {
    return custom_main(argc, argv);
  }
  else
  {
	res = ardrone_tool_setup_com( NULL );

    if( FAILED(res) )
    {
      PRINT("Wifi initialization failed. It means either:\n");
      PRINT("\t* you're not root (it's mandatory because you can set up wifi connection only as root)\n");
      PRINT("\t* wifi device is not present (on your pc or on your card)\n");
      PRINT("\t* you set the wrong name for wifi interface (for example rausb0 instead of wlan0) \n");
      PRINT("\t* ap is not up (reboot card or remove wifi usb dongle)\n");
      PRINT("\t* wifi device has no antenna\n");
    }
    else
    {
      res = ardrone_tool_init(argc, argv);

      while( SUCCEED(res) && ardrone_tool_exit() == FALSE )
      {
        res = ardrone_tool_update();
      }

      res = ardrone_tool_shutdown();
    }
  }

  if( old_locale != NULL )
  {
    setlocale(LC_NUMERIC, old_locale);
  }

  return SUCCEED(res) ? 0 : -1;
}
コード例 #9
0
ファイル: ardrone_tool.c プロジェクト: lxy0816/Ardrone_video
int ardrone_tool_main(int argc, char **argv)
{
  C_RESULT res;
  const char* old_locale;
  const char* appname = argv[0];
  int argc_backup = argc;
  char** argv_backup = argv;
  char * drone_ip_address = NULL;
  struct in_addr drone_ip_address_in;

  bool_t show_usage = FAILED( ardrone_tool_check_argc_custom(argc) ) ? TRUE : FALSE;

  argc--; argv++;
  while( argc && *argv[0] == '-' )
  {
    if( !strcmp(*argv, "-ip") && ( argc > 1 ) )
    {
    	drone_ip_address = *(argv+1);
    	printf("Using custom ip address %s\n",drone_ip_address);
	    argc--; argv++;
    }
    else if( !strcmp(*argv, "-?") || !strcmp(*argv, "-h") || !strcmp(*argv, "-help") || !strcmp(*argv, "--help") )
    {
      ardrone_tool_usage( appname );
      exit( 0 );
    }
    else if( !ardrone_tool_parse_cmd_line_custom( *argv ) )
    {
      printf("Option %s not recognized\n", *argv);
      show_usage = TRUE;
    }

    argc--; argv++;
  }

  if( show_usage || (argc != 0) )
  {
    ardrone_tool_usage( appname );
    exit(-1);
  }
  
  /* After a first analysis, the arguments are restored so they can be passed to the user-defined functions */
  argc=argc_backup;
  argv=argv_backup;
  
  old_locale = setlocale(LC_NUMERIC, "en_GB.UTF-8");

  if( old_locale == NULL )
  {
    PRINT("You have to install new locales in your dev environment! (avoid the need of conv_coma_to_dot)\n");
    PRINT("As root, do a \"dpkg-reconfigure locales\" and add en_GB.UTF8 to your locale settings\n");
  }
  else
  {
    PRINT("Setting locale to %s\n", old_locale);
  }

  vp_com_wifi_config_t *config = (vp_com_wifi_config_t*)wifi_config();
  
  if(config)
  {
	  vp_os_memset( &wifi_ardrone_ip[0], 0, sizeof(wifi_ardrone_ip) );

	  if(drone_ip_address && inet_aton(drone_ip_address,&drone_ip_address_in)!=0)
	  {
	  /* If the drone IP address was given on the command line and is valid */
  	  	printf("===================+> %s\n", drone_ip_address);
        strncpy( &wifi_ardrone_ip[0], drone_ip_address, sizeof(wifi_ardrone_ip)-1);
      }
      else
	  {
		printf("===================+> %s\n", config->server);
		strncpy( &wifi_ardrone_ip[0], config->server, sizeof(wifi_ardrone_ip)-1);
	  }
  }

  while (-1 == getDroneVersion (root_dir, wifi_ardrone_ip, &ardroneVersion))
    {
      printf ("Getting AR.Drone version ...\n");
      vp_os_delay (250);
    }

	res = ardrone_tool_setup_com( NULL );

	if( FAILED(res) )
	{
	  PRINT("Wifi initialization failed. It means either:\n");
	  PRINT("\t* you're not root (it's mandatory because you can set up wifi connection only as root)\n");
	  PRINT("\t* wifi device is not present (on your pc or on your card)\n");
	  PRINT("\t* you set the wrong name for wifi interface (for example rausb0 instead of wlan0) \n");
	  PRINT("\t* ap is not up (reboot card or remove wifi usb dongle)\n");
	  PRINT("\t* wifi device has no antenna\n");
	}
	else
	{
		// Save appname/appid for reconnections
		char *appname = NULL;
		int lastSlashPos;
		/* Cut the invoking name to the last / or \ character on the command line
		* This avoids using differents app_id for applications called from different directories
		* e.g. if argv[0] is "Build/Release/ardrone_navigation", appname will point to "ardrone_navigation" only
		*/
		for (lastSlashPos = strlen (argv[0])-1; lastSlashPos > 0 && argv[0][lastSlashPos] != '/' && argv[0][lastSlashPos] != '\\'; lastSlashPos--);
		appname = &argv[0][lastSlashPos+1];
		ardrone_gen_appid (appname, __SDK_VERSION__, app_id, app_name, sizeof (app_name));
		res = ardrone_tool_init(wifi_ardrone_ip, strlen(wifi_ardrone_ip), NULL, appname, NULL, NULL, NULL, MAX_FLIGHT_STORING_SIZE, NULL);

      while( SUCCEED(res) && ardrone_tool_exit() == FALSE )
      {
        res = ardrone_tool_update();
      }

      res = ardrone_tool_shutdown();
    }

  if( old_locale != NULL )
  {
    setlocale(LC_NUMERIC, old_locale);
  }

  return SUCCEED(res) ? 0 : -1;
}
コード例 #10
0
DEFINE_THREAD_ROUTINE(ihm, data)
{
	C_RESULT res;

	WSADATA wsaData = {0};
	int iResult = 0;


	/* Initializes Windows socket subsystem */
	iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
	if (iResult != 0)
	{
		wprintf(L"WSAStartup failed: %d\n", iResult);
		return 1;
	}

 
	/* Initializes communication sockets */	
	res = test_drone_connection(); // Nick disabled the press enter (wait)
	if(res!=0)
	{
		printf("%s","Could not detect the drone version ... press <Enter> to try connecting anyway.\n");
		getchar();
		//WSACleanup();
		exit(-1);
	}


	res = ardrone_tool_setup_com( NULL );
	if( FAILED(res) )
	{
		PRINT("Wifi initialization failed.\n");
		return -1;
	}


	START_THREAD(video_stage, 0);

	res = ardrone_tool_init(WIFI_ARDRONE_IP, strlen(WIFI_ARDRONE_IP), NULL, ARDRONE_CLIENT_APPNAME, ARDRONE_CLIENT_USRNAME);

	ardrone_tool_set_refresh_time(20); // 20 ms

	ardrone_at_reset_com_watchdog();


	// config
	ardrone_control_config.euler_angle_max = 0.20943951f; // 12 degrees
	ardrone_control_config.video_channel	= ZAP_CHANNEL_VERT;
	ardrone_control_config.video_codec		= UVLC_CODEC; //P264_CODEC;
	ardrone_control_config.navdata_demo		= FALSE;
	ardrone_control_config.altitude_max		= 10000;
	ardrone_control_config.control_vz_max	= 1000.0f;
	ardrone_control_config.outdoor			= FALSE;
	//ardrone_control_config.flight_without_shell = TRUE;


	ARDRONE_TOOL_CONFIGURATION_ADDEVENT(video_channel, &ardrone_control_config.video_channel, (ardrone_tool_configuration_callback) ardrone_demo_config_callback);
	//ARDRONE_TOOL_CONFIGURATION_ADDEVENT(video_channel, &ardrone_control_config.video_channel, NULL);
	//ARDRONE_TOOL_CONFIGURATION_ADDEVENT(video_codec, &ardrone_control_config.video_codec, NULL);
	ARDRONE_TOOL_CONFIGURATION_ADDEVENT (navdata_demo, &ardrone_control_config.navdata_demo, NULL);
	ARDRONE_TOOL_CONFIGURATION_ADDEVENT (altitude_max, &ardrone_control_config.altitude_max, NULL);
	ARDRONE_TOOL_CONFIGURATION_ADDEVENT (control_vz_max, &ardrone_control_config.control_vz_max, NULL);
	//ARDRONE_TOOL_CONFIGURATION_ADDEVENT (outdoor, &ardrone_control_config.outdoor, NULL);
	//ARDRONE_TOOL_CONFIGURATION_ADDEVENT (flight_without_shell, &ardrone_control_config.flight_without_shell, NULL);
	ARDRONE_TOOL_CONFIGURATION_ADDEVENT (euler_angle_max, &ardrone_control_config.euler_angle_max, NULL);


	// flat trim
	ardrone_at_set_flat_trim();


	//SetEvent(ardrone_ready);
	//ardrone_demo_redirect_to_interface = 1;


	while( VP_SUCCEEDED(res) && ardrone_tool_exit() == FALSE )
	{
		res = ardrone_tool_update();
	}

	JOIN_THREAD(video_stage);

	res = ardrone_tool_shutdown();

	WSACleanup();

	return (THREAD_RET)res;
}
コード例 #11
0
int main(int argc , char** argv)
{
  int cnt=0;
    
	  C_RESULT res;					// functions return value


	  WSADATA wsaData = {0};
	  int iResult = 0;

    
	/* Initializes Windows socket subsystem */
		iResult = WSAStartup(MAKEWORD(2, 2), &wsaData);
		if (iResult != 0) {	wprintf(L"WSAStartup failed: %d\n", iResult);	return 1;	}
			
	/* Includes the Pthread for Win32 Library if necessary */
		#include <VP_Os/vp_os_signal.h>
			#if defined USE_PTHREAD_FOR_WIN32
			#pragma comment (lib,"pthreadVC2.lib")
			#endif
#ifdef VIDEO_RECORD
  cv_writer = cvCreateVideoWriter("D:\\out.avi",-1,15,cvSize(320,240),1);
#endif
  cv_image = cvCreateImage(cvSize(320,240),IPL_DEPTH_8U,3);
  //Kinect_Init();
	/* 	Initializes communication sockets	*/	
    hSocketThread = CreateThread(NULL,0,Socket_ProcessThread,NULL,0,0);
   // while (1);
		res = test_drone_connection();
		if(res!=0){
			printf("%s","Could not detect the drone version ... press <Enter> to try connecting anyway.\n");
			getchar();
			//WSACleanup(); exit(-1);
		}

		res = ardrone_tool_setup_com( NULL );
		if( FAILED(res) ){  PRINT("Wifi initialization failed.\n");  return -1;	}

	/* Initialises ARDroneTool */
	   res = ardrone_tool_init(argc, argv);

    /*record video*/
     
     
   /* Keeps sending AT commands to control the drone as long as 
		everything is OK */

      while( VP_SUCCEEDED(res) && ardrone_tool_exit() == FALSE) {
#ifdef VIDEO_RECORD
        if ( cnt++ > 3000 )
          cvReleaseVideoWriter(&cv_writer);
#endif
        res = ardrone_tool_update();     
    
      }
      printf("out\n");
   /**/
      //close Socket Thread
    if ( hSocketThread!=NULL ) {
      WaitForSingleObject(hSocketThread,INFINITE);
      CloseHandle(hSocketThread);
    }
      res = ardrone_tool_shutdown();
    //Kinect_UnInit();
	  WSACleanup();

  /* Bye bye */
  cvReleaseVideoWriter(&cv_writer);
	system("cls");
	  printf("End of SDK Demo for Windows\n");
	  getchar();
	  return VP_SUCCEEDED(res) ? 0 : -1;
}
コード例 #12
0
ファイル: app.c プロジェクト: lxy0816/Ardrone_video
DEFINE_THREAD_ROUTINE(app_main, data)
{

	C_RESULT res = C_FAIL;
	vp_com_wifi_config_t* config = NULL;

	JNIEnv* env = NULL;

	if (g_vm) {
		(*g_vm)->AttachCurrentThread (g_vm, (JNIEnv **) &env, NULL);
	}

	bContinue = TRUE;
	mobile_main_param_t *param = data;

    video_recorder_thread_param_t video_recorder_param;
    video_recorder_param.priority = VIDEO_RECORDER_THREAD_PRIORITY;
    video_recorder_param.finish_callback = param->academy_download_callback_func;

	vp_os_memset(&ardrone_info, 0x0, sizeof(ardrone_info_t));

	while ((config = (vp_com_wifi_config_t *)wifi_config()) != NULL && strlen(config->itfName) == 0)
	{
		//Waiting for wifi initialization
		vp_os_delay(250);

		if (ardrone_tool_exit() == TRUE) {
			if (param != NULL && param->callback != NULL) {
				param->callback(env, param->obj, ARDRONE_MESSAGE_DISCONNECTED);
			}
			return 0;
		}
	}



	vp_os_memcpy(&ardrone_info.drone_address[0], config->server, strlen(config->server));


    while (-1 == getDroneVersion (param->root_dir, &ardrone_info.drone_address[0], &ardroneVersion))
    {
        LOGD (TAG, "Getting AR.Drone version");
        vp_os_delay (250);
    }

    sprintf(&ardrone_info.drone_version[0], "%u.%u.%u", ardroneVersion.majorVersion, ardroneVersion.minorVersion, ardroneVersion.revision);

    LOGD (TAG, "ARDrone Version : %s\n", &ardrone_info.drone_version[0]);
	LOGI(TAG, "Drone Family: %d", ARDRONE_VERSION());

	res = ardrone_tool_setup_com( NULL );

	if( FAILED(res) )
	{
		LOGII("Setup com failed");
		LOGW(TAG, "Wifi initialization failed. It means either:");
		LOGW(TAG, "\t* you're not root (it's mandatory because you can set up wifi connection only as root)\n");
		LOGW(TAG, "\t* wifi device is not present (on your pc or on your card)\n");
		LOGW(TAG, "\t* you set the wrong name for wifi interface (for example rausb0 instead of wlan0) \n");
		LOGW(TAG, "\t* ap is not up (reboot card or remove wifi usb dongle)\n");
		LOGW(TAG, "\t* wifi device has no antenna\n");

		if (param != NULL && param->callback != NULL) {
			param->callback(env, param->obj, ARDRONE_MESSAGE_ERR_NO_WIFI);
		}
	}
	else
	{
		LOGII("ardrone_tool_setup_com [OK]");
		#define NB_IPHONE_PRE_STAGES 0

		#define NB_IPHONE_POST_STAGES 2

        //Alloc structs
        specific_parameters_t * params         = (specific_parameters_t *)vp_os_calloc(1, sizeof(specific_parameters_t));
        specific_stages_t * iphone_pre_stages  = (specific_stages_t*)vp_os_calloc(1, sizeof(specific_stages_t));
        specific_stages_t * iphone_post_stages = (specific_stages_t*)vp_os_calloc(1, sizeof(specific_stages_t));
        vp_api_picture_t  * in_picture         = (vp_api_picture_t*) vp_os_calloc(1, sizeof(vp_api_picture_t));
        vp_api_picture_t  * out_picture        = (vp_api_picture_t*) vp_os_calloc(1, sizeof(vp_api_picture_t));


        in_picture->width          = STREAM_WIDTH;
        in_picture->height         = STREAM_HEIGHT;

        out_picture->framerate     = 20;
        out_picture->format        = PIX_FMT_RGB565;
        out_picture->width         = STREAM_WIDTH;
        out_picture->height        = STREAM_HEIGHT;

        out_picture->y_buf         = vp_os_malloc( STREAM_WIDTH * STREAM_HEIGHT * 2 );
        out_picture->cr_buf        = NULL;
        out_picture->cb_buf        = NULL;

        out_picture->y_line_size   = STREAM_WIDTH * 2;
        out_picture->cb_line_size  = 0;
        out_picture->cr_line_size  = 0;

        //Define the list of stages size
        iphone_pre_stages->length  = NB_IPHONE_PRE_STAGES;
        iphone_post_stages->length = NB_IPHONE_POST_STAGES;

        //Alloc the lists
        iphone_pre_stages->stages_list  = NULL;
        iphone_post_stages->stages_list = (vp_api_io_stage_t*)vp_os_calloc(iphone_post_stages->length,sizeof(vp_api_io_stage_t));

        //Fill the POST-stages------------------------------------------------------
        int postStageNumber = 0;

        vp_os_memset (&vlat, 0x0, sizeof (vlat));
        vlat.state = 0;
        vlat.last_decoded_frame_info= (void *)&vec;
        iphone_post_stages->stages_list[postStageNumber].type  = VP_API_FILTER_DECODER;
        iphone_post_stages->stages_list[postStageNumber].cfg   = (void *)&vlat;
        iphone_post_stages->stages_list[postStageNumber++].funcs = vp_stages_latency_estimation_funcs;

        vp_os_memset (&ovsc, 0x0, sizeof (ovsc));
        ovsc.video_decoder = &vec;
        iphone_post_stages->stages_list[postStageNumber].type  = VP_API_OUTPUT_LCD;
        iphone_post_stages->stages_list[postStageNumber].cfg   = (void *)&ovsc;
        iphone_post_stages->stages_list[postStageNumber++].funcs = opengl_video_stage_funcs;

        params->in_pic = in_picture;
        params->out_pic = out_picture;
        params->pre_processing_stages_list = iphone_pre_stages;
        params->post_processing_stages_list = iphone_post_stages;

#if USE_THREAD_PRIORITIES
        params->needSetPriority = 1;
        params->priority = VIDEO_THREAD_PRIORITY;
#else
        params->needSetPriority = 0;
        params->priority = 0;
#endif


		START_THREAD(video_stage, params);

        if (IS_LEAST_ARDRONE2)
        {
            START_THREAD (video_recorder, (void *)&video_recorder_param);
            LOGD(TAG, "Video recorder thread start [OK]");
        }



		res = ardrone_tool_init(&ardrone_info.drone_address[0], strlen(&ardrone_info.drone_address[0]), NULL, param->app_name, param->user_name, param->root_dir, param->flight_dir, param->flight_storing_size, param->academy_download_callback_func);

		if(SUCCEED(res))
		{

			ardrone_tool_input_add(&virtual_gamepad);

			if (param != NULL && param->callback != NULL) {
				param->callback(env, param->obj, ARDRONE_MESSAGE_CONNECTED_OK);
			}
		} else {
			if (param != NULL && param->callback != NULL) {
				param->callback(env, param->obj, ARDRONE_MESSAGE_UNKNOWN_ERR);
			}

			bContinue = FALSE;
		}

		res = ardrone_tool_set_refresh_time(1000 / kAPS);

#if USE_THREAD_PRIORITIES
        CHANGE_THREAD_PRIO (app_main, AT_THREAD_PRIORITY);
        CHANGE_THREAD_PRIO (navdata_update, NAVDATA_THREAD_PRIORITY);
        CHANGE_THREAD_PRIO (ardrone_control, NAVDATA_THREAD_PRIORITY);
#endif

		while( SUCCEED(res) && bContinue == TRUE )
		{
			ardrone_tool_update();
		}

		JOIN_THREAD(video_stage);

        if (IS_LEAST_ARDRONE2)
        {
            JOIN_THREAD (video_recorder);
        }

	    /* Unregistering for the current device */
	    ardrone_tool_input_remove( &virtual_gamepad );

		res = ardrone_tool_shutdown();
		LOGD(TAG, "AR.Drone tool shutdown [OK]");

		if (param != NULL && param->callback != NULL) {
			param->callback(env, param->obj, ARDRONE_MESSAGE_DISCONNECTED);
		}
	}

	vp_os_free (data);
	data = NULL;

	(*env)->DeleteGlobalRef(env, param->obj);

	if (g_vm) {
		(*g_vm)->DetachCurrentThread (g_vm);
	}

	LOGI(TAG, "app_main thread has been stopped.");

	return (THREAD_RET) res;
}