列车图例显示位置

This commit is contained in:
tiger_zhou 2023-04-20 17:42:05 +08:00
parent 77ee7005f1
commit e83d5dfae6
5 changed files with 46 additions and 18 deletions

View File

@ -1,6 +1,5 @@
package club.joylink.rtss.simulation.cbtc.ATS;
import club.joylink.rtss.simulation.cbtc.ATS.data.AtsAlarm;
import club.joylink.rtss.simulation.cbtc.ATS.data.StationDiagram;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.constant.SimulationConstants;
@ -18,11 +17,14 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.*;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
/**
* 收集列车相关信息
@ -45,14 +47,16 @@ public class ATSTrainMessageDiagram {
if(Objects.nonNull(trainInfo) && trainInfo.isInbound()){
continue;
}
Optional<StationDiagram> optionalDiagram = this.calculate(train);
optionalDiagram.ifPresent(stationDiagramList::add);
}
SocketMessageVO<List<StationDiagram>> messageVO =
SocketMessageFactory.buildAtsStationDiagram(simulation.getId(), stationDiagramList);
stompMessageService.send(messageVO);
}
Set<String> sessions = simulation.getSimulationUserIds();
stompMessageService.sendToUser(sessions, messageVO);
}
/*public void collect(Simulation simulation){
for (VirtualRealityTrain train : simulation.getRepository().getOnlineTrainList()) {
@ -101,34 +105,35 @@ public class ATSTrainMessageDiagram {
boolean finalStation = true;
Section targetSecion = train.getTarget();
SectionPosition tailSP = train.getTailPosition();
Section tailSection = tailSP.getSection();
Section parent = tailSection.isPhysical() ? tailSection : tailSection.getParent();
Section tailSection = train.getTailPosition().getSection();
if(!Objects.equals(train.getNextStation().getCode(),train.getTerminalStation().getCode())) {
//车辆的下一站不是终点站,获取下一站的停车位置
finalStation = false;
SectionPosition sp = train.calculateNextStandStopPosition();
if(Objects.isNull(sp)){
return Optional.empty();
StationDiagram sd = new StationDiagram(train,false);
return Optional.of(sd);
}
targetSecion = sp.getSection();
}
//如果车尾所在的区段是逻辑区段那么就查找车辆后方的车站
if(Objects.isNull(parent.getStation())){
if(!tailSection.isStandTrack()){
//如果车尾所在的区段是逻辑区段那么就查找车辆后方的车站
SectionPosition sp1 = train.calculateBackStandStopPosition();
if(Objects.isNull(sp1)){
//未找到列车后面的车站,可能还未进始发站
return Optional.empty();
StationDiagram sd = new StationDiagram(train,false);
return Optional.of(sd);
}
tailSection = sp1.getSection();
}
Float complateDis = 1F;
if(!train.isParkingAt()){
complateDis = this.calculateStationRatio(tailSection,targetSecion,train);
}
StationDiagram stationDiagram = new StationDiagram(train,complateDis,finalStation);
StationDiagram stationDiagram = new StationDiagram(train,true,complateDis,finalStation);
stationDiagram.setStartStation(tailSection.getStation());
stationDiagram.setEndStation(train.getNextStation());
return Optional.of(stationDiagram);
@ -160,6 +165,6 @@ public class ATSTrainMessageDiagram {
}
public void addJobs(Simulation simulation){
simulation.addJob(SimulationModule.TRAIN_DIAGRAM.name(), () -> collect(simulation), SimulationConstants.TRAIN_RUNNING_RATE);
simulation.addFixedRateJob(SimulationModule.TRAIN_DIAGRAM.name(), () -> collect(simulation), SimulationConstants.TRAIN_DIAGRAM_RATE);
}
}

View File

@ -12,6 +12,7 @@ import lombok.NoArgsConstructor;
@NoArgsConstructor
public class StationDiagram {
public StationDiagram(VirtualRealityTrain train,Float stationComplateRatio, Boolean finalStation){
this.groupNum = train.getGroupNumber();
this.right = train.isRight();
@ -19,6 +20,21 @@ public class StationDiagram {
this.finalStation = finalStation;
}
public StationDiagram(VirtualRealityTrain train,boolean showTrainDiagram){
this.groupNum = train.getGroupNumber();
this.right = train.isRight();
this.showTrainDiagram = showTrainDiagram;
}
public StationDiagram(VirtualRealityTrain train,boolean showTrainDiagram,Float stationComplateRatio, Boolean finalStation){
this.groupNum = train.getGroupNumber();
this.right = train.isRight();
this.stationComplateRatio = stationComplateRatio;
this.finalStation = finalStation;
this.showTrainDiagram = showTrainDiagram;
}
/**
* 车组号
*/
@ -37,6 +53,10 @@ public class StationDiagram {
*/
private Boolean finalStation;
/**
* 图例是否显示车辆
*/
private Boolean showTrainDiagram;
/**
* 运行开始车站
*/

View File

@ -108,7 +108,10 @@ public interface SimulationConstants {
/** 停车场/车辆段循环逻辑频率单位ms */
int DEPOT_LOOP_RATE = 1000;
/**
* ncc 车站图例频率(ms)
*/
int TRAIN_DIAGRAM_RATE = 1000;
/**
* 获取仿真运行计划日期运营日
* @return

View File

@ -60,7 +60,7 @@ public enum SimulationModule {
ROBOT(SimulationConstants.ROBOT_LOGIC_LOOP_RATE),
YJDDZH(SimulationConstants.ROBOT_LOGIC_LOOP_RATE),
TRAIN_DIAGRAM(SimulationConstants.TRAIN_RUNNING_RATE)
TRAIN_DIAGRAM(SimulationConstants.TRAIN_DIAGRAM_RATE)
;
/** 执行频率-单位ms */

View File

@ -55,14 +55,14 @@ public class StompTest {
WebSocketStompClient stompClient = new WebSocketStompClient(socketClient);
SimulationSessionHandler handler = new SimulationSessionHandler();
ListenableFuture<StompSession> future = stompClient
.connect("ws://127.0.0.1:9000/joylink-websocket?token=6a8dbf62d3683844a6aa722b73b989f1",handler, "null");
.connect("ws://127.0.0.1:9000/joylink-websocket?token=62ee9df6368415439b46d3293c22b6c6",handler, "null");
StompSession stompSession = null;
try {
stompSession = future.get();
} catch (Exception e) {
e.printStackTrace();
}
stompSession.subscribe("/topic/yjddzh/trainPosition", new StompFrameHandler() {
stompSession.subscribe("/queue/simulation/63-8146", new StompFrameHandler() {
@Override
public Type getPayloadType(StompHeaders stompHeaders) {
return byte[].class;