-
-
Save mdobson/05d72d37d771eb4bb13f to your computer and use it in GitHub Desktop.
Robot arm scout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = require('util'); | |
var Scout = require('zetta').Scout; | |
var RobotServer = require('./robot_server'); | |
var RobotArm = require('./robot_arm'); | |
//Inherit scouty goodness | |
var RobotArmScout = module.exports = function(){ | |
Scout.call(this); | |
//This is the server we use to communicate with the robot arm | |
this.updServer = new RobotServer(); | |
} | |
util.inherits(RobotArmScout, Scout); | |
//Initialize function | |
RobotArmScout.prototype.init = function(next){ | |
var self = this; | |
//Start up our UDP server, and listen for our robot arm | |
this.updServer.start(); | |
//If a robot arm comes online | |
this.updServer.on('online', function(socket, port, ip){ | |
//Let's check if this arm has come online previously | |
var query = self.server.where({ type: 'arm' }); | |
self.server.find(query, function(err, results) { | |
if(err) { | |
return; | |
} | |
//An arm has come online previously | |
if (results.length) { | |
//Let's initialize it with saved info from the registry | |
self.provision(results[0], RobotArm, socket, port, ip); | |
} else { | |
//This is a new arm that has come online. Let's initialize it normally. | |
self.discover(RobotArm, socket, port, ip); | |
} | |
}); | |
}); | |
//Scouting setup complete. Move on to the next scout. | |
next(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment