Search in sources :

Example 1 with AdsField

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);
}
Also used : DirectAdsField(org.apache.plc4x.java.ads.model.DirectAdsField) PlcIoException(org.apache.plc4x.java.api.exceptions.PlcIoException) PlcWriteRequest(org.apache.plc4x.java.api.messages.PlcWriteRequest) PlcRequest(org.apache.plc4x.java.api.messages.PlcRequest) LoggerFactory(org.slf4j.LoggerFactory) PlcValue(org.apache.plc4x.java.api.value.PlcValue) ConcurrentMap(java.util.concurrent.ConcurrentMap) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) AdsException(org.apache.plc4x.java.ads.protocol.exception.AdsException) PlcException(org.apache.plc4x.java.api.exceptions.PlcException) PlcReadRequest(org.apache.plc4x.java.api.messages.PlcReadRequest) LittleEndianEncoder.encodeData(org.apache.plc4x.java.ads.protocol.util.LittleEndianEncoder.encodeData) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) PlcResponseCode(org.apache.plc4x.java.api.types.PlcResponseCode) org.apache.plc4x.java.ads.api.commands(org.apache.plc4x.java.ads.api.commands) PlcList(org.apache.plc4x.java.api.value.PlcList) LinkedList(java.util.LinkedList) AdsDataType(org.apache.plc4x.java.ads.model.AdsDataType) Invoke(org.apache.plc4x.java.ads.api.generic.types.Invoke) PlcProtocolException(org.apache.plc4x.java.api.exceptions.PlcProtocolException) AmsPacket(org.apache.plc4x.java.ads.api.generic.AmsPacket) Logger(org.slf4j.Logger) AmsNetId(org.apache.plc4x.java.ads.api.generic.types.AmsNetId) PlcProtocolPayloadTooBigException(org.apache.plc4x.java.api.exceptions.PlcProtocolPayloadTooBigException) org.apache.plc4x.java.ads.api.commands.types(org.apache.plc4x.java.ads.api.commands.types) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) org.apache.plc4x.java.spi.messages(org.apache.plc4x.java.spi.messages) SymbolicAdsField(org.apache.plc4x.java.ads.model.SymbolicAdsField) Collectors(java.util.stream.Collectors) PlcField(org.apache.plc4x.java.api.model.PlcField) MessageToMessageCodec(io.netty.handler.codec.MessageToMessageCodec) Consumer(java.util.function.Consumer) AtomicLong(java.util.concurrent.atomic.AtomicLong) List(java.util.List) AmsPort(org.apache.plc4x.java.ads.api.generic.types.AmsPort) AdsField(org.apache.plc4x.java.ads.model.AdsField) PlcValue(org.apache.plc4x.java.api.value.PlcValue) DirectAdsField(org.apache.plc4x.java.ads.model.DirectAdsField) SymbolicAdsField(org.apache.plc4x.java.ads.model.SymbolicAdsField) AdsField(org.apache.plc4x.java.ads.model.AdsField) PlcResponseCode(org.apache.plc4x.java.api.types.PlcResponseCode) Pair(org.apache.commons.lang3.tuple.Pair)

Aggregations

ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 MessageToMessageCodec (io.netty.handler.codec.MessageToMessageCodec)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 Consumer (java.util.function.Consumer)1 Collectors (java.util.stream.Collectors)1 Pair (org.apache.commons.lang3.tuple.Pair)1 org.apache.plc4x.java.ads.api.commands (org.apache.plc4x.java.ads.api.commands)1 org.apache.plc4x.java.ads.api.commands.types (org.apache.plc4x.java.ads.api.commands.types)1 AmsPacket (org.apache.plc4x.java.ads.api.generic.AmsPacket)1 AmsNetId (org.apache.plc4x.java.ads.api.generic.types.AmsNetId)1 AmsPort (org.apache.plc4x.java.ads.api.generic.types.AmsPort)1 Invoke (org.apache.plc4x.java.ads.api.generic.types.Invoke)1 AdsDataType (org.apache.plc4x.java.ads.model.AdsDataType)1 AdsField (org.apache.plc4x.java.ads.model.AdsField)1