2
* Copyright (c) 2013 Jolla Mobile oy
3
* Author: Philippe De Swert <philippe.deswert@jollamobile.com>
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
27
#include <android/hardware/gps.h>
29
const GpsInterface* Gps = NULL;
30
const AGpsInterface* AGps = NULL;
31
const AGpsRilInterface* AGpsRil = NULL;
33
static const GpsInterface* get_gps_interface()
37
const GpsInterface* interface = NULL;
38
struct gps_device_t *device;
40
error = hw_get_module(GPS_HARDWARE_MODULE_ID, (hw_module_t const**)&module);
44
error = module->methods->open(module, GPS_HARDWARE_MODULE_ID, (struct hw_device_t **) &device);
45
fprintf(stdout, "*** device info\n id = %s\n name = %s\n author = %s\n",
46
module->id, module->name, module->author);
50
interface = device->get_gps_interface(device);
55
fprintf(stdout, "*** GPS interface not found :\(\n Bye! \n");
62
static const AGpsInterface* get_agps_interface(const GpsInterface *gps)
64
const AGpsInterface* interface = NULL;
68
interface = (const AGpsInterface*)gps->get_extension(AGPS_INTERFACE);
73
static const AGpsRilInterface* get_agps_ril_interface(const GpsInterface *gps)
75
const AGpsRilInterface* interface = NULL;
79
interface = (const AGpsRilInterface*)gps->get_extension(AGPS_RIL_INTERFACE);
84
static void location_callback(GpsLocation* location)
86
fprintf(stdout, "*** location callback\n");
87
fprintf(stdout, "flags:\t%d\n", location->flags);
88
fprintf(stdout, "latitude: \t%lf\n", location->latitude);
89
fprintf(stdout, "longtide: \t%lf\n", location->longitude);
90
fprintf(stdout, "accuracy:\t%f\n", location->accuracy);
91
fprintf(stdout, "utc: \t%ld\n", (long)location->timestamp);
94
static void status_callback(GpsStatus* status)
96
fprintf(stdout, "*** status callback\n");
98
switch (status->status)
100
case GPS_STATUS_NONE:
101
fprintf(stdout, "*** no gps\n");
103
case GPS_STATUS_SESSION_BEGIN:
104
fprintf(stdout, "*** session begin\n");
106
case GPS_STATUS_SESSION_END:
107
fprintf(stdout, "*** session end\n");
109
case GPS_STATUS_ENGINE_ON:
110
fprintf(stdout, "*** engine on\n");
112
case GPS_STATUS_ENGINE_OFF:
113
fprintf(stdout, "*** engine off\n");
116
fprintf(stdout, "*** unknown status\n");
120
static void sv_status_callback(GpsSvStatus* sv_info)
122
/* Too much useless info
123
fprintf(stdout, "*** sv status\n");
124
fprintf(stdout, "sv_size:\t%d\n", sv_info->size);
128
static void nmea_callback(GpsUtcTime timestamp, const char* nmea, int length)
130
fprintf(stdout, "*** nmea info\n");
131
fprintf(stdout, "timestamp:\t%ld\n", (long)timestamp);
132
fprintf(stdout, "nmea: \t%s\n", nmea);
133
fprintf(stdout, "length: \t%d\n", length);
136
static void set_capabilities_callback(uint32_t capabilities)
138
fprintf(stdout, "*** set capabilities\n");
142
static void acquire_wakelock_callback()
144
fprintf(stdout, "*** acquire wakelock\n");
148
static void release_wakelock_callback()
150
fprintf(stdout, "*** release wakelock\n");
154
static pthread_t create_thread_callback(const char* name, void (*start)(void *), void* arg)
160
error = pthread_attr_init(&attr);
161
error = pthread_create(&thread_id, &attr, (void*(*)(void*))start, arg);
170
static void agps_status_cb(AGpsStatus *status)
172
switch (status->status)
174
case GPS_REQUEST_AGPS_DATA_CONN:
175
fprintf(stdout, "*** data_conn_open\n");
176
AGps->data_conn_open("internet");
178
case GPS_RELEASE_AGPS_DATA_CONN:
179
fprintf(stdout, "*** data_conn_closed\n");
180
AGps->data_conn_closed();
185
static void agps_ril_set_id_cb(uint32_t flags)
187
fprintf(stdout, "*** set_id_cb\n");
188
AGpsRil->set_set_id(AGPS_SETID_TYPE_IMSI, "000000000000000");
191
static void agps_ril_refloc_cb(uint32_t flags)
193
fprintf(stdout, "*** refloc_cb\n");
194
/* TODO : find out how to fill in location
195
AGpsRefLocation location;
196
AGpsRil->set_ref_location(&location, sizeof(location));
200
GpsCallbacks callbacks = {
201
sizeof(GpsCallbacks),
206
set_capabilities_callback,
207
acquire_wakelock_callback,
208
release_wakelock_callback,
209
create_thread_callback,
212
AGpsCallbacks callbacks2 = {
214
create_thread_callback,
217
AGpsRilCallbacks callbacks3 = {
220
create_thread_callback,
223
void sigint_handler(int signum)
225
fprintf(stdout, "*** cleanup\n");
234
int main(int argc, char *argv[])
236
int sleeptime = 6000, opt, initok = 0;
238
int agps = 0, agpsril = 0, injecttime = 0;
240
while ((opt = getopt(argc, argv, "art")) != -1)
245
fprintf(stdout, "*** Using agps\n");
249
fprintf(stdout, "*** Using agpsril\n");
253
fprintf(stdout, "*** Timing info will be injected\n");
256
fprintf(stderr, "\n Usage: %s \n \
258
\t-r for agpsril,\n \
259
\t-t to inject time,\n \
260
\tnone for standalone gps\n",
267
fprintf(stdout, "*** setup signal handler\n");
268
signal(SIGINT, sigint_handler);
270
fprintf(stdout, "*** get gps interface\n");
271
Gps = get_gps_interface();
273
fprintf(stdout, "*** init gps interface\n");
274
initok = Gps->init(&callbacks);
275
fprintf(stdout, "*** setting positioning mode\n");
276
/* need to be done before starting gps or no info will come out */
277
if((agps||agpsril) && !initok)
278
Gps->set_position_mode(GPS_POSITION_MODE_MS_BASED, GPS_POSITION_RECURRENCE_PERIODIC, 100, 0, 0);
280
Gps->set_position_mode(GPS_POSITION_MODE_STANDALONE, GPS_POSITION_RECURRENCE_PERIODIC, 100, 0, 0);
282
if (Gps && !initok && (agps||agpsril))
284
fprintf(stdout, "*** get agps interface\n");
285
AGps = get_agps_interface(Gps);
288
fprintf(stdout, "*** set up agps interface\n");
289
AGps->init(&callbacks2);
290
fprintf(stdout, "*** set up agps server\n");
291
AGps->set_server(AGPS_TYPE_SUPL, "supl.google.com", 7276);
294
fprintf(stdout, "*** get agps ril interface\n");
296
AGpsRil = get_agps_ril_interface(Gps);
299
AGpsRil->init(&callbacks3);
302
fprintf(stdout, "*** delete aiding data\n");
303
Gps->delete_aiding_data(GPS_DELETE_ALL);
308
fprintf(stdout, "*** aiding gps by injecting time information\n");
309
gettimeofday(&tv, NULL);
310
Gps->inject_time(tv.tv_sec, tv.tv_sec, 0);
313
fprintf(stdout, "*** start gps track\n");
316
fprintf(stdout, "*** gps tracking started\n");
320
fprintf(stdout, "*** tracking.... \n");
322
sleeptime = sleeptime - 100;
325
fprintf(stdout, "*** stop tracking\n");
327
fprintf(stdout, "*** cleaning up\n");