Skip to content
Open
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
20 changes: 3 additions & 17 deletions lib/beacon.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,26 @@ function Beacon() {
Beacon.prototype.advertiseUid = function(namespaceId, instanceId, options) {
this._parseOptions(options);

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

this._advertisementData = AdvertisementData.makeUidBuffer(namespaceId, instanceId, this._txPowerLevel, bleno.platform);
this._mainAdvertisementData = this._advertisementData;

this._advertiseWhenPoweredOn();
};

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

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

this._advertisementData = AdvertisementData.makeUrlBuffer(url, this._txPowerLevel, bleno.platform);
this._mainAdvertisementData = this._advertisementData;

this._advertiseWhenPoweredOn();
};

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

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

this._removeFlagsIfOsX();
this._advertiseWhenPoweredOn();
};

Expand Down Expand Up @@ -124,12 +116,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
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
],
"repository": {
"type": "git",
"url": "https://github.com/don/node-eddystone-beacon.git"
"url": "https://github.com/don/node-eddystone-beacon.git"
},
"main": "index.js",
"scripts": {
"pretest": "jshint *.js lib/. test/. examples/.",
"test": "mocha -R spec --recursive test/"
"test": "mocha -R spec --recursive test/"
},
"author": "Don Coleman <don.coleman@gmail.com>",
"maintainers": [
Expand All @@ -36,11 +36,11 @@
],
"license": "Apache-2.0",
"dependencies": {
"bleno": "~0.1.13",
"bleno": "^0.3.0",
"eddystone-url-encoding": "^1.0.0"
},
"devDependencies": {
"jshint": "~2.5.6",
"mocha": "~1.21.4"
"jshint": "~2.5.6",
"mocha": "~1.21.4"
}
}