A parser for the GNSS protocol ubx. Developed and tested with a ublox M9L GPS module.
This library was created based on the documentation provided by ublox. Interface Description Integration Manual
Install the package:
# ✨ Auto-detect (supports npm, yarn, pnpm, deno and bun)
npx nypm install @nextlvlup/ubx-parser
# npm
npm install @nextlvlup/ubx-parser
# pnpm
pnpm install @nextlvlup/ubx-parserimport { createParser } from "@nextlvlup/ubx-parser";
import { UBX_NAV_PVT } from "@nextlvlup/ubx-parser/message";
const parser = createParser();
// callback with error and respective buffer
parser.hooks.hook("error", (err, buf) => console.log(err, buf));
// callback with packets as raw buffer
parser.hooks.hook("data", (data) => console.log(data));
// attach UBX-NAV-PVT Parser and listen for packets
// callback with fully typed UBX-NAV-PVT packets
parser.attach(UBX_NAV_PVT).hook((data) => console.log(data));
parser.parse(/** Input Buffer */);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 "node:net";
import { createParser } from "@nextlvlup/ubx-parser";
import { UBX_NAV_PVT } from "@nextlvlup/ubx-parser/message";
const client = new Socket();
const parser = createParser();
// listen for UBX_NAV_PVT packets
parser.attach(UBX_NAV_PVT).hook((data) => console.log(data));
client.connect({ host: "localhost", port: 1234 });
client.on("data", (buffer) => parser.parse(buffer));import { SerialPort } from "serialport";
import { createParser } from "@nextlvlup/ubx-parser";
import { UBX_NAV_PVT } from "@nextlvlup/ubx-parser/message";
const serialport = new SerialPort({ path: "/dev/ttyS0", baudRate: 460_800 });
const parser = createParser();
// listen for UBX_NAV_PVT packets
parser.attach(UBX_NAV_PVT).hook((data) => console.log(data));
port.on("data", (buffer) => parser.parse(buffer));local development
Published under the MIT license.
Made by community 💛
🤖 auto updated with automd