UNPKG

knxultimate

Version:

KNX IP protocol implementation for Node. This is the ENGINE of Node-Red KNX-Ultimate node.

60 lines 2.29 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const KNXConstants_1 = require("./KNXConstants"); const KNXPacket_1 = __importDefault(require("./KNXPacket")); const HPAI_1 = __importDefault(require("./HPAI")); class KNXSecureSearchRequest extends KNXPacket_1.default { constructor(hpai, dibs = [ KNXConstants_1.KNX_CONSTANTS.DEVICE_INFO, KNXConstants_1.KNX_CONSTANTS.SUPP_SVC_FAMILIES, KNXConstants_1.KNX_CONSTANTS.SECURED_SERVICE_FAMILIES, ]) { const srpDibs = KNXSecureSearchRequest.buildRequestDibsSRP(dibs); const srpSvc = KNXSecureSearchRequest.buildSelectByServiceSRP(0x09, 0x01); const srp = Buffer.concat([srpSvc, srpDibs]); super(KNXConstants_1.KNX_CONSTANTS.SEARCH_REQUEST_EXTENDED, hpai.length + srp.length); this.hpai = hpai; this._srp = srp; } static buildRequestDibsSRP(dibs) { const payload = Buffer.from(dibs); const padded = payload.length % 2 === 1 ? Buffer.concat([payload, Buffer.from([0x00])]) : payload; const len = 2 + padded.length; const buf = Buffer.alloc(len); let off = 0; buf.writeUInt8(len, off++); buf.writeUInt8(0x04, off++); padded.copy(buf, off); return buf; } static buildSelectByServiceSRP(family, minVersion) { const len = 2 + 2; const buf = Buffer.alloc(len); buf.writeUInt8(len, 0); buf.writeUInt8(0x80 | 0x03, 1); buf.writeUInt8(family & 0xff, 2); buf.writeUInt8(minVersion & 0xff, 3); return buf; } static createFromBuffer(buffer, offset = 0) { if (offset >= buffer.length) { throw new Error('Buffer too short'); } const hpai = HPAI_1.default.createFromBuffer(buffer, offset); return new KNXSecureSearchRequest(hpai); } toBuffer() { return Buffer.concat([ this.header.toBuffer(), this.hpai.toBuffer(), this._srp, ]); } } exports.default = KNXSecureSearchRequest; //# sourceMappingURL=KNXSecureSearchRequest.js.map