Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gps

Package Overview
Dependencies
Maintainers
2
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gps - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

res/dashboard.png

4

bower.json
{
"name": "gps",
"main": "gps.js",
"version": "0.0.6",
"version": "0.0.7",
"homepage": "https://github.com/infusion/GPS.js",
"description": "A GPS NMEA parser library",
"keywords": [
"nmea", "gps", "serial", "parser", "geo", "location", "rmc", "gga", "gll", "gsa", "vtg", "gva"
"nmea", "nmea", "gps", "serial", "parser", "distance", "geo", "location", "rmc", "gga", "gll", "gsa", "vtg", "gva"
],

@@ -10,0 +10,0 @@ "authors": [

@@ -8,3 +8,4 @@

// var file = '/dev/ttyUSB0';
var file = '/dev/tty.usbserial';
//var file = '/dev/tty.usbserial';
var file = '/dev/tty.usbmodem1411';

@@ -11,0 +12,0 @@ var SerialPort = require('serialport');

// var file = '/dev/cu.usbserial';
// var file = '/dev/ttyUSB0';
var file = '/dev/tty.usbserial';
//var file = '/dev/tty.usbserial';
var file = '/dev/tty.usbmodem1411';

@@ -23,4 +24,4 @@ var SerialPort = require('serialport');

gps.on('data', function(raw, data) {
ws.write(raw + '\n');
gps.on('data', function(data) {
ws.write(data.raw + '\n');
});

@@ -27,0 +28,0 @@

@@ -6,4 +6,9 @@

// var file = '/dev/cu.usbserial';
// var file = '/dev/ttyUSB0';
//var file = '/dev/tty.usbserial';
var file = '/dev/tty.usbmodem1411';
var SerialPort = require('serialport');
var serialPort = new SerialPort.SerialPort('/dev/tty.usbserial', {
var serialPort = new SerialPort.SerialPort(file, {
baudrate: 4800,

@@ -10,0 +15,0 @@ parser: SerialPort.parsers.readline('\r\n')

// var file = '/dev/cu.usbserial';
// var file = '/dev/ttyUSB0';
var file = '/dev/tty.usbserial';
//var file = '/dev/tty.usbserial';
var file = '/dev/tty.usbmodem1411';

@@ -19,3 +20,3 @@ var SerialPort = require('serialport');

gps.on('data', function(raw, data) {
gps.on('data', function(data) {
console.log(data);

@@ -22,0 +23,0 @@ });

@@ -8,3 +8,3 @@

gps.on('data', function(raw, parsed) {
gps.on('data', function(parsed) {

@@ -11,0 +11,0 @@ console.log(parsed);

@@ -5,3 +5,4 @@

// var file = '/dev/ttyUSB0';
var file = '/dev/tty.usbserial';
//var file = '/dev/tty.usbserial';
var file = '/dev/tty.usbmodem1411';

@@ -21,3 +22,3 @@ var SerialPort = require('serialport');

gps.on('data', function(raw, data) {
gps.on('data', function(data) {
console.log(gps.state);

@@ -24,0 +25,0 @@ });

/**
* GPS.js v0.0.6 26/01/2016
* GPS.js v0.0.7 26/01/2016
*

@@ -20,3 +20,3 @@ * Copyright (c) 2016, Robert Eisele (robert@xarg.org)

}
if (data['type'] === 'ZDA') {

@@ -62,15 +62,19 @@ state['time'] = data['time'];

if (time === '') {
return null;
}
var ret = new Date;
if (date) {
// If we need to parse older data, we should hack something like
// year < 80 ? 2000+year : 1900+year
var year = date.slice(4);
var month = date.slice(2, 4) - 1;
var day = date.slice(0, 2);
if (year.length === 4) {
ret.setUTCFullYear(year, month, day);
} else {
// If we need to parse older GPRMC data, we should hack something like
// year < 73 ? 2000+year : 1900+year
ret.setUTCFullYear('20' + year, month, day);

@@ -89,2 +93,4 @@ }

function parseCoord(coord, dir) {
// Latitude can go from 0 to 90; longitude can go from 0 to 180.

@@ -110,2 +116,11 @@ if (coord === '')

}
/*
* Mathematically, but more expensive and not numerical stable:
*
* raw = 4807.038
* deg = Math.floor(raw / 100)
*
* dec = (raw - (100 * deg)) / 60
* res = deg + dec // 48.1173
*/
return sgn * (parseFloat(coord.slice(0, n)) + parseFloat(coord.slice(n)) / 60);

@@ -142,3 +157,3 @@ }

}
function parseGGAFix(fix) {

@@ -151,9 +166,15 @@

case '1':
return 'fix';
return 'fix'; // valid SPS fix
case '2':
return 'diff';
return 'dgps-fix'; // valid DGPS fix
case '3':
return 'pps-fix'; // valid PPS fix
case '6':
return 'estimated';
case '7':
return 'manual';
case '8':
return 'simulated';
}
throw 'INVALID GGA FIX: ' + fix;
throw 'INVALID GGA FIX: ' + fix;
}

@@ -251,271 +272,265 @@

GPS['mod'] = {
// Global Positioning System Fix Data
'GGA': function(str, gga) {
'GGA': function(str, gga) {
if (gga.length !== 16) {
throw 'Invalid GGA length: ' + str;
}
if (gga.length !== 16) {
throw 'Invalid GGA length: ' + str;
}
/*
11
1 2 3 4 5 6 7 8 9 10 | 12 13 14 15
| | | | | | | | | | | | | | |
$--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh
1) Time (UTC)
2) Latitude
3) N or S (North or South)
4) Longitude
5) E or W (East or West)
6) GPS Quality Indicator,
0 = Invalid, 1 = Valid SPS, 2 = Valid DGPS, 3 = Valid PPS
7) Number of satellites in view, 00 - 12
8) Horizontal Dilution of precision, lower is better
9) Antenna Altitude above/below mean-sea-level (geoid)
10) Units of antenna altitude, meters
11) Geoidal separation, the difference between the WGS-84 earth
ellipsoid and mean-sea-level (geoid), '-' means mean-sea-level below ellipsoid
12) Units of geoidal separation, meters
13) Age of differential GPS data, time in seconds since last SC104
type 1 or 9 update, null field when DGPS is not used
14) Differential reference station ID, 0000-1023
15) Checksum
*/
/*
11
1 2 3 4 5 6 7 8 9 10 | 12 13 14 15
| | | | | | | | | | | | | | |
$--GGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx*hh
return {
'time': parseTime(gga[1]),
'lat': parseCoord(gga[2], gga[3]),
'lon': parseCoord(gga[4], gga[5]),
'alt': parseDist(gga[9], gga[10]),
'quality': parseGGAFix(gga[6]),
'satelites': parseNumber(gga[7]),
'hdop': parseNumber(gga[8]), // dilution
'geoidal': parseDist(gga[11], gga[12]), // aboveGeoid
'age': parseNumber(gga[13]), // dgpsUpdate???
'stationID': parseNumber(gga[14]) // dgpsReference??
};
},
// GPS DOP and active satellites
'GSA': function(str, gsa) {
1) Time (UTC)
2) Latitude
3) N or S (North or South)
4) Longitude
5) E or W (East or West)
6) GPS Quality Indicator,
0 - fix not available,
1 - GPS fix,
2 - Differential GPS fix
7) Number of satellites in view, 00 - 12
8) Horizontal Dilution of precision
9) Antenna Altitude above/below mean-sea-level (geoid)
10) Units of antenna altitude, meters
11) Geoidal separation, the difference between the WGS-84 earth
ellipsoid and mean-sea-level (geoid), '-' means mean-sea-level below ellipsoid
12) Units of geoidal separation, meters
13) Age of differential GPS data, time in seconds since last SC104
type 1 or 9 update, null field when DGPS is not used
14) Differential reference station ID, 0000-1023
15) Checksum
*/
if (gsa.length !== 19) {
throw 'Invalid GSA length: ' + str;
}
return {
'time': parseTime(gga[1]),
'lat': parseCoord(gga[2], gga[3]),
'lon': parseCoord(gga[4], gga[5]),
'alt': parseDist(gga[9], gga[10]),
'quality': parseGGAFix(gga[6]),
'satelites': parseNumber(gga[7]),
'hdop': parseNumber(gga[8]), // dilution
'geoidal': parseDist(gga[11], gga[12]), // aboveGeoid
'age': parseNumber(gga[13]), // dgpsUpdate???
'stationID': parseNumber(gga[14]) // dgpsReference??
};
},
/*
eg1. $GPGSA,A,3,,,,,,16,18,,22,24,,,3.6,2.1,2.2*3C
eg2. $GPGSA,A,3,19,28,14,18,27,22,31,39,,,,,1.7,1.0,1.3*35
1 = Mode:
M=Manual, forced to operate in 2D or 3D
A=Automatic, 3D/2D
2 = Mode:
1=Fix not available
2=2D
3=3D
3-14 = PRNs of Satellite Vehicles (SVs) used in position fix (null for unused fields)
15 = PDOP
16 = HDOP
17 = VDOP
18 = Checksum
*/
// Active satellites
'GSA': function(str, gsa) {
var sats = [];
for (var i = 3; i < 12 + 3; i++) {
if (gsa.length !== 19) {
throw 'Invalid GSA length: ' + str;
}
if (gsa[i] !== '') {
sats.push(parseInt(gsa[i], 10));
}
}
/*
eg1. $GPGSA,A,3,,,,,,16,18,,22,24,,,3.6,2.1,2.2*3C
eg2. $GPGSA,A,3,19,28,14,18,27,22,31,39,,,,,1.7,1.0,1.3*35
return {
'mode': parseGSAMode(gsa[1]),
'fix': parseGSAFix(gsa[2]),
'satellites': sats,
'pdop': parseNumber(gsa[15]),
'hdop': parseNumber(gsa[16]),
'vdop': parseNumber(gsa[17])
};
},
// Recommended Minimum data for gps
'RMC': function(str, rmc) {
if (rmc.length !== 13 && rmc.length !== 14) {
throw 'Invalid RMC length: ' + str;
}
1 = Mode:
M=Manual, forced to operate in 2D or 3D
A=Automatic, 3D/2D
2 = Mode:
1=Fix not available
2=2D
3=3D
3-14 = PRNs of Satellite Vehicles (SVs) used in position fix (null for unused fields)
15 = PDOP
16 = HDOP
17 = VDOP
18 = Checksum
*/
/*
$GPRMC,hhmmss.ss,A,llll.ll,a,yyyyy.yy,a,x.x,x.x,ddmmyy,x.x,a*hh
RMC = Recommended Minimum Specific GPS/TRANSIT Data
1 = UTC of position fix
2 = Data status (A-ok, V-invalid)
3 = Latitude of fix
4 = N or S
5 = Longitude of fix
6 = E or W
7 = Speed over ground in knots
8 = Track made good in degrees True
9 = UT date
10 = Magnetic variation degrees (Easterly var. subtracts from true course)
11 = E or W
(12) = NMEA 2.3 introduced FAA mode indicator (A=Autonomous, D=Differential, E=Estimated, N=Data not valid)
12 = Checksum
*/
var sats = [];
for (var i = 3; i < 12 + 3; i++) {
return {
'time': parseTime(rmc[1], rmc[9]),
'status': parseRMC_GLLStatus(rmc[2]),
'lat': parseCoord(rmc[3], rmc[4]),
'lon': parseCoord(rmc[5], rmc[6]),
'speed': parseKnots(rmc[7]),
'track': parseNumber(rmc[8]),
'variation': parseRMCVariation(rmc[10], rmc[11]),
'faa': rmc.length === 14 ? parseFAA(rmc[12]) : null
};
},
// Track info
'VTG': function(str, vtg) {
if (gsa[i] !== '') {
sats.push(parseInt(gsa[i], 10));
if (vtg.length !== 10 && vtg.length !== 11) {
throw 'Invalid VTG length: ' + str;
}
}
return {
'mode': parseGSAMode(gsa[1]),
'fix': parseGSAFix(gsa[2]),
'satellites': sats,
'pdop': parseNumber(gsa[15]),
'hdop': parseNumber(gsa[16]),
'vdop': parseNumber(gsa[17])
};
},
/*
------------------------------------------------------------------------------
1 2 3 4 5 6 7 8 9 10
| | | | | | | | | |
$--VTG,x.x,T,x.x,M,x.x,N,x.x,K,m,*hh<CR><LF>
------------------------------------------------------------------------------
1 = Track degrees
2 = Fixed text 'T' indicates that track made good is relative to true north
3 = not used
4 = not used
5 = Speed over ground in knots
6 = Fixed text 'N' indicates that speed over ground in in knots
7 = Speed over ground in kilometers/hour
8 = Fixed text 'K' indicates that speed over ground is in kilometers/hour
(9) = FAA mode indicator (NMEA 2.3 and later)
9/10 = Checksum
*/
// Recommended Minimum data for gps
'RMC': function(str, rmc) {
if (vtg[2] !== 'T') {
throw 'Invalid VTG track mode: ' + str;
}
if (rmc.length !== 13 && rmc.length !== 14) {
throw 'Invalid RMC length: ' + str;
}
if (vtg[8] !== 'K' || vtg[6] !== 'N') {
throw 'Invalid VTG speed tag: ' + str;
}
/*
$GPRMC,hhmmss.ss,A,llll.ll,a,yyyyy.yy,a,x.x,x.x,ddmmyy,x.x,a*hh
return {
'track': parseNumber(vtg[1]),
'speed': parseKnots(vtg[5]),
'faa': vtg.length === 11 ? parseFAA(vtg[9]) : null
};
},
// satelites in view
'GSV': function(str, gsv) {
RMC = Recommended Minimum Specific GPS/TRANSIT Data
1 = UTC of position fix
2 = Data status (A-ok, V-invalid)
3 = Latitude of fix
4 = N or S
5 = Longitude of fix
6 = E or W
7 = Speed over ground in knots
8 = Track made good in degrees True
9 = UT date
10 = Magnetic variation degrees (Easterly var. subtracts from true course)
11 = E or W
(12) = NMEA 2.3 introduced FAA mode indicator (A=Autonomous, D=Differential, E=Estimated, N=Data not valid)
12 = Checksum
*/
if (gsv.length < 9 || gsv.length % 4 !== 1) {
throw 'Invalid GSV length: ' + str;
}
return {
'time': parseTime(rmc[1], rmc[9]),
'status': parseRMC_GLLStatus(rmc[2]),
'lat': parseCoord(rmc[3], rmc[4]),
'lon': parseCoord(rmc[5], rmc[6]),
'speed': parseKnots(rmc[7]),
'track': parseNumber(rmc[8]),
'variation': parseRMCVariation(rmc[10], rmc[11]),
'faa': rmc.length === 14 ? parseFAA(rmc[12]) : null
};
},
/*
$GPGSV,1,1,13,02,02,213,,03,-3,000,,11,00,121,,14,13,172,05*67
1 = Total number of messages of this type in this cycle
2 = Message number
3 = Total number of SVs in view
4 = SV PRN number
5 = Elevation in degrees, 90 maximum
6 = Azimuth, degrees from true north, 000 to 359
7 = SNR (signal to noise ratio), 00-99 dB (null when not tracking, higher is better)
8-11 = Information about second SV, same as field 4-7
12-15= Information about third SV, same as field 4-7
16-19= Information about fourth SV, same as field 4-7
8/12/16/20 = Checksum
*/
// Track info
'VTG': function(str, vtg) {
var sats = [];
if (vtg.length !== 10 && vtg.length !== 11) {
throw 'Invalid VTG length: ' + str;
}
for (var i = 4; i < gsv.length - 1; i += 4) {
/*
------------------------------------------------------------------------------
1 2 3 4 5 6 7 8 9 10
| | | | | | | | | |
$--VTG,x.x,T,x.x,M,x.x,N,x.x,K,m,*hh<CR><LF>
------------------------------------------------------------------------------
var prn = parseNumber(gsv[i]);
var snr = parseNumber(gsv[i + 3]);
1 = Track degrees
2 = Fixed text 'T' indicates that track made good is relative to true north
3 = not used
4 = not used
5 = Speed over ground in knots
6 = Fixed text 'N' indicates that speed over ground in in knots
7 = Speed over ground in kilometers/hour
8 = Fixed text 'K' indicates that speed over ground is in kilometers/hour
(9) = FAA mode indicator (NMEA 2.3 and later)
9/10 = Checksum
*/
sats.push({
'prn': prn,
'elevation': parseNumber(gsv[i + 1]),
'azimuth': parseNumber(gsv[i + 2]),
'snr': snr,
'status': prn !== null ? (snr !== null ? 'tracking' : 'in view') : null
});
}
if (vtg[2] !== 'T') {
throw 'Invalid VTG track mode: ' + str;
}
return {
'msgNumber': parseNumber(gsv[2]),
'msgsTotal': parseNumber(gsv[1]),
//'satsInView' : parseNumber(gsv[3]), // Can be obtained by satellites.length
'satellites': sats
};
},
// Geographic Position - Latitude/Longitude
'GLL': function(str, gll) {
if (vtg[8] !== 'K' || vtg[6] !== 'N') {
throw 'Invalid VTG speed tag: ' + str;
}
if (gll.length !== 9) {
throw 'Invalid GLL length: ' + str;
}
return {
'track': parseNumber(vtg[1]),
'speed': parseKnots(vtg[5]),
'faa': vtg.length === 11 ? parseFAA(vtg[9]) : null
};
},
/*
------------------------------------------------------------------------------
1 2 3 4 5 6 7 8
| | | | | | | |
$--GLL,llll.ll,a,yyyyy.yy,a,hhmmss.ss,a,m,*hh<CR><LF>
------------------------------------------------------------------------------
1. Latitude
2. N or S (North or South)
3. Longitude
4. E or W (East or West)
5. Universal Time Coordinated (UTC)
6. Status A - Data Valid, V - Data Invalid
7. FAA mode indicator (NMEA 2.3 and later)
8. Checksum
*/
// satelites in view
'GSV': function(str, gsv) {
return {
'time': parseTime(gll[5]),
'status': parseRMC_GLLStatus(gll[6]),
'lat': parseCoord(gll[1], gll[2]),
'lon': parseCoord(gll[3], gll[4])
};
},
// UTC Date / Time and Local Time Zone Offset
'ZDA': function(str, zda) {
if (gsv.length < 9 || gsv.length % 4 !== 1) {
throw 'Invalid GSV length: ' + str;
}
/*
1 = hhmmss.ss = UTC
2 = xx = Day, 01 to 31
3 = xx = Month, 01 to 12
4 = xxxx = Year
5 = xx = Local zone description, 00 to +/- 13 hours
6 = xx = Local zone minutes description (same sign as hours)
*/
// TODO: incorporate local zone information
/*
$GPGSV,1,1,13,02,02,213,,03,-3,000,,11,00,121,,14,13,172,05*67
1 = Total number of messages of this type in this cycle
2 = Message number
3 = Total number of SVs in view
4 = SV PRN number
5 = Elevation in degrees, 90 maximum
6 = Azimuth, degrees from true north, 000 to 359
7 = SNR (signal to noise ratio), 00-99 dB (null when not tracking, higher is better)
8-11 = Information about second SV, same as field 4-7
12-15= Information about third SV, same as field 4-7
16-19= Information about fourth SV, same as field 4-7
8/12/16/20 = Checksum
*/
var sats = [];
for (var i = 4; i < gsv.length - 1; i += 4) {
var prn = parseNumber(gsv[i]);
var snr = parseNumber(gsv[i + 3]);
sats.push({
'prn': prn,
'elevation': parseNumber(gsv[i + 1]),
'azimuth': parseNumber(gsv[i + 2]),
'snr': snr,
'status': prn !== null ? (snr !== null ? 'tracking' : 'in view') : null
});
return {
'time': parseTime(zda[1], zda[2] + zda[3] + zda[4])
//'delta': time === null ? null : (Date.now() - time) / 1000
};
}
return {
'msgNumber': parseNumber(gsv[2]),
'msgsTotal': parseNumber(gsv[1]),
//'satsInView' : parseNumber(gsv[3]), // Can be obtained by satellites.length
'satellites': sats
};
},
// Geographic Position - Latitude/Longitude
'GLL': function(str, gll) {
if (gll.length !== 9) {
throw 'Invalid GLL length: ' + str;
}
/*
------------------------------------------------------------------------------
1 2 3 4 5 6 7 8
| | | | | | | |
$--GLL,llll.ll,a,yyyyy.yy,a,hhmmss.ss,a,m,*hh<CR><LF>
------------------------------------------------------------------------------
1. Latitude
2. N or S (North or South)
3. Longitude
4. E or W (East or West)
5. Universal Time Coordinated (UTC)
6. Status A - Data Valid, V - Data Invalid
7. FAA mode indicator (NMEA 2.3 and later)
8. Checksum
*/
return {
'time': parseTime(gll[5]),
'status': parseRMC_GLLStatus(gll[6]),
'lat': parseCoord(gll[1], gll[2]),
'lon': parseCoord(gll[3], gll[4])
};
},
// UTC Date / Time and Local Time Zone Offset
'ZDA': function(str, zda) {
/*
1 = hhmmss.ss = UTC
2 = xx = Day, 01 to 31
3 = xx = Month, 01 to 12
4 = xxxx = Year
5 = xx = Local zone description, 00 to +/- 13 hours
6 = xx = Local zone minutes description (same sign as hours)
*/
return {
'time': parseTime(zda[1], zda[2] + zda[3] + zda[4])
//'delta': time === null ? null : (Date.now() - time) / 1000
};
}
};

@@ -566,3 +581,3 @@

if (this['events']['data'] !== undefined) {
this['events']['data'].call(this, line, parsed);
this['events']['data'].call(this, parsed);
}

@@ -593,2 +608,33 @@

GPS['Bearing'] = function(lat1, lon1, lat2, lon2) {
var BearingRad = Math.atan2((Math.sin(lon2 - lon1) * Math.cos(lat2)),
Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) *
Math.cos(lat2) * Math.cos(lon2 - lon1));
var CalBearing = 180.0 * BearingRad / Math.PI;
return (CalBearing + 360) % 360;
};
GPS['Distance'] = function(lat1, lon1, lat2, lon2) {
// Haversine Formula
// var RADIUS = 6371; // Earth radius average
// var RADIUS = 6378.137; // Earth radius at equator
var RADIUS = 6372.8; // Earth radius in km
var d2r = Math.PI / 180;
var hLat = (lat2 - lat1) * d2r * 0.5; // Half of lat difference
var hLon = (lon2 - lon1) * d2r * 0.5; // Half of lon difference
var tmp = Math.sin(hLat) * Math.sin(hLat) +
Math.cos(lat1 * d2r) * Math.cos(lat2 * d2r) * Math.sin(hLon) * Math.sin(hLon);
//return RADIUS * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1.0 - a));
return RADIUS * 2 * Math.asin(Math.sqrt(tmp));
};
if (typeof exports === 'object') {

@@ -595,0 +641,0 @@ module.exports = GPS;

{
"name": "gps",
"title": "gps.js",
"version": "0.0.6",
"version": "0.0.7",
"homepage": "https://github.com/infusion/GPS.js",
"bugs": "https://github.com/infusion/GPS.js/issues",
"description": "A GPS NMEA parser library",
"keywords": ["nmea", "gps", "serial", "parser", "geo", "location", "rmc", "gga", "gll", "gsa", "vtg", "gva"],
"keywords": ["nmea", "gps", "serial", "parser", "distance", "geo", "location", "rmc", "gga", "gll", "gsa", "vtg", "gva"],
"author": "Robert Eisele <robert@xarg.org> (http://www.xarg.org/)",
"main": "gps",
"private": false,
"readmeFilename": "README.md",

@@ -12,0 +13,0 @@ "directories": {

![GPS.js](https://github.com/infusion/GPS.js/blob/master/logo.png?raw=true "Javascript GPS Parser")
![GPS.js](https://github.com/infusion/GPS.js/blob/master/res/logo.png?raw=true "Javascript GPS Parser")
[![NPM Package](https://img.shields.io/npm/v/gps.js.svg?style=flat)](https://npmjs.org/package/gps.js "View this project on npm")
[![NPM Package](https://img.shields.io/npm/v/gps.svg?style=flat)](https://npmjs.org/package/gps "View this project on npm")
[![Build Status](https://travis-ci.org/infusion/GPS.js.svg?branch=master)](https://travis-ci.org/infusion/GPS.js)
[![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT)
GPS.js is a stream parser for [NMEA](http://www.gpsinformation.org/dale/nmea.htm) sentences, given by any common GPS receiver. The output is tried to be as high-level as possible.
GPS.js is an extensible parser for [NMEA](http://www.gpsinformation.org/dale/nmea.htm) sentences, given by any common GPS receiver. The output is tried to be as high-level as possible to make it more useful than simply splitting the information. The aim is, that you don't have to understand NMEA, just plug in your receiver and you're ready to go.

@@ -35,3 +35,3 @@

The real advantage over other NMEA implementations is, that the GPS information is also interpreted and normalized. The most high-level API is the state object, which changes with every new event. You can use this information with:
The real advantage over other NMEA implementations is, that the GPS information is interpreted and normalized. The most high-level API is the state object, which changes with every new event. You can use this information with:

@@ -58,2 +58,27 @@ ```javascript

Simple serial example
---
```javascript
var SerialPort = require('serialport');
var port = new SerialPort.SerialPort('/dev/tty.usbserial', { // change path
baudrate: 4800,
parser: SerialPort.parsers.readline('\r\n')
});
var GPS = require('gps');
var gps = new GPS;
port.on('open', function() {
gps.on('data', function(data) {
console.log(data, gps.state);
});
port.on('data', function(data) {
gps.update(data);
});
});
```
Dashboard

@@ -67,4 +92,6 @@ ---

After that you can open the browser and go to http://localhost:3000
After that you can open the browser and go to http://localhost:3000 The result should look like
![GPS TU Dresden](https://github.com/infusion/GPS.js/blob/master/res/dashboard.png?raw=true)
Google Maps

@@ -78,5 +105,7 @@ ---

After that you can open the browser and go to http://localhost:3000
After that you can open the browser and go to http://localhost:3000 The result should look like
![GPS Google Maps Dresden](https://github.com/infusion/GPS.js/blob/master/res/maps.png?raw=true)
Protocols

@@ -197,2 +226,17 @@ ===

Functions
===
GPS.js comes with a few static functions, which help by working with geo-coordinates.
GPS.Distance(latFrom, lonFrom, latTo, lonTo)
---
Calculates the distance between two geo-coordinates using Haversine formula
GPS.Bearing(latFrom, lonFrom, latTo, lonTo)
---
Calculates the angle from one coordinate to another
Using GPS.js with the browser

@@ -223,2 +267,1 @@ ===

function _(x) {
return x < 10 ? "0" + x : x;
}
var today = new Date();
today = today.getFullYear() + '-' + _(today.getMonth() + 1) + '-' + _(today.getDate());
var expect = require('chai').expect;

@@ -55,3 +62,3 @@ var GPS = require('../gps.js');

'stationID': 0,
'time': new Date('2016-03-22T23:49:20.000Z'),
'time': new Date(today + 'T23:49:20.000Z'),
'type': 'GGA',

@@ -71,3 +78,3 @@ 'valid': true

'stationID': NaN,
'time': new Date('2016-03-22T12:35:19.000Z'),
'time': new Date(today + 'T12:35:19.000Z'),
'type': 'GGA',

@@ -135,3 +142,3 @@ 'valid': true,

'stationID': null,
'time': new Date('2016-03-22T09:27:50.000Z'),
'time': new Date(today + 'T09:27:50.000Z'),
'type': 'GGA',

@@ -201,37 +208,37 @@ 'valid': true

'$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A': {
"faa": null,
"lat": 48.1173,
"lon": 11.516666666666667,
"raw": "$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A",
"speed": 41.4848,
"status": "active",
"time": new Date('2094-03-23T12:35:19.000Z'),
"track": 84.4,
"type": "RMC",
"valid": true,
"variation": -3.1
'faa': null,
'lat': 48.1173,
'lon': 11.516666666666667,
'raw': '$GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A',
'speed': 41.4848,
'status': 'active',
'time': new Date('2094-03-23T12:35:19.000Z'),
'track': 84.4,
'type': 'RMC',
'valid': true,
'variation': -3.1
},
//'$GPVTG,210.43,T,210.43,M,5.65,N,,,A*67': {},
'$GPGGA,123519,4807.04,N,1131.00,E,1,8,0.9,545.9,M,46.9,M,,*45': {
"age": null,
"alt": 545.9,
"geoidal": 46.9,
"hdop": 0.9,
"lat": 48.117333333333335,
"lon": 113.01666666666667,
"quality": "fix",
"raw": "$GPGGA,123519,4807.04,N,1131.00,E,1,8,0.9,545.9,M,46.9,M,,*45",
"satelites": 8,
"stationID": null,
"time": new Date('2016-03-22T12:35:19.000Z'),
"type": "GGA",
"valid": true
'age': null,
'alt': 545.9,
'geoidal': 46.9,
'hdop': 0.9,
'lat': 48.117333333333335,
'lon': 113.01666666666667,
'quality': 'fix',
'raw': '$GPGGA,123519,4807.04,N,1131.00,E,1,8,0.9,545.9,M,46.9,M,,*45',
'satelites': 8,
'stationID': null,
'time': new Date(today + 'T12:35:19.000Z'),
'type': 'GGA',
'valid': true
},
'$GPGSA,A,3,12,05,25,29,,,,,,,,,9.4,7.6,5.6*37': {
"fix": "3D",
"hdop": 7.6,
"mode": "automatic",
"pdop": 9.4,
"raw": "$GPGSA,A,3,12,05,25,29,,,,,,,,,9.4,7.6,5.6*37",
"satellites": [
'fix': '3D',
'hdop': 7.6,
'mode': 'automatic',
'pdop': 9.4,
'raw': '$GPGSA,A,3,12,05,25,29,,,,,,,,,9.4,7.6,5.6*37',
'satellites': [
12,

@@ -242,79 +249,73 @@ 5,

],
"type": "GSA",
"valid": true,
"vdop": 5.6
'type': 'GSA',
'valid': true,
'vdop': 5.6
},
'$GPGSV,3,1,11,03,03,111,00,04,15,270,00,06,01,010,00,13,06,292,00*74': {
"msgNumber": 1,
"msgsTotal": 3,
"raw": "$GPGSV,3,1,11,03,03,111,00,04,15,270,00,06,01,010,00,13,06,292,00*74",
"satellites": [
'msgNumber': 1,
'msgsTotal': 3,
'raw': '$GPGSV,3,1,11,03,03,111,00,04,15,270,00,06,01,010,00,13,06,292,00*74',
'satellites': [
{
"azimuth": 111,
"elevation": 3,
"prn": 3,
"snr": 0,
"status": "tracking"
},
{
"azimuth": 270,
"elevation": 15,
"prn": 4,
"snr": 0,
"status": "tracking"
},
{
"azimuth": 10,
"elevation": 1,
"prn": 6,
"snr": 0,
"status": "tracking"
},
{
"azimuth": 292,
"elevation": 6,
"prn": 13,
"snr": 0,
"status": "tracking"
'azimuth': 111,
'elevation': 3,
'prn': 3,
'snr': 0,
'status': 'tracking'
}, {
'azimuth': 270,
'elevation': 15,
'prn': 4,
'snr': 0,
'status': 'tracking'
}, {
'azimuth': 10,
'elevation': 1,
'prn': 6,
'snr': 0,
'status': 'tracking'
}, {
'azimuth': 292,
'elevation': 6,
'prn': 13,
'snr': 0,
'status': 'tracking'
}
],
"type": "GSV",
"valid": true
'type': 'GSV',
'valid': true
},
'$GPGSV,3,2,11,14,25,170,00,16,57,208,39,18,67,296,40,19,40,246,00*2D': {
"msgNumber": 2,
"msgsTotal": 3,
"raw": "$GPGSV,3,2,11,14,25,170,00,16,57,208,39,18,67,296,40,19,40,246,00*2D",
"satellites": [
'msgNumber': 2,
'msgsTotal': 3,
'raw': '$GPGSV,3,2,11,14,25,170,00,16,57,208,39,18,67,296,40,19,40,246,00*2D',
'satellites': [
{
"azimuth": 170,
"elevation": 25,
"prn": 14,
"snr": 0,
"status": "tracking"
},
{
"azimuth": 208,
"elevation": 57,
"prn": 16,
"snr": 39,
"status": "tracking"
},
{
"azimuth": 296,
"elevation": 67,
"prn": 18,
"snr": 40,
"status": "tracking"
},
{
"azimuth": 246,
"elevation": 40,
"prn": 19,
"snr": 0,
"status": "tracking"
'azimuth': 170,
'elevation': 25,
'prn': 14,
'snr': 0,
'status': 'tracking'
}, {
'azimuth': 208,
'elevation': 57,
'prn': 16,
'snr': 39,
'status': 'tracking'
}, {
'azimuth': 296,
'elevation': 67,
'prn': 18,
'snr': 40,
'status': 'tracking'
}, {
'azimuth': 246,
'elevation': 40,
'prn': 19,
'snr': 0,
'status': 'tracking'
}
],
"type": "GSV",
"valid": false
'type': 'GSV',
'valid': false
},

@@ -407,3 +408,3 @@ '$GPGSV,3,2,11,02,39,223,16,13,28,070,17,26,23,252,,04,14,186,15*77': {

'stationID': null,
'time': new Date('2016-03-22T09:27:51.000Z'),
'time': new Date(today + 'T09:27:51.000Z'),
'type': 'GGA',

@@ -426,24 +427,24 @@ 'valid': true

'$GPGLL,6005.068,N,02332.341,E,095601,A,D*42': {
"lat": 60.084466666666664,
"lon": 23.539016666666665,
"raw": "$GPGLL,6005.068,N,02332.341,E,095601,A,D*42",
"status": "active",
"time": new Date("2016-03-22T09:56:01.000Z"),
"type": "GLL",
"valid": true
'lat': 60.084466666666664,
'lon': 23.539016666666665,
'raw': '$GPGLL,6005.068,N,02332.341,E,095601,A,D*42',
'status': 'active',
'time': new Date(today + 'T09:56:01.000Z'),
'type': 'GLL',
'valid': true
},
'$GPGLL,4916.45,N,12311.12,W,225444,A,*1D': {
"lat": 49.274166666666666,
"lon": -123.18533333333333,
"raw": "$GPGLL,4916.45,N,12311.12,W,225444,A,*1D",
"status": "active",
"time": new Date('2016-03-22T22:54:44.000Z'),
"type": "GLL",
"valid": true
'lat': 49.274166666666666,
'lon': -123.18533333333333,
'raw': '$GPGLL,4916.45,N,12311.12,W,225444,A,*1D',
'status': 'active',
'time': new Date(today + 'T22:54:44.000Z'),
'type': 'GLL',
'valid': true
}
};
var collect = {};
gps.on('data', function(raw, data) {
gps.on('data', function(data) {
collect[raw] = data;
collect[data.raw] = data;
});

@@ -450,0 +451,0 @@ for (var i in tests) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc