use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850TotalEnergyCommand method execute.
@Override
public MeasurementDto execute(final Iec61850Client client, final DeviceConnection connection, final LogicalDevice logicalDevice, final int logicalDeviceIndex) throws NodeReadException {
final NodeContainer containingNode = connection.getFcModelNode(logicalDevice, logicalDeviceIndex, LogicalNode.GENERATOR_ONE, DataAttribute.TOTAL_ENERGY, Fc.MX);
client.readNodeDataValues(connection.getConnection().getClientAssociation(), containingNode.getFcmodelNode());
return this.translate(containingNode);
}
use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850OperationalHoursCommand method execute.
@Override
public MeasurementDto execute(final Iec61850Client client, final DeviceConnection connection, final LogicalDevice logicalDevice, final int logicalDeviceIndex) throws NodeReadException {
final NodeContainer containingNode = connection.getFcModelNode(logicalDevice, logicalDeviceIndex, LogicalNode.GENERATOR_ONE, DataAttribute.OPERATIONAL_HOURS, Fc.ST);
client.readNodeDataValues(connection.getConnection().getClientAssociation(), containingNode.getFcmodelNode());
return this.translate(containingNode);
}
use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850PowerUsageHistoryCommand method getPowerUsageHistoryDataFromRelay.
private List<PowerUsageDataDto> getPowerUsageHistoryDataFromRelay(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final TimePeriodDto timePeriod, final DeviceOutputSetting deviceOutputSetting, final DeviceMessageLog deviceMessageLog) throws NodeReadException {
final List<PowerUsageDataDto> powerUsageHistoryDataFromRelay = new ArrayList<>();
final int relayIndex = deviceOutputSetting.getExternalId();
final LogicalNode logicalNode = LogicalNode.getSwitchComponentByIndex(deviceOutputSetting.getInternalId());
final NodeContainer onIntervalBuffer = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, logicalNode, DataAttribute.SWITCH_ON_INTERVAL_BUFFER, Fc.ST);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), onIntervalBuffer.getFcmodelNode());
final Short lastIndex = onIntervalBuffer.getUnsignedByte(SubDataAttribute.LAST_INDEX).getValue();
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SWITCH_ON_INTERVAL_BUFFER, Fc.ST, SubDataAttribute.LAST_INDEX, lastIndex.toString());
/*
* Last index is the last index written in the 60-entry buffer. When the
* last buffer entry is written, the next entry will be placed at the
* first position in the buffer (cyclically). To preserve the order of
* entries written in the response, iteration starts with the next index
* (oldest entry) and loops from there.
*/
final int numberOfEntries = 60;
final int idxOldest = (lastIndex + 1) % numberOfEntries;
for (int i = 0; i < numberOfEntries; i++) {
final int bufferIndex = (idxOldest + i) % numberOfEntries;
final NodeContainer indexedItvNode = onIntervalBuffer.getChild(SubDataAttribute.INTERVAL.getDescription() + (bufferIndex + 1));
LOGGER.info("device: {}, itv{}: {}", deviceConnection.getDeviceIdentification(), bufferIndex + 1, indexedItvNode);
final Integer itvNode = indexedItvNode.getInteger(SubDataAttribute.INTERVAL).getValue();
LOGGER.info("device: {}, itv{}.itv: {}", deviceConnection.getDeviceIdentification(), bufferIndex + 1, itvNode);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SWITCH_ON_INTERVAL_BUFFER, Fc.ST, SubDataAttribute.INTERVAL, SubDataAttribute.INTERVAL, itvNode + "");
final DateTime date = new DateTime(indexedItvNode.getDate(SubDataAttribute.DAY));
LOGGER.info("device: {}, itv{}.day: {}", deviceConnection.getDeviceIdentification(), bufferIndex + 1, date);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SWITCH_ON_INTERVAL_BUFFER, Fc.ST, SubDataAttribute.INTERVAL, SubDataAttribute.DAY, itvNode + "");
final int totalMinutesOnForDate = itvNode;
final boolean includeEntryInResponse = this.timePeriodContainsDateTime(timePeriod, date, deviceConnection.getDeviceIdentification(), relayIndex, bufferIndex);
if (!includeEntryInResponse) {
continue;
}
// MeterType.AUX hard-coded (not supported).
final PowerUsageDataDto powerUsageData = new PowerUsageDataDto(date, MeterTypeDto.AUX, 0, 0);
final List<RelayDataDto> relayDataList = new ArrayList<>();
final RelayDataDto relayData = new RelayDataDto(relayIndex, totalMinutesOnForDate);
relayDataList.add(relayData);
final SsldDataDto ssldData = new SsldDataDto(0, 0, 0, 0, 0, 0, 0, 0, 0, relayDataList);
powerUsageData.setSsldData(ssldData);
powerUsageHistoryDataFromRelay.add(powerUsageData);
}
DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
return powerUsageHistoryDataFromRelay;
}
use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850RebootCommand method rebootDevice.
public void rebootDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection) throws ProtocolAdapterException {
final Function<Void> function = new Function<Void>() {
@Override
public Void apply(final DeviceMessageLog deviceMessageLog) throws Exception {
final NodeContainer rebootOperationNode = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.REBOOT_OPERATION, Fc.CO);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), rebootOperationNode.getFcmodelNode());
LOGGER.info("device: {}, rebootOperationNode: {}", deviceConnection.getDeviceIdentification(), rebootOperationNode);
final NodeContainer oper = rebootOperationNode.getChild(SubDataAttribute.OPERATION);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), oper.getFcmodelNode());
LOGGER.info("device: {}, oper: {}", deviceConnection.getDeviceIdentification(), oper);
final BdaBoolean ctlVal = oper.getBoolean(SubDataAttribute.CONTROL_VALUE);
LOGGER.info("device: {}, ctlVal: {}", deviceConnection.getDeviceIdentification(), ctlVal);
ctlVal.setValue(true);
LOGGER.info("device: {}, set ctlVal to true in order to reboot the device", deviceConnection.getDeviceIdentification());
oper.write();
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.REBOOT_OPERATION, Fc.ST, SubDataAttribute.OPERATION, SubDataAttribute.CONTROL_VALUE, Boolean.toString(true));
DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
return null;
}
};
iec61850Client.sendCommandWithRetry(function, "Reboot", deviceConnection.getDeviceIdentification());
}
use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850UpdateFirmwareCommand method updateFunctionalFirmware.
private void updateFunctionalFirmware(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final String fullUrl, final DeviceMessageLog deviceMessageLog) throws NodeException {
LOGGER.info("Reading the functional firmware node for device: {}", deviceConnection.getDeviceIdentification());
final NodeContainer functionalFirmwareNode = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.FUNCTIONAL_FIRMWARE, Fc.CF);
iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), functionalFirmwareNode.getFcmodelNode());
final String currentFunctionalFirmwareDownloadUrl = functionalFirmwareNode.getString(SubDataAttribute.URL);
final Date currentFunctionalFirmwareUpdateDateTime = functionalFirmwareNode.getDate(SubDataAttribute.START_TIME);
LOGGER.info("Current functional firmware download url: {}, start time: {} for device: {}", currentFunctionalFirmwareDownloadUrl, currentFunctionalFirmwareUpdateDateTime, deviceConnection.getDeviceIdentification());
LOGGER.info("Updating the functional firmware download url to: {} for device: {}", fullUrl, deviceConnection.getDeviceIdentification());
functionalFirmwareNode.writeString(SubDataAttribute.URL, fullUrl);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.FUNCTIONAL_FIRMWARE, Fc.CF, SubDataAttribute.URL, fullUrl);
final Date oneMinuteFromNow = this.determineFirmwareUpdateDateTime(iec61850Client, deviceConnection);
LOGGER.info("Updating the functional firmware download start time to: {} for device: {}", oneMinuteFromNow, deviceConnection.getDeviceIdentification());
functionalFirmwareNode.writeDate(SubDataAttribute.START_TIME, oneMinuteFromNow);
deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.FUNCTIONAL_FIRMWARE, Fc.CF, SubDataAttribute.START_TIME, simpleDateFormat.format(oneMinuteFromNow));
}
Aggregations