@atim/codec
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

ATIM logo

ATIM Codec for ACW Products

Decoder

Usage

Standard frames

  • Load the library :
const codec = require('@atim/codec');
  • Instanciate one frame :
var frame = codec.frame.factory('010C760C7664');

where '010C760C7664' is the received frame.

  • Decode the frame :
frame.decode();
  • Result :
frame0x01 {
  channels:
   [ channel {
       range: [range],
       label: 'Idle Supply Voltage',
       decoder: [Function],
       value: 3190 },
     channel {
       range: [range],
       label: 'Tx Supply Voltage',
       decoder: [Function],
       value: 3190 } ],
  buffer: <Buffer 01 0c 76 0c 76 64>,
  label: 'Keep alive' }

Custom frames

When using DINRS / DINRSM devices, you define frame format by yourself. Thereby, we cannot automatically decode the frame. You have to pass extra parameters that describe the channels that are sent by the device.

codec.frame.factory('030D2A0C2B64', [
    new codec.channel('Channel 1', 2, 3, (buffer) => { return buffer.readUInt16BE(0); }),
    new codec.channel('Channel 2', 4, 5, (buffer) => { return buffer.readUInt16BE(0); })
]);

A channel is defined by a label, a starting byte in the frame, an ending byte in the frame and a decoding function.

A frame is read starting at byte 1 which is the header of the frame.

byte 1 byte 2 byte 3 byte 4 byte 5 byte 6 byte 7 ...
Frame 03 0D 2A 0C 2B 64

In this case :

  • first channel is read from offset 2 to 3 : 0D2A, then after applying function : 3370.
  • second channel is read from offset 4 to 5 : 0C2B, then after applying function : 3115.

Encoder

Codec encoding is available for DINDIO, TH and TMxD family products.

Refer to the user guide of each device to find the parameters you can configure.

Usage

  • Load the library :
const codec = require('@atim/codec');
  • Instanciate one downlink :
var downlink = new codec.downlink_th();

Downlink can be used with TH, TMxD and DINDIO devices.

  • Pass some values to the downlink :
downlink.values({
    2: new Date(),
    3: 1,
    6: 5.2,
    7: 1,
    8: -7.6,
    9: 22,
    10: 1,
    11: 30,
    12: 1,
    13: 30,
    14: -2.2,
    15: 1,
});

Refer to the documentation of the device to specify parameter/value key.

  • Encode the downlink :
downlink.encode();
  • Result :
console.log(downlink.get_downlinks_raws());
[ '828e248d01',
  '0301',
  '0634',
  '0701',
  '482e39',
  '494e64',
  '0a01',
  '0b1e',
  '0c01',
  '0d1e',
  '0eea',
  '0f01' ]

console.log(downlink.get_grouped_downlinks_raws(8));
[ '821a258d01482e39',
  '494e6407010f01',
  '063403010b1e0c01',
  '0d1e0eea0a01' ]
console.log(downlink.get_grouped_downlinks_raws());
[ '82bf298d01482e39494e6407010f01063403010b1e0c010d1e0eea0a01' ]

get_downlinks_raws returns one downlink per parameters provided to the value function.

get_grouped_downlinks_raws groups downlinks to optimize the required number of transmissions. Optionnal parameter size define the Max size of the message (8 in Sigfox network).

Readme

Keywords

Package Sidebar

Install

npm i @atim/codec

Weekly Downloads

53

Version

1.0.8

License

unlicensed

Unpacked Size

214 kB

Total Files

97

Last publish

Collaborators

  • as-atim
  • qd-atim