From 61b15b4cdf2c71851c3f353dc61d00e219dcc8a2 Mon Sep 17 00:00:00 2001 From: tiger_zhou Date: Thu, 8 Jun 2023 13:09:16 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=9E=E5=AE=9E=E6=97=B6=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xiannccda/ats/message/MessageData.java | 51 +++++++++++ .../ats/message/MessageResponse.java | 2 + .../ats/message/line3/DateTimeUtil.java | 84 +++++++++++-------- .../ats/message/rep/ActionReportResponse.java | 24 +++--- .../ats/message/rep/AlarmReportResponse.java | 15 ++-- 5 files changed, 120 insertions(+), 56 deletions(-) diff --git a/src/main/java/club/joylink/xiannccda/ats/message/MessageData.java b/src/main/java/club/joylink/xiannccda/ats/message/MessageData.java index ed62e5f..bc4099e 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/MessageData.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/MessageData.java @@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import java.nio.ByteBuffer; import java.time.LocalDateTime; +import java.util.Arrays; import java.util.concurrent.TimeUnit; import lombok.NoArgsConstructor; import lombok.Setter; @@ -126,7 +127,57 @@ public abstract class MessageData { return new DateTime(LocalDateTime.now()); } + } + public enum ReportSiteEnum { + STATION(0x01), CENTER(0x02), UNKNOW(0x00); + int val; + ReportSiteEnum(int b) { + this.val = b; + } + + public static ReportSiteEnum of(byte d) { + return Arrays.stream(ReportSiteEnum.values()).filter(dd -> dd.val == d).findFirst().orElse(null); + + } + } + + public enum ActionTypeControlEnum { + /** + * 进路控制 + *

+ * 包括进路排列、引导进路办理、进路取消、进路人解等操作 + */ + ROUTE(0X01), + /** + * 信号控制 + *

+ * 包括道岔操作、区段操作、信号机操作、站台操作等 + */ + SIGNAL(0X02), + /** + * 列车管理 + *

+ * 包括列车识别号操作、列车控制操作等 + */ + TRAIN(0X03), + /** + * 计划管理 + *

+ * 包括在线计划管理操作等 + */ + PLAN(0X04), OTHER(0X05); + int val; + + ActionTypeControlEnum(int v) { + this.val = v; + } + + public static ActionTypeControlEnum of(int d) { + return Arrays.stream(ActionTypeControlEnum.values()).filter(dd -> dd.val == d).findFirst().orElse(null); + + } + } } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/MessageResponse.java b/src/main/java/club/joylink/xiannccda/ats/message/MessageResponse.java index e5bc682..04aeff3 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/MessageResponse.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/MessageResponse.java @@ -7,4 +7,6 @@ public abstract class MessageResponse extends MessageData { @Override public void encode2(ByteBuf buf) { } + + } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/line3/DateTimeUtil.java b/src/main/java/club/joylink/xiannccda/ats/message/line3/DateTimeUtil.java index 331bde8..79a2cdb 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/line3/DateTimeUtil.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/line3/DateTimeUtil.java @@ -7,42 +7,54 @@ import java.time.LocalDateTime; public class DateTimeUtil { - /** - * 例如,传送2001年9月21日15时29分30秒,则年、月、日、时、分、秒各单元的值分别为:20、01、9、21、15、29、30 - */ - public static void convert(final LocalDateTime from, final byte[] to) { - if (null == to || to.length != 7) throw new RuntimeException("数组to的长度须为7"); - final ByteBuf buf = Unpooled.wrappedBuffer(to); - buf.readerIndex(0); - buf.writerIndex(0); - final String year = String.valueOf(from.getYear()); - buf.writeByte(Integer.valueOf(year.substring(0, 2))); - buf.writeByte(Integer.valueOf(year.substring(2))); - buf.writeByte(from.getMonthValue()); - buf.writeByte(from.getDayOfMonth()); - buf.writeByte(from.getHour()); - buf.writeByte(from.getMinute()); - buf.writeByte(from.getSecond()); + /** + * 例如,传送2001年9月21日15时29分30秒,则年、月、日、时、分、秒各单元的值分别为:20、01、9、21、15、29、30 + */ + public static void convert(final LocalDateTime from, final byte[] to) { + if (null == to || to.length != 7) { + throw new RuntimeException("数组to的长度须为7"); } - /** - * 例如,传送2001年9月21日15时29分30秒,则年、月、日、时、分、秒各单元的值分别为:20、01、9、21、15、29、30 - */ - public static byte[]convert(final LocalDateTime from){ - final byte[] to = new byte[7]; - convert(from,to); - return to; - } - /** - * 例如,传送2001年9月21日15时29分30秒,则01年、2月、3日、4时、5分、6秒各单元的值分别为:20、01、9、21、15、29、30 - */ - public static LocalDateTime convert(final byte[]from){ - if (null == from || from.length != 7) throw new RuntimeException("数组from的长度须为7"); - final int year = Integer.valueOf(String.format("%s%s",String.format("%d",from[0]),String.format("%02d",from[1]))); - final int month = from[2]; - final int day = from[3]; - final int hour = from[4]; - final int minute = from[5]; - final int second = from[6]; - return LocalDateTime.of(year,month,day,hour,minute,second); + final ByteBuf buf = Unpooled.wrappedBuffer(to); + buf.readerIndex(0); + buf.writerIndex(0); + final String year = String.valueOf(from.getYear()); + buf.writeByte(Integer.valueOf(year.substring(0, 2))); + buf.writeByte(Integer.valueOf(year.substring(2))); + buf.writeByte(from.getMonthValue()); + buf.writeByte(from.getDayOfMonth()); + buf.writeByte(from.getHour()); + buf.writeByte(from.getMinute()); + buf.writeByte(from.getSecond()); + } + + /** + * 例如,传送2001年9月21日15时29分30秒,则年、月、日、时、分、秒各单元的值分别为:20、01、9、21、15、29、30 + */ + public static byte[] convert(final LocalDateTime from) { + final byte[] to = new byte[7]; + convert(from, to); + return to; + } + + public static LocalDateTime convert(ByteBuf buf) { + byte[] data = new byte[7]; + buf.readBytes(data); + return convert(data); + } + + /** + * 例如,传送2001年9月21日15时29分30秒,则01年、2月、3日、4时、5分、6秒各单元的值分别为:20、01、9、21、15、29、30 + */ + public static LocalDateTime convert(final byte[] from) { + if (null == from || from.length != 7) { + throw new RuntimeException("数组from的长度须为7"); } + final int year = Integer.valueOf(String.format("%s%s", String.format("%d", from[0]), String.format("%02d", from[1]))); + final int month = from[2]; + final int day = from[3]; + final int hour = from[4]; + final int minute = from[5]; + final int second = from[6]; + return LocalDateTime.of(year, month, day, hour, minute, second); + } } diff --git a/src/main/java/club/joylink/xiannccda/ats/message/rep/ActionReportResponse.java b/src/main/java/club/joylink/xiannccda/ats/message/rep/ActionReportResponse.java index 8778300..dbce519 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/rep/ActionReportResponse.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/rep/ActionReportResponse.java @@ -1,8 +1,11 @@ package club.joylink.xiannccda.ats.message.rep; +import club.joylink.xiannccda.ats.message.MessageData; 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 io.netty.buffer.ByteBuf; +import java.time.LocalDateTime; import java.util.List; /** @@ -49,14 +52,6 @@ public class ActionReportResponse extends MessageResponse { this.entityList = EntityParseUtil.collect(this.count, buf, ActionReportEntity.class); } - public enum ActionSiteEnum { - STATION(0x01), CENTER(0x02), UNKNOW(0x00); - int val; - - ActionSiteEnum(int b) { - this.val = b; - } - } public static class ActionReportEntity implements ReadData { @@ -69,7 +64,7 @@ public class ActionReportResponse extends MessageResponse { *

* 0x00:未知 */ - private Byte actionSite; + private ReportSiteEnum actionSite; /** * 单位编码(2) *

@@ -87,7 +82,7 @@ public class ActionReportResponse extends MessageResponse { /** * 命令发送时的系统时间(7),以数字表示年、月、日、时、分、秒 */ - private DateTime actionTime; + private LocalDateTime actionTime; /** * 事件/告警对应的操作员名称(20) */ @@ -97,7 +92,7 @@ public class ActionReportResponse extends MessageResponse { *

* 注:西安3号线的操作命令无操作类型(Action_type)区分,将按照统一的操作类型(Action_type)发送。 */ - private Short actionType; + private ActionTypeControlEnum actionType; /** * 操作子类型,预留(2) */ @@ -115,13 +110,14 @@ public class ActionReportResponse extends MessageResponse { public ActionReportEntity read(ByteBuf buf) { ActionReportEntity entity = new ActionReportEntity(); - entity.actionSite = buf.readByte(); + entity.actionSite = MessageData.ReportSiteEnum.of(buf.readByte()); + entity.actionSiteid = buf.readShort(); buf.readBytes(entity.actionName); - entity.actionTime = new DateTime(buf); + entity.actionTime = DateTimeUtil.convert(buf); buf.readBytes(entity.actionUser); - entity.actionType = buf.readShort(); + entity.actionType = ActionTypeControlEnum.of(buf.readShort()); entity.actionSubType = buf.readShort(); entity.atctionLen = buf.readShort(); entity.actionContent = new byte[entity.atctionLen]; diff --git a/src/main/java/club/joylink/xiannccda/ats/message/rep/AlarmReportResponse.java b/src/main/java/club/joylink/xiannccda/ats/message/rep/AlarmReportResponse.java index 124738f..8b42995 100644 --- a/src/main/java/club/joylink/xiannccda/ats/message/rep/AlarmReportResponse.java +++ b/src/main/java/club/joylink/xiannccda/ats/message/rep/AlarmReportResponse.java @@ -2,8 +2,10 @@ package club.joylink.xiannccda.ats.message.rep; 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 io.netty.buffer.ByteBuf; +import java.time.LocalDateTime; import java.util.List; /** @@ -64,7 +66,7 @@ public class AlarmReportResponse extends MessageResponse { *

* 0x00:未知 */ - private Byte alamrSite; + private ReportSiteEnum alamrSite; /** * 单位编码(2) *

@@ -82,7 +84,7 @@ public class AlarmReportResponse extends MessageResponse { /** * 报警发送时的系统时间,以数字表示年、月、日、时、分、秒(7) */ - private DateTime alarmTime; + private LocalDateTime alarmTime; /** * 报警类型,详见附录“报警类型定义”(2) *

@@ -116,16 +118,16 @@ public class AlarmReportResponse extends MessageResponse { /** * 确认时间 */ - private DateTime alarmAckTime; + private LocalDateTime alarmAckTime; @Override public AlarmReportEntity read(ByteBuf buf) { AlarmReportEntity entity = new AlarmReportEntity(); - entity.alamrSite = buf.readByte(); + entity.alamrSite = ReportSiteEnum.of(buf.readByte()); entity.alarmSiteid = buf.readShort(); buf.readBytes(entity.alarmNname); - entity.alarmTime = new DateTime(buf); + entity.alarmTime = DateTimeUtil.convert(buf); entity.alarmType = buf.readShort(); entity.alarmSubType = buf.readShort(); entity.alarmLen = buf.readShort(); @@ -134,7 +136,8 @@ public class AlarmReportResponse extends MessageResponse { entity.alarmAckSiteid = buf.readShort(); buf.readBytes(entity.alarmAckSite); buf.readBytes(entity.alarmAckName); - entity.alarmAckTime = new DateTime(buf); + + entity.alarmAckTime = DateTimeUtil.convert(buf); return entity; } }