Skip to content
/ laprf Public
forked from fpvcult/laprf

A Typescript LapRF Protocol Library

License

Notifications You must be signed in to change notification settings

davidbue/laprf

 
 

Repository files navigation

A Node.js LapRF Protocol Library

A library, written in TypeScript, to encode and decode ImmersionRC LapRF binary messages.

Concept

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 ], ... ] }

API

Class Method: encode

encode(record: Record): Buffer

Take an object implementing Record and return a Buffer encoded with the contents.

Class Method: decode

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).

Record Interface

interface Record {
  type: string; // recordType
  fields: Array<[string, number]>; // [[fieldName: string, data: number], ...]
}

Example:

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
});

Notes

Inspired by IRCSwiftyLapRF and LapRFUtilities

About

A Typescript LapRF Protocol Library

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 90.9%
  • JavaScript 9.1%