现场调试修改

This commit is contained in:
tiger_zhou 2024-01-15 09:18:40 +08:00
parent 60f1725f8a
commit b04ea364c6
9 changed files with 99 additions and 29 deletions

View File

@ -60,9 +60,7 @@ public class FrameSchemaParse {
private static void messageDecode(ByteBuf buf, List<MessageData> messages) throws Exception { private static void messageDecode(ByteBuf buf, List<MessageData> messages) throws Exception {
int len = buf.getUnsignedShort(0); int len = buf.getUnsignedShort(0);
byte[] msgData = new byte[len + 2]; byte[] msgData = new byte[len + 2];
// ByteBuf msgBuf =
buf.readBytes(msgData); buf.readBytes(msgData);
ByteBuf msgBuf = Unpooled.wrappedBuffer(msgData); ByteBuf msgBuf = Unpooled.wrappedBuffer(msgData);
int msgId = msgBuf.getUnsignedShort(8); int msgId = msgBuf.getUnsignedShort(8);
@ -88,7 +86,7 @@ public class FrameSchemaParse {
inByteBuf.markReaderIndex(); inByteBuf.markReaderIndex();
int totalReadables = inByteBuf.readableBytes(); int totalReadables = inByteBuf.readableBytes();
if (totalReadables < 4) { if (totalReadables < 4) {
inByteBuf.resetReaderIndex(); // inByteBuf.resetReaderIndex();
log.error("数据不全,当前可读[{}]", totalReadables); log.error("数据不全,当前可读[{}]", totalReadables);
return false; return false;
} }
@ -102,10 +100,9 @@ public class FrameSchemaParse {
log.error("可读内容不足 sysId[{}] totalLen[{}] flag[{}] contentLen[{}] readableBytes[{}]", sysId, totalLength, flag, contentLen, readables); log.error("可读内容不足 sysId[{}] totalLen[{}] flag[{}] contentLen[{}] readableBytes[{}]", sysId, totalLength, flag, contentLen, readables);
return false; return false;
} }
byte[] bb = new byte[contentLen]; // byte[] bb = new byte[contentLen];
inByteBuf.readBytes(bb); // inByteBuf.readBytes(bb);
packageData.writeBytes(inByteBuf); packageData.writeBytes(inByteBuf, contentLen);
// packageData.writeBytes(inByteBuf, contentLen);
return flag != Flag_Multi; return flag != Flag_Multi;
} }
} }

View File

@ -4,13 +4,19 @@ import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest;
import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest.ApplyTypeEnum; import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest.ApplyTypeEnum;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import lombok.Getter; import lombok.Getter;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import oshi.SystemInfo;
import oshi.hardware.CentralProcessor;
import oshi.hardware.GlobalMemory;
@Slf4j @Slf4j
public class XianOccMessagingClient { public class XianOccMessagingClient {
@ -93,6 +99,7 @@ public class XianOccMessagingClient {
* 连接OCC服务 * 连接OCC服务
*/ */
public void connect(boolean monitorHandwareChange) { public void connect(boolean monitorHandwareChange) {
this.timeOutHandler.monitorHandwareChange = monitorHandwareChange;
this.timeOutHandler.start(); this.timeOutHandler.start();
} }
@ -120,15 +127,18 @@ public class XianOccMessagingClient {
static ScheduledExecutorService Executor = Executors.newSingleThreadScheduledExecutor(); static ScheduledExecutorService Executor = Executors.newSingleThreadScheduledExecutor();
private final LinkedList<OccTcpClientConnection> clientConnections = new LinkedList<>(); private final LinkedList<OccTcpClientConnection> clientConnections = new LinkedList<>();
private final SystemInfo systemInfo;
// private long[] ticks; private boolean monitorHandwareChange;
private long[] ticks;
public void shutdown() { public void shutdown() {
Executor.shutdownNow(); Executor.shutdownNow();
} }
public ConnectionTimeOutHandler() { public ConnectionTimeOutHandler() {
// this.systemInfo = new SystemInfo(); this.systemInfo = new SystemInfo();
if (Executor.isShutdown()) { if (Executor.isShutdown()) {
Executor = Executors.newSingleThreadScheduledExecutor(); Executor = Executors.newSingleThreadScheduledExecutor();
} }
@ -138,15 +148,46 @@ public class XianOccMessagingClient {
this.clientConnections.add(conn); this.clientConnections.add(conn);
} }
private String hardWareUserInfo() {
CentralProcessor cpu = systemInfo.getHardware().getProcessor();
GlobalMemory memory = systemInfo.getHardware().getMemory();
if (Objects.isNull(ticks)) {
ticks = cpu.getSystemCpuLoadTicks();
} else {
double d2 = cpu.getSystemCpuLoadBetweenTicks(ticks);
ticks = cpu.getSystemCpuLoadTicks();
long totalMemory = memory.getTotal();
long availableMemory = memory.getAvailable();
long usedMemory = totalMemory - availableMemory;
return String.format("当前CPU使用:%d%% 内存总内存:%s(MB) 使用:%s(MB) 可用:%s(MB)", Math.round(d2 * 100), (totalMemory / 1024 / 1024), (usedMemory / 1024 / 1024),
(availableMemory / 1024 / 1024));
}
return null;
/* GlobalMemory memory = systemInfo.getHardware().getMemory();
long totalMemory = memory.getTotal();
long availableMemory = memory.getAvailable();
long usedMemory = totalMemory - availableMemory;
if (Objects.isNull(this.osProcess)) {
return String.format("内存总内存:%s(MB) 使用:%s(MB) 可用:%s(MB)", (totalMemory / 1024 / 1024), (usedMemory / 1024 / 1024),
(availableMemory / 1024 / 1024));
} else {
OSProcess osp = this.systemInfo.getOperatingSystem().getProcess(this.processId);
double d2 = this.osProcess.getProcessCpuLoadBetweenTicks(osp);
return String.format("当前CPU使用:%d%% 内存总内存:%s(MB) 使用:%s(MB) 可用:%s(MB)", Math.round(d2 * 100), (totalMemory / 1024 / 1024), (usedMemory / 1024 / 1024),
(availableMemory / 1024 / 1024));
}*/
}
public void start() { public void start() {
Executor.scheduleWithFixedDelay(() -> { Executor.scheduleWithFixedDelay(() -> {
/* if (this.monitorHandwareChange) { if (this.monitorHandwareChange) {
String moitorContent = this.hardWareUserInfo(); String moitorContent = this.hardWareUserInfo();
if (StringUtils.isNotEmpty(moitorContent)) { if (StringUtils.isNotEmpty(moitorContent)) {
log.info(moitorContent); log.info(moitorContent);
} }
}*/ }
for (OccTcpClientConnection cc : this.clientConnections) { for (OccTcpClientConnection cc : this.clientConnections) {
if (cc.connected) { if (cc.connected) {
long ctm = System.currentTimeMillis(); long ctm = System.currentTimeMillis();

View File

@ -26,9 +26,13 @@ public class PlanScheduleConvertor extends DefaultConvertor {
@Override @Override
protected void runBefore(List<Builder> builders) { protected void runBefore(List<Builder> builders) {
for (Builder builder : builders) { for (Builder builder : builders) {
if ((builder instanceof Plan.Builder plan) && (plan.getActionId() == ScheduleSubIdType.HISTORY_BEGIN.val())) { if ((builder instanceof Plan.Builder plan)
&& (plan.getActionId() == ScheduleSubIdType.HISTORY_BEGIN.val()
// || plan.getActionId() == ScheduleSubIdType.BEGIN.val()
)) {
InUsedScheduleData inUsedScheduleData = DeviceDataRepository.findDataSouce(String.valueOf(plan.getLineId()), DataTypeEnum.TRAIN_PLAN); InUsedScheduleData inUsedScheduleData = DeviceDataRepository.findDataSouce(String.valueOf(plan.getLineId()), DataTypeEnum.TRAIN_PLAN);
inUsedScheduleData.clear(); inUsedScheduleData.clear();
break;
} }
} }
} }

View File

@ -2,6 +2,7 @@ package club.joylink.xiannccda.ats.message.collect.datasource;
import club.joylink.xiannccda.dto.protos.TrainShedule.Plan; import club.joylink.xiannccda.dto.protos.TrainShedule.Plan;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.google.common.collect.HashBasedTable; import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Table; import com.google.common.collect.Table;
@ -34,13 +35,39 @@ public class InUsedScheduleData extends AbstractData {
@Override @Override
public void addDevice(List<Builder> dataList) { public void addDevice(List<Builder> dataList) {
for (Builder builder : dataList) { for (Builder builder : dataList) {
if (builder instanceof Plan.Builder planBuilder) { if (builder instanceof Plan.Builder planBuilder) {
List<Plan.Builder> bList = trainSchedule.get(planBuilder.getTrainId(), planBuilder.getGlobalId()); if (StringUtils.isNotEmpty(planBuilder.getTrainId()) && StringUtils.isNotEmpty(planBuilder.getGlobalId())) {
if (Objects.isNull(bList)) { List<Plan.Builder> bList = trainSchedule.get(planBuilder.getTrainId(), planBuilder.getGlobalId());
bList = Lists.newArrayList(); if (Objects.isNull(bList)) {
trainSchedule.put(planBuilder.getTrainId(), planBuilder.getGlobalId(), bList); bList = Lists.newArrayList();
trainSchedule.put(planBuilder.getTrainId(), planBuilder.getGlobalId(), bList);
}
if (bList.isEmpty()) {
bList.add(planBuilder);
} else {
Plan.Builder oldPlan = bList.stream()
.filter(d -> d.getStationId() == planBuilder.getStationId() && d.getUpWay() == planBuilder.getUpWay() && planBuilder.getDTime() - planBuilder.getATime() > 0).findFirst().orElse(null);
if (Objects.isNull(oldPlan)) {
bList.add(planBuilder);
} else {
oldPlan.mergeFrom(planBuilder.build());
}
/* boolean merged = false;
for (Plan.Builder oldPlan : bList) {
if (oldPlan.getStationId() == planBuilder.getStationId() && oldPlan.getUpWay() == planBuilder.getUpWay()) {
oldPlan.mergeFrom(planBuilder.build());
merged = true;
break;
}
}
if (!merged) {
bList.add(planBuilder);
}*/
}
} }
bList.add(planBuilder);
} }
} }
} }

View File

@ -12,9 +12,9 @@ import java.util.Arrays;
* 实际数据 发送 0 = 开始1=传输中2=结束 * 实际数据 发送 0 = 开始1=传输中2=结束
*/ */
public enum ScheduleSubIdType { public enum ScheduleSubIdType {
BEGIN(0X0001), // BEGIN(0X0001),
RUNING(0X0002), // RUNING(0X0002),
STOP(0X0003), // STOP(0X0003),
HISTORY_BEGIN(0), HISTORY_BEGIN(0),
HISTORY_RUN(1), HISTORY_RUN(1),
HISTORY_STOP(2), HISTORY_STOP(2),

View File

@ -28,11 +28,9 @@ public class EntityParseUtil {
public static String convertStr(ByteBuf buf, int len) { public static String convertStr(ByteBuf buf, int len) {
ByteBuf bb = buf.readBytes(len); byte[] data = new byte[len];
String str = new String(bb.array(), MessageCons.STRING_CHARSET).trim(); buf.readBytes(data);
bb.clear(); return new String(data, MessageCons.STRING_CHARSET).trim();
bb.release();
return str;
} }
public interface ReadData<T> { public interface ReadData<T> {

View File

@ -63,7 +63,7 @@ public class HistoryScheduleResponse extends MessageResponse {
this.date = DateTimeUtil.convert(buf); this.date = DateTimeUtil.convert(buf);
this.subId = ScheduleSubIdType.of(buf.readShort()); this.subId = ScheduleSubIdType.of(buf.readShort());
if (this.subId == ScheduleSubIdType.RUNING) { if (this.subId == ScheduleSubIdType.HISTORY_RUN) {
this.groupId = EntityParseUtil.convertStr(buf, 9); this.groupId = EntityParseUtil.convertStr(buf, 9);
this.recCnt = buf.readShort(); this.recCnt = buf.readShort();
this.entityList = EntityParseUtil.collect(this.recCnt, buf, HistoryScheduleEntity.class); this.entityList = EntityParseUtil.collect(this.recCnt, buf, HistoryScheduleEntity.class);

View File

@ -74,7 +74,7 @@ public class InusedScheduleResponse extends MessageResponse {
this.lineId = buf.readShort(); this.lineId = buf.readShort();
this.date = DateTimeUtil.convert(buf); this.date = DateTimeUtil.convert(buf);
this.subId = ScheduleSubIdType.of(buf.readShort()); this.subId = ScheduleSubIdType.of(buf.readShort());
if (this.subId == ScheduleSubIdType.RUNING) { if (this.subId == ScheduleSubIdType.HISTORY_RUN) {
this.trainId = EntityParseUtil.convertStr(buf, 9); this.trainId = EntityParseUtil.convertStr(buf, 9);
this.tripCnt = buf.readShort(); this.tripCnt = buf.readShort();

View File

@ -52,9 +52,12 @@ public class SwitchLostTask implements AlertMonitoringTask {
for (String lineId : lineCollSet) { for (String lineId : lineCollSet) {
DeviceStatusData deviceStatusData = DeviceDataRepository.findDataSouce(lineId, DataTypeEnum.DEVICE); DeviceStatusData deviceStatusData = DeviceDataRepository.findDataSouce(lineId, DataTypeEnum.DEVICE);
Map<String, Builder> deviceBuildMap = deviceStatusData.getAllDeviceMap().get(Switch.getDescriptor().getName()); Map<String, Builder> deviceBuildMap = deviceStatusData.getAllDeviceMap().get(Switch.getDescriptor().getName());
for (Builder deviceBuild : deviceBuildMap.values()) { if (CollectionUtils.isNotEmpty(deviceBuildMap)) {
this.handle(deviceBuild); for (Builder deviceBuild : deviceBuildMap.values()) {
this.handle(deviceBuild);
}
} }
} }
} }