Search in sources :

Example 1 with EventNotificationTypeDto

use of org.opensmartgridplatform.dto.valueobjects.EventNotificationTypeDto in project open-smart-grid-platform by OSGP.

the class Iec61850SsldDeviceService method setEventNotifications.

@Override
public void setEventNotifications(final SetEventNotificationsDeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
    final List<EventNotificationTypeDto> eventNotifications = deviceRequest.getEventNotificationsContainer().getEventNotifications();
    final String filter = EventType.getEventTypeFilterMaskForNotificationTypes(eventNotifications);
    DeviceConnection deviceConnection = null;
    try {
        deviceConnection = this.connectToDevice(deviceRequest);
        new Iec61850SetEventNotificationFilterCommand(this.deviceMessageLoggingService).setEventNotificationFilterOnDevice(this.iec61850Client, deviceConnection, filter);
        this.createSuccessfulDefaultResponse(deviceRequest, deviceResponseHandler);
    } catch (final ConnectionFailureException se) {
        this.handleConnectionFailureException(deviceRequest, deviceResponseHandler, se);
    } catch (final Exception e) {
        this.handleException(deviceRequest, deviceResponseHandler, e);
    }
    this.iec61850DeviceConnectionService.disconnect(deviceConnection, deviceRequest);
}
Also used : ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection) EventNotificationTypeDto(org.opensmartgridplatform.dto.valueobjects.EventNotificationTypeDto) Iec61850SetEventNotificationFilterCommand(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850SetEventNotificationFilterCommand) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) JMSException(javax.jms.JMSException) NodeException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException) TechnicalException(org.opensmartgridplatform.shared.exceptionhandling.TechnicalException) FunctionalException(org.opensmartgridplatform.shared.exceptionhandling.FunctionalException) ConnectionFailureException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException)

Example 2 with EventNotificationTypeDto

use of org.opensmartgridplatform.dto.valueobjects.EventNotificationTypeDto in project open-smart-grid-platform by OSGP.

the class Iec61850GetStatusCommand method getStatusFromDevice.

public DeviceStatusDto getStatusFromDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final Ssld ssld) throws ProtocolAdapterException {
    final Function<DeviceStatusDto> function = new Function<DeviceStatusDto>() {

        @Override
        public DeviceStatusDto apply(final DeviceMessageLog deviceMessageLog) throws ProtocolAdapterException {
            // getting the light relay values
            final List<LightValueDto> lightValues = new ArrayList<>();
            for (final DeviceOutputSetting deviceOutputSetting : ssld.getOutputSettings()) {
                final LogicalNode logicalNode = LogicalNode.getSwitchComponentByIndex(deviceOutputSetting.getInternalId());
                final NodeContainer position = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, logicalNode, DataAttribute.POSITION, Fc.ST);
                iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), position.getFcmodelNode());
                final BdaBoolean state = position.getBoolean(SubDataAttribute.STATE);
                final boolean on = state.getValue();
                lightValues.add(new LightValueDto(deviceOutputSetting.getExternalId(), on, null));
                LOGGER.info(String.format("Got status of relay %d => %s", deviceOutputSetting.getInternalId(), on ? "on" : "off"));
                deviceMessageLog.addVariable(logicalNode, DataAttribute.POSITION, Fc.ST, SubDataAttribute.STATE, Boolean.toString(on));
            }
            final NodeContainer eventBuffer = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.EVENT_BUFFER, Fc.CF);
            iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), eventBuffer.getFcmodelNode());
            final String filter = eventBuffer.getString(SubDataAttribute.EVENT_BUFFER_FILTER);
            LOGGER.info("Got EvnBuf.enbEvnType filter {}", filter);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.EVENT_BUFFER, Fc.CF, SubDataAttribute.EVENT_BUFFER_FILTER, filter);
            final Set<EventNotificationTypeDto> notificationTypes = EventType.getNotificationTypesForFilter(filter);
            int eventNotificationsMask = 0;
            for (final EventNotificationTypeDto notificationType : notificationTypes) {
                eventNotificationsMask |= notificationType.getValue();
            }
            final NodeContainer softwareConfiguration = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF);
            iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), softwareConfiguration.getFcmodelNode());
            String lightTypeValue = softwareConfiguration.getString(SubDataAttribute.LIGHT_TYPE);
            // Fix for Kaifa bug KI-31
            if (lightTypeValue == null || lightTypeValue.isEmpty()) {
                lightTypeValue = "RELAY";
            }
            final LightTypeDto lightType = LightTypeDto.valueOf(lightTypeValue);
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF, SubDataAttribute.LIGHT_TYPE, lightTypeValue);
            Iec61850GetStatusCommand.this.loggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            /*
             * The preferredLinkType and actualLinkType are hard-coded to
             * LinkTypeDto.ETHERNET, other link types do not apply to the
             * device type in use.
             */
            return new DeviceStatusDto(lightValues, LinkTypeDto.ETHERNET, LinkTypeDto.ETHERNET, lightType, eventNotificationsMask);
        }
    };
    return iec61850Client.sendCommandWithRetry(function, "GetStatus", deviceConnection.getDeviceIdentification());
}
Also used : LightTypeDto(org.opensmartgridplatform.dto.valueobjects.LightTypeDto) ArrayList(java.util.ArrayList) DeviceOutputSetting(org.opensmartgridplatform.core.db.api.iec61850.entities.DeviceOutputSetting) NodeContainer(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) LogicalNode(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.LogicalNode) LightValueDto(org.opensmartgridplatform.dto.valueobjects.LightValueDto) Function(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Function) DeviceMessageLog(org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) DeviceStatusDto(org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto) BdaBoolean(com.beanit.openiec61850.BdaBoolean) EventNotificationTypeDto(org.opensmartgridplatform.dto.valueobjects.EventNotificationTypeDto)

Example 3 with EventNotificationTypeDto

use of org.opensmartgridplatform.dto.valueobjects.EventNotificationTypeDto in project open-smart-grid-platform by OSGP.

the class OslpDeviceService method buildOslpRequestSetEventNotifications.

private void buildOslpRequestSetEventNotifications(final SetEventNotificationsDeviceRequest deviceRequest) {
    final Oslp.SetEventNotificationsRequest.Builder builder = Oslp.SetEventNotificationsRequest.newBuilder();
    int bitMask = 0;
    for (final EventNotificationTypeDto ent : deviceRequest.getEventNotificationsContainer().getEventNotifications()) {
        bitMask += ent.getValue();
    }
    builder.setNotificationMask(bitMask);
    this.buildAndSignEnvelope(deviceRequest, Oslp.Message.newBuilder().setSetEventNotificationsRequest(builder.build()).build(), deviceRequest.getEventNotificationsContainer());
}
Also used : EventNotificationTypeDto(org.opensmartgridplatform.dto.valueobjects.EventNotificationTypeDto)

Aggregations

EventNotificationTypeDto (org.opensmartgridplatform.dto.valueobjects.EventNotificationTypeDto)3 BdaBoolean (com.beanit.openiec61850.BdaBoolean)1 ArrayList (java.util.ArrayList)1 JMSException (javax.jms.JMSException)1 DeviceMessageLog (org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)1 ConnectionFailureException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ConnectionFailureException)1 NodeException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeException)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)1 Function (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Function)1 LogicalNode (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)1 NodeContainer (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)1 Iec61850SetEventNotificationFilterCommand (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.services.commands.Iec61850SetEventNotificationFilterCommand)1 DeviceOutputSetting (org.opensmartgridplatform.core.db.api.iec61850.entities.DeviceOutputSetting)1 DeviceStatusDto (org.opensmartgridplatform.dto.valueobjects.DeviceStatusDto)1 LightTypeDto (org.opensmartgridplatform.dto.valueobjects.LightTypeDto)1 LightValueDto (org.opensmartgridplatform.dto.valueobjects.LightValueDto)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 TechnicalException (org.opensmartgridplatform.shared.exceptionhandling.TechnicalException)1