1 | /* |
2 | Copyright (c) 2016, Joo Aun Saw |
3 | All rights reserved. |
4 | |
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the following conditions are met: |
7 | * Redistributions of source code must retain the above copyright |
8 | notice, this list of conditions and the following disclaimer. |
9 | * Redistributions in binary form must reproduce the above copyright |
10 | notice, this list of conditions and the following disclaimer in the |
11 | documentation and/or other materials provided with the distribution. |
12 | * Neither the name of the copyright holder nor the |
13 | names of its contributors may be used to endorse or promote products |
14 | derived from this software without specific prior written permission. |
15 | |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ |
27 | |
28 | #ifndef LIBGPS_LOADER_H |
29 | #define LIBGPS_LOADER_H |
30 | |
31 | #include "gps.h" |
32 | |
33 | // IMPORTANT: Remember to copy gps.h from gpsd when upgrading libgps version. |
34 | #define LIBGPS_SO_VERSION "libgps.so.23" |
35 | |
36 | /** Structure containing all libgps information |
37 | */ |
38 | typedef struct |
39 | { |
40 | char *server; |
41 | char *port; |
42 | |
43 | void *libgps_handle; |
44 | int gpsd_connected; |
45 | /* requires libgps (GPSD_API_MAJOR_VERSION >= 5) */ |
46 | gps_mask_t current_mask; |
47 | struct gps_data_t gpsdata; |
48 | /* libgps functions */ |
49 | int (*gps_read)(struct gps_data_t *); |
50 | bool (*gps_waiting)(const struct gps_data_t *, int); |
51 | int (*gps_open)(const char *, const char *, struct gps_data_t *); |
52 | int (*gps_close)(struct gps_data_t *); |
53 | const char *(*gps_errstr)(const int); |
54 | int (*gps_stream)(struct gps_data_t *, unsigned int, void *); |
55 | } gpsd_info; |
56 | |
57 | /* libgps */ |
58 | void gpsd_init(gpsd_info *gpsd); |
59 | int libgps_load(gpsd_info *gpsd); |
60 | void libgps_unload(gpsd_info *gpsd); |
61 | |
62 | /* gpsd */ |
63 | int connect_gpsd(gpsd_info *gpsd); |
64 | int disconnect_gpsd(gpsd_info *gpsd); |
65 | int wait_gps_time(gpsd_info *gpsd, int timeout_s); |
66 | int read_gps_data_once(gpsd_info *gpsd); |
67 | |
68 | /* helper functions */ |
69 | int deg_to_str(double f, char *buf, int buf_size); |
70 | |
71 | |
72 | extern const char *LIBGPS_FILE; |
73 | |
74 | #endif /* LIBGPS_LOADER_H */ |
75 | |