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.
23 #include <location/location.h>
25 static GMainLoop *loop = NULL;
28 cb_service_updated (GObject *self,
34 g_debug("cb_service_updated: type(%d) userdata(0x%x)", type, (unsigned int)userdata);
36 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
38 case POSITION_UPDATED: {
39 LocationPosition *pos = (LocationPosition*) data;
40 g_debug ("ASYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
41 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
42 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
43 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
46 case VELOCITY_UPDATED: {
47 LocationVelocity *vel = (LocationVelocity*) data;
48 g_debug ("ASYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
49 vel->timestamp, vel->speed, vel->direction, vel->climb);
50 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
51 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
55 g_warning ("ASYNC>> Undefined update type");
62 cb_service_enabled (GObject *self,
66 g_debug("cb_service_enabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
68 LocationObject *loc = (LocationObject*)userdata;
69 LocationAccuracy *acc = NULL;
70 LocationPosition *pos = NULL;
71 LocationVelocity *vel = NULL;
72 LocationAddress *addr = NULL;
73 LocationSatellite *sat = NULL;
74 gchar *nmea_data = NULL;
77 if (LOCATION_ERROR_NONE == location_get_position (loc, &pos, &acc)) {
78 g_debug ("SYNC>> Current position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
79 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
80 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
81 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
82 location_position_free(pos);
83 location_accuracy_free(acc);
84 } else g_warning ("SYNC>> Current position> failed");
85 if (LOCATION_ERROR_NONE == location_get_velocity (loc, &vel, &acc)) {
86 g_debug ("SYNC>> Current velocity> time: %d, speed: %f, direction:%f, climb:%f",
87 vel->timestamp, vel->speed, vel->direction, vel->climb);
88 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
89 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
90 location_velocity_free(vel);
91 location_accuracy_free(acc);
92 } else g_warning ("SYNC>> Current velocity> failed");
93 if (LOCATION_ERROR_NONE == location_get_address(loc, &addr, &acc)) {
94 g_debug ("SYNC>> Current address> %s %s %s %s %s %s %s",
95 addr->building_number, addr->street, addr->district, addr->city, addr->state, addr->postal_code, addr->country_code);
96 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)", acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
97 location_address_free(addr);
98 location_accuracy_free(acc);
99 } else g_warning ("SYNC>> Current address> failed");
101 g_object_get (loc, "satellite", &sat, NULL);
103 g_debug ("SYNC>> Current Sattelite> satellite in view = %d, satellite in used = %d", sat->num_of_sat_inview, sat->num_of_sat_used);
104 g_debug ("\tinview satellite information = ");
105 for (idx=0; idx<sat->num_of_sat_inview; idx++) {
111 location_satellite_get_satellite_details(sat, idx, &prn, &used, &elevation, &azimuth, &snr);
112 g_debug ("\t\t[%02d] used: %d, prn: %d, elevation: %d, azimuth: %d, snr: %d",
113 idx, used, prn, elevation, azimuth, snr);
115 location_satellite_free (sat);
116 } else g_warning ("SYNC>> Current Sattelite> failed");
118 g_object_get(loc, "nmea", &nmea_data, NULL);
120 g_debug("SYNC>> Currnet NMEA> nmea_data:\n%s\n", nmea_data);
122 } else g_warning("SYNC>> Current NMEA> failed");
126 cb_service_disabled (GObject *self,
130 g_debug("cb_service_disabled: status(%d) userdata(0x%x)", status, (unsigned int)userdata);
134 cb_zone_in (GObject *self,
139 g_debug("cb_zone_in: type(%d)", type);
140 LocationPosition *pos = (LocationPosition*) position;
141 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
143 g_debug ("ASYNC>> ZoneIn> Current position: time: %d, lat: %f, long: %f, alt: %f",
144 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
145 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
146 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
150 cb_zone_out (GObject *self,
155 g_debug("cb_zone_out: type(%d)", type);
156 LocationPosition *pos = (LocationPosition*) position;
157 LocationAccuracy *acc = (LocationAccuracy*) accuracy;
159 g_debug ("ASYNC>> ZoneOut> Current position: time: %d, lat: %f, long: %f, alt: %f",
160 pos->timestamp, pos->latitude, pos->longitude, pos->altitude);
161 g_debug ("\tAccuracy level %d (%.0f meters %.0f meters)",
162 acc->level, acc->horizontal_accuracy, acc->vertical_accuracy);
166 main (int argc, char *argv[])
168 LocationObject *loc = NULL;
170 // If application is executed by AUL, this is not needed.
171 g_setenv("PKG_NAME", "org.tizen.gps-test", 1);
175 loop = g_main_loop_new (NULL, TRUE);
177 loc = location_new (LOCATION_METHOD_GPS);
179 g_debug("location_new failed");
183 LocationMethod method = LOCATION_METHOD_NONE;
184 g_object_get(loc, "method", &method, NULL);
185 g_debug("Get property>> method:%d", method);
187 char* devname = NULL;
188 g_object_get(loc, "dev-name", &devname, NULL);
190 g_debug("Get property>> dev-name: %s", devname);
191 } else g_warning("failed to get property> dev-name");
194 g_object_set(loc, "dev-name", "/dev/test", NULL);
195 g_object_get(loc, "dev-name", &devname, NULL);
197 g_debug("Get property>> dev-name: %s", devname);
199 } else g_warning("failed to set property> dev-name");
201 LocationBoundary *bound = NULL;
202 g_object_get(loc, "boundary", &bound, NULL);
204 g_debug("Get property>> boundary> type: %d", bound->type);
205 } else g_warning("failed to get property> boundary");
208 LocationPosition *rb = location_position_new(0, 37.255, 127.056, 0, LOCATION_STATUS_2D_FIX);
209 LocationPosition *lt = location_position_new(0, 37.260, 127.050, 0, LOCATION_STATUS_2D_FIX);
210 bound = location_boundary_new_for_rect(lt, rb);
211 location_position_free (rb);
212 location_position_free (lt);
214 g_object_set(loc, "boundary", bound, NULL);
215 } else g_warning("failed to location_boundary_new_for_rect()");
218 g_object_get(loc, "boundary", &bound, NULL);
220 g_debug("Set property>> boundary> type: %d, (%f,%f),(%f,%f)",
222 bound->rect.right_bottom->latitude, bound->rect.right_bottom->longitude,
223 bound->rect.left_top->latitude, bound->rect.left_top->longitude);
224 location_boundary_free (bound);
225 } else g_warning("failed to set property> boundary");
227 g_signal_connect (loc, "service-enabled", G_CALLBACK(cb_service_enabled), loc);
228 g_signal_connect (loc, "service-disabled", G_CALLBACK(cb_service_disabled), loc);
229 g_signal_connect (loc, "service-updated", G_CALLBACK(cb_service_updated), loc);
230 g_signal_connect (loc, "zone-in", G_CALLBACK(cb_zone_in), loc);
231 g_signal_connect (loc, "zone-out", G_CALLBACK(cb_zone_out), loc);
233 if( LOCATION_ERROR_NONE != location_start (loc) ){
234 g_debug("location_start failed");
238 g_main_loop_run (loop);
242 LocationPosition *pos = NULL;
243 g_object_get(loc, "last-position", &pos, NULL);
245 g_debug ("Get property>> last-position> time: %d, lat: %f, long: %f, alt: %f, status: %d",
246 pos->timestamp, pos->latitude, pos->longitude, pos->altitude, pos->status);
247 location_position_free(pos);
248 } else g_warning("failed to get property> last-position");