Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 21 additions & 25 deletions lib/beacon.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,37 +23,39 @@ function Beacon() {
}

Beacon.prototype.advertiseUid = function(namespaceId, instanceId, options) {
var self = this;
this._parseOptions(options);

this._advertisementData = AdvertisementData.makeUidBuffer(namespaceId, instanceId, this._txPowerLevel);
this._removeFlagsIfOsX();

this._mainAdvertisementData = this._advertisementData;

this._advertiseWhenPoweredOn();
bleno.platform(function(error, platform){
self._advertisementData = AdvertisementData.makeUidBuffer(namespaceId, instanceId, self._txPowerLevel, platform);
self._mainAdvertisementData = self._advertisementData;
self._advertiseWhenPoweredOn();
});
};

Beacon.prototype.advertiseUrl = function(url, options) {
var self = this;
this._parseOptions(options);

this._advertisementData = AdvertisementData.makeUrlBuffer(url, this._txPowerLevel);
this._removeFlagsIfOsX();

this._mainAdvertisementData = this._advertisementData;

this._advertiseWhenPoweredOn();
bleno.platform(function(error, platform){
self._advertisementData = AdvertisementData.makeUrlBuffer(url, self._txPowerLevel, platform);
self._mainAdvertisementData = self._advertisementData;
self._advertiseWhenPoweredOn();
});
};

Beacon.prototype.advertiseTlm = function() {
this._advertisementData = AdvertisementData.makeTlmBuffer(this._batteryVoltage, this._temperature, this._advCnt, this._secCnt);
var self = this;

if (this._tlmPeriod === 0) {
this._tlmPeriod = 1;
this._tlmCount = 1;
}
bleno.platform(function(error, platform){
self._advertisementData = AdvertisementData.makeTlmBuffer(self._batteryVoltage, self._temperature, self._advCnt, self._secCnt, platform);

this._removeFlagsIfOsX();
this._advertiseWhenPoweredOn();
if (self._tlmPeriod === 0) {
self._tlmPeriod = 1;
self._tlmCount = 1;
}
self._advertiseWhenPoweredOn();
});
};

Beacon.prototype.setBatteryVoltage = function(batteryVoltage) {
Expand Down Expand Up @@ -124,12 +126,6 @@ Beacon.prototype._advertise = function() {
}
};

Beacon.prototype._removeFlagsIfOsX = function() {
if (os.platform() === 'darwin') {
this._advertisementData = this._advertisementData.slice(3);
}
};

Beacon.prototype._tick = function() {
this._secCnt++;

Expand Down
18 changes: 10 additions & 8 deletions lib/util/advertisement-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var TLM_VERSION = 0x00;

var MAX_URL_LENGTH = 18;

var makeUidBuffer = function (namespaceId, instanceId, txPowerLevel) {
var makeUidBuffer = function (namespaceId, instanceId, txPowerLevel, platform) {
var namespaceIdData = hexStringIdToBuffer(namespaceId);
var instanceUidData = hexStringIdToBuffer(instanceId);
var rfu = new Buffer([0x00, 0x00]);
Expand All @@ -32,10 +32,10 @@ var makeUidBuffer = function (namespaceId, instanceId, txPowerLevel) {
rfu
]);

return makeEddystoneBuffer(UID_FRAME_TYPE, data);
return makeEddystoneBuffer(UID_FRAME_TYPE, data, platform);
};

var makeUrlBuffer = function (url, txPowerLevel) {
var makeUrlBuffer = function (url, txPowerLevel, platform) {
var encodedUrl = encode(url);
var txPowerLevelData = makeTxPowerLevelBuffer(txPowerLevel);

Expand All @@ -49,10 +49,10 @@ var makeUrlBuffer = function (url, txPowerLevel) {
encodedUrl
]);

return makeEddystoneBuffer(URL_FRAME_TYPE, data);
return makeEddystoneBuffer(URL_FRAME_TYPE, data, platform);
};

var makeTlmBuffer = function (vBatt, temp, advCnt, secCnt) {
var makeTlmBuffer = function (vBatt, temp, advCnt, secCnt, platform) {
var tlmData = new Buffer(13);

tlmData.writeUInt8(TLM_VERSION, 0);
Expand All @@ -62,11 +62,11 @@ var makeTlmBuffer = function (vBatt, temp, advCnt, secCnt) {
tlmData.writeUInt32BE(advCnt, 5);
tlmData.writeUInt32BE(secCnt, 9);

return makeEddystoneBuffer(TLM_FRAME_TYPE, tlmData);
return makeEddystoneBuffer(TLM_FRAME_TYPE, tlmData, platform);
};


var makeEddystoneBuffer = function(flags, data) {
var makeEddystoneBuffer = function(flags, data, platform) {
var header = new Buffer(1);

header.writeUInt8(flags, 0);
Expand All @@ -78,7 +78,9 @@ var makeEddystoneBuffer = function(flags, data) {

var eir = new Eir();

eir.addFlags(0x06);
if(platform !== 'darwin'){
eir.addFlags(0x06);
}
eir.add16BitCompleteServiceList([SERVICE_UUID]);
eir.addServiceData(SERVICE_UUID, serviceData);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
],
"license": "Apache-2.0",
"dependencies": {
"bleno": "~0.1.13",
"bleno": "git+https://github.com/jacobrosenthal/bleno#websocket-platformcheck",
"eddystone-url-encoding": "^1.0.0"
},
"devDependencies": {
Expand Down