4 * originally based on Android NDK "San Angeles" demo app
16 #include <android/log.h>
19 #include "control_ack.h"
20 #include "video_stage.h"
22 #include <ardrone_api.h>
23 #include <ardrone_tool/ardrone_tool.h>
24 #include <ardrone_tool/Control/ardrone_control.h>
25 #include <ardrone_tool/Navdata/ardrone_navdata_client.h>
26 #include <ardrone_tool/ardrone_tool.>
27 #include <VP_Api/vp_api_thread_helper.h>
32 // assume drone has address x.x.x.1
33 #define WIFI_ARDRONE_ADDR_LAST_BYTE (1)
35 #define DEBUG_THREAD 1
36 static bool_t bContinue = TRUE;
38 void get_drone_ip(void)
41 char prop_value[PROP_VALUE_MAX];
42 char prop_name[PROP_NAME_MAX];
45 // quick and dirty way to guess Drone IP address
46 ret = GETPROP("wifi.interface", prop_value);
48 INFO("wifi interface = %s\n", prop_value);
49 snprintf(prop_name, PROP_NAME_MAX, "dhcp.%s.ipaddress", prop_value);
50 ret = GETPROP(prop_name, prop_value);
53 INFO("IP address = %s\n", prop_value);
55 if (sscanf(prop_value, "%d.%d.%d.%d",
59 &inet_part[3]) == 4) {
61 sprintf(drone_ip, "%u.%u.%u.%u",
62 inet_part[0]& 0xff, inet_part[1]& 0xff, inet_part[2]&0xff,
63 WIFI_ARDRONE_ADDR_LAST_BYTE);
67 // fallback to default address
68 sprintf(drone_ip, WIFI_ARDRONE_IP);
71 INFO("assuming drone IP address is %s\n", drone_ip);
74 PROTO_THREAD_ROUTINE(mobile_main, data);
75 DEFINE_THREAD_ROUTINE(mobile_main, data)
77 __android_log_print( ANDROID_LOG_INFO, "ARDrone", "Enter in mobile_main thread\n" );
79 char drone_address[24];
81 vp_os_memset(drone_address, 0x0, sizeof(drone_address));
82 sprintf(drone_address, WIFI_ARDRONE_IP);
84 res = ardrone_tool_setup_com( NULL );
88 __android_log_print( ANDROID_LOG_INFO, "ARDrone", "Setup com failed\n" );
89 INFO("Wifi initialization failed. It means either:\n");
90 INFO("\t* you're not root (it's mandatory because you can set up wifi connection only as root)\n");
91 INFO("\t* wifi device is not present (on your pc or on your card)\n");
92 INFO("\t* you set the wrong name for wifi interface (for example rausb0 instead of wlan0) \n");
93 INFO("\t* ap is not up (reboot card or remove wifi usb dongle)\n");
94 INFO("\t* wifi device has no antenna\n");
98 START_THREAD(video_stage, NULL);
100 __android_log_print( ANDROID_LOG_INFO, "ARDrone", "Processing ardrone_tool_init\n" );
101 res = ardrone_tool_init(drone_address, strlen(drone_address), NULL);
104 control_ack_configure_navdata_demo( FALSE );
108 res = ardrone_tool_set_refresh_time(25);
110 while( SUCCEED(res) && bContinue == TRUE )
112 res = ardrone_tool_update();
116 JOIN_THREAD(video_stage);
118 res = ardrone_tool_shutdown();
121 __android_log_print( ANDROID_LOG_INFO, "ARDrone", "Exit mobile_main thread\n" );
122 return (THREAD_RET)0;
127 __android_log_print( ANDROID_LOG_INFO, "ARDrone", "Enter in appInit\n" );
136 START_THREAD( mobile_main, NULL);
143 INFO("shutting down application...\n");
146 JOIN_THREAD( mobile_main );
149 void appRender(long tick, int width, int height)
154 video_render(tick, width, height);
158 THREAD_TABLE_ENTRY(mobile_main, 20)
159 THREAD_TABLE_ENTRY(ardrone_control, 20)
160 THREAD_TABLE_ENTRY(navdata_update, 20)
161 THREAD_TABLE_ENTRY(video_stage, 20)