Search in sources :

Example 1 with EventNotification

use of org.opensmartgridplatform.oslp.Oslp.EventNotification in project open-smart-grid-platform by OSGP.

the class OslpDeviceSteps method receivingAnOslpEventNotificationMessage.

/**
 * Simulates sending an OSLP EventNotification message to the OSLP Protocol adapter.
 *
 * @throws DeviceSimulatorException
 * @throws IOException
 * @throws ParseException
 */
@When("^receiving an \"([^\"]*)\" event notification message$")
public void receivingAnOslpEventNotificationMessage(final String protocol, final Map<String, String> settings) throws DeviceSimulatorException, IOException, ParseException {
    final EventNotification eventNotification = EventNotification.newBuilder().setDescription(getString(settings, PlatformPubliclightingKeys.KEY_DESCRIPTION, "")).setEvent(getEnum(settings, PlatformPubliclightingKeys.KEY_EVENT, Event.class)).build();
    final Message message = Oslp.Message.newBuilder().setEventNotificationRequest(EventNotificationRequest.newBuilder().addNotifications(eventNotification)).build();
    // Save the OSLP response for later validation.
    ScenarioContext.current().put(PlatformPubliclightingKeys.RESPONSE, this.oslpMockServer.sendRequest(this.getDeviceUid(settings), message));
}
Also used : EventNotification(org.opensmartgridplatform.oslp.Oslp.EventNotification) Message(org.opensmartgridplatform.oslp.Oslp.Message) When(io.cucumber.java.en.When)

Example 2 with EventNotification

use of org.opensmartgridplatform.oslp.Oslp.EventNotification in project open-smart-grid-platform by OSGP.

the class RegisterDevice method createEventNotificationRequest.

private OslpEnvelope createEventNotificationRequest(final Device device, final int sequenceNumber, final Event event) {
    final String deviceUid = device.getDeviceUid();
    final Oslp.Event oslpEvent = event.getOslpEvent();
    final String description = event.getDescription();
    final Integer index = event.getIndex();
    final String timestamp = event.getTimestamp();
    final boolean hasTimestamp = event.hasTimestamp();
    // Create an event notification depending on device protocol (for now
    // with 1 event).
    Oslp.EventNotification eventNotification = null;
    if (device.getProtocol().equals(ProtocolType.OSLP.toString())) {
        eventNotification = EventNotification.newBuilder().setEvent(oslpEvent).setDescription(description == null ? "" : description).setIndex(ByteString.copyFrom(new byte[] { index == null ? 0 : index.byteValue() })).build();
    } else if (device.getProtocol().equals(ProtocolType.OSLP_ELSTER.toString())) {
        final Oslp.EventNotification.Builder builder = EventNotification.newBuilder();
        builder.setEvent(oslpEvent);
        if (StringUtils.isNotEmpty(description)) {
            builder.setDescription(description);
        }
        if (index != null) {
            builder.setIndex(ByteString.copyFrom(new byte[] { index.byteValue() }));
        }
        if (timestamp != null && hasTimestamp) {
            builder.setTimestamp(timestamp);
        }
        eventNotification = builder.build();
    }
    Assert.notNull(eventNotification, "Failed to create EventNotification. Is the protocol for the simulated device supported?");
    // Create event notification request.
    final Oslp.EventNotificationRequest eventNotificationRequest = Oslp.EventNotificationRequest.newBuilder().addNotifications(eventNotification).build();
    return this.createEnvelopeBuilder(deviceUid, sequenceNumber).withPayloadMessage(Message.newBuilder().setEventNotificationRequest(eventNotificationRequest).build()).build();
}
Also used : EventNotification(org.opensmartgridplatform.oslp.Oslp.EventNotification) ByteString(com.google.protobuf.ByteString) Oslp(org.opensmartgridplatform.oslp.Oslp)

Aggregations

EventNotification (org.opensmartgridplatform.oslp.Oslp.EventNotification)2 ByteString (com.google.protobuf.ByteString)1 When (io.cucumber.java.en.When)1 Oslp (org.opensmartgridplatform.oslp.Oslp)1 Message (org.opensmartgridplatform.oslp.Oslp.Message)1