jooby-codec
    Preparing search index...

    Namespace downlink

    Process messages to send to devices.

    import * as message from 'jooby-codec/mtx1/message/downlink';
    import * as frame from 'jooby-codec/mtx1/utils/frame.js';
    import * as downlinkCommands from 'jooby-codec/mtx1/commands/downlink';
    import getHexFromBytes from 'jooby-codec/utils/getHexFromBytes.js';
    import * as frameTypes from 'jooby-codec/mtx1/constants/frameTypes.js';

    const aesKey = [...Array(16).keys()];
    const messageId = 10;

    const commands = [
    {
    id: downlinkCommands.setDateTime.id,
    parameters: {
    isSummerTime: false,
    seconds: 55,
    minutes: 31,
    hours: 18,
    day: 2,
    date: 19,
    month: 2,
    year: 24
    }
    }
    ];
    const messageBytes = message.toBytes(
    commands,
    {
    messageId,
    accessLevel: downlinkCommands.setDateTime.accessLevel,
    aesKey
    }
    );

    console.log('message encoded:', JSON.stringify(messageBytes));
    // output:
    [10,19,237,116,10,174,74,186,200,66,196,27,231,245,13,60,40,132]

    console.log('message encoded in HEX:', getHexFromBytes(messageBytes));
    // output:
    '0a 13 ed 74 0a ae 4a ba c8 42 c4 1b e7 f5 0d 3c 28 84'

    const frameBytes = frame.toBytes(
    messageBytes,
    {
    type: frameTypes.DATA_REQUEST,
    source: 0xffff,
    destination: 0xaaaa
    }
    );

    console.log('frame encoded:', frameBytes);
    // output:
    [126,80,170,170,255,255,10,125,51,237,116,10,174,74,186,200,66,196,27,231,245,13,60,40,132,97,187,126]

    console.log('frame encoded in HEX:', getHexFromBytes(frameBytes));
    // output:
    '7e 50 aa aa ff ff 0a 7d 33 ed 74 0a ae 4a ba c8 42 c4 1b e7 f5 0d 3c 28 84 61 bb 7e'


    // decode message back from bytes
    const parsedMessage = message.fromBytes(messageBytes, {aesKey});

    console.log('parsed message:', parsedMessage);
    // output:
    {
    messageId: 3,
    accessLevel: 3,
    commands: [
    {
    id: 8,
    name: 'setDateTime',
    headerSize: 2,
    bytes: [Array],
    parameters: [Object]
    }
    ],
    bytes: [3,19,237,116,10,174,74,186,200,66,196,27,231,245,13,60,40,132],
    lrc: {received: 119, calculated: 119}
    }

    // decode message back from frame
    const parsedFrame = frame.fromBytes(frameBytes);

    console.log('parsedFrame:', parsedFrame);
    // output:
    {
    bytes: [10,19,237,116,10,174,74,186,200,66,196,27,231,245,13,60,40,132],
    crc: {calculated: 47969, received: 47969},
    header: {type: 80, destination: 43690, source: 65535}
    }

    // parsed successfully
    if ( 'bytes' in parsedFrame ) {
    const parsedMessage2 = message.fromBytes(parsedFrame.bytes, {aesKey});

    console.log('parsedMessage2:', parsedMessage2);
    // output:
    {
    messageId: 10,
    accessLevel: 3,
    commands: [
    {
    id: 8,
    name: 'setDateTime',
    headerSize: 2,
    bytes: [Array],
    parameters: [Object]
    }
    ],
    bytes: [10,19,237,116,10,174,74,186,200,66,196,27,231,245,13,60,40,132],
    lrc: {received: 119, calculated: 119}
    }
    }

    Variables

    fromBytes
    fromBytesMap
    nameMap
    toBytes
    toBytesMap