2014-12-16 03:15:29 +08:00
|
|
|
"use strict";
|
2013-10-25 05:25:42 +08:00
|
|
|
|
2015-01-23 06:40:09 +08:00
|
|
|
var initializer = require("./initializer"),
|
2014-12-16 03:15:29 +08:00
|
|
|
Logger = require("./logger"),
|
|
|
|
Utils = require("./utils"),
|
2015-02-21 10:49:31 +08:00
|
|
|
Config = require("./config"),
|
|
|
|
_ = require("./utils/helpers");
|
2014-05-08 23:57:20 +08:00
|
|
|
|
2015-06-11 08:17:11 +08:00
|
|
|
var validator = require("./validator");
|
|
|
|
|
2015-06-19 05:57:41 +08:00
|
|
|
var EventEmitter = require("events").EventEmitter;
|
2014-06-11 09:37:19 +08:00
|
|
|
|
2015-06-10 02:50:50 +08:00
|
|
|
// used when creating default robot names
|
|
|
|
var ROBOT_ID = 1;
|
|
|
|
|
2015-06-09 13:57:49 +08:00
|
|
|
/**
|
|
|
|
* Creates a new Robot instance based on provided options
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} opts object with Robot options
|
|
|
|
* @param {String} [name] the name the robot should have
|
|
|
|
* @param {Object} [connections] object containing connection info for the Robot
|
|
|
|
* @param {Object} [devices] object containing device information for the Robot
|
|
|
|
* @param {Function} [work] a function the Robot will run when started
|
|
|
|
* @returns {Robot} new Robot instance
|
|
|
|
*/
|
2014-06-10 04:39:16 +08:00
|
|
|
var Robot = module.exports = function Robot(opts) {
|
2015-05-13 09:47:27 +08:00
|
|
|
Utils.classCallCheck(this, Robot);
|
|
|
|
|
2014-07-13 01:48:54 +08:00
|
|
|
opts = opts || {};
|
2014-05-08 23:57:20 +08:00
|
|
|
|
2015-06-11 08:17:11 +08:00
|
|
|
validator.validate(opts);
|
|
|
|
|
2015-06-26 03:33:13 +08:00
|
|
|
// auto-bind prototype methods
|
|
|
|
for (var prop in Object.getPrototypeOf(this)) {
|
|
|
|
if (this[prop] && prop !== "constructor") {
|
|
|
|
this[prop] = this[prop].bind(this);
|
|
|
|
}
|
|
|
|
}
|
2014-05-08 23:57:20 +08:00
|
|
|
|
2015-01-18 07:48:45 +08:00
|
|
|
this.initRobot(opts);
|
2014-05-08 23:57:20 +08:00
|
|
|
|
2015-02-21 10:49:31 +08:00
|
|
|
_.each(opts, function(opt, name) {
|
2014-12-18 06:42:34 +08:00
|
|
|
if (this[name] !== undefined) {
|
2015-02-21 10:49:31 +08:00
|
|
|
return;
|
2014-10-28 04:40:38 +08:00
|
|
|
}
|
2014-08-06 09:41:57 +08:00
|
|
|
|
2015-03-18 05:22:14 +08:00
|
|
|
if (_.isFunction(opt)) {
|
|
|
|
this[name] = opt.bind(this);
|
2014-10-28 04:40:38 +08:00
|
|
|
|
2015-03-18 05:22:14 +08:00
|
|
|
if (opts.commands == null) {
|
|
|
|
this.commands[name] = opt.bind(this);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
this[name] = opt;
|
2014-08-06 09:41:57 +08:00
|
|
|
}
|
2015-02-21 10:49:31 +08:00
|
|
|
}, this);
|
2014-08-06 09:41:57 +08:00
|
|
|
|
2014-10-28 04:40:38 +08:00
|
|
|
if (opts.commands) {
|
2015-02-20 09:23:41 +08:00
|
|
|
var cmds;
|
2014-10-28 04:40:38 +08:00
|
|
|
|
2015-02-21 10:49:31 +08:00
|
|
|
if (_.isFunction(opts.commands)) {
|
2015-02-20 09:23:41 +08:00
|
|
|
cmds = opts.commands.call(this);
|
|
|
|
} else {
|
|
|
|
cmds = opts.commands;
|
|
|
|
}
|
|
|
|
|
2015-02-21 10:49:31 +08:00
|
|
|
if (_.isObject(cmds)) {
|
2014-10-28 04:40:38 +08:00
|
|
|
this.commands = cmds;
|
2014-12-18 07:07:03 +08:00
|
|
|
} else {
|
|
|
|
var err = "#commands must be an object ";
|
|
|
|
err += "or a function that returns an object";
|
|
|
|
throw new Error(err);
|
2014-10-28 04:40:38 +08:00
|
|
|
}
|
2014-05-08 23:57:20 +08:00
|
|
|
}
|
2014-08-06 09:41:57 +08:00
|
|
|
|
2014-12-16 03:15:29 +08:00
|
|
|
var mode = Utils.fetch(Config, "mode", "manual");
|
2014-09-09 04:41:59 +08:00
|
|
|
|
2014-12-16 03:15:29 +08:00
|
|
|
if (mode === "auto") {
|
|
|
|
// run on the next tick, to allow for "work" event handlers to be set up
|
2014-09-09 05:33:07 +08:00
|
|
|
setTimeout(this.start, 0);
|
2014-09-09 04:41:59 +08:00
|
|
|
}
|
2014-05-08 23:57:20 +08:00
|
|
|
};
|
|
|
|
|
2014-06-06 03:11:37 +08:00
|
|
|
Utils.subclass(Robot, EventEmitter);
|
2014-05-08 23:57:20 +08:00
|
|
|
|
2015-06-09 13:57:49 +08:00
|
|
|
/**
|
|
|
|
* Condenses information on a Robot to a JSON-serializable format
|
|
|
|
*
|
|
|
|
* @return {Object} serializable information on the Robot
|
|
|
|
*/
|
2014-06-07 05:11:35 +08:00
|
|
|
Robot.prototype.toJSON = function() {
|
2014-05-08 23:57:20 +08:00
|
|
|
return {
|
|
|
|
name: this.name,
|
2015-02-21 10:49:31 +08:00
|
|
|
connections: _.invoke(this.connections, "toJSON"),
|
|
|
|
devices: _.invoke(this.devices, "toJSON"),
|
2015-02-20 09:23:41 +08:00
|
|
|
commands: Object.keys(this.commands),
|
2015-02-21 10:49:31 +08:00
|
|
|
events: _.isArray(this.events) ? this.events : []
|
2014-05-08 23:57:20 +08:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-06-09 13:57:49 +08:00
|
|
|
/**
|
|
|
|
* Adds a new Connection to the Robot with the provided name and details.
|
|
|
|
*
|
|
|
|
* @param {String} name string name for the Connection to use
|
|
|
|
* @param {Object} conn options for the Connection initializer
|
|
|
|
* @return {Object} the robot
|
|
|
|
*/
|
2014-11-27 01:33:19 +08:00
|
|
|
Robot.prototype.connection = function(name, conn) {
|
2014-11-21 00:43:08 +08:00
|
|
|
conn.robot = this;
|
2014-11-27 01:33:19 +08:00
|
|
|
conn.name = name;
|
2014-11-21 00:43:08 +08:00
|
|
|
|
|
|
|
if (this.connections[conn.name]) {
|
2014-12-16 03:15:29 +08:00
|
|
|
var original = conn.name,
|
|
|
|
str;
|
2015-01-08 02:16:32 +08:00
|
|
|
|
2014-11-21 00:43:08 +08:00
|
|
|
conn.name = Utils.makeUnique(original, Object.keys(this.connections));
|
2014-12-16 03:15:29 +08:00
|
|
|
|
|
|
|
str = "Connection names must be unique.";
|
|
|
|
str += "Renaming '" + original + "' to '" + conn.name + "'";
|
2015-07-14 04:55:42 +08:00
|
|
|
this.log(str);
|
2014-11-21 00:43:08 +08:00
|
|
|
}
|
2016-02-26 00:05:09 +08:00
|
|
|
if ("adapter" in conn) {
|
|
|
|
conn.adaptor = conn.adapter;
|
|
|
|
}
|
2015-01-23 06:40:09 +08:00
|
|
|
this.connections[conn.name] = initializer("adaptor", conn);
|
2014-11-21 00:43:08 +08:00
|
|
|
|
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
2015-06-09 13:57:49 +08:00
|
|
|
/**
|
|
|
|
* Initializes all values for a new Robot.
|
|
|
|
*
|
|
|
|
* @param {Object} opts object passed to Robot constructor
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2015-01-18 07:48:45 +08:00
|
|
|
Robot.prototype.initRobot = function(opts) {
|
2015-06-10 02:50:50 +08:00
|
|
|
this.name = opts.name || "Robot " + ROBOT_ID++;
|
2015-06-26 23:17:30 +08:00
|
|
|
this.running = false;
|
|
|
|
|
2015-01-18 07:48:45 +08:00
|
|
|
this.connections = {};
|
|
|
|
this.devices = {};
|
2015-06-26 23:17:30 +08:00
|
|
|
|
2015-01-18 07:48:45 +08:00
|
|
|
this.work = opts.work || opts.play;
|
|
|
|
|
2015-06-26 23:17:30 +08:00
|
|
|
this.commands = {};
|
|
|
|
|
2015-01-18 07:48:45 +08:00
|
|
|
if (!this.work) {
|
2015-07-14 04:55:42 +08:00
|
|
|
this.work = function() { this.log("No work yet."); };
|
2015-01-18 07:48:45 +08:00
|
|
|
}
|
2014-11-11 02:52:55 +08:00
|
|
|
|
2015-03-05 01:27:33 +08:00
|
|
|
_.each(opts.connections, function(conn, key) {
|
|
|
|
var name = _.isString(key) ? key : conn.name;
|
2015-01-08 02:16:32 +08:00
|
|
|
|
2015-03-05 01:27:33 +08:00
|
|
|
if (conn.devices) {
|
|
|
|
opts.devices = opts.devices || {};
|
2015-01-08 02:16:32 +08:00
|
|
|
|
2015-03-05 01:27:33 +08:00
|
|
|
_.each(conn.devices, function(device, d) {
|
|
|
|
device.connection = name;
|
|
|
|
opts.devices[d] = device;
|
|
|
|
});
|
2015-01-08 02:16:32 +08:00
|
|
|
|
2015-03-05 01:27:33 +08:00
|
|
|
delete conn.devices;
|
|
|
|
}
|
2015-01-08 02:16:32 +08:00
|
|
|
|
2015-06-27 01:31:23 +08:00
|
|
|
this.connection(name, _.extend({}, conn));
|
2015-03-05 01:27:33 +08:00
|
|
|
}, this);
|
2014-05-08 23:57:20 +08:00
|
|
|
|
2015-06-27 01:31:23 +08:00
|
|
|
_.each(opts.devices, function(device, key) {
|
|
|
|
var name = _.isString(key) ? key : device.name;
|
|
|
|
this.device(name, _.extend({}, device));
|
|
|
|
}, this);
|
2014-05-08 23:57:20 +08:00
|
|
|
};
|
|
|
|
|
2015-06-09 13:57:49 +08:00
|
|
|
/**
|
|
|
|
* Adds a new Device to the Robot with the provided name and details.
|
|
|
|
*
|
|
|
|
* @param {String} name string name for the Device to use
|
|
|
|
* @param {Object} device options for the Device initializer
|
|
|
|
* @return {Object} the robot
|
|
|
|
*/
|
2014-11-27 01:33:19 +08:00
|
|
|
Robot.prototype.device = function(name, device) {
|
2014-12-16 03:15:29 +08:00
|
|
|
var str;
|
|
|
|
|
2014-11-21 00:43:08 +08:00
|
|
|
device.robot = this;
|
2014-11-27 01:33:19 +08:00
|
|
|
device.name = name;
|
2014-11-21 00:43:08 +08:00
|
|
|
|
|
|
|
if (this.devices[device.name]) {
|
|
|
|
var original = device.name;
|
|
|
|
device.name = Utils.makeUnique(original, Object.keys(this.devices));
|
2014-12-16 03:15:29 +08:00
|
|
|
|
|
|
|
str = "Device names must be unique.";
|
|
|
|
str += "Renaming '" + original + "' to '" + device.name + "'";
|
2015-07-14 04:55:42 +08:00
|
|
|
this.log(str);
|
2014-11-21 00:43:08 +08:00
|
|
|
}
|
|
|
|
|
2015-02-21 10:49:31 +08:00
|
|
|
if (_.isString(device.connection)) {
|
2014-11-21 00:43:08 +08:00
|
|
|
if (this.connections[device.connection] == null) {
|
2014-12-16 03:15:29 +08:00
|
|
|
str = "No connection found with the name " + device.connection + ".\n";
|
2015-07-14 04:55:42 +08:00
|
|
|
this.log(str);
|
2014-12-16 03:15:29 +08:00
|
|
|
process.emit("SIGINT");
|
2014-11-21 00:43:08 +08:00
|
|
|
}
|
|
|
|
|
2014-12-18 06:42:34 +08:00
|
|
|
device.connection = this.connections[device.connection];
|
2014-11-21 00:43:08 +08:00
|
|
|
} else {
|
2015-02-20 09:23:41 +08:00
|
|
|
for (var c in this.connections) {
|
|
|
|
device.connection = this.connections[c];
|
|
|
|
break;
|
|
|
|
}
|
2014-11-21 00:43:08 +08:00
|
|
|
}
|
|
|
|
|
2015-01-23 06:40:09 +08:00
|
|
|
this.devices[device.name] = initializer("driver", device);
|
2014-11-21 00:43:08 +08:00
|
|
|
|
|
|
|
return this;
|
2014-12-16 03:15:29 +08:00
|
|
|
};
|
2014-11-21 00:43:08 +08:00
|
|
|
|
2015-06-09 13:57:49 +08:00
|
|
|
/**
|
|
|
|
* Starts the Robot's connections, then devices, then work.
|
|
|
|
*
|
|
|
|
* @param {Function} callback function to be triggered when the Robot has
|
|
|
|
* started working
|
|
|
|
* @return {Object} the Robot
|
|
|
|
*/
|
2014-10-04 15:56:08 +08:00
|
|
|
Robot.prototype.start = function(callback) {
|
2014-10-01 03:15:46 +08:00
|
|
|
if (this.running) {
|
2014-10-01 03:22:00 +08:00
|
|
|
return this;
|
2014-10-01 03:15:46 +08:00
|
|
|
}
|
|
|
|
|
2014-12-16 03:15:29 +08:00
|
|
|
var mode = Utils.fetch(Config, "workMode", "async");
|
2014-06-10 04:55:44 +08:00
|
|
|
|
2014-12-18 06:42:34 +08:00
|
|
|
var start = function() {
|
|
|
|
if (mode === "async") {
|
|
|
|
this.startWork();
|
|
|
|
}
|
|
|
|
}.bind(this);
|
|
|
|
|
2015-06-19 05:57:41 +08:00
|
|
|
_.series([
|
2014-07-04 00:35:24 +08:00
|
|
|
this.startConnections,
|
|
|
|
this.startDevices,
|
2014-12-18 06:42:34 +08:00
|
|
|
start
|
2014-10-04 15:56:08 +08:00
|
|
|
], function(err, results) {
|
2015-04-15 12:49:12 +08:00
|
|
|
if (err) {
|
2015-07-14 04:55:42 +08:00
|
|
|
this.log("An error occured while trying to start the robot:");
|
|
|
|
this.log(err);
|
2014-12-18 06:42:34 +08:00
|
|
|
|
2015-01-21 11:18:52 +08:00
|
|
|
this.halt(function() {
|
2015-02-21 10:49:31 +08:00
|
|
|
if (_.isFunction(this.error)) {
|
2015-01-21 11:18:52 +08:00
|
|
|
this.error.call(this, err);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.listeners("error").length) {
|
|
|
|
this.emit("error", err);
|
|
|
|
}
|
|
|
|
}.bind(this));
|
2014-06-10 04:55:44 +08:00
|
|
|
}
|
2014-12-18 06:42:34 +08:00
|
|
|
|
2015-02-21 10:49:31 +08:00
|
|
|
if (_.isFunction(callback)) {
|
2014-10-04 15:56:08 +08:00
|
|
|
callback(err, results);
|
|
|
|
}
|
2014-10-01 07:13:20 +08:00
|
|
|
}.bind(this));
|
2014-10-01 03:15:46 +08:00
|
|
|
|
2014-09-09 04:41:59 +08:00
|
|
|
return this;
|
2014-05-08 23:57:20 +08:00
|
|
|
};
|
|
|
|
|
2015-06-09 13:57:49 +08:00
|
|
|
/**
|
|
|
|
* Starts the Robot's work function
|
|
|
|
*
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2014-10-04 14:07:07 +08:00
|
|
|
Robot.prototype.startWork = function() {
|
2015-07-14 04:55:42 +08:00
|
|
|
this.log("Working.");
|
2014-10-04 14:07:07 +08:00
|
|
|
|
2014-12-16 03:15:29 +08:00
|
|
|
this.emit("ready", this);
|
2014-10-04 14:07:07 +08:00
|
|
|
this.work.call(this, this);
|
|
|
|
this.running = true;
|
|
|
|
};
|
|
|
|
|
2015-06-09 13:57:49 +08:00
|
|
|
/**
|
|
|
|
* Starts the Robot's connections
|
|
|
|
*
|
|
|
|
* @param {Function} callback function to be triggered after the connections are
|
|
|
|
* started
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2014-05-08 23:57:20 +08:00
|
|
|
Robot.prototype.startConnections = function(callback) {
|
2015-07-14 04:55:42 +08:00
|
|
|
this.log("Starting connections.");
|
2014-05-08 23:57:20 +08:00
|
|
|
|
2015-09-08 01:51:34 +08:00
|
|
|
var starters = _.map(this.connections, function(conn) {
|
2014-11-29 06:42:26 +08:00
|
|
|
return function(cb) {
|
2015-09-08 01:51:34 +08:00
|
|
|
return this.startConnection(conn, cb);
|
2015-01-21 11:29:40 +08:00
|
|
|
}.bind(this);
|
2015-02-21 10:49:31 +08:00
|
|
|
}, this);
|
2014-05-08 23:57:20 +08:00
|
|
|
|
2015-06-19 05:57:41 +08:00
|
|
|
return _.parallel(starters, callback);
|
2014-05-08 23:57:20 +08:00
|
|
|
};
|
|
|
|
|
2015-09-08 01:51:34 +08:00
|
|
|
/**
|
|
|
|
* Starts a single connection on Robot
|
|
|
|
*
|
|
|
|
* @param {Object} connection to start
|
|
|
|
* @param {Function} callback function to be triggered after the connection is
|
|
|
|
* started
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
Robot.prototype.startConnection = function(connection, callback) {
|
|
|
|
if (connection.connected === true) {
|
|
|
|
return callback.call(connection);
|
|
|
|
}
|
|
|
|
|
|
|
|
var str = "Starting connection '" + connection.name + "'";
|
|
|
|
|
|
|
|
if (connection.host) {
|
|
|
|
str += " on host " + connection.host;
|
|
|
|
} else if (connection.port) {
|
|
|
|
str += " on port " + connection.port;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.log(str + ".");
|
2016-03-28 09:28:14 +08:00
|
|
|
this[connection.name] = connection;
|
2015-09-08 01:51:34 +08:00
|
|
|
connection.connect.call(connection, callback);
|
|
|
|
connection.connected = true;
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2015-06-09 13:57:49 +08:00
|
|
|
/**
|
|
|
|
* Starts the Robot's devices
|
|
|
|
*
|
|
|
|
* @param {Function} callback function to be triggered after the devices are
|
|
|
|
* started
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2014-05-08 23:57:20 +08:00
|
|
|
Robot.prototype.startDevices = function(callback) {
|
2015-01-21 11:29:40 +08:00
|
|
|
var log = this.log;
|
|
|
|
|
2015-07-14 04:55:42 +08:00
|
|
|
log("Starting devices.");
|
2014-05-08 23:57:20 +08:00
|
|
|
|
2015-09-07 23:34:01 +08:00
|
|
|
var starters = _.map(this.devices, function(device) {
|
2014-11-29 06:42:26 +08:00
|
|
|
return function(cb) {
|
2015-09-07 23:34:01 +08:00
|
|
|
return this.startDevice(device, cb);
|
|
|
|
}.bind(this);
|
|
|
|
}, this);
|
2015-09-02 09:12:39 +08:00
|
|
|
|
2015-09-07 23:34:01 +08:00
|
|
|
return _.parallel(starters, callback);
|
|
|
|
};
|
2014-11-29 06:42:26 +08:00
|
|
|
|
2015-09-07 23:34:01 +08:00
|
|
|
/**
|
|
|
|
* Starts a single device on Robot
|
|
|
|
*
|
|
|
|
* @param {Object} device to start
|
|
|
|
* @param {Function} callback function to be triggered after the device is
|
|
|
|
* started
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
Robot.prototype.startDevice = function(device, callback) {
|
|
|
|
if (device.started === true) {
|
|
|
|
return callback.call(device);
|
|
|
|
}
|
2014-11-29 06:42:26 +08:00
|
|
|
|
2015-09-07 23:34:01 +08:00
|
|
|
var log = this.log;
|
|
|
|
var str = "Starting device '" + device.name + "'";
|
2015-09-02 09:12:39 +08:00
|
|
|
|
2016-05-22 05:01:04 +08:00
|
|
|
if (device.pin || device.pin === 0) {
|
2015-09-07 23:34:01 +08:00
|
|
|
str += " on pin " + device.pin;
|
|
|
|
}
|
2014-05-08 23:57:20 +08:00
|
|
|
|
2015-09-07 23:34:01 +08:00
|
|
|
log(str + ".");
|
|
|
|
this[device.name] = device;
|
|
|
|
device.start.call(device, callback);
|
|
|
|
device.started = true;
|
|
|
|
|
|
|
|
return device.started;
|
2014-05-08 23:57:20 +08:00
|
|
|
};
|
|
|
|
|
2015-06-09 13:57:49 +08:00
|
|
|
/**
|
|
|
|
* Halts the Robot, attempting to gracefully stop devices and connections.
|
|
|
|
*
|
|
|
|
* @param {Function} callback to be triggered when the Robot has stopped
|
|
|
|
* @return {void}
|
|
|
|
*/
|
2014-06-13 06:31:49 +08:00
|
|
|
Robot.prototype.halt = function(callback) {
|
2014-09-05 02:14:47 +08:00
|
|
|
callback = callback || function() {};
|
|
|
|
|
2015-06-19 05:56:39 +08:00
|
|
|
if (!this.running) {
|
2015-01-22 00:56:13 +08:00
|
|
|
return callback();
|
|
|
|
}
|
|
|
|
|
2015-07-22 01:31:52 +08:00
|
|
|
// ensures callback(err) won't prevent others from halting
|
|
|
|
function wrap(fn) {
|
|
|
|
return function(cb) { fn.call(null, cb.bind(null, null)); };
|
|
|
|
}
|
|
|
|
|
|
|
|
var devices = _.pluck(this.devices, "halt").map(wrap),
|
|
|
|
connections = _.pluck(this.connections, "disconnect").map(wrap);
|
2014-06-13 06:31:49 +08:00
|
|
|
|
2015-01-22 00:56:13 +08:00
|
|
|
try {
|
2015-06-19 05:57:41 +08:00
|
|
|
_.parallel(devices, function() {
|
|
|
|
_.parallel(connections, callback);
|
2015-01-22 00:56:13 +08:00
|
|
|
});
|
|
|
|
} catch (e) {
|
|
|
|
var msg = "An error occured while attempting to safely halt the robot";
|
2015-07-14 04:55:42 +08:00
|
|
|
this.log(msg);
|
|
|
|
this.log(e.message);
|
2015-01-22 00:56:13 +08:00
|
|
|
}
|
2014-10-01 03:15:46 +08:00
|
|
|
|
|
|
|
this.running = false;
|
2014-05-08 23:57:20 +08:00
|
|
|
};
|
|
|
|
|
2015-06-09 13:57:49 +08:00
|
|
|
/**
|
|
|
|
* Generates a String representation of a Robot
|
|
|
|
*
|
|
|
|
* @return {String} representation of a Robot
|
|
|
|
*/
|
2014-05-08 23:57:20 +08:00
|
|
|
Robot.prototype.toString = function() {
|
|
|
|
return "[Robot name='" + this.name + "']";
|
|
|
|
};
|
2015-01-18 13:29:07 +08:00
|
|
|
|
2015-07-14 04:55:42 +08:00
|
|
|
Robot.prototype.log = function(str) {
|
|
|
|
Logger.log("[" + this.name + "] - " + str);
|
2015-01-21 11:29:40 +08:00
|
|
|
};
|