1.0.8 • Published 6 years ago

@atim/codec v1.0.8

Weekly downloads
20
License
unlicensed
Repository
-
Last release
6 years ago

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 1byte 2byte 3byte 4byte 5byte 6byte 7...
Frame030D2A0C2B64

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

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.0

6 years ago