Search in sources :

Example 6 with DeviceConnection

use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection in project open-smart-grid-platform by OSGP.

the class AbstractMessageProcessor method processMessage.

@Override
public void processMessage(final ObjectMessage message) {
    LOGGER.info("Processing message.");
    MessageMetadata messageMetadata = null;
    try {
        messageMetadata = MessageMetadata.fromMessage(message);
        final RequestMetadata requestMetadata = RequestMetadata.newBuilder().messageMetadata(messageMetadata).build();
        final ClientConnection deviceConnection = this.iec60870DeviceConnectionService.getConnection(requestMetadata);
        this.process(deviceConnection, requestMetadata);
    } catch (final ProtocolAdapterException e) {
        this.handleError(messageMetadata, e);
    } catch (final Exception e) {
        LOGGER.error("UNRECOVERABLE ERROR, unable to read ObjectMessage instance, giving up.", e);
    }
}
Also used : MessageMetadata(org.opensmartgridplatform.shared.infra.jms.MessageMetadata) ClientConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnection) ProtocolAdapterException(org.opensmartgridplatform.shared.exceptionhandling.ProtocolAdapterException) ProtocolAdapterException(org.opensmartgridplatform.shared.exceptionhandling.ProtocolAdapterException) JMSException(javax.jms.JMSException) RequestMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata)

Example 7 with DeviceConnection

use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection in project open-smart-grid-platform by OSGP.

the class GeneralInterrogationService method sendGeneralInterrogation.

public void sendGeneralInterrogation(final ClientConnection deviceConnection, final RequestMetadata requestMetadata) throws IOException {
    final String connectedDevice = deviceConnection.getConnectionParameters().getDeviceIdentification();
    final int commonAddress = deviceConnection.getConnectionParameters().getCommonAddress();
    deviceConnection.getConnection().interrogation(commonAddress, CauseOfTransmission.ACTIVATION, new IeQualifierOfInterrogation(QUALIFIER_OF_INTERROGATION_ID));
    // interrogation command creates this asdu internally, however we
    // need it here as well for logging...
    final ASdu asdu = new ASdu(ASduType.C_IC_NA_1, false, CauseOfTransmission.ACTIVATION, false, false, ORIGINATOR_ADDRESS, commonAddress, new InformationObject(0, new IeQualifierOfInterrogation(QUALIFIER_OF_INTERROGATION_ID)));
    final LogItem logItem = new LogItem(connectedDevice, requestMetadata.getOrganisationIdentification(), false, asdu.toString());
    this.loggingService.log(logItem);
}
Also used : LogItem(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.LogItem) IeQualifierOfInterrogation(org.openmuc.j60870.ie.IeQualifierOfInterrogation) ASdu(org.openmuc.j60870.ASdu) InformationObject(org.openmuc.j60870.ie.InformationObject)

Example 8 with DeviceConnection

use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection in project open-smart-grid-platform by OSGP.

the class GetLightSensorStatusRequestMessageProcessorTest method testProcessShouldSendGeneralInInterrogation.

@Test
void testProcessShouldSendGeneralInInterrogation() throws Exception {
    // Arrange
    final ConnectionParameters connectionParameters = ConnectionParameters.newBuilder().deviceIdentification(GATEWAY_IDENTIFICATION).build();
    final DeviceConnection deviceConnection = new DeviceConnection(this.connection, connectionParameters);
    final RequestMetadata requestMetadata = RequestMetadataFactory.forDevice(DEVICE_IDENTIFICATION);
    // Act
    this.getLightSensorStatusRequestMessageProcessor.process(deviceConnection, requestMetadata);
    // Assert
    verify(this.generalInterrogationService).sendGeneralInterrogation(deviceConnection, requestMetadata);
}
Also used : ConnectionParameters(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ConnectionParameters) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) RequestMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata) Test(org.junit.jupiter.api.Test)

Example 9 with DeviceConnection

use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection in project open-smart-grid-platform by OSGP.

the class ClientConnectionFactory method forDevice.

public static ClientConnection forDevice(final String deviceIdentification) {
    final Connection connection = Mockito.mock(Connection.class);
    final ConnectionParameters connectionParameters = new ConnectionParameters.Builder().deviceIdentification(deviceIdentification).build();
    return new DeviceConnection(connection, connectionParameters);
}
Also used : ClientConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnection) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) Connection(org.openmuc.j60870.Connection) ConnectionParameters(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ConnectionParameters) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection)

Example 10 with DeviceConnection

use of org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection in project open-smart-grid-platform by OSGP.

the class GeneralInterrogationServiceTest method testSendGeneralInterrogationShouldLogSameAsduAsUsedInInterrogation.

/**
 * Test method for {@link
 * org.opensmartgridplatform.adapter.protocol.iec60870.infra.messaging.processors.ConnectRequestMessageProcessor#process(org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnection,
 * org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata)}.
 *
 * @throws Exception
 */
@Test
void testSendGeneralInterrogationShouldLogSameAsduAsUsedInInterrogation() throws Exception {
    // Arrange
    final ConnectionParameters connectionParameters = ConnectionParameters.newBuilder().deviceIdentification(DEVICE_IDENTIFICATION).build();
    final DeviceConnection deviceConnection = new DeviceConnection(this.connection, connectionParameters);
    final RequestMetadata requestMetadata = RequestMetadataFactory.forDevice(DEVICE_IDENTIFICATION);
    doCallRealMethod().when(this.connection).interrogation(anyInt(), any(CauseOfTransmission.class), any(IeQualifierOfInterrogation.class));
    // Act
    this.generalInterrogationService.sendGeneralInterrogation(deviceConnection, requestMetadata);
    // Assert
    final ArgumentCaptor<ASdu> asduCaptor = ArgumentCaptor.forClass(ASdu.class);
    final ArgumentCaptor<LogItem> logItemCaptor = ArgumentCaptor.forClass(LogItem.class);
    verify(this.connection).send(asduCaptor.capture());
    verify(this.loggingService).log(logItemCaptor.capture());
    assertThat(logItemCaptor.getValue().getMessage()).isEqualTo(asduCaptor.getValue().toString());
}
Also used : CauseOfTransmission(org.openmuc.j60870.CauseOfTransmission) LogItem(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.LogItem) ConnectionParameters(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ConnectionParameters) DeviceConnection(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection) IeQualifierOfInterrogation(org.openmuc.j60870.ie.IeQualifierOfInterrogation) ASdu(org.openmuc.j60870.ASdu) RequestMetadata(org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata) Test(org.junit.jupiter.api.Test)

Aggregations

DeviceConnection (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.DeviceConnection)9 ConnectionParameters (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ConnectionParameters)5 Connection (org.openmuc.j60870.Connection)4 RequestMetadata (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.RequestMetadata)4 Test (org.junit.jupiter.api.Test)3 IeQualifierOfInterrogation (org.openmuc.j60870.ie.IeQualifierOfInterrogation)3 ClientConnection (org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnection)3 ClientConnectionEventListener (org.opensmartgridplatform.adapter.protocol.iec60870.domain.services.ClientConnectionEventListener)3 Given (io.cucumber.java.en.Given)2 ASdu (org.openmuc.j60870.ASdu)2 LogItem (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.LogItem)2 ConnectionFailureException (org.opensmartgridplatform.shared.exceptionhandling.ConnectionFailureException)2 Then (io.cucumber.java.en.Then)1 When (io.cucumber.java.en.When)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 JMSException (javax.jms.JMSException)1 CauseOfTransmission (org.openmuc.j60870.CauseOfTransmission)1 ClientConnectionBuilder (org.openmuc.j60870.ClientConnectionBuilder)1 ConnectionEventListener (org.openmuc.j60870.ConnectionEventListener)1