|
|
@@ -3,19 +3,18 @@ package com.tsi.comm.server.protocol;
|
|
|
import com.tsi.comm.server.dto.TsiCvimAbnormal;
|
|
|
import com.tsi.comm.server.dto.TsiCvimControl;
|
|
|
import com.tsi.comm.server.dto.TsiCvimStatus;
|
|
|
+import com.tsi.comm.server.dto.mongodb.TcsNodeStatus;
|
|
|
import com.tsi.comm.server.protocol.enums.eLightsStatus;
|
|
|
import com.tsi.comm.server.protocol.enums.eLightsType;
|
|
|
import com.tsi.comm.server.protocol.enums.eOpCode;
|
|
|
import com.tsi.comm.server.protocol.enums.eTimeReliability;
|
|
|
-import com.tsi.comm.server.xnet.NettyUtils;
|
|
|
-import com.tsi.comm.server.dto.mongodb.TcsNodeStatus;
|
|
|
+import com.tsi.comm.server.repository.TsiAlarmManager;
|
|
|
import com.tsi.comm.server.repository.TsiNodeAddManager;
|
|
|
import com.tsi.comm.server.vo.TsiNodeAddDetailVo;
|
|
|
import com.tsi.comm.server.vo.TsiNodeAddVo;
|
|
|
import com.tsi.comm.server.vo.TsiNodeVo;
|
|
|
import com.tsi.common.utils.ByteUtils;
|
|
|
import com.tsi.common.utils.CRC16Utils;
|
|
|
-import io.netty.channel.Channel;
|
|
|
import lombok.Getter;
|
|
|
import lombok.Setter;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
@@ -33,6 +32,7 @@ import static com.tsi.comm.server.protocol.TsiCvibProtocolSpec.*;
|
|
|
public class TsiCpuPacket extends AbstractTsiPacket {
|
|
|
|
|
|
protected static TsiNodeAddManager nodeAddManager;
|
|
|
+ protected static TsiAlarmManager alarmAddManager;
|
|
|
|
|
|
private Object obj;
|
|
|
private int length;
|
|
|
@@ -44,19 +44,16 @@ public class TsiCpuPacket extends AbstractTsiPacket {
|
|
|
|
|
|
protected List<TsiCpuAddPacket> addNodes;
|
|
|
|
|
|
- public static void setNodeAddManager(TsiNodeAddManager nodeAddManager) {
|
|
|
+ public static void setNodeAddManager(TsiNodeAddManager nodeAddManager, TsiAlarmManager alarmAddManager) {
|
|
|
TsiCpuPacket.nodeAddManager = nodeAddManager;
|
|
|
+ TsiCpuPacket.alarmAddManager = alarmAddManager;
|
|
|
}
|
|
|
|
|
|
- public TsiCpuPacket(long nodeId, long msec, long nsec, Channel channel) {
|
|
|
- super(nodeId, msec, nsec, NettyUtils.getRemoteIpAddressToLong(channel), NettyUtils.getRemotePort(channel));
|
|
|
+ public TsiCpuPacket(long nodeId, long msec, long nsec, long remoteIpAddress, int remotePort) {
|
|
|
+ super(nodeId, msec, nsec, remoteIpAddress, remotePort);
|
|
|
setOpCode(eOpCode.TSI_CPU_SIGNAL_NOTIFY.getValue());
|
|
|
}
|
|
|
|
|
|
- public TsiCpuPacket(long nodeId, long msec, long nsec, long remoteIpAddressToLong, int remotePort) {
|
|
|
- super(nodeId, msec, nsec, remoteIpAddressToLong, remotePort);
|
|
|
- }
|
|
|
-
|
|
|
// FOR CVIM packet
|
|
|
// public TsiCpuPacket(long nodeId, byte[] value) {
|
|
|
// super(nodeId, TimeUtils.currentTimeSeconds(), System.nanoTime(), 0, 0);
|
|
|
@@ -102,7 +99,6 @@ public class TsiCpuPacket extends AbstractTsiPacket {
|
|
|
if (packetLength > 0) {
|
|
|
System.arraycopy(this.buf, 0, this.cvimData, POS_IPC_PACKET, packetLength);
|
|
|
}
|
|
|
- //log.error("CVIM: {}", HexString.fromBytes(this.cvimData));
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -136,8 +132,13 @@ public class TsiCpuPacket extends AbstractTsiPacket {
|
|
|
|
|
|
protected int checkPacket(TsiNodeVo obj, boolean checkCrc) {
|
|
|
|
|
|
+ if (this.buf == null) {
|
|
|
+ log.error("parsing: errno(-1), NodeId: {}, buf==null", this.nodeId);
|
|
|
+ return -1;
|
|
|
+ }
|
|
|
// 0 단계. STX1, STX2 체크
|
|
|
if (this.buf[INDEX_STX1] != STX1 || this.buf[INDEX_STX2] != STX2) {
|
|
|
+ TsiCpuPacket.alarmAddManager.reportPacketError(this.nodeId, this.buf, "STX", (int)(this.buf[INDEX_STX1] & 0xFF), (int)(this.buf[INDEX_STX2] & 0xFF));
|
|
|
log.error("parsing: errno(-1), NodeId: {}, stx1: {}, stx2: {}", this.nodeId, this.buf[INDEX_STX1], this.buf[INDEX_STX2]);
|
|
|
return -1;
|
|
|
}
|
|
|
@@ -153,6 +154,7 @@ public class TsiCpuPacket extends AbstractTsiPacket {
|
|
|
// }
|
|
|
final int reqLength = SIZE_PACKET_DATA + (SIZE_STATUS_DATA * this.count);
|
|
|
if (this.length < reqLength ) {
|
|
|
+ TsiCpuPacket.alarmAddManager.reportPacketError(this.nodeId, this.buf, "LENGTH", reqLength, this.length);
|
|
|
log.error("parsing: errno(-2), NodeId: {}, reqLength: {}, recvLength: {}", this.nodeId, reqLength, this.length);
|
|
|
return -2;
|
|
|
}
|
|
|
@@ -161,6 +163,7 @@ public class TsiCpuPacket extends AbstractTsiPacket {
|
|
|
final int receivedCrc = ByteUtils.getUnsignedShort(this.buf, this.buf.length-2);
|
|
|
final int calculatedCrc = CRC16Utils.CRC16_ccitt_cvim(this.buf, INDEX_LENGTH, this.length-2); // 시작인덱스가 있으므로 전체길이로 계산
|
|
|
if (receivedCrc != calculatedCrc) {
|
|
|
+ TsiCpuPacket.alarmAddManager.reportCrcError(this.nodeId, this.buf, receivedCrc, calculatedCrc);
|
|
|
if (checkCrc || (obj != null && obj.isDump())) {
|
|
|
log.error("parsing: errno(-3), NodeId: {}, crc(recv/calc): {}/{}", this.nodeId, receivedCrc, calculatedCrc);
|
|
|
}
|
|
|
@@ -183,20 +186,17 @@ public class TsiCpuPacket extends AbstractTsiPacket {
|
|
|
|
|
|
obj.setSigCount(this.count); // 신호현시 갯수 저장
|
|
|
|
|
|
- // CVIM 데이터 및 TEST 데이터가 생성됨
|
|
|
- makeCvimPacket();
|
|
|
-
|
|
|
int result = checkPacket(obj, isCheckPacket);
|
|
|
if (0 != result) {
|
|
|
- if (-3 == result) {
|
|
|
- obj.setCrcError(true);
|
|
|
- }
|
|
|
if (isCheckPacket) {
|
|
|
// 20250425: CRC 체크여부에 따라 바로 리턴(기본값은 체크여부가 true 임)
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // CVIM 데이터 및 TEST 데이터가 생성됨
|
|
|
+ makeCvimPacket();
|
|
|
+
|
|
|
TsiNodeAddVo tsiNodeAddVo = TsiCpuPacket.nodeAddManager.get(this.nodeId);
|
|
|
if (tsiNodeAddVo == null) {
|
|
|
// 연등지 정보가 없는 경우
|
|
|
@@ -249,9 +249,11 @@ public class TsiCpuPacket extends AbstractTsiPacket {
|
|
|
// 연등지 방향코드를 배열에 가지고 있기 때문에
|
|
|
List<byte[]> list = addStatus.get(detailVo.getNodeId());
|
|
|
if (list == null) {
|
|
|
+ // 최초 데이터가 없을수 있기 때문에 null 을 체크한다.
|
|
|
list = new ArrayList<>();
|
|
|
addStatus.put(detailVo.getNodeId(), list);
|
|
|
}
|
|
|
+
|
|
|
if (dirIdx == 0) {
|
|
|
status[INDEX_STATUS_DIRECTION] = detailVo.getAddDirCode()[dirIdx];
|
|
|
list.add(status);
|