@curium.rocks/nmea-emitter
v0.110.0
Published
A IDataEmitter implementation that takes NMEA sentences and emits processed objects
Downloads
138
Readme
NMEA-Emitter
How To Install
npm install --save @curium.rocks/nmea-emitter
API Docs
You can view the API documentation here.
Example(s)
import {SerialDataFormat, SerialParity} from "@curium.rocks/serial-emitter";
import {NmeaEmitterFactory} from "@curium.rocks/nmea-emitter";
import {IDataEmitter, IDataEvent} from "@curium.rocks/data-emitter-base";
import {GGAPacket} from 'simple-nmea';
const factory:NmeaEmitterFactory = new NmeaEmitterFactory();
const emitter:IDataEmitter = await factory.build({
portName: '/dev/ttyUSB0',
dataBits: 8,
parity: SerialParity.NONE,
stopBits: 1,
baudRate: 9600,
format: SerialDataFormat.ASCII_LINES
}, 'unique-id', 'my-test-nmea-emitter', 'A longer description')
const dataListener = emitter.onData((dataEvent:IDataEvent) => {
console.log(`data: ${dataEvent.data}, emitted at: ${dataEvent.timestamp}, from: ${dataEvent.emitter.name}`);
if(dataEvent.data instanceof GGAPacket){
const ggaPacket:GGAPacket = dataEvent.data as GGAPacket;
console.log(`lat = ${ggaPacket.latitude}, lon = ${ggaPacket.longitude}, alt = ${ggaPacket.altitudeMeters}`);
}
})
const statusListener = emitter.onStatus((statusEvent) => {
console.log(`status: connected = ${statusEvent.connected}, at = ${statusEvent.timestamp}, BIT = ${statusEvent.bit}`);
})
dataListener.dispose();
statusListener.dispose();