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

轨道交通仿真——实现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; package club.joylink.rtss.simulation;
import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.util.PropertyPlaceholderHelper; import org.springframework.util.PropertyPlaceholderHelper;
import org.springframework.util.StringUtils; 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 = "/"; public static final String PATH_SEPARATOR = "/";
private Map<String, String> destinationMap = new HashMap<>(); private Map<String, String> destinationMap = new HashMap<>();
private static final PropertyPlaceholderHelper placeholderHelper = new PropertyPlaceholderHelper("{", "}"); private static final PropertyPlaceholderHelper placeholderHelper = new PropertyPlaceholderHelper("{", "}");
private List<SimulationSubscribeMessageService> subscribeMessageServiceList; private Map<String, SimulationMessagePublisher> messagePublisherMap = new HashMap<>();
private SimulationMessageSender messageSender; private SimulationMessageSender messageSender;
/** /**
* 消息推送线程池 * 消息推送线程池
@ -457,15 +458,16 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
public abstract String debugStr(); public abstract String debugStr();
public void setSubscribeMessageServiceList(List<SimulationSubscribeMessageService> list) { public void addMessagePublisher(SimulationMessagePublisher messagePublisher) {
this.subscribeMessageServiceList = list; 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) { public <P extends SimulationMessagePublisher> P getMessagePublisher(String name, Class<P> clz) {
if (this.subscribeMessageServiceList == null) { return (P) this.messagePublisherMap.get(name);
this.subscribeMessageServiceList = new ArrayList<>();
}
this.subscribeMessageServiceList.add(subscribeMessageService);
} }
public String handleDestination(String destinationPattern) { public String handleDestination(String destinationPattern) {
@ -505,8 +507,8 @@ public abstract class Simulation<U extends SimulationUser, M extends Simulation
return false; return false;
} }
user.subscribe(wsSessionId, destination); user.subscribe(wsSessionId, destination);
if (this.subscribeMessageServiceList != null) { if (this.messagePublisherMap != null) {
for (SimulationSubscribeMessageService service : this.subscribeMessageServiceList) { for (SimulationSubscribeMessageService service : this.messagePublisherMap.values()) {
if (service.acceptedSubscribePath(destination)) { if (service.acceptedSubscribePath(destination)) {
Object msg = service.buildMessageOfSubscribe(destination); Object msg = service.buildMessageOfSubscribe(destination);
if (msg != null) { 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; package club.joylink.rtss.simulation.rt.ATS;
import club.joylink.rtss.simulation.rt.ATS.bo.AtsRepository; import club.joylink.rtss.simulation.rt.ATS.bo.*;
import club.joylink.rtss.simulation.rt.ATS.bo.AtsSwitch; import club.joylink.rtss.simulation.rt.CIL.bo.CilRoute;
import club.joylink.rtss.simulation.rt.CIL.bo.CilDevice; 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.CIL.bo.CilSwitch;
import club.joylink.rtss.simulation.rt.RtSimulation; import club.joylink.rtss.simulation.rt.RtSimulation;
import club.joylink.rtss.simulation.rt.repo.CommonSwitch;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.List;
@Component @Component
public class AtsApiService { public class AtsApiService {
public void handle(RtSimulation rtSimulation, CilSwitch cilSwitch) { private AtsRepository getAtsRepository(RtSimulation rtSimulation) {
AtsRepository atsRepository = rtSimulation.getRepository(AtsRepository.NAME, AtsRepository.class); 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()); AtsSwitch atsSwitch = atsRepository.getSwitchById(cilSwitch.getId());
if (atsSwitch.getPosition() != cilSwitch.getPosition()) { boolean change = atsSwitch.applyChange(cilSwitch);
atsSwitch.setPosition(cilSwitch.getPosition()); if (change) {
atsRepository.ready2Send(atsSwitch.getId(), 1, atsSwitch.getPosition()); 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.stereotype.Component;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.List; import java.util.List;
/** /**
@ -17,14 +16,16 @@ import java.util.List;
*/ */
@Component @Component
public class AtsLogicService { public class AtsLogicService {
public void buildRepository(RtSimulation rtSimulation, MapVO mapVO) { public void init(RtSimulation rtSimulation, MapVO mapVO) {
AtsRepository atsRepository = AtsRepositoryBuilder.buildFrom(mapVO); AtsRepository atsRepository = AtsRepositoryBuilder.buildFrom(mapVO);
rtSimulation.addRepository(atsRepository); rtSimulation.addRepository(atsRepository);
AtsMessagePublisher atsMessagePublisher = new AtsMessagePublisher(atsRepository);
rtSimulation.addMessagePublisher(atsMessagePublisher);
} }
public void addJobs(RtSimulation rtSimulation) { public void addJobs(RtSimulation rtSimulation) {
for (RtSimulationSubscribeTopic topic : RtSimulationSubscribeTopic.values()) { 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; package club.joylink.rtss.simulation.rt.ATS.bo;
import club.joylink.rtss.simulation.rt.RtSimulationSubscribeTopic;
import lombok.Getter; import lombok.Getter;
import java.util.List; import java.util.List;
@Getter @Getter
public abstract class AtsDevice { public abstract class AtsDevice {
public static final int OFF = 0;
public static final int ON = 1;
List<Object> stateList;
String id; String id;
String name; String name;
public AtsDevice(String id, String name) { public AtsDevice(String id, String name) {
this.id = id; this.id = id;
this.name = name; 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.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.SimulationRepository; import club.joylink.rtss.simulation.SimulationRepository;
import club.joylink.rtss.simulation.cbtc.data.map.Station; import club.joylink.rtss.simulation.cbtc.data.map.Station;
import lombok.Getter;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@Getter
public class AtsRepository extends SimulationRepository { public class AtsRepository extends SimulationRepository {
public static final String NAME = "ATS"; public static final String NAME = "ATS";
@ -43,12 +45,30 @@ public class AtsRepository extends SimulationRepository {
return runPlan; 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) { public AtsSwitch getSwitchById(String id) {
AtsSwitch atsSwitch = switchMap.get(id); AtsSwitch atsSwitch = switchMap.get(id);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(atsSwitch); BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(atsSwitch);
return 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) { public void ready2Send(String id, int i, Object value) {
List<Object> message = messageMap.get(id); List<Object> message = messageMap.get(id);
if (message != null) { if (message != null) {

View File

@ -1,48 +1,43 @@
package club.joylink.rtss.simulation.rt.ATS.bo; 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.Getter;
import lombok.NonNull;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Objects;
@Getter @Getter
public class AtsRoute extends AtsDevice { public class AtsRoute extends AtsDevice {
boolean ars; boolean ars;
boolean arc; boolean arc;
boolean flt; 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) { public AtsRoute(String id, String name) {
super(id, name); super(id, name);
} }
// @Override @Override
public void buildMessage(@NonNull List<Object> message, RtSimulationSubscribeTopic topic) { List<Object> buildMessage() {
switch (topic) { return Arrays.asList(this.id, this.convert(this.ars), this.convert(this.arc), this.convert(this.flt));
case ATS: }
message.add(ars);
message.add(arc); public boolean applyChange(CilRoute cilRoute) {
message.add(flt); boolean change = false;
break; 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; 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 { public class AtsSection extends AtsDevice {
boolean axcOccupy; boolean occ;// 非通信车占用
boolean ctOcc;// 通信车占用
String routeId;
boolean rl; boolean rl;
boolean lr; boolean lr;
boolean ol; boolean ol;
public AtsSection(String id, String name) { public AtsSection(String id, String name) {
super(id, 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; 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 { public class AtsSignal extends AtsDevice {
int signalAspect; int signalAspect;
boolean logic; boolean logic;
boolean forceLight; boolean forceLight;
boolean bl; boolean bl;
boolean rbl; boolean rbl;
int level;
public AtsSignal(String id, String name) { public AtsSignal(String id, String name) {
super(id, 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; package club.joylink.rtss.simulation.rt.ATS.bo;
import java.util.Arrays;
import java.util.List;
public class AtsStand extends AtsDevice { public class AtsStand extends AtsDevice {
public AtsStand(String id, String name) { public AtsStand(String id, String name) {
super(id, 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; package club.joylink.rtss.simulation.rt.ATS.bo;
import java.util.Arrays;
import java.util.List;
public class AtsStation extends AtsDevice { public class AtsStation extends AtsDevice {
public AtsStation(String id, String name) { public AtsStation(String id, String name) {
super(id, 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; 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.Getter;
import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import java.util.Arrays; import java.util.Arrays;
@ -12,20 +11,54 @@ import java.util.List;
@Setter @Setter
public class AtsSwitch extends AtsDevice { public class AtsSwitch extends AtsDevice {
int position; int position;
int routeUserToPosition; boolean bl; // 封锁
boolean bl; boolean sl; // 单锁
boolean sl; boolean rl; // 进路锁闭
String routeId; boolean ol; // 延续保护锁闭
boolean rl; boolean fl; // 侧防锁闭
boolean ol;
boolean fl;
public AtsSwitch(String id, String name) { public AtsSwitch(String id, String name) {
super(id, name); super(id, name);
} }
public List<Object> buildMessage() { List<Object> buildMessage() {
return Arrays.asList(id, position, routeUserToPosition, bl, sl, routeId, rl, ol, fl); 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; package club.joylink.rtss.simulation.rt.ATS.bo;
import java.util.Arrays;
import java.util.List;
public class AtsTrain extends AtsDevice { public class AtsTrain extends AtsDevice {
public AtsTrain(String id, String name) { public AtsTrain(String id, String name) {
super(id, 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) { 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; return cilSwitch;
} }
public List<CilSection> getSections() {
return new ArrayList<>(this.sectionMap.values());
}
public List<CilSwitch> getSwitches() { public List<CilSwitch> getSwitches() {
return new ArrayList<>(switchMap.values()); 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) { public CilSignal getSignalById(String id) {
CilSignal cilSignal = this.signalMap.get(id); CilSignal cilSignal = this.signalMap.get(id);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(cilSignal); BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(cilSignal);

View File

@ -32,8 +32,6 @@ public class RtSimulationService {
private SrdLogicService srdLogicService; private SrdLogicService srdLogicService;
@Autowired @Autowired
private AtsLogicService atsLogicService; private AtsLogicService atsLogicService;
@Autowired
private RtSimulationSubscribeMessageService rtSimulationSubscribeMessageService;
public RtSimulation create(UserVO userVO, Long mapId, MapPrdTypeEnum prdTypeEnum) { public RtSimulation create(UserVO userVO, Long mapId, MapPrdTypeEnum prdTypeEnum) {
Objects.requireNonNull(mapId); Objects.requireNonNull(mapId);
@ -48,7 +46,6 @@ public class RtSimulationService {
this.atsLogicService.addJobs(rtSimulation); this.atsLogicService.addJobs(rtSimulation);
this.initSimulationMember(rtSimulation); this.initSimulationMember(rtSimulation);
this.initCreatorPlayMember(rtSimulation); this.initCreatorPlayMember(rtSimulation);
rtSimulation.addSubscribeMessageService(rtSimulationSubscribeMessageService);
simulationManager.start(rtSimulation.getId()); simulationManager.start(rtSimulation.getId());
return rtSimulation; return rtSimulation;
} }
@ -74,7 +71,7 @@ public class RtSimulationService {
this.commonRepoService.buildRepository(rtSimulation, mapVO); this.commonRepoService.buildRepository(rtSimulation, mapVO);
this.cilLogicService.buildRepository(rtSimulation, mapVO); this.cilLogicService.buildRepository(rtSimulation, mapVO);
this.srdLogicService.buildRepository(rtSimulation, mapVO); this.srdLogicService.buildRepository(rtSimulation, mapVO);
this.atsLogicService.buildRepository(rtSimulation, mapVO); this.atsLogicService.init(rtSimulation, mapVO);
} }
public SimulationVO getBasicInfo(String id) { 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 @Getter
public enum RtSimulationSubscribeTopic { 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), // SandBox("/queue/simulation/jl3d/{id}, ", SrdLogicService.DEVICE_RUN_RATE),
// Drive("/queue/simulation/drive/{id}", SrdLogicService.TRAIN_RUN_RATE), // Drive("/queue/simulation/drive/{id}", SrdLogicService.TRAIN_RUN_RATE),
// PassengerFlow("/queue/simulation/passenger/{id}", SrdLogicService.DEVICE_RUN_RATE), // PassengerFlow("/queue/simulation/passenger/{id}", SrdLogicService.DEVICE_RUN_RATE),
@ -47,7 +47,7 @@ public enum RtSimulationSubscribeTopic {
} }
public boolean isMatch(String destination) { 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[] patterns = StringUtils.tokenizeToStringArray(destPattern, PATH_SEPARATOR);
String[] dests = StringUtils.tokenizeToStringArray(destination, PATH_SEPARATOR); String[] dests = StringUtils.tokenizeToStringArray(destination, PATH_SEPARATOR);
if (patterns.length == dests.length) { if (patterns.length == dests.length) {

View File

@ -1,5 +1,7 @@
package club.joylink.rtss.simulation.rt.SRD.bo; package club.joylink.rtss.simulation.rt.SRD.bo;
import lombok.Getter;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
@ -7,6 +9,7 @@ import java.util.concurrent.atomic.AtomicInteger;
/** /**
* 虚拟真实道岔 * 虚拟真实道岔
*/ */
@Getter
public class SrSwitch extends SrDevice { public class SrSwitch extends SrDevice {
public static final int turnTime = 3000; // 默认转换时间 public static final int turnTime = 3000; // 默认转换时间

View File

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