Integer id = new Integer((int) msgdata[0] & 0xFF);
if (messages.containsKey(id)) {
Class cls = (Class) messages.get(id);
SubsystemMessage msg = (SubsystemMessage) cls.newInstance();
msg.fromByteArray(msgdata);
log.info("Received message " + msg.getMessageName());
return msg;
} else {
throw new InvalidMessageException("Unrecognised message id " +
id.toString());