This commit is contained in:
weizhihong 2023-06-08 17:42:20 +08:00
commit 86826cdfb3
17 changed files with 155 additions and 90 deletions

View File

@ -78,8 +78,8 @@ public class DispatcherReportResponse extends MessageResponse {
buf.readBytes(logItem);
//
this.reportTime = DateTimeUtil.convert(reportTime);
this.userName = new String(userName, MessageCons.STRING_CHARSET);
this.logItem = new String(logItem, MessageCons.STRING_CHARSET);
this.userName = new String(userName, MessageCons.STRING_CHARSET).trim();
this.logItem = new String(logItem, MessageCons.STRING_CHARSET).trim();
//
return this;
}

View File

@ -77,7 +77,7 @@ public class DriverDistanceReportResponse extends MessageResponse {
this.distance = buf.readInt();
//
this.date=DateTimeUtil.convert(date);
this.driverId=new String(driverId,MessageCons.STRING_CHARSET);
this.driverId=new String(driverId,MessageCons.STRING_CHARSET).trim();
//
return this;
}

View File

@ -90,10 +90,10 @@ public class GroupBakReportResponse extends MessageResponse {
depot = buf.readByte();
buf.readBytes(trackName);
//
this.groupId = new String(groupId, MessageCons.STRING_CHARSET);
this.groupId = new String(groupId, MessageCons.STRING_CHARSET).trim();
this.status = GroupBakStatusEnum.of(status);
this.depot = GroupBakDepotEnum.of(depot);
this.trackName = new String(trackName, MessageCons.STRING_CHARSET);
this.trackName = new String(trackName, MessageCons.STRING_CHARSET).trim();
return this;
}
}

View File

@ -83,7 +83,7 @@ public class GroupRunningReportResponse extends MessageResponse {
public GroupCell decode(final ByteBuf buf) {
final byte[] groupId = new byte[9];
buf.readBytes(groupId);
this.groupId = new String(groupId, MessageCons.STRING_CHARSET);
this.groupId = new String(groupId, MessageCons.STRING_CHARSET).trim();
//
this.totalRunning = buf.readInt();
this.monthRepair = buf.readInt();

View File

@ -78,7 +78,7 @@ public class GroupStatusReportResponse extends MessageResponse {
depot = buf.readByte();
buf.readBytes(this.status);
//
this.groupId = new String(groupId, MessageCons.STRING_CHARSET);
this.groupId = new String(groupId, MessageCons.STRING_CHARSET).trim();
this.depot = GroupPositionEnum.of(depot);
//
return this;

View File

@ -52,6 +52,6 @@ public class InUsedScheduleParameterResponse extends MessageResponse {
case 0x01 -> this.valid = true;
case 0x02 -> this.valid = false;
}
this.inUsedScheduleName = new String(inUsedScheduleName, MessageCons.STRING_CHARSET);
this.inUsedScheduleName = new String(inUsedScheduleName, MessageCons.STRING_CHARSET).trim();
}
}

View File

@ -35,7 +35,7 @@ public class MessageAlarmResponse extends MessageResponse {
final byte[] alarmContent = new byte[alarmLen];
buf.readBytes(alarmContent);
//
this.tagId = new String(tagId, MessageCons.STRING_CHARSET);
this.alarmContent = new String(alarmContent, MessageCons.STRING_CHARSET);
this.tagId = new String(tagId, MessageCons.STRING_CHARSET).trim();
this.alarmContent = new String(alarmContent, MessageCons.STRING_CHARSET).trim();
}
}

View File

@ -1,6 +1,7 @@
package club.joylink.xiannccda.ats.message.line3;
import club.joylink.xiannccda.ats.message.MessageResponse;
import club.joylink.xiannccda.ats.message.rep.device.DeviceType;
import io.netty.buffer.ByteBuf;
import lombok.Getter;
@ -65,15 +66,15 @@ public class TrainBlockInfoResponse extends MessageResponse {
/**
* 集中站站号(2)
*/
private Short rtuId;
private Short rtuId;
/**
* 列车所在的设备的类型(2)
*/
private DeviceTypeEnum devType;
private DeviceType devType;
/**
* 列车所在的设备的名称(24)
*/
private String devName;
private String devName;
/**
* 列车阻塞标记(1)
* 1列车阻塞
@ -99,10 +100,10 @@ public class TrainBlockInfoResponse extends MessageResponse {
buf.readBytes(devName);
blockFlag = buf.readByte();
//
this.groupId = new String(groupId, MessageCons.STRING_CHARSET);
this.trainId = new String(trainId, MessageCons.STRING_CHARSET);
this.devType = DeviceTypeEnum.of(devType);
this.devName = new String(devName, MessageCons.STRING_CHARSET);
this.groupId = new String(groupId, MessageCons.STRING_CHARSET).trim();
this.trainId = new String(trainId, MessageCons.STRING_CHARSET).trim();
this.devType = DeviceType.of(devType);
this.devName = new String(devName, MessageCons.STRING_CHARSET).trim();
this.direction = DirectionEnum.of(direction);
switch (blockFlag) {
case 1 -> this.blockFlag = true;

View File

@ -1,6 +1,7 @@
package club.joylink.xiannccda.ats.message.line3;
import club.joylink.xiannccda.ats.message.MessageResponse;
import club.joylink.xiannccda.ats.message.rep.device.DeviceType;
import io.netty.buffer.ByteBuf;
import lombok.Getter;
@ -43,79 +44,79 @@ public class TrainIndicationInitResponse extends MessageResponse {
/**
* 集中站站号(2)
*/
private Short rtuId;
private Short rtuId;
/**
* NCC车次窗编号(2)
*/
private Short nccWindow;
private Short nccWindow;
/**
* 列车在车次窗中的位置(1)
*/
private Byte nccWindowOffset;
private Byte nccWindowOffset;
/**
* 列车所在的设备的类型(2)
*/
private DeviceTypeEnum devType;
private DeviceType devType;
/**
* 列车所在的设备的名称(24)
*/
private String devName;
private String devName;
/**
* 列车标示号全线唯一若无法提供缺省值为0(10)
*/
private String trainIndex;
private String trainIndex;
/**
* 列车编组号(9)
*/
private String groupId;
private String groupId;
/**
* 表号(9)
*/
private String trainId;
private String trainId;
/**
* 车次号(12)
*/
private String globalId;
private String globalId;
/**
* 目的地号(4)
*/
private Integer destinationId;
private Integer destinationId;
/**
* 编组数量(1)
*/
private byte rollingStock;
private byte rollingStock;
/**
* 司机号(13)
*/
private String driverId;
private String driverId;
/**
* 根据实际报点和计划的偏离时间单位-215- +215 正数表示列车晚点秒数负数表示列车早点秒数(4)
*/
private Integer otpTime;
private Integer otpTime;
/**
* 列车状态见附录6.3.14列车状态定义(4)
*/
private Integer mode;
private Integer mode;
/**
* 列车到点(7)
*/
private LocalDateTime arriveTime;
private LocalDateTime arriveTime;
/**
* 列车发点(7)
*/
private LocalDateTime departTime;
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];
private TrainCell decode(final ByteBuf buf) {
short devType;
@ -148,13 +149,13 @@ public class TrainIndicationInitResponse extends MessageResponse {
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.devType = DeviceType.of(devType);
this.devName = new String(devName, MessageCons.STRING_CHARSET).trim();
this.trainIndex = new String(trainIndex, MessageCons.STRING_CHARSET).trim();
this.groupId = new String(groupId, MessageCons.STRING_CHARSET).trim();
this.trainId = new String(trainId, MessageCons.STRING_CHARSET).trim();
this.globalId = new String(globalId, MessageCons.STRING_CHARSET).trim();
this.driverId = new String(driverId, MessageCons.STRING_CHARSET).trim();
this.arriveTime = DateTimeUtil.convert(arriveTime);
this.departTime = DateTimeUtil.convert(departTime);
//

View File

@ -1,6 +1,7 @@
package club.joylink.xiannccda.ats.message.line3;
import club.joylink.xiannccda.ats.message.MessageResponse;
import club.joylink.xiannccda.ats.message.rep.device.DeviceType;
import io.netty.buffer.ByteBuf;
import lombok.Getter;
@ -13,35 +14,35 @@ public class TrainIndicationRemoveResponse extends MessageResponse {
/**
* 线路号(2)
*/
private Short lineId;
private Short lineId;
/**
* 集中站站号(2)
*/
private Short rtuId;
private Short rtuId;
/**
* NCC车次窗编号(2)
*/
private Short nccWindow;
private Short nccWindow;
/**
* 列车在车次窗中的位置(1)
*/
private Byte nccWindowOffset;
private Byte nccWindowOffset;
/**
* 列车所在的设备的类型(2)
*/
private DeviceTypeEnum devType;
private DeviceType devType;
/**
* 列车所在的设备的名称(24)
*/
private String devName;
private String devName;
/**
* 列车标示号全线唯一若无法提供缺省值为0(10)
*/
private String trainIndex;
private String trainIndex;
/**
* 列车编组号(9)
*/
private String groupId;
private String groupId;
@Override
public void decode2(ByteBuf buf) throws Exception {
@ -59,9 +60,9 @@ public class TrainIndicationRemoveResponse extends MessageResponse {
buf.readBytes(trainIndex);
buf.readBytes(groupId);
//
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.devType = DeviceType.of(devType);
this.devName = new String(devName, MessageCons.STRING_CHARSET).trim();
this.trainIndex = new String(trainIndex, MessageCons.STRING_CHARSET).trim();
this.groupId = new String(groupId, MessageCons.STRING_CHARSET).trim();
}
}

View File

@ -1,6 +1,7 @@
package club.joylink.xiannccda.ats.message.line3;
import club.joylink.xiannccda.ats.message.MessageResponse;
import club.joylink.xiannccda.ats.message.rep.device.DeviceType;
import io.netty.buffer.ByteBuf;
import lombok.Getter;
@ -34,15 +35,15 @@ public class TrainIndicationUpdateResponse extends MessageResponse {
/**
* 列车在车次窗中的位置(1)
*/
private Byte nccWindowOffset;
private Byte nccWindowOffset;
/**
* 列车所在的设备的类型(2)
*/
private DeviceTypeEnum devType;
private DeviceType devType;
/**
* 列车所在的设备的名称(24)
*/
private String devName;
private String devName;
/**
* 列车标示号全线唯一若无法提供缺省值为0(10)
*/
@ -140,13 +141,13 @@ public class TrainIndicationUpdateResponse extends MessageResponse {
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.devType = DeviceType.of(devType);
this.devName = new String(devName, MessageCons.STRING_CHARSET).trim();
this.trainIndex = new String(trainIndex, MessageCons.STRING_CHARSET).trim();
this.groupId = new String(groupId, MessageCons.STRING_CHARSET).trim();
this.trainId = new String(trainId, MessageCons.STRING_CHARSET).trim();
this.globalId = new String(globalId, MessageCons.STRING_CHARSET).trim();
this.driverId = new String(driverId, MessageCons.STRING_CHARSET).trim();
this.arriveTime = DateTimeUtil.convert(arriveTime);
this.departTime = DateTimeUtil.convert(departTime);
/**

View File

@ -105,12 +105,12 @@ public class TrainRecordResponse extends MessageResponse {
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.trainId = new String(trainId, MessageCons.STRING_CHARSET).trim();
this.globalId = new String(globalId, MessageCons.STRING_CHARSET).trim();
this.groupId = new String(groupId, MessageCons.STRING_CHARSET).trim();
this.trainType = TrainTypeEnum.of(trainType);
this.direction = DirectionEnum.of(direction);
this.trackName = new String(trackName, MessageCons.STRING_CHARSET);
this.trackName = new String(trackName, MessageCons.STRING_CHARSET).trim();
/**
* 到发点类型(2)<br>
* 0x01H到达<br>

View File

@ -91,7 +91,7 @@ public class DepotPlanResponse extends MessageResponse {
/**
* 上线时间(7)
*/
private DateTime outTime;
private LocalDateTime outTime;
/**
@ -174,7 +174,7 @@ public class DepotPlanResponse extends MessageResponse {
entity.driverId = EntityParseUtil.convertStr(buf, 13);
entity.outFlag = buf.readShort() == 1;
entity.outSchedule = buf.readByte() == 1;
entity.outTime = new DateTime(buf);
entity.outTime = DateTimeUtil.convert(buf);
entity.outStation = buf.readShort();
entity.outSide = buf.readShort();
entity.outName = EntityParseUtil.convertStr(buf, 20);

View File

@ -4,6 +4,7 @@ import club.joylink.xiannccda.ats.message.MessageId;
import club.joylink.xiannccda.ats.message.MessageResponse;
import club.joylink.xiannccda.ats.message.line3.DateTimeUtil;
import club.joylink.xiannccda.ats.message.rep.EntityParseUtil.ReadData;
import club.joylink.xiannccda.ats.message.rep.device.DeviceType;
import io.netty.buffer.ByteBuf;
import java.time.LocalDateTime;
import java.util.List;
@ -32,7 +33,7 @@ public class HistoryScheduleResponse extends MessageResponse {
/**
* HISTORY_SCHEDULE日期(7)
*/
private DateTime date;
private LocalDateTime date;
/**
* 0x0001: 计划列车运行信息消息开始标记
* <p>
@ -57,7 +58,7 @@ public class HistoryScheduleResponse extends MessageResponse {
@Override
public void decode2(ByteBuf buf) throws Exception {
this.lineId = buf.readShort();
this.date = new DateTime(buf);
this.date = DateTimeUtil.convert(buf);
this.subId = ScheduleSubIdType.of(buf.readShort());
if (this.subId == ScheduleSubIdType.RUNING) {
@ -67,7 +68,6 @@ public class HistoryScheduleResponse extends MessageResponse {
this.entityList = EntityParseUtil.collect(this.recCnt, buf, HistoryScheduleEntity.class);
}
}
public static class HistoryScheduleEntity implements ReadData<HistoryScheduleEntity> {

View File

@ -1,9 +1,16 @@
package club.joylink.xiannccda.ats.message.rep.device;
import java.util.List;
import lombok.Getter;
public class DeviceStatus {
public interface Status {
List<Enum> parse();
}
/**
* 表6.3-1设备状态定义表 - RTU
*/

View File

@ -1,22 +1,22 @@
package club.joylink.xiannccda.protocal.x;
import club.joylink.xiannccda.ats.message.MessageId;
import club.joylink.xiannccda.ats.message.MessageResponse;
import club.joylink.xiannccda.ats.message.line3.DateTimeUtil;
import club.joylink.xiannccda.ats.message.line3.DispatcherReportResponse;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.buffer.Unpooled;
import io.netty.buffer.UnpooledByteBufAllocator;
import club.joylink.xiannccda.ats.message.line3.MessageCons;
import com.alibaba.fastjson2.JSON;
import io.netty.buffer.*;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.Arrays;
/**
* 测试
*/
public class TestDispatcherReportResponse {
public static void main(String[]args){
final DispatcherReportResponse response = new DispatcherReportResponse();
public static void main(String[]args) throws Exception {
final ByteBufAllocator allocator = UnpooledByteBufAllocator.DEFAULT;
final ByteBuf body = allocator.buffer(1024);
System.out.println("==>>body ridx = "+body.readerIndex()+" widx = "+body.writerIndex());
body.writeInt((int) (System.currentTimeMillis() / 1000));
body.writeShort(0xff);
body.writeShort(MessageId.DISPATCHER_REPORT.idValue());
@ -25,14 +25,42 @@ public class TestDispatcherReportResponse {
body.writeShort(2);
body.writeShort(1);
body.writeShort(2);//Count
body.readBytes(DateTimeUtil.convert(LocalDateTime.now()));
///////////////////////
body.writeBytes(DateTimeUtil.convert(LocalDateTime.now()));
System.out.println("==>>1body ridx = "+body.readerIndex()+" widx = "+body.writerIndex());
//
final byte[]userName = new byte[32];
Arrays.fill(userName, (byte) '\0');
final ByteBuf userNameBuf = Unpooled.wrappedBuffer(userName);
userNameBuf.readBytes("调度员1".getBytes(StandardCharsets.UTF_8));
final byte[]userName1 = new byte[32];
TestUtil.fill("调度员1", MessageCons.STRING_CHARSET,userName1);
body.writeBytes(userName1);
System.out.println("==>>2body ridx = "+body.readerIndex()+" widx = "+body.writerIndex());
//
final byte[]logItem1 = new byte[256];
TestUtil.fill("调度1日志内容", MessageCons.STRING_CHARSET,logItem1);
body.writeBytes(logItem1);
System.out.println("==>>3body ridx = "+body.readerIndex()+" widx = "+body.writerIndex());
////////////////////////////////////////////
//
body.writeBytes(DateTimeUtil.convert(LocalDateTime.now().plusMinutes(40)));
final byte[]userName2 = new byte[32];
TestUtil.fill("调度员2", MessageCons.STRING_CHARSET,userName2);
body.writeBytes(userName2);
System.out.println("==>>4body ridx = "+body.readerIndex()+" widx = "+body.writerIndex());
//
final byte[]logItem2 = new byte[256];
TestUtil.fill("调度2日志内容", MessageCons.STRING_CHARSET,logItem2);
body.writeBytes(logItem2);
System.out.println("==>>5body ridx = "+body.readerIndex()+" widx = "+body.writerIndex());
//
final ByteBuf headLen = allocator.buffer(2);
headLen.writeShort(body.readableBytes());//Message_length
//
final CompositeByteBuf composite = allocator.compositeBuffer();
composite.addComponents(true,headLen,body);
System.out.println("==>>composite ridx = "+composite.readerIndex()+" widx = "+composite.writerIndex());
//解码
final MessageResponse response = MessageId.DISPATCHER_REPORT.createResponse();
response.decode(composite);
//
System.out.println(JSON.toJSONString(response));
}
}

View File

@ -0,0 +1,26 @@
package club.joylink.xiannccda.protocal.x;
import club.joylink.xiannccda.ats.message.line3.MessageCons;
import java.nio.charset.Charset;
public class TestUtil {
/**
* 将src通过charset编码后填充到to
*/
public static void fill(final String src, final Charset charset, final byte[] to) {
final byte[] srcBuf = src.getBytes(charset);
if (to.length < srcBuf.length) throw new RuntimeException("to.length<srcBuf.length");
for (int i = 0; i < srcBuf.length; i++) {
to[i] = srcBuf[i];
}
}
/**
* 将src通过charset编码后填充到to
*/
public static void fill(final String src, final byte[] to) {
fill(src, MessageCons.STRING_CHARSET, to);
}
}