Skip to content
Snippets Groups Projects
Commit 88a67003 authored by Guillaume PICHON's avatar Guillaume PICHON
Browse files

Bug correction when parameters are wrongs and logging improvement.

parent 7c72d75a
Branches
No related tags found
No related merge requests found
......@@ -96,6 +96,7 @@ public abstract class AOpcUaSubscriber implements IAttributeValueConsumer {
Set<OpcUaAttribute> attributesForSub = attributesBySubscription.get(subId);
Set<OpcUaAttributeReference> attrRefsToRemove = new TreeSet<>();
for (OpcUaAttribute opcuaAttribute : attributesForSub) {
//The attribute's name is set to lower case as a woarkarround of a JTango issue. It is not properly done in the called method.
getDynamicManager().removeAttribute(opcuaAttribute.getConfiguration().getName().toLowerCase(Locale.ENGLISH));
}
for (Entry<OpcUaAttributeReference, Set<OpcUaAttribute>> entry : attributes.entrySet()) {
......
......@@ -143,20 +143,18 @@ public class OpcUaConnector extends AOpcUaSubscriber {
OpcUaClientFactory opcuaClientFactory = getOpcuaClientFactory(deviceManager.getName(), opcuaURL,
requestTimeout);
this.opcUaProxyClient = new OpcUaProxyClient(opcuaClientFactory);
String errorMessage = null;
try {
this.opcUaProxyClient.connect(this::setStateStatus);
} catch (DevFailed e) {
errorMessage = e.getMessage();
logger.error("OpcUa connection error.", e);
}
if( this.opcUaProxyClient.isConnected() ) {
if (createDiagnosticAttributes) {
createDiagnosticAttributes();
}
if (subscribers.size() > 0) {
setStatus("Init in progress.\nReinit subscribers.");
synchronized (subscribers) {
for (AOpcUaSubscriber subscriber : subscribers) {
subscriber.reinitSubscriptions();
}
}
}
String sessionName = this.opcUaProxyClient.getSessionName();
String sessionId = this.opcUaProxyClient.getSessionIdString();
......@@ -177,12 +175,29 @@ public class OpcUaConnector extends AOpcUaSubscriber {
logger.info(statusBuilder.toString());
setStatus(statusBuilder.toString());
} else {
StringBuilder statusBuilder = new StringBuilder();
statusBuilder.append("Connection failed.");
if( errorMessage!=null ) {
statusBuilder.append('\n');
statusBuilder.append(errorMessage);
}
setStateStatus(DeviceState.FAULT, errorMessage, true);
}
if (subscribers.size() > 0) {
setStatus("Init in progress.\nReinit subscribers.");
synchronized (subscribers) {
for (AOpcUaSubscriber subscriber : subscribers) {
subscriber.reinitSubscriptions();
}
}
}
boolean registerOk = OpcUaProxy.setConnector(this);
if (!registerOk) {
// Another connector is running.
delete();
throw DevFailedUtils.newDevFailed(sessionId);
throw DevFailedUtils.newDevFailed("Another connector is running.");
}
if (getState() == DeviceState.INIT) {
......@@ -191,6 +206,10 @@ public class OpcUaConnector extends AOpcUaSubscriber {
logger.debug("init done for device {} ", deviceManager.getName());
}
public boolean isConnected() {
return this.opcUaProxyClient.isConnected();
}
/**
* delete device
*
......
......@@ -145,6 +145,10 @@ class OpcUaProxyClient implements IOpcUaNodeWriter {
return true;
}
public boolean isConnected() {
return this.sessionId != null;
}
public NodeId getSessionId() {
return sessionId;
}
......@@ -338,6 +342,7 @@ class OpcUaProxyClient implements IOpcUaNodeWriter {
if (!leafNodes.isEmpty()) {
try {
for (OpcUaSimpleNode node : leafNodes) {
try {
UaNode uaNode = client.getAddressSpace().getNode(node.getNodeId());
String name = node.getOpcuaIdStr();
String label = uaNode.getDisplayName().getLocale();
......@@ -355,10 +360,14 @@ class OpcUaProxyClient implements IOpcUaNodeWriter {
if (write) {
writeAttrRef = Collections.singletonList(attrRef);
}
// It's a leaf, it cannot be browsed.
OpcUaAttributeParameters attributeParameters = new OpcUaAttributeParameters(name, label,
activatedEvents, attrRef, writeAttrRef, samplingInterval, false, false); // It's a leaf, it cannot
// be browsed.
activatedEvents, attrRef, writeAttrRef, samplingInterval, false, false);
parametersList.add(attributeParameters);
} catch (UaException e) {
logger.error("Error while retreiving the node " + node.toString());
throw e;
}
}
} catch (UaException e) {
throw DevFailedUtils.newDevFailed(e);
......@@ -470,7 +479,8 @@ class OpcUaProxyClient implements IOpcUaNodeWriter {
List<OpcUaAttributeParameters> subParametersList = null;
if (parameters.isToBrowse()) {
subParametersList = getLeafsParameters(parameters.getReadNode().getNode(),
parameters.getActivatedEvents(), parameters.isToWriteLeafs(), parameters.getSamplingInterval());
parameters.getActivatedEvents(), parameters.isToWriteLeafs(),
parameters.getSamplingInterval());
} else {
subParametersList = Collections.singletonList(parameters);
}
......
......@@ -156,12 +156,14 @@ public class OpcUaSubscriber extends AOpcUaSubscriber {
defaultSamplingIndexSub = subscriptions.getDefaultSamplingInterval();
}
if (connector.isConnected()) {
List<SubscriptionResult> subscriptionResults = new ArrayList<>(subscriptions.getSubscriptions().size());
for (Subscription subscription : subscriptions.getSubscriptions()) {
List<OpcUaAttributeParameters> parametersList = new ArrayList<>(subscription.getAttributes().size());
List<OpcUaAttributeParameters> parametersList = new ArrayList<>(
subscription.getAttributes().size());
for (AttributeDefinition attrDef : subscription.getAttributes()) {
OpcUaAttributeParameters parameters = new OpcUaAttributeParameters(attrDef, defaultOpcUaIdTypeSub,
defaultNamespaceIndexSub, defaultSamplingIndexSub);
OpcUaAttributeParameters parameters = new OpcUaAttributeParameters(attrDef,
defaultOpcUaIdTypeSub, defaultNamespaceIndexSub, defaultSamplingIndexSub);
parametersList.add(parameters);
}
SubscriptionResult subscriptionResult = connector.createOPCUAAttributes(parametersList,
......@@ -171,6 +173,7 @@ public class OpcUaSubscriber extends AOpcUaSubscriber {
createTangoAttributes(subscriptionResults);
}
}
}
@Override
protected DeviceManager getDeviceManager() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment