_handleData(data) {
        if (!(data[0] === 0x00 && data[1] === 0x00 && data[2] === 0x00 && data[3] === 0x03)) {
            debug(`Ignore data package because invalid prefix: ${data.toString('hex')}`);
            return;
        }
        const dataLength = data[4] + 5;
        const messageType = data[7];

        if (data.length !== dataLength) {
            if (data.length > dataLength) {
                const additionalLength = data.length - dataLength;
                const additionalData = Buffer.alloc(additionalLength);
                const currentData = Buffer.alloc(dataLength);
                data.copy(currentData, 0, 0, dataLength);
                data.copy(additionalData, 0, dataLength);
                data = currentData;
                debug(`Split into two data packages because additional data detected. First ${data.toString('hex')} - Second ${additionalData.toString('hex')}`);
                setImmediate(() => this._handleData(additionalData));
            } else {
                debug(`Ignore data package because invalid length: ${data.toString('hex')}`);
                this.emit('error', `Ignore data package because invalid length`, data);
                return;
            }
        }

        switch (messageType) {
            case 0x07:
                this._handlePasscodeResponse(data);
                break;
            case 0x09:
                this._handleLoginResponse(data);
                break;
            case 0x16:
                this._handlePingPongResponse();
                break;
            case 0x91:
                this._handleDataResponse(data);
                break;
            case 0x94:
                this._handleDataExtendedResponse(data);
                break;
            default:
                debug(`Ignore data package because invalid message type ${messageType}: ${data}`);
                this.emit('error', `Ignore data package because invalid message type ${messageType}`, data);
                return;
        }
    }
/**
     * Check and parse received data from device
     *
     * @param {Buffer} data Received data
     * @private
     */
Check and parse received data from device
@param {Buffer} data Received data
@private
Check and parse received data from device @param { Buffer } data Received data @private
_handleData(data) {
        if (!(data[0] === 0x00 && data[1] === 0x00 && data[2] === 0x00 && data[3] === 0x03)) {
            debug(`Ignore data package because invalid prefix: ${data.toString('hex')}`);
            return;
        }
        const dataLength = data[4] + 5;
        const messageType = data[7];
        if (data.length !== dataLength) {
            if (data.length > dataLength) {
                const additionalLength = data.length - dataLength;
                const additionalData = Buffer.alloc(additionalLength);
                const currentData = Buffer.alloc(dataLength);
                data.copy(currentData, 0, 0, dataLength);
                data.copy(additionalData, 0, dataLength);
                data = currentData;
                debug(`Split into two data packages because additional data detected. First ${data.toString('hex')} - Second ${additionalData.toString('hex')}`);
                setImmediate(() => this._handleData(additionalData));
            } else {
                debug(`Ignore data package because invalid length: ${data.toString('hex')}`);
                this.emit('error', `Ignore data package because invalid length`, data);
                return;
            }
        }
        switch (messageType) {
            case 0x07:
                this._handlePasscodeResponse(data);
                break;
            case 0x09:
                this._handleLoginResponse(data);
                break;
            case 0x16:
                this._handlePingPongResponse();
                break;
            case 0x91:
                this._handleDataResponse(data);
                break;
            case 0x94:
                this._handleDataExtendedResponse(data);
                break;
            default:
                debug(`Ignore data package because invalid message type ${messageType}: ${data}`);
                this.emit('error', `Ignore data package because invalid message type ${messageType}`, data);
                return;
        }
    }
_handleData ( data ) { if ( ! ( data [ 0 ] === 0x00 && data [ 1 ] === 0x00 && data [ 2 ] === 0x00 && data [ 3 ] === 0x03 ) ) { debug ( ` ${ data . toString ( 'hex' ) } ` ) ; return ; } const dataLength = data [ 4 ] + 5 ; const messageType = data [ 7 ] ; if ( data . length !== dataLength ) { if ( data . length > dataLength ) { const additionalLength = data . length - dataLength ; const additionalData = Buffer . alloc ( additionalLength ) ; const currentData = Buffer . alloc ( dataLength ) ; data . copy ( currentData , 0 , 0 , dataLength ) ; data . copy ( additionalData , 0 , dataLength ) ; data = currentData ; debug ( ` ${ data . toString ( 'hex' ) } ${ additionalData . toString ( 'hex' ) } ` ) ; setImmediate ( ( ) => this . _handleData ( additionalData ) ) ; } else { debug ( ` ${ data . toString ( 'hex' ) } ` ) ; this . emit ( 'error' , ` ` , data ) ; return ; } } switch ( messageType ) { case 0x07 : this . _handlePasscodeResponse ( data ) ; break ; case 0x09 : this . _handleLoginResponse ( data ) ; break ; case 0x16 : this . _handlePingPongResponse ( ) ; break ; case 0x91 : this . _handleDataResponse ( data ) ; break ; case 0x94 : this . _handleDataExtendedResponse ( data ) ; break ; default : debug ( ` ${ messageType } ${ data } ` ) ; this . emit ( 'error' , ` ${ messageType } ` , data ) ; return ; } }
Check and parse received data from device
 @param {Buffer} data Received data
 @private
Check and parse received data from device @param { Buffer } data Received data @private