非实时消息

This commit is contained in:
tiger_zhou 2023-06-08 13:09:16 +08:00
parent 50129e0e87
commit 61b15b4cdf
5 changed files with 120 additions and 56 deletions

View File

@ -4,6 +4,7 @@ import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
@ -126,7 +127,57 @@ public abstract class MessageData {
return new DateTime(LocalDateTime.now()); 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 {
/**
* 进路控制
* <p>
* 包括进路排列引导进路办理进路取消进路人解等操作
*/
ROUTE(0X01),
/**
* 信号控制
* <p>
* 包括道岔操作区段操作信号机操作站台操作等
*/
SIGNAL(0X02),
/**
* 列车管理
* <p>
* 包括列车识别号操作列车控制操作等
*/
TRAIN(0X03),
/**
* 计划管理
* <p>
* 包括在线计划管理操作等
*/
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);
}
}
} }

View File

@ -7,4 +7,6 @@ public abstract class MessageResponse extends MessageData {
@Override @Override
public void encode2(ByteBuf buf) { public void encode2(ByteBuf buf) {
} }
} }

View File

@ -7,42 +7,54 @@ import java.time.LocalDateTime;
public class DateTimeUtil { public class DateTimeUtil {
/** /**
* 例如传送2001年9月21日15时29分30秒则年秒各单元的值分别为2001921152930 * 例如传送2001年9月21日15时29分30秒则年秒各单元的值分别为2001921152930
*/ */
public static void convert(final LocalDateTime from, final byte[] to) { public static void convert(final LocalDateTime from, final byte[] to) {
if (null == to || to.length != 7) throw new RuntimeException("数组to的长度须为7"); if (null == to || to.length != 7) {
final ByteBuf buf = Unpooled.wrappedBuffer(to); throw new RuntimeException("数组to的长度须为7");
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());
} }
/** final ByteBuf buf = Unpooled.wrappedBuffer(to);
* 例如传送2001年9月21日15时29分30秒则年秒各单元的值分别为2001921152930 buf.readerIndex(0);
*/ buf.writerIndex(0);
public static byte[]convert(final LocalDateTime from){ final String year = String.valueOf(from.getYear());
final byte[] to = new byte[7]; buf.writeByte(Integer.valueOf(year.substring(0, 2)));
convert(from,to); buf.writeByte(Integer.valueOf(year.substring(2)));
return to; buf.writeByte(from.getMonthValue());
} buf.writeByte(from.getDayOfMonth());
/** buf.writeByte(from.getHour());
* 例如传送2001年9月21日15时29分30秒则01年2月3日4时5分6秒各单元的值分别为2001921152930 buf.writeByte(from.getMinute());
*/ buf.writeByte(from.getSecond());
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]; * 例如传送2001年9月21日15时29分30秒则年秒各单元的值分别为2001921152930
final int day = from[3]; */
final int hour = from[4]; public static byte[] convert(final LocalDateTime from) {
final int minute = from[5]; final byte[] to = new byte[7];
final int second = from[6]; convert(from, to);
return LocalDateTime.of(year,month,day,hour,minute,second); 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秒各单元的值分别为2001921152930
*/
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);
}
} }

View File

@ -1,8 +1,11 @@
package club.joylink.xiannccda.ats.message.rep; 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.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.EntityParseUtil.ReadData;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
/** /**
@ -49,14 +52,6 @@ public class ActionReportResponse extends MessageResponse {
this.entityList = EntityParseUtil.collect(this.count, buf, ActionReportEntity.class); 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<ActionReportEntity> { public static class ActionReportEntity implements ReadData<ActionReportEntity> {
@ -69,7 +64,7 @@ public class ActionReportResponse extends MessageResponse {
* <p> * <p>
* 0x00未知 * 0x00未知
*/ */
private Byte actionSite; private ReportSiteEnum actionSite;
/** /**
* 单位编码(2) * 单位编码(2)
* <p> * <p>
@ -87,7 +82,7 @@ public class ActionReportResponse extends MessageResponse {
/** /**
* 命令发送时的系统时间(7)以数字表示年 * 命令发送时的系统时间(7)以数字表示年
*/ */
private DateTime actionTime; private LocalDateTime actionTime;
/** /**
* 事件/告警对应的操作员名称(20) * 事件/告警对应的操作员名称(20)
*/ */
@ -97,7 +92,7 @@ public class ActionReportResponse extends MessageResponse {
* <p> * <p>
* 西安3号线的操作命令无操作类型Action_type区分将按照统一的操作类型Action_type发送 * 西安3号线的操作命令无操作类型Action_type区分将按照统一的操作类型Action_type发送
*/ */
private Short actionType; private ActionTypeControlEnum actionType;
/** /**
* 操作子类型预留(2) * 操作子类型预留(2)
*/ */
@ -115,13 +110,14 @@ public class ActionReportResponse extends MessageResponse {
public ActionReportEntity read(ByteBuf buf) { public ActionReportEntity read(ByteBuf buf) {
ActionReportEntity entity = new ActionReportEntity(); ActionReportEntity entity = new ActionReportEntity();
entity.actionSite = buf.readByte(); entity.actionSite = MessageData.ReportSiteEnum.of(buf.readByte());
entity.actionSiteid = buf.readShort(); entity.actionSiteid = buf.readShort();
buf.readBytes(entity.actionName); buf.readBytes(entity.actionName);
entity.actionTime = new DateTime(buf); entity.actionTime = DateTimeUtil.convert(buf);
buf.readBytes(entity.actionUser); buf.readBytes(entity.actionUser);
entity.actionType = buf.readShort(); entity.actionType = ActionTypeControlEnum.of(buf.readShort());
entity.actionSubType = buf.readShort(); entity.actionSubType = buf.readShort();
entity.atctionLen = buf.readShort(); entity.atctionLen = buf.readShort();
entity.actionContent = new byte[entity.atctionLen]; entity.actionContent = new byte[entity.atctionLen];

View File

@ -2,8 +2,10 @@ package club.joylink.xiannccda.ats.message.rep;
import club.joylink.xiannccda.ats.message.MessageId; import club.joylink.xiannccda.ats.message.MessageId;
import club.joylink.xiannccda.ats.message.MessageResponse; 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.EntityParseUtil.ReadData;
import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBuf;
import java.time.LocalDateTime;
import java.util.List; import java.util.List;
/** /**
@ -64,7 +66,7 @@ public class AlarmReportResponse extends MessageResponse {
* <p> * <p>
* 0x00未知 * 0x00未知
*/ */
private Byte alamrSite; private ReportSiteEnum alamrSite;
/** /**
* 单位编码(2) * 单位编码(2)
* <p> * <p>
@ -82,7 +84,7 @@ public class AlarmReportResponse extends MessageResponse {
/** /**
* 报警发送时的系统时间以数字表示年(7) * 报警发送时的系统时间以数字表示年(7)
*/ */
private DateTime alarmTime; private LocalDateTime alarmTime;
/** /**
* 报警类型详见附录报警类型定义(2) * 报警类型详见附录报警类型定义(2)
* <p> * <p>
@ -116,16 +118,16 @@ public class AlarmReportResponse extends MessageResponse {
/** /**
* 确认时间 * 确认时间
*/ */
private DateTime alarmAckTime; private LocalDateTime alarmAckTime;
@Override @Override
public AlarmReportEntity read(ByteBuf buf) { public AlarmReportEntity read(ByteBuf buf) {
AlarmReportEntity entity = new AlarmReportEntity(); AlarmReportEntity entity = new AlarmReportEntity();
entity.alamrSite = buf.readByte(); entity.alamrSite = ReportSiteEnum.of(buf.readByte());
entity.alarmSiteid = buf.readShort(); entity.alarmSiteid = buf.readShort();
buf.readBytes(entity.alarmNname); buf.readBytes(entity.alarmNname);
entity.alarmTime = new DateTime(buf); entity.alarmTime = DateTimeUtil.convert(buf);
entity.alarmType = buf.readShort(); entity.alarmType = buf.readShort();
entity.alarmSubType = buf.readShort(); entity.alarmSubType = buf.readShort();
entity.alarmLen = buf.readShort(); entity.alarmLen = buf.readShort();
@ -134,7 +136,8 @@ public class AlarmReportResponse extends MessageResponse {
entity.alarmAckSiteid = buf.readShort(); entity.alarmAckSiteid = buf.readShort();
buf.readBytes(entity.alarmAckSite); buf.readBytes(entity.alarmAckSite);
buf.readBytes(entity.alarmAckName); buf.readBytes(entity.alarmAckName);
entity.alarmAckTime = new DateTime(buf);
entity.alarmAckTime = DateTimeUtil.convert(buf);
return entity; return entity;
} }
} }