zigbee-herdsman-zigate
Version:
An open source ZigBee gateway solution with node.js.
46 lines (36 loc) • 1.14 kB
text/typescript
/* istanbul ignore file */
/* eslint-disable */
import * as stream from 'stream';
// @ts-ignore
import slip from 'slip';
import Frame from './frame';
import Debug from "debug";
const debug = Debug('zigbee-herdsman:deconz:driver:parser');
class Parser extends stream.Transform {
private buffer: Buffer;
private decoder: slip.Decoder;
public constructor() {
super();
this.onMessage = this.onMessage.bind(this);
this.onError = this.onError.bind(this);
this.decoder = new slip.Decoder({
onMessage: this.onMessage,
maxMessageSize: 1000000,
bufferSize: 2048
});
}
private onMessage(message: Uint8Array): void {
//debug(`message received: ${message}`);
this.emit('parsed', message);
}
private onError(_: Uint8Array, error: string): void {
debug(`<-- error '${error}'`);
}
public _transform(chunk: Buffer, _: string, cb: Function): void {
//debug(`<-- [${[...chunk]}]`);
this.decoder.decode(chunk);
//debug(`<-- [${[...chunk]}]`);
cb();
}
}
export default Parser;