knxultimate
Version:
KNX IP protocol implementation for Node. This is the ENGINE of Node-Red KNX-Ultimate node.
40 lines (33 loc) • 980 B
text/typescript
/**
* Parses TLV 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.
*/
export default class TLVInfo {
type: number
length: number
info: Buffer
constructor(type: number, length: number, info: Buffer) {
this.type = type
this.length = length
this.info = info
}
static createFromBuffer(buffer: Buffer, offset: number = 0): TLVInfo {
const type: number = buffer.readUInt8(offset++)
const length: number = buffer.readUInt8(offset++)
const info: Buffer = Buffer.alloc(length)
for (let i: number = 0; i < length; i++) {
info.writeUInt8(buffer.readUInt8(offset++), i)
}
return new TLVInfo(type, length, info)
}
toBuffer(): Buffer {
const buffer: Buffer = Buffer.alloc(2)
buffer.writeUInt8(this.type, 0)
buffer.writeUInt8(this.length, 1)
return Buffer.concat([buffer, this.info])
}
}