示例#1
0
void ardrone_tool_init_timers_and_mutex()
{
	// Initalize mutex and condition
	vp_os_mutex_init(&ardrone_tool_mutex);
	ardrone_tool_in_pause = FALSE;

	// Init subsystems
	ardrone_timer_reset(&ardrone_tool_timer);
	ardrone_timer_update(&ardrone_tool_timer);
}
C_RESULT ardrone_tool_init( const char* ardrone_ip, size_t n, AT_CODEC_FUNCTIONS_PTRS *ptrs, const char *appname, const char *usrname)
{	
	// Initalize mutex and condition
	vp_os_mutex_init(&ardrone_tool_mutex);
	ardrone_tool_in_pause = FALSE;

	// Initialize ardrone_control_config structures;
	ardrone_tool_reset_configuration();
	// ardrone_control_config_default initialisation. Sould not be modified after that !
	vp_os_memcpy ((void *)&ardrone_control_config_default, (const void *)&ardrone_control_config, sizeof (ardrone_control_config_default));
	// initialization of application defined default values
	vp_os_memcpy ((void *)&ardrone_application_default_config, (const void *)&ardrone_control_config, sizeof (ardrone_application_default_config));
	
	//Fill structure AT codec and built the library AT commands.
   if( ptrs != NULL )
	   ardrone_at_init_with_funcs( ardrone_ip, n, ptrs );
   else	
      ardrone_at_init( ardrone_ip, n );

	// Save appname/appid for reconnections
	if (NULL != appname)
	{
	  ardrone_gen_appid (appname, __SDK_VERSION__, app_id, app_name, sizeof (app_name));
	}
	// Save usrname/usrid for reconnections
	if (NULL != usrname)
	{
		ardrone_gen_usrid (usrname, usr_id, usr_name, sizeof (usr_name));
	}
	// Create pseudorandom session id
	ardrone_gen_sessionid (ses_id, ses_name, sizeof (ses_name));

	// Init subsystems
	ardrone_timer_reset(&ardrone_tool_timer);
	ardrone_timer_update(&ardrone_tool_timer);
	
	ardrone_tool_input_init();
	ardrone_control_init();
	ardrone_tool_configuration_init();
	ardrone_navdata_client_init();


   //Opens a connection to AT port.
	ardrone_at_open();

	START_THREAD(navdata_update, 0);
	START_THREAD(ardrone_control, 0);

	// Send start up configuration
	ardrone_at_set_pmode( MiscVar[0] );
	ardrone_at_set_ui_misc( MiscVar[0], MiscVar[1], MiscVar[2], MiscVar[3] );

	return C_OK;
}
uint64_t ardrone_timer_delta_us(ardrone_timer_t* timer)
{
    ardrone_timer_t timer_current;

    timer_current.init = TRUE;
    timer_current.tv_init = timer->tv_init;

    uint64_t retVal = 0;
    if (C_OK == ardrone_timer_update(&timer_current))
    {
        retVal = ardrone_timer_elapsed_us(&timer_current) - ardrone_timer_elapsed_us(timer);
    }

    return retVal;
}
/*---------------------------------------------------------------------------------------------------------------------
Updates the AT command client by flushing pending commands.
---------------------------------------------------------------------------------------------------------------------*/
C_RESULT ardrone_tool_update()
{
	int delta;

	C_RESULT res = C_OK;

	// Update subsystems & custom tool
	if( need_update )
	{
	
		ardrone_timer_update(&ardrone_tool_timer);

		ardrone_tool_input_update();
		res = ardrone_tool_update_custom();

		if( send_com_watchdog == TRUE )
		{
			ardrone_at_reset_com_watchdog();
			send_com_watchdog = FALSE;
		}
		// Send all pushed messages
		ardrone_at_send();

		need_update = FALSE;
	}

	delta = ardrone_timer_delta_ms(&ardrone_tool_timer);
	if( delta >= ArdroneToolRefreshTimeInMs)
	{
		// Render frame
		res = ardrone_tool_display_custom();
		need_update = TRUE;
	}
	else
	{
		Sleep((ArdroneToolRefreshTimeInMs - delta));
	}

	return res;
}
C_RESULT ardrone_tool_update()
{
    int delta;

    C_RESULT res = C_OK; //C_RESULT 是定义的宏 其对应的是int类型,C_OK也是,其对应的值是0

    if( need_update )
    {
        ardrone_timer_update(&ardrone_tool_timer);//更新时间,为什么要这么处理

        ardrone_control();
        res = ardrone_tool_update_custom();

        if( send_com_watchdog == TRUE )
        {
            ardrone_at_reset_com_watchdog();
            send_com_watchdog = FALSE;
        }//watchdog看门狗防止程序出现死循环,不受控制
        ardrone_at_send();

        need_update = FALSE;
    }

    delta = ardrone_timer_delta_ms(&ardrone_tool_timer);
    if( delta >= ArdroneToolRefreshTimeInMs)
    {
        res = ardrone_tool_display_custom();
        need_update = TRUE;
    }
    else
    {
        Sleep((ArdroneToolRefreshTimeInMs - delta));
    }

    return res;
}
C_RESULT ardrone_tool_update()
{
	int delta;

	C_RESULT res = C_OK;
	
	delta = ardrone_timer_delta_us(&ardrone_tool_timer);
	if( delta >= ArdroneToolRefreshTimeInUs)
	{
		// Render frame
		ardrone_timer_update(&ardrone_tool_timer);
		
		if(!ardrone_tool_in_pause)
		{
			ardrone_tool_input_update();
			res = ardrone_tool_update_custom();
		}
		
		if( send_com_watchdog == TRUE )
		{
			ardrone_at_reset_com_watchdog();
			send_com_watchdog = FALSE;
		}
		
		// Send all pushed messages
		ardrone_at_send();
		
		res = ardrone_tool_display_custom();
	}
	else
	{
		usleep(ArdroneToolRefreshTimeInUs - delta);
	}

	return res;
}
C_RESULT ardrone_tool_init(int argc, char **argv)
{
	C_RESULT res;
	int32_t b_value = FALSE;

	// Initalize mutex and condition
	vp_os_mutex_init(&ardrone_tool_mutex);
	ardrone_tool_in_pause = FALSE;

	// Initialize ardrone_control_config structures;
	ardrone_tool_reset_configuration();
	// ardrone_control_config_default initialisation. Sould not be modified after that !
	vp_os_memcpy ((void *)&ardrone_control_config_default, (const void *)&ardrone_control_config, sizeof (ardrone_control_config_default));
	// initialization of application defined default values
	vp_os_memcpy ((void *)&ardrone_application_default_config, (const void *)&ardrone_control_config, sizeof (ardrone_application_default_config));
	ardrone_application_default_config.navdata_demo = b_value;

	// Save appname/appid for reconnections
	if (NULL != argv[0])
	{
	  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));
	}

	// Create pseudorandom session id
	ardrone_gen_sessionid (ses_id, ses_name, sizeof (ses_name));
	
	//Fill structure AT codec and built the library AT commands.
	ardrone_at_init( wifi_ardrone_ip, strlen( wifi_ardrone_ip) );

	// Init subsystems
	ardrone_timer_reset(&ardrone_tool_timer);
	ardrone_timer_update(&ardrone_tool_timer);
	
	ardrone_tool_input_init();
	ardrone_control_init();
	ardrone_tool_configuration_init();
	ardrone_navdata_client_init();

	// Init custom tool
	res = ardrone_tool_init_custom(argc, argv);

   //Opens a connection to AT port.
	ardrone_at_open();

	START_THREAD(navdata_update, 0);
	START_THREAD(ardrone_control, 0);

	// Send start up configuration
	ardrone_at_set_pmode( MiscVar[0] );
	ardrone_at_set_ui_misc( MiscVar[0], MiscVar[1], MiscVar[2], MiscVar[3] );
	
	return res;
}
C_RESULT ardrone_tool_init( const char* ardrone_ip, size_t n, AT_CODEC_FUNCTIONS_PTRS *ptrs, const char *appname, const char *usrname, const char *rootdir, const char *flightdir, int flight_storing_size, academy_download_new_media academy_download_new_media_func)
{
	C_RESULT res;

	// Initalize mutex and condition
	vp_os_mutex_init(&ardrone_tool_mutex);
	ardrone_tool_in_pause = FALSE;

	// Initialize ardrone_control_config structures;
	ardrone_tool_reset_configuration();
	// ardrone_control_config_default initialisation. Sould not be modified after that !
	vp_os_memcpy ((void *)&ardrone_control_config_default, (const void *)&ardrone_control_config, sizeof (ardrone_control_config_default));
	// initialization of application defined default values
	vp_os_memcpy ((void *)&ardrone_application_default_config, (const void *)&ardrone_control_config, sizeof (ardrone_application_default_config));
	
	// Save appname/appid for reconnections
	if (NULL != appname)
	{
        ardrone_gen_appid (appname, __SDK_VERSION__, app_id, app_name, sizeof (app_name));
	}
	// Save usrname/usrid for reconnections
	if (NULL != usrname)
	{
		ardrone_gen_usrid (usrname, usr_id, usr_name, sizeof (usr_name));
	}
	// Create pseudorandom session id
	ardrone_gen_sessionid (ses_id, ses_name, sizeof (ses_name));
    
	// copy root directory
	if((rootdir != NULL) && strlen(rootdir) < ROOT_NAME_SIZE)
		strcpy(root_dir, rootdir);
    
	//Fill structure AT codec and built the library AT commands.
   if( ptrs != NULL )
	   ardrone_at_init_with_funcs( ardrone_ip, n, ptrs );
   else	
      ardrone_at_init( ardrone_ip, n );

	// Init subsystems
	ardrone_timer_reset(&ardrone_tool_timer);
	ardrone_timer_update(&ardrone_tool_timer);
	
	ardrone_tool_input_init();
	ardrone_control_init();
	ardrone_tool_configuration_init();
	ardrone_navdata_client_init();
	PRINT("Before usbdata_client_init\n");
	ardrone_usbdata_client_init(); //add Alex

    // Init custom tool
    res = ardrone_tool_init_custom();

   //Opens a connection to AT port.
	ardrone_at_open();

	START_THREAD(navdata_update, 0);
	START_THREAD(usbdata_update, 0);
	START_THREAD(ardrone_control, 0);

	// Send start up configuration
	ardrone_at_set_pmode( MiscVar[0] );
	ardrone_at_set_ui_misc( MiscVar[0], MiscVar[1], MiscVar[2], MiscVar[3] );

	academy_download_init(academy_download_new_media_func);
	academy_init(flightdir, flight_storing_size);

	return res;
}