Comparing version 0.5.3 to 0.6.0
{ | ||
"name": "gps", | ||
"main": "gps.js", | ||
"version": "0.5.3", | ||
"version": "0.6.0", | ||
"homepage": "https://github.com/infusion/GPS.js", | ||
@@ -6,0 +6,0 @@ "description": "A GPS NMEA parser library", |
@@ -50,3 +50,3 @@ export as namespace gps; | ||
* @param lonTo | ||
* @returns Distance in meters | ||
* @returns Distance in km | ||
*/ | ||
@@ -63,3 +63,3 @@ static Distance( | ||
* @param points Array of {lat: x, lon: y} | ||
* @returns Distance in meters | ||
* @returns Distance in km | ||
*/ | ||
@@ -102,3 +102,3 @@ static TotalDistance(points: GPS.LatLon[]): number; | ||
track?: number; | ||
statsActive?: number[]; | ||
satsActive?: number[]; | ||
satsVisible?: Satellite[]; | ||
@@ -105,0 +105,0 @@ } |
23
gps.js
/** | ||
* @license GPS.js v0.5.3 26/01/2016 | ||
* @license GPS.js v0.6.0 26/01/2016 | ||
* | ||
@@ -15,3 +15,4 @@ * Copyright (c) 2016, Robert Eisele (robert@xarg.org) | ||
var collectSats = []; | ||
var collectSats = {}; | ||
var lastSeenSat = {}; | ||
@@ -49,17 +50,19 @@ function updateState(state, data) { | ||
// TODO: better merge algorithm: | ||
// 1. update every sat and mark as updated. | ||
// 2. If last msg, delete all unmarked sats & reset mark | ||
if (data['type'] === 'GSV') { | ||
var now = new Date().getTime(); | ||
var sats = data['satellites']; | ||
for (var i = 0; i < sats.length; i++) { | ||
collectSats.push(sats[i]); | ||
var prn = sats[i].prn; | ||
lastSeenSat[prn] = now; | ||
collectSats[prn] = sats[i]; | ||
} | ||
// Reset stats | ||
if (data['msgNumber'] === data['msgsTotal']) { | ||
state['satsVisible'] = collectSats; | ||
collectSats = []; | ||
var ret = []; | ||
for (var prn in collectSats) { | ||
if (now - lastSeenSat[prn] < 3000) // Sats are visible for 3 seconds | ||
ret.push(collectSats[prn]) | ||
} | ||
state['satsVisible'] = ret; | ||
} | ||
@@ -66,0 +69,0 @@ } |
/* | ||
GPS.js v0.5.3 26/01/2016 | ||
GPS.js v0.6.0 26/01/2016 | ||
@@ -7,8 +7,8 @@ Copyright (c) 2016, Robert Eisele (robert@xarg.org) | ||
*/ | ||
(function(w){function k(b,a){if(""===b)return null;var d=new Date;if(a){var c=a.slice(4),f=a.slice(2,4)-1,h=a.slice(0,2);4===c.length?d.setUTCFullYear(Number(c),Number(f),Number(h)):d.setUTCFullYear(Number("20"+c),Number(f),Number(h))}d.setUTCHours(Number(b.slice(0,2)));d.setUTCMinutes(Number(b.slice(2,4)));d.setUTCSeconds(Number(b.slice(4,6)));c=b.slice(7);f=c.length;h=0;0!==f&&(h=parseFloat(c)*Math.pow(10,3-f));d.setUTCMilliseconds(Number(h));return d}function l(b,a){if(""===b)return null;var d= | ||
1;switch(a){case "S":d=-1;case "N":var 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 q(b){return""===b?null:1.852*parseFloat(b)}function x(b){if(""===b)return null;switch(parseInt(b,10)){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 Error("INVALID GGA FIX: "+ | ||
(function(x){function k(b,a){if(""===b)return null;var d=new Date;if(a){var c=a.slice(4),f=a.slice(2,4)-1,h=a.slice(0,2);4===c.length?d.setUTCFullYear(Number(c),Number(f),Number(h)):d.setUTCFullYear(Number("20"+c),Number(f),Number(h))}d.setUTCHours(Number(b.slice(0,2)));d.setUTCMinutes(Number(b.slice(2,4)));d.setUTCSeconds(Number(b.slice(4,6)));c=b.slice(7);f=c.length;h=0;0!==f&&(h=parseFloat(c)*Math.pow(10,3-f));d.setUTCMilliseconds(Number(h));return d}function l(b,a){if(""===b)return null;var d= | ||
1;switch(a){case "S":d=-1;case "N":var 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 q(b){return""===b?null:1.852*parseFloat(b)}function y(b){if(""===b)return null;switch(parseInt(b,10)){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 Error("INVALID GGA FIX: "+ | ||
b);}function r(b){switch(b){case "A":return"active";case "V":return"void";case "":return null}throw Error("INVALID RMC/GLL STATUS: "+b);}function n(b){switch(b){case "":return null;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";case "R":return"rtk";case "F":return"rtk-float"}throw Error("INVALID FAA MODE: "+b);}function t(b,a){if("M"===a||""===a)return e(b); | ||
throw Error("Unknown unit: "+a);}function g(){if(!(this instanceof g))return new g;this.events={};this.state={errors:0,processed:0}}var m=Math.PI/180,p=[];g.prototype.events=null;g.prototype.state=null;g.mod={GGA:function(b,a){if(16!==a.length&&14!==a.length)throw Error("Invalid GGA length: "+b);return{time:k(a[1]),lat:l(a[2],a[3]),lon:l(a[4],a[5]),alt:t(a[9],a[10]),quality:x(a[6]),satellites:e(a[7]),hdop:e(a[8]),geoidal:t(a[11],a[12]),age:void 0===a[13]?null:e(a[13]),stationID:void 0===a[14]?null: | ||
e(a[14])}},GSA:function(b,a){if(19!==a.length&&20!==a.length)throw Error("Invalid GSA length: "+b);for(var d=[],c=3;15>c;c++)""!==a[c]&&d.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 Error("INVALID GSA MODE: "+c);}a:{var f=a[2];switch(f){case "1":case "":f=null;break a;case "2":f="2D";break a;case "3":f="3D";break a}throw Error("INVALID GSA FIX: "+f);}return{mode:c,fix:f,satellites:d,pdop:e(a[15]),hdop:e(a[16]), | ||
vdop:e(a[17]),systemId:19<a.length?e(a[18]):null}},RMC:function(b,a){if(13!==a.length&&14!==a.length&&15!==a.length)throw Error("Invalid RMC length: "+b);var d=k(a[1],a[9]),c=r(a[2]),f=l(a[3],a[4]),h=l(a[5],a[6]),y=q(a[7]),z=e(a[8]),u=a[10],v=a[11];return{time:d,status:c,lat:f,lon:h,speed:y,track:z,variation:""===u||""===v?null:parseFloat(u)*("W"===v?-1:1),faa:13<a.length?n(a[12]):null,navStatus:14<a.length?a[13]:null}},VTG:function(b,a){if(10!==a.length&&11!==a.length)throw Error("Invalid VTG length: "+ | ||
throw Error("Unknown unit: "+a);}function g(){if(!(this instanceof g))return new g;this.events={};this.state={errors:0,processed:0}}var m=Math.PI/180,p={},u={};g.prototype.events=null;g.prototype.state=null;g.mod={GGA:function(b,a){if(16!==a.length&&14!==a.length)throw Error("Invalid GGA length: "+b);return{time:k(a[1]),lat:l(a[2],a[3]),lon:l(a[4],a[5]),alt:t(a[9],a[10]),quality:y(a[6]),satellites:e(a[7]),hdop:e(a[8]),geoidal:t(a[11],a[12]),age:void 0===a[13]?null:e(a[13]),stationID:void 0===a[14]? | ||
null:e(a[14])}},GSA:function(b,a){if(19!==a.length&&20!==a.length)throw Error("Invalid GSA length: "+b);for(var d=[],c=3;15>c;c++)""!==a[c]&&d.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 Error("INVALID GSA MODE: "+c);}a:{var f=a[2];switch(f){case "1":case "":f=null;break a;case "2":f="2D";break a;case "3":f="3D";break a}throw Error("INVALID GSA FIX: "+f);}return{mode:c,fix:f,satellites:d,pdop:e(a[15]),hdop:e(a[16]), | ||
vdop:e(a[17]),systemId:19<a.length?e(a[18]):null}},RMC:function(b,a){if(13!==a.length&&14!==a.length&&15!==a.length)throw Error("Invalid RMC length: "+b);var d=k(a[1],a[9]),c=r(a[2]),f=l(a[3],a[4]),h=l(a[5],a[6]),z=q(a[7]),A=e(a[8]),v=a[10],w=a[11];return{time:d,status:c,lat:f,lon:h,speed:z,track:A,variation:""===v||""===w?null:parseFloat(v)*("W"===w?-1:1),faa:13<a.length?n(a[12]):null,navStatus:14<a.length?a[13]:null}},VTG:function(b,a){if(10!==a.length&&11!==a.length)throw Error("Invalid VTG length: "+ | ||
b);if(""===a[2]&&""===a[8]&&""===a[6])return{track:null,trackMagetic:null,speed:null,faa:null};if("T"!==a[2])throw Error("Invalid VTG track mode: "+b);if("K"!==a[8]||"N"!==a[6])throw Error("Invalid VTG speed tag: "+b);return{track:e(a[1]),trackMagnetic:""===a[3]?null:e(a[3]),speed:q(a[5]),faa:11===a.length?n(a[9]):null}},GSV:function(b,a){if(0===a.length%4%3)throw Error("Invalid GSV length: "+b);for(var d=[],c=4;c<a.length-3;c+=4){var f=e(a[c]),h=e(a[c+3]);d.push({prn:f,elevation:e(a[c+1]),azimuth:e(a[c+ | ||
@@ -20,4 +20,4 @@ 2]),snr:h,status:null!==f?null!==h?"tracking":"in view":null})}return{msgNumber:e(a[2]),msgsTotal:e(a[1]),satellites:d,signalId:2===a.length%4?e(a[a.length-2]):null}},GLL:function(b,a){if(9!==a.length&&8!==a.length)throw Error("Invalid GLL length: "+b);return{time:k(a[5]),status:r(a[6]),lat:l(a[1],a[2]),lon:l(a[3],a[4]),faa:9===a.length?n(a[7]):null}},ZDA:function(b,a){return{time:k(a[1],a[2]+a[3]+a[4])}},GST:function(b,a){if(10!==a.length)throw Error("Invalid GST length: "+b);return{time:k(a[1]), | ||
c,Math.cos(b)*Math.sin(d)-Math.sin(b)*c*Math.cos(a))/Math.PI+360)%360};g.Distance=function(b,a,d,c){var f=(d-b)*m*.5;a=(c-a)*m*.5;b*=m;d*=m;f=Math.sin(f);a=Math.sin(a);return 12745.6*Math.asin(Math.sqrt(f*f+Math.cos(b)*Math.cos(d)*a*a))};g.TotalDistance=function(b){if(2>b.length)return 0;for(var a=0,d=0;d<b.length-1;d++){var c=b[d],f=b[d+1];a+=g.Distance(c.lat,c.lon,f.lat,f.lon)}return a};g.prototype.update=function(b){b=g.Parse(b);this.state.processed++;if(!1===b)return this.state.errors++,!1;var a= | ||
this.state;if("RMC"===b.type||"GGA"===b.type||"GLL"===b.type||"GNS"===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 d=b.satellites,c=0;c<d.length;c++)p.push(d[c]);b.msgNumber===b.msgsTotal&&(a.satsVisible=p,p=[])}this.emit("data",b);this.emit(b.type,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};g.prototype.emit=function(b,a){void 0!==this.events[b]&&this.events[b].call(this,a)};"object"===typeof exports? | ||
(Object.defineProperty(exports,"__esModule",{value:!0}),g["default"]=g,g.GPS=g,module.exports=g):w.GPS=g})(this); | ||
this.state;if("RMC"===b.type||"GGA"===b.type||"GLL"===b.type||"GNS"===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 d=(new Date).getTime(),c=b.satellites,f=0;f<c.length;f++){var h=c[f].a;u[h]=d;p[h]=c[f]}c=[];for(h in p)3E3>d-u[h]&&c.push(p[h]);a.satsVisible=c}this.emit("data", | ||
b);this.emit(b.type,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};g.prototype.emit=function(b,a){void 0!==this.events[b]&& | ||
this.events[b].call(this,a)};"object"===typeof exports?(Object.defineProperty(exports,"__esModule",{value:!0}),g["default"]=g,g.GPS=g,module.exports=g):x.GPS=g})(this); |
{ | ||
"name": "gps", | ||
"title": "gps.js", | ||
"version": "0.5.3", | ||
"version": "0.6.0", | ||
"homepage": "https://www.xarg.org/2016/07/using-gps-with-node-js-and-javascript/", | ||
@@ -47,9 +47,9 @@ "bugs": "https://github.com/infusion/GPS.js/issues", | ||
"devDependencies": { | ||
"angles": "^0.2.0", | ||
"angles": "^0.2.4", | ||
"byline": "^5.0.0", | ||
"chai": "^4.1.0", | ||
"express": "^4.16.4", | ||
"mocha": "^5.2.0", | ||
"serialport": "^7.1.1", | ||
"socket.io": "^2.0.3", | ||
"chai": "^4.2.0", | ||
"express": "^4.17.1", | ||
"mocha": "^7.1.0", | ||
"serialport": "^8.0.7", | ||
"socket.io": "^2.3.0", | ||
"kalman": "0.0.2", | ||
@@ -56,0 +56,0 @@ "sylvester": "0.0.21" |
@@ -53,3 +53,3 @@ | ||
On Linux serial devices typically have names like `/dev/ttyS1`, on OSX `/dev/tty.usbmodem1411` after installing a USB to serial driver and on Windows, you're probably fine by using the highest COM device you can find in the device manager. Please note that if you have multople USB ports on your computer and use them randomly, you have to lookup the path/device again. | ||
On Linux serial devices typically have names like `/dev/ttyS1`, on OSX `/dev/tty.usbmodem1411` after installing a USB to serial driver and on Windows, you're probably fine by using the highest COM device you can find in the device manager. Please note that if you have multiple USB ports on your computer and use them randomly, you have to lookup the path/device again. | ||
@@ -71,3 +71,3 @@ Register device on a BeagleBone | ||
GPS.js comes with some examples, like drawing the current latutude and longitude to Google Maps, displaying a persistent state and displaying the parsed raw data. In some cases you have to adjust the serial path to your own GPS receiver to make it work. | ||
GPS.js comes with some examples, like drawing the current latitude and longitude to Google Maps, displaying a persistent state and displaying the parsed raw data. In some cases you have to adjust the serial path to your own GPS receiver to make it work. | ||
@@ -74,0 +74,0 @@ Simple serial example |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
387589
2313