Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
GPS.js is an extensible parser for NMEA sentences, given by any common GPS receiver. The output is tried to be as high-level as possible to make it more useful than simply splitting the information. The aim is, that you don't have to understand NMEA, just plug in your receiver and you're ready to go.
The interface of GPS.js is as simple as the following few lines. You need to add an event-listener for the completion of the task and invoke the update method with a sentence you want to process. There are much more examples in the examples folder.
const gps = new GPS;
// Add an event listener on all protocols
gps.on('data', parsed => {
console.log(parsed);
});
// Call the update routine directly with a NMEA sentence, which would
// come from the serial port or stream-reader normally
gps.update("$GPGGA,224900.000,4832.3762,N,00903.5393,E,1,04,7.8,498.6,M,48.0,M,,0000*5E");
It's also possible to add event-listeners only on one of the following protocols, by stating gps.on('GGA', ...)
for example.
The real advantage over other NMEA implementations is, that the GPS information is interpreted and normalized. The most high-level API is the state object, which changes with every new event. You can use this information with:
gps.on('data', () => {
console.log(gps.state);
});
Installing GPS.js is as easy as cloning this repo or use the following command:
npm install gps
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.
If you find yourself on a BeagleBone, the serial device must be registered manually. Luckily, this can be done within node quite easily using octalbonescript:
const obs = require('octalbonescript');
obs.serial.enable('/dev/ttyS1', () => {
console.log('serial device activated');
});
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.
const SerialPort = require('serialport');
const GPS = require('gps');
const port = new SerialPort('/dev/tty.usbmodem11401', { // change path
baudRate: 9600,
parser: new SerialPort.parsers.Readline({
delimiter: '\r\n'
})
});
const gps = new GPS;
gps.on('data', data => {
console.log(data, gps.state);
})
port.on('data', data => {
gps.updatePartial(data);
})
Go into the folder examples/dashboard
and start the server with
node server
After that you can open the browser and go to http://localhost:3000. The result should look like the following, which in principle is just a visualization of the state object gps.state
Go into the folder examples/maps
and start the server with
node server
After that you can open the browser and go to http://localhost:3000 The result should look like
Confluence is a project, which tries to travel to and document all integer GPS coordinates. GPS.js can assist on that goal. Go into the examples folder and run:
node confluence
You should see something like the following, updating as you move around
You are at (48.53, 9.05951),
The closest confluence point (49, 9) is in 51.36 km.
You have to go 355.2° N
On systems without a RTC - like Raspberry PI - you need to update the time yourself at runtime. If the device has an internet connection, it's quite easy to use an NTP server. An alternative for disconnected projects with access to a GPS receiver can be the high-precision time signal, sent by satellites. Go to the examples folder and run the following to update the time:
node set-date
The update method is the most important function, it parses a NMEA sentence and forces the callbacks to trigger
Will call update()
when a full NMEA sentence has been arrived
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.
Removes an event listener
Gets the data, you're most probably looking for: latitude and longitude
The parsed object will have the following attributes:
Similar to GGA but gives also delivers the velocity
The parsed object will have the following attributes:
The parsed object will have the following attributes:
The parsed object will have the following attributes:
GSV messages are paginated. msgNumber
indicates the current page and msgsTotal
is the total number of pages.
The parsed object will have the following attributes:
The parsed object will have the following attributes:
The parsed object will have the following attributes:
The parsed object will have the following attributes:
The parsed object will have the following attributes:
If the streaming API is not needed, but a solid state of the system, the gps.state
object can be used. It has the following properties:
Adding new protocols is a matter of minutes. If you need a protocol which isn't implemented, I'm happy to see a pull request or a new ticket.
If you don't get valid position information after turning on the receiver, chances are high you simply have to wait as it takes some time to first fix.
GPS.js comes with a few static functions, which helps working with geo-coordinates.
Parses a single line and returns the resulting object, in case the callback system isn't needed/wanted
Calculates the distance between two geo-coordinates using Haversine formula
Calculates the length of a traveled route, given as an array of {lat: x, lon: y} point objects
Calculates the angle from one coordinate to another. Heading is represented as windrose coordinates (N=0, E=90, S=189, W=270). The result can be used as the argument of angles compass()
method:
const angles = require('angles');
console.log(angles.compass(GPS.Heading(50, 10, 51, 9))); // will return x ∈ { N, S, E, W, NE, ... }
The use cases should be rare to parse NMEA directly inside the browser, but it works too.
<script src="gps.min.js"></script>
<script>
var gps = new GPS;
gps.update('...');
</script>
After cloning the Git repository run:
npm install
npm run build
Testing the source against the shipped test suite is as easy as
npm run test
Copyright (c) 2024, Robert Eisele Licensed under the MIT license.
FAQs
A GPS NMEA parser library
We found that gps demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.