use of org.apache.plc4x.java.firmata.readwrite.field.FirmataField in project plc4x by apache.
the class FirmataProtocolLogic method subscribe.
@Override
public CompletableFuture<PlcSubscriptionResponse> subscribe(PlcSubscriptionRequest subscriptionRequest) {
CompletableFuture<PlcSubscriptionResponse> future = new CompletableFuture<>();
try {
final List<FirmataMessage> firmataMessages = ((FirmataDriverContext) getDriverContext()).processSubscriptionRequest(subscriptionRequest);
for (FirmataMessage firmataMessage : firmataMessages) {
context.sendToWire(firmataMessage);
}
Map<String, ResponseItem<PlcSubscriptionHandle>> result = new HashMap<>();
for (String fieldName : subscriptionRequest.getFieldNames()) {
DefaultPlcSubscriptionField subscriptionField = (DefaultPlcSubscriptionField) subscriptionRequest.getField(fieldName);
FirmataField field = (FirmataField) subscriptionField.getPlcField();
result.put(fieldName, new ResponseItem<>(PlcResponseCode.OK, new FirmataSubscriptionHandle(this, fieldName, field)));
}
future.complete(new DefaultPlcSubscriptionResponse(subscriptionRequest, result));
} catch (PlcRuntimeException e) {
future.completeExceptionally(e);
}
return future;
}
Aggregations