use of com.beanit.iec61850bean.ServiceError in project OpenMUC by isc-konstanz.
the class Iec61850Connection method setRecordContainer.
private FcModelNode setRecordContainer(ChannelRecordContainer container) throws ConnectionException {
if (container.getChannelHandle() == null) {
return null;
}
FcModelNode fcModelNode = (FcModelNode) container.getChannelHandle();
try {
clientAssociation.getDataValues(fcModelNode);
} catch (ServiceError e) {
logger.debug("Error reading channel: service error calling getDataValues on {}: {}", container.getChannelAddress(), e);
container.setRecord(new Record(Flag.DRIVER_ERROR_CHANNEL_NOT_ACCESSIBLE));
return fcModelNode;
} catch (IOException e) {
throw new ConnectionException(e);
}
if (fcModelNode instanceof BasicDataAttribute) {
long receiveTime = System.currentTimeMillis();
setRecord(container, (BasicDataAttribute) fcModelNode, receiveTime);
} else {
StringBuilder sb = new StringBuilder("");
for (BasicDataAttribute bda : fcModelNode.getBasicDataAttributes()) {
sb.append(bda2String(bda) + STRING_SEPARATOR);
}
// remove last separator
sb.delete(sb.length() - 1, sb.length());
long receiveTime = System.currentTimeMillis();
setRecord(container, sb.toString(), receiveTime);
}
return null;
}
use of com.beanit.iec61850bean.ServiceError in project OpenMUC by isc-konstanz.
the class Iec61850Connection method setRecordContainerWithSamplingGroup.
private Object setRecordContainerWithSamplingGroup(List<ChannelRecordContainer> containers, Object containerListHandle, String samplingGroup) throws ConnectionException {
FcModelNode fcModelNode;
if (containerListHandle != null) {
fcModelNode = (FcModelNode) containerListHandle;
} else {
String[] args = samplingGroup.split(":", 3);
if (args.length != 2) {
logger.debug("Wrong sampling group syntax: {}", samplingGroup);
for (ChannelRecordContainer container : containers) {
container.setRecord(new Record(Flag.DRIVER_ERROR_SAMPLING_GROUP_NOT_FOUND));
}
return null;
}
ModelNode modelNode = serverModel.findModelNode(args[0], Fc.fromString(args[1]));
if (modelNode == null) {
logger.debug("Error reading sampling group: no FCDO/DA or DataSet with object reference {} was not found in the server model.", samplingGroup);
for (ChannelRecordContainer container : containers) {
container.setRecord(new Record(Flag.DRIVER_ERROR_SAMPLING_GROUP_NOT_FOUND));
}
return null;
}
try {
fcModelNode = (FcModelNode) modelNode;
} catch (ClassCastException e) {
logger.debug("Error reading channel: ModelNode with sampling group reference {} was found in the server model but is not a FcModelNode.", samplingGroup);
for (ChannelRecordContainer container : containers) {
container.setRecord(new Record(Flag.DRIVER_ERROR_SAMPLING_GROUP_NOT_FOUND));
}
return null;
}
}
try {
clientAssociation.getDataValues(fcModelNode);
} catch (ServiceError e) {
logger.debug("Error reading sampling group: service error calling getDataValues on {}: {}", samplingGroup, e);
for (ChannelRecordContainer container : containers) {
container.setRecord(new Record(Flag.DRIVER_ERROR_SAMPLING_GROUP_NOT_ACCESSIBLE));
}
return fcModelNode;
} catch (IOException e) {
throw new ConnectionException(e);
}
long receiveTime = System.currentTimeMillis();
for (ChannelRecordContainer container : containers) {
if (container.getChannelHandle() != null) {
setRecord(container, (BasicDataAttribute) container.getChannelHandle(), receiveTime);
} else {
container.setRecord(new Record(Flag.DRIVER_ERROR_CHANNEL_NOT_PART_OF_SAMPLING_GROUP));
}
}
return fcModelNode;
}
use of com.beanit.iec61850bean.ServiceError in project OpenMUC by isc-konstanz.
the class Iec61850Connection method write.
@Override
public Object write(List<ChannelValueContainer> containers, Object containerListHandle) throws UnsupportedOperationException, ConnectionException {
List<FcModelNode> modelNodesToBeWritten = new ArrayList<>(containers.size());
for (ChannelValueContainer container : containers) {
if (container.getChannelHandle() != null) {
modelNodesToBeWritten.add((FcModelNode) container.getChannelHandle());
setFcModelNode(container, (FcModelNode) container.getChannelHandle());
} else {
String[] args = container.getChannelAddress().split(":", 3);
if (args.length != 2) {
logger.debug("Wrong channel address syntax: {}", container.getChannelAddress());
container.setFlag(Flag.DRIVER_ERROR_CHANNEL_WITH_THIS_ADDRESS_NOT_FOUND);
continue;
}
ModelNode modelNode = serverModel.findModelNode(args[0], Fc.fromString(args[1]));
if (modelNode == null) {
logger.debug("No Basic Data Attribute for the channel address {} was found in the server model.", container.getChannelAddress());
container.setFlag(Flag.DRIVER_ERROR_CHANNEL_WITH_THIS_ADDRESS_NOT_FOUND);
continue;
}
FcModelNode fcModelNode;
try {
fcModelNode = (FcModelNode) modelNode;
} catch (ClassCastException e) {
logger.debug("ModelNode with object reference {} was found in the server model but is not a Basic Data Attribute.", container.getChannelAddress());
container.setFlag(Flag.DRIVER_ERROR_CHANNEL_WITH_THIS_ADDRESS_NOT_FOUND);
continue;
}
container.setChannelHandle(fcModelNode);
modelNodesToBeWritten.add(fcModelNode);
setFcModelNode(container, fcModelNode);
}
}
// TODO
// first check all datasets if the are some that contain only requested channels
// then check all remaining model nodes
List<FcModelNode> fcNodesToBeRequested = new ArrayList<>();
while (modelNodesToBeWritten.size() > 0) {
fillRequestedNodes(fcNodesToBeRequested, modelNodesToBeWritten, serverModel);
}
for (FcModelNode fcModelNode : fcNodesToBeRequested) {
try {
if (fcModelNode.getFc().toString().equals("CO")) {
logger.info("writing CO model node");
fcModelNode = (FcModelNode) fcModelNode.getParent().getParent();
clientAssociation.operate(fcModelNode);
} else {
clientAssociation.setDataValues(fcModelNode);
}
} catch (ServiceError e) {
logger.error("Error writing to channel: service error calling setDataValues on {}: {}", fcModelNode.getReference(), e);
for (BasicDataAttribute bda : fcModelNode.getBasicDataAttributes()) {
for (ChannelValueContainer valueContainer : containers) {
if (valueContainer.getChannelHandle() == bda) {
valueContainer.setFlag(Flag.DRIVER_ERROR_CHANNEL_NOT_ACCESSIBLE);
}
}
}
return null;
} catch (IOException e) {
throw new ConnectionException(e);
}
for (BasicDataAttribute bda : fcModelNode.getBasicDataAttributes()) {
for (ChannelValueContainer valueContainer : containers) {
if (valueContainer.getChannelHandle() == bda) {
valueContainer.setFlag(Flag.VALID);
}
}
}
}
return null;
}
use of com.beanit.iec61850bean.ServiceError in project OpenMUC by isc-konstanz.
the class Iec61850Driver method connect.
@Override
public Connection connect(String deviceAddress, String settings) throws ArgumentSyntaxException, ConnectionException {
DeviceAddress deviceAdress = new DeviceAddress(deviceAddress);
DeviceSettings deviceSettings = new DeviceSettings(settings);
ClientSap clientSap = new ClientSap();
clientSap.setTSelLocal(deviceSettings.getTSelLocal());
clientSap.setTSelLocal(deviceSettings.getTSelRemote());
ClientAssociation clientAssociation;
try {
clientAssociation = clientSap.associate(deviceAdress.getAdress(), deviceAdress.getRemotePort(), deviceSettings.getAuthentication(), null);
} catch (IOException e) {
throw new ConnectionException(e);
}
ServerModel serverModel;
try {
serverModel = clientAssociation.retrieveModel();
} catch (ServiceError e) {
clientAssociation.close();
throw new ConnectionException("Service error retrieving server model" + e.getMessage(), e);
} catch (IOException e) {
clientAssociation.close();
throw new ConnectionException("IOException retrieving server model: " + e.getMessage(), e);
}
return new Iec61850Connection(clientAssociation, serverModel);
}
Aggregations