use of com.alliander.osgp.dto.valueobjects.DeviceStatusDto in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850SsldDeviceService method runSelfTest.
@Override
public void runSelfTest(final DeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler, final boolean startOfTest) throws JMSException {
// Assuming all goes well.
final DeviceMessageStatus status = DeviceMessageStatus.OK;
DeviceConnection deviceConnection = null;
try {
deviceConnection = this.connectToDevice(deviceRequest);
// Getting the SSLD for the device output-settings.
final Ssld ssld = this.ssldDataService.findDevice(deviceRequest.getDeviceIdentification());
// This list will contain the external indexes of all light relays.
// It's used to interpret the deviceStatus data later on.
final List<Integer> lightRelays = new ArrayList<>();
LOGGER.info("Turning all lights relays {}", startOfTest ? "on" : "off");
final Iec61850SetLightCommand iec61850SetLightCommand = new Iec61850SetLightCommand();
// startOfTest.
for (final DeviceOutputSetting deviceOutputSetting : this.ssldDataService.findByRelayType(ssld, RelayType.LIGHT)) {
lightRelays.add(deviceOutputSetting.getExternalId());
if (!iec61850SetLightCommand.switchLightRelay(this.iec61850Client, deviceConnection, deviceOutputSetting.getInternalId(), startOfTest)) {
throw new ProtocolAdapterException(String.format("Failed to switch light relay during self-test with internal index: %d for device: %s", deviceOutputSetting.getInternalId(), deviceRequest.getDeviceIdentification()));
}
}
// Sleep and wait.
this.selfTestSleep();
// Getting the status.
final DeviceStatusDto deviceStatus = new Iec61850GetStatusCommand().getStatusFromDevice(this.iec61850Client, deviceConnection, ssld);
LOGGER.info("Fetching and checking the devicestatus");
// Checking to see if all light relays have the correct state.
for (final LightValueDto lightValue : deviceStatus.getLightValues()) {
if (lightRelays.contains(lightValue.getIndex()) && lightValue.isOn() != startOfTest) {
// request failed.
throw new ProtocolAdapterException("not all relays are ".concat(startOfTest ? "on" : "off"));
}
}
LOGGER.info("All lights relays are {}, returning OK", startOfTest ? "on" : "off");
this.createSuccessfulDefaultResponse(deviceRequest, deviceResponseHandler, status);
} catch (final ConnectionFailureException se) {
LOGGER.info("Original ConnectionFailureException message: {}", se.getMessage());
final ConnectionFailureException seGeneric = new ConnectionFailureException("Connection failure", se);
this.handleConnectionFailureException(deviceRequest, deviceResponseHandler, seGeneric);
} catch (final Exception e) {
LOGGER.info("Selftest failure", e);
final TechnicalException te = new TechnicalException(ComponentType.PROTOCOL_IEC61850, "Selftest failure - " + e.getMessage());
this.handleException(deviceRequest, deviceResponseHandler, te);
}
this.iec61850DeviceConnectionService.disconnect(deviceConnection, deviceRequest);
}
use of com.alliander.osgp.dto.valueobjects.DeviceStatusDto in project Protocol-Adapter-IEC61850 by OSGP.
the class Iec61850SsldDeviceService method getStatus.
@Override
public void getStatus(final DeviceRequest deviceRequest, final DeviceResponseHandler deviceResponseHandler) throws JMSException {
DeviceConnection devCon = null;
try {
final DeviceConnection deviceConnection = this.connectToDevice(deviceRequest);
devCon = deviceConnection;
// Getting the SSLD for the device output-settings.
final Ssld ssld = this.ssldDataService.findDevice(deviceRequest.getDeviceIdentification());
final DeviceStatusDto deviceStatus = new Iec61850GetStatusCommand().getStatusFromDevice(this.iec61850Client, deviceConnection, ssld);
final GetStatusDeviceResponse deviceResponse = new GetStatusDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), deviceStatus);
deviceResponseHandler.handleResponse(deviceResponse);
this.enableReporting(deviceConnection, deviceRequest);
} catch (final ConnectionFailureException se) {
this.handleConnectionFailureException(deviceRequest, deviceResponseHandler, se);
this.iec61850DeviceConnectionService.disconnect(devCon, deviceRequest);
} catch (final Exception e) {
this.handleException(deviceRequest, deviceResponseHandler, e);
this.iec61850DeviceConnectionService.disconnect(devCon, deviceRequest);
}
}
use of com.alliander.osgp.dto.valueobjects.DeviceStatusDto in project Protocol-Adapter-OSLP by OSGP.
the class OslpDeviceService method handleOslpResponseGetStatus.
private void handleOslpResponseGetStatus(final DeviceRequest deviceRequest, final OslpEnvelope oslpResponse, final DeviceResponseHandler deviceResponseHandler) {
this.saveOslpResponseLogEntry(deviceRequest, oslpResponse);
this.updateSequenceNumber(deviceRequest.getDeviceIdentification(), oslpResponse);
DeviceStatusDto deviceStatus = null;
if (oslpResponse.getPayloadMessage().hasGetStatusResponse()) {
final Oslp.GetStatusResponse getStatusResponse = oslpResponse.getPayloadMessage().getGetStatusResponse();
final Oslp.Status oslpStatus = getStatusResponse.getStatus();
if (oslpStatus == Oslp.Status.OK) {
// Required properties.
final List<LightValueDto> lightValues = this.mapper.mapAsList(getStatusResponse.getValueList(), LightValueDto.class);
final LinkTypeDto preferredType = getStatusResponse.getPreferredLinktype().equals(Oslp.LinkType.LINK_NOT_SET) ? null : this.mapper.map(getStatusResponse.getPreferredLinktype(), LinkTypeDto.class);
final LinkTypeDto actualLinkType = getStatusResponse.getActualLinktype().equals(Oslp.LinkType.LINK_NOT_SET) ? null : this.mapper.map(getStatusResponse.getActualLinktype(), LinkTypeDto.class);
final LightTypeDto lightType = getStatusResponse.getLightType().equals(Oslp.LightType.LT_NOT_SET) ? null : this.mapper.map(getStatusResponse.getLightType(), LightTypeDto.class);
final int eventNotificationMask = getStatusResponse.getEventNotificationMask();
deviceStatus = new DeviceStatusDto(lightValues, preferredType, actualLinkType, lightType, eventNotificationMask);
// Optional properties.
if (getStatusResponse.hasBootLoaderVersion()) {
deviceStatus.setBootLoaderVersion(getStatusResponse.getBootLoaderVersion());
}
if (getStatusResponse.getCurrentConfigurationBackUsed() != null && getStatusResponse.getCurrentConfigurationBackUsed().toByteArray().length == 1) {
deviceStatus.setCurrentConfigurationBackUsed(this.convertCurrentConfigurationBankUsed(getStatusResponse.getCurrentConfigurationBackUsed()));
}
if (getStatusResponse.hasCurrentIp()) {
deviceStatus.setCurrentIp(getStatusResponse.getCurrentIp());
}
if (getStatusResponse.hasCurrentTime()) {
deviceStatus.setCurrentTime(getStatusResponse.getCurrentTime());
}
if (getStatusResponse.hasDcOutputVoltageCurrent()) {
deviceStatus.setDcOutputVoltageCurrent(getStatusResponse.getDcOutputVoltageCurrent());
}
if (getStatusResponse.hasDcOutputVoltageMaximum()) {
deviceStatus.setDcOutputVoltageMaximum(getStatusResponse.getDcOutputVoltageMaximum());
}
if (getStatusResponse.hasEventNotificationMask()) {
deviceStatus.setEventNotificationsMask(getStatusResponse.getEventNotificationMask());
}
if (getStatusResponse.hasExternalFlashMemSize()) {
deviceStatus.setExternalFlashMemSize(getStatusResponse.getExternalFlashMemSize());
}
if (getStatusResponse.hasFirmwareVersion()) {
deviceStatus.setFirmwareVersion(getStatusResponse.getFirmwareVersion());
}
if (getStatusResponse.hasHardwareId()) {
deviceStatus.setHardwareId(getStatusResponse.getHardwareId());
}
if (getStatusResponse.hasInternalFlashMemSize()) {
deviceStatus.setInternalFlashMemSize(getStatusResponse.getInternalFlashMemSize());
}
if (getStatusResponse.hasLastInternalTestResultCode()) {
deviceStatus.setLastInternalTestResultCode(getStatusResponse.getLastInternalTestResultCode());
}
if (getStatusResponse.getMacAddress() != null && !getStatusResponse.getMacAddress().isEmpty()) {
deviceStatus.setMacAddress(this.convertMacAddress(getStatusResponse.getMacAddress()));
}
if (getStatusResponse.hasMaximumOutputPowerOnDcOutput()) {
deviceStatus.setMaximumOutputPowerOnDcOutput(getStatusResponse.getMaximumOutputPowerOnDcOutput());
}
if (getStatusResponse.hasName()) {
deviceStatus.setName(getStatusResponse.getName());
}
if (getStatusResponse.hasNumberOfOutputs()) {
deviceStatus.setNumberOfOutputs(getStatusResponse.getNumberOfOutputs());
}
if (getStatusResponse.hasSerialNumber()) {
deviceStatus.setSerialNumber(this.convertSerialNumber(getStatusResponse.getSerialNumber()));
}
if (getStatusResponse.hasStartupCounter()) {
deviceStatus.setStartupCounter(getStatusResponse.getStartupCounter());
}
} else {
// handle failure by throwing exceptions if needed
LOGGER.error("Unable to convert Oslp.GetStatusResponse");
}
}
final DeviceResponse deviceResponse = new GetStatusDeviceResponse(deviceRequest.getOrganisationIdentification(), deviceRequest.getDeviceIdentification(), deviceRequest.getCorrelationUid(), deviceStatus);
deviceResponseHandler.handleResponse(deviceResponse);
}
use of com.alliander.osgp.dto.valueobjects.DeviceStatusDto in project Protocol-Adapter-OSLP by OSGP.
the class CommonGetStatusRequestMessageProcessor method handleGetStatusDeviceResponse.
private void handleGetStatusDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount) {
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException osgpException = null;
DeviceStatusDto status = null;
try {
final GetStatusDeviceResponse response = (GetStatusDeviceResponse) deviceResponse;
status = response.getDeviceStatus();
} catch (final Exception e) {
LOGGER.error("Device Response Exception", e);
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device status", e);
}
final DeviceMessageMetadata deviceMessageMetadata = new DeviceMessageMetadata(deviceResponse.getDeviceIdentification(), deviceResponse.getOrganisationIdentification(), deviceResponse.getCorrelationUid(), messageType, MessagePriorityEnum.DEFAULT.getPriority());
final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().domain(domain).domainVersion(domainVersion).deviceMessageMetadata(deviceMessageMetadata).result(result).osgpException(osgpException).dataObject(status).retryCount(retryCount).build();
responseMessageSender.send(responseMessage);
}
use of com.alliander.osgp.dto.valueobjects.DeviceStatusDto in project Protocol-Adapter-OSLP by OSGP.
the class PublicLightingGetStatusRequestMessageProcessor method handleGetStatusDeviceResponse.
private void handleGetStatusDeviceResponse(final DeviceResponse deviceResponse, final ResponseMessageSender responseMessageSender, final String domain, final String domainVersion, final String messageType, final int retryCount) {
ResponseMessageResultType result = ResponseMessageResultType.OK;
OsgpException osgpException = null;
DeviceStatusDto status = null;
try {
final GetStatusDeviceResponse response = (GetStatusDeviceResponse) deviceResponse;
status = response.getDeviceStatus();
} catch (final Exception e) {
LOGGER.error("Device Response Exception", e);
result = ResponseMessageResultType.NOT_OK;
osgpException = new TechnicalException(ComponentType.UNKNOWN, "Exception occurred while getting device status", e);
}
final DeviceMessageMetadata deviceMessageMetadata = new DeviceMessageMetadata(deviceResponse.getDeviceIdentification(), deviceResponse.getOrganisationIdentification(), deviceResponse.getCorrelationUid(), messageType, MessagePriorityEnum.DEFAULT.getPriority());
final ProtocolResponseMessage responseMessage = ProtocolResponseMessage.newBuilder().domain(domain).domainVersion(domainVersion).deviceMessageMetadata(deviceMessageMetadata).result(result).osgpException(osgpException).dataObject(status).retryCount(retryCount).build();
responseMessageSender.send(responseMessage);
}
Aggregations