UNPKG

knxultimate

Version:

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

52 lines (45 loc) 1.32 kB
/** * Builds KNX connection state request frames. * * Written in Italy with love, sun and passion, by Massimo Saccani. * * Released under the MIT License. * Use at your own risk; the author assumes no liability for damages. */ import KNXPacket from './KNXPacket' import { KNX_CONSTANTS } from './KNXConstants' import HPAI from './HPAI' export default class KNXConnectionStateRequest extends KNXPacket { channelID: number hpaiControl: HPAI constructor(channelID: number, hpaiControl: HPAI | string = HPAI.NULLHPAI) { super(KNX_CONSTANTS.CONNECTIONSTATE_REQUEST, hpaiControl.length + 2) this.channelID = channelID this.hpaiControl = typeof hpaiControl === 'string' ? new HPAI(hpaiControl) : hpaiControl } static createFromBuffer( buffer: Buffer, offset: number = 0, ): KNXConnectionStateRequest { if (offset >= buffer.length) { throw new Error('Buffer too short') } const channelID = buffer.readUInt8(offset++) offset++ const hpaiControl = HPAI.createFromBuffer(buffer, offset) return new KNXConnectionStateRequest(channelID, hpaiControl) } toBuffer(): Buffer { const buffer = Buffer.alloc(2) buffer.writeUInt8(this.channelID, 0) buffer.writeUInt8(0, 1) return Buffer.concat([ this.header.toBuffer(), buffer, this.hpaiControl.toBuffer(), ]) } }