Search in sources :

Example 6 with ClientAssociation

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

the class Iec61850RtuDeviceService method getData.

@Override
public void getData(final GetDataDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
    try {
        final String serverName = this.getServerName(deviceRequest);
        final ServerModel serverModel = this.connectAndRetrieveServerModel(deviceRequest, serverName);
        final ClientAssociation clientAssociation = this.iec61850DeviceConnectionService.getClientAssociation(deviceRequest.getDeviceIdentification());
        final GetDataResponseDto getDataResponse = this.handleGetData(new DeviceConnection(new Iec61850Connection(new Iec61850ClientAssociation(clientAssociation, null), serverModel), deviceRequest.getDeviceIdentification(), deviceRequest.getOrganisationIdentification(), serverName), deviceRequest);
        final GetDataDeviceResponse deviceResponse = new GetDataDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), DeviceMessageStatus.OK, getDataResponse);
        deviceResponseHandler.handleResponse(deviceResponse);
    } catch (final ConnectionFailureException se) {
        LOGGER.error("Could not connect to device after all retries", se);
        final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), DeviceMessageStatus.FAILURE);
        deviceResponseHandler.handleConnectionFailure(se, deviceResponse);
    } catch (final Exception e) {
        LOGGER.error("Unexpected exception during Get Data", e);
        final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), DeviceMessageStatus.FAILURE);
        deviceResponseHandler.handleException(e, deviceResponse);
    }
}
Also used : GetDataDeviceResponse(com.alliander.osgp.adapter.protocol.iec61850.device.ssld.responses.GetDataDeviceResponse) ServerModel(org.openmuc.openiec61850.ServerModel) Iec61850Connection(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850Connection) Iec61850ClientAssociation(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) GetDataResponseDto(com.alliander.osgp.dto.valueobjects.microgrids.GetDataResponseDto) ConnectionFailureException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) Iec61850ClientAssociation(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) ClientAssociation(org.openmuc.openiec61850.ClientAssociation) ConnectionFailureException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException) JMSException(javax.jms.JMSException) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) EmptyDeviceResponse(com.alliander.osgp.adapter.protocol.iec61850.device.ssld.responses.EmptyDeviceResponse)

Example 7 with ClientAssociation

use of com.beanit.openiec61850.ClientAssociation in project open-smart-grid-platform by OSGP.

the class Iec61850Client method readAllDataValues.

/**
 * Read the values of all data attributes of all data objects of all Logical Nodes.
 *
 * @param clientAssociation An {@link ClientAssociation} instance.
 * @throws NodeReadException In case the read action fails.
 */
public void readAllDataValues(final ClientAssociation clientAssociation) throws NodeReadException {
    try {
        LOGGER.debug("Start getAllDataValues from device");
        clientAssociation.getAllDataValues();
        LOGGER.debug("Completed getAllDataValues from device");
    } catch (final ServiceError e) {
        LOGGER.error("ServiceError during readAllDataValues", e);
        throw new NodeReadException(e.getMessage(), e, ConnectionState.OK);
    } catch (final IOException e) {
        LOGGER.error("IOException during readAllDataValues", e);
        throw new NodeReadException(e.getMessage(), e, ConnectionState.BROKEN);
    }
}
Also used : ServiceError(com.beanit.openiec61850.ServiceError) NodeReadException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException) IOException(java.io.IOException)

Example 8 with ClientAssociation

use of com.beanit.openiec61850.ClientAssociation in project open-smart-grid-platform by OSGP.

the class Iec61850Client method connect.

/**
 * Connect to a given device. This will try to establish the {@link ClientAssociation} between
 * client and IED.
 *
 * @param deviceIdentification The device identification.
 * @param ipAddress The IP address of the device.
 * @param reportListener The report listener instance which can be created using {@link
 *     Iec61850ClientEventListenerFactory}.
 * @param port The port number of the IED.
 * @return An {@link Iec61850ClientAssociation} instance.
 * @throws ConnectionFailureException In case the connection to the device could not be
 *     established.
 */
public Iec61850ClientAssociation connect(final String deviceIdentification, final InetAddress ipAddress, final Iec61850ClientBaseEventListener reportListener, final int port) throws ConnectionFailureException {
    // Alternatively you could use ClientSap(SocketFactory factory) to e.g.
    // connect using SSL.
    final ClientSap clientSap = new ClientSap();
    final Iec61850ClientAssociation clientAssociation;
    LOGGER.info("Attempting to connect to server: {} on port: {}, max redelivery count: {} and max retry count: {}", ipAddress.getHostAddress(), port, this.maxRedeliveriesForIec61850Requests, this.maxRetryCount);
    try {
        clientSap.setResponseTimeout(this.connectionTimeout);
        final ClientAssociation association = clientSap.associate(ipAddress, port, null, reportListener);
        clientAssociation = new Iec61850ClientAssociation(association, reportListener);
    } catch (final IOException e) {
        // An IOException will always indicate a fatal exception. It
        // indicates that the association was closed and
        // cannot be recovered. You will need to create a new association
        // using ClientSap.associate() in order to
        // reconnect.
        LOGGER.error("Error connecting to device: {}", deviceIdentification, e);
        throw new ConnectionFailureException(e.getMessage(), e);
    }
    LOGGER.info("Connected to device: {}", deviceIdentification);
    return clientAssociation;
}
Also used : ClientSap(com.beanit.openiec61850.ClientSap) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) ClientAssociation(com.beanit.openiec61850.ClientAssociation) IOException(java.io.IOException)

Example 9 with ClientAssociation

use of com.beanit.openiec61850.ClientAssociation in project open-smart-grid-platform by OSGP.

the class Iec61850RtuDeviceService method setData.

@Override
public void setData(final SetDataDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
    try {
        final String serverName = this.getServerName(deviceRequest);
        final ServerModel serverModel = this.connectAndRetrieveServerModel(deviceRequest, serverName);
        final ClientAssociation clientAssociation = this.iec61850DeviceConnectionService.getClientAssociation(deviceRequest.getDeviceIdentification());
        this.handleSetData(new DeviceConnection(new Iec61850Connection(new Iec61850ClientAssociation(clientAssociation, null), serverModel), deviceRequest.getDeviceIdentification(), deviceRequest.getOrganisationIdentification(), serverName), deviceRequest);
        final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest, DeviceMessageStatus.OK);
        deviceResponseHandler.handleResponse(deviceResponse);
    } catch (final ConnectionFailureException se) {
        LOGGER.error("Could not connect to device after all retries", se);
        final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest, DeviceMessageStatus.FAILURE);
        deviceResponseHandler.handleConnectionFailure(se, deviceResponse);
    } catch (final Exception e) {
        LOGGER.error("Unexpected exception during Set Data", e);
        final EmptyDeviceResponse deviceResponse = new EmptyDeviceResponse(deviceRequest, DeviceMessageStatus.FAILURE);
        deviceResponseHandler.handleException(e, deviceResponse);
    }
}
Also used : ServerModel(com.beanit.openiec61850.ServerModel) Iec61850Connection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850Connection) Iec61850ClientAssociation(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) Iec61850ClientAssociation(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation) ClientAssociation(com.beanit.openiec61850.ClientAssociation) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) JMSException(javax.jms.JMSException) EmptyDeviceResponse(org.opensmartgridplatform.adapter.protocol.iec61850.device.ssld.responses.EmptyDeviceResponse)

Example 10 with ClientAssociation

use of com.beanit.openiec61850.ClientAssociation 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);
}
Also used : ServerModel(com.beanit.openiec61850.ServerModel) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)

Aggregations

ClientAssociation (com.beanit.openiec61850.ClientAssociation)8 ServerModel (com.beanit.openiec61850.ServerModel)8 ClientAssociation (org.openmuc.openiec61850.ClientAssociation)7 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)7 Iec61850ClientAssociation (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation)6 Iec61850Connection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850Connection)6 JMSException (javax.jms.JMSException)6 Iec61850ClientAssociation (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation)6 Iec61850Connection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850Connection)6 ConnectionFailureException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException)5 ConnectionFailureException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException)5 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)4 DeviceConnection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)4 IOException (java.io.IOException)4 ServerModel (org.openmuc.openiec61850.ServerModel)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 ServiceError (com.beanit.openiec61850.ServiceError)2 Serializable (java.io.Serializable)2