UNPKG

dlms-protocol

Version:

DLMS Protocol parser for JavaScript

37 lines (36 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; require("core-js/modules/es.regexp.to-string.js"); require("core-js/modules/esnext.iterator.map.js"); require("core-js/modules/web.dom-collections.iterator.js"); var _DlmsDatas = _interopRequireDefault(require("../typesDLMS/DlmsDatas")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } class DataNotification { constructor() { let bytes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; this.longInvokeId = ''; this.dateTimeValue = null; this.notificationBody = null; this.value = []; if (bytes) { this.insertData(bytes); } } insertData(bytes) { this.value = [...bytes]; // Clone the byte array this.longInvokeId = bytes.slice(1, 5).map(byte => byte.toString(16).toUpperCase().padStart(2, '0')).join(''); this.notificationBody = _DlmsDatas.default.factory(bytes[6]); const temp = bytes.slice(6); // Extract remaining bytes starting at index 6 this.notificationBody.insertData(temp); } getBytes() { return this.value; } getHexString() { return this.value.map(byte => byte.toString(16).toUpperCase().padStart(2, '0')).join(' '); } } exports.default = DataNotification;