非实时消息
This commit is contained in:
parent
50129e0e87
commit
61b15b4cdf
@ -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 {
|
||||
/**
|
||||
* 进路控制
|
||||
* <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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,4 +7,6 @@ public abstract class MessageResponse extends MessageData {
|
||||
@Override
|
||||
public void encode2(ByteBuf buf) {
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,9 @@ 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");
|
||||
if (null == to || to.length != 7) {
|
||||
throw new RuntimeException("数组to的长度须为7");
|
||||
}
|
||||
final ByteBuf buf = Unpooled.wrappedBuffer(to);
|
||||
buf.readerIndex(0);
|
||||
buf.writerIndex(0);
|
||||
@ -24,6 +26,7 @@ public class DateTimeUtil {
|
||||
buf.writeByte(from.getMinute());
|
||||
buf.writeByte(from.getSecond());
|
||||
}
|
||||
|
||||
/**
|
||||
* 例如,传送2001年9月21日15时29分30秒,则年、月、日、时、分、秒各单元的值分别为:20、01、9、21、15、29、30
|
||||
*/
|
||||
@ -32,11 +35,20 @@ public class DateTimeUtil {
|
||||
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");
|
||||
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];
|
||||
|
@ -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<ActionReportEntity> {
|
||||
|
||||
@ -69,7 +64,7 @@ public class ActionReportResponse extends MessageResponse {
|
||||
* <p>
|
||||
* 0x00:未知
|
||||
*/
|
||||
private Byte actionSite;
|
||||
private ReportSiteEnum actionSite;
|
||||
/**
|
||||
* 单位编码(2)
|
||||
* <p>
|
||||
@ -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 {
|
||||
* <p>
|
||||
* 注:西安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];
|
||||
|
@ -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 {
|
||||
* <p>
|
||||
* 0x00:未知
|
||||
*/
|
||||
private Byte alamrSite;
|
||||
private ReportSiteEnum alamrSite;
|
||||
/**
|
||||
* 单位编码(2)
|
||||
* <p>
|
||||
@ -82,7 +84,7 @@ public class AlarmReportResponse extends MessageResponse {
|
||||
/**
|
||||
* 报警发送时的系统时间,以数字表示年、月、日、时、分、秒(7)
|
||||
*/
|
||||
private DateTime alarmTime;
|
||||
private LocalDateTime alarmTime;
|
||||
/**
|
||||
* 报警类型,详见附录“报警类型定义”(2)
|
||||
* <p>
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user