Last active
February 2, 2016 19:48
-
-
Save ssube/c06ff9d6c50db11fac31 to your computer and use it in GitHub Desktop.
NMEA parser from http://www.gpsinformation.org/dale/nmea.htm#GSV via http://pegjs.org/online
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$GPGGA,123519,4807.038,N,01131.000,E,1,08,0.9,545.4,M,46.9,M,,*47 | |
$GPGSA,A,3,04,05,,09,12,,,24,,,,,2.5,1.3,2.1*39 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data = records:(nmea:nmea '\n' { return nmea; })+ | |
nmea | |
= GP_START data:gga { return data; } | |
/ GP_START data:gsa { return data; } | |
gga | |
= GGA_START SEP time:time pos:pos fix:int SEP count:int SEP hdil:dec SEP alt:dist geoid:dist SEP checksum { | |
return {type: 'gga', time: time, pos: pos, fix: fix, count: count, hdil: hdil, alt: alt, geoid: geoid}; | |
} | |
gsa | |
= GSA_START SEP auto:auto fix:int SEP sat:twelve_sat pdop:dec SEP hdop:dec SEP vdop:dec checksum { | |
return {type: 'gsa', auto: auto, fix: fix, sat: sat, pdop: pdop, hdop: hdop, vdop: vdop}; | |
} | |
time | |
= hour:hour minute:minute second:second SEP { return {hour: hour, min: minute, sec: second}; } | |
hour | |
= h:$('0' [1-9]) { return parseInt(h, 10); } | |
/ h:$('1' [0-2]) { return parseInt(h, 10); } | |
minute | |
= m:$([0-5][0-9]) { return parseInt(m, 10); } | |
second | |
= s:$([0-5][0-9]) { return parseInt(s, 10); } | |
pos | |
= lat:lat SEP long:long SEP { return {lat: lat, long: long}; } | |
lat | |
= deg:dec SEP 'N' { return {angle: deg, dir: 'n'}; } | |
/ deg:dec SEP 'S' { return {angle: deg, dir: 's'}; } | |
long | |
= deg:dec SEP 'E' { return {angle: deg, dir: 'e'}; } | |
/ deg:dec SEP 'W' { return {angle: deg, dir: 'w'}; } | |
int | |
= i:[0-9]+ { return parseInt(i, 10); } | |
dec | |
= d:$(w:[0-9]* '.' d:[0-9]+) { return parseFloat(d, 10); } | |
dist | |
= dist:dec SEP 'M' SEP { return {dist: dist, unit: 'm'}; } | |
twelve_sat | |
= sat sat sat sat sat sat sat sat sat sat sat sat | |
sat | |
= id:int? SEP { return id; } | |
checksum | |
= '*' cs:int { return cs; } | |
auto | |
= 'M' SEP { return false; } | |
/ 'A' SEP { return true; } | |
GP_START = '$GP' | |
GGA_START = 'GGA' | |
GSA_START = 'GSA' | |
SEP = ',' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[ | |
{ | |
"type": "gga", | |
"time": { | |
"hour": 12, | |
"min": 35, | |
"sec": 19 | |
}, | |
"pos": { | |
"lat": { | |
"angle": 4807.038, | |
"dir": "n" | |
}, | |
"long": { | |
"angle": 1131, | |
"dir": "e" | |
} | |
}, | |
"fix": 1, | |
"count": 0, | |
"hdil": 0.9, | |
"alt": { | |
"dist": 545.4, | |
"unit": "m" | |
}, | |
"geoid": { | |
"dist": 46.9, | |
"unit": "m" | |
} | |
}, | |
{ | |
"type": "gsa", | |
"auto": true, | |
"fix": 3, | |
"sat": [ | |
0, | |
0, | |
null, | |
0, | |
1, | |
null, | |
null, | |
2, | |
null, | |
null, | |
null, | |
null | |
], | |
"pdop": 2.5, | |
"hdop": 1.3, | |
"vdop": 2.1 | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment