npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

pmtk

v0.1.2

Published

Send pmtk commands to a serial gps device.

Downloads

9

Readme

PMTK

PMTK writes GPS PMTK commands to a GPS via a serial port.

Usage

var PMTK = require('pmtk');
var pmtk = new PMTK('/dev/ttyO1', 'detect', function (err) {
    if (err) {
        console.log('There was an error: ', err);
    } else {
        pmtk.commands.test(handleResponse);
    }
});

function handleResponse(err, result) {
    if (err) {
        console.log('Error: ', err);
    } else {
        // Prints something like: "Success: $PMTK001,0,3*30"
        console.log('Success: ', result);   
    }
}

The Details

All command callbacks are standard: callback(err, result). Where:

  • err: is an error, which could be serialport error, PTMK checksum error, or validation error.
  • result is the PMTK response sentence.

new PMTK(device, baudrate, callback)

Returns a PMTK object that can be used to probe the GPS. Where:

  • device: The serial device. This will not be opened, it will only be opened when a command is sent, then it will be closed again.
  • baudrate: A valid baudrate (e.g. 4800, 9600, ...), or 'detect'. If 'detect' is used, then the baudrate will be automatically detected, this may take a few seconds.
  • callback: A standard callback.

pmtk.commands.test(callback)

Send the PMTK 000 command. It should always respond with success.

pmtk.commands.setBaudrate(baudrate, callback)

This will use the PMTK 251 command to set the baudrate of the device. baudrate must be a number. You should consult the documentation for your device, but valid baudrates for some devices are: 0 (default setting), 4800, 9600, 14400, 19200, 38400, 57600, 115200, 230400, 460800, 921600. Make sure both your GPS and local serialport can handle those baudrates.

Important Note: On success this will actually cause an error. The reason is that the baudrate of the serial port on the GPS device has changed and it will not detect the success PTMK setence. You will need to create a new PMTK object.

Example:

pmtk.commands.setBaudrate(115200, function(err, result) {
    if (err) {
        console.log('Error: ', err);
    }
});

pmtk.commands.setNmeaOutput(nmeaTokens, callback)

This will use the PMTK 314 command to set the NMEA sentences that the GPS device will output.

nmeaTokens is an array of strings. Current valid values are:

  • 'GLL': Lat/Lon data
  • 'RMC': Recommended minimum data for gps
  • 'VTG': Vector track an Speed over the Ground
  • 'GGA': Fix information
  • 'GSA': Overall Satellite data
  • 'GSV': Detailed Satellite data
  • 'ZDA': Date and Time

Example:

pmtk.commands.setNmeaOutput(['RMC', 'ZDA'], function (err, result) {
    if (err) {
        console.log('Error: ', err);
    }
});

pmtk.commands.resetNmeaOutput(callback)

This will use the PMTK 314 command to set the NMEA output sentences to default.

pmtk.commands.setNmeaOutputRate(time, callback)

This will use the PMTK 220 command to set the rate at which NMEA sentances are output by of the GPS device.

time is a number in milliseconds, so to have a rate of 1 per second (1 Hz), set time to 1000. A rate of 10 Hz would be 100.

Example:

pmtk.commands.setNmeaOutputRate(100, function (err, result) {
    if (err) {
        console.log('Error: ', err);
    }
});

pmtk.commands.custom(pmtkSentence, callback)

This will use the custom pmtkSentence. The callback will always return the value, a checksum will not occur. You must only include the characters between the $ and *, these will be added automatically, as well as the checksum calcualted.

Example:

pmtk.commands.custom('PMTK251,38400', function (err, result) {
    if (err) {
        console.log('Error: ', err);
    }
});