/** Runs command in eclipse job */ @Override public void executeCommand( final String cmdAttribute, final String originalCommand, final boolean async) throws Exception { // Clean command String cmd = TangoUtils.getBracketedCommand(originalCommand); final DeviceData cmdData = new DeviceData(); cmdData.insert(new String[] {cmd}); executeCommand(cmdAttribute, originalCommand, cmdData, async); }
private Map<String, String> setMotors(final MotorContainer cont, final DataMessageComponent comp) throws DataMessageException { final Map<String, String> ret = new HashMap<String, String>(cont.size()); for (MotorBean mb : cont.getExpressions()) { final String motorPath = SubstituteUtils.substitute(mb.getMotorName(), comp.getScalar()); final String baseUri = TangoUtils.getHardwareAddress(motorPath); String attribute = mb.getAttributeName(); if (attribute == null || "".equals(attribute.trim())) attribute = "Position"; DeviceAttribute value = null; if (!mb.isReadOnly()) { try { final double dbl = ExpressionUtils.evaluateExpression(mb.getExpression(), comp.getScalar()); if (Double.isNaN(dbl) || Double.isInfinite(dbl)) throw new Exception(); value = new DeviceAttribute(attribute, dbl); } catch (Exception e) { final String exp = SubstituteUtils.substitute(mb.getExpression(), comp.getScalar()); value = new DeviceAttribute(attribute, exp); } } try { final TangoConnection connection = TangoConnectionFactory.openConnection(baseUri, attribute); if (value != null) { connection.setValue(value); // Uses remote call for MockMode } try { value = connection.getValue(); } catch (Exception ne) { logger.debug("Error in TangoMotorTransformer " + getName()); logger.debug("Error message: " + ne.getMessage()); logger.debug(ne.getStackTrace().toString()); value = new DeviceAttribute(attribute, 0.0); } try { final String dblString = String.valueOf(value.extractDouble()); ret.put(connection.getName(), dblString); } catch (Exception ne) { ret.put(connection.getName(), String.valueOf(value.extractString())); } } catch (Exception e) { throw createDataMessageException("Cannot connect to " + baseUri, e); } } return ret; }
private void executeCommand(String cmd) throws Exception { final Matcher matcher = TangoUtils.getBracketedMatcher(cmd); if (matcher == null) { notifyCommand("Command '" + cmd + "' not implemented in mock mode.", cmd); notifyEndCommand(); return; } final String command = matcher.group(1); if (commandMap.containsKey(command)) { commandMap.get(command).processCommand(matcher, MockTangoConnection.this); } else { notifyCommand("Command '" + cmd + "' not implemented in mock mode.", cmd); notifyEndCommand(); } ; }