# mode-s-decoder

> A library to decode a binary Mode S message to an easy to use JavaScript object

Latest version **1.0.1** (published 2017-12-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install mode-s-decoder
pnpm add mode-s-decoder
yarn add mode-s-decoder
bun add mode-s-decoder
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2017-12-11 |
| First published | 2017-12-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 16 |
| Author | Thomas Watson |
| Maintainers | watson |
| Keywords | decode, decoder, modes, mode-s, adsb, ads-b, sdr, rtlsdr, rtl-sdr, librtlsdr, radio, aircraft, airplane, airplanes, plane, 1090, 1090mhz |

## Links

- npm: https://www.npmjs.com/package/mode-s-decoder
- Repository: https://github.com/watson/mode-s-decoder
- Homepage: https://github.com/watson/mode-s-decoder#readme
- Issues: https://github.com/watson/mode-s-decoder/issues
- npm.io page: https://npm.io/package/mode-s-decoder

## Dependencies (1)

- [mode-s-msglen](https://npm.io/package/mode-s-msglen.md) ^1.0.2

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2017-12-11
- 1.0.0 — 2017-12-10
- 0.1.0 — 2017-12-01

## README

# mode-s-decoder

A library to decode a binary Mode S message to an easy to use JavaScript
object.

Mode S is an aviation transponder interrogation mode used by Secondary
Surveillance Radar (SSR) and Automatic Dependent Surveillance-Broadcast
(ADS-B) systems.

For an example of this module in use, see
[AirplaneJS](https://github.com/watson/airplanejs).

[![Build status](https://travis-ci.org/watson/mode-s-decoder.svg?branch=master)](https://travis-ci.org/watson/mode-s-decoder)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)

## Installation

```
npm install mode-s-decoder --save
```

## Usage

```js
const Decoder = require('mode-s-decoder')
const decoder = new Decoder()

const data = new Uint8Array([0x8f, 0x46, 0x1f, 0x36, 0x60, 0x4d, 0x74, 0x82, 0xe4, 0x4d, 0x97, 0xbc, 0xd6, 0x4e])
const message = decoder.parse(data)

console.log(message)
```

## API

### `Decoder.UNIT_FEET`

A constant indicating that the unit used is feet. Used to check the unit
of the message using the `message.unit` property.

### `Decoder.UNIT_METERS`

A constant indicating that the unit used is meters. Used to check the
unit of the message using the `message.unit` property.

### `decoder = new Decoder([options])`

Initialize a new decoder object.

Arguments:

- `options` - An optional options object

The available options are:

- `fixErrors` - Set to `false` to disable automatic error correction
  (default: `true`)
- `aggressive` - Set to `true` to enable aggressive error correction
  algorithm. Only used if `fixErrors` is `true` (default: `false`)

### `message = decoder.parse(data[, crcOnly])`

Parse a binary Mode S message into an easy to use JavaScript object.

Arguments:

- `data` - A binary Mode S message (e.g. a Buffer or Uint8Array object)
- `crcOnly` - Optional boolean indicating if the decoder should only
  validate the checksum. If `true`, the returned `message` object will
  only contain the properties `msg`, `msgtype`, `msgbits`, `crc`, and
  `crcOk` (default: `false`)

Returns a `message` object containing the decoded message.

It's recommended to use this module together with the
[mode-s-aircraft-store](https://github.com/watson/mode-s-aircraft-store)
module. This allows you easy access to the decoded latitude and
longitude as this information cannot be read from a single Mode S
message, but needs multiple concurrent messages in order to be properly
decoded:

```js
const message = decoder.parse(data)

// store is an instance of AircraftStore from the mode-s-aircraft-store module
store.addMessage(message)

// ...

// later after storing multiple messages, output list of aircrafts:
store.getAircrafts().forEach(function (aircraft) {
  const unit = aircraft.unit === Decoder.UNIT_FEET ? 'feet' : 'meters'
  console.log('Aircraft:\n' +
    `  ID: ${aircraft.icao}\n` +
    `  Altitude: ${aircraft.altitude} ${unit}\n` +
    `  Speed: ${aircraft.speed}\n` +
    `  Heading: ${aircraft.heading}\n` +
    `  Latitude: ${aircraft.lat}\n` +
    `  Longitude: ${aircraft.lng}\n`)
})
```

## License

MIT

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