模拟设备状态变更接口调整

This commit is contained in:
tiger_zhou 2023-07-05 16:00:44 +08:00
parent d042470c8f
commit c5f5449da9
8 changed files with 124 additions and 37 deletions

View File

@ -3,7 +3,13 @@ package club.joylink.xiannccda.ats.message.line3.rep;
import club.joylink.xiannccda.ats.message.MessageResponse;
import club.joylink.xiannccda.ats.message.line3.MessageCons;
import club.joylink.xiannccda.ats.message.line3.device.DeviceType;
import club.joylink.xiannccda.dto.protos.DeviceStatusProto;
import club.joylink.xiannccda.dto.protos.TrainProto.TrainBlock;
import com.google.common.collect.Lists;
import com.google.protobuf.GeneratedMessageV3;
import com.google.protobuf.GeneratedMessageV3.Builder;
import io.netty.buffer.ByteBuf;
import java.util.Objects;
import lombok.Getter;
import java.util.ArrayList;
@ -40,6 +46,45 @@ public class TrainBlockInfoResponse extends MessageResponse {
}
}
@Override
public List<Builder> generateProto() {
List<GeneratedMessageV3.Builder> builders = Lists.newArrayList();
for (TrainCell train : this.trains) {
TrainBlock.Builder builder = TrainBlock.newBuilder();
builder.setLineId(this.getLineId());
if (Objects.nonNull(train.getGroupId())) {
builder.setGroupId(train.getGroupId());
}
if (Objects.nonNull(train.getTrainId())) {
builder.setTrainId(train.getTrainId());
}
if (Objects.nonNull(train.getDirection())) {
builder.setDirection(train.getDirection().value);
}
if (Objects.nonNull(train.getStationIdInUpSide())) {
builder.setStationIDInUpSide(train.getStationIdInUpSide());
}
if (Objects.nonNull(train.getStationIdInDownSide())) {
builder.setStationIDInUpSide(train.getStationIdInDownSide());
}
if (Objects.nonNull(train.getRtuId())) {
builder.setRtuId(train.getRtuId());
}
if (Objects.nonNull(train.getDevType())) {
DeviceStatusProto.DeviceType dtProto = DeviceStatusProto.DeviceType.forNumber(train.getDevType().getVal());
builder.setDeviceType(dtProto);
}
if (Objects.nonNull(train.getDevName())) {
builder.setDevName(train.getDevName());
}
if (Objects.nonNull(train.getBlockFlag())) {
builder.setBlockFlag(train.getBlockFlag() ? 1 : 0);
}
builders.add(builder);
}
return builders;
}
@Getter
@Setter
public static class TrainCell {

View File

@ -12,6 +12,7 @@ import club.joylink.xiannccda.dto.protos.TrainProto.TrainInfo;
import com.google.common.collect.Lists;
import com.google.protobuf.GeneratedMessageV3.Builder;
import io.netty.buffer.ByteBuf;
import java.util.Objects;
import lombok.Getter;
import java.time.LocalDateTime;
@ -67,10 +68,18 @@ public class TrainIndicationInitResponse extends MessageResponse {
if (trainCell.getDevType() != null) {
builder.setDevType(DeviceStatusProto.DeviceType.forNumber(trainCell.getDevType().getVal()));
}
if (Objects.nonNull(trainCell.getDevName())) {
builder.setDevName(trainCell.getDevName());
}
if (Objects.nonNull(trainCell.getTrainIndex())) {
builder.setTrainIndex(trainCell.getTrainIndex());
}
if (Objects.nonNull(trainCell.getGroupId())) {
builder.setGroupId(trainCell.getGroupId());
}
if (Objects.nonNull(trainCell.getTrainId())) {
builder.setTrainId(trainCell.getTrainId());
}
if (trainCell.getGlobalId() != null) {
builder.setGlobalId(trainCell.getGlobalId());
}

View File

@ -9,6 +9,7 @@ import club.joylink.xiannccda.dto.protos.TrainProto.TrainRemove;
import com.google.protobuf.GeneratedMessageV3.Builder;
import io.netty.buffer.ByteBuf;
import java.util.List;
import java.util.Objects;
import lombok.Getter;
import lombok.Setter;
@ -77,16 +78,33 @@ public class TrainIndicationRemoveResponse extends MessageResponse {
@Override
public List<Builder> generateProto() {
TrainRemove.Builder trainRemove = TrainRemove.newBuilder();
if (Objects.nonNull(this.lineId)) {
trainRemove.setLineId(this.lineId);
}
if (Objects.nonNull(this.rtuId)) {
trainRemove.setRtuId(this.rtuId);
}
NccWindow.Builder window = NccWindow.newBuilder();
if (Objects.nonNull(this.nccWindow)) {
window.setNccWindow(this.nccWindow);
}
if (Objects.nonNull(this.nccWindowOffset)) {
window.setNccWinOffset(this.nccWindowOffset);
}
trainRemove.setWindow(window);
if (Objects.nonNull(this.devType)) {
trainRemove.setDeviceType(DeviceStatusProto.DeviceType.forNumber(this.devType.getVal()));
}
if (Objects.nonNull(this.devName)) {
trainRemove.setDevName(this.devName);
}
if (Objects.nonNull(this.trainIndex)) {
trainRemove.setTrainIndex(this.trainIndex);
}
if (Objects.nonNull(this.groupId)) {
trainRemove.setGroupId(this.groupId);
}
return List.of(trainRemove);
}

View File

@ -125,7 +125,6 @@ public class TrainIndicationUpdateResponse extends MessageResponse {
@Override
public List<Builder> generateProto() {
TrainProto.TrainInfo.Builder train = TrainInfo.newBuilder();
train.setLineId(this.lineId);
train.setType(this.type);
train.setRtuId(this.rtuId);

View File

@ -13,6 +13,7 @@ import com.google.protobuf.GeneratedMessageV3.Builder;
import io.netty.buffer.ByteBuf;
import java.time.ZoneOffset;
import java.util.List;
import java.util.Objects;
import lombok.Getter;
import java.time.LocalDateTime;
@ -130,11 +131,21 @@ public class TrainRecordResponse extends MessageResponse {
@Override
public List<Builder> generateProto() {
TrainRecord.Builder builder = TrainRecord.newBuilder();
if (Objects.nonNull(this.lineId)) {
builder.setLineId(this.getLineId());
builder.setTrainId(this.getTrainId());
builder.setGlobalId(this.getGlobalId());
builder.setLocalSubId(this.getLocalSubId());
builder.setGroupId(this.getGroupId());
}
if (Objects.nonNull(this.trainId)) {
builder.setTrainId(this.trainId);
}
if (Objects.nonNull(this.globalId)) {
builder.setGlobalId(this.globalId);
}
if (Objects.nonNull(this.localSubId)) {
builder.setLocalSubId(this.localSubId);
}
if (Objects.nonNull(this.groupId)) {
builder.setGroupId(this.groupId);
}
if (this.getDestinationId() != null) {
builder.setDestinationId(this.getDestinationId());
}

View File

@ -156,6 +156,7 @@ public class MockDeviceController {
Object v = jo2.get(s1);
this.setVal(cloneBuilder, s1, v);
}
this.setVal(builder, s, cloneBuilder.build());
}
}
DeviceDataRepository.add(lineId, List.of(builder), dataType);

View File

@ -177,7 +177,7 @@ public class Status {
String groupId;
NccWindow window;
TrainMode trainMode;
TrainMode mode;
@Schema(description = "设备类型 DEVICE_TYPE_UNKNOW;\n"
+ " DEVICE_TYPE_RTU;\n"
+ " DEVICE_TYPE_STATION;\n"

View File

@ -52,7 +52,7 @@ public class LineDeviceStatusService {
@PostConstruct
public void deviceStatusRefresh() {
// this.createDataConvertor();
this.createDataConvertor();
// 设备状态数据集合
DeviceStatusData deviceStatusData = DeviceStatusDataRepository.getDeviceStatusData(DATA_KEY);
// 添加初始化转换方法
@ -97,6 +97,7 @@ public class LineDeviceStatusService {
Executors.newSingleThreadScheduledExecutor()
.scheduleWithFixedDelay(
() -> {
try {
boolean isEmpty = true;
if (resetTimes.get() == stopTime) { // 代表还没有停顿不相等说明已经进入空循环
int count = (int) (Math.random() * 12);
@ -113,6 +114,9 @@ public class LineDeviceStatusService {
resetTimes.set(resetTimes.get() - frequency);
}
}
} catch (Exception e) {
e.printStackTrace();
}
},
frequency,
frequency,