Contents of /trunk/src/gps.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (hide annotations)
Thu Jun 25 19:08:48 2009 UTC (14 years, 10 months ago) by harbaum
File MIME type: text/plain
File size: 5997 byte(s)
Liblocation support finalized
1 harbaum 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 epv; /* Vertical position uncertainty, meters */
49     double track; /* Course made good (relative to true north) */
50     double epd; /* Track uncertainty, degrees */
51     double speed; /* Speed over ground, meters/sec */
52     double eps; /* Speed uncertainty, meters/sec */
53     double climb; /* Vertical speed, meters/sec */
54     double epc; /* Vertical speed uncertainty */
55     };
56    
57     typedef unsigned int gps_mask_t;
58    
59     struct gps_data_t {
60     gps_mask_t set; /* has field been set since this was last cleared? */
61     #define ONLINE_SET 0x00000001u
62     #define TIME_SET 0x00000002u
63     #define TIMERR_SET 0x00000004u
64     #define LATLON_SET 0x00000008u
65     #define ALTITUDE_SET 0x00000010u
66     #define SPEED_SET 0x00000020u
67     #define TRACK_SET 0x00000040u
68     #define CLIMB_SET 0x00000080u
69     #define STATUS_SET 0x00000100u
70     #define MODE_SET 0x00000200u
71     #define HDOP_SET 0x00000400u
72     #define VDOP_SET 0x00000800u
73     #define PDOP_SET 0x00001000u
74     #define TDOP_SET 0x00002000u
75     #define GDOP_SET 0x00004000u
76     #define DOP_SET (HDOP_SET|VDOP_SET|PDOP_SET|TDOP_SET|GDOP_SET)
77     #define HERR_SET 0x00008000u
78     #define VERR_SET 0x00010000u
79     #define PERR_SET 0x00020000u
80     #define ERR_SET (HERR_SET | VERR_SET | PERR_SET)
81     #define SATELLITE_SET 0x00040000u
82     #define PSEUDORANGE_SET 0x00080000u
83     #define USED_SET 0x00100000u
84     #define SPEEDERR_SET 0x00200000u
85     #define TRACKERR_SET 0x00400000u
86     #define CLIMBERR_SET 0x00800000u
87     #define DEVICE_SET 0x01000000u
88     #define DEVICELIST_SET 0x02000000u
89     #define DEVICEID_SET 0x04000000u
90     #define ERROR_SET 0x08000000u
91     #define CYCLE_START_SET 0x10000000u
92     #define RTCM_SET 0x20000000u
93     #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)
94     double online; /* NZ if GPS is on line, 0 if not.
95     *
96     * Note: gpsd clears this flag when sentences
97     * fail to show up within the GPS's normal
98     * send cycle time. If the host-to-GPS
99     * link is lossy enough to drop entire
100     * sentences, this flag will be
101     * prone to false negatives.
102     */
103    
104     struct gps_fix_t fix; /* accumulated PVT data */
105    
106     double separation; /* Geoidal separation, MSL - WGS84 (Meters) */
107    
108     /* GPS status -- always valid */
109     int status; /* Do we have a fix? */
110     #define STATUS_NO_FIX 0 /* no */
111     #define STATUS_FIX 1 /* yes, without DGPS */
112     #define STATUS_DGPS_FIX 2 /* yes, with DGPS */
113    
114     /* precision of fix -- valid if satellites_used > 0 */
115     int satellites_used; /* Number of satellites used in solution */
116     int used[MAXCHANNELS]; /* PRNs of satellites used in solution */
117     double pdop, hdop, vdop, tdop, gdop; /* Dilution of precision */
118    
119     /* redundant with the estimate elments in the fix structure */
120     double epe; /* spherical position error, 95% confidence (meters) */
121    
122     /* satellite status -- valid when satellites > 0 */
123     int satellites; /* # of satellites in view */
124     int PRN[MAXCHANNELS]; /* PRNs of satellite */
125     int elevation[MAXCHANNELS]; /* elevation of satellite */
126     int azimuth[MAXCHANNELS]; /* azimuth */
127     int ss[MAXCHANNELS]; /* signal-to-noise ratio (dB) */
128    
129     /* compass status -- TrueNorth (and any similar) devices only */
130     char headingStatus;
131     char pitchStatus;
132     char rollStatus;
133     double horzField; /* Magnitude of horizontal magnetic field */
134     };
135    
136     #ifdef USE_MAEMO
137     #ifdef ENABLE_GPSBT
138     #include <gpsbt.h>
139     #include <gpsmgr.h>
140     #endif
141     #include <errno.h>
142     #endif
143    
144     #ifdef ENABLE_LIBLOCATION
145     #include <location/location-gps-device.h>
146     #include <location/location-gpsd-control.h>
147     #endif
148    
149 harbaum 8 typedef struct {
150     int num;
151     int *PRN;
152     int *ss;
153     int *used;
154     } gps_sat_t;
155    
156    
157 harbaum 1 typedef struct gps_state {
158     #ifndef ENABLE_LIBLOCATION
159     #ifdef ENABLE_GPSBT
160     gpsbt_t context;
161     #endif
162    
163     GThread* thread_p;
164     GMutex *mutex;
165     GnomeVFSInetConnection *iconn;
166     GnomeVFSSocket *socket;
167    
168     struct gps_data_t gpsdata;
169     #else
170     LocationGPSDevice *device;
171     guint idd_changed;
172 harbaum 8 int fields;
173 harbaum 1 double latitude, longitude;
174 harbaum 7 double heading, epe;
175 harbaum 8 gps_sat_t sats;
176 harbaum 1 #endif
177     } gps_state_t;
178    
179     void gps_init(appdata_t *appdata);
180     void gps_release(appdata_t *appdata);
181     pos_t *gps_get_pos(appdata_t *appdata);
182     float gps_get_heading(appdata_t *appdata);
183     float gps_get_epe(appdata_t *appdata);
184     gps_sat_t *gps_get_sats(appdata_t *appdata);
185    
186    
187     #endif // GPS_H