Skip to content

Commit

Permalink
feat: add posibility to push bind parameters to hci layer
Browse files Browse the repository at this point in the history
  • Loading branch information
stoprocent committed Oct 23, 2023
1 parent b7b684f commit 7e645ab
Show file tree
Hide file tree
Showing 4 changed files with 15,475 additions and 71 deletions.
17 changes: 17 additions & 0 deletions examples/uart-bind-params.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const noble = require('../with-custom-binding')

// Needs to export env: BLUETOOTH_HCI_SOCKET_FORCE_UART=1

const noble_uart_a = noble ({ bindParams: { uart: { port: "/dev/tty.usbmodem1..." } } } )
const noble_uart_b = noble ({ bindParams: { uart: { port: "/dev/tty.usbmodem2..." } } } )

noble_uart_a.on('discover', (peripheral) => {
console.log("UART A", peripheral.address)
})

noble_uart_b.on('discover', (peripheral) => {
console.log("UART B", peripheral.address)
})

noble_uart_a.startScanning()
noble_uart_b.startScanning()
5 changes: 3 additions & 2 deletions lib/hci-socket/hci.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ const Hci = function (options) {
this._isDevUp = null;
this._isExtended = 'extended' in options && options.extended;
this._state = null;
this._bindParams = 'bindParams' in options ? options.bindParams : undefined

this._handleBuffers = {};

Expand Down Expand Up @@ -151,13 +152,13 @@ Hci.prototype.init = function (options) {
this._socket.on('error', this.onSocketError.bind(this));

if (this._userChannel) {
this._socket.bindUser(this._deviceId);
this._socket.bindUser(this._deviceId, this._bindParams);
this._socket.start();

this.reset();
} else {
if (!this._bound) {
this._socket.bindRaw(this._deviceId);
this._socket.bindRaw(this._deviceId, this._bindParams);
this._bound = true;
}
this._socket.start();
Expand Down
Loading

0 comments on commit 7e645ab

Please sign in to comment.