Created
February 18, 2012 21:22
-
-
Save fphillips/1861056 to your computer and use it in GitHub Desktop.
Node.js GPS NMEA parser for LS20031 and Beaglebone
This file contains hidden or 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
// | |
// Node.js GPS NMEA parser for LS20031 and Beaglebone | |
// | |
// Parses GSV/GGA strings and logs to a file. | |
// GPS module outputs lat ddmm.mmmm and lon dddmm.mmmm. | |
// Hardcoded for North-West hemispheres. latPole S and lonPole W are (-) | |
// Author: Frank Phillips <[email protected]> | |
// Uses serialport and nmea modules. Edit the require paths as necessary. | |
var http = require('http'); | |
var serialport = require('/home/root/node_modules/serialport'); | |
var nmea = require('/home/root/node_modules/nmea'); | |
var fs = require('fs'); | |
var port = new serialport.SerialPort('/dev/ttyO1', { | |
baudrate: 115200, | |
parser: serialport.parsers.readline('\r\n')}); | |
var stream = fs.createWriteStream('/tmp/out'); | |
stream.once('open', function(fd) { | |
port.on('data',function(data){ | |
// Not every line of data results in a successful parse | |
if (nmea.parse(data)) { | |
var loc = nmea.parse(data); | |
} else return; | |
// Match first NMEA GSV string | |
if (loc.type === 'satellite-list-partial') { | |
if (loc.msgNum === 1) { | |
stream.write("satsInView: " + loc.satsInView + '\n'); | |
} | |
var ids = ''; | |
for (var i=0; i < loc.satellites.length; i++) { | |
ids += loc.satellites[i].id + ','; | |
} | |
stream.write("Sats:" + ids + '\n'); | |
} | |
// Match NMEA GGA string | |
if (loc.type === 'fix') { | |
stream.write(loc.latPole + loc.lat + " " + loc.lonPole + loc.lon + '\n'); | |
// Convert ddmm.mmmm to degrees decimal | |
var deg = loc.lat.toString().slice(0,2); | |
var min = loc.lat.toString().slice(2)/60; | |
var d = parseFloat(deg) + parseFloat(min); | |
// Convert dddmm.mmmm to degrees decimal | |
var deg = loc.lon.toString().slice(0,3); | |
var min = loc.lon.toString().slice(3)/60; | |
var e = parseFloat(deg) + parseFloat(min); | |
stream.write(d.toFixed(4) + ", -" + e.toFixed(4) + "\n"); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment