UNPKG

zigbee-herdsman-zigate

Version:

An open source ZigBee gateway solution with node.js.

88 lines 3.72 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ZGAttributeReportMessage = exports.AttributeType = void 0; const message_1 = require("../message"); const debug_1 = require("../../debug"); const buffer_reader_1 = __importDefault(require("../buffer-reader")); const debug = debug_1.Debug('driver:messages'); var AttributeType; (function (AttributeType) { AttributeType[AttributeType["Null"] = 0] = "Null"; AttributeType[AttributeType["Boolean"] = 16] = "Boolean"; AttributeType[AttributeType["BitMap8"] = 24] = "BitMap8"; AttributeType[AttributeType["UInt8"] = 32] = "UInt8"; AttributeType[AttributeType["UInt16"] = 33] = "UInt16"; AttributeType[AttributeType["UInt32"] = 34] = "UInt32"; AttributeType[AttributeType["UInt48"] = 37] = "UInt48"; AttributeType[AttributeType["Int8"] = 40] = "Int8"; AttributeType[AttributeType["Int16"] = 41] = "Int16"; AttributeType[AttributeType["Int32"] = 42] = "Int32"; AttributeType[AttributeType["Enum"] = 48] = "Enum"; AttributeType[AttributeType["String"] = 66] = "String"; })(AttributeType = exports.AttributeType || (exports.AttributeType = {})); const attributeDataFromBuffer = (attributeType, attributeSize, payload) => { switch (attributeType) { case AttributeType.Null: return null; case AttributeType.Boolean: return payload.readUInt8(0) === 1; case AttributeType.BitMap8: case AttributeType.UInt8: case AttributeType.Enum: return payload.readUInt8(0); case AttributeType.UInt16: return payload.readUInt16BE(0); case AttributeType.UInt32: return payload.readUInt32BE(0); case AttributeType.UInt48: return payload.readUIntBE(0, 6); case AttributeType.Int8: return payload.readInt8(0); case AttributeType.Int16: return payload.readInt16BE(0); case AttributeType.Int32: return payload.readInt32BE(0); case AttributeType.String: return payload.toString('utf8', 0, attributeSize); default: debug.error(`Unsupported attribute data type: ${attributeType}`); } }; class ZGAttributeReportMessage { constructor(payload) { this.label = 'attribute-report'; this.code = message_1.ZGMessageCode.AttributeReport; this.payloadBuffer = payload; this.payload = this.fromBuffer(payload); debug.log.extend(`${this.getLabel()}`)(this.payload); } getCode() { return this.code; } getLabel() { return this.label; } getPayload() { return this.payload; } fromBuffer(payload) { const reader = new buffer_reader_1.default(payload); const DATA_OFFSET = 12; const msgPayload = { sequenceNumber: reader.nextUInt8(), srcAddress: reader.nextUInt16BE().toString(16), srcEndpoint: reader.nextUInt8(), clusterId: reader.nextUInt16BE(), attributeId: reader.nextUInt16BE(), attributeType: reader.nextUInt16BE(), attributeSize: reader.nextUInt16BE(), }; const attributeData = payload.slice(DATA_OFFSET); return Object.assign(Object.assign({}, msgPayload), { attributeData: attributeDataFromBuffer(msgPayload.attributeType, msgPayload.attributeSize, attributeData), attributeDataRaw: attributeData }); } } exports.ZGAttributeReportMessage = ZGAttributeReportMessage; //# sourceMappingURL=attribute-report.js.map