# @fpvcult/laprf

> A Node.js LapRF Protocol Library

Latest version **1.1.1** (published 2021-09-21) · GPL-3.0 license · 0 weekly downloads

## Install

```sh
npm install @fpvcult/laprf
pnpm add @fpvcult/laprf
yarn add @fpvcult/laprf
bun add @fpvcult/laprf
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2021-09-21 |
| First published | 2019-05-28 |
| Weekly downloads | 0 |
| License | GPL-3.0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=12.0.0 |
| Dependencies | 0 |
| Unpacked size | 175.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | John Hooks |
| Maintainers | bitmachina |
| Keywords | fpv, drone, race |

## Links

- npm: https://www.npmjs.com/package/@fpvcult/laprf
- Repository: https://github.com/fpvcult/laprf
- Homepage: https://github.com/fpvcult/laprf#readme
- Issues: https://github.com/fpvcult/laprf/issues
- npm.io page: https://npm.io/package/@fpvcult/laprf

## Recent versions

- 1.1.1 (latest) — 2021-09-21
- 1.0.1 — 2021-02-09
- 0.3.0 — 2020-11-19
- 0.2.1 — 2020-02-04
- 0.2.0 — 2020-02-03
- 0.1.0 — 2019-05-28

## README

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

## API

```ts
class Protocol {
  // Serialize a LapRF packet to request the rtc time.
  static getRctTime(): Uint8Array;

  // Serialize a LapRF packet to request the minimum lap time.
  static getMinLapTime(): Uint8Array;

  // Serialize a LapRF packet to set the minimum lap time.
  static setMinLapTime(milliseconds: number): Uint8Array;

  // Serialize a LapRF packet to set the status interval.
  static setStatusInterval(milliseconds: number): Uint8Array;

  // Serialize a LapRF packet to request the rfSetup of either an individual slot,
  // or all slots if `slotIndex` isn't provided.
  static getRfSetup(slotIndex?: number): Uint8Array;

  // Serialize a LapRF packet to configure a rfSetup slot.
  static setRfSetup(input: {
    slotIndex: SlotIndex;
    band: BandIndex;
    channel: ChannelIndex;
    gain: number;
    threshold: number;
    enabled: boolean;
  }): Uint8Array;

  // Takes a `DataView` containing a LapRF packet and return an array of
  // `DeviceRecord`s (A LapRF packet can contain more than one record).
  static decode(packet: DataView): DeviceRecord[];

  // Takes a `DataView` containing an unescaped LapRF record and returns a `DeviceRecord`.
  static decodeRecord(record: DataView): DeviceRecord;
}
```

#### DeviceRecord Types

```ts
interface RfSetupRecord {
  type: 'rfSetup';
  slotIndex: SlotIndex;
  enabled: number;
  channel: ChannelIndex;
  band: BandIndex;
  threshold: number;
  gain: number;
  frequency: number;
}

interface RssiRecord {
  type: 'rssi';
  slotIndex: SlotIndex;
  minRssi: number;
  maxRssi: number;
  meanRssi: number;
}

interface SettingsRecord {
  type: 'settings';
  updatePeriod: number;
  saveSettings: number;
  minLapTime: number;
}

interface PassingRecord {
  type: 'passing';
  slotIndex: SlotIndex;
  rtcTime: number;
  decoderId: number;
  passingNumber: number;
  peakHeight: number;
  flags: number;
}

interface StatusRecord {
  type: 'status';
  flags: number;
  gateState: number;
  batteryVoltage: number;
  detectionCount: number;
  slots: Record<SlotIndex, { lastRssi: number }>;
}

interface TimeRecord {
  type: 'time';
  rtcTime: number;
  timeRtcTime: number;
}

type DeviceRecord =
  | RfSetupRecord
  | RssiRecord
  | SettingsRecord
  | PassingRecord
  | StatusRecord
  | TimeRecord;
```

## Example:

```typescript
import { Socket } from 'net';
import { Protocol } from '@fpvcult/laprf';

const client = new Socket();

client.connect(5403, '192.168.1.9');

client.write(Protocol.setMinLapTime(10_000));

client.on('data', (buffer: Buffer) => {
  const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
  const records = Protocol.decode(view); // Argument needs to be an DataView

  // ... do something with the records
});
```

## Notes

Inspired by [IRCSwiftyLapRF](https://github.com/hydrafpv/irc-swifty-laprf) and
[LapRFUtilities](https://github.com/ImmersionRC/LapRFUtilities)

---
_Source: https://npm.io/package/@fpvcult/laprf · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
