仿真设备状态消息推送流程抽象

轨道交通仿真——实现ATS消息推送流程
This commit is contained in:
walker-sheng 2021-04-23 14:18:53 +08:00
parent 55300ffa1e
commit 8912639885
21 changed files with 426 additions and 132 deletions

View File

@ -1,5 +1,6 @@
package club.joylink.rtss.simulation;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.PropertyPlaceholderHelper;
import org.springframework.util.StringUtils;
@ -67,7 +68,7 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
public static final String PATH_SEPARATOR = "/";
private Map<String, String> destinationMap = new HashMap<>();
private static final PropertyPlaceholderHelper placeholderHelper = new PropertyPlaceholderHelper("{", "}");
private List<SimulationSubscribeMessageService> subscribeMessageServiceList;
private Map<String, SimulationMessagePublisher> messagePublisherMap = new HashMap<>();
private SimulationMessageSender messageSender;
/**
* 消息推送线程池
@ -457,15 +458,16 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
public abstract String debugStr();
public void setSubscribeMessageServiceList(List<SimulationSubscribeMessageService> list) {
this.subscribeMessageServiceList = list;
public void addMessagePublisher(SimulationMessagePublisher messagePublisher) {
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotTrue(this.messagePublisherMap.containsKey(messagePublisher.name));
this.messagePublisherMap.put(messagePublisher.name, messagePublisher);
this.addFixedRateJob(messagePublisher.name, () -> {
this.pushMessage(messagePublisher.destination, messagePublisher.getNextSendMessage());
}, messagePublisher.rate);
}
public void addSubscribeMessageService(SimulationSubscribeMessageService subscribeMessageService) {
if (this.subscribeMessageServiceList == null) {
this.subscribeMessageServiceList = new ArrayList<>();
}
this.subscribeMessageServiceList.add(subscribeMessageService);
public <P extends SimulationMessagePublisher> P getMessagePublisher(String name, Class<P> clz) {
return (P) this.messagePublisherMap.get(name);
}
public String handleDestination(String destinationPattern) {
@ -505,8 +507,8 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
return false;
}
user.subscribe(wsSessionId, destination);
if (this.subscribeMessageServiceList != null) {
for (SimulationSubscribeMessageService service : this.subscribeMessageServiceList) {
if (this.messagePublisherMap != null) {
for (SimulationSubscribeMessageService service : this.messagePublisherMap.values()) {
if (service.acceptedSubscribePath(destination)) {
Object msg = service.buildMessageOfSubscribe(destination);
if (msg != null) {

View File

@ -0,0 +1,15 @@
package club.joylink.rtss.simulation;
public abstract class SimulationMessagePublisher implements SimulationSubscribeMessageService {
String name;
int rate; // 消息发送频率单位ms
String destination; // 订阅路径
public SimulationMessagePublisher(String name, int rate, String destination) {
this.name = name;
this.rate = rate;
this.destination = destination;
}
public abstract Object getNextSendMessage();
}

View File

@ -1,26 +1,67 @@
package club.joylink.rtss.simulation.rt.ATS;
import club.joylink.rtss.simulation.rt.ATS.bo.AtsRepository;
import club.joylink.rtss.simulation.rt.ATS.bo.AtsSwitch;
import club.joylink.rtss.simulation.rt.CIL.bo.CilDevice;
import club.joylink.rtss.simulation.rt.ATS.bo.*;
import club.joylink.rtss.simulation.rt.CIL.bo.CilRoute;
import club.joylink.rtss.simulation.rt.CIL.bo.CilSection;
import club.joylink.rtss.simulation.rt.CIL.bo.CilSignal;
import club.joylink.rtss.simulation.rt.CIL.bo.CilSwitch;
import club.joylink.rtss.simulation.rt.RtSimulation;
import club.joylink.rtss.simulation.rt.repo.CommonSwitch;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class AtsApiService {
public void handle(RtSimulation rtSimulation, CilSwitch cilSwitch) {
AtsRepository atsRepository = rtSimulation.getRepository(AtsRepository.NAME, AtsRepository.class);
AtsSwitch atsSwitch = atsRepository.getSwitchById(cilSwitch.getId());
if (atsSwitch.getPosition() != cilSwitch.getPosition()) {
atsSwitch.setPosition(cilSwitch.getPosition());
atsRepository.ready2Send(atsSwitch.getId(), 1, atsSwitch.getPosition());
private AtsRepository getAtsRepository(RtSimulation rtSimulation) {
return rtSimulation.getRepository(AtsRepository.NAME, AtsRepository.class);
}
public void syncCilSwitchState(RtSimulation rtSimulation, List<CilSwitch> cilSwitchList) {
AtsRepository atsRepository = this.getAtsRepository(rtSimulation);
AtsMessagePublisher messagePublisher = rtSimulation.getMessagePublisher(AtsMessagePublisher.NAME, AtsMessagePublisher.class);
for (CilSwitch cilSwitch : cilSwitchList) {
AtsSwitch atsSwitch = atsRepository.getSwitchById(cilSwitch.getId());
boolean change = atsSwitch.applyChange(cilSwitch);
if (change) {
messagePublisher.handleSwitch(atsSwitch);
}
}
}
public void handle(CilDevice cilDevice) {
public void syncCilSectionState(RtSimulation rtSimulation, List<CilSection> cilSectionList) {
AtsRepository atsRepository = this.getAtsRepository(rtSimulation);
AtsMessagePublisher messagePublisher = rtSimulation.getMessagePublisher(AtsMessagePublisher.NAME, AtsMessagePublisher.class);
for (CilSection section : cilSectionList) {
AtsSection atsSection = atsRepository.getSectionById(section.getId());
boolean change = atsSection.applyChange(section);
if (change) {
messagePublisher.handleSection(atsSection);
}
}
}
public void syncCilSignalState(RtSimulation rtSimulation, List<CilSignal> cilSignalList) {
AtsRepository atsRepository = this.getAtsRepository(rtSimulation);
AtsMessagePublisher messagePublisher = rtSimulation.getMessagePublisher(AtsMessagePublisher.NAME, AtsMessagePublisher.class);
for (CilSignal cilSignal : cilSignalList) {
AtsSignal atsSignal = atsRepository.getSignalById(cilSignal.getId());
boolean change = atsSignal.applyChange(cilSignal);
if (change) {
messagePublisher.handleSignal(atsSignal);
}
}
}
public void syncCilRouteState(RtSimulation rtSimulation, List<CilRoute> cilRouteList) {
AtsRepository atsRepository = this.getAtsRepository(rtSimulation);
AtsMessagePublisher messagePublisher = rtSimulation.getMessagePublisher(AtsMessagePublisher.NAME, AtsMessagePublisher.class);
for (CilRoute cilRoute : cilRouteList) {
AtsRoute atsRoute = atsRepository.getRouteById(cilRoute.getId());
boolean change = atsRoute.applyChange(cilRoute);
if (change) {
messagePublisher.handleRoute(atsRoute);
}
}
}
}

View File

@ -9,7 +9,6 @@ import club.joylink.rtss.vo.client.map.MapVO;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List;
/**
@ -17,14 +16,16 @@ import java.util.List;
*/
@Component
public class AtsLogicService {
public void buildRepository(RtSimulation rtSimulation, MapVO mapVO) {
public void init(RtSimulation rtSimulation, MapVO mapVO) {
AtsRepository atsRepository = AtsRepositoryBuilder.buildFrom(mapVO);
rtSimulation.addRepository(atsRepository);
AtsMessagePublisher atsMessagePublisher = new AtsMessagePublisher(atsRepository);
rtSimulation.addMessagePublisher(atsMessagePublisher);
}
public void addJobs(RtSimulation rtSimulation) {
for (RtSimulationSubscribeTopic topic : RtSimulationSubscribeTopic.values()) {
rtSimulation.addJob("MESSAGE-" + topic.name(), () -> sendMessages(rtSimulation, topic), topic.getRate());
rtSimulation.addFixedRateJob("MESSAGE-" + topic.name(), () -> sendMessages(rtSimulation, topic), topic.getRate());
}
}

View File

@ -0,0 +1,101 @@
package club.joylink.rtss.simulation.rt.ATS;
import club.joylink.rtss.simulation.SimulationMessagePublisher;
import club.joylink.rtss.simulation.rt.ATS.bo.*;
import club.joylink.rtss.simulation.rt.RtSimulationSubscribeTopic;
import lombok.Getter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
@Getter
public class AtsMessagePublisher extends SimulationMessagePublisher {
public static final String NAME = "AMP";
public static final int RATE = 1000;
AtsRepository atsRepository;
Map<String, List<Object>> switchMap = new ConcurrentHashMap<>();
Map<String, List<Object>> sectionMap = new ConcurrentHashMap<>();
Map<String, List<Object>> signalMap = new ConcurrentHashMap<>();
Map<String, List<Object>> routeMap = new ConcurrentHashMap<>();
public AtsMessagePublisher(AtsRepository atsRepository) {
super(NAME, RATE, RtSimulationSubscribeTopic.ATS.getDestPattern());
this.atsRepository = atsRepository;
}
public void handleSwitch(AtsSwitch atsSwitch) {
if (!this.switchMap.containsKey(atsSwitch.getId())) {
this.switchMap.put(atsSwitch.getId(), atsSwitch.getStateList());
}
}
public void handleSection(AtsSection atsSection) {
if (!this.sectionMap.containsKey(atsSection.getId())) {
this.sectionMap.put(atsSection.getId(), atsSection.getStateList());
}
}
public void handleSignal(AtsSignal atsSignal) {
if (!this.signalMap.containsKey(atsSignal.getId())) {
this.signalMap.put(atsSignal.getId(), atsSignal.getStateList());
}
}
public void handleRoute(AtsRoute atsRoute) {
if (!this.routeMap.containsKey(atsRoute.getId())) {
this.routeMap.put(atsRoute.getId(), atsRoute.getStateList());
}
}
@Override
public boolean acceptedSubscribePath(String destination) {
return RtSimulationSubscribeTopic.ATS.isMatch(destination);
}
@Override
public Object buildMessageOfSubscribe(String destination) {
HashMap<Object, Object> message = new HashMap<>();
List<List<Object>> switchStateList = this.atsRepository.getSwitchMap().values().stream()
.map(AtsSwitch::getStateList)
.collect(Collectors.toList());
List<List<Object>> sectionStateList = this.atsRepository.getSectionMap().values().stream()
.map(AtsSection::getStateList)
.collect(Collectors.toList());
List<List<Object>> signalStateList = this.atsRepository.getSignalMap().values().stream()
.map(AtsSignal::getStateList)
.collect(Collectors.toList());
List<List<Object>> routeStateList = this.atsRepository.getRouteMap().values().stream()
.map(AtsRoute::getStateList)
.collect(Collectors.toList());
message.put("switch", switchStateList);
message.put("section", sectionStateList);
message.put("signal", signalStateList);
message.put("route", routeStateList);
return message;
}
@Override
public Object getNextSendMessage() {
HashMap<Object, Object> message = new HashMap<>();
if (!this.switchMap.isEmpty()) {
message.put("switch", this.switchMap.values());
this.switchMap.clear();
}
if (!this.sectionMap.isEmpty()) {
message.put("section", this.sectionMap.values());
this.sectionMap.clear();
}
if (!this.signalMap.isEmpty()) {
message.put("signal", this.signalMap.values());
this.signalMap.clear();
}
if (!this.routeMap.isEmpty()) {
message.put("route", this.routeMap.values());
this.routeMap.clear();
}
if (message.isEmpty()) {
return null;
}
return message;
}
}

View File

@ -1,19 +1,32 @@
package club.joylink.rtss.simulation.rt.ATS.bo;
import club.joylink.rtss.simulation.rt.RtSimulationSubscribeTopic;
import lombok.Getter;
import java.util.List;
@Getter
public abstract class AtsDevice {
public static final int OFF = 0;
public static final int ON = 1;
List<Object> stateList;
String id;
String name;
public AtsDevice(String id, String name) {
this.id = id;
this.name = name;
this.stateList = this.buildMessage();
}
// public abstract void buildMessage(List<Object> message, RtSimulationSubscribeTopic topic);
public int convert(boolean val) {
if (val) {
return ON;
} else {
return OFF;
}
}
abstract List<Object> buildMessage();
}

View File

@ -3,12 +3,14 @@ package club.joylink.rtss.simulation.rt.ATS.bo;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.SimulationRepository;
import club.joylink.rtss.simulation.cbtc.data.map.Station;
import lombok.Getter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Getter
public class AtsRepository extends SimulationRepository {
public static final String NAME = "ATS";
@ -43,12 +45,30 @@ public class AtsRepository extends SimulationRepository {
return runPlan;
}
public AtsSection getSectionById(String id) {
AtsSection atsSection = this.sectionMap.get(id);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(atsSection);
return atsSection;
}
public AtsSwitch getSwitchById(String id) {
AtsSwitch atsSwitch = switchMap.get(id);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(atsSwitch);
return atsSwitch;
}
public AtsSignal getSignalById(String id) {
AtsSignal atsSignal = this.signalMap.get(id);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(atsSignal);
return atsSignal;
}
public AtsRoute getRouteById(String id) {
AtsRoute atsRoute = this.routeMap.get(id);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(atsRoute);
return atsRoute;
}
public void ready2Send(String id, int i, Object value) {
List<Object> message = messageMap.get(id);
if (message != null) {

View File

@ -1,48 +1,43 @@
package club.joylink.rtss.simulation.rt.ATS.bo;
import club.joylink.rtss.simulation.rt.RtSimulationSubscribeTopic;
import club.joylink.rtss.simulation.rt.CIL.bo.CilRoute;
import lombok.Getter;
import lombok.NonNull;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
@Getter
public class AtsRoute extends AtsDevice {
boolean ars;
boolean arc;
boolean flt;
public void setArs(boolean ars) {
if (!Objects.equals(this.ars, ars)) {
}
this.ars = ars;
}
public void setArc(boolean arc) {
this.arc = arc;
}
public void setFlt(boolean flt) {
this.flt = flt;
}
public AtsRoute(String id, String name) {
super(id, name);
}
// @Override
public void buildMessage(@NonNull List<Object> message, RtSimulationSubscribeTopic topic) {
switch (topic) {
case ATS:
message.add(ars);
message.add(arc);
message.add(flt);
break;
@Override
List<Object> buildMessage() {
return Arrays.asList(this.id, this.convert(this.ars), this.convert(this.arc), this.convert(this.flt));
}
public boolean applyChange(CilRoute cilRoute) {
boolean change = false;
if (this.ars != cilRoute.isArs()) {
this.ars = cilRoute.isArs();
this.getStateList().set(1, this.convert(this.ars));
change = true;
}
if (this.arc != cilRoute.isArc()) {
this.arc = cilRoute.isArc();
this.getStateList().set(2, this.convert(this.arc));
change = true;
}
if (this.flt != cilRoute.isFlt()) {
this.flt = cilRoute.isFlt();
this.getStateList().set(3, this.convert(this.flt));
change = true;
}
return change;
}
}

View File

@ -1,17 +1,50 @@
package club.joylink.rtss.simulation.rt.ATS.bo;
import club.joylink.rtss.simulation.rt.CIL.bo.CilSection;
import java.util.Arrays;
import java.util.List;
public class AtsSection extends AtsDevice {
boolean axcOccupy;
String routeId;
boolean occ;// 非通信车占用
boolean ctOcc;// 通信车占用
boolean rl;
boolean lr;
boolean ol;
public AtsSection(String id, String name) {
super(id, name);
}
@Override
List<Object> buildMessage() {
return Arrays.asList(this.id, this.convert(this.occ),
this.convert(this.ctOcc), this.convert(this.rl), this.convert(this.lr), this.convert(this.ol));
}
public boolean applyChange(CilSection cilSection) {
List<Object> stateList = this.getStateList();
boolean change = false;
if (this.occ != cilSection.isAxcOccupy()) {
this.occ = cilSection.isAxcOccupy();
stateList.set(1, this.convert(this.occ));
change = true;
}
if (this.rl != cilSection.isRl()) {
this.rl = cilSection.isRl();
stateList.set(3, this.convert(this.rl));
change = true;
}
if (this.lr != cilSection.isLr()) {
this.lr = cilSection.isLr();
stateList.set(4, this.convert(this.lr));
change = true;
}
if (this.ol != cilSection.isOl()) {
this.ol = cilSection.isOl();
stateList.set(5, this.convert(this.ol));
change = true;
}
return change;
}
}

View File

@ -1,17 +1,63 @@
package club.joylink.rtss.simulation.rt.ATS.bo;
import club.joylink.rtss.simulation.rt.CIL.bo.CilSignal;
import lombok.Getter;
import java.util.Arrays;
import java.util.List;
@Getter
public class AtsSignal extends AtsDevice {
int signalAspect;
boolean logic;
boolean forceLight;
boolean bl;
boolean rbl;
int level;
public AtsSignal(String id, String name) {
super(id, name);
}
@Override
List<Object> buildMessage() {
return Arrays.asList(this.id, this.signalAspect,
this.convert(this.logic), this.convert(this.forceLight), this.convert(this.bl), this.convert(this.rbl), this.level);
}
public boolean applyChange(CilSignal cilSignal) {
List<Object> stateList = this.getStateList();
boolean change = false;
if (cilSignal.getSignalAspect() != this.signalAspect) {
this.signalAspect = cilSignal.getSignalAspect();
stateList.set(1, this.signalAspect);
change = true;
}
if (this.logic != cilSignal.isLogic()) {
this.logic = cilSignal.isLogic();
stateList.set(2, this.convert(this.logic));
change = true;
}
if (this.forceLight != cilSignal.isForceLight()) {
this.forceLight = cilSignal.isForceLight();
stateList.set(3, this.convert(this.forceLight));
change = true;
}
if (this.bl != cilSignal.isBl()) {
this.bl = cilSignal.isBl();
stateList.set(4, this.convert(this.bl));
change = true;
}
if (this.rbl != cilSignal.isRbl()) {
this.rbl = cilSignal.isRbl();
stateList.set(5, this.convert(this.rbl));
change = true;
}
if (this.level != cilSignal.getLevel()) {
this.level = cilSignal.getLevel();
stateList.set(6, this.level);
change = true;
}
return change;
}
}

View File

@ -1,7 +1,15 @@
package club.joylink.rtss.simulation.rt.ATS.bo;
import java.util.Arrays;
import java.util.List;
public class AtsStand extends AtsDevice {
public AtsStand(String id, String name) {
super(id, name);
}
@Override
public List<Object> buildMessage() {
return Arrays.asList(this.id);
}
}

View File

@ -1,7 +1,15 @@
package club.joylink.rtss.simulation.rt.ATS.bo;
import java.util.Arrays;
import java.util.List;
public class AtsStation extends AtsDevice {
public AtsStation(String id, String name) {
super(id, name);
}
@Override
public List<Object> buildMessage() {
return Arrays.asList(this.id);
}
}

View File

@ -1,8 +1,7 @@
package club.joylink.rtss.simulation.rt.ATS.bo;
import club.joylink.rtss.simulation.rt.RtSimulationSubscribeTopic;
import club.joylink.rtss.simulation.rt.CIL.bo.CilSwitch;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import java.util.Arrays;
@ -12,20 +11,54 @@ import java.util.List;
@Setter
public class AtsSwitch extends AtsDevice {
int position;
int routeUserToPosition;
boolean bl;
boolean sl;
String routeId;
boolean rl;
boolean ol;
boolean fl;
boolean bl; // 封锁
boolean sl; // 单锁
boolean rl; // 进路锁闭
boolean ol; // 延续保护锁闭
boolean fl; // 侧防锁闭
public AtsSwitch(String id, String name) {
super(id, name);
}
public List<Object> buildMessage() {
return Arrays.asList(id, position, routeUserToPosition, bl, sl, routeId, rl, ol, fl);
List<Object> buildMessage() {
return Arrays.asList(id, position,
this.convert(bl), this.convert(sl), this.convert(rl), this.convert(ol), this.convert(fl));
}
public boolean applyChange(CilSwitch cilSwitch) {
List<Object> stateList = this.getStateList();
boolean change = false;
if (cilSwitch.getPosition() != this.position) {
this.position = cilSwitch.getPosition();
stateList.set(1, this.position);
change = true;
}
if (cilSwitch.isBl() != this.bl) {
this.bl = cilSwitch.isBl();
stateList.set(2, this.convert(this.bl));
change = true;
}
if (cilSwitch.isSl() != this.sl) {
this.sl = cilSwitch.isSl();
stateList.set(3, this.convert(this.sl));
change = true;
}
if (cilSwitch.isRl() != this.rl) {
this.rl = cilSwitch.isRl();
stateList.set(4, this.convert(this.rl));
change = true;
}
if (cilSwitch.isOl() != this.ol) {
this.ol = cilSwitch.isOl();
stateList.set(5, this.convert(this.ol));
change = true;
}
if (cilSwitch.isFl() != this.fl) {
this.fl = cilSwitch.isFl();
stateList.set(6, this.convert(this.fl));
change = true;
}
return change;
}
}

View File

@ -1,7 +1,15 @@
package club.joylink.rtss.simulation.rt.ATS.bo;
import java.util.Arrays;
import java.util.List;
public class AtsTrain extends AtsDevice {
public AtsTrain(String id, String name) {
super(id, name);
}
@Override
public List<Object> buildMessage() {
return Arrays.asList(this.id);
}
}

View File

@ -81,8 +81,10 @@ public class CilLogicService {
}
private void sendState2Ats(RtSimulation rtSimulation, CilRepository cilRepository) {
for (CilSwitch cilSwitch : cilRepository.getSwitches()) {
atsApiService.handle(rtSimulation, cilSwitch);
}
// 后面需根据联锁站或集中站同步
this.atsApiService.syncCilSwitchState(rtSimulation, cilRepository.getSwitches());
this.atsApiService.syncCilSectionState(rtSimulation, cilRepository.getSections());
this.atsApiService.syncCilSignalState(rtSimulation, cilRepository.getSignals());
this.atsApiService.syncCilRouteState(rtSimulation, cilRepository.getRoutes());
}
}

View File

@ -67,10 +67,22 @@ public class CilRepository extends SimulationRepository {
return cilSwitch;
}
public List<CilSection> getSections() {
return new ArrayList<>(this.sectionMap.values());
}
public List<CilSwitch> getSwitches() {
return new ArrayList<>(switchMap.values());
}
public List<CilSignal> getSignals() {
return new ArrayList<>(this.signalMap.values());
}
public List<CilRoute> getRoutes() {
return new ArrayList<>(this.routeMap.values());
}
public CilSignal getSignalById(String id) {
CilSignal cilSignal = this.signalMap.get(id);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(cilSignal);

View File

@ -32,8 +32,6 @@ public class RtSimulationService {
private SrdLogicService srdLogicService;
@Autowired
private AtsLogicService atsLogicService;
@Autowired
private RtSimulationSubscribeMessageService rtSimulationSubscribeMessageService;
public RtSimulation create(UserVO userVO, Long mapId, MapPrdTypeEnum prdTypeEnum) {
Objects.requireNonNull(mapId);
@ -48,7 +46,6 @@ public class RtSimulationService {
this.atsLogicService.addJobs(rtSimulation);
this.initSimulationMember(rtSimulation);
this.initCreatorPlayMember(rtSimulation);
rtSimulation.addSubscribeMessageService(rtSimulationSubscribeMessageService);
simulationManager.start(rtSimulation.getId());
return rtSimulation;
}
@ -74,7 +71,7 @@ public class RtSimulationService {
this.commonRepoService.buildRepository(rtSimulation, mapVO);
this.cilLogicService.buildRepository(rtSimulation, mapVO);
this.srdLogicService.buildRepository(rtSimulation, mapVO);
this.atsLogicService.buildRepository(rtSimulation, mapVO);
this.atsLogicService.init(rtSimulation, mapVO);
}
public SimulationVO getBasicInfo(String id) {

View File

@ -1,41 +0,0 @@
package club.joylink.rtss.simulation.rt;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.Simulation;
import club.joylink.rtss.simulation.SimulationManager;
import club.joylink.rtss.simulation.SimulationSubscribeMessageService;
import club.joylink.rtss.simulation.SimulationUser;
import club.joylink.rtss.simulation.rt.ATS.AtsLogicService;
import club.joylink.rtss.simulation.rt.ATS.bo.AtsRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class RtSimulationSubscribeMessageService implements SimulationSubscribeMessageService {
@Autowired
private AtsLogicService atsLogicService;
@Autowired
private SimulationManager simulationManager;
@Override
public boolean acceptedSubscribePath(String destination) {
return RtSimulationSubscribeTopic.hasMatched(destination);
}
@Override
public Object buildMessageOfSubscribe(String destination) {
RtSimulationSubscribeTopic topic = RtSimulationSubscribeTopic.match(destination);
String id = topic.getId(destination);
RtSimulation simulation = simulationManager.getById(id, RtSimulation.class);
switch (topic) {
case ATS:
return atsLogicService.getAllMessages(simulation);
}
return null;
}
}

View File

@ -11,7 +11,7 @@ import java.util.Properties;
@Getter
public enum RtSimulationSubscribeTopic {
ATS("/ats", SrdLogicService.DEVICE_RUN_RATE),
ATS(String.format("%s%s", Simulation.MESSAGE_SUB_PREFIX, "/ats"), SrdLogicService.DEVICE_RUN_RATE),
// SandBox("/queue/simulation/jl3d/{id}, ", SrdLogicService.DEVICE_RUN_RATE),
// Drive("/queue/simulation/drive/{id}", SrdLogicService.TRAIN_RUN_RATE),
// PassengerFlow("/queue/simulation/passenger/{id}", SrdLogicService.DEVICE_RUN_RATE),
@ -47,7 +47,7 @@ public enum RtSimulationSubscribeTopic {
}
public boolean isMatch(String destination) {
String destPattern = Simulation.MESSAGE_SUB_PREFIX + this.destPattern;
String destPattern = this.destPattern;
String[] patterns = StringUtils.tokenizeToStringArray(destPattern, PATH_SEPARATOR);
String[] dests = StringUtils.tokenizeToStringArray(destination, PATH_SEPARATOR);
if (patterns.length == dests.length) {

View File

@ -1,5 +1,7 @@
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;
@ -7,6 +9,7 @@ import java.util.concurrent.atomic.AtomicInteger;
/**
* 虚拟真实道岔
*/
@Getter
public class SrSwitch extends SrDevice {
public static final int turnTime = 3000; // 默认转换时间

View File

@ -12,21 +12,18 @@ public class SwitchOperationHandler {
private CilApiService cilApiService;
@SimulationOperationMapping("Switch_Turn")
public boolean turn(RtSimulation simulation, String id) {
public void turn(RtSimulation simulation, String id) {
this.cilApiService.turnSwitch(simulation, id);
return true;
}
@SimulationOperationMapping("Switch_Normal_Position")
public boolean turnToNormal(RtSimulation simulation, String id) {
public void turnToNormal(RtSimulation simulation, String id) {
this.cilApiService.turnSwitchToNormal(simulation, id);
return true;
}
@SimulationOperationMapping("Switch_Reverse_Position")
public boolean turnToReverse(RtSimulation simulation, String id) {
public void turnToReverse(RtSimulation simulation, String id) {
this.cilApiService.turnSwitchToReverse(simulation, id);
return true;
}
}