pud: include nmealib v1.0.0
[olsrd.git] / lib / pud / nmealib / include / nmea / info.h
1 /*
2  * This file is part of nmealib.
3  *
4  * Copyright (c) 2008 Timur Sinitsyn
5  * Copyright (c) 2011 Ferry Huberts
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20
21 #ifndef __NMEA_INFO_H__
22 #define __NMEA_INFO_H__
23
24 #include <stdint.h>
25 #include <stdbool.h>
26
27 /**
28  * @file
29  * The table below describes which fields are present in the sentences that are
30  * supported by the library.
31  <pre>
32  field/sentence       GPGGA   GPGSA   GPGSV   GPRMC   GPVTG
33  present:               x       x       x       x       x
34  smask:                 x       x       x       x       x
35  utc (date):                                    x
36  utc (time):            x                       x
37  sig:                   x                       x1
38  fix:                           x               x1
39  PDOP:                          x
40  HDOP:                  x       x
41  VDOP:                          x
42  lat:                   x                       x
43  lon:                   x                       x
44  elv:                   x
45  speed:                                         x       x
46  track:                                         x       x
47  mtrack:                                                x
48  magvar:                                        x
49  satinfo (inuse count): x       x1
50  satinfo (inuse):               x
51  satinfo (inview):                      x
52
53  x1 = not present in the sentence but the library sets it up.
54  </pre>
55  */
56
57 #define NMEA_SIG_BAD   (0)
58 #define NMEA_SIG_LOW   (1)
59 #define NMEA_SIG_MID   (2)
60 #define NMEA_SIG_HIGH  (3)
61 #define NMEA_SIG_RTKIN (4)
62 #define NMEA_SIG_FLRTK (5)
63 #define NMEA_SIG_ESTIM (6)
64 #define NMEA_SIG_MAN   (7)
65 #define NMEA_SIG_SIM   (8)
66
67 #define NMEA_FIX_BAD   (1)
68 #define NMEA_FIX_2D    (2)
69 #define NMEA_FIX_3D    (3)
70
71 #define NMEA_MAXSAT    (12)
72 #define NMEA_SATINPACK (4)
73 #define NMEA_NSATPACKS (NMEA_MAXSAT / NMEA_SATINPACK)
74
75 #define NMEA_DEF_LAT   (0.0)
76 #define NMEA_DEF_LON   (0.0)
77
78 #ifdef  __cplusplus
79 extern "C" {
80 #endif
81
82 /**
83  * Date and time data
84  * @see nmea_time_now
85  */
86 typedef struct _nmeaTIME {
87         int year;                                               /**< Years since 1900 */
88         int mon;                                                /**< Months since January - [0,11] */
89         int day;                                                /**< Day of the month - [1,31] */
90         int hour;                                               /**< Hours since midnight - [0,23] */
91         int min;                                                /**< Minutes after the hour - [0,59] */
92         int sec;                                                /**< Seconds after the minute - [0,59] */
93         int hsec;                                               /**< Hundredth part of second - [0,99] */
94 } nmeaTIME;
95
96 /**
97  * Position data in fractional degrees or radians
98  */
99 typedef struct _nmeaPOS {
100         double lat;                                             /**< Latitude */
101         double lon;                                             /**< Longitude */
102 } nmeaPOS;
103
104 /**
105  * Information about satellite
106  * @see nmeaSATINFO
107  * @see nmeaGPGSV
108  */
109 typedef struct _nmeaSATELLITE {
110         int id;                                                 /**< Satellite PRN number */
111         int elv;                                                /**< Elevation in degrees, 90 maximum */
112         int azimuth;                                    /**< Azimuth, degrees from true north, 000 to 359 */
113         int sig;                                                /**< Signal, 00-99 dB */
114 } nmeaSATELLITE;
115
116 /**
117  * Information about all satellites in view
118  * @see nmeaINFO
119  * @see nmeaGPGSV
120  */
121 typedef struct _nmeaSATINFO {
122         int inuse;                                              /**< Number of satellites in use (not those in view) */
123         int in_use[NMEA_MAXSAT];                /**< IDs of satellites in use (not those in view) */
124         int inview;                                             /**< Total number of satellites in view */
125         nmeaSATELLITE sat[NMEA_MAXSAT]; /**< Satellites information (in view) */
126 } nmeaSATINFO;
127
128 /**
129  * Summary GPS information from all parsed packets,
130  * used also for generating NMEA stream
131  * @see nmea_parse
132  * @see nmea_GPGGA2info,  nmea_...2info
133  */
134 typedef struct _nmeaINFO {
135         uint32_t present;                               /**< Mask specifying which fields are present */
136
137         int smask;                                              /**< Mask specifying from which sentences data has been obtained */
138
139         nmeaTIME utc;                                   /**< UTC of position */
140
141         int sig;                                                /**< GPS quality indicator: 0 = Invalid
142                                                                     1 = Fix;
143                                                                                                             2 = Differential
144                                                                                                             3 = Sensitive
145                                                                                                             4 = Real Time Kinematic
146                                                                                                             5 = Float RTK,
147                                                                                                             6 = estimated (dead reckoning) (v2.3)
148                                                                                                             7 = Manual input mode
149                                                                                                             8 = Simulation mode) */
150
151         int fix;                                                /**< Operating mode, used for navigation: 1 = Fix not available
152                                                                                   2 = 2D
153                                                                                   3 = 3D) */
154
155         double PDOP;                                    /**< Position Dilution Of Precision */
156         double HDOP;                                    /**< Horizontal Dilution Of Precision */
157         double VDOP;                                    /**< Vertical Dilution Of Precision */
158
159         double lat;                                             /**< Latitude in NDEG:  +/-[degree][min].[sec/60] */
160         double lon;                                             /**< Longitude in NDEG: +/-[degree][min].[sec/60] */
161         double elv;                                             /**< Antenna altitude above/below mean sea level (geoid) in meters */
162         double speed;                                   /**< Speed over the ground in kph */
163         double track;                                   /**< Track angle in degrees True */
164         double mtrack;                                  /**< Magnetic Track angle in degrees True */
165         double magvar;                                  /**< Magnetic variation degrees */
166
167         nmeaSATINFO satinfo;                    /**< Satellites information */
168 } nmeaINFO;
169
170 /**
171  * Enumeration for the fields names of a nmeaINFO structure.
172  * The values are used in the 'present' mask.
173  */
174 typedef enum _nmeaINFO_FIELD {
175         SMASK                   = (1 << 0),  /* 0x00001 */
176         UTCDATE                 = (1 << 1),  /* 0x00002 */
177         UTCTIME                 = (1 << 2),  /* 0x00004 */
178         SIG                             = (1 << 3),  /* 0x00008 */
179         FIX                             = (1 << 4),  /* 0x00010 */
180         PDOP                    = (1 << 5),  /* 0x00020 */
181         HDOP                    = (1 << 6),  /* 0x00040 */
182         VDOP                    = (1 << 7),  /* 0x00080 */
183         LAT                             = (1 << 8),  /* 0x00100 */
184         LON                             = (1 << 9),  /* 0x00200 */
185         ELV                             = (1 << 10), /* 0x00400 */
186         SPEED                   = (1 << 11), /* 0x00800 */
187         TRACK                   = (1 << 12), /* 0x01000 */
188         MTRACK                  = (1 << 13), /* 0x02000 */
189         MAGVAR                  = (1 << 14), /* 0x04000 */
190         SATINUSECOUNT   = (1 << 15), /* 0x08000 */
191         SATINUSE                = (1 << 16), /* 0x10000 */
192         SATINVIEW               = (1 << 17), /* 0x20000 */
193         _nmeaINFO_FIELD_LAST = SATINVIEW
194 } nmeaINFO_FIELD;
195
196 #define NMEA_INFO_PRESENT_MASK ((_nmeaINFO_FIELD_LAST << 1) - 1)
197
198 void nmea_time_now(nmeaTIME *utc, uint32_t * present);
199 void nmea_zero_INFO(nmeaINFO *info);
200
201 bool nmea_INFO_is_present_smask(int smask, nmeaINFO_FIELD fieldName);
202 bool nmea_INFO_is_present(uint32_t present, nmeaINFO_FIELD fieldName);
203 void nmea_INFO_set_present(uint32_t * present, nmeaINFO_FIELD fieldName);
204 void nmea_INFO_unset_present(uint32_t * present, nmeaINFO_FIELD fieldName);
205
206 void nmea_INFO_sanitise(nmeaINFO *nmeaInfo);
207
208 void nmea_INFO_unit_conversion(nmeaINFO * nmeaInfo);
209
210 #ifdef  __cplusplus
211 }
212 #endif
213
214 #endif /* __NMEA_INFO_H__ */