透传服务bug修改-by 卫

This commit is contained in:
joylink_zhangsai 2023-03-20 14:09:05 +08:00
parent a0c94047f6
commit 8f7bec9854
2 changed files with 7 additions and 11 deletions

View File

@ -2,20 +2,14 @@ package club.joylink.rtss.simulation.cbtc.device.real.afctransfer;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayConnectManager;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.handler.ModbusMessageHandler2;
import com.digitalpetri.modbus.FunctionCode;
import com.digitalpetri.modbus.codec.ModbusResponseDecoder;
import com.digitalpetri.modbus.codec.ModbusTcpPayload;
import com.digitalpetri.modbus.requests.*;
import com.digitalpetri.modbus.responses.*;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import com.digitalpetri.modbus.responses.ModbusResponse;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueue;
import lombok.extern.slf4j.Slf4j;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.locks.ReentrantLock;
@ -69,7 +63,8 @@ public class AfcMessageHandler extends SimpleChannelInboundHandler<ModbusTcpPayl
try {
// 获取网关消息并回写给AFC客户端
ModbusResponse payload = future.get();
query.getChannel().writeAndFlush(payload);
query.getChannel().writeAndFlush(new ModbusTcpPayload(query.getPayload().getTransactionId(), query.getPayload().getUnitId(), payload));
log.info("回复AFC客户端请求");
} catch (Exception e) {
log.error("获取AFC网关响应异常", e);
}
@ -95,6 +90,7 @@ public class AfcMessageHandler extends SimpleChannelInboundHandler<ModbusTcpPayl
}
synchronized (AfcQueryQueue) {
// 生产客户端查询记录
log.info("收到AFC客户端请求");
AfcQueryQueue.offer(new AfcClientQuery(ctx.channel(), msg));
AfcQueryQueue.notify();
}

View File

@ -3,8 +3,9 @@ package club.joylink.rtss.simulation.cbtc.device.real.afctransfer;
import club.joylink.rtss.configuration.configProp.ModbusTcpConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayConnectManager;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.handler.ModbusMessageHandler2;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.handler.RegisterHandler2;
import com.digitalpetri.modbus.codec.*;
import com.digitalpetri.modbus.codec.ModbusRequestDecoder;
import com.digitalpetri.modbus.codec.ModbusResponseEncoder;
import com.digitalpetri.modbus.codec.ModbusTcpCodec;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.*;
import io.netty.channel.nio.NioEventLoopGroup;
@ -46,7 +47,6 @@ public class AfcTransferServer implements ApplicationRunner {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// pipeline.addLast(new ModbusTcpCodec(new ModbusRequestEncoder(), new ModbusResponseDecoder()));
pipeline.addLast(new ModbusTcpCodec(new ModbusResponseEncoder(), new ModbusRequestDecoder()));
pipeline.addLast(new AfcMessageHandler(plcGatewayConnectManager, modbusMessageHandler));
}