Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 package com.github.rosjava.android_apps.application_management;
00035
00036 import org.jboss.netty.buffer.ChannelBuffer;
00037 import org.jboss.netty.buffer.ChannelBuffers;
00038
00039 import java.util.Date;
00040 import java.util.regex.Pattern;
00041 import java.util.regex.Matcher;
00042 import rocon_app_manager_msgs.Icon;
00043
00044 public class RobotDescription implements java.io.Serializable {
00045 public static final String CONNECTING = "connecting...";
00046 public static final String OK = "ok";
00047 public static final String ERROR = "exception";
00048 public static final String WIFI = "invalid wifi";
00049 public static final String UNAVAILABLE = "unavailable";
00050 public static final String CONTROL = "not started";
00051 private static final String NAME_UNKNOWN = "Unknown";
00052 private static final String TYPE_UNKNOWN = "Unknown";
00053 private static final long serialVersionUID = 1L;
00054 private RobotId robotId;
00055 private String robotName;
00056 private String robotType;
00057 private String gatewayName;
00058
00059
00060 private String robotIconFormat;
00061 private byte[] robotIconData;
00062 private int robotIconDataOffset;
00063 private int robotIconDataLength;
00064
00065 private String connectionStatus;
00066 private Date timeLastSeen;
00067
00068 public static final String UNIQUE_KEY = "com.github.rosjava.android_apps.application_management.RobotDescription";
00069
00070
00071 public RobotDescription() {
00072 }
00073
00074 public RobotDescription(RobotId robotId, String robotName, String robotType, Icon robotIcon, String gatewayName, Date timeLastSeen) {
00075 setRobotName(robotName);
00076 setRobotId(robotId);
00077 this.robotName = robotName;
00078 this.robotType = robotType;
00079 this.gatewayName = gatewayName;
00080 if ( robotIcon != null ) {
00081 this.robotIconFormat = robotIcon.getFormat();
00082 this.robotIconData = robotIcon.getData().array();
00083 this.robotIconDataOffset = robotIcon.getData().arrayOffset();
00084 this.robotIconDataLength = robotIcon.getData().readableBytes();
00085 }
00086 this.timeLastSeen = timeLastSeen;
00087 }
00088 public void copyFrom(RobotDescription other) {
00089 robotId = other.robotId;
00090 robotName = other.robotName;
00091 robotType = other.robotType;
00092 gatewayName = other.gatewayName;
00093 robotIconFormat = other.robotIconFormat;
00094 robotIconData = other.robotIconData;
00095 robotIconDataOffset = other.robotIconDataOffset;
00096 robotIconDataLength = other.robotIconDataLength;
00097 connectionStatus = other.connectionStatus;
00098 timeLastSeen = other.timeLastSeen;
00099 }
00100 public RobotId getRobotId() {
00101 return robotId;
00102 }
00103
00104 public String getGatewayName() { return gatewayName; }
00105
00110 public String getMasterUri() {
00111 return robotId.getMasterUri();
00112 }
00113
00114 public void setRobotId(RobotId robotId) {
00115
00116
00117
00118
00119
00120 this.robotId = robotId;
00121 }
00122 public String getRobotName() {
00123 return robotName;
00124 }
00136 public String getRobotFriendlyName() {
00137 String friendlyName = robotName;
00138
00139 if (robotName.length() > 32) {
00140 String possibleUuidPart = robotName.substring(robotName.length() - 32);
00141 Pattern p = Pattern.compile("[^a-f0-9]");
00142 Matcher m = p.matcher(possibleUuidPart);
00143 if (!m.find()) {
00144 friendlyName = robotName.substring(0, robotName.length() - 32);
00145 }
00146 }
00147 friendlyName = friendlyName.replace('_',' ');
00148 final StringBuilder result = new StringBuilder(friendlyName.length());
00149 String[] words = friendlyName.split("\\s");
00150 for(int i=0, l=words.length; i<l; ++i) {
00151 if(i > 0) result.append(" ");
00152 result.append(Character.toUpperCase(words[i].charAt(0)))
00153 .append(words[i].substring(1));
00154 }
00155 return result.toString();
00156 }
00157
00158 public void setRobotName(String robotName) {
00159
00160
00161
00162
00163
00164 this.robotName = robotName;
00165 }
00166 public String getRobotType() {
00167 return robotType;
00168 }
00169 public void setRobotType(String robotType) {
00170 this.robotType = robotType;
00171 }
00172
00173 public String getRobotIconFormat() {
00174 return robotIconFormat;
00175 }
00176
00177 public ChannelBuffer getRobotIconData() {
00178 if ( robotIconData == null ) {
00179 return null;
00180 } else {
00181 ChannelBuffer channelBuffer = ChannelBuffers.copiedBuffer(robotIconData, robotIconDataOffset, robotIconDataLength);
00182 return channelBuffer;
00183 }
00184 }
00185
00186 public void setRobotIcon(Icon robotIcon) {
00187 this.robotIconFormat = robotIcon.getFormat();
00188 this.robotIconData = robotIcon.getData().array();
00189 }
00190
00191 public String getConnectionStatus() {
00192 return connectionStatus;
00193 }
00194 public void setConnectionStatus(String connectionStatus) {
00195 this.connectionStatus = connectionStatus;
00196 }
00197 public Date getTimeLastSeen() {
00198 return timeLastSeen;
00199 }
00200 public void setTimeLastSeen(Date timeLastSeen) {
00201 this.timeLastSeen = timeLastSeen;
00202 }
00203 public boolean isUnknown() {
00204 return this.robotName.equals(NAME_UNKNOWN);
00205 }
00206 public static RobotDescription createUnknown(RobotId robotId) {
00207 return new RobotDescription(robotId, NAME_UNKNOWN, TYPE_UNKNOWN, null, NAME_UNKNOWN, new Date());
00208 }
00209 @Override
00210 public boolean equals(Object o) {
00211
00212
00213 if(this == o) {
00214 return true;
00215 }
00216
00217
00218
00219 if(!(o instanceof RobotDescription)) {
00220 return false;
00221 }
00222
00223
00224
00225 RobotDescription lhs = (RobotDescription) o;
00226
00227
00228
00229 return (robotId == null ? lhs.robotId == null : robotId.equals(lhs.robotId));
00230 }
00231
00232 @Override
00233 public int hashCode() {
00234
00235 int result = 17;
00236
00237 result = 31 * result + (robotId == null ? 0 : robotId.hashCode());
00238 return result;
00239 }
00240 }