use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.IED in project open-smart-grid-platform by OSGP.
the class Iec61850DeviceConnectionService method testIfConnectionIsCachedAndAlive.
private boolean testIfConnectionIsCachedAndAlive(final String deviceIdentification, final IED ied, final String serverName, final String logicalDevice) throws ProtocolAdapterException {
try {
LOGGER.info("Trying to find connection in cache for deviceIdentification: {}", deviceIdentification);
final Iec61850Connection iec61850Connection = this.fetchIec61850Connection(deviceIdentification);
if (iec61850Connection != null) {
// Already connected, check if connection is still usable.
LOGGER.info("Connection found for deviceIdentification: {}", deviceIdentification);
// requires manual reads of remote data.
if (ied != null && logicalDevice != null) {
final String description = this.getActualServerName(ied, serverName);
LOGGER.info("Testing if connection is alive using {}{}/{}.{} for deviceIdentification: {}", description, logicalDevice, LogicalNode.LOGICAL_NODE_ZERO.getDescription(), DataAttribute.NAME_PLATE.getDescription(), deviceIdentification);
final FcModelNode modelNode = this.getModelNode(logicalDevice, iec61850Connection, description);
this.iec61850Client.readNodeDataValues(iec61850Connection.getClientAssociation(), modelNode);
} else {
// Read all data values, which is much slower, but requires
// no manual reads of remote data.
LOGGER.info("Testing if connection is alive using readAllDataValues() for deviceIdentification: {}", deviceIdentification);
this.iec61850Client.readAllDataValues(iec61850Connection.getClientAssociation());
}
LOGGER.info("Connection is still active for deviceIdentification: {}", deviceIdentification);
return true;
}
} catch (final NodeReadException e) {
LOGGER.error("Connection is no longer active, removing connection from cache for deviceIdentification: " + deviceIdentification, e);
this.disconnect(deviceIdentification);
}
return false;
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.IED in project open-smart-grid-platform by OSGP.
the class Iec61850RtuDeviceService method connectAndRetrieveServerModel.
// ======================================
// PRIVATE DEVICE COMMUNICATION METHODS =
// ======================================
private ServerModel connectAndRetrieveServerModel(final DeviceRequest deviceRequest, final String serverName) throws ProtocolAdapterException {
final DeviceConnectionParameters deviceConnectionParameters = DeviceConnectionParameters.newBuilder().ipAddress(deviceRequest.getIpAddress()).deviceIdentification(deviceRequest.getDeviceIdentification()).ied(IED.ZOWN_RTU).serverName(serverName).logicalDevice(LogicalDevice.RTU.getDescription() + 1).build();
this.iec61850DeviceConnectionService.connect(deviceConnectionParameters, deviceRequest.getOrganisationIdentification());
return this.iec61850DeviceConnectionService.getServerModel(deviceRequest.getDeviceIdentification());
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.IED in project open-smart-grid-platform by OSGP.
the class Iec61850ChannelHandlerServer method processRegistrationMessage.
private void processRegistrationMessage(final RegisterDeviceRequest message, final String correlationId) {
this.logMessage(message);
final String deviceIdentification = message.getDeviceIdentification();
if (this.deviceRegistrationService.isKnownDevice(deviceIdentification)) {
LOGGER.info("Device {} found, start processing this registration message", deviceIdentification);
} else {
LOGGER.warn("Ignoring this registration message, because there's no device having identification {}", deviceIdentification);
return;
}
final IED ied = IED.FLEX_OVL;
final String ipAddress;
// set, the values will be used to set an IP address for a device.
if (this.testDeviceIps != null && this.testDeviceIps.containsKey(deviceIdentification)) {
final String testDeviceIp = this.testDeviceIps.get(deviceIdentification);
LOGGER.info("Using testDeviceId: {} and testDeviceIp: {}", deviceIdentification, testDeviceIp);
ipAddress = testDeviceIp;
} else {
ipAddress = message.getIpAddress();
}
final DeviceRegistrationDataDto deviceRegistrationData = new DeviceRegistrationDataDto(ipAddress, Ssld.SSLD_TYPE, true);
final RequestMessage requestMessage = new RequestMessage(correlationId, NO_ORGANISATION, deviceIdentification, ipAddress, null, null, deviceRegistrationData);
LOGGER.info("Sending register device request to OSGP with correlation ID: {}", correlationId);
this.osgpRequestMessageSender.send(requestMessage, MessageType.REGISTER_DEVICE.name());
try {
this.deviceRegistrationService.disableRegistration(deviceIdentification, InetAddress.getByName(ipAddress), ied, ied.getDescription());
final RequestMessage cdrRequestMessage = new RequestMessage(correlationId, NO_ORGANISATION, deviceIdentification, ipAddress);
this.osgpRequestMessageSender.send(cdrRequestMessage, MessageType.DEVICE_REGISTRATION_COMPLETED.name());
LOGGER.info("Disabled registration for device: {}, at IP address: {}", deviceIdentification, ipAddress);
} catch (final Exception e) {
LOGGER.error("Failed to disable registration for device: {}, at IP address: {}", deviceIdentification, ipAddress, e);
}
}
Aggregations