dlms-protocol
Version:
DLMS Protocol parser for JavaScript
48 lines (47 loc) • 1.28 kB
JavaScript
"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 DlmsEnum {
constructor() {
let data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
this.tag = _DlmsDataType.default.ENUM;
this.totalBytes = 0;
this.rawValue = [];
this.bodyBytes = [];
this.value = 0;
if (data) {
if (Array.isArray(data)) {
this.insertData(data);
} else {
this.insertDataFromEnum(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;
}
insertDataFromEnum(dlmsEnum) {
this.totalBytes = 2;
this.bodyBytes = [dlmsEnum];
this.rawValue = [this.tag, ...this.bodyBytes];
this.value = dlmsEnum;
}
}
exports.default = DlmsEnum;