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

@nextlvlup/ubx-parser

v2.0.0

Published

A parser for the GNSS protocol ubx. Developed and tested with a ublox M9L GPS module.

Downloads

44

Readme

UBX Parser

A parser for the GNSS protocol ubx. Developed and tested with a ublox M9L GPS module.

npm install @nextlvlup/ubx-parser

This library was created based on the documentation provided by ublox. Interface Description Integration Manual

Very basic usage example

import { UBXParser } from "@nextlvlup/ubx-parser";

// Create Parser Instance
const parser = new UBXParser();

// Add Event Listener
parser.on("warning", (warning, buffer) => console.warn(warning));
parser.on("error", (error, buffer) => console.error(error));
parser.on("data", (data, buffer) => console.log(data));

the buffer object contains the raw data packet.

Example over TCP/IP

If you want to provide the GNSS data from a local Linux device via TCP you can do this with the following command. socat -d -d tcp-l:1234 file://dev/ttyS0,b460800,raw

This command starts a TCP server and serves as a gateway between the local serial port ttyS0 and the TCP client.

import { Socket } from "net";
import { UBXParser } from "@nextlvlup/ubx-parser";

const client = new Socket();
const parser = new UBXParser();

client.connect({ host: "localhost", port: 1234 }, () => console.log("connected"));

// Pass data to the parser
client.on("data", (buffer) => parser.parse(buffer));
// Receiving parsed data
parser.on("data", (data) => console.log(data));

Example over SerialPort

import { SerialPort } from "serialport";
import { UBXParser } from "@nextlvlup/ubx-parser";

const serialport = new SerialPort({ path: "/dev/ttyS0", baudRate: 460800 }, () => console.log("gps connected"));
const parser = new UBXParser();

// Pass data to the parser
port.on("data", (buffer) => parser.parse(buffer));
// Receiving parsed data
parser.on("data", (data) => console.log(data));

Data Object

The object returned in the data listener always contains a packet_class and a packet_id. These are used to identify what kind of packet it is. The remaining fields are packet-type dependent.

| Field | Type | Example | | ------------ | ----- | ------- | | packet_class | uint8 | 0x01 | | packet_id | uint8 | 0x07 | | ... | ... | ... |

Create Custom Packet-Parser

You can also create your own packet parser if you need a packet that is not yet supported by this library.

import { UBXParser, readBitFromUInt8, readBitFromUInt16, readBitFromUInt32 } from "@nextlvlup/ubx-parser";

export class CustomParser extends PacketParser {
    constructor() {
        // pass packet_class and packet_id for identification
        super(0x01, 0x07);
    }

    parse(payload: Buffer): CustomData {
        return {
            // read uint32 starting at byte 0
            iTOW: payload.readUInt32LE(0),
            // read uint16 starting at byte 4
            year: payload.readUInt16LE(4),
            // read uint8 starting at byte 6
            month: payload.readUInt8(6),
            // read bit 0 from uint8 byte 7
            validDate: readBitFromUInt8(payload.readUInt8(7), 0),
            // read bit 0 from uint16 byte 8
            invalidLlh: readBitFromUInt16(payload.readUInt16LE(8), 0),
            // read bit 24 - 29 from uint32 byte 10
            dataType: readBitFromUInt32(payload.readUInt32LE(10), 24, 6),
        };
    }
}

export interface CustomData {
    iTOW: number;
    year: number;
    month: number;
    validDate: number;
    invalidLlh: number;
    dataType: number;
}

Then the CustomParser can be registered in the UBXParser instance.

import { UBXParser } from "@nextlvlup/ubx-parser";
import { CustomParser } from "path/to/your/CustomParser";

const parser = new UBXParser();
parser.registerParser(new CustomParser());