4 * Copyright (c) 2010-2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Youngae Kang <youngae.kang@samsung.com>, Yunhan Kim <yhan.kim@samsung.com>,
7 * Genie Kim <daejins.kim@samsung.com>, Minjune Kim <sena06.kim@samsung.com>
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
24 #include <glib/gprintf.h>
26 #include "location-api-test-util.h"
29 LocationObject* location_obj = NULL;
30 static GMainLoop *g_mainloop = NULL;
32 #define LOCATION_API_TEST_JSON_FILE "/opt/data/location-api-test.json"
34 static gpointer GmainThread(gpointer data)
36 g_mainloop = g_main_loop_new (NULL, FALSE);
37 g_printf("\n...Entering GMain Loop to Receive Notifications....\n");
38 g_main_loop_run (g_mainloop);
39 g_main_loop_unref (g_mainloop);
45 static void GetLocationError(char str[STR_MAX], int ret)
49 case LOCATION_ERROR_NONE:
50 g_utf8_strncpy(str, "LOCATION_ERROR_NONE", STR_MAX);
52 case LOCATION_ERROR_NOT_ALLOWED:
53 g_utf8_strncpy(str, "LOCATION_ERROR_NOT_ALLOWED", STR_MAX);
55 case LOCATION_ERROR_NOT_AVAILABLE:
56 g_utf8_strncpy(str, "LOCATION_ERROR_NOT_AVAILABLE", STR_MAX);
58 case LOCATION_ERROR_NETWORK_FAILED:
59 g_utf8_strncpy(str, "LOCATION_ERROR_NETWORK_FAILED", STR_MAX);
61 case LOCATION_ERROR_NETWORK_NOT_CONNECTED:
62 g_utf8_strncpy(str, "LOCATION_ERROR_NETWORK_NOT_CONNECTED", STR_MAX);
64 case LOCATION_ERROR_CONFIGURATION:
65 g_utf8_strncpy(str, "LOCATION_ERROR_CONFIGURATION", STR_MAX);
67 case LOCATION_ERROR_PARAMETER:
68 g_utf8_strncpy(str, "LOCATION_ERROR_PARAMETER", STR_MAX);
70 case LOCATION_ERROR_UNKNOWN:
71 g_utf8_strncpy(str, "LOCATION_ERROR_UNKNOWN", STR_MAX);
74 g_utf8_strncpy(str, "Error: undefined error code", STR_MAX);
78 static void GetStatus(char str[STR_MAX], LocationStatus acc_level)
82 case LOCATION_STATUS_NO_FIX:
83 g_utf8_strncpy(str, "LOCATION_STATUS_NO_FIX", STR_MAX);
85 case LOCATION_STATUS_2D_FIX:
86 g_utf8_strncpy(str, "LOCATION_STATUS_2D_FIX", STR_MAX);
88 case LOCATION_STATUS_3D_FIX:
89 g_utf8_strncpy(str, "LOCATION_STATUS_3D_FIX", STR_MAX);
92 g_utf8_strncpy(str, "Error: undefined status code", STR_MAX);
96 static void GetMethod(char str[STR_MAX], LocationMethod method)
100 case LOCATION_METHOD_HYBRID:
101 g_utf8_strncpy(str, "LOCATION_METHOD_HYBRID", STR_MAX);
103 case LOCATION_METHOD_GPS:
104 g_utf8_strncpy(str, "LOCATION_METHOD_GPS", STR_MAX);
106 case LOCATION_METHOD_CPS:
107 g_utf8_strncpy(str, "LOCATION_METHOD_CPS", STR_MAX);
109 case LOCATION_METHOD_WPS:
110 g_utf8_strncpy(str, "LOCATION_METHOD_WPS", STR_MAX);
113 g_utf8_strncpy(str, "Error: undefined method", STR_MAX);
117 static void GetAccuracyLevel(char str[STR_MAX], LocationAccuracyLevel acc_level)
121 case LOCATION_ACCURACY_LEVEL_NONE:
122 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_NONE", STR_MAX);
124 case LOCATION_ACCURACY_LEVEL_COUNTRY:
125 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_COUNTRY", STR_MAX);
127 case LOCATION_ACCURACY_LEVEL_REGION:
128 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_REGION", STR_MAX);
130 case LOCATION_ACCURACY_LEVEL_LOCALITY:
131 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_LOCALITY", STR_MAX);
133 case LOCATION_ACCURACY_LEVEL_POSTALCODE:
134 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_POSTALCODE", STR_MAX);
136 case LOCATION_ACCURACY_LEVEL_STREET:
137 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_STREET", STR_MAX);
139 case LOCATION_ACCURACY_LEVEL_DETAILED:
140 g_utf8_strncpy(str, "LOCATION_ACCURACY_LEVEL_DETAILED", STR_MAX);
143 g_utf8_strncpy(str, "Error: undefined accuracy level", STR_MAX);
148 static void SelectOpt(char* buf)
151 fgets(buf, 255, stdin);
152 iLen = g_utf8_strlen(buf, -1);
156 static int PromptInt()
160 fgets(buf, 255, stdin);
161 buf[strlen(buf)-1]='\0';
162 ret = g_ascii_strtoll(buf, NULL, 10);
166 gulong g_sig_enable = 0;
167 gulong g_sig_disable = 0;
168 gulong g_sig_update = 0;
169 gulong g_sig_zonein = 0;
170 gulong g_sig_zoneout = 0;
172 static void PrintPolygonPosition(gpointer data, gpointer user_data)
174 LocationPosition *position = (LocationPosition*) data;
175 g_printf("[%lf %lf %lf] ", position->latitude, position->longitude, position->altitude);
178 static void PrintBoundary(LocationBoundary *boundary, void *user_data)
180 if(boundary == NULL) return;
181 if (boundary->type == LOCATION_BOUNDARY_CIRCLE) {
182 g_printf("\n\tCIRCLE: center[%lf %lf %lf] radius[%lf]",
183 boundary->circle.center->latitude, boundary->circle.center->longitude, boundary->circle.center->altitude, boundary->circle.radius);
184 } else if (boundary->type == LOCATION_BOUNDARY_RECT) {
185 g_printf("\n\tRECT: left_top[%lf %lf %lf] right_bottom[%lf %lf %lf]",
186 boundary->rect.left_top->latitude, boundary->rect.left_top->longitude, boundary->rect.left_top->altitude,
187 boundary->rect.right_bottom->latitude, boundary->rect.right_bottom->longitude, boundary->rect.right_bottom->altitude);
188 } else if (boundary->type == LOCATION_BOUNDARY_POLYGON) {
189 g_printf("\n\tPOLYGON: ");
191 GList *list = boundary->polygon.position_list;
193 g_list_foreach(list, PrintPolygonPosition, NULL);
197 static void RemoveBoundary(LocationBoundary *boundary, void *user_data)
199 LocationObject * obj = (LocationObject *)user_data;
200 if(obj == NULL || boundary == NULL) return;
202 location_boundary_remove(obj, boundary);
205 static void PrintProperty (LocationObject* loc)
208 LocationMethod method = LOCATION_METHOD_NONE;
209 LocationPosition *pos = NULL;
210 LocationAccuracy *acc = NULL;
211 guint pos_interval = 0;
212 guint vel_interval = 0;
213 guint sat_interval = 0;
214 gchar method_str[STR_MAX] = {0, };
215 gchar status_str[STR_MAX] = {0, };
217 gchar* devname = NULL;
219 g_object_get(loc, "method", &method, NULL);
220 GetMethod(method_str, method);
221 g_printf("method[%s] ", method_str);
223 if (LOCATION_METHOD_GPS == method) {
224 g_object_get(loc, "dev-name", &devname, NULL);
226 g_printf("dev-name[%s] ", devname);
231 int ret = location_get_last_position (loc, &pos, &acc);
232 if (ret == LOCATION_ERROR_NONE) {
233 GetStatus(status_str, pos->status);
234 g_printf("\nLast position [time(%d) lat(%f) long(%f) alt(%f) status(%s)]",
235 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, status_str);
236 location_position_free (pos);
237 location_accuracy_free (acc);
240 if (method == LOCATION_METHOD_HYBRID || method == LOCATION_METHOD_GPS) {
241 g_object_get(loc, "pos-interval", &pos_interval, NULL);
242 g_object_get(loc, "vel-interval", &vel_interval, NULL);
243 g_object_get(loc, "sat-interval", &sat_interval, NULL);
245 else if (method == LOCATION_METHOD_WPS) {
246 g_object_get(loc, "pos-interval", &pos_interval, NULL);
247 g_object_get(loc, "vel-interval", &vel_interval, NULL);
249 else if (method == LOCATION_METHOD_CPS) {
250 g_object_get(loc, "pos-interval", &pos_interval, NULL);
252 g_printf("Position interval : [%u], Velocity interval [%u], Satellite interval [%u]\n", pos_interval, vel_interval, sat_interval);
254 g_printf("\nSignals: ");
255 if (g_sig_enable) g_printf("[service-enabled], ");
256 if (g_sig_disable) g_printf("[service-disabled], ");
257 if (g_sig_update) g_printf("[service-updated], ");
258 if (g_sig_zonein) g_printf("[zone-in], ");
259 if (g_sig_zoneout) g_printf("[zone-out]");
262 static void cb_service_enabled (GObject *self, guint status, gpointer userdata)
264 g_printf("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
266 LocationObject *loc = (LocationObject*)userdata;
267 LocationAccuracy *acc = NULL;
268 LocationPosition *pos = NULL;
269 LocationVelocity *vel = NULL;
270 LocationMethod method;
272 g_object_get(loc, "method", &method, NULL);
273 g_printf("Get property>> method:%d", method);
275 if (LOCATION_ERROR_NONE == location_get_position (loc, &pos, &acc)) {
276 g_printf ("SYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d\n",
277 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
278 g_printf ("\tAccuracy level %d (%.0f meters %.0f meters)\n",
279 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
280 location_position_free(pos);
281 location_accuracy_free(acc);
282 } else g_warning ("SYNC>> Current position> failed");
283 if (LOCATION_ERROR_NONE == location_get_velocity (loc, &vel, &acc)) {
284 g_printf ("SYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f\n",
285 vel->timestamp, vel->speed, vel->direction, vel->climb);
286 g_printf ("\tAccuracy level %d (%.0f meters %.0f meters)\n",
287 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
288 location_velocity_free(vel);
289 location_accuracy_free(acc);
290 } else g_warning ("SYNC>> Current velocity> failed\n");
294 cb_service_disabled (GObject *self,
298 g_printf("cb_service_disabled: status(%d) userdata(0x%x)\n", status, (unsigned int)userdata);
302 cb_zone_in (GObject *self,
307 g_printf("cb_zone_in: type(%d)\n", type);
308 LocationPosition *pos = (LocationPosition*) position;
309 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
311 g_printf ("ASYNC>> ZoneIn> Current position: time: %d, lat: %f, long: %f, alt: %f\n",
312 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
313 g_printf ("\tAccuracy level %d (%.0f meters %.0f meters)\n",
314 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
318 cb_zone_out (GObject *self,
323 g_printf("cb_zone_out: type(%d)\n", type);
324 LocationPosition *pos = (LocationPosition*) position;
325 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
327 g_printf ("ASYNC>> ZoneOut> Current position: time: %d, lat: %f, long: %f, alt: %f\n",
328 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
329 g_printf ("\tAccuracy level %d (%.0f meters %.0f meters)\n",
330 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
334 cb_service_updated (GObject *self,
340 g_printf("cb_service_updated: type(%d) userdata(0x%x)", type, (unsigned int)userdata);
342 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
344 case POSITION_UPDATED: {
345 LocationPosition *pos = (LocationPosition*) data;
346 g_printf ("ASYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d\n",
347 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
348 g_printf ("\tAccuracy level %d (%.0f meters %.0f meters)\n",
349 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
352 case VELOCITY_UPDATED: {
353 LocationVelocity *vel = (LocationVelocity*) data;
354 g_printf ("ASYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f\n",
355 vel->timestamp, vel->speed, vel->direction, vel->climb);
356 g_printf ("\tAccuracy level %d (%.0f meters %.0f meters)\n",
357 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
360 case SATELLITE_UPDATED: {
368 LocationSatellite *sat = (LocationSatellite *)data;
369 g_printf ("SYNC>> Current Satellite> time: %d, satellite in view = %d, satellite in used = %d\n", sat->timestamp, sat->num_of_sat_inview, sat->num_of_sat_used);
370 g_printf ("\tinview satellite information = ");
371 for (idx=0; idx<sat->num_of_sat_inview; idx++) {
372 location_satellite_get_satellite_details(sat, idx, &prn, &used, &elevation, &azimuth, &snr);
373 g_printf ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d\n", idx, used, prn, elevation, azimuth, snr);
378 g_warning ("ASYNC>> Undefined update type");
383 static void print_menu()
385 g_printf("\n================================= Location API Test =================================\n");
386 g_printf("q. Exit\n");
387 g_printf("1. location_init\n");
388 g_printf("2. location_new\n");
389 g_printf("3. location_free\n");
390 g_printf("4. location_start\n");
391 g_printf("5. location_stop\n");
392 g_printf("6. location_get_position\n");
393 g_printf("6a. location_get_last_position\n");
394 g_printf("7. location_get_velocity\n");
395 g_printf("7a. location_get_last_velocity\n");
396 g_printf("8. location_get_satellite\n");
397 g_printf("8a. location_get_last_satellite\n");
398 g_printf("9. location_get_distance\n");
399 g_printf("10. location_is_supported_method\n");
400 g_printf("11. location_is_enabled_gps\n");
401 g_printf("99. location_send_command\n");
402 g_printf("a?. signals:(1)'service-enabled',(2)'service-disabled',(3)'service-updated',(4)'zone-in',(5)'zone-out'\n");
403 g_printf("b?. disconnect signals:(1)'service-enabled',(2)'service-disabled',(3)'service-updated',(4)'zone-in',(5)'zone-out'\n");
404 g_printf("c?. (1)Set boundary, (2)Get boundary, (3) Remove boundary, (4) Remove all boundaries, (5)Set device name, \n");
405 g_printf(" (6)Set position interval (7) Set velocity interval (8) Set satellite interval\n");
406 g_printf("==================================== Property ====================================\n");
407 PrintProperty(location_obj);
408 g_printf("\n==================================================================================\n");
411 int main(int argc, char** argv)
418 // If application is executed by AUL, this is not needed.
419 g_setenv("PKG_NAME", "com.samsung.location-api-test", 1);
423 #if !GLIB_CHECK_VERSION (2, 31, 0)
424 if( !g_thread_supported() )
431 g_main = g_thread_create(GmainThread, NULL, TRUE, &gerr);
433 g_printf("Error create gmain thread: Err domain[%d] Err code[%d] Err msg[%s]",
434 gerr->domain, gerr->code, gerr->message);
439 json_util_init(LOCATION_API_TEST_JSON_FILE);
440 g_printf("--- Start LBS Test App ---\n");
444 g_printf("Select option: ");
446 g_printf("======================================================================================\n");
447 if (0 == g_strcmp0 ("x", strOpt)) {
450 else if (0 == g_strcmp0("1",strOpt)) {
451 ret = location_init();
452 GetLocationError(str, ret);
453 g_printf("location_init: returned value [%s]\n", str);
454 } else if (0 == g_strcmp0("2",strOpt)) {
456 g_printf("Location object already existed: [0x%x]", (unsigned int)location_obj);
459 g_printf("LOCATION_METHOD_HYBRID[0] LOCATION_METHOD_GPS[1] LOCATION_METHOD_WPS[2] LOCATION_METHOD_CPS[3]\n");
460 g_printf("Select Location Method: ");
461 LocationMethod method = PromptInt();
462 location_obj = location_new(method);
463 if(location_obj) g_printf("Success\n");
464 else g_printf("Failed\n");
465 } else if (0 == g_strcmp0("3",strOpt)) {
466 ret = location_free (location_obj);
474 GetLocationError(str, ret);
475 g_printf("location_free: returned value [%s]\n", str);
476 } else if (0 == g_strcmp0("4",strOpt)) {
477 ret = location_start(location_obj);
478 GetLocationError(str, ret);
479 g_printf("location_start: returned value [%s]\n", str);
480 } else if (0 == g_strcmp0("5",strOpt)) {
481 ret = location_stop(location_obj);
482 GetLocationError(str, ret);
483 g_printf("location_stop: returned value [%s]\n", str);
484 } else if (0 == g_strcmp0("6",strOpt)) {
485 LocationPosition *pos = NULL;
486 LocationAccuracy *acc = NULL;
487 ret = location_get_position(location_obj, &pos, &acc);
488 GetLocationError(str, ret);
489 g_printf("location_get_position: returned value [%s]\n", str);
490 if (ret == LOCATION_ERROR_NONE) {
491 g_printf("time: [%d], latitude: [%f], longitude: [%f], altitude: [%f], status: [%d]\n", pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
492 GetAccuracyLevel(str, acc->level);
493 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
495 if(pos) location_position_free(pos);
496 if(acc) location_accuracy_free(acc);
497 } else if (0 == g_strcmp0("6a",strOpt)) {
498 LocationPosition *last_pos;
499 LocationAccuracy *last_acc;
502 ret = location_get_last_position (location_obj, &last_pos, &last_acc);
503 GetLocationError(str, ret);
504 if (ret == LOCATION_ERROR_NONE) {
505 g_printf ("SYNC>> Last position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
506 last_pos->timestamp, last_pos->latitude, last_pos->longitude, last_pos->altitude, last_pos->status);
507 g_printf ("\tAccuracy level %d (%.0f meters %.0f meters)",
508 last_acc->level, last_acc->horizontal_accuracy, last_acc->vertical_accuracy);
509 location_position_free(last_pos);
510 location_accuracy_free(last_acc);
511 } else g_warning ("SYNC>> Last position> failed. Error[%s]",str);
513 }else if(0 == g_strcmp0("7",strOpt) ){
514 LocationVelocity *vel = NULL;
515 LocationAccuracy *acc = NULL;
516 ret = location_get_velocity(location_obj, &vel, &acc);
517 g_printf("location_get_velocity: returned value [%s]\n", str);
518 if (ret == LOCATION_ERROR_NONE) {
519 g_printf("time: [%d], speed: [%f], direction: [%f], climb: [%f]\n", vel->timestamp, vel->speed, vel->direction, vel->climb);
520 GetAccuracyLevel(str, acc->level);
521 g_printf("level: [%s], horizontal_accuracy: [%f], vertical_accuracy: [%f]\n", str, acc->horizontal_accuracy, acc->vertical_accuracy);
524 GetLocationError(str, ret);
525 g_warning ("SYNC>> velocity> failed. Error[%s]", str);
527 if(vel) location_velocity_free(vel);
528 if(acc) location_accuracy_free(acc);
529 }else if(0 == g_strcmp0("7a",strOpt) ){
530 LocationVelocity *last_vel = NULL;
531 LocationAccuracy *last_acc = NULL;
532 ret = location_get_last_velocity (location_obj, &last_vel, &last_acc);
533 GetLocationError(str, ret);
534 if (ret == LOCATION_ERROR_NONE) {
535 g_printf ("SYNC>> Last velocity> time: %d, speed: %f, direction:%f, climb:%f",
536 last_vel->timestamp, last_vel->speed, last_vel->direction, last_vel->climb);
537 g_printf ("\tAccuracy level %d (%.0f meters %.0f meters)",
538 last_acc->level, last_acc->horizontal_accuracy, last_acc->vertical_accuracy);
539 location_velocity_free(last_vel);
540 location_accuracy_free(last_acc);
541 } else g_warning ("SYNC>> Last velocity> failed. Error[%s]", str);
542 }else if(0 == g_strcmp0("8",strOpt) ){
543 int ret = 0, idx = 0;
544 LocationSatellite *sat = NULL;
551 ret = location_get_satellite (location_obj, &sat);
552 GetLocationError(str, ret);
553 if (ret == LOCATION_ERROR_NONE) {
554 g_printf ("SYNC>> Current Sattelite> time = %d, satellite in view = %d, satellite in used = %d", sat->timestamp, sat->num_of_sat_inview, sat->num_of_sat_used);
555 g_printf ("\tinview satellite information = ");
556 for (idx=0; idx<sat->num_of_sat_inview; idx++) {
557 location_satellite_get_satellite_details(sat, idx, &prn, &used, &elevation, &azimuth, &snr);
558 g_printf ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr);
560 location_satellite_free (sat);
561 } else g_warning ("SYNC>> Current satellite> failed. Error[%s]", str);
562 }else if(0 == g_strcmp0("8a",strOpt) ){
563 int ret = 0, idx = 0;
564 LocationSatellite *last_sat = NULL;
571 ret = location_get_last_satellite (location_obj, &last_sat);
572 GetLocationError(str, ret);
573 if (ret == LOCATION_ERROR_NONE) {
574 g_printf ("SYNC>> Last Sattelite> time = %d, satellite in view = %d, satellite in used = %d", last_sat->timestamp, last_sat->num_of_sat_inview, last_sat->num_of_sat_used);
575 g_printf ("\tinview satellite information = ");
576 for (idx=0; idx<last_sat->num_of_sat_inview; idx++) {
577 location_satellite_get_satellite_details(last_sat, idx, &prn, &used, &elevation, &azimuth, &snr);
578 g_printf ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d", idx, used, prn, elevation, azimuth, snr);
580 location_satellite_free (last_sat);
581 } else g_warning ("SYNC>> Last satellite> failed. Error[%s]", str);
582 }else if(0 == g_strcmp0("9",strOpt) ) {
587 LocationPosition pos1, pos2;
589 pos1.latitude = 50.0663222;
590 pos1.longitude = -5.71475;
592 pos2.latitude = 58.6441;
593 pos2.longitude = -3.070094;
595 ret = location_get_distance(&pos1, &pos2, &distance);
596 GetLocationError(str, ret);
597 if(ret != LOCATION_ERROR_NONE) {
598 g_printf("Fail to get position. Error[%s]\n", str);
601 g_printf("The approximate distance is [%lu]\n", distance);
602 g_printf("cf.) It is approximately 969954.114 meter\n");
604 }else if(0 == g_strcmp0("10", strOpt)) {
606 char method_str[STR_MAX] = {0, };
607 char input[8] = {0, };
608 gboolean is_supported = FALSE;
610 g_printf("0.Hybrid 1.GPS 2.WPS 3.CPS\n");
611 g_printf("Select Method :");
612 fgets(input, 8, stdin);
613 method = atoi(input);
615 case LOCATION_METHOD_HYBRID:
616 is_supported = location_is_supported_method(LOCATION_METHOD_HYBRID);
619 case LOCATION_METHOD_GPS:
620 is_supported = location_is_supported_method(LOCATION_METHOD_GPS);
623 case LOCATION_METHOD_WPS:
624 is_supported = location_is_supported_method(LOCATION_METHOD_WPS);
627 case LOCATION_METHOD_CPS:
628 is_supported = location_is_supported_method(LOCATION_METHOD_CPS);
635 GetMethod(method_str, method);
637 g_printf("Method[%s] is %s.", method_str, is_supported ? "supported" : "not supported");
639 }else if(0 == g_strcmp0("11", strOpt)) {
640 gboolean is_enabled = FALSE;
641 is_enabled = location_is_enabled_gps(location_obj);
642 if(is_enabled == TRUE) g_printf("GPS is turned on");
643 else g_printf("GPS is turned off");
644 }else if(0 == g_strcmp0("99", strOpt)) {
646 const *str = "command";
647 ret = location_send_command(str);
649 g_printf("Success to send command[%s]", str);
650 }else if(0 == g_strcmp0("a1",strOpt)){
651 if(location_obj && !g_sig_enable) {
652 g_sig_enable = g_signal_connect (location_obj, "service-enabled", G_CALLBACK(cb_service_enabled), location_obj);
654 }else if(0 == g_strcmp0("a2",strOpt)){
655 if(location_obj && !g_sig_disable){
656 g_sig_disable = g_signal_connect (location_obj, "service-disabled", G_CALLBACK(cb_service_disabled), location_obj);
658 }else if(0 == g_strcmp0("a3",strOpt)){
659 if(location_obj && !g_sig_update){
660 g_sig_update = g_signal_connect (location_obj, "service-updated", G_CALLBACK(cb_service_updated), location_obj);
662 }else if(0 == g_strcmp0("a4",strOpt)){
663 if(location_obj && !g_sig_zonein){
664 g_sig_zonein = g_signal_connect (location_obj, "zone-in", G_CALLBACK(cb_zone_in), location_obj);
666 }else if(0 == g_strcmp0("a5",strOpt)){
667 if(location_obj && !g_sig_zoneout){
668 g_sig_zoneout = g_signal_connect (location_obj, "zone-out", G_CALLBACK(cb_zone_out), location_obj);
670 }else if(0 == g_strcmp0("b1",strOpt)){
671 if(location_obj && g_sig_enable) {
672 g_signal_handler_disconnect (location_obj, g_sig_enable);
675 }else if(0 == g_strcmp0("b2",strOpt)){
676 if(location_obj && g_sig_disable){
677 g_signal_handler_disconnect (location_obj, g_sig_disable);
680 }else if(0 == g_strcmp0("b3",strOpt)){
681 if(location_obj && g_sig_update){
682 g_signal_handler_disconnect (location_obj, g_sig_update);
685 }else if(0 == g_strcmp0("b4",strOpt)){
686 if(location_obj && g_sig_zonein){
687 g_signal_handler_disconnect (location_obj, g_sig_zonein);
690 }else if(0 == g_strcmp0("b5",strOpt)){
691 if(location_obj && g_sig_zoneout){
692 g_signal_handler_disconnect (location_obj, g_sig_zoneout);
695 }else if(0 == g_strcmp0("c1",strOpt)){
696 LocationBoundary* bound = NULL;
698 int polygon_count = json_util_get_polygon_count();
700 g_printf("[0].San jose(Rect) [1].Suwon HQ(Rect) [2].Seoul City(circle) ");
701 for(i = 0; i < polygon_count; i++)
702 g_printf("[%d].%s ", i + 3, json_util_get_polygon_name(i));
704 g_printf("\nSelect Boundary: ");
705 int opt = PromptInt();
707 LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
708 LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX);
709 bound = location_boundary_new_for_rect (lt, rb);
710 location_position_free(rb);
711 location_position_free(lt);
713 location_boundary_add(location_obj, bound);
715 } else if(opt == 1) {
716 LocationPosition* rb = location_position_new (0, 37.255, 127.058, 0, LOCATION_STATUS_2D_FIX);
717 LocationPosition* lt = location_position_new (0, 37.260, 127.045, 0, LOCATION_STATUS_2D_FIX);
718 bound = location_boundary_new_for_rect (lt, rb);
719 location_position_free(rb);
720 location_position_free(lt);
722 location_boundary_add(location_obj, bound);
723 } else if(opt == 2) {
724 LocationPosition *center = location_position_new(0, 37.566535, 126.977969, 0.0, LOCATION_STATUS_2D_FIX);
725 double radius = 10.0;
726 bound = location_boundary_new_for_circle(center, radius);
728 location_boundary_add(location_obj, bound);
729 } else if (opt > 2 && opt < 3 + polygon_count) {
731 int polygon_index = opt - 3;
732 bound = json_util_get_polygon_boundary(polygon_index);
733 location_boundary_add(location_obj, bound);
735 LocationPosition * check_pos = NULL;
736 gboolean ret = FALSE;
737 int count = json_util_get_marker_position_count(polygon_index);
738 for(index = 0; index < count; index++) {
739 check_pos = json_util_get_marker_position(polygon_index, index);
741 ret = location_boundary_if_inside(bound, check_pos);
742 g_printf("[%s] is [%s] and the test result is [%s]\n", json_util_get_marker_name(polygon_index, index), json_util_result_zone_test(polygon_index, index), ret == TRUE? "inside": "outside");
743 location_position_free(check_pos);
746 g_printf("boundary is not set\n");
748 location_boundary_free(bound);
750 }else if(0 == g_strcmp0("c2",strOpt)){
751 g_printf("Get Boundary\n");
752 location_boundary_foreach(location_obj, PrintBoundary, NULL);
754 }else if(0 == g_strcmp0("c3",strOpt)){
755 g_printf("Remove Boundary\n");
756 LocationBoundary* bound = NULL;
759 int polygon_count = json_util_get_polygon_count();
761 g_printf("[0].San jose(Rect) [1].Suwon HQ(Rect) [2].Seoul City(circle) ");
762 for(i = 0; i < polygon_count; i++)
763 g_printf("[%d].%s ", i + 3, json_util_get_polygon_name(i));
765 g_printf("\nSelect Boundary: ");
766 int opt = PromptInt();
768 LocationPosition* rb = location_position_new (0, 37.300, -121.86, 0, LOCATION_STATUS_2D_FIX);
769 LocationPosition* lt = location_position_new (0, 37.360, -121.92, 0, LOCATION_STATUS_2D_FIX);
770 bound = location_boundary_new_for_rect (lt, rb);
771 location_position_free(rb);
772 location_position_free(lt);
774 } else if(opt == 1) {
775 LocationPosition* rb = location_position_new (0, 37.255, 127.058, 0, LOCATION_STATUS_2D_FIX);
776 LocationPosition* lt = location_position_new (0, 37.260, 127.045, 0, LOCATION_STATUS_2D_FIX);
777 bound = location_boundary_new_for_rect (lt, rb);
778 location_position_free(rb);
779 location_position_free(lt);
781 } else if(opt == 2) {
782 LocationPosition *center = location_position_new(0, 37.566535, 126.977969, 0.0, LOCATION_STATUS_2D_FIX);
783 double radius = 10.0;
784 bound = location_boundary_new_for_circle(center, radius);
785 location_position_free(center);
787 } else if (opt > 2 && opt < 3 + polygon_count) {
788 int polygon_index = opt - 3;
789 bound = json_util_get_polygon_boundary(polygon_index);
791 g_printf("Invalid value\n");
794 if(bound != NULL) location_boundary_remove(location_obj, bound);
796 }else if(0 == g_strcmp0("c4",strOpt)){
797 location_boundary_foreach(location_obj, RemoveBoundary, location_obj);
798 }else if(0 == g_strcmp0("c5",strOpt)){
800 g_printf("Input device name: ");
801 fgets(buf, 255, stdin);
802 buf[strlen(buf)-1]='\0';
803 g_object_set(location_obj, "dev-name", buf, NULL);
804 } else if (0 == g_strcmp0("c6", strOpt)) {
806 g_printf("Input interval[1~120]:");
807 scanf("%u", &interval);
808 g_printf("changed interval to [%u]\n", interval);
809 g_object_set(location_obj, "pos-interval", interval, NULL);
810 } else if (0 == g_strcmp0("c7", strOpt)) {
812 g_printf("Input interval[1~120]:");
813 scanf("%u", &interval);
814 g_printf("changed interval to [%u]\n", interval);
815 g_object_set(location_obj, "vel-interval", interval, NULL);
816 } else if (0 == g_strcmp0("c8", strOpt)) {
818 g_printf("Input interval[1~120]:");
819 scanf("%u", &interval);
820 g_printf("changed interval to [%u]\n", interval);
821 g_object_set(location_obj, "sat-interval", interval, NULL);
822 }else if(0 == g_strcmp0("q",strOpt) ){
823 g_main_loop_quit(g_mainloop);
827 g_thread_join(g_main);
828 g_printf("\n--- Exit LBS Test App ---\n");