Search in sources :

Example 1 with Iec60870AsduBuilder

use of org.opensmartgridplatform.simulator.protocol.iec60870.domain.Iec60870AsduBuilder in project open-smart-grid-platform by OSGP.

the class LightMeasurementDeviceAsduFactory method createLightMeasurementEvent.

public ASdu createLightMeasurementEvent() {
    final long timestamp = System.currentTimeMillis();
    final InformationObject[] informationObjects = new InformationObject[1];
    final int index = new Random().nextInt(this.ioa.length);
    this.switchValue(index);
    final String eventValue = this.iev[index] ? "DARK" : "LIGHT";
    LOGGER.info("Creating Light Measurement event for IOA {} with value {} ({})", this.ioa[index], this.iev[index], eventValue);
    informationObjects[0] = new InformationObject(this.ioa[index], this.createInformationElementWithTimetag(this.iev[index], timestamp));
    return new Iec60870AsduBuilder().withAsduType(ASduType.M_SP_TB_1).withSequenceOfElements(false).withCauseOfTransmission(CauseOfTransmission.SPONTANEOUS).withInformationObjects(informationObjects).build();
}
Also used : Random(java.util.Random) InformationObject(org.openmuc.j60870.ie.InformationObject) Iec60870AsduBuilder(org.opensmartgridplatform.simulator.protocol.iec60870.domain.Iec60870AsduBuilder)

Example 2 with Iec60870AsduBuilder

use of org.opensmartgridplatform.simulator.protocol.iec60870.domain.Iec60870AsduBuilder 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)

Aggregations

InformationObject (org.openmuc.j60870.ie.InformationObject)2 Iec60870AsduBuilder (org.opensmartgridplatform.simulator.protocol.iec60870.domain.Iec60870AsduBuilder)2 ZonedDateTime (java.time.ZonedDateTime)1 Random (java.util.Random)1