use of org.apache.plc4x.java.spi.events.ConnectedEvent in project plc4x by apache.
the class Plc4xAbEthProtocol method decode.
@Override
protected void decode(ChannelHandlerContext ctx, CIPEncapsulationPacket packet, List<Object> out) throws Exception {
logger.trace("Received {}, decoding...", packet);
if (packet instanceof CIPEncapsulationConnectionResponse) {
CIPEncapsulationConnectionResponse connectionResponse = (CIPEncapsulationConnectionResponse) packet;
// Save the session handle
sessionHandle = connectionResponse.getSessionHandle();
// Tell Netty we're finished connecting
ctx.channel().pipeline().fireUserEventTriggered(new ConnectedEvent());
} else {
// We're currently just expecting responses.
if (!(packet instanceof CIPEncapsulationReadResponse)) {
return;
}
CIPEncapsulationReadResponse cipResponse = (CIPEncapsulationReadResponse) packet;
int transactionCounter = cipResponse.getResponse().getTransactionCounter();
if (!requests.containsKey(transactionCounter)) {
ctx.fireExceptionCaught(new PlcProtocolException("Couldn't find request for response with transaction counter " + transactionCounter));
return;
}
PlcRequestContainer requestContainer = requests.remove(transactionCounter);
PlcRequest request = requestContainer.getRequest();
PlcResponse response = null;
if (request instanceof PlcReadRequest) {
response = decodeReadResponse(cipResponse, requestContainer);
} else {
ctx.fireExceptionCaught(new PlcProtocolException("Unsupported request type " + request.getClass().getName()));
}
// Confirm the response being handled.
if (response != null) {
requestContainer.getResponseFuture().complete(response);
}
}
}
Aggregations