npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xbee-frame

v1.2.0

Published

XBee API frame encoder and decoder

Downloads

6

Readme

xbee-frame

XBee API frame encoder and decoder.

npm install xbee-frame

Usage

The module exposes the encode, decode and encodingLength functions as well as constants used in the frames. All binary data is handled with Uint8Array buffers.

const { encode, decode, FrameType } = require('xbee-frame')

// Returns Uint8Array with frame content
const buffer = encode({
  type: FrameType.LOCAL_AT_COMMAND_REQUEST,
  id: 1,
  command: 'NI'
})

console.log(buffer) // [0x7e, 0x00, 0x04, 0x08, ...]

const obj = decode(buffer)

console.log(obj) // { type: 0x08, id: 1, command: 'NI' }

API

encode(obj, [buffer], [offset])

Encodes the object frame into the buffer beginning at specified byte offset. If no buffer is provided a new one is allocated. The byte offset defaults to 0.

After the encoding encode.bytes is set to the amount of bytes used to encode the object.

decode(buffer, [start], [end])

Returns the decoded object frame from the buffer, beginning at specified byte offset given by the second argument. An optional end offset can be passed, and defaults to the buffer length.

After the decoding encode.bytes is set to the amount of bytes used to decode the object.

encodingLength(obj)

Returns the amount of bytes needed to encode the passed object frame.

FrameType

Valid frame types.

  • LOCAL_AT_COMMAND_REQUEST (0x08)
  • BLE_UNLOCK_REQUEST (0x2c)
  • USER_DATA_RELAY_INPUT (0x2d)
  • LOCAL_AT_COMMAND_RESPONSE (0x88)
  • TRANSMIT_STATUS (0x89)
  • BLE_UNLOCK_RESPONSE (0xac)

ATCommandStatus

Valid AT command status codes. Used with the Local AT Command Response frame.

  • OK (0)
  • ERROR (1)
  • INVALID_COMMAND (2)
  • INVALID_PARAMETER (3)

Interface

Valid interface values. Used with the User Data Relay Input frame.

  • SERIAL (0)
  • BLE (1)
  • MICROPYTHON (2)

DeliveryStatus

Used with the Transmit Status frame.

Frames

Local AT Command Request

The value property is optional.

{
  type: FrameType.LOCAL_AT_COMMAND_REQUEST,
  id: Number,
  command: String,
  [value: Uint8Array]
}

BLE Unlock Request/Response

The frame payload depends on the step value.

{
  type: FrameType.BLE_UNLOCK_REQUEST | FrameType.BLE_UNLOCK_RESPONSE,
  step: 1,
  clientEphemeral: Uint8Array(128)
}
{
  type: FrameType.BLE_UNLOCK_REQUEST | FrameType.BLE_UNLOCK_RESPONSE,
  step: 2,
  salt: Uint8Array(4),
  serverEphemeral: Uint8Array(128)
}
{
  type: FrameType.BLE_UNLOCK_REQUEST | FrameType.BLE_UNLOCK_RESPONSE,
  step: 3,
  clientSessionProof: Uint8Array(32)
}
{
  type: FrameType.BLE_UNLOCK_REQUEST | FrameType.BLE_UNLOCK_RESPONSE,
  step: 4,
  serverSessionProof: Uint8Array(32),
  txNonce: Uint8Array(12),
  rxNonce: Uint8Array(12)
}

User Data Relay Input

{
  type: FrameType.USER_DATA_RELAY_INPUT,
  id: Number,
  destination: Interface,
  data: Uint8Array
}

Transmit Status

Get the string description of the status by calling DeliveryStatus.getName(status).

{
  type: FrameType.TRANSMIT_STATUS,
  id: Number,
  status: DeliveryStatus
}

Local AT Command Response

The value property is optional. Get the string description of the status by calling ATCommandStatus.getName(status).

{
  type: FrameType.LOCAL_AT_COMMAND_RESPONSE,
  id: Number,
  command: String,
  status: ATCommandStatus,
  [value: Uint8Array]
}