Skip to content

Commit

Permalink
fix deprecated Buffer usage and try to get jshint active again
Browse files Browse the repository at this point in the history
Last-Update: 2024-02-11
Origin: https://github.com/Apollon77/node-bluetooth-hci-socket/tree/buildupgrade
Signed-off-by: Philippe Coval <rzr@users.sf.net>
  • Loading branch information
rzr committed Feb 11, 2024
1 parent 216e342 commit 763d263
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ var bluetoothHciSocket = new BluetoothHciSocket();
#### Set Filter

```javascript
var filter = new Buffer(14);
var filter = Buffer.alloc(14);

// ...

Expand Down Expand Up @@ -155,7 +155,7 @@ __Note:__ must be called after ```bindRaw``` or ```bindControl```.
#### Write

```javascript
var data = new Buffer(/* ... */);
var data = Buffer.from(/* ... */);

// ...

Expand Down
16 changes: 8 additions & 8 deletions examples/le-advertisement-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ var LE_SET_ADVERTISE_ENABLE_CMD = OCF_LE_SET_ADVERTISE_ENABLE | OGF_LE_CTL << 10
var HCI_SUCCESS = 0;

function setFilter() {
var filter = new Buffer(14);
var filter = Buffer.alloc(14);
var typeMask = (1 << HCI_EVENT_PKT) | (1 << HCI_ACLDATA_PKT);
var eventMask1 = (1 << EVT_DISCONN_COMPLETE) | (1 << EVT_CMD_COMPLETE) | (1 << EVT_CMD_STATUS);
var eventMask2 = (1 << (EVT_LE_META_EVENT - 32));
Expand All @@ -131,7 +131,7 @@ function setFilter() {
}

function setAdvertisingParameter() {
var cmd = new Buffer(19);
var cmd = Buffer.alloc(19);

// header
cmd.writeUInt8(HCI_COMMAND_PKT, 0);
Expand All @@ -146,7 +146,7 @@ function setAdvertisingParameter() {
cmd.writeUInt8(0x00, 8); // adv type
cmd.writeUInt8(0x00, 9); // own addr typ
cmd.writeUInt8(0x00, 10); // direct addr type
(new Buffer('000000000000', 'hex')).copy(cmd, 11); // direct addr
(Buffer.from('000000000000', 'hex')).copy(cmd, 11); // direct addr
cmd.writeUInt8(0x07, 17);
cmd.writeUInt8(0x00, 18);

Expand All @@ -155,7 +155,7 @@ function setAdvertisingParameter() {
};

function setAdvertisingData(data) {
var cmd = new Buffer(36);
var cmd = Buffer.alloc(36);

cmd.fill(0);

Expand All @@ -175,7 +175,7 @@ function setAdvertisingData(data) {
}

function setScanResponseData(data) {
var cmd = new Buffer(36);
var cmd = Buffer.alloc(36);

cmd.fill(0);

Expand All @@ -195,7 +195,7 @@ function setScanResponseData(data) {
}

function setAdvertiseEnable(enabled) {
var cmd = new Buffer(5);
var cmd = Buffer.alloc(5);

// header
cmd.writeUInt8(HCI_COMMAND_PKT, 0);
Expand All @@ -219,6 +219,6 @@ console.log('isDevUp = ' + bluetoothHciSocket.isDevUp());

setAdvertiseEnable(false);
setAdvertisingParameter();
setScanResponseData(new Buffer('0909657374696d6f74650e160a182eb8855fb5ddb601000200', 'hex'));
setAdvertisingData(new Buffer('0201061aff4c000215b9407f30f5f8466eaff925556b57fe6d00010002b6', 'hex'));
setScanResponseData(Buffer.from('0909657374696d6f74650e160a182eb8855fb5ddb601000200', 'hex'));
setAdvertisingData(Buffer.from('0201061aff4c000215b9407f30f5f8466eaff925556b57fe6d00010002b6', 'hex'));
setAdvertiseEnable(true);
12 changes: 6 additions & 6 deletions examples/le-connection-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bluetoothHciSocket.on('data', function(data) {
console.log('\t' + latency);
console.log('\t' + supervisionTimeout * 10);

writeHandle(handle, new Buffer('020001', 'hex'));
writeHandle(handle, Buffer.from('020001', 'hex'));
}
}
} else if (data.readUInt8(0) === HCI_ACLDATA_PKT) {
Expand Down Expand Up @@ -112,7 +112,7 @@ var HCI_SUCCESS = 0;
var HCI_OE_USER_ENDED_CONNECTION = 0x13;

function setFilter() {
var filter = new Buffer(14);
var filter = Buffer.alloc(14);
var typeMask = (1 << HCI_EVENT_PKT) | (1 << HCI_ACLDATA_PKT);
var eventMask1 = (1 << EVT_DISCONN_COMPLETE) | (1 << EVT_CMD_COMPLETE) | (1 << EVT_CMD_STATUS);
var eventMask2 = (1 << (EVT_LE_META_EVENT - 32));
Expand All @@ -131,7 +131,7 @@ setFilter();
bluetoothHciSocket.start();

function createConnection(address, addressType) {
var cmd = new Buffer(29);
var cmd = Buffer.alloc(29);

// header
cmd.writeUInt8(HCI_COMMAND_PKT, 0);
Expand All @@ -146,7 +146,7 @@ function createConnection(address, addressType) {
cmd.writeUInt8(0x00, 8); // initiator filter

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

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

Expand All @@ -161,7 +161,7 @@ function createConnection(address, addressType) {
}

function writeHandle(handle, data) {
var cmd = new Buffer(9 + data.length);
var cmd = Buffer.alloc(9 + data.length);

// header
cmd.writeUInt8(HCI_ACLDATA_PKT, 0);
Expand All @@ -176,7 +176,7 @@ function writeHandle(handle, data) {
}

function disconnectConnection(handle, reason) {
var cmd = new Buffer(7);
var cmd = Buffer.alloc(7);

// header
cmd.writeUInt8(HCI_COMMAND_PKT, 0);
Expand Down
6 changes: 3 additions & 3 deletions examples/le-scan-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var LE_SET_SCAN_ENABLE_CMD = OCF_LE_SET_SCAN_ENABLE | OGF_LE_CTL << 10;
var HCI_SUCCESS = 0;

function setFilter() {
var filter = new Buffer(14);
var filter = Buffer.alloc(14);
var typeMask = (1 << HCI_EVENT_PKT);
var eventMask1 = (1 << EVT_CMD_COMPLETE) | (1 << EVT_CMD_STATUS);
var eventMask2 = (1 << (EVT_LE_META_EVENT - 32));
Expand All @@ -84,7 +84,7 @@ function setFilter() {
}

function setScanParameters() {
var cmd = new Buffer(11);
var cmd = Buffer.alloc(11);

// header
cmd.writeUInt8(HCI_COMMAND_PKT, 0);
Expand All @@ -104,7 +104,7 @@ function setScanParameters() {
}

function setScanEnable(enabled, duplicates) {
var cmd = new Buffer(6);
var cmd = Buffer.alloc(6);

// header
cmd.writeUInt8(HCI_COMMAND_PKT, 0);
Expand Down
2 changes: 1 addition & 1 deletion examples/mgmt-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function write(opcode, index, data) {
length += data.length;
}

var pkt = new Buffer(6 + length);
var pkt = Buffer.alloc(6 + length);

pkt.writeUInt16LE(opcode, 0);
pkt.writeUInt16LE(index, 2);
Expand Down
12 changes: 6 additions & 6 deletions lib/usb.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var OCF_RESET = 0x0003;
var VENDOR_DEVICE_LIST = [
{vid: 0x0CF3, pid: 0xE300 }, // Qualcomm Atheros QCA61x4
{vid: 0x0a5c, pid: 0x21e8 }, // Broadcom BCM20702A0
{vid: 0x0a5c, pid: 0x21f1 }, // Broadcom BCM20702A0
{vid: 0x0a5c, pid: 0x21f1 }, // Broadcom BCM20702A0
{vid: 0x19ff, pid: 0x0239 }, // Broadcom BCM20702A0
{vid: 0x413c, pid: 0x8143 }, // Broadcom BCM20702A0
{vid: 0x0a12, pid: 0x0001 }, // CSR
Expand All @@ -33,8 +33,8 @@ var VENDOR_DEVICE_LIST = [
function BluetoothHciSocket() {
this._isUp = false;

this._hciEventEndpointBuffer = new Buffer(0);
this._aclDataInEndpointBuffer = new Buffer(0);
this._hciEventEndpointBuffer = Buffer.alloc(0);
this._aclDataInEndpointBuffer = Buffer.alloc(0);
}

util.inherits(BluetoothHciSocket, events.EventEmitter);
Expand Down Expand Up @@ -246,7 +246,7 @@ BluetoothHciSocket.prototype.onHciEventEndpointData = function(data) {

// fire event
this.emit('data', Buffer.concat([
new Buffer([HCI_EVENT_PKT]),
Buffer.from([HCI_EVENT_PKT]),
buf
]));

Expand Down Expand Up @@ -280,7 +280,7 @@ BluetoothHciSocket.prototype.onAclDataInEndpointData = function(data) {

// fire event
this.emit('data', Buffer.concat([
new Buffer([HCI_ACLDATA_PKT]),
Buffer.from([HCI_ACLDATA_PKT]),
buf
]));

Expand All @@ -290,7 +290,7 @@ BluetoothHciSocket.prototype.onAclDataInEndpointData = function(data) {
};

BluetoothHciSocket.prototype.reset = function() {
var cmd = new Buffer(4);
var cmd = Buffer.alloc(4);

// header
cmd.writeUInt8(HCI_COMMAND_PKT, 0);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"node": ">=10.0.0"
},
"scripts": {
"install": "node-pre-gyp install --build-from-source",
"install": "node-pre-gyp install --fallback-to-build --update-binary",
"test": "jshint lib/*.js && node test.js"
},
"binary": {
Expand Down

0 comments on commit 763d263

Please sign in to comment.