8c28b65800d5a44ae913a3601223f9de1ec298de
[bertos.git] / bertos / net / nmea.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2009 Develer S.r.l. (http://www.develer.com/)
30  *
31  * -->
32  * \brief NMEA Parser
33  *
34  * \author Daniele Basile <asterix@develer.com>
35  *
36  * $WIZ$ module_name = "nmea"
37  * $WIZ$ module_configuration = "bertos/cfg/cfg_nmea.h"
38  * $WIZ$ module_depends = "kfile"
39  */
40
41 #ifndef NET_NMEA_H
42 #define NET_NMEA_H
43
44 #include "cfg/cfg_nmea.h"
45
46 #include <net/nmeap/inc/nmeap.h>
47
48 #include <kern/kfile.h>
49
50 /*
51  * Implemented NMEA parser strings.
52  */
53 #define NMEA_GPGGA 1   // GGA MESSAGE ID
54 #define NMEA_GPRMC 2   // RMC MESSAGE ID
55 #define NMEA_GPVTG 3   // VTG MESSAGE ID
56 #define NMEA_GPGSV 4   // GSV MESSAGE ID
57
58 // Standart type to rappresent fiels.
59 typedef uint32_t udegree_t;    // Micro degrees
60 typedef uint32_t mdegree_t;    // Milli degrees
61 typedef uint16_t degree_t;     // Degrees
62 typedef uint16_t cm_t;         // Centimeter
63 typedef uint32_t sec_t;        // Seconds
64 typedef uint32_t str_time_t;   // Time format HH:MM:SS
65 typedef uint32_t mknots_t;     // Milli knots
66 typedef uint32_t mkh_t;        // Milli kilometers/hour
67 typedef uint16_t number_t;      // Pure number
68
69
70 /**
71  * Extracted data from a GGA message
72  */
73 typedef struct NmeaGga
74 {
75         udegree_t     latitude;
76         udegree_t     longitude;
77         cm_t          altitude;
78         sec_t         time;
79         number_t       satellites;
80         number_t       quality;
81         udegree_t     hdop;
82         udegree_t     geoid;
83 } NmeaGga;
84
85 /**
86  * Extracted data from an RMC message
87  */
88 typedef struct NmeaRmc
89 {
90         str_time_t    time;
91         char          warn;
92         udegree_t     latitude;
93         udegree_t     longitude;
94         mknots_t      speed;
95         mdegree_t     course;
96         str_time_t    date;
97         mdegree_t     mag_var;
98 } NmeaRmc;
99
100 /**
101  * Extracted data from an vtg message
102  */
103 typedef struct NmeaVtg
104 {
105         mdegree_t     track_good;
106         mknots_t      knot_speed;
107         mkh_t         km_speed;
108 } NmeaVtg;
109
110 /**
111  * Extracted data from an gsv message
112  */
113 typedef struct NmeaGsv
114 {
115         number_t       tot_message;
116         number_t       message_num;
117         number_t       tot_svv;
118         number_t       sv_prn;
119         degree_t          elevation;
120         degree_t      azimut;
121         number_t       snr;
122         number_t       sv_prn2;
123         degree_t          elevation2;
124         degree_t      azimut2;
125         number_t       snr2;
126         number_t       sv_prn3;
127         degree_t          elevation3;
128         degree_t      azimut3;
129         number_t       snr3;
130         number_t       sv_prn4;
131         degree_t          elevation4;
132         degree_t      azimut4;
133         number_t       snr4;
134 } NmeaGsv;
135
136 void nmea_poll(nmeap_context_t *context, KFile *channel);
137
138 int nmea_gpgsv(nmeap_context_t *context, nmeap_sentence_t *sentence);
139 int nmea_gpvtg(nmeap_context_t *context, nmeap_sentence_t *sentence);
140 int nmea_gprmc(nmeap_context_t *context, nmeap_sentence_t *sentence);
141 int nmea_gpgga(nmeap_context_t *context, nmeap_sentence_t *sentence);
142
143 #endif /* NET_NMEA_H */