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.4.3 to 0.4.4

2

bower.json
{
"name": "gps",
"main": "gps.js",
"version": "0.4.3",
"version": "0.4.4",
"homepage": "https://github.com/infusion/GPS.js",

@@ -6,0 +6,0 @@ "description": "A GPS NMEA parser library",

@@ -9,3 +9,3 @@

//var file = '/dev/tty.usbserial';
const file = '/dev/tty.usbmodem1411';
const file = '/dev/tty.usbmodem1421';

@@ -31,2 +31,4 @@ const SerialPort = require('serialport');

var gps = new GPS;
gps.state.bearing = 0;
var prev = {lat: null, lon: null};

@@ -38,3 +40,9 @@ http.listen(3000, function() {

gps.on('data', function() {
if (prev.lat !== null && prev.lon !== null) {
gps.state.bearing = GPS.Heading(prev.lat, prev.lon, gps.state.lat, gps.state.lon);
}
io.emit('state', gps.state);
prev.lat = gps.state.lat;
prev.lon = gps.state.lon;
;
});

@@ -41,0 +49,0 @@

/**
* @license GPS.js v0.4.3 26/01/2016
* @license GPS.js v0.4.4 26/01/2016
*

@@ -71,2 +71,8 @@ * Copyright (c) 2016, Robert Eisele (robert@xarg.org)

/**
*
* @param {String} time
* @param {String=} date
* @returns {Date}
*/
function parseTime(time, date) {

@@ -87,3 +93,3 @@

if (year.length === 4) {
ret.setUTCFullYear(year, month, day);
ret.setUTCFullYear(Number(year), Number(month), Number(day));
} else {

@@ -93,9 +99,9 @@ // If we need to parse older GPRMC data, we should hack something like

// Since GPS appeared in 1973
ret.setUTCFullYear('20' + year, month, day);
ret.setUTCFullYear(Number('20' + year), Number(month), Number(day));
}
}
ret.setUTCHours(time.slice(0, 2));
ret.setUTCMinutes(time.slice(2, 4));
ret.setUTCSeconds(time.slice(4, 6));
ret.setUTCHours(Number(time.slice(0, 2)));
ret.setUTCMinutes(Number(time.slice(2, 4)));
ret.setUTCSeconds(Number(time.slice(4, 6)));

@@ -109,3 +115,3 @@ // Extract the milliseconds, since they can be not present, be 3 decimal place, or 2 decimal places, or other?

}
ret.setUTCMilliseconds(ms);
ret.setUTCMilliseconds(Number(ms));

@@ -287,3 +293,6 @@ return ret;

/**
*
* @constructor
*/
function GPS() {

@@ -713,3 +722,3 @@

updateState(this.state, parsed);
updateState(this['state'], parsed);

@@ -768,3 +777,6 @@ this['emit']('data', parsed);

if (typeof exports === 'object') {
module.exports = GPS;
Object.defineProperty(exports, "__esModule", {'value': true});
module['exports'] = GPS;
exports['Angles'] = GPS;
exports['default'] = GPS;
} else {

@@ -771,0 +783,0 @@ root['GPS'] = GPS;

/*
GPS.js v0.4.3 26/01/2016
GPS.js v0.4.4 26/01/2016
Copyright (c) 2016, Robert Eisele (robert@xarg.org)
Dual licensed under the MIT or GPL Version 2 licenses.
Copyright (c) 2016, Robert Eisele (robert@xarg.org)
Dual licensed under the MIT or GPL Version 2 licenses.
*/
'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);
(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: "+
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
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]),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 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 g=a[2];switch(g){case "1":case "":g=null;break a;case "2":g="2D";break a;case "3":g="3D";break a}throw Error("INVALID GSA FIX: "+g);}return{mode:c,fix:g,satellites:d,pdop:e(a[15]),hdop:e(a[16]),vdop:e(a[17])}},RMC:function(b,a){if(13!==a.length&&14!==a.length)throw Error("Invalid RMC length: "+b);var d=l(a[1],a[9]),c=p(a[2]),g=a[10],f=a[11];return{time:d,
status:c,lat:k(a[3],a[4]),lon:k(a[5],a[6]),speed:n(a[7]),track:e(a[8]),variation:""===g||""===f?null:parseFloat(g)*("W"===f?-1:1),faa:14===a.length?q(a[12]):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: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}),module.exports=f,exports.Angles=f,exports["default"]=f):t.GPS=f})(this);
{
"name": "gps",
"title": "gps.js",
"version": "0.4.3",
"version": "0.4.4",
"homepage": "https://github.com/infusion/GPS.js",

@@ -6,0 +6,0 @@ "bugs": "https://github.com/infusion/GPS.js/issues",

Sorry, the diff of this file is not supported yet

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