pud: include nmealib v1.0.3
[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_FIRST (NMEA_SIG_BAD)
58 #define NMEA_SIG_BAD   (0)
59 #define NMEA_SIG_LOW   (1)
60 #define NMEA_SIG_MID   (2)
61 #define NMEA_SIG_HIGH  (3)
62 #define NMEA_SIG_RTKIN (4)
63 #define NMEA_SIG_FLRTK (5)
64 #define NMEA_SIG_ESTIM (6)
65 #define NMEA_SIG_MAN   (7)
66 #define NMEA_SIG_SIM   (8)
67 #define NMEA_SIG_LAST  (NMEA_SIG_SIM)
68
69 #define NMEA_FIX_FIRST (NMEA_FIX_BAD)
70 #define NMEA_FIX_BAD   (1)
71 #define NMEA_FIX_2D    (2)
72 #define NMEA_FIX_3D    (3)
73 #define NMEA_FIX_LAST  (NMEA_FIX_3D)
74
75 #define NMEA_MAXSAT    (64)
76 #define NMEA_SATINPACK (4)
77 #define NMEA_NSATPACKS (NMEA_MAXSAT / NMEA_SATINPACK)
78
79 #define NMEA_DEF_LAT   (0.0)
80 #define NMEA_DEF_LON   (0.0)
81
82 #ifdef  __cplusplus
83 extern "C" {
84 #endif
85
86 /**
87  * Date and time data
88  * @see nmea_time_now
89  */
90 typedef struct _nmeaTIME {
91         int year;                                               /**< Years since 1900 */
92         int mon;                                                /**< Months since January - [0,11] */
93         int day;                                                /**< Day of the month - [1,31] */
94         int hour;                                               /**< Hours since midnight - [0,23] */
95         int min;                                                /**< Minutes after the hour - [0,59] */
96         int sec;                                                /**< Seconds after the minute - [0,59] */
97         int hsec;                                               /**< Hundredth part of second - [0,99] */
98 } nmeaTIME;
99
100 /**
101  * Position data in fractional degrees or radians
102  */
103 typedef struct _nmeaPOS {
104         double lat;                                             /**< Latitude */
105         double lon;                                             /**< Longitude */
106 } nmeaPOS;
107
108 /**
109  * Information about satellite
110  * @see nmeaSATINFO
111  * @see nmeaGPGSV
112  */
113 typedef struct _nmeaSATELLITE {
114         int id;                                                 /**< Satellite PRN number */
115         int elv;                                                /**< Elevation in degrees, 90 maximum */
116         int azimuth;                                    /**< Azimuth, degrees from true north, 000 to 359 */
117         int sig;                                                /**< Signal, 00-99 dB */
118 } nmeaSATELLITE;
119
120 /**
121  * Information about all satellites in view
122  * @see nmeaINFO
123  * @see nmeaGPGSV
124  */
125 typedef struct _nmeaSATINFO {
126         int inuse;                                              /**< Number of satellites in use (not those in view) */
127         int in_use[NMEA_MAXSAT];                /**< IDs of satellites in use (not those in view) */
128         int inview;                                             /**< Total number of satellites in view */
129         nmeaSATELLITE sat[NMEA_MAXSAT]; /**< Satellites information (in view) */
130 } nmeaSATINFO;
131
132 /**
133  * Summary GPS information from all parsed packets,
134  * used also for generating NMEA stream
135  * @see nmea_parse
136  * @see nmea_GPGGA2info,  nmea_...2info
137  */
138 typedef struct _nmeaINFO {
139         uint32_t present;                               /**< Mask specifying which fields are present */
140
141         int smask;                                              /**< Mask specifying from which sentences data has been obtained */
142
143         nmeaTIME utc;                                   /**< UTC of position */
144
145         int sig;                                                /**< GPS quality indicator: 0 = Invalid
146                                                                     1 = Fix;
147                                                                                                             2 = Differential
148                                                                                                             3 = Sensitive
149                                                                                                             4 = Real Time Kinematic
150                                                                                                             5 = Float RTK,
151                                                                                                             6 = estimated (dead reckoning) (v2.3)
152                                                                                                             7 = Manual input mode
153                                                                                                             8 = Simulation mode) */
154
155         int fix;                                                /**< Operating mode, used for navigation: 1 = Fix not available
156                                                                                   2 = 2D
157                                                                                   3 = 3D) */
158
159         double PDOP;                                    /**< Position Dilution Of Precision */
160         double HDOP;                                    /**< Horizontal Dilution Of Precision */
161         double VDOP;                                    /**< Vertical Dilution Of Precision */
162
163         double lat;                                             /**< Latitude in NDEG:  +/-[degree][min].[sec/60] */
164         double lon;                                             /**< Longitude in NDEG: +/-[degree][min].[sec/60] */
165         double elv;                                             /**< Antenna altitude above/below mean sea level (geoid) in meters */
166         double speed;                                   /**< Speed over the ground in kph */
167         double track;                                   /**< Track angle in degrees True */
168         double mtrack;                                  /**< Magnetic Track angle in degrees True */
169         double magvar;                                  /**< Magnetic variation degrees */
170
171         nmeaSATINFO satinfo;                    /**< Satellites information */
172 } nmeaINFO;
173
174 /**
175  * Enumeration for the fields names of a nmeaINFO structure.
176  * The values are used in the 'present' mask.
177  */
178 typedef enum _nmeaINFO_FIELD {
179         SMASK                   = (1 << 0),  /* 0x00001 */
180         UTCDATE                 = (1 << 1),  /* 0x00002 */
181         UTCTIME                 = (1 << 2),  /* 0x00004 */
182         SIG                             = (1 << 3),  /* 0x00008 */
183         FIX                             = (1 << 4),  /* 0x00010 */
184         PDOP                    = (1 << 5),  /* 0x00020 */
185         HDOP                    = (1 << 6),  /* 0x00040 */
186         VDOP                    = (1 << 7),  /* 0x00080 */
187         LAT                             = (1 << 8),  /* 0x00100 */
188         LON                             = (1 << 9),  /* 0x00200 */
189         ELV                             = (1 << 10), /* 0x00400 */
190         SPEED                   = (1 << 11), /* 0x00800 */
191         TRACK                   = (1 << 12), /* 0x01000 */
192         MTRACK                  = (1 << 13), /* 0x02000 */
193         MAGVAR                  = (1 << 14), /* 0x04000 */
194         SATINUSECOUNT   = (1 << 15), /* 0x08000 */
195         SATINUSE                = (1 << 16), /* 0x10000 */
196         SATINVIEW               = (1 << 17), /* 0x20000 */
197         _nmeaINFO_FIELD_LAST = SATINVIEW
198 } nmeaINFO_FIELD;
199
200 #define NMEA_INFO_PRESENT_MASK ((_nmeaINFO_FIELD_LAST << 1) - 1)
201
202 void nmea_time_now(nmeaTIME *utc, uint32_t * present);
203 void nmea_zero_INFO(nmeaINFO *info);
204
205 bool nmea_INFO_is_present_smask(int smask, nmeaINFO_FIELD fieldName);
206 bool nmea_INFO_is_present(uint32_t present, nmeaINFO_FIELD fieldName);
207 void nmea_INFO_set_present(uint32_t * present, nmeaINFO_FIELD fieldName);
208 void nmea_INFO_unset_present(uint32_t * present, nmeaINFO_FIELD fieldName);
209
210 void nmea_INFO_sanitise(nmeaINFO *nmeaInfo);
211
212 void nmea_INFO_unit_conversion(nmeaINFO * nmeaInfo);
213
214 #ifdef  __cplusplus
215 }
216 #endif
217
218 #endif /* __NMEA_INFO_H__ */