User | Revision | Line number | New contents of line |
slisgrinder |
0:01c9f535e512
|
1
|
#include "GPSParser.h"
|
slisgrinder |
0:01c9f535e512
|
2
|
|
slisgrinder |
0:01c9f535e512
|
3
|
|
slisgrinder |
0:01c9f535e512
|
4
|
const int GLL = 0, RMC = 0, VTG = 1, GGA = 1, GSA = 0, GSV = 0, GRS = 0, GST = 0, MALM = 0, MEPH = 0, MDGP = 0, MDBG = 0, ZDA = 0, MCHN = 0; //refer to http://aprs.gids.nl/nmea/#gll for NMEA 0183 sentences
|
slisgrinder |
0:01c9f535e512
|
5
|
volatile bool buffer_ready = false;
|
slisgrinder |
0:01c9f535e512
|
6
|
volatile int num_sentences = 0;
|
slisgrinder |
0:01c9f535e512
|
7
|
volatile int ctr = 0;
|
slisgrinder |
0:01c9f535e512
|
8
|
typedef struct
|
slisgrinder |
0:01c9f535e512
|
9
|
{
|
slisgrinder |
0:01c9f535e512
|
10
|
float latitude, lat_deg, lat_min, deg_latitude, longitude, long_deg, long_min, deg_longitude, altitude, HDOP, geoidal_sep, AODC, heading, mag_heading, speed_knots, speed_kph;
|
slisgrinder |
0:01c9f535e512
|
11
|
char ns, ew, mode;
|
slisgrinder |
0:01c9f535e512
|
12
|
int hours, minutes, seconds, m_seconds, fix, sats_used, DGPS_ID;
|
slisgrinder |
0:01c9f535e512
|
13
|
unsigned short checksum_gga, checksum_vtg;
|
slisgrinder |
0:01c9f535e512
|
14
|
} GPS;
|
slisgrinder |
0:01c9f535e512
|
15
|
|
slisgrinder |
0:01c9f535e512
|
16
|
GPS _gps;
|
slisgrinder |
0:01c9f535e512
|
17
|
|
slisgrinder |
0:01c9f535e512
|
18
|
void gps_init (int num_sentence, MODSERIAL &gps)
|
slisgrinder |
0:01c9f535e512
|
19
|
{
|
slisgrinder |
0:01c9f535e512
|
20
|
num_sentences = num_sentence;
|
slisgrinder |
0:01c9f535e512
|
21
|
// BEGIN CONFIGURATION OF GPS use http://www.hhhh.org/wiml/proj/nmeaxor.html for checksum calculations...
|
slisgrinder |
0:01c9f535e512
|
22
|
gps.printf ("$PMTK313,1*2E\r\n"); //enable SBAS satellite searching
|
slisgrinder |
0:01c9f535e512
|
23
|
gps.printf ("$PMTK301,2*2E\r\n"); //set DGPS mode to WAAS
|
slisgrinder |
0:01c9f535e512
|
24
|
gps.printf ("$PMTK314,%d,%d,%d,%d,%d,%d,%d,%d,0,0,0,0,0,%d,%d,%d,%d,%d,%d*28\r\n", GLL, RMC, VTG, GGA, GSA, GSV, GRS, GST, MALM, MEPH, MDGP, MDBG, ZDA, MCHN); //enable NMEA output sentences and frequencies
|
slisgrinder |
0:01c9f535e512
|
25
|
// END CONFIGURATION OF GPS
|
slisgrinder |
0:01c9f535e512
|
26
|
wait (0.1);
|
slisgrinder |
0:01c9f535e512
|
27
|
gps.rxBufferFlush ();
|
slisgrinder |
0:01c9f535e512
|
28
|
gps.attach (&ready_buffer, MODSERIAL::RxIrq);
|
slisgrinder |
0:01c9f535e512
|
29
|
}
|
slisgrinder |
0:01c9f535e512
|
30
|
|
slisgrinder |
0:01c9f535e512
|
31
|
void ready_buffer (MODSERIAL_IRQ_INFO *q)
|
slisgrinder |
0:01c9f535e512
|
32
|
{
|
slisgrinder |
0:01c9f535e512
|
33
|
MODSERIAL *serial = q->serial;
|
slisgrinder |
0:01c9f535e512
|
34
|
|
slisgrinder |
0:01c9f535e512
|
35
|
if (serial->rxGetLastChar() == '\n')
|
slisgrinder |
0:01c9f535e512
|
36
|
ctr++;
|
slisgrinder |
0:01c9f535e512
|
37
|
|
slisgrinder |
0:01c9f535e512
|
38
|
if (ctr == num_sentences)
|
slisgrinder |
0:01c9f535e512
|
39
|
{
|
slisgrinder |
0:01c9f535e512
|
40
|
buffer_ready = true;
|
slisgrinder |
0:01c9f535e512
|
41
|
ctr = 0;
|
slisgrinder |
0:01c9f535e512
|
42
|
}
|
slisgrinder |
0:01c9f535e512
|
43
|
}
|
slisgrinder |
0:01c9f535e512
|
44
|
|
slisgrinder |
0:01c9f535e512
|
45
|
void read_gps (MODSERIAL &gps, MODSERIAL &pc)
|
slisgrinder |
0:01c9f535e512
|
46
|
{
|
slisgrinder |
0:01c9f535e512
|
47
|
char buff [num_sentences][128];
|
slisgrinder |
0:01c9f535e512
|
48
|
gps.attach (&ready_buffer, MODSERIAL::RxIrq);
|
slisgrinder |
0:01c9f535e512
|
49
|
|
slisgrinder |
0:01c9f535e512
|
50
|
//while (!buffer_ready);
|
slisgrinder |
0:01c9f535e512
|
51
|
|
slisgrinder |
0:01c9f535e512
|
52
|
for (int i = 0; i < num_sentences; i++)
|
slisgrinder |
0:01c9f535e512
|
53
|
{
|
slisgrinder |
0:01c9f535e512
|
54
|
for (int k = 0; k < 128; k++)
|
slisgrinder |
0:01c9f535e512
|
55
|
{
|
slisgrinder |
0:01c9f535e512
|
56
|
buff [i][k] = gps.getc();
|
slisgrinder |
0:01c9f535e512
|
57
|
if (buff [i][k] == ',' && buff [i][k - 1] == ',') // if the current and last character read were both ',' then assign the next buff position ',' and the current buff position a '0' and increment k by one.
|
slisgrinder |
0:01c9f535e512
|
58
|
{
|
slisgrinder |
0:01c9f535e512
|
59
|
buff [i][k + 1] = buff [i][k];
|
slisgrinder |
0:01c9f535e512
|
60
|
buff [i][k] = '0';
|
slisgrinder |
0:01c9f535e512
|
61
|
k++;
|
slisgrinder |
0:01c9f535e512
|
62
|
}
|
slisgrinder |
0:01c9f535e512
|
63
|
if (buff [i][k] == '*' && buff [i][k - 1] == ',') // if the current character is '*' and last character read were both ',' then assign the next buff position '*' and the current buff position a '0' and increment k by one.
|
slisgrinder |
0:01c9f535e512
|
64
|
{
|
slisgrinder |
0:01c9f535e512
|
65
|
buff [i][k + 1] = buff [i][k];
|
slisgrinder |
0:01c9f535e512
|
66
|
buff [i][k] = '0';
|
slisgrinder |
0:01c9f535e512
|
67
|
k++;
|
slisgrinder |
0:01c9f535e512
|
68
|
}
|
slisgrinder |
0:01c9f535e512
|
69
|
//pc.putc (buff [i][k]);
|
slisgrinder |
0:01c9f535e512
|
70
|
if (buff [i][k] == '\n')
|
slisgrinder |
0:01c9f535e512
|
71
|
{
|
slisgrinder |
0:01c9f535e512
|
72
|
k++;
|
slisgrinder |
0:01c9f535e512
|
73
|
buff [i][k] = '\0';
|
slisgrinder |
0:01c9f535e512
|
74
|
break;
|
slisgrinder |
0:01c9f535e512
|
75
|
}
|
slisgrinder |
0:01c9f535e512
|
76
|
}
|
slisgrinder |
0:01c9f535e512
|
77
|
}
|
slisgrinder |
0:01c9f535e512
|
78
|
|
slisgrinder |
0:01c9f535e512
|
79
|
for (int i = 0; i < num_sentences; i++)
|
slisgrinder |
0:01c9f535e512
|
80
|
{
|
slisgrinder |
0:01c9f535e512
|
81
|
if (!sscanf (buff [i], "$GPGGA,%2d%2d%2d.%3d,%f,%c,%f,%c,%d,%d,%f,%f,M,%f,M,%f,%X*%hX\r\n", &_gps.hours, &_gps.minutes, &_gps.seconds, &_gps.m_seconds, &_gps.latitude, &_gps.ns, &_gps.longitude, &_gps.ew, &_gps.fix, &_gps.sats_used, &_gps.HDOP, &_gps.altitude, &_gps.geoidal_sep, &_gps.AODC, &_gps.DGPS_ID, &_gps.checksum_gga))
|
slisgrinder |
0:01c9f535e512
|
82
|
sscanf (buff [i + 1], "$GPGGA,%2d%2d%2d.%3d,%f,%c,%f,%c,%d,%d,%f,%f,M,%f,M,%f,%X*%hX\r\n", &_gps.hours, &_gps.minutes, &_gps.seconds, &_gps.m_seconds, &_gps.latitude, &_gps.ns, &_gps.longitude, &_gps.ew, &_gps.fix, &_gps.sats_used, &_gps.HDOP, &_gps.altitude, &_gps.geoidal_sep, &_gps.AODC, &_gps.DGPS_ID, &_gps.checksum_gga);
|
slisgrinder |
0:01c9f535e512
|
83
|
|
slisgrinder |
0:01c9f535e512
|
84
|
if(!sscanf (buff [i], "$GPVTG,%f,T,%f,M,%f,N,%f,K,%c*%hX\r\n", &_gps.heading, &_gps.mag_heading, &_gps.speed_knots, &_gps.speed_kph, &_gps.mode, &_gps.checksum_vtg))
|
slisgrinder |
0:01c9f535e512
|
85
|
sscanf (buff [i + 1], "$GPVTG,%f,T,%f,M,%f,N,%f,K,%c*%hX\r\n", &_gps.heading, &_gps.mag_heading, &_gps.speed_knots, &_gps.speed_kph, &_gps.mode, &_gps.checksum_vtg);
|
slisgrinder |
0:01c9f535e512
|
86
|
|
slisgrinder |
0:01c9f535e512
|
87
|
pc.printf ("%s", buff [i]);
|
slisgrinder |
0:01c9f535e512
|
88
|
}
|
slisgrinder |
0:01c9f535e512
|
89
|
if (_gps.ns == 'S')
|
slisgrinder |
0:01c9f535e512
|
90
|
_gps.latitude *= -1.0f;
|
slisgrinder |
0:01c9f535e512
|
91
|
|
slisgrinder |
0:01c9f535e512
|
92
|
if (_gps.ew == 'W')
|
slisgrinder |
0:01c9f535e512
|
93
|
_gps.longitude *= -1.0f;
|
slisgrinder |
0:01c9f535e512
|
94
|
|
slisgrinder |
0:01c9f535e512
|
95
|
_gps.lat_deg = (int)(_gps.latitude / 100);
|
slisgrinder |
0:01c9f535e512
|
96
|
_gps.lat_min = _gps.latitude - (_gps.lat_deg * 100.0f);
|
slisgrinder |
0:01c9f535e512
|
97
|
_gps.deg_latitude = _gps.lat_deg + _gps.lat_min / 60.0f;
|
slisgrinder |
0:01c9f535e512
|
98
|
_gps.long_deg = (int)(_gps.longitude /100);
|
slisgrinder |
0:01c9f535e512
|
99
|
_gps.long_min = _gps.longitude - (_gps.long_deg * 100.0f);
|
slisgrinder |
0:01c9f535e512
|
100
|
_gps.deg_longitude = _gps.long_deg + _gps.long_min / 60.0f;
|
slisgrinder |
0:01c9f535e512
|
101
|
|
slisgrinder |
0:01c9f535e512
|
102
|
//pc.txBufferFlush();
|
slisgrinder |
0:01c9f535e512
|
103
|
//pc.printf ("%X,%X,[HH:MM:SS:SSS %02d:%02d:%02d:%03d],%f,%f,%f,%c\r\n", _gps.checksum_gga, _gps.checksum_vtg, _gps.hours, _gps.minutes, _gps.seconds, _gps.m_seconds, _gps.deg_latitude, _gps.deg_longitude, _gps.heading, _gps.mode);
|
slisgrinder |
0:01c9f535e512
|
104
|
|
slisgrinder |
0:01c9f535e512
|
105
|
//gps.txBufferFlush ();
|
slisgrinder |
0:01c9f535e512
|
106
|
gps.rxBufferFlush ();
|
slisgrinder |
0:01c9f535e512
|
107
|
buffer_ready = false;
|
slisgrinder |
0:01c9f535e512
|
108
|
} |