-
Notifications
You must be signed in to change notification settings - Fork 0
/
NMEA0183-Demo_Parse.spin2
165 lines (126 loc) · 5.45 KB
/
NMEA0183-Demo_Parse.spin2
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
{
--------------------------------------------
Filename: NMEA0183-Demo_Parse.spin2
Author: Jesse Burt
Description: Simple demo that uses the NMEA0183 object
to parse sentences read from a compatible serial-connected
GPS module and displays the data on the terminal. (P2 version)
Copyright (c) 2022
Started Jul 7, 2022
Updated Nov 13, 2022
See end of file for terms of use.
--------------------------------------------
}
#include "core.con.click.spin2"
CON
_clkfreq = cfg._clkfreq_def
_xtlfreq = cfg._xtlfreq
' -- User-modifiable constants
LED = cfg.LED1
SER_BAUD = 2_000_000
CLICK_BASE = 16
{ uncomment these two lines, and comment out the #include above, to use custom I/O pins }
' GPS_TXD = 1
' GPS_RXD = 2
GPS_BAUD = 9600
' --
OBJ
cfg : "boardcfg.p2eval"
ser : "com.serial.terminal.ansi"
gps : "com.serial.terminal"
nmea : "protocol.navigation.nmea0183"
VAR
byte _sentence[nmea.SENTNC_MAX_LEN]
PUB main() | allowed
setup()
nmea.ptr_sentence(@_sentence) ' tell NMEA0183 object where the sentence data is
{ sentence type to display:
SNTID_VTG, SNTID_GGA, SNTID_GSA, SNTID_RMC, SNTID_GSV }
allowed := nmea.SNTID_RMC
repeat
' clear out sentence buffer
bytefill(@_sentence, 0, nmea.SENTNC_MAX_LEN)
repeat until (gps.getchar() == nmea.SENTSTART)
gps.gets(@_sentence) ' read sentence data (ASCII)
if (nmea.sentence_id() == allowed)
ser.pos_xy(0, 3)
' show the raw sentence
ser.printf(@"Sentence: %s", @_sentence)
ser.clear_line()
ser.newline()
case nmea.sentence_id() ' now extract and print data
nmea.SNTID_VTG: ' pertinent to each sentence
display_vtg()
nmea.SNTID_GGA:
display_gga()
nmea.SNTID_GSA:
display_gsa()
nmea.SNTID_RMC:
display_rmc()
nmea.SNTID_GSV:
display_gsv()
else
next
PUB display_gga()
disp_pos()
ser.printf(@"Time: %d\n\r", nmea.time_of_day())
PUB display_gsa() | fix_stat
case nmea.fix()
1:
fix_stat := @"No fix"
2:
fix_stat := @"2D fix"
3:
fix_stat := @"3D fix"
ser.printf(@"Position fix: %s\n\r", fix_stat)
ser.printf(@"HDOP: %d \n\r", nmea.hdop())
ser.printf(@"PDOP: %d \n\r", nmea.pdop())
ser.printf(@"VDOP: %d \n\r", nmea.vdop())
PUB display_gsv()
PUB display_rmc()
disp_pos()
ser.printf(@"Date: %02.2d/%02.2d/%02.2d\n\r", nmea.month(), nmea.date(), nmea.year())
ser.printf(@"Time: %02.2d:%02.2d:%02.2d\n\r", nmea.hours(), nmea.minutes(), {
} nmea.seconds())
ser.printf(@"Course (true): %03.3d.%02.2d\n\r", (nmea.course_true() / 100), {
} (nmea.course_true() // 100))
ser.printf(@"Speed: %d.%02.2dkts\n\r", (nmea.speed_kts() / 100), {
} (nmea.speed_kts // 100))
PUB display_vtg()
ser.printf(@"Course (true): %d \n\r", nmea.course_true())
ser.printf(@"Course (magnetic): %d \n\r", nmea.course_magnetic())
ser.printf(@"Speed: %dkts \n\r", nmea.speed_kts())
ser.printf(@"Speed: %dkm/h \n\r", nmea.speed_kmh())
PRI disp_pos()
' Display position
ser.printf(@"Latitude: %02.2ddeg %02.2d.%04.4dmin %c\n\r", nmea.lat_deg(), {
} nmea.lat_minutes_whole(), {
} nmea.lat_minutes_part(), {
} nmea.north_south())
ser.printf(@"Longitude: %02.2ddeg %02.2d.%04.4dmin %c\n\r", nmea.long_deg(), {
} nmea.long_minutes_whole(),{
} nmea.long_minutes_part(), {
} nmea.east_west())
PUB setup()
ser.start(SER_BAUD)
waitms(30)
ser.clear()
ser.strln(@"Serial terminal started")
gps.startrxtx(GPS_TXD, GPS_RXD, %0000, GPS_BAUD)
ser.strln(@"GPS serial started")
DAT
{
Copyright 2022 Jesse Burt
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute,
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or
substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT
OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
}