Search in sources :

Example 6 with LogicalDevice

use of com.beanit.openiec61850.LogicalDevice in project open-smart-grid-platform by OSGP.

the class RtuSimulator method mockValue.

public void mockValue(final String logicalDeviceName, final String node, final String value) {
    if (!this.stopGeneratingValues.get()) {
        /*
       * A mocked value is explicitly set, stop changing values with
       * generateData, because one of those might break the mock value
       * that will be expected.
       */
        this.ensurePeriodicDataGenerationIsStopped();
    }
    final LogicalDevice logicalDevice = this.getLogicalDevice(logicalDeviceName);
    final BasicDataAttribute basicDataAttribute = logicalDevice.getAttributeAndSetValue(LogicalDeviceNode.fromDescription(node), value);
    this.server.setValues(Arrays.asList(basicDataAttribute));
}
Also used : LogicalDevice(org.opensmartgridplatform.simulator.protocol.iec61850.server.logicaldevices.LogicalDevice) BasicDataAttribute(com.beanit.openiec61850.BasicDataAttribute)

Example 7 with LogicalDevice

use of com.beanit.openiec61850.LogicalDevice in project open-smart-grid-platform by OSGP.

the class RtuSimulator method generateData.

@Scheduled(fixedDelay = 60000)
public void generateData() {
    synchronized (this.stopGeneratingValues) {
        if (!this.stopGeneratingValues.get()) {
            final Date timestamp = new Date();
            final List<BasicDataAttribute> values = new ArrayList<>();
            for (final LogicalDevice ld : this.logicalDevices) {
                try {
                    values.addAll(ld.getAttributesAndSetValues(timestamp));
                } catch (final Exception e) {
                    LOGGER.info("Exception while generating values.", e);
                }
            }
            this.server.setValues(values);
            LOGGER.info("Generated values");
        }
    }
}
Also used : LogicalDevice(org.opensmartgridplatform.simulator.protocol.iec61850.server.logicaldevices.LogicalDevice) ArrayList(java.util.ArrayList) BasicDataAttribute(com.beanit.openiec61850.BasicDataAttribute) Date(java.util.Date) IOException(java.io.IOException) SclParseException(com.beanit.openiec61850.SclParseException) Scheduled(org.springframework.scheduling.annotation.Scheduled)

Example 8 with LogicalDevice

use of com.beanit.openiec61850.LogicalDevice in project open-smart-grid-platform by OSGP.

the class RtuSimulator method writeValueAndUpdateRelatedAttributes.

/**
 * Writes an updated value for an attribute to the server model. This attribute update can also
 * trigger updates to other attributes. Those updates are also handled.
 *
 * @param bda The attribute that has been updated.
 */
private void writeValueAndUpdateRelatedAttributes(final BasicDataAttribute bda) {
    final String logicalNodeSeparator = "/";
    final Pattern pattern = Pattern.compile(this.serverName + "(.*?)" + logicalNodeSeparator + "(.*?):");
    final Matcher matcher = pattern.matcher(bda.toString());
    if (matcher.find()) {
        final String logicalDeviceName = matcher.group(1);
        final String node = matcher.group(2);
        final LogicalDevice logicalDevice = this.getLogicalDevice(logicalDeviceName);
        final List<BasicDataAttribute> updatedAttributes = logicalDevice.writeValueAndUpdateRelatedAttributes(node, bda);
        this.server.setValues(updatedAttributes);
    }
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) LogicalDevice(org.opensmartgridplatform.simulator.protocol.iec61850.server.logicaldevices.LogicalDevice) BasicDataAttribute(com.beanit.openiec61850.BasicDataAttribute)

Example 9 with LogicalDevice

use of com.beanit.openiec61850.LogicalDevice in project open-smart-grid-platform by OSGP.

the class RtuSimulator method assertValue.

public void assertValue(final String logicalDeviceName, final String node, final String value) {
    final LogicalDevice logicalDevice = this.getLogicalDevice(logicalDeviceName);
    // Get a new model copy to see values that have been set on the server.
    logicalDevice.refreshServerModel(this.server.getModelCopy());
    final ModelNode actual = logicalDevice.getBasicDataAttribute(LogicalDeviceNode.fromDescription(node));
    final String onLogicalDevice = "\" on logical device \"";
    if (actual == null) {
        throw new AssertionError("RTU Simulator does not have expected node \"" + node + onLogicalDevice + logicalDeviceName + "\".");
    }
    if (!(actual instanceof BasicDataAttribute)) {
        throw new AssertionError("RTU Simulator value has node \"" + node + onLogicalDevice + logicalDeviceName + "\", but it is not a BasicDataAttribute: " + actual.getClass().getName());
    }
    final BasicDataAttribute expected = this.getCopyWithNewValue((BasicDataAttribute) actual, value);
    if (!BasicDataAttributesHelper.attributesEqual(expected, (BasicDataAttribute) actual)) {
        throw new AssertionError("RTU Simulator attribute for node \"" + node + onLogicalDevice + logicalDeviceName + "\" - expected: [" + expected + "], actual: [" + actual + "]");
    }
}
Also used : LogicalDevice(org.opensmartgridplatform.simulator.protocol.iec61850.server.logicaldevices.LogicalDevice) BasicDataAttribute(com.beanit.openiec61850.BasicDataAttribute) ModelNode(com.beanit.openiec61850.ModelNode)

Example 10 with LogicalDevice

use of com.beanit.openiec61850.LogicalDevice in project open-smart-grid-platform by OSGP.

the class Iec61850DeviceConnectionService method getModelNode.

private FcModelNode getModelNode(final String logicalDevice, final Iec61850Connection iec61850Connection, final String description) throws ProtocolAdapterException {
    final ServerModel serverModel = iec61850Connection.getServerModel();
    if (serverModel == null) {
        final String msg = String.format("ServerModel is null for logicalDevice {%s}", logicalDevice);
        throw new ProtocolAdapterException(msg);
    }
    final String objRef = description + logicalDevice + "/" + LogicalNode.LOGICAL_NODE_ZERO.getDescription() + "." + DataAttribute.NAME_PLATE.getDescription();
    final FcModelNode modelNode = (FcModelNode) serverModel.findModelNode(objRef, Fc.DC);
    if (modelNode == null) {
        final String msg = String.format("ModelNode is null for {%s}", objRef);
        throw new ProtocolAdapterException(msg);
    }
    return modelNode;
}
Also used : ServerModel(com.beanit.openiec61850.ServerModel) FcModelNode(com.beanit.openiec61850.FcModelNode) ProtocolAdapterException(org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)

Aggregations

FcModelNode (com.beanit.openiec61850.FcModelNode)5 BasicDataAttribute (com.beanit.openiec61850.BasicDataAttribute)4 ArrayList (java.util.ArrayList)4 LogicalDevice (org.opensmartgridplatform.simulator.protocol.iec61850.server.logicaldevices.LogicalDevice)4 ModelNode (com.beanit.openiec61850.ModelNode)2 ObjectReference (com.beanit.openiec61850.ObjectReference)2 NodeNotFoundException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeNotFoundException)2 LogicalDeviceDto (org.opensmartgridplatform.dto.da.iec61850.LogicalDeviceDto)2 LogicalNodeDto (org.opensmartgridplatform.dto.da.iec61850.LogicalNodeDto)2 LogicalDevice (com.beanit.openiec61850.LogicalDevice)1 SclParseException (com.beanit.openiec61850.SclParseException)1 ServerModel (com.beanit.openiec61850.ServerModel)1 IOException (java.io.IOException)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 LogicalDevice (org.openmuc.openiec61850.LogicalDevice)1 ModelNode (org.openmuc.openiec61850.ModelNode)1 NodeReadException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.NodeReadException)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1