Commit 5a17ea7a authored by Ivan Dages's avatar Ivan Dages
Browse files

link : controller wrapper

parent 688c9e08
package fr.ill.ics.n3d.link;
import java.util.ArrayList;
import java.util.logging.Logger;
import fr.ill.ics.bridge.Controller;
import fr.ill.ics.core.property.Property;
import fr.ill.ics.core.property.PropertyManager;
/**
* Wrapper for Nomad controller
* @author dages
*/
public class Nomad3DController {
public enum Type {
ROTATION {
@Override
public void init() {
this.unitValues = new ArrayList<String>();
this.unitValues.add("");
this.unitValues.add("deg");
this.unitValues.add("degree");
}
},
TRANSLATION {
@Override
public void init() {
this.unitValues = new ArrayList<String>();
this.unitValues.add("mm");
this.unitValues.add("cm");
}
},
STEP {
@Override
public void init() {
this.unitValues = new ArrayList<String>();
this.unitValues.add("step");
}
};
protected ArrayList<String> unitValues;
private Type() {
init();
}
protected abstract void init();
public static Type fromUnitValue(String unitValue) {
if (ROTATION.unitValues.contains(unitValue)) {
return Type.ROTATION;
} else if (TRANSLATION.unitValues.contains(unitValue)) {
return Type.TRANSLATION;
} else if (STEP.unitValues.contains(unitValue)) {
return Type.STEP;
} else {
Logger.getLogger("nomad-3d").severe("Unknown unit value \"" + unitValue + "\"");
return null;
}
}
@Override
public String toString() {
return this.unitValues.get(0);
}
}
/** Wrapped controller. */
private Controller controller;
/**
* Constructor.
* @param controller Controller to wrap
*/
public Nomad3DController(Controller controller) {
this.controller = controller;
}
public String getName() {
return controller.getName();
}
public String getPropertyValue(String propertyName) {
Property prop = PropertyManager.getInstance().getProperty(controller, propertyName);
return prop.getValue();
}
public String getPropertyServerValue(String propertyName) {
Property prop = PropertyManager.getInstance().getProperty(controller, propertyName);
return prop.getServerValue();
}
public double getActualPosition() {
return Double.parseDouble(getPropertyServerValue("actual_position"));
}
public double getWantedPosition() {
return Double.parseDouble(getPropertyServerValue("wanted_position"));
}
public double getMinPosition() {
return Double.parseDouble(getPropertyServerValue("min_position"));
}
public double getMaxPosition() {
return Double.parseDouble(getPropertyServerValue("max_position"));
}
public Type getType() {
return Type.fromUnitValue(getPropertyServerValue("unit"));
}
@Override
public String toString() {
return this.getName();
}
}
......@@ -34,7 +34,7 @@ public class NomadLinker {
private final static NomadLinker instance = new NomadLinker();
private HashMap<String, ControllerServant> controllers;
private HashMap<String, Nomad3DController> controllers;
/**
* Default constructor.
......@@ -69,12 +69,8 @@ public class NomadLinker {
for (String controllerName : controllersNames) {
ControllerServant controller = ControllerManager.getInstance().getController(controllerName);
controllers.put(controllerName, controller);
// Property prop = PropertyManager.getInstance().getProperty(controller, "actual_position");
// System.out.println("server value : " + prop.getServerValue());
controllers.put(controllerName, new Nomad3DController(controller));
}
// System.out.println("Loaded controllers : \n" + controllers);
// displayActualPositions();
Logger.getLogger("nomad-3d").info("Nomad server connection initialized.");
}
......@@ -83,35 +79,32 @@ public class NomadLinker {
return controllers.keySet();
}
public String getServerValue(String controllerName, String propertyName) {
ControllerServant controller = controllers.get(controllerName);
Property prop = PropertyManager.getInstance().getProperty(controller, propertyName);
return prop.getServerValue();
}
public String getValue(String controllerName, String propertyName) {
ControllerServant controller = controllers.get(controllerName);
Property prop = PropertyManager.getInstance().getProperty(controller, propertyName);
return prop.getValue();
}
// TODO TEST
private void displayActualPositions() {
public void displayProperties() {
String msg = "";
String properties[] = {
"actual_position",
"offset_position",
"wanted_position",
"min_position",
"max_position",
"unit"
};
System.out.println("Controllers : ");
for (String controllerName : getAxisControllersNames()) {
System.out.println(controllerName + " :");
for (String propertyName : properties) {
String val = getServerValue(controllerName, propertyName);
System.out.println("\t" + propertyName + " : " + val);
}
msg += "Controllers : \n";
for (Nomad3DController controller : controllers.values()) {
msg += controller + " :\n";
// for (String propertyName : properties) {
// String val = controller.getPropertyServerValue(propertyName);
// msg += "\t" + propertyName + " : " + val + "\n";
// }
msg += "\tactual position : " + controller.getActualPosition() + "\n";
msg += "\toffset position : " + controller.getPropertyServerValue("offset_position") + "\n";
msg += "\twanted position : " + controller.getWantedPosition() + "\n";
msg += "\tmin position : " + controller.getMinPosition() + "\n";
msg += "\tmax position : " + controller.getMaxPosition() + "\n";
msg += "\tunit : " + controller.getType() + "\n";
}
Logger.getLogger("nomad-3d").info(msg);
}
public void terminate() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment