use of org.opensmartgridplatform.dto.valueobjects.RelayMapDto in project open-smart-grid-platform by OSGP.
the class RelayConfigurationToOslpRelayConfigurationConverter method convertFrom.
@Override
public RelayConfigurationDto convertFrom(final org.opensmartgridplatform.oslp.Oslp.RelayConfiguration source, final Type<RelayConfigurationDto> destinationType, final MappingContext context) {
if (source == null) {
return null;
}
// Map the relay configuration.
final List<RelayMapDto> indexAddressMap = new ArrayList<>();
for (final IndexAddressMap entry : source.getAddressMapList()) {
// Map OSLP RT_NOT_SET to null
indexAddressMap.add(new RelayMapDto(this.mapperFacade.map(entry.getIndex(), Integer.class), this.mapperFacade.map(entry.getAddress(), Integer.class), entry.hasRelayType() && entry.getRelayType() != Oslp.RelayType.RT_NOT_SET ? this.mapperFacade.map(entry.getRelayType(), RelayTypeDto.class) : null, null));
}
// Sort the relay configuration on index.
Collections.sort(indexAddressMap, (o1, o2) -> o1.getIndex().compareTo(o2.getIndex()));
return new RelayConfigurationDto(indexAddressMap);
}
use of org.opensmartgridplatform.dto.valueobjects.RelayMapDto in project open-smart-grid-platform by OSGP.
the class Iec61850GetConfigurationCommand method getConfigurationFromDevice.
public ConfigurationDto getConfigurationFromDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final Ssld ssld, final Iec61850Mapper mapper) throws ProtocolAdapterException {
final Function<ConfigurationDto> function = new Function<ConfigurationDto>() {
@Override
public ConfigurationDto apply(final DeviceMessageLog deviceMessageLog) throws ProtocolAdapterException {
// Keeping the hardcoded values and values that aren't fetched
// from the device out of the Function.
final LinkTypeDto preferredLinkType = LinkTypeDto.ETHERNET;
// Map the relay configuration.
final List<RelayMapDto> relayMaps = new ArrayList<>();
for (final DeviceOutputSetting deviceOutputSetting : ssld.getOutputSettings()) {
Iec61850GetConfigurationCommand.this.checkRelayType(iec61850Client, deviceConnection, deviceOutputSetting, deviceMessageLog);
relayMaps.add(mapper.map(deviceOutputSetting, RelayMapDto.class));
}
// Sort the relay configuration on index.
Collections.sort(relayMaps, (o1, o2) -> o1.getIndex().compareTo(o2.getIndex()));
final RelayConfigurationDto relayConfiguration = new RelayConfigurationDto(relayMaps);
// PSLD specific => just sending null so it'll be ignored
final DaliConfigurationDto daliConfiguration = null;
// getting the software configuration values
LOGGER.info("Reading the software configuration values");
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";
}
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF, SubDataAttribute.LIGHT_TYPE, lightTypeValue);
final LightTypeDto lightType = LightTypeDto.valueOf(lightTypeValue);
final short astroGateSunRiseOffset = softwareConfiguration.getShort(SubDataAttribute.ASTRONOMIC_SUNRISE_OFFSET).getValue();
final short astroGateSunSetOffset = softwareConfiguration.getShort(SubDataAttribute.ASTRONOMIC_SUNSET_OFFSET).getValue();
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF, SubDataAttribute.ASTRONOMIC_SUNRISE_OFFSET, Short.toString(astroGateSunRiseOffset));
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SOFTWARE_CONFIGURATION, Fc.CF, SubDataAttribute.ASTRONOMIC_SUNSET_OFFSET, Short.toString(astroGateSunSetOffset));
final ConfigurationDto configuration = ConfigurationDto.newBuilder().withLightType(lightType).withDaliConfiguration(daliConfiguration).withRelayConfiguration(relayConfiguration).withPreferredLinkType(preferredLinkType).build();
// getting the registration configuration values
LOGGER.info("Reading the registration configuration values");
final NodeContainer registration = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.REGISTRATION, Fc.CF);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), registration.getFcmodelNode());
final String serverAddress = registration.getString(SubDataAttribute.SERVER_ADDRESS);
final int serverPort = registration.getInteger(SubDataAttribute.SERVER_PORT).getValue();
configuration.setOsgpIpAddress(serverAddress);
configuration.setOsgpPortNumber(serverPort);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.REGISTRATION, Fc.CF, SubDataAttribute.SERVER_ADDRESS, serverAddress);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.REGISTRATION, Fc.CF, SubDataAttribute.SERVER_PORT, Integer.toString(serverPort));
// getting the IP configuration values
LOGGER.info("Reading the IP configuration values");
final NodeContainer ipConfiguration = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), ipConfiguration.getFcmodelNode());
final String deviceFixedIpAddress = ipConfiguration.getString(SubDataAttribute.IP_ADDRESS);
final String deviceFixedIpNetmask = ipConfiguration.getString(SubDataAttribute.NETMASK);
final String deviceFixedIpGateway = ipConfiguration.getString(SubDataAttribute.GATEWAY);
final boolean isDhcpEnabled = ipConfiguration.getBoolean(SubDataAttribute.ENABLE_DHCP).getValue();
final DeviceFixedIpDto deviceFixedIp = new DeviceFixedIpDto(deviceFixedIpAddress, deviceFixedIpNetmask, deviceFixedIpGateway);
configuration.setDeviceFixedIp(deviceFixedIp);
configuration.setDhcpEnabled(isDhcpEnabled);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF, SubDataAttribute.IP_ADDRESS, deviceFixedIpAddress);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF, SubDataAttribute.NETMASK, deviceFixedIpNetmask);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF, SubDataAttribute.GATEWAY, deviceFixedIpGateway);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.IP_CONFIGURATION, Fc.CF, SubDataAttribute.ENABLE_DHCP, Boolean.toString(isDhcpEnabled));
// setting the software configuration values
configuration.setAstroGateSunRiseOffset((int) astroGateSunRiseOffset);
configuration.setAstroGateSunSetOffset((int) astroGateSunSetOffset);
// getting the clock configuration values
LOGGER.info("Reading the clock configuration values");
final NodeContainer clock = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), clock.getFcmodelNode());
final int timeSyncFrequency = clock.getUnsignedShort(SubDataAttribute.TIME_SYNC_FREQUENCY).getValue();
final boolean automaticSummerTimingEnabled = clock.getBoolean(SubDataAttribute.AUTOMATIC_SUMMER_TIMING_ENABLED).getValue();
final String summerTimeDetails = clock.getString(SubDataAttribute.SUMMER_TIME_DETAILS);
final String winterTimeDetails = clock.getString(SubDataAttribute.WINTER_TIME_DETAILS);
final String ntpHost = clock.getString(SubDataAttribute.NTP_HOST);
final boolean ntpEnabled = clock.getBoolean(SubDataAttribute.NTP_ENABLED).getValue();
final int ntpSyncInterval = clock.getUnsignedShort(SubDataAttribute.NTP_SYNC_INTERVAL).getValue();
configuration.setTimeSyncFrequency(timeSyncFrequency);
configuration.setAutomaticSummerTimingEnabled(automaticSummerTimingEnabled);
configuration.setSummerTimeDetails(new DaylightSavingTimeTransition(TIME_ZONE_AMSTERDAM, summerTimeDetails).getDateTimeForNextTransition().toDateTime(DateTimeZone.UTC));
configuration.setWinterTimeDetails(new DaylightSavingTimeTransition(TIME_ZONE_AMSTERDAM, winterTimeDetails).getDateTimeForNextTransition().toDateTime(DateTimeZone.UTC));
configuration.setNtpHost(ntpHost);
configuration.setNtpEnabled(ntpEnabled);
configuration.setNtpSyncInterval(ntpSyncInterval);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.TIME_SYNC_FREQUENCY, Integer.toString(timeSyncFrequency));
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.AUTOMATIC_SUMMER_TIMING_ENABLED, Boolean.toString(automaticSummerTimingEnabled));
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.SUMMER_TIME_DETAILS, summerTimeDetails);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.WINTER_TIME_DETAILS, winterTimeDetails);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.NTP_HOST, ntpHost);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.NTP_ENABLED, String.valueOf(ntpEnabled));
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF, SubDataAttribute.NTP_SYNC_INTERVAL, String.valueOf(ntpSyncInterval));
Iec61850GetConfigurationCommand.this.loggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
return configuration;
}
};
return iec61850Client.sendCommandWithRetry(function, "GetConfiguration", deviceConnection.getDeviceIdentification());
}
use of org.opensmartgridplatform.dto.valueobjects.RelayMapDto in project open-smart-grid-platform by OSGP.
the class ConfigurationManagementService method replaceEmptyOutputSettings.
private void replaceEmptyOutputSettings(final ConfigurationDto originalConfig, final List<DeviceOutputSetting> outputSettings) {
// In case the relay map is not null or not empty, return it.
if (originalConfig.getRelayConfiguration() == null || CollectionUtils.isEmpty(originalConfig.getRelayConfiguration().getRelayMap())) {
// Fall back to output settings when no relay configuration
// available to generate configuration
final List<RelayMapDto> relayMap = new ArrayList<>();
outputSettings.forEach(outputSetting -> relayMap.add(new org.opensmartgridplatform.dto.valueobjects.RelayMapDto(outputSetting.getExternalId(), outputSetting.getInternalId(), RelayTypeDto.valueOf(outputSetting.getOutputType().toString()), outputSetting.getAlias())));
originalConfig.setRelayConfiguration(new RelayConfigurationDto(relayMap));
}
}
use of org.opensmartgridplatform.dto.valueobjects.RelayMapDto in project open-smart-grid-platform by OSGP.
the class Iec61850SetConfigurationFunction method setRelayConfiguration.
private void setRelayConfiguration(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final ConfigurationDto configuration, final DeviceMessageLog deviceMessageLog) throws NodeException {
if (configuration.getRelayConfiguration() != null && configuration.getRelayConfiguration().getRelayMap() != null) {
final List<RelayMapDto> relayMaps = configuration.getRelayConfiguration().getRelayMap();
for (final RelayMapDto relayMap : relayMaps) {
final Integer internalIndex = relayMap.getAddress();
final RelayTypeDto relayType = relayMap.getRelayType();
final LogicalNode logicalNode = LogicalNode.getSwitchComponentByIndex(internalIndex);
final NodeContainer switchType = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, logicalNode, DataAttribute.SWITCH_TYPE, Fc.CO);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), switchType.getFcmodelNode());
final NodeContainer operation = switchType.getChild(SubDataAttribute.OPERATION);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), operation.getFcmodelNode());
final BdaInt8 ctlVal = operation.getByte(SubDataAttribute.CONTROL_VALUE);
final byte switchTypeValue = (byte) (RelayTypeDto.LIGHT.equals(relayType) ? SWITCH_TYPE_LIGHT : SWITCH_TYPE_TARIFF);
LOGGER.info("Updating Switch for internal index {} to {} ({})", internalIndex, switchTypeValue, relayType);
ctlVal.setValue(switchTypeValue);
operation.write();
deviceMessageLog.addVariable(logicalNode, DataAttribute.SWITCH_TYPE, Fc.CO, SubDataAttribute.OPERATION, SubDataAttribute.CONTROL_VALUE, Byte.toString(switchTypeValue));
}
}
}
Aggregations