// DiagnosticsStatus
/**
* @fileOverview a file to define RWTRobotMonitor.DiagnosticsStatus class.
* @author Ryohei Ueda
*/
/**
* @class DiagnosticsStatus
* @param spec
*/
ROSLIB.DiagnosticsStatus = function(spec) {
if (typeof spec === 'undefined') {
spec = {};
}
this.name = spec.name;
this.message = spec.message;
this.level = spec.level;
this.hardware_id = spec.hardware_id;
this.values = {};
this.stamp = spec.timestamp;
for (var i = 0; i < spec.values.length; i++) {
this.values[spec.values[i].key] = spec.values[i].value;
}
// parsing name
// name has a directory separated by /
this.path = _.filter(this.name.split('/'), function(str) {
return str.toString() !== ''.toString();
});
};
ROSLIB.DiagnosticsStatus.LEVEL = {
OK: 0,
WARN: 1,
ERROR: 2
};
/**
* return true if the level is OK
*/
ROSLIB.DiagnosticsStatus.prototype.isOK = function() {
return this.level === ROSLIB.DiagnosticsStatus.LEVEL.OK;
};
/**
* return true if the level is WARN
*/
ROSLIB.DiagnosticsStatus.prototype.isWARN = function() {
return this.level === ROSLIB.DiagnosticsStatus.LEVEL.WARN;
};
/**
* return true if the level is ERROR
*/
ROSLIB.DiagnosticsStatus.prototype.isERROR = function() {
return this.level === ROSLIB.DiagnosticsStatus.LEVEL.ERROR;
};
/**
* create DiagnosticsStatus instances from DiagnosticArray
*/
ROSLIB.DiagnosticsStatus.createFromArray = function(msg) {
var header = msg.header;
var header_stamp = ROSLIB.Time.fromROSMsg(header);
return _.map(msg.status, function(status) {
return new ROSLIB.DiagnosticsStatus({
timestamp: header_stamp,
name: status.name,
message: status.message,
hardware_id: status.hardware_id,
level: status.level,
values: status.values
});
});
};
/**
* return the level as string
*/
ROSLIB.DiagnosticsStatus.prototype.levelString = function() {
if (this.isERROR()) {
return 'Error';
}
else if (this.isWARN()) {
return 'Warn';
}
else if (this.isOK()){
return 'OK';
}
};