Merge pull request #1 from hybridgroup/master

Refresh master from hybridgroup
This commit is contained in:
Loren West 2014-12-31 13:27:02 -08:00
commit 18dfd2fc84
2 changed files with 110 additions and 8 deletions

View File

@ -189,7 +189,7 @@ Cylon.start();
## Hardware Support ## Hardware Support
Cylon.js has an extensible syntax for connecting to multiple, different hardware Cylon.js has an extensible syntax for connecting to multiple, different hardware
devices. The following 32 platforms are currently supported: devices. The following 34 platforms are currently supported:
Platform | Support Platform | Support
-------- | ------- -------- | -------
@ -202,11 +202,13 @@ Platform | Support
[Bluetooth LE](http://en.wikipedia.org/wiki/Bluetooth_low_energy) | [cylon-ble](https://github.com/hybridgroup/cylon-ble) [Bluetooth LE](http://en.wikipedia.org/wiki/Bluetooth_low_energy) | [cylon-ble](https://github.com/hybridgroup/cylon-ble)
[Crazyflie](http://www.bitcraze.se/) | [cylon-crazyflie](https://github.com/hybridgroup/cylon-crazyflie) [Crazyflie](http://www.bitcraze.se/) | [cylon-crazyflie](https://github.com/hybridgroup/cylon-crazyflie)
[Digispark](http://digistump.com/products/1) | [cylon-digispark](https://github.com/hybridgroup/cylon-digispark) [Digispark](http://digistump.com/products/1) | [cylon-digispark](https://github.com/hybridgroup/cylon-digispark)
[Electric Imp](https://electricimp.com/product/) | [cylon-imp](https://github.com/hybridgroup/cylon-imp)
[Intel Edison](http://www.intel.com/content/www/us/en/do-it-yourself/edison.html) | [cylon-intel-iot](https://github.com/hybridgroup/cylon-intel-iot) [Intel Edison](http://www.intel.com/content/www/us/en/do-it-yourself/edison.html) | [cylon-intel-iot](https://github.com/hybridgroup/cylon-intel-iot)
[Intel Galileo](http://www.intel.com/content/www/us/en/do-it-yourself/galileo-maker-quark-board.html) | [cylon-intel-iot](https://github.com/hybridgroup/cylon-intel-iot) [Intel Galileo](http://www.intel.com/content/www/us/en/do-it-yourself/galileo-maker-quark-board.html) | [cylon-intel-iot](https://github.com/hybridgroup/cylon-intel-iot)
[Joystick](http://en.wikipedia.org/wiki/Joystick) | [cylon-joystick](https://github.com/hybridgroup/cylon-joystick) [Joystick](http://en.wikipedia.org/wiki/Joystick) | [cylon-joystick](https://github.com/hybridgroup/cylon-joystick)
[Keyboard](http://en.wikipedia.org/wiki/Computer_keyboard) | [cylon-keyboard](https://github.com/hybridgroup/cylon-keyboard) [Keyboard](http://en.wikipedia.org/wiki/Computer_keyboard) | [cylon-keyboard](https://github.com/hybridgroup/cylon-keyboard)
[Leap Motion](https://www.leapmotion.com/) | [cylon-leapmotion](https://github.com/hybridgroup/cylon-leapmotion) [Leap Motion](https://www.leapmotion.com/) | [cylon-leapmotion](https://github.com/hybridgroup/cylon-leapmotion)
[MiP](http://www.wowwee.com/mip/) | [cylon-mip](https://github.com/hybridgroup/cylon-mip)
[MQTT](http://mqtt.org/) | [cylon-mqtt](https://github.com/hybridgroup/cylon-mqtt) [MQTT](http://mqtt.org/) | [cylon-mqtt](https://github.com/hybridgroup/cylon-mqtt)
[Nest](http://nest.com/) | [cylon-nest](https://github.com/hybridgroup/cylon-nest) [Nest](http://nest.com/) | [cylon-nest](https://github.com/hybridgroup/cylon-nest)
[Neurosky](http://store.neurosky.com/products/mindwave-mobile) | [cylon-neurosky](https://github.com/hybridgroup/cylon-neurosky) [Neurosky](http://store.neurosky.com/products/mindwave-mobile) | [cylon-neurosky](https://github.com/hybridgroup/cylon-neurosky)
@ -275,7 +277,7 @@ Cylon.api();
``` ```
Then visit `https://localhost:3000/` and you are ready to control your robots from a web browser! Then visit `https://localhost:3000/` and you are ready to control your robots from a web browser!
<img src="http://cylonjs.com/images/screenshots/robeaux.png" style="margin-top: 15px; width: 100%"> <img src="http://cylonjs.com/images/screenshots/robeaux.jpg" style="margin-top: 15px; width: 100%">
You can check out more information on the Cylon API in the docs [here](http://cylonjs.com/documentation/guides/api). You can check out more information on the Cylon API in the docs [here](http://cylonjs.com/documentation/guides/api).

View File

@ -1,7 +1,25 @@
/* jshint expr:true */ /* jshint expr:true */
"use strict"; "use strict";
var router = source("api/routes"); var Cylon = source("cylon"),
router = source("api/routes");
var MockRequest = require("../../support/mock_request"),
MockResponse = require("../../support/mock_response");
function findRoute(path) {
var routes = router.stack.filter(function(m) {
return m.regexp.test(path);
});
return routes[0];
}
function findFinalHandler(path) {
var handlers = findRoute(path).route.stack.map(function(m) {
return m.handle;
});
return handlers[handlers.length - 1];
}
describe("API routes", function() { describe("API routes", function() {
var routes = [ var routes = [
@ -25,11 +43,93 @@ describe("API routes", function() {
path = route[1]; path = route[1];
it("defines a " + method + " route for " + path, function() { it("defines a " + method + " route for " + path, function() {
var matches = router.stack.map(function(m) { expect(findRoute(path)).to.exist();
return m.regexp.test(path);
});
expect(matches).to.include(true);
}); });
}); });
});
describe("API commands", function() {
var req, res;
beforeEach(function() {
Cylon.commands.ping = function() { return "pong"; };
req = new MockRequest();
res = new MockResponse();
req.device = {
name: "testDevice",
commands: {
announce: function(){return "im here";}
}
};
req.robot = {
name: "fred",
commands: {
speak: function(){return "ahem";}
},
devices: {
testDevice: req.device
}
};
});
afterEach(function() {
delete Cylon.commands.ping;
});
it("returns the list of MCP commands", function() {
res.json = function(obj){
expect(obj.commands).to.exist();
expect(obj.commands.length).to.equal(1);
expect(obj.commands[0]).to.equal("ping");
};
findFinalHandler("/commands")(req, res);
});
it("invokes an MCP command", function() {
req.params = {command:"ping"};
res.json = function(obj){
expect(obj.result).to.equal("pong");
};
findFinalHandler("/commands/ping")(req, res);
});
it("returns the list of robot commands", function() {
req.params = {robot: "fred"};
res.json = function(obj){
expect(obj.commands).to.exist();
expect(obj.commands.length).to.equal(1);
expect(obj.commands[0]).to.equal("speak");
};
findFinalHandler("/robots/fred/commands")(req, res);
});
it("invokes a robot command", function() {
req.params = {robot: "fred", command:"speak"};
res.json = function(obj){
expect(obj.result).to.equal("ahem");
};
findFinalHandler("/robots/fred/commands/speak")(req, res);
});
it("returns the list of device commands", function() {
req.params = {robot: "fred", device: "testDevice" };
res.json = function(obj){
expect(obj.commands).to.exist();
expect(obj.commands.length).to.equal(1);
expect(obj.commands[0]).to.equal("announce");
};
var path = "/robots/fred/devices/testDevice/commands";
findFinalHandler(path)(req, res);
});
it("invokes a device command", function() {
req.params = {robot: "fred", device: "testDevice", command:"announce"};
res.json = function(obj){
expect(obj.result).to.equal("im here");
};
var path = "/robots/fred/devices/testDevice/commands/speak";
findFinalHandler(path)(req, res);
});
}); });