透传服务bug修改-by 卫
This commit is contained in:
parent
a0c94047f6
commit
8f7bec9854
@ -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.PlcGatewayConnectManager;
|
||||||
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.handler.ModbusMessageHandler2;
|
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.codec.ModbusTcpPayload;
|
||||||
import com.digitalpetri.modbus.requests.*;
|
import com.digitalpetri.modbus.responses.ModbusResponse;
|
||||||
import com.digitalpetri.modbus.responses.*;
|
|
||||||
import io.netty.buffer.ByteBuf;
|
|
||||||
import io.netty.buffer.Unpooled;
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
import io.netty.channel.ChannelHandlerContext;
|
import io.netty.channel.ChannelHandlerContext;
|
||||||
import io.netty.channel.SimpleChannelInboundHandler;
|
import io.netty.channel.SimpleChannelInboundHandler;
|
||||||
import io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueue;
|
import io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueue;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.locks.ReentrantLock;
|
import java.util.concurrent.locks.ReentrantLock;
|
||||||
|
|
||||||
@ -69,7 +63,8 @@ public class AfcMessageHandler extends SimpleChannelInboundHandler<ModbusTcpPayl
|
|||||||
try {
|
try {
|
||||||
// 获取网关消息并回写给AFC客户端
|
// 获取网关消息并回写给AFC客户端
|
||||||
ModbusResponse payload = future.get();
|
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) {
|
} catch (Exception e) {
|
||||||
log.error("获取AFC网关响应异常", e);
|
log.error("获取AFC网关响应异常", e);
|
||||||
}
|
}
|
||||||
@ -95,6 +90,7 @@ public class AfcMessageHandler extends SimpleChannelInboundHandler<ModbusTcpPayl
|
|||||||
}
|
}
|
||||||
synchronized (AfcQueryQueue) {
|
synchronized (AfcQueryQueue) {
|
||||||
// 生产客户端查询记录
|
// 生产客户端查询记录
|
||||||
|
log.info("收到AFC客户端请求");
|
||||||
AfcQueryQueue.offer(new AfcClientQuery(ctx.channel(), msg));
|
AfcQueryQueue.offer(new AfcClientQuery(ctx.channel(), msg));
|
||||||
AfcQueryQueue.notify();
|
AfcQueryQueue.notify();
|
||||||
}
|
}
|
||||||
|
@ -3,8 +3,9 @@ package club.joylink.rtss.simulation.cbtc.device.real.afctransfer;
|
|||||||
import club.joylink.rtss.configuration.configProp.ModbusTcpConfig;
|
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.PlcGatewayConnectManager;
|
||||||
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.handler.ModbusMessageHandler2;
|
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.ModbusRequestDecoder;
|
||||||
import com.digitalpetri.modbus.codec.*;
|
import com.digitalpetri.modbus.codec.ModbusResponseEncoder;
|
||||||
|
import com.digitalpetri.modbus.codec.ModbusTcpCodec;
|
||||||
import io.netty.bootstrap.ServerBootstrap;
|
import io.netty.bootstrap.ServerBootstrap;
|
||||||
import io.netty.channel.*;
|
import io.netty.channel.*;
|
||||||
import io.netty.channel.nio.NioEventLoopGroup;
|
import io.netty.channel.nio.NioEventLoopGroup;
|
||||||
@ -46,7 +47,6 @@ public class AfcTransferServer implements ApplicationRunner {
|
|||||||
@Override
|
@Override
|
||||||
public void initChannel(SocketChannel ch) throws Exception {
|
public void initChannel(SocketChannel ch) throws Exception {
|
||||||
ChannelPipeline pipeline = ch.pipeline();
|
ChannelPipeline pipeline = ch.pipeline();
|
||||||
// pipeline.addLast(new ModbusTcpCodec(new ModbusRequestEncoder(), new ModbusResponseDecoder()));
|
|
||||||
pipeline.addLast(new ModbusTcpCodec(new ModbusResponseEncoder(), new ModbusRequestDecoder()));
|
pipeline.addLast(new ModbusTcpCodec(new ModbusResponseEncoder(), new ModbusRequestDecoder()));
|
||||||
pipeline.addLast(new AfcMessageHandler(plcGatewayConnectManager, modbusMessageHandler));
|
pipeline.addLast(new AfcMessageHandler(plcGatewayConnectManager, modbusMessageHandler));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user