Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow multiple manufacturer specific data #2

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
25 changes: 25 additions & 0 deletions lib/ble/common/manufacturers/altbeacon/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright reelyActive 2015-2016
* We believe in an open Internet of Things
*/

//var ibeacon = require('./ibeacon.js');


/**
* Parse BLE advertiser manufacturer specific data for Apple.
* @param {Object} advertiserData The object containing all parsed data.
*/
function process(manufacturerSpecificData) {

var data = manufacturerSpecificData.data;

var beaconId = data.substr(4,40);
var rssi = data.substr(44, 2);
var reserved = data.substr(46, 2);

manufacturerSpecificData.altbeacon = {beaconId: beaconId, refRSSI: rssi, reserved: reserved};
}


module.exports.process = process;
6 changes: 3 additions & 3 deletions lib/ble/common/manufacturers/apple/ibeacon.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ var licenseeNames = {
* Parse Apple iBeacon manufacturer specific data.
* @param {Object} advertiserData The object containing all parsed data.
*/
function process(advertiserData) {
function process(manufacturerSpecificData) {
var iBeacon = {};
var data = advertiserData.manufacturerSpecificData.data;
var data = manufacturerSpecificData.data;

iBeacon.uuid = data.substr(4,32);
iBeacon.major = data.substr(36,4);
Expand All @@ -46,7 +46,7 @@ function process(advertiserData) {
}
iBeacon.licenseeName = licenseeName;

advertiserData.manufacturerSpecificData.iBeacon = iBeacon;
manufacturerSpecificData.iBeacon = iBeacon;
}


Expand Down
6 changes: 3 additions & 3 deletions lib/ble/common/manufacturers/apple/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ var ibeacon = require('./ibeacon.js');
* Parse BLE advertiser manufacturer specific data for Apple.
* @param {Object} advertiserData The object containing all parsed data.
*/
function process(advertiserData) {
var data = advertiserData.manufacturerSpecificData.data;
function process(manufacturerSpecificData) {
var data = manufacturerSpecificData.data;
var appleType = data.substr(0,2);

switch(appleType) {
case '02':
ibeacon.process(advertiserData);
ibeacon.process(manufacturerSpecificData);
break;
case '09':
// TODO: processAppleTV and/or whatever else uses this
Expand Down
6 changes: 3 additions & 3 deletions lib/ble/common/manufacturers/estimote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ var nearable = require('./nearable.js');
* Parse BLE advertiser manufacturer specific data for Estimote.
* @param {Object} advertiserData The object containing all parsed data.
*/
function process(advertiserData) {
var data = advertiserData.manufacturerSpecificData.data;
function process(manufacturerSpecificData) {
var data = manufacturerSpecificData.data;
var packetType = data.substr(0,2);

switch(packetType) { // Update when we have manufacturer documentation
case '01':
default:
nearable.process(advertiserData);
nearable.process(manufacturerSpecificData);
}
}

Expand Down
8 changes: 4 additions & 4 deletions lib/ble/common/manufacturers/estimote/nearable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

/**
* Parse Estimote Nearable manufacturer specific data.
* @param {Object} advertiserData The object containing all parsed data.
* @param {Object} manufacturerSpecificData The object containing all parsed data.
*/
function process(advertiserData) {
function process(manufacturerSpecificData) {
var nearable = {};
var data = advertiserData.manufacturerSpecificData.data;
var data = manufacturerSpecificData.data;

nearable.id = data.substr(2,16);
nearable.temperature = toTemperature(data.substr(24,2), data.substr(22,2));
Expand All @@ -29,7 +29,7 @@ function process(advertiserData) {
data.substr(20,2), data.substr(24,2),
data.substr(26,2), data.substr(38,2) ];

advertiserData.manufacturerSpecificData.nearable = nearable;
manufacturerSpecificData.nearable = nearable;
}


Expand Down
2 changes: 2 additions & 0 deletions lib/ble/common/manufacturers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
*/

var apple = require('./apple/index.js');
var altbeacon = require('./altbeacon/index.js');
var sticknfind = require('./sticknfind/index.js');
var estimote = require('./estimote/index.js');

module.exports.apple = apple;
module.exports.altbeacon = altbeacon;
module.exports.sticknfind = sticknfind;
module.exports.estimote = estimote;
10 changes: 5 additions & 5 deletions lib/ble/common/manufacturers/sticknfind/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ var snsmotion = require('./snsmotion.js');

/**
* Parse BLE advertiser manufacturer specific data for StickNFind.
* @param {Object} advertiserData The object containing all parsed data.
* @param {Object} manufacturerSpecificData The object containing all parsed data.
*/
function process(advertiserData) {
var data = advertiserData.manufacturerSpecificData.data;
function process(manufacturerSpecificData) {
var data = manufacturerSpecificData.data;
var packetType = data.substr(0,2);

switch(packetType) {
case '01':
snfsingle.process(advertiserData);
snfsingle.process(manufacturerSpecificData);
break;
case '42':
snsmotion.process(advertiserData);
snsmotion.process(manufacturerSpecificData);
break;
default:
}
Expand Down
8 changes: 4 additions & 4 deletions lib/ble/common/manufacturers/sticknfind/snfsingle.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ var pdu = require('../../util/pdu.js');

/**
* Parse StickNFind 'single payload' manufacturer specific data.
* @param {Object} advertiserData The object containing all parsed data.
* @param {Object} manufacturerSpecificData The object containing all parsed data.
*/
function process(advertiserData) {
function process(manufacturerSpecificData) {
var snfBeacon = {};
var data = advertiserData.manufacturerSpecificData.data;
var data = manufacturerSpecificData.data;

snfBeacon.type = 'V2 Single Payload';
snfBeacon.id = pdu.reverseBytes(data.substr(2,16));
Expand All @@ -28,7 +28,7 @@ function process(advertiserData) {
snfBeacon.calibration = data.substr(32,2);
snfBeacon.checksum = data.substr(34,6);

advertiserData.manufacturerSpecificData.snfBeacon = snfBeacon;
manufacturerSpecificData.snfBeacon = snfBeacon;
}


Expand Down
8 changes: 4 additions & 4 deletions lib/ble/common/manufacturers/sticknfind/snsmotion.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ var pdu = require('../../util/pdu.js');

/**
* Parse StickNSense 'motion' manufacturer specific data.
* @param {Object} advertiserData The object containing all parsed data.
* @param {Object} manufacturerSpecificData The object containing all parsed data.
*/
function process(advertiserData) {
function process(manufacturerSpecificData) {
var snfBeacon = {};
var data = advertiserData.manufacturerSpecificData.data;
var data = manufacturerSpecificData.data;

snfBeacon.type = 'SnS Motion';
snfBeacon.timestamp = parseInt(pdu.reverseBytes(data.substr(2,8)),16);
Expand Down Expand Up @@ -42,7 +42,7 @@ function process(advertiserData) {
snfBeacon.accelerationZ = parseInt((data.substr(36,2) +
data.substr(40,1)), 16);

advertiserData.manufacturerSpecificData.snfBeacon = snfBeacon;
manufacturerSpecificData.snfBeacon = snfBeacon;
}


Expand Down
52 changes: 39 additions & 13 deletions lib/ble/data/gap/manufacturerspecificdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var pdu = require('../../common/util/pdu.js');
var companyIdentifierCodes =
require('../../common/assignednumbers/companyidentifiercodes.js');
var apple = require('../../common/manufacturers/apple/index.js');
var altbeacon = require('../../common/manufacturers/altbeacon/index.js');
var sticknfind = require('../../common/manufacturers/sticknfind/index.js');
var estimote = require('../../common/manufacturers/estimote/index.js');

Expand All @@ -21,31 +22,56 @@ function process(payload, cursor, advertiserData) {
var companyIdentifierCode = payload.substr(cursor+6, 2);
companyIdentifierCode += payload.substr(cursor+4, 2);

var altBeacon = false;

var adLength = payload.substr(cursor, 2);

if (adLength == "1b")
{
var beaconCode = payload.substr(cursor+8, 4);

if (beaconCode == "beac")
{
altBeacon = true;
}
}

var companyName = companyIdentifierCodes.companyNames[companyIdentifierCode];
if(typeof companyName === 'undefined') {
companyName = 'Unknown';
}

var data = payload.substr(cursor+8, pdu.getTagDataLength(payload, cursor)-4);

advertiserData.manufacturerSpecificData = {
if (!advertiserData.manufacturerSpecificData)
advertiserData.manufacturerSpecificData = [];

advertiserData.manufacturerSpecificData.push({
companyName : companyName,
companyIdentifierCode: companyIdentifierCode,
data: data };
data: data });

// Interpret the manufacturer specific data, if possible
// Kindly respect ascending order of company identifier codes
switch(companyIdentifierCode) {
case '004c':
apple.process(advertiserData);
break;
case '00f9':
sticknfind.process(advertiserData);
break;
case '015d':
estimote.process(advertiserData);
break;
default:

if (altBeacon)
{
altbeacon.process(advertiserData.manufacturerSpecificData[advertiserData.manufacturerSpecificData.length-1]);
}
else
{
switch(companyIdentifierCode) {
case '004c':
apple.process(advertiserData.manufacturerSpecificData[advertiserData.manufacturerSpecificData.length-1]);
break;
case '00f9':
sticknfind.process(advertiserData.manufacturerSpecificData[advertiserData.manufacturerSpecificData.length-1]);
break;
case '015d':
estimote.process(advertiserData.manufacturerSpecificData[advertiserData.manufacturerSpecificData.length-1]);
break;
default:
}
}
}

Expand Down