From c2dbbbb715b4ee311272ea791d69a2a70e0ee031 Mon Sep 17 00:00:00 2001 From: tiger_zhou <123456> Date: Wed, 19 Oct 2022 13:25:25 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E6=80=A5=E7=B3=BB=E7=BB=9F=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E9=80=9F=E5=BA=A6=E5=8F=8A=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ATS/ATSMessageCollectAndDispatcher.java | 14 +- .../ATS/service/NewAtsTrainLoadService.java | 29 ++-- .../ATS/service/TrainPositionService.java | 107 +------------- .../service/TrainPositionTimeOverService.java | 131 ++++++++++++++++++ .../cbtc/SimulationLifeCycleServiceImpl.java | 5 + .../cbtc/constant/SimulationConstants.java | 1 + .../cbtc/constant/SimulationModule.java | 1 + .../cbtc/data/status/YJDDZHTrainStatus.java | 49 +++++++ .../simulation/cbtc/data/vo/TrainInfo.java | 21 ++- .../cbtc/data/vo/YJDDZHTrainStatusVO.java | 43 ++++++ .../cbtc/data/vr/VirtualRealityTrain.java | 14 +- .../message/SimulationSubscribeTopic.java | 2 +- .../client/factory/SocketMessageFactory.java | 2 +- .../joylink/rtss/vo/ws/TrainPosition.java | 11 ++ .../rtss/websocket/WebSocketController.java | 2 - .../websocket/client/StompClientManager.java | 1 + src/main/resources/application.yml | 13 +- 17 files changed, 316 insertions(+), 130 deletions(-) create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionTimeOverService.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/data/status/YJDDZHTrainStatus.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/YJDDZHTrainStatusVO.java diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSMessageCollectAndDispatcher.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSMessageCollectAndDispatcher.java index be795e831..93a023e52 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSMessageCollectAndDispatcher.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/ATSMessageCollectAndDispatcher.java @@ -1,5 +1,6 @@ package club.joylink.rtss.simulation.cbtc.ATS; +import club.joylink.rtss.constants.MapPrdTypeEnum; import club.joylink.rtss.simulation.cbtc.CI.data.StationDirection; import club.joylink.rtss.simulation.cbtc.CI.data.vo.StationDirectionStatusVO; import club.joylink.rtss.simulation.cbtc.CI.status.StationDirectionStatus; @@ -100,11 +101,20 @@ public class ATSMessageCollectAndDispatcher { trainList.forEach(train -> { TrainStatus trainStatus = repository.findStatusByCode(train.getGroupNumber(), TrainStatus.class); if (Objects.isNull(trainStatus)) { - trainStatus = new TrainStatus(train); + if(simulation.getBuildParams().getProdType() == MapPrdTypeEnum.YJDDZH){ + trainStatus = new YJDDZHTrainStatus(train); + }else{ + trainStatus = new TrainStatus(train); + } repository.addDeviceInfo(trainStatus); totalList.add(trainStatus.convert2VO(train)); } else { - DeviceStatusVO statusVO = new TrainStatusVO(train); + DeviceStatusVO statusVO; + if(simulation.getBuildParams().getProdType() == MapPrdTypeEnum.YJDDZH){ + statusVO = new YJDDZHTrainStatusVO(train); + }else{ + statusVO = new TrainStatusVO(train); + } if (trainStatus.compareAndChange(train, statusVO)) { totalList.add(statusVO); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/NewAtsTrainLoadService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/NewAtsTrainLoadService.java index 2fad58b54..656a42ac7 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/NewAtsTrainLoadService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/NewAtsTrainLoadService.java @@ -6,7 +6,6 @@ import club.joylink.rtss.simulation.cbtc.constant.RunLevel; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.map.MapConfig; import club.joylink.rtss.simulation.cbtc.data.map.Section; -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.support.SectionPosition; import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; @@ -15,7 +14,6 @@ import club.joylink.rtss.vo.ws.TrainPosition; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; -import java.util.List; import java.util.Map; import java.util.Objects; import java.util.function.Function; @@ -36,6 +34,7 @@ public class NewAtsTrainLoadService { stands = station.getRdStandList(); }*/ VirtualRealityTrain.Door door = train.getDoor1(); + train.setSpeed(tp.getSpeed()); if(tp.isRight()){ door = train.getDoor2(); } @@ -55,14 +54,16 @@ public class NewAtsTrainLoadService { door.setClose(tp.isCloseDoor()); train.setSpeed(99F); } - } - public void loadTripNumberTrain(Simulation simulation, TrainPosition tp,Section section) { + + + + public VirtualRealityTrain loadTripNumberTrain(Simulation simulation, TrainPosition tp,Section section) { SimulationDataRepository repository = simulation.getRepository(); Map trainMap = repository.getAllVrTrain().stream().collect(Collectors.toMap(VirtualRealityTrain::getGroupNumber,Function.identity())); if(Objects.equals(false,trainMap.containsKey(tp.getGroupNum()))){ log.error("没有找到对应车组号 param:{}",tp); - return; + return null; } VirtualRealityTrain virtualRealityTrain = repository.queryOnlineTrainBy(tp.getGroupNum()); @@ -77,6 +78,7 @@ public class NewAtsTrainLoadService { virtualRealityTrain.setRunLevel(RunLevel.IL); trainOnline(simulation, section, tp, virtualRealityTrain); } + return virtualRealityTrain; } @@ -95,22 +97,16 @@ public class NewAtsTrainLoadService { BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotNull(section.isPhysical(), "列车需加载到物理区段上"); //重叠检测 SectionPosition headPosition = new SectionPosition(section, tp.getLocation() - section.getKmMin()); -// SectionPosition headPosition = new SectionPosition(section, section.getStopPointByDirection(right)); -// SectionPosition tailPosition = CalculateService.calculateNextPositionByStartAndLen(headPosition, !right, train.getLen(), false); -// boolean willOverlap = vrTrainRunningService.willOverlap(simulation, headPosition, tailPosition); -// if(willOverlap){ -// return; -// } -// BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(willOverlap, "列车重叠"); + // 列车上线并构建ATS监控列车信息 - manualTrainOnlineAndSupervise(simulation, train, headPosition, right); + manualTrainOnlineAndSupervise(simulation, train, headPosition, right,tp); } /** * 人工车上线并监控 */ - private void manualTrainOnlineAndSupervise(Simulation simulation, VirtualRealityTrain train, SectionPosition headPosition, boolean right) { - train.initManualTrain(headPosition, right); + private void manualTrainOnlineAndSupervise(Simulation simulation, VirtualRealityTrain train, SectionPosition headPosition, boolean right,TrainPosition tp) { + train.initManualTrain(headPosition, right,tp); SimulationDataRepository repository = simulation.getRepository(); //设置列车预选模式、驾驶模式、运行级别 if (!headPosition.getSection().anyZcWorking()) { @@ -130,4 +126,7 @@ public class NewAtsTrainLoadService { repository.addTrainInfo(trainInfo); } } + + + } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionService.java index e3950898b..1b26f7eba 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionService.java @@ -1,38 +1,24 @@ package club.joylink.rtss.simulation.cbtc.ATS.service; -import club.joylink.rtss.constants.MapPrdTypeEnum; -import club.joylink.rtss.simulation.SimulationManager; -import club.joylink.rtss.simulation.cbtc.Simulation; -import club.joylink.rtss.simulation.cbtc.build.SimulationBuildParams; -import club.joylink.rtss.simulation.cbtc.data.map.Section; -import club.joylink.rtss.simulation.cbtc.data.map.Station; import club.joylink.rtss.util.JsonUtils; import club.joylink.rtss.vo.client.SocketMessageVO; import club.joylink.rtss.vo.client.WebSocketMessageType; import club.joylink.rtss.vo.client.factory.SocketMessageFactory; import club.joylink.rtss.vo.ws.TrainPosition; import club.joylink.rtss.websocket.StompMessageService; -import com.google.common.cache.Cache; -import com.google.common.cache.CacheBuilder; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; -import org.springframework.util.CollectionUtils; import javax.annotation.Resource; -import java.util.*; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; @Service @Slf4j public class TrainPositionService { + + @Resource - private NewAtsTrainLoadService newAtsTrainLoadService; - @Resource - private SimulationManager simulationManager; - @Resource - StompMessageService messageService; + TrainPositionTimeOverService timeOverService; /** @@ -44,91 +30,10 @@ public class TrainPositionService { public void initTrainOrUpdate(String mapName,String json){ TrainPosition tp = JsonUtils.read(json, TrainPosition.class); tp.setReceiveTime(System.currentTimeMillis()); -// log.info(tp.toString()); - List simulationList = this.findSimulationList(mapName); - if(Objects.equals(true, CollectionUtils.isEmpty(simulationList))){ - log.error("未找到对应的类型的仿真,无法渲染列车位置 param:{}",json); - return; - } -// boolean d = true; - SocketMessageVO vo = SocketMessageFactory.buildBasic(WebSocketMessageType.YJDDZH_TRAIN_POSITION,tp); - this.messageService.send(vo); +// SocketMessageVO vo = SocketMessageFactory.buildBasic(WebSocketMessageType.YJDDZH_TRAIN_POSITION,tp); +// this.messageService.send(vo); + this.timeOverService.addTrainAccept(mapName,tp); - for (Simulation sim : simulationList) { - List
sectionList = findDirectionAllSection(sim,tp.getRoadType()); - Section section = this.findSecion(sectionList,tp); -// if(d){ -// tp.setSectionCode(section.getCode()); -// log.info(tp.toString()); -// d = false; -// } - if(Objects.isNull(section)){ - log.error("未找到对应的区段 param:{}",json); - return; - } - log.info(tp.toString()); - this.newAtsTrainLoadService.loadTripNumberTrain(sim,tp,section); - } } - - /** - * 根据传入的参数 定位对应的所在的区段 - * @param sectionList - * @param tp - * @return - */ - private Section findSecion(List
sectionList,TrainPosition tp){ -// int i = 0; -// Section findSection; - for (Section section : sectionList) { - if(tp.isRight()){ - if(tp.getLocation() <= section.getKmMax()){ - return section; - } - }else{ - if(tp.getLocation() <= section.getKmMax() && tp.getLocation() >= section.getKmMin()){ - return section; - } - } -// i++; - } - return null; - } - - - /** - * 根据车辆方向获取对应的区段并升序排序 - * @param sim - * @param roadType - * @return - */ - private synchronized List
findDirectionAllSection(Simulation sim,Section.SectionRoadType roadType){ - String key = sim.getId() + "-" + roadType.name(); - List
list = simulationManager.getSectionDir(key); - if(Objects.equals(true,CollectionUtils.isEmpty(list))){ - list = sim.getRepository().getSectionList(); - - list = list.stream().filter(d->d.getRoadType() == roadType && Objects.nonNull(d.getKmMin())) - .sorted(Comparator.comparing(Section::getKmMin)).collect(Collectors.toList()); - simulationManager.putSectionDirCache(key,list); - } - return list; - } - - /** - * 获取对应线路的仿真,并且地图类型为 MapPrdTypeEnum.YJDDZH - * @param mapName - * @return - */ - private List findSimulationList(String mapName){ - return this.simulationManager.getSimulationList().stream().filter(d->{ - if(d instanceof Simulation){ - Simulation sim = (Simulation) d; - SimulationBuildParams params = sim.getBuildParams(); - return Objects.equals(mapName,params.getMap().getName()) && params.getProdType() == MapPrdTypeEnum.YJDDZH; - } - return false; - }).map(d->(Simulation) d).collect(Collectors.toList()); - } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionTimeOverService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionTimeOverService.java new file mode 100644 index 000000000..032684ff2 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/TrainPositionTimeOverService.java @@ -0,0 +1,131 @@ +package club.joylink.rtss.simulation.cbtc.ATS.service; + + +import club.joylink.rtss.simulation.SimulationManager; +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; +import club.joylink.rtss.simulation.cbtc.constant.SimulationModule; +import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; +import club.joylink.rtss.simulation.cbtc.data.map.Section; +import club.joylink.rtss.simulation.cbtc.data.status.TrainStatus; +import club.joylink.rtss.vo.ws.TrainPosition; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; + +import javax.annotation.Resource; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; + +@Service +@Slf4j +public class TrainPositionTimeOverService { + @Resource + private SimulationManager simulationManager; + @Resource + NewAtsTrainLoadService newAtsTrainLoadService; + @Value("${yjddzh.receiveTimeOver:60}") + private Integer receiveTimeOver; + + private static final Map TRAIN_POSITION_MAP = new ConcurrentHashMap<>(); + private static final Map> TRAIN_SIMULATION_EXIST_MAP = new ConcurrentHashMap<>(); + private static synchronized boolean checkExist(String key,Simulation simulation){ + List list = TRAIN_SIMULATION_EXIST_MAP.get(key); + if(CollectionUtils.isEmpty(list)){ + list = new ArrayList<>(); + list.add(simulation.getId()); + TRAIN_SIMULATION_EXIST_MAP.put(key,list); + return true; + }else if(list.contains(simulation.getId())){ + return false; + }else{ + list.add(simulation.getId()); + return true; + } + } + public void addTrainAccept(String mapName ,TrainPosition train){ + String key = String.format("%s,%s",mapName,train.getGroupNum()); + + TRAIN_POSITION_MAP.put(key,train); + TRAIN_SIMULATION_EXIST_MAP.remove(key); + } + + /** + * 根据车辆方向获取对应的区段并升序排序 + * @param sim + * @param roadType + * @return + */ + private synchronized List
findDirectionAllSection(Simulation sim, Section.SectionRoadType roadType){ + String key = sim.getId() + "-" + roadType.name(); + List
list = simulationManager.getSectionDir(key); + if(Objects.equals(true, CollectionUtils.isEmpty(list))){ + list = sim.getRepository().getSectionList(); + + list = list.stream().filter(d->d.getRoadType() == roadType && Objects.nonNull(d.getKmMin())) + .sorted(Comparator.comparing(Section::getKmMin)).collect(Collectors.toList()); + simulationManager.putSectionDirCache(key,list); + } + return list; + } + /** + * 根据传入的参数 定位对应的所在的区段 + * @param sectionList + * @param tp + * @return + */ + private Section findSecion(List
sectionList,TrainPosition tp){ + for (Section section : sectionList) { + if(tp.isRight()){ + if(tp.getLocation() <= section.getKmMax()){ + return section; + } + }else{ + if(tp.getLocation() <= section.getKmMax() && tp.getLocation() >= section.getKmMin()){ + return section; + } + } + } + return null; + } + + private void trainInitOrUpdate(Simulation simulation){ + String mapName = simulation.getBuildParams().getMap().getName(); + + for (Map.Entry entry: TRAIN_POSITION_MAP.entrySet()) { + String key = entry.getKey(); + TrainPosition tp = entry.getValue(); + if(!StringUtils.startsWithIgnoreCase(key,mapName)){ + continue; + } + if(tp.receiveTimeOver(this.receiveTimeOver)){ + if(checkExist(key,simulation)){ + SimulationDataRepository repository = simulation.getRepository(); + TrainStatus ts = new TrainStatus(tp.getGroupNum()); + ts.setGroupNumber(tp.getGroupNum()); + repository.addDeviceInfo(ts); + repository.deleteSuperviseTrain(tp.getGroupNum()); + repository.deleteOnlineTrain(tp.getGroupNum()); + } + continue; + } + + List
sectionList = findDirectionAllSection(simulation,tp.getRoadType()); + Section section = this.findSecion(sectionList,tp); + if(Objects.isNull(section)){ + log.error("未找到对应的区段 param:{}",tp); + continue; + } + log.info(tp.toString()); + this.newAtsTrainLoadService.loadTripNumberTrain(simulation,tp,section); + } + } + + public void run(Simulation simulation){ + simulation.addJob(SimulationModule.YJDDZH.name(), () -> trainInitOrUpdate(simulation), SimulationConstants.YJDDZH_LOGIC_LOOP_RATE); + } + +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java index 482ef9aae..af5ac6aab 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/SimulationLifeCycleServiceImpl.java @@ -12,6 +12,7 @@ import club.joylink.rtss.services.publishData.IbpService; import club.joylink.rtss.simulation.SimulationManager; import club.joylink.rtss.simulation.cbtc.ATS.ATSLogicLoop; import club.joylink.rtss.simulation.cbtc.ATS.ATSMessageCollectAndDispatcher; +import club.joylink.rtss.simulation.cbtc.ATS.service.TrainPositionTimeOverService; import club.joylink.rtss.simulation.cbtc.CI.CiLogic; import club.joylink.rtss.simulation.cbtc.CTC.CTCLogicLoop; import club.joylink.rtss.simulation.cbtc.ISCS.IscsLogicLoop; @@ -49,6 +50,7 @@ import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import javax.annotation.Resource; import java.util.List; import java.util.Objects; @@ -143,6 +145,8 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic @Autowired private PisLogicLoop pisLogicLoop; + @Resource + TrainPositionTimeOverService timeOverService; @Override public Simulation create(SimulationBuildParams params, String group) { @@ -199,6 +203,7 @@ public class SimulationLifeCycleServiceImpl implements SimulationLifeCycleServic vrDeviceLogicLoop.addJobsForTrainPosition(simulation); // ciLogic.addJobs(simulation); ciLogic.addJobsForTrainPosition(simulation); + timeOverService.run(simulation); return; } if (simulation.getRepository().getConfig().isRailway()) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationConstants.java b/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationConstants.java index c7d5a4a77..3e9e273fc 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationConstants.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationConstants.java @@ -94,6 +94,7 @@ public interface SimulationConstants { /** 机器人逻辑循环间隔 */ int ROBOT_LOGIC_LOOP_RATE = 200; + int YJDDZH_LOGIC_LOOP_RATE = 200; /** * ATO列车收到通行信号到列车发动延迟时间 diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationModule.java b/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationModule.java index fc438e63d..9461a6e18 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationModule.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/constant/SimulationModule.java @@ -59,6 +59,7 @@ public enum SimulationModule { CATENARY(SimulationConstants.POWER_SUPPLY_STATUS_UPDATE_RATE), ROBOT(SimulationConstants.ROBOT_LOGIC_LOOP_RATE), + YJDDZH(SimulationConstants.ROBOT_LOGIC_LOOP_RATE) ; /** 执行频率-单位ms */ diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/status/YJDDZHTrainStatus.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/status/YJDDZHTrainStatus.java new file mode 100644 index 000000000..99764ed89 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/status/YJDDZHTrainStatus.java @@ -0,0 +1,49 @@ +package club.joylink.rtss.simulation.cbtc.data.status; + +import club.joylink.rtss.simulation.cbtc.data.map.MapElement; +import club.joylink.rtss.simulation.cbtc.data.vo.DeviceStatusVO; +import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; +import club.joylink.rtss.simulation.cbtc.data.vo.YJDDZHTrainStatusVO; +import lombok.Getter; +import lombok.Setter; + +import java.util.Objects; + +/** + * 应急列车状态 + */ +@Getter +@Setter +public class YJDDZHTrainStatus extends TrainStatus { + + /** + * 公里标 + */ + private Float locationKM; + + public YJDDZHTrainStatus(TrainInfo train) { + super(train); + this.setSpeed(train.getSpeed()); + this.locationKM = train.getLocationKM(); + + } + + @Override + public DeviceStatusVO convert2VO(MapElement device) { + return new YJDDZHTrainStatusVO(this); + } + + @Override + public boolean compareAndChange(MapElement device, DeviceStatusVO statusVO) { + TrainInfo train = (TrainInfo) device; + YJDDZHTrainStatusVO status = (YJDDZHTrainStatusVO)statusVO; + boolean change = super.compareAndChange(device, statusVO); + if (!Objects.equals(this.locationKM, train.getLocationKM())) { + this.locationKM = train.getLocationKM(); + status.setLocationKM(this.locationKM); + change = true; + } + status.setSpeed(train.getSpeed()); + return change; + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/TrainInfo.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/TrainInfo.java index 394a42f5e..ced7415a8 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/TrainInfo.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/TrainInfo.java @@ -11,6 +11,7 @@ import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan; import club.joylink.rtss.simulation.cbtc.data.storage.vo.StorageTrainInfo; import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; +import club.joylink.rtss.vo.ws.TrainPosition; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; @@ -95,7 +96,7 @@ public class TrainInfo extends MapElement { @Setter private Boolean right; - + @Setter private float speed; private boolean doorOpen; @@ -292,6 +293,12 @@ public class TrainInfo extends MapElement { private boolean beAbout2Arrival; + /** + * 公里标 + */ + @Setter + private Float locationKM; + public TrainInfo(String groupNumber) { super(groupNumber, DeviceType.TRAIN); this.groupNumber = groupNumber; @@ -313,6 +320,13 @@ public class TrainInfo extends MapElement { info.tripNumber = StringUtils.isEmpty(train.getTripNumber()) ? "" : train.getTripNumber(); return info; } +// public static TrainInfo constructManualTrain(VirtualRealityTrain train, TrainPosition tp) { +// TrainInfo info = constructManualTrain(train); +// info.setLocationKM(tp.getLocation()); +// info.setRight(tp.isRight()); +// info.setSpeed(tp.getSpeed()); +// return info; +// } private TrainInfo(VirtualRealityTrain train) { super(train.getGroupNumber(), DeviceType.TRAIN); @@ -404,6 +418,10 @@ public class TrainInfo extends MapElement { this.runLevel = config.getRunMode(); } + /** + * ats 数据采集 + * @param train + */ public void tracking(VirtualRealityTrain train) { this.runLevel = train.getRunLevel(); SectionPosition headPosition = train.getHeadPosition(); @@ -419,6 +437,7 @@ public class TrainInfo extends MapElement { } this.right = train.isRight(); this.speed = train.getSpeed(); + this.locationKM = train.getLocationKM(); this.doorOpen = !train.isAllDoorCloseAndLock(); this.driveMode = train.getDriveMode(); this.jump = train.isJump(); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/YJDDZHTrainStatusVO.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/YJDDZHTrainStatusVO.java new file mode 100644 index 000000000..fa825a10f --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vo/YJDDZHTrainStatusVO.java @@ -0,0 +1,43 @@ +package club.joylink.rtss.simulation.cbtc.data.vo; + +import club.joylink.rtss.simulation.cbtc.constant.DriveMode; +import club.joylink.rtss.simulation.cbtc.constant.PlanRoutingType; +import club.joylink.rtss.simulation.cbtc.constant.RunLevel; +import club.joylink.rtss.simulation.cbtc.constant.TrainType; +import club.joylink.rtss.simulation.cbtc.data.map.MapElement; +import club.joylink.rtss.simulation.cbtc.data.status.TrainStatus; +import club.joylink.rtss.simulation.cbtc.data.status.YJDDZHTrainStatus; +import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; +import club.joylink.rtss.util.jsonSerialize.Boolean2NumSerializer; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +/** + * 列车状态 + */ +@Getter +@Setter +@NoArgsConstructor +public class YJDDZHTrainStatusVO extends TrainStatusVO { + + /** + * 公里标 + */ + private Float locationKM; + + public YJDDZHTrainStatusVO(TrainInfo train){ + super(train); + } + public YJDDZHTrainStatusVO(TrainStatus train) { + super(train); + if(train instanceof YJDDZHTrainStatus){ + YJDDZHTrainStatus yjddzhTrainStatus = (YJDDZHTrainStatus)train; + this.locationKM = yjddzhTrainStatus.getLocationKM(); + } + + } + +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityTrain.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityTrain.java index 14592ee73..b5ed9fbb4 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityTrain.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityTrain.java @@ -14,6 +14,7 @@ import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition; import club.joylink.rtss.simulation.cbtc.exception.SimulationException; import club.joylink.rtss.simulation.cbtc.exception.SimulationExceptionType; import club.joylink.rtss.vo.client.operation.DriveParamVO; +import club.joylink.rtss.vo.ws.TrainPosition; import lombok.Getter; import lombok.Setter; import lombok.extern.slf4j.Slf4j; @@ -237,6 +238,11 @@ public class VirtualRealityTrain extends VirtualRealityDevice { */ private float speed; + + /** + * 公里标 + */ + private float locationKM; /** * 目标距离 */ @@ -651,7 +657,13 @@ public class VirtualRealityTrain extends VirtualRealityDevice { this.initPosition(right, headPosition); init(); } - + public void initManualTrain(SectionPosition headPosition, boolean right, TrainPosition tp) { + this.initPosition(right, headPosition); + init(); + this.speed = tp.getSpeed(); + this.locationKM = tp.getLocation(); + this.right = tp.isRight(); + } private void init() { this.communication = true; this.jump = false; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/message/SimulationSubscribeTopic.java b/src/main/java/club/joylink/rtss/simulation/cbtc/message/SimulationSubscribeTopic.java index f39f3a836..768c28f83 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/message/SimulationSubscribeTopic.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/message/SimulationSubscribeTopic.java @@ -18,7 +18,7 @@ public enum SimulationSubscribeTopic { Ctc("/queue/simulation/{id}/ctc"), //大铁CTC Room("/queue/room/{id}"), Wgu3d("/topic/simulation/wgu3d/{id}"), - YJDDZH_TRAIN_POSITION("/topic/yjddzh/trainPosition") + YJDDZH_TRAIN_POSITION("/topic/yjddzh/trainPosition/simulation/{id}") ; private String destPattern; diff --git a/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java b/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java index 644ee2635..a688fb416 100644 --- a/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java +++ b/src/main/java/club/joylink/rtss/vo/client/factory/SocketMessageFactory.java @@ -64,7 +64,7 @@ public class SocketMessageFactory { List topicList = new ArrayList<>(); switch (messageType) { case YJDDZH_TRAIN_POSITION:{ - topicList.add(SimulationSubscribeTopic.YJDDZH_TRAIN_POSITION.getDestPattern()); + topicList.add(SimulationSubscribeTopic.YJDDZH_TRAIN_POSITION.buildDestination(group)); break; } case BROADCAST: diff --git a/src/main/java/club/joylink/rtss/vo/ws/TrainPosition.java b/src/main/java/club/joylink/rtss/vo/ws/TrainPosition.java index b733dd5ca..7cdf03223 100644 --- a/src/main/java/club/joylink/rtss/vo/ws/TrainPosition.java +++ b/src/main/java/club/joylink/rtss/vo/ws/TrainPosition.java @@ -10,6 +10,7 @@ import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.format.DateTimeFormatter; +import java.util.concurrent.TimeUnit; @Data @NoArgsConstructor @@ -55,6 +56,16 @@ public class TrainPosition { */ private boolean stop; + /** + * 列车速度 + */ + private Float speed; + + private boolean del = false; + + public boolean receiveTimeOver(int second){ + return (System.currentTimeMillis() - this.receiveTime) > TimeUnit.SECONDS.toMillis(second); + } public Section.SectionRoadType getRoadType(){ Section.SectionRoadType type = Section.SectionRoadType.LEFT; diff --git a/src/main/java/club/joylink/rtss/websocket/WebSocketController.java b/src/main/java/club/joylink/rtss/websocket/WebSocketController.java index 07b31144c..7aa85ac7c 100644 --- a/src/main/java/club/joylink/rtss/websocket/WebSocketController.java +++ b/src/main/java/club/joylink/rtss/websocket/WebSocketController.java @@ -37,9 +37,7 @@ public class WebSocketController { } @MessageMapping("/{mapName}/trainPosition") -// @SendTo("/topic/trainPosition") public void mlbs( String json,@DestinationVariable String mapName) { this.trainPositionService.initTrainOrUpdate(mapName,json); -// return json; } } diff --git a/src/main/java/club/joylink/rtss/websocket/client/StompClientManager.java b/src/main/java/club/joylink/rtss/websocket/client/StompClientManager.java index 2b57658ee..a42c0c740 100644 --- a/src/main/java/club/joylink/rtss/websocket/client/StompClientManager.java +++ b/src/main/java/club/joylink/rtss/websocket/client/StompClientManager.java @@ -53,6 +53,7 @@ public class StompClientManager { TrainPosition tp = list.get(i); tp.setCloseDoor(false); tp.setStop(false); + tp.setSpeed(Float.valueOf(i)); // tp.setLocation(tp.getLocation() - 500); String val = JsonUtils.writeValueNullableFieldAsString(tp); Instant instant = Instant.ofEpochMilli(tp.getReceiveTime()); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 0c0134bca..35cd1b219 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -7,7 +7,8 @@ modbus-tcp: udp: serverPort: 20002 clientPort: 20001 - +yjddzh: + receiveTimeOver: 60 spring: profiles: active: dev @@ -93,11 +94,11 @@ springfox: --- spring: - profiles: dev - datasource: - url: jdbc:mysql://localhost:3306/joylink?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true - username: root - password: root + profiles: dev + datasource: + url: jdbc:mysql://192.168.3.233:3306/joylink?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true + username: root + password: joylink0503 tencent-cloud: allow-send: false