noble/node-bluetooth-hci-socket

Socket.write not writing commands

k-bharath-7 opened this issue · 1 comments

OS: Ubuntu 20.04
Node version: v16.18.1 / v12.12.0 / v10.15.3
node-bluetooth-hci-socket: v0.5.3-8

The following code is used to crearte le conn with the bluetooth device but this is not working and connection is not created. This is used in @abandonware/noble package.

const { minInterval = 0x0006, maxInterval = 0x000c, latency = 0x0000, timeout = 0x00c8 } = parameters;

  const cmd = Buffer.alloc(29);

  // header
  cmd.writeUInt8(HCI_COMMAND_PKT, 0);
  cmd.writeUInt16LE(LE_CREATE_CONN_CMD, 1);

  // length
  cmd.writeUInt8(0x19, 3);

  // data
  cmd.writeUInt16LE(0x0060, 4); // interval
  cmd.writeUInt16LE(0x0030, 6); // window
  cmd.writeUInt8(0x00, 8); // initiator filter

  cmd.writeUInt8(addressType === 'random' ? 0x01 : 0x00, 9); // peer address type
  (Buffer.from(address.split(':').reverse().join(''), 'hex')).copy(cmd, 10); // peer address

  cmd.writeUInt8(0x00, 16); // own address type

  cmd.writeUInt16LE(minInterval, 17); // min interval
  cmd.writeUInt16LE(maxInterval, 19); // max interval
  cmd.writeUInt16LE(latency, 21); // latency
  cmd.writeUInt16LE(timeout, 23); // supervision timeout
  cmd.writeUInt16LE(0x0004, 25); // min ce length
  cmd.writeUInt16LE(0x0006, 27); // max ce length

  debug("create le conn - writing:", ${cmd.toString('hex')});
  this._socket.write(cmd);
rzr commented