PUD: import nmealib v0.6.9
[olsrd.git] / lib / pud / nmealib / samples / parse / main.c
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 #include <nmea/nmea.h>
22
23 #include <stdio.h>
24 #include <string.h>
25
26 int main(int argc __attribute__((unused)), char *argv[] __attribute__((unused))) {
27     const char *buff[] = {
28         "$GPRMC,173843,A,3349.896,N,11808.521,W,000.0,360.0,230108,013.4,E*69\r\n",
29         "$GPGGA,111609.14,5001.27,N,3613.06,E,3,08,0.0,10.2,M,0.0,M,0.0,0000*70\r\n",
30         "$GPGSV,2,1,08,01,05,005,80,02,05,050,80,03,05,095,80,04,05,140,80*7f\r\n",
31         "$GPGSV,2,2,08,05,05,185,80,06,05,230,80,07,05,275,80,08,05,320,80*71\r\n",
32         "$GPGSA,A,3,01,02,03,04,05,06,07,08,00,00,00,00,0.0,0.0,0.0*3a\r\n",
33         "$GPRMC,111609.14,A,5001.27,N,3613.06,E,11.2,0.0,261206,0.0,E*50\r\n",
34         "$GPVTG,217.5,T,208.8,M,000.00,N,000.01,K*4C\r\n"
35     };
36
37     int it;
38     nmeaINFO info;
39     nmeaPARSER parser;
40     nmeaPOS dpos;
41
42     nmea_zero_INFO(&info);
43     nmea_parser_init(&parser);
44
45     for(it = 0; it < 6; ++it)
46     {
47         nmea_parse(&parser, buff[it], (int)strlen(buff[it]), &info);
48
49         nmea_info2pos(&info, &dpos);
50         printf("%03d, Lat: %f, Lon: %f, Sig: %d, Fix: %d\n", it, dpos.lat,
51                dpos.lon, info.sig, info.fix);
52     }
53
54     nmea_parser_destroy(&parser);
55
56     return 0;
57 }