增加列车TMS(司机视角左下角)消息

This commit is contained in:
joylink_zhangsai 2023-11-13 09:17:56 +08:00
parent 48803daf24
commit f281499099
8 changed files with 1404 additions and 1072 deletions

View File

@ -7,476 +7,475 @@ import club.joylink.rtss.simulation.cbtc.data.support.MovementAuthority;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import club.joylink.rtss.util.jsonSerialize.Boolean2NumSerializer;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import lombok.Getter;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import lombok.Getter;
@Getter
public class TrainHmiDisplay {
/**
* 列车code
*/
private String code;
/**
* 列车code
*/
private String code;
/**
* 车组号
*/
private String groupNumber;
/**
* 车组号
*/
private String groupNumber;
/**
* 服务号
*/
private String serviceNumber;
/**
* 服务号
*/
private String serviceNumber;
/**
* 车次号
*/
private String tripNumber;
/**
* 车次号
*/
private String tripNumber;
/**
* 目的地码
*/
private String destinationCode;
/**
* 目的地码
*/
private String destinationCode;
/**
* 列车方向true-向右 false-向左
*/
@JsonSerialize(using = Boolean2NumSerializer.class)
private boolean right;
/**
* 列车方向true-向右 false-向左
*/
@JsonSerialize(using = Boolean2NumSerializer.class)
private boolean right;
// @JsonSerialize(using = Boolean2NumSerializer.class)
// /** 列车是否被托管 */
// private boolean trust;
/**
* 列车当前速度
*/
private float v;
/**
* 列车当前速度
*/
private float v;
/**
* 列车防护速度
*/
private float pv;
/**
* 列车防护速度
*/
private float pv;
/**
* 列车目标速度
*/
private float tv;
/**
* 列车目标速度
*/
private float tv;
private float maLen;
private float maLen;
/**
* 列车运行级别
*/
private RunLevel runLevel;
/**
* 列车运行级别
*/
private RunLevel runLevel;
/**
* 驾驶模式
*/
private DriveMode driveMode;
/**
* 驾驶模式
*/
private DriveMode driveMode;
/**
* 预选模式
*/
private VirtualRealityTrain.PreselectionMode preselectionMode;
/**
* 预选模式
*/
private VirtualRealityTrain.PreselectionMode preselectionMode;
/**
* 列车牵引/制动状态
*/
private TrainTBControl tbControl;
/**
* 列车牵引/制动状态
*/
private TrainTBControl tbControl;
/**
* 车门是否开门
*/
private boolean doorOpen;
/**
* 车门是否开门
*/
private boolean doorOpen;
/**
* 左门是否可以关
*/
private boolean leftDoorCanClose;
/**
* 左门是否可以关
*/
private boolean leftDoorCanClose;
/**
* 右门是否可以关
*/
private boolean rightDoorCanClose;
/**
* 右门是否可以关
*/
private boolean rightDoorCanClose;
/**
* 是否紧急停车
*/
private boolean eb;
/**
* 是否紧急停车
*/
private boolean eb;
/**
* 是否电路EB
*/
private boolean circuitEB;
/**
* 是否电路EB
*/
private boolean circuitEB;
/**
* 跳站信息
*/
private boolean jump;
/**
* 跳站信息
*/
private boolean jump;
/**
* 是否扣车
*/
private boolean hold;
/**
* 是否扣车
*/
private boolean hold;
/**
* ATO是否启用
*/
private boolean atoOn;
/**
* ATO是否启用
*/
private boolean atoOn;
/**
* ATP是否启用
*/
private boolean atpOn;
/**
* ATP是否启用
*/
private boolean atpOn;
/**
* 计划下一站
*/
private String nextStation;
/**
* 计划下一站
*/
private String nextStation;
/**
* 是否即将到站
*/
private boolean beAbout2Arrive;
/**
* 是否即将到站
*/
private boolean beAbout2Arrive;
/**
* 计划终点站
*/
private String endStation;
/**
* 计划终点站
*/
private String endStation;
/**
* 停站
*/
private boolean parking;
/**
* 停站
*/
private boolean parking;
/**
* 在站台区域
*/
private boolean inTheStandArea;
/**
* 在站台区域
*/
private boolean inTheStandArea;
/**
* true牵引false制动1牵引2制动3惰行4无
*/
private int tow;
/**
* true牵引false制动1牵引2制动3惰行4无
*/
private int tow;
/**
* 牵引制动力百分比
*/
private int forcePercent;
/**
* 牵引制动力百分比
*/
private int forcePercent;
/**
* 门模式
*/
private String doorMode;
/**
* 门模式
*/
private String doorMode;
/**
* 门选择
*/
private String doorSelection;
/**
* 门选择
*/
private String doorSelection;
/**
* 确认信息
*/
private VirtualRealityTrain.ConfirmationMessage message;
/**
* 确认信息
*/
private VirtualRealityTrain.ConfirmationMessage message;
/**
* ATO可以启动
*/
private Boolean atoCanOpen;
/**
* ATO可以启动
*/
private Boolean atoCanOpen;
/**
* 列车停站站台
*/
private String standCode;
/**
* 列车停站站台
*/
private String standCode;
private VirtualRealityTrain.Handwheel gear;
private VirtualRealityTrain.Handwheel gear;
private Boolean takeOver;
private Boolean takeOver;
public TrainHmiDisplay(VirtualRealityTrain train) {
this.code = train.getCode();
this.groupNumber = train.getGroupNumber();
this.serviceNumber = train.getServiceNumber();
this.tripNumber = train.getTripNumber();
this.destinationCode = train.getDestinationCode();
this.right = train.isRight();
public TrainHmiDisplay(VirtualRealityTrain train) {
this.code = train.getCode();
this.groupNumber = train.getGroupNumber();
this.serviceNumber = train.getServiceNumber();
this.tripNumber = train.getTripNumber();
this.destinationCode = train.getDestinationCode();
this.right = train.isRight();
// this.trust = train.getRobotTargetPosition() != null;
this.runLevel = train.getRunLevel();
this.driveMode = train.getDriveMode();
this.preselectionMode = train.getTempPreselectionMode();
this.tbControl = train.getTbControl();
this.doorOpen = !train.isAllDoorCloseAndLock();
if (!train.getDoor1().isClose()) {
if (this.right) {
this.leftDoorCanClose = true;
} else {
this.rightDoorCanClose = true;
}
}
if (!train.getDoor2().isClose()) {
if (this.right) {
this.rightDoorCanClose = true;
} else {
this.leftDoorCanClose = true;
}
}
this.v = BigDecimal.valueOf(train.getSpeedKmPh())
.setScale(2, RoundingMode.HALF_UP).floatValue();
this.pv = BigDecimal.valueOf(train.getProtectSpeedKmPh())
.setScale(2, RoundingMode.HALF_UP).floatValue();
this.tv = BigDecimal.valueOf(train.getTargetSpeedKmPh())
.setScale(2, RoundingMode.HALF_UP).floatValue();
MovementAuthority ma = train.getMa();
if (Objects.nonNull(ma)) {
this.maLen = BigDecimal.valueOf(train.getTargetDistance())
.setScale(3, RoundingMode.HALF_UP).floatValue();
}
this.eb = train.isEB();
this.circuitEB = train.isCircuitEB();
this.jump = train.isJump();
this.hold = train.isHold();
this.atoOn = train.isAtoOn();
this.atpOn = train.isAtpOn();
if (Objects.nonNull(train.getNextStation())) {
this.nextStation = train.getNextStation().getName();
}
this.beAbout2Arrive = train.isBeAbout2Arrive();
if (Objects.nonNull(train.getTerminalStation())) {
this.endStation = train.getTerminalStation().getName();
}
this.parking = train.isParkingAt();
this.inTheStandArea = train.isInTheStandArea();
this.tow = getTow(train);
this.forcePercent = getForcePercent(train);
this.doorMode = train.getDoorMode().toString();
this.doorSelection = train.getDoorSelection().toString();
this.message = train.findFirstMessage();
this.atoCanOpen = train.isAtoCanOpen();
this.standCode = train.queryParkingStandCode();
this.gear = train.getGear();
this.takeOver = train.isTakeOver();
this.runLevel = train.getRunLevel();
this.driveMode = train.getDriveMode();
this.preselectionMode = train.getTempPreselectionMode();
this.tbControl = train.getTbControl();
this.doorOpen = !train.isAllDoorCloseAndLock();
if (!train.getDoor1().isClose()) {
if (this.right) {
this.leftDoorCanClose = true;
} else {
this.rightDoorCanClose = true;
}
}
private int getForcePercent(VirtualRealityTrain train) {
if (train.getFk() > 0) {
return (int) (train.getFk() / train.getCurrentFkMax() * 100);
} else if (train.getFb() > 0) {
return (int) (train.getFb() / train.getCurrentFbMax() * 100);
} else {
return 0;
}
if (!train.getDoor2().isClose()) {
if (this.right) {
this.rightDoorCanClose = true;
} else {
this.leftDoorCanClose = true;
}
}
private int getTow(VirtualRealityTrain train) {
Boolean towed = train.isTowed();
if (towed == null) {
return !train.isStop() ? 3 : 4;
} else if (towed) {
return 1;
} else {
return 2;
}
this.v = BigDecimal.valueOf(train.getSpeedKmPh())
.setScale(2, RoundingMode.HALF_UP).floatValue();
this.pv = BigDecimal.valueOf(train.getProtectSpeedKmPh())
.setScale(2, RoundingMode.HALF_UP).floatValue();
this.tv = BigDecimal.valueOf(train.getTargetSpeedKmPh())
.setScale(2, RoundingMode.HALF_UP).floatValue();
MovementAuthority ma = train.getMa();
if (Objects.nonNull(ma)) {
this.maLen = BigDecimal.valueOf(train.getTargetDistance())
.setScale(3, RoundingMode.HALF_UP).floatValue();
}
this.eb = train.isEB();
this.circuitEB = train.isCircuitEB();
this.jump = train.isJump();
this.hold = train.isHold();
this.atoOn = train.isAtoOn();
this.atpOn = train.isAtpOn();
if (Objects.nonNull(train.getNextStation())) {
this.nextStation = train.getNextStation().getName();
}
this.beAbout2Arrive = train.isBeAbout2Arrive();
if (Objects.nonNull(train.getTerminalStation())) {
this.endStation = train.getTerminalStation().getName();
}
this.parking = train.isParkingAt();
this.inTheStandArea = train.isInTheStandArea();
this.tow = getTow(train);
this.forcePercent = getForcePercent(train);
this.doorMode = train.getDoorMode().toString();
this.doorSelection = train.getDoorSelection().toString();
this.message = train.findFirstMessage();
this.atoCanOpen = train.isAtoCanOpen();
this.standCode = train.queryParkingStandCode();
this.gear = train.getGear();
this.takeOver = train.isTakeOver();
}
public Map<String, Object> changeAndCollectDiff(VirtualRealityTrain train) {
Map<String, Object> map = new HashMap<>();
if (!Objects.equals(this.serviceNumber, train.getServiceNumber())) {
map.put("serviceNumber", train.getServiceNumber());
this.serviceNumber = train.getServiceNumber();
}
if (!Objects.equals(this.tripNumber, train.getTripNumber())) {
map.put("tripNumber", train.getTripNumber());
this.tripNumber = train.getTripNumber();
}
if (!Objects.equals(this.destinationCode, train.getDestinationCode())) {
map.put("destinationCode", train.getDestinationCode());
this.destinationCode = train.getDestinationCode();
}
if (!Objects.equals(this.right, train.isRight())) {
map.put("right", train.isRight());
this.right = train.isRight();
}
if (!Objects.equals(this.right, train.isRight())) {
map.put("right", train.isRight());
this.right = train.isRight();
}
if (!Objects.equals(this.runLevel, train.getRunLevel())) {
map.put("runLevel", train.getRunLevel());
this.runLevel = train.getRunLevel();
}
if (!Objects.equals(this.driveMode, train.getDriveMode())) {
map.put("driveMode", train.getDriveMode());
this.driveMode = train.getDriveMode();
}
if (!Objects.equals(this.preselectionMode, train.getTempPreselectionMode())) {
this.preselectionMode = train.getTempPreselectionMode();
map.put("preselectionMode", this.preselectionMode);
}
if (!Objects.equals(this.tbControl, train.getTbControl())) {
map.put("tbControl", train.getTbControl());
this.tbControl = train.getTbControl();
}
if (!Objects.equals(this.doorOpen, !train.isAllDoorCloseAndLock())) {
map.put("doorOpen", !train.isAllDoorCloseAndLock());
this.doorOpen = !train.isAllDoorCloseAndLock();
}
boolean leftCc = false;
boolean rightCc = false;
if (!train.getDoor1().isClose()) {
if (this.right) {
leftCc = true;
} else {
rightCc = true;
}
}
if (!train.getDoor2().isClose()) {
if (this.right) {
rightCc = true;
} else {
leftCc = true;
}
}
if (!Objects.equals(this.leftDoorCanClose, leftCc)) {
map.put("leftDoorCanClose", leftCc);
this.leftDoorCanClose = leftCc;
}
if (!Objects.equals(this.rightDoorCanClose, rightCc)) {
map.put("rightDoorCanClose", rightCc);
this.rightDoorCanClose = rightCc;
}
float v = BigDecimal.valueOf(train.getSpeedKmPh())
.setScale(2, RoundingMode.HALF_UP).floatValue();
float pv = BigDecimal.valueOf(train.getProtectSpeedKmPh())
.setScale(2, RoundingMode.HALF_UP).floatValue();
float tv = BigDecimal.valueOf(train.getTargetSpeedKmPh())
.setScale(2, RoundingMode.HALF_UP).floatValue();
private int getForcePercent(VirtualRealityTrain train) {
if (train.getFk() > 0) {
return Math.min(100, (int) (train.getFk() / train.getCurrentFkMax() * 100));
} else if (train.getFb() > 0) {
return Math.min(100, (int) (train.getFb() / train.getCurrentFbMax() * 100));
} else {
return 0;
}
}
private int getTow(VirtualRealityTrain train) {
Boolean towed = train.isTowed();
if (towed == null) {
return !train.isStop() ? 3 : 4;
} else if (towed) {
return 1;
} else {
return 2;
}
}
public Map<String, Object> changeAndCollectDiff(VirtualRealityTrain train) {
Map<String, Object> map = new HashMap<>();
if (!Objects.equals(this.serviceNumber, train.getServiceNumber())) {
map.put("serviceNumber", train.getServiceNumber());
this.serviceNumber = train.getServiceNumber();
}
if (!Objects.equals(this.tripNumber, train.getTripNumber())) {
map.put("tripNumber", train.getTripNumber());
this.tripNumber = train.getTripNumber();
}
if (!Objects.equals(this.destinationCode, train.getDestinationCode())) {
map.put("destinationCode", train.getDestinationCode());
this.destinationCode = train.getDestinationCode();
}
if (!Objects.equals(this.right, train.isRight())) {
map.put("right", train.isRight());
this.right = train.isRight();
}
if (!Objects.equals(this.right, train.isRight())) {
map.put("right", train.isRight());
this.right = train.isRight();
}
if (!Objects.equals(this.runLevel, train.getRunLevel())) {
map.put("runLevel", train.getRunLevel());
this.runLevel = train.getRunLevel();
}
if (!Objects.equals(this.driveMode, train.getDriveMode())) {
map.put("driveMode", train.getDriveMode());
this.driveMode = train.getDriveMode();
}
if (!Objects.equals(this.preselectionMode, train.getTempPreselectionMode())) {
this.preselectionMode = train.getTempPreselectionMode();
map.put("preselectionMode", this.preselectionMode);
}
if (!Objects.equals(this.tbControl, train.getTbControl())) {
map.put("tbControl", train.getTbControl());
this.tbControl = train.getTbControl();
}
if (!Objects.equals(this.doorOpen, !train.isAllDoorCloseAndLock())) {
map.put("doorOpen", !train.isAllDoorCloseAndLock());
this.doorOpen = !train.isAllDoorCloseAndLock();
}
boolean leftCc = false;
boolean rightCc = false;
if (!train.getDoor1().isClose()) {
if (this.right) {
leftCc = true;
} else {
rightCc = true;
}
}
if (!train.getDoor2().isClose()) {
if (this.right) {
rightCc = true;
} else {
leftCc = true;
}
}
if (!Objects.equals(this.leftDoorCanClose, leftCc)) {
map.put("leftDoorCanClose", leftCc);
this.leftDoorCanClose = leftCc;
}
if (!Objects.equals(this.rightDoorCanClose, rightCc)) {
map.put("rightDoorCanClose", rightCc);
this.rightDoorCanClose = rightCc;
}
float v = BigDecimal.valueOf(train.getSpeedKmPh())
.setScale(2, RoundingMode.HALF_UP).floatValue();
float pv = BigDecimal.valueOf(train.getProtectSpeedKmPh())
.setScale(2, RoundingMode.HALF_UP).floatValue();
float tv = BigDecimal.valueOf(train.getTargetSpeedKmPh())
.setScale(2, RoundingMode.HALF_UP).floatValue();
// if (!Objects.equals(this.v, v)) {
map.put("v", v);
this.v = v;
map.put("v", v);
this.v = v;
// }
// if (!Objects.equals(this.pv, pv)) {
map.put("pv", pv);
this.pv = pv;
map.put("pv", pv);
this.pv = pv;
// }
// if (!Objects.equals(this.tv, tv)) {
map.put("tv", tv);
this.tv = tv;
map.put("tv", tv);
this.tv = tv;
// }
MovementAuthority ma = train.getMa();
float maLen = 0;
if (Objects.nonNull(ma)) {
maLen = BigDecimal.valueOf(train.getTargetDistance())
.setScale(3, RoundingMode.HALF_UP).floatValue();
}
if (!Objects.equals(this.maLen, maLen)) {
map.put("maLen", maLen);
this.maLen = maLen;
}
if (!Objects.equals(this.eb, train.isEB())) {
map.put("eb", train.isEB());
this.eb = train.isEB();
}
if (!Objects.equals(this.circuitEB, train.isCircuitEB())) {
map.put("circuitEB", train.isCircuitEB());
this.circuitEB = train.isCircuitEB();
}
if (!Objects.equals(this.jump, train.isJump())) {
map.put("jump", train.isJump());
this.jump = train.isJump();
}
if (!Objects.equals(this.hold, train.isHold())) {
map.put("hold", train.isHold());
this.hold = train.isHold();
}
if (!Objects.equals(this.atoOn, train.isAtoOn())) {
map.put("atoOn", train.isAtoOn());
this.atoOn = train.isAtoOn();
}
if (!Objects.equals(this.atpOn, train.isAtpOn())) {
map.put("atpOn", train.isAtpOn());
this.atpOn = train.isAtpOn();
}
String nextStation = null;
if (Objects.nonNull(train.getNextStation())) {
nextStation = train.getNextStation().getName();
}
if (!Objects.equals(this.nextStation, nextStation)) {
map.put("nextStation", nextStation);
this.nextStation = nextStation;
}
if (!Objects.equals(this.beAbout2Arrive, train.isBeAbout2Arrive())) {
map.put("beAbout2Arrive", train.isBeAbout2Arrive());
this.beAbout2Arrive = train.isBeAbout2Arrive();
}
String endStation = null;
if (Objects.nonNull(train.getTerminalStation())) {
endStation = train.getTerminalStation().getName();
}
if (!Objects.equals(this.endStation, endStation)) {
map.put("endStation", endStation);
this.endStation = endStation;
}
if (!Objects.equals(this.parking, train.isParkingAt())) {
this.parking = train.isParkingAt();
map.put("parking", this.parking);
}
if (!Objects.equals(this.inTheStandArea, train.isInTheStandArea())) {
this.inTheStandArea = train.isInTheStandArea();
map.put("inTheStandArea", this.inTheStandArea);
}
int tow = getTow(train);
if (this.tow != tow) {
this.tow = tow;
map.put("tow", tow);
}
int forcePercent = getForcePercent(train);
if (!Objects.equals(this.forcePercent, forcePercent)) {
this.forcePercent = forcePercent;
map.put("forcePercent", forcePercent);
}
if (!Objects.equals(this.doorMode, train.getDoorMode().toString())) {
this.doorMode = train.getDoorMode().toString();
map.put("doorMode", this.doorMode);
}
if (!Objects.equals(this.doorSelection, train.getDoorSelection().toString())) {
this.doorSelection = train.getDoorSelection().toString();
map.put("doorSelection", this.doorSelection);
}
VirtualRealityTrain.ConfirmationMessage message = train.findFirstMessage();
if (!Objects.equals(this.message, message)) {
this.message = message;
map.put("message", this.message);
}
boolean atoCanOpen = train.isAtoCanOpen();
if (!Objects.equals(this.atoCanOpen, atoCanOpen)) {
this.atoCanOpen = atoCanOpen;
map.put("atoCanOpen", this.atoCanOpen);
}
VirtualRealityTrain.Handwheel gear = train.getGear();
if (!Objects.equals(this.gear, gear)) {
this.gear = gear;
map.put("gear", this.gear);
}
String standCode = train.queryParkingStandCode();
if (!Objects.equals(this.standCode, standCode)) {
this.standCode = standCode;
map.put("standCode", this.standCode);
}
boolean takeOver = train.isTakeOver();
if (Objects.equals(this.takeOver, takeOver)) {
this.takeOver = takeOver;
map.put("takeOver", takeOver);
}
if (map.size() > 0) {
map.put("code", this.code);
return map;
}
return null;
MovementAuthority ma = train.getMa();
float maLen = 0;
if (Objects.nonNull(ma)) {
maLen = BigDecimal.valueOf(train.getTargetDistance())
.setScale(3, RoundingMode.HALF_UP).floatValue();
}
if (!Objects.equals(this.maLen, maLen)) {
map.put("maLen", maLen);
this.maLen = maLen;
}
if (!Objects.equals(this.eb, train.isEB())) {
map.put("eb", train.isEB());
this.eb = train.isEB();
}
if (!Objects.equals(this.circuitEB, train.isCircuitEB())) {
map.put("circuitEB", train.isCircuitEB());
this.circuitEB = train.isCircuitEB();
}
if (!Objects.equals(this.jump, train.isJump())) {
map.put("jump", train.isJump());
this.jump = train.isJump();
}
if (!Objects.equals(this.hold, train.isHold())) {
map.put("hold", train.isHold());
this.hold = train.isHold();
}
if (!Objects.equals(this.atoOn, train.isAtoOn())) {
map.put("atoOn", train.isAtoOn());
this.atoOn = train.isAtoOn();
}
if (!Objects.equals(this.atpOn, train.isAtpOn())) {
map.put("atpOn", train.isAtpOn());
this.atpOn = train.isAtpOn();
}
String nextStation = null;
if (Objects.nonNull(train.getNextStation())) {
nextStation = train.getNextStation().getName();
}
if (!Objects.equals(this.nextStation, nextStation)) {
map.put("nextStation", nextStation);
this.nextStation = nextStation;
}
if (!Objects.equals(this.beAbout2Arrive, train.isBeAbout2Arrive())) {
map.put("beAbout2Arrive", train.isBeAbout2Arrive());
this.beAbout2Arrive = train.isBeAbout2Arrive();
}
String endStation = null;
if (Objects.nonNull(train.getTerminalStation())) {
endStation = train.getTerminalStation().getName();
}
if (!Objects.equals(this.endStation, endStation)) {
map.put("endStation", endStation);
this.endStation = endStation;
}
if (!Objects.equals(this.parking, train.isParkingAt())) {
this.parking = train.isParkingAt();
map.put("parking", this.parking);
}
if (!Objects.equals(this.inTheStandArea, train.isInTheStandArea())) {
this.inTheStandArea = train.isInTheStandArea();
map.put("inTheStandArea", this.inTheStandArea);
}
int tow = getTow(train);
if (this.tow != tow) {
this.tow = tow;
map.put("tow", tow);
}
int forcePercent = getForcePercent(train);
if (!Objects.equals(this.forcePercent, forcePercent)) {
this.forcePercent = forcePercent;
map.put("forcePercent", forcePercent);
}
if (!Objects.equals(this.doorMode, train.getDoorMode().toString())) {
this.doorMode = train.getDoorMode().toString();
map.put("doorMode", this.doorMode);
}
if (!Objects.equals(this.doorSelection, train.getDoorSelection().toString())) {
this.doorSelection = train.getDoorSelection().toString();
map.put("doorSelection", this.doorSelection);
}
VirtualRealityTrain.ConfirmationMessage message = train.findFirstMessage();
if (!Objects.equals(this.message, message)) {
this.message = message;
map.put("message", this.message);
}
boolean atoCanOpen = train.isAtoCanOpen();
if (!Objects.equals(this.atoCanOpen, atoCanOpen)) {
this.atoCanOpen = atoCanOpen;
map.put("atoCanOpen", this.atoCanOpen);
}
VirtualRealityTrain.Handwheel gear = train.getGear();
if (!Objects.equals(this.gear, gear)) {
this.gear = gear;
map.put("gear", this.gear);
}
String standCode = train.queryParkingStandCode();
if (!Objects.equals(this.standCode, standCode)) {
this.standCode = standCode;
map.put("standCode", this.standCode);
}
boolean takeOver = train.isTakeOver();
if (Objects.equals(this.takeOver, takeOver)) {
this.takeOver = takeOver;
map.put("takeOver", takeOver);
}
if (map.size() > 0) {
map.put("code", this.code);
return map;
}
return null;
}
}

View File

@ -0,0 +1,192 @@
package club.joylink.rtss.simulation.cbtc.communication.vo;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import lombok.Data;
/**
* 列车监控信息展示牵引/制动力
*/
@Data
public class TrainTmsDisplay {
private final String groupNumber;
/**
* 网压V
*/
private int voltage;
/**
* 网流A
*/
private int current;
/**
* 速度km/h
*/
private float speed;
/**
* 牵引/制动级位百分比 traction/breaking level
*/
private int tbLevelPercent;
/**
* 里程标
*/
private String mileage;
/**
* 下一站名
*/
private String nextStation;
/**
* 目的站名
*/
private String destination;
/**
* 牵引状态当true前端显示在一定范围内波动
*/
private boolean traction;
/**
* 制动缸的压强
*/
private float pressureOfBrakeCylinder;
/**
* 1侧门开
*/
private boolean oneSideDoorOpened;
/**
* 2侧门开
*/
private boolean twoSideDoorOpened;
/**
* 停车制动的压力bar
*/
private float parkingBreakPressure;
// /**
// * 牵引力百分比
// */
// private float tractionForcePercent;
// /**
// * 制动力百分比
// */
// private float breakingForcePercent;
public TrainTmsDisplay(VirtualRealityTrain train) {
this.groupNumber = train.getGroupNumber();
this.voltage = 1600;
this.current = 317;
this.speed = train.getSpeedKmPh();
this.tbLevelPercent = getTbLevelPercent(train);
this.mileage = "---";
this.nextStation = getNextStationName(train);
this.destination = getDestinationName(train);
this.traction = isTraction(train);
this.pressureOfBrakeCylinder = getPressureOfBrakeCylinder(train);
this.oneSideDoorOpened = train.getDoor1().isOpen();
this.twoSideDoorOpened = train.getDoor2().isOpen();
this.parkingBreakPressure = getParkingBreakPressure(train);
// this.tractionForcePercent = getTractionForcePercent(train);
// this.breakingForcePercent = getBreakingForcePercent(train);
}
public Map<String, Object> updateAndCollectDiff(VirtualRealityTrain train) {
Map<String, Object> map = new HashMap<>();
float speedKmPh = train.getSpeedKmPh();
if (!Objects.equals(speedKmPh, this.speed)) {
this.speed = speedKmPh;
map.put("speed", this.speed);
}
int tbLevelPercent = getTbLevelPercent(train);
if (!Objects.equals(tbLevelPercent, this.tbLevelPercent)) {
this.tbLevelPercent = tbLevelPercent;
map.put("tbLevelPercent", this.tbLevelPercent);
}
String nextStationName = getNextStationName(train);
if (!Objects.equals(nextStationName, this.nextStation)) {
this.nextStation = nextStationName;
map.put("nextStation", this.nextStation);
}
String destinationName = getDestinationName(train);
if (!Objects.equals(destinationName, this.destination)) {
this.destination = destinationName;
map.put("destination", this.destination);
}
if (!Objects.equals(isTraction(), this.traction)) {
this.traction = isTraction();
map.put("traction", this.traction);
}
float pressureOfBrakeCylinder = getPressureOfBrakeCylinder(train);
if (!Objects.equals(pressureOfBrakeCylinder, this.pressureOfBrakeCylinder)) {
this.pressureOfBrakeCylinder = pressureOfBrakeCylinder;
map.put("pressureOfBrakeCylinder", this.pressureOfBrakeCylinder);
}
if (!Objects.equals(train.getDoor1().isOpen(), this.oneSideDoorOpened)) {
this.oneSideDoorOpened = train.getDoor1().isOpen();
map.put("oneSideDoorOpened", this.oneSideDoorOpened);
}
if (!Objects.equals(train.getDoor2().isOpen(), this.twoSideDoorOpened)) {
this.twoSideDoorOpened = train.getDoor2().isOpen();
map.put("twoSideDoorOpened", this.twoSideDoorOpened);
}
float parkingBreakPressure = getParkingBreakPressure(train);
if (!Objects.equals(parkingBreakPressure, this.parkingBreakPressure)) {
this.parkingBreakPressure = parkingBreakPressure;
map.put("parkingBreakPressure", this.parkingBreakPressure);
}
// float tractionForcePercent = getTractionForcePercent(train);
// if (!Objects.equals(tractionForcePercent, this.tractionForcePercent)) {
// this.tractionForcePercent = tractionForcePercent;
// map.put("tractionForcePercent", this.tractionForcePercent);
// }
// float breakingForcePercent = getBreakingForcePercent(train);
// if (!Objects.equals(breakingForcePercent, this.breakingForcePercent)) {
// this.breakingForcePercent = breakingForcePercent;
// map.put("breakingForcePercent", this.breakingForcePercent);
// }
if (!map.isEmpty()) {
map.put("groupNumber", this.groupNumber);
return map;
} else {
return null;
}
}
private int getTbLevelPercent(VirtualRealityTrain train) {
if (train.getFk() > 0) {
return Math.min(100, (int) (train.getFk() / train.getCurrentFkMax()) * 100);
} else {
return -Math.min(100, (int) (train.getFb() / train.getCurrentFbMax()) * 100);
}
}
private String getNextStationName(VirtualRealityTrain train) {
return train.getNextStation() == null ? "---" : train.getNextStation().getName();
}
private String getDestinationName(VirtualRealityTrain train) {
return train.getTerminalStation() == null ? "---" : train.getTerminalStation().getName();
}
private boolean isTraction(VirtualRealityTrain train) {
return train.getFk() > 0;
}
private float getPressureOfBrakeCylinder(VirtualRealityTrain train) {
return Math.min(1, train.getFb() / train.getCurrentFbMax()) * 20;
}
private float getParkingBreakPressure(VirtualRealityTrain train) {
if (train.isStop()) {
return getPressureOfBrakeCylinder(train);
}
return 0;
}
// private float getTractionForcePercent(VirtualRealityTrain train) {
// return Math.min(100, (train.getFk() / train.getCurrentFkMax()) * 100);
// }
//
// private float getBreakingForcePercent(VirtualRealityTrain train) {
// return Math.min(100, (train.getFb() / train.getCurrentFbMax()) * 100);
// }
}

View File

@ -5,6 +5,7 @@ import club.joylink.rtss.exception.BusinessExceptionAssertEnum;
import club.joylink.rtss.simulation.cbtc.ATS.data.AtsAlarm;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.communication.vo.TrainHmiDisplay;
import club.joylink.rtss.simulation.cbtc.communication.vo.TrainTmsDisplay;
import club.joylink.rtss.simulation.cbtc.data.iscs.Audio;
import club.joylink.rtss.simulation.cbtc.data.map.AutoSignal;
import club.joylink.rtss.simulation.cbtc.data.map.Catenary;
@ -124,6 +125,11 @@ public class SimulationDataRepository {
*/
private Map<String, TrainHmiDisplay> trainHmiMap = new ConcurrentHashMap<>();
/**
* 列车操控台列车信息展示
*/
private Map<String, TrainTmsDisplay> trainTmsMap = new ConcurrentHashMap<>();
/**
* TDTtrain depart timer状态数据 key-站台code val-tdt状态对象
*/
@ -530,9 +536,9 @@ public class SimulationDataRepository {
public List<RoutePath> queryRoutePathsByStart(Section start) {
List<RoutePath> pathList = new ArrayList<>();
for (List<RoutePath> list : routePathMap.values()) {
if (CollectionUtils.isEmpty(list)) {
continue;
}
if (CollectionUtils.isEmpty(list)) {
continue;
}
if (Objects.equals(list.get(0).getStart(), start)) {
pathList.addAll(list);
}
@ -549,9 +555,9 @@ public class SimulationDataRepository {
public List<RoutePath> queryRoutePathsByEnd(Section end) {
List<RoutePath> pathList = new ArrayList<>();
for (List<RoutePath> list : routePathMap.values()) {
if (CollectionUtils.isEmpty(list)) {
continue;
}
if (CollectionUtils.isEmpty(list)) {
continue;
}
if (Objects.equals(list.get(0).getEnd(), end)) {
pathList.addAll(list);
}
@ -826,9 +832,9 @@ public class SimulationDataRepository {
break;
}
}
if (next != null && next.isInvalid()) {
return null;
}
if (next != null && next.isInvalid()) {
return null;
}
return next;
}
@ -1099,9 +1105,9 @@ public class SimulationDataRepository {
public RealRun queryLastRealRun(String groupNumber) {
for (int i = this.realRunRecordList.size() - 1; i >= 0; i--) {
RealRun realRun = this.realRunRecordList.get(i);
if (realRun.getGroupNumber().equals(groupNumber)) {
return realRun;
}
if (realRun.getGroupNumber().equals(groupNumber)) {
return realRun;
}
}
return null;
}
@ -1150,7 +1156,8 @@ public class SimulationDataRepository {
if (tripPlan != null) {
TrainInfo trainInfo = findSupervisedTrainByTrip(serviceNumber, tripNumber);
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED
.assertNull(trainInfo, String.format("车次计划[%s-%s]已在运行", serviceNumber, tripNumber));
.assertNull(trainInfo,
String.format("车次计划[%s-%s]已在运行", serviceNumber, tripNumber));
invalidList.add(tripPlan);
List<TripPlan> tripPlans = serviceTripsMap.get(serviceNumber);
for (TripPlan plan : tripPlans) {
@ -1158,7 +1165,8 @@ public class SimulationDataRepository {
trainInfo = findSupervisedTrainByTrip(plan.getServiceNumber(), plan.getTripNumber());
BusinessExceptionAssertEnum.OPERATION_NOT_SUPPORTED
.assertNull(trainInfo,
String.format("车次计划[%s-%s]已在运行", plan.getServiceNumber(), plan.getTripNumber()));
String.format("车次计划[%s-%s]已在运行", plan.getServiceNumber(),
plan.getTripNumber()));
invalidList.add(plan);
}
}

View File

@ -49,6 +49,7 @@ import club.joylink.rtss.simulation.cbtc.robot.SimulationRobotService;
import club.joylink.rtss.simulation.cbtc.vo.SimulationWorkParamVO;
import club.joylink.rtss.simulation.rt.iscs.IscsStatusPublisher;
import club.joylink.rtss.simulation.rt.pis.PisStatusPublisher;
import club.joylink.rtss.simulation.rt.train.TrainTmsPublisher;
import club.joylink.rtss.vo.LoginUserInfoVO;
import club.joylink.rtss.vo.client.CommandDefinitionVO;
import club.joylink.rtss.vo.client.iscs.device.IscsDeviceVO;
@ -75,418 +76,438 @@ import org.springframework.util.CollectionUtils;
@Slf4j
@Service
public class MetroSimulationWorkServiceImpl implements SimulationWorkService {
@Autowired
private IMapService iMapService;
@Autowired
private IRunPlanRunlevelService iRunPlanRunlevelService;
@Autowired
private IRunPlanParktimeService iRunPlanParktimeService;
@Autowired
private ICommandService iCommandService;
@Autowired
private SchedulingService schedulingService;
@Autowired
private IRunPlanTemplateService iRunPlanTemplateService;
@Autowired
private ILoadPlanService iLoadPlanService;
@Autowired
private IbpService ibpService;
@Autowired
private IscsDeviceService iscsDeviceService;
@Autowired
private IscsSystemResourcesService iscsSystemResourcesService;
@Autowired
private DeviceStatusService deviceStatusService;
@Autowired
private DepotService depotService;
@Autowired
private TrainTargetUpdateService trainTargetUpdateService;
@Autowired
private IVirtualRealityIbpService iVirtualRealityIbpService;
@Autowired
private PowerSupplyService powerSupplyService;
@Autowired
private IVirtualRealityPslService iVirtualRealityPslService;
@Autowired
private IscsMessageCollectAndDispatcher iscsMessageCollectAndDispatcher;
@Autowired
private IscsLogicLoop iscsLogicLoop;
@Autowired
private PisLogicLoop pisLogicLoop;
@Autowired
private ATPLogicLoop atpLogicLoop;
@Autowired
private ATSLogicLoop atsLogicLoop;
@Autowired
private SimulationRobotService simulationRobotService;
@Autowired
private VRTrainRunningService vrTrainRunningService;
@Autowired
private CiLogic ciLogic;
@Autowired
private VRDeviceLogicLoop vrDeviceLogicLoop;
@Autowired
private ATSMessageCollectAndDispatcher atsMessageCollectAndDispatcher;
@Autowired
private Joylink3DMessageService joylink3DMessageService;
@Autowired
private FaultGenerator faultGenerator;
@Autowired
private SimulationLifeCycleService simulationLifeCycleService;
@Autowired
private ITrainingV1Service iTrainingV1Service;
@Autowired
private PassengerFlowSimulateService passengerFlowSimulateService;
@Autowired
private GroupSimulationService groupSimulationService;
@Autowired
private LargePassengerFlowStrategyService largePassengerFlowStrategyService;
@Autowired
private SimulationWorkServiceManager simulationWorkServiceManager;
@Autowired
private DeviceService deviceService;
@Autowired
private SimulationRealDeviceThread simulationRealDeviceThread;
@Autowired
private UDPRealDeviceThread udpRealDeviceThread;
@Autowired
private ATSTrainMessageDiagram trainMessageDiagram;
@Autowired
private NccAlarmService nccAlarmService;
@Override
public Simulation.Type getType() {
return Simulation.Type.METRO;
@Autowired
private IMapService iMapService;
@Autowired
private IRunPlanRunlevelService iRunPlanRunlevelService;
@Autowired
private IRunPlanParktimeService iRunPlanParktimeService;
@Autowired
private ICommandService iCommandService;
@Autowired
private SchedulingService schedulingService;
@Autowired
private IRunPlanTemplateService iRunPlanTemplateService;
@Autowired
private ILoadPlanService iLoadPlanService;
@Autowired
private IbpService ibpService;
@Autowired
private IscsDeviceService iscsDeviceService;
@Autowired
private IscsSystemResourcesService iscsSystemResourcesService;
@Autowired
private DeviceStatusService deviceStatusService;
@Autowired
private DepotService depotService;
@Autowired
private TrainTargetUpdateService trainTargetUpdateService;
@Autowired
private IVirtualRealityIbpService iVirtualRealityIbpService;
@Autowired
private PowerSupplyService powerSupplyService;
@Autowired
private IVirtualRealityPslService iVirtualRealityPslService;
@Autowired
private IscsMessageCollectAndDispatcher iscsMessageCollectAndDispatcher;
@Autowired
private IscsLogicLoop iscsLogicLoop;
@Autowired
private PisLogicLoop pisLogicLoop;
@Autowired
private ATPLogicLoop atpLogicLoop;
@Autowired
private ATSLogicLoop atsLogicLoop;
@Autowired
private SimulationRobotService simulationRobotService;
@Autowired
private VRTrainRunningService vrTrainRunningService;
@Autowired
private CiLogic ciLogic;
@Autowired
private VRDeviceLogicLoop vrDeviceLogicLoop;
@Autowired
private ATSMessageCollectAndDispatcher atsMessageCollectAndDispatcher;
@Autowired
private Joylink3DMessageService joylink3DMessageService;
@Autowired
private FaultGenerator faultGenerator;
@Autowired
private SimulationLifeCycleService simulationLifeCycleService;
@Autowired
private ITrainingV1Service iTrainingV1Service;
@Autowired
private PassengerFlowSimulateService passengerFlowSimulateService;
@Autowired
private GroupSimulationService groupSimulationService;
@Autowired
private LargePassengerFlowStrategyService largePassengerFlowStrategyService;
@Autowired
private SimulationWorkServiceManager simulationWorkServiceManager;
@Autowired
private DeviceService deviceService;
@Autowired
private SimulationRealDeviceThread simulationRealDeviceThread;
@Autowired
private UDPRealDeviceThread udpRealDeviceThread;
@Autowired
private ATSTrainMessageDiagram trainMessageDiagram;
@Autowired
private NccAlarmService nccAlarmService;
@Override
public Simulation.Type getType() {
return Simulation.Type.METRO;
}
@Override
public Simulation create(long mapId, SimulationWorkParamVO workParamVO,
LoginUserInfoVO loginUserInfoVO, String simulationId) {
checkParam(workParamVO);
SimulationBuildParams params = prepareSimulationParams(mapId, workParamVO, loginUserInfoVO);
Simulation simulation = new Simulation(simulationId);
simulation.setBuildParams(params);
return simulation;
}
@Override
public void loadData(Simulation simulation) {
SimulationBuildParams buildParams = simulation.getBuildParams();
// ibp数据
List<Ibp> ibps = ibpService.queryEntities(buildParams.getMap().getId());
buildParams.getMap().setIbpList(ibps);
// iscs设备
List<IscsDeviceVO> iscsDevices = iscsDeviceService.getListByMapId(buildParams.getMap().getId());
buildParams.getMap().setIscsDeviceList(iscsDevices);
// iscs资源
IscsSystemResourcesQueryVO queryVO = new IscsSystemResourcesQueryVO();
queryVO.setMapId(buildParams.getMap().getId());
List<IscsSystemResourcesVO> resourceList = iscsSystemResourcesService.criteriaQuery(queryVO);
buildParams.getMap().setIscsSystemResourceList(resourceList);
// 加载地图数据
loadMapData(simulation);
// 车辆段
depotService.loadDepotTrain(simulation);
// 添加仿真用户
SimulationUser creator = SimulationUser.buildCreator(simulation,
buildParams.getLoginUserInfo());
simulation.addSimulationUser(creator);
// 添加仿真成员
simulationWorkServiceManager.buildMember(simulation);
// 添加项目设备
if (buildParams.getWorkParamVO().containsRealDeviceItem()) {
simulationWorkServiceManager.loadRealDevices(simulation);
}
}
@Override
public Simulation create(long mapId, SimulationWorkParamVO workParamVO, LoginUserInfoVO loginUserInfoVO, String simulationId) {
checkParam(workParamVO);
SimulationBuildParams params = prepareSimulationParams(mapId, workParamVO, loginUserInfoVO);
Simulation simulation = new Simulation(simulationId);
simulation.setBuildParams(params);
return simulation;
@Override
public void addJobs(Simulation simulation) {
depotService.addJobs(simulation);
trainTargetUpdateService.addJobs(simulation);
iVirtualRealityIbpService.addJobs(simulation);
powerSupplyService.addJobs(simulation);
iVirtualRealityPslService.addJobs(simulation);
iscsMessageCollectAndDispatcher.addJob(simulation);
iscsLogicLoop.addJobs(simulation);
pisLogicLoop.addJobs(simulation);
atpLogicLoop.addJobs(simulation);
atsLogicLoop.addJobs(simulation);
simulationRobotService.addJobs(simulation);
vrTrainRunningService.addJobs(simulation);
vrDeviceLogicLoop.addJobs(simulation);
ciLogic.addJobs(simulation);
joylink3DMessageService.addJobs(simulation);
faultGenerator.addJobs(simulation);
atsMessageCollectAndDispatcher.addJobs(simulation);
nccAlarmService.addJobs(simulation);
trainMessageDiagram.addJobs(simulation);
}
@Override
public void addMessagePublisher(Simulation simulation) {
simulation.addMessagePublisher(new IscsStatusPublisher(simulation));
simulation.addMessagePublisher(new PisStatusPublisher(simulation));
simulation.addMessagePublisher(new TrainTmsPublisher(simulation));
}
@Override
public void init(Simulation simulation) {
// 初始化设备状态
this.reset(simulation);
// 加载仿真可选项
SimulationWorkParamVO workParamVO = simulation.getBuildParams().getWorkParamVO();
Map<SimulationWorkParamVO.Item, String> itemMap = workParamVO.getItemMap();
if (!CollectionUtils.isEmpty(itemMap)) {
loadItem(simulation);
}
}
@Override
public void loadData(Simulation simulation) {
SimulationBuildParams buildParams = simulation.getBuildParams();
// ibp数据
List<Ibp> ibps = ibpService.queryEntities(buildParams.getMap().getId());
buildParams.getMap().setIbpList(ibps);
// iscs设备
List<IscsDeviceVO> iscsDevices = iscsDeviceService.getListByMapId(buildParams.getMap().getId());
buildParams.getMap().setIscsDeviceList(iscsDevices);
// iscs资源
IscsSystemResourcesQueryVO queryVO = new IscsSystemResourcesQueryVO();
queryVO.setMapId(buildParams.getMap().getId());
List<IscsSystemResourcesVO> resourceList = iscsSystemResourcesService.criteriaQuery(queryVO);
buildParams.getMap().setIscsSystemResourceList(resourceList);
// 加载地图数据
loadMapData(simulation);
// 车辆段
depotService.loadDepotTrain(simulation);
// 添加仿真用户
SimulationUser creator = SimulationUser.buildCreator(simulation, buildParams.getLoginUserInfo());
simulation.addSimulationUser(creator);
// 添加仿真成员
simulationWorkServiceManager.buildMember(simulation);
// 添加项目设备
if (buildParams.getWorkParamVO().containsRealDeviceItem()) {
simulationWorkServiceManager.loadRealDevices(simulation);
@Override
public void runAsPlan(Simulation simulation, RunAsPlanParam param) {
SimulationWorkParamVO workParamVO = simulation.getBuildParams().getWorkParamVO();
Map<SimulationWorkParamVO.Item, String> itemMap = workParamVO.getItemMap();
if (!CollectionUtils.isEmpty(itemMap)) {
for (Map.Entry<SimulationWorkParamVO.Item, String> entry : itemMap.entrySet()) {
SimulationWorkParamVO.Item item = entry.getKey();
switch (item) {
case DEFAULT_MEMBER:
break;
case LPF:
boolean initSuccess = passengerFlowSimulateService.initPassengerFlow(simulation);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(initSuccess,
"大客流初始化失败");
largePassengerFlowStrategyService.addJobs(simulation);
break;
case REAL_DEVICE:
break;
case EXAM:
break;
case TRAINING:
break;
default:
throw new IllegalStateException("Unexpected value: " + item);
}
}
}
groupSimulationService.runAsPlan(simulation.getId(), param);
}
@Override
public void addJobs(Simulation simulation) {
depotService.addJobs(simulation);
trainTargetUpdateService.addJobs(simulation);
iVirtualRealityIbpService.addJobs(simulation);
powerSupplyService.addJobs(simulation);
iVirtualRealityPslService.addJobs(simulation);
iscsMessageCollectAndDispatcher.addJob(simulation);
iscsLogicLoop.addJobs(simulation);
pisLogicLoop.addJobs(simulation);
atpLogicLoop.addJobs(simulation);
atsLogicLoop.addJobs(simulation);
simulationRobotService.addJobs(simulation);
vrTrainRunningService.addJobs(simulation);
@Override
public void reset(Simulation simulation) {
simulationLifeCycleService.reset(simulation);
vrDeviceLogicLoop.addJobs(simulation);
ciLogic.addJobs(simulation);
joylink3DMessageService.addJobs(simulation);
faultGenerator.addJobs(simulation);
atsMessageCollectAndDispatcher.addJobs(simulation);
nccAlarmService.addJobs(simulation);
trainMessageDiagram.addJobs(simulation);
}
@Override
public void addMessagePublisher(Simulation simulation) {
simulation.addMessagePublisher(new IscsStatusPublisher(simulation));
simulation.addMessagePublisher(new PisStatusPublisher(simulation));
}
@Override
public void init(Simulation simulation) {
// 初始化设备状态
this.reset(simulation);
// 加载仿真可选项
SimulationWorkParamVO workParamVO = simulation.getBuildParams().getWorkParamVO();
Map<SimulationWorkParamVO.Item, String> itemMap = workParamVO.getItemMap();
if (!CollectionUtils.isEmpty(itemMap)) {
loadItem(simulation);
SimulationWorkParamVO workParamVO = simulation.getBuildParams().getWorkParamVO();
Map<SimulationWorkParamVO.Item, String> itemMap = workParamVO.getItemMap();
if (!CollectionUtils.isEmpty(itemMap)) {
for (Map.Entry<SimulationWorkParamVO.Item, String> entry : itemMap.entrySet()) {
SimulationWorkParamVO.Item item = entry.getKey();
switch (item) {
case DEFAULT_MEMBER:
break;
case LPF:
passengerFlowSimulateService.simulationReset(simulation);
largePassengerFlowStrategyService.removeJobs(simulation);
break;
case REAL_DEVICE:
break;
case TRAINING:
break;
case EXAM:
break;
default:
throw new IllegalStateException("Unexpected value: " + item);
}
}
}
}
@Override
public void runAsPlan(Simulation simulation, RunAsPlanParam param) {
SimulationWorkParamVO workParamVO = simulation.getBuildParams().getWorkParamVO();
Map<SimulationWorkParamVO.Item, String> itemMap = workParamVO.getItemMap();
if (!CollectionUtils.isEmpty(itemMap)) {
for (Map.Entry<SimulationWorkParamVO.Item, String> entry : itemMap.entrySet()) {
SimulationWorkParamVO.Item item = entry.getKey();
switch (item) {
case DEFAULT_MEMBER:
break;
case LPF:
boolean initSuccess = passengerFlowSimulateService.initPassengerFlow(simulation);
BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertTrue(initSuccess, "大客流初始化失败");
largePassengerFlowStrategyService.addJobs(simulation);
break;
case REAL_DEVICE:
break;
case EXAM:
break;
case TRAINING:
break;
default:
throw new IllegalStateException("Unexpected value: " + item);
}
}
}
groupSimulationService.runAsPlan(simulation.getId(), param);
}
@Override
public void reset(Simulation simulation) {
simulationLifeCycleService.reset(simulation);
SimulationWorkParamVO workParamVO = simulation.getBuildParams().getWorkParamVO();
Map<SimulationWorkParamVO.Item, String> itemMap = workParamVO.getItemMap();
if (!CollectionUtils.isEmpty(itemMap)) {
for (Map.Entry<SimulationWorkParamVO.Item, String> entry : itemMap.entrySet()) {
SimulationWorkParamVO.Item item = entry.getKey();
switch (item) {
case DEFAULT_MEMBER:
break;
case LPF:
passengerFlowSimulateService.simulationReset(simulation);
largePassengerFlowStrategyService.removeJobs(simulation);
break;
case REAL_DEVICE:
break;
case TRAINING:
break;
case EXAM:
break;
default:
throw new IllegalStateException("Unexpected value: " + item);
}
}
}
}
@Override
public void addItems(Simulation simulation, Map<SimulationWorkParamVO.Item, String> itemMap) {
itemMap.forEach((item, param) -> {
switch (item) {
case DEFAULT_MEMBER:
break;
case LPF: //目前大客流的任务在按计划行车时增加
break;
case REAL_DEVICE:
break;
case TRAINING:
@Override
public void addItems(Simulation simulation, Map<SimulationWorkParamVO.Item, String> itemMap) {
itemMap.forEach((item, param) -> {
switch (item) {
case DEFAULT_MEMBER:
break;
case LPF: //目前大客流的任务在按计划行车时增加
break;
case REAL_DEVICE:
break;
case TRAINING:
// BusinessExceptionAssertEnum.SYSTEM_EXCEPTION.assertNotNull(param, "参数不能为空");
// Long trainingId = Long.valueOf(param);
// iTrainingV1Service.loadTraining(simulation.getId(), trainingId, loginInfo.getAccountVO());
break;
case EXAM:
break;
default:
throw new IllegalStateException("Unexpected value: " + item);
}
});
simulation.getBuildParams().getWorkParamVO().addItemMap(itemMap);
}
break;
case EXAM:
break;
default:
throw new IllegalStateException("Unexpected value: " + item);
}
});
simulation.getBuildParams().getWorkParamVO().addItemMap(itemMap);
}
@Override
public void removeFunctions(Simulation simulation, Collection<SimulationWorkParamVO.Item> items) {
simulation.getBuildParams().getWorkParamVO().removeItems(items);
}
@Override
public void removeFunctions(Simulation simulation, Collection<SimulationWorkParamVO.Item> items) {
simulation.getBuildParams().getWorkParamVO().removeItems(items);
}
/**
* 加载地图设备及联锁数据
*/
private void loadMapData(Simulation simulation) {
SimulationBuildParams buildParams = simulation.getBuildParams();
simulation.setBuildParams(buildParams);
if (Objects.nonNull(buildParams.getLoginUserInfo())) {
simulation.setCreatorId(buildParams.getLoginUserInfo().getAccountVO().getIdStr());
simulation.setProject(buildParams.getLoginUserInfo().getProject());
simulation.setProjectVO(buildParams.getLoginUserInfo().getProjectInfo());
/**
* 加载地图设备及联锁数据
*/
private void loadMapData(Simulation simulation) {
SimulationBuildParams buildParams = simulation.getBuildParams();
simulation.setBuildParams(buildParams);
if (Objects.nonNull(buildParams.getLoginUserInfo())) {
simulation.setCreatorId(buildParams.getLoginUserInfo().getAccountVO().getIdStr());
simulation.setProject(buildParams.getLoginUserInfo().getProject());
simulation.setProjectVO(buildParams.getLoginUserInfo().getProjectInfo());
}
// 线路配置参数
simulation.getRepository()
.setConfig(SimulationBuilder.buildConfig(buildParams.getMap().getConfigVO(),
buildParams.getMap().getGraphDataNew().getMapFunctionConfig()));
simulation.getRepository().getConfig()
.setRouteLikeHa1(buildParams.getMap().getGraphDataNew().getGenerateConfig().isLikeHa1());
simulation.getRepository().getConfig()
.setOverlapSettingByTrigger(
buildParams.getMap().getGraphDataNew().getGenerateConfig().isOverlapSettingByTrigger());
simulation.getRepository().getConfig()
.setSharingECStations(
buildParams.getMap().getGraphDataNew().getGenerateConfig().getSharingECStations());
simulation.getRepository().getConfig()
.setHandleDepot(buildParams.getMap().getGraphDataNew().getGenerateConfig().isHandleDepot());
// 地图数据构建
SimulationBuilder.SimulationDeviceBuildResult mapDataBuildResult = SimulationBuilder.checkAndBuildMapData(
buildParams.getMap());
// ibp数据构建
SimulationBuilder.buildIbpData(mapDataBuildResult, buildParams.getMap().getIbpList());
// iscs设备构建
SimulationBuilder.buildIscsDevices(mapDataBuildResult,
buildParams.getMap().getIscsDeviceList());
simulation.getRepository().setDeviceMap(mapDataBuildResult.getDeviceMap());
simulation.getRepository()
.setSectionArriveNearMap(mapDataBuildResult.getSectionArriveNearMap());
simulation.getRepository().setVrDeviceMap(mapDataBuildResult.getVrDeviceMap());
simulation.getRepository().setRoutePathMap(mapDataBuildResult.getRoutePathMap());
simulation.getRepository().setDestinationMap(mapDataBuildResult.getDestinationMap());
simulation.getRepository().setRoutingList(mapDataBuildResult.getRoutingList());
simulation.getRepository().getCatenaryMap().putAll(mapDataBuildResult.getCatenaryMap());
simulation.getRepository().getSectionRespondersMap()
.putAll(mapDataBuildResult.getSectionRespondersMap());
simulation.getRepository().setParkingTracksMap(mapDataBuildResult.getParkingTracksMap());
UserConfigDataBuilder.buildRunLevel(simulation.getRepository(),
buildParams.getUserRunLevelList(),
buildParams.getMap(), mapDataBuildResult.getErrMsgList());
UserConfigDataBuilder.buildParkTime(simulation.getRepository(),
buildParams.getUserParkTimeList(),
buildParams.getMap(), mapDataBuildResult.getErrMsgList());
if (!CollectionUtils.isEmpty(mapDataBuildResult.getErrMsgList())) { // 存在数据异常
mapDataBuildResult.getErrMsgList()
.forEach(errMsg -> log.warn(String.format("地图数据异常:%s", errMsg)));
simulation.setMapDataError(true);
simulation.addDataErrMsgs(mapDataBuildResult.getErrMsgList());
}
// 加载ISCS资源
SimulationBuilder.loadIscsResources(simulation,
buildParams.getMap().getIscsSystemResourceList());
// 加载运行图
SimulationBuilder.checkAndLoadRunPlan(simulation, buildParams.getRunPlan());
// 加载派班计划
SimulationBuilder.checkAndLoadSchedulingPlan(simulation, buildParams.getSchedulingPlan());
// 加载车辆段route path
SimulationBuilder.loadDepotInOutRoutePath(simulation);
}
private SimulationBuildParams prepareSimulationParams(long mapId,
SimulationWorkParamVO workParamVO, LoginUserInfoVO loginUserInfoVO) {
// 获取地图数据
MapVO mapVO = iMapService.getMapDetail(mapId);
List<RunPlanRunlevelVO> runLevelList = this.prepareRunLevelData(loginUserInfoVO, mapId);
List<RunPlanParkingTimeVO> parkTimeList = this.prepareParkTimeData(loginUserInfoVO, mapId);
// 获取操作定义数据
List<CommandDefinitionVO> operationDefinitionList = iCommandService
.queryDefinitionsByLineCode(mapVO.getLineCode());
SimulationBuildParams.SimulationBuildParamsBuilder builder = SimulationBuildParams.builder();
// 都有的属性构造
builder.loginUserInfo(loginUserInfoVO)
.workParamVO(workParamVO)
.createTime(LocalDateTime.now())
.map(mapVO)
.userRunLevelList(runLevelList)
.userParkTimeList(parkTimeList)
.operationDefinitionList(operationDefinitionList);
//运行图选择性构造
LocalDate runPlanDate = SimulationConstants.getRunPlanDate();
RunPlanVO runPlanVO = findRunPlan(workParamVO, loginUserInfoVO.getAccountVO().getId(), mapId);
if (Objects.nonNull(runPlanVO)) {
runPlanVO.setRunDate(runPlanDate);
builder.runPlan(runPlanVO);
SchedulingPlanNewVO schedulingPlanNewVO;
if (loginUserInfoVO.isProjectDeviceLogin()) { // 如果是项目设备登录找通用日期的派班计划
schedulingPlanNewVO = schedulingService.queryCommonSchedulingPlanOfDay(mapId, runPlanDate);
} else {
schedulingPlanNewVO = schedulingService
.querySchedulingPlanUserFirst(loginUserInfoVO.getAccountVO().getId(), runPlanVO.getId(),
runPlanDate);
}
builder.schedulingPlan(schedulingPlanNewVO);
}
return builder.build();
}
private RunPlanVO findRunPlan(SimulationWorkParamVO createParamVO, Long userId, long mapId) {
LocalDate runPlanDate = SimulationConstants.getRunPlanDate();
RunPlanLoadVO loadPlan = null;
Simulation.Type type = createParamVO.getType();
if (Simulation.Type.METRO == type) {
Map<SimulationWorkParamVO.Item, String> itemMap = createParamVO.getItemMap();
if (CollectionUtils.isEmpty(itemMap)) {
//优先使用用户的运行图
loadPlan = iLoadPlanService.findUserLoadPlan(userId, mapId, runPlanDate);
if (loadPlan == null) {
loadPlan = iLoadPlanService.findCommonLoadPlanOfMap(mapId);
}
// 线路配置参数
simulation.getRepository().setConfig(SimulationBuilder.buildConfig(buildParams.getMap().getConfigVO(),
buildParams.getMap().getGraphDataNew().getMapFunctionConfig()));
simulation.getRepository().getConfig()
.setRouteLikeHa1(buildParams.getMap().getGraphDataNew().getGenerateConfig().isLikeHa1());
simulation.getRepository().getConfig()
.setOverlapSettingByTrigger(buildParams.getMap().getGraphDataNew().getGenerateConfig().isOverlapSettingByTrigger());
simulation.getRepository().getConfig()
.setSharingECStations(buildParams.getMap().getGraphDataNew().getGenerateConfig().getSharingECStations());
simulation.getRepository().getConfig()
.setHandleDepot(buildParams.getMap().getGraphDataNew().getGenerateConfig().isHandleDepot());
// 地图数据构建
SimulationBuilder.SimulationDeviceBuildResult mapDataBuildResult = SimulationBuilder.checkAndBuildMapData(buildParams.getMap());
// ibp数据构建
SimulationBuilder.buildIbpData(mapDataBuildResult, buildParams.getMap().getIbpList());
// iscs设备构建
SimulationBuilder.buildIscsDevices(mapDataBuildResult, buildParams.getMap().getIscsDeviceList());
simulation.getRepository().setDeviceMap(mapDataBuildResult.getDeviceMap());
simulation.getRepository().setSectionArriveNearMap(mapDataBuildResult.getSectionArriveNearMap());
simulation.getRepository().setVrDeviceMap(mapDataBuildResult.getVrDeviceMap());
simulation.getRepository().setRoutePathMap(mapDataBuildResult.getRoutePathMap());
simulation.getRepository().setDestinationMap(mapDataBuildResult.getDestinationMap());
simulation.getRepository().setRoutingList(mapDataBuildResult.getRoutingList());
simulation.getRepository().getCatenaryMap().putAll(mapDataBuildResult.getCatenaryMap());
simulation.getRepository().getSectionRespondersMap().putAll(mapDataBuildResult.getSectionRespondersMap());
simulation.getRepository().setParkingTracksMap(mapDataBuildResult.getParkingTracksMap());
UserConfigDataBuilder.buildRunLevel(simulation.getRepository(), buildParams.getUserRunLevelList(),
buildParams.getMap(), mapDataBuildResult.getErrMsgList());
UserConfigDataBuilder.buildParkTime(simulation.getRepository(), buildParams.getUserParkTimeList(),
buildParams.getMap(), mapDataBuildResult.getErrMsgList());
if (!CollectionUtils.isEmpty(mapDataBuildResult.getErrMsgList())) { // 存在数据异常
mapDataBuildResult.getErrMsgList().forEach(errMsg -> log.warn(String.format("地图数据异常:%s", errMsg)));
simulation.setMapDataError(true);
simulation.addDataErrMsgs(mapDataBuildResult.getErrMsgList());
} else {
for (Map.Entry<SimulationWorkParamVO.Item, String> entry : itemMap.entrySet()) {
SimulationWorkParamVO.Item item = entry.getKey();
switch (item) {
case DEFAULT_MEMBER:
case LPF:
case REAL_DEVICE:
//优先使用用户的运行图
loadPlan = iLoadPlanService.findUserLoadPlan(userId, mapId, runPlanDate);
if (loadPlan == null) {
loadPlan = iLoadPlanService.findCommonLoadPlanOfMap(mapId);
}
break;
case TRAINING:
case EXAM:
//实训考试先不加载运行图
break;
default:
throw new IllegalStateException("Unexpected value: " + item);
}
}
// 加载ISCS资源
SimulationBuilder.loadIscsResources(simulation, buildParams.getMap().getIscsSystemResourceList());
// 加载运行图
SimulationBuilder.checkAndLoadRunPlan(simulation, buildParams.getRunPlan());
// 加载派班计划
SimulationBuilder.checkAndLoadSchedulingPlan(simulation, buildParams.getSchedulingPlan());
// 加载车辆段route path
SimulationBuilder.loadDepotInOutRoutePath(simulation);
}
}
if (loadPlan != null) {
return iRunPlanTemplateService.getRunPlan(loadPlan.getTemplatePlanId());
}
return null;
}
private SimulationBuildParams prepareSimulationParams(long mapId, SimulationWorkParamVO workParamVO, LoginUserInfoVO loginUserInfoVO) {
// 获取地图数据
MapVO mapVO = iMapService.getMapDetail(mapId);
List<RunPlanRunlevelVO> runLevelList = this.prepareRunLevelData(loginUserInfoVO, mapId);
List<RunPlanParkingTimeVO> parkTimeList = this.prepareParkTimeData(loginUserInfoVO, mapId);
// 获取操作定义数据
List<CommandDefinitionVO> operationDefinitionList = iCommandService
.queryDefinitionsByLineCode(mapVO.getLineCode());
SimulationBuildParams.SimulationBuildParamsBuilder builder = SimulationBuildParams.builder();
// 都有的属性构造
builder.loginUserInfo(loginUserInfoVO)
.workParamVO(workParamVO)
.createTime(LocalDateTime.now())
.map(mapVO)
.userRunLevelList(runLevelList)
.userParkTimeList(parkTimeList)
.operationDefinitionList(operationDefinitionList);
//运行图选择性构造
LocalDate runPlanDate = SimulationConstants.getRunPlanDate();
RunPlanVO runPlanVO = findRunPlan(workParamVO, loginUserInfoVO.getAccountVO().getId(), mapId);
if (Objects.nonNull(runPlanVO)) {
runPlanVO.setRunDate(runPlanDate);
builder.runPlan(runPlanVO);
SchedulingPlanNewVO schedulingPlanNewVO;
if (loginUserInfoVO.isProjectDeviceLogin()) { // 如果是项目设备登录找通用日期的派班计划
schedulingPlanNewVO = schedulingService.queryCommonSchedulingPlanOfDay(mapId, runPlanDate);
} else {
schedulingPlanNewVO = schedulingService
.querySchedulingPlanUserFirst(loginUserInfoVO.getAccountVO().getId(), runPlanVO.getId(), runPlanDate);
}
builder.schedulingPlan(schedulingPlanNewVO);
}
return builder.build();
}
private List<RunPlanParkingTimeVO> prepareParkTimeData(LoginUserInfoVO loginUserInfoVO,
long mapId) {
return iRunPlanParktimeService.queryUserParktimes(loginUserInfoVO.getAccountVO().getId(),
mapId);
}
private RunPlanVO findRunPlan(SimulationWorkParamVO createParamVO, Long userId, long mapId) {
LocalDate runPlanDate = SimulationConstants.getRunPlanDate();
RunPlanLoadVO loadPlan = null;
Simulation.Type type = createParamVO.getType();
if (Simulation.Type.METRO == type) {
Map<SimulationWorkParamVO.Item, String> itemMap = createParamVO.getItemMap();
if (CollectionUtils.isEmpty(itemMap)) {
//优先使用用户的运行图
loadPlan = iLoadPlanService.findUserLoadPlan(userId, mapId, runPlanDate);
if (loadPlan == null) {
loadPlan = iLoadPlanService.findCommonLoadPlanOfMap(mapId);
}
} else {
for (Map.Entry<SimulationWorkParamVO.Item, String> entry : itemMap.entrySet()) {
SimulationWorkParamVO.Item item = entry.getKey();
switch (item) {
case DEFAULT_MEMBER:
case LPF:
case REAL_DEVICE:
//优先使用用户的运行图
loadPlan = iLoadPlanService.findUserLoadPlan(userId, mapId, runPlanDate);
if (loadPlan == null) {
loadPlan = iLoadPlanService.findCommonLoadPlanOfMap(mapId);
}
break;
case TRAINING:
case EXAM:
//实训考试先不加载运行图
break;
default:
throw new IllegalStateException("Unexpected value: " + item);
}
}
}
}
if (loadPlan != null) {
return iRunPlanTemplateService.getRunPlan(loadPlan.getTemplatePlanId());
}
return null;
}
private List<RunPlanRunlevelVO> prepareRunLevelData(LoginUserInfoVO loginUserInfoVO, long mapId) {
return iRunPlanRunlevelService.queryUserRunLevels(loginUserInfoVO.getAccountVO().getId(),
mapId);
}
private List<RunPlanParkingTimeVO> prepareParkTimeData(LoginUserInfoVO loginUserInfoVO, long mapId) {
return iRunPlanParktimeService.queryUserParktimes(loginUserInfoVO.getAccountVO().getId(), mapId);
}
private List<RunPlanRunlevelVO> prepareRunLevelData(LoginUserInfoVO loginUserInfoVO, long mapId) {
return iRunPlanRunlevelService.queryUserRunLevels(loginUserInfoVO.getAccountVO().getId(), mapId);
}
private void loadItem(Simulation simulation) {
SimulationWorkParamVO workParamVO = simulation.getBuildParams().getWorkParamVO();
Map<SimulationWorkParamVO.Item, String> itemMap = workParamVO.getItemMap();
itemMap.forEach((k, v) -> {
switch (k) {
case DEFAULT_MEMBER:
simulationWorkServiceManager.playMember(simulation, v);
break;
case LPF:
break;
case REAL_DEVICE:
break;
case TRAINING:
break;
case EXAM:
break;
default:
throw new IllegalStateException("Unexpected value: " + k);
}
});
}
private void loadItem(Simulation simulation) {
SimulationWorkParamVO workParamVO = simulation.getBuildParams().getWorkParamVO();
Map<SimulationWorkParamVO.Item, String> itemMap = workParamVO.getItemMap();
itemMap.forEach((k, v) -> {
switch (k) {
case DEFAULT_MEMBER:
simulationWorkServiceManager.playMember(simulation, v);
break;
case LPF:
break;
case REAL_DEVICE:
break;
case TRAINING:
break;
case EXAM:
break;
default:
throw new IllegalStateException("Unexpected value: " + k);
}
});
}
}

View File

@ -3,7 +3,6 @@ package club.joylink.rtss.simulation.rt.TL;
import club.joylink.rtss.simulation.Simulation;
import club.joylink.rtss.simulation.SimulationScheduleMessagePublisher;
import club.joylink.rtss.simulation.rt.TL.bo.TlTrain;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
@ -11,36 +10,46 @@ import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class TlHmiMessagePublisher extends SimulationScheduleMessagePublisher {
public static final String NAME = "TlHmiMP";
public static final int RATE = 1000;
public static final String DESTINATION = String.format("%s%s", Simulation.MESSAGE_SUB_PREFIX, "/train/{trainId}/Hmi");
Map<String, List<Object>> hmiMap = new ConcurrentHashMap<>();
public static final String NAME = "TlHmiMP";
public static final int RATE = 1000;
public TlHmiMessagePublisher(List<TlTrain> tlTrainList) {
super(NAME, RATE, true, Arrays.asList(DESTINATION));
for (TlTrain train : tlTrainList) {
hmiMap.put(train.getId(), train.getStateList());
}
public static final String HMI_PATH = "Hmi";
public static final String DESTINATION = String.format("%s/%s/%s", Simulation.MESSAGE_SUB_PREFIX,
"train/{trainId}", HMI_PATH);
public static final String TMS_PATH = "tmsPage";
//三维界面左下角仪表盘需要的信息
public static final String SUB_HMI_PATTERN = String.format("%s/%s/%s",
Simulation.MESSAGE_SUB_PREFIX, "train/{trainId}", TMS_PATH);
Map<String, List<Object>> hmiMap = new ConcurrentHashMap<>();
public TlHmiMessagePublisher(List<TlTrain> tlTrainList) {
super(NAME, RATE, true, Arrays.asList(DESTINATION, SUB_HMI_PATTERN));
for (TlTrain train : tlTrainList) {
hmiMap.put(train.getId(), train.getStateList());
}
}
@Override
public boolean isValidParams(List<String> params) {
return this.hmiMap.containsKey(params.get(1));
}
@Override
public boolean isValidParams(List<String> params) {
return this.hmiMap.containsKey(params.get(1));
}
@Override
public Object buildNextSendMessage(String destination) {
Map<String, List<String>> destinationParamsMap = this.getDestinationParamsMap();
List<String> params = destinationParamsMap.get(destination);
String trainId = params.get(1);
Map<String, List<Object>> map = new HashMap<>();
map.putIfAbsent("hmi", this.hmiMap.get(trainId));
return map;
}
@Override
public Object buildNextSendMessage(String destination) {
Map<String, List<String>> destinationParamsMap = this.getDestinationParamsMap();
List<String> params = destinationParamsMap.get(destination);
String trainId = params.get(1);
Map<String, List<Object>> map = new HashMap<>();
map.putIfAbsent("hmi", this.hmiMap.get(trainId));
return map;
}
@Override
public Object buildMessageOfSubscribe(String destination) {
return this.buildNextSendMessage(destination);
}
@Override
public Object buildMessageOfSubscribe(String destination) {
return this.buildNextSendMessage(destination);
}
}

View File

@ -5,131 +5,149 @@ import club.joylink.rtss.simulation.Simulation;
import club.joylink.rtss.simulation.SimulationTriggerMessagePublisher;
import club.joylink.rtss.simulation.Watchable;
import club.joylink.rtss.simulation.cbtc.data.SimulationIscsDataRepository;
import club.joylink.rtss.simulation.cbtc.data.vo.iscs.*;
import club.joylink.rtss.simulation.cbtc.data.vo.iscs.IscsAudioStatusVO;
import club.joylink.rtss.simulation.cbtc.data.vo.iscs.IscsIbpStatusVO;
import club.joylink.rtss.simulation.cbtc.data.vo.iscs.IscsPsdStatusVO;
import club.joylink.rtss.simulation.cbtc.data.vo.iscs.IscsPslStatusVO;
import club.joylink.rtss.simulation.cbtc.data.vo.iscs.IscsStatusVO;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import lombok.NonNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import java.util.*;
import java.util.stream.Collectors;
@Slf4j
public class IscsStatusPublisher extends SimulationTriggerMessagePublisher {
public static final String NAME = "iscs";
public static final String PSD_PATH = "psd";
public static final String PSD_PATTERN = String.format("%s/%s/%s/%s", Simulation.MESSAGE_SUB_PREFIX, "iscs", PSD_PATH, "{stationCode}");
public static final String PA_PATH = "pa";
public static final String PA_PATTERN = String.format("%s/%s/%s", Simulation.MESSAGE_SUB_PREFIX, "iscs", PA_PATH);
public static final String PIS_PATH = "pis";
public static final String PIS_PATTERN = String.format("%s/%s/%s", Simulation.MESSAGE_SUB_PREFIX, "iscs", PIS_PATH);
public static final String GATE_PATH = "gate";
public static final String GATE_PATTERN = String.format("%s/%s/%s/%s", Simulation.MESSAGE_SUB_PREFIX, "iscs", GATE_PATH, "{stationCode}");
club.joylink.rtss.simulation.cbtc.Simulation simulation;
public IscsStatusPublisher(club.joylink.rtss.simulation.cbtc.Simulation simulation) {
super(NAME, Arrays.asList(PSD_PATTERN, PA_PATTERN, PIS_PATTERN, GATE_PATTERN));
this.simulation = simulation;
public static final String NAME = "iscs";
public static final String PSD_PATH = "psd";
public static final String PSD_PATTERN = String.format("%s/%s/%s/%s",
Simulation.MESSAGE_SUB_PREFIX, "iscs", PSD_PATH, "{stationCode}");
public static final String PA_PATH = "pa";
public static final String PA_PATTERN = String.format("%s/%s/%s", Simulation.MESSAGE_SUB_PREFIX,
"iscs", PA_PATH);
public static final String PIS_PATH = "pis";
public static final String PIS_PATTERN = String.format("%s/%s/%s", Simulation.MESSAGE_SUB_PREFIX,
"iscs", PIS_PATH);
public static final String GATE_PATH = "gate";
public static final String GATE_PATTERN = String.format("%s/%s/%s/%s",
Simulation.MESSAGE_SUB_PREFIX, "iscs", GATE_PATH, "{stationCode}");
club.joylink.rtss.simulation.cbtc.Simulation simulation;
public IscsStatusPublisher(club.joylink.rtss.simulation.cbtc.Simulation simulation) {
super(NAME, Arrays.asList(PSD_PATTERN, PA_PATTERN, PIS_PATTERN, GATE_PATTERN));
this.simulation = simulation;
}
@Override
public Object buildMessageOfSubscribe(String destination) {
List<String> list = this.getDestinationParamsMap().get(destination);
Object result = null;
if (destination.contains(PSD_PATH)) {
String s = list.get(1);
result = buildPsdMessage(s);
} else if (destination.contains(PA_PATH)) {
result = buildPaMessage();
} else if (destination.contains(PIS_PATH)) {
result = buildPisMessage();
} else if (destination.contains(GATE_PATH)) {
String s = list.get(1);
result = buildGateMessage(s);
}
return result;
}
@Override
public Object buildMessageOfSubscribe(String destination) {
List<String> list = this.getDestinationParamsMap().get(destination);
Object result = null;
if (destination.contains(PSD_PATH)) {
String s = list.get(1);
result = buildPsdMessage(s);
} else if (destination.contains(PA_PATH)) {
result = buildPaMessage();
} else if (destination.contains(PIS_PATH)) {
result = buildPisMessage();
} else if (destination.contains(GATE_PATH)) {
String s = list.get(1);
result = buildGateMessage(s);
@Override
public List<String> getNeedBuildDestination(@NonNull Watchable watchable) {
List<String> list = new ArrayList<>();
for (Map.Entry<String, List<String>> entry : this.getDestinationParamsMap().entrySet()) {
String destination = entry.getKey();
List<String> param = entry.getValue();
if (destination.contains(PSD_PATH) || destination.contains(GATE_PATH)) {
if (CollectionUtils.isEmpty(param) || param.size() < 2) {
log.error("iscs系统屏蔽门和闸机的订阅路径中参数数量不足");
} else {
if (Objects.equals(((IscsStatusVO) watchable).getStationCode(), param.get(1))) {
list.add(destination);
}
}
return result;
}
private Object buildGateMessage(String stationCode) {
SimulationIscsDataRepository iscsRepository = simulation.getIscsRepository();
List<IscsStatusVO> collect = iscsRepository.getStatusStream(IscsStatusVO.DeviceType.GATE, stationCode).collect(Collectors.toList());
return collect;
}
private Object buildPaMessage() {
List<IscsStatusVO> audioStatus = simulation.getIscsRepository().getStatusByDeviceType(IscsStatusVO.DeviceType.AUDIO);
audioStatus = audioStatus.stream()
.filter(vo -> Objects.equals(IscsSystem.PA, ((IscsAudioStatusVO) vo).getSystem()))
.collect(Collectors.toList());
return audioStatus;
}
private Object buildPisMessage() {
List<IscsStatusVO> audioStatus = simulation.getIscsRepository().getStatusByDeviceType(IscsStatusVO.DeviceType.AUDIO);
audioStatus = audioStatus.stream()
.filter(vo -> Objects.equals(IscsSystem.PIS, ((IscsAudioStatusVO) vo).getSystem()))
.collect(Collectors.toList());
return audioStatus;
}
private List<IscsStatusVO> buildPsdMessage(String stationCode) {
SimulationIscsDataRepository iscsRepository = simulation.getIscsRepository();
Collection<IscsStatusVO> allStatus = iscsRepository.getAllStatus();
List<IscsStatusVO> collect = allStatus.stream()
.filter(status -> {
return status.getStationCode().equals(stationCode)
&& (IscsStatusVO.DeviceType.PSL.equals(status.getDeviceType())
|| IscsStatusVO.DeviceType.SLIDING_DOOR.equals(status.getDeviceType())
|| IscsStatusVO.DeviceType.IBP.equals(status.getDeviceType()));
})
.collect(Collectors.toList());
if (collect.isEmpty()) {
collect.add(new IscsPsdStatusVO("", stationCode, new IscsPsdStatusVO.DirectionalStatus(),
new IscsPsdStatusVO.DirectionalStatus()));
collect.add(new IscsPslStatusVO("", stationCode, new IscsPslStatusVO.DirectionalStatus(),
new IscsPslStatusVO.DirectionalStatus()));
collect.add(new IscsIbpStatusVO("", stationCode, new IscsIbpStatusVO.DirectionalStatus(),
new IscsIbpStatusVO.DirectionalStatus()));
} else {
if (watchable instanceof IscsAudioStatusVO) {
IscsAudioStatusVO audioStatusVO = (IscsAudioStatusVO) watchable;
if (audioStatusVO.isPaSystem() && destination.contains(PA_PATH)) {
list.add(destination);
} else if (audioStatusVO.isPisSystem() && destination.contains(PIS_PATH)) {
list.add(destination);
}
} else {
log.error("iscs消息出现未知情况");
}
return collect;
}
}
return list;
}
@Override
public List<String> getNeedBuildDestination(@NonNull Watchable watchable) {
List<String> list = new ArrayList<>();
for (Map.Entry<String, List<String>> entry : this.getDestinationParamsMap().entrySet()) {
String destination = entry.getKey();
List<String> param = entry.getValue();
if (destination.contains(PSD_PATH) || destination.contains(GATE_PATH)) {
if (CollectionUtils.isEmpty(param) || param.size() < 2) {
log.error("iscs系统屏蔽门和闸机的订阅路径中参数数量不足");
} else {
if (Objects.equals(((IscsStatusVO) watchable).getStationCode(), param.get(1))) {
list.add(destination);
}
}
} else {
if (watchable instanceof IscsAudioStatusVO) {
IscsAudioStatusVO audioStatusVO = (IscsAudioStatusVO) watchable;
if (audioStatusVO.isPaSystem() && destination.contains(PA_PATH)) {
list.add(destination);
} else if (audioStatusVO.isPisSystem() && destination.contains(PIS_PATH)) {
list.add(destination);
}
} else {
log.error("iscs消息出现未知情况");
}
}
}
return list;
}
@Override
public Object buildMessage(Watchable watchable) {
return Collections.singletonList(watchable);
}
@Override
public Object buildMessage(Watchable watchable) {
return Collections.singletonList(watchable);
}
@Override
public Object buildMessage(Watchable watchable, String field, Object val) {
return buildMessage(watchable);
}
@Override
public Object buildMessage(Watchable watchable, String field, Object val) {
return buildMessage(watchable);
private Object buildGateMessage(String stationCode) {
SimulationIscsDataRepository iscsRepository = simulation.getIscsRepository();
List<IscsStatusVO> collect = iscsRepository.getStatusStream(IscsStatusVO.DeviceType.GATE,
stationCode).collect(Collectors.toList());
return collect;
}
private Object buildPaMessage() {
List<IscsStatusVO> audioStatus = simulation.getIscsRepository()
.getStatusByDeviceType(IscsStatusVO.DeviceType.AUDIO);
audioStatus = audioStatus.stream()
.filter(vo -> Objects.equals(IscsSystem.PA, ((IscsAudioStatusVO) vo).getSystem()))
.collect(Collectors.toList());
return audioStatus;
}
private Object buildPisMessage() {
List<IscsStatusVO> audioStatus = simulation.getIscsRepository()
.getStatusByDeviceType(IscsStatusVO.DeviceType.AUDIO);
audioStatus = audioStatus.stream()
.filter(vo -> Objects.equals(IscsSystem.PIS, ((IscsAudioStatusVO) vo).getSystem()))
.collect(Collectors.toList());
return audioStatus;
}
private List<IscsStatusVO> buildPsdMessage(String stationCode) {
SimulationIscsDataRepository iscsRepository = simulation.getIscsRepository();
Collection<IscsStatusVO> allStatus = iscsRepository.getAllStatus();
List<IscsStatusVO> collect = allStatus.stream()
.filter(status -> {
return status.getStationCode().equals(stationCode)
&& (IscsStatusVO.DeviceType.PSL.equals(status.getDeviceType())
|| IscsStatusVO.DeviceType.SLIDING_DOOR.equals(status.getDeviceType())
|| IscsStatusVO.DeviceType.IBP.equals(status.getDeviceType()));
})
.collect(Collectors.toList());
if (collect.isEmpty()) {
collect.add(new IscsPsdStatusVO("", stationCode, new IscsPsdStatusVO.DirectionalStatus(),
new IscsPsdStatusVO.DirectionalStatus()));
collect.add(new IscsPslStatusVO("", stationCode, new IscsPslStatusVO.DirectionalStatus(),
new IscsPslStatusVO.DirectionalStatus()));
collect.add(new IscsIbpStatusVO("", stationCode, new IscsIbpStatusVO.DirectionalStatus(),
new IscsIbpStatusVO.DirectionalStatus()));
}
return collect;
}
}

View File

@ -0,0 +1,77 @@
package club.joylink.rtss.simulation.rt.train;
import club.joylink.rtss.simulation.SimulationScheduleMessagePublisher;
import club.joylink.rtss.simulation.cbtc.Simulation;
import club.joylink.rtss.simulation.cbtc.communication.vo.TrainTmsDisplay;
import club.joylink.rtss.simulation.cbtc.data.vr.VirtualRealityTrain;
import java.util.List;
import java.util.Map;
public class TrainTmsPublisher extends SimulationScheduleMessagePublisher {
public static final String NAME = "TRAIN";
public static final int RATE = 1000;
public static final String TMS_PATH = "tms";
public static final String TMS_PATTERN = String.format("%s/%s/%s",
club.joylink.rtss.simulation.Simulation.MESSAGE_SUB_PREFIX, "train/{groupNumber}", TMS_PATH);
public static void main(String[] args) {
System.out.println(TMS_PATTERN);
}
private final Simulation simulation;
public TrainTmsPublisher(Simulation simulation) {
super(NAME, RATE, true, List.of(TMS_PATTERN));
this.simulation = simulation;
}
@Override
public boolean isValidParams(List<String> params) {
if (params.size() != 2) {
return false;
}
return simulation.getRepository().findVRByCode(params.get(1), VirtualRealityTrain.class)
!= null;
}
@Override
public Object buildMessageOfSubscribe(String destination) {
List<String> list = this.getDestinationParamsMap().get(destination);
if (destination.contains(TMS_PATH)) {
String gn = list.get(1);
TrainTmsDisplay display = simulation.getRepository().getTrainTmsMap().get(gn);
if (display != null) {
return display;
} else {
return buildTmsMessage(gn);
}
}
return null;
}
@Override
public Object buildNextSendMessage(String destination) {
List<String> list = this.getDestinationParamsMap().get(destination);
if (destination.contains(TMS_PATH)) {
String s = list.get(1);
return buildTmsMessage(s);
}
return null;
}
private Object buildTmsMessage(String groupNumber) {
VirtualRealityTrain train = simulation.getRepository()
.getVRByCode(groupNumber, VirtualRealityTrain.class);
Map<String, TrainTmsDisplay> trainTmsMap = simulation.getRepository().getTrainTmsMap();
TrainTmsDisplay trainTmsDisplay = trainTmsMap.get(groupNumber);
if (trainTmsDisplay == null) {
trainTmsDisplay = new TrainTmsDisplay(train);
trainTmsMap.put(groupNumber, trainTmsDisplay);
return trainTmsDisplay;
} else {
return trainTmsDisplay.updateAndCollectDiff(train);
}
}
}

View File

@ -1,9 +1,15 @@
package club.joylink.rtss.services.ws;
import club.joylink.rtss.simulation.cbtc.data.map.Section;
import club.joylink.rtss.util.JsonUtils;
import club.joylink.rtss.vo.ws.TrainPosition;
import club.joylink.rtss.websocket.client.SimulationSessionHandler;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
import org.springframework.messaging.simp.stomp.StompFrameHandler;
import org.springframework.messaging.simp.stomp.StompHeaders;
@ -12,150 +18,152 @@ import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.web.socket.client.standard.StandardWebSocketClient;
import org.springframework.web.socket.messaging.WebSocketStompClient;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
public class StompTest {
@Test
public void sendMsg(){
StandardWebSocketClient socketClient = new StandardWebSocketClient();
WebSocketStompClient stompClient = new WebSocketStompClient(socketClient);
SimulationSessionHandler handler = new SimulationSessionHandler();
ListenableFuture<StompSession> future = stompClient
.connect("ws://127.0.0.1:9000/joylink-tbi-websocket?user_account=train_place&account_pwd=train_place",handler, "null");
StompSession stompSession = null;
try {
stompSession = future.get();
} catch (Exception e) {
e.printStackTrace();
}
EnvLoggerFileTest lt = new EnvLoggerFileTest();
List<TrainPosition> list = lt.readFile("d:\\spring.log");
@Test
public void sendMsg() {
StandardWebSocketClient socketClient = new StandardWebSocketClient();
WebSocketStompClient stompClient = new WebSocketStompClient(socketClient);
SimulationSessionHandler handler = new SimulationSessionHandler();
ListenableFuture<StompSession> future = stompClient
.connect(
"ws://127.0.0.1:9000/joylink-tbi-websocket?user_account=train_place&account_pwd=train_place",
handler, "null");
StompSession stompSession = null;
try {
stompSession = future.get();
} catch (Exception e) {
e.printStackTrace();
}
EnvLoggerFileTest lt = new EnvLoggerFileTest();
List<TrainPosition> list = lt.readFile("d:\\spring.log");
// List<TrainPosition> list = lt.readSource("d:\\t.txt");
// runToLeft(stompSession,"001");
// runToRight(stompSession,"002");
// list = lt.query(list,"031");
// list = lt.query(list,"004", Section.SectionRoadType.LEFT);
// list = lt.query(list, Lists.newArrayList("015","037"), Section.SectionRoadType.RIGHT);
send(stompSession,list);
}
@Test
public void subscribe(){
StandardWebSocketClient socketClient = new StandardWebSocketClient();
WebSocketStompClient stompClient = new WebSocketStompClient(socketClient);
SimulationSessionHandler handler = new SimulationSessionHandler();
ListenableFuture<StompSession> future = stompClient
.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("/queue/simulation/63-8146", new StompFrameHandler() {
@Override
public Type getPayloadType(StompHeaders stompHeaders) {
return byte[].class;
}
send(stompSession, list);
}
@Override
public void handleFrame(StompHeaders stompHeaders, Object o) {
String recv=null;
try {
recv = new String((byte[]) o,"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.println(recv);
}
});
stompSession.setAutoReceipt(true);
try {
TimeUnit.SECONDS.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
@Test
public void subscribe() {
StandardWebSocketClient socketClient = new StandardWebSocketClient();
WebSocketStompClient stompClient = new WebSocketStompClient(socketClient);
SimulationSessionHandler handler = new SimulationSessionHandler();
ListenableFuture<StompSession> future = stompClient
.connect("ws://127.0.0.1:9000/joylink-websocket?token=cb3b90e30e65bbbf2e3f2cc67a623d28",
handler, "null");
StompSession stompSession = null;
try {
stompSession = future.get();
} catch (Exception e) {
e.printStackTrace();
}
public static void send(StompSession stompSession,List<TrainPosition> list){
stompSession.subscribe("/queue/simulation/63-42/train/001/tms", new StompFrameHandler() {
@Override
public Type getPayloadType(StompHeaders stompHeaders) {
return byte[].class;
}
for (int i = 0; i < list.size(); i++) {
@Override
public void handleFrame(StompHeaders stompHeaders, Object o) {
String recv = null;
try {
recv = new String((byte[]) o, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
System.out.println(recv);
}
});
stompSession.setAutoReceipt(true);
try {
TimeUnit.SECONDS.sleep(100);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
System.out.println("SUBSCRIBE\n"
+ "destination:/queue/simulation/63-8146\n"
+ "id:0\n"
+ "\n"
+ "\u0000");
}
public static void send(StompSession stompSession, List<TrainPosition> list) {
for (int i = 0; i < list.size(); i++) {
// for (int i = 22; i < 23; i++) {
TrainPosition tp = list.get(i);
tp.setCloseDoor(false);
tp.setStop(false);
tp.setSpeed(Float.valueOf(i));
TrainPosition tp = list.get(i);
tp.setCloseDoor(false);
tp.setStop(false);
tp.setSpeed(Float.valueOf(i));
// tp.setLocation(tp.getLocation() - 500);
String val = JsonUtils.writeValueNullableFieldAsString(tp);
String val = JsonUtils.writeValueNullableFieldAsString(tp);
// Instant instant = Instant.ofEpochMilli(tp.getReceiveTime());
// ZoneId zone = ZoneId.systemDefault();
// String d = LocalDateTime.ofInstant(instant, zone).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
System.out.println(i +" ->" + val);
stompSession.send("/app/武汉8号线/trainPosition",val.getBytes(StandardCharsets.UTF_8));
System.out.println(i + " ->" + val);
stompSession.send("/app/武汉8号线/trainPosition", val.getBytes(StandardCharsets.UTF_8));
if(i > 0){
TrainPosition old = list.get(i - 1);
try {
if (i > 0) {
TrainPosition old = list.get(i - 1);
try {
// long sleepTime = (tp.getReceiveTime() - old.getReceiveTime());
// if(sleepTime > 10000){
// sleepTime = sleepTime / 1000;
// }
// System.out.println("index:" + i + "sleep:"+sleepTime);
TimeUnit.MILLISECONDS.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
TimeUnit.MILLISECONDS.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
public static void runToLeft(StompSession stompSession,String tripNum){
int step = 20;
int location = 40000;
while(true){
location -= step;
Map<String,Object> dataMap = new HashMap<>();
dataMap.put("groupNum",tripNum);
public static void runToLeft(StompSession stompSession, String tripNum) {
int step = 20;
int location = 40000;
while (true) {
location -= step;
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("groupNum", tripNum);
// dataMap.put("direction",1);
dataMap.put("direction",0);
dataMap.put("location",location);
String val = JsonUtils.writeValueNullableFieldAsString(dataMap);
System.out.println(val);
stompSession.send("/app/武汉8号线/trainPosition",val.getBytes(StandardCharsets.UTF_8));
try {
TimeUnit.MILLISECONDS.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
dataMap.put("direction", 0);
dataMap.put("location", location);
String val = JsonUtils.writeValueNullableFieldAsString(dataMap);
System.out.println(val);
stompSession.send("/app/武汉8号线/trainPosition", val.getBytes(StandardCharsets.UTF_8));
try {
TimeUnit.MILLISECONDS.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void runToRight(StompSession stompSession,String tripNum){
int step = 20;
int location = 0;
while(true){
location += step;
Map<String,Object> dataMap = new HashMap<>();
dataMap.put("groupNum",tripNum);
dataMap.put("direction",1);
}
public static void runToRight(StompSession stompSession, String tripNum) {
int step = 20;
int location = 0;
while (true) {
location += step;
Map<String, Object> dataMap = new HashMap<>();
dataMap.put("groupNum", tripNum);
dataMap.put("direction", 1);
// dataMap.put("direction",0);
dataMap.put("location",location);
String val = JsonUtils.writeValueNullableFieldAsString(dataMap);
System.out.println(val);
stompSession.send("/app/武汉8号线/trainPosition",val.getBytes(StandardCharsets.UTF_8));
try {
TimeUnit.MILLISECONDS.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
dataMap.put("location", location);
String val = JsonUtils.writeValueNullableFieldAsString(dataMap);
System.out.println(val);
stompSession.send("/app/武汉8号线/trainPosition", val.getBytes(StandardCharsets.UTF_8));
try {
TimeUnit.MILLISECONDS.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}