Parent Directory | Revision Log
sun compass and libgps satellite integration
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 | harbaum | 282 | * This file is part of Maep. |
7 | harbaum | 1 | * |
8 | harbaum | 282 | * Maep is free software: you can redistribute it and/or modify |
9 | harbaum | 1 | * 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 | harbaum | 282 | * Maep is distributed in the hope that it will be useful, |
14 | harbaum | 1 | * 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 | harbaum | 282 | * along with Maep. If not, see <http://www.gnu.org/licenses/>. |
20 | harbaum | 1 | * |
21 | */ | ||
22 | |||
23 | #ifndef GPS_H | ||
24 | #define GPS_H | ||
25 | |||
26 | harbaum | 282 | #include <glib.h> |
27 | #include <math.h> // for isnan | ||
28 | harbaum | 1 | |
29 | harbaum | 282 | #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 | harbaum | 1 | #ifndef NAN |
37 | #define NAN (0.0/0.0) | ||
38 | #endif /* !NAN */ | ||
39 | |||
40 | harbaum | 283 | #define GPS_MAXCHANNELS 20 |
41 | harbaum | 1 | #define MAXTAGLEN 8 /* maximum length of sentence tag name */ |
42 | |||
43 | harbaum | 282 | 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 | harbaum | 283 | gps_sat_t sat_data[GPS_MAXCHANNELS]; |
58 | harbaum | 1 | }; |
59 | |||
60 | typedef unsigned int gps_mask_t; | ||
61 | |||
62 | harbaum | 282 | #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 | harbaum | 1 | #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 | harbaum | 282 | 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 | harbaum | 1 | #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 | harbaum | 282 | GMutex *mutex, *control_mutex, *global_mutex; |
106 | |||
107 | #ifdef USE_LIBGPS | ||
108 | struct gps_data_t *data; | ||
109 | #else | ||
110 | harbaum | 1 | GnomeVFSInetConnection *iconn; |
111 | GnomeVFSSocket *socket; | ||
112 | |||
113 | harbaum | 282 | /* number of clients requesting satellite details */ |
114 | gint sat_requests; | ||
115 | #endif | ||
116 | harbaum | 252 | |
117 | harbaum | 1 | #else |
118 | LocationGPSDevice *device; | ||
119 | harbaum | 11 | LocationGPSDControl *control; |
120 | harbaum | 282 | gboolean connected; |
121 | harbaum | 36 | guint idd_changed; |
122 | harbaum | 1 | #endif |
123 | harbaum | 149 | |
124 | harbaum | 282 | struct { |
125 | struct gps_t fix; | ||
126 | gps_mask_t set; | ||
127 | } last; | ||
128 | harbaum | 149 | |
129 | harbaum | 282 | struct gps_t fix; |
130 | gps_mask_t set; | ||
131 | |||
132 | GSList *callbacks; | ||
133 | |||
134 | gboolean stopped, backgrounded; | ||
135 | |||
136 | harbaum | 1 | } gps_state_t; |
137 | |||
138 | harbaum | 282 | 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 | harbaum | 1 | |
145 | #endif // GPS_H |