}
}
protected void initScanCommon(IConfig<?> config, String scanServerName) throws SalsaDeviceException {
LOGGER.trace("initScanCommon({})", config);
DeviceProxy scanServerProxy = TangoDeviceHelper.getDeviceProxy(scanServerName, false);
if (scanServerProxy != null) {
try {
// Time out
actionName = "set_timeout_millis(10000)";
LOGGER.trace("{}/{}", scanServerName, actionName);
scanServerProxy.set_timeout_millis(10000);
// First Init Clean
// command("Clean");//The Clean command do not clean anything
// bug 0023724
command("Init");
// Partial mode for recording,clean set mode to false
boolean isPartialMode = isDataRecorderPartialMode();
actionName = writeAttributeLog(CurrentScanDataModel.DATA_RECORDER_PARTIAL_MODE,
String.valueOf(isPartialMode));
setAttribute(CurrentScanDataModel.DATA_RECORDER_PARTIAL_MODE, isPartialMode, false);
// Run name JIRA SCAN-163
String runName = config.getRunName();
if ((runName == null) || runName.trim().isEmpty()) {
String configName = config.getName();
IDirectory directory = config.getDirectory();
while (directory != null) {
configName = directory.getName() + "." + configName;
directory = directory.getDirectory();
}
runName = configName;
}
actionName = writeAttributeLog(CurrentScanDataModel.RUN_NAME, runName);
setAttribute(CurrentScanDataModel.RUN_NAME, runName, false);
// Scan number.
int scanNumber = config.getScanNumber();
actionName = writeAttributeLog(CurrentScanDataModel.SCAN_NUMBER, String.valueOf(scanNumber));
setAttribute(CurrentScanDataModel.SCAN_NUMBER, scanNumber, false);
// Timebases
List<ITimebase> timebasesList = config.getTimebaseList();
List<String> timebasesNameList = new ArrayList<String>(timebasesList.size());
String deviceName = null;
for (ITimebase timebase : timebasesList) {
deviceName = timebase.getName();
if (timebase.isEnabled() && (deviceName != null) && !deviceName.trim().isEmpty()) {
timebasesNameList.add(timebase.getName());
}
}
String[] timebasesNameArray = timebasesNameList.toArray(new String[timebasesNameList.size()]);
actionName = writeAttributeLog(CurrentScanDataModel.TIMEBASES, Arrays.toString(timebasesNameArray));
setAttribute(CurrentScanDataModel.TIMEBASES, timebasesNameArray, false);
// Sensors
List<ISensor> sensorsList = config.getSensorsList();
List<String> sensorsNameList = new ArrayList<String>(sensorsList.size());
for (ISensor sensor : sensorsList) {
deviceName = sensor.getName();
if (sensor.isEnabled() && (deviceName != null) && !deviceName.trim().isEmpty()) {
sensorsNameList.add(sensor.getName());
}
}
String[] sensorsNameArray = sensorsNameList.toArray(new String[sensorsNameList.size()]);
actionName = writeAttributeLog(CurrentScanDataModel.SENSORS_LIST, Arrays.toString(sensorsNameArray));
setAttribute(CurrentScanDataModel.SENSORS_LIST, sensorsNameArray, false);
// Actuator delay.
double actuatorsDelay = config.getActuatorsDelay();
actionName = writeAttributeLog(CurrentScanDataModel.ACTUATOR_DELAY, String.valueOf(actuatorsDelay));
setAttribute(CurrentScanDataModel.ACTUATOR_DELAY, actuatorsDelay, false);
// Zig zag.
boolean zigzag = config.isZigzag();
actionName = writeAttributeLog(CurrentScanDataModel.ZIGZAG, String.valueOf(zigzag));
setAttribute(CurrentScanDataModel.ZIGZAG, zigzag, false);
// Enable actuator speed.
boolean enableScanSpeed = config.isEnableScanSpeed();
actionName = writeAttributeLog(CurrentScanDataModel.ENABLESCANSPEED, String.valueOf(enableScanSpeed));
setAttribute(CurrentScanDataModel.ENABLESCANSPEED, enableScanSpeed, false);
// Post scan behaviour.
IPostScanBehaviour postScanBehaviour = config.getScanAddOn().getPostScanBehaviour();
Behaviour behaviour = postScanBehaviour.getBehaviour();
if (behaviour == null) {
behaviour = Behaviour.NOOP;
}
int behaviourType = behaviour.getType();
actionName = writeAttributeLog(CurrentScanDataModel.AFTER_ACTION_TYPE, String.valueOf(behaviourType));
setAttribute(CurrentScanDataModel.AFTER_ACTION_TYPE, behaviourType, false);
if (behaviour.getArgumentCount() >= 1) {
int behaviourSensorIndex = postScanBehaviour.getSensor();
actionName = writeAttributeLog(CurrentScanDataModel.AFTER_ACTION_SENSOR,
String.valueOf(behaviourSensorIndex));
setAttribute(CurrentScanDataModel.AFTER_ACTION_SENSOR, behaviourSensorIndex, false);
} else if (behaviour.getArgumentCount() >= 2) {
int behaviourActuatorIndex = postScanBehaviour.getActuator();
actionName = writeAttributeLog(CurrentScanDataModel.AFTER_ACTION_ACTUATOR,
String.valueOf(behaviourActuatorIndex));
setAttribute(CurrentScanDataModel.AFTER_ACTION_ACTUATOR, behaviourActuatorIndex, false);
}
// Error strategies.
if ((config.getScanAddOn() != null) && (config.getScanAddOn().getErrorStrategy() != null)) {
IErrorStrategy errorStrat = config.getScanAddOn().getErrorStrategy();
IErrorStrategyItem[] categoriesESI = new IErrorStrategyItem[] {
errorStrat.getActuatorsErrorStrategy(), errorStrat.getSensorsErrorStrategy(),
errorStrat.getTimebasesErrorStrategy(), errorStrat.getHooksErrorStrategy() };
String[] categoriesStr = new String[] { "actuators", "sensors", "timebases", "hooks" };
for (int i = 0; i < categoriesStr.length; i++) {
String cat = categoriesStr[i];
IErrorStrategyItem esi = categoriesESI[i];
double errorStrategyTimeOut = esi.getTimeOut();
int errorStrategyRetryCount = esi.getRetryCount();
double errorStrategyRetryTimeOut = esi.getTimeBetweenRetries();
int errorStrategyType = esi.getStrategy().ordinal();
// Time out.
String catAttribute = cat + "TimeOut";
actionName = writeAttributeLog(catAttribute, String.valueOf(errorStrategyTimeOut));
scanServerProxy.write_attribute(new DeviceAttribute(catAttribute, errorStrategyTimeOut));
// Retry count.
catAttribute = cat + "RetryCount";
actionName = writeAttributeLog(catAttribute, String.valueOf(errorStrategyRetryCount));
scanServerProxy.write_attribute(new DeviceAttribute(catAttribute, errorStrategyRetryCount));
// Retry time out.
catAttribute = cat + "RetryTimeOut";
actionName = writeAttributeLog(catAttribute, String.valueOf(errorStrategyRetryTimeOut));
scanServerProxy.write_attribute(new DeviceAttribute(catAttribute, errorStrategyRetryTimeOut));
// Error strategy.
catAttribute = cat + "ErrorStrategy";
actionName = writeAttributeLog(catAttribute, String.valueOf(errorStrategyType));
scanServerProxy.write_attribute(new DeviceAttribute(catAttribute, errorStrategyType));
}
// Context validation error strategy.
int erreurStrategyValue = errorStrat.getContextValidationStrategy().ordinal();
actionName = writeAttributeLog(CurrentScanDataModel.CONTEXT_VALIDATION_STRATEGY,
String.valueOf(erreurStrategyValue));