Skip to content

Hackuarium/legoino-util

Repository files navigation

legoino-util

NPM version build status David deps npm download

Create and parse compact logs.

Installation

$ npm install legoino-util

Example

Create compact log

'use strict';

const { createCompactLog } = require('legoino-util');

let result = createCompactLog(
  {
    id: 65535,
    epoch: 32767,
    parameters: {
      A: 1,
      B: 2,
      C: 3,
      D: 4
    },
    eventId: 5,
    eventValue: 6,
    deviceId: 0xaaaa - 65536
  },
  4
);
// result is a string with value '0000FFFF00007FFF000100020003000400050006AAAA87'

Parse current settings

'use strict';

const { parseCurrentSettings } = require('legoino-util');

let result = parseCurrentSettings('0000FFFF00007FFF000100020003000400050006AAAA87');
// result is a JSON (object)

Parse multi-logs

Parse many lines of logs in one go. The lines must be separated by carriage returns.

'use strict';

const { parseMultilog } = require('legoino-util');

var multilog = `
000100005B77EFBE0046000E003800000000000000000013000C00060000005100010011004080000000000004D242
000100015B77EFC10046000E003800000000000000000044003200100000002000020011004080000000000004D231
000100025B77EFC40047000E00380000000000020002002F0024000A0000003500010011004080000000000004D247
`

let result = parseMultilog(multilog);
// result is a JSON (array of objects)

License

MIT