增加成都工业职业技术学院线下项目实体设备连接配置及服务

This commit is contained in:
joylink_zhangsai 2023-11-15 09:26:04 +08:00
parent 885e98dccf
commit f1da71f236
99 changed files with 8057 additions and 6355 deletions

View File

@ -5,5 +5,6 @@ public interface ProjectCode {
String THAILAND_SANDBOX = "THAILAND_SANDBOX";
String SR_SANDBOX = "SR_SANDBOX";
String NGY_SAND_TABLE = "NGY_SAND_TABLE";
String CDGXY = "CDGXY";
}

View File

@ -67,7 +67,7 @@ public class DeviceController {
@PostMapping("")
public String create(@RequestBody @Validated ProjectDeviceVO deviceVO,
@RequestAttribute(name = AuthenticateInterceptor.LOGIN_INFO_KEY)
LoginUserInfoVO userLoginInfo) {
LoginUserInfoVO userLoginInfo) {
return this.deviceService.create(deviceVO, userLoginInfo);
}
@ -251,63 +251,68 @@ public class DeviceController {
@PostMapping("/xty/addOrUpdate")
public void addOrUpdateXtyDeviceConfig(
@RequestAttribute(name = AuthenticateInterceptor.LOGIN_USER_KEY)
AccountVO accountVO) {
AccountVO accountVO) {
this.deviceService.addOrUpdateXtyDeviceConfig(accountVO);
}
@PostMapping("/gzb/addOrUpdate")
public void addOrUpdateGzbDeviceConfig(
@RequestAttribute(name = AuthenticateInterceptor.LOGIN_USER_KEY)
AccountVO accountVO) {
AccountVO accountVO) {
this.deviceService.addOrUpdateGzbDeviceConfig(accountVO);
}
@PostMapping("/sdy/addOrUpdate")
public void addOrUpdateSdyDeviceConfig(
@RequestAttribute(name = AuthenticateInterceptor.LOGIN_USER_KEY)
AccountVO accountVO) {
AccountVO accountVO) {
this.deviceService.addOrUpdateSdyDeviceConfig(accountVO);
}
@PostMapping("/zjd/addOrUpdate")
public void addOrUpdateZjdDeviceConfig(
@RequestAttribute(name = AuthenticateInterceptor.LOGIN_USER_KEY)
AccountVO accountVO) {
AccountVO accountVO) {
this.deviceService.addOrUpdateRichorDeviceConfig(accountVO);
}
@PostMapping("/sr/addOrUpdate/{mapId}")
public void addOrUpdateSrDeviceConfig(
@RequestAttribute(name = AuthenticateInterceptor.LOGIN_USER_KEY)
AccountVO accountVO, @PathVariable Long mapId) {
AccountVO accountVO, @PathVariable Long mapId) {
this.deviceService.addOrUpdateSrDeviceConfig(accountVO, mapId);
}
@PostMapping("/hhcj/addOrUpdate")
public void addOrUpdateHhcjDeviceConfig(
@RequestAttribute(name = AuthenticateInterceptor.LOGIN_USER_KEY)
AccountVO accountVO) {
AccountVO accountVO) {
this.deviceService.addOrUpdateHhcjDeviceConfig(accountVO);
}
@PostMapping("/say/addOrUpdate")
public void addOrUpdateSayDeviceConfig(
@RequestAttribute(name = AuthenticateInterceptor.LOGIN_USER_KEY)
AccountVO accountVO) {
AccountVO accountVO) {
this.deviceService.addOrUpdateSayDeviceConfig(accountVO);
}
@PostMapping("/thailand/addOrUpdate/{mapId}")
public void addOrUpdateThailandDeviceConfig(
@RequestAttribute(name = AuthenticateInterceptor.LOGIN_USER_KEY)
AccountVO accountVO, @PathVariable Long mapId) {
AccountVO accountVO, @PathVariable Long mapId) {
this.deviceService.addOrUpdateThailandDeviceConfig(accountVO, mapId);
}
@PostMapping("/ngy/addOrUpdate/{mapId}")
public void addOrUpdateNgyDeviceConfig(
@RequestAttribute(name = AuthenticateInterceptor.LOGIN_USER_KEY)
AccountVO accountVO, @PathVariable Long mapId) {
AccountVO accountVO, @PathVariable Long mapId) {
this.deviceService.addOrUpdateNgyDeviceConfig(accountVO, mapId);
}
@PostMapping("/cdgxy/addOrUpdate")
public void addOrUpdateCdgxyDeviceConfig(@RequestAttribute AccountVO user) {
this.deviceService.addOrUpdateCdgxyDeviceConfig(user);
}
}

View File

@ -231,8 +231,7 @@ public interface DeviceService {
void addOrUpdateThailandDeviceConfig(AccountVO accountVO, Long mapId);
/**
* 所有沙盘项目通用接口
*/
void addOrUpdateNgyDeviceConfig(AccountVO accountVO, Long mapId);
void addOrUpdateCdgxyDeviceConfig(AccountVO user);
}

View File

@ -34,6 +34,8 @@ import club.joylink.rtss.vo.client.project.UDPClientConfigVO;
import club.joylink.rtss.vo.client.project.UDPLowConfigVO;
import club.joylink.rtss.vo.client.project.VrIbpConfigVO;
import club.joylink.rtss.vo.client.project.VrpsdConfigVO;
import club.joylink.rtss.vo.client.project.cgy.CgySignalConfigVO;
import club.joylink.rtss.vo.client.project.cgy.CgySwitchConfigVO;
import club.joylink.rtss.vo.client.project.gzb.GzbSignalConfigVO;
import club.joylink.rtss.vo.client.project.gzb.GzbSwitchConfigVO;
import club.joylink.rtss.vo.client.project.hhcj.HhcjIbpConfigVO;
@ -256,7 +258,8 @@ public class DeviceServiceImpl implements DeviceService {
ProjectDevice device = this.projectDeviceDAO.selectByPrimaryKey(id);
BusinessExceptionAssertEnum.INVALID_OPERATION.assertEquals(
ProjectDeviceType.valueOf(device.getType()), ProjectDeviceType.SANDBOX,
String.format("设备[%s(%s)]不是电子沙盘工作站,不能更新", device.getCode(), device.getType()));
String.format("设备[%s(%s)]不是电子沙盘工作站,不能更新", device.getCode(),
device.getType()));
device.setConfig(configVO.toJson());
this.projectDeviceDAO.updateByPrimaryKeySelective(device);
}
@ -266,7 +269,8 @@ public class DeviceServiceImpl implements DeviceService {
ProjectDevice device = this.projectDeviceDAO.selectByPrimaryKey(id);
BusinessExceptionAssertEnum.INVALID_OPERATION.assertEquals(
ProjectDeviceType.valueOf(device.getType()), ProjectDeviceType.ISCS_LW,
String.format("设备[%s(%s)]不是现地综合监控工作站,不能更新", device.getCode(), device.getType()));
String.format("设备[%s(%s)]不是现地综合监控工作站,不能更新", device.getCode(),
device.getType()));
device.setConfig(configVO.toJson());
this.projectDeviceDAO.updateByPrimaryKeySelective(device);
}
@ -276,7 +280,8 @@ public class DeviceServiceImpl implements DeviceService {
ProjectDevice device = this.projectDeviceDAO.selectByPrimaryKey(id);
BusinessExceptionAssertEnum.INVALID_OPERATION.assertEquals(
ProjectDeviceType.valueOf(device.getType()), ProjectDeviceType.ISCS_CW,
String.format("设备[%s(%s)]不是中心综合监控工作站,不能更新", device.getCode(), device.getType()));
String.format("设备[%s(%s)]不是中心综合监控工作站,不能更新", device.getCode(),
device.getType()));
device.setConfig(configVO.toJson());
this.projectDeviceDAO.updateByPrimaryKeySelective(device);
}
@ -286,7 +291,8 @@ public class DeviceServiceImpl implements DeviceService {
ProjectDevice device = this.projectDeviceDAO.selectByPrimaryKey(id);
BusinessExceptionAssertEnum.INVALID_OPERATION.assertEquals(
ProjectDeviceType.valueOf(device.getType()), ProjectDeviceType.VR_PSD,
String.format("设备[%s(%s)]不是虚拟屏蔽门工作站,不能更新", device.getCode(), device.getType()));
String.format("设备[%s(%s)]不是虚拟屏蔽门工作站,不能更新", device.getCode(),
device.getType()));
device.setConfig(configVO.toJson());
this.projectDeviceDAO.updateByPrimaryKeySelective(device);
}
@ -545,6 +551,68 @@ public class DeviceServiceImpl implements DeviceService {
}
}
@Override
public void addOrUpdateCdgxyDeviceConfig(AccountVO accountVO) {
// 删除旧配置
ProjectDeviceExample example = new ProjectDeviceExample();
example.createCriteria()
.andProjectCodeEqualTo(ProjectCode.CDGXY)
.andTypeIn(ProjectDeviceType.PlcDeviceList().stream().map(Enum::name)
.collect(Collectors.toList()));
this.projectDeviceDAO.deleteByExample(example);
// 保存新配置
List<ProjectDevice> list = this.buildCdgxyProjectDevices(accountVO);
for (ProjectDevice projectDevice : list) {
this.projectDeviceDAO.insert(projectDevice);
}
}
private List<ProjectDevice> buildCdgxyProjectDevices(AccountVO accountVO) {
LocalDateTime now = LocalDateTime.now();
List<ProjectDevice> list = new ArrayList<>();
String projectCode = ProjectCode.CDGXY;
String prefix = "cdgxy-";
// PLC网关
ProjectDevice plcGateway = new ProjectDevice();
plcGateway.setProjectCode(projectCode);
plcGateway.setCode(prefix + "gateway");
plcGateway.setType(ProjectDeviceType.PLC_GATEWAY.name());
plcGateway.setCreator(accountVO.getId());
plcGateway.setCreateTime(now);
PlcGatewayConfigVO plcGatewayConfigVO = new PlcGatewayConfigVO(0, 16);
plcGateway.setConfig(plcGatewayConfigVO.toJson());
list.add(plcGateway);
//SIGNAL
ProjectDevice signal = new ProjectDevice();
signal.setProjectCode(projectCode);
signal.setCode(prefix + "signal");
signal.setType(ProjectDeviceType.SIGNAL.name());
signal.setCreator(accountVO.getId());
signal.setCreateTime(now);
signal.setConfig(new CgySignalConfigVO().toJson());
list.add(signal);
//SWITCH
ProjectDevice aSwitch = new ProjectDevice();
aSwitch.setProjectCode(projectCode);
aSwitch.setCode(prefix + "switch");
aSwitch.setType(ProjectDeviceType.SWITCH.name());
aSwitch.setCreator(accountVO.getId());
aSwitch.setCreateTime(now);
aSwitch.setConfig(new CgySwitchConfigVO().toJson());
list.add(aSwitch);
// //SECTION
// ProjectDevice section = new ProjectDevice();
// section.setProjectCode(projectCode);
// section.setCode(prefix + "section");
// section.setType(ProjectDeviceType.SECTION.name());
// section.setCreator(accountVO.getId());
// section.setCreateTime(now);
// section.setConfig(new CgySectionConfigVO().toJson());
// list.add(section);
return list;
}
private List<ProjectDevice> buildSayProjectDevices(AccountVO accountVO) {
LocalDateTime now = LocalDateTime.now();
List<ProjectDevice> list = new ArrayList<>();

File diff suppressed because it is too large Load Diff

View File

@ -1,51 +1,50 @@
package club.joylink.rtss.simulation.cbtc.data.vo;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.constants.ProjectDeviceType;
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.ProjectDeviceVO;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.util.CollectionUtils;
@Getter
@NoArgsConstructor
public class RealDeviceVO {
private Long id;
private Long id;
private String code;
private String code;
private ProjectDeviceType type;
private ProjectDeviceType type;
private Boolean online;
private Boolean online;
private String vrDeviceCode;
private String vrDeviceCode;
public RealDeviceVO(RealDeviceConfig realDevice) {
ProjectDeviceVO device = realDevice.getProjectDevice();
this.id = device.getId();
this.code = device.getCode();
this.type = device.getType();
if (ProjectDeviceType.PLC_GATEWAY.equals(device.getType())) {
this.online = ((PlcGateway) realDevice).isOnline();
}
if (Objects.nonNull(realDevice.getMapElement())) {
this.vrDeviceCode = realDevice.getMapElement().getCode();
}
public RealDeviceVO(RealDeviceConfig realDevice) {
ProjectDeviceVO device = realDevice.getProjectDevice();
this.id = device.getId();
this.code = device.getCode();
this.type = device.getType();
if (ProjectDeviceType.PLC_GATEWAY.equals(device.getType())) {
this.online = ((PlcGateway) realDevice).isOnline();
}
public static List<RealDeviceVO> convert2VOList(List<RealDeviceConfig> list) {
List<RealDeviceVO> voList = new ArrayList<>();
if (!CollectionUtils.isEmpty(list)) {
for (RealDeviceConfig realDevice : list) {
voList.add(new RealDeviceVO(realDevice));
}
}
return voList;
if (Objects.nonNull(realDevice.getMapElement())) {
this.vrDeviceCode = realDevice.getMapElement().getCode();
}
}
public static List<RealDeviceVO> convert2VOList(List<RealDeviceConfig> list) {
List<RealDeviceVO> voList = new ArrayList<>();
if (!CollectionUtils.isEmpty(list)) {
for (RealDeviceConfig realDevice : list) {
voList.add(new RealDeviceVO(realDevice));
}
}
return voList;
}
}

View File

@ -2,10 +2,9 @@ package club.joylink.rtss.simulation.cbtc.data.vr;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import lombok.Getter;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import java.util.Objects;
import lombok.Getter;
/**
* 虚拟真实室外设备
@ -13,20 +12,22 @@ import java.util.Objects;
@Getter
public abstract class VirtualRealityDevice extends MapNamedElement {
/** 连接的项目真实设备id */
private RealDeviceConfig realDevice;
/**
* 连接的项目真实设备id
*/
private RealDeviceConfig realDevice;
protected VirtualRealityDevice(String code, String name, MapElement.DeviceType deviceType) {
super(code, name, deviceType);
}
protected VirtualRealityDevice(String code, String name, MapElement.DeviceType deviceType) {
super(code, name, deviceType);
}
public boolean isConnectReal() {
return Objects.nonNull(this.realDevice);
}
public boolean isConnectReal() {
return Objects.nonNull(this.realDevice);
}
public void updateRealDevice(RealDeviceConfig realDevice) {
this.realDevice = realDevice;
}
public void updateRealDevice(RealDeviceConfig realDevice) {
this.realDevice = realDevice;
}
/*public interface DeviceFault {
boolean applyOn(VirtualRealityDevice device);

View File

@ -1,64 +1,71 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.PlcGateway;
import io.netty.channel.Channel;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
@Slf4j
@Component
public class PlcGatewayConnectManager {
public static interface GatewayChannelRegisterListener {
void onRegister(String gatewayCode, Channel channel);
}
Map<String, GatewayChannelRegisterListener> gatewayChannelRegisterListenerMap = new ConcurrentHashMap<>();
private static final Map<String, Channel> gatewayChannelMap = new ConcurrentHashMap<>();
public static interface GatewayChannelRegisterListener {
public void addGatewayRegisterListener(String listenerId, GatewayChannelRegisterListener listener) {
this.gatewayChannelRegisterListenerMap.put(listenerId, listener);
}
void onRegister(String gatewayCode, Channel channel);
}
public boolean hasGatewayRegisterListener(String listenerId) {
return this.gatewayChannelRegisterListenerMap.containsKey(listenerId);
}
Map<String, GatewayChannelRegisterListener> gatewayChannelRegisterListenerMap = new ConcurrentHashMap<>();
public void removeGatewayRegisterListener(String listenerId) {
this.gatewayChannelRegisterListenerMap.remove(listenerId);
}
private static final Map<String, Channel> gatewayChannelMap = new ConcurrentHashMap<>();
public void register(String gatewayCode, Channel channel) {
log.info(String.format("网关[%s]连接并注册", gatewayCode));
gatewayChannelMap.put(gatewayCode, channel);
// 发布网关注册事件
this.gatewayChannelRegisterListenerMap.values().forEach(listener -> listener.onRegister(gatewayCode, channel));
}
public void addGatewayRegisterListener(String listenerId,
GatewayChannelRegisterListener listener) {
this.gatewayChannelRegisterListenerMap.put(listenerId, listener);
}
public void remove(Channel channel) {
List<String> removeList = new ArrayList<>();
gatewayChannelMap.forEach((code, temp) -> {
if (Objects.equals(channel.id(), temp.id())) {
removeList.add(code);
}
});
if (!CollectionUtils.isEmpty(removeList)) {
for (String code : removeList) {
log.info(String.format("网关[%s]断开连接并移除", code));
gatewayChannelMap.remove(code);
}
}
channel.close();
}
public boolean hasGatewayRegisterListener(String listenerId) {
return this.gatewayChannelRegisterListenerMap.containsKey(listenerId);
}
public Channel getChannel(PlcGateway plcGateway) {
return gatewayChannelMap.get(plcGateway.getProjectDevice().getProject());
}
public void removeGatewayRegisterListener(String listenerId) {
this.gatewayChannelRegisterListenerMap.remove(listenerId);
}
public Channel getChannel(String code) {
return gatewayChannelMap.get(code);
public void register(String gatewayCode, Channel channel) {
log.info(String.format("网关[%s]连接并注册", gatewayCode));
gatewayChannelMap.put(gatewayCode, channel);
// 发布网关注册事件
this.gatewayChannelRegisterListenerMap.values()
.forEach(listener -> listener.onRegister(gatewayCode, channel));
}
public void remove(Channel channel) {
List<String> removeList = new ArrayList<>();
gatewayChannelMap.forEach((code, temp) -> {
if (Objects.equals(channel.id(), temp.id())) {
removeList.add(code);
}
});
if (!CollectionUtils.isEmpty(removeList)) {
for (String code : removeList) {
log.info(String.format("网关[%s]断开连接并移除", code));
gatewayChannelMap.remove(code);
}
}
channel.close();
}
public Channel getChannel(PlcGateway plcGateway) {
return gatewayChannelMap.get(plcGateway.getProjectDevice().getProject());
}
public Channel getChannel(String code) {
return gatewayChannelMap.get(code);
}
}

View File

@ -1,14 +1,14 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import io.netty.buffer.ByteBuf;
public interface RealDeviceService {
boolean canHandle(RealDeviceConfig deviceConfig);
boolean canHandle(RealDeviceConfig deviceConfig);
void init(Simulation simulation, RealDeviceConfig deviceConfig);
void init(Simulation simulation, RealDeviceConfig deviceConfig);
void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf);
void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf);
}

View File

@ -4,151 +4,156 @@ import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement;
import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.simulation.cbtc.data.vr.*;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityDevice;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityIbp;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityScreenDoor;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySectionAxleCounter;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch;
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.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import io.netty.channel.Channel;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Objects;
/**
* 仿真PLC真实设备连接状态管理
*/
@Component
public class SimulationRealDeviceConnectManager {
@Autowired
private PlcGatewayConnectManager plcGatewayConnectManager;
@Autowired
private PlcGatewayConnectManager plcGatewayConnectManager;
public void updatePlcGatewayOnlineStatus(Simulation simulation) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (Objects.nonNull(plcGateway)) {
Channel channel = this.plcGatewayConnectManager.getChannel(plcGateway);
if (!Objects.equals(plcGateway.getChannel(), channel)) {
plcGateway.updateChannel(channel);
}
}
public void updatePlcGatewayOnlineStatus(Simulation simulation) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (Objects.nonNull(plcGateway)) {
Channel channel = this.plcGatewayConnectManager.getChannel(plcGateway);
if (!Objects.equals(plcGateway.getChannel(), channel)) {
plcGateway.updateChannel(channel);
}
}
}
public void connectDevice(Simulation simulation, String deviceCode, Long projectDeviceId) {
RealDeviceConfig realDevice = simulation.getRealDeviceById(projectDeviceId);
MapElement mapElement = simulation.getRepository().findByCode(deviceCode);
boolean typeEqual = false;
switch (realDevice.getProjectDevice().getType()) {
case SWITCH:{
VirtualRealityDevice vrDevice = simulation.getRepository().getVRByCode(deviceCode);
if (MapElement.DeviceType.SWITCH.equals(vrDevice.getDeviceType())) {
typeEqual = true;
MapNamedElement old = realDevice.getMapElement();
if (Objects.nonNull(old)) {
((VirtualRealitySwitch) old).updateRealDevice(null);
}
vrDevice.updateRealDevice(realDevice);
realDevice.connect(vrDevice);
}
break;
}
case SIGNAL:{
VirtualRealityDevice vrDevice = simulation.getRepository().getVRByCode(deviceCode);
if (MapElement.DeviceType.SIGNAL.equals(vrDevice.getDeviceType())) {
typeEqual = true;
MapNamedElement old = realDevice.getMapElement();
if (Objects.nonNull(old)) {
((VirtualRealitySignal) old).updateRealDevice(null);
}
vrDevice.updateRealDevice(realDevice);
realDevice.connect(vrDevice);
}
break;
}
case SECTION: {
VirtualRealityDevice vrDevice = simulation.getRepository().getVRByCode(deviceCode);
if (MapElement.DeviceType.AXLE_COUNTER.equals(vrDevice.getDeviceType())) {
typeEqual = true;
MapNamedElement old = realDevice.getMapElement();
if (Objects.nonNull(old)) {
((VirtualRealitySectionAxleCounter) old).updateRealDevice(null);
}
vrDevice.updateRealDevice(realDevice);
realDevice.connect(vrDevice);
}
break;
}
case PSC:
case PSD: {
VirtualRealityDevice vrDevice = simulation.getRepository().getVRByCode(deviceCode);
if (MapElement.DeviceType.PSD.equals(vrDevice.getDeviceType())) {
typeEqual = true;
MapNamedElement old = realDevice.getMapElement();
if (Objects.nonNull(old)) {
((VirtualRealityScreenDoor) old).updateRealDevice(null);
}
vrDevice.updateRealDevice(realDevice);
realDevice.connect(vrDevice);
}
break;
}
case PSL: {
VirtualRealityDevice vrDevice = simulation.getRepository().getVRByCode(deviceCode);
if (MapElement.DeviceType.PSD.equals(vrDevice.getDeviceType())) {
typeEqual = true;
realDevice.connect(vrDevice);
}
if (MapElement.DeviceType.PSL.equals(vrDevice.getDeviceType())) {
typeEqual = true;
realDevice.connect(vrDevice);
}
vrDevice.updateRealDevice(realDevice);
break;
}
case IBP:{
if (MapElement.DeviceType.STATION.equals(mapElement.getDeviceType())) {
typeEqual = true;
realDevice.connect(((Station) mapElement));
}
if (MapElement.DeviceType.IBP.equals(mapElement.getDeviceType())) {
typeEqual = true;
VirtualRealityIbp vrIbp = (VirtualRealityIbp) mapElement;
realDevice.connect(vrIbp);
vrIbp.updateRealDevice(realDevice);
}
break;
}
case TRAIN:{
VirtualRealityDevice vrDevice = simulation.getRepository().getVRByCode(deviceCode);
if (MapElement.DeviceType.TRAIN.equals(vrDevice.getDeviceType())) {
typeEqual = true;
realDevice.connect(vrDevice);
vrDevice.updateRealDevice(realDevice);
}
break;
}
default:
throw new SimulationException(SimulationExceptionType.Invalid_Operation);
public void connectDevice(Simulation simulation, String deviceCode, Long projectDeviceId) {
RealDeviceConfig realDevice = simulation.getRealDeviceById(projectDeviceId);
MapElement mapElement = simulation.getRepository().findByCode(deviceCode);
boolean typeEqual = false;
switch (realDevice.getProjectDevice().getType()) {
case SWITCH: {
VirtualRealityDevice vrDevice = simulation.getRepository().getVRByCode(deviceCode);
if (MapElement.DeviceType.SWITCH.equals(vrDevice.getDeviceType())) {
typeEqual = true;
MapNamedElement old = realDevice.getMapElement();
if (Objects.nonNull(old)) {
((VirtualRealitySwitch) old).updateRealDevice(null);
}
vrDevice.updateRealDevice(realDevice);
realDevice.connect(vrDevice);
}
if (!typeEqual) {
throw new SimulationException(SimulationExceptionType.Invalid_Operation,
String.format("不匹配的类型[vr(%s)-real(%s)]",
mapElement.getDeviceType(), realDevice.getProjectDevice().getType()));
break;
}
case SIGNAL: {
VirtualRealityDevice vrDevice = simulation.getRepository().getVRByCode(deviceCode);
if (MapElement.DeviceType.SIGNAL.equals(vrDevice.getDeviceType())) {
typeEqual = true;
MapNamedElement old = realDevice.getMapElement();
if (Objects.nonNull(old)) {
((VirtualRealitySignal) old).updateRealDevice(null);
}
vrDevice.updateRealDevice(realDevice);
realDevice.connect(vrDevice);
}
break;
}
case SECTION: {
VirtualRealityDevice vrDevice = simulation.getRepository().getVRByCode(deviceCode);
if (MapElement.DeviceType.AXLE_COUNTER.equals(vrDevice.getDeviceType())) {
typeEqual = true;
MapNamedElement old = realDevice.getMapElement();
if (Objects.nonNull(old)) {
((VirtualRealitySectionAxleCounter) old).updateRealDevice(null);
}
vrDevice.updateRealDevice(realDevice);
realDevice.connect(vrDevice);
}
break;
}
case PSC:
case PSD: {
VirtualRealityDevice vrDevice = simulation.getRepository().getVRByCode(deviceCode);
if (MapElement.DeviceType.PSD.equals(vrDevice.getDeviceType())) {
typeEqual = true;
MapNamedElement old = realDevice.getMapElement();
if (Objects.nonNull(old)) {
((VirtualRealityScreenDoor) old).updateRealDevice(null);
}
vrDevice.updateRealDevice(realDevice);
realDevice.connect(vrDevice);
}
break;
}
case PSL: {
VirtualRealityDevice vrDevice = simulation.getRepository().getVRByCode(deviceCode);
if (MapElement.DeviceType.PSD.equals(vrDevice.getDeviceType())) {
typeEqual = true;
realDevice.connect(vrDevice);
}
if (MapElement.DeviceType.PSL.equals(vrDevice.getDeviceType())) {
typeEqual = true;
realDevice.connect(vrDevice);
}
vrDevice.updateRealDevice(realDevice);
break;
}
case IBP: {
if (MapElement.DeviceType.STATION.equals(mapElement.getDeviceType())) {
typeEqual = true;
realDevice.connect(((Station) mapElement));
}
if (MapElement.DeviceType.IBP.equals(mapElement.getDeviceType())) {
typeEqual = true;
VirtualRealityIbp vrIbp = (VirtualRealityIbp) mapElement;
realDevice.connect(vrIbp);
vrIbp.updateRealDevice(realDevice);
}
break;
}
case TRAIN: {
VirtualRealityDevice vrDevice = simulation.getRepository().getVRByCode(deviceCode);
if (MapElement.DeviceType.TRAIN.equals(vrDevice.getDeviceType())) {
typeEqual = true;
realDevice.connect(vrDevice);
vrDevice.updateRealDevice(realDevice);
}
break;
}
default:
throw new SimulationException(SimulationExceptionType.Invalid_Operation);
}
if (!typeEqual) {
throw new SimulationException(SimulationExceptionType.Invalid_Operation,
String.format("不匹配的类型[vr(%s)-real(%s)]",
mapElement.getDeviceType(), realDevice.getProjectDevice().getType()));
}
}
public void disconnectDevice(Simulation simulation, Long projectDeviceId) {
RealDeviceConfig realDevice = simulation.getRealDeviceById(projectDeviceId);
MapNamedElement mapElement = realDevice.getMapElement();
if (Objects.nonNull(mapElement)) {
if (mapElement instanceof VirtualRealityDevice) {
((VirtualRealityDevice) mapElement).updateRealDevice(null);
}
realDevice.disconnect();
}
public void disconnectDevice(Simulation simulation, Long projectDeviceId) {
RealDeviceConfig realDevice = simulation.getRealDeviceById(projectDeviceId);
MapNamedElement mapElement = realDevice.getMapElement();
if (Objects.nonNull(mapElement)) {
if (mapElement instanceof VirtualRealityDevice) {
((VirtualRealityDevice) mapElement).updateRealDevice(null);
}
realDevice.disconnect();
}
}
public void addJobs(Simulation simulation) {
simulation.addFixedRateJob("PlcGatewayOnline", () -> this.updatePlcGatewayOnlineStatus(simulation), 1000);
}
public void addJobs(Simulation simulation) {
simulation.addFixedRateJob("PlcGatewayOnline",
() -> this.updatePlcGatewayOnlineStatus(simulation), 1000);
}
}

View File

@ -7,181 +7,188 @@ import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityScreenDoor;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
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.simulation.cbtc.device.virtual.VirtualRealityDeviceService;
import club.joylink.rtss.simulation.cbtc.event.SimulationResetEvent;
import com.digitalpetri.modbus.responses.ReadCoilsResponse;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.concurrent.CompletableFuture;
@Slf4j
@Component
public class SimulationRealDeviceThread {
public static final int Query_Rate = 300;
public static final int Query_Rate = 300;
public static final int COLLECT_RATE = 100;
public static final int COLLECT_RATE = 100;
@Autowired
public GroupSimulationCache groupSimulationCache;
@Autowired
private VirtualRealityDeviceService virtualRealityDeviceService;
@Autowired
private PlcGatewayConnectManager plcGatewayConnectManager;
@Autowired
public GroupSimulationCache groupSimulationCache;
@Autowired
private VirtualRealityDeviceService virtualRealityDeviceService;
@Autowired
private PlcGatewayConnectManager plcGatewayConnectManager;
@Autowired
private PlcGatewayService plcGatewayService;
@Autowired
private PlcGatewayService plcGatewayService;
@Autowired
private RealDeviceServiceManager realDeviceServiceManager;
@Autowired
private RealDeviceServiceManager realDeviceServiceManager;
@Autowired
private ProjectService projectService;
@Autowired
private ProjectService projectService;
@EventListener
public void simulationReset(SimulationResetEvent event) {
Simulation simulation = event.getSimulation();
List<RealDeviceConfig> realDeviceList = simulation.getRealDeviceList();
if (!CollectionUtils.isEmpty(realDeviceList)) {
Channel channel = this.queryAndCheckChannel(simulation);
if (Objects.isNull(channel)) {
return;
}
@EventListener
public void simulationReset(SimulationResetEvent event) {
Simulation simulation = event.getSimulation();
List<RealDeviceConfig> realDeviceList = simulation.getRealDeviceList();
if (!CollectionUtils.isEmpty(realDeviceList)) {
Channel channel = this.queryAndCheckChannel(simulation);
if (Objects.isNull(channel)) {
return;
}
for (RealDeviceConfig realDevice : realDeviceList) {
if (realDevice instanceof PlcGateway) {
continue;
}
for (RealDeviceService realDeviceService : this.realDeviceServiceManager.getDeviceServiceList()) {
if (realDeviceService.canHandle(realDevice)) {
realDeviceService.init(simulation, realDevice);
}
}
}
}
}
public void controlDevice(Simulation simulation) {
List<RealDeviceConfig> realDeviceList = simulation.getRealDeviceList();
if (!CollectionUtils.isEmpty(realDeviceList)) {
if (simulation.getProjectVO().isControlDevice()) {
Set<VirtualRealityScreenDoor> vrPsdSet = new HashSet<>();
Set<VirtualRealitySwitch> vrSwitchSet = new HashSet<>();
for (RealDeviceConfig realDevice : realDeviceList) {
if (realDevice.getMapElement() instanceof VirtualRealityScreenDoor) {
vrPsdSet.add((VirtualRealityScreenDoor) realDevice.getMapElement());
} else if (realDevice.getMapElement() instanceof VirtualRealitySwitch) {
vrSwitchSet.add((VirtualRealitySwitch) realDevice.getMapElement());
}
}
for (VirtualRealityScreenDoor vrPsd : vrPsdSet) {
this.virtualRealityDeviceService.turning(simulation, vrPsd);
}
for (VirtualRealitySwitch vrSwitch : vrSwitchSet) {
this.virtualRealityDeviceService.turning(simulation, vrSwitch);
}
}
}
}
/**
* 获取真实设备数据
*
* @param simulation
*/
public void queryDeviceStatus(Simulation simulation) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (Objects.isNull(plcGateway)) {
return;
}
Channel channel = plcGateway.getChannel();
if (Objects.isNull(channel)) { //网关不在线
return;
} else if (!channel.isWritable()) {//网关不可写
return;
}
CompletableFuture<ReadCoilsResponse> future = this.plcGatewayService.query(channel,
plcGateway.getConfig());
if (Objects.nonNull(future)) {
simulation.pushModbusFuture(new DeviceQueryFuture(channel, future));
}
}
/**
* 根据获取到的真实设备状态更新仿真设备状态
*
* @param simulation
*/
public void UpdateDeviceStatusByCollection(Simulation simulation) {
Queue<DeviceQueryFuture> futureQueue = simulation.getDeviceQueryFutureQueue();
DeviceQueryFuture deviceQueryFuture = futureQueue.peek();
if (Objects.nonNull(deviceQueryFuture) && deviceQueryFuture.getFuture().isDone()) {
futureQueue.remove(); // 移除此future
CompletableFuture<ReadCoilsResponse> future = deviceQueryFuture.getFuture();
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (future.isCancelled() || future.isCompletedExceptionally()) {
// 获取数据失败累加时间超时断开网关连接
log.warn("Modbus read coils quest failed");
plcGateway.failAdd();
if (plcGateway.getFailures() > 10) {
log.debug(String.format("网关[%s]多次读取数据失败,移除网关连接", plcGateway));
this.plcGatewayConnectManager.remove(deviceQueryFuture.getChannel());
plcGateway.removeChannel();
simulation.clearModubsFuture();
}
} else {
try {
plcGateway.resetFailures();
ReadCoilsResponse coilsResponse = future.get();
ByteBuf coilStatus = coilsResponse.getCoilStatus();
List<RealDeviceConfig> realDeviceList = simulation.getRealDeviceList();
if (!CollectionUtils.isEmpty(realDeviceList)) {
for (RealDeviceConfig realDevice : realDeviceList) {
if (realDevice instanceof PlcGateway) {
continue;
}
for (RealDeviceService realDeviceService : this.realDeviceServiceManager.getDeviceServiceList()) {
if (realDeviceService.canHandle(realDevice)) {
realDeviceService.init(simulation, realDevice);
}
if (ProjectDeviceType.PLC_GATEWAY.equals(realDevice.getDeviceType())) {
continue;
}
for (RealDeviceService realDeviceService : this.realDeviceServiceManager.getDeviceServiceList()) {
if (realDeviceService.canHandle(realDevice)) {
realDeviceService.handle(simulation, realDevice, coilStatus);
}
}
}
}
} catch (Exception e) {
log.error(String.format("仿真[%s]Modbus响应处理异常"
, simulation.getId()), e);
}
}
}
}
public void controlDevice(Simulation simulation) {
List<RealDeviceConfig> realDeviceList = simulation.getRealDeviceList();
if (!CollectionUtils.isEmpty(realDeviceList)) {
if (simulation.getProjectVO().isControlDevice()) {
Set<VirtualRealityScreenDoor> vrPsdSet = new HashSet<>();
Set<VirtualRealitySwitch> vrSwitchSet = new HashSet<>();
for (RealDeviceConfig realDevice : realDeviceList) {
if (realDevice.getMapElement() instanceof VirtualRealityScreenDoor) {
vrPsdSet.add((VirtualRealityScreenDoor) realDevice.getMapElement());
} else if (realDevice.getMapElement() instanceof VirtualRealitySwitch) {
vrSwitchSet.add((VirtualRealitySwitch) realDevice.getMapElement());
}
}
for (VirtualRealityScreenDoor vrPsd : vrPsdSet) {
this.virtualRealityDeviceService.turning(simulation, vrPsd);
}
for (VirtualRealitySwitch vrSwitch : vrSwitchSet) {
this.virtualRealityDeviceService.turning(simulation, vrSwitch);
}
}
}
/**
* 获取并检查channel状态channel不存在或不可写都返回null
*/
private Channel queryAndCheckChannel(Simulation simulation) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (Objects.isNull(plcGateway)) {//无PLC网关返回
return null;
}
Channel channel = plcGateway.getChannel();
if (Objects.isNull(channel)) {//网关不在线返回
return null;
} else if (!channel.isWritable()) {//网关不可写
return null;
}
return channel;
}
/**
* 获取真实设备数据
*
* @param simulation
*/
public void queryDeviceStatus(Simulation simulation) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (Objects.isNull(plcGateway)) {
return;
}
Channel channel = plcGateway.getChannel();
if (Objects.isNull(channel)) { //网关不在线
return;
} else if (!channel.isWritable()) {//网关不可写
return;
}
CompletableFuture<ReadCoilsResponse> future = this.plcGatewayService.query(channel, plcGateway.getConfig());
if (Objects.nonNull(future)) {
simulation.pushModbusFuture(new DeviceQueryFuture(channel, future));
}
}
/**
* 根据获取到的真实设备状态更新仿真设备状态
*
* @param simulation
*/
public void UpdateDeviceStatusByCollection(Simulation simulation) {
Queue<DeviceQueryFuture> futureQueue = simulation.getDeviceQueryFutureQueue();
DeviceQueryFuture deviceQueryFuture = futureQueue.peek();
if (Objects.nonNull(deviceQueryFuture) && deviceQueryFuture.getFuture().isDone()) {
futureQueue.remove(); // 移除此future
CompletableFuture<ReadCoilsResponse> future = deviceQueryFuture.getFuture();
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (future.isCancelled() || future.isCompletedExceptionally()) {
// 获取数据失败累加时间超时断开网关连接
log.warn("Modbus read coils quest failed");
plcGateway.failAdd();
if (plcGateway.getFailures() > 10) {
log.debug(String.format("网关[%s]多次读取数据失败,移除网关连接", plcGateway));
this.plcGatewayConnectManager.remove(deviceQueryFuture.getChannel());
plcGateway.removeChannel();
simulation.clearModubsFuture();
}
} else {
try {
plcGateway.resetFailures();
ReadCoilsResponse coilsResponse = future.get();
ByteBuf coilStatus = coilsResponse.getCoilStatus();
List<RealDeviceConfig> realDeviceList = simulation.getRealDeviceList();
if (!CollectionUtils.isEmpty(realDeviceList)) {
for (RealDeviceConfig realDevice : realDeviceList) {
if (ProjectDeviceType.PLC_GATEWAY.equals(realDevice.getDeviceType())) {
continue;
}
for (RealDeviceService realDeviceService : this.realDeviceServiceManager.getDeviceServiceList()) {
if (realDeviceService.canHandle(realDevice)) {
realDeviceService.handle(simulation, realDevice, coilStatus);
}
}
}
}
} catch (Exception e) {
log.error(String.format("仿真[%s]Modbus响应处理异常"
, simulation.getId()), e);
}
}
}
}
/**
* 获取并检查channel状态channel不存在或不可写都返回null
*/
private Channel queryAndCheckChannel(Simulation simulation) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (Objects.isNull(plcGateway)) {//无PLC网关返回
return null;
}
Channel channel = plcGateway.getChannel();
if (Objects.isNull(channel)) {//网关不在线返回
return null;
} else if (!channel.isWritable()) {//网关不可写
return null;
}
return channel;
}
public void addJobs(Simulation simulation) {
simulation.addFixedRateJob(Simulation.JobName.controlDevice, () -> this.controlDevice(simulation), SimulationConstants.VRD_LOOP_RATE);
simulation.addFixedRateJob(Simulation.JobName.queryDeviceStatus, () -> this.queryDeviceStatus(simulation), Query_Rate);
simulation.addFixedRateJob(Simulation.JobName.UpdateDeviceStatusByCollection, () -> this.UpdateDeviceStatusByCollection(simulation), COLLECT_RATE);
}
public void addJobs(Simulation simulation) {
simulation.addFixedRateJob(Simulation.JobName.controlDevice,
() -> this.controlDevice(simulation), SimulationConstants.VRD_LOOP_RATE);
simulation.addFixedRateJob(Simulation.JobName.queryDeviceStatus,
() -> this.queryDeviceStatus(simulation), Query_Rate);
simulation.addFixedRateJob(Simulation.JobName.UpdateDeviceStatusByCollection,
() -> this.UpdateDeviceStatusByCollection(simulation), COLLECT_RATE);
}
}

View File

@ -0,0 +1,25 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.cgy;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.cgy.CgySectionConfigVO;
import lombok.Getter;
@Getter
public class CgySectionConfig extends RealDeviceConfig {
private CgySectionConfigVO configVO;
public CgySectionConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (projectDevice != null) {
configVO = JsonUtils.read(projectDevice.getConfig(), CgySectionConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO == null ? null : configVO.findDeviceCode();
}
}

View File

@ -0,0 +1,44 @@
//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 club.joylink.rtss.vo.client.project.say.SaySectionConfigVO;
//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_clear = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_clear());
// vrAxleCounter.setOccupy(!r_clear);
// }
//}

View File

@ -0,0 +1,25 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.cgy;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.cgy.CgySignalConfigVO;
import lombok.Getter;
@Getter
public class CgySignalConfig extends RealDeviceConfig {
private CgySignalConfigVO configVO;
public CgySignalConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (projectDevice != null) {
configVO = JsonUtils.read(projectDevice.getConfig(), CgySignalConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO == null ? null : configVO.findDeviceCode();
}
}

View File

@ -0,0 +1,180 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.cgy;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SignalAspect;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
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.CgySignalConfigVO;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class CgySignalServiceImpl implements RealDeviceService {
@Autowired
private PlcGatewayService plcGatewayService;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof CgySignalConfig;
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (plcGateway == null) {
return;
}
CgySignalConfig config = (CgySignalConfig) deviceConfig;
VirtualRealitySignal vrSignal = (VirtualRealitySignal) config.getMapElement();
if (vrSignal == null) {
return;
}
CgySignalConfigVO configVO = config.getConfigVO();
SignalAspect aspect = vrSignal.getAspect();
if (aspect == null) {
return;
}
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
Channel channel = plcGateway.getChannel();
switch (aspect) {
case No:
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_red(), false, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_green(), false, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_yellow(), false, channel);
break;
case R:
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_red(), true, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_green(), false, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_yellow(), false, channel);
break;
case G:
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_red(), false, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_green(), true, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_yellow(), false, channel);
break;
case Y:
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_red(), false, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_green(), false, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_yellow(), true, channel);
break;
case RY:
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_red(), true, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_green(), false, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_yellow(), true, channel);
break;
default:
log.error("不支持的显示:{}", aspect);
break;
}
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (plcGateway == null) {
return;
}
CgySignalConfig config = (CgySignalConfig) deviceConfig;
VirtualRealitySignal vrSignal = (VirtualRealitySignal) config.getMapElement();
if (vrSignal == null) {
return;
}
CgySignalConfigVO configVO = config.getConfigVO();
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(),
configVO.getQuantity());
boolean r_r = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_red());
boolean r_g = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_green());
boolean r_y = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_yellow());
SignalAspect aspect = null;
if (!r_r && !r_g && !r_y) {
aspect = SignalAspect.No;
} else if (r_r && !r_g && !r_y) {
aspect = SignalAspect.R;
} else if (!r_r && r_g && !r_y) {
aspect = SignalAspect.G;
} else if (!r_r && !r_g && r_y) {
aspect = SignalAspect.Y;
} else if (r_r && !r_g && r_y) {
aspect = SignalAspect.RY;
}
if (aspect == null) {
log.error("未知的信号组合[红:%s][绿:%s][黄:%s]", r_r, r_g, r_y);
} else {
vrSignal.apply(aspect);
}
if (vrSignal.isTurning()) {
boolean w_r = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_red());
boolean w_g = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_green());
boolean w_y = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_yellow());
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
Channel channel = plcGateway.getChannel();
SignalAspect command = vrSignal.getCommand();
switch (command) {
case No:
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_red(), w_r, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_green(), w_g,
false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_yellow(), w_y,
false,
channel);
break;
case R:
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_red(), w_r, true,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_green(), w_g,
false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_yellow(), w_y,
false,
channel);
break;
case G:
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_red(), w_r, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_green(), w_g, true,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_yellow(), w_y,
false,
channel);
break;
case Y:
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_red(), w_r, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_green(), w_g,
false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_yellow(), w_y,
true,
channel);
break;
case RY:
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_red(), w_r, true,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_green(), w_g,
false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_yellow(), w_y,
true,
channel);
break;
default:
log.error("不支持的显示:{}", aspect);
break;
}
}
}
}

View File

@ -0,0 +1,94 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.cgy;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.cgy.CgySwitchConfigVO;
import java.time.LocalDateTime;
import lombok.Getter;
@Getter
public class CgySwitchConfig extends RealDeviceConfig {
private CgySwitchConfigVO configVO;
/**
* 下令定操
*/
private boolean turnToN;
/**
* 下令反操
*/
private boolean turnToP;
/**
* 定反操继电器接通时刻 3s后断开继电器防止继电器长期接通
*/
private LocalDateTime startTime;
public CgySwitchConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (projectDevice != null) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), CgySwitchConfigVO.class);
}
}
/**
* 请求转向定位
*
* @return 是否可以操作继电器以转向定位
*/
public boolean turnToN() {
if (turnToN) {
return false;
} else {
turnToN = true;
turnToP = false;
startTime = LocalDateTime.now();
return true;
}
}
/**
* 请求转向反位
*
* @return 是否可以操作继电器以转向反位
*/
public boolean turnToP() {
if (turnToP) {
return false;
} else {
turnToN = false;
turnToP = true;
startTime = LocalDateTime.now();
return true;
}
}
/**
* 定反操的继电器操作是否可以结束
*/
public boolean isEnd() {
return startTime == null || LocalDateTime.now().isAfter(startTime.plusSeconds(3));
}
/**
* 同步道岔状态表示以限定此时道岔可以进行的操作 此方法是为了防止类似以下情况通过仿真将道岔操到定位再手摇道岔到反位则此时仿真中道岔表示为反位
* 只能执行定操又因此处记录上一次操作也是定操不予执行导致死循环仿真中无法再操作道岔了
*/
public void sync(boolean r_db, boolean r_fb) {
if (r_db) {
turnToN = true;
turnToP = false;
} else if (r_fb) {
turnToN = false;
turnToP = true;
}
}
@Override
public String findDeviceCode() {
return configVO == null ? null : configVO.findDeviceCode();
}
}

View File

@ -0,0 +1,126 @@
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.VirtualRealitySwitch;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
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.CgySwitchConfigVO;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class CgySwitchServiceImpl implements RealDeviceService {
@Autowired
private PlcGatewayService plcGatewayService;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof CgySwitchConfig;
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (plcGateway == null) {
return;
}
CgySwitchConfig config = (CgySwitchConfig) deviceConfig;
CgySwitchConfigVO configVO = config.getConfigVO();
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
Channel channel = plcGateway.getChannel();
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_sj(), false, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_dc(), false, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_fc(), false, channel);
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (plcGateway == null) {
return;
}
CgySwitchConfig config = (CgySwitchConfig) deviceConfig;
CgySwitchConfigVO configVO = config.getConfigVO();
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(),
configVO.getQuantity());
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
Channel channel = plcGateway.getChannel();
VirtualRealitySwitch vrSwitch = (VirtualRealitySwitch) config.getMapElement();
if (vrSwitch == null) {
release(deviceStatus, baseAddr, configVO, channel); //防止定反操继电器长时间接通
return;
}
boolean r_db = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_db());
boolean r_fb = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_fb());
vrSwitch.apply(r_db, r_fb);
//以下操作实体设备的逻辑中防止继电器长期接通的逻辑将定反操视为技能共用3秒冷却技能持续时间也是3秒
if (config.isEnd()) { //此判断既可视为操作是否冷却也可视为持续时间是否耗尽
config.sync(r_db, r_fb);
release(deviceStatus, baseAddr, configVO, channel); //操作持续时间耗尽后断开所有继电器
if (vrSwitch.isTurning()) {
switch (vrSwitch.getCommand()) {
case NP:
if (config.turnToN()) {
turnToN(deviceStatus, baseAddr, configVO, channel);
}
break;
case RP:
if (config.turnToP()) {
turnToP(deviceStatus, baseAddr, configVO, channel);
}
break;
}
}
}
}
private void turnToN(ByteBuf deviceStatus, int baseAddr, CgySwitchConfigVO configVO,
Channel channel) {
boolean w_sb = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_sj());
boolean w_dc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_dc());
boolean w_fc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_fc());
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_sj(), w_sb, true,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_dc(), w_dc, true,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_fc(), w_fc, false,
channel);
}
private void turnToP(ByteBuf deviceStatus, int baseAddr, CgySwitchConfigVO configVO,
Channel channel) {
boolean w_sb = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_sj());
boolean w_dc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_dc());
boolean w_fc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_fc());
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_sj(), w_sb, true,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_dc(), w_dc, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_fc(), w_fc, true,
channel);
}
private void release(ByteBuf deviceStatus, int baseAddr, CgySwitchConfigVO configVO,
Channel channel) {
boolean w_sj = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_sj());
boolean w_dc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_dc());
boolean w_fc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_fc());
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_sj(), w_sj, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_dc(), w_dc, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_fc(), w_fc, false,
channel);
}
}

View File

@ -0,0 +1,51 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common;
import club.joylink.rtss.vo.client.project.PlcGatewayConfigVO;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import io.netty.channel.Channel;
import java.util.Objects;
import lombok.Getter;
@Getter
public class PlcGateway extends RealDeviceConfig {
private PlcGatewayConfigVO config;
private Channel channel;
/**
* 失败累计
*/
private int failures;
public PlcGateway(ProjectDeviceVO deviceVO) {
super(deviceVO);
this.config = deviceVO.buildPlcGatewayConfig();
}
public void updateChannel(Channel channel) {
this.channel = channel;
}
public Boolean isOnline() {
return Objects.nonNull(this.channel);
}
public synchronized void failAdd() {
this.failures++;
}
public synchronized void removeChannel() {
this.channel = null;
this.failures = 0;
}
public synchronized void resetFailures() {
this.failures = 0;
}
@Override
public String findDeviceCode() {
return config == null ? null : config.findDeviceCode();
}
}

View File

@ -0,0 +1,93 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common;
import club.joylink.rtss.constants.ProjectDeviceType;
import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.math.BigInteger;
import java.util.Objects;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Getter
public abstract class RealDeviceConfig {
private ProjectDeviceVO projectDevice;
protected MapNamedElement mapElement;
public RealDeviceConfig(ProjectDeviceVO projectDevice) {
this.projectDevice = projectDevice;
}
public static ByteBuf getDeviceCoilStatus(ByteBuf totalCoilStatus, Integer addr,
Integer quantity) {
int capacity = quantity / 8;
ByteBuf buffer = Unpooled.buffer(capacity);
byte[] array = new byte[totalCoilStatus.readableBytes()];
totalCoilStatus.getBytes(0, array);
StringBuilder sb = new StringBuilder();
for (byte b : array) {
StringBuilder bsb = new StringBuilder();
String bs = Integer.toBinaryString(b);
if (bs.length() < 8) {
for (int i = 0; i < 8 - bs.length(); i++) {
bsb.append(0);
}
} else if (bs.length() > 8) {
bs = bs.substring(bs.length() - 8);
}
bsb.append(bs);
bsb.reverse();
sb.append(bsb);
}
String bitStr = sb.substring(addr, addr + quantity);
for (int i = 0; i < capacity; i++) {
String binaryByteStr = bitStr.substring(i * 8, (i + 1) * 8);
byte b = new BigInteger(binaryByteStr, 2).byteValue();
buffer.writeByte(b);
}
return buffer;
}
public void connect(MapNamedElement vrDevice) {
this.mapElement = vrDevice;
log.debug(String.format("设备[%s]连接了仿真设备[%s]", this.projectDevice.toString(),
mapElement.debugStr()));
}
public void disconnect() {
if (Objects.nonNull(this.mapElement)) {
this.mapElement = null;
}
}
/**
* 获取指定位值
*
* @param buf
* @param bitIndex 从左到右位的索引
* @return
*/
public static boolean getBitOf(ByteBuf buf, int bitIndex) {
int index = bitIndex / 8; // 第几字节
int nbIndex = 8 - (bitIndex % 8) - 1; // 新的位索引
byte val = buf.getByte(index);
return (val & (1 << nbIndex)) != 0;
}
public String getProject() {
return this.projectDevice.getProject();
}
public ProjectDeviceType getDeviceType() {
return this.projectDevice.getType();
}
/**
* 仿真设备的code 目前用于实体设备配置与仿真设备连接
*/
public abstract String findDeviceCode();
}

View File

@ -1,49 +0,0 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device;
import club.joylink.rtss.vo.client.project.PlcGatewayConfigVO;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import io.netty.channel.Channel;
import lombok.Getter;
import java.util.Objects;
@Getter
public class PlcGateway extends RealDeviceConfig {
private PlcGatewayConfigVO config;
private Channel channel;
/** 失败累计 */
private int failures;
public PlcGateway(ProjectDeviceVO deviceVO) {
super(deviceVO);
this.config = deviceVO.buildPlcGatewayConfig();
}
public void updateChannel(Channel channel) {
this.channel = channel;
}
public Boolean isOnline() {
return Objects.nonNull(this.channel);
}
public synchronized void failAdd() {
this.failures++;
}
public synchronized void removeChannel() {
this.channel = null;
this.failures = 0;
}
public synchronized void resetFailures() {
this.failures = 0;
}
@Override
public String findDeviceCode() {
return config == null ? null : config.findDeviceCode();
}
}

View File

@ -1,93 +0,0 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device;
import club.joylink.rtss.constants.ProjectDeviceType;
import club.joylink.rtss.simulation.cbtc.data.map.MapNamedElement;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import java.math.BigInteger;
import java.util.Objects;
@Slf4j
@Getter
public abstract class RealDeviceConfig {
private ProjectDeviceVO projectDevice;
protected MapNamedElement mapElement;
public RealDeviceConfig(ProjectDeviceVO projectDevice) {
this.projectDevice = projectDevice;
}
public static ByteBuf getDeviceCoilStatus(ByteBuf totalCoilStatus, Integer addr, Integer quantity) {
int capacity = quantity / 8;
ByteBuf buffer = Unpooled.buffer(capacity);
byte[] array = new byte[totalCoilStatus.readableBytes()];
totalCoilStatus.getBytes(0, array);
StringBuilder sb = new StringBuilder();
for (byte b : array) {
StringBuilder bsb = new StringBuilder();
String bs = Integer.toBinaryString(b);
if (bs.length() < 8) {
for (int i = 0; i < 8 - bs.length(); i++) {
bsb.append(0);
}
} else if (bs.length() > 8) {
bs = bs.substring(bs.length() - 8);
}
bsb.append(bs);
bsb.reverse();
sb.append(bsb);
}
String bitStr = sb.substring(addr, addr + quantity);
for (int i = 0; i < capacity; i++) {
String binaryByteStr = bitStr.substring(i * 8, (i + 1) * 8);
byte b = new BigInteger(binaryByteStr, 2).byteValue();
buffer.writeByte(b);
}
return buffer;
}
public void connect(MapNamedElement vrDevice) {
this.mapElement = vrDevice;
log.debug(String.format("设备[%s]连接了仿真设备[%s]", this.projectDevice.toString(), mapElement.debugStr()));
}
public void disconnect() {
if (Objects.nonNull(this.mapElement)) {
this.mapElement = null;
}
}
/**
* 获取指定位值
*
* @param buf
* @param bitIndex 从左到右位的索引
* @return
*/
public static boolean getBitOf(ByteBuf buf, int bitIndex) {
int index = bitIndex / 8; // 第几字节
int nbIndex = 8 - (bitIndex % 8) - 1; // 新的位索引
byte val = buf.getByte(index);
return (val & (1 << nbIndex)) != 0;
}
public String getProject() {
return this.projectDevice.getProject();
}
public ProjectDeviceType getDeviceType() {
return this.projectDevice.getType();
}
/**
* 仿真设备的code
* 目前用于实体设备配置与仿真设备连接
*/
public abstract String findDeviceCode();
}

View File

@ -3,10 +3,8 @@ package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gxsd;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gzb.GzbSignalConfig;
import club.joylink.rtss.vo.client.project.gzb.GzbSignalConfigVO;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import lombok.Getter;

View File

@ -1,10 +1,9 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gxsd;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.gxsd.GxsdSignalConfigVO;
import club.joylink.rtss.vo.client.project.gzb.GzbSignalConfigVO;
import java.util.Objects;
import lombok.Getter;

View File

@ -3,20 +3,13 @@ package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gxsd;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SignalAspect;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal.Fault;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gzb.GzbSignalConfig;
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.gxsd.GxsdSignalConfigVO;
import club.joylink.rtss.vo.client.project.gzb.GzbSignalConfigVO;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import java.util.Objects;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
@ -59,7 +52,8 @@ public class GxsdSignalServiceImpl extends GxsdService {
GxsdSignalConfigVO config = switchConfig.getConfig();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + config.getAddr();
ByteBuf signalStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, config.getAddr(), config.getQuantity());
ByteBuf signalStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, config.getAddr(),
config.getQuantity());
boolean br0 = RealDeviceConfig.getBitOf(signalStatus, config.getR1());//红灯
boolean br3 = RealDeviceConfig.getBitOf(signalStatus, config.getR3());//绿灯或黄灯
@ -92,38 +86,54 @@ public class GxsdSignalServiceImpl extends GxsdService {
}
switch (vrSignal.getCommand()) {
case RY: {
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW3(), w3, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW4(), w4, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW5(), w5, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW3(), w3, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW4(), w4, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW5(), w5, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW7(), w7, true, channel);
break;
}
case G: {
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW3(), w3, true, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW4(), w4, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW5(), w5, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW7(), w7, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW4(), w4, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW5(), w5, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW7(), w7, false,
channel);
break;
}
case Y: {
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW3(), w3, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW3(), w3, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW4(), w4, true, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW5(), w5, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW7(), w7, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW5(), w5, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW7(), w7, false,
channel);
break;
}
case R: {
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW3(), w3, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW4(), w4, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW5(), w5, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW7(), w7, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW3(), w3, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW4(), w4, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW5(), w5, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW7(), w7, false,
channel);
break;
}
case No: {
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW3(), w3, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW4(), w4, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW3(), w3, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW4(), w4, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW5(), w5, true, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW7(), w7, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW7(), w7, false,
channel);
break;
}
}

View File

@ -1,11 +1,9 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gxsd;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.gxsd.GxsdSignalConfigVO;
import club.joylink.rtss.vo.client.project.gxsd.GxsdSwitchConfigVO;
import club.joylink.rtss.vo.client.project.gzb.GzbSwitchConfigVO;
import java.time.LocalDateTime;
import java.util.Objects;
import lombok.Getter;
@ -83,7 +81,8 @@ public class GxsdSwitchConfig extends RealDeviceConfig {
/**
* 同步道岔状态表示以限定此时道岔可以进行的操作 此方法是为了防止类似以下情况通过仿真将道岔操到定位再手摇道岔到反位则此时仿真中道岔表示为反位 只能执行定操又因此处记录上一次操作也是定操不予执行导致死循环仿真中无法再操作道岔了
* 同步道岔状态表示以限定此时道岔可以进行的操作 此方法是为了防止类似以下情况通过仿真将道岔操到定位再手摇道岔到反位则此时仿真中道岔表示为反位
* 只能执行定操又因此处记录上一次操作也是定操不予执行导致死循环仿真中无法再操作道岔了
*/
public void sync(boolean r_db, boolean r_fb) {
if (r_db) {

View File

@ -1,20 +1,12 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gxsd;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gzb.GzbSignalConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.say.SaySwitchConfig;
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.gxsd.GxsdSwitchConfigVO;
import club.joylink.rtss.vo.client.project.say.SaySwitchConfigVO;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import java.util.Objects;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
@ -51,7 +43,8 @@ public class GxsdSwitchServiceImpl extends GxsdService {
GxsdSwitchConfig config = (GxsdSwitchConfig) deviceConfig;
GxsdSwitchConfigVO configVO = config.getConfig();
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(), configVO.getQuantity());
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(),
configVO.getQuantity());
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
Channel channel = plcGateway.getChannel();
VirtualRealitySwitch vrSwitch = (VirtualRealitySwitch) config.getMapElement();
@ -89,30 +82,42 @@ public class GxsdSwitchServiceImpl extends GxsdService {
}
private void turnToN(ByteBuf deviceStatus, int baseAddr, GxsdSwitchConfigVO configVO, Channel channel) {
private void turnToN(ByteBuf deviceStatus, int baseAddr, GxsdSwitchConfigVO configVO,
Channel channel) {
boolean w_sb = RealDeviceConfig.getBitOf(deviceStatus, configVO.getWsj());
boolean w_dc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getWdc());
boolean w_fc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getWfc());
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWsj(), w_sb, true, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWdc(), w_dc, true, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWfc(), w_fc, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWsj(), w_sb, true,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWdc(), w_dc, true,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWfc(), w_fc, false,
channel);
}
private void turnToP(ByteBuf deviceStatus, int baseAddr, GxsdSwitchConfigVO configVO, Channel channel) {
private void turnToP(ByteBuf deviceStatus, int baseAddr, GxsdSwitchConfigVO configVO,
Channel channel) {
boolean w_sb = RealDeviceConfig.getBitOf(deviceStatus, configVO.getWsj());
boolean w_dc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getWdc());
boolean w_fc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getWfc());
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWsj(), w_sb, true, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWdc(), w_dc, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWfc(), w_fc, true, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWsj(), w_sb, true,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWdc(), w_dc, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWfc(), w_fc, true,
channel);
}
private void release(ByteBuf deviceStatus, int baseAddr, GxsdSwitchConfigVO configVO, Channel channel) {
private void release(ByteBuf deviceStatus, int baseAddr, GxsdSwitchConfigVO configVO,
Channel channel) {
boolean w_sb = RealDeviceConfig.getBitOf(deviceStatus, configVO.getWsj());
boolean w_dc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getWdc());
boolean w_fc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getWfc());
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWsj(), w_sb, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWdc(), w_dc, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWfc(), w_fc, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWsj(), w_sb, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWdc(), w_dc, false,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getWfc(), w_fc, false,
channel);
}
}

View File

@ -1,27 +1,26 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gzb;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.gzb.GzbSignalConfigVO;
import lombok.Getter;
import java.util.Objects;
import lombok.Getter;
@Getter
public class GzbSignalConfig extends RealDeviceConfig {
private GzbSignalConfigVO config;
private GzbSignalConfigVO config;
public GzbSignalConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
if (Objects.nonNull(deviceVO.getConfig())) {
this.config = JsonUtils.read(deviceVO.getConfig(), GzbSignalConfigVO.class);
}
public GzbSignalConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
if (Objects.nonNull(deviceVO.getConfig())) {
this.config = JsonUtils.read(deviceVO.getConfig(), GzbSignalConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return config.findDeviceCode();
}
@Override
public String findDeviceCode() {
return config.findDeviceCode();
}
}

View File

@ -5,106 +5,126 @@ import club.joylink.rtss.simulation.cbtc.constant.SignalAspect;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
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.gzb.GzbSignalConfigVO;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Objects;
@Slf4j
@Component
public class GzbSignalServiceImpl implements RealDeviceService {
@Autowired
private PlcGatewayService plcGatewayService;
@Autowired
private PlcGatewayService plcGatewayService;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof GzbSignalConfig;
}
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof GzbSignalConfig;
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
// 默认初始化为灭灯状态
GzbSignalConfig switchConfig = (GzbSignalConfig) deviceConfig;
GzbSignalConfigVO config = switchConfig.getConfig();
PlcGateway plcGateway = simulation.getPlcGateway();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + config.getAddr();
this.plcGatewayService.writeSingleCoil(baseAddr, config.getW8(), true, channel);
this.plcGatewayService.writeSingleCoil(baseAddr, config.getW9(), false, channel);
this.plcGatewayService.writeSingleCoil(baseAddr, config.getW10(), false, channel);
this.plcGatewayService.writeSingleCoil(baseAddr, config.getW11(), false, channel);
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
// 默认初始化为灭灯状态
GzbSignalConfig switchConfig = (GzbSignalConfig) deviceConfig;
GzbSignalConfigVO config = switchConfig.getConfig();
PlcGateway plcGateway = simulation.getPlcGateway();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + config.getAddr();
this.plcGatewayService.writeSingleCoil(baseAddr, config.getW8(), true, channel);
this.plcGatewayService.writeSingleCoil(baseAddr, config.getW9(), false, channel);
this.plcGatewayService.writeSingleCoil(baseAddr, config.getW10(), false, channel);
this.plcGatewayService.writeSingleCoil(baseAddr, config.getW11(), false, channel);
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig,
ByteBuf coilStatus) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
GzbSignalConfig switchConfig = (GzbSignalConfig) deviceConfig;
VirtualRealitySignal vrSignal = ((VirtualRealitySignal) switchConfig.getMapElement());
if (Objects.nonNull(vrSignal)) {
GzbSignalConfigVO config = switchConfig.getConfig();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + config.getAddr();
ByteBuf signalStatus = RealDeviceConfig.getDeviceCoilStatus(coilStatus, config.getAddr(), config.getQuantity());
boolean br0 = RealDeviceConfig.getBitOf(signalStatus, config.getR0());
boolean br1 = RealDeviceConfig.getBitOf(signalStatus, config.getR1());
boolean br2 = RealDeviceConfig.getBitOf(signalStatus, config.getR2());
boolean br3 = RealDeviceConfig.getBitOf(signalStatus, config.getR3());
boolean br4 = RealDeviceConfig.getBitOf(signalStatus, config.getR4());
boolean bw8 = RealDeviceConfig.getBitOf(signalStatus, config.getW8());
boolean bw9 = RealDeviceConfig.getBitOf(signalStatus, config.getW9());
boolean bw10 = RealDeviceConfig.getBitOf(signalStatus, config.getW10());
boolean bw11 = RealDeviceConfig.getBitOf(signalStatus, config.getW11());
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig,
ByteBuf coilStatus) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
GzbSignalConfig switchConfig = (GzbSignalConfig) deviceConfig;
VirtualRealitySignal vrSignal = ((VirtualRealitySignal) switchConfig.getMapElement());
if (Objects.nonNull(vrSignal)) {
GzbSignalConfigVO config = switchConfig.getConfig();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + config.getAddr();
ByteBuf signalStatus = RealDeviceConfig.getDeviceCoilStatus(coilStatus, config.getAddr(),
config.getQuantity());
boolean br0 = RealDeviceConfig.getBitOf(signalStatus, config.getR0());
boolean br1 = RealDeviceConfig.getBitOf(signalStatus, config.getR1());
boolean br2 = RealDeviceConfig.getBitOf(signalStatus, config.getR2());
boolean br3 = RealDeviceConfig.getBitOf(signalStatus, config.getR3());
boolean br4 = RealDeviceConfig.getBitOf(signalStatus, config.getR4());
boolean bw8 = RealDeviceConfig.getBitOf(signalStatus, config.getW8());
boolean bw9 = RealDeviceConfig.getBitOf(signalStatus, config.getW9());
boolean bw10 = RealDeviceConfig.getBitOf(signalStatus, config.getW10());
boolean bw11 = RealDeviceConfig.getBitOf(signalStatus, config.getW11());
// 信号机采集控制
if (SignalAspect.RY.equals(vrSignal.getCommand())) { // 开红黄
if (!br0 && !br1 && br2 && !br3 && br4) { // 黄红灯已开
return;
}
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW8(), bw8, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW9(), bw9, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW10(), bw10, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW11(), bw11, true, channel);
} else if (SignalAspect.R.equals(vrSignal.getCommand())) { // 开红灯
if (!br0 && !br1 && !br2 && !br3 && br4) { // 红灯已开
return;
}
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW8(), bw8, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW9(), bw9, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW10(), bw10, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW11(), bw11, false, channel);
} else if (SignalAspect.G.equals(vrSignal.getCommand())) { // 开绿灯
if (br0 && br1 && !br2 && !br3 && br4) { // 绿灯已开
return;
}
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW8(), bw8, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW9(), bw9, true, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW10(), bw10, true, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW11(), bw11, false, channel);
} else if (SignalAspect.Y.equals(vrSignal.getCommand())) { // 开黄灯
if (br0 && !br1 && !br2 && !br3 && br4) { // 黄灯已开
return;
}
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW8(), bw8, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW9(), bw9, true, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW10(), bw10, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW11(), bw11, false, channel);
} else if (SignalAspect.No.equals(vrSignal.getCommand())) { // 灭灯
if (!br4) { // 已灭灯
return;
}
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW8(), bw8, true, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW9(), bw9, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW10(), bw10, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW11(), bw11, false, channel);
}
// 信号机采集控制
if (SignalAspect.RY.equals(vrSignal.getCommand())) { // 开红黄
if (!br0 && !br1 && br2 && !br3 && br4) { // 黄红灯已开
return;
}
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW8(), bw8, false,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW9(), bw9, false,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW10(), bw10, false,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW11(), bw11, true,
channel);
} else if (SignalAspect.R.equals(vrSignal.getCommand())) { // 开红灯
if (!br0 && !br1 && !br2 && !br3 && br4) { // 红灯已开
return;
}
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW8(), bw8, false,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW9(), bw9, false,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW10(), bw10, false,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW11(), bw11, false,
channel);
} else if (SignalAspect.G.equals(vrSignal.getCommand())) { // 开绿灯
if (br0 && br1 && !br2 && !br3 && br4) { // 绿灯已开
return;
}
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW8(), bw8, false,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW9(), bw9, true,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW10(), bw10, true,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW11(), bw11, false,
channel);
} else if (SignalAspect.Y.equals(vrSignal.getCommand())) { // 开黄灯
if (br0 && !br1 && !br2 && !br3 && br4) { // 黄灯已开
return;
}
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW8(), bw8, false,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW9(), bw9, true,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW10(), bw10, false,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW11(), bw11, false,
channel);
} else if (SignalAspect.No.equals(vrSignal.getCommand())) { // 灭灯
if (!br4) { // 已灭灯
return;
}
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW8(), bw8, true,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW9(), bw9, false,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW10(), bw10, false,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getW11(), bw11, false,
channel);
}
}
}
}

View File

@ -1,27 +1,26 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gzb;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.gzb.GzbSwitchConfigVO;
import lombok.Getter;
import java.util.Objects;
import lombok.Getter;
@Getter
public class GzbSwitchConfig extends RealDeviceConfig {
private GzbSwitchConfigVO config;
private GzbSwitchConfigVO config;
public GzbSwitchConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
if (Objects.nonNull(deviceVO.getConfig())) {
this.config = JsonUtils.read(deviceVO.getConfig(), GzbSwitchConfigVO.class);
}
public GzbSwitchConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
if (Objects.nonNull(deviceVO.getConfig())) {
this.config = JsonUtils.read(deviceVO.getConfig(), GzbSwitchConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return config.findDeviceCode();
}
@Override
public String findDeviceCode() {
return config.findDeviceCode();
}
}

View File

@ -4,86 +4,95 @@ import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
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.gzb.GzbSwitchConfigVO;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Objects;
@Slf4j
@Component
public class GzbSwitchServiceImpl implements RealDeviceService {
@Autowired
private PlcGatewayService plcGatewayService;
@Autowired
private PlcGatewayService plcGatewayService;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof GzbSwitchConfig;
}
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof GzbSwitchConfig;
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
// 默认初始化到定位
GzbSwitchConfig switchConfig = (GzbSwitchConfig) deviceConfig;
GzbSwitchConfigVO config = switchConfig.getConfig();
PlcGateway plcGateway = simulation.getPlcGateway();
this.turn2Normal(plcGateway, config);
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
// 默认初始化到定位
GzbSwitchConfig switchConfig = (GzbSwitchConfig) deviceConfig;
GzbSwitchConfigVO config = switchConfig.getConfig();
PlcGateway plcGateway = simulation.getPlcGateway();
this.turn2Normal(plcGateway, config);
}
private void turn2Normal(PlcGateway plcGateway, GzbSwitchConfigVO config) {
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + config.getAddr();
this.plcGatewayService.writeSingleCoil(baseAddr, config.getWrp(), false, channel);
this.plcGatewayService.writeSingleCoil(baseAddr, config.getWsn(), true, channel);
this.plcGatewayService.writeSingleCoil(baseAddr, config.getWnp(), true, channel);
}
private void turn2Normal(PlcGateway plcGateway, GzbSwitchConfigVO config) {
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + config.getAddr();
this.plcGatewayService.writeSingleCoil(baseAddr, config.getWrp(), false, channel);
this.plcGatewayService.writeSingleCoil(baseAddr, config.getWsn(), true, channel);
this.plcGatewayService.writeSingleCoil(baseAddr, config.getWnp(), true, channel);
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig,
ByteBuf coilStatus) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
GzbSwitchConfig switchConfig = (GzbSwitchConfig) deviceConfig;
VirtualRealitySwitch vrSwitch = ((VirtualRealitySwitch) switchConfig.getMapElement());
if (Objects.nonNull(vrSwitch)) {
GzbSwitchConfigVO config = switchConfig.getConfig();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + config.getAddr();
ByteBuf switchStatus = RealDeviceConfig.getDeviceCoilStatus(coilStatus, config.getAddr(), config.getQuantity());
boolean rbnp = RealDeviceConfig.getBitOf(switchStatus, config.getRnp());
boolean rbrp = RealDeviceConfig.getBitOf(switchStatus, config.getRrp());
boolean wbl = RealDeviceConfig.getBitOf(switchStatus, config.getWsn());
boolean wbnp = RealDeviceConfig.getBitOf(switchStatus, config.getWnp());
boolean wbrp = RealDeviceConfig.getBitOf(switchStatus, config.getWrp());
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig,
ByteBuf coilStatus) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
GzbSwitchConfig switchConfig = (GzbSwitchConfig) deviceConfig;
VirtualRealitySwitch vrSwitch = ((VirtualRealitySwitch) switchConfig.getMapElement());
if (Objects.nonNull(vrSwitch)) {
GzbSwitchConfigVO config = switchConfig.getConfig();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + config.getAddr();
ByteBuf switchStatus = RealDeviceConfig.getDeviceCoilStatus(coilStatus, config.getAddr(),
config.getQuantity());
boolean rbnp = RealDeviceConfig.getBitOf(switchStatus, config.getRnp());
boolean rbrp = RealDeviceConfig.getBitOf(switchStatus, config.getRrp());
boolean wbl = RealDeviceConfig.getBitOf(switchStatus, config.getWsn());
boolean wbnp = RealDeviceConfig.getBitOf(switchStatus, config.getWnp());
boolean wbrp = RealDeviceConfig.getBitOf(switchStatus, config.getWrp());
if (vrSwitch.isTurning()) { // 道岔转动中
if (vrSwitch.isCommandNp()) { // 定操
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWrp(), wbrp, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWsn(), wbl, true, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWnp(), wbnp, true, channel);
} else { // 反操
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWnp(), wbnp, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWsn(), wbl, true, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWrp(), wbrp, true, channel);
}
} else { // 非转换中清空
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWnp(), wbnp, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWsn(), wbl, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWrp(), wbrp, false, channel);
}
// 虚拟道岔应用实际道岔位值状态
if (rbnp && rbrp) {
// 故障状态
log.error(String.format("道岔[%s]故障", switchConfig.getProjectDevice()));
return;
}
vrSwitch.apply(rbnp, rbrp);
if (vrSwitch.isTurning()) { // 道岔转动中
if (vrSwitch.isCommandNp()) { // 定操
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWrp(), wbrp,
false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWsn(), wbl, true,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWnp(), wbnp, true,
channel);
} else { // 反操
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWnp(), wbnp,
false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWsn(), wbl, true,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWrp(), wbrp, true,
channel);
}
} else { // 非转换中清空
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWnp(), wbnp, false,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWsn(), wbl, false,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWrp(), wbrp, false,
channel);
}
// 虚拟道岔应用实际道岔位值状态
if (rbnp && rbrp) {
// 故障状态
log.error(String.format("道岔[%s]故障", switchConfig.getProjectDevice()));
return;
}
vrSwitch.apply(rbnp, rbrp);
}
}
}

View File

@ -1,22 +1,23 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.vo.client.project.IbpConfigVO;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import lombok.Getter;
@Getter
public class Heb1IbpConfig extends RealDeviceConfig {
private IbpConfigVO config;
public Heb1IbpConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
IbpConfigVO ibpConfigVO = deviceVO.buildIbpConfig();
this.config = ibpConfigVO;
}
private IbpConfigVO config;
@Override
public String findDeviceCode() {
return config.findDeviceCode();
}
public Heb1IbpConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
IbpConfigVO ibpConfigVO = deviceVO.buildIbpConfig();
this.config = ibpConfigVO;
}
@Override
public String findDeviceCode() {
return config.findDeviceCode();
}
}

View File

@ -1,6 +1,6 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.PscConfigVO;
import lombok.Getter;
@ -8,16 +8,16 @@ import lombok.Getter;
@Getter
public class Heb1PscConfig extends RealDeviceConfig {
private PscConfigVO config;
private PscConfigVO config;
public Heb1PscConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
PscConfigVO config = projectDevice.buildPscConfig();
this.config = config;
}
public Heb1PscConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
PscConfigVO config = projectDevice.buildPscConfig();
this.config = config;
}
@Override
public String findDeviceCode() {
return config.findDeviceCode();
}
@Override
public String findDeviceCode() {
return config.findDeviceCode();
}
}

View File

@ -1,6 +1,6 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.PslConfigVO;
import lombok.Getter;
@ -8,16 +8,16 @@ import lombok.Getter;
@Getter
public class Heb1PslConfig extends RealDeviceConfig {
private PslConfigVO config;
private PslConfigVO config;
public Heb1PslConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
PslConfigVO config = projectDevice.buildPslConfig();
this.config = config;
}
public Heb1PslConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
PslConfigVO config = projectDevice.buildPslConfig();
this.config = config;
}
@Override
public String findDeviceCode() {
return config.findDeviceCode();
}
@Override
public String findDeviceCode() {
return config.findDeviceCode();
}
}

View File

@ -1,18 +1,18 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import lombok.Getter;
@Getter
public class Heb1SignalConfig extends RealDeviceConfig {
public Heb1SignalConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
}
public Heb1SignalConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
}
@Override
public String findDeviceCode() {
return null;
}
@Override
public String findDeviceCode() {
return null;
}
}

View File

@ -1,6 +1,6 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.SwitchConfigVO;
import lombok.Getter;
@ -8,22 +8,22 @@ import lombok.Getter;
@Getter
public class Heb1SwitchConfig extends RealDeviceConfig {
private SwitchConfigVO config;
private SwitchConfigVO config;
public Heb1SwitchConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
SwitchConfigVO config = deviceVO.buildSwitchConfig();
this.config = config;
public Heb1SwitchConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
SwitchConfigVO config = deviceVO.buildSwitchConfig();
this.config = config;
// this.addr = config.getAddr();
// this.rnp = Integer.valueOf(config.getRnp());
// this.rrp = Integer.valueOf(config.getRrp());
// this.rl = Integer.valueOf(config.getRl());
// this.wnp = Integer.valueOf(config.getWnp());
// this.wrp = Integer.valueOf(config.getWrp());
}
}
@Override
public String findDeviceCode() {
return config.findDeviceCode();
}
@Override
public String findDeviceCode() {
return config.findDeviceCode();
}
}

View File

@ -2,7 +2,7 @@ package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.service;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.handler.ModbusMessageHandler2;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device.Heb1PscConfig;
import io.netty.buffer.ByteBuf;
@ -14,54 +14,66 @@ import org.springframework.stereotype.Component;
@Slf4j
@Component
public class Heb1PscServiceImpl implements RealDeviceService {
@Autowired
private ModbusMessageHandler2 modbusMessageHandler;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof Heb1PscConfig;
}
@Autowired
private ModbusMessageHandler2 modbusMessageHandler;
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
Heb1PscConfig pscConfig = (Heb1PscConfig) deviceConfig;
this.close(pscConfig, simulation.getPlcGateway().getChannel());
}
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof Heb1PscConfig;
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
Heb1PscConfig pscConfig = (Heb1PscConfig) deviceConfig;
this.close(pscConfig, simulation.getPlcGateway().getChannel());
}
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
public void open(Heb1PscConfig pscConfig, Channel channel) {
this.modbusMessageHandler.writeSingleCoil(channel, pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWpslgm(), false);
this.modbusMessageHandler.writeSingleCoil(channel, pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWpslsn(), true);
this.modbusMessageHandler.writeSingleCoil(channel, pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWpslkm(), true);
}
}
public void close(Heb1PscConfig pscConfig, Channel channel) {
this.modbusMessageHandler.writeSingleCoil(channel, pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWpslkm(), false);
this.modbusMessageHandler.writeSingleCoil(channel, pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWpslsn(), true);
this.modbusMessageHandler.writeSingleCoil(channel, pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWpslgm(), true);
}
public void open(Heb1PscConfig pscConfig, Channel channel) {
this.modbusMessageHandler.writeSingleCoil(channel,
pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWpslgm(), false);
this.modbusMessageHandler.writeSingleCoil(channel,
pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWpslsn(), true);
this.modbusMessageHandler.writeSingleCoil(channel,
pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWpslkm(), true);
}
public void controlPslEnable(Heb1PscConfig pscConfig, boolean val, Channel channel) {
this.modbusMessageHandler.writeSingleCoil(channel, pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWpslsn(), val);
}
public void close(Heb1PscConfig pscConfig, Channel channel) {
this.modbusMessageHandler.writeSingleCoil(channel,
pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWpslkm(), false);
this.modbusMessageHandler.writeSingleCoil(channel,
pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWpslsn(), true);
this.modbusMessageHandler.writeSingleCoil(channel,
pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWpslgm(), true);
}
public void controlIbpEnable(Heb1PscConfig pscConfig, boolean val, Channel channel) {
this.modbusMessageHandler.writeSingleCoil(channel, pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWibpsn(), val);
}
public void controlPslEnable(Heb1PscConfig pscConfig, boolean val, Channel channel) {
this.modbusMessageHandler.writeSingleCoil(channel,
pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWpslsn(), val);
}
public void controlIbpKm(Heb1PscConfig pscConfig, boolean val, Channel channel) {
this.modbusMessageHandler.writeSingleCoil(channel, pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWibpkm(), val);
}
public void controlIbpEnable(Heb1PscConfig pscConfig, boolean val, Channel channel) {
this.modbusMessageHandler.writeSingleCoil(channel,
pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWibpsn(), val);
}
public void controlIbpGm(Heb1PscConfig pscConfig, boolean val, Channel channel) {
this.modbusMessageHandler.writeSingleCoil(channel, pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWibpgm(), val);
}
public void controlIbpKm(Heb1PscConfig pscConfig, boolean val, Channel channel) {
this.modbusMessageHandler.writeSingleCoil(channel,
pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWibpkm(), val);
}
public void controlIbpHsjc(Heb1PscConfig pscConfig, boolean val, Channel channel) {
this.modbusMessageHandler.writeSingleCoil(channel, pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWpslhsjc(), val);
}
public void controlIbpGm(Heb1PscConfig pscConfig, boolean val, Channel channel) {
this.modbusMessageHandler.writeSingleCoil(channel,
pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWibpgm(), val);
}
public void controlIbpHsjc(Heb1PscConfig pscConfig, boolean val, Channel channel) {
this.modbusMessageHandler.writeSingleCoil(channel,
pscConfig.getConfig().getAddr() + pscConfig.getConfig().getWpslhsjc(), val);
}
}

View File

@ -7,8 +7,8 @@ import club.joylink.rtss.simulation.cbtc.data.map.PSD;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityScreenDoor;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
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.simulation.cbtc.device.real.modbustcp.handler.ModbusMessageHandler2;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device.Heb1PscConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device.Heb1PslConfig;
@ -17,218 +17,247 @@ import club.joylink.rtss.vo.client.project.PscConfigVO;
import club.joylink.rtss.vo.client.project.PslConfigVO;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Objects;
@Slf4j
@Component
public class Heb1PslServiceImpl implements RealDeviceService {
@Autowired
private ModbusMessageHandler2 modbusMessageHandler;
@Autowired
private PlcGatewayService plcGatewayService;
@Autowired
private ModbusMessageHandler2 modbusMessageHandler;
private VirtualRealityDeviceService virtualRealityDeviceService;
@Autowired
private CiApiService ciApiService;
@Autowired
private PlcGatewayService plcGatewayService;
@Autowired
private Heb1PscServiceImpl heb1PscService;
private VirtualRealityDeviceService virtualRealityDeviceService;
@Autowired
private CiApiService ciApiService;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof Heb1PslConfig;
@Autowired
private Heb1PscServiceImpl heb1PscService;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof Heb1PslConfig;
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
}
public void controlIbpzsd(Heb1PslConfig pslConfig, boolean open, Channel channel) {
if (!channel.isWritable()) {
log.debug(String.format("channel 不可写控制IBP信号灯modbus不发送"));
return;
}
Integer baseAddr = pslConfig.getConfig().getAddr();
this.modbusMessageHandler.writeSingleCoil(channel,
baseAddr + pslConfig.getConfig().getWibpczd(), open);
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf coilStatus) {
PlcGateway plcGateway = simulation.getPlcGateway();
Heb1PslConfig pslConfig = (Heb1PslConfig) deviceConfig;
PslConfigVO config = pslConfig.getConfig();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + config.getAddr();
ByteBuf pslStatus = RealDeviceConfig.getDeviceCoilStatus(coilStatus, config.getAddr(),
config.getQuantity());
boolean rsd = RealDeviceConfig.getBitOf(pslStatus, config.getRsdan());//灯测试按钮
boolean rpslcz = RealDeviceConfig.getBitOf(pslStatus, config.getRpslcz());//PSL操作旋钮
boolean rgm = RealDeviceConfig.getBitOf(pslStatus, config.getRgman());//关门按钮
boolean rkm = RealDeviceConfig.getBitOf(pslStatus, config.getRkman());//开门按钮
boolean rhsjc = RealDeviceConfig.getBitOf(pslStatus, config.getRjc());//互锁解除按钮
boolean rjjtc = RealDeviceConfig.getBitOf(pslStatus, config.getRjtan());//紧急停车
boolean wpsl = RealDeviceConfig.getBitOf(pslStatus, config.getWpslyxd());//PSL允许指示灯
boolean wqbmgb = RealDeviceConfig.getBitOf(pslStatus, config.getWqbgbd());//全部门关闭指示灯
boolean wkmdw = RealDeviceConfig.getBitOf(pslStatus, config.getWkmdwd());//开门到位指示灯
boolean whsjc = RealDeviceConfig.getBitOf(pslStatus, config.getWjcd());//互锁解除指示灯
boolean wibp = RealDeviceConfig.getBitOf(pslStatus, config.getWibpczd());//IBP操作指示灯
boolean wpst = RealDeviceConfig.getBitOf(pslStatus, config.getWpstczd());//PST操作指示灯
VirtualRealityScreenDoor vrPsd = (VirtualRealityScreenDoor) pslConfig.getMapElement();
boolean vrExist = Objects.nonNull(vrPsd);
// 处理关联的PSC控制
Heb1PscConfig pscConfig = simulation.queryPscDevice();
this.controlPsc(simulation, plcGateway, rpslcz, rkm, rgm, rhsjc, vrPsd, pscConfig, coilStatus);
this.plcGatewayService.handleRelation(baseAddr, config.getWpslyxd(), rpslcz, wpsl, channel);
// 紧急停车
if (vrExist) {
PSD psd = simulation.getRepository().getByCode(vrPsd.getCode(), PSD.class);
ESP esp = psd.getStand().getEsp();
if (rjjtc) {
this.ciApiService.setEst(simulation, esp);
} else {
this.ciApiService.cancelEst(simulation, esp);
}
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
if (rpslcz) { // PSL操作允许
// 开门按钮
if (rkm && !rgm) {
// 开门指令
if (vrExist && !vrPsd.isSettingOpen() && !vrPsd.isOpen2End()) {
log.info(String.format("仿真[%s]PSL设备[%s]执行控制PSD开门",
simulation.getId(), pslConfig.getProjectDevice()));
this.virtualRealityDeviceService.control(simulation, vrPsd,
VirtualRealityScreenDoor.Operation.K);
}
}
// 关门按钮
else if (rgm && !rkm) {
// 关门指令
if (vrExist && !vrPsd.isSettingClose() && !vrPsd.isClose()) {
log.info(String.format("仿真[%s]PSL设备[%s]执行控制PSD关门",
simulation.getId(), pslConfig.getProjectDevice()));
this.virtualRealityDeviceService.control(simulation, vrPsd,
VirtualRealityScreenDoor.Operation.G);
}
}
// 互锁解除按钮
if (Objects.nonNull(vrPsd)) {
if (rhsjc && !vrPsd.isInterlockRelease()) {
log.info(String.format("仿真[%s]PSL设备[%s]互锁解除执行",
simulation.getId(), pslConfig.getProjectDevice()));
vrPsd.setPslInterlockRelease(true);
} else if (!rhsjc && vrPsd.isInterlockRelease()) {
log.info(String.format("仿真[%s]PSL设备[%s]互锁解除取消",
simulation.getId(), pslConfig.getProjectDevice()));
vrPsd.setPslInterlockRelease(false);
}
}
}
public void controlIbpzsd(Heb1PslConfig pslConfig, boolean open, Channel channel) {
if (!channel.isWritable()) {
log.debug(String.format("channel 不可写控制IBP信号灯modbus不发送"));
return;
}
Integer baseAddr = pslConfig.getConfig().getAddr();
this.modbusMessageHandler.writeSingleCoil(channel, baseAddr + pslConfig.getConfig().getWibpczd(), open);
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf coilStatus) {
PlcGateway plcGateway = simulation.getPlcGateway();
Heb1PslConfig pslConfig = (Heb1PslConfig) deviceConfig;
PslConfigVO config = pslConfig.getConfig();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + config.getAddr();
ByteBuf pslStatus = RealDeviceConfig.getDeviceCoilStatus(coilStatus, config.getAddr(), config.getQuantity());
boolean rsd = RealDeviceConfig.getBitOf(pslStatus, config.getRsdan());//灯测试按钮
boolean rpslcz = RealDeviceConfig.getBitOf(pslStatus, config.getRpslcz());//PSL操作旋钮
boolean rgm = RealDeviceConfig.getBitOf(pslStatus, config.getRgman());//关门按钮
boolean rkm = RealDeviceConfig.getBitOf(pslStatus, config.getRkman());//开门按钮
boolean rhsjc = RealDeviceConfig.getBitOf(pslStatus, config.getRjc());//互锁解除按钮
boolean rjjtc = RealDeviceConfig.getBitOf(pslStatus, config.getRjtan());//紧急停车
boolean wpsl = RealDeviceConfig.getBitOf(pslStatus, config.getWpslyxd());//PSL允许指示灯
boolean wqbmgb = RealDeviceConfig.getBitOf(pslStatus, config.getWqbgbd());//全部门关闭指示灯
boolean wkmdw = RealDeviceConfig.getBitOf(pslStatus, config.getWkmdwd());//开门到位指示灯
boolean whsjc = RealDeviceConfig.getBitOf(pslStatus, config.getWjcd());//互锁解除指示灯
boolean wibp = RealDeviceConfig.getBitOf(pslStatus, config.getWibpczd());//IBP操作指示灯
boolean wpst = RealDeviceConfig.getBitOf(pslStatus, config.getWpstczd());//PST操作指示灯
VirtualRealityScreenDoor vrPsd = (VirtualRealityScreenDoor) pslConfig.getMapElement();
boolean vrExist = Objects.nonNull(vrPsd);
// 处理关联的PSC控制
Heb1PscConfig pscConfig = simulation.queryPscDevice();
this.controlPsc(simulation, plcGateway, rpslcz, rkm, rgm, rhsjc, vrPsd, pscConfig, coilStatus);
this.plcGatewayService.handleRelation(baseAddr, config.getWpslyxd(), rpslcz, wpsl, channel);
// 紧急停车
if (vrExist) {
PSD psd = simulation.getRepository().getByCode(vrPsd.getCode(), PSD.class);
ESP esp = psd.getStand().getEsp();
if (rjjtc) {
this.ciApiService.setEst(simulation, esp);
} else {
this.ciApiService.cancelEst(simulation, esp);
}
}
if (rpslcz) { // PSL操作允许
// 开门按钮
if (rkm && !rgm) {
// 开门指令
if (vrExist && !vrPsd.isSettingOpen() && !vrPsd.isOpen2End()) {
log.info(String.format("仿真[%s]PSL设备[%s]执行控制PSD开门",
simulation.getId(), pslConfig.getProjectDevice()));
this.virtualRealityDeviceService.control(simulation, vrPsd, VirtualRealityScreenDoor.Operation.K);
}
}
// 关门按钮
else if (rgm && !rkm) {
// 关门指令
if (vrExist && !vrPsd.isSettingClose() && !vrPsd.isClose()) {
log.info(String.format("仿真[%s]PSL设备[%s]执行控制PSD关门",
simulation.getId(), pslConfig.getProjectDevice()));
this.virtualRealityDeviceService.control(simulation, vrPsd, VirtualRealityScreenDoor.Operation.G);
}
}
// 互锁解除按钮
if (Objects.nonNull(vrPsd)) {
if (rhsjc && !vrPsd.isInterlockRelease()) {
log.info(String.format("仿真[%s]PSL设备[%s]互锁解除执行",
simulation.getId(), pslConfig.getProjectDevice()));
vrPsd.setPslInterlockRelease(true);
} else if(!rhsjc && vrPsd.isInterlockRelease()) {
log.info(String.format("仿真[%s]PSL设备[%s]互锁解除取消",
simulation.getId(), pslConfig.getProjectDevice()));
vrPsd.setPslInterlockRelease(false);
}
}
}
// 试灯按钮
if (rsd) {
// 试灯按钮按下开灯
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslyxd(), wpsl, true, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWkmdwd(), wkmdw, true, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWqbgbd(), wqbmgb, true, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWjcd(), whsjc, true, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWibpczd(), wibp, true, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpstczd(), wpst, true, channel);
} else {
// PSL指示灯控制
this.plcGatewayService.handleRelation(baseAddr, config.getWpslyxd(), rpslcz, wpsl, channel);
this.plcGatewayService.handleRelation(baseAddr, config.getWjcd(), rhsjc, whsjc, channel);
// 试灯按钮
if (rsd) {
// 试灯按钮按下开灯
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslyxd(), wpsl, true,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWkmdwd(), wkmdw, true,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWqbgbd(), wqbmgb,
true, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWjcd(), whsjc, true,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWibpczd(), wibp, true,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpstczd(), wpst, true,
channel);
} else {
// PSL指示灯控制
this.plcGatewayService.handleRelation(baseAddr, config.getWpslyxd(), rpslcz, wpsl, channel);
this.plcGatewayService.handleRelation(baseAddr, config.getWjcd(), rhsjc, whsjc, channel);
// // 全部门关闭/开门到位指示灯
if (Objects.nonNull(vrPsd)) {
if (vrPsd.isLockAndClose()) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWqbgbd(), wqbmgb, true, channel);
} else if (!vrPsd.isLockAndClose()) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWqbgbd(), wqbmgb, false, channel);
}
if (vrPsd.isOpen2End()) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWkmdwd(), wkmdw, true, channel);
} else if (!vrPsd.isOpen2End()) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWkmdwd(), wkmdw, false, channel);
}
} else {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWqbgbd(), wqbmgb, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWkmdwd(), wkmdw, false, channel);
}
// PST指示灯
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpstczd(), wpst, false, channel);
if (Objects.nonNull(vrPsd)) {
if (vrPsd.isLockAndClose()) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWqbgbd(), wqbmgb,
true, channel);
} else if (!vrPsd.isLockAndClose()) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWqbgbd(), wqbmgb,
false, channel);
}
}
private void controlPsc(Simulation simulation, PlcGateway plcGateway,
boolean rpslcz, boolean rkm, boolean rgm, boolean rhsjc,
VirtualRealityScreenDoor vrPsd, Heb1PscConfig pscConfig, ByteBuf coilStatus) {
if (Objects.nonNull(pscConfig) && Objects.nonNull(vrPsd) && Objects.equals(vrPsd, pscConfig.getMapElement())) {
PscConfigVO config = pscConfig.getConfig();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + config.getAddr();
ByteBuf pslStatus = RealDeviceConfig.getDeviceCoilStatus(coilStatus, config.getAddr(), config.getQuantity());
boolean wbsn = RealDeviceConfig.getBitOf(pslStatus, config.getWpslsn());//PSL操作使能
boolean wbkm = RealDeviceConfig.getBitOf(pslStatus, config.getWpslkm());//PSL开门
boolean wbgm = RealDeviceConfig.getBitOf(pslStatus, config.getWpslgm());//PSL关门
boolean wbhsjc = RealDeviceConfig.getBitOf(pslStatus, config.getWpslhsjc());//PSL互锁解除
boolean sn;
boolean km;
boolean gm;
if (vrPsd.isTurning()) {
if (VirtualRealityScreenDoor.Operation.K.equals(vrPsd.getCommand())) { // 开门
sn = true;
km = true;
gm = false;
} else { // 关门
sn = true;
km = false;
gm = true;
}
} else {
sn = rpslcz;
km = rkm;
gm = rgm;
}
if (sn) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslsn(), wbsn, true, channel);
} else {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslsn(), wbsn, false, channel);
}
if (km) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslkm(), wbkm, true, channel);
} else {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslkm(), wbkm, false, channel);
}
if (gm) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslgm(), wbgm, true, channel);
} else {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslgm(), wbgm, false, channel);
}
if (rhsjc) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslhsjc(), wbhsjc, true, channel);
} else {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslhsjc(), wbhsjc, false, channel);
}
if (vrPsd.isOpen2End()) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWkmdwd(), wkmdw,
true, channel);
} else if (!vrPsd.isOpen2End()) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWkmdwd(), wkmdw,
false, channel);
}
} else {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWqbgbd(), wqbmgb,
false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWkmdwd(), wkmdw,
false, channel);
}
// PST指示灯
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpstczd(), wpst,
false, channel);
}
}
private void controlPsc(Simulation simulation, boolean rpslcz, boolean rkm, boolean rgm, VirtualRealityScreenDoor vrPsd, Heb1PscConfig pscConfig, Channel channel) {
if (Objects.nonNull(pscConfig) && Objects.nonNull(vrPsd) && Objects.equals(vrPsd, pscConfig.getMapElement())) {
if (rpslcz) {
this.heb1PscService.controlPslEnable(pscConfig, true, channel);
} else {
if (!vrPsd.isTurning()) {
this.heb1PscService.controlPslEnable(pscConfig, false, channel);
}
}
private void controlPsc(Simulation simulation, PlcGateway plcGateway,
boolean rpslcz, boolean rkm, boolean rgm, boolean rhsjc,
VirtualRealityScreenDoor vrPsd, Heb1PscConfig pscConfig, ByteBuf coilStatus) {
if (Objects.nonNull(pscConfig) && Objects.nonNull(vrPsd) && Objects.equals(vrPsd,
pscConfig.getMapElement())) {
PscConfigVO config = pscConfig.getConfig();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + config.getAddr();
ByteBuf pslStatus = RealDeviceConfig.getDeviceCoilStatus(coilStatus, config.getAddr(),
config.getQuantity());
boolean wbsn = RealDeviceConfig.getBitOf(pslStatus, config.getWpslsn());//PSL操作使能
boolean wbkm = RealDeviceConfig.getBitOf(pslStatus, config.getWpslkm());//PSL开门
boolean wbgm = RealDeviceConfig.getBitOf(pslStatus, config.getWpslgm());//PSL关门
boolean wbhsjc = RealDeviceConfig.getBitOf(pslStatus, config.getWpslhsjc());//PSL互锁解除
boolean sn;
boolean km;
boolean gm;
if (vrPsd.isTurning()) {
if (VirtualRealityScreenDoor.Operation.K.equals(vrPsd.getCommand())) { // 开门
sn = true;
km = true;
gm = false;
} else { // 关门
sn = true;
km = false;
gm = true;
}
} else {
sn = rpslcz;
km = rkm;
gm = rgm;
}
if (sn) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslsn(), wbsn,
true, channel);
} else {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslsn(), wbsn,
false, channel);
}
if (km) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslkm(), wbkm,
true, channel);
} else {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslkm(), wbkm,
false, channel);
}
if (gm) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslgm(), wbgm,
true, channel);
} else {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslgm(), wbgm,
false, channel);
}
if (rhsjc) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslhsjc(), wbhsjc,
true, channel);
} else {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWpslhsjc(), wbhsjc,
false, channel);
}
}
}
private void controlPsc(Simulation simulation, boolean rpslcz, boolean rkm, boolean rgm,
VirtualRealityScreenDoor vrPsd, Heb1PscConfig pscConfig, Channel channel) {
if (Objects.nonNull(pscConfig) && Objects.nonNull(vrPsd) && Objects.equals(vrPsd,
pscConfig.getMapElement())) {
if (rpslcz) {
this.heb1PscService.controlPslEnable(pscConfig, true, channel);
} else {
if (!vrPsd.isTurning()) {
this.heb1PscService.controlPslEnable(pscConfig, false, channel);
}
}
}
}
}

View File

@ -4,82 +4,92 @@ import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
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.simulation.cbtc.device.real.modbustcp.heb.device.Heb1SwitchConfig;
import club.joylink.rtss.vo.client.project.SwitchConfigVO;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Objects;
@Slf4j
@Component
public class Heb1SwitchServiceImpl implements RealDeviceService {
@Autowired
private PlcGatewayService plcGatewayService;
@Autowired
private PlcGatewayService plcGatewayService;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof Heb1SwitchConfig;
}
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof Heb1SwitchConfig;
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
// 默认初始化到定位
Heb1SwitchConfig switchConfig = (Heb1SwitchConfig) deviceConfig;
SwitchConfigVO config = switchConfig.getConfig();
PlcGateway plcGateway = simulation.getPlcGateway();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + config.getAddr();
this.plcGatewayService.writeSingleCoil(baseAddr, config.getWrp(), false, channel);
this.plcGatewayService.writeSingleCoil(baseAddr, config.getWl(), true, channel);
this.plcGatewayService.writeSingleCoil(baseAddr, config.getWnp(), true, channel);
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
// 默认初始化到定位
Heb1SwitchConfig switchConfig = (Heb1SwitchConfig) deviceConfig;
SwitchConfigVO config = switchConfig.getConfig();
PlcGateway plcGateway = simulation.getPlcGateway();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + config.getAddr();
this.plcGatewayService.writeSingleCoil(baseAddr, config.getWrp(), false, channel);
this.plcGatewayService.writeSingleCoil(baseAddr, config.getWl(), true, channel);
this.plcGatewayService.writeSingleCoil(baseAddr, config.getWnp(), true, channel);
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig,
ByteBuf coilStatus) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
Heb1SwitchConfig switchConfig = (Heb1SwitchConfig) deviceConfig;
VirtualRealitySwitch vrSwitch = ((VirtualRealitySwitch) switchConfig.getMapElement());
if (Objects.nonNull(vrSwitch)) {
SwitchConfigVO config = switchConfig.getConfig();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + config.getAddr();
ByteBuf switchStatus = RealDeviceConfig.getDeviceCoilStatus(coilStatus, config.getAddr(), config.getQuantity());
boolean rbnp = RealDeviceConfig.getBitOf(switchStatus, config.getRnp());
boolean rbrp = RealDeviceConfig.getBitOf(switchStatus, config.getRrp());
boolean wbl = RealDeviceConfig.getBitOf(switchStatus, config.getWl());
boolean wbnp = RealDeviceConfig.getBitOf(switchStatus, config.getWnp());
boolean wbrp = RealDeviceConfig.getBitOf(switchStatus, config.getWrp());
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig,
ByteBuf coilStatus) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
Heb1SwitchConfig switchConfig = (Heb1SwitchConfig) deviceConfig;
VirtualRealitySwitch vrSwitch = ((VirtualRealitySwitch) switchConfig.getMapElement());
if (Objects.nonNull(vrSwitch)) {
SwitchConfigVO config = switchConfig.getConfig();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + config.getAddr();
ByteBuf switchStatus = RealDeviceConfig.getDeviceCoilStatus(coilStatus, config.getAddr(),
config.getQuantity());
boolean rbnp = RealDeviceConfig.getBitOf(switchStatus, config.getRnp());
boolean rbrp = RealDeviceConfig.getBitOf(switchStatus, config.getRrp());
boolean wbl = RealDeviceConfig.getBitOf(switchStatus, config.getWl());
boolean wbnp = RealDeviceConfig.getBitOf(switchStatus, config.getWnp());
boolean wbrp = RealDeviceConfig.getBitOf(switchStatus, config.getWrp());
if (vrSwitch.isTurning()) { // 道岔转动中
if (vrSwitch.isCommandNp()) { // 定操
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWrp(), wbrp, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWl(), wbl, true, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWnp(), wbnp, true, channel);
} else { // 反操
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWnp(), wbnp, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWl(), wbl, true, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWrp(), wbrp, true, channel);
}
} else { // 未转动清空
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWnp(), wbnp, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWl(), wbl, false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWrp(), wbrp, false, channel);
}
// 虚拟道岔应用实际道岔位值状态
if (rbnp && rbrp) {
log.error(String.format("道岔[%s]状态检查异常,道岔位置同时是定位和反位", switchConfig.getProjectDevice()));
return;
}
vrSwitch.apply(rbnp, rbrp);
if (vrSwitch.isTurning()) { // 道岔转动中
if (vrSwitch.isCommandNp()) { // 定操
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWrp(), wbrp,
false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWl(), wbl, true,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWnp(), wbnp, true,
channel);
} else { // 反操
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWnp(), wbnp,
false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWl(), wbl, true,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWrp(), wbrp, true,
channel);
}
} else { // 未转动清空
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWnp(), wbnp, false,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWl(), wbl, false,
channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getWrp(), wbrp, false,
channel);
}
// 虚拟道岔应用实际道岔位值状态
if (rbnp && rbrp) {
log.error(String.format("道岔[%s]状态检查异常,道岔位置同时是定位和反位",
switchConfig.getProjectDevice()));
return;
}
vrSwitch.apply(rbnp, rbrp);
}
}
}

View File

@ -1,6 +1,6 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.hhcj;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.hhcj.HhcjIbpConfigVO;
@ -10,24 +10,25 @@ import lombok.Setter;
@Getter
@Setter
public class HhcjIbpConfig extends RealDeviceConfig {
private HhcjIbpConfigVO configVO;
/**
* 消防泵1#是否在运行
*/
private boolean xfsb_yxxfb1;
private HhcjIbpConfigVO configVO;
private boolean xfsb_yxxfb2;
/**
* 消防泵1#是否在运行
*/
private boolean xfsb_yxxfb1;
public HhcjIbpConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (projectDevice != null) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), HhcjIbpConfigVO.class);
}
private boolean xfsb_yxxfb2;
public HhcjIbpConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (projectDevice != null) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), HhcjIbpConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
}

View File

@ -1,6 +1,6 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.hhcj;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.hhcj.HhcjPsdConfigVO;
@ -10,17 +10,18 @@ import lombok.Setter;
@Getter
@Setter
public class HhcjPsdConfig extends RealDeviceConfig {
private HhcjPsdConfigVO configVO;
public HhcjPsdConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (projectDevice != null) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), HhcjPsdConfigVO.class);
}
}
private HhcjPsdConfigVO configVO;
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
public HhcjPsdConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (projectDevice != null) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), HhcjPsdConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
}

View File

@ -5,8 +5,8 @@ import club.joylink.rtss.simulation.cbtc.constant.SimulationModule;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityScreenDoor;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
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.hhcj.HhcjPsdConfigVO;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
@ -15,54 +15,60 @@ import org.springframework.stereotype.Service;
@Service
public class HhcjPsdServiceImpl implements RealDeviceService {
@Autowired
private PlcGatewayService plcGatewayService;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof HhcjPsdConfig;
@Autowired
private PlcGatewayService plcGatewayService;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof HhcjPsdConfig;
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
//不需要初始化逻辑因为所有的状态都来源于IBP盘上按钮的状态
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (plcGateway == null) {
return;
}
HhcjPsdConfig config = (HhcjPsdConfig) deviceConfig;
VirtualRealityScreenDoor vrPsd = (VirtualRealityScreenDoor) config.getMapElement();
if (vrPsd == null) {
return;
}
HhcjPsdConfigVO configVO = config.getConfigVO();
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(),
configVO.getQuantity());
boolean w_km = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_km());
boolean w_gm = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_gm());
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
Channel channel = plcGateway.getChannel();
boolean newKm;
boolean newGm;
if (vrPsd.isSettingOpen()) {
newKm = true;
newGm = false;
} else if (vrPsd.isSettingClose()) {
newKm = false;
newGm = true;
} else {
newKm = false;
newGm = false;
}
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_km(), w_km, newKm,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_gm(), w_gm, newGm,
channel);
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
//不需要初始化逻辑因为所有的状态都来源于IBP盘上按钮的状态
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (plcGateway == null)
return;
HhcjPsdConfig config = (HhcjPsdConfig) deviceConfig;
VirtualRealityScreenDoor vrPsd = (VirtualRealityScreenDoor) config.getMapElement();
if (vrPsd == null)
return;
HhcjPsdConfigVO configVO = config.getConfigVO();
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(), configVO.getQuantity());
boolean w_km = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_km());
boolean w_gm = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_gm());
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
Channel channel = plcGateway.getChannel();
boolean newKm;
boolean newGm;
if (vrPsd.isSettingOpen()) {
newKm = true;
newGm = false;
} else if (vrPsd.isSettingClose()) {
newKm = false;
newGm = true;
} else {
newKm = false;
newGm = false;
}
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_km(), w_km, newKm, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_gm(), w_gm, newGm, channel);
if (vrPsd.getRemain() > 0) {
vrPsd.turning(SimulationModule.VRD.getRateMs());
}
if (vrPsd.getRemain() > 0) {
vrPsd.turning(SimulationModule.VRD.getRateMs());
}
}
}

View File

@ -1,6 +1,6 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.say;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.say.SayIbpConfigVO;
@ -10,26 +10,27 @@ import lombok.Setter;
@Getter
@Setter
public class SayIbpConfig extends RealDeviceConfig {
private SayIbpConfigVO configVO;
//防淹门上行关门到位
private boolean fymSxKmdw;
private boolean fymXxKmdw;
//排烟风机1号风机运行
private boolean pyfj1Yx;
private boolean pyfj2Yx;
//消防水泵1/2号运行
private boolean xfsbYx;
private SayIbpConfigVO configVO;
public SayIbpConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (projectDevice != null) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SayIbpConfigVO.class);
}
//防淹门上行关门到位
private boolean fymSxKmdw;
private boolean fymXxKmdw;
//排烟风机1号风机运行
private boolean pyfj1Yx;
private boolean pyfj2Yx;
//消防水泵1/2号运行
private boolean xfsbYx;
public SayIbpConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (projectDevice != null) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SayIbpConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO == null ? null : configVO.findDeviceCode();
}
@Override
public String findDeviceCode() {
return configVO == null ? null : configVO.findDeviceCode();
}
}

View File

@ -1,7 +1,7 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.say;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.SimulationRealDeviceThread;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.say.SayPsdConfigVO;
@ -11,36 +11,37 @@ import lombok.Setter;
@Getter
@Setter
public class SayPsdConfig extends RealDeviceConfig {
private SayPsdConfigVO configVO;
/**
* 使能剩余时间屏蔽门开关门过程中需要使能位持续处于闭合状态故设置使能位固定接通5秒
*/
private int enableRemain;
private SayPsdConfigVO configVO;
public void enableStart() {
enableRemain = 5000;
/**
* 使能剩余时间屏蔽门开关门过程中需要使能位持续处于闭合状态故设置使能位固定接通5秒
*/
private int enableRemain;
public void enableStart() {
enableRemain = 5000;
}
public void enableRemainReduce() {
if (isEnable()) {
enableRemain -= SimulationRealDeviceThread.COLLECT_RATE;
}
}
public void enableRemainReduce() {
if (isEnable()) {
enableRemain -= SimulationRealDeviceThread.COLLECT_RATE;
}
}
public boolean isEnable() {
return enableRemain > 0;
}
public boolean isEnable() {
return enableRemain > 0;
public SayPsdConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (projectDevice != null) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SayPsdConfigVO.class);
}
}
public SayPsdConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (projectDevice != null) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SayPsdConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO == null ? null : configVO.findDeviceCode();
}
@Override
public String findDeviceCode() {
return configVO == null ? null : configVO.findDeviceCode();
}
}

View File

@ -5,8 +5,8 @@ import club.joylink.rtss.simulation.cbtc.constant.SimulationModule;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityScreenDoor;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
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.say.SayPsdConfigVO;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
@ -17,66 +17,73 @@ import org.springframework.stereotype.Service;
@Slf4j
@Service
public class SayPsdServiceImpl implements RealDeviceService {
@Autowired
private PlcGatewayService plcGatewayService;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof SayPsdConfig;
}
@Autowired
private PlcGatewayService plcGatewayService;
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
//不需要初始化逻辑因为所有的状态都来源于IBP盘上按钮的状态
}
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof SayPsdConfig;
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (plcGateway == null)
return;
SayPsdConfig config = (SayPsdConfig) deviceConfig;
VirtualRealityScreenDoor vrPsd = (VirtualRealityScreenDoor) config.getMapElement();
if (vrPsd == null)
return;
SayPsdConfigVO configVO = config.getConfigVO();
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(), configVO.getQuantity());
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
//不需要初始化逻辑因为所有的状态都来源于IBP盘上按钮的状态
}
boolean w_km = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_km());
boolean w_gm = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_gm());
boolean w_enable = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_enable());
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (plcGateway == null) {
return;
}
SayPsdConfig config = (SayPsdConfig) deviceConfig;
VirtualRealityScreenDoor vrPsd = (VirtualRealityScreenDoor) config.getMapElement();
if (vrPsd == null) {
return;
}
SayPsdConfigVO configVO = config.getConfigVO();
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(),
configVO.getQuantity());
boolean w_km = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_km());
boolean w_gm = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_gm());
boolean w_enable = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_enable());
// boolean r_km = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_km());
// boolean r_gm = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_gm());
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
Channel channel = plcGateway.getChannel();
boolean needKm;
boolean needGm;
if (vrPsd.isSettingOpen()) {
log.info("开门指令");
needKm = true;
needGm = false;
} else if (vrPsd.isSettingClose()) {
log.info("关门指令");
needKm = false;
needGm = true;
} else {
needKm = false;
needGm = false;
}
if (config.isEnable()) { //已经处于使能状态倒计时状态
log.info("使能");
config.enableRemainReduce();
} else { //未处于使能状态
if (needKm || needGm) { //有开关门指令待执行
config.enableStart(); //使能开始
}
}
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_enable(), w_enable, config.isEnable(), channel);
boolean needKm;
boolean needGm;
if (vrPsd.isSettingOpen()) {
log.info("开门指令");
needKm = true;
needGm = false;
} else if (vrPsd.isSettingClose()) {
log.info("关门指令");
needKm = false;
needGm = true;
} else {
needKm = false;
needGm = false;
}
if (config.isEnable()) { //已经处于使能状态倒计时状态
log.info("使能");
config.enableRemainReduce();
} else { //未处于使能状态
if (needKm || needGm) { //有开关门指令待执行
config.enableStart(); //使能开始
}
}
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_enable(), w_enable,
config.isEnable(), channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_km(), w_km, needKm, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_gm(), w_gm, needGm, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_km(), w_km, needKm,
channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_gm(), w_gm, needGm,
channel);
// if (r_km) {
// vrPsd.updateOpen2End(true);
@ -85,8 +92,8 @@ public class SayPsdServiceImpl implements RealDeviceService {
// vrPsd.updateLockAndClose(true, true);
// }
if (vrPsd.getRemain() > 0) {
vrPsd.turning(SimulationModule.VRD.getRateMs());
}
if (vrPsd.getRemain() > 0) {
vrPsd.turning(SimulationModule.VRD.getRateMs());
}
}
}

View File

@ -1,6 +1,6 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.say;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.say.SaySectionConfigVO;

View File

@ -3,8 +3,8 @@ package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.say;
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.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
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.say.SaySectionConfigVO;
import io.netty.buffer.ByteBuf;
import org.springframework.stereotype.Service;

View File

@ -1,6 +1,6 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.say;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.say.SaySignalConfigVO;

View File

@ -5,8 +5,8 @@ import club.joylink.rtss.simulation.cbtc.constant.SignalAspect;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
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.say.SaySignalConfigVO;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;

View File

@ -1,94 +1,94 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.say;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.say.SaySwitchConfigVO;
import lombok.Getter;
import java.time.LocalDateTime;
import lombok.Getter;
@Getter
public class SaySwitchConfig extends RealDeviceConfig {
private SaySwitchConfigVO configVO;
/**
* 下令定操
*/
private boolean turnToN;
private SaySwitchConfigVO configVO;
/**
* 下令反
*/
private boolean turnToP;
/**
* 下令定操
*/
private boolean turnToN;
/**
* 定反操继电器接通时刻
* 3s后断开继电器防止继电器长期接通
*/
private LocalDateTime startTime;
/**
* 下令反操
*/
private boolean turnToP;
public SaySwitchConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (projectDevice != null) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SaySwitchConfigVO.class);
}
/**
* 定反操继电器接通时刻 3s后断开继电器防止继电器长期接通
*/
private LocalDateTime startTime;
public SaySwitchConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (projectDevice != null) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SaySwitchConfigVO.class);
}
}
/**
* 请求转向定位
* @return 是否可以操作继电器以转向定位
*/
public boolean turnToN() {
if (turnToN) {
return false;
} else {
turnToN = true;
turnToP = false;
startTime = LocalDateTime.now();
return true;
}
/**
* 请求转向定位
*
* @return 是否可以操作继电器以转向定位
*/
public boolean turnToN() {
if (turnToN) {
return false;
} else {
turnToN = true;
turnToP = false;
startTime = LocalDateTime.now();
return true;
}
}
/**
* 请求转向反位
* @return 是否可以操作继电器以转向反位
*/
public boolean turnToP() {
if (turnToP) {
return false;
} else {
turnToN = false;
turnToP = true;
startTime = LocalDateTime.now();
return true;
}
/**
* 请求转向反位
*
* @return 是否可以操作继电器以转向反位
*/
public boolean turnToP() {
if (turnToP) {
return false;
} else {
turnToN = false;
turnToP = true;
startTime = LocalDateTime.now();
return true;
}
}
/**
* 定反操的继电器操作是否可以结束
*/
public boolean isEnd() {
return startTime == null || LocalDateTime.now().isAfter(startTime.plusSeconds(3));
}
/**
* 定反操的继电器操作是否可以结束
*/
public boolean isEnd() {
return startTime == null || LocalDateTime.now().isAfter(startTime.plusSeconds(3));
}
/**
* 同步道岔状态表示以限定此时道岔可以进行的操作
* 此方法是为了防止类似以下情况通过仿真将道岔操到定位再手摇道岔到反位则此时仿真中道岔表示为反位
* 只能执行定操又因此处记录上一次操作也是定操不予执行导致死循环仿真中无法再操作道岔了
*/
public void sync(boolean r_db, boolean r_fb) {
if (r_db) {
turnToN = true;
turnToP = false;
} else if (r_fb) {
turnToN = false;
turnToP = true;
}
/**
* 同步道岔状态表示以限定此时道岔可以进行的操作 此方法是为了防止类似以下情况通过仿真将道岔操到定位再手摇道岔到反位则此时仿真中道岔表示为反位
* 只能执行定操又因此处记录上一次操作也是定操不予执行导致死循环仿真中无法再操作道岔了
*/
public void sync(boolean r_db, boolean r_fb) {
if (r_db) {
turnToN = true;
turnToP = false;
} else if (r_fb) {
turnToN = false;
turnToP = true;
}
}
@Override
public String findDeviceCode() {
return configVO == null ? null : configVO.findDeviceCode();
}
@Override
public String findDeviceCode() {
return configVO == null ? null : configVO.findDeviceCode();
}
}

View File

@ -4,8 +4,8 @@ import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
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.say.SaySwitchConfigVO;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;

View File

@ -1,87 +1,86 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.sdy;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.sdy.SdyPsdConfigVO;
import java.time.LocalDateTime;
import lombok.Getter;
import lombok.Setter;
import java.time.LocalDateTime;
@Getter
public class SdyPsdConfig extends RealDeviceConfig {
private SdyPsdConfigVO configVO;
private SdyPsdConfigVO configVO;
/**
* 开门到位
*/
@Setter
private Boolean r_km;
/**
* 开门到位
*/
@Setter
private Boolean r_km;
/**
* 蜂鸣器响起的时间为null表示蜂鸣器当前没响同时作为开关门流程的开始标志
*/
private LocalDateTime buzzerRingingTime;
/**
* 蜂鸣器响起的时间为null表示蜂鸣器当前没响同时作为开关门流程的开始标志
*/
private LocalDateTime buzzerRingingTime;
/**
* 是否触发过开关门控制
*/
@Setter
private boolean triggerOpenOrClose;
/**
* 是否触发过开关门控制
*/
@Setter
private boolean triggerOpenOrClose;
/**
* 开关门过程中即非开/关门到位状态
*/
private boolean running;
/**
* 开关门过程中即非开/关门到位状态
*/
private boolean running;
public SdyPsdConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (projectDevice != null) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SdyPsdConfigVO.class);
}
public SdyPsdConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (projectDevice != null) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SdyPsdConfigVO.class);
}
}
public void reset() {
this.r_km = null;
this.buzzerRingingTime = null;
this.triggerOpenOrClose = false;
this.running = false;
}
public void reset() {
this.r_km = null;
this.buzzerRingingTime = null;
this.triggerOpenOrClose = false;
this.running = false;
}
public void buzzerRinging(LocalDateTime time) {
this.buzzerRingingTime = time;
}
public void buzzerRinging(LocalDateTime time) {
this.buzzerRingingTime = time;
}
/**
* 开始开/关门
*/
public void run() {
this.running = true;
this.triggerOpenOrClose = false; //门已经开始移动触发状态可以去掉了
}
/**
* 开始开/关门
*/
public void run() {
this.running = true;
this.triggerOpenOrClose = false; //门已经开始移动触发状态可以去掉了
}
/**
* /关门结束
*/
public void finishRunning() {
if (running) {
this.buzzerRingingTime = null;
this.running = false;
}
/**
* /关门结束
*/
public void finishRunning() {
if (running) {
this.buzzerRingingTime = null;
this.running = false;
}
}
/**
* 取消控制门的流程
*/
public void cancelControl() {
this.buzzerRingingTime = null;
this.triggerOpenOrClose = false;
}
/**
* 取消控制门的流程
*/
public void cancelControl() {
this.buzzerRingingTime = null;
this.triggerOpenOrClose = false;
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
}

View File

@ -4,142 +4,149 @@ import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityScreenDoor;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
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.sdy.SdyPsdConfigVO;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import java.time.LocalDateTime;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.time.LocalDateTime;
@Slf4j
@Component
public class SdyPsdServiceImpl implements RealDeviceService {
@Autowired
private PlcGatewayService plcGatewayService;
@Autowired
private PlcGatewayService plcGatewayService;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof SdyPsdConfig;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof SdyPsdConfig;
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
PlcGateway plcGateway = simulation.getPlcGateway();
SdyPsdConfig config = (SdyPsdConfig) deviceConfig;
SdyPsdConfigVO configVO = config.getConfigVO();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
this.plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_jb(), false, channel); //关响铃
VirtualRealityScreenDoor vrPsd = (VirtualRealityScreenDoor) config.getMapElement();
if (vrPsd != null) {
vrPsd.control(VirtualRealityScreenDoor.Operation.G);
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
PlcGateway plcGateway = simulation.getPlcGateway();
SdyPsdConfig config = (SdyPsdConfig) deviceConfig;
SdyPsdConfigVO configVO = config.getConfigVO();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
this.plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_jb(), false, channel); //关响铃
VirtualRealityScreenDoor vrPsd = (VirtualRealityScreenDoor) config.getMapElement();
if (vrPsd != null) {
vrPsd.control(VirtualRealityScreenDoor.Operation.G);
}
// plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_jb(), false, channel); //关警报
// if (config.getR_km() != null && config.getR_km()) { //确保关门
// plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_kgm(), false, channel);
// plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_kgm(), true, channel);
// }
config.reset();
config.reset();
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
SdyPsdConfig config = (SdyPsdConfig) deviceConfig;
SdyPsdConfigVO configVO = config.getConfigVO();
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(),
configVO.getQuantity());
boolean km = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_km());
boolean gm = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_gm());
boolean w_kgm = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_kgm());
boolean w_jb = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_jb());
config.setR_km(km);
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (plcGateway == null) {
log.error(String.format("仿真[%s]没有plc", simulation.getId()));
return;
}
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
Channel channel = plcGateway.getChannel();
this.openOrCloseLoop(config, km, gm, baseAddr, w_kgm, channel);
if (!km && !gm) {
config.run();
} else {
if (config.isRunning()) {
this.plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_jb(), false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr,
config.getConfigVO().getW_kgm(), w_kgm, false, channel);
config.finishRunning();
}
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
SdyPsdConfig config = (SdyPsdConfig) deviceConfig;
SdyPsdConfigVO configVO = config.getConfigVO();
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(), configVO.getQuantity());
boolean km = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_km());
boolean gm = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_gm());
boolean w_kgm = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_kgm());
boolean w_jb = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_jb());
config.setR_km(km);
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (plcGateway == null) {
log.error(String.format("仿真[%s]没有plc", simulation.getId()));
return;
VirtualRealityScreenDoor vrPsd = (VirtualRealityScreenDoor) deviceConfig.getMapElement();
if (vrPsd != null) {
//控制realDevice
if (vrPsd.isSettingClose()) {
if (km && !gm) {
this.openOrClose(config, km, gm, baseAddr, channel);
}
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
Channel channel = plcGateway.getChannel();
this.openOrCloseLoop(config, km, gm, baseAddr, w_kgm, channel);
if (!km && !gm) {
config.run();
} else {
if (config.isRunning()) {
this.plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_jb(), false, channel);
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getConfigVO().getW_kgm(), w_kgm, false, channel);
config.finishRunning();
}
}
VirtualRealityScreenDoor vrPsd = (VirtualRealityScreenDoor) deviceConfig.getMapElement();
if (vrPsd != null) {
//控制realDevice
if (vrPsd.isSettingClose()) {
if (km && !gm) {
this.openOrClose(config, km, gm, baseAddr, channel);
}
}
if (vrPsd.isSettingOpen()) {
if (!km && gm) {
this.openOrClose(config, km, gm, baseAddr, channel);
}
}
//从realDevice读取并更新状态
if (!km && !gm) {
vrPsd.turning();
}
if (km && !gm) {
vrPsd.updateOpen2End(true);
}
if (gm && !km) {
vrPsd.updateLockAndClose(true, true);
}
}
if (vrPsd.isSettingOpen()) {
if (!km && gm) {
this.openOrClose(config, km, gm, baseAddr, channel);
}
}
//从realDevice读取并更新状态
if (!km && !gm) {
vrPsd.turning();
}
if (km && !gm) {
vrPsd.updateOpen2End(true);
}
if (gm && !km) {
vrPsd.updateLockAndClose(true, true);
}
}
}
/**
* 触发开关门流程
*/
public void openOrClose(SdyPsdConfig config, boolean km, boolean gm, int baseAddr, Channel channel) {
LocalDateTime buzzerRingingTime = config.getBuzzerRingingTime();
if (buzzerRingingTime != null) { //说明正在开关门流程中
return;
}
if ((km || gm)) {
this.plcGatewayService.writeSingleCoil(baseAddr, config.getConfigVO().getW_jb(), true, channel);
config.buzzerRinging(LocalDateTime.now());
}
/**
* 触发开关门流程
*/
public void openOrClose(SdyPsdConfig config, boolean km, boolean gm, int baseAddr,
Channel channel) {
LocalDateTime buzzerRingingTime = config.getBuzzerRingingTime();
if (buzzerRingingTime != null) { //说明正在开关门流程中
return;
}
if ((km || gm)) {
this.plcGatewayService.writeSingleCoil(baseAddr, config.getConfigVO().getW_jb(), true,
channel);
config.buzzerRinging(LocalDateTime.now());
}
}
/**
* 开关门循环逻辑响铃3秒然后开/关门如果响铃超过6秒门还是没有开始移动有人卡着屏蔽门导致无法关闭中断开关门流程
*/
public void openOrCloseLoop(SdyPsdConfig config, boolean km, boolean gm, int baseAddr, boolean w_kgm, Channel channel) {
LocalDateTime buzzerRingingTime = config.getBuzzerRingingTime();
if (buzzerRingingTime == null) {
return;
}
if (config.isRunning())
return;
LocalDateTime now = LocalDateTime.now();
if (now.isAfter(buzzerRingingTime.plusSeconds(1))) { //蜂鸣器响了超过3秒
if ((km || gm) && !config.isTriggerOpenOrClose()) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getConfigVO().getW_kgm(), w_kgm, true, channel);
config.setTriggerOpenOrClose(true);
}
if (now.isAfter(buzzerRingingTime.plusSeconds(3))) { //如果响铃超过该时长门还没有进入运动状态取消触发状态
/**
* 开关门循环逻辑响铃3秒然后开/关门如果响铃超过6秒门还是没有开始移动有人卡着屏蔽门导致无法关闭中断开关门流程
*/
public void openOrCloseLoop(SdyPsdConfig config, boolean km, boolean gm, int baseAddr,
boolean w_kgm, Channel channel) {
LocalDateTime buzzerRingingTime = config.getBuzzerRingingTime();
if (buzzerRingingTime == null) {
return;
}
if (config.isRunning()) {
return;
}
LocalDateTime now = LocalDateTime.now();
if (now.isAfter(buzzerRingingTime.plusSeconds(1))) { //蜂鸣器响了超过3秒
if ((km || gm) && !config.isTriggerOpenOrClose()) {
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr,
config.getConfigVO().getW_kgm(), w_kgm, true, channel);
config.setTriggerOpenOrClose(true);
}
if (now.isAfter(buzzerRingingTime.plusSeconds(3))) { //如果响铃超过该时长门还没有进入运动状态取消触发状态
// this.plcGatewayService.writeSingleCoil(baseAddr, config.getConfigVO().getW_jb(), false, channel);
// config.cancelControl();
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, config.getConfigVO().getW_kgm(), w_kgm, false, channel);
config.setTriggerOpenOrClose(false);
}
}
this.plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr,
config.getConfigVO().getW_kgm(), w_kgm, false, channel);
config.setTriggerOpenOrClose(false);
}
}
}
}

View File

@ -1,6 +1,6 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.sdy;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.sdy.SdyPslConfigVO;
@ -9,17 +9,17 @@ import lombok.Getter;
@Getter
public class SdyPslConfig extends RealDeviceConfig {
private SdyPslConfigVO configVO;
private SdyPslConfigVO configVO;
public SdyPslConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (projectDevice != null) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SdyPslConfigVO.class);
}
public SdyPslConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (projectDevice != null) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SdyPslConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
}

View File

@ -8,142 +8,157 @@ import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityPsl;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityScreenDoor;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
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.sdy.SdyPsdConfigVO;
import club.joylink.rtss.vo.client.project.sdy.SdyPslConfigVO;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import java.util.Objects;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Objects;
import java.util.Optional;
@Slf4j
@Component
public class SdyPslServiceImpl implements RealDeviceService {
@Autowired
private PlcGatewayService plcGatewayService;
@Autowired
private PlcGatewayService plcGatewayService;
@Autowired
private SdyPsdServiceImpl sdyPsdService;
@Autowired
private SdyPsdServiceImpl sdyPsdService;
@Autowired
private IVirtualRealityPslService iVirtualRealityPslService;
@Autowired
private IVirtualRealityPslService iVirtualRealityPslService;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof SdyPslConfig;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof SdyPslConfig;
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
PlcGateway plcGateway = simulation.getPlcGateway();
SdyPslConfigVO configVO = ((SdyPslConfig) deviceConfig).getConfigVO();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_gm_light(), true, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_km_light(), false, channel);
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (plcGateway == null) {
return;
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
PlcGateway plcGateway = simulation.getPlcGateway();
SdyPslConfigVO configVO = ((SdyPslConfig) deviceConfig).getConfigVO();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_gm_light(), true, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_km_light(), false, channel);
SdyPslConfig config = (SdyPslConfig) deviceConfig;
SdyPslConfigVO configVO = config.getConfigVO();
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(),
configVO.getQuantity());
boolean r_gm_button = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_gm_button());
boolean r_km_button = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_km_button());
boolean r_sd_button = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sd_button());
boolean r_yxjz_key = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_xyjz_key());
boolean r_hsjc_key = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_hsjc_key());
boolean w_gm_light = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_gm_light());
boolean w_km_light = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_km_light());
boolean w_psl_light = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_psl_light());
boolean w_hsjc_light = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_hsjc_light());
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
Channel channel = plcGateway.getChannel();
//查找真实设备和vr设备
SdyPsdConfig realPsd = null;
VirtualRealityScreenDoor vrPsd = null;
Optional<RealDeviceConfig> optional = simulation.getRealDeviceList().stream()
.filter(device -> device.getDeviceType().equals(ProjectDeviceType.PSD)).findAny();
if (optional.isPresent()) {
realPsd = (SdyPsdConfig) optional.get();
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (plcGateway == null)
return;
SdyPslConfig config = (SdyPslConfig) deviceConfig;
SdyPslConfigVO configVO = config.getConfigVO();
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(), configVO.getQuantity());
boolean r_gm_button = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_gm_button());
boolean r_km_button = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_km_button());
boolean r_sd_button = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sd_button());
boolean r_yxjz_key = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_xyjz_key());
boolean r_hsjc_key = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_hsjc_key());
boolean w_gm_light = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_gm_light());
boolean w_km_light = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_km_light());
boolean w_psl_light = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_psl_light());
boolean w_hsjc_light = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_hsjc_light());
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
Channel channel = plcGateway.getChannel();
//查找真实设备和vr设备
SdyPsdConfig realPsd = null;
VirtualRealityScreenDoor vrPsd = null;
Optional<RealDeviceConfig> optional = simulation.getRealDeviceList().stream()
.filter(device -> device.getDeviceType().equals(ProjectDeviceType.PSD)).findAny();
if (optional.isPresent())
realPsd = (SdyPsdConfig) optional.get();
if (realPsd != null)
vrPsd = (VirtualRealityScreenDoor) realPsd.getMapElement();
//收集真实屏蔽门的状态等
SdyPsdConfigVO psdConfigVO = null;
Integer psdBaseAddr = null;
Boolean psd_r_km = null;
Boolean psd_r_gm = null;
Boolean psd_w_kgm = null;
if (realPsd != null) {
psdConfigVO = realPsd.getConfigVO();
psdBaseAddr = plcGateway.getConfig().getAddr() + psdConfigVO.getAddr();
ByteBuf psdStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, psdConfigVO.getAddr(), psdConfigVO.getQuantity());
psd_r_km = RealDeviceConfig.getBitOf(psdStatus, psdConfigVO.getR_km());
psd_r_gm = RealDeviceConfig.getBitOf(psdStatus, psdConfigVO.getR_gm());
psd_w_kgm = RealDeviceConfig.getBitOf(psdStatus, psdConfigVO.getW_kgm());
}
//更新虚拟真实屏蔽门的控制状态
if (realPsd != null) {
vrPsd = (VirtualRealityScreenDoor) realPsd.getMapElement();
}
//收集真实屏蔽门的状态等
SdyPsdConfigVO psdConfigVO = null;
Integer psdBaseAddr = null;
Boolean psd_r_km = null;
Boolean psd_r_gm = null;
Boolean psd_w_kgm = null;
if (realPsd != null) {
psdConfigVO = realPsd.getConfigVO();
psdBaseAddr = plcGateway.getConfig().getAddr() + psdConfigVO.getAddr();
ByteBuf psdStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, psdConfigVO.getAddr(),
psdConfigVO.getQuantity());
psd_r_km = RealDeviceConfig.getBitOf(psdStatus, psdConfigVO.getR_km());
psd_r_gm = RealDeviceConfig.getBitOf(psdStatus, psdConfigVO.getR_gm());
psd_w_kgm = RealDeviceConfig.getBitOf(psdStatus, psdConfigVO.getW_kgm());
}
//更新虚拟真实屏蔽门的控制状态
if (vrPsd != null) {
SimulationDataRepository repository = simulation.getRepository();
VirtualRealityPsl vrPsl = repository.getStandByVrPsd(vrPsd);
vrPsl.setYxjzKey(r_yxjz_key);
}
//所有灯的状态控制
if (r_sd_button) { //试灯按钮按下
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_gm_light(), w_gm_light,
true, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_km_light(), w_km_light,
true, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_psl_light(),
w_psl_light, true, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_hsjc_light(),
w_hsjc_light, true, channel);
} else {
//开关门灯读取状态从真实设备
if (Objects.equals(true, psd_r_gm)) {
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_gm_light(),
w_gm_light, true, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_km_light(),
w_km_light, false, channel);
} else {
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_gm_light(),
w_gm_light, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_km_light(),
w_km_light, true, channel);
}
//psl操作灯
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_psl_light(),
w_psl_light, r_yxjz_key, channel);
//互锁解除灯
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_hsjc_light(),
w_hsjc_light, r_hsjc_key, channel);
}
//允许禁止钥匙处于允许位
if (r_yxjz_key) {
if (psd_r_km || psd_r_gm) { //屏蔽门处于开门/关门到位控制才生效
if (vrPsd != null) {
SimulationDataRepository repository = simulation.getRepository();
VirtualRealityPsl vrPsl = repository.getStandByVrPsd(vrPsd);
vrPsl.setYxjzKey(r_yxjz_key);
}
//所有灯的状态控制
if (r_sd_button) { //试灯按钮按下
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_gm_light(), w_gm_light, true, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_km_light(), w_km_light, true, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_psl_light(), w_psl_light, true, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_hsjc_light(), w_hsjc_light, true, channel);
} else {
//开关门灯读取状态从真实设备
if (Objects.equals(true, psd_r_gm)) {
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_gm_light(), w_gm_light, true, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_km_light(), w_km_light, false, channel);
} else {
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_gm_light(), w_gm_light, false, channel);
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_km_light(), w_km_light, true, channel);
if (r_gm_button && !r_km_button) {
if (!vrPsd.isSettingClose() && !vrPsd.isClose()) {
vrPsd.control(VirtualRealityScreenDoor.Operation.G);
}
//psl操作灯
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_psl_light(), w_psl_light, r_yxjz_key, channel);
//互锁解除灯
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, configVO.getW_hsjc_light(), w_hsjc_light, r_hsjc_key, channel);
}
//允许禁止钥匙处于允许位
if (r_yxjz_key) {
if (psd_r_km || psd_r_gm) { //屏蔽门处于开门/关门到位控制才生效
if (vrPsd != null) {
if (r_gm_button && !r_km_button) {
if (!vrPsd.isSettingClose() && !vrPsd.isClose()) {
vrPsd.control(VirtualRealityScreenDoor.Operation.G);
}
}
if (r_km_button && !r_gm_button) {
if (!vrPsd.isOpen2End()) {
vrPsd.control(VirtualRealityScreenDoor.Operation.K);
}
}
} else if (realPsd != null) {
if (r_gm_button && !r_km_button && psd_r_km) {
sdyPsdService.openOrClose(realPsd, psd_r_km, psd_r_gm, psdBaseAddr, channel);
}
if (r_km_button && !r_gm_button && psd_r_gm) {
sdyPsdService.openOrClose(realPsd, psd_r_km, psd_r_gm, psdBaseAddr, channel);
}
}
}
if (r_km_button && !r_gm_button) {
if (!vrPsd.isOpen2End()) {
vrPsd.control(VirtualRealityScreenDoor.Operation.K);
}
}
} else if (realPsd != null) {
if (r_gm_button && !r_km_button && psd_r_km) {
sdyPsdService.openOrClose(realPsd, psd_r_km, psd_r_gm, psdBaseAddr, channel);
}
if (r_km_button && !r_gm_button && psd_r_gm) {
sdyPsdService.openOrClose(realPsd, psd_r_km, psd_r_gm, psdBaseAddr, channel);
}
}
//互锁解除钥匙
if (vrPsd != null)
vrPsd.setPslInterlockRelease(r_hsjc_key);
}
}
//互锁解除钥匙
if (vrPsd != null) {
vrPsd.setPslInterlockRelease(r_hsjc_key);
}
}
}

View File

@ -1,27 +1,26 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.xty;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.xty.XtyPsdConfigVO;
import lombok.Getter;
import java.util.Objects;
import lombok.Getter;
@Getter
public class XtyPsdConfig extends RealDeviceConfig {
private XtyPsdConfigVO config;
private XtyPsdConfigVO config;
public XtyPsdConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
if (Objects.nonNull(deviceVO.getConfig())) {
this.config = JsonUtils.read(deviceVO.getConfig(), XtyPsdConfigVO.class);
}
public XtyPsdConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
if (Objects.nonNull(deviceVO.getConfig())) {
this.config = JsonUtils.read(deviceVO.getConfig(), XtyPsdConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return config.findDeviceCode();
}
@Override
public String findDeviceCode() {
return config.findDeviceCode();
}
}

View File

@ -4,81 +4,80 @@ import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityScreenDoor;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
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.xty.XtyPsdConfigVO;
import io.netty.buffer.ByteBuf;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Objects;
@Slf4j
@Component
public class XtyPsdServiceImpl implements RealDeviceService {
@Autowired
private PlcGatewayService plcGatewayService;
@Autowired
private PlcGatewayService plcGatewayService;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof XtyPsdConfig;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof XtyPsdConfig;
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
PlcGateway plcGateway = simulation.getPlcGateway();
XtyPsdConfigVO configVO = ((XtyPsdConfig) deviceConfig).getConfig();
int wvgm = configVO.getWvgm();// 关门控制值
this.plcGatewayService.checkEqualAndWriteSingleRegister(plcGateway.getConfig().getAddr(),
configVO.getWbi(), 0, wvgm, plcGateway.getChannel());
}
@Override
public void handle(Simulation simulation, RealDeviceConfig config, ByteBuf byteBuf) {
PlcGateway plcGateway = simulation.getPlcGateway();
VirtualRealityScreenDoor vrPsd = (VirtualRealityScreenDoor) config.getMapElement();
if (Objects.isNull(vrPsd)) { // 未关联设备不处理
return;
}
XtyPsdConfig psdConfig = (XtyPsdConfig) config;
XtyPsdConfigVO configVO = psdConfig.getConfig();
boolean rbmsa = RealDeviceConfig.getBitOf(byteBuf, configVO.getRmsa());
boolean rbmsb = RealDeviceConfig.getBitOf(byteBuf, configVO.getRmsb());
boolean rbmsc = RealDeviceConfig.getBitOf(byteBuf, configVO.getRmsc());
boolean rbgmbndw = RealDeviceConfig.getBitOf(byteBuf, configVO.getRgmbndw());
boolean rbkmbndw = RealDeviceConfig.getBitOf(byteBuf, configVO.getRkmbndw());
boolean rbgmdw = RealDeviceConfig.getBitOf(byteBuf, configVO.getRgmdw());
boolean rbkmdw = RealDeviceConfig.getBitOf(byteBuf, configVO.getRkmdw());
boolean rbhsjc = RealDeviceConfig.getBitOf(byteBuf, configVO.getRhsjc());
boolean rbdm = RealDeviceConfig.getBitOf(byteBuf, configVO.getRdm());
boolean rbyjm = RealDeviceConfig.getBitOf(byteBuf, configVO.getRyjm());
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
PlcGateway plcGateway = simulation.getPlcGateway();
XtyPsdConfigVO configVO = ((XtyPsdConfig) deviceConfig).getConfig();
int wvgm = configVO.getWvgm();// 关门控制值
boolean autoMode = rbmsa && rbmsb && rbmsc;//111:自动模式(信号可控模式)
int cv = byteBuf.getUnsignedShort(configVO.getWbi());// 开关门控制值
int wvkm = configVO.getWvkm(); // 开门控制值
int wvgm = configVO.getWvgm();// 关门控制值
if (vrPsd.isTurning()) { // 屏蔽门设置中且为信号系统可操作状态
if (autoMode && vrPsd.isCommandOpen() && (cv & wvkm) != wvkm) { // 开门
this.plcGatewayService.checkEqualAndWriteSingleRegister(plcGateway.getConfig().getAddr(),
configVO.getWbi(), 0, wvgm, plcGateway.getChannel());
configVO.getWbi(), cv, wvkm, plcGateway.getChannel());
} else if (autoMode && !vrPsd.isCommandOpen() && (cv & wvgm) != wvgm) { // 关门
this.plcGatewayService.checkEqualAndWriteSingleRegister(plcGateway.getConfig().getAddr(),
configVO.getWbi(), cv, wvgm, plcGateway.getChannel());
}
}
@Override
public void handle(Simulation simulation, RealDeviceConfig config, ByteBuf byteBuf) {
PlcGateway plcGateway = simulation.getPlcGateway();
VirtualRealityScreenDoor vrPsd = (VirtualRealityScreenDoor) config.getMapElement();
if (Objects.isNull(vrPsd)) { // 未关联设备不处理
return;
}
XtyPsdConfig psdConfig = (XtyPsdConfig) config;
XtyPsdConfigVO configVO = psdConfig.getConfig();
boolean rbmsa = RealDeviceConfig.getBitOf(byteBuf, configVO.getRmsa());
boolean rbmsb = RealDeviceConfig.getBitOf(byteBuf, configVO.getRmsb());
boolean rbmsc = RealDeviceConfig.getBitOf(byteBuf, configVO.getRmsc());
boolean rbgmbndw = RealDeviceConfig.getBitOf(byteBuf, configVO.getRgmbndw());
boolean rbkmbndw = RealDeviceConfig.getBitOf(byteBuf, configVO.getRkmbndw());
boolean rbgmdw = RealDeviceConfig.getBitOf(byteBuf, configVO.getRgmdw());
boolean rbkmdw = RealDeviceConfig.getBitOf(byteBuf, configVO.getRkmdw());
boolean rbhsjc = RealDeviceConfig.getBitOf(byteBuf, configVO.getRhsjc());
boolean rbdm = RealDeviceConfig.getBitOf(byteBuf, configVO.getRdm());
boolean rbyjm = RealDeviceConfig.getBitOf(byteBuf, configVO.getRyjm());
boolean autoMode = rbmsa && rbmsb && rbmsc;//111:自动模式(信号可控模式)
int cv = byteBuf.getUnsignedShort(configVO.getWbi());// 开关门控制值
int wvkm = configVO.getWvkm(); // 开门控制值
int wvgm = configVO.getWvgm();// 关门控制值
if (vrPsd.isTurning()) { // 屏蔽门设置中且为信号系统可操作状态
if (autoMode && vrPsd.isCommandOpen() && (cv & wvkm) != wvkm) { // 开门
this.plcGatewayService.checkEqualAndWriteSingleRegister(plcGateway.getConfig().getAddr(),
configVO.getWbi(), cv, wvkm, plcGateway.getChannel());
} else if(autoMode && !vrPsd.isCommandOpen() && (cv & wvgm) != wvgm){ // 关门
this.plcGatewayService.checkEqualAndWriteSingleRegister(plcGateway.getConfig().getAddr(),
configVO.getWbi(), cv, wvgm, plcGateway.getChannel());
}
}
if (rbkmdw && rbgmdw) { // 开关门进行中
vrPsd.turning();
}
if (rbkmdw && !rbgmdw) { // 开门到位
vrPsd.updateOpen2End(true);
}
if (rbgmdw && !rbkmdw) { // 关门到位
vrPsd.updateLockAndClose(true, true);
}
// 更新互锁解除状态
vrPsd.setPslInterlockRelease(rbhsjc);
if (rbkmdw && rbgmdw) { // 开关门进行中
vrPsd.turning();
}
if (rbkmdw && !rbgmdw) { // 开门到位
vrPsd.updateOpen2End(true);
}
if (rbgmdw && !rbkmdw) { // 关门到位
vrPsd.updateLockAndClose(true, true);
}
// 更新互锁解除状态
vrPsd.setPslInterlockRelease(rbhsjc);
}
}

View File

@ -1,26 +1,26 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.zjd;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.richor.ZjdIbpConfigVO;
import lombok.Getter;
import java.util.Objects;
import lombok.Getter;
@Getter
public class ZjdIbpConfig extends RealDeviceConfig {
private ZjdIbpConfigVO configVO;
public ZjdIbpConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
if (Objects.nonNull(deviceVO.getConfig())) {
this.configVO = JsonUtils.read(deviceVO.getConfig(), ZjdIbpConfigVO.class);
}
}
private ZjdIbpConfigVO configVO;
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
public ZjdIbpConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
if (Objects.nonNull(deviceVO.getConfig())) {
this.configVO = JsonUtils.read(deviceVO.getConfig(), ZjdIbpConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
}

View File

@ -8,161 +8,190 @@ import club.joylink.rtss.simulation.cbtc.data.vo.iscs.IscsIbpStatusVO;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityIbp;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.PlcGatewayService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
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.simulation.rt.iscs.IscsStatusPublisher;
import club.joylink.rtss.vo.client.project.richor.ZjdIbpConfigVO;
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Objects;
@Slf4j
@Component
public class ZjdIbpServiceImpl implements RealDeviceService {
@Autowired
private PlcGatewayService plcGatewayService;
@Autowired
private PlcGatewayService plcGatewayService;
@Autowired
private CiApiService ciApiService;
@Autowired
private CiApiService ciApiService;
@Autowired
private IVirtualRealityIbpService iVirtualRealityIbpService;
@Autowired
private IVirtualRealityIbpService iVirtualRealityIbpService;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof ZjdIbpConfig;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof ZjdIbpConfig;
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
PlcGateway plcGateway = simulation.getPlcGateway();
ZjdIbpConfigVO configVO = ((ZjdIbpConfig) deviceConfig).getConfigVO();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_sx_kcd(), false, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_sx_jjtcd(), false, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_xx_kcd(), false, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_xx_jjtcd(), false, channel);
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (plcGateway == null) {
return;
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
PlcGateway plcGateway = simulation.getPlcGateway();
ZjdIbpConfigVO configVO = ((ZjdIbpConfig) deviceConfig).getConfigVO();
Channel channel = plcGateway.getChannel();
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_sx_kcd(), false, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_sx_jjtcd(), false, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_xx_kcd(), false, channel);
plcGatewayService.writeSingleCoil(baseAddr, configVO.getW_xx_jjtcd(), false, channel);
ZjdIbpConfig config = (ZjdIbpConfig) deviceConfig;
VirtualRealityIbp vrIbp = (VirtualRealityIbp) config.getMapElement();
if (vrIbp == null) {
return;
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
PlcGateway plcGateway = simulation.queryPlcGatewayDevice();
if (plcGateway == null)
return;
ZjdIbpConfig config = (ZjdIbpConfig) deviceConfig;
VirtualRealityIbp vrIbp = (VirtualRealityIbp) config.getMapElement();
if (vrIbp == null)
return;
ZjdIbpConfigVO configVO = config.getConfigVO();
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(), configVO.getQuantity());
boolean r_xx_jjtc = !RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_xx_jjtc());
boolean r_xx_qxjt = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_xx_qxjt());
boolean r_xx_kc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_xx_kc());
boolean r_xx_qxkc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_xx_qxkc());
boolean r_sx_jjtc = !RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_jjtc());
boolean r_sx_qxjt = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_qxjt());
boolean r_sx_kc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_kc());
boolean r_sx_qxkc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_qxkc());
boolean r_sd = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sd());
boolean r_qdbj = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_qdbj());
boolean w_fmq = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_fmq());
boolean w_xx_jjtcd = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_xx_jjtcd());
boolean w_xx_kcd = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_xx_kcd());
boolean w_sx_jjtcd = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_sx_jjtcd());
boolean w_sx_kcd = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_sx_kcd());
boolean r_sx_czyx = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_czyx());
boolean r_sx_km = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_km());
boolean r_sx_gm = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_gm());
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
Channel channel = plcGateway.getChannel();
//
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.jjtcLight, false, w_xx_kcd);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.kcLight, false, w_xx_kcd);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.jjtcLight, true, w_sx_kcd);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.kcLight, true, w_sx_kcd);
// 按钮灯simulation,
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.JJTC, false, r_xx_jjtc);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.QXJJTC, false, r_xx_qxjt);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.KC, false, r_xx_kc);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.ZZKC, false, r_xx_qxkc);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.JJTC, true, r_sx_jjtc);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.QXJJTC, true, r_sx_qxjt);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.KC, true, r_sx_kc);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.ZZKC, true, r_sx_qxkc);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.XXYS, false, r_sx_czyx);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.KM, true, r_sx_km);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.GM, true, r_sx_gm);
// 按钮
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.JJTC, false, r_xx_jjtc);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.QXJJTC, false, r_xx_qxjt);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.KC, false, r_xx_kc);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.ZZKC, false, r_xx_qxkc);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.JJTC, true, r_sx_jjtc);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.QXJJTC, true, r_sx_qxjt);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.KC, true, r_sx_kc);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.ZZKC, true, r_sx_qxkc);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.ZZKC, null, r_sd);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.XXYS, false, r_sx_czyx);
/*------------------------- 输出 -------------------------*/
for (VirtualRealityIbp.IbpElement element : vrIbp.getAllElements()) {
Integer addr = null;
boolean currentIsOn = false;
Boolean turnOn = null;
if (element.isTurnOn()) {
turnOn = true;
} else if (element.isTurnOff()) {
turnOn = false;
}
switch (element.getMean()) {
case kcLight:
if (Objects.equals(true, element.getUp())) {
addr = configVO.getW_sx_kcd();
currentIsOn = w_sx_kcd;
} else if (Objects.equals(false, element.getUp())) {
addr = configVO.getW_xx_kcd();
currentIsOn = w_xx_kcd;
}
break;
case jjtcLight:
if (Objects.equals(true, element.getUp())) {
addr = configVO.getW_sx_jjtcd();
currentIsOn = w_sx_jjtcd;
} else if (Objects.equals(false, element.getUp())) {
addr = configVO.getW_xx_jjtcd();
currentIsOn = w_xx_jjtcd;
}
break;
}
if (addr != null && turnOn != null) {
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, addr, currentIsOn, turnOn, channel);
}
}
//ISCS状态
SimulationIscsDataRepository iscsRepository = simulation.getIscsRepository();
String iscsCode = configVO.getIscsCode();
IscsIbpStatusVO iscsStatus = (IscsIbpStatusVO) iscsRepository.findStatus(iscsCode);
boolean change;
if (iscsStatus == null) {
IscsIbpStatusVO.DirectionalStatus downStatus =
new IscsIbpStatusVO.DirectionalStatus(r_sx_czyx, r_sx_km, false, r_sx_gm);
iscsStatus = new IscsIbpStatusVO(iscsCode,
vrIbp.getStation().getCode(), null, downStatus);
iscsRepository.addStatus(iscsStatus);
IscsStatusPublisher watcher = simulation.getMessagePublisher(IscsStatusPublisher.NAME, IscsStatusPublisher.class);
simulation.watch(iscsStatus, watcher);
change = true;
} else {
IscsIbpStatusVO.DirectionalStatus downStatus = iscsStatus.getDownStatus();
change = downStatus.compareAndChange(r_sx_czyx, r_sx_km, false, r_sx_gm);
}
if (change) {
iscsStatus.fireWatcher(null, null);
}
ZjdIbpConfigVO configVO = config.getConfigVO();
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(),
configVO.getQuantity());
boolean r_xx_jjtc = !RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_xx_jjtc());
boolean r_xx_qxjt = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_xx_qxjt());
boolean r_xx_kc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_xx_kc());
boolean r_xx_qxkc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_xx_qxkc());
boolean r_sx_jjtc = !RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_jjtc());
boolean r_sx_qxjt = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_qxjt());
boolean r_sx_kc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_kc());
boolean r_sx_qxkc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_qxkc());
boolean r_sd = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sd());
boolean r_qdbj = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_qdbj());
boolean w_fmq = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_fmq());
boolean w_xx_jjtcd = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_xx_jjtcd());
boolean w_xx_kcd = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_xx_kcd());
boolean w_sx_jjtcd = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_sx_jjtcd());
boolean w_sx_kcd = RealDeviceConfig.getBitOf(deviceStatus, configVO.getW_sx_kcd());
boolean r_sx_czyx = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_czyx());
boolean r_sx_km = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_km());
boolean r_sx_gm = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_gm());
int baseAddr = plcGateway.getConfig().getAddr() + configVO.getAddr();
Channel channel = plcGateway.getChannel();
//
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.jjtcLight,
false, w_xx_kcd);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.kcLight,
false, w_xx_kcd);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.jjtcLight,
true, w_sx_kcd);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.kcLight, true,
w_sx_kcd);
// 按钮灯simulation,
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.JJTC, false,
r_xx_jjtc);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.QXJJTC, false,
r_xx_qxjt);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.KC, false,
r_xx_kc);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.ZZKC, false,
r_xx_qxkc);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.JJTC, true,
r_sx_jjtc);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.QXJJTC, true,
r_sx_qxjt);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.KC, true,
r_sx_kc);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.ZZKC, true,
r_sx_qxkc);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.XXYS, false,
r_sx_czyx);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.KM, true,
r_sx_km);
iVirtualRealityIbpService.updateOnOrOff(simulation, vrIbp, VirtualRealityIbp.Mean.GM, true,
r_sx_gm);
// 按钮
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.JJTC, false,
r_xx_jjtc);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.QXJJTC,
false, r_xx_qxjt);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.KC, false,
r_xx_kc);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.ZZKC, false,
r_xx_qxkc);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.JJTC, true,
r_sx_jjtc);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.QXJJTC, true,
r_sx_qxjt);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.KC, true,
r_sx_kc);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.ZZKC, true,
r_sx_qxkc);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.ZZKC, null,
r_sd);
iVirtualRealityIbpService.pressOrRelease(simulation, vrIbp, VirtualRealityIbp.Mean.XXYS, false,
r_sx_czyx);
/*------------------------- 输出 -------------------------*/
for (VirtualRealityIbp.IbpElement element : vrIbp.getAllElements()) {
Integer addr = null;
boolean currentIsOn = false;
Boolean turnOn = null;
if (element.isTurnOn()) {
turnOn = true;
} else if (element.isTurnOff()) {
turnOn = false;
}
switch (element.getMean()) {
case kcLight:
if (Objects.equals(true, element.getUp())) {
addr = configVO.getW_sx_kcd();
currentIsOn = w_sx_kcd;
} else if (Objects.equals(false, element.getUp())) {
addr = configVO.getW_xx_kcd();
currentIsOn = w_xx_kcd;
}
break;
case jjtcLight:
if (Objects.equals(true, element.getUp())) {
addr = configVO.getW_sx_jjtcd();
currentIsOn = w_sx_jjtcd;
} else if (Objects.equals(false, element.getUp())) {
addr = configVO.getW_xx_jjtcd();
currentIsOn = w_xx_jjtcd;
}
break;
}
if (addr != null && turnOn != null) {
plcGatewayService.checkEqualAndWriteSingleCoil(baseAddr, addr, currentIsOn, turnOn,
channel);
}
}
//ISCS状态
SimulationIscsDataRepository iscsRepository = simulation.getIscsRepository();
String iscsCode = configVO.getIscsCode();
IscsIbpStatusVO iscsStatus = (IscsIbpStatusVO) iscsRepository.findStatus(iscsCode);
boolean change;
if (iscsStatus == null) {
IscsIbpStatusVO.DirectionalStatus downStatus =
new IscsIbpStatusVO.DirectionalStatus(r_sx_czyx, r_sx_km, false, r_sx_gm);
iscsStatus = new IscsIbpStatusVO(iscsCode,
vrIbp.getStation().getCode(), null, downStatus);
iscsRepository.addStatus(iscsStatus);
IscsStatusPublisher watcher = simulation.getMessagePublisher(IscsStatusPublisher.NAME,
IscsStatusPublisher.class);
simulation.watch(iscsStatus, watcher);
change = true;
} else {
IscsIbpStatusVO.DirectionalStatus downStatus = iscsStatus.getDownStatus();
change = downStatus.compareAndChange(r_sx_czyx, r_sx_km, false, r_sx_gm);
}
if (change) {
iscsStatus.fireWatcher(null, null);
}
}
}

View File

@ -1,26 +1,26 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.zjd;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.richor.ZjdPsdConfigVO;
import lombok.Getter;
import java.util.Objects;
import lombok.Getter;
@Getter
public class ZjdPsdConfig extends RealDeviceConfig {
private ZjdPsdConfigVO configVO;
public ZjdPsdConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
if (Objects.nonNull(deviceVO.getConfig())) {
this.configVO = JsonUtils.read(deviceVO.getConfig(), ZjdPsdConfigVO.class);
}
}
private ZjdPsdConfigVO configVO;
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
public ZjdPsdConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
if (Objects.nonNull(deviceVO.getConfig())) {
this.configVO = JsonUtils.read(deviceVO.getConfig(), ZjdPsdConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
}

View File

@ -4,7 +4,7 @@ import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.SimulationIscsDataRepository;
import club.joylink.rtss.simulation.cbtc.data.vo.iscs.IscsPsdStatusVO;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.simulation.rt.iscs.IscsStatusPublisher;
import club.joylink.rtss.vo.client.project.richor.ZjdPsdConfigVO;
import io.netty.buffer.ByteBuf;
@ -17,16 +17,17 @@ import org.springframework.util.StringUtils;
@Slf4j
@Component
public class ZjdPsdServiceImpl implements RealDeviceService {
@Autowired
private ApplicationContext applicationContext;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof ZjdPsdConfig;
}
@Autowired
private ApplicationContext applicationContext;
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof ZjdPsdConfig;
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
// PlcGateway plcGateway = simulation.getPlcGateway();
// ZjdPsdConfig config = (ZjdPsdConfig) deviceConfig;
// ZjdPsdConfigVO configVO = config.getConfigVO();
@ -37,46 +38,49 @@ public class ZjdPsdServiceImpl implements RealDeviceService {
// if (vrPsd != null) {
// vrPsd.startSetting(false);
// }
}
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
ZjdPsdConfig config = (ZjdPsdConfig) deviceConfig;
ZjdPsdConfigVO configVO = config.getConfigVO();
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(), configVO.getQuantity());
boolean km = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_wgm());
boolean sj = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_sj());
boolean dcugz = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_dcugz());
boolean r_sx_glms = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_glms());
String iscsCode = configVO.getIscsCode();
if (StringUtils.hasText(iscsCode)) {
IscsPsdStatusVO.Status status;
if (km) {
status = IscsPsdStatusVO.Status.OPEN;
} else if (sj) {
status = IscsPsdStatusVO.Status.CLOSE;
} else if (dcugz) {
status = IscsPsdStatusVO.Status.DCU_FAULT;
} else {
status = IscsPsdStatusVO.Status.UNDEFINED;
}
SimulationIscsDataRepository iscsRepository = simulation.getIscsRepository();
IscsPsdStatusVO iscsStatus = (IscsPsdStatusVO) iscsRepository.findStatus(iscsCode);
boolean change;
if (iscsStatus == null) {
IscsPsdStatusVO.DirectionalStatus downStatus = new IscsPsdStatusVO.DirectionalStatus(status, r_sx_glms);
iscsStatus = new IscsPsdStatusVO(iscsCode, configVO.getStationCode(), null, downStatus);
iscsRepository.addStatus(iscsStatus);
IscsStatusPublisher watcher = simulation.getMessagePublisher(IscsStatusPublisher.NAME, IscsStatusPublisher.class);
simulation.watch(iscsStatus, watcher);
change = true;
} else {
IscsPsdStatusVO.DirectionalStatus downStatus = iscsStatus.getDownStatus();
change = downStatus.compareAndChange(status, r_sx_glms);
}
if (change) {
iscsStatus.fireWatcher(null, null);
}
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
ZjdPsdConfig config = (ZjdPsdConfig) deviceConfig;
ZjdPsdConfigVO configVO = config.getConfigVO();
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(),
configVO.getQuantity());
boolean km = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_wgm());
boolean sj = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_sj());
boolean dcugz = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_dcugz());
boolean r_sx_glms = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_glms());
String iscsCode = configVO.getIscsCode();
if (StringUtils.hasText(iscsCode)) {
IscsPsdStatusVO.Status status;
if (km) {
status = IscsPsdStatusVO.Status.OPEN;
} else if (sj) {
status = IscsPsdStatusVO.Status.CLOSE;
} else if (dcugz) {
status = IscsPsdStatusVO.Status.DCU_FAULT;
} else {
status = IscsPsdStatusVO.Status.UNDEFINED;
}
SimulationIscsDataRepository iscsRepository = simulation.getIscsRepository();
IscsPsdStatusVO iscsStatus = (IscsPsdStatusVO) iscsRepository.findStatus(iscsCode);
boolean change;
if (iscsStatus == null) {
IscsPsdStatusVO.DirectionalStatus downStatus = new IscsPsdStatusVO.DirectionalStatus(status,
r_sx_glms);
iscsStatus = new IscsPsdStatusVO(iscsCode, configVO.getStationCode(), null, downStatus);
iscsRepository.addStatus(iscsStatus);
IscsStatusPublisher watcher = simulation.getMessagePublisher(IscsStatusPublisher.NAME,
IscsStatusPublisher.class);
simulation.watch(iscsStatus, watcher);
change = true;
} else {
IscsPsdStatusVO.DirectionalStatus downStatus = iscsStatus.getDownStatus();
change = downStatus.compareAndChange(status, r_sx_glms);
}
if (change) {
iscsStatus.fireWatcher(null, null);
}
}
}
}

View File

@ -1,26 +1,26 @@
package club.joylink.rtss.simulation.cbtc.device.real.modbustcp.zjd;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.richor.ZjdPslConfigVO;
import lombok.Getter;
import java.util.Objects;
import lombok.Getter;
@Getter
public class ZjdPslConfig extends RealDeviceConfig {
private ZjdPslConfigVO configVO;
public ZjdPslConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
if (Objects.nonNull(deviceVO.getConfig())) {
this.configVO = JsonUtils.read(deviceVO.getConfig(), ZjdPslConfigVO.class);
}
}
private ZjdPslConfigVO configVO;
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
public ZjdPslConfig(ProjectDeviceVO deviceVO) {
super(deviceVO);
if (Objects.nonNull(deviceVO.getConfig())) {
this.configVO = JsonUtils.read(deviceVO.getConfig(), ZjdPslConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
}

View File

@ -7,7 +7,7 @@ import club.joylink.rtss.simulation.cbtc.data.SimulationIscsDataRepository;
import club.joylink.rtss.simulation.cbtc.data.vo.iscs.IscsPslStatusVO;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityPsl;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.RealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.simulation.rt.iscs.IscsStatusPublisher;
import club.joylink.rtss.vo.client.project.richor.ZjdPslConfigVO;
import io.netty.buffer.ByteBuf;
@ -16,58 +16,65 @@ import org.springframework.stereotype.Component;
@Component
public class ZjdPslServiceImpl implements RealDeviceService {
@Autowired
private CiStandService standService;
@Autowired
private IVirtualRealityPslService iVirtualRealityPslService;
@Autowired
private CiStandService standService;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof ZjdPslConfig;
@Autowired
private IVirtualRealityPslService iVirtualRealityPslService;
@Override
public boolean canHandle(RealDeviceConfig deviceConfig) {
return deviceConfig instanceof ZjdPslConfig;
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
ZjdPslConfig config = (ZjdPslConfig) deviceConfig;
ZjdPslConfigVO configVO = config.getConfigVO();
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(),
configVO.getQuantity());
boolean r_sx_czyx = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_czyx());
boolean r_sx_km = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_km());
boolean r_sx_gm = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_gm());
boolean r_sx_hsjc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_hsjc());
//信号系统状态
VirtualRealityPsl vrPsl = (VirtualRealityPsl) config.getMapElement();
if (vrPsl == null) {
return;
}
iVirtualRealityPslService.updateStatus(simulation, vrPsl, VirtualRealityPsl.Button.YXJZ,
r_sx_czyx);
iVirtualRealityPslService.updateStatus(simulation, vrPsl, VirtualRealityPsl.Button.KM, r_sx_km);
iVirtualRealityPslService.updateStatus(simulation, vrPsl, VirtualRealityPsl.Button.GM, r_sx_gm);
iVirtualRealityPslService.updateStatus(simulation, vrPsl, VirtualRealityPsl.Button.HSJC,
r_sx_hsjc);
//ISCS状态
SimulationIscsDataRepository iscsRepository = simulation.getIscsRepository();
String iscsCode = configVO.getIscsCode();
IscsPslStatusVO iscsStatus = (IscsPslStatusVO) iscsRepository.findStatus(iscsCode);
boolean change;
if (iscsStatus == null) {
IscsPslStatusVO.DirectionalStatus downStatus = new IscsPslStatusVO.DirectionalStatus(
r_sx_czyx, r_sx_km, r_sx_gm, r_sx_hsjc);
iscsStatus = new IscsPslStatusVO(iscsCode,
vrPsl.getStand().getStation().getCode(), null, downStatus);
iscsRepository.addStatus(iscsStatus);
IscsStatusPublisher watcher = simulation.getMessagePublisher(IscsStatusPublisher.NAME,
IscsStatusPublisher.class);
simulation.watch(iscsStatus, watcher);
change = true;
} else {
IscsPslStatusVO.DirectionalStatus downStatus = iscsStatus.getDownStatus();
change = downStatus.compareAndChange(r_sx_czyx, r_sx_km, r_sx_gm, r_sx_hsjc);
}
@Override
public void init(Simulation simulation, RealDeviceConfig deviceConfig) {
}
@Override
public void handle(Simulation simulation, RealDeviceConfig deviceConfig, ByteBuf byteBuf) {
ZjdPslConfig config = (ZjdPslConfig) deviceConfig;
ZjdPslConfigVO configVO = config.getConfigVO();
ByteBuf deviceStatus = RealDeviceConfig.getDeviceCoilStatus(byteBuf, configVO.getAddr(), configVO.getQuantity());
boolean r_sx_czyx = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_czyx());
boolean r_sx_km = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_km());
boolean r_sx_gm = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_gm());
boolean r_sx_hsjc = RealDeviceConfig.getBitOf(deviceStatus, configVO.getR_sx_hsjc());
//信号系统状态
VirtualRealityPsl vrPsl = (VirtualRealityPsl) config.getMapElement();
if (vrPsl == null)
return;
iVirtualRealityPslService.updateStatus(simulation, vrPsl, VirtualRealityPsl.Button.YXJZ, r_sx_czyx);
iVirtualRealityPslService.updateStatus(simulation, vrPsl, VirtualRealityPsl.Button.KM, r_sx_km);
iVirtualRealityPslService.updateStatus(simulation, vrPsl, VirtualRealityPsl.Button.GM, r_sx_gm);
iVirtualRealityPslService.updateStatus(simulation, vrPsl, VirtualRealityPsl.Button.HSJC, r_sx_hsjc);
//ISCS状态
SimulationIscsDataRepository iscsRepository = simulation.getIscsRepository();
String iscsCode = configVO.getIscsCode();
IscsPslStatusVO iscsStatus = (IscsPslStatusVO) iscsRepository.findStatus(iscsCode);
boolean change;
if (iscsStatus == null) {
IscsPslStatusVO.DirectionalStatus downStatus = new IscsPslStatusVO.DirectionalStatus(r_sx_czyx, r_sx_km, r_sx_gm, r_sx_hsjc);
iscsStatus = new IscsPslStatusVO(iscsCode,
vrPsl.getStand().getStation().getCode(), null, downStatus);
iscsRepository.addStatus(iscsStatus);
IscsStatusPublisher watcher = simulation.getMessagePublisher(IscsStatusPublisher.NAME, IscsStatusPublisher.class);
simulation.watch(iscsStatus, watcher);
change = true;
} else {
IscsPslStatusVO.DirectionalStatus downStatus = iscsStatus.getDownStatus();
change = downStatus.compareAndChange(r_sx_czyx, r_sx_km, r_sx_gm, r_sx_hsjc);
}
if (change) {
iscsStatus.fireWatcher(null, null);
}
if (change) {
iscsStatus.fireWatcher(null, null);
}
}
}

View File

@ -1,6 +1,6 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.UDPClientConfigVO;
@ -9,17 +9,18 @@ import org.springframework.util.StringUtils;
@Getter
public class UDPClientConfig extends RealDeviceConfig {
private UDPClientConfigVO configVO;
public UDPClientConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (StringUtils.hasText(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), UDPClientConfigVO.class);
}
}
private UDPClientConfigVO configVO;
@Override
public String findDeviceCode() {
return null;
public UDPClientConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (StringUtils.hasText(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), UDPClientConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return null;
}
}

View File

@ -1,7 +1,7 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.UDPLowConfigVO;
@ -12,48 +12,49 @@ import lombok.Getter;
import org.springframework.util.StringUtils;
public class UDPLowConfig extends RealDeviceConfig {
@Getter
private UDPLowConfigVO configVO;
private byte[] ip;
@Getter
private UDPLowConfigVO configVO;
private Integer port;
private byte[] ip;
@Getter
private InetSocketAddress addr;
private Integer port;
public UDPLowConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (StringUtils.hasText(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), UDPLowConfigVO.class);
String ipStr = configVO.getIp();
if (StringUtils.hasText(ipStr)) {
String[] split = ipStr.split("\\.");
BusinessExceptionAssertEnum.DATA_ERROR.assertEquals(split.length, 4);
ip = new byte[4];
for (int i = 0; i < 4; i++) {
ip[i] = (byte) Integer.parseInt(split[i]);
}
}
this.port = configVO.getPort();
//构建地址
if (ip != null && port != null) {
try {
InetAddress inetAddress = InetAddress.getByAddress(ip);
addr = new InetSocketAddress(inetAddress, port);
} catch (UnknownHostException e) {
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception(e);
}
}
@Getter
private InetSocketAddress addr;
public UDPLowConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (StringUtils.hasText(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), UDPLowConfigVO.class);
String ipStr = configVO.getIp();
if (StringUtils.hasText(ipStr)) {
String[] split = ipStr.split("\\.");
BusinessExceptionAssertEnum.DATA_ERROR.assertEquals(split.length, 4);
ip = new byte[4];
for (int i = 0; i < 4; i++) {
ip[i] = (byte) Integer.parseInt(split[i]);
}
}
this.port = configVO.getPort();
//构建地址
if (ip != null && port != null) {
try {
InetAddress inetAddress = InetAddress.getByAddress(ip);
addr = new InetSocketAddress(inetAddress, port);
} catch (UnknownHostException e) {
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception(e);
}
}
}
}
@Override
public String findDeviceCode() {
return null;
}
@Override
public String findDeviceCode() {
return null;
}
public String getName() {
return configVO == null ? null : configVO.getName();
}
public String getName() {
return configVO == null ? null : configVO.getName();
}
}

View File

@ -1,19 +1,20 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import io.netty.buffer.ByteBuf;
public interface UDPRealDeviceService {
default boolean isMatch(UDPLowConfig udpLowConfig) {
return true;
}
boolean isMatch(RealDeviceConfig realDevice);
default boolean isMatch(UDPLowConfig udpLowConfig) {
return true;
}
void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice);
boolean isMatch(RealDeviceConfig realDevice);
void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice);
void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice);
void handle(Simulation simulation, ByteBuf msg);
void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice);
void handle(Simulation simulation, ByteBuf msg);
}

View File

@ -3,8 +3,8 @@ package club.joylink.rtss.simulation.cbtc.device.real.udp;
import club.joylink.rtss.constants.ProjectDeviceType;
import club.joylink.rtss.simulation.cbtc.GroupSimulationService;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
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.simulation.cbtc.event.SimulationResetEvent;
import io.netty.buffer.ByteBuf;
import java.util.List;

View File

@ -1,6 +1,6 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.config;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import java.util.Objects;

View File

@ -1,7 +1,7 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.config;
import club.joylink.rtss.simulation.cbtc.constant.SignalAspect;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import java.util.Objects;

View File

@ -1,7 +1,7 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.config;
import club.joylink.rtss.simulation.cbtc.constant.SwitchIndication;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import java.util.Objects;

View File

@ -1,7 +1,7 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.config;
import club.joylink.rtss.simulation.cbtc.data.map.Section;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import java.time.LocalDateTime;

View File

@ -5,7 +5,7 @@ import club.joylink.rtss.constants.ProjectDeviceType;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySectionAxleCounter;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPClientConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPLowConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceService;

View File

@ -5,7 +5,7 @@ import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SignalAspect;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPClient;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPLowConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceService;

View File

@ -5,7 +5,7 @@ import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.constant.SwitchIndication;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPClient;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPLowConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceService;

View File

@ -16,7 +16,7 @@ import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition;
import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySectionAxleCounter;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPClient;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPLowConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceService;
@ -26,13 +26,12 @@ import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPService;
import club.joylink.rtss.simulation.cbtc.robot.SimulationRobotService;
import club.joylink.rtss.vo.client.project.thailand.ThailandSectionConfigVO;
import io.netty.buffer.ByteBuf;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service

View File

@ -1,33 +1,33 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.sr.SrSectionConfigVO;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import java.util.Objects;
@Getter
public class SrSectionConfig extends RealDeviceConfig {
private SrSectionConfigVO configVO;
/**
* 连续无占用次数
*/
@Setter
private int timesOfRelease;
private SrSectionConfigVO configVO;
public SrSectionConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (Objects.nonNull(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SrSectionConfigVO.class);
}
/**
* 连续无占用次数
*/
@Setter
private int timesOfRelease;
public SrSectionConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (Objects.nonNull(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SrSectionConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
}

View File

@ -1,31 +1,31 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config;
import club.joylink.rtss.simulation.cbtc.constant.SignalAspect;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.sr.SrSignalConfigVO;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import java.util.Objects;
@Getter
public class SrSignalConfig extends RealDeviceConfig {
private SrSignalConfigVO configVO;
@Setter
private SignalAspect aspect;
private SrSignalConfigVO configVO;
public SrSignalConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (Objects.nonNull(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SrSignalConfigVO.class);
}
@Setter
private SignalAspect aspect;
public SrSignalConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (Objects.nonNull(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SrSignalConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
}

View File

@ -1,30 +1,31 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config;
import club.joylink.rtss.simulation.cbtc.constant.SwitchIndication;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.sr.SrSwitchConfigVO;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import java.util.Objects;
@Getter
public class SrSwitchConfig extends RealDeviceConfig {
private SrSwitchConfigVO configVO;
@Setter
private SwitchIndication p;
public SrSwitchConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (Objects.nonNull(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SrSwitchConfigVO.class);
}
}
private SrSwitchConfigVO configVO;
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
@Setter
private SwitchIndication p;
public SrSwitchConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (Objects.nonNull(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SrSwitchConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
}

View File

@ -1,54 +1,54 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config;
import club.joylink.rtss.simulation.cbtc.data.map.Section;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.sr.SrTrainConfigVO;
import java.time.LocalDateTime;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import java.time.LocalDateTime;
import java.util.Objects;
@Getter
public class SrTrainConfig extends RealDeviceConfig {
private SrTrainConfigVO configVO;
@Setter
private Integer gear;
private SrTrainConfigVO configVO;
/**
* 列车需要在这个轨道停车
*/
private Section headSection;
@Setter
private Integer gear;
/**
* 列车在headSection停车的时间
*/
@Setter
private LocalDateTime timeOfStop;
/**
* 列车需要在这个轨道停车
*/
private Section headSection;
/**
* 人为驾驶的档位
*/
@Setter
private Integer manualGear;
/**
* 列车在headSection停车的时间
*/
@Setter
private LocalDateTime timeOfStop;
public void updateHeadSection(Section headSection) {
this.headSection = headSection;
this.timeOfStop = null;
/**
* 人为驾驶的档位
*/
@Setter
private Integer manualGear;
public void updateHeadSection(Section headSection) {
this.headSection = headSection;
this.timeOfStop = null;
}
public SrTrainConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (Objects.nonNull(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SrTrainConfigVO.class);
}
}
public SrTrainConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (Objects.nonNull(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), SrTrainConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
}

View File

@ -8,7 +8,7 @@ import club.joylink.rtss.simulation.cbtc.data.map.Section;
import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySectionAxleCounter;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPClientConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPLowConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceService;

View File

@ -4,130 +4,132 @@ import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SignalAspect;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPClient;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPLowConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrSignalConfig;
import io.netty.buffer.ByteBuf;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Objects;
@Service
public class SrSignalServiceImpl implements UDPRealDeviceService {
@Autowired
private UDPClient udpClient;
@Override
public boolean isMatch(RealDeviceConfig realDevice) {
return realDevice instanceof SrSignalConfig;
@Autowired
private UDPClient udpClient;
@Override
public boolean isMatch(RealDeviceConfig realDevice) {
return realDevice instanceof SrSignalConfig;
}
@Override
public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
SrSignalConfig config = (SrSignalConfig) realDevice;
//控制vr设备
VirtualRealitySignal vrSignal = (VirtualRealitySignal) realDevice.getMapElement();
SignalAspect aspect = vrSignal.getAspect();
SignalAspect command = vrSignal.getCommand();
if (Objects.equals(aspect, command)) {
return;
}
@Override
public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
SrSignalConfig config = (SrSignalConfig) realDevice;
//控制vr设备
VirtualRealitySignal vrSignal = (VirtualRealitySignal) realDevice.getMapElement();
SignalAspect aspect = vrSignal.getAspect();
SignalAspect command = vrSignal.getCommand();
if (Objects.equals(aspect, command)) {
return;
}
if (vrSignal.isTurning()) {
vrSignal.turning(SimulationConstants.VRD_LOOP_RATE);
}
//控制沙盘设备
aspect = vrSignal.getAspect();
if (aspect == null || udpLowConfig == null || Objects.equals(aspect, config.getAspect())) {
return;
}
byte[] data = buildData(aspect, config);
if (data == null)
return;
udpClient.write(udpLowConfig.getAddr(), data);
if (vrSignal.isTurning()) {
vrSignal.turning(SimulationConstants.VRD_LOOP_RATE);
}
//控制沙盘设备
aspect = vrSignal.getAspect();
if (aspect == null || udpLowConfig == null || Objects.equals(aspect, config.getAspect())) {
return;
}
byte[] data = buildData(aspect, config);
if (data == null) {
return;
}
udpClient.write(udpLowConfig.getAddr(), data);
}
@Override
public void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
@Override
public void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
// SrSignalConfig config = (SrSignalConfig) realDevice;
// VirtualRealitySignal vrSignal = (VirtualRealitySignal) config.getMapElement();
// byte[] data = buildData(vrSignal.getAspect(), config);
// udpClient.write(udpLowConfig.getAddr(), data);
}
}
@Override
public void handle(Simulation simulation, ByteBuf msg) {
@Override
public void handle(Simulation simulation, ByteBuf msg) {
}
}
private byte[] buildData(SignalAspect aspect, SrSignalConfig config) {
if (aspect == null)
return null;
config.setAspect(aspect);
byte[] data = new byte[5];
data[1] = (byte) 203;
data[2] = (byte) Integer.parseInt(config.getConfigVO().getSandboxCode());
switch (aspect) {
case No:
case R:
case RF:
data[3] = (byte) 0;
break;
case G:
case GF:
data[3] = (byte) 1;
break;
case Y:
case YF:
data[3] = (byte) 2;
break;
case W:
case WF:
data[3] = (byte) 6;
break;
case B:
data[3] = (byte) 7;
break;
case GG:
data[3] = (byte) 5;
break;
case GY:
data[3] = (byte) 4;
break;
case YY:
data[3] = (byte) 3;
break;
case RY:
case RW:
return null;
default:
return null;
}
switch (aspect) {
case No:
case R:
case G:
case Y:
case W:
case B:
case RY:
case RW:
case GG:
case GY:
case YY:
data[4] = (byte) 0;
break;
case RF:
case YF:
case GF:
case WF:
data[4] = (byte) 1;
break;
default:
throw new IllegalStateException("Unexpected value: " + aspect);
}
return data;
private byte[] buildData(SignalAspect aspect, SrSignalConfig config) {
if (aspect == null) {
return null;
}
config.setAspect(aspect);
byte[] data = new byte[5];
data[1] = (byte) 203;
data[2] = (byte) Integer.parseInt(config.getConfigVO().getSandboxCode());
switch (aspect) {
case No:
case R:
case RF:
data[3] = (byte) 0;
break;
case G:
case GF:
data[3] = (byte) 1;
break;
case Y:
case YF:
data[3] = (byte) 2;
break;
case W:
case WF:
data[3] = (byte) 6;
break;
case B:
data[3] = (byte) 7;
break;
case GG:
data[3] = (byte) 5;
break;
case GY:
data[3] = (byte) 4;
break;
case YY:
data[3] = (byte) 3;
break;
case RY:
case RW:
return null;
default:
return null;
}
switch (aspect) {
case No:
case R:
case G:
case Y:
case W:
case B:
case RY:
case RW:
case GG:
case GY:
case YY:
data[4] = (byte) 0;
break;
case RF:
case YF:
case GF:
case WF:
data[4] = (byte) 1;
break;
default:
throw new IllegalStateException("Unexpected value: " + aspect);
}
return data;
}
}

View File

@ -4,48 +4,49 @@ import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.constant.SwitchIndication;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPClient;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPLowConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrSwitchConfig;
import io.netty.buffer.ByteBuf;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Objects;
@Service
public class SrSwitchServiceImpl implements UDPRealDeviceService {
@Autowired
private UDPClient udpClient;
@Override
public boolean isMatch(RealDeviceConfig realDevice) {
return realDevice instanceof SrSwitchConfig;
@Autowired
private UDPClient udpClient;
@Override
public boolean isMatch(RealDeviceConfig realDevice) {
return realDevice instanceof SrSwitchConfig;
}
@Override
public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
SrSwitchConfig config = (SrSwitchConfig) realDevice;
//控制vr设备
VirtualRealitySwitch vrSwitch = (VirtualRealitySwitch) realDevice.getMapElement();
if (vrSwitch.isTurning()) {
vrSwitch.turning(SimulationConstants.VRD_LOOP_RATE);
}
@Override
public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
SrSwitchConfig config = (SrSwitchConfig) realDevice;
//控制vr设备
VirtualRealitySwitch vrSwitch = (VirtualRealitySwitch) realDevice.getMapElement();
if (vrSwitch.isTurning()) {
vrSwitch.turning(SimulationConstants.VRD_LOOP_RATE);
}
//控制沙盘设备
SwitchIndication p = vrSwitch.getP();
if (p == null || udpLowConfig == null || Objects.equals(p, config.getP())) {
return;
}
byte[] data = buildData(p, config);
if (data == null)
return;
udpClient.write(udpLowConfig.getAddr(), data);
//控制沙盘设备
SwitchIndication p = vrSwitch.getP();
if (p == null || udpLowConfig == null || Objects.equals(p, config.getP())) {
return;
}
byte[] data = buildData(p, config);
if (data == null) {
return;
}
udpClient.write(udpLowConfig.getAddr(), data);
}
@Override
public void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
@Override
public void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
// SrSwitchConfig config = (SrSwitchConfig) realDevice;
// //控制vr设备
// VirtualRealitySwitch vrSwitch = (VirtualRealitySwitch) realDevice.getMapElement();
@ -59,33 +60,34 @@ public class SrSwitchServiceImpl implements UDPRealDeviceService {
// }
// byte[] data = buildData(p, config);
// udpClient.write(udpLowConfig.getAddr(), data);
}
}
@Override
public void handle(Simulation simulation, ByteBuf msg) {
@Override
public void handle(Simulation simulation, ByteBuf msg) {
}
}
private byte[] buildData(SwitchIndication p, SrSwitchConfig config) {
if (p == null)
return null;
config.setP(p);
byte[] data = new byte[4];
data[1] = (byte) 208;
data[2] = (byte) Integer.parseInt(config.getConfigVO().getSandboxCode());
switch (p) {
case N:
data[3] = (byte) 0;
break;
case R:
data[3] = (byte) 1;
break;
case NO:
case EX:
return null;
default:
throw new IllegalStateException("Unexpected value: " + p);
}
return data;
private byte[] buildData(SwitchIndication p, SrSwitchConfig config) {
if (p == null) {
return null;
}
config.setP(p);
byte[] data = new byte[4];
data[1] = (byte) 208;
data[2] = (byte) Integer.parseInt(config.getConfigVO().getSandboxCode());
switch (p) {
case N:
data[3] = (byte) 0;
break;
case R:
data[3] = (byte) 1;
break;
case NO:
case EX:
return null;
default:
throw new IllegalStateException("Unexpected value: " + p);
}
return data;
}
}

View File

@ -15,7 +15,7 @@ import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan;
import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition;
import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPClient;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPLowConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceService;
@ -24,273 +24,297 @@ import club.joylink.rtss.simulation.cbtc.member.SimulationMember;
import club.joylink.rtss.simulation.cbtc.onboard.ATO.SpeedCurve;
import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPService;
import io.netty.buffer.ByteBuf;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class SrTrainServiceImpl implements UDPRealDeviceService {
@Autowired
private UDPClient udpClient;
@Autowired
private ATPService atpService;
@Autowired
private UDPClient udpClient;
@Autowired
private AtsOperationDispatcher atsOperationDispatcher;
@Autowired
private ATPService atpService;
@Autowired
private GroupSimulationService groupSimulationService;
@Autowired
private AtsOperationDispatcher atsOperationDispatcher;
@Autowired
private AtsTrainLoadService atsTrainLoadService;
@Autowired
private GroupSimulationService groupSimulationService;
@Override
public boolean isMatch(RealDeviceConfig realDevice) {
return realDevice instanceof SrTrainConfig;
}
@Autowired
private AtsTrainLoadService atsTrainLoadService;
@Override
public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
SrTrainConfig config = (SrTrainConfig) realDevice;
//控制vr设备
VirtualRealityTrain train = (VirtualRealityTrain) config.getMapElement();
SimulationDataRepository repository = simulation.getRepository();
String groupNumber = train.getGroupNumber();
if (repository.isVrTrainOnline(groupNumber)) {
removeVrTrainIfNotSupervised(repository, groupNumber);
if (train.isEB()) {
train.setSpeed(0);
} else {
if (train.getRobotTargetPosition() != null || train.isAMMode()) {
config.setManualGear(null);
}
if (config.getManualGear() == null) {
change2RMWhenStopAtPlanEnd(simulation, train);
trainRunning(simulation, train, config);
}
if (train.getDelayTime() > 3000) {
train.setDelayTime(3000);
}
}
//控制沙盘设备
byte[] data = buildData(train, config);
udpClient.write(udpLowConfig.getAddr(), data);
} else {
addVrTrainIfSupervised(simulation, repository, groupNumber);
@Override
public boolean isMatch(RealDeviceConfig realDevice) {
return realDevice instanceof SrTrainConfig;
}
@Override
public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
SrTrainConfig config = (SrTrainConfig) realDevice;
//控制vr设备
VirtualRealityTrain train = (VirtualRealityTrain) config.getMapElement();
SimulationDataRepository repository = simulation.getRepository();
String groupNumber = train.getGroupNumber();
if (repository.isVrTrainOnline(groupNumber)) {
removeVrTrainIfNotSupervised(repository, groupNumber);
if (train.isEB()) {
train.setSpeed(0);
} else {
if (train.getRobotTargetPosition() != null || train.isAMMode()) {
config.setManualGear(null);
}
}
/**
* 如果有监控添加一个vrTrain
*/
private void addVrTrainIfSupervised(Simulation simulation, SimulationDataRepository repository, String groupNumber) {
TrainInfo trainInfo = repository.findSupervisedTrainByGroup(groupNumber);
if (trainInfo != null) {
Section section = repository.getByCode(trainInfo.getSection(), Section.class);
if (section.isSwitchAxleCounterSection()) {
section = section.getLogicList().get(0).getRelSwitch().getA();
}
atsTrainLoadService.loadSpareTrain(simulation, groupNumber, section.getCode(), false, null);
if (config.getManualGear() == null) {
change2RMWhenStopAtPlanEnd(simulation, train);
trainRunning(simulation, train, config);
}
}
/**
* 移除vrTrain如果没有被监控
*/
private void removeVrTrainIfNotSupervised(SimulationDataRepository repository, String groupNumber) {
TrainInfo trainInfo = repository.findSupervisedTrainByGroup(groupNumber);
if (trainInfo == null) {
repository.deleteOnlineTrain(groupNumber);
if (train.getDelayTime() > 3000) {
train.setDelayTime(3000);
}
}
//控制沙盘设备
byte[] data = buildData(train, config);
udpClient.write(udpLowConfig.getAddr(), data);
} else {
addVrTrainIfSupervised(simulation, repository, groupNumber);
}
}
/**
* 当到达计划终点时将列车驾驶模式转为RM
*/
private void change2RMWhenStopAtPlanEnd(Simulation simulation, VirtualRealityTrain train) {
if (!train.isStop())
return;
if (!train.getHeadPosition().getSection().isTransferTrack()) //不是转换轨
return;
SimulationDataRepository repository = simulation.getRepository();
String groupNumber = train.getGroupNumber();
TrainInfo trainInfo = repository.getSupervisedTrainByGroup(groupNumber);
if (!trainInfo.isPlanTrain())
return;
TripPlan tripPlan = repository.getTripPlan(trainInfo.getServiceNumber(), trainInfo.getTripNumber());
if (!Objects.equals(train.getHeadPosition().getSection(), tripPlan.getEndSection())) //不是计划最后一个区段
return;
TripPlan nextTripPlan = repository.queryServiceNextTripPlan(trainInfo.getServiceNumber(), trainInfo.getTripNumber());
if (nextTripPlan != null)
return;
//无下一计划要回车辆段
VirtualRealityTrain.PreselectionMode preselectionMode = VirtualRealityTrain.PreselectionMode.RM;
VirtualRealityTrain.PreselectionMode trainMode = train.getPreselectionMode();
if (trainMode == preselectionMode) //已是RM
return;
VirtualRealityTrain.PreselectionMode tempMode = train.getTempPreselectionMode();
SimulationMember driver = simulation.getSimulationMember(train, SimulationMember.Type.DRIVER);
Map<String, Object> params = new HashMap<>();
String operation;
params.put("groupNumber", groupNumber);
if (tempMode != preselectionMode) { //临时级别不对
if (preselectionMode.isHigherThan(tempMode)) {
operation = Operation.Type.Driver_Preselection_Mode_Up.name();
} else {
operation = Operation.Type.Driver_Preselection_Mode_Down.name();
}
} else {
operation = Operation.Type.Driver_Confirm.name();
}
atsOperationDispatcher.execute(simulation, driver, operation, params);
/**
* 如果有监控添加一个vrTrain
*/
private void addVrTrainIfSupervised(Simulation simulation, SimulationDataRepository repository,
String groupNumber) {
TrainInfo trainInfo = repository.findSupervisedTrainByGroup(groupNumber);
if (trainInfo != null) {
Section section = repository.getByCode(trainInfo.getSection(), Section.class);
if (section.isSwitchAxleCounterSection()) {
section = section.getLogicList().get(0).getRelSwitch().getA();
}
atsTrainLoadService.loadSpareTrain(simulation, groupNumber, section.getCode(), false, null);
}
}
@Override
public void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
SrTrainConfig config = (SrTrainConfig) realDevice;
//控制vr设备
VirtualRealityTrain train = (VirtualRealityTrain) config.getMapElement();
//控制沙盘设备
byte[] data = buildData(train, config);
udpClient.write(udpLowConfig.getAddr(), data);
//清除状态
/**
* 移除vrTrain如果没有被监控
*/
private void removeVrTrainIfNotSupervised(SimulationDataRepository repository,
String groupNumber) {
TrainInfo trainInfo = repository.findSupervisedTrainByGroup(groupNumber);
if (trainInfo == null) {
repository.deleteOnlineTrain(groupNumber);
}
}
/**
* 当到达计划终点时将列车驾驶模式转为RM
*/
private void change2RMWhenStopAtPlanEnd(Simulation simulation, VirtualRealityTrain train) {
if (!train.isStop()) {
return;
}
if (!train.getHeadPosition().getSection().isTransferTrack()) //不是转换轨
{
return;
}
SimulationDataRepository repository = simulation.getRepository();
String groupNumber = train.getGroupNumber();
TrainInfo trainInfo = repository.getSupervisedTrainByGroup(groupNumber);
if (!trainInfo.isPlanTrain()) {
return;
}
TripPlan tripPlan = repository.getTripPlan(trainInfo.getServiceNumber(),
trainInfo.getTripNumber());
if (!Objects.equals(train.getHeadPosition().getSection(),
tripPlan.getEndSection())) //不是计划最后一个区段
{
return;
}
TripPlan nextTripPlan = repository.queryServiceNextTripPlan(trainInfo.getServiceNumber(),
trainInfo.getTripNumber());
if (nextTripPlan != null) {
return;
}
//无下一计划要回车辆段
VirtualRealityTrain.PreselectionMode preselectionMode = VirtualRealityTrain.PreselectionMode.RM;
VirtualRealityTrain.PreselectionMode trainMode = train.getPreselectionMode();
if (trainMode == preselectionMode) //已是RM
{
return;
}
VirtualRealityTrain.PreselectionMode tempMode = train.getTempPreselectionMode();
SimulationMember driver = simulation.getSimulationMember(train, SimulationMember.Type.DRIVER);
Map<String, Object> params = new HashMap<>();
String operation;
params.put("groupNumber", groupNumber);
if (tempMode != preselectionMode) { //临时级别不对
if (preselectionMode.isHigherThan(tempMode)) {
operation = Operation.Type.Driver_Preselection_Mode_Up.name();
} else {
operation = Operation.Type.Driver_Preselection_Mode_Down.name();
}
} else {
operation = Operation.Type.Driver_Confirm.name();
}
atsOperationDispatcher.execute(simulation, driver, operation, params);
}
@Override
public void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
SrTrainConfig config = (SrTrainConfig) realDevice;
//控制vr设备
VirtualRealityTrain train = (VirtualRealityTrain) config.getMapElement();
//控制沙盘设备
byte[] data = buildData(train, config);
udpClient.write(udpLowConfig.getAddr(), data);
//清除状态
config.updateHeadSection(null);
}
@Override
public void handle(Simulation simulation, ByteBuf msg) {
}
private void trainRunning(Simulation simulation, VirtualRealityTrain train,
SrTrainConfig config) {
//判断到停车时间将列车位置更新到停车点
boolean right = train.isRight();
SectionPosition headPosition = train.getHeadPosition();
Section headSection = headPosition.getSection();
if (Objects.equals(headSection, config.getHeadSection())) {
LocalDateTime timeOfStop = config.getTimeOfStop();
if (timeOfStop != null && LocalDateTime.now().isAfter(timeOfStop)) {
headPosition = headSection.buildStopPointPosition(right);
train.setHeadPosition(headPosition);
config.updateHeadSection(null);
}
}
@Override
public void handle(Simulation simulation, ByteBuf msg) {
//更新速度
SimulationDataRepository repository = simulation.getRepository();
SectionPosition tailPosition = train.calculateTailPosition();
float speed = train.getSpeed();
float newSpeed;
if (train.isAMMode() || train.isCMMode()) {
newSpeed = train.getAtoSpeed();
} else {
SectionPosition targetPosition = train.getRobotTargetPosition();
if (targetPosition == null
|| (Objects.equals(headSection, targetPosition.getSection())
&& !headSection.isFunctionTrack())) {
newSpeed = 0;
} else {
float recommendedSpeedMax;
if (train.isRMMode()) {
recommendedSpeedMax =
Math.min(repository.getConfig().getRmAtpSpeed(), train.getSpeedLimitInMs()) * 0.9f;
} else if (train.isNRMMode()) {
recommendedSpeedMax =
Math.min(repository.getConfig().getUrmAtpSpeed(), train.getSpeedLimitInMs()) * 0.9f;
} else {
recommendedSpeedMax = 0;
}
Float distance = CalculateService.calculateDistance(headPosition, targetPosition, right,
false);
if (distance == null
|| distance <= SimulationConstants.PARK_POINT_MAX_OFFSET) { //如果列车已经抵达或越过目标位置
newSpeed = 0;
} else {
SpeedCurve speedCurve = SpeedCurve.buildTargetSpeedCurve(headPosition, tailPosition,
right,
distance, speed, recommendedSpeedMax);
newSpeed = speedCurve.getSpeedOf(speedCurve.getTotalDistance());
}
}
}
private void trainRunning(Simulation simulation, VirtualRealityTrain train, SrTrainConfig config) {
//判断到停车时间将列车位置更新到停车点
boolean right = train.isRight();
SectionPosition headPosition = train.getHeadPosition();
Section headSection = headPosition.getSection();
if (Objects.equals(headSection, config.getHeadSection())) {
LocalDateTime timeOfStop = config.getTimeOfStop();
if (timeOfStop != null && LocalDateTime.now().isAfter(timeOfStop)) {
headPosition = headSection.buildStopPointPosition(right);
train.setHeadPosition(headPosition);
config.updateHeadSection(null);
}
}
//更新速度
SimulationDataRepository repository = simulation.getRepository();
SectionPosition tailPosition = train.calculateTailPosition();
float speed = train.getSpeed();
float newSpeed;
if (train.isAMMode() || train.isCMMode()) {
newSpeed = train.getAtoSpeed();
} else {
SectionPosition targetPosition = train.getRobotTargetPosition();
if (targetPosition == null
|| (Objects.equals(headSection, targetPosition.getSection()) && !headSection.isFunctionTrack())) {
newSpeed = 0;
} else {
float recommendedSpeedMax;
if (train.isRMMode()) {
recommendedSpeedMax = Math.min(repository.getConfig().getRmAtpSpeed(), train.getSpeedLimitInMs()) * 0.9f;
} else if (train.isNRMMode()) {
recommendedSpeedMax = Math.min(repository.getConfig().getUrmAtpSpeed(), train.getSpeedLimitInMs()) * 0.9f;
} else {
recommendedSpeedMax = 0;
}
Float distance = CalculateService.calculateDistance(headPosition, targetPosition, right, false);
if (distance == null || distance <= SimulationConstants.PARK_POINT_MAX_OFFSET) { //如果列车已经抵达或越过目标位置
newSpeed = 0;
} else {
SpeedCurve speedCurve = SpeedCurve.buildTargetSpeedCurve(headPosition, tailPosition, right,
distance, speed, recommendedSpeedMax);
newSpeed = speedCurve.getSpeedOf(speedCurve.getTotalDistance());
}
}
}
if (newSpeed == 0) {
train.setSpeed(0);
} else {
newSpeed = 20f / 3.6f;
}
Float speedMax = null;
if (headSection.isStandTrack()) { //车头在站台轨
speedMax = 10f / 3.6f;
} else {
//车尾未离开站台轨
Section behindStandTrack = null;
Section behindSection = headSection;
for (int i = 0; i < 5; i++) {
behindSection = behindSection.getNextRunningSectionOf(!right);
if (behindSection == null)
break;
if (behindSection.isStandTrack()) {
behindStandTrack = behindSection;
break;
}
}
if (behindStandTrack != null && behindStandTrack.isOccupied()) {
speedMax = 10f / 3.6f;
}
}
if (speedMax != null) {
train.setSpeed(Math.min(newSpeed, speedMax));
} else {
train.setSpeed(newSpeed);
}
if (newSpeed == 0) {
train.setSpeed(0);
} else {
newSpeed = 20f / 3.6f;
}
private byte[] buildData(VirtualRealityTrain train, SrTrainConfig config) {
int gear;
if (train.isStop()) {
gear = 0;
} else {
float speedKmPh = train.getSpeedKmPh();
if (train.isStop()) {
gear = 0;
} else {
gear = (int) Math.ceil(speedKmPh / 10);
gear = Math.max(1, gear);
}
if (train.isRight()) {
gear += 5;
}
Float speedMax = null;
if (headSection.isStandTrack()) { //车头在站台轨
speedMax = 10f / 3.6f;
} else {
//车尾未离开站台轨
Section behindStandTrack = null;
Section behindSection = headSection;
for (int i = 0; i < 5; i++) {
behindSection = behindSection.getNextRunningSectionOf(!right);
if (behindSection == null) {
break;
}
if (Objects.equals(config.getGear(), gear)) {
return null;
if (behindSection.isStandTrack()) {
behindStandTrack = behindSection;
break;
}
config.setGear(gear);
byte[] data = new byte[4];
data[1] = (byte) 1;
data[2] = (byte) Integer.parseInt(config.getConfigVO().getSandboxCode());
data[3] = (byte) gear;
return data;
}
if (behindStandTrack != null && behindStandTrack.isOccupied()) {
speedMax = 10f / 3.6f;
}
}
public void controlTrain(String simulationId, String groupNumber, boolean right, int speed) {
Simulation simulation = groupSimulationService.getSimulationByGroup(simulationId);
VirtualRealityTrain train = simulation.getRepository().getOnlineTrainBy(groupNumber);
SrTrainConfig config = (SrTrainConfig) train.getRealDevice();
if (right != train.isRight()) { //调头
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED
.assertTrue(train.getSpeed() == 0, "换端需先停车");
atpService.turnDirectionImmediately(train);
}
train.setRobotTargetPosition(null); //终止机器人司机驾驶
//加减速
if (train.isEB())
return;
atpService.changeGear(train, VirtualRealityTrain.Handwheel.MANUAL);
int manualGear = speed / 10;
config.setManualGear(manualGear);
train.setSpeed(speed / 3.6f);
byte[] data = buildData(train, config);
UDPLowConfig udpLowConfig = (UDPLowConfig) simulation.queryOneRealDevice(ProjectDeviceType.UDP_LOW);
udpClient.write(udpLowConfig.getAddr(), data);
if (speedMax != null) {
train.setSpeed(Math.min(newSpeed, speedMax));
} else {
train.setSpeed(newSpeed);
}
}
private byte[] buildData(VirtualRealityTrain train, SrTrainConfig config) {
int gear;
if (train.isStop()) {
gear = 0;
} else {
float speedKmPh = train.getSpeedKmPh();
if (train.isStop()) {
gear = 0;
} else {
gear = (int) Math.ceil(speedKmPh / 10);
gear = Math.max(1, gear);
}
if (train.isRight()) {
gear += 5;
}
}
if (Objects.equals(config.getGear(), gear)) {
return null;
}
config.setGear(gear);
byte[] data = new byte[4];
data[1] = (byte) 1;
data[2] = (byte) Integer.parseInt(config.getConfigVO().getSandboxCode());
data[3] = (byte) gear;
return data;
}
public void controlTrain(String simulationId, String groupNumber, boolean right, int speed) {
Simulation simulation = groupSimulationService.getSimulationByGroup(simulationId);
VirtualRealityTrain train = simulation.getRepository().getOnlineTrainBy(groupNumber);
SrTrainConfig config = (SrTrainConfig) train.getRealDevice();
if (right != train.isRight()) { //调头
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED
.assertTrue(train.getSpeed() == 0, "换端需先停车");
atpService.turnDirectionImmediately(train);
}
train.setRobotTargetPosition(null); //终止机器人司机驾驶
//加减速
if (train.isEB()) {
return;
}
atpService.changeGear(train, VirtualRealityTrain.Handwheel.MANUAL);
int manualGear = speed / 10;
config.setManualGear(manualGear);
train.setSpeed(speed / 3.6f);
byte[] data = buildData(train, config);
UDPLowConfig udpLowConfig = (UDPLowConfig) simulation.queryOneRealDevice(
ProjectDeviceType.UDP_LOW);
udpClient.write(udpLowConfig.getAddr(), data);
}
}

View File

@ -1,6 +1,6 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.thailand.config;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.thailand.ThailandSectionConfigVO;
@ -10,23 +10,24 @@ import lombok.Setter;
@Getter
public class ThailandSectionConfig extends RealDeviceConfig {
private ThailandSectionConfigVO configVO;
/**
* 连续无占用次数
*/
@Setter
private int timesOfRelease;
private ThailandSectionConfigVO configVO;
public ThailandSectionConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (Objects.nonNull(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), ThailandSectionConfigVO.class);
}
/**
* 连续无占用次数
*/
@Setter
private int timesOfRelease;
public ThailandSectionConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (Objects.nonNull(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), ThailandSectionConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
}

View File

@ -1,7 +1,7 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.thailand.config;
import club.joylink.rtss.simulation.cbtc.constant.SignalAspect;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.thailand.ThailandSignalConfigVO;
@ -11,20 +11,21 @@ import lombok.Setter;
@Getter
public class ThailandSignalConfig extends RealDeviceConfig {
private ThailandSignalConfigVO configVO;
@Setter
private SignalAspect aspect;
private ThailandSignalConfigVO configVO;
public ThailandSignalConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (Objects.nonNull(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), ThailandSignalConfigVO.class);
}
@Setter
private SignalAspect aspect;
public ThailandSignalConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (Objects.nonNull(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), ThailandSignalConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
}

View File

@ -1,7 +1,7 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.thailand.config;
import club.joylink.rtss.simulation.cbtc.constant.SwitchIndication;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.thailand.ThailandSwitchConfigVO;
@ -11,19 +11,21 @@ import lombok.Setter;
@Getter
public class ThailandSwitchConfig extends RealDeviceConfig {
private ThailandSwitchConfigVO configVO;
@Setter
private SwitchIndication p;
public ThailandSwitchConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (Objects.nonNull(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), ThailandSwitchConfigVO.class);
}
}
private ThailandSwitchConfigVO configVO;
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
@Setter
private SwitchIndication p;
public ThailandSwitchConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (Objects.nonNull(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), ThailandSwitchConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
}

View File

@ -1,7 +1,7 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.thailand.config;
import club.joylink.rtss.simulation.cbtc.data.map.Section;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.thailand.ThailandTrainConfigVO;

View File

@ -4,7 +4,7 @@ import club.joylink.rtss.constants.ProjectCode;
import club.joylink.rtss.constants.ProjectDeviceType;
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.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPClientConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPLowConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceService;

View File

@ -4,7 +4,7 @@ import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SignalAspect;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPClient;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPLowConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceService;
@ -16,121 +16,124 @@ import org.springframework.stereotype.Service;
@Service
public class ThailandSignalServiceImpl implements UDPRealDeviceService {
public static final String NAME = "SIGNAL";
@Autowired
private UDPClient udpClient;
public static final String NAME = "SIGNAL";
@Override
public boolean isMatch(UDPLowConfig udpLowConfig) {
return NAME.equals(udpLowConfig.getName());
@Autowired
private UDPClient udpClient;
@Override
public boolean isMatch(UDPLowConfig udpLowConfig) {
return NAME.equals(udpLowConfig.getName());
}
@Override
public boolean isMatch(RealDeviceConfig realDevice) {
return realDevice instanceof ThailandSignalConfig;
}
@Override
public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
ThailandSignalConfig config = (ThailandSignalConfig) realDevice;
//控制vr设备
VirtualRealitySignal vrSignal = (VirtualRealitySignal) realDevice.getMapElement();
SignalAspect aspect = vrSignal.getAspect();
SignalAspect command = vrSignal.getCommand();
if (Objects.equals(aspect, command)) {
return;
}
@Override
public boolean isMatch(RealDeviceConfig realDevice) {
return realDevice instanceof ThailandSignalConfig;
if (vrSignal.isTurning()) {
vrSignal.turning(SimulationConstants.VRD_LOOP_RATE);
}
@Override
public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
ThailandSignalConfig config = (ThailandSignalConfig) realDevice;
//控制vr设备
VirtualRealitySignal vrSignal = (VirtualRealitySignal) realDevice.getMapElement();
SignalAspect aspect = vrSignal.getAspect();
SignalAspect command = vrSignal.getCommand();
if (Objects.equals(aspect, command)) {
return;
}
if (vrSignal.isTurning()) {
vrSignal.turning(SimulationConstants.VRD_LOOP_RATE);
}
//控制沙盘设备
aspect = vrSignal.getAspect();
if (aspect == null || udpLowConfig == null || Objects.equals(aspect, config.getAspect())) {
return;
}
byte[] data = buildData(aspect, config);
if (data == null)
return;
udpClient.write(udpLowConfig.getAddr(), data);
//控制沙盘设备
aspect = vrSignal.getAspect();
if (aspect == null || udpLowConfig == null || Objects.equals(aspect, config.getAspect())) {
return;
}
byte[] data = buildData(aspect, config);
if (data == null) {
return;
}
udpClient.write(udpLowConfig.getAddr(), data);
}
@Override
public void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
@Override
public void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
}
@Override
public void handle(Simulation simulation, ByteBuf msg) {
}
private byte[] buildData(SignalAspect aspect, ThailandSignalConfig config) {
if (aspect == null) {
return null;
}
config.setAspect(aspect);
byte[] data = new byte[5];
data[1] = (byte) 203;
data[2] = (byte) Integer.parseInt(config.getConfigVO().getSandboxCode());
switch (aspect) {
case No:
case R:
case RF:
data[3] = (byte) 0;
break;
case G:
case GF:
data[3] = (byte) 1;
break;
case Y:
case YF:
data[3] = (byte) 2;
break;
case W:
case WF:
data[3] = (byte) 6;
break;
case B:
data[3] = (byte) 7;
break;
case GG:
data[3] = (byte) 5;
break;
case GY:
data[3] = (byte) 4;
break;
case YY:
data[3] = (byte) 3;
break;
case RY:
case RW:
return null;
default:
return null;
}
@Override
public void handle(Simulation simulation, ByteBuf msg) {
}
private byte[] buildData(SignalAspect aspect, ThailandSignalConfig config) {
if (aspect == null)
return null;
config.setAspect(aspect);
byte[] data = new byte[5];
data[1] = (byte) 203;
data[2] = (byte) Integer.parseInt(config.getConfigVO().getSandboxCode());
switch (aspect) {
case No:
case R:
case RF:
data[3] = (byte) 0;
break;
case G:
case GF:
data[3] = (byte) 1;
break;
case Y:
case YF:
data[3] = (byte) 2;
break;
case W:
case WF:
data[3] = (byte) 6;
break;
case B:
data[3] = (byte) 7;
break;
case GG:
data[3] = (byte) 5;
break;
case GY:
data[3] = (byte) 4;
break;
case YY:
data[3] = (byte) 3;
break;
case RY:
case RW:
return null;
default:
return null;
}
switch (aspect) {
case No:
case R:
case G:
case Y:
case W:
case B:
case RY:
case RW:
case GG:
case GY:
case YY:
data[4] = (byte) 0;
break;
case RF:
case YF:
case GF:
case WF:
data[4] = (byte) 1;
break;
default:
throw new IllegalStateException("Unexpected value: " + aspect);
}
return data;
switch (aspect) {
case No:
case R:
case G:
case Y:
case W:
case B:
case RY:
case RW:
case GG:
case GY:
case YY:
data[4] = (byte) 0;
break;
case RF:
case YF:
case GF:
case WF:
data[4] = (byte) 1;
break;
default:
throw new IllegalStateException("Unexpected value: " + aspect);
}
return data;
}
}

View File

@ -4,7 +4,7 @@ import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.constant.SwitchIndication;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPClient;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPLowConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceService;
@ -16,70 +16,73 @@ import org.springframework.stereotype.Service;
@Service
public class ThailandSwitchServiceImpl implements UDPRealDeviceService {
public static final String NAME = "SWITCH-TRAIN";
@Autowired
private UDPClient udpClient;
public static final String NAME = "SWITCH-TRAIN";
@Override
public boolean isMatch(UDPLowConfig udpLowConfig) {
return NAME.equals(udpLowConfig.getName());
@Autowired
private UDPClient udpClient;
@Override
public boolean isMatch(UDPLowConfig udpLowConfig) {
return NAME.equals(udpLowConfig.getName());
}
@Override
public boolean isMatch(RealDeviceConfig realDevice) {
return realDevice instanceof ThailandSwitchConfig;
}
@Override
public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
ThailandSwitchConfig config = (ThailandSwitchConfig) realDevice;
//控制vr设备
VirtualRealitySwitch vrSwitch = (VirtualRealitySwitch) realDevice.getMapElement();
if (vrSwitch.isTurning()) {
vrSwitch.turning(SimulationConstants.VRD_LOOP_RATE);
}
@Override
public boolean isMatch(RealDeviceConfig realDevice) {
return realDevice instanceof ThailandSwitchConfig;
//控制沙盘设备
SwitchIndication p = vrSwitch.getP();
if (p == null || udpLowConfig == null || Objects.equals(p, config.getP())) {
return;
}
byte[] data = buildData(p, config);
if (data == null) {
return;
}
udpClient.write(udpLowConfig.getAddr(), data);
}
@Override
public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
ThailandSwitchConfig config = (ThailandSwitchConfig) realDevice;
//控制vr设备
VirtualRealitySwitch vrSwitch = (VirtualRealitySwitch) realDevice.getMapElement();
if (vrSwitch.isTurning()) {
vrSwitch.turning(SimulationConstants.VRD_LOOP_RATE);
}
//控制沙盘设备
SwitchIndication p = vrSwitch.getP();
if (p == null || udpLowConfig == null || Objects.equals(p, config.getP())) {
return;
}
byte[] data = buildData(p, config);
if (data == null)
return;
udpClient.write(udpLowConfig.getAddr(), data);
}
@Override
public void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
}
@Override
public void handle(Simulation simulation, ByteBuf msg) {
}
private byte[] buildData(SwitchIndication p, ThailandSwitchConfig config) {
if (p == null)
return null;
config.setP(p);
byte[] data = new byte[4];
data[1] = (byte) 208;
data[2] = (byte) Integer.parseInt(config.getConfigVO().getSandboxCode());
switch (p) {
case N:
data[3] = (byte) 0;
break;
case R:
data[3] = (byte) 1;
break;
case NO:
case EX:
return null;
default:
throw new IllegalStateException("Unexpected value: " + p);
}
return data;
@Override
public void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
}
@Override
public void handle(Simulation simulation, ByteBuf msg) {
}
private byte[] buildData(SwitchIndication p, ThailandSwitchConfig config) {
if (p == null) {
return null;
}
config.setP(p);
byte[] data = new byte[4];
data[1] = (byte) 208;
data[2] = (byte) Integer.parseInt(config.getConfigVO().getSandboxCode());
switch (p) {
case N:
data[3] = (byte) 0;
break;
case R:
data[3] = (byte) 1;
break;
case NO:
case EX:
return null;
default:
throw new IllegalStateException("Unexpected value: " + p);
}
return data;
}
}

View File

@ -15,7 +15,7 @@ import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition;
import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySectionAxleCounter;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPClient;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPLowConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceService;
@ -25,13 +25,12 @@ import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPService;
import club.joylink.rtss.simulation.cbtc.robot.SimulationRobotService;
import club.joylink.rtss.vo.client.project.thailand.ThailandSectionConfigVO;
import io.netty.buffer.ByteBuf;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.Optional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service

View File

@ -9,7 +9,7 @@ import club.joylink.rtss.simulation.cbtc.build.SimulationBuildParams;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.SimulationRealDeviceThread;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.common.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceThread;
import club.joylink.rtss.simulation.cbtc.event.SimulationUserEnterEvent;
import club.joylink.rtss.simulation.cbtc.member.MemberManager;
@ -32,123 +32,133 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
/**
* 仿真工作服务管理
* 1.管理仿真工作服务的实现类
* 2.各种仿真的公共方法
* 仿真工作服务管理 1.管理仿真工作服务的实现类 2.各种仿真的公共方法
*/
@Slf4j
@Component
public class SimulationWorkServiceManager implements ApplicationContextAware {
@Autowired
private MemberManager memberManager;
@Autowired
private ApplicationContext applicationContext;
@Autowired
private DeviceService deviceService;
@Autowired
private GroupSimulationService groupSimulationService;
@Autowired
private SimulationRealDeviceThread simulationRealDeviceThread;
@Autowired
private UDPRealDeviceThread udpRealDeviceThread;
private Map<Simulation.Type, SimulationWorkService> map;
@Autowired
private MemberManager memberManager;
@Autowired
private ApplicationContext applicationContext;
@Autowired
private DeviceService deviceService;
@Autowired
private GroupSimulationService groupSimulationService;
@Autowired
private SimulationRealDeviceThread simulationRealDeviceThread;
@Autowired
private UDPRealDeviceThread udpRealDeviceThread;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
Map<String, SimulationWorkService> services = applicationContext.getBeansOfType(SimulationWorkService.class);
map = services.values().stream().collect(Collectors.toMap(SimulationWorkService::getType, Function.identity()));
}
private Map<Simulation.Type, SimulationWorkService> map;
public SimulationWorkService getWorkService(@NonNull Simulation.Type simulationType) {
SimulationWorkService initService = map.get(simulationType);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(initService, String.format("[%s]仿真未配置初始化服务", simulationType));
return initService;
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
Map<String, SimulationWorkService> services = applicationContext.getBeansOfType(
SimulationWorkService.class);
map = services.values().stream()
.collect(Collectors.toMap(SimulationWorkService::getType, Function.identity()));
}
/**
* 构建仿真成员实体
*/
public void buildMember(Simulation simulation) {
Map<Simulation.Type, List<MapMemberVO>> memberMap = simulation.getBuildParams().getMap().getGraphDataNew().getMemberMap();
if (CollectionUtils.isEmpty(memberMap))
return;
List<MapMemberVO> memberVOS = memberMap.get(simulation.getBuildParams().getWorkParamVO().getType());
if (CollectionUtils.isEmpty(memberVOS))
return;
List<String> dataErrMsgList = simulation.getDataErrMsgList();
SimulationDataRepository repository = simulation.getRepository();
for (MapMemberVO memberVO : memberVOS) {
if (memberVO.getId() == null) {
dataErrMsgList.add(String.format("成员数据[%s]未设置id", memberVO));
continue;
}
if (memberVO.getType() == null) {
dataErrMsgList.add(String.format("成员数据[%s]未设置类型", memberVO));
continue;
}
MapElement mapElement = null;
if (StringUtils.hasText(memberVO.getDeviceCode())) {
mapElement = repository.findByCode(memberVO.getDeviceCode());
if (mapElement == null) {
mapElement = repository.getVRByCode(memberVO.getDeviceCode());
}
}
memberManager.addRole(simulation, memberVO.getId(), memberVO.getType(), memberVO.getName(), mapElement);
public SimulationWorkService getWorkService(@NonNull Simulation.Type simulationType) {
SimulationWorkService initService = map.get(simulationType);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(initService,
String.format("[%s]仿真未配置初始化服务", simulationType));
return initService;
}
/**
* 构建仿真成员实体
*/
public void buildMember(Simulation simulation) {
Map<Simulation.Type, List<MapMemberVO>> memberMap = simulation.getBuildParams().getMap()
.getGraphDataNew().getMemberMap();
if (CollectionUtils.isEmpty(memberMap)) {
return;
}
List<MapMemberVO> memberVOS = memberMap.get(
simulation.getBuildParams().getWorkParamVO().getType());
if (CollectionUtils.isEmpty(memberVOS)) {
return;
}
List<String> dataErrMsgList = simulation.getDataErrMsgList();
SimulationDataRepository repository = simulation.getRepository();
for (MapMemberVO memberVO : memberVOS) {
if (memberVO.getId() == null) {
dataErrMsgList.add(String.format("成员数据[%s]未设置id", memberVO));
continue;
}
if (memberVO.getType() == null) {
dataErrMsgList.add(String.format("成员数据[%s]未设置类型", memberVO));
continue;
}
MapElement mapElement = null;
if (StringUtils.hasText(memberVO.getDeviceCode())) {
mapElement = repository.findByCode(memberVO.getDeviceCode());
if (mapElement == null) {
mapElement = repository.getVRByCode(memberVO.getDeviceCode());
}
}
memberManager.addRole(simulation, memberVO.getId(), memberVO.getType(), memberVO.getName(),
mapElement);
}
}
/**
* 仿真初始化时设置仿真创建者扮演的角色
*/
public void playMember(Simulation simulation, String memberId) {
if (StringUtils.hasText(memberId)) {
Long creatorId = simulation.getBuildParams().getLoginUserInfo().getAccountVO().getId();
memberManager.playRole(simulation, creatorId, memberId);
/**
* 仿真初始化时设置仿真创建者扮演的角色
*/
public void playMember(Simulation simulation, String memberId) {
if (StringUtils.hasText(memberId)) {
Long creatorId = simulation.getBuildParams().getLoginUserInfo().getAccountVO().getId();
memberManager.playRole(simulation, creatorId, memberId);
}
}
/**
* 添加仿真用户
*/
public void addSimulationUser(Simulation simulation, SimulationUser simulationUser) {
simulation.addSimulationUser(simulationUser);
SimulationUserEnterEvent userEnterEvent = new SimulationUserEnterEvent(this, simulation,
simulationUser);
this.applicationContext.publishEvent(userEnterEvent);
}
public void loadRealDevices(Simulation simulation) {
SimulationBuildParams buildParams = simulation.getBuildParams();
List<ProjectDeviceVO> projectDeviceList = this.deviceService
.queryDetailByTypes(ProjectDeviceType.PlcDeviceList(),
buildParams.getMap().getProjectCode());
List<RealDeviceConfig> realDeviceList = ProjectDeviceVO.convert2RealDeviceList(
projectDeviceList);
log.info(String.format("load project device list: [%s]",
realDeviceList.stream().map(Object::toString).collect(Collectors.joining(","))));
this.loadRealDevices(simulation, realDeviceList);
}
private void loadRealDevices(Simulation simulation, List<RealDeviceConfig> realDeviceList) {
try {
simulation.setRealDeviceList(realDeviceList);
if (!CollectionUtils.isEmpty(realDeviceList)) {
simulationRealDeviceThread.addJobs(simulation);
udpRealDeviceThread.addJobs(simulation);
}
for (RealDeviceConfig realDevice : realDeviceList) {
if (ProjectDeviceType.PLC_GATEWAY.equals(realDevice.getDeviceType())) {
continue;
}
}
/**
* 添加仿真用户
*/
public void addSimulationUser(Simulation simulation, SimulationUser simulationUser) {
simulation.addSimulationUser(simulationUser);
SimulationUserEnterEvent userEnterEvent = new SimulationUserEnterEvent(this, simulation, simulationUser);
this.applicationContext.publishEvent(userEnterEvent);
}
public void loadRealDevices(Simulation simulation) {
SimulationBuildParams buildParams = simulation.getBuildParams();
List<ProjectDeviceVO> projectDeviceList = this.deviceService
.queryDetailByTypes(ProjectDeviceType.PlcDeviceList(), buildParams.getMap().getProjectCode());
List<RealDeviceConfig> realDeviceList = ProjectDeviceVO.convert2RealDeviceList(projectDeviceList);
log.info(String.format("load project device list: [%s]",
realDeviceList.stream().map(Object::toString).collect(Collectors.joining(","))));
this.loadRealDevices(simulation, realDeviceList);
}
private void loadRealDevices(Simulation simulation, List<RealDeviceConfig> realDeviceList) {
try {
simulation.setRealDeviceList(realDeviceList);
if (!CollectionUtils.isEmpty(realDeviceList)) {
simulationRealDeviceThread.addJobs(simulation);
udpRealDeviceThread.addJobs(simulation);
}
for (RealDeviceConfig realDevice : realDeviceList) {
if (ProjectDeviceType.PLC_GATEWAY.equals(realDevice.getDeviceType())) {
continue;
}
String deviceCode = realDevice.findDeviceCode();
if (Objects.nonNull(deviceCode)) {
this.groupSimulationService.connectDevice(simulation.getId(),
deviceCode, realDevice.getProjectDevice().getId());
}
}
} catch (Exception e) {
log.error("仿真加载真实设备异常", e);
// 清理仿真
this.groupSimulationService.clearSimulation(simulation.getId(), simulation.getCreator());
throw BusinessExceptionAssertEnum.TRAINING_ROOM_SIMULATION_LOAD_DEVICE_ERROR.exception(e);
String deviceCode = realDevice.findDeviceCode();
if (Objects.nonNull(deviceCode)) {
this.groupSimulationService.connectDevice(simulation.getId(),
deviceCode, realDevice.getProjectDevice().getId());
}
}
} catch (Exception e) {
log.error("仿真加载真实设备异常", e);
// 清理仿真
this.groupSimulationService.clearSimulation(simulation.getId(), simulation.getCreator());
throw BusinessExceptionAssertEnum.TRAINING_ROOM_SIMULATION_LOAD_DEVICE_ERROR.exception(e);
}
}
}

View File

@ -4,8 +4,11 @@ import club.joylink.rtss.constants.ProjectCode;
import club.joylink.rtss.constants.ProjectDeviceType;
import club.joylink.rtss.entity.ProjectDevice;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.cgy.CgySectionConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.cgy.CgySignalConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.cgy.CgySwitchConfig;
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.simulation.cbtc.device.real.modbustcp.gxsd.GxsdSignalConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gxsd.GxsdSwitchConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gzb.GzbSignalConfig;
@ -147,12 +150,36 @@ public class ProjectDeviceVO {
case "GXSD": {
return gxsdDeviceConfigConvert(voList);
}
case ProjectCode.CDGXY: {
return cdgxyDeviceConfigConvert(voList);
}
}
}
return list;
}
private static List<RealDeviceConfig> cdgxyDeviceConfigConvert(List<ProjectDeviceVO> voList) {
List<RealDeviceConfig> list = new ArrayList<>();
for (ProjectDeviceVO deviceVO : voList) {
switch (deviceVO.getType()) {
case PLC_GATEWAY:
list.add(new PlcGateway(deviceVO));
break;
case SIGNAL:
list.add(new CgySignalConfig(deviceVO));
break;
case SWITCH:
list.add(new CgySwitchConfig(deviceVO));
break;
case SECTION:
list.add(new CgySectionConfig(deviceVO));
break;
}
}
return list;
}
private static List<RealDeviceConfig> thailandSandboxDeviceConfigConvert(
List<ProjectDeviceVO> voList) {
List<RealDeviceConfig> list = new ArrayList<>();

View File

@ -0,0 +1,24 @@
package club.joylink.rtss.vo.client.project.cgy;
import club.joylink.rtss.vo.client.project.RealConfigVO;
import lombok.Getter;
@Getter
public class CgySectionConfigVO extends RealConfigVO {
private String sectionCode;
/**
* 出清
*/
private Integer r_occupied = 6;
public CgySectionConfigVO() {
super(0, 32);
}
@Override
public String findDeviceCode() {
return sectionCode;
}
}

View File

@ -0,0 +1,42 @@
package club.joylink.rtss.vo.client.project.cgy;
import club.joylink.rtss.vo.client.project.RealConfigVO;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class CgySignalConfigVO extends RealConfigVO {
private String signalCode;
/**
*
*/
private Integer r_red = 3;
/**
* 绿
*/
private Integer r_green = 4;
/**
*
*/
private Integer r_yellow = 5;
private Integer w_red = 12;
private Integer w_green = 13;
private Integer w_yellow = 14;
public CgySignalConfigVO() {
super(0, 16);
}
@Override
public String findDeviceCode() {
return signalCode;
}
}

View File

@ -0,0 +1,46 @@
package club.joylink.rtss.vo.client.project.cgy;
import club.joylink.rtss.vo.client.project.RealConfigVO;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class CgySwitchConfigVO extends RealConfigVO {
private String switchCode;
/**
* 定表
*/
private Integer r_db = 0;
/**
* 反表
*/
private Integer r_fb = 1;
/**
* 锁接
*/
private Integer w_sj = 9;
/**
* 定操
*/
private Integer w_dc = 10;
/**
* 反操
*/
private Integer w_fc = 11;
public CgySwitchConfigVO() {
super(0, 40);
}
@Override
public String findDeviceCode() {
return switchCode;
}
}