Search in sources :

Example 1 with Iec61850ClientBaseEventListener

use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850EnableReportingCommand method enableReportingOnDevice.

/**
     * Enable reporting so the device can send reports.
     *
     * @throws NodeException
     *             In case writing or reading of data-attributes fails.
     */
public void enableReportingOnDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection) throws NodeException {
    final NodeContainer reporting = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.LOGICAL_NODE_ZERO, DataAttribute.REPORTING, Fc.BR);
    // Only reading the sequence number for the report node, as the report
    // node is not fully described by the ServerModel when using an ICD
    // file. Since the report node differs from the ServerModel, a full read
    // of the node and all data-attributes will fail. Therefore, only the
    // needed data-attributes are read.
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), (FcModelNode) reporting.getFcmodelNode().getChild(SubDataAttribute.SEQUENCE_NUMBER.getDescription()));
    final Iec61850ClientBaseEventListener reportListener = deviceConnection.getConnection().getIec61850ClientAssociation().getReportListener();
    final short sqNum = reporting.getUnsignedByte(SubDataAttribute.SEQUENCE_NUMBER).getValue();
    reportListener.setSqNum(sqNum);
    reporting.writeBoolean(SubDataAttribute.ENABLE_REPORTING, true);
    LOGGER.info("Allowing device {} to send reports containing events", deviceConnection.getDeviceIdentification());
}
Also used : NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) Iec61850ClientBaseEventListener(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener)

Example 2 with Iec61850ClientBaseEventListener

use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850EnableReportingCommand method enableReportingOnDeviceWithoutUsingSequenceNumber.

/**
     * Enable reporting so the device can send reports. This version of the
     * function does not use the 'sequence number' to filter incoming reports.
     * When using the {@link Iec61850ClearReportCommand} the 'sequence number'
     * will always be reset to 0.
     *
     * @throws NodeWriteException
     *             In case writing of data-attributes fails.
     */
public void enableReportingOnDeviceWithoutUsingSequenceNumber(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection) throws NodeWriteException {
    final NodeContainer reporting = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.LOGICAL_NODE_ZERO, DataAttribute.REPORTING, Fc.BR);
    final Iec61850ClientBaseEventListener reportListener = deviceConnection.getConnection().getIec61850ClientAssociation().getReportListener();
    reportListener.setSqNum(0);
    reporting.writeBoolean(SubDataAttribute.ENABLE_REPORTING, true);
    LOGGER.info("Allowing device {} to send reports containing events", deviceConnection.getDeviceIdentification());
}
Also used : NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) Iec61850ClientBaseEventListener(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener)

Example 3 with Iec61850ClientBaseEventListener

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

Example 4 with Iec61850ClientBaseEventListener

use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener 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 5 with Iec61850ClientBaseEventListener

use of org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener in project open-smart-grid-platform by OSGP.

the class Iec61850EnableReportingCommand method enableBufferedReportingOnLightMeasurementDevice.

public void enableBufferedReportingOnLightMeasurementDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection) throws NodeException {
    final NodeContainer reporting = deviceConnection.getFcModelNode(LogicalDevice.LD0, LogicalNode.LOGICAL_NODE_ZERO, DataAttribute.RCB_A, Fc.BR);
    // Read the reporting enabled boolean.
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), (FcModelNode) reporting.getFcmodelNode().getChild(SubDataAttribute.ENABLE_REPORTING.getDescription()));
    final boolean reportingEnabled = reporting.getBoolean(SubDataAttribute.ENABLE_REPORTING).getValue();
    LOGGER.info("reportingEnabled for buffered reports: {}", reportingEnabled);
    if (reportingEnabled) {
        LOGGER.info("Buffered reporting is already enabled for device: {}", deviceConnection.getDeviceIdentification());
        return;
    }
    // Only reading the sequence number for the report node, as the report
    // node is not fully described by the ServerModel when using an ICD
    // file. Since the report node differs from the ServerModel, a full read
    // of the node and all data-attributes will fail. Therefore, only the
    // needed data-attributes are read.
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), (FcModelNode) reporting.getFcmodelNode().getChild(SubDataAttribute.SEQUENCE_NUMBER.getDescription()));
    final Iec61850ClientBaseEventListener reportListener = deviceConnection.getConnection().getIec61850ClientAssociation().getReportListener();
    final short sqNum = reporting.getUnsignedByte(SubDataAttribute.SEQUENCE_NUMBER).getValue();
    reportListener.setSqNum(sqNum);
    final String dataSetReference = reporting.getString(SubDataAttribute.DATA_SET);
    LOGGER.info("dataSetReference for buffered reports: {}", dataSetReference);
    if (StringUtils.isEmpty(dataSetReference)) {
        // Data set reference should be something like:
        // "AA1TH01LD0/LLN0.StatNrmlA".
        // If not set, this will cause problems. Not possible to write to
        // this node.
        final String dataSet = this.getDataSetReferenceForLightMeasurementDevice();
        LOGGER.warn("Expected value like [{}] to be present in {}. This will most likely cause trouble when buffered reports are received in the future!", dataSet, SubDataAttribute.DATA_SET.getDescription());
    }
    // Enable reporting.
    reporting.writeBoolean(SubDataAttribute.ENABLE_REPORTING, true);
    LOGGER.info("Allowing light measurement device {} to send buffered reports containing events", deviceConnection.getDeviceIdentification());
}
Also used : NodeContainer(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) Iec61850ClientBaseEventListener(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener)

Aggregations

Iec61850ClientBaseEventListener (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener)6 NodeContainer (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)5 Iec61850ClientBaseEventListener (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.reporting.Iec61850ClientBaseEventListener)3 NodeContainer (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)2 ClientAssociation (com.beanit.openiec61850.ClientAssociation)2 InetAddress (java.net.InetAddress)2 DateTime (org.joda.time.DateTime)2 ConnectionFailureException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException)2 Iec61850Device (com.alliander.osgp.adapter.protocol.iec61850.domain.entities.Iec61850Device)1 ConnectionFailureException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException)1 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 Iec61850ClientAssociation (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation)1 Iec61850Connection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850Connection)1 DeviceConnection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)1 ClientSap (com.beanit.openiec61850.ClientSap)1 ServerModel (com.beanit.openiec61850.ServerModel)1 IOException (java.io.IOException)1 ClientAssociation (org.openmuc.openiec61850.ClientAssociation)1 ServerModel (org.openmuc.openiec61850.ServerModel)1 Iec61850Device (org.opensmartgridplatform.adapter.protocol.iec61850.domain.entities.Iec61850Device)1