version 0.3, initial support to liblocation
[googlelatitude] / src / gps.cpp
1 #include "gps.h"
2
3 GpsMaemo5::GpsMaemo5(QObject *parent) : QObject(parent) {
4     latitude = 0;
5     longitude = 0;
6     accuracy = 0;
7     usegps = -1;
8
9     control = location_gpsd_control_get_default();
10     device = (LocationGPSDevice*) g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
11     g_signal_connect(device, "changed", G_CALLBACK(GpsMaemo5_changed), this);
12 }
13
14 void GpsMaemo5::get_acwp() {
15     g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_ACWP, NULL);
16     usegps = 0;
17     restart();
18 }
19
20 void GpsMaemo5::get_agnss() {
21     g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_AGNSS, NULL);
22     usegps = 1;
23     restart();
24 }
25
26 void GpsMaemo5::stop() {
27     location_gpsd_control_stop(control);
28 }
29
30 void GpsMaemo5::restart() {
31     location_gpsd_control_stop(control);
32     location_gpsd_control_start(control);
33 }
34
35 void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps) {
36     if (device->fix) {
37         if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
38             g_print("lat = %f, long = %f, eph = %f\n", device->fix->latitude, device->fix->longitude, device->fix->eph/100.);
39             gps->latitude = device->fix->latitude;
40             gps->longitude = device->fix->longitude;
41             gps->accuracy = device->fix->eph/100.;
42
43             if ( gps->usegps == 0) {
44                 emit gps->getOK_acwp();
45             } else if ( gps->usegps == 1 ) {
46                 if ( gps->device->satellites_in_use > 0 ) {
47                     emit gps->getOK_agnss();
48                 }
49             } else {
50                 emit gps->getOK();
51             }
52         }
53     }
54 }