UNPKG

knxultimate

Version:

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

23 lines (20 loc) 655 B
import { KNX_CONSTANTS } from './KNXConstants' import TunnelCRI from './TunnelCRI' export default class CRIFactory { static createFromBuffer(buffer: Buffer, offset: number): any { if (offset >= buffer.length) { throw new Error('Buffer too short') } const structureLength: number = buffer.readUInt8(offset) if (offset + structureLength > buffer.length) { throw new Error('Buffer too short') } offset += 1 const connectionType: number = buffer.readUInt8(offset++) switch (connectionType) { case KNX_CONSTANTS.TUNNEL_CONNECTION: return TunnelCRI.createFromBuffer(buffer, offset) } throw new Error('Unknown CRI type') } }