Search in sources :

Example 16 with ASdu

use of org.openmuc.j60870.ASdu in project open-smart-grid-platform by OSGP.

the class Iec60870ConnectionEventListener method newASdu.

@Override
public void newASdu(final ASdu asdu) {
    try {
        final ASduType asduType = asdu.getTypeIdentification();
        final Iec60870AsduHandler asduHandler = this.iec60870AsduHandlerRegistry.getHandler(asduType);
        asduHandler.handleAsdu(this.connection, asdu);
    } catch (final Iec60870AsduHandlerNotFoundException e) {
        LOGGER.error("Unknown request received, no handler available for ASDU: {}", asdu, e);
    } catch (final EOFException e) {
        LOGGER.error("Connection closed on connection ({}).", this.connection, e);
    } catch (final Exception e) {
        LOGGER.error("Exception occurred on connection ({}).", this.connection, e);
    }
}
Also used : ASduType(org.openmuc.j60870.ASduType) EOFException(java.io.EOFException) Iec60870AsduHandlerNotFoundException(org.opensmartgridplatform.iec60870.exceptions.Iec60870AsduHandlerNotFoundException) IOException(java.io.IOException) EOFException(java.io.EOFException) Iec60870AsduHandlerNotFoundException(org.opensmartgridplatform.iec60870.exceptions.Iec60870AsduHandlerNotFoundException)

Example 17 with ASdu

use of org.openmuc.j60870.ASdu in project open-smart-grid-platform by OSGP.

the class Iec60870ServerEventListener method sendInformationUpdateEvent.

public void sendInformationUpdateEvent(final int informationObjectAddress, final InformationElement[][] informationElements) {
    final ASdu event = new ASdu(ASduType.M_SP_TB_1, false, CauseOfTransmission.SPONTANEOUS, false, false, 0, 0, new InformationObject(informationObjectAddress, informationElements));
    this.iec60870ConnectionRegistry.getAllConnections().forEach(connection -> this.sendEvent(connection, event));
}
Also used : ASdu(org.openmuc.j60870.ASdu) InformationObject(org.openmuc.j60870.ie.InformationObject)

Example 18 with ASdu

use of org.openmuc.j60870.ASdu 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 19 with ASdu

use of org.openmuc.j60870.ASdu in project open-smart-grid-platform by OSGP.

the class Iec60870InterrogationCommandAsduHandler method handleAsdu.

@Override
public void handleAsdu(final Connection connection, final ASdu asdu) throws IOException {
    LOGGER.info("Received interrogation command. Sending confirmation for ASDU: {}", asdu);
    connection.sendConfirmation(asdu);
    final ASdu responseAsdu = this.iec60870AsduFactory.createInterrogationCommandResponseAsdu();
    LOGGER.info("Processing interrogation command. Sending response ASDU: {}.", responseAsdu);
    connection.send(responseAsdu);
    final ASdu terminationAsdu = this.iec60870AsduFactory.createActivationTerminationResponseAsdu();
    LOGGER.info("Finished processing interrogation command. Sending termination ASDU: {}", terminationAsdu);
    connection.send(terminationAsdu);
}
Also used : ASdu(org.openmuc.j60870.ASdu)

Example 20 with ASdu

use of org.openmuc.j60870.ASdu in project open-smart-grid-platform by OSGP.

the class DefaultControlledStationAsduFactoryTest method testCreateInterrogationCommandResponse.

@Test
void testCreateInterrogationCommandResponse() {
    // Arrange
    this.iec60870AsduFactory.initialize();
    final InformationObject[] expectedInformationObjects = new InformationObject[2];
    expectedInformationObjects[0] = new InformationObject(9127, this.createInformationElement(10.0f));
    expectedInformationObjects[1] = new InformationObject(9128, this.createInformationElement(20.5f));
    final ASdu expected = new ASdu(ASduType.M_ME_NC_1, false, CauseOfTransmission.INTERROGATED_BY_STATION, false, false, 0, 1, expectedInformationObjects);
    // Act
    final ASdu actual = this.iec60870AsduFactory.createInterrogationCommandResponseAsdu();
    // Assert
    assertThat(actual).usingRecursiveComparison().isEqualTo(expected);
}
Also used : InformationObject(org.openmuc.j60870.ie.InformationObject) ASdu(org.openmuc.j60870.ASdu) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ASdu (org.openmuc.j60870.ASdu)20 Test (org.junit.jupiter.api.Test)14 InformationObject (org.openmuc.j60870.ie.InformationObject)9 LogItem (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.LogItem)3 MeasurementReportDto (org.opensmartgridplatform.dto.da.measurements.MeasurementReportDto)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 When (io.cucumber.java.en.When)2 ASduType (org.openmuc.j60870.ASduType)2 IeQualifierOfInterrogation (org.openmuc.j60870.ie.IeQualifierOfInterrogation)2 ResponseMetadata (org.opensmartgridplatform.adapter.protocol.iec60870.domain.valueobjects.ResponseMetadata)2 Iec60870AsduHandlerNotFoundException (org.opensmartgridplatform.iec60870.exceptions.Iec60870AsduHandlerNotFoundException)2 Iec60870AsduBuilder (org.opensmartgridplatform.simulator.protocol.iec60870.domain.Iec60870AsduBuilder)2 EOFException (java.io.EOFException)1 IOException (java.io.IOException)1 ZonedDateTime (java.time.ZonedDateTime)1 Random (java.util.Random)1 InOrder (org.mockito.InOrder)1 CauseOfTransmission (org.openmuc.j60870.CauseOfTransmission)1 Connection (org.openmuc.j60870.Connection)1 ConnectionEventListener (org.openmuc.j60870.ConnectionEventListener)1