From 5b9ce0003f1aa69723b80913cf65df647c92e774 Mon Sep 17 00:00:00 2001 From: Ingo Fischer Date: Mon, 6 Nov 2023 11:14:45 +0100 Subject: [PATCH] fix deprecated Buffer usage and try to get jshint active again --- README.md | 4 ++-- examples/le-advertisement-test.js | 16 ++++++++-------- examples/le-connection-test.js | 12 ++++++------ examples/le-scan-test.js | 6 +++--- examples/mgmt-test.js | 2 +- lib/usb.js | 12 ++++++------ package.json | 2 +- 7 files changed, 27 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 6ba0f82..a57dbf7 100644 --- a/README.md +++ b/README.md @@ -97,7 +97,7 @@ var bluetoothHciSocket = new BluetoothHciSocket(); #### Set Filter ```javascript -var filter = new Buffer(14); +var filter = Buffer.alloc(14); // ... @@ -155,7 +155,7 @@ __Note:__ must be called after ```bindRaw``` or ```bindControl```. #### Write ```javascript -var data = new Buffer(/* ... */); +var data = Buffer.from(/* ... */); // ... diff --git a/examples/le-advertisement-test.js b/examples/le-advertisement-test.js index 9620e38..b140f9e 100644 --- a/examples/le-advertisement-test.js +++ b/examples/le-advertisement-test.js @@ -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)); @@ -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); @@ -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); @@ -155,7 +155,7 @@ function setAdvertisingParameter() { }; function setAdvertisingData(data) { - var cmd = new Buffer(36); + var cmd = Buffer.alloc(36); cmd.fill(0); @@ -175,7 +175,7 @@ function setAdvertisingData(data) { } function setScanResponseData(data) { - var cmd = new Buffer(36); + var cmd = Buffer.alloc(36); cmd.fill(0); @@ -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); @@ -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); diff --git a/examples/le-connection-test.js b/examples/le-connection-test.js index 003e778..400aad5 100644 --- a/examples/le-connection-test.js +++ b/examples/le-connection-test.js @@ -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) { @@ -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)); @@ -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); @@ -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 @@ -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); @@ -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); diff --git a/examples/le-scan-test.js b/examples/le-scan-test.js index e573c53..813fc4d 100644 --- a/examples/le-scan-test.js +++ b/examples/le-scan-test.js @@ -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)); @@ -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); @@ -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); diff --git a/examples/mgmt-test.js b/examples/mgmt-test.js index b5935e3..89dc2a4 100644 --- a/examples/mgmt-test.js +++ b/examples/mgmt-test.js @@ -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); diff --git a/lib/usb.js b/lib/usb.js index aaa20c0..85e2bc4 100644 --- a/lib/usb.js +++ b/lib/usb.js @@ -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 @@ -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); @@ -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 ])); @@ -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 ])); @@ -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); diff --git a/package.json b/package.json index 0e78a5a..c83a459 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ }, "scripts": { "install": "node-pre-gyp install --fallback-to-build --update-binary", - "test": "jshint lib/*.js && node test.js" + "test": "jshint 'lib/*.js' && node test.js" }, "binary": { "module_name": "bluetooth_hci_socket",