现场调试修改
This commit is contained in:
parent
60f1725f8a
commit
b04ea364c6
@ -60,9 +60,7 @@ public class FrameSchemaParse {
|
||||
private static void messageDecode(ByteBuf buf, List<MessageData> messages) throws Exception {
|
||||
int len = buf.getUnsignedShort(0);
|
||||
byte[] msgData = new byte[len + 2];
|
||||
// ByteBuf msgBuf =
|
||||
buf.readBytes(msgData);
|
||||
|
||||
ByteBuf msgBuf = Unpooled.wrappedBuffer(msgData);
|
||||
|
||||
int msgId = msgBuf.getUnsignedShort(8);
|
||||
@ -88,7 +86,7 @@ public class FrameSchemaParse {
|
||||
inByteBuf.markReaderIndex();
|
||||
int totalReadables = inByteBuf.readableBytes();
|
||||
if (totalReadables < 4) {
|
||||
inByteBuf.resetReaderIndex();
|
||||
// inByteBuf.resetReaderIndex();
|
||||
log.error("数据不全,当前可读[{}]", totalReadables);
|
||||
return false;
|
||||
}
|
||||
@ -102,10 +100,9 @@ public class FrameSchemaParse {
|
||||
log.error("可读内容不足 sysId[{}] totalLen[{}] flag[{}] contentLen[{}] readableBytes[{}]", sysId, totalLength, flag, contentLen, readables);
|
||||
return false;
|
||||
}
|
||||
byte[] bb = new byte[contentLen];
|
||||
inByteBuf.readBytes(bb);
|
||||
packageData.writeBytes(inByteBuf);
|
||||
// packageData.writeBytes(inByteBuf, contentLen);
|
||||
// byte[] bb = new byte[contentLen];
|
||||
// inByteBuf.readBytes(bb);
|
||||
packageData.writeBytes(inByteBuf, contentLen);
|
||||
return flag != Flag_Multi;
|
||||
}
|
||||
}
|
||||
|
@ -4,13 +4,19 @@ import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest;
|
||||
import club.joylink.xiannccda.ats.message.line3.req.LoadHistoryTGDataRequest.ApplyTypeEnum;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import oshi.SystemInfo;
|
||||
import oshi.hardware.CentralProcessor;
|
||||
import oshi.hardware.GlobalMemory;
|
||||
|
||||
@Slf4j
|
||||
public class XianOccMessagingClient {
|
||||
@ -93,6 +99,7 @@ public class XianOccMessagingClient {
|
||||
* 连接OCC服务
|
||||
*/
|
||||
public void connect(boolean monitorHandwareChange) {
|
||||
this.timeOutHandler.monitorHandwareChange = monitorHandwareChange;
|
||||
this.timeOutHandler.start();
|
||||
|
||||
}
|
||||
@ -120,15 +127,18 @@ public class XianOccMessagingClient {
|
||||
|
||||
static ScheduledExecutorService Executor = Executors.newSingleThreadScheduledExecutor();
|
||||
private final LinkedList<OccTcpClientConnection> clientConnections = new LinkedList<>();
|
||||
private final SystemInfo systemInfo;
|
||||
|
||||
// private long[] ticks;
|
||||
private boolean monitorHandwareChange;
|
||||
|
||||
private long[] ticks;
|
||||
|
||||
public void shutdown() {
|
||||
Executor.shutdownNow();
|
||||
}
|
||||
|
||||
public ConnectionTimeOutHandler() {
|
||||
// this.systemInfo = new SystemInfo();
|
||||
this.systemInfo = new SystemInfo();
|
||||
if (Executor.isShutdown()) {
|
||||
Executor = Executors.newSingleThreadScheduledExecutor();
|
||||
}
|
||||
@ -138,15 +148,46 @@ public class XianOccMessagingClient {
|
||||
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() {
|
||||
Executor.scheduleWithFixedDelay(() -> {
|
||||
/* if (this.monitorHandwareChange) {
|
||||
if (this.monitorHandwareChange) {
|
||||
String moitorContent = this.hardWareUserInfo();
|
||||
if (StringUtils.isNotEmpty(moitorContent)) {
|
||||
log.info(moitorContent);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
for (OccTcpClientConnection cc : this.clientConnections) {
|
||||
if (cc.connected) {
|
||||
long ctm = System.currentTimeMillis();
|
||||
|
@ -26,9 +26,13 @@ public class PlanScheduleConvertor extends DefaultConvertor {
|
||||
@Override
|
||||
protected void runBefore(List<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.clear();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package club.joylink.xiannccda.ats.message.collect.datasource;
|
||||
|
||||
import club.joylink.xiannccda.dto.protos.TrainShedule.Plan;
|
||||
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.Lists;
|
||||
import com.google.common.collect.Table;
|
||||
@ -34,13 +35,39 @@ public class InUsedScheduleData extends AbstractData {
|
||||
@Override
|
||||
public void addDevice(List<Builder> dataList) {
|
||||
for (Builder builder : dataList) {
|
||||
|
||||
if (builder instanceof Plan.Builder planBuilder) {
|
||||
if (StringUtils.isNotEmpty(planBuilder.getTrainId()) && StringUtils.isNotEmpty(planBuilder.getGlobalId())) {
|
||||
List<Plan.Builder> bList = trainSchedule.get(planBuilder.getTrainId(), planBuilder.getGlobalId());
|
||||
if (Objects.isNull(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);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,9 +12,9 @@ import java.util.Arrays;
|
||||
* 实际数据 发送 0 = 开始,1=传输中,2=结束
|
||||
*/
|
||||
public enum ScheduleSubIdType {
|
||||
BEGIN(0X0001),
|
||||
RUNING(0X0002),
|
||||
STOP(0X0003),
|
||||
// BEGIN(0X0001),
|
||||
// RUNING(0X0002),
|
||||
// STOP(0X0003),
|
||||
HISTORY_BEGIN(0),
|
||||
HISTORY_RUN(1),
|
||||
HISTORY_STOP(2),
|
||||
|
@ -28,11 +28,9 @@ public class EntityParseUtil {
|
||||
|
||||
|
||||
public static String convertStr(ByteBuf buf, int len) {
|
||||
ByteBuf bb = buf.readBytes(len);
|
||||
String str = new String(bb.array(), MessageCons.STRING_CHARSET).trim();
|
||||
bb.clear();
|
||||
bb.release();
|
||||
return str;
|
||||
byte[] data = new byte[len];
|
||||
buf.readBytes(data);
|
||||
return new String(data, MessageCons.STRING_CHARSET).trim();
|
||||
}
|
||||
|
||||
public interface ReadData<T> {
|
||||
|
@ -63,7 +63,7 @@ public class HistoryScheduleResponse extends MessageResponse {
|
||||
this.date = DateTimeUtil.convert(buf);
|
||||
this.subId = ScheduleSubIdType.of(buf.readShort());
|
||||
|
||||
if (this.subId == ScheduleSubIdType.RUNING) {
|
||||
if (this.subId == ScheduleSubIdType.HISTORY_RUN) {
|
||||
this.groupId = EntityParseUtil.convertStr(buf, 9);
|
||||
this.recCnt = buf.readShort();
|
||||
this.entityList = EntityParseUtil.collect(this.recCnt, buf, HistoryScheduleEntity.class);
|
||||
|
@ -74,7 +74,7 @@ public class InusedScheduleResponse extends MessageResponse {
|
||||
this.lineId = buf.readShort();
|
||||
this.date = DateTimeUtil.convert(buf);
|
||||
this.subId = ScheduleSubIdType.of(buf.readShort());
|
||||
if (this.subId == ScheduleSubIdType.RUNING) {
|
||||
if (this.subId == ScheduleSubIdType.HISTORY_RUN) {
|
||||
|
||||
this.trainId = EntityParseUtil.convertStr(buf, 9);
|
||||
this.tripCnt = buf.readShort();
|
||||
|
@ -52,10 +52,13 @@ public class SwitchLostTask implements AlertMonitoringTask {
|
||||
for (String lineId : lineCollSet) {
|
||||
DeviceStatusData deviceStatusData = DeviceDataRepository.findDataSouce(lineId, DataTypeEnum.DEVICE);
|
||||
Map<String, Builder> deviceBuildMap = deviceStatusData.getAllDeviceMap().get(Switch.getDescriptor().getName());
|
||||
if (CollectionUtils.isNotEmpty(deviceBuildMap)) {
|
||||
for (Builder deviceBuild : deviceBuildMap.values()) {
|
||||
this.handle(deviceBuild);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void handle(Builder deviceBuild) {
|
||||
|
Loading…
Reference in New Issue
Block a user