A library, written in TypeScript, to encode and decode ImmersionRC LapRF binary messages.
Convert all the data coming from a LapRF into a form that is easily converted to and from JSON, or consumed directly in a JavaScript application.
{ "type": "settings", "fields": [ [ "minLapTime", 6000 ], ... ] }
encode(record: Record): Buffer
Take an object implementing Record
and return a Buffer
encoded with the contents.
decode(packet: Buffer): Record[]
Take a Buffer
containing a LapRF packet and return an array of objects implementing
Record
(A LapRF packet can contain more than one record).
interface Record {
type: string; // recordType
fields: Array<[string, number]>; // [[fieldName: string, data: number], ...]
}
import { Socket } from 'net';
import { LapRF, Record } from './index';
const client = new Socket();
const laprf = new LapRF();
client.connect(5403, '192.168.1.9');
client.write(
laprf.encode({
type: 'settings',
fields: [['minLapTime', 6000]],
})
);
client.on('data', chunk => {
const records = laprf.decode(chunk);
// ... do something with the records
});
Inspired by IRCSwiftyLapRF and LapRFUtilities