UNPKG

dlms-protocol

Version:

DLMS Protocol parser for JavaScript

48 lines (47 loc) 1.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; require("core-js/modules/web.dom-collections.iterator.js"); var _DlmsDataType = _interopRequireDefault(require("../enum/DlmsDataType")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } class DlmsUint8 { constructor() { let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null; this.tag = _DlmsDataType.default.UINT8; this.totalBytes = 0; this.rawValue = []; this.bodyBytes = []; this.value = 0; if (data) { if (Array.isArray(data)) { this.insertData(data); } else { this.insertDataFromValue(data); } } } getStandardLength() { return 2; } getValue() { return this.value; } insertData(data) { if (this.tag !== data[0]) { throw new Error("Tag mismatch."); } this.bodyBytes = [data[1]]; this.value = data[1]; this.rawValue = [this.tag, ...this.bodyBytes]; this.totalBytes = this.rawValue.length; } insertDataFromValue(value) { this.value = value; this.bodyBytes = [value & 0xFF]; this.rawValue = [this.tag, ...this.bodyBytes]; this.totalBytes = this.rawValue.length; } } exports.default = DlmsUint8;