use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function 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());
}
use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function in project Protocol-Adapter-IEC61850 by OSGP.
the class DeviceRegistrationService method disableRegistration.
/**
* After the device has registered with the platform successfully, the
* device has to be informed that the registration worked. Disable an
* attribute so the device will stop attempting to register once a minute.
*
* @param deviceIdentification
* The device identification.
* @param ipAddress
* The IP address of the device.
* @param ied
* The type of IED.
* @param serverName
* The server name.
*
* @throws ProtocolAdapterException
* In case the connection to the device can not be established
* or the connection breaks during communication.
*/
public void disableRegistration(final String deviceIdentification, final InetAddress ipAddress, final IED ied, final String serverName) throws ProtocolAdapterException {
final DeviceConnection deviceConnection = this.iec61850DeviceConnectionService.connectWithoutConnectionCaching(ipAddress.getHostAddress(), deviceIdentification, "", ied, serverName, LogicalDevice.LIGHTING.getDescription());
final Function<Void> function = new Function<Void>() {
@Override
public Void apply(final DeviceMessageLog deviceMessageLog) throws Exception {
DeviceRegistrationService.this.disableRegistration(deviceConnection);
DeviceRegistrationService.this.setLocationInformation(deviceConnection);
if (DeviceRegistrationService.this.isReportingAfterDeviceRegistrationEnabled) {
LOGGER.info("Reporting enabled for device: {}", deviceConnection.getDeviceIdentification());
DeviceRegistrationService.this.enableReporting(deviceConnection);
} else {
LOGGER.info("Reporting disabled for device: {}", deviceIdentification);
DeviceRegistrationService.this.iec61850DeviceConnectionService.disconnect(deviceConnection, null);
}
return null;
}
};
this.iec61850DeviceConnectionService.sendCommandWithRetry(function, deviceIdentification);
}
use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850RtuDeviceService method handleGetData.
// ========================
// PRIVATE HELPER METHODS =
// ========================
private GetDataResponseDto handleGetData(final DeviceConnection connection, final GetDataDeviceRequest deviceRequest) throws ProtocolAdapterException {
final GetDataRequestDto requestedData = deviceRequest.getDataRequest();
final String serverName = this.getServerName(deviceRequest);
final Function<GetDataResponseDto> function = new Function<GetDataResponseDto>() {
@Override
public GetDataResponseDto apply(final DeviceMessageLog deviceMessageLog) throws Exception {
final Iec61850RtuDeviceReportingService reportingService = new Iec61850RtuDeviceReportingService(serverName);
reportingService.enableReportingOnDevice(connection, deviceRequest.getDeviceIdentification());
final List<GetDataSystemIdentifierDto> identifiers = new ArrayList<>();
for (final SystemFilterDto systemFilter : requestedData.getSystemFilters()) {
final SystemService systemService = Iec61850RtuDeviceService.this.systemServiceFactory.getSystemService(systemFilter);
final GetDataSystemIdentifierDto getDataSystemIdentifier = systemService.getData(systemFilter, Iec61850RtuDeviceService.this.iec61850Client, connection);
identifiers.add(getDataSystemIdentifier);
}
return new GetDataResponseDto(identifiers, null);
}
};
return this.iec61850Client.sendCommandWithRetry(function, deviceRequest.getDeviceIdentification());
}
use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850RtuDeviceService method handleSetData.
private void handleSetData(final DeviceConnection connection, final SetDataDeviceRequest deviceRequest) throws ProtocolAdapterException {
final SetDataRequestDto setDataRequest = deviceRequest.getSetDataRequest();
final String serverName = this.getServerName(deviceRequest);
final Function<Void> function = new Function<Void>() {
@Override
public Void apply(final DeviceMessageLog deviceMessageLog) throws Exception {
final Iec61850RtuDeviceReportingService reportingService = new Iec61850RtuDeviceReportingService(serverName);
reportingService.enableReportingOnDevice(connection, deviceRequest.getDeviceIdentification());
for (final SetDataSystemIdentifierDto identifier : setDataRequest.getSetDataSystemIdentifiers()) {
final SystemService systemService = Iec61850RtuDeviceService.this.systemServiceFactory.getSystemService(identifier.getSystemType());
systemService.setData(identifier, Iec61850RtuDeviceService.this.iec61850Client, connection);
}
return null;
}
};
this.iec61850Client.sendCommandWithRetry(function, deviceRequest.getDeviceIdentification());
}
use of com.alliander.osgp.adapter.protocol.iec61850.infra.networking.helper.Function in project Protocol-Adapter-IEC61850 by OSGP.
the class SsldDeviceRequestMessageProcessor method handleGetStatusDeviceResponse.
// This function is used in 3 domains.
protected void handleGetStatusDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount) {
LOGGER.info("Handling getStatusDeviceResponse for device: {}", deviceResponse.getDeviceIdentification());
if (StringUtils.isEmpty(deviceResponse.getCorrelationUid())) {
LOGGER.warn("CorrelationUID is null or empty, not sending GetStatusResponse message for GetStatusRequest message for device: {}", deviceResponse.getDeviceIdentification());
return;
}
final GetStatusDeviceResponse response = (GetStatusDeviceResponse) deviceResponse;
final DeviceStatusDto status = response.getDeviceStatus();
final DeviceMessageMetadata deviceMessageMetadata = new DeviceMessageMetadata(deviceResponse.getDeviceIdentification(), deviceResponse.getOrganisationIdentification(), deviceResponse.getCorrelationUid(), messageType, 0);
final ProtocolResponseMessage protocolResponseMessage = new ProtocolResponseMessage.Builder().domain(domain).domainVersion(domainVersion).deviceMessageMetadata(deviceMessageMetadata).result(ResponseMessageResultType.OK).osgpException(null).retryCount(retryCount).dataObject(status).build();
responseMessageSender.send(protocolResponseMessage);
}
Aggregations