diff --git a/run_cordova.sh b/run_cordova.sh index bea3334..5eb863f 100755 --- a/run_cordova.sh +++ b/run_cordova.sh @@ -1,9 +1,20 @@ #!/bin/sh set -e # stop on errors cd www/js + +# add a variable to our index containing the git hash +cp index.js noGitIndex.js +echo window.gitRevision = \"$(git rev-parse --short HEAD)\"\; | cat - index.js > temp && mv temp index.js + coffee --compile mm.coffee browserify index.js -o bundle.js cd ../.. cordova run --device -rm www/js/bundle.js -rm www/js/mm.js \ No newline at end of file + +cd www/js + +rm bundle.js +rm mm.js + +# forget our temporary index +mv noGitIndex.js index.js diff --git a/www/js/badgeDialogue.js b/www/js/badgeDialogue.js index ee55a61..9be9fd4 100644 --- a/www/js/badgeDialogue.js +++ b/www/js/badgeDialogue.js @@ -111,7 +111,7 @@ function Scan() { this.ts = -1; this.voltage = -1; this.numDevices = -1; - this.scans = []; + this.scans = {}; /** *Sets the header of the chunk @@ -142,7 +142,7 @@ function Scan() { }.bind(this); /* - * @return the samples of this chunk + * @return the scans in this chunk */ this.getScans = function(){ return this.scans; @@ -152,11 +152,19 @@ function Scan() { * @param newData the byte array that represents more samples */ this.addScans = function(newData) { - Array.prototype.push.apply(this.scans, newData); + //Array.prototype.push.apply(this.scans, newData); //this.samples = this.samples.concat(newData); - if (this.scans.length > this.numDevices) { + + for (var id in newData) { + if (newData.hasOwnProperty(id)) { + this.scans[id] = newData[id] + } + } + + + if (Object.keys(this.scans).length> this.numDevices) { // error - console.error("Too many samples in chunk!",this.scans.length); + console.error("Too many samples in chunk!", Object.keys(this.scans).length); } }.bind(this); @@ -168,20 +176,20 @@ function Scan() { this.ts = -1; this.voltage = -1; this.numDevices = -1; - this.scans = []; + this.scans = {}; }.bind(this); this.completed = function() { - return this.scans.length >= this.numDevices; + return Object.keys(this.scans).length >= this.numDevices; } this.toDict = function (member) { return { voltage:this.voltage, timestamp:this.ts, - num_devices:this.numDevices, - scans:this.scans, - member: member.key + rssi_distances:this.scans, + member: member.key, + badge_address:member.badgeId }; }.bind(this); } @@ -507,13 +515,15 @@ function BadgeDialogue(badge) { var scan_arr = struct.Unpack("<" + toUnpack, data); - var unpacked = [] + var unpacked = {} for (var i = 0; i < scan_arr.length; i+= 3 ) { - unpacked.push( - {'id' : scan_arr[i], - 'rssi': scan_arr[i+1], - 'scans': scan_arr[i+2] - }) + var id = scan_arr[i] + var rssi = scan_arr[i+1] + var count = scan_arr[i+2] + unpacked[id] = { + 'rssi': rssi, + 'scans': count + } } this.workingScanChunk.addScans(unpacked); diff --git a/www/js/index.js b/www/js/index.js index be64264..aa2fb6c 100644 --- a/www/js/index.js +++ b/www/js/index.js @@ -1,3 +1,4 @@ + require('q'); var qbluetoothle = require('./qbluetoothle'); var Badge = require('./badge'); @@ -161,7 +162,7 @@ function Meeting(group, members, type, moderator, description, location) { this.logScanChunk = function(chunk, member) { var chunk_data = chunk.toDict(member); - this.writeLog("scan received", chunk_data); + this.writeLog("proximity received", chunk_data); console.log("scan received", chunk_data); }.bind(this); @@ -254,6 +255,7 @@ function Meeting(group, members, type, moderator, description, location) { 'uuid': this.uuid, 'start_time':new Date()/1000, 'log_version':"2.0", + 'hub_version':window.gitRevision, 'moderator':this.moderator, 'location':this.location, 'description': this.description.replace(/\s\s+/g, ' '), @@ -390,7 +392,16 @@ mainPage = new Page("main", if (app.bluetoothInitialized) { // after bluetooth is disabled, it's automatically re-enabled. //this.beginRefreshData(); - app.disableBluetooth(); + if (device.version[0] == '4') { + app.disableBluetooth(); + } + else { + clearInterval(app.badgeScanIntervalID); + app.badgeScanIntervalID = setInterval(function() { + app.scanForBadges(); + }, BADGE_SCAN_INTERVAL); + app.scanForBadges(); + } } }, function onHide() {