Search in sources :

Example 21 with ServerModel

use of com.beanit.openiec61850.ServerModel 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;
}
Also used : Iec61850Connection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850Connection) Iec61850Device(org.opensmartgridplatform.adapter.protocol.iec61850.domain.entities.Iec61850Device) IED(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.IED) Iec61850ClientAssociation(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) ClientAssociation(com.beanit.openiec61850.ClientAssociation) DateTime(org.joda.time.DateTime) Iec61850ClientAssociation(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) ServerModel(com.beanit.openiec61850.ServerModel) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) Iec61850ClientBaseEventListener(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener) InetAddress(java.net.InetAddress)

Example 22 with ServerModel

use of com.beanit.openiec61850.ServerModel in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850DeviceConnectionService method getModelNode.

private FcModelNode getModelNode(final String logicalDevice, final Iec61850Connection iec61850Connection, final String description) throws ProtocolAdapterException {
    final ServerModel serverModel = iec61850Connection.getServerModel();
    if (serverModel == null) {
        final String msg = String.format("ServerModel is null for logicalDevice {%s}", logicalDevice);
        throw new ProtocolAdapterException(msg);
    }
    final String objRef = description + logicalDevice + "/" + LogicalNode.LOGICAL_NODE_ZERO.getDescription() + "." + DataAttribute.NAME_PLATE.getDescription();
    final FcModelNode modelNode = (FcModelNode) serverModel.findModelNode(objRef, Fc.DC);
    if (modelNode == null) {
        final String msg = String.format("ModelNode is null for {%s}", objRef);
        throw new ProtocolAdapterException(msg);
    }
    return modelNode;
}
Also used : ServerModel(org.openmuc.openiec61850.ServerModel) FcModelNode(org.openmuc.openiec61850.FcModelNode) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)

Example 23 with ServerModel

use of com.beanit.openiec61850.ServerModel in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850RtuDeviceReportingService method enableHeatPumpReportingOnDevice.

private void enableHeatPumpReportingOnDevice(final DeviceConnection connection, final String deviceIdentification) {
    final ServerModel serverModel = connection.getConnection().getServerModel();
    final String heatPumpPrefix = LogicalDevice.HEAT_PUMP.getDescription();
    int i = 1;
    String logicalDeviceName = heatPumpPrefix + i;
    ModelNode heatPumpNode = serverModel.getChild(this.serverName + logicalDeviceName);
    while (heatPumpNode != null) {
        this.enableStatusReportingOnDevice(connection, deviceIdentification, LogicalDevice.HEAT_PUMP, i, DataAttribute.REPORT_STATUS_ONE);
        this.enableMeasurementReportingOnDevice(connection, deviceIdentification, LogicalDevice.HEAT_PUMP, i, DataAttribute.REPORT_MEASUREMENTS_ONE);
        i += 1;
        logicalDeviceName = heatPumpPrefix + i;
        heatPumpNode = serverModel.getChild(this.serverName + logicalDeviceName);
    }
}
Also used : ServerModel(org.openmuc.openiec61850.ServerModel) ModelNode(org.openmuc.openiec61850.ModelNode)

Example 24 with ServerModel

use of com.beanit.openiec61850.ServerModel in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850RtuDeviceReportingService method enableLoadReportingOnDevice.

private void enableLoadReportingOnDevice(final DeviceConnection connection, final String deviceIdentification) {
    final ServerModel serverModel = connection.getConnection().getServerModel();
    final String loadPrefix = LogicalDevice.LOAD.getDescription();
    int i = 1;
    String logicalDeviceName = loadPrefix + i;
    ModelNode loadNode = serverModel.getChild(this.serverName + logicalDeviceName);
    while (loadNode != null) {
        this.enableStatusReportingOnDevice(connection, deviceIdentification, LogicalDevice.LOAD, i, DataAttribute.REPORT_STATUS_ONE);
        this.enableMeasurementReportingOnDevice(connection, deviceIdentification, LogicalDevice.LOAD, i, DataAttribute.REPORT_MEASUREMENTS_ONE);
        i += 1;
        logicalDeviceName = loadPrefix + i;
        loadNode = serverModel.getChild(this.serverName + logicalDeviceName);
    }
}
Also used : ServerModel(org.openmuc.openiec61850.ServerModel) ModelNode(org.openmuc.openiec61850.ModelNode)

Example 25 with ServerModel

use of com.beanit.openiec61850.ServerModel in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850RtuDeviceReportingService method enableBoilerReportingOnDevice.

private void enableBoilerReportingOnDevice(final DeviceConnection connection, final String deviceIdentification) {
    final ServerModel serverModel = connection.getConnection().getServerModel();
    final String boilerPrefix = LogicalDevice.BOILER.getDescription();
    int i = 1;
    String logicalDeviceName = boilerPrefix + i;
    ModelNode boilerNode = serverModel.getChild(this.serverName + logicalDeviceName);
    while (boilerNode != null) {
        this.enableStatusReportingOnDevice(connection, deviceIdentification, LogicalDevice.BOILER, i, DataAttribute.REPORT_STATUS_ONE);
        this.enableMeasurementReportingOnDevice(connection, deviceIdentification, LogicalDevice.BOILER, i, DataAttribute.REPORT_MEASUREMENTS_ONE);
        i += 1;
        logicalDeviceName = boilerPrefix + i;
        boilerNode = serverModel.getChild(this.serverName + logicalDeviceName);
    }
}
Also used : ServerModel(org.openmuc.openiec61850.ServerModel) ModelNode(org.openmuc.openiec61850.ModelNode)

Aggregations

ServerModel (org.openmuc.openiec61850.ServerModel)17 ModelNode (com.beanit.openiec61850.ModelNode)16 ServerModel (com.beanit.openiec61850.ServerModel)12 ModelNode (org.openmuc.openiec61850.ModelNode)10 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)8 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)7 JMSException (javax.jms.JMSException)6 ClientAssociation (com.beanit.openiec61850.ClientAssociation)5 ConnectionFailureException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException)4 Iec61850ClientAssociation (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation)4 Iec61850Connection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850Connection)4 DeviceConnection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)4 ClientAssociation (org.openmuc.openiec61850.ClientAssociation)4 ConnectionFailureException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException)4 Iec61850ClientAssociation (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation)4 Iec61850Connection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850Connection)4 DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)4 EmptyDeviceResponse (com.alliander.osgp.adapter.protocol.iec61850.device.ssld.responses.EmptyDeviceResponse)3 EmptyDeviceResponse (org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.responses.EmptyDeviceResponse)3 BasicDataAttribute (com.beanit.openiec61850.BasicDataAttribute)2