抽象仿真,重构
This commit is contained in:
parent
07252b5fea
commit
3d7fd9a5c2
@ -0,0 +1,19 @@
|
||||
package club.joylink.rtss.simulation;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 默认的仿真消息发布器,基于webSocket STOMP协议
|
||||
*/
|
||||
@Component
|
||||
public class DefaultMessagePublisher implements SimulationPublisher {
|
||||
@Autowired
|
||||
private SimpMessagingTemplate smt;
|
||||
|
||||
@Override
|
||||
public void publishToUser(String user, String destination, Object message) {
|
||||
smt.convertAndSendToUser(user, destination, message);
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Slf4j
|
||||
public abstract class Simulation<U extends SimulationUser> {
|
||||
@ -27,7 +28,10 @@ public abstract class Simulation<U extends SimulationUser> {
|
||||
/**
|
||||
* 仿真状态
|
||||
*/
|
||||
private volatile State state;
|
||||
private final AtomicInteger state = new AtomicInteger(RUNNING);
|
||||
private static final int RUNNING = 1;
|
||||
private static final int PAUSE = 0;
|
||||
private static final int ERROR = -1;
|
||||
/**
|
||||
* 仿真运行发生异常时,保存的异常信息
|
||||
*/
|
||||
@ -39,7 +43,7 @@ public abstract class Simulation<U extends SimulationUser> {
|
||||
/**
|
||||
* 执行线程池,核心线程数量默认4,所有仿真共享
|
||||
*/
|
||||
private static final ScheduledExecutorService EXECUTOR = Executors.newScheduledThreadPool(4);
|
||||
public static final ScheduledExecutorService EXECUTOR = Executors.newScheduledThreadPool(4);
|
||||
|
||||
private SimulationPublisher publisher;
|
||||
|
||||
@ -50,10 +54,13 @@ public abstract class Simulation<U extends SimulationUser> {
|
||||
}
|
||||
|
||||
public Simulation(String id, int speed) {
|
||||
if (id == null) {
|
||||
throw new IllegalArgumentException("仿真id不能为空");
|
||||
}
|
||||
this.id = id;
|
||||
this.speed = speed;
|
||||
this.systemTime = LocalDateTime.now();
|
||||
this.state = State.PAUSE;
|
||||
this.state.set(PAUSE);
|
||||
this.addJob("systemTime", () ->
|
||||
this.systemTime = this.systemTime.plusNanos(TimeUnit.MILLISECONDS.toNanos(1)), 10);
|
||||
}
|
||||
@ -69,9 +76,9 @@ public abstract class Simulation<U extends SimulationUser> {
|
||||
return this.systemTime;
|
||||
}
|
||||
/**
|
||||
* 仿真数据初始化,由具体仿真实现
|
||||
* 仿真数据状态初始化,由具体仿真实现
|
||||
*/
|
||||
protected abstract void initData();
|
||||
protected abstract void initState();
|
||||
|
||||
/**
|
||||
* 仿真初始化
|
||||
@ -80,7 +87,7 @@ public abstract class Simulation<U extends SimulationUser> {
|
||||
this.pause(); // 先暂停
|
||||
this.reset();
|
||||
// 通知实现初始化数据
|
||||
this.initData();
|
||||
this.initState();
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
@ -106,6 +113,16 @@ public abstract class Simulation<U extends SimulationUser> {
|
||||
scheduledJob.runAsSpeed(EXECUTOR, this.speed);
|
||||
}
|
||||
|
||||
/**
|
||||
* 延时执行逻辑,只执行一次
|
||||
* PS:暂时不处理速度变化对延迟执行的逻辑产生影响
|
||||
* @param logic
|
||||
* @param delay
|
||||
*/
|
||||
public void delayExecute(Runnable logic, long delay) {
|
||||
EXECUTOR.schedule(logic, delay, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除指定仿真任务逻辑循环
|
||||
* @param name
|
||||
@ -125,14 +142,14 @@ public abstract class Simulation<U extends SimulationUser> {
|
||||
* 控制-开始
|
||||
*/
|
||||
public void start() {
|
||||
this.state = State.RUNNING;
|
||||
this.state.set(RUNNING);
|
||||
}
|
||||
|
||||
/**
|
||||
* 控制-暂停
|
||||
*/
|
||||
public void pause() {
|
||||
this.state = State.PAUSE;
|
||||
this.state.set(PAUSE);
|
||||
while (true) {
|
||||
if (this.getAllRunningJobAmount() == this.getAllFinishedJobAmount()) {
|
||||
break;
|
||||
@ -161,24 +178,24 @@ public abstract class Simulation<U extends SimulationUser> {
|
||||
return amount;
|
||||
}
|
||||
|
||||
public State getState() {
|
||||
return this.state;
|
||||
public int getState() {
|
||||
return this.state.get();
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return State.RUNNING.equals(this.state);
|
||||
return this.state.get() == RUNNING;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新仿真速度
|
||||
* @param speed [1,10] 1<=speed<=10
|
||||
* @param speed [1,8] 1<=speed<=8
|
||||
*/
|
||||
public void updateSpeed(int speed) {
|
||||
if (speed < 1) {
|
||||
throw new IllegalArgumentException("speed must big or equal than 1");
|
||||
}
|
||||
if (speed > 10) {
|
||||
throw new IllegalArgumentException("speed must small or equal than 10");
|
||||
if (speed > 8) {
|
||||
throw new IllegalArgumentException("speed must small or equal than 8");
|
||||
}
|
||||
if (this.speed == speed) { // 速度与当前相同,返回
|
||||
return;
|
||||
@ -191,7 +208,7 @@ public abstract class Simulation<U extends SimulationUser> {
|
||||
}
|
||||
|
||||
public void runError(Throwable throwable) {
|
||||
this.state = State.ERROR;
|
||||
this.state.set(ERROR);
|
||||
this.throwable = throwable;
|
||||
}
|
||||
|
||||
@ -239,7 +256,7 @@ public abstract class Simulation<U extends SimulationUser> {
|
||||
|
||||
public void publishMessage(String destination, Object message) {
|
||||
if (this.publisher == null) {
|
||||
throw new UnsupportedOperationException(String.format("仿真[%s]没有消息发布者对象", this.id));
|
||||
throw new UnsupportedOperationException(String.format("仿真[%s]没有消息发布对象:publisher = null", this.id));
|
||||
}
|
||||
for (U simulationUser : this.simulationUserMap.values()) {
|
||||
if (simulationUser.isSubscribe(destination)) {
|
||||
@ -248,9 +265,5 @@ public abstract class Simulation<U extends SimulationUser> {
|
||||
}
|
||||
}
|
||||
|
||||
enum State {
|
||||
RUNNING,
|
||||
PAUSE,
|
||||
ERROR,
|
||||
}
|
||||
public abstract String debugStr();
|
||||
}
|
||||
|
@ -0,0 +1,11 @@
|
||||
package club.joylink.rtss.simulation;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class SimulationIdGenerator {
|
||||
public static final AtomicInteger sn = new AtomicInteger(0);
|
||||
|
||||
public static String buildId() {
|
||||
return String.valueOf(sn.incrementAndGet());
|
||||
}
|
||||
}
|
@ -0,0 +1,71 @@
|
||||
package club.joylink.rtss.simulation;
|
||||
|
||||
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Component
|
||||
public class SimulationManager {
|
||||
|
||||
public static final Map<String, Simulation> simulationCache = new ConcurrentHashMap<>();
|
||||
|
||||
@Autowired
|
||||
private DefaultMessagePublisher defaultMessagePublisher;
|
||||
|
||||
public Simulation save(Simulation simulation) {
|
||||
BusinessExceptionAssertEnum.DATA_ALREADY_EXIST.assertNotTrue(simulationCache.containsKey(simulation.getId()),
|
||||
String.format("已经存在id为[%s]的仿真[%s]", simulation.getId(), simulation.debugStr()));
|
||||
simulationCache.put(simulation.getId(), simulation);
|
||||
simulation.setPublisher(this.defaultMessagePublisher); // 设置默认的消息发布器
|
||||
return simulation;
|
||||
}
|
||||
|
||||
public Simulation queryById(String id) {
|
||||
return simulationCache.get(id);
|
||||
}
|
||||
|
||||
public Simulation getById(String id) {
|
||||
Simulation simulation = simulationCache.get(id);
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST
|
||||
.assertNotNull(simulation, String.format("id为[%s]的仿真不存在", id));
|
||||
return simulation;
|
||||
}
|
||||
|
||||
public <T extends Simulation> T queryById(String id, T t) {
|
||||
return (T) simulationCache.get(id);
|
||||
}
|
||||
|
||||
public <T extends Simulation> T getById(String id, T t) {
|
||||
Simulation simulation = simulationCache.get(id);
|
||||
BusinessExceptionAssertEnum.DATA_NOT_EXIST
|
||||
.assertNotNull(simulation, String.format("id为[%s]的仿真不存在", id));
|
||||
return (T) simulation;
|
||||
}
|
||||
|
||||
public void init(String id) {
|
||||
this.getById(id).init();
|
||||
}
|
||||
|
||||
public void start(String id) {
|
||||
this.getById(id).start();
|
||||
}
|
||||
|
||||
public void pause(String id) {
|
||||
this.getById(id).pause();
|
||||
}
|
||||
|
||||
public void updateSpeed(String id, int speed) {
|
||||
this.getById(id).updateSpeed(speed);
|
||||
}
|
||||
|
||||
public Simulation destroy(String id) {
|
||||
Simulation simulation = simulationCache.remove(id);
|
||||
if (simulation != null) {
|
||||
simulation.destroy();
|
||||
}
|
||||
return simulation;
|
||||
}
|
||||
}
|
@ -2,7 +2,7 @@ package club.joylink.rtss.simulation;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class SimulationUser {
|
||||
public abstract class SimulationUser {
|
||||
/**
|
||||
* 仿真用户唯一标识,并且是发布订阅消息时的用户唯一标识
|
||||
*/
|
||||
|
@ -0,0 +1,26 @@
|
||||
package club.joylink.rtss.simulation.rt;
|
||||
|
||||
import club.joylink.rtss.simulation.Simulation;
|
||||
import club.joylink.rtss.simulation.rt.srd.SrdRepository;
|
||||
|
||||
public class RtSimulation extends Simulation<RtSimulationUser> {
|
||||
|
||||
/**
|
||||
* 模拟真实设备数据仓库
|
||||
*/
|
||||
SrdRepository srdRepository;
|
||||
|
||||
public RtSimulation(String id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initState() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String debugStr() {
|
||||
return String.format("轨道交通仿真[%s]", getId());
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package club.joylink.rtss.simulation.rt;
|
||||
|
||||
import club.joylink.rtss.simulation.SimulationIdGenerator;
|
||||
import club.joylink.rtss.simulation.SimulationManager;
|
||||
import club.joylink.rtss.vo.UserVO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class RtSimulationService {
|
||||
@Autowired
|
||||
private SimulationManager simulationManager;
|
||||
|
||||
public RtSimulation create(UserVO userVO) {
|
||||
RtSimulation rtSimulation = new RtSimulation(SimulationIdGenerator.buildId());
|
||||
this.simulationManager.save(rtSimulation);
|
||||
this.load(rtSimulation);
|
||||
return rtSimulation;
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载相关数据
|
||||
* @param rtSimulation
|
||||
*/
|
||||
private void load(RtSimulation rtSimulation) {
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package club.joylink.rtss.simulation.rt;
|
||||
|
||||
import club.joylink.rtss.simulation.SimulationUser;
|
||||
|
||||
public class RtSimulationUser extends SimulationUser {
|
||||
public RtSimulationUser(String id) {
|
||||
super(id);
|
||||
}
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package club.joylink.rtss.simulation.rt.srd;
|
||||
|
||||
import club.joylink.rtss.simulation.rt.RtSimulation;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SimulateRealDeviceLogic {
|
||||
public static final int TRAIN_RUN_RATE = 2000;
|
||||
|
||||
public void addJobs(RtSimulation rtSimulation) {
|
||||
rtSimulation.addJob("srTrainRun", () -> {this.srTrainRun(rtSimulation);}, TRAIN_RUN_RATE);
|
||||
|
||||
}
|
||||
|
||||
public void srTrainRun(RtSimulation simulation) {
|
||||
}
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package club.joylink.rtss.simulation.rt.srd;
|
||||
|
||||
import club.joylink.rtss.simulation.rt.srd.bo.SrDevice;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class SrdRepository {
|
||||
|
||||
Map<String, SrDevice> deviceMap = new HashMap<>();
|
||||
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
package club.joylink.rtss.simulation.rt.srd;
|
||||
|
||||
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
|
||||
import club.joylink.rtss.simulation.rt.srd.bo.*;
|
||||
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.HashMap;
|
||||
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();
|
||||
Map<String, SrDevice> deviceMap = new HashMap<>();
|
||||
deviceMap.putAll(buildTrackAndAxc(graphDataNew.getSectionList()));
|
||||
deviceMap.putAll(buildTurnout(graphDataNew.getSwitchList()));
|
||||
deviceMap.putAll(buildSignal(graphDataNew.getSignalList()));
|
||||
deviceMap.putAll(buildSrPsd(graphDataNew.getPsdList()));
|
||||
deviceMap.putAll(buildTrain(graphDataNew.getTrainList()));
|
||||
// 关系构建
|
||||
buildRelationOfTrackAndAxc(graphDataNew.getSectionList(), deviceMap);
|
||||
return srdRepository;
|
||||
}
|
||||
|
||||
private static void buildRelationOfTrackAndAxc(List<MapSectionNewVO> sectionList, Map<String, SrDevice> deviceMap) {
|
||||
for (MapSectionNewVO sectionVO : sectionList) {
|
||||
SrTrack srTrack = (SrTrack) deviceMap.get(sectionVO.getCode());
|
||||
if (srTrack == null) {
|
||||
continue;
|
||||
}
|
||||
if (StringUtils.hasText(sectionVO.getParentCode())) {
|
||||
deviceMap.get(sectionVO.getParentCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Map<String, SrDevice> buildTrackAndAxc(List<MapSectionNewVO> sectionList) {
|
||||
Map<String, SrDevice> map = new HashMap<>();
|
||||
for (MapSectionNewVO sectionVO : sectionList) {
|
||||
if (Objects.equals(sectionVO.getType(), "02")) { // 逻辑区段
|
||||
continue;
|
||||
}
|
||||
if (Objects.equals(sectionVO.getType(), "04")) { // 道岔计轴
|
||||
// 只创建计轴器
|
||||
SrAXC srAXC = new SrAXC(sectionVO.getCode());
|
||||
map.put(srAXC.getId(), srAXC);
|
||||
continue;
|
||||
}
|
||||
// 创建轨道
|
||||
SrTrack srTrack = new SrTrack(sectionVO.getCode());
|
||||
map.put(srTrack.getId(), srTrack);
|
||||
BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(sectionVO.getLengthFact() > 0,
|
||||
String.format("区段[%s(%s)]未设置实际长度或长度小于0", sectionVO.getName(), sectionVO.getCode()));
|
||||
srTrack.setLen((int) (sectionVO.getLengthFact()*1000));
|
||||
|
||||
// 创建计轴器
|
||||
SrAXC srAXC = new SrAXC(sectionVO.getCode());
|
||||
map.put(srAXC.getId(), srAXC);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private static Map<String, SrDevice> buildTurnout(List<MapSwitchVO> switchList) {
|
||||
Map<String, SrDevice> map = new HashMap<>();
|
||||
for (MapSwitchVO switchVO : switchList) {
|
||||
SrTurnout srTurnout = new SrTurnout(switchVO.getCode());
|
||||
map.put(srTurnout.getId(), srTurnout);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private static Map<String, SrDevice> buildSignal(List<MapSignalNewVO> signalList) {
|
||||
Map<String, SrDevice> map = new HashMap<>();
|
||||
for (MapSignalNewVO signalVO : signalList) {
|
||||
SrSignal srSignal = new SrSignal(signalVO.getCode());
|
||||
BusinessExceptionAssertEnum.DATA_ERROR.assertTrue(signalVO.getSectionOffset() >= 0,
|
||||
String.format("信号机[%s(%s)]区段偏移量小于0", signalVO.getName(), signalVO.getCode()));
|
||||
srSignal.setOffset((int) (signalVO.getSectionOffset()*1000));
|
||||
map.put(srSignal.getId(), srSignal);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private static Map<String, SrDevice> buildSrPsd(List<MapPSDVO> psdList) {
|
||||
Map<String, SrDevice> map = new HashMap<>();
|
||||
for (MapPSDVO psdVO : psdList) {
|
||||
SrPSD srPSD = new SrPSD(psdVO.getCode());
|
||||
map.put(srPSD.getId(), srPSD);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
private static Map<String, SrDevice> buildTrain(List<MapTrainVO> trainList) {
|
||||
Map<String, SrDevice> map = new HashMap<>();
|
||||
for (MapTrainVO trainVO : trainList) {
|
||||
SrTrain srTrain = new SrTrain(trainVO.getGroupNumber());
|
||||
map.put(srTrain.getId(), srTrain);
|
||||
MapTrainModelVO trainModel = trainVO.getTrainModel();
|
||||
srTrain.setLen((int) (trainModel.getLength()*1000));
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
package club.joylink.rtss.simulation.rt.srd.bo;
|
||||
|
||||
public enum DeviceType {
|
||||
/** 计轴器 */
|
||||
AXC,
|
||||
/** 道岔 */
|
||||
TURNOUT,
|
||||
/** 信号机 */
|
||||
SIGNAL,
|
||||
/** 站台屏蔽门 */
|
||||
PSD,
|
||||
TRAIN,
|
||||
/** 轨道 */
|
||||
TRACK
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package club.joylink.rtss.simulation.rt.srd.bo;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
/**
|
||||
* 模拟真实计轴器(Axle counter)
|
||||
*/
|
||||
public class SrAXC extends SrDevice {
|
||||
|
||||
AtomicBoolean state = new AtomicBoolean(OFF);
|
||||
public static final boolean OFF = true;//出清
|
||||
public static final boolean ON = true;//占用
|
||||
|
||||
public SrAXC(String id) {
|
||||
super(id, DeviceType.AXC);
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package club.joylink.rtss.simulation.rt.srd.bo;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
/**
|
||||
* 虚拟真实设备抽象父类
|
||||
*/
|
||||
@Getter
|
||||
public abstract class SrDevice {
|
||||
String id;
|
||||
DeviceType deviceType;
|
||||
|
||||
public SrDevice() {}
|
||||
|
||||
public SrDevice(String id, DeviceType deviceType) {
|
||||
this.id = id;
|
||||
this.deviceType = deviceType;
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package club.joylink.rtss.simulation.rt.srd.bo;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* 模拟真实屏蔽门(Platform screen door)
|
||||
*/
|
||||
public class SrPSD extends SrDevice {
|
||||
public static final int turnTime = 3000; // 默认开关门时间,单位ms
|
||||
|
||||
AtomicInteger state = new AtomicInteger(CLOSE_LOCK);
|
||||
public static final int CLOSE_LOCK = 1;//关闭且锁闭
|
||||
public static final int CLOSED = 2;//关闭未锁闭
|
||||
public static final int OPEN = 3;//打开未到位
|
||||
public static final int OPEN_FINISH = 4;//打开到位
|
||||
|
||||
AtomicInteger command = new AtomicInteger();
|
||||
public static final int NONE = 0;//无动作
|
||||
public static final int C_OPEN = 1;//控制开门
|
||||
public static final int C_CLOSE = 2;//控制关门
|
||||
/**
|
||||
* 剩余动作时间
|
||||
*/
|
||||
int remain;
|
||||
|
||||
public SrPSD(String id) {
|
||||
super(id, DeviceType.PSD);
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package club.joylink.rtss.simulation.rt.srd.bo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* 模拟真实信号机
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class SrSignal extends SrDevice {
|
||||
|
||||
/**
|
||||
* 所在区段
|
||||
*/
|
||||
SrTrack track;
|
||||
/**
|
||||
* 所在区段偏移量,单位mm
|
||||
*/
|
||||
int offset;
|
||||
|
||||
AtomicInteger state = new AtomicInteger(CLOSE);
|
||||
public static final int CLOSE = 0;
|
||||
public static final int RED = 1;
|
||||
public static final int GREEN = 2;
|
||||
public static final int YELLOW = 3;
|
||||
public static final int RED_YELLOW = 4;
|
||||
|
||||
AtomicInteger command = new AtomicInteger(C_NONE);
|
||||
public static final int C_NONE = -1;
|
||||
public static final int C_CLOSE = 0;
|
||||
public static final int C_RED = 1;
|
||||
public static final int C_GREEN = 2;
|
||||
public static final int C_YELLOW = 3;
|
||||
public static final int C_RED_YELLOW = 4;
|
||||
|
||||
|
||||
public SrSignal(String id) {
|
||||
super(id, DeviceType.SIGNAL);
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package club.joylink.rtss.simulation.rt.srd.bo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 模拟真实轨道区段
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class SrTrack extends SrDevice {
|
||||
|
||||
/**
|
||||
* 轨道长度,单位mm
|
||||
*/
|
||||
private int len;
|
||||
/**
|
||||
* 左停车点
|
||||
*/
|
||||
private int leftPs;
|
||||
/**
|
||||
* 右停车点
|
||||
*/
|
||||
private int rightPs;
|
||||
/**
|
||||
* 计轴器
|
||||
*/
|
||||
private SrAXC axc;
|
||||
/**
|
||||
* 左侧轨道(可能为null)
|
||||
*/
|
||||
private SrDevice left;
|
||||
/**
|
||||
* 右侧轨道(可能为null)
|
||||
*/
|
||||
private SrDevice right;
|
||||
/**
|
||||
* 关联的道岔(是道岔区段才会关联,否则为null)
|
||||
*/
|
||||
private SrTurnout turnout;
|
||||
|
||||
public SrTrack(String id) {
|
||||
super(id, DeviceType.TRACK);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package club.joylink.rtss.simulation.rt.srd.bo;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* 模拟真实列车
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class SrTrain extends SrDevice {
|
||||
|
||||
/**
|
||||
* 列车长度,单位mm
|
||||
*/
|
||||
int len;
|
||||
/**
|
||||
* 列车速度
|
||||
*/
|
||||
int speed;
|
||||
/**
|
||||
* 列车位置
|
||||
*/
|
||||
TrackPosition position;
|
||||
|
||||
public SrTrain(String id) {
|
||||
super(id, DeviceType.TRAIN);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package club.joylink.rtss.simulation.rt.srd.bo;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* 模拟真实道岔
|
||||
*/
|
||||
public class SrTurnout extends SrDevice {
|
||||
public static final int turnTime = 3000; // 默认转换时间
|
||||
|
||||
SrTrack a;
|
||||
SrTrack b;
|
||||
SrTrack c;
|
||||
|
||||
AtomicInteger state = new AtomicInteger(NORMAL);
|
||||
public static final int NORMAL = 1;
|
||||
public static final int REVERSE = 2;
|
||||
public static final int TURNING = 0;
|
||||
|
||||
AtomicInteger command = new AtomicInteger(NONE);
|
||||
public static final int NONE = 0;
|
||||
public static final int TN = 1;
|
||||
public static final int TR = 2;
|
||||
/**
|
||||
* 转换剩余时间,单位ms
|
||||
*/
|
||||
int remain;
|
||||
|
||||
public SrTurnout(String id) {
|
||||
super(id, DeviceType.TURNOUT);
|
||||
}
|
||||
}
|
@ -0,0 +1,6 @@
|
||||
package club.joylink.rtss.simulation.rt.srd.bo;
|
||||
|
||||
public class TrackPosition {
|
||||
SrTrack track;
|
||||
int offset;
|
||||
}
|
Loading…
Reference in New Issue
Block a user