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();
}
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);
}
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();
}
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);
}
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);
}
Aggregations