#include <locations.h>
#include <location_bounds.h>
-location_manager_h manager;
+static location_manager_h manager;
+static GMainLoop *g_mainloop = NULL;
+static char *menu;
+
+static void location_cleanup();
+static int location_test();
+static gboolean exit_program(gpointer data)
+{
+ g_main_loop_quit(g_mainloop);
+
+ return FALSE;
+}
+
+static gboolean wait_test()
+{
+ location_cleanup();
+ location_test();
+
+ return FALSE;
+}
+
+#if 0
void zone_event_cb(location_boundary_state_e state, double latitude, double longitude, double altitude, time_t timestamp,
- void *user_data)
+ void *user_data)
{
if (state == LOCATIONS_BOUNDARY_IN) {
printf("Entering zone\n");
- } else // state == LOCATIONS_BOUNDARY_OUT
- {
+ } else { /* state == LOCATIONS_BOUNDARY_OUT */
printf("Leaving zone\n");
}
printf("Time: %s\n", ctime(×tamp));
}
-static bool satellites_foreach_cb(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_in_use,
- void *user_data)
+static bool last_satellites_foreach_cb(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_in_use,
+ void *user_data)
{
- printf("[Satellite information] azimuth : %d, elevation : %d, prn :%d, snr : %d, used: %d\n", azimuth, elevation, prn,
- snr, is_in_use);
+ printf("[Last Satellite information] azimuth : %d, elevation: %d, prn: %d, snr: %d, used: %d\n", azimuth, elevation,
+ prn, snr, is_in_use);
return true;
}
+#endif
-static bool last_satellites_foreach_cb(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_in_use,
- void *user_data)
+static bool satellites_foreach_cb(unsigned int azimuth, unsigned int elevation, unsigned int prn, int snr, bool is_in_use,
+ void *user_data)
{
- printf("[Last Satellite information] azimuth : %d, elevation : %d, prn :%d, snr : %d, used: %d\n", azimuth, elevation,
- prn, snr, is_in_use);
+ printf("[Satellite information] azimuth : %d, elevation: %d, prn: %d, snr: %d, used: %d\n", azimuth, elevation, prn,
+ snr, is_in_use);
return true;
}
time_t timestamp;
ret = location_manager_get_position(lm, &altitude, &latitude, &longitude, ×tamp);
if (ret != LOCATIONS_ERROR_NONE) {
- printf(" Fail : location_manager_get_position ---> %d \n", ret);
+ printf(" Fail: location_manager_get_position ---> %d \n", ret);
} else {
printf("[%ld] alt: %g, lat %g, long %g\n", timestamp, altitude, latitude, longitude);
}
double vertical;
ret = location_manager_get_accuracy(lm, &level, &horizontal, &vertical);
if (ret != LOCATIONS_ERROR_NONE) {
- printf(" Fail : location_manager_get_accuracy ---> %d \n", ret);
+ printf(" Fail: location_manager_get_accuracy ---> %d \n", ret);
} else {
- printf("Level : %d, horizontal: %g, vertical %g\n", level, horizontal, vertical);
+ printf("Level: %d, horizontal: %g, vertical %g\n", level, horizontal, vertical);
}
char *nmea;
ret = gps_status_get_nmea(lm, &nmea);
if (ret != LOCATIONS_ERROR_NONE) {
- printf(" Fail : gps_status_get_nmea ---> %d \n", ret);
+ printf(" Fail: gps_status_get_nmea ---> %d \n", ret);
} else {
- printf("NMEA : %s\n", nmea);
+ printf("NMEA: %s\n", nmea);
free(nmea);
}
- int num_of_view, num_of_active;
+ int num_of_view = 0, num_of_active = 0;
ret = gps_status_get_satellite(lm, &num_of_active, &num_of_view, ×tamp);
if (ret != LOCATIONS_ERROR_NONE) {
- printf(" Fail : gps_status_get_satellite_count_in_view ---> %d \n", ret);
+ printf(" Fail: gps_status_get_satellite_count_in_view ---> %d \n", ret);
} else {
- printf("[%ld] Satellite number of active : %d, in view : %d\n", timestamp, num_of_active, num_of_view);
+ printf("[%ld] Satellite number of active: %d, in view: %d\n", timestamp, num_of_active, num_of_view);
}
- ret = gps_status_foreach_satellites_in_view(lm, satellites_foreach_cb, user_data);
- if (ret != LOCATIONS_ERROR_NONE) {
- printf(" Fail : gps_status_foreach_satellites_in_view ---> %d \n", ret);
+ if (num_of_view) {
+ ret = gps_status_foreach_satellites_in_view(lm, satellites_foreach_cb, user_data);
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf(" Fail: gps_status_foreach_satellites_in_view ---> %d \n", ret);
+ }
}
+ g_timeout_add_seconds(1, wait_test, NULL);
}
}
+#if 0
static bool __poly_coords_cb(location_coords_s coords, void *user_data)
{
- printf("location_bounds_foreach_rect_coords(latitude : %lf, longitude: %lf) \n", coords.latitude, coords.longitude);
+ printf("location_bounds_foreach_rect_coords(latitude: %lf, longitude: %lf) \n", coords.latitude, coords.longitude);
return TRUE;
}
location_coords_s center;
double radius;
location_bounds_get_circle_coords(bounds, ¢er, &radius);
- printf("location_bounds_get_circle_coords(center : %lf, %lf, radius : %lf) \n", center.latitude,
+ printf("location_bounds_get_circle_coords(center: %lf, %lf, radius: %lf) \n", center.latitude,
center.longitude, radius);
} else if (type == LOCATION_BOUNDS_RECT) {
location_coords_s left_top;
location_coords_s right_bottom;
location_bounds_get_rect_coords(bounds, &left_top, &right_bottom);
- printf("location_bounds_get_rect_coords(left_top : %lf, %lf - right_bottom : %lf, %lf) \n",
+ printf("location_bounds_get_rect_coords(left_top: %lf, %lf - right_bottom: %lf, %lf) \n",
left_top.latitude, left_top.longitude, right_bottom.latitude, right_bottom.longitude);
} else if (type == LOCATION_BOUNDS_POLYGON) {
location_bounds_foreach_polygon_coords(bounds, __poly_coords_cb, NULL);
if (ret != LOCATIONS_ERROR_NONE) {
printf("location_bounds_get_circle_coords() failed\n");
} else
- printf("location_bounds_get_circle_coords(center : %lf, %lf, radius : %lf) \n", center2.latitude,
+ printf("location_bounds_get_circle_coords(center: %lf, %lf, radius: %lf) \n", center2.latitude,
center2.longitude, radius2);
- //Add the rect bounds
+ /*Add the rect bounds */
location_coords_s left_top;
left_top.latitude = 30;
left_top.longitude = 30;
if (ret != LOCATIONS_ERROR_NONE) {
printf("location_bounds_get_rect_coords() failed\n");
} else
- printf("location_bounds_get_rect_coords(left_top : %lf, %lf - right_bottom : %lf, %lf) \n", left_top2.latitude,
+ printf("location_bounds_get_rect_coords(left_top: %lf, %lf - right_bottom: %lf, %lf) \n", left_top2.latitude,
left_top2.longitude, right_bottom2.latitude, right_bottom2.longitude);
- //Add the polygon bounds
+ /*Add the polygon bounds */
int poly_size = 3;
location_coords_s coord_list[poly_size];
else
printf("location_bounds_contains_coordinates() retrun FALSE \n");
- //print current bounds
+ /*print current bounds */
ret = location_manager_foreach_boundary(manager, __location_bounds_cb, (void *)manager);
if (ret != LOCATIONS_ERROR_NONE) {
printf("location_manager_foreach_boundary() failed\n");
ret = location_manager_get_last_position(manager, &altitude, &latitude, &longitude, ×tamp);
if (ret != LOCATIONS_ERROR_NONE) {
- printf(" Fail : location_manager_get_last_position ---> %d \n", ret);
+ printf(" Fail: location_manager_get_last_position ---> %d \n", ret);
} else {
printf("[%ld] alt: %g, lat: %g, long: %g\n", timestamp, altitude, latitude, longitude);
}
ret = location_manager_get_last_velocity(manager, &climb, &direction, &speed, ×tamp);
if (ret != LOCATIONS_ERROR_NONE) {
- printf(" Fail : location_manager_get_last_velocity ---> %d \n", ret);
+ printf(" Fail: location_manager_get_last_velocity ---> %d \n", ret);
} else {
printf("climb: %f, direction: %f, speed: %f\n", climb, direction, speed);
}
ret = location_manager_get_last_accuracy(manager, &level, &horizontal, &vertical);
if (ret != LOCATIONS_ERROR_NONE) {
- printf(" Fail : location_manager_get_last_accuracy ---> %d \n", ret);
+ printf(" Fail: location_manager_get_last_accuracy ---> %d \n", ret);
} else {
- printf("Level : %d, horizontal: %g, vertical : %g\n", level, horizontal, vertical);
+ printf("Level: %d, horizontal: %g, vertical: %g\n", level, horizontal, vertical);
}
ret = gps_status_get_last_satellite(manager, &num_of_active, &num_of_inview, ×tamp);
if (ret != LOCATIONS_ERROR_NONE) {
- printf(" Fail : gps_status_get_last_satellite_count_in_view ---> %d \n", ret);
+ printf(" Fail: gps_status_get_last_satellite_count_in_view ---> %d \n", ret);
} else {
- printf("[%ld] Satellite number of active : %d, in view : %d\n", timestamp, num_of_active, num_of_inview);
+ printf("[%ld] Satellite number of active: %d, in view: %d\n", timestamp, num_of_active, num_of_inview);
}
ret = gps_status_foreach_last_satellites_in_view(manager, last_satellites_foreach_cb, NULL);
if (ret != LOCATIONS_ERROR_NONE) {
- printf(" Fail : gps_status_foreach_last_satellites_in_view ---> %d \n", ret);
+ printf(" Fail: gps_status_foreach_last_satellites_in_view ---> %d \n", ret);
}
}
+#endif
-int location_test()
+void location_cb(int error, double latitude, double longitude, double altitude, time_t timestamp, double speed, double climb, double direction, void *user_data)
{
- int ret;
- ret = location_manager_create(LOCATIONS_METHOD_GPS, &manager);
- printf("create : %d\n", ret);
+ printf("error[%d]\n", error);
+ printf("location_cb: lat[%f] lon[%f] alt[%f]\n", latitude, longitude, altitude);
+ printf("speed[%f] climb[%f] direction[%f]\n", speed, climb, direction);
- location_bounds_test();
- location_get_last_information_test();
+ g_timeout_add_seconds(1, wait_test, NULL);
+}
- //set zone changed callback
- ret = location_manager_set_zone_changed_cb(manager, zone_event_cb, (void *)manager);
- printf("set zone callback : %d\n", ret);
+static void __setting_cb(location_method_e method, bool enable, void *user_data)
+{
+ printf("method[%d], enable[%d]\n", method, enable);
+}
- ret = location_manager_set_service_state_changed_cb(manager, _state_change_cb, (void *)manager);
- printf("set state callback : %d\n", ret);
+static void select_menu()
+{
+ char buf[256];
+ int len = 0;
+ char *str = NULL;
- ret = location_manager_start(manager);
- printf("start : %d\n", ret);
- return 1;
+ str = fgets(buf, 255, stdin);
+ if (NULL == str) {
+ printf("fgets return NULL. \n");
+ }
+ len = g_utf8_strlen(buf, -1);
+ buf[len - 1] = '\0';
+
+ g_free(menu);
+ menu = g_strdup(buf);
}
-static GMainLoop *g_mainloop = NULL;
+static void print_menu()
+{
+ printf("==== LOCATION TEST ======\n");
+ printf("[1] LOCATIONS_METHOD_HYBRID: Get location\n");
+ printf("[2] LOCATIONS_METHOD_GPS: Get location\n");
+ printf("[3] LOCATIONS_METHOD_WPS: Get location\n");
+ printf("[4] LOCATIONS_METHOD_HYBRID: Single location\n");
+ printf("[5] LOCATIONS_METHOD_GPS: Single location\n");
+ printf("[x] Exit!!!\n\n");
+ printf("Select menu: ");
+}
-static gboolean exit_program(gpointer data)
+static int location_test()
{
- if (manager == NULL) {
- printf("manager == NULL \n");
+ int ret = LOCATIONS_ERROR_NONE;
+
+ printf("==== LOCATION STATUS ======\n");
+ bool is_enabled = FALSE;
+ location_manager_is_enabled_method(LOCATIONS_METHOD_HYBRID, &is_enabled);
+ printf("hybrid: %d, ", is_enabled);
+
+ location_manager_is_enabled_method(LOCATIONS_METHOD_GPS, &is_enabled);
+ printf("gps: %d, ", is_enabled);
+
+ location_manager_is_enabled_method(LOCATIONS_METHOD_WPS, &is_enabled);
+ printf("wps: %d\n", is_enabled);
+
+ location_manager_set_setting_changed_cb(LOCATIONS_METHOD_GPS, __setting_cb, NULL);
+ location_manager_set_setting_changed_cb(LOCATIONS_METHOD_WPS, __setting_cb, NULL);
+
+ print_menu();
+ select_menu();
+
+ if (strcmp(menu, "1") == 0) {
+ ret = location_manager_create(LOCATIONS_METHOD_HYBRID, &manager);
+ printf("LOCATIONS_METHOD_HYBRID create: %d\n", ret);
+ ret = location_manager_start(manager);
+ printf("start: %d\n", ret);
+ } else if (strcmp(menu, "2") == 0) {
+ ret = location_manager_create(LOCATIONS_METHOD_GPS, &manager);
+ printf("LOCATIONS_METHOD_GPS create: %d\n", ret);
+ ret = location_manager_start(manager);
+ printf("start: %d\n", ret);
+ } else if (strcmp(menu, "3") == 0) {
+ ret = location_manager_create(LOCATIONS_METHOD_WPS, &manager);
+ printf("LOCATIONS_METHOD_WPS create: %d\n", ret);
+ } else if (strcmp(menu, "4") == 0) {
+ ret = location_manager_create(LOCATIONS_METHOD_HYBRID, &manager);
+ printf("LOCATIONS_METHOD_HYBRID create: %d\n", ret);
+ ret = location_manager_request_single_location(manager, 60, location_cb, manager);
+ printf("single_location create: %d\n", ret);
+ } else if (strcmp(menu, "5") == 0) {
+ ret = location_manager_create(LOCATIONS_METHOD_GPS, &manager);
+ printf("LOCATIONS_METHOD_HYBRID create: %d\n", ret);
+ ret = location_manager_request_single_location(manager, 60, location_cb, manager);
+ printf("single_location create: %d\n", ret);
+ } else if (strcmp(menu, "x") == 0) {
+ g_timeout_add_seconds(0.1, exit_program, NULL);
+ return 0;
} else {
+ printf("Exit!!! Input: %s\n", menu);
+ g_timeout_add_seconds(0.1, exit_program, NULL);
+ return 0;
+ }
+
+ if (ret != LOCATIONS_ERROR_NONE) {
+ printf("Test Failed!!! [%d]\n", ret);
+ g_timeout_add_seconds(0.1, exit_program, NULL);
+ return 0;
+ }
+ ret = location_manager_set_service_state_changed_cb(manager, _state_change_cb, (void *)manager);
+ printf("set state callback: %d\n", ret);
+
+ /* location_bounds_test(); */
+ /* set zone changed callback */
+ /*
+ ret = location_manager_set_zone_changed_cb(manager, zone_event_cb, (void *)manager);
+ printf("set zone callback: %d\n", ret);
+ */
+ return 0;
+}
+
+static void location_cleanup()
+{
+ if (manager != NULL) {
int ret = location_manager_stop(manager);
- printf("stop : %d\n", ret);
+ printf("stop: %d\n", ret);
ret = location_manager_destroy(manager);
- printf("destroy : %d\n", ret);
+ printf("destroy: %d\n", ret);
+ manager = NULL;
}
- g_main_loop_quit(g_mainloop);
- printf("Quit g_main_loop\n");
- return FALSE;
+ location_manager_unset_setting_changed_cb(LOCATIONS_METHOD_GPS);
+ location_manager_unset_setting_changed_cb(LOCATIONS_METHOD_WPS);
}
int main(int argc, char **argv)
{
- g_setenv("PKG_NAME", "com.samsung.location-test", 1);
g_mainloop = g_main_loop_new(NULL, 0);
location_test();
- g_timeout_add_seconds(90, exit_program, NULL);
g_main_loop_run(g_mainloop);
+ location_cleanup();
return 0;
}