Search in sources :

Example 6 with ResponseMetadata

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));
}
Also used : DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) ResponseMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata) ClientConnectionEventListener(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnectionEventListener) Given(io.cucumber.java.en.Given)

Example 7 with ResponseMetadata

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);
    }
}
Also used : LogItem(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.LogItem) Iec60870AsduHandlerNotFoundException(org.opensmartgridplatform.iec60870.exceptions.Iec60870AsduHandlerNotFoundException) IOException(java.io.IOException) ResponseMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata) Iec60870AsduHandlerNotFoundException(org.opensmartgridplatform.iec60870.exceptions.Iec60870AsduHandlerNotFoundException)

Example 8 with ResponseMetadata

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);
    }
}
Also used : DeviceResponseService(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.DeviceResponseService) MeasurementReportDto(org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto)

Example 9 with 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);
}
Also used : ResponseMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata)

Example 10 with ResponseMetadata

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));
}
Also used : MeasurementReportDto(org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto) ASdu(org.openmuc.j60870.ASdu) ResponseMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata) Test(org.junit.jupiter.api.Test)

Aggregations

ResponseMetadata (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata)10 MeasurementReportDto (org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto)5 Test (org.junit.jupiter.api.Test)4 Iec60870Device (org.opensmartgridplatform.adapter.protocol.iec60870.domain.entities.Iec60870Device)3 ASdu (org.openmuc.j60870.ASdu)2 Given (io.cucumber.java.en.Given)1 IOException (java.io.IOException)1 ClientConnectionAlreadyInCacheException (org.opensmartgridplatform.adapter.protocol.iec60870.domain.exceptions.ClientConnectionAlreadyInCacheException)1 ClientConnectionEventListener (org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnectionEventListener)1 DeviceResponseService (org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.DeviceResponseService)1 ConnectionParameters (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ConnectionParameters)1 DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection)1 DomainInfo (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DomainInfo)1 LogItem (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.LogItem)1 Iec60870AsduHandlerNotFoundException (org.opensmartgridplatform.iec60870.exceptions.Iec60870AsduHandlerNotFoundException)1