UNPKG

dlms-protocol

Version:

DLMS Protocol parser for JavaScript

50 lines (49 loc) 1.85 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 UnconfirmedWriteRequest { constructor() { let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; let variableName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null; this.variableAccessSpecificationQty = 0x01; this.variableAccessSpecification = 0x02; this.variableName = variableName; this.dataQty = data ? 0x01 : 0x00; this.data = data; this.value = []; this.parameters = []; this.variableParameters = []; } insertData(bytes) { throw new Error("Method not implemented."); } getBytes() { const result = []; result.push(_MessageType.default.UNCONFIRMED_WRITE_REQUEST); result.push(this.variableAccessSpecificationQty); result.push(this.variableAccessSpecification); if (this.variableParameters.length > 0) { result.push(...this.variableParameters); } else { const variableNameValue = Number(this.variableName); result.push(variableNameValue >> 8 & 0xFF, variableNameValue & 0xFF); } result.push(this.dataQty); if (this.data || this.parameters.length > 0) { result.push(...(this.data ? this.data.rawValue : this.parameters)); } this.value = [...result]; return result; } getHexString() { return this.value.map(byte => byte.toString(16).toUpperCase().padStart(2, '0')).join(' '); } } exports.default = UnconfirmedWriteRequest;