泰国沙盘调试改动

This commit is contained in:
joylink_zhangsai 2023-06-04 17:23:46 +08:00
parent f3ec423779
commit 74b9ab80da
38 changed files with 4404 additions and 3282 deletions

View File

@ -0,0 +1,8 @@
package club.joylink.rtss.constants;
public interface ProjectCode {
String THAILAND_SANDBOX = "THAILAND_SANDBOX";
String SR_SANDBOX = "SR_SANDBOX";
}

View File

@ -7,12 +7,32 @@ import club.joylink.rtss.services.project.DeviceService;
import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.project.*; import club.joylink.rtss.vo.client.project.IbpConfigVO;
import club.joylink.rtss.vo.client.project.LswConfigVO;
import club.joylink.rtss.vo.client.project.LwConfigVO;
import club.joylink.rtss.vo.client.project.PlcGatewayConfigVO;
import club.joylink.rtss.vo.client.project.ProjectDevicePageQueryVO;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.PscConfigVO;
import club.joylink.rtss.vo.client.project.PsdConfigVO;
import club.joylink.rtss.vo.client.project.PslConfigVO;
import club.joylink.rtss.vo.client.project.RelationLoginConfigVO;
import club.joylink.rtss.vo.client.project.SignalConfigVO;
import club.joylink.rtss.vo.client.project.SwitchConfigVO;
import club.joylink.rtss.vo.client.project.VrIbpConfigVO;
import club.joylink.rtss.vo.client.project.VrpsdConfigVO;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import java.util.List; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/** /**
* 项目设备管理接口() * 项目设备管理接口()
@ -258,4 +278,10 @@ public class DeviceController {
AccountVO accountVO) { AccountVO accountVO) {
this.deviceService.addOrUpdateSayDeviceConfig(accountVO); this.deviceService.addOrUpdateSayDeviceConfig(accountVO);
} }
@PostMapping("/thailand/addOrUpdate/{mapId}")
public void addOrUpdateThailandDeviceConfig(@RequestAttribute(name = AuthenticateInterceptor.LOGIN_USER_KEY)
AccountVO accountVO, @PathVariable Long mapId) {
this.deviceService.addOrUpdateThailandDeviceConfig(accountVO, mapId);
}
} }

View File

@ -4,8 +4,20 @@ import club.joylink.rtss.constants.ProjectDeviceType;
import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.PageVO; import club.joylink.rtss.vo.client.PageVO;
import club.joylink.rtss.vo.client.project.*; import club.joylink.rtss.vo.client.project.IbpConfigVO;
import club.joylink.rtss.vo.client.project.LswConfigVO;
import club.joylink.rtss.vo.client.project.LwConfigVO;
import club.joylink.rtss.vo.client.project.PlcGatewayConfigVO;
import club.joylink.rtss.vo.client.project.ProjectDevicePageQueryVO;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.PscConfigVO;
import club.joylink.rtss.vo.client.project.PsdConfigVO;
import club.joylink.rtss.vo.client.project.PslConfigVO;
import club.joylink.rtss.vo.client.project.RelationLoginConfigVO;
import club.joylink.rtss.vo.client.project.SignalConfigVO;
import club.joylink.rtss.vo.client.project.SwitchConfigVO;
import club.joylink.rtss.vo.client.project.VrIbpConfigVO;
import club.joylink.rtss.vo.client.project.VrpsdConfigVO;
import java.util.List; import java.util.List;
public interface DeviceService { public interface DeviceService {
@ -216,4 +228,6 @@ public interface DeviceService {
void addOrUpdateHhcjDeviceConfig(AccountVO accountVO); void addOrUpdateHhcjDeviceConfig(AccountVO accountVO);
void addOrUpdateSayDeviceConfig(AccountVO accountVO); void addOrUpdateSayDeviceConfig(AccountVO accountVO);
void addOrUpdateThailandDeviceConfig(AccountVO accountVO, Long mapId);
} }

View File

@ -1,6 +1,5 @@
package club.joylink.rtss.simulation.cbtc.CI.device; package club.joylink.rtss.simulation.cbtc.CI.device;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SignalAspect; import club.joylink.rtss.simulation.cbtc.constant.SignalAspect;
import club.joylink.rtss.simulation.cbtc.data.map.Signal; import club.joylink.rtss.simulation.cbtc.data.map.Signal;
@ -62,9 +61,9 @@ public class CiSignalControlService {
} else { } else {
this.virtualRealityDeviceService.control(simulation, vrSignal, SignalAspect.No); this.virtualRealityDeviceService.control(simulation, vrSignal, SignalAspect.No);
} }
} else { // 模式开放室外信号 } else { // 模式开放室外信号
if(signal.getSignalModel().getDefaultAspect().equals(aspect) || if(signal.getSignalModel().getDefaultAspect().equals(aspect) ||
(signal.getSignalModel().getGuideAspect().equals(aspect) && signal.isHigherThanGuideLevel()) || (aspect.equals(signal.getSignalModel().getGuideAspect()) && signal.isHigherThanGuideLevel()) ||
(signal.isAtpLevel() || signal.isMainLevel())) { (signal.isAtpLevel() || signal.isMainLevel())) {
this.virtualRealityDeviceService.control(simulation, vrSignal, aspect); this.virtualRealityDeviceService.control(simulation, vrSignal, aspect);
} }

View File

@ -7,21 +7,6 @@ import club.joylink.rtss.vo.project.ProjectVO;
* 项目综合演练仿真服务 * 项目综合演练仿真服务
*/ */
public interface ProjectJointSimulationService { public interface ProjectJointSimulationService {
/**
* 实训室教员机登录创建仿真
*
* @param loginUserInfo
* @return
*/
Simulation createSimulation(LoginUserInfoVO loginUserInfo);
/**
* 获取实训室仿真
*
* @param project
* @return
*/
Simulation getProjectSimulation(String project);
/** /**
* 通过项目设置的mapID与功能ID获取仿真 * 通过项目设置的mapID与功能ID获取仿真

View File

@ -1,35 +1,21 @@
package club.joylink.rtss.simulation.cbtc; package club.joylink.rtss.simulation.cbtc;
import club.joylink.rtss.constants.MapPrdTypeEnum;
import club.joylink.rtss.constants.ProjectDeviceType;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.IMapService;
import club.joylink.rtss.services.auth.ProjectDeviceLogoutEvent; import club.joylink.rtss.services.auth.ProjectDeviceLogoutEvent;
import club.joylink.rtss.services.auth.UserLogoutEvent; import club.joylink.rtss.services.auth.UserLogoutEvent;
import club.joylink.rtss.services.project.DeviceService;
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.udp.UDPRealDeviceThread;
import club.joylink.rtss.simulation.cbtc.event.SimulationUserEnterEvent; import club.joylink.rtss.simulation.cbtc.event.SimulationUserEnterEvent;
import club.joylink.rtss.simulation.cbtc.member.MemberManager;
import club.joylink.rtss.simulation.cbtc.member.SimulationUser; import club.joylink.rtss.simulation.cbtc.member.SimulationUser;
import club.joylink.rtss.vo.AccountVO;
import club.joylink.rtss.vo.LoginUserInfoVO; import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO; import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.map.MapVO;
import club.joylink.rtss.vo.project.ProjectVO; import club.joylink.rtss.vo.project.ProjectVO;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@Slf4j @Slf4j
@Service @Service
@ -40,169 +26,17 @@ public class ProjectJointSimulationServiceImpl implements ProjectJointSimulation
@Autowired @Autowired
private ApplicationContext applicationContext; private ApplicationContext applicationContext;
@Autowired
private IMapService iMapService;
@Autowired
private DeviceService deviceService;
@Autowired @Autowired
private GroupSimulationService groupSimulationService; private GroupSimulationService groupSimulationService;
@Autowired
private MemberManager memberManager;
@Autowired
private SimulationRealDeviceThread simulationRealDeviceThread;
@Autowired
private UDPRealDeviceThread udpRealDeviceThread;
@Autowired @Autowired
private SimulationService simulationService; private SimulationService simulationService;
@Override
public Simulation createSimulation(LoginUserInfoVO loginUserInfo) {
String project = loginUserInfo.getProject();
Simulation oldSimulation = projectSimulationMap.get(project);
// 之前的仿真销毁
if (Objects.nonNull(oldSimulation)) {
this.handleLogout(oldSimulation.getBuildParams().getLoginUserInfo());
}
// 权限判断
AccountVO accountVO = loginUserInfo.getAccountVO();
// 查询用户综合演练配置
// 查询项目地图默认取第一个暂时这样处理后面考虑配置实训室-地图对应
List<MapVO> mapList = this.iMapService.findOnlineMapByProjectCode(project);
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertCollectionNotEmpty(mapList,
String.format("项目[%s]无地图", project));
// 查询项目设备
List<ProjectDeviceVO> projectDeviceList = this.deviceService
.queryDetailByTypes(ProjectDeviceType.PlcDeviceList(), project);
List<RealDeviceConfig> realDeviceList = ProjectDeviceVO.convert2RealDeviceList(projectDeviceList);
log.info(String.format("load project device list: [%s]",
String.join(",", realDeviceList.stream().map(realDevice -> realDevice.toString()).collect(Collectors.toList()))));
// 构建仿真
Long mapId = mapList.get(0).getId();
Simulation simulation = this.groupSimulationService.create(loginUserInfo, mapId,
MapPrdTypeEnum.JOINT, Simulation.FunctionalType.SIMULATION);
this.loadRealDevices(simulation, realDeviceList);
projectSimulationMap.put(project, simulation);
return simulation;
}
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 = this.queryDeviceCodeFromConfig(realDevice);
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);
}
}
private String queryDeviceCodeFromConfig(RealDeviceConfig config) {
return config.findDeviceCode();
// switch (config.getProject()) {
// case "HEB": {
// switch (config.getDeviceType()) {
// case IBP:
// return ((Heb1IbpConfig) config).getConfig().getStationCode();
// case PSL:
// return ((Heb1PslConfig) config).getConfig().getPsdCode();
// case PSC:
// return ((Heb1PscConfig) config).getConfig().getPsdCode();
// }
// break;
// }
// case "XTY": {
// switch (config.getDeviceType()) {
// case PSD:
// return ((XtyPsdConfig) config).getConfig().getPsdCode();
// }
// break;
// }
// case "RICHOR_JOINT": {
// switch (config.getDeviceType()) {
// case IBP:
// return ((ZjdIbpConfig) config).getConfigVO().getIbpCode();
// case PSL:
// return ((ZjdPslConfig) config).getConfigVO().getPslCode();
// }
// break;
// }
// case "SR_SANDBOX": {
// switch (config.getDeviceType()) {
// case SIGNAL:
// return ((SrSignalConfig) config).getConfigVO().getVrCode();
// case SECTION:
// return ((SrSectionConfig) config).getConfigVO().getVrCode();
// case SWITCH:
// return ((SrSwitchConfig) config).getConfigVO().getVrCode();
// case TRAIN:
// return ((SrTrainConfig) config).getConfigVO().getVrCode();
// }
// break;
// }
// case "RICHOR_HHCJ": {
// switch (config.getDeviceType()) {
// case IBP:
// return ((HhcjIbpConfig) config).getConfigVO().getIbpCode();
// case PSD:
// return ((HhcjPsdConfig) config).getConfigVO().getPsdCode();
// }
// break;
// }
// case "SAY": {
// return config.findDeviceCode();
// switch (config.getDeviceType()) {
// case IBP:
// return ((SayIbpConfig) config).getConfigVO().getIbpCode();
// case PSD:
// return ((SayPsdConfig) config).getConfigVO().getPsdCode();
// case SIGNAL:
// return ((SaySignalConfig) config).getConfigVO().getSignalCode();
// case SWITCH:
// return ((SaySwitchConfig) config).getConfigVO().getSwitchCode();
// case SECTION:
// return config.findDeviceCode();
// }
// break;
// }
// }
// return null;
}
private Simulation queryProjectSimulation(String project) { private Simulation queryProjectSimulation(String project) {
Simulation simulation = projectSimulationMap.get(project); Simulation simulation = projectSimulationMap.get(project);
return simulation; return simulation;
} }
@Override
public Simulation getProjectSimulation(String project) {
Simulation simulation = projectSimulationMap.get(project);
BusinessExceptionAssertEnum.TRAINING_ROOM_SIMULATION_NOT_EXIST
.assertNotNull(simulation, String.format("项目[%s]实训室仿真不存在", project));
return simulation;
}
@Override @Override
public Simulation getSimulationByProject(ProjectVO project) { public Simulation getSimulationByProject(ProjectVO project) {
Simulation simulation = simulationService.querySimulation(project.getMapId(), project.getFunctionId()); Simulation simulation = simulationService.querySimulation(project.getMapId(), project.getFunctionId());
@ -219,52 +53,6 @@ public class ProjectJointSimulationServiceImpl implements ProjectJointSimulation
simulation.addSimulationUser(simulationUser); simulation.addSimulationUser(simulationUser);
SimulationUserEnterEvent userEnterEvent = new SimulationUserEnterEvent(this, simulation, simulationUser); SimulationUserEnterEvent userEnterEvent = new SimulationUserEnterEvent(this, simulation, simulationUser);
this.applicationContext.publishEvent(userEnterEvent); this.applicationContext.publishEvent(userEnterEvent);
// switch (deviceVO.getType()) {
// case LW: {
// // 暂时默认先按配置的车站创建成员
// LwConfigVO lwConfigVO = deviceVO.buildLwConfig();
// Station station = simulation.getRepository().getByCode(lwConfigVO.getStationCode(), Station.class);
// SimulationMember member = simulation.getSimulationMember(station, SimulationMember.Type.STATION_SUPERVISOR);
// this.memberManager.playRole(simulation, loginUserInfo.getAccountVO().getId(), member.getId());
// // 现地工作站
// break;
// }
// case CW: {
// // 行调工作站
// List<SimulationMember> dispatcherList = simulation.querySimulationMembersOfRole(SimulationMember.Type.DISPATCHER);
// SimulationMember dispatcher = null;
// for (SimulationMember member : dispatcherList) {
// if (member.isRobot()) {
// dispatcher = member;
// break;
// }
// }
// if (Objects.isNull(dispatcher)) {
// // 行调都被占用添加新的行调
// dispatcher = this.memberManager.addRole(simulation, SimulationMember.Type.DISPATCHER);
// }
// this.memberManager.playRole(simulation, loginUserInfo.getAccountVO().getId(), dispatcher.getId());
// break;
// }
// case DEPOT: {
// List<SimulationMember> depoterList = simulation.querySimulationMembersOfRole(SimulationMember.Type.DEPOT_DISPATCHER);
// SimulationMember depoter = null;
// for (SimulationMember member : depoterList) {
// if (member.isRobot()) {
// depoter = member;
// break;
// }
// }
// if (Objects.isNull(depoter)) {
// depoter = this.memberManager.addRole(simulation, SimulationMember.Type.DEPOT_DISPATCHER);
// }
// this.memberManager.playRole(simulation, loginUserInfo.getAccountVO().getId(), depoter.getId());
// break;
// }
// case SCHEDULING: {
//
// }
// }
loginUserInfo.setGroup(simulation.getId()); loginUserInfo.setGroup(simulation.getId());
} }

View File

@ -6,7 +6,11 @@ import club.joylink.rtss.simulation.cbtc.constant.RunLevel;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.constant.TrainTBControl; import club.joylink.rtss.simulation.cbtc.constant.TrainTBControl;
import club.joylink.rtss.simulation.cbtc.data.CalculateService; import club.joylink.rtss.simulation.cbtc.data.CalculateService;
import club.joylink.rtss.simulation.cbtc.data.map.*; import club.joylink.rtss.simulation.cbtc.data.map.MapElement;
import club.joylink.rtss.simulation.cbtc.data.map.Section;
import club.joylink.rtss.simulation.cbtc.data.map.Signal;
import club.joylink.rtss.simulation.cbtc.data.map.Stand;
import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan; import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan;
import club.joylink.rtss.simulation.cbtc.data.support.MovementAuthority; import club.joylink.rtss.simulation.cbtc.data.support.MovementAuthority;
import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition; import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition;
@ -14,15 +18,14 @@ import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import club.joylink.rtss.vo.client.operation.DriveParamVO; import club.joylink.rtss.vo.client.operation.DriveParamVO;
import club.joylink.rtss.vo.ws.TrainPosition; import club.joylink.rtss.vo.ws.TrainPosition;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Objects; import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
/** /**
* 虚拟真实列车 * 虚拟真实列车
@ -1188,6 +1191,10 @@ public class VirtualRealityTrain extends VirtualRealityDevice {
return robotDriveParam.needStop(); return robotDriveParam.needStop();
} }
public boolean isRobotStopControl() {
return robotDriveParam.isStopControl();
}
@Getter @Getter
@Setter @Setter
public static class Door extends ControllableVrDevice<Door.Operation> { public static class Door extends ControllableVrDevice<Door.Operation> {

View File

@ -1,16 +1,15 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; package club.joylink.rtss.simulation.cbtc.device.real.udp;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
@Getter @Getter
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
public class SrTrainControlParam { public class SandTableTrainControlParam {
@NotBlank(message = "车组号不能为空") @NotBlank(message = "车组号不能为空")
private String groupNumber; private String groupNumber;

View File

@ -0,0 +1,70 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp;
import club.joylink.rtss.constants.ProjectCode;
import club.joylink.rtss.dao.MapDataDAO;
import club.joylink.rtss.entity.MapDataExample;
import club.joylink.rtss.entity.MapDataWithBLOBs;
import club.joylink.rtss.simulation.cbtc.GroupSimulationService;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.service.SrTrainServiceImpl;
import club.joylink.rtss.simulation.cbtc.device.real.udp.thailand.service.ThailandTrainServiceImpl;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.map.MapLogicDataNewVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/api/sandTable")
public class SandTableTrainController {
@Autowired
private GroupSimulationService groupSimulationService;
@Autowired
private ThailandTrainServiceImpl thailandTrainService;
@Autowired
private SrTrainServiceImpl srTrainService;
@PutMapping("/{simulationId}/control")
public void control(@PathVariable String simulationId, String groupNumber, boolean right,
int speed) {
Simulation simulation = groupSimulationService.getSimulationByGroup(simulationId);
switch (simulation.getProject()) {
case ProjectCode.THAILAND_SANDBOX:
thailandTrainService.controlTrain(simulationId, groupNumber, right, speed);
break;
case ProjectCode.SR_SANDBOX:
srTrainService.controlTrain(simulationId, groupNumber, right, speed);
break;
default:
}
}
@Autowired
private MapDataDAO mapDataDAO;
@PutMapping("/handle")
public void handle() {
MapDataExample example = new MapDataExample();
example.setOrderByClause("id desc");
example.setLimit(1);
MapDataWithBLOBs data = mapDataDAO.selectByExampleWithBLOBs(example).get(0);
MapLogicDataNewVO logicDataNewVO = JsonUtils.read(data.getLogicData(), MapLogicDataNewVO.class);
logicDataNewVO.getRouteList().stream()
.filter(route -> route.getStartSignalCode().equals("X542") || route.getStartSignalCode()
.equals("X11357")
|| route.getStartSignalCode().equals("X47820") || route.getStartSignalCode()
.equals("X4371")
|| route.getStartSignalCode().equals("X21134") || route.getStartSignalCode()
.equals("X99402")
|| route.getStartSignalCode().equals("X2670") || route.getStartSignalCode()
.equals("X49087"))
.forEach(route -> {
route.setSignalAspect(3);
});
data.setLogicData(JsonUtils.writeValueAsString(logicDataNewVO));
mapDataDAO.updateByPrimaryKeyWithBLOBs(data);
}
}

View File

@ -10,6 +10,9 @@ import io.netty.channel.ChannelInitializer;
import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.DatagramPacket;
import io.netty.channel.socket.nio.NioDatagramChannel; import io.netty.channel.socket.nio.NioDatagramChannel;
import java.net.InetSocketAddress;
import java.time.LocalDateTime;
import java.util.concurrent.ConcurrentLinkedQueue;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
@ -18,73 +21,74 @@ import org.springframework.boot.ApplicationRunner;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.concurrent.ConcurrentLinkedQueue;
@Component @Component
@Slf4j @Slf4j
public class UDPClient implements ApplicationRunner { public class UDPClient implements ApplicationRunner {
@Autowired
private UDPConfig udpConfig;
private Channel channel; @Autowired
private UDPConfig udpConfig;
private final ConcurrentLinkedQueue<Msg> msgQueue = new ConcurrentLinkedQueue<>(); private Channel channel;
@Override private final ConcurrentLinkedQueue<Msg> msgQueue = new ConcurrentLinkedQueue<>();
public void run(ApplicationArguments args) throws Exception {
this.start(); @Override
public void run(ApplicationArguments args) throws Exception {
this.start();
}
public void start() throws InterruptedException {
Bootstrap bootstrap = new Bootstrap();
NioEventLoopGroup group = new NioEventLoopGroup();
bootstrap.group(group)
.channel(NioDatagramChannel.class)
.handler(new ChannelInitializer<NioDatagramChannel>() {
@Override
protected void initChannel(NioDatagramChannel channel) {
}
});
ChannelFuture future = bootstrap.bind(udpConfig.getClientPort()).sync();
Channel channel = future.channel();
this.channel = channel;
if (future.isSuccess()) {
log.info(String.format("udp client start on port [%s]", this.udpConfig.getClientPort()));
} else {
log.error("udp server start failed", future.cause());
} }
}
public void start() throws InterruptedException { public void write(InetSocketAddress addr, byte[] msg) {
Bootstrap bootstrap = new Bootstrap(); if (msg != null) {
NioEventLoopGroup group = new NioEventLoopGroup(); msgQueue.add(new Msg(addr, msg));
bootstrap.group(group) System.out.println(LocalDateTime.now());
.channel(NioDatagramChannel.class)
.handler(new ChannelInitializer<NioDatagramChannel>() {
@Override
protected void initChannel(NioDatagramChannel channel) {
}
});
ChannelFuture future = bootstrap.bind(udpConfig.getClientPort()).sync();
Channel channel = future.channel();
this.channel = channel;
if (future.isSuccess()) {
log.info(String.format("udp client start on port [%s]", this.udpConfig.getClientPort()));
} else {
log.error("udp server start failed", future.cause());
}
} }
}
public void write(InetSocketAddress addr, byte[] msg) { @Scheduled(fixedRate = 10)
msgQueue.add(new Msg(addr, msg)); public void send() {
Msg msg = msgQueue.poll();
if (msg == null) {
return;
}
InetSocketAddress addr = msg.getAddr();
byte[] data = msg.getData();
if (channel != null && channel.isWritable() && addr != null && data != null) {
ByteBuf byteBuf = Unpooled.copiedBuffer(data);
DatagramPacket datagramPacket = new DatagramPacket(byteBuf, addr);
channel.writeAndFlush(datagramPacket);
} }
}
@Scheduled(fixedRate = 10) @Getter
public void send() { class Msg {
Msg msg = msgQueue.poll();
if (msg == null) private InetSocketAddress addr;
return;
InetSocketAddress addr = msg.getAddr(); private byte[] data;
byte[] data = msg.getData();
if (channel != null && channel.isWritable() && addr != null && data != null) { public Msg(InetSocketAddress addr, byte[] data) {
ByteBuf byteBuf = Unpooled.copiedBuffer(data); this.addr = addr;
DatagramPacket datagramPacket = new DatagramPacket(byteBuf, addr); this.data = data;
channel.writeAndFlush(datagramPacket);
}
}
@Getter
class Msg {
private InetSocketAddress addr;
private byte[] data;
public Msg(InetSocketAddress addr, byte[] data) {
this.addr = addr;
this.data = data;
}
} }
}
} }

View File

@ -5,12 +5,11 @@ import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDevice
import club.joylink.rtss.util.JsonUtils; import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO; import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.UDPLowConfigVO; import club.joylink.rtss.vo.client.project.UDPLowConfigVO;
import lombok.Getter;
import org.springframework.util.StringUtils;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import lombok.Getter;
import org.springframework.util.StringUtils;
public class UDPLowConfig extends RealDeviceConfig { public class UDPLowConfig extends RealDeviceConfig {
@Getter @Getter
@ -53,4 +52,8 @@ public class UDPLowConfig extends RealDeviceConfig {
public String findDeviceCode() { public String findDeviceCode() {
return null; return null;
} }
public String getName() {
return configVO == null ? null : configVO.getName();
}
} }

View File

@ -5,6 +5,10 @@ import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDevice
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
public interface UDPRealDeviceService { public interface UDPRealDeviceService {
default boolean isMatch(UDPLowConfig udpLowConfig) {
return true;
}
boolean isMatch(RealDeviceConfig realDevice); boolean isMatch(RealDeviceConfig realDevice);
void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice); void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice);

View File

@ -3,93 +3,104 @@ package club.joylink.rtss.simulation.cbtc.device.real.udp;
import club.joylink.rtss.constants.ProjectDeviceType; import club.joylink.rtss.constants.ProjectDeviceType;
import club.joylink.rtss.simulation.cbtc.GroupSimulationService; import club.joylink.rtss.simulation.cbtc.GroupSimulationService;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.PlcGateway; 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.device.RealDeviceConfig;
import club.joylink.rtss.simulation.cbtc.event.SimulationResetEvent; import club.joylink.rtss.simulation.cbtc.event.SimulationResetEvent;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.util.List;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener; import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Objects;
@Slf4j @Slf4j
@Component @Component
public class UDPRealDeviceThread { public class UDPRealDeviceThread {
@Autowired
private UDPRealDeviceServiceManager udpRealDeviceServiceManager;
@Autowired /**
private GroupSimulationService groupSimulationService; * 真是设备逻辑执行频率
* <p>
* 因沙盘对延迟要求较高所以将频率提高
*/
public static final int RATE = 100;
@EventListener @Autowired
public void simulationReset(SimulationResetEvent event) { private UDPRealDeviceServiceManager udpRealDeviceServiceManager;
Simulation simulation = event.getSimulation();
List<RealDeviceConfig> realDeviceList = simulation.getRealDeviceList(); @Autowired
if (CollectionUtils.isEmpty(realDeviceList)) private GroupSimulationService groupSimulationService;
return;
UDPLowConfig udpConfig = (UDPLowConfig) simulation.queryOneRealDevice(ProjectDeviceType.UDP_LOW); @EventListener
if (udpConfig == null) public void simulationReset(SimulationResetEvent event) {
return; Simulation simulation = event.getSimulation();
for (RealDeviceConfig realDevice : realDeviceList) { List<RealDeviceConfig> realDeviceList = simulation.getRealDeviceList();
if (realDevice instanceof PlcGateway) { if (CollectionUtils.isEmpty(realDeviceList)) {
continue; return;
}
for (UDPRealDeviceService realDeviceService : this.udpRealDeviceServiceManager.getServiceList()) {
if (realDeviceService.isMatch(realDevice)) {
realDeviceService.init(simulation, udpConfig, realDevice);
}
}
}
} }
UDPLowConfig udpConfig = (UDPLowConfig) simulation.queryOneRealDevice(
public void run(Simulation simulation) { ProjectDeviceType.UDP_LOW);
List<RealDeviceConfig> realDeviceList = simulation.getRealDeviceList(); if (udpConfig == null) {
if (CollectionUtils.isEmpty(realDeviceList)) return;
return; }
List<UDPRealDeviceService> serviceList = udpRealDeviceServiceManager.getServiceList(); for (RealDeviceConfig realDevice : realDeviceList) {
if (CollectionUtils.isEmpty(serviceList)) if (realDevice instanceof PlcGateway) {
return; continue;
UDPLowConfig udpLowConfig = null; }
for (RealDeviceConfig realDeviceConfig : realDeviceList) { for (UDPRealDeviceService realDeviceService : this.udpRealDeviceServiceManager.getServiceList()) {
if (ProjectDeviceType.UDP_LOW.equals(realDeviceConfig.getDeviceType())) { if (realDeviceService.isMatch(realDevice)) {
udpLowConfig = (UDPLowConfig) realDeviceConfig; realDeviceService.init(simulation, udpConfig, realDevice);
break;
}
} }
for (RealDeviceConfig config : realDeviceList) { }
}
}
public void run(Simulation simulation) {
List<RealDeviceConfig> realDeviceList = simulation.getRealDeviceList();
if (CollectionUtils.isEmpty(realDeviceList)) {
return;
}
List<UDPRealDeviceService> serviceList = udpRealDeviceServiceManager.getServiceList();
if (CollectionUtils.isEmpty(serviceList)) {
return;
}
realDeviceList.stream()
.filter(
realDeviceConfig -> ProjectDeviceType.UDP_LOW.equals(realDeviceConfig.getDeviceType()))
.map(realDeviceConfig -> (UDPLowConfig) realDeviceConfig)
.forEach(udpLowConfig -> {
for (RealDeviceConfig config : realDeviceList) {
for (UDPRealDeviceService service : serviceList) { for (UDPRealDeviceService service : serviceList) {
if (service.isMatch(config) && config.getMapElement() != null) { if (service.isMatch(udpLowConfig) && service.isMatch(config)
service.run(simulation, udpLowConfig, config); && config.getMapElement() != null) {
} service.run(simulation, udpLowConfig, config);
}
} }
} }
} });
}
public void handleData(String ip, int port, ByteBuf data) { public void handleData(String ip, int port, ByteBuf data) {
List<Simulation> simulations = groupSimulationService.querySimulations(); List<Simulation> simulations = groupSimulationService.querySimulations();
for (Simulation simulation : simulations) { for (Simulation simulation : simulations) {
List<RealDeviceConfig> realDeviceList = simulation.getRealDeviceList(); List<RealDeviceConfig> realDeviceList = simulation.getRealDeviceList();
if (CollectionUtils.isEmpty(realDeviceList)) if (CollectionUtils.isEmpty(realDeviceList)) {
continue; continue;
UDPClientConfig udpClientConfig = (UDPClientConfig) simulation.queryOneRealDevice(ProjectDeviceType.UDP_CLIENT); }
if (udpClientConfig != null && Objects.equals(ip, udpClientConfig.getConfigVO().getIp()) UDPClientConfig udpClientConfig = (UDPClientConfig) simulation.queryOneRealDevice(
&& Objects.equals(port, udpClientConfig.getConfigVO().getPort())) { ProjectDeviceType.UDP_CLIENT);
for (UDPRealDeviceService udpRealDeviceService : this.udpRealDeviceServiceManager.getServiceList()) { if (udpClientConfig != null /*&& Objects.equals(ip, udpClientConfig.getConfigVO().getIp())
if (udpRealDeviceService.isMatch(udpClientConfig)) { && Objects.equals(port, udpClientConfig.getConfigVO().getPort())*/) {
udpRealDeviceService.handle(simulation, data); for (UDPRealDeviceService udpRealDeviceService : this.udpRealDeviceServiceManager.getServiceList()) {
} if (udpRealDeviceService.isMatch(udpClientConfig)) {
} udpRealDeviceService.handle(simulation, data);
} }
} }
}
} }
}
public void addJobs(Simulation simulation) { public void addJobs(Simulation simulation) {
simulation.addFixedRateJob(Simulation.JobName.udpRealDevice, simulation.addFixedRateJob(Simulation.JobName.udpRealDevice, () -> this.run(simulation), RATE);
() -> this.run(simulation), SimulationConstants.VRD_LOOP_RATE); }
}
} }

View File

@ -1,22 +0,0 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.sr;
import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.service.SrTrainServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/api/sr")
public class SrTrainController {
@Autowired
private SrTrainServiceImpl srTrainService;
// @PutMapping("/{simulationId}/control")
// public void control(@PathVariable String simulationId, @RequestBody @Validated SrTrainControlParam controlParam) {
// srTrainService.control(simulationId, controlParam.getGroupNumber(), controlParam.getRight(), controlParam.getSpeed());
// }
@PutMapping("/{simulationId}/control")
public void control(@PathVariable String simulationId, String groupNumber, boolean right, int speed) {
srTrainService.controlTrain(simulationId, groupNumber, right, speed);
}
}

View File

@ -15,10 +15,6 @@ import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceService;
import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrSectionConfig; import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrSectionConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrTrainConfig; import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrTrainConfig;
import io.netty.buffer.ByteBuf; 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.time.LocalDateTime;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
@ -26,167 +22,187 @@ import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j @Slf4j
@Service @Service
public class SrSectionServiceImpl implements UDPRealDeviceService { public class SrSectionServiceImpl implements UDPRealDeviceService {
@Autowired
private SrTrainServiceImpl srTrainService;
@Autowired public static final String PROJECT_CODE = "SR_SANDBOX";
private MaService maService;
@Override @Autowired
public boolean isMatch(RealDeviceConfig realDevice) { private MaService maService;
return realDevice instanceof UDPClientConfig;
@Override
public boolean isMatch(RealDeviceConfig realDevice) {
return realDevice instanceof UDPClientConfig && PROJECT_CODE
.equals(realDevice.getProject());
}
@Override
public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
}
@Override
public void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
}
@Override
public void handle(Simulation simulation, ByteBuf msg) {
//检查数据
byte[] data = new byte[msg.readableBytes()];
if (data.length < 4) {
return;
} }
msg.readBytes(data);
@Override if (Byte.toUnsignedInt(data[1]) != 137) {
public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) { return;
} }
//处理数据
@Override Map<String, SrSectionConfig> configMap = simulation.queryAllRealDevice(
public void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) { ProjectDeviceType.SECTION).stream()
} .map(config -> (SrSectionConfig) config)
.collect(
@Override Collectors.toMap(config -> config.getConfigVO().getSandboxCode(), Function.identity()));
public void handle(Simulation simulation, ByteBuf msg) { for (int i = 3, dataLength = data.length; i < dataLength; i += 2) {
//检查数据 int code = Byte.toUnsignedInt(data[i - 1]);
byte[] data = new byte[msg.readableBytes()]; String key = String.valueOf(code);
if (data.length < 4) SrSectionConfig config = configMap.get(key);
return; if (config == null) {
msg.readBytes(data); continue;
if (Byte.toUnsignedInt(data[1]) != 137) { }
return; VirtualRealitySectionAxleCounter axle = (VirtualRealitySectionAxleCounter) config.getMapElement();
if (axle != null) {
int n = Byte.toUnsignedInt(data[i]);
if (n == 170) {
updateTrainPosition(simulation, axle);
config.setTimesOfRelease(0);
axle.setOccupy(true);
} else if (n == 85) {
config.setTimesOfRelease(config.getTimesOfRelease() + 1);
if (config.getTimesOfRelease() > 3) { //连续4次该计轴都是无占用状态才视为确实无占用
config.setTimesOfRelease(0);
axle.clear();
}
} }
//处理数据 }
Map<String, SrSectionConfig> configMap = simulation.queryAllRealDevice(ProjectDeviceType.SECTION).stream()
.map(config -> (SrSectionConfig) config)
.collect(Collectors.toMap(config -> config.getConfigVO().getSandboxCode(), Function.identity()));
for (int i = 3, dataLength = data.length; i < dataLength; i += 2) {
int code = Byte.toUnsignedInt(data[i - 1]);
String key = String.valueOf(code);
SrSectionConfig config = configMap.get(key);
if (config == null)
continue;
VirtualRealitySectionAxleCounter axle = (VirtualRealitySectionAxleCounter) config.getMapElement();
if (axle != null) {
int n = Byte.toUnsignedInt(data[i]);
if (n == 170) {
updateTrainPosition(simulation, axle);
config.setTimesOfRelease(0);
axle.setOccupy(true);
} else if (n == 85) {
config.setTimesOfRelease(config.getTimesOfRelease() + 1);
if (config.getTimesOfRelease() > 3) { //连续4次该计轴都是无占用状态才视为确实无占用
config.setTimesOfRelease(0);
axle.clear();
}
}
}
}
//设置停车信息
stop(simulation);
} }
//设置停车信息
stop(simulation);
}
/** /**
* 列车到达特殊轨道设置延迟停车时间 * 列车到达特殊轨道设置延迟停车时间
*/ */
private void stop(Simulation simulation) { private void stop(Simulation simulation) {
for (VirtualRealityTrain train : simulation.getRepository().getOnlineTrainList()) { for (VirtualRealityTrain train : simulation.getRepository().getOnlineTrainList()) {
Section headSection = train.getHeadPosition().getSection(); Section headSection = train.getHeadPosition().getSection();
SrTrainConfig config = (SrTrainConfig) train.getRealDevice();
if (!Objects.equals(headSection, config.getHeadSection())) //列车无需在该站台停车
{
continue;
}
if (config.getTimeOfStop() != null) //已经设置过停车时间
{
continue;
}
if (!headSection.isFunctionTrack()) {
continue;
}
VirtualRealitySectionAxleCounter headAxle = headSection.findAxle();
if (headAxle == null) {
continue;
}
SrSectionConfig sectionConfig = (SrSectionConfig) headAxle.getRealDevice();
//设置延时停车时间
long m = 1000000000;
long nanos;
if (sectionConfig.getConfigVO().getHeadDelayTime() != null) {
nanos = (long) (sectionConfig.getConfigVO().getHeadDelayTime() * m);
config.setTimeOfStop(LocalDateTime.now().plusNanos(nanos));
continue;
}
//以前一个区段无占用作为停车标志的区段
boolean right = train.isRight();
Section behindSection = headSection.getNextRunningSectionOf(!right);
if (behindSection == null) {
continue;
}
VirtualRealitySectionAxleCounter behindAxle = behindSection.findAxle();
if (behindAxle == null) {
continue;
}
if (!behindAxle.isOccupy()) { //车头后方区段所属计轴无占用状态
nanos = 0;
if (sectionConfig.getConfigVO().getTailDelayTime() != null) {
nanos = (long) (sectionConfig.getConfigVO().getTailDelayTime() * m);
}
if (nanos == 0) {
train.setHeadPosition(headSection.buildStopPointPosition(right));
} else {
config.setTimeOfStop(LocalDateTime.now().plusNanos(nanos));
}
}
}
}
private void updateTrainPosition(Simulation simulation, VirtualRealitySectionAxleCounter axle) {
for (Section section : simulation.getRepository().getAxleSectionList()) {
if (section.getVirtualAxleCounter().equals(axle)) {
List<Section> pSection;
if (section.isPhysical()) {
pSection = Collections.singletonList(section);
} else if (section.isSwitchAxleCounterSection()) {
pSection = section.findConnectedSections();
} else {
pSection = Collections.emptyList();
}
for (Section sec : pSection) {
check4UpdateHeadPosition(simulation, sec, false);
check4UpdateHeadPosition(simulation, sec, true);
}
}
}
}
/**
* 检查是否有right向的列车可以更新车头位置
*/
private void check4UpdateHeadPosition(Simulation simulation, Section occupiedSection,
boolean right) {
Section section = occupiedSection.getNextRunningSectionOf(!right); //找反向的区段
if (section != null) {
for (VirtualRealityTrain train : simulation.getRepository().getOnlineTrainList()) {
Section headSection = train.getHeadPosition().getSection();
boolean trainRight = train.isRight();
if (trainRight == right && section.equals(headSection)) { //列车到达occupiedSection
//判断更新ITC ma
if (headSection.getSignalOf(trainRight) != null) {
maService.calculateAndUpdateItcMa(simulation, train);
}
//更新位置
SectionPosition headPosition;
SectionPosition stopPointPosition;
if (occupiedSection.isFunctionTrack()) {
stopPointPosition = occupiedSection.buildStopPointPosition(right);
headPosition = CalculateService.calculateNextPositionByStartAndLen(stopPointPosition,
!right, 1, true);
} else {
stopPointPosition = new SectionPosition(occupiedSection,
occupiedSection.getEndOffsetByDirection(right));
headPosition = CalculateService.calculateNextPositionByStartAndLen(stopPointPosition,
!right, 3, true);
}
train.setHeadPosition(headPosition); //更新位置
if (occupiedSection.isFunctionTrack()) { //功能轨可能需要停车
SrTrainConfig config = (SrTrainConfig) train.getRealDevice(); SrTrainConfig config = (SrTrainConfig) train.getRealDevice();
if (!Objects.equals(headSection, config.getHeadSection())) //列车无需在该站台停车 config.updateHeadSection(occupiedSection);
continue; }
if (config.getTimeOfStop() != null) //已经设置过停车时间
continue;
if (!headSection.isFunctionTrack())
continue;
VirtualRealitySectionAxleCounter headAxle = headSection.findAxle();
if (headAxle == null)
continue;
SrSectionConfig sectionConfig = (SrSectionConfig) headAxle.getRealDevice();
//设置延时停车时间
long m = 1000000000;
long nanos;
if (sectionConfig.getConfigVO().getHeadDelayTime() != null) {
nanos = (long) (sectionConfig.getConfigVO().getHeadDelayTime() * m);
config.setTimeOfStop(LocalDateTime.now().plusNanos(nanos));
continue;
}
//以前一个区段无占用作为停车标志的区段
boolean right = train.isRight();
Section behindSection = headSection.getNextRunningSectionOf(!right);
if (behindSection == null)
continue;
VirtualRealitySectionAxleCounter behindAxle = behindSection.findAxle();
if (behindAxle == null)
continue;
if (!behindAxle.isOccupy()) { //车头后方区段所属计轴无占用状态
nanos = 0;
if (sectionConfig.getConfigVO().getTailDelayTime() != null) {
nanos = (long) (sectionConfig.getConfigVO().getTailDelayTime() * m);
}
if (nanos == 0) {
train.setHeadPosition(headSection.buildStopPointPosition(right));
} else {
config.setTimeOfStop(LocalDateTime.now().plusNanos(nanos));
}
}
}
}
private void updateTrainPosition(Simulation simulation, VirtualRealitySectionAxleCounter axle) {
for (Section section : simulation.getRepository().getAxleSectionList()) {
if (section.getVirtualAxleCounter().equals(axle)) {
List<Section> pSection;
if (section.isPhysical()) {
pSection = Collections.singletonList(section);
} else if (section.isSwitchAxleCounterSection()) {
pSection = section.findConnectedSections();
} else {
pSection = Collections.emptyList();
}
for (Section sec : pSection) {
check4UpdateHeadPosition(simulation, sec, false);
check4UpdateHeadPosition(simulation, sec, true);
}
}
}
}
/**
* 检查是否有right向的列车可以更新车头位置
*/
private void check4UpdateHeadPosition(Simulation simulation, Section occupiedSection, boolean right) {
Section section = occupiedSection.getNextRunningSectionOf(!right); //找反向的区段
if (section != null) {
for (VirtualRealityTrain train : simulation.getRepository().getOnlineTrainList()) {
Section headSection = train.getHeadPosition().getSection();
boolean trainRight = train.isRight();
if (trainRight == right && section.equals(headSection)) { //列车到达occupiedSection
//判断更新ITC ma
if (headSection.getSignalOf(trainRight) != null) {
maService.calculateAndUpdateItcMa(simulation, train);
}
//更新位置
SectionPosition headPosition;
SectionPosition stopPointPosition;
if (occupiedSection.isFunctionTrack()) {
stopPointPosition = occupiedSection.buildStopPointPosition(right);
headPosition = CalculateService.calculateNextPositionByStartAndLen(stopPointPosition, !right, 1, true);
} else {
stopPointPosition = new SectionPosition(occupiedSection, occupiedSection.getEndOffsetByDirection(right));
headPosition = CalculateService.calculateNextPositionByStartAndLen(stopPointPosition, !right, 3, true);
}
train.setHeadPosition(headPosition); //更新位置
if (occupiedSection.isFunctionTrack()) { //功能轨可能需要停车
SrTrainConfig config = (SrTrainConfig) train.getRealDevice();
config.updateHeadSection(occupiedSection);
}
}
}
} }
}
} }
}
} }

View File

@ -0,0 +1,32 @@
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.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.thailand.ThailandSectionConfigVO;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
@Getter
public class ThailandSectionConfig extends RealDeviceConfig {
private ThailandSectionConfigVO configVO;
/**
* 连续无占用次数
*/
@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();
}
}

View File

@ -0,0 +1,30 @@
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.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.thailand.ThailandSignalConfigVO;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
@Getter
public class ThailandSignalConfig extends RealDeviceConfig {
private ThailandSignalConfigVO configVO;
@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();
}
}

View File

@ -0,0 +1,29 @@
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.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.thailand.ThailandSwitchConfigVO;
import java.util.Objects;
import lombok.Getter;
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);
}
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
}

View File

@ -0,0 +1,58 @@
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.util.JsonUtils;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.project.thailand.ThailandTrainConfigVO;
import java.time.LocalDateTime;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
@Getter
public class ThailandTrainConfig extends RealDeviceConfig {
private ThailandTrainConfigVO configVO;
@Setter
private Integer gear;
/**
* 列车需要在这个轨道停车
*/
private Section headSection;
/**
* 列车抵达停车点的时间
* <p>
* 当走到这个时间时需要将列车的车头位置更新至当前区段的停车点
* <p>
* 上述停车点指代一切可能需要停车的位置比如站台轨的停车点信号机2m前轨道尽头10m前
*/
@Setter
private LocalDateTime timeOfArriveStopPoint;
/**
* 人为驾驶的档位
*/
@Setter
private Integer manualGear;
public void updateHeadSection(Section headSection) {
this.headSection = headSection;
this.timeOfArriveStopPoint = null;
}
public ThailandTrainConfig(ProjectDeviceVO projectDevice) {
super(projectDevice);
if (Objects.nonNull(projectDevice.getConfig())) {
this.configVO = JsonUtils.read(projectDevice.getConfig(), ThailandTrainConfigVO.class);
}
}
@Override
public String findDeviceCode() {
return configVO.findDeviceCode();
}
}

View File

@ -0,0 +1,85 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.thailand.service;
import club.joylink.rtss.constants.ProjectCode;
import club.joylink.rtss.constants.ProjectDeviceType;
import club.joylink.rtss.simulation.cbtc.ATP.ground.MaService;
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.udp.UDPClientConfig;
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.thailand.config.ThailandSectionConfig;
import io.netty.buffer.ByteBuf;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class ThailandSectionServiceImpl implements UDPRealDeviceService {
@Autowired
private MaService maService;
@Override
public boolean isMatch(RealDeviceConfig realDevice) {
return realDevice instanceof UDPClientConfig && ProjectCode.THAILAND_SANDBOX
.equals(realDevice.getProject());
}
@Override
public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
}
@Override
public void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
//沙盘不需要停太长时间
simulation.getRepository().getStandList().forEach(stand -> stand.setParkingTime(15));
}
@Override
public void handle(Simulation simulation, ByteBuf msg) {
//检查数据
byte[] data = new byte[msg.readableBytes()];
if (data.length < 4) {
return;
}
msg.readBytes(data);
if (Byte.toUnsignedInt(data[1]) != 137) {
return;
}
//处理数据
Map<String, ThailandSectionConfig> configMap = simulation.queryAllRealDevice(
ProjectDeviceType.SECTION).stream()
.map(config -> (ThailandSectionConfig) config)
.collect(
Collectors.toMap(config -> config.getConfigVO().getSandboxCode(), Function.identity()));
for (int i = 3, dataLength = data.length; i < dataLength; i += 2) {
int code = Byte.toUnsignedInt(data[i - 1]);
String key = String.valueOf(code);
ThailandSectionConfig config = configMap.get(key);
if (config == null) {
continue;
}
VirtualRealitySectionAxleCounter axle = (VirtualRealitySectionAxleCounter) config.getMapElement();
if (axle != null) {
int n = Byte.toUnsignedInt(data[i]);
if (n == 170) {
config.setTimesOfRelease(0);
axle.setOccupy(true);
} else if (n == 85) {
config.setTimesOfRelease(config.getTimesOfRelease() + 1);
if (config.getTimesOfRelease() > 2) { //连续3次该计轴都是无占用状态才视为确实无占用
config.setTimesOfRelease(0);
axle.clear();
}
}
}
}
}
}

View File

@ -0,0 +1,136 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.thailand.service;
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.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.thailand.config.ThailandSignalConfig;
import io.netty.buffer.ByteBuf;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ThailandSignalServiceImpl implements UDPRealDeviceService {
public static final String NAME = "SIGNAL";
@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;
}
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 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;
}
}

View File

@ -0,0 +1,85 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.thailand.service;
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.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.thailand.config.ThailandSwitchConfig;
import io.netty.buffer.ByteBuf;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class ThailandSwitchServiceImpl implements UDPRealDeviceService {
public static final String NAME = "SWITCH-TRAIN";
@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);
}
//控制沙盘设备
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;
}
}

View File

@ -0,0 +1,303 @@
package club.joylink.rtss.simulation.cbtc.device.real.udp.thailand.service;
import club.joylink.rtss.constants.ProjectDeviceType;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.ATS.service.AtsTrainLoadService;
import club.joylink.rtss.simulation.cbtc.GroupSimulationService;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
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.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.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.thailand.config.ThailandSectionConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.thailand.config.ThailandTrainConfig;
import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPService;
import club.joylink.rtss.vo.client.project.thailand.ThailandSectionConfigVO;
import club.joylink.rtss.vo.map.graph.MapSectionNewVO;
import io.netty.buffer.ByteBuf;
import java.time.LocalDateTime;
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 ThailandTrainServiceImpl implements UDPRealDeviceService {
public static final String NAME = ThailandSwitchServiceImpl.NAME;
@Autowired
private UDPClient udpClient;
@Autowired
private ATPService atpService;
@Autowired
private GroupSimulationService groupSimulationService;
@Autowired
private AtsTrainLoadService atsTrainLoadService;
@Override
public boolean isMatch(UDPLowConfig udpLowConfig) {
return NAME.equals(udpLowConfig.getName());
}
@Override
public boolean isMatch(RealDeviceConfig realDevice) {
return realDevice instanceof ThailandTrainConfig;
}
@Override
public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
ThailandTrainConfig config = (ThailandTrainConfig) realDevice;
//控制vr设备
VirtualRealityTrain train = (VirtualRealityTrain) config.getMapElement();
SimulationDataRepository repository = simulation.getRepository();
String groupNumber = train.getGroupNumber();
if (repository.isVrTrainOnline(groupNumber)) {
removeVrTrainIfNotSupervised(repository, groupNumber);
if (!train.isRobotStopControl() && config.getManualGear() != null) {
config.setManualGear(null);
config.setGear(null);
}
updateTrainPosition(simulation, train, config);
updateTrainSpeed(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);
}
}
/**
* 更新列车位置
* <p>
* 1.如果列车占压新的区段则先将列车车头位置更新至该区段的停车点之前保证列车可以继续运行 2.根据区段的配置信息决定列车何时将车头位置更新至停车点
* 3.根据上一步设置的停车时间判断执行更新车头位置至停车点逻辑触发列车停车逻辑
*/
private void updateTrainPosition(Simulation simulation, VirtualRealityTrain train,
ThailandTrainConfig config) {
//判断列车是否到达新区段
boolean right = train.isRight(); //车头方向
Section headSection = train.getHeadPosition().getSection(); //车头区段
Section previousSection = null; //车头方向的上一个区段
Section nextSection = headSection.getNextRunningSectionOf(right); //车头方向的下一个区段
ThailandSectionConfig sectionConfig = (ThailandSectionConfig) headSection.findAxle()
.getRealDevice(); //车头区段的配置
if (nextSection != null) {
VirtualRealitySectionAxleCounter nextAxle = nextSection.findAxle();
if (nextAxle.isOccupy()) {
train.setHeadPosition(
new SectionPosition(nextSection, right ? 0 : nextSection.getMaxOffset()));
config.setTimeOfArriveStopPoint(null);
sectionConfig = (ThailandSectionConfig) nextAxle.getRealDevice();
//更新变量
previousSection = headSection;
headSection = train.getHeadPosition().getSection();
nextSection = null;
}
}
//根据区段的配置信息设置车头位置更新至停车点的时间
// fill(headSection, sectionConfig.getConfigVO()); 仅用于调试
LocalDateTime now = LocalDateTime.now();
if (config.getTimeOfArriveStopPoint() == null) {
int rate = 1000000000; //秒到纳秒的换算比例
Long delayOfNano = null; //延迟时间的纳秒表示
if (sectionConfig.getConfigVO().getHeadDelayTime() != null) { //车头占压延时停车
delayOfNano = (long) (sectionConfig.getConfigVO().getHeadDelayTime() * rate);
} else if (sectionConfig.getConfigVO().getTailDelayTime() != null) { //车尾出清延时停车
if (previousSection == null) {
previousSection = headSection.getNextRunningSectionOf(!right);
}
if (previousSection != null && !previousSection.isOccupied()) {
delayOfNano = (long) (sectionConfig.getConfigVO().getTailDelayTime() * rate);
}
} else { //未设置则认为车头占压即刻停车
delayOfNano = 0L;
}
if (delayOfNano != null) {
config.setTimeOfArriveStopPoint(now.plusNanos(delayOfNano));
}
}
//根据当前时间判断更新车头位置至停车点
LocalDateTime timeOfArriveStopPoint = config.getTimeOfArriveStopPoint();
if (timeOfArriveStopPoint != null && !now.isBefore(timeOfArriveStopPoint)) {
SectionPosition stopPosition = train.getRobotDriveParam().getStopPosition();
if (stopPosition != null && stopPosition.getSection().equals(headSection)) {
train.setHeadPosition(stopPosition);
} else if (stopPosition == null || !stopPosition.getSection().equals(headSection)) {
float offset = right ? headSection.getMaxOffset() : 0;
train.setHeadPosition(new SectionPosition(headSection, offset));
}
}
}
/**
* 如果有监控添加一个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);
}
}
/**
* 移除vrTrain如果没有被监控
*/
private void removeVrTrainIfNotSupervised(SimulationDataRepository repository,
String groupNumber) {
TrainInfo trainInfo = repository.findSupervisedTrainByGroup(groupNumber);
if (trainInfo == null) {
repository.deleteOnlineTrain(groupNumber);
}
}
@Override
public void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) {
ThailandTrainConfig config = (ThailandTrainConfig) 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 updateTrainSpeed(Simulation simulation, VirtualRealityTrain train,
ThailandTrainConfig config) {
//更新速度
if (config.getManualGear() != null) {
return;
}
if (train.getFk() > train.getFb()) {
train.setSpeed(10 / 3.6f);
} else if (train.getFb() > train.getFk()) {
train.setSpeed(0);
}
}
private byte[] buildData(VirtualRealityTrain train, ThailandTrainConfig 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()) { //档位1-5是正向6-10是反向
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;
}
/**
* 此方法用于调试调试完成后方法内的数据请保存到项目设备配置{@link club.joylink.rtss.services.project.DeviceServiceImpl#thailandFillTime(ThailandSectionConfigVO, MapSectionNewVO)}
*/
public void fill(Section section, ThailandSectionConfigVO configVO) {
Float headDelayTime = null;
Float tailDelayTime = null;
if (section.isStandTrack()) { //站台轨默认为车尾出清立即停车
headDelayTime = 5f;
}
switch (section.getCode()) {
case "T233": //X302G
headDelayTime = 7f;
break;
case "T232": //X303G
headDelayTime = 7f;
break;
case "T231": //X304G
headDelayTime = 5.5f;
break;
case "T175": //4站-IIG
headDelayTime = 5.5f;
break;
case "T121": //4站-IIG
headDelayTime = 5.2f;
break;
case "T77": //4站-IIG
headDelayTime = 6f;
break;
case "T145": //QX04
tailDelayTime = 0f;
break;
case "T146": //QS04
tailDelayTime = 0f;
break;
case "T104": //QX03
tailDelayTime = 0f;
break;
case "T105": //QS03
tailDelayTime = 0f;
break;
case "T62": //QX02
tailDelayTime = 0f;
break;
case "T63": //QS02
tailDelayTime = 0f;
break;
}
configVO.setHeadDelayTime(headDelayTime);
configVO.setTailDelayTime(tailDelayTime);
}
public void controlTrain(String simulationId, String groupNumber, boolean right, int speed) {
Simulation simulation = groupSimulationService.getSimulationByGroup(simulationId);
VirtualRealityTrain train = simulation.getRepository().getOnlineTrainBy(groupNumber);
ThailandTrainConfig config = (ThailandTrainConfig) 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);
train.getRobotDriveParam().stopControl();
byte[] data = buildData(train, config);
UDPLowConfig udpLowConfig = (UDPLowConfig) simulation.queryOneRealDevice(
ProjectDeviceType.UDP_LOW);
udpClient.write(udpLowConfig.getAddr(), data);
}
}

View File

@ -9,14 +9,18 @@ import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationException;
import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.*;
/** /**
* 目标速度-距离曲线 * 目标速度-距离曲线
*/ */
@ -315,75 +319,6 @@ public class SpeedCurve {
return speedCurve; return speedCurve;
} }
// public static SpeedCurve buildTargetSpeedCurve(SectionPosition headPosition,
// SectionPosition tailPosition, boolean right,
// float totalLen, float v0, float recommendedSpeedMax) {
// if (totalLen <= 0) {
// return SpeedCurve.ZERO;
// }
// Section base = tailPosition.getSection();
// Section headSection = headPosition.getSection();
// float limitSpeed = recommendedSpeedMax;
// boolean limit = false;
// if (Objects.nonNull(tailPosition.getSection().getNeedLimitSpeed())) {
// limitSpeed = Math.min(limitSpeed, tailPosition.getSection().getNeedLimitSpeed() * 0.9f);
// limit = true;
// } else if (Objects.nonNull(headPosition.getSection().getNeedLimitSpeed())) {
// limitSpeed = Math.min(limitSpeed, headPosition.getSection().getNeedLimitSpeed() * 0.9f);
// limit = true;
// }
// SectionPosition endPosition = null;
// boolean ahead = false;
// float vt = 0;
// int count = 0;
// if (!limit) {
// // 无限速找前方限速
// while (Objects.nonNull(base) && count < 20) {
// ++count;
// Float limitSpeed1 = base.getNeedLimitSpeed();
// if (limitSpeed1 == null && !CollectionUtils.isEmpty(base.getLogicList())) { //兼容逻辑区段设置限速
// float distanceBetweenLogicAndPhysical = 0; //逻辑区段距物理区段端点的距离同向端点
// for (Section section : base.getLogicList()) {
// limitSpeed1 = section.getNeedLimitSpeed();
// if (limitSpeed1 != null) {
// float offsetOfLogicSectionOnPhysicalSection = distanceBetweenLogicAndPhysical + (right ? section.getLen() : 0); //逻辑区段的端点在物理区段上的偏移量
// SectionPosition logicSectionPosition = new SectionPosition(base, offsetOfLogicSectionOnPhysicalSection);
// if (logicSectionPosition.isAheadOf(tailPosition, right)) {
// break;
// }
// }
// distanceBetweenLogicAndPhysical += section.getLen();
// }
// }
// if (Objects.nonNull(limitSpeed1)) {
// if (ahead) {
// // 车头前方
// vt = Math.min(limitSpeed, limitSpeed1 * 0.9f);
// endPosition = new SectionPosition(base, right ? 0 : base.getLen());
// break;
// } else {
// limitSpeed = Math.min(limitSpeed, limitSpeed1 * 0.9f);
// }
// }
// if (Objects.equals(base, headSection)) {
// ahead = true;
// }
// base = base.getNextRunningSectionOf(right);
// }
// }
// SpeedCurve normalSpeedCurve = buildTargetSpeedCurve(totalLen, v0, 0, limitSpeed);
// if (endPosition != null) {
// Float distance = CalculateService.calculateDistance(headPosition, endPosition, right);
// if (distance != null && distance < totalLen) {
// SpeedCurve limitSpeedCurve = buildTargetSpeedCurve(distance, v0, vt, limitSpeed);
// float normalStartSpeed = normalSpeedCurve.getSpeedOf(normalSpeedCurve.getTotalDistance());
// float limitStartSpeed = limitSpeedCurve.getSpeedOf(limitSpeedCurve.getTotalDistance());
// return normalStartSpeed < limitStartSpeed ? normalSpeedCurve : limitSpeedCurve;
// }
// }
// return normalSpeedCurve;
// }
/** /**
* 构建目标速度曲线 * 构建目标速度曲线
* *

View File

@ -1,9 +1,12 @@
package club.joylink.rtss.simulation.cbtc.work; package club.joylink.rtss.simulation.cbtc.work;
import club.joylink.rtss.constants.ProjectDeviceType;
import club.joylink.rtss.entity.Ibp; import club.joylink.rtss.entity.Ibp;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.*; import club.joylink.rtss.services.ICommandService;
import club.joylink.rtss.services.ILoadPlanService;
import club.joylink.rtss.services.IMapService;
import club.joylink.rtss.services.IRunPlanTemplateService;
import club.joylink.rtss.services.IVirtualRealityIbpService;
import club.joylink.rtss.services.iscs.IscsDeviceService; import club.joylink.rtss.services.iscs.IscsDeviceService;
import club.joylink.rtss.services.iscs.IscsSystemResourcesService; import club.joylink.rtss.services.iscs.IscsSystemResourcesService;
import club.joylink.rtss.services.project.DeviceService; import club.joylink.rtss.services.project.DeviceService;
@ -15,12 +18,16 @@ import club.joylink.rtss.services.simulation.SchedulingService;
import club.joylink.rtss.services.training.ITrainingV1Service; import club.joylink.rtss.services.training.ITrainingV1Service;
import club.joylink.rtss.simulation.cbtc.ATS.ATSLogicLoop; import club.joylink.rtss.simulation.cbtc.ATS.ATSLogicLoop;
import club.joylink.rtss.simulation.cbtc.ATS.ATSMessageCollectAndDispatcher; import club.joylink.rtss.simulation.cbtc.ATS.ATSMessageCollectAndDispatcher;
import club.joylink.rtss.simulation.cbtc.ATS.service.alarm.NccAlarmService;
import club.joylink.rtss.simulation.cbtc.ATS.ATSTrainMessageDiagram; import club.joylink.rtss.simulation.cbtc.ATS.ATSTrainMessageDiagram;
import club.joylink.rtss.simulation.cbtc.ATS.service.alarm.NccAlarmService;
import club.joylink.rtss.simulation.cbtc.CI.CiLogic; import club.joylink.rtss.simulation.cbtc.CI.CiLogic;
import club.joylink.rtss.simulation.cbtc.*; import club.joylink.rtss.simulation.cbtc.DeviceStatusService;
import club.joylink.rtss.simulation.cbtc.GroupSimulationService;
import club.joylink.rtss.simulation.cbtc.ISCS.IscsLogicLoop; import club.joylink.rtss.simulation.cbtc.ISCS.IscsLogicLoop;
import club.joylink.rtss.simulation.cbtc.ISCS.IscsMessageCollectAndDispatcher; import club.joylink.rtss.simulation.cbtc.ISCS.IscsMessageCollectAndDispatcher;
import club.joylink.rtss.simulation.cbtc.PowerSupplyService;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.SimulationLifeCycleService;
import club.joylink.rtss.simulation.cbtc.build.SimulationBuildParams; import club.joylink.rtss.simulation.cbtc.build.SimulationBuildParams;
import club.joylink.rtss.simulation.cbtc.build.SimulationBuilder; import club.joylink.rtss.simulation.cbtc.build.SimulationBuilder;
import club.joylink.rtss.simulation.cbtc.build.UserConfigDataBuilder; import club.joylink.rtss.simulation.cbtc.build.UserConfigDataBuilder;
@ -28,7 +35,6 @@ import club.joylink.rtss.simulation.cbtc.communication.Joylink3DMessageService;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
import club.joylink.rtss.simulation.cbtc.depot.DepotService; import club.joylink.rtss.simulation.cbtc.depot.DepotService;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.SimulationRealDeviceThread; 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.udp.UDPRealDeviceThread; import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceThread;
import club.joylink.rtss.simulation.cbtc.device.virtual.VRDeviceLogicLoop; import club.joylink.rtss.simulation.cbtc.device.virtual.VRDeviceLogicLoop;
import club.joylink.rtss.simulation.cbtc.device.virtual.VRTrainRunningService; import club.joylink.rtss.simulation.cbtc.device.virtual.VRTrainRunningService;
@ -48,7 +54,6 @@ import club.joylink.rtss.vo.client.CommandDefinitionVO;
import club.joylink.rtss.vo.client.iscs.device.IscsDeviceVO; import club.joylink.rtss.vo.client.iscs.device.IscsDeviceVO;
import club.joylink.rtss.vo.client.iscs.systemRes.IscsSystemResourcesQueryVO; import club.joylink.rtss.vo.client.iscs.systemRes.IscsSystemResourcesQueryVO;
import club.joylink.rtss.vo.client.iscs.systemRes.IscsSystemResourcesVO; import club.joylink.rtss.vo.client.iscs.systemRes.IscsSystemResourcesVO;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.client.runplan.RunPlanLoadVO; import club.joylink.rtss.vo.client.runplan.RunPlanLoadVO;
import club.joylink.rtss.vo.client.runplan.RunPlanVO; import club.joylink.rtss.vo.client.runplan.RunPlanVO;
import club.joylink.rtss.vo.client.runplan.user.RunPlanParkingTimeVO; import club.joylink.rtss.vo.client.runplan.user.RunPlanParkingTimeVO;
@ -56,18 +61,16 @@ import club.joylink.rtss.vo.client.runplan.user.RunPlanRunlevelVO;
import club.joylink.rtss.vo.client.schedulingNew.SchedulingPlanNewVO; import club.joylink.rtss.vo.client.schedulingNew.SchedulingPlanNewVO;
import club.joylink.rtss.vo.client.simulationv1.RunAsPlanParam; import club.joylink.rtss.vo.client.simulationv1.RunAsPlanParam;
import club.joylink.rtss.vo.map.MapVO; import club.joylink.rtss.vo.map.MapVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@Slf4j @Slf4j
@Service @Service
@ -190,12 +193,7 @@ public class MetroSimulationWorkServiceImpl implements SimulationWorkService {
simulationWorkServiceManager.buildMember(simulation); simulationWorkServiceManager.buildMember(simulation);
// 添加项目设备 // 添加项目设备
if (buildParams.getWorkParamVO().containsRealDeviceItem()) { if (buildParams.getWorkParamVO().containsRealDeviceItem()) {
List<ProjectDeviceVO> projectDeviceList = this.deviceService simulationWorkServiceManager.loadRealDevices(simulation);
.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);
} }
} }
@ -491,29 +489,4 @@ public class MetroSimulationWorkServiceImpl implements SimulationWorkService {
} }
}); });
} }
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);
}
}
} }

View File

@ -33,17 +33,16 @@ import club.joylink.rtss.vo.map.MapGraphDataNewVO;
import club.joylink.rtss.vo.map.MapLogicDataNewVO; import club.joylink.rtss.vo.map.MapLogicDataNewVO;
import club.joylink.rtss.vo.map.MapVO; import club.joylink.rtss.vo.map.MapVO;
import club.joylink.rtss.websocket.StompMessageService; import club.joylink.rtss.websocket.StompMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
@Slf4j @Slf4j
@Service @Service
@ -101,16 +100,20 @@ public class RailwaySimulationWorkServiceImpl implements SimulationWorkService {
@Override @Override
public void loadData(Simulation simulation) { public void loadData(Simulation simulation) {
SimulationBuildParams params = simulation.getBuildParams(); SimulationBuildParams buildParams = simulation.getBuildParams();
// 加载地图数据 // 加载地图数据
loadMapData(simulation); loadMapData(simulation);
// // 车辆段 // // 车辆段
// depotService.loadDepotTrain(simulation); // depotService.loadDepotTrain(simulation);
// 添加仿真用户 // 添加仿真用户
SimulationUser creator = SimulationUser.buildCreator(simulation, params.getLoginUserInfo()); SimulationUser creator = SimulationUser.buildCreator(simulation, buildParams.getLoginUserInfo());
simulation.addSimulationUser(creator); simulation.addSimulationUser(creator);
// 添加仿真成员 // 添加仿真成员
simulationWorkServiceManager.buildMember(simulation); simulationWorkServiceManager.buildMember(simulation);
// 添加项目设备
if (buildParams.getWorkParamVO().containsRealDeviceItem()) {
simulationWorkServiceManager.loadRealDevices(simulation);
}
} }
@Override @Override

View File

@ -1,13 +1,26 @@
package club.joylink.rtss.simulation.cbtc.work; package club.joylink.rtss.simulation.cbtc.work;
import club.joylink.rtss.constants.ProjectDeviceType;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.services.project.DeviceService;
import club.joylink.rtss.simulation.cbtc.GroupSimulationService;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.build.SimulationBuildParams;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.MapElement; 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.udp.UDPRealDeviceThread;
import club.joylink.rtss.simulation.cbtc.event.SimulationUserEnterEvent; import club.joylink.rtss.simulation.cbtc.event.SimulationUserEnterEvent;
import club.joylink.rtss.simulation.cbtc.member.MemberManager; import club.joylink.rtss.simulation.cbtc.member.MemberManager;
import club.joylink.rtss.simulation.cbtc.member.SimulationUser; import club.joylink.rtss.simulation.cbtc.member.SimulationUser;
import club.joylink.rtss.vo.client.project.ProjectDeviceVO;
import club.joylink.rtss.vo.map.graph.MapMemberVO; import club.joylink.rtss.vo.map.graph.MapMemberVO;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Collectors;
import lombok.NonNull; import lombok.NonNull;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
@ -18,11 +31,11 @@ import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import java.util.List; /**
import java.util.Map; * 仿真工作服务管理
import java.util.function.Function; * 1.管理仿真工作服务的实现类
import java.util.stream.Collectors; * 2.各种仿真的公共方法
*/
@Slf4j @Slf4j
@Component @Component
public class SimulationWorkServiceManager implements ApplicationContextAware { public class SimulationWorkServiceManager implements ApplicationContextAware {
@ -30,6 +43,14 @@ public class SimulationWorkServiceManager implements ApplicationContextAware {
private MemberManager memberManager; private MemberManager memberManager;
@Autowired @Autowired
private ApplicationContext applicationContext; 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; private Map<Simulation.Type, SimulationWorkService> map;
@ -95,4 +116,39 @@ public class SimulationWorkServiceManager implements ApplicationContextAware {
SimulationUserEnterEvent userEnterEvent = new SimulationUserEnterEvent(this, simulation, simulationUser); SimulationUserEnterEvent userEnterEvent = new SimulationUserEnterEvent(this, simulation, simulationUser);
this.applicationContext.publishEvent(userEnterEvent); 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);
}
}
} }

View File

@ -16,107 +16,127 @@ import lombok.Setter;
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
public class DriveParamVO { public class DriveParamVO {
/**
* 限速值km/h
*/
private Float speedLimit;
/** /**
* 限速值m/s * 限速值km/h
*/ */
@JsonIgnore private Float speedLimit;
@Setter(value = AccessLevel.NONE)
private float speedLimitInMs = Float.MAX_VALUE;
/** /**
* 下令停车优先级比运行高 * 限速值m/s
*/ */
@JsonIgnore @JsonIgnore
private boolean stop; @Setter(value = AccessLevel.NONE)
private float speedLimitInMs = Float.MAX_VALUE;
/** /**
* 下令驾驶 * 下令停车优先级比运行高
*/ */
@JsonIgnore @JsonIgnore
private boolean run = true; private boolean stop;
/** /**
* 目标设备code用于确定目标位置 * 下令驾驶
*/ */
private String targetDeviceCode; @JsonIgnore
private boolean run = true;
/** /**
* 根据目标设备code计算出的目标位置 * 目标设备code用于确定目标位置
*/ */
@JsonIgnore private String targetDeviceCode;
private SectionPosition targetPosition;
/** /**
* 越过信号机 * 根据目标设备code计算出的目标位置
*/ */
private int through; @JsonIgnore
private SectionPosition targetPosition;
public static final int NO = 0; /**
public static final int RED_SIGNAL = 1; * 越过信号机
public static final int GUIDE_SIGNAL = 2; */
public static final int DRIVER_NEXT_STAND = 3; private int through;
public static final int DRIVER_ROUTE_BLOCK = 4;
/** /**
* 要越过的信号机 * 这个停车位置是机器人驾驶逻辑计算出来的这个字段仅供泰国沙盘的列车逻辑使用
*/ */
@JsonIgnore @JsonIgnore
private Signal throughSignal; private SectionPosition stopPosition;
/** public static final int NO = 0;
* 要越过的信号 public static final int RED_SIGNAL = 1;
*/ public static final int GUIDE_SIGNAL = 2;
@JsonIgnore public static final int DRIVER_NEXT_STAND = 3;
private SignalAspect throughSignalAspect; public static final int DRIVER_ROUTE_BLOCK = 4;
/**
* 解除EB目的是在且仅在每次进行驾驶操作后自动缓解当时存在的EB
*/
@JsonIgnore
private boolean releaseEB = true;
public void setSpeedLimit(Float speedLimit) { /**
this.speedLimit = speedLimit; * 要越过的信号机
this.speedLimitInMs = speedLimit == null ? Float.MAX_VALUE : speedLimit / 3.6f; */
@JsonIgnore
private Signal throughSignal;
/**
* 要越过的信号
*/
@JsonIgnore
private SignalAspect throughSignalAspect;
/**
* 解除EB目的是在且仅在每次进行驾驶操作后自动缓解当时存在的EB
*/
@JsonIgnore
private boolean releaseEB = true;
public void setSpeedLimit(Float speedLimit) {
this.speedLimit = speedLimit;
this.speedLimitInMs = speedLimit == null ? Float.MAX_VALUE : speedLimit / 3.6f;
}
/**
* 让机器人驾驶逻辑停止控制该列车
*/
public void stopControl() {
stop = false;
run = false;
}
@JsonIgnore
public boolean isStopControl() {
return !stop && !run;
}
public boolean needStop() {
return stop;
}
public boolean needRun() {
return !stop && run;
}
public void setThrough(int v) {
this.through = v;
if (through == NO) {
throughSignal = null;
throughSignalAspect = null;
} }
}
public boolean needStop() { @JsonIgnore
return stop; public boolean isThroughRedSignal() {
} return RED_SIGNAL == through;
}
public boolean needRun() { @JsonIgnore
return !stop && run; public boolean isThroughGuideSignal() {
} return GUIDE_SIGNAL == through;
}
public void setThrough(int v) { @JsonIgnore
this.through = v; public boolean isDriverNextStand() {
if (through == NO) { return DRIVER_NEXT_STAND == through;
throughSignal = null; }
throughSignalAspect = null;
}
}
@JsonIgnore @JsonIgnore
public boolean isThroughRedSignal() { public boolean isRouteBlockDriver() {
return RED_SIGNAL == through; return DRIVER_ROUTE_BLOCK == through;
} }
@JsonIgnore
public boolean isThroughGuideSignal() {
return GUIDE_SIGNAL == through;
}
@JsonIgnore
public boolean isDriverNextStand() {
return DRIVER_NEXT_STAND == through;
}
@JsonIgnore
public boolean isRouteBlockDriver() {
return DRIVER_ROUTE_BLOCK == through;
}
} }

View File

@ -1,5 +1,6 @@
package club.joylink.rtss.vo.client.project; package club.joylink.rtss.vo.client.project;
import club.joylink.rtss.constants.ProjectCode;
import club.joylink.rtss.constants.ProjectDeviceType; import club.joylink.rtss.constants.ProjectDeviceType;
import club.joylink.rtss.entity.ProjectDevice; import club.joylink.rtss.entity.ProjectDevice;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
@ -9,10 +10,18 @@ import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gxsd.GxsdSignalCo
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gxsd.GxsdSwitchConfig; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gxsd.GxsdSwitchConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gzb.GzbSignalConfig; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gzb.GzbSignalConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gzb.GzbSwitchConfig; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.gzb.GzbSwitchConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device.*; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device.Heb1IbpConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device.Heb1PscConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device.Heb1PslConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device.Heb1SignalConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device.Heb1SwitchConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.hhcj.HhcjIbpConfig; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.hhcj.HhcjIbpConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.hhcj.HhcjPsdConfig; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.hhcj.HhcjPsdConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.say.*; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.say.SayIbpConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.say.SayPsdConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.say.SaySectionConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.say.SaySignalConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.say.SaySwitchConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.sdy.SdyPsdConfig; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.sdy.SdyPsdConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.sdy.SdyPslConfig; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.sdy.SdyPslConfig;
import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.xty.XtyPsdConfig; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.xty.XtyPsdConfig;
@ -25,8 +34,17 @@ import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrSectionConf
import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrSignalConfig; import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrSignalConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrSwitchConfig; import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrSwitchConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrTrainConfig; import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrTrainConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.thailand.config.ThailandSectionConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.thailand.config.ThailandSignalConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.thailand.config.ThailandSwitchConfig;
import club.joylink.rtss.simulation.cbtc.device.real.udp.thailand.config.ThailandTrainConfig;
import club.joylink.rtss.util.JsonUtils; import club.joylink.rtss.util.JsonUtils;
import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnore;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import javax.validation.constraints.NotBlank;
import lombok.Getter; import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
@ -34,12 +52,6 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
import javax.validation.constraints.NotBlank;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/** /**
* 项目设备对象 * 项目设备对象
*/ */
@ -104,8 +116,7 @@ public class ProjectDeviceVO {
List<RealDeviceConfig> list = new ArrayList<>(); List<RealDeviceConfig> list = new ArrayList<>();
if (!CollectionUtils.isEmpty(voList)) { if (!CollectionUtils.isEmpty(voList)) {
String project = voList.get(0).getProject(); String project = voList.get(0).getProject();
String projectCode = StringUtils.hasText(project) ? project.toUpperCase() : ""; switch (project) {
switch (projectCode) {
case "XTY": { case "XTY": {
return xtyDeviceConfigConvert(voList); return xtyDeviceConfigConvert(voList);
} }
@ -121,7 +132,7 @@ public class ProjectDeviceVO {
case "RICHOR_JOINT": { case "RICHOR_JOINT": {
return zjdDeviceConfigConvert(voList); return zjdDeviceConfigConvert(voList);
} }
case "SR_SANDBOX": { case ProjectCode.SR_SANDBOX: {
return srSandboxDeviceConfigConvert(voList); return srSandboxDeviceConfigConvert(voList);
} }
case "RICHOR_HHCJ": { case "RICHOR_HHCJ": {
@ -130,6 +141,9 @@ public class ProjectDeviceVO {
case "SAY": { case "SAY": {
return sayDeviceConfigConvert(voList); return sayDeviceConfigConvert(voList);
} }
case ProjectCode.THAILAND_SANDBOX: {
return thailandSandboxDeviceConfigConvert(voList);
}
case "GXSD": { case "GXSD": {
return gxsdDeviceConfigConvert(voList); return gxsdDeviceConfigConvert(voList);
} }
@ -139,6 +153,34 @@ public class ProjectDeviceVO {
return list; return list;
} }
private static List<RealDeviceConfig> thailandSandboxDeviceConfigConvert(
List<ProjectDeviceVO> voList) {
List<RealDeviceConfig> list = new ArrayList<>();
for (ProjectDeviceVO deviceVO : voList) {
switch (deviceVO.getType()) {
case UDP_LOW:
list.add(new UDPLowConfig(deviceVO));
break;
case UDP_CLIENT:
list.add(new UDPClientConfig(deviceVO));
break;
case SIGNAL:
list.add(new ThailandSignalConfig(deviceVO));
break;
case SECTION:
list.add(new ThailandSectionConfig(deviceVO));
break;
case SWITCH:
list.add(new ThailandSwitchConfig(deviceVO));
break;
case TRAIN:
list.add(new ThailandTrainConfig(deviceVO));
break;
}
}
return list;
}
private static List<RealDeviceConfig> gxsdDeviceConfigConvert(List<ProjectDeviceVO> voList) { private static List<RealDeviceConfig> gxsdDeviceConfigConvert(List<ProjectDeviceVO> voList) {
List<RealDeviceConfig> list = new ArrayList<>(); List<RealDeviceConfig> list = new ArrayList<>();
for (ProjectDeviceVO deviceVO : voList) { for (ProjectDeviceVO deviceVO : voList) {

View File

@ -12,6 +12,12 @@ import lombok.Setter;
@Setter @Setter
@NoArgsConstructor @NoArgsConstructor
public class UDPLowConfigVO { public class UDPLowConfigVO {
/**
* 名称
* 泰国沙盘下位机有两个接收数据的端口一个用于接收信号机控制指令一个用于接收道岔和区段控制指令
*/
private String name;
private String ip; private String ip;
private Integer port; private Integer port;
@ -21,6 +27,11 @@ public class UDPLowConfigVO {
this.port = port; this.port = port;
} }
public UDPLowConfigVO(String name, String ip, Integer port) {
this(ip, port);
this.name = name;
}
public String toJson() { public String toJson() {
return JsonUtils.writeValueAsString(this); return JsonUtils.writeValueAsString(this);
} }

View File

@ -0,0 +1,38 @@
package club.joylink.rtss.vo.client.project.thailand;
import club.joylink.rtss.vo.client.project.RealConfigVO;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ThailandSectionConfigVO extends RealConfigVO {
private String vrCode;
private String sandboxCode;
/**
* 车头到达区段延迟停车时间/s
*/
private Float headDelayTime;
/**
* 车尾解除占用延迟停车时间/s
*/
private Float tailDelayTime;
public ThailandSectionConfigVO() {
super(null, null);
}
public ThailandSectionConfigVO(String vrCode, String sandboxCode) {
this();
this.vrCode = vrCode;
this.sandboxCode = sandboxCode;
}
@Override
public String findDeviceCode() {
return vrCode;
}
}

View File

@ -0,0 +1,28 @@
package club.joylink.rtss.vo.client.project.thailand;
import club.joylink.rtss.vo.client.project.RealConfigVO;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ThailandSignalConfigVO extends RealConfigVO {
private String vrCode;
private String sandboxCode;
public ThailandSignalConfigVO() {
super(null, null);
}
public ThailandSignalConfigVO(String vrCode, String sandboxCode) {
this();
this.vrCode = vrCode;
this.sandboxCode = sandboxCode;
}
@Override
public String findDeviceCode() {
return vrCode;
}
}

View File

@ -0,0 +1,28 @@
package club.joylink.rtss.vo.client.project.thailand;
import club.joylink.rtss.vo.client.project.RealConfigVO;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ThailandSwitchConfigVO extends RealConfigVO {
private String vrCode;
private String sandboxCode;
public ThailandSwitchConfigVO() {
super(null, null);
}
public ThailandSwitchConfigVO(String vrCode, String sandboxCode) {
this();
this.vrCode = vrCode;
this.sandboxCode = sandboxCode;
}
@Override
public String findDeviceCode() {
return vrCode;
}
}

View File

@ -0,0 +1,28 @@
package club.joylink.rtss.vo.client.project.thailand;
import club.joylink.rtss.vo.client.project.RealConfigVO;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
public class ThailandTrainConfigVO extends RealConfigVO {
private String vrCode;
private String sandboxCode;
public ThailandTrainConfigVO() {
super(null, null);
}
public ThailandTrainConfigVO(String vrCode, String sandboxCode) {
this();
this.vrCode = vrCode;
this.sandboxCode = sandboxCode;
}
@Override
public String findDeviceCode() {
return vrCode;
}
}

View File

@ -215,7 +215,7 @@ common:
spring: spring:
profiles: local profiles: local
datasource: datasource:
url: jdbc:mysql://192.168.1.254:3306/joylink?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true url: jdbc:mysql://192.168.53.12:3306/joylink?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true
username: root username: root
password: localdb password: localdb