DEFINE_THREAD_ROUTINE(main_application_thread, data)
{

	/* Mutexes for synchronisation */
	vp_os_mutex_init(&test_mutex);
	vp_os_cond_init(&test_condition,&test_mutex);

	vp_os_delay(1000);

	//fflush(stdin);

	printf("[IMPORTANT] Please check you deleted all configuration files on the drone before starting.\n");


	printf("\n Resetting the drone to the default configuration \n");

	/* Switch to the default configuration file */

		/* Always start by setting the session, then the application, then the user */
		set_string(session_id,"00000000");
		set_string(application_id,"00000000");
		set_string(profile_id,"00000000");

		/* Suppress all other settings. A session and an application were automatically created
		 * at application startup by ARDrone Tool ; we must delete them.
		 * The '-' symbol means 'delete'.
		 * '-all' deletes all the existing configurations.
		 */
		set_string(session_id,"-all");
		set_string(application_id,"-all");
		set_string(profile_id,"-all");

		set_int(navdata_demo,1);

	mypause();

	/* Ask the drone configuration and compare it to the expected values */

	/* Send time to the drone */
	//gettimeofday(&tv,NULL);
	//set_int(time,(int32_t)tv.tv_sec);

		title("\nGetting the drone configuration ...\n");

		ARDRONE_TOOL_CONFIGURATION_GET(test_callback);		vp_os_cond_wait(&test_condition);

		title("Comparing received values to the config_keys.h defaults ...\n");

			#define ARDRONE_CONFIG_KEY_IMM_a9(KEY, NAME, INI_TYPE, C_TYPE, C_TYPE_PTR, RW, DEFAULT, CALLBACK,SCOPE) \
				test_float(NAME,DEFAULT);
			#undef ARDRONE_CONFIG_KEY_REF_a9
			#define ARDRONE_CONFIG_KEY_STR_a9(KEY, NAME, INI_TYPE, C_TYPE, C_TYPE_PTR, RW, DEFAULT, CALLBACK,SCOPE) \
				test_string(NAME,DEFAULT);

			#include <config_keys.h>


			/* Modify one value of each category and see what happens */

				/* To test the 'COMMON' category */
				set_string(ardrone_name,"TEST_CONFIG");

				/* To test the 'APPLIS' category */
				test_nint(bitrate_ctrl_mode,1);     /* 0 is the default value */
				set_int(bitrate_ctrl_mode,1);

				/* To test the 'PROFILE' (aka. 'USER') category */
				test_nfloat(outdoor_euler_angle_max,F1);
				set_float(outdoor_euler_angle_max,F1);

				/* To test the 'SESSION' category */
				test_string(leds_anim,"0,0,0");
				set_string(leds_anim,"1,1,1");

				test_string(application_id,"00000000");
				test_string(profile_id,"00000000");
				test_string(session_id,"00000000");


			title("\nGetting the drone configuration ...\n");


				{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

				test_string(ardrone_name,"TEST_CONFIG"); /* CAT_COMMON param */
				test_int(bitrate_ctrl_mode,1);           /* CAT_APPLI param */
				test_float(outdoor_euler_angle_max,F1);	 /* CAT_USER param */
				test_string(leds_anim,"1,1,1");			 /* CAT_SESSION param */

				test_string(application_id,"00000000");
				test_string(profile_id,"00000000");
				test_string(session_id,"00000000");

				test_string(application_desc , DEFAULT_APPLICATION_DESC);
				test_string(profile_desc, DEFAULT_PROFILE_DESC);
				test_string(session_desc, DEFAULT_SESSION_DESC);



	/*---------------------------------------------------------------------------------------------------------*/

   /* Create an application configuration file */

		title("\nCreating the application ID 11111111 ...\n");

			set_string(application_id,"11111111");
			set_string(application_desc,APPDESC1);

			title("\nGetting the drone configuration ...\n");
			{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

			test_string(ardrone_name,"TEST_CONFIG"); /* CAT_COMMON param; its value should not be changed by creating an application config. */
			test_int(bitrate_ctrl_mode,0);           /* 0 is the default value ; default values are affected to newly created configurations */
			test_float(outdoor_euler_angle_max,F1);	 /* CAT_USER param ; its value should not be changed by creating an application config. */
			test_int(detect_type,CAD_TYPE_NONE);     /* CAT_SESSION param; its value should not be changed by creating an application config. */

			test_string(application_id,"11111111");
			test_string(profile_id,"00000000");
			test_string(session_id,"00000000");

			test_string(application_desc,APPDESC1);
			test_string(profile_desc, DEFAULT_PROFILE_DESC);
			test_string(session_desc, DEFAULT_SESSION_DESC);


			set_int(bitrate_ctrl_mode,1);
			{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}
			test_string(ardrone_name,"TEST_CONFIG");
			test_int(bitrate_ctrl_mode,1);

			set_int(bitrate_ctrl_mode,0);
			{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}
			test_string(ardrone_name,"TEST_CONFIG");
			test_int(bitrate_ctrl_mode,0);
			
			mypause();


		title("\nGoing back to the default application configuration ...\n");

			set_string(application_id,"00000000");

			{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

			test_string(ardrone_name,"TEST_CONFIG");
			test_int(bitrate_ctrl_mode,1);    		 /* 1 was the value of the config.ini configuration  */
			test_float(outdoor_euler_angle_max,F1);
			test_int(detect_type,CAD_TYPE_NONE);

			test_string(application_id,"00000000");
			test_string(profile_id,"00000000");
			test_string(session_id,"00000000");

			test_string(application_desc,DEFAULT_APPLICATION_DESC);
			test_string(profile_desc, DEFAULT_PROFILE_DESC);
			test_string(session_desc, DEFAULT_SESSION_DESC);

			mypause();

		title(" Going back to the newly created application configuration ...\n");

			set_string(application_id,"11111111");

			{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

			test_string(ardrone_name,"TEST_CONFIG");
			test_int(bitrate_ctrl_mode,0);
			test_float(outdoor_euler_angle_max,F1);
			test_int(detect_type,CAD_TYPE_NONE);

			test_string(application_id,"11111111");
			test_string(profile_id,"00000000");
			test_string(session_id,"00000000");

			test_string(application_desc , APPDESC1);
			test_string(profile_desc, DEFAULT_PROFILE_DESC);
			test_string(session_desc, DEFAULT_SESSION_DESC);

			set_string(application_id,"00000000");

			mypause();

/*-----------------------------------------------------------------------------------------------*/

   /* Create a user profile configuration file */

		title("\nCreating the user profile ID 22222222 ...\n");

			set_string(profile_id,"22222222");
			set_string(profile_desc,PROFDESC2);


			title("\nGetting the drone configuration ...\n");


			{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}



			test_string(ardrone_name,"TEST_CONFIG");
			test_int(bitrate_ctrl_mode,1);			 /* 1 was the value of the config.ini configuration  */
			test_float(outdoor_euler_angle_max,default_outdoor_euler_angle_ref_max);
			test_int(detect_type,CAD_TYPE_NONE);

			test_string(application_id,"00000000");
			test_string(profile_id,"22222222");
			test_string(session_id,"00000000");

			test_string(application_desc , DEFAULT_APPLICATION_DESC);
			test_string(profile_desc, PROFDESC2);//DEFAULT_PROFILE_DESC
			test_string(session_desc, DEFAULT_SESSION_DESC);

			set_float(outdoor_euler_angle_max,F2);

			{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

			mypause();


		title("\nGoing back to the default user profile configuration ...\n");

			set_string(profile_id,"00000000");

			{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}


			/* The default value for this is 1 after the first test */
			test_string(ardrone_name,"TEST_CONFIG");
			test_int(bitrate_ctrl_mode,1);			 /* 1 was the value of the config.ini configuration  */
			test_float(outdoor_euler_angle_max,F1);
			test_int(detect_type,CAD_TYPE_NONE);

			test_string(application_id,"00000000");
			test_string(profile_id,"00000000");
			test_string(session_id,"00000000");

			test_string(application_desc , DEFAULT_APPLICATION_DESC);
			test_string(profile_desc, DEFAULT_PROFILE_DESC);
			test_string(session_desc, DEFAULT_SESSION_DESC);

			mypause();


		title(" Going back to the newly created user profile configuration ...\n");

			set_string(profile_id,"22222222");

			{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

			test_string(ardrone_name,"TEST_CONFIG");
			test_int(bitrate_ctrl_mode,1);			 /* 1 was the value of the config.ini configuration  */
			test_float(outdoor_euler_angle_max,F2);
			test_int(detect_type,CAD_TYPE_NONE);

			test_string(ardrone_name,"TEST_CONFIG");

			test_string(application_id,"00000000");
			test_string(profile_id,"22222222");
			test_string(session_id,"00000000");

			test_string(application_desc , DEFAULT_APPLICATION_DESC);
			test_string(profile_desc, PROFDESC2);//DEFAULT_PROFILE_DESC
			test_string(session_desc, DEFAULT_SESSION_DESC);



			set_string(profile_id,"00000000");

			mypause();


/*-----------------------------------------------------------------------------------------------*/

	   /* Create a session configuration file */

		title("\nCreating the session ID 33333333 ...\n");

			set_string(session_id,"33333333");

			title("\nGetting the drone configuration ...\n");
			{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

			test_string(ardrone_name,"TEST_CONFIG"); /* CAT_COMMON param; its value should not be changed by creating a session */
			test_int(bitrate_ctrl_mode,1);           /* CAT_APPLI param; its value should not be changed by creating a session */
			test_float(outdoor_euler_angle_max,F1);  /* value in default config.ini */
			test_int(detect_type,CAD_TYPE_NONE);     /* CAT_SESSION param; its value should be the default one */

			test_string(application_id,"00000000");
			test_string(profile_id,"00000000");
			test_string(session_id,"33333333");

			test_string(application_desc , DEFAULT_APPLICATION_DESC);
			test_string(profile_desc, DEFAULT_PROFILE_DESC);
			test_string(session_desc, DEFAULT_SESSION_DESC ); //DEFAULT_SESSION_DESC);

			/* Test changing a value in the session */
			set_int(detect_type,CAD_TYPE_VISION);
			{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}
			test_int(detect_type,CAD_TYPE_VISION);

			mypause();


		title("\nGoing back to the default session configuration ...\n");

			set_string(session_id,"00000000");

			{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

			test_string(ardrone_name,"TEST_CONFIG");
			test_int(bitrate_ctrl_mode,1);           /* value in default config.ini */
			test_float(outdoor_euler_angle_max,F1);  /* value in default config.ini */
			test_int(detect_type,CAD_TYPE_NONE);

			test_string(application_id,"00000000");
			test_string(profile_id,"00000000");
			test_string(session_id,"00000000");

			test_string(application_desc , DEFAULT_APPLICATION_DESC);
			test_string(profile_desc, DEFAULT_PROFILE_DESC);
			test_string(session_desc, DEFAULT_SESSION_DESC);

			mypause();


		title(" Going back to the newly created session configuration ...\n");

			set_string(session_id,"33333333");
			set_string(session_desc,SESSDESC3);

			{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

			test_string(ardrone_name,"TEST_CONFIG");
			test_int(bitrate_ctrl_mode,1);           /* value in default config.ini */
			test_float(outdoor_euler_angle_max,F1);  /* value in default config.ini */
			test_int(detect_type,CAD_TYPE_VISION);

			test_string(ardrone_name,"TEST_CONFIG");
			test_string(application_id,"00000000");
			test_string(profile_id,"00000000");
			test_string(session_id,"33333333");

			test_string(application_desc , DEFAULT_APPLICATION_DESC);
			test_string(profile_desc, DEFAULT_PROFILE_DESC);
			test_string(session_desc, SESSDESC3 ); //DEFAULT_SESSION_DESC);

			set_int(detect_type,CAD_TYPE_COCARDE);

			set_string(session_id,"00000000");

			mypause();


/*-----------------------------------------------------------------------------------------------*/

		/* Create a session configuration file */
			title("\nCreating the session ID 44444444 ...\n");

					set_string(session_id,"44444444");

					title("\nGetting the drone configuration ...\n");

					{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

					test_int(detect_type,CAD_TYPE_NONE);

					test_string(ardrone_name,"TEST_CONFIG");
					test_int(bitrate_ctrl_mode,1);

					test_string(application_id,"00000000");
					test_string(profile_id,"00000000");
					test_string(session_id,"44444444");

					test_string(application_desc , DEFAULT_APPLICATION_DESC);
					test_string(profile_desc, DEFAULT_PROFILE_DESC);
					test_string(session_desc, DEFAULT_SESSION_DESC ); //FAULT_SESSION_DESC);

					set_int(detect_type,CAD_TYPE_VISION);

					{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

					test_int(detect_type,CAD_TYPE_VISION);

					set_string(application_id,"11111111");
					set_string(profile_id,"22222222");

					{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

					test_string(ardrone_name,"TEST_CONFIG"); 				set_string(ardrone_name,"TEST_CONFIG2");
					test_string(application_id,"11111111");
					test_string(profile_id,"22222222");
					test_string(session_id,"44444444");

					test_string(application_desc , APPDESC1);
					test_string(profile_desc, PROFDESC2);
					test_string(session_desc, DEFAULT_SESSION_DESC);

					mypause();


while(1){

			title("\nGoing back to the default session ...\n");

					set_string(session_id,"00000000");

					{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

					test_string(ardrone_name,"TEST_CONFIG2");
					test_int(bitrate_ctrl_mode,1);

					test_string(application_id,"00000000");
					test_string(profile_id,"00000000");
					test_string(session_id,"00000000");

					test_string(application_desc , DEFAULT_APPLICATION_DESC);
					test_string(profile_desc, DEFAULT_PROFILE_DESC);
					test_string(session_desc, DEFAULT_SESSION_DESC);
					
					mypause();


			title("\nGoing back to the 44444444 session ...\n");

					set_string(session_id,"44444444");
					set_string(session_desc,SESSDESC4);


					{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

					test_string(ardrone_name,"TEST_CONFIG2");
					test_int(bitrate_ctrl_mode,0);

					test_string(application_id,"11111111");
					test_string(profile_id,"22222222");
					test_string(session_id,"44444444");

					test_string(application_desc , APPDESC1);
					test_string(profile_desc, PROFDESC2);
					test_string(session_desc, SESSDESC4);

					mypause();


			title("\nGoing back to the default session ...\n");

					set_string(session_id,"00000000");

					{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

					test_string(ardrone_name,"TEST_CONFIG2"); set_string(ardrone_name,"TEST_CONFIG3");
					test_string(application_id,"00000000");
					test_string(profile_id,"00000000");
					test_string(session_id,"00000000");

					test_string(application_desc , DEFAULT_APPLICATION_DESC);
					test_string(profile_desc, DEFAULT_PROFILE_DESC);
					test_string(session_desc, DEFAULT_SESSION_DESC);

					mypause();


			title(" Going back to the 33333333 session ...\n");

					set_string(session_id,"33333333");

					{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

					test_string(ardrone_name,"TEST_CONFIG3");
					test_int(bitrate_ctrl_mode,1);           /* value in default config.ini */
					test_float(outdoor_euler_angle_max,F1);  /* value in default config.ini */
					test_int(detect_type,CAD_TYPE_COCARDE);

					test_string(application_id,"00000000");
					test_string(profile_id,"00000000");
					test_string(session_id,"33333333");

					test_string(application_desc , DEFAULT_APPLICATION_DESC);
					test_string(profile_desc, DEFAULT_PROFILE_DESC);
					test_string(session_desc, SESSDESC3);

					mypause();


			title("\nGoing back to the 44444444 session ...\n");

					set_string(session_id,"44444444");

					{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

					test_string(ardrone_name,"TEST_CONFIG3");    set_string(ardrone_name,"TEST_CONFIG4");
					test_int(bitrate_ctrl_mode,0);
					test_float(outdoor_euler_angle_max,F2);
					test_int(detect_type,CAD_TYPE_VISION);

					test_string(application_id,"11111111");
					test_string(profile_id,"22222222");
					test_string(session_id,"44444444");

					test_string(application_desc , APPDESC1);
					test_string(profile_desc, PROFDESC2);
					test_string(session_desc, SESSDESC4);

					mypause();


			title(" Going back to the 33333333 session ...\n");

					set_string(session_id,"33333333");

					{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

					test_int(bitrate_ctrl_mode,1);
					test_int(detect_type,CAD_TYPE_COCARDE);

					test_string(ardrone_name,"TEST_CONFIG4");
					test_int(bitrate_ctrl_mode,1);
					test_float(outdoor_euler_angle_max,F1);
					test_string(application_id,"00000000");
					test_string(profile_id,"00000000");
					test_string(session_id,"33333333");

					test_string(application_desc , DEFAULT_APPLICATION_DESC);
					test_string(profile_desc, DEFAULT_PROFILE_DESC);
					test_string(session_desc, SESSDESC3);

					mypause();


			title("\nGoing back to the default session ...\n");

				set_string(session_id,"00000000");

				{ARDRONE_TOOL_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

				test_string(ardrone_name,"TEST_CONFIG4");   /* common parameter whose value should never be reset */
				test_int(bitrate_ctrl_mode,1);
				test_float(outdoor_euler_angle_max,F1);
				test_int(detect_type,CAD_TYPE_NONE);

				test_string(application_id,"00000000");
				test_string(profile_id,"00000000");
				test_string(session_id,"00000000");

				test_string(application_desc , DEFAULT_APPLICATION_DESC);
				test_string(profile_desc, DEFAULT_PROFILE_DESC);
				test_string(session_desc, DEFAULT_SESSION_DESC);

				set_string(ardrone_name,"TEST_CONFIG2");

				mypause();


				/*-----------------------------------------------------------------------------------------------*/

				/* Read the list of custom configurations */
				title("\nReading the list of custom configuration files ...\n");
				{ARDRONE_TOOL_CUSTOM_CONFIGURATION_GET(test_callback);vp_os_cond_wait(&test_condition);}

				printf("\n\n ====================================== \n\n");

				if(available_configurations[CAT_APPLI].nb_configurations!=1) { printf("Bad number of custom applis.\n"); }
				if(available_configurations[CAT_USER].nb_configurations!=1) { printf("Bad number of custom applis.\n"); }
				if(available_configurations[CAT_SESSION].nb_configurations!=2) { printf("Bad number of custom applis.\n"); }

				if (available_configurations[CAT_APPLI].list[0].id==NULL) { printf("Unexpected custom app 0 NULL\n"); }
				else if (strcmp(available_configurations[CAT_APPLI].list[0].id,"11111111")) { printf("Unexpected custom app : <%s>\n",available_configurations[CAT_APPLI].list[0].id); }

				if (available_configurations[CAT_USER].list[0].id==NULL) { printf("Unexpected custom user 0 NULL\n"); }
				else if (strcmp(available_configurations[CAT_USER].list[0].id,"22222222")) { printf("Unexpected custom profile : <%s>\n",available_configurations[CAT_USER].list[0].id); }

				if (available_configurations[CAT_SESSION].list[0].id==NULL) { printf("Unexpected custom session 0 NULL\n"); }
				else if (strcmp(available_configurations[CAT_SESSION].list[0].id,"33333333")) { printf("Unexpected custom session 0 : <%s>\n",available_configurations[CAT_SESSION].list[0].id); }

				if (available_configurations[CAT_SESSION].list[1].id==NULL) { printf("Unexpected custom session 1 NULL\n"); }
				else if (strcmp(available_configurations[CAT_SESSION].list[1].id,"44444444")) { printf("Unexpected custom session 1 : <%s>\n",available_configurations[CAT_SESSION].list[1].id); }



				if (available_configurations[CAT_APPLI].list[0].description==NULL) { printf("Unexpected custom appli descrition 0 NULL\n"); }
				else if (strcmp(available_configurations[CAT_APPLI].list[0].description,APPDESC1)) { printf("Unexpected custom app description : <%s>\n",available_configurations[CAT_APPLI].list[0].description); }

				if (available_configurations[CAT_USER].list[0].description==NULL) { printf("Unexpected custom user 0 description NULL\n"); }
				else if (strcmp(available_configurations[CAT_USER].list[0].description,PROFDESC2)) { printf("Unexpected custom profile description : <%s>\n",available_configurations[CAT_USER].list[0].description); }

				if (available_configurations[CAT_SESSION].list[0].description==NULL) { printf("Unexpected custom session 0 description NULL\n"); }
				else if (strcmp(available_configurations[CAT_SESSION].list[0].description,SESSDESC3)) { printf("Unexpected custom session 0 description : <%s>\n",available_configurations[CAT_SESSION].list[0].description); }

				if (available_configurations[CAT_SESSION].list[1].description==NULL) { printf("Unexpected custom session 1 description NULL\n"); }
				else if (strcmp(available_configurations[CAT_SESSION].list[1].description,SESSDESC4)) { printf("Unexpected custom session 1 description : <%s>\n",available_configurations[CAT_SESSION].list[1].description); }



				printf("   Custom config list checked.\n");
				
				mypause();


				/*-----------------------------------------------------------------------------------------------*/

				printf("\n\n ====================================== \n\n");

				title("\nEnd of the test.\n");
	}
}
C_RESULT ardrone_general_navdata_process( const navdata_unpacked_t* const pnd )
{
	navdata_mode_t current_navdata_state = NAVDATA_BOOTSTRAP;

	/* Makes sure the navdata stream will be resumed if the drone is disconnected and reconnected.
	 * Allows changing the drone battery during debugging sessions.	 */
	if( ardrone_get_mask_from_state(pnd->ardrone_state, ARDRONE_NAVDATA_BOOTSTRAP) )
	{
		current_navdata_state = NAVDATA_BOOTSTRAP;
	}
	else
	{
		current_navdata_state = (ardrone_get_mask_from_state(pnd->ardrone_state, ARDRONE_NAVDATA_DEMO_MASK)) ? NAVDATA_DEMO : NAVDATA_FULL ;
	}

	if (current_navdata_state == NAVDATA_BOOTSTRAP && configState == MULTICONFIG_IDLE && navdataState == NAVDATA_REQUEST_IDLE)
	{
        navdataState = NAVDATA_REQUEST_NEEDED; 
	}
	
	/* Multiconfig settings */
	int configIndex, userNeedInit, appNeedInit;
	userNeedInit = 0; appNeedInit = 0;
	switch (configState)
	{
		case MULTICONFIG_GOT_DRONE_VERSION:
            PRINTDBG ("Checking drone version ...\n");
			// Check if drone version is >= 1.6
			if (versionSupportsMulticonfiguration (ardrone_control_config.num_version_soft))
			{
                PRINTDBG ("Drone supports multiconfig\n");
				configState = MULTICONFIG_IN_PROGRESS_LIST;
				ARDRONE_TOOL_CUSTOM_CONFIGURATION_GET (configurationCallback);
                droneSupportsMulticonfig = 1;
			}
			else
			{
                PRINTDBG ("Drone does not support multiconfig\n");
				// Drone does not support multiconfig ... don't call init functions because we don't want to mess up things in default config
				configState = MULTICONFIG_REQUEST_NAVDATA;
			}
			break;
		case MULTICONFIG_GOT_IDS_LIST:
			// At this point, we're sure that the AR.Drone supports multiconfiguration, so we'll wheck if our ids exists, and send them.
            PRINTDBG ("Got AR.Drone ID list. Switch->%d,%d,%d. ND->%d\n", sesSwitch, usrSwitch, appSwitch, navdataNeeded);
            if (1 == sesSwitch)
            {
                switchToSession(); // Go to session ...
            }

            if (1 == appSwitch)
            {
                if (0 != strcmp(ardrone_control_config_default.application_id, app_id)) // Check for application only if we're not asking for the default one
                {
                    appNeedInit = 1;
                    for (configIndex = 0; configIndex < available_configurations[CAT_APPLI].nb_configurations; configIndex++) // Check all existing app_ids
                    {
                        PRINTDBG ("Checking application %s (desc : %s)\n", available_configurations[CAT_APPLI].list[configIndex].id,
                                  available_configurations[CAT_APPLI].list[configIndex].description);
                        if (0 == strcmp(available_configurations[CAT_APPLI].list[configIndex].id, app_id))
                        {
                            PRINTDBG ("Found our application ... should not init\n");
                            appNeedInit = 0;
                            break;
                        }
                    }
                    switchToApplication();
                }
                else
                {
                    PRINTDBG ("We're requesting default application (%s), do nothing.\n", app_id);
                }
            }
			
            if (1 == usrSwitch)
            {
                if (0 != strcmp(ardrone_control_config_default.profile_id, usr_id)) // Check for user only if we're not asking for the default one
                {
                    userNeedInit = 1;
                    for (configIndex = 0; configIndex < available_configurations[CAT_USER].nb_configurations; configIndex++) // Check all existing user_ids
                    {
                        PRINTDBG ("Checking user %s (desc : %s)\n", available_configurations[CAT_USER].list[configIndex].id,
                                  available_configurations[CAT_USER].list[configIndex].description);
                        if (0 == strcmp(available_configurations[CAT_USER].list[configIndex].id, usr_id))
                        {
                            PRINTDBG ("Found our user ... should not init\n");
                            userNeedInit = 0;
                            break;
                        }
                    }
                    switchToUser();
                }
                else
                {
                    PRINTDBG ("We're requesting default user (%s), do nothing.\n", usr_id);
                }
            }
			
			if (1 == appNeedInit)
			{
				// Send application defined default values
				ardrone_tool_send_application_default();
				PRINTDBG ("Creating app. profile on AR.Drone\n");
				ARDRONE_TOOL_CONFIGURATION_ADDEVENT (application_desc, app_name, NULL);
			}
			if (1 == userNeedInit)
			{
				// Send user defined default values
				ardrone_tool_send_user_default();
				PRINTDBG ("Creating usr. profile on AR.Drone\n");
				ARDRONE_TOOL_CONFIGURATION_ADDEVENT (profile_desc, usr_name, NULL);
			}
            if (1 == sesSwitch)
            {
                if (0 != strcmp(ardrone_control_config_default.session_id, ses_id)) // Send session info only if session is not the default one
                {
                    ARDRONE_TOOL_CONFIGURATION_ADDEVENT (session_desc, ses_name, NULL);
                    // Send session specific default values
                    ardrone_tool_send_session_default();
                }
                else
                {
                    PRINTDBG ("We're requesting default session (%s), do nothing.\n", ses_id);
                }
            }
            configState = MULTICONFIG_IN_PROGRESS_IDS;
            ARDRONE_TOOL_CONFIGURATION_GET (configurationCallback);
			
        case MULTICONFIG_GOT_CURRENT_IDS:
            if (0 != strcmp(ardrone_control_config.session_id, ses_id) ||
                0 != strcmp(ardrone_control_config.profile_id, usr_id) ||
                0 != strcmp(ardrone_control_config.application_id, app_id))
            {
                configState = MULTICONFIG_GOT_DRONE_VERSION; // We failed at setting up the application ids ... restart (but assume that drone supports multiconfig as we already checked)
            }
            else if (1 == navdataNeeded)
            {
                configState = MULTICONFIG_REQUEST_NAVDATA;
            }
            else
            {
                configState = MULTICONFIG_IDLE;
            }
			break;
		case MULTICONFIG_NEEDED:
            PRINTDBG ("Need to check multiconfig ... request config file\n");
			// Get config file for reset
			configState = MULTICONFIG_IN_PROGRESS_VERSION;
			ARDRONE_TOOL_CONFIGURATION_GET (configurationCallback);
			break;
        case MULTICONFIG_REQUEST_NAVDATA:
            PRINTDBG ("Send application navdata demo/options\n");
            // Send application navdata demo/options to start navdatas from AR.Drone
			ARDRONE_TOOL_CONFIGURATION_ADDEVENT (navdata_demo, &ardrone_application_default_config.navdata_demo, NULL);
            if (TRUE == ardrone_application_default_config.navdata_demo)
            {   // Send navdata options only for navdata demo mode
                ARDRONE_TOOL_CONFIGURATION_ADDEVENT (navdata_options, &ardrone_application_default_config.navdata_options, NULL);
            }
            configState = MULTICONFIG_IDLE;
            break;
		case MULTICONFIG_IDLE:
		case MULTICONFIG_IN_PROGRESS_LIST:
		case MULTICONFIG_IN_PROGRESS_VERSION:
        case MULTICONFIG_IN_PROGRESS_IDS:
		default:
			break;
	}
			
    /* Navdata request settings */
    switch (navdataState)
    {
        case NAVDATA_REQUEST_NEEDED:
            PRINTDBG ("Resetting navdatas to %s\n", (0 == ardrone_application_default_config.navdata_demo) ? "full" : "demo");
            navdataState = NAVDATA_REQUEST_IN_PROGRESS;
            switchToSession(); // Resend session id when reconnecting.
			ARDRONE_TOOL_CONFIGURATION_ADDEVENT(navdata_demo, &ardrone_application_default_config.navdata_demo, NULL);
            if (TRUE == ardrone_application_default_config.navdata_demo)
            {   // Send navdata options only for navdata demo mode
                ARDRONE_TOOL_CONFIGURATION_ADDEVENT (navdata_options, &ardrone_application_default_config.navdata_options, navdataCallback);
            }
            break;
        case NAVDATA_REQUEST_IN_PROGRESS:
        case NAVDATA_REQUEST_IDLE:
        default:
            break;
    }

	return C_OK;
}
static void get_custom_configurations_callback(GtkWidget *widget, gpointer data)
{
	printf("%s %s %i\n",__FILE__,__FUNCTION__,__LINE__);
	ARDRONE_TOOL_CUSTOM_CONFIGURATION_GET(custom_configurations_received_callback);
	printf("%s %s %i\n",__FILE__,__FUNCTION__,__LINE__);
}