Contents of /trunk/src/gps.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 149 - (show annotations)
Thu Oct 29 13:59:16 2009 UTC (14 years, 6 months ago) by harbaum
File MIME type: text/plain
File size: 6127 byte(s)
gps callback started
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 GPXView.
7 *
8 * GPXView 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 * GPXView 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 GPXView. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23 #ifndef GPS_H
24 #define GPS_H
25
26 #include "gpx.h"
27
28 #ifndef NAN
29 #define NAN (0.0/0.0)
30 #endif /* !NAN */
31
32 #define MAXCHANNELS 20
33 #define MAXTAGLEN 8 /* maximum length of sentence tag name */
34 #define MPS_TO_KNOTS 1.9438445 /* Meters per second to knots */
35
36 struct gps_fix_t {
37 int mode; /* Mode of fix */
38 #define MODE_NOT_SEEN 0 /* mode update not seen yet */
39 #define MODE_NO_FIX 1 /* none */
40 #define MODE_2D 2 /* good for latitude/longitude */
41 #define MODE_3D 3 /* good for altitude/climb too */
42 double ept; /* Expected time uncertainty */
43 // double latitude; /* Latitude in degrees (valid if mode >= 2) */
44 // double longitude; /* Longitude in degrees (valid if mode >= 2) */
45 pos_t pos; /* Latitude/Longitude in degrees (valid if mode >= 2) */
46 double eph; /* Horizontal position uncertainty, meters */
47 double altitude; /* Altitude in meters (valid if mode == 3) */
48 double track; /* Course made good (relative to true north) */
49 double epd; /* Track uncertainty, degrees */
50 double speed; /* Speed over ground, meters/sec */
51 double eps; /* Speed uncertainty, meters/sec */
52 double climb; /* Vertical speed, meters/sec */
53 double epc; /* Vertical speed uncertainty */
54 };
55
56 typedef unsigned int gps_mask_t;
57
58 struct gps_data_t {
59 gps_mask_t set; /* has field been set since this was last cleared? */
60 #define ONLINE_SET 0x00000001u
61 #define TIME_SET 0x00000002u
62 #define TIMERR_SET 0x00000004u
63 #define LATLON_SET 0x00000008u
64 #define ALTITUDE_SET 0x00000010u
65 #define SPEED_SET 0x00000020u
66 #define TRACK_SET 0x00000040u
67 #define CLIMB_SET 0x00000080u
68 #define STATUS_SET 0x00000100u
69 #define MODE_SET 0x00000200u
70 #define HDOP_SET 0x00000400u
71 #define VDOP_SET 0x00000800u
72 #define PDOP_SET 0x00001000u
73 #define TDOP_SET 0x00002000u
74 #define GDOP_SET 0x00004000u
75 #define DOP_SET (HDOP_SET|VDOP_SET|PDOP_SET|TDOP_SET|GDOP_SET)
76 #define HERR_SET 0x00008000u
77 #define VERR_SET 0x00010000u
78 #define PERR_SET 0x00020000u
79 #define ERR_SET (HERR_SET | VERR_SET | PERR_SET)
80 #define SATELLITE_SET 0x00040000u
81 #define PSEUDORANGE_SET 0x00080000u
82 #define USED_SET 0x00100000u
83 #define SPEEDERR_SET 0x00200000u
84 #define TRACKERR_SET 0x00400000u
85 #define CLIMBERR_SET 0x00800000u
86 #define DEVICE_SET 0x01000000u
87 #define DEVICELIST_SET 0x02000000u
88 #define DEVICEID_SET 0x04000000u
89 #define ERROR_SET 0x08000000u
90 #define CYCLE_START_SET 0x10000000u
91 #define RTCM_SET 0x20000000u
92 #define FIX_SET (TIME_SET|MODE_SET|TIMERR_SET|LATLON_SET|HERR_SET|ALTITUDE_SET|VERR_SET|TRACK_SET|TRACKERR_SET|SPEED_SET|SPEEDERR_SET|CLIMB_SET|CLIMBERR_SET)
93 double online; /* NZ if GPS is on line, 0 if not.
94 *
95 * Note: gpsd clears this flag when sentences
96 * fail to show up within the GPS's normal
97 * send cycle time. If the host-to-GPS
98 * link is lossy enough to drop entire
99 * sentences, this flag will be
100 * prone to false negatives.
101 */
102
103 struct gps_fix_t fix; /* accumulated PVT data */
104
105 double separation; /* Geoidal separation, MSL - WGS84 (Meters) */
106
107 /* GPS status -- always valid */
108 int status; /* Do we have a fix? */
109 #define STATUS_NO_FIX 0 /* no */
110 #define STATUS_FIX 1 /* yes, without DGPS */
111 #define STATUS_DGPS_FIX 2 /* yes, with DGPS */
112
113 /* precision of fix -- valid if satellites_used > 0 */
114 int satellites_used; /* Number of satellites used in solution */
115 int used[MAXCHANNELS]; /* PRNs of satellites used in solution */
116 double pdop, hdop, vdop, tdop, gdop; /* Dilution of precision */
117
118 /* satellite status -- valid when satellites > 0 */
119 int satellites; /* # of satellites in view */
120 int PRN[MAXCHANNELS]; /* PRNs of satellite */
121 int elevation[MAXCHANNELS]; /* elevation of satellite */
122 int azimuth[MAXCHANNELS]; /* azimuth */
123 int ss[MAXCHANNELS]; /* signal-to-noise ratio (dB) */
124
125 /* compass status -- TrueNorth (and any similar) devices only */
126 char headingStatus;
127 char pitchStatus;
128 char rollStatus;
129 double horzField; /* Magnitude of horizontal magnetic field */
130 };
131
132 #ifdef USE_MAEMO
133 #ifdef ENABLE_GPSBT
134 #include <gpsbt.h>
135 #include <gpsmgr.h>
136 #endif
137 #include <errno.h>
138 #endif
139
140 #ifdef ENABLE_LIBLOCATION
141 #include <location/location-gps-device.h>
142 #include <location/location-gpsd-control.h>
143 #endif
144
145 typedef struct {
146 int num;
147 int *PRN;
148 int *ss;
149 int *used;
150 } gps_sat_t;
151
152 typedef void (*gps_cb)(struct gps_state *, gpointer data);
153 #define GPS_CB(f) ((gps_cb)(f))
154
155 typedef struct {
156 gps_cb cb;
157 gpointer data;
158 } gps_cb_t;
159
160 typedef struct gps_state {
161 #ifndef ENABLE_LIBLOCATION
162 #ifdef ENABLE_GPSBT
163 gpsbt_t context;
164 #endif
165
166 GThread* thread_p;
167 GMutex *mutex;
168 GnomeVFSInetConnection *iconn;
169 GnomeVFSSocket *socket;
170
171 struct gps_data_t gpsdata;
172 #else
173 LocationGPSDevice *device;
174 LocationGPSDControl *control;
175 guint idd_changed;
176 int fields;
177 double latitude, longitude;
178 double heading, eph;
179 gps_sat_t sats;
180 #endif
181
182 GSList *cb;
183
184 } gps_state_t;
185
186 void gps_init(appdata_t *appdata);
187 void gps_release(appdata_t *appdata);
188 pos_t *gps_get_pos(appdata_t *appdata);
189 float gps_get_heading(appdata_t *appdata);
190 float gps_get_eph(appdata_t *appdata);
191 gps_sat_t *gps_get_sats(appdata_t *appdata);
192
193 void *gps_register_callback(appdata_t *appdata, gps_cb cb, gpointer data);
194 void gps_unregister_callback(appdata_t *appdata, void *cb);
195
196 #endif // GPS_H