UNPKG

dlms-protocol

Version:

DLMS Protocol parser for JavaScript

46 lines (45 loc) 1.51 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 GetResponse { constructor() { let bytes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; this.setType = 0; this.invokeIdAndPriority = 0; this.parameterType = 0; this.accessResult = null; this.dlmsData = null; this.value = []; if (bytes) { this.insertData(bytes); } } insertData(bytes) { this.value = [...bytes]; // Clone the byte array this.setType = bytes[1]; this.invokeIdAndPriority = bytes[2]; this.parameterType = bytes[3]; if (this.parameterType !== 0) { this.accessResult = bytes[4]; // Assume mapping to `DataAccessResult` elsewhere } else { const dataType = bytes[4]; this.dlmsData = _DlmsDatas.default.factory(dataType); const temp = bytes.slice(4); // Extract remaining bytes starting from index 4 this.dlmsData.insertData(temp); } } getBytes() { return this.value; } getHexString() { return this.value.map(byte => byte.toString(16).toUpperCase().padStart(2, '0')).join(' '); } } exports.default = GetResponse;