This commit is contained in:
tiger_zhou 2023-06-08 15:48:30 +08:00
commit 836d4b484b
3 changed files with 192 additions and 62 deletions

View File

@ -4,7 +4,6 @@ import club.joylink.xiannccda.ats.message.MessageResponse;
import io.netty.buffer.ByteBuf;
import lombok.Getter;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

View File

@ -2,124 +2,162 @@ package club.joylink.xiannccda.ats.message.line3;
import club.joylink.xiannccda.ats.message.MessageResponse;
import io.netty.buffer.ByteBuf;
import lombok.Getter;
import java.time.LocalDateTime;
/**
* 2.7.10 列车信息更新消息[增加/更新]
*/
@Getter
public class TrainIndicationUpdateResponse extends MessageResponse {
/**
* 线路号(2)
*/
private Short lineId;
private Short lineId;
/**
* 车次号变化状态(2)
* 0x01增加<br>
* 0x02更新<br>
* true-更新false-增加
*/
private Short type;
private Boolean type;
/**
* 集中站站号(2)
*/
private Short rtuId;
private Short rtuId;
/**
* NCC车次窗编号(2)
*/
private Short nccWindow;
private Short nccWindow;
/**
* 列车在车次窗中的位置(1)
*/
private Byte nccWindowOffset;
private Byte nccWindowOffset;
/**
* 列车所在的设备的类型(2)
*/
private Short devType;
private DeviceTypeEnum devType;
/**
* 列车所在的设备的名称(24)
*/
private byte[] devName = new byte[24];
private String devName;
/**
* 列车标示号全线唯一若无法提供缺省值为0(10)
*/
private byte[] trainIndex = new byte[10];
private String trainIndex;
/**
* 列车编组号(9)
*/
private byte[] groupId = new byte[9];
private String groupId;
/**
* 表号(9)
*/
private byte[] trainId = new byte[9];
private String trainId;
/**
* 车次号(12)
*/
private byte[] globalId = new byte[12];
private String globalId;
/**
* 目的地号(4)
*/
private byte[] destinationId = new byte[4];
private Integer destinationId;
/**
* 编组数量(1)
*/
private byte rollingStock;
private byte rollingStock;
/**
* 司机号(13)
*/
private byte[] driverId = new byte[13];
private String driverId;
/**
* 运行路径号若无法提供缺省值为0(2)
*/
private Short routeId;
private Short routeId;
/**
* 计划偏离时间(4)
*/
private Integer optTime;
private Integer optTime;
/**
* 列车状态见附录6.3.14列车状态定义(4)
*/
private Integer mode;
private Integer mode;
/**
* 列车到点(7)
*/
private byte[] arriveTime = new byte[7];
private LocalDateTime arriveTime;
/**
* 列车发点(7)
*/
private byte[] departTime = new byte[7];
private LocalDateTime departTime;
/**
* 满载率百分比例如50表示满载率为50%(4)
*/
private Integer rate;
private Integer rate;
/**
* 速度KM/H(1)
*/
private byte speed;
private byte speed;
/**
* 预留(2)
*/
private byte[] reserve = new byte[2];
private byte[] reserve = new byte[2];
@Override
public void decode2(ByteBuf buf) throws Exception {
short devType;
short type;
final byte[] devName = new byte[24];
final byte[] trainIndex = new byte[10];
final byte[] groupId = new byte[9];
final byte[] trainId = new byte[9];
final byte[] globalId = new byte[12];
final byte[] driverId = new byte[13];
final byte[] arriveTime = new byte[7];
final byte[] departTime = new byte[7];
//
this.lineId = buf.readShort();
this.type = buf.readShort();
type = buf.readShort();
this.rtuId = buf.readShort();
this.nccWindow = buf.readShort();
this.nccWindowOffset = buf.readByte();
this.devType = buf.readShort();
buf.readBytes(this.devName);
buf.readBytes(this.trainIndex);
buf.readBytes(this.groupId);
buf.readBytes(this.trainId);
buf.readBytes(this.globalId);
buf.readBytes(this.destinationId);
this.rollingStock = buf.readByte();
buf.readBytes(this.driverId);
devType = buf.readShort();
buf.readBytes(devName);
buf.readBytes(trainIndex);
buf.readBytes(groupId);
buf.readBytes(trainId);
buf.readBytes(globalId);
this.destinationId = buf.readInt();
this.rollingStock = buf.readByte();
buf.readBytes(driverId);
this.routeId = buf.readShort();
this.optTime = buf.readInt();
this.mode = buf.readInt();
buf.readBytes(this.arriveTime);
buf.readBytes(this.departTime);
buf.readBytes(arriveTime);
buf.readBytes(departTime);
this.rate = buf.readInt();
this.speed = buf.readByte();
buf.readBytes(this.reserve);
//
this.devType = DeviceTypeEnum.of(devType);
this.devName = new String(devName, MessageCons.STRING_CHARSET);
this.trainIndex = new String(trainIndex, MessageCons.STRING_CHARSET);
this.groupId = new String(groupId, MessageCons.STRING_CHARSET);
this.trainId = new String(trainId, MessageCons.STRING_CHARSET);
this.globalId = new String(globalId, MessageCons.STRING_CHARSET);
this.driverId = new String(driverId, MessageCons.STRING_CHARSET);
this.arriveTime = DateTimeUtil.convert(arriveTime);
this.departTime = DateTimeUtil.convert(departTime);
/**
* 车次号变化状态(2)
* 0x01增加<br>
* 0x02更新<br>
* true-更新false-增加
*/
switch (type) {
case 0x02 -> this.type = true;
case 0x01 -> this.type = false;
}
}
}

View File

@ -2,84 +2,177 @@ package club.joylink.xiannccda.ats.message.line3;
import club.joylink.xiannccda.ats.message.MessageResponse;
import io.netty.buffer.ByteBuf;
import lombok.Getter;
import java.time.LocalDateTime;
/**
* 2.7.8列车报点消息
*/
@Getter
public class TrainRecordResponse extends MessageResponse {
/**
* 线路号(2)
*/
private Short lineId;
private Short lineId;
/**
* 表号(9)
*/
private byte[] trainId = new byte[9];
private String trainId;
/**
* 车次号(12)
*/
private byte[] globalId = new byte[12];
private String globalId;
/**
* 局部序列号(4)
*/
private byte[] localSubId = new byte[4];
private Integer localSubId;
/**
* 车组号(9)
*/
private byte[] groupId = new byte[9];
private String groupId;
/**
* 目的地(4)
*/
private byte[] destinationId = new byte[4];
private Integer destinationId;
/**
* 列车类型(2)
* 0x01计划车<br>
* 0x02头码车<br>
* 0x03M0车<br>
* 0x04MM车<br>
*/
private Short trainType;
private TrainTypeEnum trainType;
/**
* 运行方向(1)
* 0x01下行 <br>
* 0x02上行<br>
* 0x00无方向<br>
*/
private Byte direction;
private DirectionEnum direction;
/**
* 站号(2)
*/
private Short stationId;
private Short stationId;
/**
* 站台编号(2)
*/
private Short sideId;
private Short sideId;
/**
* 轨道名称小区段名称(20)
*/
private byte[] trackName = new byte[20];
private String trackName;
/**
* 到发点类型(2)
* 到发点类型(2)<br>
* 0x01H到达<br>
* 0x02H出发<br>
* true-到达false-出发
*/
private Short recordType;
private Boolean recordType;
/**
* 到发时间(7)
*/
private byte[] recordTime = new byte[7];
private LocalDateTime recordTime;
/**
* 预留(4)
*/
private byte[] reserve = new byte[4];
private byte[] reserve = new byte[4];
@Override
public void decode2(ByteBuf buf) throws Exception {
final byte[] trainId = new byte[9];
final byte[] globalId = new byte[12];
final byte[] groupId = new byte[9];
short trainType;
byte direction;
final byte[] trackName = new byte[20];
short recordType;
final byte[] recordTime = new byte[7];
//
this.lineId = buf.readShort();
buf.readBytes(this.trainId);
buf.readBytes(this.globalId);
buf.readBytes(this.localSubId);
buf.readBytes(this.groupId);
buf.readBytes(this.destinationId);
this.trainType = buf.readShort();
this.direction = buf.readByte();
this.stationId = buf.readShort();
this.sideId = buf.readShort();
buf.readBytes(this.trackName);
this.recordType = buf.readShort();
buf.readBytes(this.recordTime);
buf.readBytes(trainId);
buf.readBytes(globalId);
this.localSubId = buf.readInt();
buf.readBytes(groupId);
this.destinationId = buf.readInt();
trainType = buf.readShort();
direction = buf.readByte();
this.stationId = buf.readShort();
this.sideId = buf.readShort();
buf.readBytes(trackName);
recordType = buf.readShort();
buf.readBytes(recordTime);
buf.readBytes(this.reserve);
//
this.trainId = new String(trainId, MessageCons.STRING_CHARSET);
this.globalId = new String(globalId, MessageCons.STRING_CHARSET);
this.groupId = new String(groupId, MessageCons.STRING_CHARSET);
this.trainType = TrainTypeEnum.of(trainType);
this.direction = DirectionEnum.of(direction);
this.trackName = new String(trackName, MessageCons.STRING_CHARSET);
/**
* 到发点类型(2)<br>
* 0x01H到达<br>
* 0x02H出发<br>
* true-到达false-出发
*/
switch (recordType) {
case 0x01 -> this.recordType = true;
case 0x02 -> this.recordType = false;
}
this.recordTime = DateTimeUtil.convert(recordTime);
}
/**
* 运行方向(1)
* 0x01下行 <br>
* 0x02上行<br>
* 0x00无方向<br>
*/
public static enum DirectionEnum {
Down(0x01),
Up(0x02),
Unknown(0x00),
;
private int value;
private DirectionEnum(final int value) {
this.value = value;
}
public static DirectionEnum of(final int value) {
for (final DirectionEnum direction : values()) {
if (direction.value == value) return direction;
}
return DirectionEnum.Unknown;
}
}
/**
* 列车类型(2)
* 0x01计划车<br>
* 0x02头码车<br>
* 0x03M0车<br>
* 0x04MM车<br>
*/
public static enum TrainTypeEnum {
PlannedTrain(0x01),
HeadTrain(0x02),
M0Train(0x03),
MMTrain(0x04),
;
private int type;
private TrainTypeEnum(final int type) {
this.type = type;
}
public static TrainTypeEnum of(final int type) {
for (final TrainTypeEnum tt : values()) {
if (type == tt.type) return tt;
}
return null;
}
}
}