Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit eaf7361

Browse files
authored
Increase ci (#889)
* Change MTU size of BLE transfer packets This change allows us to monkeypatch the increase in MTU size to optimize the data transfer rate. Currently, we are setting it at 505, which is the limit the android can accept. * Allow for Changing the Connection Interval This change allows us to change the connection interval through system calls when we obtain the connection handle. It's hacky, but it accomplishes the task. It's important to note a few things. First, the Bluetooth specs require that a connection interval as low as 7.5 ms. Second, there is a 1.25 multiplier on the min & max settings.
1 parent 6a27a43 commit eaf7361

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

nodejs/FatBeaconPeripheral/FatBeacon.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ var AdvertisementData =
1414
require('eddystone-beacon/lib/util/advertisement-data');
1515
var Eir = require('eddystone-beacon/lib/util/eir');
1616
var Gatt = require('bleno/lib/hci-socket/gatt');
17+
var Hci = require('bleno/lib/hci-socket/hci');
18+
var exec = require('child_process').exec;
1719

1820
var FAT_BEACON_FRAME_TYPE = 0x0e;
1921
var MAX_URL_LENGTH = 18;
@@ -81,6 +83,55 @@ Gatt.prototype.handleMtuRequest = function(request) {
8183
return response;
8284
};
8385

86+
/**
87+
* Change the connection interval through commandline tool hcileup. Specs,
88+
* allow for a 7.5ms connection interval. Note, there is a 1.25 multiplier
89+
* on the min and max values.
90+
*/
91+
Hci.changeConnectionInterval = function(handle) {
92+
var min = 6; // Will be multiplied by 1.25.
93+
var max = 7; // Will be multiplied by 1.25.
94+
var latency = 0;
95+
var timeout = 500;
96+
97+
var cmd = `hcitool lecup --handle ${handle} --min ${min} --max ${max} ` +
98+
`--latency ${latency} --timeout ${timeout}`;
99+
100+
console.log(cmd);
101+
102+
exec(cmd, function(error, stdout, stderr) {
103+
if(stdout !== null) {
104+
console.log('stdout:\t' + stdout );
105+
}
106+
if(stderr !== null) {
107+
console.log('stderr:\t' + stderr);
108+
}
109+
if(error !== null) {
110+
console.log('ERROR:\t' + error);
111+
}
112+
});
113+
};
114+
115+
/**
116+
* Does the standard processLeConnComplete library behavior, but calls our
117+
* custom changeConnectionInterval function to optimize CI.
118+
*/
119+
Hci.prototype.processLeConnComplete = function(status, data) {
120+
var handle = data.readUInt16LE(0);
121+
var role = data.readUInt8(2);
122+
var addressType = data.readUInt8(3) === 0x01 ? 'random': 'public';
123+
var address = data.slice(4, 10).toString('hex').match(/.{1,2}/g).reverse().join(':');
124+
var interval = data.readUInt16LE(10) * 1.25;
125+
var latency = data.readUInt16LE(12); // TODO: multiplier?
126+
var supervisionTimeout = data.readUInt16LE(14) * 10;
127+
var masterClockAccuracy = data.readUInt8(16); // TODO: multiplier?
128+
129+
Hci.changeConnectionInterval(handle);
130+
131+
this.emit('leConnComplete', status, handle, role, addressType, address,
132+
interval, latency, supervisionTimeout, masterClockAccuracy);
133+
};
134+
84135
/*********************************************************/
85136

86137
var characteristic = new webpageCharacteristic();

0 commit comments

Comments
 (0)