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.0.7 to 0.0.8

tests/partial.js

2

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

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

@@ -28,13 +28,9 @@

port.on('open', function() {
console.log('GPS listening');
gps.on('data', function(raw, data) {
io.emit('state', gps.state);
});
gps.on('data', function(raw, data) {
io.emit('state', gps.state);
});
port.on('data', function(data) {
gps.update(data);
});
port.on('data', function(data) {
gps.update(data);
});
});

@@ -18,5 +18,5 @@

stream.on('data', function(line) {
stream.on('data', function(data) {
gps.update(line.toString());
gps.update(data.toString());
});

@@ -19,14 +19,8 @@

gps.on('data', function(data) {
ws.write(data.raw + '\n');
});
port.on('open', function() {
console.log('serial port open');
gps.on('data', function(data) {
ws.write(data.raw + '\n');
});
port.on('data', function(data) {
gps.update(data);
});
port.on('data', function(data) {
gps.update(data);
});

@@ -12,3 +12,3 @@

var SerialPort = require('serialport');
var serialPort = new SerialPort.SerialPort(file, {
var port = new SerialPort.SerialPort(file, {
baudrate: 4800,

@@ -32,9 +32,6 @@ parser: SerialPort.parsers.readline('\r\n')

console.log('listening on *:3000');
});
serialPort.on('open', function() {
console.log('GPS listening');
serialPort.on('data', function(data) {
gps.update(data);
});
});
port.on('data', function(data) {
gps.update(data);
});

@@ -16,13 +16,8 @@

port.on('open', function() {
gps.on('data', function(data) {
console.log(data);
});
console.log('serial port open');
gps.on('data', function(data) {
console.log(data);
});
port.on('data', function(data) {
gps.update(data);
});
port.on('data', function(data) {
gps.update(data);
});

@@ -17,13 +17,8 @@

port.on('open', function() {
gps.on('data', function(data) {
console.log(gps.state);
});
console.log('serial port open');
gps.on('data', function(data) {
console.log(gps.state);
});
port.on('data', function(data) {
gps.update(data);
});
port.on('data', function(data) {
gps.update(data);
});
/**
* GPS.js v0.0.7 26/01/2016
* GPS.js v0.0.8 26/01/2016
*

@@ -91,3 +91,3 @@ * Copyright (c) 2016, Robert Eisele (robert@xarg.org)

function parseCoord(coord, dir) {
// Latitude can go from 0 to 90; longitude can go from 0 to 180.

@@ -261,6 +261,8 @@

function GPS() {
this['events'] = {};
this['state'] = {};
}
GPS.prototype['events'] = {};
GPS.prototype['state'] = {};
GPS.prototype['events'] = null;
GPS.prototype['state'] = null;

@@ -522,3 +524,3 @@ GPS['mod'] = {

*/
// TODO: incorporate local zone information

@@ -534,3 +536,3 @@

GPS.parse = function(line) {
GPS['Parse'] = function(line) {

@@ -567,6 +569,36 @@ if (typeof line !== 'string')

GPS['Bearing'] = function(lat1, lon1, lat2, lon2) {
var BearingRad = Math.atan2((Math.sin(lon2 - lon1) * Math.cos(lat2)),
Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) *
Math.cos(lat2) * Math.cos(lon2 - lon1));
var CalBearing = 180.0 * BearingRad / Math.PI;
return (CalBearing + 360) % 360;
};
GPS['Distance'] = function(lat1, lon1, lat2, lon2) {
// Haversine Formula
// var RADIUS = 6371; // Earth radius average
// var RADIUS = 6378.137; // Earth radius at equator
var RADIUS = 6372.8; // Earth radius in km
var d2r = Math.PI / 180;
var hLat = (lat2 - lat1) * d2r * 0.5; // Half of lat difference
var hLon = (lon2 - lon1) * d2r * 0.5; // Half of lon difference
var tmp = Math.sin(hLat) * Math.sin(hLat) +
Math.cos(lat1 * d2r) * Math.cos(lat2 * d2r) * Math.sin(hLon) * Math.sin(hLon);
//return RADIUS * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1.0 - a));
return RADIUS * 2 * Math.asin(Math.sqrt(tmp));
};
GPS.prototype['update'] = function(line) {
var parsed = GPS.parse(line);
var parsed = GPS['Parse'](line);

@@ -588,2 +620,24 @@ if (parsed === false)

GPS.prototype['partial'] = "";
GPS.prototype['updatePartial'] = function(chunk) {
this['partial'] += chunk;
while (true) {
var pos = this['partial'].indexOf("\r\n");
if (pos === -1)
break;
var line = this['partial'].slice(0, pos);
if (line.charAt(0) === '$') {
this['update'](line);
}
this['partial'] = this['partial'].slice(pos + 2);
}
};
GPS.prototype['on'] = function(ev, cb) {

@@ -606,33 +660,2 @@

GPS['Bearing'] = function(lat1, lon1, lat2, lon2) {
var BearingRad = Math.atan2((Math.sin(lon2 - lon1) * Math.cos(lat2)),
Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) *
Math.cos(lat2) * Math.cos(lon2 - lon1));
var CalBearing = 180.0 * BearingRad / Math.PI;
return (CalBearing + 360) % 360;
};
GPS['Distance'] = function(lat1, lon1, lat2, lon2) {
// Haversine Formula
// var RADIUS = 6371; // Earth radius average
// var RADIUS = 6378.137; // Earth radius at equator
var RADIUS = 6372.8; // Earth radius in km
var d2r = Math.PI / 180;
var hLat = (lat2 - lat1) * d2r * 0.5; // Half of lat difference
var hLon = (lon2 - lon1) * d2r * 0.5; // Half of lon difference
var tmp = Math.sin(hLat) * Math.sin(hLat) +
Math.cos(lat1 * d2r) * Math.cos(lat2 * d2r) * Math.sin(hLon) * Math.sin(hLon);
//return RADIUS * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1.0 - a));
return RADIUS * 2 * Math.asin(Math.sqrt(tmp));
};
if (typeof exports === 'object') {

@@ -639,0 +662,0 @@ module.exports = GPS;

{
"name": "gps",
"title": "gps.js",
"version": "0.0.7",
"version": "0.0.8",
"homepage": "https://github.com/infusion/GPS.js",

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

@@ -70,11 +70,8 @@

port.on('open', function() {
gps.on('data', function(data) {
console.log(data, gps.state);
});
gps.on('data', function(data) {
console.log(data, gps.state);
});
port.on('data', function(data) {
gps.update(data);
});
port.on('data', function(data) {
gps.update(data);
});

@@ -108,5 +105,24 @@ ```

Protocols
Available Methods
===
update(line)
---
The update method is the most important function, it adds a new NMEA sentence and forces the callback to trigger
updatePartial(chunk)
---
Will call `update()` when a full NMEA sentence has been arrived
on(event, callback)
---
Adds an event listener for a protocol to occur (see implemented protocols, simply use the name - upper case) or for all sentences with `data`. Because GPS.js should be more general, it doesn't inherit `EventEmitter`, but simply invokes the callback.
off(event)
---
Removes an event listener
Implemented Protocols
===
GGA - Fix information

@@ -230,2 +246,6 @@ ---

GPS.Parse(line)
---
Parses a single line and returns the resulting object, in case the callback system isn't needed/wanted
GPS.Distance(latFrom, lonFrom, latTo, lonTo)

@@ -232,0 +252,0 @@ ---

@@ -7,3 +7,3 @@

var today = new Date();
today = today.getFullYear() + '-' + _(today.getMonth() + 1) + '-' + _(today.getDate());
today = today.getUTCFullYear() + '-' + _(today.getUTCMonth() + 1) + '-' + _(today.getUTCDate());

@@ -80,3 +80,3 @@ var expect = require('chai').expect;

'type': 'GGA',
'valid': true,
'valid': true
},

@@ -83,0 +83,0 @@ '$GPGGA,123519,4807.038,N,01131.324,E,1,08,0.9,545.4,M,46.9,M,,': 'invalid',

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