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; }
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; }