use of org.opensmartgridplatform.dto.valueobjects.LightValueDto in project open-smart-grid-platform by OSGP.
the class Iec61850SetScheduleCommand method createScheduleEntries.
/**
* Returns a map of schedule entries, grouped by the internal index.
*/
private Map<Integer, List<ScheduleEntry>> createScheduleEntries(final List<ScheduleEntryDto> scheduleList, final Ssld ssld, final RelayTypeDto relayTypeDto) throws FunctionalException {
final Map<Integer, List<ScheduleEntry>> relaySchedulesEntries = new HashMap<>();
final RelayType relayType = RelayType.valueOf(relayTypeDto.name());
final List<DeviceOutputSetting> settings = this.ssldDataService.findByRelayType(ssld, relayType);
for (final ScheduleEntryDto schedule : scheduleList) {
for (final LightValueDto lightValue : schedule.getLightValue()) {
this.setScheduleEntry(ssld, relaySchedulesEntries, relayType, settings, schedule, lightValue);
}
}
return relaySchedulesEntries;
}
use of org.opensmartgridplatform.dto.valueobjects.LightValueDto in project open-smart-grid-platform by OSGP.
the class Iec61850SetLightCommand method switchLightRelays.
/**
* Switch one or more light relays of a switching device.
*
* @param iec61850Client The {@link Iec61850Client} instance.
* @param deviceConnection The {@link DeviceConnection} instance.
* @param relaysWithInternalIdToSwitch List of {@link LightValueDto}'s which represent the relays
* to switch on or off.
* @param functionName The name of the function reported to {@link DeviceMessageLog}.
* @throws ProtocolAdapterException In case the switch action(s) for light relays fail.
*/
public void switchLightRelays(final Iec61850Client iec61850Client, final DeviceConnection deviceConnection, final List<LightValueDto> relaysWithInternalIdToSwitch, final String functionName) throws ProtocolAdapterException {
final Function<Void> function = new Function<Void>() {
@Override
public Void apply(final DeviceMessageLog deviceMessageLog) throws ProtocolAdapterException {
for (final LightValueDto relayWithInternalIdToSwitch : relaysWithInternalIdToSwitch) {
final int index = relayWithInternalIdToSwitch.getIndex();
final boolean on = relayWithInternalIdToSwitch.isOn();
final String deviceIdentification = deviceConnection.getDeviceIdentification();
LOGGER.info("Trying to switch light relay with internal index: {} on: {} for device: {}", index, on, deviceIdentification);
try {
Iec61850SetLightCommand.this.switchLightRelay(iec61850Client, deviceConnection, deviceMessageLog, index, on);
} catch (final Exception e) {
LOGGER.error("Exception during switchLightRelay()", e);
throw new ProtocolAdapterException(String.format("Failed to switch light relay with internal index: %d for device: %s", relayWithInternalIdToSwitch.getIndex(), deviceConnection.getDeviceIdentification()));
}
}
Iec61850SetLightCommand.this.loggingService.logMessage(deviceMessageLog, deviceConnection.getDeviceIdentification(), deviceConnection.getOrganisationIdentification(), false);
return null;
}
};
iec61850Client.sendCommandWithRetry(function, StringUtils.isEmpty(functionName) ? "SetLight" : functionName, deviceConnection.getDeviceIdentification());
}
use of org.opensmartgridplatform.dto.valueobjects.LightValueDto in project open-smart-grid-platform 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 = this.getPreferredLinktype(getStatusResponse);
final LinkTypeDto actualLinkType = this.getActualLinktype(getStatusResponse);
final LightTypeDto lightType = this.getLightType(getStatusResponse);
final int eventNotificationMask = getStatusResponse.getEventNotificationMask();
deviceStatus = new DeviceStatusDto(lightValues, preferredType, actualLinkType, lightType, eventNotificationMask);
// Optional properties.
this.setBootLoaderVersion(deviceStatus, getStatusResponse);
this.setCurrentConfigurationBankUsed(deviceStatus, getStatusResponse);
this.setCurrentIp(deviceStatus, getStatusResponse);
this.setCurrentTime(deviceStatus, getStatusResponse);
this.setDcOutputVoltageCurrent(deviceStatus, getStatusResponse);
this.setDcOutputVoltageMaximum(deviceStatus, getStatusResponse);
this.setEventNotificationsMask(deviceStatus, getStatusResponse);
this.setExternalFlashMemSize(deviceStatus, getStatusResponse);
this.setFirmwareVersion(deviceStatus, getStatusResponse);
this.setHardwareId(deviceStatus, getStatusResponse);
this.setInternalFlashMemSize(deviceStatus, getStatusResponse);
this.setLastInternalTestResultCode(deviceStatus, getStatusResponse);
this.setMacAddress(deviceStatus, getStatusResponse);
this.setMaximumOutputPowerOnDcOutput(deviceStatus, getStatusResponse);
this.setName(deviceStatus, getStatusResponse);
this.setNumberOfOutputs(deviceStatus, getStatusResponse);
this.setSerialNumber(deviceStatus, getStatusResponse);
this.setStartupCounter(deviceStatus, getStatusResponse);
} else {
// handle failure by throwing exceptions if needed
LOGGER.error("Unable to convert Oslp.GetStatusResponse");
}
}
final DeviceResponse deviceResponse = new GetStatusDeviceResponse(deviceRequest, deviceStatus);
deviceResponseHandler.handleResponse(deviceResponse);
}
use of org.opensmartgridplatform.dto.valueobjects.LightValueDto in project open-smart-grid-platform 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());
LOGGER.info("Turning all lights relays {}", startOfTest ? "on" : "off");
final Iec61850SetLightCommand iec61850SetLightCommand = new Iec61850SetLightCommand(this.deviceMessageLoggingService);
final List<LightValueDto> relaysWithInternalIdToSwitch = this.createListOfInternalIndicesToSwitch(this.ssldDataService.findByRelayType(ssld, RelayType.LIGHT), startOfTest);
iec61850SetLightCommand.switchLightRelays(this.iec61850Client, deviceConnection, relaysWithInternalIdToSwitch, startOfTest ? "StartSelfTest" : "StopSelfTest");
// Sleep and wait.
this.selfTestSleep();
// Getting the status.
final DeviceStatusDto deviceStatus = new Iec61850GetStatusCommand(this.deviceMessageLoggingService).getStatusFromDevice(this.iec61850Client, deviceConnection, ssld);
LOGGER.info("Fetching and checking the devicestatus");
// Checking to see if all light relays have the correct state.
this.checkLightRelaysState(startOfTest, relaysWithInternalIdToSwitch, deviceStatus);
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 org.opensmartgridplatform.dto.valueobjects.LightValueDto in project open-smart-grid-platform by OSGP.
the class Iec61850SsldDeviceService method setLight.
@Override
public void setLight(final SetLightDeviceRequest 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 List<DeviceOutputSetting> deviceOutputSettings = this.ssldDataService.findByRelayType(ssld, RelayType.LIGHT);
final List<LightValueDto> lightValues = deviceRequest.getLightValuesContainer().getLightValues();
final List<LightValueDto> relaysWithInternalIdToSwitch;
// Check if external index 0 is used.
final LightValueDto index0LightValue = this.checkForIndex0(lightValues);
if (index0LightValue != null) {
// If external index 0 is used, create a list of all light
// relays according to the device output settings.
relaysWithInternalIdToSwitch = this.createListOfInternalIndicesToSwitch(deviceOutputSettings, index0LightValue.isOn());
} else {
// Else, create a list of internal indices based on the given
// external indices in the light values list.
relaysWithInternalIdToSwitch = this.createListOfInternalIndicesToSwitch(deviceOutputSettings, lightValues);
}
// Switch light relays based on internal indices.
final Iec61850SetLightCommand iec61850SetLightCommand = new Iec61850SetLightCommand(this.deviceMessageLoggingService);
iec61850SetLightCommand.switchLightRelays(this.iec61850Client, deviceConnection, relaysWithInternalIdToSwitch, null);
this.createSuccessfulDefaultResponse(deviceRequest, deviceResponseHandler);
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);
}
}
Aggregations