0.0.5 • Published 3 months ago

hiqnet v0.0.5

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
3 months ago

platform npm package version license Npm package total downloads github-issues

HiQnet

Parsing library for HiQnet communication protocol

Installation

npm install hiqnet

Version History

VersionRelease Notes
0.0.5Fixed: github actions not publishing .js and .d.ts
0.0.4Package publishing automation
0.0.3Fixed missing .js and .d.ts files
0.0.2Fixed broken links in readme
0.0.1Initial beta release

Usage

Sending Commands

Before sending a command to a Blu device, use hiqnet.encapsulatCommand(buf: Buffer). This function will byte substitute, add checksum, and prepend/append STX/ETX respectively.

const hiqnet = require('hiqnet');

let cmd_id = Buffer.from([0x88]);
let address = Buffer.from([0x00, 0x09, 0x03, 0x00, 0x01, 0x00, 0x4e, 0x20]);
let data = hiqnet.encDiscrete(10);

let cmd = hiqnet.encapsulateCommand(Buffer.concat([cmd_id, address, data]));

// send encapsulated command to Blu device via TCP or Serial.

There are several functions to facilitate encoding data types:

  • encDiscrete(v: number): Buffer
  • encPercent(v: number): Buffer
  • encGain(v: number): Buffer
  • encScalarLinear(v: number): Buffer
  • encDelay(v: number): Buffer
  • encFrequencyOrSpeed(v: number)

Parsing Responses

To parse incomming messages, use hiqnet.decapsulateCommand(buf: Buffer). This function will strip STX/ETX, verify and remove checksum, and byte unsubstitute.

const hiqnet = require('hiqnet');

let cmd = hiqnet.decapsulateCommand(rx$);

let cmd_id = hiqnet.getCommandIdBuffer(cmd);
let address = hiqnet.getAddressBuffer(cmd);
let data = hiqnet.getDateBuffer(cmd);

// decode data buffer
let dataValue = hiqnet.decDiscrete(data);

There are several functions to facilitate decoding data types:

  • decDiscrete(b: Buffer): number
  • decPercent(b: Buffer): number
  • decGain(b: Buffer): number
  • decScalarLinear(b: Buffer): number
  • decDelay(b: Buffer): number
  • decFrequencyOrSpeed(b: Buffer): number

Resources

Address Property

The address property is a buffer of exactly 8 bytes. it is comprised of:

  • Node Address (2 bytes)
  • Virtual Device (1 byte)
  • Object ID (3 bytes)
  • Parameter ID (2 bytes)

The following bytes have special meanings. The node suite will automatically handle replacement when commands are encapsulated and decapsulated. Be mindfull on nodes requiring an address property that the non replaced character is needed in decimal format.

TYPEHEXHEX replacementDECDEC replacement
STX0x020x1B, 0x82227, 130
ETX0x030x1B, 0x83327, 131
ACK0x060x1B, 0x86627, 134
NAK0x150x1B, 0x952127, 149
Escape0x1B0x1B, 0x9B2727, 155

Feature Requests / Bug Reporting

Please report any bugs or issues to the repository here.

0.0.5

3 months ago

0.0.4

3 months ago

0.0.3

3 months ago

0.0.2

3 months ago

0.0.1

3 months ago