UNPKG

dlms-protocol

Version:

DLMS Protocol parser for JavaScript

41 lines (40 loc) 1.34 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 _MessageType = _interopRequireDefault(require("../enum/MessageType")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } class SetResponse { constructor() { let bytes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; this.setType = 0; this.invokeIdAndPriority = 0; this.dataAccessResult = 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.dataAccessResult = bytes[3]; // Assumes mapping to `DataAccessResult` elsewhere } getBytes() { const result = []; result.push(_MessageType.default.SET_RESPONSE); result.push(this.setType); result.push(this.invokeIdAndPriority); result.push(this.dataAccessResult); return result; } getHexString() { return this.value.map(byte => byte.toString(16).toUpperCase().padStart(2, '0')).join(' '); } } exports.default = SetResponse;