包调整
This commit is contained in:
parent
7f0a9284fe
commit
986fc71d60
@ -1,92 +0,0 @@
|
||||
package club.joylink.rtss.simulation.rt.SRD;
|
||||
|
||||
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
|
||||
import club.joylink.rtss.simulation.rt.RtSimulation;
|
||||
import club.joylink.rtss.simulation.rt.SRD.bo.*;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class SrdApiService {
|
||||
|
||||
private SrdRepository getSrdRepository(RtSimulation rtSimulation) {
|
||||
SrdRepository repository = rtSimulation.getRepository(SrdRepository.NAME, SrdRepository.class);
|
||||
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(repository);
|
||||
return repository;
|
||||
}
|
||||
|
||||
public List<SrAXC> queryAllAxc(RtSimulation rtSimulation) {
|
||||
SrdRepository repository = this.getSrdRepository(rtSimulation);
|
||||
return repository.getAxcList();
|
||||
}
|
||||
|
||||
public List<SrSwitch> queryAllSwitch(RtSimulation rtSimulation) {
|
||||
SrdRepository repository = this.getSrdRepository(rtSimulation);
|
||||
return repository.getSwitchList();
|
||||
}
|
||||
|
||||
public List<SrSignal> queryAllSignal(RtSimulation rtSimulation) {
|
||||
SrdRepository repository = this.getSrdRepository(rtSimulation);
|
||||
return repository.getSignalList();
|
||||
}
|
||||
|
||||
public List<SrPSD> queryAllPsd(RtSimulation rtSimulation) {
|
||||
SrdRepository repository = this.getSrdRepository(rtSimulation);
|
||||
return repository.getPsdList();
|
||||
}
|
||||
|
||||
public void turnSwitch(RtSimulation rtSimulation, String switchId, int position) {
|
||||
SrdRepository repository = this.getSrdRepository(rtSimulation);
|
||||
SrSwitch srSwitch = repository.getSwitchById(switchId);
|
||||
boolean startTurn = false;
|
||||
if (SrSwitch.NORMAL == position) {
|
||||
startTurn = srSwitch.turnToNormal(rtSimulation.getSystemTime());
|
||||
} else if (SrSwitch.REVERSE == position) {
|
||||
startTurn = srSwitch.turnToReverse(rtSimulation.getSystemTime());
|
||||
} else {
|
||||
throw BusinessExceptionAssertEnum.ARGUMENT_ILLEGAL.exception();
|
||||
}
|
||||
if (startTurn) {
|
||||
// 发送道岔开始转换
|
||||
}
|
||||
}
|
||||
|
||||
public void changeSignalLight(RtSimulation rtSimulation, String id, int aspect) {
|
||||
SrdRepository srdRepository = this.getSrdRepository(rtSimulation);
|
||||
SrSignal srSignal = srdRepository.getSignalById(id);
|
||||
boolean change = false;
|
||||
if (srSignal.getState() != aspect) {
|
||||
LocalDateTime systemTime = rtSimulation.getSystemTime();
|
||||
switch (aspect) {
|
||||
case SrSignal.OFF:{
|
||||
srSignal.close(systemTime);
|
||||
break;
|
||||
}
|
||||
case SrSignal.RED:{
|
||||
srSignal.openRed(systemTime);
|
||||
break;
|
||||
}
|
||||
case SrSignal.GREEN:{
|
||||
srSignal.openGreen(systemTime);
|
||||
break;
|
||||
}
|
||||
case SrSignal.YELLOW: {
|
||||
srSignal.openYellow(systemTime);
|
||||
break;
|
||||
}
|
||||
case SrSignal.GUIDE: {
|
||||
srSignal.openGuide(systemTime);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.exception(String.format("无效的信号机显示:[%s]", aspect));
|
||||
}
|
||||
change = true;
|
||||
}
|
||||
if (change) {
|
||||
// 发送信号机变更
|
||||
}
|
||||
}
|
||||
}
|
@ -1,177 +0,0 @@
|
||||
package club.joylink.rtss.simulation.rt.SRD;
|
||||
|
||||
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
|
||||
import club.joylink.rtss.simulation.rt.RtSimulation;
|
||||
import club.joylink.rtss.simulation.rt.SRD.bo.*;
|
||||
import club.joylink.rtss.vo.client.map.MapVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* 虚拟真实设备运行逻辑
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class SrdLogicService {
|
||||
public static final int TRAIN_RUN_RATE = 20; // 列车运行逻辑频率
|
||||
public static final int DEVICE_RUN_RATE = 500; // 其他设备逻辑频率
|
||||
|
||||
public void buildRepository(RtSimulation rtSimulation, MapVO mapVO) {
|
||||
SrdRepository srdRepository = SrdRepositoryBuilder.buildFrom(mapVO);
|
||||
rtSimulation.addRepository(srdRepository);
|
||||
}
|
||||
|
||||
public void addJobs(RtSimulation rtSimulation) {
|
||||
rtSimulation.addJob("srTrainRun",
|
||||
() -> this.srTrainRun(rtSimulation.getRepository(SrdRepository.NAME, SrdRepository.class)),
|
||||
TRAIN_RUN_RATE);
|
||||
rtSimulation.addJob("srDeviceLogic",
|
||||
() -> this.srDeviceLogic(rtSimulation.getRepository(SrdRepository.NAME, SrdRepository.class), rtSimulation.getSystemTime()),
|
||||
DEVICE_RUN_RATE);
|
||||
}
|
||||
|
||||
private void srDeviceLogic(SrdRepository repository, LocalDateTime systemTime) {
|
||||
// 道岔转动
|
||||
List<SrSwitch> turnoutList = repository.getSwitchList();
|
||||
for (SrSwitch turnout : turnoutList) {
|
||||
if (turnout.isControlByReal()) {
|
||||
continue;
|
||||
}
|
||||
if (turnout.isTurning()) {
|
||||
turnout.tryFinishTurning(systemTime);
|
||||
}
|
||||
}
|
||||
// 屏蔽门开/闭
|
||||
List<SrPSD> psdList = repository.getPsdList();
|
||||
for (SrPSD psd : psdList) {
|
||||
if (psd.isControlByReal()) {
|
||||
continue;
|
||||
}
|
||||
if (psd.isTurning()) {
|
||||
psd.tryFinishTurning(systemTime);
|
||||
}
|
||||
}
|
||||
// 信号机控制
|
||||
List<SrSignal> signalList = repository.getSignalList();
|
||||
for (SrSignal signal : signalList) {
|
||||
if (signal.isControlByReal()) {
|
||||
continue;
|
||||
}
|
||||
if (signal.isTurning()) {
|
||||
signal.tryFinishTurning(systemTime);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void srTrainRun(SrdRepository repository) {
|
||||
List<SrTrain> trainList = repository.getTrainList();
|
||||
for (SrTrain srTrain : trainList) {
|
||||
if (!srTrain.isUsing()) {
|
||||
continue;
|
||||
}
|
||||
// 计算列车加速度,更新列车速度,计算列车运行距离,更新列车位置
|
||||
boolean right = srTrain.isRight();
|
||||
TrackPosition position = srTrain.getHeadPosition();
|
||||
int cv = this.calculateSpeed(srTrain);
|
||||
int s = this.calculateLen(srTrain, cv, TRAIN_RUN_RATE);
|
||||
TrackPosition np = calculatePosition(position, s, right, new HashSet<>());
|
||||
if (np.equals(position) && cv != 0) {
|
||||
cv = 0;
|
||||
}
|
||||
Set<SrTrack> occupiedTrackSet = new HashSet<>();
|
||||
TrackPosition tailPosition = this.calculatePosition(np, srTrain.getLen(), !right, occupiedTrackSet);
|
||||
srTrain.updatePositionAndSpeed(np, tailPosition, cv);
|
||||
// 更新计轴占用
|
||||
Set<SrTrack> oldOccupiedTrackSet = new HashSet<>();
|
||||
this.calculatePosition(position, srTrain.getLen(), !right, oldOccupiedTrackSet);
|
||||
Set<SrTrack> clearList = new HashSet<>(oldOccupiedTrackSet);
|
||||
clearList.removeAll(occupiedTrackSet);
|
||||
for (SrTrack srTrack : clearList) {
|
||||
srTrack.getAxc().clear();
|
||||
}
|
||||
for (SrTrack srTrack : occupiedTrackSet) {
|
||||
srTrack.getAxc().occupy();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int calculateLen(SrTrain srTrain, int cv, int time) {
|
||||
int s = cv * time;
|
||||
return s * srTrain.getGear();
|
||||
}
|
||||
|
||||
private int calculateSpeed(SrTrain srTrain) {
|
||||
long speed = srTrain.getSpeed();
|
||||
int wa = (int) (10 + speed * 0.001 + speed * speed * 0.0000003); // 阻力所产生的反向加速度
|
||||
int pa = 0;
|
||||
if (srTrain.isEb()) {
|
||||
pa = SrTrain.ES_DEC;
|
||||
} else {
|
||||
pa = srTrain.getP() >= 0 ? srTrain.getP() * SrTrain.MAX_ACC : srTrain.getP() * SrTrain.MAX_DEC;
|
||||
}
|
||||
int a = pa - wa;
|
||||
int cv = (int) (speed + a * TRAIN_RUN_RATE); // 当前速度
|
||||
if (cv < 0) {
|
||||
cv = 0;
|
||||
}
|
||||
if (srTrain.isNeutralGear() && cv > 0) { // 空档位
|
||||
cv = 0;
|
||||
}
|
||||
return cv;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param position 起始位置
|
||||
* @param s 距离
|
||||
* @param right 方向
|
||||
* @param trackSet 从position往方向[right]经过距离[s]所经过的轨道列表
|
||||
* @return
|
||||
*/
|
||||
private TrackPosition calculatePosition(TrackPosition position, int s, boolean right, Set<SrTrack> trackSet) {
|
||||
if (s == 0) {
|
||||
return position;
|
||||
}
|
||||
SrTrack track = position.getTrack();
|
||||
int offset = position.getOffset();
|
||||
if (right) {
|
||||
offset += s;
|
||||
} else {
|
||||
offset -= s;
|
||||
}
|
||||
SrTrack base = track;
|
||||
trackSet.add(base);
|
||||
int iter = 0;
|
||||
while (offset < 0 || offset > base.getLen()) {
|
||||
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(iter < 10);
|
||||
++iter;
|
||||
SrTrack nextTrack = base.queryNextTrack(right);
|
||||
if (nextTrack == null) { // 下一区段为空,到达尽头或道岔失表处
|
||||
log.debug(String.format("区段[%s][%s]区段不存在",base.debugStr(), right?"右向":"左向"));
|
||||
if (offset < 0) {
|
||||
offset = 0;
|
||||
} else {
|
||||
offset = base.getLen();
|
||||
}
|
||||
break;
|
||||
} else {
|
||||
if (right) {
|
||||
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(offset > base.getLen());
|
||||
offset -= base.getLen();
|
||||
} else {
|
||||
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(offset < 0);
|
||||
offset += nextTrack.getLen();
|
||||
}
|
||||
base = nextTrack;
|
||||
trackSet.add(nextTrack);
|
||||
}
|
||||
}
|
||||
return new TrackPosition(base, offset);
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
package club.joylink.rtss.simulation.rt.SRD.bo;
|
||||
|
||||
public enum DeviceType {
|
||||
/** 计轴器 */
|
||||
AXC,
|
||||
/** 道岔 */
|
||||
TURNOUT,
|
||||
/** 信号机 */
|
||||
SIGNAL,
|
||||
/** 站台屏蔽门 */
|
||||
PSD,
|
||||
TRAIN,
|
||||
/** 轨道 */
|
||||
TRACK
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
package club.joylink.rtss.simulation.rt.SRD.bo;
|
||||
|
||||
/**
|
||||
* 虚拟真实计轴器(Axle counter)
|
||||
*/
|
||||
public class SrAXC extends SrDevice {
|
||||
|
||||
int state = OFF;
|
||||
public static final int OFF = 0;//出清
|
||||
public static final int ON = 1;//占用
|
||||
|
||||
public SrAXC(String id) {
|
||||
super(id, DeviceType.AXC);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
this.state = OFF;
|
||||
}
|
||||
|
||||
public void occupy() {
|
||||
if (this.state != ON) {
|
||||
this.state=ON;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOccupy() {
|
||||
return this.state == ON;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyState(int state) {
|
||||
|
||||
}
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
package club.joylink.rtss.simulation.rt.SRD.bo;
|
||||
|
||||
import club.joylink.rtss.simulation.Debug;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 虚拟真实设备抽象父类
|
||||
*/
|
||||
@Getter
|
||||
public abstract class SrDevice implements Debug {
|
||||
String id;
|
||||
DeviceType deviceType;
|
||||
/**
|
||||
* 是否由真实设备控制
|
||||
*/
|
||||
boolean controlByReal;
|
||||
|
||||
public SrDevice() {}
|
||||
|
||||
public SrDevice(String id, DeviceType deviceType) {
|
||||
this.id = id;
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
|
||||
public abstract void applyState(int state);
|
||||
|
||||
@Override
|
||||
public String debugStr() {
|
||||
return String.format("%s:%s", this.deviceType, this.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
SrDevice srDevice = (SrDevice) o;
|
||||
return Objects.equals(id, srDevice.id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(id);
|
||||
}
|
||||
}
|
@ -1,72 +0,0 @@
|
||||
package club.joylink.rtss.simulation.rt.SRD.bo;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* 虚拟真实屏蔽门(Platform screen door)
|
||||
*/
|
||||
public class SrPSD extends SrDevice {
|
||||
public static final int turnTime = 3000; // 默认开关门时间,单位ms
|
||||
|
||||
int state = CLOSE_LOCK;
|
||||
public static final int CLOSE_LOCK = 1;//关闭且锁闭
|
||||
public static final int CLOSED = 2;//关闭未锁闭
|
||||
public static final int TURNING = 3;//转换中
|
||||
public static final int OPEN_FINISH = 4;//打开到位
|
||||
|
||||
AtomicInteger command = new AtomicInteger(NONE);
|
||||
public static final int NONE = 0;//无动作
|
||||
/**
|
||||
* 转换完成时间
|
||||
*/
|
||||
LocalDateTime finishTime;
|
||||
|
||||
public SrPSD(String id) {
|
||||
super(id, DeviceType.PSD);
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public boolean isTurning() {
|
||||
return NONE != this.command.get();
|
||||
}
|
||||
|
||||
public void open(LocalDateTime systemTime) {
|
||||
this.startTurn(systemTime, OPEN_FINISH);
|
||||
}
|
||||
|
||||
public void close(LocalDateTime systemTime) {
|
||||
this.startTurn(systemTime, CLOSE_LOCK);
|
||||
}
|
||||
|
||||
private void startTurn(LocalDateTime systemTime, int command) {
|
||||
this.finishTime = systemTime.plusNanos(TimeUnit.MILLISECONDS.toNanos(turnTime));
|
||||
this.command.set(command);
|
||||
this.state = TURNING;
|
||||
}
|
||||
|
||||
public void tryFinishTurning(LocalDateTime systemTime) {
|
||||
if (this.finishTime != null && systemTime.compareTo(this.finishTime) >= 0) {
|
||||
this.turnFinish();
|
||||
}
|
||||
}
|
||||
|
||||
public void turnFinish() {
|
||||
this.state = this.command.get();
|
||||
this.command.set(NONE);
|
||||
this.finishTime = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyState(int state) {
|
||||
if (CLOSE_LOCK == state || CLOSED == state || TURNING == state || OPEN_FINISH == state) {
|
||||
this.state = state;
|
||||
} else {
|
||||
throw new IllegalArgumentException(String.format("无效的屏蔽门状态:[%s]", state));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
package club.joylink.rtss.simulation.rt.SRD.bo;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* 虚拟真实信号机
|
||||
*/
|
||||
@Getter
|
||||
public class SrSignal extends SrDevice {
|
||||
public static final int turnTime = 500; // 默认转换时间,单位ms
|
||||
|
||||
/**
|
||||
* 所在区段
|
||||
*/
|
||||
SrTrack track;
|
||||
/**
|
||||
* 所在区段偏移量,单位mm
|
||||
*/
|
||||
int offset;
|
||||
|
||||
int state = OFF;
|
||||
public static final int OFF = 0; // 关闭
|
||||
public static final int RED = 1; // 红灯信号(禁止信号)
|
||||
public static final int GREEN = 2; // 绿灯信号(直向通行)
|
||||
public static final int YELLOW = 3; // 黄灯信号(侧向通行)
|
||||
public static final int GUIDE = 4; // 引导信号(正线为黄红)
|
||||
|
||||
AtomicInteger command = new AtomicInteger(NONE);
|
||||
public static final int NONE = 0;
|
||||
/**
|
||||
* 转换完成时间
|
||||
*/
|
||||
LocalDateTime finishTime;
|
||||
|
||||
public SrSignal(String id) {
|
||||
super(id, DeviceType.SIGNAL);
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setTrackAndOffset(SrTrack srTrack, int offset) {
|
||||
this.track = srTrack;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public boolean isTurning() {
|
||||
return NONE != this.command.get();
|
||||
}
|
||||
|
||||
public void close(LocalDateTime systemTime) {
|
||||
this.startTurn(systemTime, OFF);
|
||||
}
|
||||
|
||||
public void openRed(LocalDateTime systemTime) {
|
||||
this.startTurn(systemTime, RED);
|
||||
}
|
||||
|
||||
public void openGreen(LocalDateTime systemTime) {
|
||||
this.startTurn(systemTime, GREEN);
|
||||
}
|
||||
|
||||
public void openYellow(LocalDateTime systemTime) {
|
||||
this.startTurn(systemTime, YELLOW);
|
||||
}
|
||||
|
||||
public void openGuide(LocalDateTime systemTime) {
|
||||
this.startTurn(systemTime, GUIDE);
|
||||
}
|
||||
|
||||
private void startTurn(LocalDateTime systemTime, int command) {
|
||||
this.finishTime = systemTime.plusNanos(TimeUnit.MILLISECONDS.toNanos(turnTime));
|
||||
this.command.set(command);
|
||||
}
|
||||
|
||||
public void tryFinishTurning(LocalDateTime systemTime) {
|
||||
if (this.finishTime != null && systemTime.compareTo(this.finishTime) >= 0) {
|
||||
this.turnFinish();
|
||||
}
|
||||
}
|
||||
|
||||
public void turnFinish() {
|
||||
this.state = this.command.get();
|
||||
this.command.set(NONE);
|
||||
this.finishTime = null;
|
||||
}
|
||||
@Override
|
||||
public void applyState(int state) {
|
||||
if (OFF == state || RED == state || GREEN == state || YELLOW == state || GUIDE == state) {
|
||||
this.state = state;
|
||||
} else {
|
||||
throw new IllegalArgumentException(String.format("无效的道岔状态:[%s]", state));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
package club.joylink.rtss.simulation.rt.SRD.bo;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* 虚拟真实道岔
|
||||
*/
|
||||
public class SrSwitch extends SrDevice {
|
||||
public static final int turnTime = 3000; // 默认转换时间
|
||||
|
||||
SrTrack a;
|
||||
SrTrack b;
|
||||
SrTrack c;
|
||||
|
||||
int state = NORMAL;
|
||||
public static final int LOST = 0; // 失表
|
||||
public static final int NORMAL = 1; // 定位
|
||||
public static final int REVERSE = 2; // 反位
|
||||
public static final int SQUEEZING = 4; // 挤叉
|
||||
|
||||
AtomicInteger command = new AtomicInteger(NONE);
|
||||
public static final int NONE = 0;
|
||||
/**
|
||||
* 转换完成时间
|
||||
*/
|
||||
LocalDateTime finishTime;
|
||||
|
||||
public SrSwitch(String id) {
|
||||
super(id, DeviceType.TURNOUT);
|
||||
}
|
||||
|
||||
void setTracks(SrTrack a, SrTrack b, SrTrack c) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
a.srSwitch = this;
|
||||
b.srSwitch = this;
|
||||
c.srSwitch = this;
|
||||
if (this.a.leftTrack == null && this.a.rightTrack == null) {
|
||||
throw new IllegalStateException("道岔a区段两端都没有关联的区段");
|
||||
}
|
||||
if (this.a.leftTrack != null) { // a左侧存在
|
||||
this.a.setRightTrack(this.b);
|
||||
this.a.setRightFlankTrack(this.c);
|
||||
} else { // a右侧存在
|
||||
this.a.setLeftTrack(this.b);
|
||||
this.a.setLeftFlankTrack(this.c);
|
||||
}
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public boolean isNormalPosition() {
|
||||
return NORMAL == this.state;
|
||||
}
|
||||
|
||||
public boolean isReversePosition() {
|
||||
return REVERSE == this.state;
|
||||
}
|
||||
|
||||
public boolean isTurning() {
|
||||
return NONE != this.command.get();
|
||||
}
|
||||
|
||||
public boolean turnToNormal(LocalDateTime systemTime) {
|
||||
if (this.isNormalPosition() || this.command.get() == NORMAL) {
|
||||
return false;
|
||||
}
|
||||
this.startTurn(systemTime, NORMAL);
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean turnToReverse(LocalDateTime systemTime) {
|
||||
if (this.isReversePosition() || this.command.get() == REVERSE) {
|
||||
return false;
|
||||
}
|
||||
this.startTurn(systemTime, REVERSE);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void startTurn(LocalDateTime systemTime, int command) {
|
||||
this.finishTime = systemTime.plusNanos(TimeUnit.MILLISECONDS.toNanos(turnTime));
|
||||
this.command.set(command);
|
||||
this.state = LOST;
|
||||
}
|
||||
|
||||
public void tryFinishTurning(LocalDateTime systemTime) {
|
||||
if (this.finishTime != null && systemTime.compareTo(this.finishTime) >= 0) {
|
||||
this.turnFinish();
|
||||
}
|
||||
}
|
||||
|
||||
public void turnFinish() {
|
||||
this.state = this.command.get();
|
||||
this.command.set(NONE);
|
||||
this.finishTime = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyState(int state) {
|
||||
if (NORMAL == state || REVERSE == state || LOST == state) {
|
||||
this.state = state;
|
||||
} else {
|
||||
throw new IllegalArgumentException(String.format("无效的道岔状态:[%s]", state));
|
||||
}
|
||||
}
|
||||
}
|
@ -1,109 +0,0 @@
|
||||
package club.joylink.rtss.simulation.rt.SRD.bo;
|
||||
|
||||
import club.joylink.rtss.simulation.Debug;
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 虚拟真实轨道区段
|
||||
*/
|
||||
@Getter
|
||||
public class SrTrack extends SrDevice implements Debug {
|
||||
|
||||
String name;
|
||||
/**
|
||||
* 轨道长度,单位mm
|
||||
*/
|
||||
int len;
|
||||
/**
|
||||
* 计轴器
|
||||
*/
|
||||
SrAXC axc;
|
||||
/**
|
||||
* 左侧直向轨道(可能为null)
|
||||
*/
|
||||
SrTrack leftTrack;
|
||||
/**
|
||||
* 左侧侧向轨道(非道岔的都为null)
|
||||
*/
|
||||
SrTrack leftFlankTrack;
|
||||
/**
|
||||
* 右侧轨道(可能为null)
|
||||
*/
|
||||
SrTrack rightTrack;
|
||||
/**
|
||||
* 右侧侧向轨道(非道岔的都为null)
|
||||
*/
|
||||
SrTrack rightFlankTrack;
|
||||
/**
|
||||
* 关联的道岔(是道岔区段才会关联,否则为null)
|
||||
*/
|
||||
SrSwitch srSwitch;
|
||||
|
||||
public SrTrack(String id) {
|
||||
super(id, DeviceType.TRACK);
|
||||
}
|
||||
|
||||
public void setAxc(SrAXC axc) {
|
||||
this.axc = axc;
|
||||
}
|
||||
|
||||
public void setLeftTrack(SrTrack left) {
|
||||
this.leftTrack = left;
|
||||
left.setRightTrack(this);
|
||||
}
|
||||
|
||||
public void setLeftFlankTrack(SrTrack leftFlank) {
|
||||
this.leftFlankTrack = leftFlank;
|
||||
leftFlank.setRightTrack(this);
|
||||
}
|
||||
|
||||
public void setRightTrack(SrTrack right) {
|
||||
this.rightTrack = right;
|
||||
right.setLeftTrack(this);
|
||||
}
|
||||
|
||||
public void setRightFlankTrack(SrTrack rightFlank) {
|
||||
this.rightFlankTrack = rightFlank;
|
||||
rightFlank.setLeftTrack(this);
|
||||
}
|
||||
|
||||
void setSrSwitch(SrSwitch srSwitch) {
|
||||
this.srSwitch = srSwitch;
|
||||
}
|
||||
|
||||
public SrTrack queryNextTrack(boolean right) {
|
||||
if (this.srSwitch != null) {
|
||||
if (this.srSwitch.isNormalPosition()) {
|
||||
return right ? this.rightTrack : this.leftTrack;
|
||||
} else if (this.srSwitch.isReversePosition()) {
|
||||
if (right) {
|
||||
if (this.rightFlankTrack != null) {
|
||||
return this.rightFlankTrack;
|
||||
} else {
|
||||
return this.rightTrack;
|
||||
}
|
||||
} else {
|
||||
if (this.leftFlankTrack != null) {
|
||||
return this.leftFlankTrack;
|
||||
} else {
|
||||
return this.leftTrack;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return right ? this.rightTrack : this.leftTrack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyState(int state) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String debugStr() {
|
||||
return String.format("%s(%s)", this.name, this.id);
|
||||
}
|
||||
|
||||
}
|
@ -1,85 +0,0 @@
|
||||
package club.joylink.rtss.simulation.rt.SRD.bo;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 虚拟真实列车
|
||||
*/
|
||||
@Getter
|
||||
public class SrTrain extends SrDevice {
|
||||
/**
|
||||
* 是否使用中
|
||||
*/
|
||||
boolean using;
|
||||
|
||||
/**
|
||||
* 列车长度,单位mm
|
||||
*/
|
||||
int len;
|
||||
/**
|
||||
* 列车质量,单位:吨
|
||||
*/
|
||||
int mass = 224;
|
||||
/**
|
||||
* 最大加速度, 单位mm/s2
|
||||
*/
|
||||
public static final int MAX_ACC = 1600;
|
||||
/**
|
||||
* 最大常用制动加速度, 单位mm/s2
|
||||
*/
|
||||
public static final int MAX_DEC = -1200;
|
||||
/**
|
||||
* 紧急制动加速度, 单位mm/s2
|
||||
*/
|
||||
public static final int ES_DEC = -1500;
|
||||
/**
|
||||
* 功率-100 <= p <= 100
|
||||
*/
|
||||
int p;
|
||||
/**
|
||||
* 是否紧急制动
|
||||
*/
|
||||
boolean eb;
|
||||
/**
|
||||
* 列车速度,单位mm/s
|
||||
*/
|
||||
int speed;
|
||||
/**
|
||||
* 列车方向
|
||||
*/
|
||||
boolean right;
|
||||
/**
|
||||
* 档位
|
||||
*/
|
||||
int gear;
|
||||
public static final int NEUTRAL = 0; //空挡
|
||||
public static final int FORWARD = 1; //前进挡
|
||||
public static final int REVERSE = -1; //后退档
|
||||
/**
|
||||
* 列车头位置
|
||||
*/
|
||||
TrackPosition headPosition;
|
||||
/**
|
||||
* 列车尾位置
|
||||
*/
|
||||
TrackPosition tailPosition;
|
||||
public SrTrain(String id, int len) {
|
||||
super(id, DeviceType.TRAIN);
|
||||
this.len = len;
|
||||
}
|
||||
|
||||
public boolean isNeutralGear() {
|
||||
return NEUTRAL == this.gear;
|
||||
}
|
||||
|
||||
public void updatePositionAndSpeed(TrackPosition headPosition, TrackPosition tailPosition, int v) {
|
||||
this.headPosition = headPosition;
|
||||
this.tailPosition = tailPosition;
|
||||
this.speed = v;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyState(int state) {
|
||||
|
||||
}
|
||||
}
|
@ -1,67 +0,0 @@
|
||||
package club.joylink.rtss.simulation.rt.SRD.bo;
|
||||
|
||||
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
|
||||
import club.joylink.rtss.simulation.SimulationRepository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class SrdRepository extends SimulationRepository {
|
||||
public static final String NAME = "SDR";
|
||||
|
||||
Map<String, SrTrack> trackMap;
|
||||
Map<String, SrAXC> axcMap;
|
||||
Map<String, SrSwitch> switchMap;
|
||||
Map<String, SrSignal> signalMap;
|
||||
Map<String, SrPSD> psdMap;
|
||||
Map<String, SrTrain> trainMap;
|
||||
|
||||
public SrdRepository() {
|
||||
super(NAME);
|
||||
this.trackMap = new HashMap<>();
|
||||
this.axcMap = new HashMap<>();
|
||||
this.switchMap = new HashMap<>();
|
||||
this.signalMap = new HashMap<>();
|
||||
this.psdMap = new HashMap<>();
|
||||
this.trainMap = new HashMap<>();
|
||||
}
|
||||
|
||||
public List<SrTrain> getTrainList() {
|
||||
return new ArrayList<>(this.trainMap.values());
|
||||
}
|
||||
|
||||
public List<SrSwitch> getSwitchList() {
|
||||
return new ArrayList<>(this.switchMap.values());
|
||||
}
|
||||
|
||||
public List<SrPSD> getPsdList() {
|
||||
return new ArrayList<>(this.psdMap.values());
|
||||
}
|
||||
|
||||
public List<SrSignal> getSignalList() {
|
||||
return new ArrayList<>(this.signalMap.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initState() {
|
||||
|
||||
}
|
||||
|
||||
public List<SrAXC> getAxcList() {
|
||||
return new ArrayList<>(this.axcMap.values());
|
||||
}
|
||||
|
||||
public SrSwitch getSwitchById(String id) {
|
||||
SrSwitch srSwitch = this.switchMap.get(id);
|
||||
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(srSwitch);
|
||||
return srSwitch;
|
||||
}
|
||||
|
||||
public SrSignal getSignalById(String id) {
|
||||
SrSignal srSignal = this.signalMap.get(id);
|
||||
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(srSignal);
|
||||
return srSignal;
|
||||
}
|
||||
}
|
@ -1,154 +0,0 @@
|
||||
package club.joylink.rtss.simulation.rt.SRD.bo;
|
||||
|
||||
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
|
||||
import club.joylink.rtss.vo.client.map.MapSwitchVO;
|
||||
import club.joylink.rtss.vo.client.map.MapTrainModelVO;
|
||||
import club.joylink.rtss.vo.client.map.MapTrainVO;
|
||||
import club.joylink.rtss.vo.client.map.MapVO;
|
||||
import club.joylink.rtss.vo.client.map.newmap.MapGraphDataNewVO;
|
||||
import club.joylink.rtss.vo.client.map.newmap.MapPSDVO;
|
||||
import club.joylink.rtss.vo.client.map.newmap.MapSectionNewVO;
|
||||
import club.joylink.rtss.vo.client.map.newmap.MapSignalNewVO;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class SrdRepositoryBuilder {
|
||||
|
||||
public static SrdRepository buildFrom(MapVO mapVO) {
|
||||
SrdRepository srdRepository = new SrdRepository();
|
||||
MapGraphDataNewVO graphDataNew = mapVO.getGraphDataNew();
|
||||
buildTrackAndAxc(graphDataNew.getSectionList(), srdRepository.trackMap, srdRepository.axcMap);
|
||||
buildTurnout(graphDataNew.getSwitchList(), srdRepository.switchMap);
|
||||
buildSignal(graphDataNew.getSignalList(), srdRepository.signalMap);
|
||||
buildSrPsd(graphDataNew.getPsdList(), srdRepository.psdMap);
|
||||
buildTrain(graphDataNew.getTrainList(), srdRepository.trainMap);
|
||||
// 关系构建
|
||||
buildRelationOfTrackAndAxc(graphDataNew.getSectionList(), srdRepository.trackMap, srdRepository.axcMap);
|
||||
buildRelationOfTurnoutAndTrack(graphDataNew.getSwitchList(), srdRepository.switchMap, srdRepository.trackMap);
|
||||
buildRelationOfSignalAndTrack(graphDataNew.getSignalList(), srdRepository.signalMap, srdRepository.trackMap);
|
||||
return srdRepository;
|
||||
}
|
||||
|
||||
private static void buildRelationOfTrackAndAxc(List<MapSectionNewVO> sectionList, Map<String, SrTrack> trackMap, Map<String, SrAXC> axcMap) {
|
||||
for (MapSectionNewVO sectionVO : sectionList) {
|
||||
SrTrack srTrack = trackMap.get(sectionVO.getCode());
|
||||
if (srTrack == null) {
|
||||
continue;
|
||||
}
|
||||
// 构建轨道关联关系
|
||||
if (StringUtils.hasText(sectionVO.getLeftSectionCode())) {
|
||||
SrTrack left = trackMap.get(sectionVO.getLeftSectionCode());
|
||||
BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(left,
|
||||
String.format("区段[%s]的左关联区段[%s]不存在", srTrack.getId(), sectionVO.getLeftSectionCode()));
|
||||
srTrack.setLeftTrack(left);
|
||||
}
|
||||
if (StringUtils.hasText(sectionVO.getRightSectionCode())) {
|
||||
SrTrack right = trackMap.get(sectionVO.getRightSectionCode());
|
||||
BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(right,
|
||||
String.format("区段[%s]的右关联区段[%s]不存在", srTrack.getId(), sectionVO.getRightSectionCode()));
|
||||
srTrack.setRightTrack(right);
|
||||
}
|
||||
// 构建轨道和计轴关系
|
||||
SrAXC axc;
|
||||
if (StringUtils.hasText(sectionVO.getParentCode())) {
|
||||
axc = axcMap.get(sectionVO.getParentCode());
|
||||
} else {
|
||||
axc = axcMap.get(sectionVO.getCode());
|
||||
}
|
||||
srTrack.setAxc(axc);
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildRelationOfSignalAndTrack(List<MapSignalNewVO> signalList,
|
||||
Map<String, SrSignal> signalMap,
|
||||
Map<String, SrTrack> trackMap) {
|
||||
for (MapSignalNewVO signalVO : signalList) {
|
||||
SrSignal srSignal = signalMap.get(signalVO.getCode());
|
||||
SrTrack srTrack = trackMap.get(signalVO.getSectionCode());
|
||||
BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(srTrack,
|
||||
String.format("信号机[%s]关联区段[%s]不存在", signalVO.getCode(), signalVO.getSectionCode()));
|
||||
Float sectionOffset = signalVO.getSectionOffset();
|
||||
BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(sectionOffset >= 0,
|
||||
String.format("信号机[%s]区段偏移量小于0", signalVO.getCode()));
|
||||
srSignal.setTrackAndOffset(srTrack, (int) (sectionOffset*1000));
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildRelationOfTurnoutAndTrack(List<MapSwitchVO> switchList,
|
||||
Map<String, SrSwitch> turnoutMap,
|
||||
Map<String, SrTrack> trackMap) {
|
||||
for (MapSwitchVO switchVO : switchList) {
|
||||
SrTrack a = trackMap.get(switchVO.getSectionACode());
|
||||
SrTrack b = trackMap.get(switchVO.getSectionBCode());
|
||||
SrTrack c = trackMap.get(switchVO.getSectionCCode());
|
||||
BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(a,
|
||||
String.format("道岔[%s]关联区段A[%s]不存在", switchVO.getCode(), switchVO.getSectionACode()));
|
||||
BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(b,
|
||||
String.format("道岔[%s]关联区段B[%s]不存在", switchVO.getCode(), switchVO.getSectionBCode()));
|
||||
BusinessExceptionAssertEnum.DATA_ERROR.assertNotNull(c,
|
||||
String.format("道岔[%s]关联区段C[%s]不存在", switchVO.getCode(), switchVO.getSectionCCode()));
|
||||
SrSwitch turnout = turnoutMap.get(switchVO.getCode());
|
||||
turnout.setTracks(a, b, c);
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildTrackAndAxc(List<MapSectionNewVO> sectionList,
|
||||
Map<String, SrTrack> trackMap,
|
||||
Map<String, SrAXC> axcMap) {
|
||||
for (MapSectionNewVO sectionVO : sectionList) {
|
||||
if (Objects.equals(sectionVO.getType(), "02")) { // 逻辑区段
|
||||
continue;
|
||||
}
|
||||
if (Objects.equals(sectionVO.getType(), "04")) { // 道岔计轴
|
||||
// 只创建计轴器
|
||||
SrAXC srAXC = new SrAXC(sectionVO.getCode());
|
||||
axcMap.put(srAXC.getId(), srAXC);
|
||||
continue;
|
||||
}
|
||||
// 创建轨道
|
||||
SrTrack srTrack = new SrTrack(sectionVO.getCode());
|
||||
trackMap.put(srTrack.getId(), srTrack);
|
||||
BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(sectionVO.getLengthFact() > 0,
|
||||
String.format("区段[%s(%s)]未设置实际长度或长度小于等于0", sectionVO.getName(), sectionVO.getCode()));
|
||||
srTrack.len = ((int) (sectionVO.getLengthFact() * 1000));
|
||||
|
||||
// 创建计轴器
|
||||
SrAXC srAXC = new SrAXC(sectionVO.getCode());
|
||||
axcMap.put(srAXC.getId(), srAXC);
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildTurnout(List<MapSwitchVO> switchList, Map<String, SrSwitch> turnoutMap) {
|
||||
for (MapSwitchVO switchVO : switchList) {
|
||||
SrSwitch srSwitch = new SrSwitch(switchVO.getCode());
|
||||
turnoutMap.put(srSwitch.getId(), srSwitch);
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildSignal(List<MapSignalNewVO> signalList, Map<String, SrSignal> signalMap) {
|
||||
for (MapSignalNewVO signalVO : signalList) {
|
||||
SrSignal srSignal = new SrSignal(signalVO.getCode());
|
||||
|
||||
signalMap.put(srSignal.getId(), srSignal);
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildSrPsd(List<MapPSDVO> psdList, Map<String, SrPSD> psdMap) {
|
||||
for (MapPSDVO psdVO : psdList) {
|
||||
SrPSD srPSD = new SrPSD(psdVO.getCode());
|
||||
psdMap.put(srPSD.getId(), srPSD);
|
||||
}
|
||||
}
|
||||
|
||||
private static void buildTrain(List<MapTrainVO> trainList, Map<String, SrTrain> trainMap) {
|
||||
for (MapTrainVO trainVO : trainList) {
|
||||
MapTrainModelVO trainModel = trainVO.getTrainModel();
|
||||
SrTrain srTrain = new SrTrain(trainVO.getGroupNumber(), (int) (trainModel.getLength() * 1000));
|
||||
trainMap.put(srTrain.getId(), srTrain);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package club.joylink.rtss.simulation.rt.SRD.bo;
|
||||
|
||||
public class TrackPosition {
|
||||
SrTrack track;
|
||||
/**
|
||||
* 轨道偏移量,单位mm
|
||||
*/
|
||||
int offset;
|
||||
|
||||
public TrackPosition(SrTrack track, int offset) {
|
||||
this.track = track;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
||||
public SrTrack getTrack() {
|
||||
return track;
|
||||
}
|
||||
|
||||
public int getOffset() {
|
||||
return offset;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user