Comparing version 0.1.4 to 0.2.0
@@ -6,10 +6,11 @@ var debug = require('debug')('bindings'); | ||
var BlueZ = require('./bluez'); | ||
var Gatttool = require('./gatttool'); | ||
var HciBle = require('./hci-ble'); | ||
var L2capBle = require('./l2cap-ble'); | ||
var NobleBindings = function() { | ||
this._addresses = {}; | ||
this._addresseTypes = {}; | ||
this._bluez = new BlueZ(); | ||
this._gatttool = {}; | ||
this._hciBle = new HciBle(); | ||
this._l2capBle = {}; | ||
}; | ||
@@ -22,6 +23,6 @@ | ||
nobleBindings.init = function() { | ||
this._bluez.on('stateChange', this.onStateChange.bind(this)); | ||
this._bluez.on('scanStart', this.onScanStart.bind(this)); | ||
this._bluez.on('scanStop', this.onScanStop.bind(this)); | ||
this._bluez.on('discover', this.onDiscover.bind(this)); | ||
this._hciBle.on('stateChange', this.onStateChange.bind(this)); | ||
this._hciBle.on('scanStart', this.onScanStart.bind(this)); | ||
this._hciBle.on('scanStop', this.onScanStop.bind(this)); | ||
this._hciBle.on('discover', this.onDiscover.bind(this)); | ||
}; | ||
@@ -34,8 +35,5 @@ | ||
nobleBindings.startScanning = function(serviceUuids, allowDuplicates) { | ||
this._devicesDiscovered = {}; // reset previously discovered devices | ||
this._scanServiceUuids = serviceUuids || []; | ||
this._scanAllowDuplicated = allowDuplicates; | ||
this._bluez.startScanning(); | ||
this._hciBle.startScanning(allowDuplicates); | ||
}; | ||
@@ -48,3 +46,3 @@ | ||
nobleBindings.stopScanning = function() { | ||
this._bluez.stopScanning(); | ||
this._hciBle.stopScanning(); | ||
}; | ||
@@ -56,25 +54,22 @@ | ||
nobleBindings.onDiscover = function(address, advertisement, rssi) { | ||
if (!this._devicesDiscovered[address] || this._scanAllowDuplicated) { | ||
this._devicesDiscovered[address] = true; | ||
nobleBindings.onDiscover = function(address, addressType, advertisement, rssi) { | ||
var serviceUuids = advertisement.serviceUuids; | ||
var hasScanServiceUuids = (this._scanServiceUuids.length === 0); | ||
var serviceUuids = advertisement.serviceUuids; | ||
var hasScanServiceUuids = (this._scanServiceUuids.length === 0); | ||
if (!hasScanServiceUuids) { | ||
for (var i in serviceUuids) { | ||
hasScanServiceUuids = (this._scanServiceUuids.indexOf(serviceUuids[i]) !== -1); | ||
if (!hasScanServiceUuids) { | ||
for (var i in serviceUuids) { | ||
hasScanServiceUuids = (this._scanServiceUuids.indexOf(serviceUuids[i]) !== -1); | ||
if (hasScanServiceUuids) { | ||
break; | ||
} | ||
if (hasScanServiceUuids) { | ||
break; | ||
} | ||
} | ||
} | ||
if (hasScanServiceUuids) { | ||
var uuid = address.split(':').join('').toLowerCase(); | ||
this._addresses[uuid] = address; | ||
if (hasScanServiceUuids) { | ||
var uuid = address.split(':').join('').toLowerCase(); | ||
this._addresses[uuid] = address; | ||
this._addresseTypes[uuid] = addressType; | ||
this.emit('discover', uuid, advertisement, rssi); | ||
} | ||
this.emit('discover', uuid, advertisement, rssi); | ||
} | ||
@@ -85,21 +80,23 @@ }; | ||
var address = this._addresses[peripheralUuid]; | ||
var addressType = this._addresseTypes[peripheralUuid]; | ||
this._gatttool[address] = new Gatttool(address); | ||
this._gatttool[address].on('connect', this.onConnect.bind(this)); | ||
this._gatttool[address].on('disconnect', this.onDisconnect.bind(this)); | ||
this._gatttool[address].on('servicesDiscover', this.onServicesDiscovered.bind(this)); | ||
this._gatttool[address].on('includedServicesDiscover', this.onIncludedServicesDiscovered.bind(this)); | ||
this._gatttool[address].on('characteristicsDiscover', this.onCharacteristicsDiscovered.bind(this)); | ||
this._gatttool[address].on('read', this.onRead.bind(this)); | ||
this._gatttool[address].on('write', this.onWrite.bind(this)); | ||
this._gatttool[address].on('broadcast', this.onBroadcast.bind(this)); | ||
this._gatttool[address].on('notify', this.onNotify.bind(this)); | ||
this._gatttool[address].on('notification', this.onNotification.bind(this)); | ||
this._gatttool[address].on('descriptorsDiscover', this.onDescriptorsDiscovered.bind(this)); | ||
this._gatttool[address].on('valueRead', this.onValueRead.bind(this)); | ||
this._gatttool[address].on('valueWrite', this.onValueWrite.bind(this)); | ||
this._gatttool[address].on('handleRead', this.onHandleRead.bind(this)); | ||
this._gatttool[address].on('handleWrite', this.onHandleWrite.bind(this)); | ||
this._l2capBle[address] = new L2capBle(address, addressType); | ||
this._l2capBle[address].on('connect', this.onConnect.bind(this)); | ||
this._l2capBle[address].on('disconnect', this.onDisconnect.bind(this)); | ||
this._l2capBle[address].on('rssi', this.onRssi.bind(this)); | ||
this._l2capBle[address].on('servicesDiscover', this.onServicesDiscovered.bind(this)); | ||
this._l2capBle[address].on('includedServicesDiscover', this.onIncludedServicesDiscovered.bind(this)); | ||
this._l2capBle[address].on('characteristicsDiscover', this.onCharacteristicsDiscovered.bind(this)); | ||
this._l2capBle[address].on('read', this.onRead.bind(this)); | ||
this._l2capBle[address].on('write', this.onWrite.bind(this)); | ||
this._l2capBle[address].on('broadcast', this.onBroadcast.bind(this)); | ||
this._l2capBle[address].on('notify', this.onNotify.bind(this)); | ||
this._l2capBle[address].on('notification', this.onNotification.bind(this)); | ||
this._l2capBle[address].on('descriptorsDiscover', this.onDescriptorsDiscovered.bind(this)); | ||
this._l2capBle[address].on('valueRead', this.onValueRead.bind(this)); | ||
this._l2capBle[address].on('valueWrite', this.onValueWrite.bind(this)); | ||
this._l2capBle[address].on('handleRead', this.onHandleRead.bind(this)); | ||
this._l2capBle[address].on('handleWrite', this.onHandleWrite.bind(this)); | ||
this._gatttool[address].connect(); | ||
this._l2capBle[address].connect(); | ||
}; | ||
@@ -116,3 +113,3 @@ | ||
this._gatttool[address].disconnect(); | ||
this._l2capBle[address].disconnect(); | ||
}; | ||
@@ -123,7 +120,7 @@ | ||
this._gatttool[address].kill(); | ||
this._l2capBle[address].kill(); | ||
this._gatttool[address].removeAllListeners(); | ||
this._l2capBle[address].removeAllListeners(); | ||
delete this._gatttool[address]; | ||
delete this._l2capBle[address]; | ||
@@ -134,12 +131,17 @@ this.emit('disconnect', uuid); | ||
nobleBindings.updateRssi = function(peripheralUuid) { | ||
// not implemented | ||
var rssi = 127; | ||
var address = this._addresses[peripheralUuid]; | ||
this.emit('rssiUpdate', peripheralUuid, rssi); | ||
this._l2capBle[address].updateRssi(); | ||
}; | ||
nobleBindings.onRssi = function(address, rssi) { | ||
var uuid = address.split(':').join('').toLowerCase(); | ||
this.emit('rssiUpdate', uuid, rssi); | ||
}; | ||
nobleBindings.discoverServices = function(peripheralUuid, uuids) { | ||
var address = this._addresses[peripheralUuid]; | ||
this._gatttool[address].discoverServices(uuids || []); | ||
this._l2capBle[address].discoverServices(uuids || []); | ||
}; | ||
@@ -156,3 +158,3 @@ | ||
this._gatttool[address].discoverIncludedServices(serviceUuid, serviceUuids || []); | ||
this._l2capBle[address].discoverIncludedServices(serviceUuid, serviceUuids || []); | ||
}; | ||
@@ -169,3 +171,3 @@ | ||
this._gatttool[address].discoverCharacteristics(serviceUuid, characteristicUuids || []); | ||
this._l2capBle[address].discoverCharacteristics(serviceUuid, characteristicUuids || []); | ||
}; | ||
@@ -182,3 +184,3 @@ | ||
this._gatttool[address].read(serviceUuid, characteristicUuid); | ||
this._l2capBle[address].read(serviceUuid, characteristicUuid); | ||
}; | ||
@@ -195,3 +197,3 @@ | ||
this._gatttool[address].write(serviceUuid, characteristicUuid, data, withoutResponse); | ||
this._l2capBle[address].write(serviceUuid, characteristicUuid, data, withoutResponse); | ||
}; | ||
@@ -208,3 +210,3 @@ | ||
this._gatttool[address].broadcast(serviceUuid, characteristicUuid, broadcast); | ||
this._l2capBle[address].broadcast(serviceUuid, characteristicUuid, broadcast); | ||
}; | ||
@@ -221,3 +223,3 @@ | ||
this._gatttool[address].notify(serviceUuid, characteristicUuid, notify); | ||
this._l2capBle[address].notify(serviceUuid, characteristicUuid, notify); | ||
}; | ||
@@ -240,3 +242,3 @@ | ||
this._gatttool[address].discoverDescriptors(serviceUuid, characteristicUuid); | ||
this._l2capBle[address].discoverDescriptors(serviceUuid, characteristicUuid); | ||
}; | ||
@@ -253,3 +255,3 @@ | ||
this._gatttool[address].readValue(serviceUuid, characteristicUuid, descriptorUuid); | ||
this._l2capBle[address].readValue(serviceUuid, characteristicUuid, descriptorUuid); | ||
}; | ||
@@ -266,3 +268,3 @@ | ||
this._gatttool[address].writeValue(serviceUuid, characteristicUuid, descriptorUuid, data); | ||
this._l2capBle[address].writeValue(serviceUuid, characteristicUuid, descriptorUuid, data); | ||
}; | ||
@@ -279,3 +281,3 @@ | ||
this._gatttool[address].readHandle(handle); | ||
this._l2capBle[address].readHandle(handle); | ||
}; | ||
@@ -292,3 +294,3 @@ | ||
this._gatttool[address].writeHandle(handle, data, withoutResponse); | ||
this._l2capBle[address].writeHandle(handle, data, withoutResponse); | ||
}; | ||
@@ -295,0 +297,0 @@ |
@@ -5,3 +5,3 @@ { | ||
"description": "A node.js BLE (Bluetooth low energy) library.", | ||
"version": "0.1.4", | ||
"version": "0.2.0", | ||
"repository": { | ||
@@ -8,0 +8,0 @@ "type": "git", |
@@ -13,12 +13,4 @@ noble | ||
* [BlueZ](http://www.bluez.org) __4.100 or 4.101__ is needed ! | ||
* 4.99 does not support connecting to LE devices | ||
* Install BlueZ 4.101 (if you are running an older unsupported version) | ||
* install build dependencies: ```sudo apt-get install libglib2.0-dev libdbus-1-dev libusb-dev libudev-dev libical-dev libreadline-dev``` | ||
* fetch archive: ```wget https://www.kernel.org/pub/linux/bluetooth/bluez-4.101.tar.bz2``` | ||
* extract archive: ```tar xvjf bluez-4.101.tar.bz2``` | ||
* change directory: ```cd bluez-4.101``` | ||
* configure: ```./configure --disable-systemd``` | ||
* build: ```make``` | ||
* install: ```sudo make install``` | ||
* ```sudo apt-get install libbluetooth-dev``` | ||
* Run as ```sudo``` or ```root``` | ||
@@ -262,3 +254,3 @@ Install | ||
* Linux | ||
* ~~Adapter state (off | on)~~ | ||
* ~~Adapter state (unsupported | unauthorized | off | on)~~ | ||
* ~~Scan~~ | ||
@@ -273,9 +265,9 @@ * ~~startScanning~~ | ||
* ~~public address~~ | ||
* random address | ||
* ~~random address~~ | ||
* ~~disconnect/cancel connect~~ | ||
* update RSSI | ||
* ~~update RSSI~~ | ||
* ~~services~~ | ||
* ~~discover~~ | ||
* ~~filter by uuid~~ | ||
* ~~disover included~~ | ||
* ~~discover included~~ | ||
* ~~discover characteristics for services~~ | ||
@@ -317,2 +309,2 @@ * ~~filter by uuid~~ | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
136320
27
2833
307
4