Parent Directory | Revision Log
Geotoad fixes
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 | pos_t pos; /* Latitude/Longitude in degrees (valid if mode >= 2) */ |
43 | float eph; /* Horizontal position uncertainty, meters */ |
44 | float track; /* Course made good (relative to true north) */ |
45 | }; |
46 | |
47 | typedef unsigned int gps_mask_t; |
48 | |
49 | #ifdef USE_MAEMO |
50 | #ifdef ENABLE_GPSBT |
51 | #include <gpsbt.h> |
52 | #include <gpsmgr.h> |
53 | #endif |
54 | #include <errno.h> |
55 | #endif |
56 | |
57 | #ifdef ENABLE_LIBLOCATION |
58 | #include <location/location-gps-device.h> |
59 | #include <location/location-gpsd-control.h> |
60 | #endif |
61 | |
62 | typedef struct { |
63 | int num; |
64 | int *PRN; |
65 | int *ss; |
66 | int *used; |
67 | } gps_sat_t; |
68 | |
69 | typedef void (*gps_cb)(struct gps_state *state, void *data); |
70 | #define GPS_CB(f) ((gps_cb)(f)) |
71 | |
72 | typedef struct { |
73 | gps_cb cb; |
74 | gpointer data; |
75 | } gps_cb_t; |
76 | |
77 | #define LATLON_SET 0x00000008u |
78 | #define TRACK_SET 0x00000040u |
79 | #define STATUS_SET 0x00000100u |
80 | #define MODE_SET 0x00000200u |
81 | #define HERR_SET 0x00008000u |
82 | #define SATELLITE_SET 0x00040000u |
83 | |
84 | typedef struct gps_state { |
85 | #ifndef ENABLE_LIBLOCATION |
86 | #ifdef ENABLE_GPSBT |
87 | gpsbt_t context; |
88 | #endif |
89 | |
90 | GThread* thread_p; |
91 | GMutex *mutex; |
92 | GnomeVFSInetConnection *iconn; |
93 | GnomeVFSSocket *socket; |
94 | |
95 | gps_mask_t set; /* has field been set since this was last cleared? */ |
96 | struct gps_fix_t fix; /* accumulated PVT data */ |
97 | |
98 | /* GPS status -- always valid */ |
99 | int status; /* Do we have a fix? */ |
100 | #define STATUS_NO_FIX 0 /* no */ |
101 | #define STATUS_FIX 1 /* yes, without DGPS */ |
102 | #define STATUS_DGPS_FIX 2 /* yes, with DGPS */ |
103 | |
104 | /* precision of fix -- valid if satellites_used > 0 */ |
105 | int satellites_used; /* Number of satellites used in solution */ |
106 | int used[MAXCHANNELS]; /* PRNs of satellites used in solution */ |
107 | |
108 | /* satellite status -- valid when satellites > 0 */ |
109 | int satellites; /* # of satellites in view */ |
110 | int PRN[MAXCHANNELS]; /* PRNs of satellite */ |
111 | int elevation[MAXCHANNELS]; /* elevation of satellite */ |
112 | int azimuth[MAXCHANNELS]; /* azimuth */ |
113 | int ss[MAXCHANNELS]; /* signal-to-noise ratio (dB) */ |
114 | |
115 | #else |
116 | LocationGPSDevice *device; |
117 | LocationGPSDControl *control; |
118 | gboolean in_use; |
119 | guint idd_changed; |
120 | int fields; |
121 | |
122 | struct gps_fix_t fix; |
123 | gps_sat_t sats; |
124 | #endif |
125 | |
126 | GSList *cb; |
127 | |
128 | } gps_state_t; |
129 | |
130 | void gps_init(appdata_t *appdata); |
131 | void gps_release(appdata_t *appdata); |
132 | pos_t *gps_get_pos(appdata_t *appdata); |
133 | float gps_get_heading(appdata_t *appdata); |
134 | float gps_get_eph(appdata_t *appdata); |
135 | gps_sat_t *gps_get_sats(appdata_t *appdata); |
136 | void gps_change_state(appdata_t *appdata); |
137 | |
138 | void *gps_register_callback(appdata_t *appdata, gps_cb cb, gpointer data); |
139 | void gps_unregister_callback(appdata_t *appdata, void *cb); |
140 | |
141 | #endif // GPS_H |