Comparing version 0.3.0 to 0.4.0
{ | ||
"name": "gps", | ||
"main": "gps.js", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"homepage": "https://github.com/infusion/GPS.js", | ||
@@ -6,0 +6,0 @@ "description": "A GPS NMEA parser library", |
@@ -8,8 +8,16 @@ | ||
var SerialPort = require('serialport'); | ||
var port = new SerialPort.SerialPort(file, { | ||
baudrate: 4800, | ||
parser: SerialPort.parsers.readline('\r\n') | ||
const SerialPort = require('serialport'); | ||
const parsers = SerialPort.parsers; | ||
const parser = new parsers.Readline({ | ||
delimiter: '\r\n' | ||
}); | ||
const port = new SerialPort(file, { | ||
baudRate: 4800 | ||
}); | ||
port.pipe(parser); | ||
var Angles = require('angles'); | ||
@@ -39,4 +47,4 @@ var GPS = require('../gps.js'); | ||
port.on('data', function(data) { | ||
parser.on('data', function(data) { | ||
gps.update(data); | ||
}); |
var app = require('express')(); | ||
var http = require('http').Server(app); | ||
var io = require('socket.io')(http); | ||
const app = require('express')(); | ||
const http = require('http').Server(app); | ||
const io = require('socket.io')(http); | ||
@@ -9,10 +9,17 @@ // var file = '/dev/cu.usbserial'; | ||
//var file = '/dev/tty.usbserial'; | ||
var file = '/dev/tty.usbmodem1411'; | ||
const file = '/dev/tty.usbmodem1411'; | ||
var SerialPort = require('serialport'); | ||
var port = new SerialPort.SerialPort(file, { | ||
baudrate: 4800, | ||
parser: SerialPort.parsers.readline('\r\n') | ||
const SerialPort = require('serialport'); | ||
const parsers = SerialPort.parsers; | ||
const parser = new parsers.Readline({ | ||
delimiter: '\r\n' | ||
}); | ||
const port = new SerialPort(file, { | ||
baudRate: 4800 | ||
}); | ||
port.pipe(parser); | ||
app.get('/', function(req, res) { | ||
@@ -33,5 +40,5 @@ res.sendFile(__dirname + '/dashboard.html'); | ||
port.on('data', function(data) { | ||
parser.on('data', function(data) { | ||
gps.update(data); | ||
}); | ||
}); |
@@ -7,8 +7,15 @@ | ||
var SerialPort = require('serialport'); | ||
var port = new SerialPort.SerialPort(file, { | ||
baudrate: 4800, | ||
parser: SerialPort.parsers.readline('\r\n') | ||
const SerialPort = require('serialport'); | ||
const parsers = SerialPort.parsers; | ||
const parser = new parsers.Readline({ | ||
delimiter: '\r\n' | ||
}); | ||
const port = new SerialPort(file, { | ||
baudRate: 4800 | ||
}); | ||
port.pipe(parser); | ||
var fs = require('fs'); | ||
@@ -24,4 +31,4 @@ var ws = fs.createWriteStream('gps.dump'); | ||
port.on('data', function(data) { | ||
parser.on('data', function(data) { | ||
gps.update(data); | ||
}); |
@@ -11,8 +11,16 @@ | ||
var SerialPort = require('serialport'); | ||
var port = new SerialPort.SerialPort(file, { | ||
baudrate: 4800, | ||
parser: SerialPort.parsers.readline('\r\n') | ||
const SerialPort = require('serialport'); | ||
const parsers = SerialPort.parsers; | ||
const parser = new parsers.Readline({ | ||
delimiter: '\r\n' | ||
}); | ||
const port = new SerialPort(file, { | ||
baudRate: 4800 | ||
}); | ||
port.pipe(parser); | ||
var GPS = require('../../gps.js'); | ||
@@ -34,4 +42,4 @@ var gps = new GPS; | ||
port.on('data', function(data) { | ||
parser.on('data', function(data) { | ||
gps.update(data); | ||
}); |
@@ -7,8 +7,16 @@ | ||
var SerialPort = require('serialport'); | ||
var port = new SerialPort.SerialPort(file, { | ||
baudrate: 4800, | ||
parser: SerialPort.parsers.readline('\r\n') | ||
const SerialPort = require('serialport'); | ||
const parsers = SerialPort.parsers; | ||
const parser = new parsers.Readline({ | ||
delimiter: '\r\n' | ||
}); | ||
const port = new SerialPort(file, { | ||
baudRate: 4800 | ||
}); | ||
port.pipe(parser); | ||
var GPS = require('../gps.js'); | ||
@@ -21,4 +29,4 @@ var gps = new GPS; | ||
port.on('data', function(data) { | ||
parser.on('data', function(data) { | ||
gps.update(data); | ||
}); |
@@ -9,8 +9,15 @@ | ||
var SerialPort = require('serialport'); | ||
var port = new SerialPort.SerialPort(file, { | ||
baudrate: 4800, | ||
parser: SerialPort.parsers.readline('\r\n') | ||
const SerialPort = require('serialport'); | ||
const parsers = SerialPort.parsers; | ||
const parser = new parsers.Readline({ | ||
delimiter: '\r\n' | ||
}); | ||
const port = new SerialPort(file, { | ||
baudRate: 4800 | ||
}); | ||
port.pipe(parser); | ||
var GPS = require('../gps.js'); | ||
@@ -32,3 +39,3 @@ var gps = new GPS; | ||
port.on('data', function(data) { | ||
parser.on('data', function(data) { | ||
gps.update(data); | ||
@@ -35,0 +42,0 @@ }); |
@@ -8,8 +8,15 @@ | ||
var SerialPort = require('serialport'); | ||
var port = new SerialPort.SerialPort(file, { | ||
baudrate: 4800, | ||
parser: SerialPort.parsers.readline('\r\n') | ||
const SerialPort = require('serialport'); | ||
const parsers = SerialPort.parsers; | ||
const parser = new parsers.Readline({ | ||
delimiter: '\r\n' | ||
}); | ||
const port = new SerialPort(file, { | ||
baudRate: 4800 | ||
}); | ||
port.pipe(parser); | ||
var GPS = require('../gps.js'); | ||
@@ -22,4 +29,4 @@ var gps = new GPS; | ||
port.on('data', function(data) { | ||
parser.on('data', function(data) { | ||
gps.update(data); | ||
}); |
72
gps.js
/** | ||
* @license GPS.js v0.3.0 26/01/2016 | ||
* @license GPS.js v0.4.0 26/01/2016 | ||
* | ||
@@ -11,4 +11,5 @@ * Copyright (c) 2016, Robert Eisele (robert@xarg.org) | ||
var Deg2Rad = Math.PI / 180; | ||
var Rad2Deg = 180 / Math.PI; | ||
'use strict'; | ||
var D2R = Math.PI / 180; | ||
@@ -18,7 +19,2 @@ var collectSats = []; | ||
function updateState(state, data) { | ||
// Skip update if data is void | ||
if (data['type'] === 'RMC' && data['status'] !== 'A' || data['type'] === 'GGA' && data['quality'] === null) { | ||
return; | ||
} | ||
@@ -29,4 +25,2 @@ if (data['type'] === 'RMC' || data['type'] === 'GGA' || data['type'] === 'GLL') { | ||
state['lon'] = data['lon']; | ||
state['lastFix'] = Date.now(); // Check data.quality==fix maybe? | ||
} | ||
@@ -40,9 +34,8 @@ | ||
state['alt'] = data['alt']; | ||
state['hdop'] = data['hdop']; | ||
} | ||
if (data['type'] === 'RMC'/* || data['type'] === 'VTG'*/) { | ||
// TODO: is rmc speed/heading really interchangeable with vtg speed/heading? | ||
// TODO: is rmc speed/track really interchangeable with vtg speed/track? | ||
state['speed'] = data['speed']; | ||
state['heading'] = data['heading']; | ||
state['track'] = data['track']; | ||
} | ||
@@ -113,3 +106,3 @@ | ||
function parseDegree(coord, dir) { | ||
function parseCoord(coord, dir) { | ||
@@ -331,4 +324,4 @@ // Latitude can go from 0 to 90; longitude can go from 0 to 180. | ||
'time': parseTime(gga[1]), | ||
'lat': parseDegree(gga[2], gga[3]), | ||
'lon': parseDegree(gga[4], gga[5]), | ||
'lat': parseCoord(gga[2], gga[3]), | ||
'lon': parseCoord(gga[4], gga[5]), | ||
'alt': parseDist(gga[9], gga[10]), | ||
@@ -411,4 +404,2 @@ 'quality': parseGGAFix(gga[6]), | ||
*/ | ||
// Throw packet away if status!='A'? | ||
@@ -418,6 +409,6 @@ return { | ||
'status': parseRMC_GLLStatus(rmc[2]), | ||
'lat': parseDegree(rmc[3], rmc[4]), | ||
'lon': parseDegree(rmc[5], rmc[6]), | ||
'lat': parseCoord(rmc[3], rmc[4]), | ||
'lon': parseCoord(rmc[5], rmc[6]), | ||
'speed': parseKnots(rmc[7]), | ||
'heading': parseNumber(rmc[8]), | ||
'track': parseNumber(rmc[8]), | ||
'variation': parseRMCVariation(rmc[10], rmc[11]), | ||
@@ -456,3 +447,3 @@ 'faa': rmc.length === 14 ? parseFAA(rmc[12]) : null | ||
return { | ||
'heading': null, | ||
'track': null, | ||
'speed': null, | ||
@@ -472,3 +463,3 @@ 'faa': null | ||
return { | ||
'heading': parseNumber(vtg[1]), | ||
'track': parseNumber(vtg[1]), | ||
'speed': parseKnots(vtg[5]), | ||
@@ -551,4 +542,4 @@ 'faa': vtg.length === 11 ? parseFAA(vtg[9]) : null | ||
'status': parseRMC_GLLStatus(gll[6]), | ||
'lat': parseDegree(gll[1], gll[2]), | ||
'lon': parseDegree(gll[3], gll[4]) | ||
'lat': parseCoord(gll[1], gll[2]), | ||
'lon': parseCoord(gll[3], gll[4]) | ||
}; | ||
@@ -610,15 +601,24 @@ }, | ||
// Heading (N=0, E=90, S=180, W=270) from point 1 to point 2 | ||
// Heading (N=0, E=90, S=189, W=270) from point 1 to point 2 | ||
GPS['Heading'] = function(lat1, lon1, lat2, lon2) { | ||
var dlon = (lon2 - lon1) * Deg2Rad; | ||
var dlon = (lon2 - lon1) * D2R; | ||
lat1 = lat1 * Deg2Rad; | ||
lat2 = lat2 * Deg2Rad; | ||
lat1 = lat1 * D2R; | ||
lat2 = lat2 * D2R; | ||
var n = Math.sin(dlon) * Math.cos(lat2); | ||
var d = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dlon); | ||
var sdlon = Math.sin(dlon); | ||
var cdlon = Math.cos(dlon); | ||
var head = Math.atan2(n, d) * Rad2Deg; | ||
var slat1 = Math.sin(lat1); | ||
var clat1 = Math.cos(lat1); | ||
var slat2 = Math.sin(lat2); | ||
var clat2 = Math.cos(lat2); | ||
var n = sdlon * clat2; | ||
var d = clat1 * slat2 - slat1 * clat2 * cdlon; | ||
var head = Math.atan2(n, d) * 180 / Math.PI; | ||
return (head + 360) % 360; | ||
@@ -637,7 +637,7 @@ }; | ||
var hLat = (lat2 - lat1) * Deg2Rad * 0.5; // Half of lat difference | ||
var hLon = (lon2 - lon1) * Deg2Rad * 0.5; // Half of lon difference | ||
var hLat = (lat2 - lat1) * D2R * 0.5; // Half of lat difference | ||
var hLon = (lon2 - lon1) * D2R * 0.5; // Half of lon difference | ||
lat1 = lat1 * Deg2Rad; | ||
lat2 = lat2 * Deg2Rad; | ||
lat1 = lat1 * D2R; | ||
lat2 = lat2 * D2R; | ||
@@ -644,0 +644,0 @@ var shLat = Math.sin(hLat); |
/* | ||
GPS.js v0.3.0 26/01/2016 | ||
GPS.js v0.4.0 26/01/2016 | ||
@@ -7,12 +7,11 @@ Copyright (c) 2016, Robert Eisele (robert@xarg.org) | ||
*/ | ||
(function(t){function l(b,a){if(""===b)return null;var c=new Date;if(a){var d=a.slice(4),e=a.slice(2,4)-1,f=a.slice(0,2);4===d.length?c.setUTCFullYear(d,e,f):c.setUTCFullYear("20"+d,e,f)}c.setUTCHours(b.slice(0,2));c.setUTCMinutes(b.slice(2,4));c.setUTCSeconds(b.slice(4,6));d=b.slice(7);e=d.length;f=0;0!==e&&(f=parseFloat(d)*Math.pow(10,3-e));c.setUTCMilliseconds(f);return c}function k(b,a){if(""===b)return null;var c=1;switch(a){case "S":c=-1;case "N":var d=2;break;case "W":c=-1;case "E":d=3}return c* | ||
(parseFloat(b.slice(0,d))+parseFloat(b.slice(d))/60)}function f(b){return""===b?null:parseFloat(b)}function n(b){return""===b?null:1.852*parseFloat(b)}function u(b){switch(b){case "":case "0":return null;case "1":return"fix";case "2":return"dgps-fix";case "3":return"pps-fix";case "4":return"rtk";case "5":return"rtk-float";case "6":return"estimated";case "7":return"manual";case "8":return"simulated"}throw"INVALID GGA FIX: "+b;}function p(b){switch(b){case "A":return"active";case "V":return"void";case "":return null}throw"INVALID RMC/GLL STATUS: "+ | ||
b;}function q(b){switch(b){case "A":return"autonomous";case "D":return"differential";case "E":return"estimated";case "M":return"manual input";case "S":return"simulated";case "N":return"not valid";case "P":return"precise"}throw"INVALID FAA MODE: "+b;}function r(b,a){if("M"===a||""===a)return f(b);throw"Unknown unit: "+a;}function g(){this.events={};this.state={}}var h=Math.PI/180,v=180/Math.PI,m=[];g.prototype.events=null;g.prototype.state=null;g.mod={GGA:function(b,a){if(16!==a.length)throw"Invalid GGA length: "+ | ||
b;return{time:l(a[1]),lat:k(a[2],a[3]),lon:k(a[4],a[5]),alt:r(a[9],a[10]),quality:u(a[6]),satelites:f(a[7]),hdop:f(a[8]),geoidal:r(a[11],a[12]),age:f(a[13]),stationID:f(a[14])}},GSA:function(b,a){if(19!==a.length)throw"Invalid GSA length: "+b;for(var c=[],d=3;15>d;d++)""!==a[d]&&c.push(parseInt(a[d],10));a:{d=a[1];switch(d){case "M":d="manual";break a;case "A":d="automatic";break a;case "":d=null;break a}throw"INVALID GSA MODE: "+d;}a:{var e=a[2];switch(e){case "1":case "":e=null;break a;case "2":e= | ||
"2D";break a;case "3":e="3D";break a}throw"INVALID GSA FIX: "+e;}return{mode:d,fix:e,satellites:c,pdop:f(a[15]),hdop:f(a[16]),vdop:f(a[17])}},RMC:function(b,a){if(13!==a.length&&14!==a.length)throw"Invalid RMC length: "+b;var c=l(a[1],a[9]),d=p(a[2]),e=a[10],g=a[11];return{time:c,status:d,lat:k(a[3],a[4]),lon:k(a[5],a[6]),speed:n(a[7]),heading:f(a[8]),variation:""===e||""===g?null:parseFloat(e)*("W"===g?-1:1),faa:14===a.length?q(a[12]):null}},VTG:function(b,a){if(10!==a.length&&11!==a.length)throw"Invalid VTG length: "+ | ||
b;if(""===a[2]&&""===a[8]&&""===a[6])return{heading:null,speed:null,faa:null};if("T"!==a[2])throw"Invalid VTG track mode: "+b;if("K"!==a[8]||"N"!==a[6])throw"Invalid VTG speed tag: "+b;return{heading:f(a[1]),speed:n(a[5]),faa:11===a.length?q(a[9]):null}},GSV:function(b,a){if(9>a.length||1!==a.length%4)throw"Invalid GSV length: "+b;for(var c=[],d=4;d<a.length-1;d+=4){var e=f(a[d]),g=f(a[d+3]);c.push({prn:e,elevation:f(a[d+1]),azimuth:f(a[d+2]),snr:g,status:null!==e?null!==g?"tracking":"in view":null})}return{msgNumber:f(a[2]), | ||
msgsTotal:f(a[1]),satellites:c}},GLL:function(b,a){if(9!==a.length)throw"Invalid GLL length: "+b;return{time:l(a[5]),status:p(a[6]),lat:k(a[1],a[2]),lon:k(a[3],a[4])}},ZDA:function(b,a){return{time:l(a[1],a[2]+a[3]+a[4])}}};g.Parse=function(b){if("string"!==typeof b)return!1;var a=b.split(","),c=a.pop();if(4>a.length||"$"!==b.charAt(0)||-1===c.indexOf("*"))return!1;c=c.split("*");a.push(c[0]);a.push(c[1]);a[0]=a[0].slice(3);if(void 0!==g.mod[a[0]]){c=this.mod[a[0]](b,a);c.raw=b;for(var d=0,e=1;e< | ||
b.length;e++){var f=b.charCodeAt(e);if(42===f)break;d^=f}c.valid=d===parseInt(a[a.length-1],16);c.type=a[0];return c}return!1};g.Heading=function(b,a,c,d){a=(d-a)*h;b*=h;c*=h;return(Math.atan2(Math.sin(a)*Math.cos(c),Math.cos(b)*Math.sin(c)-Math.sin(b)*Math.cos(c)*Math.cos(a))*v+360)%360};g.Distance=function(b,a,c,d){var e=(c-b)*h*.5;a=(d-a)*h*.5;b*=h;c*=h;e=Math.sin(e);a=Math.sin(a);return 12745.6*Math.asin(Math.sqrt(e*e+Math.cos(b)*Math.cos(c)*a*a))};g.prototype.update=function(b){b=g.Parse(b); | ||
if(!1===b)return!1;var a=this.state;if(!("RMC"===b.type&&"A"!==b.status||"GGA"===b.type&&null===b.quality)){if("RMC"===b.type||"GGA"===b.type||"GLL"===b.type)a.time=b.time,a.lat=b.lat,a.lon=b.lon,a.lastFix=Date.now();"ZDA"===b.type&&(a.time=b.time);"GGA"===b.type&&(a.alt=b.alt,a.hdop=b.hdop);"RMC"===b.type&&(a.speed=b.speed,a.heading=b.heading);"GSA"===b.type&&(a.satsActive=b.satellites,a.fix=b.fix,a.hdop=b.hdop,a.pdop=b.pdop,a.vdop=b.vdop);if("GSV"===b.type){for(var c=b.satellites,d=0;d<c.length;d++)m.push(c[d]); | ||
b.msgNumber===b.msgsTotal&&(a.satsVisible=m,m=[])}}void 0!==this.events.data&&this.events.data.call(this,b);void 0!==this.events[b.type]&&this.events[b.type].call(this,b);return!0};g.prototype.partial="";g.prototype.updatePartial=function(b){for(this.partial+=b;;){b=this.partial.indexOf("\r\n");if(-1===b)break;var a=this.partial.slice(0,b);"$"===a.charAt(0)&&this.update(a);this.partial=this.partial.slice(b+2)}};g.prototype.on=function(b,a){return void 0===this.events[b]?(this.events[b]=a,this):null}; | ||
g.prototype.off=function(b){void 0!==this.events[b]&&(this.events[b]=void 0);return this};"object"===typeof exports?module.a=g:t.GPS=g})(this); | ||
'use strict';(function(t){function l(b,a){if(""===b)return null;var c=new Date;if(a){var d=a.slice(4),g=a.slice(2,4)-1;a=a.slice(0,2);4===d.length?c.setUTCFullYear(d,g,a):c.setUTCFullYear("20"+d,g,a)}c.setUTCHours(b.slice(0,2));c.setUTCMinutes(b.slice(2,4));c.setUTCSeconds(b.slice(4,6));c.setUTCMilliseconds(parseFloat(b.slice(7))||0);return c}function k(b,a){if(""===b)return null;var c,d=1;switch(a){case "S":d=-1;case "N":c=2;break;case "W":d=-1;case "E":c=3}return d*(parseFloat(b.slice(0,c))+parseFloat(b.slice(c))/ | ||
60)}function e(b){return""===b?null:parseFloat(b)}function n(b){return""===b?null:1.852*parseFloat(b)}function u(b){switch(b){case "":case "0":return null;case "1":return"fix";case "2":return"dgps-fix";case "3":return"pps-fix";case "6":return"estimated";case "7":return"manual";case "8":return"simulated"}throw"INVALID GGA FIX: "+b;}function p(b){switch(b){case "A":return"active";case "V":return"void";case "":return null}throw"INVALID RMC/GLL STATUS: "+b;}function q(b){switch(b){case "A":return"autonomous"; | ||
case "D":return"differential";case "E":return"estimated";case "M":return"manual input";case "S":return"simulated";case "N":return"not valid";case "P":return"precise"}throw"INVALID FAA MODE: "+b;}function r(b,a){if("M"===a||""===a)return e(b);throw"Unknown unit: "+a;}function f(){this.events={};this.state={}}var h=Math.PI/180,m=[];f.prototype.events=null;f.prototype.state=null;f.mod={GGA:function(b,a){if(16!==a.length)throw"Invalid GGA length: "+b;return{time:l(a[1]),lat:k(a[2],a[3]),lon:k(a[4],a[5]), | ||
alt:r(a[9],a[10]),quality:u(a[6]),satelites:e(a[7]),hdop:e(a[8]),geoidal:r(a[11],a[12]),age:e(a[13]),stationID:e(a[14])}},GSA:function(b,a){if(19!==a.length)throw"Invalid GSA length: "+b;b=[];for(var c=3;15>c;c++)""!==a[c]&&b.push(parseInt(a[c],10));a:{c=a[1];switch(c){case "M":c="manual";break a;case "A":c="automatic";break a;case "":c=null;break a}throw"INVALID GSA MODE: "+c;}var d;a:{d=a[2];switch(d){case "1":case "":d=null;break a;case "2":d="2D";break a;case "3":d="3D";break a}throw"INVALID GSA FIX: "+ | ||
d;}return{mode:c,fix:d,satellites:b,pdop:e(a[15]),hdop:e(a[16]),vdop:e(a[17])}},RMC:function(b,a){if(13!==a.length&&14!==a.length)throw"Invalid RMC length: "+b;b=l(a[1],a[9]);var c=p(a[2]),d=a[10],g=a[11];return{time:b,status:c,lat:k(a[3],a[4]),lon:k(a[5],a[6]),speed:n(a[7]),track:e(a[8]),variation:""===d||""===g?null:parseFloat(d)*("W"===g?-1:1),faa:14===a.length?q(a[12]):null}},VTG:function(b,a){if(10!==a.length&&11!==a.length)throw"Invalid VTG length: "+b;if(""===a[2]&&""===a[8]&&""===a[6])return{track:null, | ||
speed:null,faa:null};if("T"!==a[2])throw"Invalid VTG track mode: "+b;if("K"!==a[8]||"N"!==a[6])throw"Invalid VTG speed tag: "+b;return{track:e(a[1]),speed:n(a[5]),faa:11===a.length?q(a[9]):null}},GSV:function(b,a){if(9>a.length||1!==a.length%4)throw"Invalid GSV length: "+b;b=[];for(var c=4;c<a.length-1;c+=4){var d=e(a[c]),g=e(a[c+3]);b.push({prn:d,elevation:e(a[c+1]),azimuth:e(a[c+2]),snr:g,status:null!==d?null!==g?"tracking":"in view":null})}return{msgNumber:e(a[2]),msgsTotal:e(a[1]),satellites:b}}, | ||
GLL:function(b,a){if(9!==a.length)throw"Invalid GLL length: "+b;return{time:l(a[5]),status:p(a[6]),lat:k(a[1],a[2]),lon:k(a[3],a[4])}},ZDA:function(b,a){return{time:l(a[1],a[2]+a[3]+a[4])}}};f.Parse=function(b){if("string"!==typeof b)return!1;var a=b.split(","),c=a.pop();if(4>a.length||"$"!==b.charAt(0)||-1===c.indexOf("*"))return!1;c=c.split("*");a.push(c[0]);a.push(c[1]);a[0]=a[0].slice(3);if(void 0!==f.mod[a[0]]){c=this.mod[a[0]](b,a);c.raw=b;for(var d=0,g=1;g<b.length;g++){var e=b.charCodeAt(g); | ||
if(42===e)break;d^=e}c.valid=d===parseInt(a[a.length-1],16);c.type=a[0];return c}return!1};f.Heading=function(b,a,c,d){a=(d-a)*h;b*=h;c*=h;d=Math.cos(c);return(180*Math.atan2(Math.sin(a)*d,Math.cos(b)*Math.sin(c)-Math.sin(b)*d*Math.cos(a))/Math.PI+360)%360};f.Distance=function(b,a,c,d){var e=(c-b)*h*.5;a=(d-a)*h*.5;b*=h;c*=h;e=Math.sin(e);a=Math.sin(a);return 12745.6*Math.asin(Math.sqrt(e*e+Math.cos(b)*Math.cos(c)*a*a))};f.prototype.update=function(b){b=f.Parse(b);if(!1===b)return!1;var a=this.state; | ||
if("RMC"===b.type||"GGA"===b.type||"GLL"===b.type)a.time=b.time,a.lat=b.lat,a.lon=b.lon;"ZDA"===b.type&&(a.time=b.time);"GGA"===b.type&&(a.alt=b.alt);"RMC"===b.type&&(a.speed=b.speed,a.track=b.track);"GSA"===b.type&&(a.satsActive=b.satellites,a.fix=b.fix,a.hdop=b.hdop,a.pdop=b.pdop,a.vdop=b.vdop);if("GSV"===b.type){for(var c=b.satellites,d=0;d<c.length;d++)m.push(c[d]);b.msgNumber===b.msgsTotal&&(a.satsVisible=m,m=[])}void 0!==this.events.data&&this.events.data.call(this,b);void 0!==this.events[b.type]&& | ||
this.events[b.type].call(this,b);return!0};f.prototype.partial="";f.prototype.updatePartial=function(b){for(this.partial+=b;;){b=this.partial.indexOf("\r\n");if(-1===b)break;var a=this.partial.slice(0,b);"$"===a.charAt(0)&&this.update(a);this.partial=this.partial.slice(b+2)}};f.prototype.on=function(b,a){return void 0===this.events[b]?(this.events[b]=a,this):null};f.prototype.off=function(b){void 0!==this.events[b]&&(this.events[b]=void 0);return this};"object"===typeof exports?module.a=f:t.GPS=f})(this); |
{ | ||
"name": "gps", | ||
"title": "gps.js", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"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", "distance", "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/)", | ||
@@ -28,10 +42,10 @@ "main": "gps", | ||
"devDependencies": { | ||
"express": "*", | ||
"socket.io": "*", | ||
"serialport": "*", | ||
"angles": "*", | ||
"mocha": "*", | ||
"chai": "*", | ||
"byline": "*" | ||
"angles": "^0.2.0", | ||
"byline": "^5.0.0", | ||
"chai": "^4.1.0", | ||
"express": "^4.15.3", | ||
"mocha": "^3.5.0", | ||
"serialport": "^5.0.0", | ||
"socket.io": "^2.0.3" | ||
} | ||
} |
@@ -47,3 +47,3 @@ | ||
``` | ||
npm install --save gps | ||
npm install gps | ||
``` | ||
@@ -193,3 +193,3 @@ | ||
- speed: Speed over the ground in km/h | ||
- heading: Track angle in degrees | ||
- track: Track angle in degrees | ||
- variation: Magnetic Variation | ||
@@ -247,3 +247,3 @@ - faa: The FAA mode, introduced with NMEA 2.3 | ||
- type: "VTG" | ||
- heading: Track heading in degrees | ||
- track: Track in degrees | ||
- speed: Speed over ground in km/h | ||
@@ -271,5 +271,4 @@ - faa: The FAA mode, introduced with NMEA 2.3 | ||
- speed: Speed over ground in km/h | ||
- heading: Track angle in degrees | ||
- track: Track in degrees | ||
- satsVisible: Array of all visible satellites | ||
- lastFix: Timestamp of last fix | ||
@@ -286,3 +285,3 @@ Adding new protocols is a matter of minutes. If you need a protocol which isn't implemented, I'm happy to see a pull request or a new ticket. | ||
GPS.js comes with a few static functions, which help by working with geo-coordinates. | ||
GPS.js comes with a few static functions, which helps working with geo-coordinates. | ||
@@ -306,5 +305,3 @@ GPS.Parse(line) | ||
**Note:** GPS.js provides the heading, sent by the GPS receiver with *state.heading*. Maybe you should fuse the provided value with a manual calculation. | ||
Using GPS.js with the browser | ||
@@ -332,4 +329,4 @@ === | ||
=== | ||
Copyright (c) 2016, [Robert Eisele](http://www.xarg.org/) | ||
Copyright (c) 2016, [Robert Eisele](https://www.xarg.org/) | ||
Dual licensed under the MIT or GPL Version 2 licenses. | ||
@@ -36,3 +36,3 @@ | ||
'time': new Date('2016-01-26T23:49:19.000Z'), | ||
'heading': 2.93, | ||
'track': 2.93, | ||
'raw': '$GPRMC,234919.000,A,4832.3914,N,00903.5500,E,2.28,2.93,260116,,*0D', | ||
@@ -46,3 +46,3 @@ 'type': 'RMC', | ||
'speed': 4.22256, | ||
'heading': 2.93, | ||
'track': 2.93, | ||
'raw': '$GPVTG,2.93,T,,M,2.28,N,4.2,K*66', | ||
@@ -91,3 +91,3 @@ 'type': 'VTG', | ||
'time': new Date('2098-09-13T08:18:36.000Z'), | ||
'heading': 360, | ||
'track': 360, | ||
'type': 'RMC', | ||
@@ -215,3 +215,3 @@ 'faa': null, | ||
'time': new Date('2094-03-23T12:35:19.000Z'), | ||
'heading': 84.4, | ||
'track': 84.4, | ||
'type': 'RMC', | ||
@@ -391,3 +391,3 @@ 'valid': true, | ||
'time': new Date('2011-05-28T09:27:50.000Z'), | ||
'heading': 31.66, | ||
'track': 31.66, | ||
'type': 'RMC', | ||
@@ -420,3 +420,3 @@ 'valid': true, | ||
'time': new Date('2011-05-28T09:27:51.000Z'), | ||
'heading': 31.66, | ||
'track': 31.66, | ||
'type': 'RMC', | ||
@@ -423,0 +423,0 @@ 'valid': true, |
@@ -12,3 +12,3 @@ | ||
'time': new Date('2016-01-26T23:49:19.000Z'), | ||
'heading': 2.93, | ||
'track': 2.93, | ||
'raw': '$GPRMC,234919.000,A,4832.3914,N,00903.5500,E,2.28,2.93,260116,,*0D', | ||
@@ -21,3 +21,3 @@ 'type': 'RMC', | ||
'speed': 4.22256, | ||
'heading': 2.93, | ||
'track': 2.93, | ||
'raw': '$GPVTG,2.93,T,,M,2.28,N,4.2,K*66', | ||
@@ -24,0 +24,0 @@ 'type': 'VTG', |
Sorry, the diff of this file is not supported yet
312454
1408
326