CI系统重构

This commit is contained in:
walker-sheng 2021-09-02 15:41:44 +08:00
parent 05b61765f5
commit 7908d8c76b
10 changed files with 279 additions and 24 deletions

View File

@ -3,7 +3,6 @@ package club.joylink.rtss.simulation.cbtc.CI.device;
import club.joylink.rtss.simulation.cbtc.Simulation; import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository; import club.joylink.rtss.simulation.cbtc.data.SimulationDataRepository;
import club.joylink.rtss.simulation.cbtc.data.map.Signal; import club.joylink.rtss.simulation.cbtc.data.map.Signal;
import club.joylink.rtss.simulation.cbtc.data.map.Station;
import club.joylink.rtss.simulation.cbtc.data.map.Switch; import club.joylink.rtss.simulation.cbtc.data.map.Switch;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySignal;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch; import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch;
@ -23,20 +22,6 @@ public class CiDeviceStatusCollector {
private void collectSwitch(SimulationDataRepository repository, List<Switch> switchList) { private void collectSwitch(SimulationDataRepository repository, List<Switch> switchList) {
// 道岔位置状态 // 道岔位置状态
switchList.forEach(aSwitch -> { switchList.forEach(aSwitch -> {
//联锁机故障逻辑
Station deviceStation = aSwitch.getDeviceStation();
if (deviceStation != null) {
if (Station.Fault.INTERLOCK_MACHINE_FAULT.equals(deviceStation.getFault())) {
aSwitch.setNoStatus(true);
return;
} else {
aSwitch.setNoStatus(false);
}
if (deviceStation.isInterlockMachineStarting())
return;
} else {
aSwitch.setNoStatus(false);
}
VirtualRealitySwitch vrSwitch = aSwitch.getVirtualSwitch(); VirtualRealitySwitch vrSwitch = aSwitch.getVirtualSwitch();
aSwitch.updatePos(vrSwitch.getP()); aSwitch.updatePos(vrSwitch.getP());
}); });

View File

@ -0,0 +1,132 @@
package club.joylink.rtss.simulation.cbtc.CI.device;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SwitchIndication;
import club.joylink.rtss.simulation.cbtc.data.map.*;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.List;
import java.util.Objects;
@Component
public class CiRouteService {
/**
* 进路排列检查
* @param simulation
* @param route
* @return
*/
public Route.CheckFailMessage routeSetCheck(Simulation simulation, Route route) {
MapConfig config = simulation.getRepository().getConfig();
Signal start = route.getStart();
if (!config.isSignalBlockRouteSettable()) {
// 信号封锁不能办理
if (start.isBlockade()) {
return new Route.CheckFailMessage(Route.CheckFailReason.StartSignalBlockade, start);
}
}
// 进路中道岔没有被征用或锁定在相反位置
List<SwitchElement> switchList = route.getSwitchList();
for (SwitchElement switchElement : switchList) {
Switch aSwitch = switchElement.getASwitch();
if (aSwitch.isBlockade()) { // 道岔封锁
return new Route.CheckFailMessage(Route.CheckFailReason.SwitchBlockade, aSwitch);
}
if ((aSwitch.isLocked() || aSwitch.isSectionOccupied()) &&
aSwitch.getPos().equals(SwitchIndication.of(!switchElement.isNormal()))) {//道岔锁闭或占用在相反位置
return new Route.CheckFailMessage(Route.CheckFailReason.SwitchLockPositionError, aSwitch);
}
if (aSwitch.isCiUseOnOppositePosition(switchElement.isNormal())) { // 道岔征用在相反位置
return new Route.CheckFailMessage(Route.CheckFailReason.SwitchCiUseOnOppositePosition, aSwitch);
}
}
// 进路内区段封锁/锁闭方向检查
List<Section> sectionList = route.getSectionList();
for (Section section : sectionList) {
// 封锁状态
if (section.isBlockade()) {
return new Route.CheckFailMessage(Route.CheckFailReason.SectionBlockade, section);
} else if (!CollectionUtils.isEmpty(section.getLogicList())) {
for (Section logicSection : section.getLogicList()) {
if (logicSection.isBlockade()) {
return new Route.CheckFailMessage(Route.CheckFailReason.SectionBlockade, logicSection);
}
}
} else if (section.getParent() != null) {
if (section.getParent().isCross() && section.getParent().isBlockade()) {
return new Route.CheckFailMessage(Route.CheckFailReason.SectionBlockade, section);
}
}
// 进路内区段锁闭方向不是此进路方向
if ((section.isRouteLock() || section.isOverlapLock()) &&
!Objects.equals(section.isLockRight(), start.isRight())) {
return new Route.CheckFailMessage(Route.CheckFailReason.SectionLockOppositeDirection, section);
}
}
//敌对进路
List<Route> conflictingRouteList = route.getConflictingRouteList();
for (Route conflict : conflictingRouteList) {
if (conflict.isSetting() || conflict.isLock()) {
return new Route.CheckFailMessage(Route.CheckFailReason.ConflictingRouteSetting, conflict);
}
}
return null;
}
/**
* 排列进路
* @param simulation
* @param route
*/
public void setRoute(Simulation simulation, Route route) {
}
/**
* 排列进路过程控制
* @param simulation
* @param route
*/
public void routeSettingProcess(Simulation simulation, Route route) {
}
/**
* 取消进路
* @param simulation
* @param route
*/
public void cancelRoute(Simulation simulation, Route route) {
}
/**
* 延续保护办理
* @param simulation
* @param overlap
*/
public void setOverlap(Simulation simulation, RouteOverlap overlap) {
}
/**
* 延续保护办理过程
* @param simulation
* @param overlap
*/
public void overlapSettingProcess(Simulation simulation, RouteOverlap overlap) {
}
/**
* 联锁检查
* @param simulation
* @param route
*/
public void interlockCheck(Simulation simulation, Route route) {
}
}

View File

@ -0,0 +1,12 @@
package club.joylink.rtss.simulation.cbtc.CI.device;
import org.springframework.stereotype.Component;
@Component
public class CiService {
public void interlockCheck() {
}
}

View File

@ -0,0 +1,7 @@
package club.joylink.rtss.simulation.cbtc.CI.device;
import org.springframework.stereotype.Component;
@Component
public class CiSignalControlService {
}

View File

@ -0,0 +1,94 @@
package club.joylink.rtss.simulation.cbtc.CI.device;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.data.map.Switch;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealitySwitch;
import club.joylink.rtss.simulation.cbtc.device.virtual.VirtualRealityDeviceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Component
public class CiSwitchControlService {
@Autowired
private VirtualRealityDeviceService virtualRealityDeviceService;
/**
* 强转道岔
* @param simulation
* @param aSwitch
* @return
*/
public boolean forceTurn(Simulation simulation, Switch aSwitch) {
if (!aSwitch.isSectionOccupied()) {
return false;
}
if (aSwitch.isLocked()) {
return false;
}
// 设置强扳授权
aSwitch.setForceTurnRemain(120 * 1000);
this.turn(simulation, aSwitch);
// 手动释放强扳
aSwitch.setForceTurnRemain(0);
return true;
}
/**
* 道岔转动
* @param simulation
* @param aSwitch
* @return
*/
public boolean turn(Simulation simulation, Switch aSwitch) {
VirtualRealitySwitch vrSwitch = aSwitch.getVirtualSwitch();
if (vrSwitch.getCommand() != null) {
switch (vrSwitch.getCommand()) {
case NP:
return this.turn2ReversePosition(simulation, aSwitch);
case RP:
return this.turn2NormalPosition(simulation, aSwitch);
}
}
return this.turn2NormalPosition(simulation, aSwitch);
}
/**
* 道岔定操
* @param simulation
* @param aSwitch
*/
public boolean turn2NormalPosition(Simulation simulation, Switch aSwitch) {
if (!this.checkTurnCondition(aSwitch)) {
return false;
}
VirtualRealitySwitch vrSwitch = aSwitch.getVirtualSwitch();
this.virtualRealityDeviceService.control(simulation, vrSwitch, VirtualRealitySwitch.SwitchOperation.NP);
return true;
}
/**
* 道岔反操
* @param simulation
* @param aSwitch
* @return
*/
public boolean turn2ReversePosition(Simulation simulation, Switch aSwitch) {
if (!this.checkTurnCondition(aSwitch)) {
return false;
}
VirtualRealitySwitch vrSwitch = aSwitch.getVirtualSwitch();
this.virtualRealityDeviceService.control(simulation, vrSwitch, VirtualRealitySwitch.SwitchOperation.RP);
return true;
}
/**
* 检查道岔转动条件
* @param aSwitch
* @return
*/
private boolean checkTurnCondition(Switch aSwitch) {
// 道岔锁闭 或者 道岔占用且无强扳授权则不能转动
return !(aSwitch.isLocked() || (aSwitch.isSectionOccupied() && aSwitch.getForceTurnRemain() <= 0));
}
}

View File

@ -8,9 +8,17 @@ public enum SwitchIndication {
N, N,
/** 反位 */ /** 反位 */
R, R,
/** 无 */ /** 无(失表) */
NO, NO,
/** 挤叉 */ /** 挤叉 */
EX, EX,
; ;
public static SwitchIndication of(boolean normal) {
if (normal) {
return N;
} else {
return R;
}
}
} }

View File

@ -146,6 +146,10 @@ public class Switch extends MayOutOfOrderDevice {
* 初始化 * 初始化
*/ */
private boolean init; private boolean init;
/**
* 道岔强扳授权剩余时间,单位ms
*/
private int forceTurnRemain;
/** /**
* 上一次是否是将道岔转向定位 * 上一次是否是将道岔转向定位
@ -175,6 +179,7 @@ public class Switch extends MayOutOfOrderDevice {
this.blockadeInvalid = false; this.blockadeInvalid = false;
this.init = false; this.init = false;
this.lastTurnToNormal = null; this.lastTurnToNormal = null;
this.forceTurnRemain = 0;
} }
/** /**

View File

@ -26,17 +26,24 @@ public abstract class ControllableVrDevice<C> extends VirtualRealityDevice {
} }
public boolean control(C command) { public boolean control(C command) {
if (this.command != null && this.command.equals(command)) { //已经在执行指令 if (this.command != null && this.command.equals(command)) { //相同指令
return false;
}
if (!this.checkConditionBeforeControl(command)) { //是否符合条件
return false; return false;
} }
this.doBeforeControl(command);
this.command = command; this.command = command;
this.remain = this.turnTime; this.remain = this.turnTime;
return true; return true;
} }
protected void doBeforeControl(C command) { /**
* 接受指定前的条件检查
* @param command
* @return true-符合条件可以控制false-不符合不能控制
*/
protected boolean checkConditionBeforeControl(C command) {
return true;
} }
/** /**
@ -55,7 +62,6 @@ public abstract class ControllableVrDevice<C> extends VirtualRealityDevice {
private void finish() { private void finish() {
this.doFinish(this.command); this.doFinish(this.command);
this.command = null;
this.remain = 0; this.remain = 0;
} }

View File

@ -16,8 +16,14 @@ import java.util.Objects;
@Setter @Setter
public class VirtualRealitySwitch extends ControllableVrDevice<VirtualRealitySwitch.SwitchOperation> { public class VirtualRealitySwitch extends ControllableVrDevice<VirtualRealitySwitch.SwitchOperation> {
@Override @Override
protected void doBeforeControl(SwitchOperation command) { protected boolean checkConditionBeforeControl(SwitchOperation command) {
switch (command) {
case NP:
return !(SwitchIndication.N == this.p);
case RP:
return !(SwitchIndication.R == this.p);
}
return true;
} }
@Override @Override

View File

@ -33,7 +33,7 @@ public class VirtualRealityDeviceService {
} }
public void turning(Simulation simulation, ControllableVrDevice device) { public void turning(Simulation simulation, ControllableVrDevice device) {
if (!device.isConnectReal() && device.getCommand() != null) { if (!device.isConnectReal() && device.getRemain() > 0) {
device.turning(SimulationModule.VRD.getRateMs()); device.turning(SimulationModule.VRD.getRateMs());
} }
} }