Search in sources :

Example 1 with NodeReadException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException in project Protocol-Adapter-IEC61850 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(org.openmuc.openiec61850.ServiceError) NodeReadException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeReadException) IOException(java.io.IOException)

Example 2 with NodeReadException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850Client method sendCommandWithRetry.

/**
     * Executes the apply method of the given {@link Function} with retries and
     * message logging.
     *
     * @return The given T.
     */
public <T> T sendCommandWithRetry(final Function<T> function, final String functionName, final String deviceIdentification) throws ProtocolAdapterException {
    T output = null;
    final DeviceMessageLog deviceMessageLog = new DeviceMessageLog(IED.FLEX_OVL, LogicalDevice.LIGHTING, functionName);
    try {
        output = function.apply(deviceMessageLog);
    } catch (final NodeWriteException | NodeReadException e) {
        if (ConnectionState.OK.equals(e.getConnectionState())) {
            // ServiceError means we have to retry.
            LOGGER.error("Caught ServiceError, retrying", e);
            this.sendCommandWithRetry(function, deviceIdentification, 1, deviceMessageLog);
        } else {
            LOGGER.error("Caught IOException, connection with device is broken.", e);
        }
    } catch (final ConnectionFailureException e) {
        throw e;
    } catch (final Exception e) {
        throw new ProtocolAdapterException(e == null ? "Could not execute command" : e.getMessage(), e);
    }
    return output;
}
Also used : DeviceMessageLog(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) NodeWriteException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeWriteException) ConnectionFailureException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException) NodeReadException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeReadException) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) SclParseException(org.openmuc.openiec61850.SclParseException) NodeWriteException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeWriteException) NodeReadException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeReadException) ConnectionFailureException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException) IOException(java.io.IOException) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)

Example 3 with NodeReadException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850DeviceConnectionService method testIfConnectionIsCachedAndAlive.

private boolean testIfConnectionIsCachedAndAlive(final String deviceIdentification, final IED ied, final String serverName, final String logicalDevice) throws ProtocolAdapterException {
    try {
        LOGGER.info("Trying to find connection in cache for deviceIdentification: {}", deviceIdentification);
        final Iec61850Connection iec61850Connection = this.fetchIec61850Connection(deviceIdentification);
        if (iec61850Connection != null) {
            // Already connected, check if connection is still usable.
            LOGGER.info("Connection found for deviceIdentification: {}", deviceIdentification);
            // requires manual reads of remote data.
            if (ied != null && logicalDevice != null) {
                final String description = this.getActualServerName(ied, serverName);
                LOGGER.info("Testing if connection is alive using {}{}/{}.{} for deviceIdentification: {}", description, logicalDevice, LogicalNode.LOGICAL_NODE_ZERO.getDescription(), DataAttribute.NAME_PLATE.getDescription(), deviceIdentification);
                final FcModelNode modelNode = this.getModelNode(logicalDevice, iec61850Connection, description);
                this.iec61850Client.readNodeDataValues(iec61850Connection.getClientAssociation(), modelNode);
            } else {
                // Read all data values, which is much slower, but requires
                // no manual reads of remote data.
                LOGGER.info("Testing if connection is alive using readAllDataValues() for deviceIdentification: {}", deviceIdentification);
                this.iec61850Client.readAllDataValues(iec61850Connection.getClientAssociation());
            }
            LOGGER.info("Connection is still active for deviceIdentification: {}", deviceIdentification);
            return true;
        }
    } catch (final NodeReadException e) {
        LOGGER.error("Connection is no longer active, removing connection from cache for deviceIdentification: " + deviceIdentification, e);
        this.removeIec61850Connection(deviceIdentification);
    }
    return false;
}
Also used : Iec61850Connection(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850Connection) NodeReadException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeReadException) FcModelNode(org.openmuc.openiec61850.FcModelNode)

Example 4 with NodeReadException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException 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 5 with NodeReadException

use of org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException in project open-smart-grid-platform by OSGP.

the class Iec61850SetConfigurationFunction method setClockConfiguration.

private void setClockConfiguration(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final ConfigurationDto configuration, final DeviceMessageLog deviceMessageLog) throws NodeNotFoundException, NodeReadException, NodeWriteException {
    final NodeContainer clock = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF);
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), clock.getFcmodelNode());
    if (configuration.getTimeSyncFrequency() != null) {
        LOGGER.info("Updating TimeSyncFrequency to {}", configuration.getTimeSyncFrequency());
        clock.writeUnsignedShort(SubDataAttribute.TIME_SYNC_FREQUENCY, configuration.getTimeSyncFrequency());
        deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.TIME_SYNC_FREQUENCY, Integer.toString(configuration.getTimeSyncFrequency()));
    }
    if (configuration.isAutomaticSummerTimingEnabled() != null) {
        LOGGER.info("Updating AutomaticSummerTimingEnabled to {}", configuration.isAutomaticSummerTimingEnabled());
        clock.writeBoolean(SubDataAttribute.AUTOMATIC_SUMMER_TIMING_ENABLED, configuration.isAutomaticSummerTimingEnabled());
        deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.AUTOMATIC_SUMMER_TIMING_ENABLED, Boolean.toString(configuration.isAutomaticSummerTimingEnabled()));
    }
    /*
     * Perform some effort to create dstBegT/dstEndt information
     * based on provided DateTime values. This will work in a
     * number of cases, but to be able to do this accurately in
     * an international context, DST transition times will
     * probably have to be based on information about the
     * time-zone the device is operating in, instead of a
     * particular DateTime provided by the caller without
     * further information.
     */
    final DaylightSavingTimeTransition.DstTransitionFormat dstFormatMwd = DaylightSavingTimeTransition.DstTransitionFormat.DAY_OF_WEEK_OF_MONTH;
    final DateTime summerTimeDetails = configuration.getSummerTimeDetails();
    final DateTime winterTimeDetails = configuration.getWinterTimeDetails();
    if (summerTimeDetails != null) {
        final String mwdValueForBeginOfDst = DaylightSavingTimeTransition.forDateTimeAccordingToFormat(summerTimeDetails, dstFormatMwd).getTransition();
        LOGGER.info("Updating DstBeginTime to {} based on SummerTimeDetails {}", mwdValueForBeginOfDst, summerTimeDetails);
        clock.writeString(SubDataAttribute.SUMMER_TIME_DETAILS, mwdValueForBeginOfDst);
        deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.SUMMER_TIME_DETAILS, mwdValueForBeginOfDst);
    }
    if (winterTimeDetails != null) {
        final String mwdValueForEndOfDst = DaylightSavingTimeTransition.forDateTimeAccordingToFormat(winterTimeDetails, dstFormatMwd).getTransition();
        LOGGER.info("Updating DstEndTime to {} based on WinterTimeDetails {}", mwdValueForEndOfDst, winterTimeDetails);
        clock.writeString(SubDataAttribute.WINTER_TIME_DETAILS, mwdValueForEndOfDst);
        deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.WINTER_TIME_DETAILS, mwdValueForEndOfDst);
    }
    if (configuration.getNtpEnabled() != null) {
        LOGGER.info("Updating ntpEnabled to {}", configuration.getNtpEnabled());
        clock.writeBoolean(SubDataAttribute.NTP_ENABLED, configuration.getNtpEnabled());
        deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.NTP_ENABLED, Boolean.toString(configuration.getNtpEnabled()));
    }
    if (configuration.getNtpHost() != null) {
        LOGGER.info("Updating ntpHost to {}", configuration.getNtpHost());
        clock.writeString(SubDataAttribute.NTP_HOST, configuration.getNtpHost());
        deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.NTP_HOST, configuration.getNtpHost());
    }
    if (configuration.getNtpSyncInterval() != null) {
        LOGGER.info("Updating ntpSyncInterval to {}", configuration.getNtpSyncInterval());
        clock.writeUnsignedShort(SubDataAttribute.NTP_SYNC_INTERVAL, configuration.getNtpSyncInterval());
        deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.NTP_SYNC_INTERVAL, configuration.getNtpSyncInterval().toString());
    }
}
Also used : DaylightSavingTimeTransition(org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DaylightSavingTimeTransition) DateTime(org.joda.time.DateTime)

Aggregations

IOException (java.io.IOException)4 NodeReadException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException)4 NodeReadException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeReadException)3 Iec61850Connection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850Connection)3 ClientAssociation (com.beanit.openiec61850.ClientAssociation)2 NodeWriteException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeWriteException)2 Iec61850ClientAssociation (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation)2 DeviceMessageLog (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)1 ConnectionFailureException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException)1 NodeWriteException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeWriteException)1 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 Iec61850Connection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850Connection)1 FcModelNode (com.beanit.openiec61850.FcModelNode)1 SclParseException (com.beanit.openiec61850.SclParseException)1 ServiceError (com.beanit.openiec61850.ServiceError)1 DateTime (org.joda.time.DateTime)1 FcModelNode (org.openmuc.openiec61850.FcModelNode)1 SclParseException (org.openmuc.openiec61850.SclParseException)1 ServiceError (org.openmuc.openiec61850.ServiceError)1 Iec61850ReportEntry (org.opensmartgridplatform.adapter.protocol.iec61850.domain.entities.Iec61850ReportEntry)1