/** * * User: Martin Donnelly * Date: 2016-05-24 * Time: 14:21 * */ var MANUFACTUREDECODER = function() { 'use strict'; this.getManID = function(data) { return ('0000' + ((data[1] << 8) | data[0]).toString(16)).slice(-4).toUpperCase(); }, this.decodeIbeacon = function(data) { // Not decoding anything yet. // https://support.kontakt.io/hc/en-gb/articles/201492492-iBeacon-advertising-packet-structure var bin = data; var obj = { msg: '(iBeacon)'}; // obj.manID = ('0000' + ((bin[1] << 8) | bin[0]).toString(16)).slice(-4); obj.manID = this.getManID(bin); var uuid = []; uuid.push(bin[4].toString(16) + bin[5].toString(16) + bin[6].toString(16) + bin[7].toString(16)) ; uuid.push(bin[8].toString(16) + bin[9].toString(16)) ; uuid.push(bin[10].toString(16) + bin[11].toString(16)) ; uuid.push(bin[12].toString(16) + bin[13].toString(16)) ; uuid.push(bin[14].toString(16) + bin[15].toString(16) + bin[16].toString(16) + bin[17].toString(16) + bin[18].toString(16) + bin[19].toString(16)) ; obj.uuid = uuid.join('-'); return obj; }; this.decodeSiliconLabsSensorPuck = function(data) { var bin = data; var obj = {data:{}}; //obj.manID = ('0000' + ((bin[1] << 8) | bin[0]).toString(16)).slice(-4); obj.manID = this.getManID(bin); obj.a = (bin[3] << 8) | bin[2]; obj.b = (bin[5] << 8) | bin[4]; obj.data.humidity = (bin[7] << 8) | bin[6]; obj.data.temp = (bin[9] << 8) | bin[8]; obj.c = (bin[11] << 8) | bin[10]; obj.d = (bin[13] << 8) | bin[12]; obj.msg = 'Humidity: ' + (obj.data.humidity / 10) + ', temp: ' + (obj.data.temp / 10); return obj; }; this.decodeSansible = function(data) { var bin = data; var obj = {data:{}}; // obj.manID = ('0000' + ((bin[1] << 8) | bin[0]).toString(16)).slice(-4); obj.manID = this.getManID(bin); obj.data.p1 = ((bin[2] << 16) | bin[3] << 8 | bin[4]); obj.data.p2 = ((bin[5] << 16) | bin[6] << 8 | bin[7]); obj.msg = 'Left: ' + (obj.data.p1 / 100) + ' hPa, Right: ' + (obj.data.p2 / 100) + ' hPa'; return obj; }; }; /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ /* global mui, bt_company_ids, ble, LocalFileSystem, capabilityManager, MANUFACTUREDECODER */ var app = { stop: false, log: {}, activeServices: {}, list: {}, foundDevices: {}, manufactureDecoder: new MANUFACTUREDECODER(), // Application Constructor initialize: function() { this.bindEvents(); }, arrayBufferToIntArray: function(buffer) { var result; if (buffer) { var typedArray = new Uint8Array(buffer); result = []; for (var i = 0; i < typedArray.length; i++) { result[i] = typedArray[i]; } } return result; }, parseAdvertisingData: function(bytes) { var length, type, data, i = 0, advertisementData = {}; while (length !== 0) { length = bytes[i] & 0xFF; i++; type = bytes[i] & 0xFF; i++; data = bytes.slice(i, i + length - 1); // Length includes type byte, but not length byte i += length - 2; // Move to end of data i++; advertisementData[type] = data; } return advertisementData; }, handle255: function(buffer) { 'use strict'; var company; var cid; var manID; var bin = buffer; var decoded = {}; void 0; /* var manSpec = bin.map(function(i) { return i.toString(16) + ' '; }); console.log('manSpec: ', manSpec); */ manID = app.manufactureDecoder.getManID(bin); void 0; cid = '0x' + manID; company = bt_company_ids.find(cid); switch (manID) { case '004c': { decoded = app.manufactureDecoder.decodeIbeacon(bin); decoded.company = company; break; } case '1235': { decoded = app.manufactureDecoder.decodeSiliconLabsSensorPuck(bin); decoded.company = company; break; } case '0060': { decoded = app.manufactureDecoder.decodeSansible(bin); decoded.company = company; break; } default: { void 0; decoded = {company: company}; } } return decoded; }, makeHexBuffer: function(buffer) { 'use strict'; var hexBuffer = buffer.map(function(i) { return ('00' + i.toString(16)).slice(-2) + ','; }); return hexBuffer; }, makeChars: function(buffer) { 'use strict'; var output = buffer.map(function(i) { return String.fromCharCode(i); }); return output; }, buildNewDeviceResultPanel: function(device) { 'use strict'; var newPanel, newRow; var otherData = device.otherData; var newId = 'd-' + device.id.replace(/:/g, ''); var title = device.hasOwnProperty('name') ? device.name : '*** Unknown'; newPanel = $('