Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,8 @@ public Collection<DeviceInfo> getScanDevices(final long id) throws Exception
*/
public long submitScan(final String name, final String xml_commands, final boolean queue) throws Exception
{
final HttpURLConnection connection = connect("/scan/" + name, queue ? "" : "queue=false", long_timeout);
final String params = (queue ? "" : "queue=false") + "&pre_post=false";
final HttpURLConnection connection = connect("/scan/" + name, params, long_timeout);
connection.setReadTimeout(0);
try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public class ScanInfoModel
private volatile List<ScanInfo> infos = Collections.emptyList();

/** Listeners */
private List<ScanInfoModelListener> listeners = new CopyOnWriteArrayList<>();
private List<ScanInfoModelListener> listeners = new CopyOnWriteArrayList<ScanInfoModelListener>();


/** Obtain reference to the singleton instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ host=localhost
# TCP port of scan server REST interface
port=4810

# Poll period in milliseconds of the scan client (scan monitor, plot, ...)
poll_period=1000
# Poll period [millisecs] of the scan client (scan monitor, plot, ...)
poll_period=1000
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,8 @@ private static int fillFlatArray(final ListNumber flat, int index, final Object
if (data instanceof List)
{
final List<?> list = (List<?>)data;
for (Object o : list) index = fillFlatArray(flat, index, o);
for (int i=0; i<list.size(); ++i)
index = fillFlatArray(flat, index, list.get(i));
return index;
}
else if (data.getClass().isArray())
Expand All @@ -320,9 +321,9 @@ else if (data instanceof Number)
flat.setDouble(index, ((Number)data).doubleValue());
return index + 1;
}
else if (data instanceof Boolean)
else if (data instanceof Boolean bool)
{
flat.setByte(index, Boolean.TRUE.equals(data) ? (byte)1 : 0);
flat.setByte(index, bool.booleanValue() ? (byte)1 : 0);
return index + 1;
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.net.URL;
import java.util.Map;
import java.util.function.Supplier;
import java.util.LinkedHashMap;

import org.csstudio.scan.ScanSystem;
import org.csstudio.scan.spi.ScanCommandRegistry;
Expand All @@ -41,6 +42,7 @@ public Map<String, URL> getImages()
entry("include", ScanSystem.class.getResource("/icons/includecommand.gif")),
entry("log", ScanSystem.class.getResource("/icons/logcommand.gif")),
entry("loop", ScanSystem.class.getResource("/icons/loopcommand.gif")),
entry("while", ScanSystem.class.getResource("/icons/loopcommand.gif")),
entry("parallel", ScanSystem.class.getResource("/icons/parallelcommand.gif")),
entry("script", ScanSystem.class.getResource("/icons/scriptcommand.gif")),
entry("sequence", ScanSystem.class.getResource("/icons/sequencecommand.gif")),
Expand All @@ -52,19 +54,20 @@ public Map<String, URL> getImages()
@Override
public Map<String, Supplier<ScanCommand>> getCommands()
{
return Map.ofEntries(
entry("comment", CommentCommand::new),
entry("config_log", ConfigLogCommand::new),
entry("delay", DelayCommand::new),
entry("if", IfCommand::new),
entry("include", IncludeCommand::new),
entry("log", LogCommand::new),
entry("loop", LoopCommand::new),
entry("parallel", ParallelCommand::new),
entry("script", ScriptCommand::new),
entry("sequence", SequenceCommand::new),
entry("set", SetCommand::new),
entry("wait", WaitCommand::new)
);
final Map<String, Supplier<ScanCommand>> commands = new LinkedHashMap<>();
commands.put("comment", CommentCommand::new);
commands.put("config_log", ConfigLogCommand::new);
commands.put("log", LogCommand::new);
commands.put("delay", DelayCommand::new);
commands.put("if", IfCommand::new);
commands.put("wait", WaitCommand::new);
commands.put("set", SetCommand::new);
commands.put("loop", LoopCommand::new);
commands.put("while", WhileCommand::new);
commands.put("parallel", ParallelCommand::new);
commands.put("sequence", SequenceCommand::new);
commands.put("script", ScriptCommand::new);
commands.put("include", IncludeCommand::new);
return commands;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public CommandSequence(final ScanCommand... commands)
*/
public CommandSequence(final Collection<ScanCommand> commands)
{
this.commands = new ArrayList<>();
this.commands = new ArrayList<ScanCommand>();
this.commands.addAll(commands);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,8 @@ public void addXMLElements(final Document dom, final Element command_element)
command_element.appendChild(element);

element = dom.createElement("value");
if (desired_value instanceof String)
element.appendChild(dom.createTextNode('"' + (String)desired_value + '"'));
else
element.appendChild(dom.createTextNode(desired_value.toString()));
// Quoted: literal String; unquoted: Double or PVReference (PV name)
element.appendChild(dom.createTextNode(StringOrDouble.quote(desired_value)));
command_element.appendChild(element);

element = dom.createElement("comparison");
Expand Down Expand Up @@ -174,7 +172,7 @@ public String toString()
buf.append("If '").append(device_name).append("' ")
.append(comparison).append(" ");
buf.append(StringOrDouble.quote(desired_value));
if (comparison == Comparison.EQUALS)
if (comparison != Comparison.IN && comparison != Comparison.NOT_IN && tolerance > 0.0)
buf.append(" (+-").append(tolerance).append(")");
return buf.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void addXMLElements(final Document dom, final Element command_element)
@Override
public void readXML(final Element element) throws Exception
{
final List<String> devices = new ArrayList<>();
final List<String> devices = new ArrayList<String>();
Element node = XMLUtil.getChildElement(element, "devices");
if (node == null)
throw new Exception("Missing 'devices'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.List;
import java.util.Objects;

import org.csstudio.scan.util.PVReference;
import org.csstudio.scan.util.StringOrDouble;
import org.phoebus.framework.persistence.XMLUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -49,10 +51,15 @@
@SuppressWarnings("nls")
public class LoopCommand extends ScanCommandWithBody
{
private static final String START_TAG = "start";

private volatile String device_name;
private volatile double start;
private volatile double end;
private volatile double stepsize;
/** Start value: {@link Double} literal or {@link PVReference} (PV name read at runtime) */
private volatile Object start;
/** End value: {@link Double} literal or {@link PVReference} (PV name read at runtime) */
private volatile Object end;
/** Step size: {@link Double} literal or {@link PVReference} (PV name read at runtime) */
private volatile Object stepsize;
private volatile String readback = "";
private volatile boolean completion = false;
private volatile boolean wait = true;
Expand Down Expand Up @@ -114,19 +121,19 @@ public LoopCommand(final String device_name, final double start,
{
super(body);
this.device_name = Objects.requireNonNull(device_name);
setStepSize(stepsize);
this.start = start;
this.end = end;
setStepSize(Double.valueOf(stepsize));
this.start = Double.valueOf(start);
this.end = Double.valueOf(end);
}

/** {@inheritDoc} */
@Override
protected void configureProperties(final List<ScanCommandProperty> properties)
{
properties.add(ScanCommandProperty.DEVICE_NAME);
properties.add(new ScanCommandProperty("start", "Initial Value", Double.class));
properties.add(new ScanCommandProperty("end", "Final Value", Double.class));
properties.add(new ScanCommandProperty("step_size", "Step Size", Double.class));
properties.add(new ScanCommandProperty(START_TAG, "Initial Value", Object.class));
properties.add(new ScanCommandProperty("end", "Final Value", Object.class));
properties.add(new ScanCommandProperty("step_size", "Step Size", Object.class));
properties.add(ScanCommandProperty.COMPLETION);
properties.add(ScanCommandProperty.WAIT);
properties.add(ScanCommandProperty.READBACK);
Expand All @@ -149,45 +156,50 @@ public void setDeviceName(final String device_name)
this.device_name = device_name;
}

/** @return Loop start value */
public double getStart()
/** @return Loop start value: {@link Double} or {@link PVReference} */
public Object getStart()
{
return start;
}

/** @param start Initial loop value */
public void setStart(final Double start)
/** @param start Initial loop value ({@link Double} or {@link PVReference}) */
public void setStart(final Object start)
{
this.start = start;
}

/** @return Loop end value */
public double getEnd()
/** @return Loop end value: {@link Double} or {@link PVReference} */
public Object getEnd()
{
return end;
}

/** @param end Final loop value */
public void setEnd(final Double end)
/** @param end Final loop value ({@link Double} or {@link PVReference}) */
public void setEnd(final Object end)
{
this.end = end;
}

/** @return Loop step size */
public double getStepSize()
/** @return Loop step size: {@link Double} or {@link PVReference} */
public Object getStepSize()
{
return stepsize;
}

/** @param stepsize Increment of the loop variable */
public void setStepSize(final Double stepsize)
/** @param stepsize Increment of the loop variable ({@link Double} or {@link PVReference}) */
public void setStepSize(final Object stepsize)
{
if (stepsize != 0.0)
this.stepsize = stepsize;
if (stepsize instanceof Double step)
{
final double s = step.doubleValue();
this.stepsize = (s == 0.0) ? 1.0 : s;
// Use fraction of stepsize for tolerance
tolerance = Math.abs((Double) this.stepsize / 10.0);
}
else
this.stepsize = 1.0;
// Use fraction of stepsize for tolerance
tolerance = Math.abs(this.stepsize / 10.0);
{ // PVReference: defer tolerance calculation to runtime
this.stepsize = stepsize;
}
}

/** @return Wait for write completion? */
Expand Down Expand Up @@ -263,16 +275,16 @@ public void addXMLElements(final Document dom, final Element command_element)
element.appendChild(dom.createTextNode(device_name));
command_element.appendChild(element);

element = dom.createElement("start");
element.appendChild(dom.createTextNode(Double.toString(start)));
element = dom.createElement(START_TAG);
element.appendChild(dom.createTextNode(StringOrDouble.quote(start)));
command_element.appendChild(element);

element = dom.createElement("end");
element.appendChild(dom.createTextNode(Double.toString(end)));
element.appendChild(dom.createTextNode(StringOrDouble.quote(end)));
command_element.appendChild(element);

element = dom.createElement("step");
element.appendChild(dom.createTextNode(Double.toString(stepsize)));
element.appendChild(dom.createTextNode(StringOrDouble.quote(stepsize)));
command_element.appendChild(element);

if (completion)
Expand Down Expand Up @@ -316,9 +328,9 @@ public void readXML(final Element element) throws Exception
super.readXML(element);

setDeviceName(XMLUtil.getChildString(element, ScanCommandProperty.TAG_DEVICE).orElse(""));
setStart(XMLUtil.getChildDouble(element, "start").orElse(0.0));
setEnd(XMLUtil.getChildDouble(element, "end").orElse(10.0));
setStepSize(XMLUtil.getChildDouble(element, "step").orElse(1.0));
setStart(StringOrDouble.parse(XMLUtil.getChildString(element, START_TAG).orElse("0")));
setEnd(StringOrDouble.parse(XMLUtil.getChildString(element, "end").orElse("10")));
setStepSize(StringOrDouble.parse(XMLUtil.getChildString(element, "step").orElse("1")));
setCompletion(XMLUtil.getChildBoolean(element, ScanCommandProperty.TAG_COMPLETION).orElse(false));
setWait(XMLUtil.getChildBoolean(element, ScanCommandProperty.TAG_WAIT).orElse(true));
setReadback(XMLUtil.getChildString(element, ScanCommandProperty.TAG_READBACK).orElse(""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.function.Supplier;
import java.util.logging.Level;

Expand All @@ -38,21 +38,24 @@
public class ScanCommandFactory
{
private static final Map<String, URL> images = new HashMap<>();
private static final Map<String, Supplier<ScanCommand>> factories = new HashMap<>();
private static final Map<String, Supplier<ScanCommand>> factories = new LinkedHashMap<>();

static
{
for (ScanCommandRegistry reg : ServiceLoader.load(ScanCommandRegistry.class))
{
logger.info(() -> "Loaded registry: " + reg.getClass().getName());
Map<String, Supplier<ScanCommand>> cmds = reg.getCommands();
logger.info(() -> "Commands from " + reg.getClass().getSimpleName() + ": " + cmds.keySet());
images.putAll(reg.getImages());
factories.putAll(reg.getCommands());
logger.info(() -> "Factories now: " + factories.keySet());
}
}

/** @return All known command IDs */
public static Set<String> getCommandIDs()
public static List<String> getCommandIDs()
{
return factories.keySet();
return new ArrayList<>(factories.keySet());
}

/** @param id Command ID
Expand Down Expand Up @@ -86,7 +89,7 @@ public static URL getImage(final String id)
*/
public static List<ScanCommand> readCommands(Node node) throws Exception
{
final List<ScanCommand> commands = new ArrayList<>();
final List<ScanCommand> commands = new ArrayList<ScanCommand>();
while (node != null)
{
if (node.getNodeType() == Node.ELEMENT_NODE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public ScanCommandWithBody(final List<ScanCommand> body)
*/
protected static List<ScanCommand> toList(final ScanCommand[] commands)
{
final List<ScanCommand> list = new ArrayList<>(commands.length);
final List<ScanCommand> list = new ArrayList<ScanCommand>(commands.length);
for (ScanCommand command : commands)
list.add(command);
return list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ abstract public class ScanScriptContext
public double[][] getData(final String... devices) throws Exception
{
ScanDataIterator sheet = new ScanDataIterator(getScanData(), devices);
final List<List<Double>> data = new ArrayList<>(devices.length);
final List<List<Double>> data = new ArrayList<List<Double>>(devices.length);
for (int i=0; i<devices.length; ++i)
data.add(new ArrayList<>());
data.add(new ArrayList<Double>());
while (sheet.hasNext())
{
final ScanSample[] samples = sheet.getSamples();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void readXML(final Element element) throws Exception
{
setScript(XMLUtil.getChildString(element, "path").orElse(""));

final List<String> arguments = new ArrayList<>();
final List<String> arguments = new ArrayList<String>();
Element node = XMLUtil.getChildElement(element, "arguments");
if (node != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,8 @@ public void addXMLElements(final Document dom, final Element command_element)
command_element.appendChild(element);

element = dom.createElement("value");
if (desired_value instanceof String)
element.appendChild(dom.createTextNode('"' + (String)desired_value + '"'));
else
element.appendChild(dom.createTextNode(desired_value.toString()));
// Quoted: literal String; unquoted: Double or PVReference (PV name)
element.appendChild(dom.createTextNode(StringOrDouble.quote(desired_value)));
command_element.appendChild(element);

element = dom.createElement("comparison");
Expand Down Expand Up @@ -223,7 +221,7 @@ public String toString()
final StringBuilder buf = new StringBuilder();
buf.append("Wait for '").append(device_name).append("' ").append(comparison).append(" ");
buf.append(StringOrDouble.quote(desired_value));
if (comparison == Comparison.EQUALS)
if (comparison != Comparison.IN && comparison != Comparison.NOT_IN && tolerance > 0.0)
buf.append(" (+-").append(tolerance).append(")");
if (timeout > 0)
buf.append(" (").append(timeout).append(" sec timeout)");
Expand Down
Loading