Comparing version 0.4.7 to 0.4.8
{ | ||
"name": "gps", | ||
"main": "gps.js", | ||
"version": "0.4.7", | ||
"version": "0.4.8", | ||
"homepage": "https://github.com/infusion/GPS.js", | ||
@@ -6,0 +6,0 @@ "description": "A GPS NMEA parser library", |
59
gps.js
/** | ||
* @license GPS.js v0.4.7 26/01/2016 | ||
* @license GPS.js v0.4.8 26/01/2016 | ||
* | ||
@@ -182,22 +182,23 @@ * Copyright (c) 2016, Robert Eisele (robert@xarg.org) | ||
function parseGGAFix(fix) { | ||
var int = parseInt(fix, 10); | ||
switch (fix) { | ||
switch (int || fix) { | ||
case '': | ||
case '0': | ||
case 0: | ||
return null; | ||
case '1': | ||
case 1: | ||
return 'fix'; // valid SPS fix | ||
case '2': | ||
case 2: | ||
return 'dgps-fix'; // valid DGPS fix | ||
case '3': | ||
case 3: | ||
return 'pps-fix'; // valid PPS fix | ||
case '4': | ||
case 4: | ||
return 'rtk'; // valid RTK fix | ||
case '5': | ||
case 5: | ||
return 'rtk-float'; // valid RTK float | ||
case '6': | ||
case 6: | ||
return 'estimated'; | ||
case '7': | ||
case 7: | ||
return 'manual'; | ||
case '8': | ||
case 8: | ||
return 'simulated'; | ||
@@ -515,2 +516,9 @@ } | ||
/* | ||
Plot satellites in Radar chart with north on top | ||
by linear map elevation from 0° to 90° into r to 0 | ||
centerX + cos(azimuth - 90) * (1 - elevation / 90) * radius | ||
centerY + sin(azimuth - 90) * (1 - elevation / 90) * radius | ||
*/ | ||
sats.push({ | ||
@@ -610,4 +618,28 @@ 'prn': prn, | ||
}; | ||
}, | ||
// add HDT | ||
'HDT': function (str, hdt) { | ||
if (hdt.length !== 4) { | ||
throw new Error('Invalid HDT length: ' + str); | ||
} | ||
/* | ||
------------------------------------------------------------------------------ | ||
1 2 3 | ||
| | | | ||
$--HDT,hhh.hhh,T*XX<CR><LF> | ||
------------------------------------------------------------------------------ | ||
1. Heading in degrees | ||
2. T: indicates heading relative to True North | ||
3. Checksum | ||
*/ | ||
return { | ||
'heading': parseFloat(hdt[1]), | ||
'trueNorth': hdt[2] === 'T' | ||
}; | ||
} | ||
}; | ||
@@ -624,3 +656,4 @@ | ||
if (nmea.length < 4 || line.charAt(0) !== '$' || last.indexOf('*') === -1) { | ||
// HDT is 2 items length | ||
if (nmea.length < 2 || line.charAt(0) !== '$' || last.indexOf('*') === -1) { | ||
return false; | ||
@@ -627,0 +660,0 @@ } |
/* | ||
GPS.js v0.4.7 26/01/2016 | ||
GPS.js v0.4.8 26/01/2016 | ||
@@ -8,3 +8,3 @@ Copyright (c) 2016, Robert Eisele (robert@xarg.org) | ||
(function(t){function l(b,a){if(""===b)return null;var d=new Date;if(a){var c=a.slice(4),g=a.slice(2,4)-1,e=a.slice(0,2);4===c.length?d.setUTCFullYear(Number(c),Number(g),Number(e)):d.setUTCFullYear(Number("20"+c),Number(g),Number(e))}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);g=c.length;e=0;0!==g&&(e=parseFloat(c)*Math.pow(10,3-g));d.setUTCMilliseconds(Number(e));return d}function k(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 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 Error("INVALID GGA FIX: "+ | ||
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 n(b){return""===b?null:1.852*parseFloat(b)}function u(b){switch(parseInt(b,10)||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 Error("INVALID GGA FIX: "+ | ||
b);}function p(b){switch(b){case "A":return"active";case "V":return"void";case "":return null}throw Error("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 Error("INVALID FAA MODE: "+b);}function r(b,a){if("M"===a||""===a)return e(b);throw Error("Unknown unit: "+a);}function f(){if(!(this instanceof | ||
@@ -15,6 +15,6 @@ f))return new 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 Error("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]),satellites: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 Error("Invalid GSA length: "+b);for(var d=[],c=3;15>c;c++)""!==a[c]&&d.push(parseInt(a[c], | ||
a[3]?null:e(a[3]),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 Error("Invalid GSV length: "+b);for(var d=[],c=4;c<a.length-1;c+=4){var g=e(a[c]),f=e(a[c+3]);d.push({prn:g,elevation:e(a[c+1]),azimuth:e(a[c+2]),snr:f,status:null!==g?null!==f?"tracking":"in view":null})}return{msgNumber:e(a[2]),msgsTotal:e(a[1]),satellites:d}},GLL:function(b,a){if(9!==a.length)throw Error("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])}},GST:function(b,a){if(10!==a.length)throw Error("Invalid GST length: "+b);return{time:l(a[1]),rms:e(a[2]),ellipseMajor:e(a[3]),ellipseMinor:e(a[4]),ellipseOrientation:e(a[5]),latitudeError:e(a[6]),longitudeError:e(a[7]),heightError:e(a[8])}}};f.Parse=function(b){if("string"!==typeof b)return!1;var a=b.split(","),d=a.pop();if(4>a.length||"$"!==b.charAt(0)||-1===d.indexOf("*"))return!1;d=d.split("*");a.push(d[0]);a.push(d[1]); | ||
a[0]=a[0].slice(3);if(void 0!==f.mod[a[0]]){d=this.mod[a[0]](b,a);d.raw=b;for(var c=0,e=1;e<b.length;e++){var h=b.charCodeAt(e);if(42===h)break;c^=h}d.valid=c===parseInt(a[a.length-1],16);d.type=a[0];return d}return!1};f.Heading=function(b,a,d,c){a=(c-a)*h;b*=h;d*=h;c=Math.cos(d);return(180*Math.atan2(Math.sin(a)*c,Math.cos(b)*Math.sin(d)-Math.sin(b)*c*Math.cos(a))/Math.PI+360)%360};f.Distance=function(b,a,d,c){var e=(d-b)*h*.5;a=(c-a)*h*.5;b*=h;d*=h;e=Math.sin(e);a=Math.sin(a);return 12745.6*Math.asin(Math.sqrt(e* | ||
e+Math.cos(b)*Math.cos(d)*a*a))};f.TotalDistance=function(b){if(2>b.length)return 0;for(var a=0,d=0;d<b.length-1;d++){var c=b[d],e=b[d+1];a+=f.Distance(c.lat,c.lon,e.lat,e.lon)}return 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 d=b.satellites,c=0;c<d.length;c++)m.push(d[c]);b.msgNumber===b.msgsTotal&&(a.satsVisible=m,m=[])}this.emit("data",b);this.emit(b.type,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};f.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}),f["default"]=f,f.GPS=f,module.exports=f):t.GPS=f})(this); | ||
lon:k(a[3],a[4])}},ZDA:function(b,a){return{time:l(a[1],a[2]+a[3]+a[4])}},GST:function(b,a){if(10!==a.length)throw Error("Invalid GST length: "+b);return{time:l(a[1]),rms:e(a[2]),ellipseMajor:e(a[3]),ellipseMinor:e(a[4]),ellipseOrientation:e(a[5]),latitudeError:e(a[6]),longitudeError:e(a[7]),heightError:e(a[8])}},HDT:function(b,a){if(4!==a.length)throw Error("Invalid HDT length: "+b);return{heading:parseFloat(a[1]),trueNorth:"T"===a[2]}}};f.Parse=function(b){if("string"!==typeof b)return!1;var a= | ||
b.split(","),d=a.pop();if(2>a.length||"$"!==b.charAt(0)||-1===d.indexOf("*"))return!1;d=d.split("*");a.push(d[0]);a.push(d[1]);a[0]=a[0].slice(3);if(void 0!==f.mod[a[0]]){d=this.mod[a[0]](b,a);d.raw=b;for(var c=0,e=1;e<b.length;e++){var h=b.charCodeAt(e);if(42===h)break;c^=h}d.valid=c===parseInt(a[a.length-1],16);d.type=a[0];return d}return!1};f.Heading=function(b,a,d,c){a=(c-a)*h;b*=h;d*=h;c=Math.cos(d);return(180*Math.atan2(Math.sin(a)*c,Math.cos(b)*Math.sin(d)-Math.sin(b)*c*Math.cos(a))/Math.PI+ | ||
360)%360};f.Distance=function(b,a,d,c){var e=(d-b)*h*.5;a=(c-a)*h*.5;b*=h;d*=h;e=Math.sin(e);a=Math.sin(a);return 12745.6*Math.asin(Math.sqrt(e*e+Math.cos(b)*Math.cos(d)*a*a))};f.TotalDistance=function(b){if(2>b.length)return 0;for(var a=0,d=0;d<b.length-1;d++){var c=b[d],e=b[d+1];a+=f.Distance(c.lat,c.lon,e.lat,e.lon)}return 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 d=b.satellites,c=0;c<d.length;c++)m.push(d[c]);b.msgNumber===b.msgsTotal&&(a.satsVisible=m,m=[])}this.emit("data",b);this.emit(b.type,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};f.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}),f["default"]=f,f.GPS=f,module.exports=f):t.GPS=f})(this); |
{ | ||
"name": "gps", | ||
"title": "gps.js", | ||
"version": "0.4.7", | ||
"version": "0.4.8", | ||
"homepage": "https://github.com/infusion/GPS.js", | ||
@@ -23,3 +23,4 @@ "bugs": "https://github.com/infusion/GPS.js/issues", | ||
"vtg", | ||
"gva" | ||
"gva", | ||
"hdt" | ||
], | ||
@@ -50,6 +51,6 @@ "author": "Robert Eisele <robert@xarg.org> (http://www.xarg.org/)", | ||
"express": "^4.15.3", | ||
"mocha": "^3.5.0", | ||
"serialport": "^5.0.0", | ||
"mocha": "^5.2.0", | ||
"serialport": "^7.1.1", | ||
"socket.io": "^2.0.3" | ||
} | ||
} |
@@ -454,2 +454,18 @@ | ||
}, | ||
// test with two digits on quality | ||
'$GPGGA,174815.40,4141.46474,N,00849.77225,W,05,08,1.24,11.8,M,50.5,M,,*42': { | ||
'age': null, | ||
'alt': 11.8, | ||
'geoidal': 50.5, | ||
'hdop': 1.24, | ||
'quality': 'rtk-float', | ||
'satellites': 8, | ||
'stationID': null, | ||
'lat': 41.691079, | ||
'lon': -8.8295375, | ||
'time': new Date(today+'T17:48:15.400Z'), | ||
'raw': '$GPGGA,174815.40,4141.46474,N,00849.77225,W,05,08,1.24,11.8,M,50.5,M,,*42', | ||
'type': 'GGA', | ||
'valid': true, | ||
}, | ||
'$GPGST,172814.0,0.006,0.023,0.020,273.6,0.023,0.020,0.031*6A': { | ||
@@ -494,2 +510,10 @@ 'time': new Date(today+'T17:28:14.000Z'), | ||
}, | ||
// add hdt test | ||
'$HEHDT,066.2,T*2D': { | ||
'heading': 66.2, | ||
'raw': '$HEHDT,066.2,T*2D', | ||
'trueNorth': true, | ||
'type': 'HDT', | ||
'valid': true | ||
} | ||
}; | ||
@@ -496,0 +520,0 @@ var collect = {}; |
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
364741
1581