use of org.apache.plc4x.java.ads.model.AdsField in project plc4x by apache.
the class Plc4x2AdsProtocol method decodeReadResponse.
@SuppressWarnings("unchecked")
private InternalPlcResponse decodeReadResponse(AdsReadResponse responseMessage, PlcRequestContainer<InternalPlcRequest, InternalPlcResponse> requestContainer) {
InternalPlcReadRequest plcReadRequest = (InternalPlcReadRequest) requestContainer.getRequest();
// TODO: only single requests supported for now
AdsField field = (AdsField) plcReadRequest.getFields().get(0);
PlcResponseCode responseCode = decodeResponseCode(responseMessage.getResult());
byte[] bytes = responseMessage.getData().getBytes();
PlcValue value = decodeData(field.getAdsDataType(), bytes);
// TODO: does every item has the same ads response or is this whole aggregation broken?
Map<String, Pair<PlcResponseCode, PlcValue>> responseItems = plcReadRequest.getFieldNames().stream().collect(Collectors.toMap(fieldName -> fieldName, ignore -> Pair.of(responseCode, value)));
return new DefaultPlcReadResponse(plcReadRequest, responseItems);
}
Aggregations