Search in sources :

Example 1 with CANOpenHeartbeatField

use of org.apache.plc4x.java.canopen.field.CANOpenHeartbeatField in project plc4x by apache.

the class CANOpenProtocolLogic method subscribe.

@Override
public CompletableFuture<PlcSubscriptionResponse> subscribe(PlcSubscriptionRequest request) {
    DefaultPlcSubscriptionRequest rq = (DefaultPlcSubscriptionRequest) request;
    Map<String, ResponseItem<PlcSubscriptionHandle>> answers = new LinkedHashMap<>();
    DefaultPlcSubscriptionResponse response = new DefaultPlcSubscriptionResponse(rq, answers);
    for (String key : rq.getFieldNames()) {
        DefaultPlcSubscriptionField subscription = (DefaultPlcSubscriptionField) rq.getField(key);
        if (subscription.getPlcSubscriptionType() != PlcSubscriptionType.EVENT) {
            answers.put(key, new ResponseItem<>(PlcResponseCode.UNSUPPORTED, null));
        } else if ((subscription.getPlcField() instanceof CANOpenPDOField)) {
            answers.put(key, new ResponseItem<>(PlcResponseCode.OK, new CANOpenSubscriptionHandle(this, key, (CANOpenPDOField) subscription.getPlcField())));
        } else if ((subscription.getPlcField() instanceof CANOpenNMTField)) {
            answers.put(key, new ResponseItem<>(PlcResponseCode.OK, new CANOpenSubscriptionHandle(this, key, (CANOpenNMTField) subscription.getPlcField())));
        } else if ((subscription.getPlcField() instanceof CANOpenHeartbeatField)) {
            answers.put(key, new ResponseItem<>(PlcResponseCode.OK, new CANOpenSubscriptionHandle(this, key, (CANOpenHeartbeatField) subscription.getPlcField())));
        } else {
            answers.put(key, new ResponseItem<>(PlcResponseCode.INVALID_ADDRESS, null));
        }
    }
    return CompletableFuture.completedFuture(response);
}
Also used : DefaultPlcSubscriptionField(org.apache.plc4x.java.spi.model.DefaultPlcSubscriptionField) CANOpenPDOField(org.apache.plc4x.java.canopen.field.CANOpenPDOField) DefaultPlcSubscriptionResponse(org.apache.plc4x.java.spi.messages.DefaultPlcSubscriptionResponse) CANOpenNMTField(org.apache.plc4x.java.canopen.field.CANOpenNMTField) ResponseItem(org.apache.plc4x.java.spi.messages.utils.ResponseItem) DefaultPlcSubscriptionRequest(org.apache.plc4x.java.spi.messages.DefaultPlcSubscriptionRequest) LinkedHashMap(java.util.LinkedHashMap) CANOpenHeartbeatField(org.apache.plc4x.java.canopen.field.CANOpenHeartbeatField)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)1 CANOpenHeartbeatField (org.apache.plc4x.java.canopen.field.CANOpenHeartbeatField)1 CANOpenNMTField (org.apache.plc4x.java.canopen.field.CANOpenNMTField)1 CANOpenPDOField (org.apache.plc4x.java.canopen.field.CANOpenPDOField)1 DefaultPlcSubscriptionRequest (org.apache.plc4x.java.spi.messages.DefaultPlcSubscriptionRequest)1 DefaultPlcSubscriptionResponse (org.apache.plc4x.java.spi.messages.DefaultPlcSubscriptionResponse)1 ResponseItem (org.apache.plc4x.java.spi.messages.utils.ResponseItem)1 DefaultPlcSubscriptionField (org.apache.plc4x.java.spi.model.DefaultPlcSubscriptionField)1