Search in sources :

Example 36 with DeviceConnection

use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850UpdateFirmwareCommand method updateSecurityFirmware.

private void updateSecurityFirmware(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final String fullUrl, final DeviceMessageLog deviceMessageLog) throws NodeException {
    LOGGER.info("Reading the security firmware node for device: {}", deviceConnection.getDeviceIdentification());
    final NodeContainer securityFirmwareNode = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SECURITY_FIRMWARE, Fc.CF);
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), securityFirmwareNode.getFcmodelNode());
    final String currentSecurityFirmwareDownloadUrl = securityFirmwareNode.getString(SubDataAttribute.URL);
    final Date currentSecurityFirmwareUpdateDateTime = securityFirmwareNode.getDate(SubDataAttribute.START_TIME);
    LOGGER.info("Current security firmware download url: {}, start time: {} for device: {}", currentSecurityFirmwareDownloadUrl, currentSecurityFirmwareUpdateDateTime, deviceConnection.getDeviceIdentification());
    LOGGER.info("Updating the security firmware download url to : {} for device: {}", fullUrl, deviceConnection.getDeviceIdentification());
    securityFirmwareNode.writeString(SubDataAttribute.URL, fullUrl);
    deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SECURITY_FIRMWARE, Fc.CF, SubDataAttribute.URL, fullUrl);
    final Date oneMinuteFromNow = this.determineFirmwareUpdateDateTime(iec61850Client, deviceConnection);
    LOGGER.info("Updating the security firmware download start time to: {} for device: {}", oneMinuteFromNow, deviceConnection.getDeviceIdentification());
    securityFirmwareNode.writeDate(SubDataAttribute.START_TIME, oneMinuteFromNow);
    deviceMessageLog.addVariable(LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.SECURITY_FIRMWARE, Fc.CF, SubDataAttribute.START_TIME, simpleDateFormat.format(oneMinuteFromNow));
}
Also used : NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) Date(java.util.Date)

Example 37 with DeviceConnection

use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850UpdateFirmwareCommand method pushFirmwareToDevice.

public void pushFirmwareToDevice(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final String fullUrl, final FirmwareModuleData firmwareModuleData) throws ProtocolAdapterException {
    final Function<Void> function = new Function<Void>() {

        @Override
        public Void apply(final DeviceMessageLog deviceMessageLog) throws Exception {
            final int count = firmwareModuleData.countNumberOfModules();
            if (count != 1) {
                throw new ProtocolAdapterException(String.format("Number of firmware modules is not equal to 1 but %d", count));
            }
            // updated.
            if (FirmwareModuleType.FUNCTIONAL.name().equalsIgnoreCase(firmwareModuleData.getModuleVersionFunc())) {
                Iec61850UpdateFirmwareCommand.this.updateFunctionalFirmware(iec61850Client, deviceConnection, fullUrl, deviceMessageLog);
            } else if (FirmwareModuleType.SECURITY.name().equalsIgnoreCase(firmwareModuleData.getModuleVersionSec())) {
                Iec61850UpdateFirmwareCommand.this.updateSecurityFirmware(iec61850Client, deviceConnection, fullUrl, deviceMessageLog);
            } else {
                throw new ProtocolAdapterException(String.format("Unsupported firmwareModuleData (only functional and security are allowed): communication: %s, functional: %s, module-active: %s, m-bus: %s, security: %s, fullUrl: %s", firmwareModuleData.getModuleVersionComm(), firmwareModuleData.getModuleVersionFunc(), firmwareModuleData.getModuleVersionMa(), firmwareModuleData.getModuleVersionMbus(), firmwareModuleData.getModuleVersionSec(), fullUrl));
            }
            DeviceMessageLoggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
            return null;
        }
    };
    iec61850Client.sendCommandWithRetry(function, "UpdateFirmware", deviceConnection.getDeviceIdentification());
}
Also used : Function(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function) DeviceMessageLog(com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)

Example 38 with DeviceConnection

use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850UpdateFirmwareCommand method determineFirmwareUpdateDateTime.

private Date determineFirmwareUpdateDateTime(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection) throws NodeReadException {
    final NodeContainer clock = deviceConnection.getFcModelNode(LogicalDevice.LIGHTING, LogicalNode.STREET_LIGHT_CONFIGURATION, DataAttribute.CLOCK, Fc.CF);
    iec61850Client.readNodeDataValues(deviceConnection.getConnection().getClientAssociation(), clock.getFcmodelNode());
    final DateTime deviceTime = new DateTime(clock.getDate(SubDataAttribute.CURRENT_TIME));
    // Creating a DateTime one minute from now.
    return deviceTime.plusMinutes(1).toDate();
}
Also used : NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer) DateTime(org.joda.time.DateTime)

Example 39 with DeviceConnection

use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850VlmCapCommand 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.TANK_CHARACTERISTICS_ONE, DataAttribute.VLMCAP, Fc.SP);
    client.readNodeDataValues(connection.getConnection().getClientAssociation(), containingNode.getFcmodelNode());
    return this.translate(containingNode);
}
Also used : NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)

Example 40 with DeviceConnection

use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection 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);
}
Also used : NodeContainer(com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)

Aggregations

NodeContainer (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.NodeContainer)55 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)22 DeviceConnection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.DeviceConnection)18 ConnectionFailureException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ConnectionFailureException)17 NodeWriteException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.NodeWriteException)17 JMSException (javax.jms.JMSException)16 DeviceMessageLog (com.alliander.osgp.adapter.protocol.iec61850.domain.valueobjects.DeviceMessageLog)15 Function (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function)15 FunctionalException (com.alliander.osgp.shared.exceptionhandling.FunctionalException)14 TechnicalException (com.alliander.osgp.shared.exceptionhandling.TechnicalException)13 ArrayList (java.util.ArrayList)8 Ssld (com.alliander.osgp.core.db.api.iec61850.entities.Ssld)7 LogicalNode (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.LogicalNode)6 DeviceOutputSetting (com.alliander.osgp.core.db.api.iec61850.entities.DeviceOutputSetting)6 DateTime (org.joda.time.DateTime)6 BdaBoolean (org.openmuc.openiec61850.BdaBoolean)5 Iec61850ClientAssociation (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850ClientAssociation)4 Iec61850Connection (com.alliander.osgp.adapter.protocol.iec61850.infra.networking.Iec61850Connection)4 ClientAssociation (org.openmuc.openiec61850.ClientAssociation)4 ServerModel (org.openmuc.openiec61850.ServerModel)4