@Test @Ignore("This test fails on Java 12 and above") public void decode() throws Exception { assumeThat(payloadClazzName + " not yet implemented", notYetSupportedDataType, not(hasItem(payloadClazzName))); ArrayList<Object> in = new ArrayList<>(); SUT.encode(null, plcRequestContainer, in); assertThat(in, hasSize(1)); syncInvoiceId(); ArrayList<Object> out = new ArrayList<>(); LOGGER.info("{}\nHexDump:\n{}", amsPacket, amsPacket.dump()); SUT.decode(null, amsPacket, out); assertThat(out, hasSize(0)); LOGGER.info("PlcRequestContainer {}", plcRequestContainer); InternalPlcResponse plcResponse = plcRequestContainer.getResponseFuture().get(); if (amsPacket instanceof AdsReadResponse) { } }
@Override protected void decode(ChannelHandlerContext channelHandlerContext, AmsPacket amsPacket, List<Object> out) throws Exception { LOGGER.trace("(-->IN): {}, {}, {}", channelHandlerContext, amsPacket, out); if (amsPacket instanceof AdsDeviceNotificationRequest) { LOGGER.debug("Received notification {}", amsPacket); handleAdsDeviceNotificationRequest((AdsDeviceNotificationRequest) amsPacket); return; } PlcRequestContainer<InternalPlcRequest, InternalPlcResponse> plcRequestContainer = requests.remove(amsPacket.getAmsHeader().getInvokeId().getAsLong()); if (plcRequestContainer == null) { LOGGER.info("Unmapped packet received {}", amsPacket); return; } PlcRequest request = plcRequestContainer.getRequest(); final InternalPlcResponse response; if (request instanceof PlcReadRequest) { if (amsPacket instanceof AdsReadResponse) { response = decodeReadResponse((AdsReadResponse) amsPacket, plcRequestContainer); } else { throw new PlcProtocolException("Wrong type correlated " + amsPacket); } } else if (request instanceof PlcWriteRequest) { if (amsPacket instanceof AdsWriteResponse) { response = decodeWriteResponse((AdsWriteResponse) amsPacket, plcRequestContainer); } else { throw new PlcProtocolException("Wrong type correlated " + amsPacket); } } else if (request instanceof PlcProprietaryRequest) { response = decodeProprietaryResponse(amsPacket, plcRequestContainer); } else { response = null; } LOGGER.debug("Plc4x response {}", response); if (response != null) { plcRequestContainer.getResponseFuture().complete(response); } }
Plc4x2AdsProtocol extends MessageToMessageCodec<AmsPacket, PlcRequestContainer<InternalPlcRequest, InternalPlcResponse>> { @Override protected void decode(ChannelHandlerContext channelHandlerContext, AmsPacket amsPacket, List<Object> out) throws Exception { LOGGER.trace("(-->IN): {}, {}, {}", channelHandlerContext, amsPacket, out); if (amsPacket instanceof AdsDeviceNotificationRequest) { LOGGER.debug("Received notification {}", amsPacket); handleAdsDeviceNotificationRequest((AdsDeviceNotificationRequest) amsPacket); return; } PlcRequestContainer<InternalPlcRequest, InternalPlcResponse> plcRequestContainer = requests.remove(amsPacket.getAmsHeader().getInvokeId().getAsLong()); if (plcRequestContainer == null) { LOGGER.info("Unmapped packet received {}", amsPacket); return; } PlcRequest request = plcRequestContainer.getRequest(); final InternalPlcResponse response; if (request instanceof PlcReadRequest) { if (amsPacket instanceof AdsReadResponse) { response = decodeReadResponse((AdsReadResponse) amsPacket, plcRequestContainer); } else { throw new PlcProtocolException("Wrong type correlated " + amsPacket); } } else if (request instanceof PlcWriteRequest) { if (amsPacket instanceof AdsWriteResponse) { response = decodeWriteResponse((AdsWriteResponse) amsPacket, plcRequestContainer); } else { throw new PlcProtocolException("Wrong type correlated " + amsPacket); } } else if (request instanceof PlcProprietaryRequest) { response = decodeProprietaryResponse(amsPacket, plcRequestContainer); } else { response = null; } LOGGER.debug("Plc4x response {}", response); if (response != null) { plcRequestContainer.getResponseFuture().complete(response); } } }
Plc4x2AdsProtocol extends MessageToMessageCodec<AmsPacket, PlcRequestContainer<InternalPlcRequest, InternalPlcResponse>> { @Override protected void decode(ChannelHandlerContext channelHandlerContext, AmsPacket amsPacket, List<Object> out) throws Exception { LOGGER.trace("(-->IN): {}, {}, {}", channelHandlerContext, amsPacket, out); if (amsPacket instanceof AdsDeviceNotificationRequest) { LOGGER.debug("Received notification {}", amsPacket); handleAdsDeviceNotificationRequest((AdsDeviceNotificationRequest) amsPacket); return; } PlcRequestContainer<InternalPlcRequest, InternalPlcResponse> plcRequestContainer = requests.remove(amsPacket.getAmsHeader().getInvokeId().getAsLong()); if (plcRequestContainer == null) { LOGGER.info("Unmapped packet received {}", amsPacket); return; } PlcRequest request = plcRequestContainer.getRequest(); final InternalPlcResponse response; if (request instanceof PlcReadRequest) { if (amsPacket instanceof AdsReadResponse) { response = decodeReadResponse((AdsReadResponse) amsPacket, plcRequestContainer); } else { throw new PlcProtocolException("Wrong type correlated " + amsPacket); } } else if (request instanceof PlcWriteRequest) { if (amsPacket instanceof AdsWriteResponse) { response = decodeWriteResponse((AdsWriteResponse) amsPacket, plcRequestContainer); } else { throw new PlcProtocolException("Wrong type correlated " + amsPacket); } } else if (request instanceof PlcProprietaryRequest) { response = decodeProprietaryResponse(amsPacket, plcRequestContainer); } else { response = null; } LOGGER.debug("Plc4x response {}", response); if (response != null) { plcRequestContainer.getResponseFuture().complete(response); } } Plc4x2AdsProtocol(AmsNetId targetAmsNetId, AmsPort targetAmsPort, AmsNetId sourceAmsNetId, AmsPort sourceAmsPort, ConcurrentMap<SymbolicAdsField, DirectAdsField> fieldMapping); }
Plc4x2AdsProtocol extends MessageToMessageCodec<AmsPacket, PlcRequestContainer<InternalPlcRequest, InternalPlcResponse>> { @Override protected void decode(ChannelHandlerContext channelHandlerContext, AmsPacket amsPacket, List<Object> out) throws Exception { LOGGER.trace("(-->IN): {}, {}, {}", channelHandlerContext, amsPacket, out); if (amsPacket instanceof AdsDeviceNotificationRequest) { LOGGER.debug("Received notification {}", amsPacket); handleAdsDeviceNotificationRequest((AdsDeviceNotificationRequest) amsPacket); return; } PlcRequestContainer<InternalPlcRequest, InternalPlcResponse> plcRequestContainer = requests.remove(amsPacket.getAmsHeader().getInvokeId().getAsLong()); if (plcRequestContainer == null) { LOGGER.info("Unmapped packet received {}", amsPacket); return; } PlcRequest request = plcRequestContainer.getRequest(); final InternalPlcResponse response; if (request instanceof PlcReadRequest) { if (amsPacket instanceof AdsReadResponse) { response = decodeReadResponse((AdsReadResponse) amsPacket, plcRequestContainer); } else { throw new PlcProtocolException("Wrong type correlated " + amsPacket); } } else if (request instanceof PlcWriteRequest) { if (amsPacket instanceof AdsWriteResponse) { response = decodeWriteResponse((AdsWriteResponse) amsPacket, plcRequestContainer); } else { throw new PlcProtocolException("Wrong type correlated " + amsPacket); } } else if (request instanceof PlcProprietaryRequest) { response = decodeProprietaryResponse(amsPacket, plcRequestContainer); } else { response = null; } LOGGER.debug("Plc4x response {}", response); if (response != null) { plcRequestContainer.getResponseFuture().complete(response); } } Plc4x2AdsProtocol(AmsNetId targetAmsNetId, AmsPort targetAmsPort, AmsNetId sourceAmsNetId, AmsPort sourceAmsPort, ConcurrentMap<SymbolicAdsField, DirectAdsField> fieldMapping); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause); boolean addConsumer(Consumer<AdsDeviceNotificationRequest> adsDeviceNotificationRequestConsumer); boolean removeConsumer(Consumer<AdsDeviceNotificationRequest> adsDeviceNotificationRequestConsumer); }
Plc4x2AdsProtocol extends MessageToMessageCodec<AmsPacket, PlcRequestContainer<InternalPlcRequest, InternalPlcResponse>> { @Override protected void decode(ChannelHandlerContext channelHandlerContext, AmsPacket amsPacket, List<Object> out) throws Exception { LOGGER.trace("(-->IN): {}, {}, {}", channelHandlerContext, amsPacket, out); if (amsPacket instanceof AdsDeviceNotificationRequest) { LOGGER.debug("Received notification {}", amsPacket); handleAdsDeviceNotificationRequest((AdsDeviceNotificationRequest) amsPacket); return; } PlcRequestContainer<InternalPlcRequest, InternalPlcResponse> plcRequestContainer = requests.remove(amsPacket.getAmsHeader().getInvokeId().getAsLong()); if (plcRequestContainer == null) { LOGGER.info("Unmapped packet received {}", amsPacket); return; } PlcRequest request = plcRequestContainer.getRequest(); final InternalPlcResponse response; if (request instanceof PlcReadRequest) { if (amsPacket instanceof AdsReadResponse) { response = decodeReadResponse((AdsReadResponse) amsPacket, plcRequestContainer); } else { throw new PlcProtocolException("Wrong type correlated " + amsPacket); } } else if (request instanceof PlcWriteRequest) { if (amsPacket instanceof AdsWriteResponse) { response = decodeWriteResponse((AdsWriteResponse) amsPacket, plcRequestContainer); } else { throw new PlcProtocolException("Wrong type correlated " + amsPacket); } } else if (request instanceof PlcProprietaryRequest) { response = decodeProprietaryResponse(amsPacket, plcRequestContainer); } else { response = null; } LOGGER.debug("Plc4x response {}", response); if (response != null) { plcRequestContainer.getResponseFuture().complete(response); } } Plc4x2AdsProtocol(AmsNetId targetAmsNetId, AmsPort targetAmsPort, AmsNetId sourceAmsNetId, AmsPort sourceAmsPort, ConcurrentMap<SymbolicAdsField, DirectAdsField> fieldMapping); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause); boolean addConsumer(Consumer<AdsDeviceNotificationRequest> adsDeviceNotificationRequestConsumer); boolean removeConsumer(Consumer<AdsDeviceNotificationRequest> adsDeviceNotificationRequestConsumer);  }