Skip to content

Commit

Permalink
added an example and small update to main file
Browse files Browse the repository at this point in the history
  • Loading branch information
dmh2000 committed Apr 25, 2012
1 parent fe8a72b commit a95a0c9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
25 changes: 25 additions & 0 deletions examples/tty.js
@@ -0,0 +1,25 @@
var serial = require('serialport') // voodootikigod / node-serialport : npm -g install serialport
,nmea = require('nmea');

// don't print errors
nmea.setErrorHandler(function(s) {});

// open the serial port at the required baud rate and use the line parser
// note that NMEA output uses \r\n instead of just \n as a line delimiter
var sp = new serial.SerialPort("/dev/ttyS0",
{
baudrate:4800,
parser: serial.parsers.readline("\r\n")
});

// wait for data
sp.on('data',function(line) {
// parse the nmea sentence
var s = nmea.parse(line);
if (s != null) {
// if it was parseable, print the raw line and the decoded object data
console.log(line);
console.log(s);
}
});

8 changes: 4 additions & 4 deletions lib/nmea001.js
Expand Up @@ -351,7 +351,7 @@ var NMEA = ( function() {
};

// decode longitude
// first two digits are degress
// first three digits are degress
// rest of digits are decimal minutes
nmea.parseLongitude = function(lon,hemi) {
var h;
Expand All @@ -362,12 +362,12 @@ var NMEA = ( function() {
h = (hemi === 'E')?1.0:-1.0;
a = lon.split('.');
if (a[0].length === 5) {
// two digits of degrees
// three digits of degrees
dg = lon.substring(0,3);
mn = lon.substring(3);
}
else if (a[0].length === 4) {
// 1 digit of degrees (in case no leading zero)
// 2 digits of degrees (in case no leading zero)
dg = lon.substring(0,2);
mn = lon.substring(2);
}
Expand Down Expand Up @@ -399,7 +399,7 @@ var NMEA = ( function() {
var s = parseInt(time.slice(4,6),10);
var D = parseInt(date.slice(0,2),10);
var M = parseInt(date.slice(2,4),10);
var Y = parseInt(date.slice(4,6),10) + 1900;
var Y = parseInt(date.slice(4,6),10) + 2000;

return new Date(Date.UTC(Y,M,D,h,m,s));
};
Expand Down

0 comments on commit a95a0c9

Please sign in to comment.