use of com.beanit.openiec61850.BasicDataAttribute 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));
}
use of com.beanit.openiec61850.BasicDataAttribute 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");
}
}
}
use of com.beanit.openiec61850.BasicDataAttribute 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);
}
}
use of com.beanit.openiec61850.BasicDataAttribute in project open-smart-grid-platform by OSGP.
the class RtuSimulator method write.
@Override
public List<ServiceError> write(final List<BasicDataAttribute> bdas) {
for (final BasicDataAttribute bda : bdas) {
LOGGER.info("got a write request: {}", bda);
this.writeValueAndUpdateRelatedAttributes(bda);
}
return new ArrayList<>();
}
use of com.beanit.openiec61850.BasicDataAttribute 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 + "]");
}
}
Aggregations