Contents of /trunk/src/gps.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 283 - (show annotations)
Thu May 27 19:13:18 2010 UTC (13 years, 11 months ago) by harbaum
File MIME type: text/plain
File size: 3536 byte(s)
sun compass and libgps satellite integration
1 /*
2 * Copyright (C) 2008 Till Harbaum <till@harbaum.org>.
3 *
4 * This file is based upon parts of gpsd/libgps
5 *
6 * This file is part of Maep.
7 *
8 * Maep is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * Maep is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with Maep. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 #ifndef GPS_H
24 #define GPS_H
25
26 #include <glib.h>
27 #include <math.h> // for isnan
28
29 #include <libgnomevfs/gnome-vfs.h>
30 #include <libgnomevfs/gnome-vfs-inet-connection.h>
31
32 #ifdef USE_LIBGPS
33 #include <gps.h>
34 #endif
35
36 #ifndef NAN
37 #define NAN (0.0/0.0)
38 #endif /* !NAN */
39
40 #define GPS_MAXCHANNELS 20
41 #define MAXTAGLEN 8 /* maximum length of sentence tag name */
42
43 typedef struct {
44 int prn; /* prn of satellite, -1 if no info */
45 int ss; /* signal to noise ratio */
46 int used; /* satellite is is being used */
47 } gps_sat_t;
48
49 struct gps_t {
50 double latitude; /* Latitude in degrees */
51 double longitude; /* Longitude in degrees */
52 double altitude; /* Altitude in meters */
53 double eph; /* Horizontal position uncertainty, meters */
54 double track; /* Course made good (relative to true north) */
55
56 int sat_num;
57 gps_sat_t sat_data[GPS_MAXCHANNELS];
58 };
59
60 typedef unsigned int gps_mask_t;
61
62 #define FIX_LATLON_SET (1<<0)
63 #define FIX_ALTITUDE_SET (1<<1)
64 #define FIX_TRACK_SET (1<<2)
65 #define FIX_HERR_SET (1<<3)
66 #define FIX_SATELLITE_SET (1<<4)
67
68 #define LATLON_CHANGED (FIX_LATLON_SET << 8)
69 #define ALTITUDE_CHANGED (FIX_ALTITUDE_SET << 8)
70 #define TRACK_CHANGED (FIX_TRACK_SET << 8)
71 #define HERR_CHANGED (FIX_HERR_SET << 8)
72 #define SATELLITE_CHANGED (FIX_SATELLITE_SET << 8)
73
74 #define CHANGED_MASK 0xff00
75
76 #ifdef USE_MAEMO
77 #ifdef ENABLE_GPSBT
78 #include <gpsbt.h>
79 #include <gpsmgr.h>
80 #endif
81 #include <errno.h>
82 #endif
83
84 typedef void (*gps_cb)(gps_mask_t set, struct gps_t *fix, void *data);
85 #define GPS_CB(f) ((gps_cb)(f))
86
87 typedef struct {
88 gps_mask_t mask;
89 gps_cb cb;
90 void *data;
91 } gps_callback_t;
92
93 #ifdef ENABLE_LIBLOCATION
94 #include <location/location-gps-device.h>
95 #include <location/location-gpsd-control.h>
96 #endif
97
98 typedef struct gps_state {
99 #ifndef ENABLE_LIBLOCATION
100 #ifdef ENABLE_GPSBT
101 gpsbt_t context;
102 #endif
103
104 GThread* thread_p;
105 GMutex *mutex, *control_mutex, *global_mutex;
106
107 #ifdef USE_LIBGPS
108 struct gps_data_t *data;
109 #else
110 GnomeVFSInetConnection *iconn;
111 GnomeVFSSocket *socket;
112
113 /* number of clients requesting satellite details */
114 gint sat_requests;
115 #endif
116
117 #else
118 LocationGPSDevice *device;
119 LocationGPSDControl *control;
120 gboolean connected;
121 guint idd_changed;
122 #endif
123
124 struct {
125 struct gps_t fix;
126 gps_mask_t set;
127 } last;
128
129 struct gps_t fix;
130 gps_mask_t set;
131
132 GSList *callbacks;
133
134 gboolean stopped, backgrounded;
135
136 } gps_state_t;
137
138 gps_state_t *gps_init(void);
139 void gps_register_callback(gps_state_t *gps_state, int mask,
140 gps_cb cb, void *data);
141 void gps_unregister_callback(gps_state_t *gps_state, gps_cb cb);
142 void gps_release(gps_state_t *gps_state);
143 void gps_enable(gps_state_t *gps_state, gboolean enable);
144
145 #endif // GPS_H