diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/modbustcp/cgy/CgySectionServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/modbustcp/cgy/CgySectionServiceImpl.java new file mode 100644 index 000000000..4de0669e1 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/modbustcp/cgy/CgySectionServiceImpl.java @@ -0,0 +1,43 @@ +package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.cgy; + +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySectionAxleCounter; +import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService; +import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.PlcGateway; +import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig; +import club.joylink.rtss.vo.client.project.cgy.CgySectionConfigVO; +import io.netty.buffer.ByteBuf; +import org.springframework.stereotype.Service; + +@Service +public class CgySectionServiceImpl implements RealDeviceService { + + @Override + public boolean canHandle(RealDeviceConfig deviceConfig) { + return deviceConfig instanceof CgySectionConfig; + } + + @Override + public void init(Simulation simulation, RealDeviceConfig deviceConfig) { + + } + + @Override + public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) { + PlcGateway plcGateway = simulation.queryPlcGatewayDevice(); + if (plcGateway == null) { + return; + } + CgySectionConfig config = (CgySectionConfig) deviceConfig; + VirtualRealitySectionAxleCounter vrAxleCounter = (VirtualRealitySectionAxleCounter) config.getMapElement(); + if (vrAxleCounter == null) { + return; + } + CgySectionConfigVO configVO = config.getConfigVO(); + ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(), + configVO.getQuantity()); + + boolean r_occupied = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_occupied()); + vrAxleCounter.setOccupy(r_occupied); + } +}