use of org.opensmartgridplatform.adapter.protocol.iec61850.domain.entities.Iec61850Device in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850DeviceConnectionService method connect.
public synchronized DeviceConnection connect(final String ipAddress, final String deviceIdentification, final String organisationIdentification, final IED ied, final String serverName, final String logicalDevice, final boolean cacheConnection) throws ConnectionFailureException {
// an usable for the given deviceIdentification.
try {
if (cacheConnection && this.testIfConnectionIsCachedAndAlive(deviceIdentification, ied, serverName, logicalDevice)) {
return new DeviceConnection(this.fetchIec61850Connection(deviceIdentification), deviceIdentification, organisationIdentification, serverName);
}
} catch (final ProtocolAdapterException e) {
this.logProtocolAdapterException(deviceIdentification, e);
}
if (StringUtils.isEmpty(ipAddress)) {
throw new ConnectionFailureException("Ip address is null");
}
final InetAddress inetAddress = this.convertIpAddress(ipAddress);
// Connect to obtain ClientAssociation and ServerModel.
LOGGER.info("Trying to connect to deviceIdentification: {} at IP address {} using response time-out: {}", deviceIdentification, ipAddress, this.responseTimeout);
final DateTime startTime = DateTime.now();
// Create instance of appropriate event listener.
Iec61850ClientBaseEventListener eventListener = null;
try {
eventListener = Iec61850ClientEventListenerFactory.getInstance().getEventListener(ied, deviceIdentification, this.deviceManagementService);
} catch (final ProtocolAdapterException e) {
this.logProtocolAdapterException(deviceIdentification, e);
}
final Iec61850Device iec61850Device = this.iec61850DeviceRepository.findByDeviceIdentification(deviceIdentification);
final int port = this.determinePortForIec61850Device(ied, iec61850Device);
// Try to connect and receive the ClientAssociation.
final Iec61850ClientAssociation iec61850ClientAssociation = this.iec61850Client.connect(deviceIdentification, inetAddress, eventListener, port);
final ClientAssociation clientAssociation = iec61850ClientAssociation.getClientAssociation();
// Set response time-out.
clientAssociation.setResponseTimeout(this.responseTimeout);
// Read the ServerModel, either from the device or from a SCL file.
ServerModel serverModel;
try {
serverModel = this.readServerModel(clientAssociation, deviceIdentification, iec61850Device);
} catch (final ProtocolAdapterException e) {
LOGGER.error("ProtocolAdapterException: unable to read ServerModel for deviceIdentification " + deviceIdentification, e);
throw new ConnectionFailureException(e.getMessage(), e);
}
// Cache the connection.
final Iec61850Connection iec61850Connection = new Iec61850Connection(iec61850ClientAssociation, serverModel, startTime);
if (cacheConnection) {
this.cacheIec61850Connection(deviceIdentification, iec61850Connection);
}
final DateTime endTime = DateTime.now();
LOGGER.info("Connected to device: {}, fetched server model. Start time: {}, end time: {}, total time in milliseconds: {}", deviceIdentification, startTime, endTime, endTime.minus(startTime.getMillis()).getMillis());
return new DeviceConnection(iec61850Connection, deviceIdentification, organisationIdentification, serverName);
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.domain.entities.Iec61850Device in project open-smart-grid-platform by OSGP.
the class Iec61850DeviceConnectionService method readServerModel.
private ServerModel readServerModel(final ClientAssociation clientAssociation, final String deviceIdentification, final Iec61850Device iec61850Device) throws ProtocolAdapterException {
ServerModel serverModel;
try {
serverModel = this.readServerModelConfiguredForDevice(clientAssociation, deviceIdentification, iec61850Device);
if (serverModel != null) {
return serverModel;
}
} catch (final ProtocolAdapterException e) {
LOGGER.warn("Ignore exception reading server model based on per device configuration for device: {}.", deviceIdentification, e);
}
try {
serverModel = this.readServerModelFromConfiguredIcdFile(clientAssociation);
if (serverModel != null) {
return serverModel;
}
} catch (final ProtocolAdapterException e) {
LOGGER.warn("Ignore exception reading server model based on configured ICD file.", e);
}
LOGGER.info("Reading ServerModel from device: {} using readServerModelFromDevice()", deviceIdentification);
return this.iec61850Client.readServerModelFromDevice(clientAssociation);
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.domain.entities.Iec61850Device in project open-smart-grid-platform by OSGP.
the class Iec61850DeviceConnectionService method connect.
public DeviceConnection connect(final DeviceConnectionParameters deviceConnectionParameters, final String organisationIdentification, final boolean cacheConnection) throws ConnectionFailureException {
final String deviceIdentification = deviceConnectionParameters.getDeviceIdentification();
final String serverName = deviceConnectionParameters.getServerName();
final IED ied = deviceConnectionParameters.getIed();
// an usable for the given deviceIdentification.
try {
if (cacheConnection && this.testIfConnectionIsCachedAndAlive(deviceIdentification, ied, serverName, deviceConnectionParameters.getLogicalDevice())) {
return new DeviceConnection(this.fetchIec61850Connection(deviceIdentification), deviceIdentification, organisationIdentification, serverName);
}
} catch (final ProtocolAdapterException e) {
this.logProtocolAdapterException(deviceIdentification, e);
}
final InetAddress inetAddress = this.convertIpAddress(deviceConnectionParameters.getIpAddress());
// Connect to obtain ClientAssociation and ServerModel.
LOGGER.info("Trying to connect to deviceIdentification: {} at IP address {} using response time-out: {}", deviceIdentification, deviceConnectionParameters.getIpAddress(), this.responseTimeout);
final DateTime startTime = DateTime.now();
// Create instance of appropriate event listener.
Iec61850ClientBaseEventListener eventListener = null;
try {
eventListener = this.iec61850ClientEventListenerFactory.getEventListener(ied, deviceIdentification, organisationIdentification);
} catch (final ProtocolAdapterException e) {
this.logProtocolAdapterException(deviceIdentification, e);
}
final Iec61850Device iec61850Device = this.iec61850DeviceRepository.findByDeviceIdentification(deviceIdentification);
final int port = this.determinePortForIec61850Device(ied, iec61850Device);
// Try to connect and receive the ClientAssociation.
final Iec61850ClientAssociation iec61850ClientAssociation = this.iec61850Client.connect(deviceIdentification, inetAddress, eventListener, port);
final ClientAssociation clientAssociation = iec61850ClientAssociation.getClientAssociation();
// Set response time-out.
clientAssociation.setResponseTimeout(this.responseTimeout);
// Read the ServerModel, either from the device or from a SCL file.
ServerModel serverModel;
try {
serverModel = this.readServerModel(clientAssociation, deviceIdentification, iec61850Device);
} catch (final ProtocolAdapterException e) {
LOGGER.error("ProtocolAdapterException: unable to read ServerModel for deviceIdentification {}", deviceIdentification, e);
throw new ConnectionFailureException(e.getMessage(), e);
}
// Cache the connection.
final Iec61850Connection iec61850Connection = new Iec61850Connection(iec61850ClientAssociation, serverModel, startTime, ied);
if (cacheConnection) {
this.cacheIec61850Connection(deviceIdentification, iec61850Connection);
}
final DeviceConnection connection = new DeviceConnection(iec61850Connection, deviceIdentification, organisationIdentification, serverName);
final DateTime endTime = DateTime.now();
LOGGER.info("Connected to device: {}, fetched server model. Start time: {}, end time: {}, total time in milliseconds: {}", deviceIdentification, startTime, endTime, endTime.minus(startTime.getMillis()).getMillis());
this.iec61850RtuDeviceReportingService.enableReportingForDevice(connection, deviceIdentification, serverName);
return connection;
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.domain.entities.Iec61850Device in project open-smart-grid-platform by OSGP.
the class Iec61850DeviceSteps method createIec61850Device.
@Transactional("txMgrIec61850")
private void createIec61850Device(final Map<String, String> settings) {
/*
* Make sure an ICD filename, port and servername corresponding to the
* mock server settings will be used from the application to connect to
* the device. ICD filename, port and servername may be null
*/
final Iec61850Device iec61850Device = new Iec61850Device(getString(settings, PlatformMicrogridsKeys.KEY_DEVICE_IDENTIFICATION, PlatformMicrogridsDefaults.DEFAULT_DEVICE_IDENTIFICATION));
iec61850Device.setIcdFilename(getString(settings, PlatformMicrogridsKeys.KEY_IEC61850_ICD_FILENAME));
iec61850Device.setPort(getInteger(settings, PlatformMicrogridsKeys.KEY_IEC61850_PORT));
iec61850Device.setServerName(getString(settings, PlatformMicrogridsKeys.KEY_IEC61850_SERVERNAME));
iec61850Device.setEnableAllReportsOnConnect(getBoolean(settings, PlatformMicrogridsKeys.ENABLE_ALL_REPORTS, PlatformMicrogridsDefaults.ENABLE_ALL_REPORTS));
iec61850Device.setUseCombinedLoad(getBoolean(settings, PlatformMicrogridsKeys.USE_COMBINED_LOAD, PlatformMicrogridsDefaults.USE_COMBINED_LOAD));
this.iec61850DeviceRepository.save(iec61850Device);
}
use of org.opensmartgridplatform.adapter.protocol.iec61850.domain.entities.Iec61850Device in project open-smart-grid-platform by OSGP.
the class Iec61850ClientRTUEventListener method useCombinedLoad.
private boolean useCombinedLoad() {
final Iec61850DeviceRepository repository = BeanUtil.getBean(Iec61850DeviceRepository.class);
final Iec61850Device device = repository.findByDeviceIdentification(this.deviceIdentification);
if (device != null) {
return device.isUseCombinedLoad();
}
return BeanUtil.getBeanByName("defaultUseCombinedLoad", Boolean.class);
}
Aggregations