From dd78e5bd29c9cc20fa46068adc25e47c41438197 Mon Sep 17 00:00:00 2001 From: thesai <1021828630@qq.com> Date: Mon, 8 Nov 2021 11:26:04 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E9=94=81=E9=97=AD=E9=81=93=E5=B2=94?= =?UTF-8?q?=E7=9A=84=E8=BF=9B=E8=B7=AF=E6=94=B9=E4=B8=BAlist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simulation/cbtc/ATP/ground/MaService.java | 2 +- .../simulation/cbtc/CI/CiApiServiceImpl2.java | 11 ++++--- .../rtss/simulation/cbtc/data/map/Switch.java | 23 ++++++++------ .../data/storage/device/StorageSwitch.java | 31 ++++++++++++++++--- 4 files changed, 48 insertions(+), 19 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/MaService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/MaService.java index face2d3aa..29ddc1752 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/MaService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/MaService.java @@ -550,7 +550,7 @@ public class MaService { SwitchElement switchElement = route.getRouteSwitchElement(routeSection.getRelSwitch()); Switch aSwitch = switchElement.getASwitch(); handledSwitchSet.add(aSwitch.getCode()); - if (route.equals(aSwitch.getRoute())) { + if (aSwitch.getRoutes().contains(route)) { if (aSwitch.isLoss()) { switchFault = true; break; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiServiceImpl2.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiServiceImpl2.java index ffbf926e0..b6a286365 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiServiceImpl2.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiServiceImpl2.java @@ -15,6 +15,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import java.time.LocalTime; +import java.util.ArrayList; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -253,18 +254,20 @@ public class CiApiServiceImpl2 implements CiApiService { if (!aSwitch.isLocked() && aSwitch.getAllSections().stream().noneMatch(Section::isFaultLock)) return; List lockedRouteList = simulation.getRepository().queryAllLockedRoute(); - Route lockedRoute = null; + List lockSwitchRoutes = new ArrayList<>(); if (aSwitch.isRouteLock()) { - lockedRoute = aSwitch.getRoute(); + lockSwitchRoutes = aSwitch.getRoutes(); } else if (aSwitch.isOverlapLock()) { for (Route route : lockedRouteList) { if (route.overlapContainSwitch(aSwitch)) { - lockedRoute = route; + lockSwitchRoutes.add(route); break; } } } - this.routeService.switchFaultUnlock(simulation, aSwitch, lockedRoute); + for (Route lockedRoute : lockSwitchRoutes) { + this.routeService.switchFaultUnlock(simulation, aSwitch, lockedRoute); + } } @Override diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Switch.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Switch.java index a12977631..b74ee6dad 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Switch.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Switch.java @@ -5,6 +5,7 @@ import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch; import lombok.Getter; import lombok.Setter; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Objects; @@ -74,7 +75,7 @@ public class Switch extends DelayUnlockDevice { /** * 锁闭该道岔的进路 */ - private Route route; + private final List routes = new ArrayList<>(); /** * 是否进路侧防锁闭 @@ -141,7 +142,7 @@ public class Switch extends DelayUnlockDevice { this.blockade = false; this.usePosition = No_Use; this.routeLock = false; - this.route = null; + this.routes.clear(); this.fpLock = false; this.overlapLock = false; this.masterGuideLock = false; @@ -207,22 +208,22 @@ public class Switch extends DelayUnlockDevice { public void routeLock(Route route) { this.routeLock = true; - this.route = route; + this.routes.add(route); } public void routeUnlock(Route route) { if (this.isRouteLockBy(route)) { - this.a.routeUnlocking(this.route); - this.b.routeUnlocking(this.route); - this.c.routeUnlocking(this.route); - this.routeLock = false; - this.route = null; + this.a.routeUnlocking(route); + this.b.routeUnlocking(route); + this.c.routeUnlocking(route); + this.routes.remove(route); + this.routeLock = !this.routes.isEmpty(); this.checkAndResetUsePosition(); } } public boolean isRouteLockBy(Route route) { - return this.routeLock && this.route.equals(route); + return this.routeLock && this.routes.contains(route); } private void checkAndResetUsePosition() { @@ -393,7 +394,9 @@ public class Switch extends DelayUnlockDevice { } public void faultUnlock() { - this.routeUnlock(this.route); + for (Route route : routes) { + this.routeUnlock(route); + } this.overlapUnLock(); this.fpUnlock(); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/device/StorageSwitch.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/device/StorageSwitch.java index 3220955ec..8fe963fed 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/device/StorageSwitch.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/device/StorageSwitch.java @@ -14,6 +14,10 @@ import com.fasterxml.jackson.databind.annotation.JsonSerialize; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; +import org.springframework.util.CollectionUtils; + +import java.util.List; +import java.util.stream.Collectors; @Getter @Setter @@ -43,6 +47,8 @@ public class StorageSwitch extends StorageDelayUnlockDevice { private String route; + private List routes; + /** * 是否进路侧防锁闭 */ @@ -95,10 +101,16 @@ public class StorageSwitch extends StorageDelayUnlockDevice { change = true; storageSwitch.setRouteLock(s.isRouteLock()); } - Route route = s.getRoute(); - if (route != null) { +// Route route = s.getRoutes(); +// if (route != null) { +// change = true; +// storageSwitch.setRoute(route.getCode()); +// } + List routes = s.getRoutes(); + if (!CollectionUtils.isEmpty(routes)) { change = true; - storageSwitch.setRoute(route.getCode()); + List routeCodes = routes.stream().map(MapElement::getCode).collect(Collectors.toList()); + storageSwitch.setRoutes(routeCodes); } if (s.isFpLock()) { change = true; @@ -141,7 +153,18 @@ public class StorageSwitch extends StorageDelayUnlockDevice { s.setSingleLock(singleLock != null ? singleLock : false); s.setBlockade(blockade != null ? blockade : false); s.setRouteLock(routeLock != null ? routeLock : false); - s.setRoute(route == null ? null : repository.getByCode(route, Route.class)); + if (route != null) { + Route route = repository.getByCode(this.route, Route.class); + s.getRoutes().add(route); + } else if (!CollectionUtils.isEmpty(routes)) { + for (String code : routes) { + Route route = repository.getByCode(code, Route.class); + s.getRoutes().add(route); + } + } else { + s.getRoutes().clear(); + } +// s.setRoutes(route == null ? null : repository.getByCode(route, Route.class)); s.setOverlapLock(overlapLock != null ? overlapLock : false); s.setMasterGuideLock(masterGuideLock != null ? masterGuideLock : false); if (pos != null) { From 4b034565ed3eb9ab8d542491631c0f0c8e129a00 Mon Sep 17 00:00:00 2001 From: thesai <1021828630@qq.com> Date: Mon, 8 Nov 2021 11:28:28 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E4=B8=8A=E9=A5=B6=E6=B2=99=E7=9B=98?= =?UTF-8?q?=E9=80=9A=E7=94=A8=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../rtss/constants/ProjectDeviceType.java | 5 +- .../controller/project/DeviceController.java | 8 + .../rtss/services/project/DeviceService.java | 5 + .../services/project/DeviceServiceImpl.java | 89 ++++- .../services/runplan/RunPlanGenerator.java | 2 +- .../cbtc/ATP/ground/AtpSectionService.java | 22 -- .../handler/DriverOperateHandler.java | 6 + .../cbtc/ATS/service/AtsTrainLoadService.java | 13 +- .../cbtc/ATS/service/AtsTrainService.java | 352 ------------------ .../stage/AtsPlanTrainStageService.java | 8 +- .../service/stage/AtsTrainStageHandler.java | 4 +- .../simulation/cbtc/CI/CiApiServiceImpl2.java | 2 +- .../cbtc/CI/device/CiRouteService.java | 7 + .../ProjectJointSimulationServiceImpl.java | 9 +- .../cbtc/build/MapDeviceBuilder.java | 3 +- .../simulation/cbtc/command/CommandBO.java | 2 +- .../cbtc/data/SimulationDataRepository.java | 16 + .../simulation/cbtc/data/map/Section.java | 87 +++-- .../rtss/simulation/cbtc/data/map/Signal.java | 4 + .../data/vr/VirtualRealityScreenDoor.java | 18 + .../vr/VirtualRealitySectionAxleCounter.java | 7 - .../cbtc/data/vr/VirtualRealityTrain.java | 19 +- .../SimulationRealDeviceConnectManager.java | 16 +- .../device/real/udp/Sr/SrSectionConfig.java | 9 +- .../real/udp/Sr/SrSectionServiceImpl.java | 184 ++++++++- .../device/real/udp/Sr/SrSignalConfig.java | 8 +- .../real/udp/Sr/SrSignalServiceImpl.java | 17 +- .../device/real/udp/Sr/SrSwitchConfig.java | 6 +- .../real/udp/Sr/SrSwitchServiceImpl.java | 25 +- .../device/real/udp/Sr/SrTrainConfig.java | 51 +++ .../device/real/udp/Sr/SrTrainController.java | 19 + .../real/udp/Sr/SrTrainServiceImpl.java | 243 ++++++++++++ .../cbtc/device/real/udp/UDPClient.java | 48 ++- .../cbtc/device/real/udp/UDPLowConfig.java | 3 +- .../device/real/udp/UDPRealDeviceService.java | 2 +- .../device/real/udp/UDPRealDeviceThread.java | 3 +- .../real/udp/handler/UDPMessageHandler.java | 3 - .../device/virtual/VRTrainRunningService.java | 17 +- .../cbtc/onboard/ATP/ATPLogicLoop.java | 21 +- .../vo/client/project/ProjectDeviceVO.java | 11 +- .../client/project/sr/SrSectionConfigVO.java | 8 +- .../vo/client/project/sr/SrTrainConfigVO.java | 19 + .../rtss/vo/client/runplan/RunPlanTripVO.java | 4 +- src/main/resources/application.yml | 2 +- 44 files changed, 905 insertions(+), 502 deletions(-) create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainConfig.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainController.java create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainServiceImpl.java create mode 100644 src/main/java/club/joylink/rtss/vo/client/project/sr/SrTrainConfigVO.java diff --git a/src/main/java/club/joylink/rtss/constants/ProjectDeviceType.java b/src/main/java/club/joylink/rtss/constants/ProjectDeviceType.java index d95724175..f23ac2f96 100644 --- a/src/main/java/club/joylink/rtss/constants/ProjectDeviceType.java +++ b/src/main/java/club/joylink/rtss/constants/ProjectDeviceType.java @@ -34,6 +34,8 @@ public enum ProjectDeviceType { UDP_LOW, /** UDP客户端 */ UDP_CLIENT, + /** 列车 */ + TRAIN, /* -----------plc device end---------- */ /* -----------client device start---------- */ @@ -79,6 +81,7 @@ public enum ProjectDeviceType { SIGNAL, DCU, UDP_LOW, - UDP_CLIENT); + UDP_CLIENT, + TRAIN); } } diff --git a/src/main/java/club/joylink/rtss/controller/project/DeviceController.java b/src/main/java/club/joylink/rtss/controller/project/DeviceController.java index 248d6d0ec..425cd653f 100644 --- a/src/main/java/club/joylink/rtss/controller/project/DeviceController.java +++ b/src/main/java/club/joylink/rtss/controller/project/DeviceController.java @@ -189,6 +189,14 @@ public class DeviceController { this.deviceService.updateIlwConfig(id, configVO); } + /** + * 修改配置,以json的形式 + */ + @PutMapping("/config/updateConfig") + public void updateConfig(@RequestBody ProjectDeviceVO projectDeviceVO) { + this.deviceService.updateConfig(projectDeviceVO); + } + /** *删除设备 */ diff --git a/src/main/java/club/joylink/rtss/services/project/DeviceService.java b/src/main/java/club/joylink/rtss/services/project/DeviceService.java index cf42eccb9..d06a09301 100644 --- a/src/main/java/club/joylink/rtss/services/project/DeviceService.java +++ b/src/main/java/club/joylink/rtss/services/project/DeviceService.java @@ -148,6 +148,11 @@ public interface DeviceService { */ void updateIlwConfig(Long id, RelationLoginConfigVO configVO); + /** + * 更新(以json直接更新) + */ + void updateConfig(ProjectDeviceVO projectDeviceVO); + /** * 删除设备 * @param id diff --git a/src/main/java/club/joylink/rtss/services/project/DeviceServiceImpl.java b/src/main/java/club/joylink/rtss/services/project/DeviceServiceImpl.java index e3a67ebb3..490fef874 100644 --- a/src/main/java/club/joylink/rtss/services/project/DeviceServiceImpl.java +++ b/src/main/java/club/joylink/rtss/services/project/DeviceServiceImpl.java @@ -7,6 +7,7 @@ import club.joylink.rtss.entity.ProjectDevice; import club.joylink.rtss.entity.ProjectDeviceExample; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.services.IMapService; +import club.joylink.rtss.simulation.cbtc.data.map.Section; import club.joylink.rtss.util.JsonUtils; import club.joylink.rtss.vo.AccountVO; import club.joylink.rtss.vo.LoginUserInfoVO; @@ -22,12 +23,14 @@ import club.joylink.rtss.vo.client.project.sdy.SdyPslConfigVO; import club.joylink.rtss.vo.client.project.sr.SrSectionConfigVO; import club.joylink.rtss.vo.client.project.sr.SrSignalConfigVO; import club.joylink.rtss.vo.client.project.sr.SrSwitchConfigVO; +import club.joylink.rtss.vo.client.project.sr.SrTrainConfigVO; import club.joylink.rtss.vo.client.project.xty.XtyPsdConfigVO; import club.joylink.rtss.vo.map.MapGraphDataNewVO; import club.joylink.rtss.vo.map.MapVO; import club.joylink.rtss.vo.map.graph.MapSectionNewVO; import club.joylink.rtss.vo.map.graph.MapSignalNewVO; import club.joylink.rtss.vo.map.graph.MapSwitchVO; +import club.joylink.rtss.vo.map.graph.MapTrainVO; import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import org.springframework.beans.factory.annotation.Autowired; @@ -269,6 +272,24 @@ public class DeviceServiceImpl implements DeviceService { this.projectDeviceDAO.updateByPrimaryKeySelective(device); } + @Override + public void updateConfig(ProjectDeviceVO projectDeviceVO) { + ProjectDevice entity = getEntityById(projectDeviceVO.getId()); + check(entity, projectDeviceVO); + entity.setConfig(projectDeviceVO.getConfig()); + projectDeviceDAO.updateByPrimaryKey(entity); + } + + private ProjectDevice getEntityById(long id) { + return projectDeviceDAO.selectByPrimaryKey(id); + } + + private void check(ProjectDevice entity, ProjectDeviceVO projectDeviceVO) { + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertEquals(entity.getProjectCode(), projectDeviceVO.getProject().name()); + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertEquals(entity.getCode(), projectDeviceVO.getCode()); + BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.assertEquals(entity.getType(), projectDeviceVO.getType().name()); + } + @Override public void delete(Long id) { this.projectDeviceDAO.deleteByPrimaryKey(id); @@ -436,7 +457,7 @@ public class DeviceServiceImpl implements DeviceService { udp.setType(ProjectDeviceType.UDP_LOW.name()); udp.setCreator(accountVO.getId()); udp.setCreateTime(now); - UDPLowConfigVO udpConfigVO = new UDPLowConfigVO("", 10086); + UDPLowConfigVO udpConfigVO = new UDPLowConfigVO("192.168.0.110", 44449); udp.setConfig(udpConfigVO.toJson()); list.add(udp); //UDP客户端 @@ -446,7 +467,7 @@ public class DeviceServiceImpl implements DeviceService { udpClient.setType(ProjectDeviceType.UDP_CLIENT.name()); udpClient.setCreator(accountVO.getId()); udpClient.setCreateTime(now); - UDPClientConfigVO udpClientConfigVO = new UDPClientConfigVO("192.168.8.109", 10000); + UDPClientConfigVO udpClientConfigVO = new UDPClientConfigVO("192.168.0.110", 44449); udpClient.setConfig(JsonUtils.writeValueAsString(udpClientConfigVO)); list.add(udpClient); /*-------------------- 地图设备 --------------------*/ @@ -489,14 +510,76 @@ public class DeviceServiceImpl implements DeviceService { section.setType(ProjectDeviceType.SECTION.name()); section.setCreator(accountVO.getId()); section.setCreateTime(now); - SrSectionConfigVO configVO = new SrSectionConfigVO(mapSectionNewVO.getCode(), mapSectionNewVO.getSrCode()); + SrSectionConfigVO configVO = new SrSectionConfigVO(mapSectionNewVO.getCode(), mapSectionNewVO.getSrCode(), getTime(mapSectionNewVO)); section.setConfig(JsonUtils.writeValueAsString(configVO)); list.add(section); } } + //列车 + List trainList = graphDataNew.getTrainList(); + for (MapTrainVO mapTrainVO : trainList) { + ProjectDevice train = new ProjectDevice(); + train.setProjectCode(Project.SR_SANDBOX.name()); + train.setCode("sr-train-" + mapTrainVO.getGroupNumber()); + train.setType(ProjectDeviceType.TRAIN.name()); + train.setCreator(accountVO.getId()); + train.setCreateTime(now); + SrTrainConfigVO configVO = new SrTrainConfigVO(mapTrainVO.getGroupNumber(), String.valueOf(Integer.parseInt(mapTrainVO.getGroupNumber()))); + train.setConfig(JsonUtils.writeValueAsString(configVO)); + list.add(train); + } return list; } + private Long getTime(MapSectionNewVO section) { + Long nanos = null; + if (section.isTransferTrack() || section.isReentryTrack() || section.isStandTrack()) { + long m = 1000000000; + switch (section.getCode()) { + case "T5": //1x + nanos = (long) (2.3 * m); + break; + case "T7": //2x + nanos = (long) (3.5 * m); + break; + case "T45": //3x + nanos = (long) (3.0 * m); + break; + case "T53": //4x + nanos = (long) (2.6 * m); + break; + case "T61": //5x + nanos = (long) (2.0 * m); + break; + case "T67": //6x + nanos = (long) (2.7 * m); + break; + case "T33": //1s + nanos = (long) (3.2 * m); + break; + case "T35": //2s + nanos = (long) (2.9 * m); + break; + case "T46": //3s + nanos = (long) (2.6 * m); + break; + case "T54": //4s + nanos = (long) (3.2 * m); + break; + case "T62": //5s + nanos = (long) (2.5 * m); + break; + case "T68": //6s + nanos = (long) (2.8 * m); + break; + case "T141": //49G + nanos = (long) (0.5 * m); + break; + } + } + return nanos; + } + private List buildZjdProjectDevices(AccountVO accountVO) { LocalDateTime now = LocalDateTime.now(); List list = new ArrayList<>(); diff --git a/src/main/java/club/joylink/rtss/services/runplan/RunPlanGenerator.java b/src/main/java/club/joylink/rtss/services/runplan/RunPlanGenerator.java index 6ad00c112..fe25f3f90 100644 --- a/src/main/java/club/joylink/rtss/services/runplan/RunPlanGenerator.java +++ b/src/main/java/club/joylink/rtss/services/runplan/RunPlanGenerator.java @@ -239,7 +239,7 @@ public class RunPlanGenerator { List inSectionList = inRouting.getParkSectionCodeList(); RunPlanRoutingSection inSection = inSectionList.get(inSectionList.size() - 2); return Objects.equals(parkSection.getSectionCode(), inSection.getSectionCode()); - }).sorted(Comparator.comparing(routingVO -> runLevelMap.get(parkSection.getSectionCode() + "-" + routingVO.getEndSectionCode()))).findFirst().orElse(null); + }).min(Comparator.comparing(routingVO -> runLevelMap.get(parkSection.getSectionCode() + "-" + routingVO.getEndSectionCode()))).orElse(null); if (Objects.nonNull(inboundRouting)) { r = runningRouting.getStartTbFront() ? i + 1 : i; break t; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/AtpSectionService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/AtpSectionService.java index a5c99ce12..d99afe4e0 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/AtpSectionService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/AtpSectionService.java @@ -209,26 +209,4 @@ public class AtpSectionService { }); } - /** - * 如果有非通信车接近故障区段,将故障区段设为非通信车占用 - */ - public void judgeFaultSectionAsNctOccupied(Map nctApproachSignalMap) { - if (CollectionUtils.isEmpty(nctApproachSignalMap)) { - return; - } - nctApproachSignalMap.forEach((k, v) -> { - v.getRouteList().forEach(route -> { - if (v.equals(route.getStart())) { //如果该信号机是某进路的始端信号机 - route.getSectionList().forEach(section -> { - if (section.isFault()) { - section.setNctOccupied(true); //设为非通信车占用 - if (section.isInvalid()) { - section.setInvalid(false); //去掉ARB状态 - } - } - }); - } - }); - }); - } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/DriverOperateHandler.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/DriverOperateHandler.java index 70d49926b..178862d8f 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/DriverOperateHandler.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/operation/handler/DriverOperateHandler.java @@ -67,6 +67,12 @@ public class DriverOperateHandler { } } + /** + * 修改工况手轮档位 + * @param simulation + * @param groupNumber + * @param gear + */ @OperateHandlerMapping(type = Operation.Type.Driver_Gear_Change) public void changeTrainGear(Simulation simulation, String groupNumber, VirtualRealityTrain.Handwheel gear) { Objects.requireNonNull(gear); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java index 30a3040ae..5d3cf11f1 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java @@ -861,8 +861,19 @@ public class AtsTrainLoadService { * 人工车上线并监控 */ private void manualTrainOnlineAndSupervise(Simulation simulation, VirtualRealityTrain train, SectionPosition headPosition, boolean right) { - train.initManualTrain(headPosition, right); //暂时默认向左 + train.initManualTrain(headPosition, right); SimulationDataRepository repository = simulation.getRepository(); + //设置列车预选模式、驾驶模式、运行级别 + if (!headPosition.getSection().anyZcWorking()) { + train.initAsRM(); + } else { + MapConfig config = repository.getConfig(); + if (RunLevel.ITC.equals(config.getRunMode())) { + train.initAsAM_I(); + } else if (RunLevel.IL.equals(config.getRunMode())) { + train.initAsRM(); + } + } TrainInfo trainInfo = TrainInfo.constructManualTrain(train); trainInfo.tracking(train); repository.addOnlineTrain(train); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java index 335fe5459..ab078a05d 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java @@ -8,8 +8,6 @@ import club.joylink.rtss.simulation.cbtc.ATS.service.stage.AtsHeadTrainStageServ import club.joylink.rtss.simulation.cbtc.ATS.service.stage.AtsPlanTrainStageService; import club.joylink.rtss.simulation.cbtc.CI.CiApiService; 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.constant.TrainType; import club.joylink.rtss.simulation.cbtc.data.CalculateService; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; @@ -18,7 +16,6 @@ import club.joylink.rtss.simulation.cbtc.data.plan.StationPlan; import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan; import club.joylink.rtss.simulation.cbtc.data.support.RoutePath; import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition; -import club.joylink.rtss.simulation.cbtc.data.support.StationTurnBackStrategyOption; import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; import club.joylink.rtss.simulation.cbtc.exception.SimulationException; @@ -360,355 +357,6 @@ public class AtsTrainService { onboardAtpApiService.resetAtoSpeedMax(simulation, groupNumber); } - /** - * 头码车和人工车运行逻辑 - * - * @param simulation - * @param train - */ - public void runContinue(Simulation simulation, TrainInfo train) { - if (train.isPlanTrain() || !train.hasPositionAndDirection()) { - return; - } - SimulationDataRepository repository = simulation.getRepository(); - if (train.isInbound()) { // 准备回库列车 - int deleteRemain = train.getDeleteRemain(); - deleteRemain -= SimulationModule.ATS.getRateMs(); - if (deleteRemain <= 0) { // 删除列车 - repository.deleteOnlineTrain(train.getGroupNumber()); - repository.deleteSuperviseTrain(train.getGroupNumber()); - } else { - train.updateDeleteRemain(deleteRemain); - } - return; - } - Long mapId = simulation.getBuildParams().getMap().getId(); - LocalTime systemTime = simulation.getSystemTime().toLocalTime(); - Section headSection = repository.getByCode(train.getPhysicalSection(), Section.class); - Station headStation = headSection.getStation(); - float offset = train.getOffsetp() * headSection.getLen(); - SectionPosition headPosition = new SectionPosition(headSection, offset); - Boolean trainRight = train.getRight(); - TrainType type = train.getType(); - String estimatedArriveStandTrack = train.getEstimatedArriveStandTrack(); - Section targetSection = null; - Station targetStation = null; - if (estimatedArriveStandTrack != null) { - targetSection = repository.getByCode(estimatedArriveStandTrack, Section.class); - targetStation = targetSection.getStation(); - } - boolean stop = train.isStop(); - Section nextTarget = null; - long runningTime = 0; - - switch (type) { - case MANUAL: { - Section base = headSection; - boolean right = trainRight; - if (!CollectionUtils.isEmpty(headSection.getStandList())) { - Optional onStand = headSection.getStandList().stream().filter(stand -> Objects.equals(stand.isRight(), train.getRight())).findFirst(); - if (onStand.isPresent()) { - runningTime = onStand.get().getRunLevelTime(); - } - } - if (train.isParking()) { - if (train.getSpeed() > 0) { // 列车出发了 - // 站台停站状态取消 - this.atsStandService.trainLeaveStand(headSection); - // 更新列车实际离开信息 - train.updateLeaveInfo(headSection, systemTime); - } - // 站台停靠 - Signal tdSignal = headSection.getSignalOf(trainRight); // 列车方向信号机 - if (Objects.nonNull(tdSignal) && tdSignal.isMainAspect()) { - base = headSection.getNextRunningSectionOf(trainRight); - } else { - Signal trdSignal = headSection.getSignalOf(!trainRight); - if (Objects.nonNull(trdSignal) && trdSignal.isMainAspect()) { - right = !trainRight; - base = headSection.getNextRunningSectionOf(right); - } - } - } else if (stop) { - // 列车停车中 - Signal trdSignal = headSection.getSignalOf(!trainRight); - if (Objects.nonNull(trdSignal) && trdSignal.isMainAspect()) { - right = !trainRight; - } - if (headSection.isNormalStandTrack() || headSection.isTransferTrack()) { - float stopPointOffset = headSection.getStopPointByDirection(right); - SectionPosition standPosition = new SectionPosition(headSection, stopPointOffset); - if (headPosition.isAheadOf(standPosition, right)) { - base = headSection.getNextRunningSectionOf(right); - } - } - } - int count = 0; - while (Objects.nonNull(base)) { - if ((base.isNormalStandTrack() || base.isTransferTrack())) { - nextTarget = base; - break; - } - Signal signal = base.getSignalOf(right); - if (Objects.nonNull(signal) && !signal.isMainAspect()) { - nextTarget = base; - break; - } - Section section = base.getNextRunningSectionOf(right); - if (Objects.isNull(section)) { - nextTarget = base; - break; - } else { - base = section; - } - if (count > 20) { - log.warn(String.format("人工列车[%s]前方20个区段都通畅", train.getGroupNumber())); - break; - } - ++count; - } - break; - } - case HEAD: { - String destinationCode = train.getDestinationCode(); - if (!stop) { - if (train.isParking()) { - // 站台停站状态取消 - this.atsStandService.trainLeaveStand(headSection); - // 更新列车实际离开信息 - train.updateLeaveInfo(headSection, systemTime); - } - } else { - /* 判断是否需要更新下一目标区段 */ - if (trainRight == null) - return; - Map destinationMap = repository.getDestinationMap(); - if (CollectionUtils.isEmpty(destinationMap)) - return; - DestinationCodeDefinition destDefinition = destinationMap.get(destinationCode); - if (destDefinition == null) { - log.error("地图[{}}]目的地码[{}]不存在", simulation.getBuildParams().getMap().getName(), destinationCode); - return; - } - Section destSection = destDefinition.getSection(); - if (headSection.equals(destSection)) { //列车已到达目的地区段 - VirtualRealityTrain vrTrain = repository.getOnlineTrainBy(train.getGroupNumber()); - if (vrTrain.isStopAtThePosition(new SectionPosition(destSection, destSection.getStopPointByDirection(trainRight)))) { - if (repository.getConfig().isSetManualWhenHeadTrainArriveTarget()) { - setManualTrain(simulation, vrTrain.getGroupNumber()); - } - return; - } - } - if (targetSection != null) { - SectionPosition targetPosition = new SectionPosition(targetSection, targetSection.getStopPointByDirection(trainRight)); - // TODO: 2021/5/28 这里列车越过目标停车点的判断逻辑不严谨,如果开过头并换端了,以此逻辑判断并不正确 - SectionPosition minStopPosition = CalculateService - .calculateNextPositionByStartAndLen(targetPosition, !trainRight, SimulationConstants.PARK_POINT_MAX_OFFSET); - if (!headPosition.isAheadOf(minStopPosition, trainRight)) //没有越过最小停车位置 - return; - } - /* 寻找下一目标区段 */ - nextTarget = findNextTarget4HeadTrain(simulation, train, repository, headSection, headStation, destDefinition); - /* 判断换端并更新目标 */ - if (nextTarget != null) { - if (nextTarget.getCode().equals(estimatedArriveStandTrack)) { - return; - } - boolean isPark = true; - if (repository.getConfig().isNoParkingServiceNumber(train.getServiceNumber())) { - isPark = false; - } - if (!nextTarget.isAheadOf(repository, headSection, trainRight)) //下一目标区段不在当前车头方向的前方 - atpService.turnDirectionImmediately(repository.getOnlineTrainBy(train.getGroupNumber())); //调头 - SectionPosition stopPosition = new SectionPosition(nextTarget, nextTarget.getStopPointByDirection(trainRight)); - Float distance = CalculateService.calculateDistance(headPosition, stopPosition, trainRight); - if (distance == null) { - distance = CalculateService.calculateDistance(headPosition, stopPosition, !trainRight); - - } - if (distance != null) { - runningTime = (int) (distance / (45 / 3.6)); - } - train.updateEstimatedArriveInfo(nextTarget, simulation.getSystemTime().plusSeconds(runningTime).toLocalTime()); - this.onboardAtpApiService.updateNextStation(simulation, train.getGroupNumber(), - nextTarget.getStation().getCode(), nextTarget.getCode(), runningTime, isPark); - } - } - break; - } - } - - if (Objects.nonNull(nextTarget)) { - //非计划车跟踪目标轨 - train.setPlanStandTrack(nextTarget.getCode()); - String standTrackCode = null; - if (train.isParking()) { - standTrackCode = train.getActualArriveStandTrack(); - } - if (!stop) { - standTrackCode = estimatedArriveStandTrack; - } - if (standTrackCode == null) { - return; - } - boolean jump = this.atsStandService.isJump(repository.getByCode(standTrackCode, Section.class), - train.getGroupNumber()); - boolean hold = this.atsStandService.isHoldTrain(repository.getByCode(standTrackCode, Section.class)); - // 更新跳停状态 - if (!Objects.equals(train.isJump(), jump)) { - if (jump) { - this.onboardAtpApiService.setJump(simulation, train.getGroupNumber()); - } else { - this.onboardAtpApiService.cancelJump(simulation, train.getGroupNumber()); - } - } - // 更新扣车状态 - if (!Objects.equals(train.isHold(), hold)) { - if (hold) { - this.onboardAtpApiService.standHoldTrain(simulation, train.getGroupNumber()); - } else { - this.onboardAtpApiService.standCancelHoldTrain(simulation, train.getGroupNumber()); - } - } - - } - - } - - /** - * 寻找头码车的下一个目标区段 - */ - public static Section findNextTarget4HeadTrain(Simulation simulation, TrainInfo train, SimulationDataRepository repository, Section headSection, - Station headStation, DestinationCodeDefinition destinationCodeDefinition) { - Section nextTarget = null; - Boolean destinationRight = destinationCodeDefinition.getRight(); - switch (destinationCodeDefinition.getType()) { - case NORMAL_OPERATION: { - nextTarget = destinationCodeDefinition.queryNextTargetSection(headSection); - if (nextTarget != null) { - break; - } - Station leftStation = destinationCodeDefinition.getLeftStation(); - Station rightStation = destinationCodeDefinition.getRightStation(); - if (destinationCodeDefinition.isBorder(headStation)) { //到达边界车站 - boolean rightEnd = headStation.equals(rightStation); //是否右端车站 - if (headSection.isNormalStandTrack()) { - boolean standRight = headStation.isStandOfSectionRight(headSection); //是否是右行站台 - if (rightEnd == standRight && !destinationCodeDefinition.isFrontTurnBack(headStation)) { //需要站后折返 - //查询目的地码定义指定的折返轨 - nextTarget = destinationCodeDefinition.getNecessarySections().stream() - .filter(section -> section.isTurnBackTrack() && !section.isStandTrack() && section.getStation().equals(headStation)) - .findAny().orElse(null); - //查询车站指定的折返轨 - if (nextTarget == null) { - if (!CollectionUtils.isEmpty(headStation.getTbStrategyMap()) && headStation.getTbStrategyId() != null) { - StationTurnBackStrategyOption strategy = headStation.getCurrentTurnBackStrategy(); - Section tbSection = strategy.getSectionList().get(0); - switch (strategy.getType()) { - case FIRST: - List routePaths = CalculateService.queryRoutePathsOnDirection(headSection, tbSection, standRight, 10); - if (routePaths.stream().anyMatch(path -> !path.isOccupied())) { - nextTarget = tbSection; - } - break; - case ONLY: - nextTarget = tbSection; - break; - } - } - } - //随意选择能用的折返轨 - if (nextTarget == null) { - for (Section section : headStation.getTurnBackList()) { - if (section.isNormalStandTrack()) { - continue; - } - List routePaths = CalculateService.queryRoutePathsOnDirection(headSection, section, standRight, 10); - if (routePaths.stream().anyMatch(path -> !path.isOccupied())) { - nextTarget = section; - break; - } - } - } - } else { //站前折返或已到站后折返轨 - Station adjacentStation = simulation.getRepository().findAdjacentStation(headStation, !rightEnd); - BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(adjacentStation, - String.format("%s的%s侧相邻车站不存在", headStation.debugStr(), rightEnd ? "左" : "右")); - nextTarget = adjacentStation.getNormalStand(!rightEnd).get(0).getSection(); - } - } else if (headSection.isTurnBackTrack()) { //认为是站后折返轨 - nextTarget = headStation.getNormalStand(!rightEnd).get(0).getSection(); - } - } else { //不在边界车站 - if (!headSection.isNormalStandTrack()) { //认为此时列车一定在站台轨(如果是在折返轨不好处理,故略过) - break; - } - boolean standRight = headStation.isStandOfSectionRight(headSection); - Station adjacentStation = simulation.getRepository().findAdjacentStation(headStation, standRight); - if (destinationCodeDefinition.isBorder(adjacentStation)) { - if (destinationCodeDefinition.isFrontTurnBack(adjacentStation)) { - nextTarget = destinationCodeDefinition.getNecessarySections().stream() - .filter(section -> section.isStandTrack() && adjacentStation.equals(section.getStation())) - .limit(1).findAny().orElse(null); - if (nextTarget != null) { - break; - } - nextTarget = adjacentStation.getNormalStand(!standRight).get(0).getSection(); - if (CollectionUtils.isEmpty(CalculateService.queryRoutePathsOnDirection(headSection, nextTarget, standRight, 10))) { - nextTarget = adjacentStation.getNormalStand(standRight).get(0).getSection(); - } - } else { - nextTarget = adjacentStation.getNormalStand(standRight).get(0).getSection(); - } - } else { - nextTarget = adjacentStation.getNormalStand(standRight).get(0).getSection(); - } - } - break; - } - case LAST_OPERATION: - case NON_OPERATION: - case LAST_NON_OPERATION: - nextTarget = destinationCodeDefinition.queryNextTargetSection(headSection); - if (nextTarget == null) { - nextTarget = headStation.getNormalStand(destinationRight).get(0).getSection(); - if (!headSection.equals(nextTarget)) { - List routePaths = CalculateService.queryRoutePathsOnDirection(headSection, nextTarget, destinationRight, 10); - if (!CollectionUtils.isEmpty(routePaths)) { - break; - } - } - Station adjacentStation = simulation.getRepository().findAdjacentStation(headStation, destinationRight); - nextTarget = adjacentStation.getNormalStand(destinationRight).get(0).getSection(); - } - break; - case OTHER: - List
path = train.getHctPath().getSections(); - if (path != null) { - int index = path.indexOf(headSection); - if (index == -1) { - break; - } - for (int i = index + 1; i < path.size(); i++) { - Section section = path.get(i); - if (section.isSpecialSection()) { - List routePaths = repository.queryRoutePathsByEnd(section); - if (routePaths.stream().anyMatch(rp -> rp.containsSection(headSection))) { - nextTarget = section; - break; - } - } - } - if (nextTarget == null) { - nextTarget = path.get(path.size() - 1); - } - } - break; - } - return nextTarget; - } - /** * 扣车 */ diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsPlanTrainStageService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsPlanTrainStageService.java index cd91312e0..9c4606b00 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsPlanTrainStageService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsPlanTrainStageService.java @@ -41,11 +41,15 @@ public class AtsPlanTrainStageService implements AtsStageService { TripPlan tripPlan = repository.getTripPlan(trainInfo.getServiceNumber(), trainInfo.getTripNumber()); List routePathList = repository.queryRoutePathsByEnd(parkSection); if (routePathList.get(0).isRight() == trainInfo.getRight()) { //准备回库 - trainInfo.finishPlanPrepareInbound(); + if (!parkSection.isTurnBackTrack()) { //针对上饶沙盘 + trainInfo.finishPlanPrepareInbound(); + } } else if (tripPlan.getEndSection().equals(parkSection) || tripPlan.getEndSection().getStation().equals(parkSection.getStation())) { // 列车到达计划终点,准备回库 - trainInfo.finishPlanPrepareInbound(); + if (!parkSection.isTurnBackTrack()) { //针对上饶沙盘 + trainInfo.finishPlanPrepareInbound(); + } } else if (tripPlan.getStartSection().equals(parkSection)) { // 出库列车 if (trainInfo.getPlanStandTrack() != null) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsTrainStageHandler.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsTrainStageHandler.java index 8a68b5619..5bd9e853f 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsTrainStageHandler.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsTrainStageHandler.java @@ -75,7 +75,9 @@ public class AtsTrainStageHandler { this.onboardAtpApiService.departure(simulation, trainInfo.getGroupNumber()); } } else { // 折返轨 - stageService.handleTurnBackTrackParking(simulation, trainInfo, parkSection); + if (!(parkSection.getStation() != null && parkSection.getStation().isDepot())) { //上饶 + stageService.handleTurnBackTrackParking(simulation, trainInfo, parkSection); + } } if (!trainInfo.isStop()) { trainInfo.updateParking(false); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiServiceImpl2.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiServiceImpl2.java index d218fef8b..b45c41bfe 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiServiceImpl2.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiServiceImpl2.java @@ -247,7 +247,7 @@ public class CiApiServiceImpl2 implements CiApiService { @Override public void switchSectionFaultUnlock(Simulation simulation, String switchCode) { Switch aSwitch = simulation.getRepository().getByCode(switchCode, Switch.class); - if (!aSwitch.isLocked() && aSwitch.getAllSections().stream().noneMatch(Section::isFaultLock)) + if (!aSwitch.isLocked() && aSwitch.getAllSections().stream().noneMatch(Section::isLocked)) return; List lockedRouteList = simulation.getRepository().queryAllLockedRoute(); List lockSwitchRoutes = new ArrayList<>(); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/device/CiRouteService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/device/CiRouteService.java index c3e5a297a..64ac6e96e 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/device/CiRouteService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/device/CiRouteService.java @@ -310,12 +310,19 @@ public class CiRouteService { return; } if (section.isSwitchTrack()) { + //解锁道岔 Switch relSwitch = section.getRelSwitch(); relSwitch.routeUnlock(route); + //解锁道岔侧防 RouteFls routeFls = route.queryRouteFlsOfSwitch(relSwitch); if (routeFls != null) { routeFls.unlock(); } + //解锁联动道岔 + Switch linkedSwitch = relSwitch.queryLinkedSwitch(); + if (linkedSwitch != null) { + linkedSwitch.routeUnlock(route); + } } else { section.routeUnlocking(route); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ProjectJointSimulationServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ProjectJointSimulationServiceImpl.java index d757ebf14..0ec86a61e 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ProjectJointSimulationServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ProjectJointSimulationServiceImpl.java @@ -17,10 +17,11 @@ import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device.Heb1Ps import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.richor.ZjdIbpConfig; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.richor.ZjdPslConfig; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.xty.XtyPsdConfig; -import club.joylink.rtss.simulation.cbtc.device.real.udp.Sr.SrSectionConfig; -import club.joylink.rtss.simulation.cbtc.device.real.udp.Sr.SrSignalConfig; -import club.joylink.rtss.simulation.cbtc.device.real.udp.Sr.SrSwitchConfig; +import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.SrSectionConfig; +import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.SrSignalConfig; +import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.SrSwitchConfig; import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceThread; +import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.SrTrainConfig; import club.joylink.rtss.simulation.cbtc.event.SimulationUserEnterEvent; import club.joylink.rtss.simulation.cbtc.member.MemberManager; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; @@ -161,6 +162,8 @@ public class ProjectJointSimulationServiceImpl implements ProjectJointSimulation return ((SrSectionConfig) config).getConfigVO().getVrCode(); case SWITCH: return ((SrSwitchConfig) config).getConfigVO().getVrCode(); + case TRAIN: + return ((SrTrainConfig) config).getConfigVO().getVrCode(); } } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/build/MapDeviceBuilder.java b/src/main/java/club/joylink/rtss/simulation/cbtc/build/MapDeviceBuilder.java index a7f1dc065..4dda6f50b 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/build/MapDeviceBuilder.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/build/MapDeviceBuilder.java @@ -1291,7 +1291,8 @@ public class MapDeviceBuilder { } elementMap.put(station.getCode(), station); station.setCentralized(stationVO.isCentralized()); - if (station.isCentralized()) { + station.setDepot(stationVO.isDepot()); + if (station.isCentralized() && !station.isDepot()) { ZC zc = (ZC) elementMap.get(stationVO.getZcCode()); if (Objects.isNull(zc)) { errMsgList.add(String.format("车站[%s(%s)]未关联ZC或ZC不存在,请在ZC设备处选择管理的集中站列表", station.getName(), station.getCode())); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/CommandBO.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/CommandBO.java index 1e2b06dc6..a7729d12a 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/command/CommandBO.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/CommandBO.java @@ -754,7 +754,7 @@ public class CommandBO { } else { return buildPreselectionModeDownOperationStep(groupNumber); } - } else if (ConfirmationMessage.Confirm_Preselection.equals(train.findFirstMessage())) { + } else /*if (ConfirmationMessage.Confirm_Preselection.equals(train.findFirstMessage()))*/ { return buildConfirmOperationStep(groupNumber); } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/SimulationDataRepository.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/SimulationDataRepository.java index 47000bfb7..684bf8fd6 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/SimulationDataRepository.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/SimulationDataRepository.java @@ -802,6 +802,22 @@ public class SimulationDataRepository { return next; } + public TripPlan findNextTripPlan(TripPlan tripPlan) { + Section endSection = tripPlan.getEndSection(); + List planList = this.endTripMap.get(endSection.getCode()); + TripPlan next = null; + if (!CollectionUtils.isEmpty(planList)) { + for (TripPlan plan : planList) { + if (plan.isDeparture()) { + continue; + } + next = plan; + break; + } + } + return next; + } + /** * 此方法只能用于计划车次号唯一的线路(比如西门子风格的运行计划) * @param tripNumber diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java index e9817e94e..5eff3da33 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java @@ -10,10 +10,7 @@ import lombok.Getter; import lombok.Setter; import org.springframework.util.CollectionUtils; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; +import java.util.*; /** * 区段 @@ -363,7 +360,7 @@ public class Section extends DelayUnlockDevice { } else { // B或C if (right && a.getLeftSection() != null) { return this.rightSection; - } else if(!right && a.getRightSection() != null) { + } else if (!right && a.getRightSection() != null) { return this.leftSection; } else if ((relSwitch.isPosN() && relSwitch.isB(this)) || (relSwitch.isPosR() && relSwitch.isC(this))) { @@ -463,6 +460,9 @@ public class Section extends DelayUnlockDevice { public void axleCounterOccupy(boolean right) { this.trainRight = right; this.setNctOccupied(true); + if (isSwitchAxleCounterSection()) { + nctOccupiedBySwitchPosition(); + } } /** @@ -764,10 +764,19 @@ public class Section extends DelayUnlockDevice { } public void nonCommunicateTrainOccupy(boolean right) { - this.trainRight = right; - this.setNctOccupied(true); -// this.nctOccupied = true; -// setCtOccupied(false); + VirtualRealitySectionAxleCounter axle = findAxle(); + if (axle != null && axle.isOccupy()) { + this.trainRight = right; + this.setNctOccupied(true); + } + } + + public VirtualRealitySectionAxleCounter findAxle() { + VirtualRealitySectionAxleCounter axle = this.virtualAxleCounter; + if (axle == null && this.parent != null) { + return this.parent.findAxle(); + } + return axle; } public boolean isOccupiedOn(boolean right) { @@ -813,24 +822,7 @@ public class Section extends DelayUnlockDevice { } this.setNctOccupied(true); if (this.isSwitchAxleCounterSection()) { // 道岔计轴区段 - List relSwitchList = this.getRelSwitchList(); - for (Switch aSwitch : relSwitchList) { - aSwitch.getA().setNctOccupied(true); - if (aSwitch.isPosN()) { - aSwitch.getB().setNctOccupied(true); - aSwitch.getC().setNctOccupied(false); - } else if (aSwitch.isPosR()) { - aSwitch.getC().setNctOccupied(true); - aSwitch.getB().setNctOccupied(false); - } else { - aSwitch.getB().setNctOccupied(true); - aSwitch.getC().setNctOccupied(true); - } - } - Section cross = queryCross(); - if (cross != null) { - cross.crossJudgeInvalid(); - } + nctOccupiedBySwitchPosition(); } else if (!CollectionUtils.isEmpty(this.logicList)) { for (Section logic : this.logicList) { logic.setNctOccupied(true); @@ -838,6 +830,30 @@ public class Section extends DelayUnlockDevice { } } + /** + * 根据道岔位置设置非通信车占用 + */ + private void nctOccupiedBySwitchPosition() { + List relSwitchList = this.getRelSwitchList(); + for (Switch aSwitch : relSwitchList) { + aSwitch.getA().setNctOccupied(true); + if (aSwitch.isPosN()) { + aSwitch.getB().setNctOccupied(true); + aSwitch.getC().setNctOccupied(false); + } else if (aSwitch.isPosR()) { + aSwitch.getC().setNctOccupied(true); + aSwitch.getB().setNctOccupied(false); + } else { + aSwitch.getB().setNctOccupied(true); + aSwitch.getC().setNctOccupied(true); + } + } + Section cross = queryCross(); + if (cross != null) { + cross.crossJudgeInvalid(); + } + } + /** * 岔心判断失效 */ @@ -1168,6 +1184,23 @@ public class Section extends DelayUnlockDevice { return false; } + /** + * 获取道岔计轴区段被道岔连接起来的区段 + */ + public List
findConnectedSections() { + if (!isSwitchAxleCounterSection()) + return Collections.emptyList(); + Switch relSwitch = getLogicList().get(0).getRelSwitch(); + List
sections = new ArrayList<>(); + sections.add(relSwitch.getA()); + if (relSwitch.isPosN()) { + sections.add(relSwitch.getB()); + } else if (relSwitch.isPosR()) { + sections.add(relSwitch.getC()); + } + return sections; + } + public enum SectionRoadType { /** * 左行线 diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Signal.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Signal.java index ad54689b6..1b18c06c6 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Signal.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Signal.java @@ -440,6 +440,10 @@ public class Signal extends DelayUnlockDevice { return SignalType.TRANSMISSION.equals(this.type); } + public boolean isOutboundSignal() { + return SignalType.OUTBOUND.equals(this.type); + } + public boolean isDepotSameSignal(Signal signal) { return this.type.equals(signal.getType()) || (this.type.equals(SignalType.SHUNTING2) && signal.getType().equals(SignalType.SHUNTING)); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityScreenDoor.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityScreenDoor.java index ef8f8939a..defc7eab4 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityScreenDoor.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/vr/VirtualRealityScreenDoor.java @@ -63,6 +63,24 @@ public class VirtualRealityScreenDoor extends ControllableVrDevice { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/modbustcp/SimulationRealDeviceConnectManager.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/modbustcp/SimulationRealDeviceConnectManager.java index 0d25f3358..5da18a029 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/modbustcp/SimulationRealDeviceConnectManager.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/modbustcp/SimulationRealDeviceConnectManager.java @@ -36,7 +36,7 @@ public class SimulationRealDeviceConnectManager { public void connectDevice(Simulation simulation, String deviceCode, Long projectDeviceId) { RealDeviceConfig realDevice = simulation.getRealDeviceById(projectDeviceId); - MapElement mapElement = simulation.getRepository().getByCode(deviceCode); + MapElement mapElement = simulation.getRepository().findByCode(deviceCode); boolean typeEqual = false; switch (realDevice.getProjectDevice().getType()) { case SWITCH:{ @@ -102,6 +102,7 @@ public class SimulationRealDeviceConnectManager { typeEqual = true; realDevice.connect(vrDevice); } + vrDevice.updateRealDevice(realDevice); break; } case IBP:{ @@ -111,7 +112,18 @@ public class SimulationRealDeviceConnectManager { } if (MapElement.DeviceType.IBP.equals(mapElement.getDeviceType())) { typeEqual = true; - realDevice.connect((VirtualRealityIbp) mapElement); + VirtualRealityIbp vrIbp = (VirtualRealityIbp) mapElement; + realDevice.connect(vrIbp); + vrIbp.updateRealDevice(realDevice); + } + break; + } + case TRAIN:{ + VirtualRealityDevice vrDevice = simulation.getRepository().getVRByCode(deviceCode); + if (MapElement.DeviceType.TRAIN.equals(vrDevice.getDeviceType())) { + typeEqual = true; + realDevice.connect(vrDevice); + vrDevice.updateRealDevice(realDevice); } break; } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSectionConfig.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSectionConfig.java index 89687c6e0..f74097027 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSectionConfig.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSectionConfig.java @@ -1,10 +1,11 @@ -package club.joylink.rtss.simulation.cbtc.device.real.udp.Sr; +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; 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.sr.SrSectionConfigVO; import lombok.Getter; +import lombok.Setter; import java.util.Objects; @@ -12,6 +13,12 @@ import java.util.Objects; public class SrSectionConfig extends RealDeviceConfig { private SrSectionConfigVO configVO; + /** + * 连续无占用次数 + */ + @Setter + private int timesOfRelease; + public SrSectionConfig(ProjectDeviceVO projectDevice) { super(projectDevice); if (Objects.nonNull(projectDevice.getConfig())) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSectionServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSectionServiceImpl.java index e901c7a95..68fc838b4 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSectionServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSectionServiceImpl.java @@ -1,20 +1,40 @@ -package club.joylink.rtss.simulation.cbtc.device.real.udp.Sr; +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; 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.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.UDPClientConfig; import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPLowConfig; import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceService; import io.netty.buffer.ByteBuf; +import lombok.extern.java.Log; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.time.LocalDateTime; +import java.util.Collections; +import java.util.List; import java.util.Map; +import java.util.Objects; +import java.util.function.Function; import java.util.stream.Collectors; +@Slf4j @Service public class SrSectionServiceImpl implements UDPRealDeviceService { + @Autowired + private SrTrainServiceImpl srTrainService; + + @Autowired + private MaService maService; + @Override public boolean isMatch(RealDeviceConfig realDevice) { return realDevice instanceof UDPClientConfig; @@ -26,31 +46,175 @@ public class SrSectionServiceImpl implements UDPRealDeviceService { } @Override - public void init(Simulation simulation, UDPLowConfig udpConfig, RealDeviceConfig realDevice) { - + 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); - if (Byte.toUnsignedInt(data[1]) != 137) + if (Byte.toUnsignedInt(data[1]) != 137) { return; - Map map = simulation.queryAllRealDevice(ProjectDeviceType.SECTION).stream() + } + //处理数据 + Map configMap = simulation.queryAllRealDevice(ProjectDeviceType.SECTION).stream() .map(config -> (SrSectionConfig) config) - .collect(Collectors.toMap(config -> config.getConfigVO().getSandboxCode(), - config -> (VirtualRealitySectionAxleCounter) config.getMapElement())); - for (int i = 3, dataLength = data.length; i < dataLength; i+=2) { + .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]); - VirtualRealitySectionAxleCounter axle = map.get(String.valueOf(code)); + 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) { - axle.setOccupy(false); + config.setTimesOfRelease(config.getTimesOfRelease() + 1); + if (config.getTimesOfRelease() > 3) { //连续4次该计轴都是无占用状态,才视为确实无占用 + config.setTimesOfRelease(0); + axle.clear(); + } + } + } + } + //设置停车信息 + stop(simulation); + } + + /** + * 列车到达特殊轨道,设置延迟停车时间 + */ + private void stop(Simulation simulation) { + for (VirtualRealityTrain train : simulation.getRepository().getOnlineTrainList()) { + Section headSection = train.getHeadPosition().getSection(); + SrTrainConfig config = (SrTrainConfig) train.getRealDevice(); + if (!Objects.equals(headSection, config.getHeadSection())) //列车无需在该站台停车 + continue; + if (config.getTimeOfStop() != null) //已经设置过停车时间 + continue; + boolean right = train.isRight(); + if (!headSection.isFunctionTrack()) + continue; + //设置延时停车时间 + long m = 1000000000; + long nanos = -1; + switch (headSection.getCode()) { //不能以前一个区段无占用作为停车标志的区段 + case "T141": //49G + nanos = (long) (1.0 * m); + break; + case "T1": //1G + nanos = (long) (3.7 * m); + break; + case "T11": + nanos = (long) (3.7 * m); + break; + } + if (nanos != -1) { + config.setTimeOfStop(LocalDateTime.now().plusNanos(nanos)); + continue; + } + //以前一个区段无占用作为停车标志的区段 + Section behindSection = headSection.getNextRunningSectionOf(!right); + if (behindSection == null) + continue; + VirtualRealitySectionAxleCounter axle = behindSection.findAxle(); + if (!axle.isOccupy()) { //前一个区段所属计轴无占用状态 + nanos = 0; + switch (headSection.getCode()) { + case "T5": //1x + nanos = (long) (0.0 * m); + break; + case "T7": //2x + nanos = (long) (0.0 * m); + break; + case "T45": //3x + nanos = (long) (0.0 * m); + break; + case "T53": //4x + nanos = (long) (0.0 * m); + break; + case "T61": //5x + nanos = (long) (0.0 * m); + break; + case "T67": //6x + nanos = (long) (0.0 * m); + break; + case "T33": //1s + nanos = (long) (2.0 * m); + break; + case "T35": //2s + nanos = (long) (2.5 * m); + break; + case "T46": //3s + nanos = (long) (0.0 * m); + break; + case "T54": //4s + nanos = (long) (0.0 * m); + break; + case "T62": //5s + nanos = (long) (0.0 * m); + break; + case "T68": //6s + nanos = (long) (2.0 * m); + break; + } + 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
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 = new SectionPosition(occupiedSection, occupiedSection.getEndOffsetByDirection(!right)); + train.setHeadPosition(headPosition); //更新位置 + if (occupiedSection.isFunctionTrack()) { //功能轨可能需要停车 + SrTrainConfig config = (SrTrainConfig) train.getRealDevice(); + config.updateHeadSection(occupiedSection); + } } } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSignalConfig.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSignalConfig.java index d69e0be3b..4d760ecd9 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSignalConfig.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSignalConfig.java @@ -1,10 +1,13 @@ -package club.joylink.rtss.simulation.cbtc.device.real.udp.Sr; +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; +import club.joylink.rtss.simulation.cbtc.constant.SignalAspect; +import club.joylink.rtss.simulation.cbtc.data.map.Signal; 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.sr.SrSignalConfigVO; import lombok.Getter; +import lombok.Setter; import java.util.Objects; @@ -12,6 +15,9 @@ import java.util.Objects; public class SrSignalConfig extends RealDeviceConfig { private SrSignalConfigVO configVO; + @Setter + private SignalAspect aspect; + public SrSignalConfig(ProjectDeviceVO projectDevice) { super(projectDevice); if (Objects.nonNull(projectDevice.getConfig())) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSignalServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSignalServiceImpl.java index 84e863240..2a50b87ba 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSignalServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSignalServiceImpl.java @@ -1,4 +1,4 @@ -package club.joylink.rtss.simulation.cbtc.device.real.udp.Sr; +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.constant.SignalAspect; @@ -34,12 +34,12 @@ public class SrSignalServiceImpl implements UDPRealDeviceService { if (Objects.equals(aspect, command)) { return; } - if (vrSignal.getRemain() > 0) { + if (vrSignal.isTurning()) { vrSignal.turning(SimulationConstants.VRD_LOOP_RATE); } //控制沙盘设备 aspect = vrSignal.getAspect(); - if (aspect == null || udpLowConfig == null) { + if (aspect == null || udpLowConfig == null || Objects.equals(aspect, config.getAspect())) { return; } byte[] data = buildData(aspect, config); @@ -49,11 +49,11 @@ public class SrSignalServiceImpl implements UDPRealDeviceService { } @Override - public void init(Simulation simulation, UDPLowConfig udpConfig, RealDeviceConfig realDevice) { - SrSignalConfig config = (SrSignalConfig) realDevice; - VirtualRealitySignal vrSignal = (VirtualRealitySignal) config.getMapElement(); - byte[] data = buildData(vrSignal.getAspect(), config); - udpClient.write(udpConfig.getAddr(), data); + public void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) { +// SrSignalConfig config = (SrSignalConfig) realDevice; +// VirtualRealitySignal vrSignal = (VirtualRealitySignal) config.getMapElement(); +// byte[] data = buildData(vrSignal.getAspect(), config); +// udpClient.write(udpLowConfig.getAddr(), data); } @Override @@ -64,6 +64,7 @@ public class SrSignalServiceImpl implements UDPRealDeviceService { private byte[] buildData(SignalAspect aspect, SrSignalConfig config) { if (aspect == null) return null; + config.setAspect(aspect); byte[] data = new byte[5]; data[1] = (byte) 203; data[2] = (byte) Integer.parseInt(config.getConfigVO().getSandboxCode()); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSwitchConfig.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSwitchConfig.java index 22eb03325..c776624ae 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSwitchConfig.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSwitchConfig.java @@ -1,10 +1,12 @@ -package club.joylink.rtss.simulation.cbtc.device.real.udp.Sr; +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; +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.sr.SrSwitchConfigVO; import lombok.Getter; +import lombok.Setter; import java.util.Objects; @@ -12,6 +14,8 @@ import java.util.Objects; public class SrSwitchConfig extends RealDeviceConfig { private SrSwitchConfigVO configVO; + @Setter + private SwitchIndication p; public SrSwitchConfig(ProjectDeviceVO projectDevice) { super(projectDevice); if (Objects.nonNull(projectDevice.getConfig())) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSwitchServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSwitchServiceImpl.java index 118ea40c3..410450b57 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSwitchServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSwitchServiceImpl.java @@ -1,4 +1,4 @@ -package club.joylink.rtss.simulation.cbtc.device.real.udp.Sr; +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; @@ -12,6 +12,8 @@ import io.netty.buffer.ByteBuf; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.Objects; + @Service public class SrSwitchServiceImpl implements UDPRealDeviceService { @Autowired @@ -27,12 +29,12 @@ public class SrSwitchServiceImpl implements UDPRealDeviceService { SrSwitchConfig config = (SrSwitchConfig) realDevice; //控制vr设备 VirtualRealitySwitch vrSwitch = (VirtualRealitySwitch) realDevice.getMapElement(); - if (vrSwitch.getRemain() > 0) { + if (vrSwitch.isTurning()) { vrSwitch.turning(SimulationConstants.VRD_LOOP_RATE); } //控制沙盘设备 SwitchIndication p = vrSwitch.getP(); - if (p == null || udpLowConfig == null) { + if (p == null || udpLowConfig == null || Objects.equals(p, config.getP())) { return; } byte[] data = buildData(p, config); @@ -42,8 +44,20 @@ public class SrSwitchServiceImpl implements UDPRealDeviceService { } @Override - public void init(Simulation simulation, UDPLowConfig udpConfig, RealDeviceConfig realDevice) { - + public void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) { +// SrSwitchConfig config = (SrSwitchConfig) realDevice; +// //控制vr设备 +// VirtualRealitySwitch vrSwitch = (VirtualRealitySwitch) realDevice.getMapElement(); +// if (vrSwitch.getRemain() > 0) { +// vrSwitch.turning(SimulationConstants.VRD_LOOP_RATE); +// } +// //控制沙盘设备 +// SwitchIndication p = vrSwitch.getP(); +// if (p == null || udpLowConfig == null) { +// return; +// } +// byte[] data = buildData(p, config); +// udpClient.write(udpLowConfig.getAddr(), data); } @Override @@ -54,6 +68,7 @@ public class SrSwitchServiceImpl implements UDPRealDeviceService { private byte[] buildData(SwitchIndication p, SrSwitchConfig config) { if (p == null) return null; + config.setP(p); byte[] data = new byte[4]; data[1] = (byte) 208; data[2] = (byte) Integer.parseInt(config.getConfigVO().getSandboxCode()); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainConfig.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainConfig.java new file mode 100644 index 000000000..98d94f6bd --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainConfig.java @@ -0,0 +1,51 @@ +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; + +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.sr.SrSwitchConfigVO; +import club.joylink.rtss.vo.client.project.sr.SrTrainConfigVO; +import lombok.Getter; +import lombok.Setter; +import org.apache.ibatis.annotations.Update; + +import java.time.LocalDateTime; +import java.util.Objects; + +@Getter +public class SrTrainConfig extends RealDeviceConfig { + private SrTrainConfigVO configVO; + + @Setter + private Integer gear; + + /** + * 列车需要在这个轨道停车 + */ + private Section headSection; + + /** + * 列车在headSection停车的时间 + */ + @Setter + private LocalDateTime timeOfStop; + + /** + * 人为驾驶的档位 + */ + @Setter + private Integer manualGear; + + public void updateHeadSection(Section headSection) { + this.headSection = headSection; + this.timeOfStop = null; + } + + public SrTrainConfig(ProjectDeviceVO projectDevice) { + super(projectDevice); + if (Objects.nonNull(projectDevice.getConfig())) { + this.configVO = JsonUtils.read(projectDevice.getConfig(), SrTrainConfigVO.class); + } + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainController.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainController.java new file mode 100644 index 000000000..52680642c --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainController.java @@ -0,0 +1,19 @@ +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; + +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/sr") +public class SrTrainController { + @Autowired + private SrTrainServiceImpl srTrainService; + + @PutMapping("/{simulationId}/control") + public void control(@PathVariable String simulationId, String groupNumber, int gear) { + srTrainService.control(simulationId, groupNumber, gear); + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainServiceImpl.java new file mode 100644 index 000000000..f530320b9 --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainServiceImpl.java @@ -0,0 +1,243 @@ +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; + +import club.joylink.rtss.simulation.cbtc.ATS.operation.AtsOperationDispatcher; +import club.joylink.rtss.simulation.cbtc.ATS.operation.Operation; +import club.joylink.rtss.simulation.cbtc.GroupSimulationService; +import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; +import club.joylink.rtss.simulation.cbtc.data.CalculateService; +import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; +import club.joylink.rtss.simulation.cbtc.data.map.Section; +import club.joylink.rtss.simulation.cbtc.data.plan.TripPlan; +import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition; +import club.joylink.rtss.simulation.cbtc.data.vo.TrainInfo; +import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain; +import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig; +import club.joylink.rtss.simulation.cbtc.device.real.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.member.SimulationMember; +import club.joylink.rtss.simulation.cbtc.onboard.ATO.SpeedCurve; +import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPService; +import io.netty.buffer.ByteBuf; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +@Slf4j +@Service +public class SrTrainServiceImpl implements UDPRealDeviceService { + @Autowired + private UDPClient udpClient; + + @Autowired + private ATPService atpService; + + @Autowired + private AtsOperationDispatcher atsOperationDispatcher; + + @Autowired + private GroupSimulationService groupSimulationService; + + @Override + public boolean isMatch(RealDeviceConfig realDevice) { + return realDevice instanceof SrTrainConfig; + } + + @Override + public void control(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) { + SrTrainConfig config = (SrTrainConfig) realDevice; + //控制vr设备 + VirtualRealityTrain train = (VirtualRealityTrain) config.getMapElement(); + if (simulation.getRepository().isVrTrainOnline(train.getGroupNumber())) { + change2RMWhenStopAtPlanEnd(simulation, train); + trainRunning(simulation, train, config); + if (train.getDelayTime() > 3000) { + train.setDelayTime(3000); + } + //控制沙盘设备 + byte[] data = buildData(train, config); + udpClient.write(udpLowConfig.getAddr(), data); + } + } + + /** + * 当到达计划终点时,将列车驾驶模式转为RM + */ + private void change2RMWhenStopAtPlanEnd(Simulation simulation, VirtualRealityTrain train) { + if (!train.isStop()) + return; + if (!train.getHeadPosition().getSection().isTransferTrack()) //不是转换轨 + return; + SimulationDataRepository repository = simulation.getRepository(); + String groupNumber = train.getGroupNumber(); + TrainInfo trainInfo = repository.getSupervisedTrainByGroup(groupNumber); + if (!trainInfo.isPlanTrain()) + return; + TripPlan tripPlan = repository.getTripPlan(trainInfo.getServiceNumber(), trainInfo.getTripNumber()); + if (!Objects.equals(train.getHeadPosition().getSection(), tripPlan.getEndSection())) //不是计划最后一个区段 + return; + TripPlan nextTripPlan = repository.queryServiceNextTripPlan(trainInfo.getServiceNumber(), trainInfo.getTripNumber()); + if (nextTripPlan != null) + return; + //无下一计划(要回车辆段) + VirtualRealityTrain.PreselectionMode preselectionMode = VirtualRealityTrain.PreselectionMode.RM; + VirtualRealityTrain.PreselectionMode trainMode = train.getPreselectionMode(); + if (trainMode == preselectionMode) //已是RM + return; + VirtualRealityTrain.PreselectionMode tempMode = train.getTempPreselectionMode(); + SimulationMember driver = simulation.getSimulationMembersByDevice(train).get(0); + Map params = new HashMap<>(); + String operation; + params.put("groupNumber", groupNumber); + if (tempMode != preselectionMode) { //临时级别不对 + if (preselectionMode.isHigherThan(tempMode)) { + operation = Operation.Type.Driver_Preselection_Mode_Up.name(); + } else { + operation = Operation.Type.Driver_Preselection_Mode_Down.name(); + } + } else { + operation = Operation.Type.Driver_Confirm.name(); + } + atsOperationDispatcher.execute(simulation, driver, operation, params); + } + + @Override + public void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) { + SrTrainConfig config = (SrTrainConfig) realDevice; + //控制vr设备 + VirtualRealityTrain train = (VirtualRealityTrain) config.getMapElement(); + //控制沙盘设备 + byte[] data = buildData(train, config); + udpClient.write(udpLowConfig.getAddr(), data); + //清除状态 + config.updateHeadSection(null); + } + + @Override + public void handle(Simulation simulation, ByteBuf msg) { + + } + + private void trainRunning(Simulation simulation, VirtualRealityTrain train, SrTrainConfig config) { + //判断到停车时间,将列车位置更新到停车点 + boolean right = train.isRight(); + SectionPosition headPosition = train.getHeadPosition(); + Section headSection = headPosition.getSection(); + if (Objects.equals(headSection, config.getHeadSection())) { + LocalDateTime timeOfStop = config.getTimeOfStop(); + if (timeOfStop != null && LocalDateTime.now().isAfter(timeOfStop)) { + headPosition = headSection.buildStopPointPosition(right); + train.setHeadPosition(headPosition); + config.updateHeadSection(null); + System.out.println(train.debugStr() + "触发停车时间:" + LocalDateTime.now()); + } + } + //更新速度 + SimulationDataRepository repository = simulation.getRepository(); + SectionPosition tailPosition = train.calculateTailPosition(); + float speed = train.getSpeed(); + float newSpeed; + if (train.isAMMode() || train.isCMMode()) { + newSpeed = train.getAtoSpeed(); + } else { + SectionPosition targetPosition = train.getRobotTargetPosition(); + if (targetPosition == null) { + newSpeed = 0; + } else { + float recommendedSpeedMax; + if (train.isRMMode()) { + recommendedSpeedMax = Math.min(repository.getConfig().getRmAtpSpeed(), train.getSpeedLimit()) * 0.9f; + } else if (train.isNRMMode()) { + recommendedSpeedMax = Math.min(repository.getConfig().getUrmAtpSpeed(), train.getSpeedLimit()) * 0.9f; + } else { + recommendedSpeedMax = 0; + } + Float distance = CalculateService.calculateDistance(headPosition, targetPosition, right); + if (distance == null || distance <= SimulationConstants.PARK_POINT_MAX_OFFSET) { //如果列车已经抵达或越过目标位置 + newSpeed = 0; + } else { + SpeedCurve speedCurve = SpeedCurve.buildTargetSpeedCurve(headPosition, tailPosition, right, + distance, speed, recommendedSpeedMax); + newSpeed = speedCurve.getSpeedOf(speedCurve.getTotalDistance()); + } + } + } + if (newSpeed == 0) { + train.setSpeed(0); + } else { + newSpeed = 20f / 3.6f; + } + Float speedMax = null; + if (headSection.isStandTrack()) { //车头在站台轨 + speedMax = 10f / 3.6f; + } else { + //(车尾未离开站台轨) + Section behindStandTrack = null; + Section behindSection = headSection; + for (int i = 0; i < 5; i++) { + behindSection = behindSection.getNextRunningSectionOf(!right); + if (behindSection == null) + break; + if (behindSection.isStandTrack()) { + behindStandTrack = behindSection; + break; + } + } + if (behindStandTrack != null && behindStandTrack.isOccupied()) { + speedMax = 10f / 3.6f; + } + } + if (speedMax != null) { + train.setSpeed(Math.min(newSpeed, speedMax)); + } else { + train.setSpeed(newSpeed); + } + } + + private byte[] buildData(VirtualRealityTrain train, SrTrainConfig config) { + int gear; + if (train.isStop()) { + gear = 0; + } else { + float speedKmPh = train.getSpeedKmPh(); + if (train.isStop()) { + gear = 0; + } else { + gear = (int) Math.ceil(speedKmPh / 10); + gear = Math.max(1, gear); + } + if (train.isRight()) { + gear += 5; + } + } + if (Objects.equals(config.getGear(), gear)) { + return null; + } + config.setGear(gear); + byte[] data = new byte[4]; + data[1] = (byte) 1; + data[2] = (byte) Integer.parseInt(config.getConfigVO().getSandboxCode()); + data[3] = (byte) gear; + return data; + } + + public void control(String simulationId, String groupNumber, int gear) { + Simulation simulation = groupSimulationService.getSimulationByGroup(simulationId); + List realDeviceList = simulation.getRealDeviceList(); + for (RealDeviceConfig realDevice : realDeviceList) { + if (realDevice instanceof SrTrainConfig) { + SrTrainConfig config = (SrTrainConfig) realDevice; + VirtualRealityTrain train = (VirtualRealityTrain) config.getMapElement(); + train.setRobotTargetPosition(null); //终止机器人司机驾驶 + config.setManualGear(gear / 10); + } + } + } +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPClient.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPClient.java index f4cbf59dd..c1bbc8620 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPClient.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPClient.java @@ -10,15 +10,18 @@ import io.netty.channel.ChannelInitializer; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.DatagramPacket; import io.netty.channel.socket.nio.NioDatagramChannel; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; +import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; +import java.util.concurrent.ConcurrentLinkedQueue; @Component @Slf4j @@ -28,6 +31,8 @@ public class UDPClient implements ApplicationRunner { private Channel channel; + private final ConcurrentLinkedQueue msgQueue = new ConcurrentLinkedQueue<>(); + @Override public void run(ApplicationArguments args) throws Exception { this.start(); @@ -46,31 +51,40 @@ public class UDPClient implements ApplicationRunner { ChannelFuture future = bootstrap.bind(udpConfig.getClientPort()).sync(); Channel channel = future.channel(); this.channel = channel; - if(future.isSuccess()) { + 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(byte[] ip, int port, byte[] msg) { - try { - if (channel != null && channel.isWritable()) { - InetAddress inetAddress = InetAddress.getByAddress(ip); - InetSocketAddress addr = new InetSocketAddress(inetAddress, port); - write(addr, msg); - } - } catch (UnknownHostException e) { - e.printStackTrace(); - } - } - public void write(InetSocketAddress addr, byte[] msg) { - if (channel != null && channel.isWritable() && addr != null) { - ByteBuf byteBuf = Unpooled.copiedBuffer(msg); - DatagramPacket data = new DatagramPacket(byteBuf, addr); - channel.writeAndFlush(data); + msgQueue.add(new Msg(addr, msg)); + } + + @Scheduled(fixedRate = 10) + 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); } } + @Getter + class Msg { + private InetSocketAddress addr; + + private byte[] data; + + public Msg(InetSocketAddress addr, byte[] data) { + this.addr = addr; + this.data = data; + } + } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPLowConfig.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPLowConfig.java index c4f97b766..6685d0845 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPLowConfig.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPLowConfig.java @@ -12,14 +12,15 @@ import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.UnknownHostException; -@Getter public class UDPLowConfig extends RealDeviceConfig { + @Getter private UDPLowConfigVO configVO; private byte[] ip; private Integer port; + @Getter private InetSocketAddress addr; public UDPLowConfig(ProjectDeviceVO projectDevice) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPRealDeviceService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPRealDeviceService.java index 727d4b98a..3be503bb0 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPRealDeviceService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPRealDeviceService.java @@ -9,7 +9,7 @@ public interface UDPRealDeviceService { void control(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice); - void init(Simulation simulation, UDPLowConfig udpConfig, RealDeviceConfig realDevice); + void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice); void handle(Simulation simulation, ByteBuf msg); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPRealDeviceThread.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPRealDeviceThread.java index fb0fc3d16..c933d63d8 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPRealDeviceThread.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPRealDeviceThread.java @@ -63,7 +63,7 @@ public class UDPRealDeviceThread { } for (RealDeviceConfig config : realDeviceList) { for (UDPRealDeviceService service : serviceList) { - if (service.isMatch(config)) { + if (service.isMatch(config) && config.getMapElement() != null) { service.control(simulation, udpLowConfig, config); } } @@ -84,7 +84,6 @@ public class UDPRealDeviceThread { udpRealDeviceService.handle(simulation, data); } } - break; } } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/handler/UDPMessageHandler.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/handler/UDPMessageHandler.java index 83b71e286..1df8d60f8 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/handler/UDPMessageHandler.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/handler/UDPMessageHandler.java @@ -22,8 +22,5 @@ public class UDPMessageHandler extends SimpleChannelInboundHandler trainList = simulation.getRepository().getOnlineTrainList(); - trainList.forEach(train -> this.trainRunning(simulation,train)); + trainList.forEach(train -> { + if (!train.isConnectReal()) { + this.trainRunning(simulation, train); + } + }); } /** @@ -57,8 +61,6 @@ public class VRTrainRunningService { float fr = (float) (2.27 + 0.00156f * originSpeed * 3.6); // 基本阻力 float f = train.getFk() - train.getFb() - fr; // 合力 float a = f / train.getMass(); // f=ma, a = f/m -// System.out.println(String.format("fk-[%s], fb-[%s], fr-[%s], f-[%s], a[%s]", -// train.getFk(), train.getFb(), fr, f, a)); float time = SimulationModule.TR.getRateS(); float increment = a * time; // 现在的速度 @@ -66,14 +68,6 @@ public class VRTrainRunningService { if (currentSpeed < 0) { currentSpeed = 0; } -// else if (currentSpeed > train.getSpeedMax()) { -// currentSpeed = train.getSpeedMax(); -// } - // 更新列车速度 - -// System.out.println(String.format("当前车速:[%s]", currentSpeed)); - // 根据速度计算并更新列车所在区段位置 -// float s = (float) (currentSpeed * time - acceleration * Math.pow(time, 2) / 2); float s; if (VirtualRealityTrain.Handwheel.REVERSE.equals(train.getGear())) { // 倒车挡 currentSpeed = Math.min(train.getReverseSpeedMax(), currentSpeed); @@ -92,7 +86,6 @@ public class VRTrainRunningService { boolean right = train.isRight(); SectionPosition headPosition = train.getHeadPosition(); SectionPosition headPositionNew = CalculateService.calculateNextPositionByStartAndLen(headPosition, right, s); - // todo 碰撞检测?如果撞车,不修改位置 //更新车头区段(不会碰撞才更新) boolean change = true; for (VirtualRealityTrain aTrain : simulation.getRepository().getOnlineTrainList()) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATP/ATPLogicLoop.java b/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATP/ATPLogicLoop.java index 11437cc98..3e8266cc2 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATP/ATPLogicLoop.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATP/ATPLogicLoop.java @@ -1,5 +1,6 @@ package club.joylink.rtss.simulation.cbtc.onboard.ATP; +import club.joylink.rtss.constants.Project; import club.joylink.rtss.simulation.cbtc.ATP.ground.MaService; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.constant.DriveMode; @@ -7,6 +8,7 @@ import club.joylink.rtss.simulation.cbtc.constant.RunLevel; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; import club.joylink.rtss.simulation.cbtc.constant.SimulationModule; import club.joylink.rtss.simulation.cbtc.data.CalculateService; +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.Signal; import club.joylink.rtss.simulation.cbtc.data.map.Stand; @@ -66,10 +68,10 @@ public class ATPLogicLoop { * 更新列车运行级别 */ private void updateRunLevel(Simulation simulation, VirtualRealityTrain train, VirtualRealityTrain.PreselectionMode preselectionMode) { -// //如果当前级别高于预选,降至IL -// if (!preselectionMode.isMatchTheRunLevel(train.getRunLevel())) { -// atpService.updateRunLevel(train, RunLevel.IL, preselectionMode); -// } + //如果当前级别高于预选,降至IL + if (!preselectionMode.isMatchTheRunLevel(train.getRunLevel())) { + atpService.updateRunLevel(train, RunLevel.IL, preselectionMode); + } RunLevel defaultRunLevel = simulation.getRepository().getConfig().getRunMode(); //更新移动授权丢失时长 @@ -140,7 +142,7 @@ public class ATPLogicLoop { // this.sendStopMessage2GroundAtp(simulation, train); // // 检查列车是否在转换轨 // this.checkOnTransferAndSend2Ats(simulation, train, headPosition, tailPosition); - if (!train.isBreaking()) { // 制动状态 + if (!train.isBreaking() && !train.isRMMode() && !train.isNRMMode()) { // 制动状态 // 施加常规制动,防止倒溜 this.atoService.openBreaking(train); } @@ -153,6 +155,10 @@ public class ATPLogicLoop { if (train.isRMMode() && train.isLeverNotInTractionGear()) { //停车、RM模式、操纵杆非牵引位 atpService.cancelSignalEB(train); } + if (Project.SR_SANDBOX.name().equals(simulation.getBuildParams().getMap().getProjectCode())) { + atpService.cancelSignalEB(train); + atpService.openATO(train); + } } if (this.checkConditionToMove2(simulation, train)) { // 可以启动 @@ -268,13 +274,14 @@ public class ATPLogicLoop { private void handlePreselectionMode(Simulation simulation, VirtualRealityTrain train) { VirtualRealityTrain.PreselectionMode preselectionMode = train.getPreselectionMode(); + MapConfig config = simulation.getRepository().getConfig(); switch (preselectionMode) { case AM_C: - if (!train.isCBTC()) + if (!train.isCBTC() && config.getRunMode().isNotLowerThan(RunLevel.CBTC)) train.setCommunication(true); break; case SM_C: - if (!train.isCBTC()) + if (!train.isCBTC() && config.getRunMode().isNotLowerThan(RunLevel.CBTC)) train.setCommunication(true); atpService.closeATO(train); break; diff --git a/src/main/java/club/joylink/rtss/vo/client/project/ProjectDeviceVO.java b/src/main/java/club/joylink/rtss/vo/client/project/ProjectDeviceVO.java index 790d0c942..ad9239fdd 100644 --- a/src/main/java/club/joylink/rtss/vo/client/project/ProjectDeviceVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/project/ProjectDeviceVO.java @@ -15,12 +15,14 @@ import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.richor.ZjdPslConf 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.xty.XtyPsdConfig; -import club.joylink.rtss.simulation.cbtc.device.real.udp.Sr.SrSectionConfig; -import club.joylink.rtss.simulation.cbtc.device.real.udp.Sr.SrSignalConfig; -import club.joylink.rtss.simulation.cbtc.device.real.udp.Sr.SrSwitchConfig; +import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.SrSectionConfig; +import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.SrSignalConfig; +import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.SrSwitchConfig; 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.sr.SrTrainConfig; import club.joylink.rtss.util.JsonUtils; +import club.joylink.rtss.vo.client.project.sr.SrTrainConfigVO; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Getter; import lombok.NoArgsConstructor; @@ -143,6 +145,9 @@ public class ProjectDeviceVO { case SWITCH: list.add(new SrSwitchConfig(deviceVO)); break; + case TRAIN: + list.add(new SrTrainConfig(deviceVO)); + break; } } return list; diff --git a/src/main/java/club/joylink/rtss/vo/client/project/sr/SrSectionConfigVO.java b/src/main/java/club/joylink/rtss/vo/client/project/sr/SrSectionConfigVO.java index e85e69198..f4e423aae 100644 --- a/src/main/java/club/joylink/rtss/vo/client/project/sr/SrSectionConfigVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/project/sr/SrSectionConfigVO.java @@ -12,8 +12,14 @@ public class SrSectionConfigVO { private String sandboxCode; - public SrSectionConfigVO(String vrCode, String sandboxCode) { + /** + * 延迟停车时间/ns + */ + private Long time; + + public SrSectionConfigVO(String vrCode, String sandboxCode, Long time) { this.vrCode = vrCode; this.sandboxCode = sandboxCode; + this.time = time; } } diff --git a/src/main/java/club/joylink/rtss/vo/client/project/sr/SrTrainConfigVO.java b/src/main/java/club/joylink/rtss/vo/client/project/sr/SrTrainConfigVO.java new file mode 100644 index 000000000..913b4993a --- /dev/null +++ b/src/main/java/club/joylink/rtss/vo/client/project/sr/SrTrainConfigVO.java @@ -0,0 +1,19 @@ +package club.joylink.rtss.vo.client.project.sr; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class SrTrainConfigVO { + private String vrCode; + + private String sandboxCode; + + public SrTrainConfigVO(String vrCode, String sandboxCode) { + this.vrCode = vrCode; + this.sandboxCode = sandboxCode; + } +} diff --git a/src/main/java/club/joylink/rtss/vo/client/runplan/RunPlanTripVO.java b/src/main/java/club/joylink/rtss/vo/client/runplan/RunPlanTripVO.java index 67c5b5a7a..8705527d4 100644 --- a/src/main/java/club/joylink/rtss/vo/client/runplan/RunPlanTripVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/runplan/RunPlanTripVO.java @@ -123,8 +123,8 @@ public class RunPlanTripVO { public RunPlanTripVO(RunPlanRoutingVO routingVO) { this.right = routingVO.getRight(); - this.isOutbound = routingVO.isInBoundRoute(); - this.isInbound = routingVO.isOutBoundRoute(); + this.isOutbound = routingVO.isOutBoundRoute(); + this.isInbound = routingVO.isInBoundRoute(); this.destinationCode = Objects.isNull(routingVO.getDestinationCode()) ? "" : routingVO.getDestinationCode(); this.startSectionCode = routingVO.getStartSectionCode(); this.endSectionCode = routingVO.getEndSectionCode(); diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index d5f529687..d42397f18 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -167,7 +167,7 @@ common: spring: profiles: local 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.0.254:3306/joylink?useSSL=false&characterEncoding=utf-8&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true username: root password: localdb From d9bab161d15aba4885018fe1a917bb189b0746a9 Mon Sep 17 00:00:00 2001 From: thesai <1021828630@qq.com> Date: Mon, 8 Nov 2021 14:44:32 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E9=94=81=E9=97=AD=E9=81=93=E5=B2=94?= =?UTF-8?q?=E7=9A=84=E8=BF=9B=E8=B7=AF=E6=94=B9=E4=B8=BASet=E4=BB=A5?= =?UTF-8?q?=E9=81=BF=E5=85=8D=E5=90=8C=E4=B8=80=E8=BF=9B=E8=B7=AF=E5=A4=9A?= =?UTF-8?q?=E6=AC=A1=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../joylink/rtss/simulation/cbtc/CI/CiApiServiceImpl2.java | 7 ++----- .../club/joylink/rtss/simulation/cbtc/data/map/Switch.java | 7 ++----- .../simulation/cbtc/data/storage/device/StorageSwitch.java | 7 ++++--- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiServiceImpl2.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiServiceImpl2.java index b45c41bfe..81d9d2417 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiServiceImpl2.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/CiApiServiceImpl2.java @@ -15,10 +15,7 @@ import org.springframework.util.CollectionUtils; import org.springframework.util.StringUtils; import java.time.LocalTime; -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; -import java.util.Optional; +import java.util.*; import java.util.stream.Collectors; /** @@ -250,7 +247,7 @@ public class CiApiServiceImpl2 implements CiApiService { if (!aSwitch.isLocked() && aSwitch.getAllSections().stream().noneMatch(Section::isLocked)) return; List lockedRouteList = simulation.getRepository().queryAllLockedRoute(); - List lockSwitchRoutes = new ArrayList<>(); + Set lockSwitchRoutes = new HashSet<>(); if (aSwitch.isRouteLock()) { lockSwitchRoutes = aSwitch.getRoutes(); } else if (aSwitch.isOverlapLock()) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Switch.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Switch.java index b74ee6dad..1e199cedd 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Switch.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Switch.java @@ -5,10 +5,7 @@ import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch; import lombok.Getter; import lombok.Setter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; +import java.util.*; import java.util.stream.Collectors; /** @@ -75,7 +72,7 @@ public class Switch extends DelayUnlockDevice { /** * 锁闭该道岔的进路 */ - private final List routes = new ArrayList<>(); + private final Set routes = new HashSet<>(); /** * 是否进路侧防锁闭 diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/device/StorageSwitch.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/device/StorageSwitch.java index 8fe963fed..4626ef834 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/device/StorageSwitch.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/device/StorageSwitch.java @@ -17,6 +17,7 @@ import lombok.Setter; import org.springframework.util.CollectionUtils; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; @Getter @@ -47,7 +48,7 @@ public class StorageSwitch extends StorageDelayUnlockDevice { private String route; - private List routes; + private Set routes; /** * 是否进路侧防锁闭 @@ -106,10 +107,10 @@ public class StorageSwitch extends StorageDelayUnlockDevice { // change = true; // storageSwitch.setRoute(route.getCode()); // } - List routes = s.getRoutes(); + Set routes = s.getRoutes(); if (!CollectionUtils.isEmpty(routes)) { change = true; - List routeCodes = routes.stream().map(MapElement::getCode).collect(Collectors.toList()); + Set routeCodes = routes.stream().map(MapElement::getCode).collect(Collectors.toSet()); storageSwitch.setRoutes(routeCodes); } if (s.isFpLock()) { From 187d91ce08277d810520d189be1a926ff9bc2515 Mon Sep 17 00:00:00 2001 From: thesai <1021828630@qq.com> Date: Mon, 8 Nov 2021 16:50:16 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BD=ACNRM=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F=E6=8C=87=E4=BB=A4=EF=BC=9B=E4=B8=8A=E9=A5=B6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E6=8E=A7=E5=88=B6=E5=88=97=E8=BD=A6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectJointSimulationServiceImpl.java | 8 ++-- .../simulation/cbtc/command/CommandBO.java | 24 ++++++++++ .../real/udp/Sr/SrTrainControlParam.java | 22 ++++++++++ .../device/real/udp/Sr/SrTrainController.java | 16 ++++--- .../udp/Sr/{ => config}/SrSectionConfig.java | 2 +- .../udp/Sr/{ => config}/SrSignalConfig.java | 2 +- .../udp/Sr/{ => config}/SrSwitchConfig.java | 2 +- .../udp/Sr/{ => config}/SrTrainConfig.java | 2 +- .../{ => service}/SrSectionServiceImpl.java | 6 +-- .../Sr/{ => service}/SrSignalServiceImpl.java | 3 +- .../Sr/{ => service}/SrSwitchServiceImpl.java | 3 +- .../Sr/{ => service}/SrTrainServiceImpl.java | 44 ++++++++++++------- .../cbtc/onboard/ATP/ATPService.java | 2 + .../vo/client/project/ProjectDeviceVO.java | 9 ++-- 14 files changed, 106 insertions(+), 39 deletions(-) create mode 100644 src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainControlParam.java rename src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/{ => config}/SrSectionConfig.java (91%) rename src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/{ => config}/SrSignalConfig.java (92%) rename src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/{ => config}/SrSwitchConfig.java (92%) rename src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/{ => config}/SrTrainConfig.java (95%) rename src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/{ => service}/SrSectionServiceImpl.java (97%) rename src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/{ => service}/SrSignalServiceImpl.java (96%) rename src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/{ => service}/SrSwitchServiceImpl.java (95%) rename src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/{ => service}/SrTrainServiceImpl.java (85%) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ProjectJointSimulationServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ProjectJointSimulationServiceImpl.java index 0ec86a61e..0c4d91aec 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ProjectJointSimulationServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ProjectJointSimulationServiceImpl.java @@ -17,11 +17,11 @@ import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.heb.device.Heb1Ps import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.richor.ZjdIbpConfig; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.richor.ZjdPslConfig; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.xty.XtyPsdConfig; -import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.SrSectionConfig; -import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.SrSignalConfig; -import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.SrSwitchConfig; +import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrSectionConfig; +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.UDPRealDeviceThread; -import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.SrTrainConfig; +import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrTrainConfig; import club.joylink.rtss.simulation.cbtc.event.SimulationUserEnterEvent; import club.joylink.rtss.simulation.cbtc.member.MemberManager; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/command/CommandBO.java b/src/main/java/club/joylink/rtss/simulation/cbtc/command/CommandBO.java index a7729d12a..54652b7dd 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/command/CommandBO.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/command/CommandBO.java @@ -516,6 +516,9 @@ public class CommandBO { public Step execute(Simulation simulation, CommandBO command) { SimulationMember driver = command.getTargetMember(); VirtualRealityTrain train = (VirtualRealityTrain) driver.getDevice(); + if (!train.isAtpOn()) { + return buildDriverATPChangeOperationStep(train.getGroupNumber(), false); + } if (train.isSignalEB()) { return getStep4ReleaseEB(train); } @@ -531,6 +534,27 @@ public class CommandBO { } return null; } + }, + + /** + * 转NRM模式 + */ + Apply_NRM(List.of(), SimulationMember.Type.DRIVER) { + @Override + public List buildStepList(Simulation simulation, SimulationMember targetMember, Map params) { + return Collections.emptyList(); + } + + @Override + public Step execute(Simulation simulation, CommandBO command) { + SimulationMember driver = command.getTargetMember(); + VirtualRealityTrain train = (VirtualRealityTrain) driver.getDevice(); + if (train.isNRMMode()) { + driver.setCommand(null); + return null; + } + return buildDriverATPChangeOperationStep(train.getGroupNumber(), true); + } }; public enum ParamName { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainControlParam.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainControlParam.java new file mode 100644 index 000000000..5d489484a --- /dev/null +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainControlParam.java @@ -0,0 +1,22 @@ +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Getter +@Setter +@NoArgsConstructor +public class SrTrainControlParam { + @NotBlank(message = "车组号不能为空") + private String groupNumber; + + @NotNull(message = "方向不能为null") + private Boolean right; + + @NotNull(message = "速度不能为null") + private Integer speed; +} diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainController.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainController.java index 52680642c..8cb0c7579 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainController.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainController.java @@ -1,10 +1,9 @@ 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.PathVariable; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.*; @RestController @RequestMapping("/api/sr") @@ -12,8 +11,13 @@ 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, int gear) { - srTrainService.control(simulationId, groupNumber, gear); + public void control(@PathVariable String simulationId, String groupNumber, boolean right, int speed) { + srTrainService.control(simulationId, groupNumber, right, speed); } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSectionConfig.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/config/SrSectionConfig.java similarity index 91% rename from src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSectionConfig.java rename to src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/config/SrSectionConfig.java index f74097027..c9356c232 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSectionConfig.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/config/SrSectionConfig.java @@ -1,4 +1,4 @@ -package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig; import club.joylink.rtss.util.JsonUtils; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSignalConfig.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/config/SrSignalConfig.java similarity index 92% rename from src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSignalConfig.java rename to src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/config/SrSignalConfig.java index 4d760ecd9..9bacf6825 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSignalConfig.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/config/SrSignalConfig.java @@ -1,4 +1,4 @@ -package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config; import club.joylink.rtss.simulation.cbtc.constant.SignalAspect; import club.joylink.rtss.simulation.cbtc.data.map.Signal; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSwitchConfig.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/config/SrSwitchConfig.java similarity index 92% rename from src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSwitchConfig.java rename to src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/config/SrSwitchConfig.java index c776624ae..4c46fec1a 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSwitchConfig.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/config/SrSwitchConfig.java @@ -1,4 +1,4 @@ -package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config; import club.joylink.rtss.simulation.cbtc.constant.SwitchIndication; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainConfig.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/config/SrTrainConfig.java similarity index 95% rename from src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainConfig.java rename to src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/config/SrTrainConfig.java index 98d94f6bd..f149b1dd3 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainConfig.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/config/SrTrainConfig.java @@ -1,4 +1,4 @@ -package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config; import club.joylink.rtss.simulation.cbtc.data.map.Section; import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDeviceConfig; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSectionServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSectionServiceImpl.java similarity index 97% rename from src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSectionServiceImpl.java rename to src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSectionServiceImpl.java index 68fc838b4..6bee8ddb5 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSectionServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSectionServiceImpl.java @@ -1,19 +1,19 @@ -package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr.service; 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.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.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.sr.config.SrSectionConfig; +import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrTrainConfig; import io.netty.buffer.ByteBuf; -import lombok.extern.java.Log; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSignalServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSignalServiceImpl.java similarity index 96% rename from src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSignalServiceImpl.java rename to src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSignalServiceImpl.java index 2a50b87ba..da338ae30 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSignalServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSignalServiceImpl.java @@ -1,4 +1,4 @@ -package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr.service; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.constant.SignalAspect; @@ -8,6 +8,7 @@ import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDevice import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPClient; import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPLowConfig; import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceService; +import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrSignalConfig; import io.netty.buffer.ByteBuf; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSwitchServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSwitchServiceImpl.java similarity index 95% rename from src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSwitchServiceImpl.java rename to src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSwitchServiceImpl.java index 410450b57..ddfc81570 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrSwitchServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSwitchServiceImpl.java @@ -1,4 +1,4 @@ -package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr.service; import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants; @@ -8,6 +8,7 @@ import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDevice import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPClient; import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPLowConfig; import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceService; +import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrSwitchConfig; import io.netty.buffer.ByteBuf; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrTrainServiceImpl.java similarity index 85% rename from src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainServiceImpl.java rename to src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrTrainServiceImpl.java index f530320b9..0af7d21d5 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrTrainServiceImpl.java @@ -1,5 +1,7 @@ -package club.joylink.rtss.simulation.cbtc.device.real.udp.sr; +package club.joylink.rtss.simulation.cbtc.device.real.udp.sr.service; +import club.joylink.rtss.constants.ProjectDeviceType; +import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.cbtc.ATS.operation.AtsOperationDispatcher; import club.joylink.rtss.simulation.cbtc.ATS.operation.Operation; import club.joylink.rtss.simulation.cbtc.GroupSimulationService; @@ -16,6 +18,7 @@ import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.device.RealDevice import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPClient; import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPLowConfig; import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPRealDeviceService; +import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrTrainConfig; import club.joylink.rtss.simulation.cbtc.member.SimulationMember; import club.joylink.rtss.simulation.cbtc.onboard.ATO.SpeedCurve; import club.joylink.rtss.simulation.cbtc.onboard.ATP.ATPService; @@ -26,7 +29,6 @@ import org.springframework.stereotype.Service; import java.time.LocalDateTime; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.Objects; @@ -56,8 +58,13 @@ public class SrTrainServiceImpl implements UDPRealDeviceService { //控制vr设备 VirtualRealityTrain train = (VirtualRealityTrain) config.getMapElement(); if (simulation.getRepository().isVrTrainOnline(train.getGroupNumber())) { - change2RMWhenStopAtPlanEnd(simulation, train); - trainRunning(simulation, train, config); + if (train.getRobotTargetPosition() != null || train.isAMMode()) { + config.setManualGear(null); + } + if (config.getManualGear() == null) { + change2RMWhenStopAtPlanEnd(simulation, train); + trainRunning(simulation, train, config); + } if (train.getDelayTime() > 3000) { train.setDelayTime(3000); } @@ -136,7 +143,6 @@ public class SrTrainServiceImpl implements UDPRealDeviceService { headPosition = headSection.buildStopPointPosition(right); train.setHeadPosition(headPosition); config.updateHeadSection(null); - System.out.println(train.debugStr() + "触发停车时间:" + LocalDateTime.now()); } } //更新速度 @@ -148,7 +154,8 @@ public class SrTrainServiceImpl implements UDPRealDeviceService { newSpeed = train.getAtoSpeed(); } else { SectionPosition targetPosition = train.getRobotTargetPosition(); - if (targetPosition == null) { + if (targetPosition == null + || (Objects.equals(headSection, targetPosition.getSection()) && !headSection.isFunctionTrack())) { newSpeed = 0; } else { float recommendedSpeedMax; @@ -228,16 +235,23 @@ public class SrTrainServiceImpl implements UDPRealDeviceService { return data; } - public void control(String simulationId, String groupNumber, int gear) { + public void control(String simulationId, String groupNumber, boolean right, int speed) { Simulation simulation = groupSimulationService.getSimulationByGroup(simulationId); - List realDeviceList = simulation.getRealDeviceList(); - for (RealDeviceConfig realDevice : realDeviceList) { - if (realDevice instanceof SrTrainConfig) { - SrTrainConfig config = (SrTrainConfig) realDevice; - VirtualRealityTrain train = (VirtualRealityTrain) config.getMapElement(); - train.setRobotTargetPosition(null); //终止机器人司机驾驶 - config.setManualGear(gear / 10); - } + VirtualRealityTrain train = simulation.getRepository().getOnlineTrainBy(groupNumber); + SrTrainConfig config = (SrTrainConfig) train.getRealDevice(); + if (right != train.isRight()) { //调头 + BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED + .assertTrue(train.getSpeed() == 0, "换端需先停车"); + atpService.turnDirectionImmediately(train); } + train.setRobotTargetPosition(null); //终止机器人司机驾驶 + //加减速 + atpService.changeGear(train, VirtualRealityTrain.Handwheel.MANUAL); + int manualGear = speed / 10; + config.setManualGear(manualGear); + train.setSpeed(speed / 3.6f); + byte[] data = buildData(train, config); + UDPLowConfig udpLowConfig = (UDPLowConfig) simulation.queryOneRealDevice(ProjectDeviceType.UDP_LOW); + udpClient.write(udpLowConfig.getAddr(), data); } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATP/ATPService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATP/ATPService.java index 334edb18a..c715a7217 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATP/ATPService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATP/ATPService.java @@ -175,6 +175,7 @@ public class ATPService { if (train.isAtoOn()) { closeATO(train); } + train.initAsRM(); //简单粗暴 train.setAtpOn(false); train.setSignalEB(false); train.setDriveMode(DriveMode.NRM); @@ -185,6 +186,7 @@ public class ATPService { */ public void openAtp(VirtualRealityTrain train) { train.setAtpOn(true); + train.setDriveMode(DriveMode.RM); } /** diff --git a/src/main/java/club/joylink/rtss/vo/client/project/ProjectDeviceVO.java b/src/main/java/club/joylink/rtss/vo/client/project/ProjectDeviceVO.java index ad9239fdd..fbc657431 100644 --- a/src/main/java/club/joylink/rtss/vo/client/project/ProjectDeviceVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/project/ProjectDeviceVO.java @@ -15,14 +15,13 @@ import club.joylink.rtss.simulation.cbtc.device.real.modbustcp.richor.ZjdPslConf 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.xty.XtyPsdConfig; -import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.SrSectionConfig; -import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.SrSignalConfig; -import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.SrSwitchConfig; +import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrSectionConfig; +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.UDPClientConfig; import club.joylink.rtss.simulation.cbtc.device.real.udp.UDPLowConfig; -import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.SrTrainConfig; +import club.joylink.rtss.simulation.cbtc.device.real.udp.sr.config.SrTrainConfig; import club.joylink.rtss.util.JsonUtils; -import club.joylink.rtss.vo.client.project.sr.SrTrainConfigVO; import com.fasterxml.jackson.annotation.JsonIgnore; import lombok.Getter; import lombok.NoArgsConstructor; From 43bc7d04ce435fd77418013f5afa22a4f31d9dc7 Mon Sep 17 00:00:00 2001 From: Jade Date: Tue, 9 Nov 2021 10:51:34 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E5=89=A7=E6=9C=AC=E6=95=85=E9=9A=9C?= =?UTF-8?q?=E6=93=8D=E4=BD=9C=E6=AD=A5=E9=AA=A4=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/competition/CompetitionAndScriptManager.java | 5 +++-- .../simulation/cbtc/competition/ScriptExecuteService.java | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/competition/CompetitionAndScriptManager.java b/src/main/java/club/joylink/rtss/simulation/cbtc/competition/CompetitionAndScriptManager.java index afa87f2cb..c3751d8d0 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/competition/CompetitionAndScriptManager.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/competition/CompetitionAndScriptManager.java @@ -97,8 +97,9 @@ public class CompetitionAndScriptManager { String content = unfinishedAction.getContent(); unfinishedAction.setContent(String.format(content, currentTime)); } - //如果动作执行者不是机器人 - if (!unfinishedAction.getMember().isRobot()) { + //如果动作执行者不是机器人,且不是故障操作 + if (!unfinishedAction.getMember().isRobot() && !(unfinishedAction.getType().equals(ScriptActionBO.ActionType.Operation) + && unfinishedAction.getOperationType().equals(Set_Fault))) { if (!unfinishedAction.isPrompt()) { applicationContext.publishEvent(new SimulationScriptTipEvent(this, simulation, unfinishedAction)); unfinishedAction.setPrompt(true); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/competition/ScriptExecuteService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/competition/ScriptExecuteService.java index adb3bb85a..375f2ef97 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/competition/ScriptExecuteService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/competition/ScriptExecuteService.java @@ -207,6 +207,11 @@ public class ScriptExecuteService { return; } ScriptActionBO action = script.getNextNeedPassAction(); + // 故障模式不提示 + if (action.getType().equals(ScriptActionBO.ActionType.Operation) + && action.getOperationType().equals(Operation.Type.Set_Fault)) { + return; + } if (!action.getOperationType().equals(operationType) || !action.getOperationParamMap().equals(params)) { applicationContext.publishEvent(new SimulationScriptActionErrorEvent(this, simulation, action)); From 36f9a3beee8721f61c533ed7f1b201d7baac1a51 Mon Sep 17 00:00:00 2001 From: Jade Date: Wed, 10 Nov 2021 13:13:38 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E5=A4=B4=E7=A0=81=E8=BD=A6=E5=88=B0?= =?UTF-8?q?=E7=AB=99=E5=85=88=E5=9B=9E=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../services/completition/CompetitionPracticalService.java | 7 ++++++- .../cbtc/ATS/service/stage/AtsHeadTrainStageService.java | 2 ++ .../vo/client/competition/CompetitionPagedQueryVO.java | 6 ++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/java/club/joylink/rtss/services/completition/CompetitionPracticalService.java b/src/main/java/club/joylink/rtss/services/completition/CompetitionPracticalService.java index 3ab952099..0714c67a4 100644 --- a/src/main/java/club/joylink/rtss/services/completition/CompetitionPracticalService.java +++ b/src/main/java/club/joylink/rtss/services/completition/CompetitionPracticalService.java @@ -44,6 +44,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; +import org.springframework.util.StringUtils; import org.springframework.web.multipart.MultipartFile; import java.time.LocalDateTime; @@ -109,7 +110,11 @@ public class CompetitionPracticalService implements ICompetitionPracticalService @Override public PageVO pagedQueryCompetition(CompetitionPagedQueryVO queryVO) { PageHelper.startPage(queryVO.getPageNum(), queryVO.getPageSize()); - Page page = (Page) this.competitionDAO.selectByExample(null); + CompetitionExample competitionExample = new CompetitionExample(); + if (StringUtils.hasText(queryVO.getName())) { + competitionExample.createCriteria().andNameLike(String.format("%%%s%%", queryVO.getName())); + } + Page page = (Page) this.competitionDAO.selectByExample(competitionExample); List list = page.getResult().stream().map(CompetitionVO::new).collect(Collectors.toList()); return PageVO.convert(page, list); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsHeadTrainStageService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsHeadTrainStageService.java index afde6d42f..eb17ba6a2 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsHeadTrainStageService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/stage/AtsHeadTrainStageService.java @@ -86,6 +86,8 @@ public class AtsHeadTrainStageService implements AtsStageService { * 处理列车到达目的地 */ private void handleArriveDestination(Simulation simulation, TrainInfo trainInfo) { + // 先回库,后设置为人工车 + trainInfo.finishPlanPrepareInbound(); if (simulation.getRepository().getConfig().isSetManualWhenHeadTrainArriveTarget()) { atsTrainService.setManualTrain(simulation, trainInfo.getGroupNumber()); } diff --git a/src/main/java/club/joylink/rtss/vo/client/competition/CompetitionPagedQueryVO.java b/src/main/java/club/joylink/rtss/vo/client/competition/CompetitionPagedQueryVO.java index 0e22569f3..c32e501e7 100644 --- a/src/main/java/club/joylink/rtss/vo/client/competition/CompetitionPagedQueryVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/competition/CompetitionPagedQueryVO.java @@ -1,9 +1,15 @@ package club.joylink.rtss.vo.client.competition; import club.joylink.rtss.vo.client.PageQueryVO; +import lombok.Getter; +import lombok.Setter; /** * 竞赛分页查询 */ +@Getter +@Setter public class CompetitionPagedQueryVO extends PageQueryVO { + + private String name; } From 93948956ab10b749e07aeddbbd2b7b9ec8b039c7 Mon Sep 17 00:00:00 2001 From: Jade Date: Thu, 11 Nov 2021 13:06:59 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E4=BB=BF=E7=9C=9F=E8=83=8C=E6=99=AF?= =?UTF-8?q?=E6=81=A2=E5=A4=8D-=E8=BD=A6=E6=AC=A1=E8=AE=A1=E5=88=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/storage/StorageSimulationDataRepository.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/StorageSimulationDataRepository.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/StorageSimulationDataRepository.java index 1eee565dc..67ac5778c 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/StorageSimulationDataRepository.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/storage/StorageSimulationDataRepository.java @@ -1,6 +1,7 @@ package club.joylink.rtss.simulation.cbtc.data.storage; import club.joylink.rtss.simulation.cbtc.Simulation; +import club.joylink.rtss.simulation.cbtc.build.RunPlanBuilder; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.map.*; import club.joylink.rtss.simulation.cbtc.data.plan.SchedulingTrainPlan; @@ -18,6 +19,7 @@ import lombok.Setter; import org.springframework.util.CollectionUtils; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Objects; @@ -379,8 +381,12 @@ public class StorageSimulationDataRepository { // 恢复服务-车次计划列表map if (!CollectionUtils.isEmpty(this.serviceTripList)) { List plans = StorageTripPlan.convert2SimulationObjList(repository, this.serviceTripList); - Map> tripPlanMap = plans.stream().collect(Collectors.groupingBy(TripPlan::getServiceNumber)); - repository.setServiceTripsMap(tripPlanMap); + RunPlanBuilder.RunPlanBuildResult runPlanBuildResult = new RunPlanBuilder.RunPlanBuildResult(); + plans.forEach(runPlanBuildResult::addTripPlan); + runPlanBuildResult.sort(); + repository.setServiceTripsMap(runPlanBuildResult.getServerTripMap()); + repository.setStandTripMap(runPlanBuildResult.getStandTripMap()); + repository.setEndTripMap(runPlanBuildResult.getEndTripMap()); // for (StorageTripPlan storageTripPlan : this.serviceTripList) { // TripPlan tripPlan = repository.getTripPlan(storageTripPlan.getServiceNumber(), storageTripPlan.getTripNumber()); // tripPlan.use(); From c3711f1ed046b2ee45fef4a320789b28d99ed52e Mon Sep 17 00:00:00 2001 From: thesai <1021828630@qq.com> Date: Thu, 11 Nov 2021 14:28:22 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E4=B8=8A=E9=A5=B6=E6=B2=99=E7=9B=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../club/joylink/rtss/constants/Project.java | 2 + .../services/project/DeviceServiceImpl.java | 105 ++++++++++-------- .../cbtc/ATS/service/AtsTrainService.java | 5 + .../simulation/cbtc/data/map/Section.java | 10 +- .../simulation/cbtc/data/vo/TrainInfo.java | 4 + .../device/real/udp/Sr/SrTrainController.java | 3 +- .../udp/Sr/service/SrSectionServiceImpl.java | 80 +++++-------- .../udp/Sr/service/SrSignalServiceImpl.java | 2 +- .../udp/Sr/service/SrSwitchServiceImpl.java | 2 +- .../udp/Sr/service/SrTrainServiceImpl.java | 63 +++++++++-- .../device/real/udp/UDPRealDeviceService.java | 2 +- .../device/real/udp/UDPRealDeviceThread.java | 2 +- .../cbtc/onboard/ATP/ATPLogicLoop.java | 8 +- .../client/project/sr/SrSectionConfigVO.java | 12 +- 14 files changed, 169 insertions(+), 131 deletions(-) diff --git a/src/main/java/club/joylink/rtss/constants/Project.java b/src/main/java/club/joylink/rtss/constants/Project.java index 3239eddb4..0d36bbfdd 100644 --- a/src/main/java/club/joylink/rtss/constants/Project.java +++ b/src/main/java/club/joylink/rtss/constants/Project.java @@ -40,6 +40,8 @@ public enum Project { RICHOR_JOINT, /** 上饶沙盘 */ SR_SANDBOX, + /** 江西工贸 */ + JXGM, ; public static boolean isDefault(Project project) { diff --git a/src/main/java/club/joylink/rtss/services/project/DeviceServiceImpl.java b/src/main/java/club/joylink/rtss/services/project/DeviceServiceImpl.java index 490fef874..f39fb3d74 100644 --- a/src/main/java/club/joylink/rtss/services/project/DeviceServiceImpl.java +++ b/src/main/java/club/joylink/rtss/services/project/DeviceServiceImpl.java @@ -277,7 +277,7 @@ public class DeviceServiceImpl implements DeviceService { ProjectDevice entity = getEntityById(projectDeviceVO.getId()); check(entity, projectDeviceVO); entity.setConfig(projectDeviceVO.getConfig()); - projectDeviceDAO.updateByPrimaryKey(entity); + projectDeviceDAO.updateByPrimaryKeyWithBLOBs(entity); } private ProjectDevice getEntityById(long id) { @@ -510,7 +510,8 @@ public class DeviceServiceImpl implements DeviceService { section.setType(ProjectDeviceType.SECTION.name()); section.setCreator(accountVO.getId()); section.setCreateTime(now); - SrSectionConfigVO configVO = new SrSectionConfigVO(mapSectionNewVO.getCode(), mapSectionNewVO.getSrCode(), getTime(mapSectionNewVO)); + SrSectionConfigVO configVO = new SrSectionConfigVO(mapSectionNewVO.getCode(), mapSectionNewVO.getSrCode()); + fillTime(configVO, mapSectionNewVO); section.setConfig(JsonUtils.writeValueAsString(configVO)); list.add(section); } @@ -531,53 +532,59 @@ public class DeviceServiceImpl implements DeviceService { return list; } - private Long getTime(MapSectionNewVO section) { - Long nanos = null; - if (section.isTransferTrack() || section.isReentryTrack() || section.isStandTrack()) { - long m = 1000000000; - switch (section.getCode()) { - case "T5": //1x - nanos = (long) (2.3 * m); - break; - case "T7": //2x - nanos = (long) (3.5 * m); - break; - case "T45": //3x - nanos = (long) (3.0 * m); - break; - case "T53": //4x - nanos = (long) (2.6 * m); - break; - case "T61": //5x - nanos = (long) (2.0 * m); - break; - case "T67": //6x - nanos = (long) (2.7 * m); - break; - case "T33": //1s - nanos = (long) (3.2 * m); - break; - case "T35": //2s - nanos = (long) (2.9 * m); - break; - case "T46": //3s - nanos = (long) (2.6 * m); - break; - case "T54": //4s - nanos = (long) (3.2 * m); - break; - case "T62": //5s - nanos = (long) (2.5 * m); - break; - case "T68": //6s - nanos = (long) (2.8 * m); - break; - case "T141": //49G - nanos = (long) (0.5 * m); - break; - } + /** + * 填充区段延时停车时间 + */ + private void fillTime(SrSectionConfigVO configVO, MapSectionNewVO section) { + Float headDelayTime = null; + Float tailDelayTime = null; + switch (section.getCode()) { + //以车头到目标位置作为停车标志的区段 + case "T141": //49G + case "T142": + headDelayTime = 1.0f; + break; + case "T1": //1G + headDelayTime = 3.7f; + break; + case "T11": + headDelayTime = 3.7f; + break; + case "T73": + case "T75": + headDelayTime = 3.4f; + break; + //以车尾解除占用作为停车标志的区段 + case "T5": //1x + break; + case "T7": //2x + break; + case "T45": //3x + break; + case "T53": //4x + break; + case "T61": //5x + break; + case "T67": //6x + break; + case "T33": //1s + tailDelayTime = 2.0f; + break; + case "T35": //2s + tailDelayTime = 2.5f; + break; + case "T46": //3s + break; + case "T54": //4s + break; + case "T62": //5s + break; + case "T68": //6s + tailDelayTime = 2.0f; + break; } - return nanos; + configVO.setHeadDelayTime(headDelayTime); + configVO.setTailDelayTime(tailDelayTime); } private List buildZjdProjectDevices(AccountVO accountVO) { @@ -667,7 +674,7 @@ public class DeviceServiceImpl implements DeviceService { private ProjectDevice buildIm(Project project, Long creatorId) { ProjectDevice im = new ProjectDevice(); im.setProjectCode(project.name()); - im.setCode(project.name().toLowerCase() + "-" +"im"); + im.setCode(project.name().toLowerCase() + "-" + "im"); im.setType(ProjectDeviceType.IM.name()); im.setCreator(creatorId); im.setCreateTime(LocalDateTime.now()); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java index ab078a05d..b61c36c04 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java @@ -60,6 +60,9 @@ public class AtsTrainService { @Autowired private AtsHeadTrainStageService atsHeadTrainStageService; + @Autowired + private AtsTrainService atsTrainService; + /** * 添加列车追踪 * @@ -97,6 +100,8 @@ public class AtsTrainService { BusinessExceptionAssertEnum.OPERATION_FAIL.assertNotTrue(tripRepeat, "车次计划已在运行"); ti = new TrainInfo(groupNumber, TrainType.PLAN); ti.init(section, tripPlan, dn, cn); + } else if (StringUtils.hasText(dn)) { + ti = new TrainInfo(groupNumber, TrainType.HEAD); } else { ti = new TrainInfo(groupNumber, TrainType.MANUAL); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java index 5eff3da33..77c4dbfb6 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/map/Section.java @@ -1108,7 +1108,7 @@ public class Section extends DelayUnlockDevice { if (!CollectionUtils.isEmpty(zcs)) { return zcs.stream().anyMatch(zc -> !zc.isFault()); } - return true; + return false; } public void setInvalid(boolean invalid) { @@ -1201,6 +1201,14 @@ public class Section extends DelayUnlockDevice { return sections; } + public Section findPhysicalSection() { + if (this.isPhysical()) + return this; + if (this.parent != null) + return this.parent.findPhysicalSection(); + return null; + } + public enum SectionRoadType { /** * 左行线 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 e48129204..8f1f5562b 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 @@ -365,6 +365,9 @@ public class TrainInfo extends MapElement { public void init(Section section, String dn, String sn, String tn, String cn) { this.section = section.getCode(); + Section ps = section.findPhysicalSection(); + if (ps != null) + this.physicalSection = ps.getCode(); this.destinationCode = dn; this.serviceNumber = sn; this.tripNumber = tn; @@ -426,6 +429,7 @@ public class TrainInfo extends MapElement { public boolean isHeadCodeTrain() { return Objects.equals(this.type, TrainType.HEAD); } + public boolean isManualTrain() { return TrainType.MANUAL.equals(this.type); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainController.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainController.java index 8cb0c7579..67ba43e6f 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainController.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/SrTrainController.java @@ -2,7 +2,6 @@ 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.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @RestController @@ -18,6 +17,6 @@ public class SrTrainController { @PutMapping("/{simulationId}/control") public void control(@PathVariable String simulationId, String groupNumber, boolean right, int speed) { - srTrainService.control(simulationId, groupNumber, right, speed); + srTrainService.controlTrain(simulationId, groupNumber, right, speed); } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSectionServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSectionServiceImpl.java index 6bee8ddb5..ee00c24ba 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSectionServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSectionServiceImpl.java @@ -3,6 +3,7 @@ package club.joylink.rtss.simulation.cbtc.device.real.udp.sr.service; 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.CalculateService; import club.joylink.rtss.simulation.cbtc.data.map.Section; import club.joylink.rtss.simulation.cbtc.data.support.SectionPosition; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySectionAxleCounter; @@ -41,7 +42,7 @@ public class SrSectionServiceImpl implements UDPRealDeviceService { } @Override - public void control(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) { + public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) { } @@ -100,71 +101,32 @@ public class SrSectionServiceImpl implements UDPRealDeviceService { continue; if (config.getTimeOfStop() != null) //已经设置过停车时间 continue; - boolean right = train.isRight(); if (!headSection.isFunctionTrack()) continue; + VirtualRealitySectionAxleCounter headAxle = headSection.findAxle(); + if (headAxle == null) + continue; + SrSectionConfig sectionConfig = (SrSectionConfig) headAxle.getRealDevice(); //设置延时停车时间 long m = 1000000000; - long nanos = -1; - switch (headSection.getCode()) { //不能以前一个区段无占用作为停车标志的区段 - case "T141": //49G - nanos = (long) (1.0 * m); - break; - case "T1": //1G - nanos = (long) (3.7 * m); - break; - case "T11": - nanos = (long) (3.7 * m); - break; - } - if (nanos != -1) { + 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 axle = behindSection.findAxle(); - if (!axle.isOccupy()) { //前一个区段所属计轴无占用状态 + VirtualRealitySectionAxleCounter behindAxle = behindSection.findAxle(); + if (behindAxle == null) + continue; + if (!behindAxle.isOccupy()) { //车头后方区段所属计轴无占用状态 nanos = 0; - switch (headSection.getCode()) { - case "T5": //1x - nanos = (long) (0.0 * m); - break; - case "T7": //2x - nanos = (long) (0.0 * m); - break; - case "T45": //3x - nanos = (long) (0.0 * m); - break; - case "T53": //4x - nanos = (long) (0.0 * m); - break; - case "T61": //5x - nanos = (long) (0.0 * m); - break; - case "T67": //6x - nanos = (long) (0.0 * m); - break; - case "T33": //1s - nanos = (long) (2.0 * m); - break; - case "T35": //2s - nanos = (long) (2.5 * m); - break; - case "T46": //3s - nanos = (long) (0.0 * m); - break; - case "T54": //4s - nanos = (long) (0.0 * m); - break; - case "T62": //5s - nanos = (long) (0.0 * m); - break; - case "T68": //6s - nanos = (long) (2.0 * m); - break; + if (sectionConfig.getConfigVO().getTailDelayTime() != null) { + nanos = (long) (sectionConfig.getConfigVO().getTailDelayTime() * m); } if (nanos == 0) { train.setHeadPosition(headSection.buildStopPointPosition(right)); @@ -209,7 +171,15 @@ public class SrSectionServiceImpl implements UDPRealDeviceService { maService.calculateAndUpdateItcMa(simulation, train); } //更新位置 - SectionPosition headPosition = new SectionPosition(occupiedSection, occupiedSection.getEndOffsetByDirection(!right)); + SectionPosition headPosition; + SectionPosition stopPointPosition; + if (occupiedSection.isFunctionTrack()) { + stopPointPosition = occupiedSection.buildStopPointPosition(right); + headPosition = CalculateService.calculateNextPositionByStartAndLen(stopPointPosition, !right, 1); + } else { + stopPointPosition = new SectionPosition(occupiedSection, occupiedSection.getEndOffsetByDirection(right)); + headPosition = CalculateService.calculateNextPositionByStartAndLen(stopPointPosition, !right, 3); + } train.setHeadPosition(headPosition); //更新位置 if (occupiedSection.isFunctionTrack()) { //功能轨可能需要停车 SrTrainConfig config = (SrTrainConfig) train.getRealDevice(); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSignalServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSignalServiceImpl.java index da338ae30..c2e165fb7 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSignalServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSignalServiceImpl.java @@ -26,7 +26,7 @@ public class SrSignalServiceImpl implements UDPRealDeviceService { } @Override - public void control(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) { + public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) { SrSignalConfig config = (SrSignalConfig) realDevice; //控制vr设备 VirtualRealitySignal vrSignal = (VirtualRealitySignal) realDevice.getMapElement(); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSwitchServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSwitchServiceImpl.java index ddfc81570..56e4ebb02 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSwitchServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSwitchServiceImpl.java @@ -26,7 +26,7 @@ public class SrSwitchServiceImpl implements UDPRealDeviceService { } @Override - public void control(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) { + public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) { SrSwitchConfig config = (SrSwitchConfig) realDevice; //控制vr设备 VirtualRealitySwitch vrSwitch = (VirtualRealitySwitch) realDevice.getMapElement(); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrTrainServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrTrainServiceImpl.java index 0af7d21d5..885724c44 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrTrainServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrTrainServiceImpl.java @@ -4,6 +4,7 @@ import club.joylink.rtss.constants.ProjectDeviceType; import club.joylink.rtss.exception.BusinessExceptionAssertEnum; import club.joylink.rtss.simulation.cbtc.ATS.operation.AtsOperationDispatcher; import club.joylink.rtss.simulation.cbtc.ATS.operation.Operation; +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.constant.SimulationConstants; @@ -47,30 +48,66 @@ public class SrTrainServiceImpl implements UDPRealDeviceService { @Autowired private GroupSimulationService groupSimulationService; + @Autowired + private AtsTrainLoadService atsTrainLoadService; + @Override public boolean isMatch(RealDeviceConfig realDevice) { return realDevice instanceof SrTrainConfig; } @Override - public void control(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) { + public void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice) { SrTrainConfig config = (SrTrainConfig) realDevice; //控制vr设备 VirtualRealityTrain train = (VirtualRealityTrain) config.getMapElement(); - if (simulation.getRepository().isVrTrainOnline(train.getGroupNumber())) { - if (train.getRobotTargetPosition() != null || train.isAMMode()) { - config.setManualGear(null); - } - if (config.getManualGear() == null) { - change2RMWhenStopAtPlanEnd(simulation, train); - trainRunning(simulation, train, config); - } - if (train.getDelayTime() > 3000) { - train.setDelayTime(3000); + SimulationDataRepository repository = simulation.getRepository(); + String groupNumber = train.getGroupNumber(); + if (repository.isVrTrainOnline(groupNumber)) { + removeVrTrainIfNotSupervised(repository, groupNumber); + if (train.isEB()) { + train.setSpeed(0); + } else { + if (train.getRobotTargetPosition() != null || train.isAMMode()) { + config.setManualGear(null); + } + if (config.getManualGear() == null) { + change2RMWhenStopAtPlanEnd(simulation, train); + trainRunning(simulation, train, config); + } + if (train.getDelayTime() > 3000) { + train.setDelayTime(3000); + } } //控制沙盘设备 byte[] data = buildData(train, config); udpClient.write(udpLowConfig.getAddr(), data); + } else { + addVrTrainIfSupervised(simulation, repository, groupNumber); + } + } + + /** + * 如果有监控,添加一个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); } } @@ -235,7 +272,7 @@ public class SrTrainServiceImpl implements UDPRealDeviceService { return data; } - public void control(String simulationId, String groupNumber, boolean right, int speed) { + public void controlTrain(String simulationId, String groupNumber, boolean right, int speed) { Simulation simulation = groupSimulationService.getSimulationByGroup(simulationId); VirtualRealityTrain train = simulation.getRepository().getOnlineTrainBy(groupNumber); SrTrainConfig config = (SrTrainConfig) train.getRealDevice(); @@ -246,6 +283,8 @@ public class SrTrainServiceImpl implements UDPRealDeviceService { } train.setRobotTargetPosition(null); //终止机器人司机驾驶 //加减速 + if (train.isEB()) + return; atpService.changeGear(train, VirtualRealityTrain.Handwheel.MANUAL); int manualGear = speed / 10; config.setManualGear(manualGear); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPRealDeviceService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPRealDeviceService.java index 3be503bb0..ff7bf45b9 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPRealDeviceService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPRealDeviceService.java @@ -7,7 +7,7 @@ import io.netty.buffer.ByteBuf; public interface UDPRealDeviceService { boolean isMatch(RealDeviceConfig realDevice); - void control(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice); + void run(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice); void init(Simulation simulation, UDPLowConfig udpLowConfig, RealDeviceConfig realDevice); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPRealDeviceThread.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPRealDeviceThread.java index c933d63d8..c1457be01 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPRealDeviceThread.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/UDPRealDeviceThread.java @@ -64,7 +64,7 @@ public class UDPRealDeviceThread { for (RealDeviceConfig config : realDeviceList) { for (UDPRealDeviceService service : serviceList) { if (service.isMatch(config) && config.getMapElement() != null) { - service.control(simulation, udpLowConfig, config); + service.run(simulation, udpLowConfig, config); } } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATP/ATPLogicLoop.java b/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATP/ATPLogicLoop.java index 3e8266cc2..10fcfc2ce 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATP/ATPLogicLoop.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATP/ATPLogicLoop.java @@ -155,10 +155,10 @@ public class ATPLogicLoop { if (train.isRMMode() && train.isLeverNotInTractionGear()) { //停车、RM模式、操纵杆非牵引位 atpService.cancelSignalEB(train); } - if (Project.SR_SANDBOX.name().equals(simulation.getBuildParams().getMap().getProjectCode())) { - atpService.cancelSignalEB(train); - atpService.openATO(train); - } +// if (Project.SR_SANDBOX.name().equals(simulation.getBuildParams().getMap().getProjectCode())) { +// atpService.cancelSignalEB(train); +// atpService.openATO(train); +// } } if (this.checkConditionToMove2(simulation, train)) { // 可以启动 diff --git a/src/main/java/club/joylink/rtss/vo/client/project/sr/SrSectionConfigVO.java b/src/main/java/club/joylink/rtss/vo/client/project/sr/SrSectionConfigVO.java index f4e423aae..1fdb0cad4 100644 --- a/src/main/java/club/joylink/rtss/vo/client/project/sr/SrSectionConfigVO.java +++ b/src/main/java/club/joylink/rtss/vo/client/project/sr/SrSectionConfigVO.java @@ -13,13 +13,17 @@ public class SrSectionConfigVO { private String sandboxCode; /** - * 延迟停车时间/ns + * 车头到达区段延迟停车时间/s */ - private Long time; + private Float headDelayTime; - public SrSectionConfigVO(String vrCode, String sandboxCode, Long time) { + /** + * 车尾解除占用延迟停车时间/s + */ + private Float tailDelayTime; + + public SrSectionConfigVO(String vrCode, String sandboxCode) { this.vrCode = vrCode; this.sandboxCode = sandboxCode; - this.time = time; } } From 582005279fba5c9373fef040c0bc2152063bc17f Mon Sep 17 00:00:00 2001 From: Jade Date: Fri, 12 Nov 2021 14:28:11 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E5=89=A7=E6=9C=AC=E6=95=85=E9=9A=9C?= =?UTF-8?q?=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/competition/CompetitionAndScriptManager.java | 5 ++--- .../simulation/cbtc/competition/ScriptExecuteService.java | 5 ----- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/competition/CompetitionAndScriptManager.java b/src/main/java/club/joylink/rtss/simulation/cbtc/competition/CompetitionAndScriptManager.java index c3751d8d0..afa87f2cb 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/competition/CompetitionAndScriptManager.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/competition/CompetitionAndScriptManager.java @@ -97,9 +97,8 @@ public class CompetitionAndScriptManager { String content = unfinishedAction.getContent(); unfinishedAction.setContent(String.format(content, currentTime)); } - //如果动作执行者不是机器人,且不是故障操作 - if (!unfinishedAction.getMember().isRobot() && !(unfinishedAction.getType().equals(ScriptActionBO.ActionType.Operation) - && unfinishedAction.getOperationType().equals(Set_Fault))) { + //如果动作执行者不是机器人 + if (!unfinishedAction.getMember().isRobot()) { if (!unfinishedAction.isPrompt()) { applicationContext.publishEvent(new SimulationScriptTipEvent(this, simulation, unfinishedAction)); unfinishedAction.setPrompt(true); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/competition/ScriptExecuteService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/competition/ScriptExecuteService.java index 375f2ef97..adb3bb85a 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/competition/ScriptExecuteService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/competition/ScriptExecuteService.java @@ -207,11 +207,6 @@ public class ScriptExecuteService { return; } ScriptActionBO action = script.getNextNeedPassAction(); - // 故障模式不提示 - if (action.getType().equals(ScriptActionBO.ActionType.Operation) - && action.getOperationType().equals(Operation.Type.Set_Fault)) { - return; - } if (!action.getOperationType().equals(operationType) || !action.getOperationParamMap().equals(params)) { applicationContext.publishEvent(new SimulationScriptActionErrorEvent(this, simulation, action)); From dccba0e918e815c8a52c4f7f5f2e0ef8e1f0e19c Mon Sep 17 00:00:00 2001 From: Jade Date: Fri, 12 Nov 2021 14:29:11 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E5=9C=BA=E6=99=AF3=20=E9=81=93=E5=B2=94?= =?UTF-8?q?=E5=A4=B1=E8=A1=A8=E6=8E=92=E5=88=97=E8=BF=9B=E8=B7=AF=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/CI/device/CiRouteService.java | 13 ++++++++++--- .../simulation/cbtc/CI/device/CiService.java | 16 ++++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/device/CiRouteService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/device/CiRouteService.java index 64ac6e96e..66e7bcb9c 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/device/CiRouteService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/device/CiRouteService.java @@ -44,7 +44,7 @@ public class CiRouteService { } } // 进路中道岔没有被征用或锁定在相反位置 - Route.CheckFailMessage failMessage = setSwitchCheck(route.getSwitchList()); + Route.CheckFailMessage failMessage = setSwitchCheck(simulation, route.getSwitchList()); if (failMessage != null) { return failMessage; } @@ -110,7 +110,7 @@ public class CiRouteService { RouteOverlap overlap = route.getOverlap(); if (Objects.nonNull(overlap)) { SectionPath sectionPath = overlap.selectPath(); - failMessage = setSwitchCheck(sectionPath.getSwitchList()); + failMessage = setSwitchCheck(simulation, sectionPath.getSwitchList()); } } return failMessage; @@ -133,7 +133,7 @@ public class CiRouteService { return null; } - private static Route.CheckFailMessage setSwitchCheck(List switchList) { + private static Route.CheckFailMessage setSwitchCheck(Simulation simulation, List switchList) { if (switchList != null) { for (SwitchElement switchElement : switchList) { Switch aSwitch = switchElement.getASwitch(); @@ -147,6 +147,13 @@ public class CiRouteService { if (aSwitch.isCiUseOnOppositePosition(switchElement.isNormal())) { // 道岔征用在相反位置 return new Route.CheckFailMessage(Route.CheckFailReason.SwitchCiUseOnOppositePosition, aSwitch); } + // 非预先锁闭,道岔相应位置失表则不排进路 + if (!simulation.getRepository().getConfig().isLockFirst() && aSwitch.isLoss()) { + if ((Switch.SwitchFault.NORMAL_SPLIT.equals(aSwitch.getFault()) && switchElement.isNormal()) + || (Switch.SwitchFault.REVERSE_SPLIT.equals(aSwitch.getFault()) && !switchElement.isNormal())) { + return new Route.CheckFailMessage(Route.CheckFailReason.SwitchFault, aSwitch); + } + } } } return null; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/device/CiService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/device/CiService.java index 8ef1eaec4..12084c0a2 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/CI/device/CiService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/CI/device/CiService.java @@ -27,11 +27,23 @@ public class CiService { if (overlap.getSection().isRouteLock()) { SectionPath sectionPath = overlap.selectPath(); for (SwitchElement switchElement : sectionPath.getSwitchList()) { - if (switchElement.getASwitch().isLocked() && !switchElement.isOnPosition()) { + Switch aSwitch = switchElement.getASwitch(); + if (aSwitch.isLocked() && !switchElement.isOnPosition()) { log.debug("延续保护进路[{}]道岔[{}]锁闭在相反位置,不触发办理", overlap.debugStr(), - switchElement.getASwitch().debugStr()); + aSwitch.debugStr()); return; } + // 非预先锁闭,道岔相应位置失表则不排延续保护 + if (!simulation.getRepository().getConfig().isLockFirst() && aSwitch.isLoss()) { + if ((Switch.SwitchFault.NORMAL_SPLIT.equals(aSwitch.getFault()) + && switchElement.isNormal()) + || (Switch.SwitchFault.REVERSE_SPLIT.equals(aSwitch.getFault()) + && !switchElement.isNormal())) { + log.debug("延续保护进路[{}]道岔[{}]位置失表,不触发办理", overlap.debugStr(), + aSwitch.debugStr()); + return; + } + } } overlap.startSetting(simulation.getSystemTime()); } From ff4b3c1d515a9354d5549e6175eea7aebf953713 Mon Sep 17 00:00:00 2001 From: Jade Date: Fri, 12 Nov 2021 14:54:30 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=8F=AF=E7=94=A8?= =?UTF-8?q?=E5=8C=BA=E6=AE=B5=E4=BD=8D=E7=BD=AE=E8=AE=A1=E7=AE=97=E5=8C=BA?= =?UTF-8?q?=E5=88=86=E6=98=AF=E5=90=A6=E7=9C=9F=E5=AE=9E=E8=AE=BE=E5=A4=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cbtc/ATP/ground/AtpSectionService.java | 6 ++--- .../simulation/cbtc/ATP/ground/MaService.java | 8 +++--- .../cbtc/ATS/service/AtsTrainLoadService.java | 6 ++--- .../cbtc/ATS/service/AtsTrainService.java | 4 +-- .../cbtc/data/CalculateService.java | 26 +++++++++++++------ .../cbtc/data/support/MovementAuthority.java | 13 ++++------ .../cbtc/data/support/SectionPosition.java | 4 +-- .../cbtc/data/vr/VirtualRealityTrain.java | 6 ++--- .../udp/Sr/service/SrSectionServiceImpl.java | 4 +-- .../device/virtual/VRDeviceLogicLoop.java | 2 +- .../device/virtual/VRTrainRunningService.java | 8 +++--- .../cbtc/onboard/ATP/ATPService.java | 2 +- .../onboard/TrainTargetUpdateService.java | 2 +- .../simulation/cbtc/robot/RobotLogicLoop.java | 2 +- 14 files changed, 50 insertions(+), 43 deletions(-) diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/AtpSectionService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/AtpSectionService.java index d99afe4e0..cbce19f84 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/AtpSectionService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/AtpSectionService.java @@ -84,7 +84,7 @@ public class AtpSectionService { if (train.isCommunicable()) { // 通信车占用 // 车尾位置追加不确定性距离:(速度*2)m SectionPosition trainTailPosition = CalculateService - .calculateNextPositionByStartAndLen(trainHeadPosition, !right, train.getLen() + train.getSpeed() * 2); + .calculateNextPositionByStartAndLen(trainHeadPosition, !right, train.getLen() + train.getSpeed() * 2, false); atpSectionList = CalculateService.getAtpSections(trainHeadPosition, trainTailPosition, right, switchSingleHandle); List
removes = new ArrayList<>(); @@ -171,11 +171,11 @@ public class AtpSectionService { SectionPosition headPosition = train.getHeadPosition(); float offset = 50; SectionPosition head = CalculateService - .calculateNextPositionByStartAndLen(headPosition, right, offset); + .calculateNextPositionByStartAndLen(headPosition, right, offset, false); // 考虑列车最大可能占用区间,用于判断ARB区段 SectionPosition tail = CalculateService .calculateNextPositionByStartAndLen(headPosition, - !right, train.getLen() + offset); + !right, train.getLen() + offset, false); List
sectionList = CalculateService.getTrainOccupyAxleSection(head, tail, right); if (!CollectionUtils.isEmpty(sectionList)) { for (Section section : sectionList) { diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/MaService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/MaService.java index 29ddc1752..711985f47 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/MaService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATP/ground/MaService.java @@ -134,7 +134,7 @@ public class MaService { end = signal.getSection().buildStopPointPosition(right); } else { SectionPosition sectionPosition = new SectionPosition(signal.getSection(), signal.getOffset()); - end = CalculateService.calculateNextPositionByStartAndLen(sectionPosition, !right, 5); + end = CalculateService.calculateNextPositionByStartAndLen(sectionPosition, !right, 5, false); } Float distance = CalculateService.calculateDistance(this.train.getHeadPosition(), end, right); if (distance == null) { @@ -165,7 +165,7 @@ public class MaService { } else { eoa = frontTrain.getHeadPosition(); } - eoa = CalculateService.calculateNextPositionByStartAndLen(eoa, !right, 10); + eoa = CalculateService.calculateNextPositionByStartAndLen(eoa, !right, 10, false); break; } case Axle_Occupy_Section:{ @@ -202,7 +202,7 @@ public class MaService { Section section = (Section) this.device; float offset = section.getStopPointByDirection(right); offset = right ? offset - train.getLen() - 20 : offset + train.getLen() + 20; - eoa = CalculateService.getAvailableSectionPositionOf(new SectionPosition(section, offset)); + eoa = CalculateService.getAvailableSectionPositionOf(new SectionPosition(section, offset), false); break; } case ITC_Signal:{ @@ -222,7 +222,7 @@ public class MaService { physicalSection = physicalSection.getParent(); } eoa = new SectionPosition(physicalSection, right ? section.getMinOffset() : section.getMaxOffset()); - eoa = CalculateService.calculateNextPositionByStartAndLen(eoa, !right, 10); + eoa = CalculateService.calculateNextPositionByStartAndLen(eoa, !right, 10, false); break; } default: diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java index 5d3cf11f1..3f4287d5c 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainLoadService.java @@ -615,7 +615,7 @@ public class AtsTrainLoadService { // 与上一辆车距离一个安全距离 SectionPosition headPosition = CalculateService .calculateNextPositionByStartAndLen(frontTrain.getHeadPosition(), - !train.isRight(), frontTrain.getLen() + 2 * SimulationConstants.TRAIN_SAFE_DISTANCE); + !train.isRight(), frontTrain.getLen() + 2 * SimulationConstants.TRAIN_SAFE_DISTANCE, false); train.setHeadPosition(headPosition); } } @@ -664,7 +664,7 @@ public class AtsTrainLoadService { for (VirtualRealityTrain train : loadedList) { Section headSection = train.getHeadPosition().getSection(); boolean right = train.isRight(); - SectionPosition tailPosition = CalculateService.calculateNextPositionByStartAndLen(train.getHeadPosition(), !right, train.getLen()); + SectionPosition tailPosition = CalculateService.calculateNextPositionByStartAndLen(train.getHeadPosition(), !right, train.getLen(), false); TripPlan tripPlan = repository.getTripPlan(train.getServiceNumber(), train.getTripNumber()); // 取进路所有经过的区段 List
viaSectionList = tripPlan.getAllViaStoppedSectionList(); @@ -850,7 +850,7 @@ public class AtsTrainLoadService { "列车需加载到物理区段上"); //重叠检测 SectionPosition headPosition = new SectionPosition(section, section.getStopPointByDirection(right)); - SectionPosition tailPosition = CalculateService.calculateNextPositionByStartAndLen(headPosition, !right, train.getLen()); + SectionPosition tailPosition = CalculateService.calculateNextPositionByStartAndLen(headPosition, !right, train.getLen(), false); boolean willOverlap = vrTrainRunningService.willOverlap(simulation, headPosition, tailPosition); BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED.assertNotTrue(willOverlap, "列车重叠"); // 列车上线并构建ATS监控列车信息 diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java index b61c36c04..eb5dd0972 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/ATS/service/AtsTrainService.java @@ -425,7 +425,7 @@ public class AtsTrainService { if (distance == null) { throw new SimulationException(SimulationExceptionType.Illegal_Argument, "无法到达的位置"); } - targetPosition = CalculateService.calculateNextPositionByStartAndLen(train.getHeadPosition(), right, distance); + targetPosition = CalculateService.calculateNextPositionByStartAndLen(train.getHeadPosition(), right, distance, false); } else { targetPosition = new SectionPosition(section, section.getStopPointByDirection(right)); } @@ -436,7 +436,7 @@ public class AtsTrainService { VirtualRealityTrain targetTrain = repository.getVRByCode(targetDeviceCode, VirtualRealityTrain.class); SectionPosition targetTrainTailPosition = targetTrain.calculateTailPosition(); boolean targetIsRight = targetTrain.isRight(); - targetPosition = CalculateService.calculateNextPositionByStartAndLen(targetTrainTailPosition, !targetIsRight, 2); + targetPosition = CalculateService.calculateNextPositionByStartAndLen(targetTrainTailPosition, !targetIsRight, 2, false); } SectionPosition physicalPosition = targetPosition.convert2PhysicalSectionPosition(); train.setRobotTargetPosition(physicalPosition); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/CalculateService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/CalculateService.java index 22f85961b..fd4dba10e 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/CalculateService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/CalculateService.java @@ -17,7 +17,7 @@ import java.util.*; @Slf4j public class CalculateService { - public static SectionPosition getAvailableSectionPositionOf(SectionPosition sectionPosition) { + public static SectionPosition getAvailableSectionPositionOf(SectionPosition sectionPosition, boolean baseReal) { if (!sectionPosition.isAvailable()) { float offset = sectionPosition.getOffset(); Section baseSection = sectionPosition.getSection(); @@ -25,7 +25,12 @@ public class CalculateService { while (offset < 0 || offset > baseSection.getLen()) { ++count; if (offset < 0) { // 向左 - Section leftSection = baseSection.getNextRunningSectionOf(false); + Section leftSection; + if (baseReal) { + leftSection = baseSection.getNextRunningSectionBaseRealSwitch(false); + } else { + leftSection = baseSection.getNextRunningSectionOf(false); + } if (Objects.nonNull(leftSection)) { // 左区段存在 offset = leftSection.getLen() + offset; baseSection = leftSection; @@ -34,7 +39,12 @@ public class CalculateService { offset = 0; } } else { // 向右 - Section rightSection = baseSection.getNextRunningSectionOf(true); + Section rightSection; + if (baseReal) { + rightSection = baseSection.getNextRunningSectionBaseRealSwitch(true); + } else { + rightSection = baseSection.getNextRunningSectionOf(true); + } if (Objects.nonNull(rightSection)) { // 右向区段存在 offset = offset - baseSection.getLen(); baseSection = rightSection; @@ -61,13 +71,13 @@ public class CalculateService { * 根据开始位置、方向、距离计算到达的位置(不会超出正线轨道范围,不会冲过位置不合适道岔) */ public static SectionPosition calculateNextPositionByStartAndLen(SectionPosition startPosition, - boolean right, float len) { + boolean right, float len, boolean baseReal) { if (!right) { len = -len; } float offset = startPosition.getOffset(); float offsetNew = offset + len; - return getAvailableSectionPositionOf(new SectionPosition(startPosition.getSection(), offsetNew)); + return getAvailableSectionPositionOf(new SectionPosition(startPosition.getSection(), offsetNew), baseReal); } /** @@ -509,7 +519,7 @@ public class CalculateService { Section section = source; while (!section.getCode().equals(target.getCode()) && loop < 20) { loop++; - Section temp = section.getNextRunningSectionOf(right); + Section temp = section.getNextRunningSectionBaseRealSwitch(right); if (Objects.nonNull(temp)) { // 不为空 section = temp; occupySectionList.add(section); @@ -1010,7 +1020,7 @@ public class CalculateService { this.headPosition = train.getHeadPosition(); this.right = train.isRight(); this.tailPosition = CalculateService - .calculateNextPositionByStartAndLen(headPosition, !right, train.getLen()); + .calculateNextPositionByStartAndLen(headPosition, !right, train.getLen(), false); } /** @@ -1020,7 +1030,7 @@ public class CalculateService { this.headPosition = train.getHeadPosition(); this.right = train.isRight(); this.tailPosition = CalculateService - .calculateNextPositionByStartAndLen(headPosition, !right, train.getLen() + append); + .calculateNextPositionByStartAndLen(headPosition, !right, train.getLen() + append, false); } } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/MovementAuthority.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/MovementAuthority.java index d7ac82fc5..989b3785e 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/MovementAuthority.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/MovementAuthority.java @@ -11,9 +11,6 @@ import club.joylink.rtss.simulation.cbtc.onboard.ATO.SpeedCurve; import lombok.Getter; import lombok.Setter; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; import java.util.Objects; /** @@ -99,7 +96,7 @@ public class MovementAuthority { case CLOSED_STAND:{ Section section = baseSection; SectionPosition stopPosition = new SectionPosition(section, section.getStopPointByDirection(right)); - return CalculateService.calculateNextPositionByStartAndLen(stopPosition, !right, 180); + return CalculateService.calculateNextPositionByStartAndLen(stopPosition, !right, 180, false); } case CLOSED_SIGNAL: { Signal signal = (Signal) this.device; @@ -117,10 +114,10 @@ public class MovementAuthority { section = section.getParent(); SectionPosition sectionPosition = new SectionPosition(section, offset); if (section.isStandTrack() && section.getStandList().get(0).isTrainParking()) { - return CalculateService.calculateNextPositionByStartAndLen(sectionPosition, !right, 10); + return CalculateService.calculateNextPositionByStartAndLen(sectionPosition, !right, 10, false); } else { return CalculateService.calculateNextPositionByStartAndLen(sectionPosition, - !right, 2 * SimulationConstants.TRAIN_SAFE_DISTANCE); + !right, 2 * SimulationConstants.TRAIN_SAFE_DISTANCE, false); } // VirtualRealityTrain train = (VirtualRealityTrain) this.device; @@ -154,7 +151,7 @@ public class MovementAuthority { Section section = this.baseSection; float offset = right ? section.getLen() : 0; SectionPosition stopPosition = new SectionPosition(section, offset); - return CalculateService.calculateNextPositionByStartAndLen(stopPosition, !right, 100); + return CalculateService.calculateNextPositionByStartAndLen(stopPosition, !right, 100, false); } case UNLOCK_SECTION: case FAULT_SECTION: @@ -197,7 +194,7 @@ public class MovementAuthority { if (Objects.isNull(this.endPosition)) { SectionPosition sectionPosition = this.computeEndPosition(right); if (!sectionPosition.isAvailable()) { - sectionPosition = CalculateService.getAvailableSectionPositionOf(sectionPosition); + sectionPosition = CalculateService.getAvailableSectionPositionOf(sectionPosition, false); } this.endPosition = sectionPosition; } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/SectionPosition.java b/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/SectionPosition.java index f8ecd2f8d..08bf6d0d0 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/SectionPosition.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/data/support/SectionPosition.java @@ -120,9 +120,9 @@ public class SectionPosition { public boolean isWithinParkingRange(boolean right) { SectionPosition targetPosition = new SectionPosition(this.section, this.section.getStopPointByDirection(right)); SectionPosition max = CalculateService.calculateNextPositionByStartAndLen(targetPosition, - right, SimulationConstants.PARK_POINT_MAX_OFFSET); + right, SimulationConstants.PARK_POINT_MAX_OFFSET, false); SectionPosition min = CalculateService.calculateNextPositionByStartAndLen(targetPosition, - !right, SimulationConstants.PARK_POINT_MAX_OFFSET); + !right, SimulationConstants.PARK_POINT_MAX_OFFSET, false); return this.isAheadOf(min, right) && max.isAheadOf(this, right); } } 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 faf5c0a74..7400d3941 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 @@ -766,7 +766,7 @@ public class VirtualRealityTrain extends VirtualRealityDevice { } public SectionPosition calculateTailPosition() { - this.tailPosition = CalculateService.calculateNextPositionByStartAndLen(this.headPosition, !right, this.getLen()); + this.tailPosition = CalculateService.calculateNextPositionByStartAndLen(this.headPosition, !right, this.getLen(), true); return this.tailPosition; } @@ -825,9 +825,9 @@ public class VirtualRealityTrain extends VirtualRealityDevice { SectionPosition headPosition = this.headPosition; boolean right = this.right; SectionPosition max = CalculateService.calculateNextPositionByStartAndLen(targetPosition, - right, SimulationConstants.PARK_POINT_MAX_OFFSET); + right, SimulationConstants.PARK_POINT_MAX_OFFSET, true); SectionPosition min = CalculateService.calculateNextPositionByStartAndLen(targetPosition, - !right, SimulationConstants.PARK_POINT_MAX_OFFSET); + !right, SimulationConstants.PARK_POINT_MAX_OFFSET, true); return headPosition.isAheadOf(min, right) && max.isAheadOf(headPosition, right); } diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSectionServiceImpl.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSectionServiceImpl.java index ee00c24ba..002e7a5a6 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSectionServiceImpl.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/real/udp/Sr/service/SrSectionServiceImpl.java @@ -175,10 +175,10 @@ public class SrSectionServiceImpl implements UDPRealDeviceService { SectionPosition stopPointPosition; if (occupiedSection.isFunctionTrack()) { stopPointPosition = occupiedSection.buildStopPointPosition(right); - headPosition = CalculateService.calculateNextPositionByStartAndLen(stopPointPosition, !right, 1); + headPosition = CalculateService.calculateNextPositionByStartAndLen(stopPointPosition, !right, 1, true); } else { stopPointPosition = new SectionPosition(occupiedSection, occupiedSection.getEndOffsetByDirection(right)); - headPosition = CalculateService.calculateNextPositionByStartAndLen(stopPointPosition, !right, 3); + headPosition = CalculateService.calculateNextPositionByStartAndLen(stopPointPosition, !right, 3, true); } train.setHeadPosition(headPosition); //更新位置 if (occupiedSection.isFunctionTrack()) { //功能轨可能需要停车 diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/virtual/VRDeviceLogicLoop.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/virtual/VRDeviceLogicLoop.java index 302ccbf39..13765bae1 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/virtual/VRDeviceLogicLoop.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/virtual/VRDeviceLogicLoop.java @@ -50,7 +50,7 @@ public class VRDeviceLogicLoop { for (VirtualRealityTrain train : onlineTrainList) { SectionPosition headPosition = train.getHeadPosition(); boolean right = train.isRight(); - SectionPosition tailPosition = CalculateService.calculateNextPositionByStartAndLen(headPosition, !right, train.getLen()); + SectionPosition tailPosition = CalculateService.calculateNextPositionByStartAndLen(headPosition, !right, train.getLen(), true); List
occupyAxleSectionList = CalculateService .getTrainOccupyAxleSection(headPosition, tailPosition, right); // 更新占用区段的占用状态 diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/device/virtual/VRTrainRunningService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/device/virtual/VRTrainRunningService.java index 3fe9541ef..f37495659 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/device/virtual/VRTrainRunningService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/device/virtual/VRTrainRunningService.java @@ -85,7 +85,7 @@ public class VRTrainRunningService { } boolean right = train.isRight(); SectionPosition headPosition = train.getHeadPosition(); - SectionPosition headPositionNew = CalculateService.calculateNextPositionByStartAndLen(headPosition, right, s); + SectionPosition headPositionNew = CalculateService.calculateNextPositionByStartAndLen(headPosition, right, s, true); //更新车头区段(不会碰撞才更新) boolean change = true; for (VirtualRealityTrain aTrain : simulation.getRepository().getOnlineTrainList()) { @@ -95,7 +95,7 @@ public class VRTrainRunningService { if (s > 0) { //向前行驶 checkPosition = headPositionNew; } else { //向后行驶 - checkPosition = CalculateService.calculateNextPositionByStartAndLen(headPositionNew, !right, train.getLen()); + checkPosition = CalculateService.calculateNextPositionByStartAndLen(headPositionNew, !right, train.getLen(), true); } Section checkSection = checkPosition.getSection(); SectionPosition aTrainHeadPosition = aTrain.getHeadPosition(); @@ -150,13 +150,13 @@ public class VRTrainRunningService { } } //离开计轴区段判断 - SectionPosition tailPositionOld = CalculateService.calculateNextPositionByStartAndLen(headPosition, !trainRight, train.getLen()); + SectionPosition tailPositionOld = CalculateService.calculateNextPositionByStartAndLen(headPosition, !trainRight, train.getLen(), true); Section tailAxleCounterSection = tailPositionOld.getSection(); if (!tailAxleCounterSection.isAxleCounter()) { tailAxleCounterSection = tailAxleCounterSection.getParent(); } if (tailAxleCounterSection != null && tailAxleCounterSection.isAxleCounter()) { //老的车尾区段是计轴区段 - SectionPosition tailPositionNew = CalculateService.calculateNextPositionByStartAndLen(headPositionNew, !trainRight, train.getLen()); + SectionPosition tailPositionNew = CalculateService.calculateNextPositionByStartAndLen(headPositionNew, !trainRight, train.getLen(), true); Section tailSectionNew = tailPositionNew.getSection(); if (!tailAxleCounterSection.equals(tailSectionNew) && !tailAxleCounterSection.equals(tailSectionNew.getParent())) { //老车尾计轴区段和新车尾区段不一样 tailAxleCounterSection.getVirtualAxleCounter().trainOut(trainRight); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATP/ATPService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATP/ATPService.java index c715a7217..b11aa3d61 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATP/ATPService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/ATP/ATPService.java @@ -273,7 +273,7 @@ public class ATPService { newHeadPosition = new SectionPosition(section, offset); } else { newHeadPosition = CalculateService - .calculateNextPositionByStartAndLen(headPosition, !right, train.getLen()); + .calculateNextPositionByStartAndLen(headPosition, !right, train.getLen(), false); } // 车尾变车头,车头变车尾 train.setHeadPosition(newHeadPosition); diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/TrainTargetUpdateService.java b/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/TrainTargetUpdateService.java index 898593198..e6077d485 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/TrainTargetUpdateService.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/onboard/TrainTargetUpdateService.java @@ -71,7 +71,7 @@ public class TrainTargetUpdateService { if (!temp.getCode().equals(trainInfo.getActualArriveStandTrack())) { //列车未在该区段停车 SectionPosition maxStopPosition = CalculateService .calculateNextPositionByStartAndLen(temp.buildStopPointPosition(right), - right, SimulationConstants.PARK_POINT_MAX_OFFSET); //最远停车点 + right, SimulationConstants.PARK_POINT_MAX_OFFSET, false); //最远停车点 if (maxStopPosition.isAheadOf(headPosition, right)) { //该区段最远停车点在车头前方 newTarget = temp; break; diff --git a/src/main/java/club/joylink/rtss/simulation/cbtc/robot/RobotLogicLoop.java b/src/main/java/club/joylink/rtss/simulation/cbtc/robot/RobotLogicLoop.java index 812192b9b..3600e8f26 100644 --- a/src/main/java/club/joylink/rtss/simulation/cbtc/robot/RobotLogicLoop.java +++ b/src/main/java/club/joylink/rtss/simulation/cbtc/robot/RobotLogicLoop.java @@ -192,7 +192,7 @@ public class RobotLogicLoop { // operationParams.put("percent", 0); // atsOperationDispatcher.execute(simulation, driver, Operation.Type.Driver_Force_Change.name(), operationParams); // } - SectionPosition tailPosition = CalculateService.calculateNextPositionByStartAndLen(headPosition, !right, train.getLen()); + SectionPosition tailPosition = CalculateService.calculateNextPositionByStartAndLen(headPosition, !right, train.getLen(), true); SpeedCurve speedCurve = null; switch (train.getDriveMode()) { case AM: //AM模式下不需要司机驾驶