forked from ethersex/ethersex
/
nmea.c
100 lines (82 loc) · 2.32 KB
/
nmea.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* Copyright (c) 2009 by Stefan Siegl <stesie@brokenpipe.de>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* For more information on the GPL, please go to:
* http://www.gnu.org/copyleft/gpl.html
*/
#include "nmea.h"
struct nmea_t nmea_data;
#include "config.h"
#define USE_USART NMEA_USE_USART
#define BAUD 4800
#include "core/usart.h"
/* We generate our own usart init module, for our usart port */
generate_usart_init()
void
nmea_init(void)
{
/* Initialize the usart module */
usart_init();
}
ISR(usart(USART,_RX_vect))
{
/* Ignore errors */
if ((usart(UCSR,A) & _BV(usart(DOR))) || (usart(UCSR,A) & _BV(usart(FE))))
{
uint8_t v = usart(UDR);
(void) v;
return;
}
uint8_t data = usart(UDR);
if (data == '$')
{
nmea_data.locked = 1;
nmea_data.ptr = 0;
}
else if (!nmea_data.locked)
return;
else
nmea_data.ptr ++;
if ((nmea_data.ptr == 3 || nmea_data.ptr == 4)
&& data != 'G')
streamerror: {
nmea_data.locked = 0;
return;
}
if (nmea_data.ptr == 5 && data != 'A')
goto streamerror;
if (nmea_data.ptr >= 18 && nmea_data.ptr <= 26)
nmea_data.latitude[nmea_data.ptr - 18] = data;
else if (nmea_data.ptr == 28)
nmea_data.latitude_dir = data;
else if (nmea_data.ptr >= 30 && nmea_data.ptr <= 39)
nmea_data.longitude[nmea_data.ptr - 30] = data;
else if (nmea_data.ptr == 41)
nmea_data.longitude_dir = data;
else if (nmea_data.ptr == 45)
nmea_data.satellites = (data - '0') * 10;
else if (nmea_data.ptr == 46)
{
nmea_data.satellites += (data - '0');
nmea_data.valid = 1;
}
}
/*
-- Ethersex META --
header(protocols/nmea/nmea.h)
init(nmea_init)
*/