3 |
* |
* |
4 |
* This file is based upon parts of gpsd/libgps |
* This file is based upon parts of gpsd/libgps |
5 |
* |
* |
6 |
* This file is part of GPXView. |
* This file is part of Maep. |
7 |
* |
* |
8 |
* GPXView is free software: you can redistribute it and/or modify |
* 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 |
* 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 |
* the Free Software Foundation, either version 3 of the License, or |
11 |
* (at your option) any later version. |
* (at your option) any later version. |
12 |
* |
* |
13 |
* GPXView is distributed in the hope that it will be useful, |
* Maep is distributed in the hope that it will be useful, |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
* GNU General Public License for more details. |
* GNU General Public License for more details. |
17 |
* |
* |
18 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
19 |
* along with GPXView. If not, see <http://www.gnu.org/licenses/>. |
* along with Maep. If not, see <http://www.gnu.org/licenses/>. |
20 |
* |
* |
21 |
*/ |
*/ |
22 |
|
|
23 |
#ifndef GPS_H |
#ifndef GPS_H |
24 |
#define GPS_H |
#define GPS_H |
25 |
|
|
26 |
#include "gpx.h" |
#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 |
#ifndef NAN |
37 |
#define NAN (0.0/0.0) |
#define NAN (0.0/0.0) |
39 |
|
|
40 |
#define MAXCHANNELS 20 |
#define MAXCHANNELS 20 |
41 |
#define MAXTAGLEN 8 /* maximum length of sentence tag name */ |
#define MAXTAGLEN 8 /* maximum length of sentence tag name */ |
|
#define MPS_TO_KNOTS 1.9438445 /* Meters per second to knots */ |
|
42 |
|
|
43 |
struct gps_fix_t { |
typedef struct { |
44 |
int mode; /* Mode of fix */ |
int prn; /* prn of satellite, -1 if no info */ |
45 |
#define MODE_NOT_SEEN 0 /* mode update not seen yet */ |
int ss; /* signal to noise ratio */ |
46 |
#define MODE_NO_FIX 1 /* none */ |
int used; /* satellite is is being used */ |
47 |
#define MODE_2D 2 /* good for latitude/longitude */ |
} gps_sat_t; |
48 |
#define MODE_3D 3 /* good for altitude/climb too */ |
|
49 |
pos_t pos; /* Latitude/Longitude in degrees (valid if mode >= 2) */ |
struct gps_t { |
50 |
float eph; /* Horizontal position uncertainty, meters */ |
double latitude; /* Latitude in degrees */ |
51 |
float track; /* Course made good (relative to true north) */ |
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[MAXCHANNELS]; |
58 |
}; |
}; |
59 |
|
|
60 |
typedef unsigned int gps_mask_t; |
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 |
#ifdef USE_MAEMO |
77 |
#ifdef ENABLE_GPSBT |
#ifdef ENABLE_GPSBT |
78 |
#include <gpsbt.h> |
#include <gpsbt.h> |
81 |
#include <errno.h> |
#include <errno.h> |
82 |
#endif |
#endif |
83 |
|
|
84 |
#ifdef ENABLE_LIBLOCATION |
typedef void (*gps_cb)(gps_mask_t set, struct gps_t *fix, void *data); |
85 |
#include <location/location-gps-device.h> |
#define GPS_CB(f) ((gps_cb)(f)) |
|
#include <location/location-gpsd-control.h> |
|
|
#endif |
|
|
|
|
|
typedef struct { |
|
|
int num; |
|
|
int *PRN; |
|
|
int *ss; |
|
|
int *used; |
|
|
} gps_sat_t; |
|
|
|
|
|
typedef void (*gps_cb)(struct gps_state *state, void *data); |
|
|
#define GPS_CB(f) ((gps_cb)(f)) |
|
86 |
|
|
87 |
typedef struct { |
typedef struct { |
88 |
|
gps_mask_t mask; |
89 |
gps_cb cb; |
gps_cb cb; |
90 |
gpointer data; |
void *data; |
91 |
} gps_cb_t; |
} gps_callback_t; |
92 |
|
|
93 |
#define LATLON_SET 0x00000008u |
#ifdef ENABLE_LIBLOCATION |
94 |
#define TRACK_SET 0x00000040u |
#include <location/location-gps-device.h> |
95 |
#define STATUS_SET 0x00000100u |
#include <location/location-gpsd-control.h> |
96 |
#define MODE_SET 0x00000200u |
#endif |
|
#define HERR_SET 0x00008000u |
|
|
#define SATELLITE_SET 0x00040000u |
|
97 |
|
|
98 |
typedef struct gps_state { |
typedef struct gps_state { |
99 |
#ifndef ENABLE_LIBLOCATION |
#ifndef ENABLE_LIBLOCATION |
102 |
#endif |
#endif |
103 |
|
|
104 |
GThread* thread_p; |
GThread* thread_p; |
105 |
GMutex *mutex; |
GMutex *mutex, *control_mutex, *global_mutex; |
106 |
|
|
107 |
|
#ifdef USE_LIBGPS |
108 |
|
struct gps_data_t *data; |
109 |
|
#else |
110 |
GnomeVFSInetConnection *iconn; |
GnomeVFSInetConnection *iconn; |
111 |
GnomeVFSSocket *socket; |
GnomeVFSSocket *socket; |
112 |
|
|
113 |
gps_mask_t set; /* has field been set since this was last cleared? */ |
/* number of clients requesting satellite details */ |
114 |
struct gps_fix_t fix; /* accumulated PVT data */ |
gint sat_requests; |
115 |
|
#endif |
116 |
|
|
|
/* GPS status -- always valid */ |
|
|
int status; /* Do we have a fix? */ |
|
|
#define STATUS_NO_FIX 0 /* no */ |
|
|
#define STATUS_FIX 1 /* yes, without DGPS */ |
|
|
#define STATUS_DGPS_FIX 2 /* yes, with DGPS */ |
|
|
|
|
|
/* precision of fix -- valid if satellites_used > 0 */ |
|
|
int satellites_used; /* Number of satellites used in solution */ |
|
|
int used[MAXCHANNELS]; /* PRNs of satellites used in solution */ |
|
|
|
|
|
/* satellite status -- valid when satellites > 0 */ |
|
|
int satellites; /* # of satellites in view */ |
|
|
int PRN[MAXCHANNELS]; /* PRNs of satellite */ |
|
|
int elevation[MAXCHANNELS]; /* elevation of satellite */ |
|
|
int azimuth[MAXCHANNELS]; /* azimuth */ |
|
|
int ss[MAXCHANNELS]; /* signal-to-noise ratio (dB) */ |
|
|
|
|
117 |
#else |
#else |
118 |
LocationGPSDevice *device; |
LocationGPSDevice *device; |
119 |
LocationGPSDControl *control; |
LocationGPSDControl *control; |
120 |
gboolean in_use; |
gboolean connected; |
121 |
guint idd_changed; |
guint idd_changed; |
|
int fields; |
|
|
|
|
|
struct gps_fix_t fix; |
|
|
gps_sat_t sats; |
|
122 |
#endif |
#endif |
123 |
|
|
124 |
GSList *cb; |
struct { |
125 |
|
struct gps_t fix; |
126 |
|
gps_mask_t set; |
127 |
|
} last; |
128 |
|
|
129 |
} gps_state_t; |
struct gps_t fix; |
130 |
|
gps_mask_t set; |
131 |
|
|
132 |
void gps_init(appdata_t *appdata); |
GSList *callbacks; |
133 |
void gps_release(appdata_t *appdata); |
|
134 |
pos_t *gps_get_pos(appdata_t *appdata); |
gboolean stopped, backgrounded; |
135 |
float gps_get_heading(appdata_t *appdata); |
|
136 |
float gps_get_eph(appdata_t *appdata); |
} gps_state_t; |
|
gps_sat_t *gps_get_sats(appdata_t *appdata); |
|
|
void gps_change_state(appdata_t *appdata); |
|
137 |
|
|
138 |
void *gps_register_callback(appdata_t *appdata, gps_cb cb, gpointer data); |
gps_state_t *gps_init(void); |
139 |
void gps_unregister_callback(appdata_t *appdata, void *cb); |
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 |
#endif // GPS_H |