Search in sources :

Example 1 with TransitionTypeDto

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

the class Iec61850TransitionCommand method transitionDevice.

public void transitionDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final TransitionMessageDataContainerDto transitionMessageDataContainer) throws ProtocolAdapterException {
    final TransitionTypeDto transitionType = transitionMessageDataContainer.getTransitionType();
    LOGGER.info("device: {}, transition: {}", deviceConnection.getDeviceIdentification(), transitionType);
    final boolean controlValueForTransition = transitionType.equals(TransitionTypeDto.DAY_NIGHT);
    final DateTime dateTime = transitionMessageDataContainer.getDateTime();
    if (dateTime != null) {
        LOGGER.warn("device: {}, setting date/time {} for transition {} not supported", deviceConnection.getDeviceIdentification(), dateTime, transitionType);
    }
    final Function<Void> function = new Function<Void>() {

        @Override
        public Void apply(final DeviceMessageLog deviceMessageLog) throws ProtocolAdapterException {
            final NodeContainer sensorNode = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SENSOR, Fc.CO);
            iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), sensorNode.getFcmodelNode());
            LOGGER.info("device: {}, sensorNode: {}", deviceConnection.getDeviceIdentification(), sensorNode);
            final NodeContainer oper = sensorNode.getChild(SubDataAttribute.OPERATION);
            LOGGER.info("device: {}, oper: {}", deviceConnection.getDeviceIdentification(), oper);
            final BdaBoolean ctlVal = oper.getBoolean(SubDataAttribute.CONTROL_VALUE);
            LOGGER.info("device: {}, ctlVal: {}", deviceConnection.getDeviceIdentification(), ctlVal);
            ctlVal.setValue(controlValueForTransition);
            LOGGER.info("device: {}, set ctlVal to {} in order to transition the device", deviceConnection.getDeviceIdentification(), controlValueForTransition);
            oper.write();
            deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SENSOR, Fc.CO, SubDataAttribute.OPERATION, SubDataAttribute.CONTROL_VALUE, Boolean.toString(controlValueForTransition));
            Iec61850TransitionCommand.this.loggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            return null;
        }
    };
    iec61850Client.sendCommandWithRetry(function, "SetTransition", deviceConnection.getDeviceIdentification());
}
Also used : Function(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Function) DeviceMessageLog(org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) TransitionTypeDto(org.opensmartgridplatform.dto.valueobjects.TransitionTypeDto) BdaBoolean(com.beanit.openiec61850.BdaBoolean) NodeContainer(org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) DateTime(org.joda.time.DateTime)

Aggregations

BdaBoolean (com.beanit.openiec61850.BdaBoolean)1 DateTime (org.joda.time.DateTime)1 DeviceMessageLog (org.opensmartgridplatform.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)1 Function (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.Function)1 NodeContainer (org.opensmartgridplatform.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)1 TransitionTypeDto (org.opensmartgridplatform.dto.valueobjects.TransitionTypeDto)1