Search in sources :

Example 11 with ASdu

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

the class Iec60870InterrogationCommandAsduHandlerTest method testSendingOrder.

@Test
void testSendingOrder() throws IOException {
    // Arrange
    doNothing().when(this.connection).sendConfirmation(any(ASdu.class));
    final ASdu responseAsdu = this.getAsdu(ASduType.M_SP_NA_1, CauseOfTransmission.INTERROGATED_BY_STATION);
    when(this.iec60870AsduFactory.createInterrogationCommandResponseAsdu()).thenReturn(responseAsdu);
    final ASdu terminationAsdu = this.getAsdu(ASduType.C_IC_NA_1, CauseOfTransmission.ACTIVATION_TERMINATION);
    when(this.iec60870AsduFactory.createActivationTerminationResponseAsdu()).thenReturn(terminationAsdu);
    doNothing().when(this.connection).send(any(ASdu.class));
    final InOrder inOrder = inOrder(this.connection);
    // Act
    final Iec60870InterrogationCommandAsduHandler interrogationCommandHandler = new Iec60870InterrogationCommandAsduHandler(this.iec60870AsduFactory);
    interrogationCommandHandler.handleAsdu(this.connection, responseAsdu);
    // Assert
    inOrder.verify(this.connection).sendConfirmation(any(ASdu.class));
    inOrder.verify(this.connection).send(argThat(new AsduTypeArgumentMatcher(ASduType.M_SP_NA_1)));
    inOrder.verify(this.connection).send(argThat(new AsduTypeArgumentMatcher(ASduType.C_IC_NA_1, CauseOfTransmission.ACTIVATION_TERMINATION)));
    inOrder.verifyNoMoreInteractions();
}
Also used : InOrder(org.mockito.InOrder) AsduTypeArgumentMatcher(org.opensmartgridplatform.simulator.protocol.iec60870.server.AsduTypeArgumentMatcher) ASdu(org.openmuc.j60870.ASdu) Test(org.junit.jupiter.api.Test)

Example 12 with ASdu

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

the class LightMeasurementDeviceAsduFactoryTest method shouldCreateInterrogationCommandResponse.

@Test
void shouldCreateInterrogationCommandResponse() {
    // Arrange
    this.iec60870AsduFactory.initialize();
    final InformationObject[] expectedInformationObjects = new InformationObject[4];
    expectedInformationObjects[0] = new InformationObject(42, this.createInformationElement(false));
    expectedInformationObjects[1] = new InformationObject(78, this.createInformationElement(false));
    expectedInformationObjects[2] = new InformationObject(127, this.createInformationElement(true));
    expectedInformationObjects[3] = new InformationObject(95, this.createInformationElement(false));
    final ASdu expected = new ASdu(ASduType.M_SP_NA_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)

Example 13 with ASdu

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

the class DefaultControlledStationAsduFactory method createShortFloatingPointMeasurementAsdu.

public ASdu createShortFloatingPointMeasurementAsdu() {
    final ZonedDateTime now = ZonedDateTime.now(ZoneOffset.UTC);
    final long timestamp = now.toInstant().toEpochMilli();
    final float hour = now.getHour();
    final float minute = now.getMinute();
    final InformationObject[] informationObjects = new InformationObject[this.ioa.length];
    for (int index = 0; index < this.ioa.length; index++) {
        final float value = (index == 0 ? hour : minute);
        informationObjects[index] = new InformationObject(this.ioa[index], this.createInformationElementWithTimetag(value, timestamp));
    }
    return new Iec60870AsduBuilder().withAsduType(ASduType.M_ME_TF_1).withSequenceOfElements(false).withCauseOfTransmission(CauseOfTransmission.SPONTANEOUS).withInformationObjects(informationObjects).build();
}
Also used : ZonedDateTime(java.time.ZonedDateTime) InformationObject(org.openmuc.j60870.ie.InformationObject) Iec60870AsduBuilder(org.opensmartgridplatform.simulator.protocol.iec60870.domain.Iec60870AsduBuilder)

Example 14 with ASdu

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

the class AsduSteps method aLightMeasurementOccursForAddress.

@When("a light measurement event occurs for address {int} with value {string}")
public void aLightMeasurementOccursForAddress(final int informationObjectAddress, final String informationElementValue) {
    final boolean on = "ON".equalsIgnoreCase(informationElementValue);
    final InformationObject[] informationObjects = { new InformationObject(informationObjectAddress, new IeSinglePointWithQuality(on, false, false, false, false), new IeTime56(System.currentTimeMillis(), TimeZone.getDefault(), false)) };
    final ASdu asdu = new ASdu(ASduType.M_SP_TB_1, false, CauseOfTransmission.SPONTANEOUS, false, false, 0, 1, informationObjects);
    this.connectionSteps.getConnectionEventListener().newASdu(asdu);
}
Also used : IeSinglePointWithQuality(org.openmuc.j60870.ie.IeSinglePointWithQuality) IeTime56(org.openmuc.j60870.ie.IeTime56) InformationObject(org.openmuc.j60870.ie.InformationObject) ASdu(org.openmuc.j60870.ASdu) When(io.cucumber.java.en.When)

Example 15 with ASdu

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

the class AsduSteps method whenIReceiveAsduOfType.

@When("I receive an ASDU of type {string} from the IEC60870 device")
public void whenIReceiveAsduOfType(final String asduType) {
    LOGGER.debug("When I receive an ASDU of type {}", asduType);
    final ASdu asdu = AsduFactory.ofType(ASduType.valueOf(asduType));
    this.connectionSteps.getConnectionEventListener().newASdu(asdu);
}
Also used : ASdu(org.openmuc.j60870.ASdu) When(io.cucumber.java.en.When)

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