Skip to content

Commit

Permalink
Merge pull request #33 from tessel/jon-usb-discovery
Browse files Browse the repository at this point in the history
Fixes #32
  • Loading branch information
johnnyman727 committed Feb 24, 2016
2 parents 6d8968b + f8bd66a commit 914a66c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
29 changes: 19 additions & 10 deletions client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,23 +209,32 @@ function runWifiTest(wifiOpts, serialNumber, cb){
if (device.serialNumber === serialNumber) {
// We then fetch a Tessel Object from the Tessel CLI that has been built
// with this USB Connection
tesselCLI.list({timeout: 1, output: false, usb: true, name:serialNumber})
tesselCLI.list({timeout: 2, output: false, usb: true})
.then((tessels) => {
if (tessels.length > 1) {
return cb && cb(new Error("Found multiple USB Tessels with the same serial number..."));
}

// Our Tessel should be the first and only
var tessel = tessels[0];
var tessel;
// Iterate through returned Tessels
tessels.forEach((possibleMatch) => {
// If this tessel's serial number matches the one we are looking for
if (possibleMatch.connection.serialNumber === serialNumber) {
// This is our Tessel
tessel = possibleMatch;
}
});

if (tessel.connection.serialNumber !== serialNumber) {
return cb && cb(new Error(`Somehow we fetched a Tessel with the incorrect serial number: ${serialNumber}`));
if (!tessel) {
throw new Error(`Tessel under test ${serialNumber} not discovered under available Tessels`);
}
// Stop scanning for new devices
scanner.stop();

// Remove old listeners in case we have future events unrelated to this device
scanner.removeAllListeners();

// Start the wifi Test
startTest(tessel, cb);
})
.catch((err) => {
if (err.toString() === 'No Tessels Found') {
if (err.toString().includes('No Tessels Found.')) {
cb && cb(`Not able to find ${serialNumber} because no Tessels are connected.`);
}
else {
Expand Down
2 changes: 1 addition & 1 deletion client/tests/discovery/usb_discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ Scanner.prototype.stop = function() {
this.devices = [];
// Stop listening for connects and disconnects
usb.removeAllListeners('attach');
usb.removeAllListeners('detatch');
usb.removeAllListeners('detach');
this.scanning = false;
};

Expand Down
2 changes: 1 addition & 1 deletion client/tests/integration/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ var commands = require('./commands');
// Assumes Tessel connection was already opened and will be closed afterwards
function wifiTest(opts, tessel) {
// Empirically derived time it takes for connection to be ready for pings
const settleTime = 8000;
const settleTime = 15000;
return tessel.connectToNetwork(opts)
.then(() => {
return new Promise((resolve, reject) => {
Expand Down

0 comments on commit 914a66c

Please sign in to comment.