use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata in project open-smart-grid-platform by OSGP.
the class ConnectionSteps method givenIec60870DeviceIsConnected.
@Given("an existing connection with IEC60870 device {string} of type {deviceType}")
public void givenIec60870DeviceIsConnected(final String deviceIdentification, final DeviceType deviceType) throws Exception {
LOGGER.debug("Given an existing connection with IEC60870 device {} of type {}", deviceIdentification, deviceType);
// Make sure the connection event listener works as expected
this.connectionParameters = this.initConnectionParameters(deviceIdentification);
final ResponseMetadata responseMetadata = this.initResponseMetadata(deviceIdentification, deviceType);
this.connectionEventListener = new ClientConnectionEventListener.Builder().withDeviceIdentification(deviceIdentification).withClientAsduHandlerRegistry(this.clientAsduHandlerRegistry).withClientConnectionCache(this.connectionCacheSpy).withLoggingService(this.loggingService).withLogItemFactory(this.logItemFactory).withResponseMetadata(responseMetadata).withResponseMetadataFactory(this.responseMetadataFactory).build();
// Make sure a connection could be retrieved from the cache
// Only needed for scenarios sending requests to a device
// final Connection connection = mock(Connection.class);
this.connectionCacheSpy.addConnection(deviceIdentification, new DeviceConnection(this.connection, this.connectionParameters));
}
use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata in project open-smart-grid-platform by OSGP.
the class ClientConnectionEventListener method newASdu.
@Override
public void newASdu(final ASdu asdu) {
LOGGER.info("Received incoming ASDU from device {}:\n{}", this.deviceIdentification, asdu);
try {
final ResponseMetadata newResponseMetadata = this.responseMetadataFactory.createWithNewCorrelationUid(this.responseMetadata);
final LogItem logItem = this.logItemFactory.create(asdu, this.deviceIdentification, newResponseMetadata.getOrganisationIdentification(), true);
this.loggingService.log(logItem);
final ClientAsduHandler asduHandler = this.asduHandlerRegistry.getHandler(asdu);
asduHandler.handleAsdu(asdu, newResponseMetadata);
} catch (final Iec60870AsduHandlerNotFoundException e) {
LOGGER.error("Unknown request received, no handler available for ASDU: {}", asdu, e);
} catch (final Exception e) {
LOGGER.error("Exception occurred while handling an incoming ASDU from device {}.", this.deviceIdentification, e);
}
}
use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata in project open-smart-grid-platform by OSGP.
the class SinglePointInformationWithTimeTagAsduHandler method handleAsdu.
@Override
public void handleAsdu(final ASdu asdu, final ResponseMetadata responseMetadata) {
LOGGER.debug("Received asdu {} for device {}.", asdu, responseMetadata.getDeviceIdentification());
final MeasurementReportDto measurementReportDto = this.converter.convert(asdu);
final DeviceResponseService deviceResponseService = this.deviceResponseServiceRegistry.forDeviceType(responseMetadata.getDeviceType());
if (CauseOfTransmission.SPONTANEOUS == asdu.getCauseOfTransmission()) {
deviceResponseService.processEvent(measurementReportDto, responseMetadata);
} else {
deviceResponseService.process(measurementReportDto, responseMetadata);
}
}
use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata in project open-smart-grid-platform by OSGP.
the class LightSensorDeviceResponseService method sendLightSensorStatus.
private void sendLightSensorStatus(final String correlationUid, final LightSensorStatusDto lightSensorStatus, final String deviceIdentification, final ResponseMetadata responseMetadata) {
final ResponseMetadata rm = new ResponseMetadata.Builder().withCorrelationUid(correlationUid).withDeviceIdentification(deviceIdentification).withDomainInfo(responseMetadata.getDomainInfo()).withMessageType(MessageType.GET_LIGHT_SENSOR_STATUS.name()).withOrganisationIdentification(responseMetadata.getOrganisationIdentification()).build();
this.lightMeasurementService.sendSensorStatus(lightSensorStatus, rm);
}
use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata in project open-smart-grid-platform by OSGP.
the class SinglePointWithQualityAsduHandlerTest method testHandleAsduShouldSendMeasurementReport.
/**
* Test method for {@link
* org.opensmartgridplatform.adapter.protocol.iec60870.domain.lightmeasurement.asduhandlers.SinglePointWithQualityAsduHandler#handleAsdu(org.openmuc.j60870.ASdu,
* org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata)}.
*
* @throws Exception
*/
@Test
void testHandleAsduShouldSendMeasurementReport() throws Exception {
// Arrange
when(this.deviceResponseServiceMap.forDeviceType(DeviceType.LIGHT_MEASUREMENT_RTU)).thenReturn(this.deviceResponseService);
final ASdu asdu = this.createAsdu();
final ResponseMetadata responseMetadata = this.createResponseMetadata();
final MeasurementReportDto measurementReport = this.createMeasurementReportDto();
when(this.converterService.convert(asdu)).thenReturn(measurementReport);
when(this.deviceResponseServiceMap.forDeviceType(GATEWAY_DEVICE_TYPE)).thenReturn(this.deviceResponseService);
// Act
this.asduHandler.handleAsdu(asdu, responseMetadata);
// Assert
verify(this.deviceResponseService).process(any(MeasurementReportDto.class), eq(responseMetadata));
}
Aggregations