forked from SlashDevin/NeoGPS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NMEAloc.ino
183 lines (146 loc) · 5.2 KB
/
NMEAloc.ino
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#include <NMEAGPS.h>
//======================================================================
// Program: NMEAloc.ino
//
// Description: This program only parses an RMC sentence for the lat/lon.
//
// Prerequisites:
// 1) NMEA.ino works with your device (correct TX/RX pins and baud rate)
// 2) The RMC sentence has been enabled.
// 3) Your device sends an RMC sentence (e.g., $GPRMC).
//
// 'Serial' is for debug output to the Serial Monitor window.
//
// License:
// Copyright (C) 2014-2017, SlashDevin
//
// This file is part of NeoGPS
//
// NeoGPS 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.
//
// NeoGPS 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 NeoGPS. If not, see <http://www.gnu.org/licenses/>.
//
//======================================================================
#include <GPSport.h>
//------------------------------------------------------------
// Check that the config files are set up properly
#if !defined( NMEAGPS_PARSE_RMC )
#error You must uncomment NMEAGPS_PARSE_RMC in NMEAGPS_cfg.h!
#endif
#if !defined( GPS_FIX_TIME )
#error You must uncomment GPS_FIX_TIME in GPSfix_cfg.h!
#endif
#if !defined( GPS_FIX_LOCATION )
#error You must uncomment GPS_FIX_LOCATION in GPSfix_cfg.h!
#endif
#if !defined( GPS_FIX_SPEED )
#error You must uncomment GPS_FIX_SPEED in GPSfix_cfg.h!
#endif
#if !defined( GPS_FIX_SATELLITES )
#error You must uncomment GPS_FIX_SATELLITES in GPSfix_cfg.h!
#endif
#ifdef NMEAGPS_INTERRUPT_PROCESSING
#error You must *NOT* define NMEAGPS_INTERRUPT_PROCESSING in NMEAGPS_cfg.h!
#endif
//------------------------------------------------------------
static NMEAGPS gps; // This parses the GPS characters
//----------------------------------------------------------------
// Print the 32-bit integer degrees *as if* they were high-precision floats
static void printL( Print & outs, int32_t degE7 );
static void printL( Print & outs, int32_t degE7 )
{
// Extract and print negative sign
if (degE7 < 0) {
degE7 = -degE7;
outs.print( '-' );
}
// Whole degrees
int32_t deg = degE7 / 10000000L;
outs.print( deg );
outs.print( '.' );
// Get fractional degrees
degE7 -= deg*10000000L;
// Print leading zeroes, if needed
int32_t factor = 1000000L;
while ((degE7 < factor) && (factor > 1L)){
outs.print( '0' );
factor /= 10L;
}
// Print fractional degrees
outs.print( degE7 );
}
static void doSomeWork( const gps_fix & fix );
static void doSomeWork( const gps_fix & fix )
{
// This is the best place to do your time-consuming work, right after
// the RMC sentence was received. If you do anything in "loop()",
// you could cause GPS characters to be lost, and you will not
// get a good lat/lon.
// For this example, we just print the lat/lon. If you print too much,
// this routine will not get back to "loop()" in time to process
// the next set of GPS data.
if (fix.valid.location) {
if ( fix.dateTime.seconds < 10 )
DEBUG_PORT.print( '0' );
DEBUG_PORT.print( fix.dateTime.seconds );
DEBUG_PORT.print( ',' );
// DEBUG_PORT.print( fix.latitude(), 6 ); // floating-point display
// DEBUG_PORT.print( fix.latitudeL() ); // integer display
printL( DEBUG_PORT, fix.latitudeL() ); // prints int like a float
DEBUG_PORT.print( ',' );
// DEBUG_PORT.print( fix.longitude(), 6 ); // floating-point display
// DEBUG_PORT.print( fix.longitudeL() ); // integer display
printL( DEBUG_PORT, fix.longitudeL() ); // prints int like a float
DEBUG_PORT.print( ',' );
if (fix.valid.satellites)
DEBUG_PORT.print( fix.satellites );
DEBUG_PORT.print( ',' );
DEBUG_PORT.print( fix.speed(), 6 );
DEBUG_PORT.print( F(" kn = ") );
DEBUG_PORT.print( fix.speed_mph(), 6 );
DEBUG_PORT.print( F(" mph") );
} else {
// No valid location data yet!
DEBUG_PORT.print( '?' );
}
DEBUG_PORT.println();
} // doSomeWork
//------------------------------------
static void GPSloop();
static void GPSloop()
{
while (gps.available( gpsPort ))
doSomeWork( gps.read() );
} // GPSloop
//--------------------------
void setup()
{
DEBUG_PORT.begin(9600);
while (!DEBUG_PORT)
;
DEBUG_PORT.print( F("NMEAloc.INO: started\n") );
DEBUG_PORT.print( F("fix object size = ") );
DEBUG_PORT.println( sizeof(gps.fix()) );
DEBUG_PORT.print( F("NMEAGPS object size = ") );
DEBUG_PORT.println( sizeof(gps) );
DEBUG_PORT.println( F("Looking for GPS device on " GPS_PORT_NAME) );
#ifdef NMEAGPS_NO_MERGING
DEBUG_PORT.println( F("Only displaying data from xxRMC sentences.\n Other sentences may be parsed, but their data will not be displayed.") );
#endif
DEBUG_PORT.flush();
gpsPort.begin(9600);
}
//--------------------------
void loop()
{
GPSloop();
}