Search in sources :

Example 1 with ConnectionEventListener

use of org.openmuc.j60870.ConnectionEventListener in project open-smart-grid-platform by OSGP.

the class ControlledStationSteps method sendInterrogationResponse.

private Object sendInterrogationResponse(final int commonAddress, final IeQualifierOfInterrogation qualifier, final ProcessImage processImage) {
    final ConnectionEventListener listener = this.connectionSteps.getConnectionEventListener();
    listener.newASdu(this.interrogationActivationConfirmationAsdu(commonAddress, qualifier));
    for (final ASdu asdu : processImage.toInterrogationAsdus(commonAddress, qualifier)) {
        listener.newASdu(asdu);
    }
    listener.newASdu(this.interrogationActivationTerminationAsdu(commonAddress, qualifier));
    return null;
}
Also used : ASdu(org.openmuc.j60870.ASdu) ConnectionEventListener(org.openmuc.j60870.ConnectionEventListener)

Example 2 with ConnectionEventListener

use of org.openmuc.j60870.ConnectionEventListener in project open-smart-grid-platform by OSGP.

the class Iec60870Client method connect.

@Override
public ClientConnection connect(final ConnectionParameters connectionParameters, final ConnectionEventListener asduListener) throws ConnectionFailureException {
    final InetAddress address = this.convertIpAddress(connectionParameters.getIpAddress());
    final String deviceIdentification = connectionParameters.getDeviceIdentification();
    final int port = connectionParameters.getPort() == null ? IEC60870_DEFAULT_PORT : connectionParameters.getPort();
    final ClientConnectionBuilder clientConnectionBuilder = new ClientConnectionBuilder(address).setPort(port).setConnectionTimeout(this.connectionTimeout);
    try {
        LOGGER.info("Connecting to device: {}...", deviceIdentification);
        final Connection connection = clientConnectionBuilder.build();
        connection.startDataTransfer(asduListener);
        LOGGER.info("Connected to device: {}", deviceIdentification);
        return new DeviceConnection(connection, connectionParameters);
    } catch (final IOException e) {
        final String errorMessage = "Unable to connect to remote host: " + connectionParameters.getIpAddress();
        LOGGER.error(errorMessage, e);
        throw new ConnectionFailureException(ComponentType.PROTOCOL_IEC60870, errorMessage);
    }
}
Also used : ClientConnectionBuilder(org.openmuc.j60870.ClientConnectionBuilder) ConnectionFailureException(org.opensmartgridplatform.shared.exceptionhandling.ConnectionFailureException) ClientConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnection) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) Connection(org.openmuc.j60870.Connection) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) IOException(java.io.IOException) InetAddress(java.net.InetAddress)

Aggregations

IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 ASdu (org.openmuc.j60870.ASdu)1 ClientConnectionBuilder (org.openmuc.j60870.ClientConnectionBuilder)1 Connection (org.openmuc.j60870.Connection)1 ConnectionEventListener (org.openmuc.j60870.ConnectionEventListener)1 ClientConnection (org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnection)1 DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection)1 ConnectionFailureException (org.opensmartgridplatform.shared.exceptionhandling.ConnectionFailureException)1