bluetooth-hci-socket
Advanced tools
Comparing version 0.4.2 to 0.4.3
@@ -18,2 +18,3 @@ var events = require('events'); | ||
this._hciEventEndpointBuffer = new Buffer(0); | ||
this._aclDataInEndpointBuffer = new Buffer(0); | ||
} | ||
@@ -114,7 +115,2 @@ | ||
if (this._mode === 'raw' && data.length === 6 && ('0e0401030c00' === data.toString('hex'))) { | ||
debug('reset complete'); | ||
this._isUp = true; | ||
} | ||
// add to buffer | ||
@@ -131,11 +127,20 @@ this._hciEventEndpointBuffer = Buffer.concat([ | ||
// check if desired length | ||
if (this._hciEventEndpointBuffer.readUInt8(1) === (this._hciEventEndpointBuffer.length - 2)) { | ||
var pktLen = this._hciEventEndpointBuffer.readUInt8(1); | ||
if (pktLen <= (this._hciEventEndpointBuffer.length - 2)) { | ||
var buf = this._hciEventEndpointBuffer.slice(0, pktLen + 2); | ||
if (this._mode === 'raw' && buf.length === 6 && ('0e0401030c00' === buf.toString('hex'))) { | ||
debug('reset complete'); | ||
this._isUp = true; | ||
} | ||
// fire event | ||
this.emit('data', Buffer.concat([ | ||
new Buffer([HCI_EVENT_PKT]), | ||
this._hciEventEndpointBuffer | ||
buf | ||
])); | ||
// reset buffer | ||
this._hciEventEndpointBuffer = new Buffer(0); | ||
this._hciEventEndpointBuffer = this._hciEventEndpointBuffer.slice(pktLen + 2); | ||
} | ||
@@ -147,2 +152,32 @@ }; | ||
if (data.length === 0) { | ||
return; | ||
} | ||
// add to buffer | ||
this._aclDataInEndpointBuffer = Buffer.concat([ | ||
this._aclDataInEndpointBuffer, | ||
data | ||
]); | ||
if (this._aclDataInEndpointBuffer.length < 4) { | ||
return; | ||
} | ||
// check if desired length | ||
var pktLen = this._aclDataInEndpointBuffer.readUInt16LE(2); | ||
if (pktLen <= (this._aclDataInEndpointBuffer.length - 4)) { | ||
var buf = this._aclDataInEndpointBuffer.slice(0, pktLen + 4); | ||
// fire event | ||
this.emit('data', Buffer.concat([ | ||
new Buffer([HCI_ACLDATA_PKT]), | ||
buf | ||
])); | ||
// reset buffer | ||
this._aclDataInEndpointBuffer = this._aclDataInEndpointBuffer.slice(pktLen + 4); | ||
} | ||
this.emit('data', Buffer.concat([ | ||
@@ -149,0 +184,0 @@ new Buffer([HCI_ACLDATA_PKT]), |
{ | ||
"name": "bluetooth-hci-socket", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "Bluetooth HCI socket binding for Node.js", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
43302
671