/* https://github.com/infusion/GPS.js GPS.js v0.6.1 26/01/2016 Copyright (c) 2016, Robert Eisele (robert@xarg.org) Dual licensed under the MIT or GPL Version 2 licenses. */ (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={},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=c;c++){var f=e(a[c]);null!==f&&d.push(f)}return{time:k(a[1]),mode:e(a[2]),res:d}},GBS:function(b,a){if(10!==a.length&& 12!==a.length)throw Error("Invalid GBS length: "+b);return{time:k(a[1]),errLat:e(a[2]),errLon:e(a[3]),errAlt:e(a[4]),failedSat:e(a[5]),probFailedSat:e(a[6]),biasFailedSat:e(a[7]),stdFailedSat:e(a[8]),systemId:12===a.length?e(a[9]):null,signalId:12===a.length?e(a[10]):null}},GNS:function(b,a){if(14!==a.length&&15!==a.length)throw Error("Invalid GNS length: "+b);return{time:k(a[1]),lat:l(a[2],a[3]),lon:l(a[4],a[5]),mode:a[6],satsUsed:e(a[7]),hdop:e(a[8]),alt:e(a[9]),sep:e(a[10]),diffAge:e(a[11]),diffStation:e(a[12]), navStatus:15===a.length?a[13]:null}}};g.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!==g.mod[a[0]]){d=this.mod[a[0]](b,a);d.raw=b;for(var c=0,f=1;fb.length)return 0;for(var a=0,d=0;dd-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);if("$"===a.charAt(0))try{this.update(a)}catch(d){throw this.partial="",Error(d);}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(g,"__esModule",{value:!0}),g["default"]=g,g.GPS=g,module.exports=g):x.GPS=g})(this);