UNPKG

knxultimate

Version:

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

47 lines (39 loc) 954 B
/** * Parses optional additional info blocks in KNX cEMI 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 TLVInfo from './TLVInfo' export default class AdditionalInfo { _tlvs: TLVInfo[] _length: number constructor(_tlvs = []) { this._tlvs = _tlvs this._length = 0 for (const tlv of _tlvs) { this._length += tlv.length } } static createFromBuffer(buffer: Buffer, offset = 0) { const tlvs = [] const _getOneTLV = () => { if (offset >= buffer.length) { return tlvs } const tlv = TLVInfo.createFromBuffer(buffer, offset) tlvs.push(tlv) offset += tlv.length return _getOneTLV() } return new AdditionalInfo(_getOneTLV()) } addTLV(tlv: TLVInfo) { this._tlvs.push(tlv) } toBuffer() { return Buffer.concat(this._tlvs.map((tlv) => tlv.toBuffer())) } }