2024.325.1353 • Published 2 months ago

@jooby-dev/jooby-codec v2024.325.1353

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Jooby message encoders/decoders

GitHub Workflow Status npm version Docs

This library contains message encoders and decoders for Jooby LoRaWAN devices.

Installation

Install required dependencies:

npm install jooby-codec

This will provide 2 classes of codecs:

  • analog
  • OBIS observer

Usage of analog codecs

Add to the project:

import {commands, message} from 'jooby-codec/analog';

// output all available commands tree
console.log(commands);
// all uplink commands
console.log(commands.uplink);
// one particular command
console.log(commands.uplink.CurrentMC);

// output main namespace for work with messages
console.log(message);

But it's better to add only necessary commands to the project:

// to get only downlink commands
import {downlink} from 'jooby-codec/analog/commands';
// or slightly more efficient
import * as downlink from 'jooby-codec/analog/commands/downlink';

// to get one particular command
import SetTime2000 from 'jooby-codec/analog/commands/downlink/SetTime2000.js';

The last approach is preferred as it is more efficient and will init only a necessary commands.

It's possible to parse messages either from raw Uint8Array or HEX string:

Parse downlink message:

import {directions, hardwareTypes} from 'jooby-codec/analog/constants';

// from byte array
const messageData = message.fromBytes(
    new Uint8Array([
        0x02, 0x05, 0x4e, 0x00, 0x01, 0xe2, 0x40,
        0x02, 0x05, 0x4e, 0x00, 0x01, 0xe2, 0x40,
        0x55
    ]),
    directions.DOWNLINK
);
// or from hex string
const messageData = message.fromHex(
    '02 05 4e 00 01 e2 40  02 05 4e 00 01 e2 40  55',
    directions.DOWNLINK
);

// decoded data with commands and checksum
console.log(messageData);
/*{
    commands: [
        { data: [Object], command: [SetTime2000] },
        { data: [Object], command: [SetTime2000] }
    ],
    lrc: { expected: 85, actual: 85 },
    isValid: true
}*/

Parse uplink message:

const messageData = message.fromHex(
    '02 01 01  18 06 0f 83 01 08 0a 0c  16 08 2f 97 0f 83 01 08 0a 0c  ef',
    directions.UPLINK
);

It's possible to parse message with autodetect direction:

// It is highly recommended to use a specific direction.
// AUTO is used here just for example.
const messageData = message.fromHex(
    '02 01 01  18 06 0f 83 01 08 0a 0c  16 08 2f 97 0f 83 01 08 0a 0c  ef',
    directions.AUTO
);
// or even shorter as message.TYPE_AUTO is default behavior
const messageData = message.fromHex(
    '02 01 01  18 06 0f 83 01 08 0a 0c  16 08 2f 97 0f 83 01 08 0a 0c  ef'
);

It's best to avoid using message.TYPE_AUTO due to performance penalty.

Prepare command and get encoded data:

import SoftRestart from 'jooby-codec/analog/commands/downlink/SoftRestart.js';
import SetTime2000 from 'jooby-codec/analog/commands/downlink/SetTime2000.js';

const command = new SetTime2000({sequenceNumber: 5, seconds: 9462957});

// output command binary in hex representation
// 02 05 05 00 90 64 ad
console.log(command.toHex());
// [2, 5, 5, 0, 144, 100, 173]
console.log(command.toBytes());

Combine a message from commands:

const messageBytes = message.toBytes([
    new SetTime2000({sequenceNumber: 78, seconds: 123456}),
    new SoftRestart()
]);

or to get in a hex format:

import DayMC from 'jooby-codec/analog/commands/uplink/DayMC.js';
import LastEvent from 'jooby-codec/analog/commands/uplink/LastEvent.js';

const commandInstancesArray = [
    new LastEvent(
        {
            sequenceNumber: 32,
            status: {
                isBatteryLow: true,
                isButtonReleased: false,
                isConnectionLost: true,
                isMagneticInfluence: false
            }
        },
        hardwareTypes.GASI3
    ),
    new DayMC({
        startTime2000: 756604800,
        channelList: [
            {value: 131, index: 3},
            {value: 8, index: 5},
            {value: 10, index: 7},
            {value: 12, index: 1}
        ]
    })
];

const messageBytes = message.toHex(commandInstancesArray, {prefix: '0x'});
// 0x62 0x20 0x09 0x16 0x09 0x2f 0x97 0xaa 0x01 0x0c 0x83 0x01 0x08 0x0a 0x9e
2024.325.1023

2 months ago

2024.325.1353

2 months ago

2024.323.1005

2 months ago

2024.321.1813

2 months ago

2024.313.1021

2 months ago

2024.306.1044

2 months ago

2024.306.1200

2 months ago

2024.306.1157

2 months ago

2024.306.1228

2 months ago

2024.305.1439

2 months ago

2024.304.1902

2 months ago

2024.304.1637

2 months ago

2024.228.1403

2 months ago

2024.228.1404

2 months ago

2024.212.1140

3 months ago

2024.202.1526

3 months ago

2024.202.1116

3 months ago

2023.1108.1150

6 months ago

2023.929.859

7 months ago

2023.1030.1544

6 months ago

2023.1108.1441

6 months ago

2023.925.941

8 months ago

2023.831.728

8 months ago

2023.1116.1715

6 months ago

2023.713.1527

10 months ago

2023.705.1115

10 months ago

2023.1128.1519

5 months ago

2023.1117.824

6 months ago

2023.529.1136

12 months ago

2023.515.1136

12 months ago

2023.516.1343

12 months ago

2023.516.822

12 months ago

2023.516.744

12 months ago

2023.512.1007

12 months ago

2023.517.1842

12 months ago

2023.602.1330

11 months ago

2023.620.713

11 months ago

2023.511.1623

12 months ago

2023.421.1518

1 year ago

2023.421.1502

1 year ago

2023.421.1459

1 year ago

2023.421.1418

1 year ago

2023.421.1222

1 year ago

2023.420.1818

1 year ago

2023.420.1816

1 year ago

2023.420.1512

1 year ago

2023.420.1309

1 year ago

2023.420.742

1 year ago

2023.419.1530

1 year ago

2023.419.1524

1 year ago

2023.419.1518

1 year ago

2023.419.1454

1 year ago

2023.419.1411

1 year ago

2023.419.1054

1 year ago

2023.419.848

1 year ago

2023.418.1357

1 year ago

2023.418.1223

1 year ago

2023.418.1005

1 year ago

2023.417.848

1 year ago

2023.417.844

1 year ago

2023.417.745

1 year ago

2023.414.1707

1 year ago

2023.414.1657

1 year ago

2023.414.1645

1 year ago

2023.414.1425

1 year ago

2023.414.826

1 year ago

2023.413.1323

1 year ago

2023.413.826

1 year ago

2023.413.821

1 year ago

2023.412.1719

1 year ago

2023.412.1716

1 year ago

2023.412.1659

1 year ago

2023.412.1643

1 year ago

2023.412.1623

1 year ago

2023.412.1606

1 year ago

2023.412.1305

1 year ago