"Fossies" - the Fresh Open Source Software Archive 
Member "netxms-3.8.166/src/agent/subagents/gps/nmea.h" (23 Feb 2021, 14511 Bytes) of package /linux/misc/netxms-3.8.166.tar.gz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
For more information about "nmea.h" see the
Fossies "Dox" file reference documentation.
1 /*
2 *
3 * NMEA library
4 * URL: http://nmea.sourceforge.net
5 * Author: Tim (xtimor@gmail.com)
6 * Licence: http://www.gnu.org/licenses/lgpl.html
7 * $Id: config.h 17 2008-03-11 11:56:11Z xtimor $
8 *
9 */
10
11 #ifndef __NMEA_CONFIG_H__
12 #define __NMEA_CONFIG_H__
13
14 #define NMEA_VERSION ("0.5.3")
15 #define NMEA_VERSION_MAJOR (0)
16 #define NMEA_VERSION_MINOR (5)
17 #define NMEA_VERSION_PATCH (3)
18
19 #define NMEA_CONVSTR_BUF (256)
20 #define NMEA_TIMEPARSE_BUF (256)
21
22 #if defined(WINCE) || defined(UNDER_CE)
23 # define NMEA_CE
24 #endif
25
26 #if defined(WIN32) || defined(NMEA_CE)
27 # define NMEA_WIN
28 #else
29 # define NMEA_UNI
30 #endif
31
32 #if defined(NMEA_WIN) && (_MSC_VER >= 1400)
33 # pragma warning(disable: 4996) /* declared deprecated */
34 #endif
35
36 #if defined(_MSC_VER)
37 # define NMEA_POSIX(x) _##x
38 # define NMEA_INLINE __inline
39 #else
40 # define NMEA_POSIX(x) x
41 # define NMEA_INLINE inline
42 #endif
43
44 #if !defined(NDEBUG) && !defined(NMEA_CE)
45 # include <assert.h>
46 # define NMEA_ASSERT(x) assert(x)
47 #else
48 # define NMEA_ASSERT(x)
49 #endif
50
51 #endif /* __NMEA_CONFIG_H__ */
52 /*
53 *
54 * NMEA library
55 * URL: http://nmea.sourceforge.net
56 * Author: Tim (xtimor@gmail.com)
57 * Licence: http://www.gnu.org/licenses/lgpl.html
58 * $Id: units.h 4 2007-08-27 13:11:03Z xtimor $
59 *
60 */
61
62 #ifndef __NMEA_UNITS_H__
63 #define __NMEA_UNITS_H__
64
65 /*
66 * Distance units
67 */
68
69 #define NMEA_TUD_YARDS (1.0936) /**< Yeards, meter * NMEA_TUD_YARDS = yard */
70 #define NMEA_TUD_KNOTS (1.852) /**< Knots, kilometer / NMEA_TUD_KNOTS = knot */
71 #define NMEA_TUD_MILES (1.609) /**< Miles, kilometer / NMEA_TUD_MILES = mile */
72
73 /*
74 * Speed units
75 */
76
77 #define NMEA_TUS_MS (3.6) /**< Meters per seconds, (k/h) / NMEA_TUS_MS= (m/s) */
78
79 #endif /* __NMEA_UNITS_H__ */
80 /*
81 *
82 * NMEA library
83 * URL: http://nmea.sourceforge.net
84 * Author: Tim (xtimor@gmail.com)
85 * Licence: http://www.gnu.org/licenses/lgpl.html
86 * $Id: time.h 4 2007-08-27 13:11:03Z xtimor $
87 *
88 */
89
90 /*! \file */
91
92 #ifndef __NMEA_TIME_H__
93 #define __NMEA_TIME_H__
94
95 #ifdef __cplusplus
96 extern "C" {
97 #endif
98
99 /**
100 * Date and time data
101 * @see nmea_time_now
102 */
103 typedef struct _nmeaTIME
104 {
105 int year; /**< Years since 1900 */
106 int mon; /**< Months since January - [0,11] */
107 int day; /**< Day of the month - [1,31] */
108 int hour; /**< Hours since midnight - [0,23] */
109 int min; /**< Minutes after the hour - [0,59] */
110 int sec; /**< Seconds after the minute - [0,59] */
111 int hsec; /**< Hundredth part of second - [0,99] */
112
113 } nmeaTIME;
114
115 /**
116 * \brief Get time now to nmeaTIME structure
117 */
118 void nmea_time_now(nmeaTIME *t);
119
120 #ifdef __cplusplus
121 }
122 #endif
123
124 #endif /* __NMEA_TIME_H__ */
125 /*
126 *
127 * NMEA library
128 * URL: http://nmea.sourceforge.net
129 * Author: Tim (xtimor@gmail.com)
130 * Licence: http://www.gnu.org/licenses/lgpl.html
131 * $Id: info.h 10 2007-11-15 14:50:15Z xtimor $
132 *
133 */
134
135 /*! \file */
136
137 #ifndef __NMEA_INFO_H__
138 #define __NMEA_INFO_H__
139
140 #define NMEA_SIG_BAD (0)
141 #define NMEA_SIG_LOW (1)
142 #define NMEA_SIG_MID (2)
143 #define NMEA_SIG_HIGH (3)
144
145 #define NMEA_FIX_BAD (1)
146 #define NMEA_FIX_2D (2)
147 #define NMEA_FIX_3D (3)
148
149 #define NMEA_MAXSAT (12)
150 #define NMEA_SATINPACK (4)
151 #define NMEA_NSATPACKS (NMEA_MAXSAT / NMEA_SATINPACK)
152
153 #define NMEA_DEF_LAT (5001.2621)
154 #define NMEA_DEF_LON (3613.0595)
155
156 #ifdef __cplusplus
157 extern "C" {
158 #endif
159
160 /**
161 * Position data in fractional degrees or radians
162 */
163 typedef struct _nmeaPOS
164 {
165 double lat; /**< Latitude */
166 double lon; /**< Longitude */
167
168 } nmeaPOS;
169
170 /**
171 * Information about satellite
172 * @see nmeaSATINFO
173 * @see nmeaGPGSV
174 */
175 typedef struct _nmeaSATELLITE
176 {
177 int id; /**< Satellite PRN number */
178 int in_use; /**< Used in position fix */
179 int elv; /**< Elevation in degrees, 90 maximum */
180 int azimuth; /**< Azimuth, degrees from true north, 000 to 359 */
181 int sig; /**< Signal, 00-99 dB */
182
183 } nmeaSATELLITE;
184
185 /**
186 * Information about all satellites in view
187 * @see nmeaINFO
188 * @see nmeaGPGSV
189 */
190 typedef struct _nmeaSATINFO
191 {
192 int inuse; /**< Number of satellites in use (not those in view) */
193 int inview; /**< Total number of satellites in view */
194 nmeaSATELLITE sat[NMEA_MAXSAT]; /**< Satellites information */
195
196 } nmeaSATINFO;
197
198 /**
199 * Summary GPS information from all parsed packets,
200 * used also for generating NMEA stream
201 * @see nmea_parse
202 * @see nmea_GPGGA2info, nmea_...2info
203 */
204 typedef struct _nmeaINFO
205 {
206 int smask; /**< Mask specifying types of packages from which data have been obtained */
207
208 nmeaTIME utc; /**< UTC of position */
209
210 int sig; /**< GPS quality indicator (0 = Invalid; 1 = Fix; 2 = Differential, 3 = Sensitive) */
211 int fix; /**< Operating mode, used for navigation (1 = Fix not available; 2 = 2D; 3 = 3D) */
212
213 double PDOP; /**< Position Dilution Of Precision */
214 double HDOP; /**< Horizontal Dilution Of Precision */
215 double VDOP; /**< Vertical Dilution Of Precision */
216
217 double lat; /**< Latitude in NDEG - +/-[degree][min].[sec/60] */
218 double lon; /**< Longitude in NDEG - +/-[degree][min].[sec/60] */
219 double elv; /**< Antenna altitude above/below mean sea level (geoid) in meters */
220 double speed; /**< Speed over the ground in kilometers/hour */
221 double direction; /**< Track angle in degrees True */
222 double declination; /**< Magnetic variation degrees (Easterly var. subtracts from true course) */
223
224 nmeaSATINFO satinfo; /**< Satellites information */
225
226 } nmeaINFO;
227
228 void nmea_zero_INFO(nmeaINFO *info);
229
230 #ifdef __cplusplus
231 }
232 #endif
233
234 #endif /* __NMEA_INFO_H__ */
235 /*
236 *
237 * NMEA library
238 * URL: http://nmea.sourceforge.net
239 * Author: Tim (xtimor@gmail.com)
240 * Licence: http://www.gnu.org/licenses/lgpl.html
241 * $Id: tok.h 4 2007-08-27 13:11:03Z xtimor $
242 *
243 */
244
245 #ifndef __NMEA_TOK_H__
246 #define __NMEA_TOK_H__
247
248 #ifdef __cplusplus
249 extern "C" {
250 #endif
251
252 int nmea_calc_crc(const char *buff, int buff_sz);
253 int nmea_atoi(const char *str, int str_sz, int radix);
254 double nmea_atof(const char *str, int str_sz);
255 int nmea_printf(char *buff, int buff_sz, const char *format, ...);
256 int nmea_scanf(const char *buff, int buff_sz, const char *format, ...);
257
258 #ifdef __cplusplus
259 }
260 #endif
261
262 #endif /* __NMEA_TOK_H__ */
263 /*
264 *
265 * NMEA library
266 * URL: http://nmea.sourceforge.net
267 * Author: Tim (xtimor@gmail.com)
268 * Licence: http://www.gnu.org/licenses/lgpl.html
269 * $Id: sentence.h 17 2008-03-11 11:56:11Z xtimor $
270 *
271 */
272
273 /*! \file */
274
275 #ifndef __NMEA_SENTENCE_H__
276 #define __NMEA_SENTENCE_H__
277
278 #ifdef __cplusplus
279 extern "C" {
280 #endif
281
282 /**
283 * NMEA packets type which parsed and generated by library
284 */
285 enum nmeaPACKTYPE
286 {
287 GPNON = 0x0000, /**< Unknown packet type. */
288 GPGGA = 0x0001, /**< GGA - Essential fix data which provide 3D location and accuracy data. */
289 GPGSA = 0x0002, /**< GSA - GPS receiver operating mode, SVs used for navigation, and DOP values. */
290 GPGSV = 0x0004, /**< GSV - Number of SVs in view, PRN numbers, elevation, azimuth & SNR values. */
291 GPRMC = 0x0008, /**< RMC - Recommended Minimum Specific GPS/TRANSIT Data. */
292 GPVTG = 0x0010 /**< VTG - Actual track made good and speed over ground. */
293 };
294
295 /**
296 * GGA packet information structure (Global Positioning System Fix Data)
297 */
298 typedef struct _nmeaGPGGA
299 {
300 nmeaTIME utc; /**< UTC of position (just time) */
301 double lat; /**< Latitude in NDEG - [degree][min].[sec/60] */
302 char ns; /**< [N]orth or [S]outh */
303 double lon; /**< Longitude in NDEG - [degree][min].[sec/60] */
304 char ew; /**< [E]ast or [W]est */
305 int sig; /**< GPS quality indicator (0 = Invalid; 1 = Fix; 2 = Differential, 3 = Sensitive) */
306 int satinuse; /**< Number of satellites in use (not those in view) */
307 double HDOP; /**< Horizontal dilution of precision */
308 double elv; /**< Antenna altitude above/below mean sea level (geoid) */
309 char elv_units; /**< [M]eters (Antenna height unit) */
310 double diff; /**< Geoidal separation (Diff. between WGS-84 earth ellipsoid and mean sea level. '-' = geoid is below WGS-84 ellipsoid) */
311 char diff_units; /**< [M]eters (Units of geoidal separation) */
312 double dgps_age; /**< Time in seconds since last DGPS update */
313 int dgps_sid; /**< DGPS station ID number */
314
315 } nmeaGPGGA;
316
317 /**
318 * GSA packet information structure (Satellite status)
319 */
320 typedef struct _nmeaGPGSA
321 {
322 char fix_mode; /**< Mode (M = Manual, forced to operate in 2D or 3D; A = Automatic, 3D/2D) */
323 int fix_type; /**< Type, used for navigation (1 = Fix not available; 2 = 2D; 3 = 3D) */
324 int sat_prn[NMEA_MAXSAT]; /**< PRNs of satellites used in position fix (null for unused fields) */
325 double PDOP; /**< Dilution of precision */
326 double HDOP; /**< Horizontal dilution of precision */
327 double VDOP; /**< Vertical dilution of precision */
328
329 } nmeaGPGSA;
330
331 /**
332 * GSV packet information structure (Satellites in view)
333 */
334 typedef struct _nmeaGPGSV
335 {
336 int pack_count; /**< Total number of messages of this type in this cycle */
337 int pack_index; /**< Message number */
338 int sat_count; /**< Total number of satellites in view */
339 nmeaSATELLITE sat_data[NMEA_SATINPACK];
340
341 } nmeaGPGSV;
342
343 /**
344 * RMC packet information structure (Recommended Minimum sentence C)
345 */
346 typedef struct _nmeaGPRMC
347 {
348 nmeaTIME utc; /**< UTC of position */
349 char status; /**< Status (A = active or V = void) */
350 double lat; /**< Latitude in NDEG - [degree][min].[sec/60] */
351 char ns; /**< [N]orth or [S]outh */
352 double lon; /**< Longitude in NDEG - [degree][min].[sec/60] */
353 char ew; /**< [E]ast or [W]est */
354 double speed; /**< Speed over the ground in knots */
355 double direction; /**< Track angle in degrees True */
356 double declination; /**< Magnetic variation degrees (Easterly var. subtracts from true course) */
357 char declin_ew; /**< [E]ast or [W]est */
358 char mode; /**< Mode indicator of fix type (A = autonomous, D = differential, E = estimated, N = not valid, S = simulator) */
359
360 } nmeaGPRMC;
361
362 /**
363 * VTG packet information structure (Track made good and ground speed)
364 */
365 typedef struct _nmeaGPVTG
366 {
367 double dir; /**< True track made good (degrees) */
368 char dir_t; /**< Fixed text 'T' indicates that track made good is relative to true north */
369 double dec; /**< Magnetic track made good */
370 char dec_m; /**< Fixed text 'M' */
371 double spn; /**< Ground speed, knots */
372 char spn_n; /**< Fixed text 'N' indicates that speed over ground is in knots */
373 double spk; /**< Ground speed, kilometers per hour */
374 char spk_k; /**< Fixed text 'K' indicates that speed over ground is in kilometers/hour */
375
376 } nmeaGPVTG;
377
378 void nmea_zero_GPGGA(nmeaGPGGA *pack);
379 void nmea_zero_GPGSA(nmeaGPGSA *pack);
380 void nmea_zero_GPGSV(nmeaGPGSV *pack);
381 void nmea_zero_GPRMC(nmeaGPRMC *pack);
382 void nmea_zero_GPVTG(nmeaGPVTG *pack);
383
384 #ifdef __cplusplus
385 }
386 #endif
387
388 #endif /* __NMEA_SENTENCE_H__ */
389 /*
390 *
391 * NMEA library
392 * URL: http://nmea.sourceforge.net
393 * Author: Tim (xtimor@gmail.com)
394 * Licence: http://www.gnu.org/licenses/lgpl.html
395 * $Id: context.h 4 2007-08-27 13:11:03Z xtimor $
396 *
397 */
398
399 #ifndef __NMEA_CONTEXT_H__
400 #define __NMEA_CONTEXT_H__
401
402 #define NMEA_DEF_PARSEBUFF (1024)
403 #define NMEA_MIN_PARSEBUFF (256)
404
405 #ifdef __cplusplus
406 extern "C" {
407 #endif
408
409 typedef void (*nmeaTraceFunc)(const char *str, int str_size);
410 typedef void (*nmeaErrorFunc)(const char *str, int str_size);
411
412 typedef struct _nmeaPROPERTY
413 {
414 nmeaTraceFunc trace_func;
415 nmeaErrorFunc error_func;
416 int parse_buff_size;
417
418 } nmeaPROPERTY;
419
420 nmeaPROPERTY * nmea_property();
421
422 void nmea_trace(const char *str, ...);
423 void nmea_trace_buff(const char *buff, int buff_size);
424 void nmea_error(const char *str, ...);
425
426 #ifdef __cplusplus
427 }
428 #endif
429
430 #endif /* __NMEA_CONTEXT_H__ */
431 /*
432 *
433 * NMEA library
434 * URL: http://nmea.sourceforge.net
435 * Author: Tim (xtimor@gmail.com)
436 * Licence: http://www.gnu.org/licenses/lgpl.html
437 * $Id: parse.h 4 2007-08-27 13:11:03Z xtimor $
438 *
439 */
440
441 #ifndef __NMEA_PARSE_H__
442 #define __NMEA_PARSE_H__
443
444 #ifdef __cplusplus
445 extern "C" {
446 #endif
447
448 int nmea_pack_type(const char *buff, int buff_sz);
449 int nmea_find_tail(const char *buff, int buff_sz, int *res_crc);
450
451 int nmea_parse_GPGGA(const char *buff, int buff_sz, nmeaGPGGA *pack);
452 int nmea_parse_GPGSA(const char *buff, int buff_sz, nmeaGPGSA *pack);
453 int nmea_parse_GPGSV(const char *buff, int buff_sz, nmeaGPGSV *pack);
454 int nmea_parse_GPRMC(const char *buff, int buff_sz, nmeaGPRMC *pack);
455 int nmea_parse_GPVTG(const char *buff, int buff_sz, nmeaGPVTG *pack);
456
457 void nmea_GPGGA2info(nmeaGPGGA *pack, nmeaINFO *info);
458 void nmea_GPGSA2info(nmeaGPGSA *pack, nmeaINFO *info);
459 void nmea_GPGSV2info(nmeaGPGSV *pack, nmeaINFO *info);
460 void nmea_GPRMC2info(nmeaGPRMC *pack, nmeaINFO *info);
461 void nmea_GPVTG2info(nmeaGPVTG *pack, nmeaINFO *info);
462
463 #ifdef __cplusplus
464 }
465 #endif
466
467 #endif /* __NMEA_PARSE_H__ */
468 /*
469 *
470 * NMEA library
471 * URL: http://nmea.sourceforge.net
472 * Author: Tim (xtimor@gmail.com)
473 * Licence: http://www.gnu.org/licenses/lgpl.html
474 * $Id: parser.h 4 2007-08-27 13:11:03Z xtimor $
475 *
476 */
477
478 #ifndef __NMEA_PARSER_H__
479 #define __NMEA_PARSER_H__
480
481 #ifdef __cplusplus
482 extern "C" {
483 #endif
484
485 /*
486 * high level
487 */
488
489 typedef struct _nmeaPARSER
490 {
491 void *top_node;
492 void *end_node;
493 unsigned char *buffer;
494 int buff_size;
495 int buff_use;
496
497 } nmeaPARSER;
498
499 int nmea_parser_init(nmeaPARSER *parser);
500 void nmea_parser_destroy(nmeaPARSER *parser);
501
502 int nmea_parse(
503 nmeaPARSER *parser,
504 const char *buff, int buff_sz,
505 nmeaINFO *info
506 );
507
508 /*
509 * low level
510 */
511
512 int nmea_parser_push(nmeaPARSER *parser, const char *buff, int buff_sz);
513 int nmea_parser_top(nmeaPARSER *parser);
514 int nmea_parser_pop(nmeaPARSER *parser, void **pack_ptr);
515 int nmea_parser_peek(nmeaPARSER *parser, void **pack_ptr);
516 int nmea_parser_drop(nmeaPARSER *parser);
517 int nmea_parser_buff_clear(nmeaPARSER *parser);
518 int nmea_parser_queue_clear(nmeaPARSER *parser);
519
520 #ifdef __cplusplus
521 }
522 #endif
523
524 #endif /* __NMEA_PARSER_H__ */