瀏覽代碼

refactoring class member variables

shjung 6 天之前
父節點
當前提交
c1e15d5963

+ 0 - 1
conf/tsi-comm-server.pid

@@ -1 +0,0 @@
-20930

+ 3 - 5
tsi-comm-server/src/main/java/com/tsi/comm/server/kafka/KafkaProducerService.java

@@ -2,15 +2,14 @@ package com.tsi.comm.server.kafka;
 
 import com.tsi.comm.server.config.TsiCvimServerConfig;
 import com.tsi.comm.server.config.TsiKafkaProducerConfig;
-import com.tsi.comm.server.vo.mariadb.AbstractDbmsVo;
-import com.tsi.comm.server.vo.mariadb.AlarmOccrVo;
-import com.tsi.comm.server.vo.mariadb.KafkaTransVo;
 import com.tsi.comm.server.process.dbms.TsiCvimDbmsProcess;
 import com.tsi.comm.server.repository.TsiAlarmManager;
 import com.tsi.comm.server.repository.TsiTpmsManager;
 import com.tsi.comm.server.vo.TsiAlarmConfigVo;
+import com.tsi.comm.server.vo.mariadb.AbstractDbmsVo;
+import com.tsi.comm.server.vo.mariadb.AlarmOccrVo;
+import com.tsi.comm.server.vo.mariadb.KafkaTransVo;
 import com.tsi.common.utils.TimeUtils;
-import io.netty.buffer.ByteBufUtil;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.kafka.clients.producer.ProducerConfig;
@@ -199,7 +198,6 @@ public class KafkaProducerService {
     public void sendNode(String key, byte[] data) {
         if (this.nodeProducer != null) {
             try {
-                ByteBufUtil.getBytes()
                 this.nodeProducer.send(key, key, data);
             }
             catch (Exception e) {

+ 9 - 30
tsi-comm-server/src/main/java/com/tsi/comm/server/process/packet/TsiCvimPacketWorker.java

@@ -5,10 +5,7 @@ import com.tsi.comm.server.config.TsiCvimServerConfig;
 import com.tsi.comm.server.kafka.KafkaProducerService;
 import com.tsi.comm.server.process.AbstractTsiCvimWorker;
 import com.tsi.comm.server.process.logging.TsiCvimLoggingProcess;
-import com.tsi.comm.server.protocol.AbstractTsiPacket;
-import com.tsi.comm.server.protocol.TsiCpuAddPacket;
-import com.tsi.comm.server.protocol.TsiCpuDisconnected;
-import com.tsi.comm.server.protocol.TsiCpuPacket;
+import com.tsi.comm.server.protocol.*;
 import com.tsi.comm.server.protocol.enums.eOpCode;
 import com.tsi.comm.server.vo.TsiNodeVo;
 import com.tsi.common.spring.SpringUtils;
@@ -216,37 +213,18 @@ public class TsiCvimPacketWorker extends AbstractTsiCvimWorker implements Runnab
                 return false; // 패킷 버퍼가 null 이거나 너무 짧은 경우
             }
 
-            long nodeId = nodeVo.getNodeId();
-            int reqLength = TsiCpuPacket.SIZE_PACKET_DATA + (TsiCpuPacket.SIZE_STATUS_DATA * cpuPacket.getCount());
-            byte stx1 = 0x00, stx2 = 0x00, version = 0x00;
             if (cpuPacket.getBuf() != null) {
+                byte version = 0x00;
                 byte[] buf = cpuPacket.getBuf();
-                log.error("packet parse error: {}", ByteBufUtil.hexDump(buf));
-                if (buf.length > TsiCpuPacket.INDEX_VERSION) {
-                    stx1 = buf[TsiCpuPacket.INDEX_STX1];
-                    stx2 = buf[TsiCpuPacket.INDEX_STX2];
-                    version = buf[TsiCpuPacket.INDEX_VERSION];
+                if (buf.length > TsiCvibProtocolSpec.INDEX_VERSION) {
+                    version = buf[TsiCvibProtocolSpec.INDEX_VERSION];
                 }
-            }
-
-            switch (result) {
-                case -1:
-                    log.error("Node: {}, STX Error: {}, {}", nodeId, stx1, stx2);
-                    break;
-                case -2:
-                    log.error("Node: {}, Length Error: {}, Version: {}, status count: {}, {}", nodeId, cpuPacket.getLength(), version,
-                            cpuPacket.getCount(), reqLength);
-                    break;
-                case -3:
-                    log.error("Node: {}, Check Sum Error: Version: {}, recv: {}, calc: {}", nodeId, version, cpuPacket.getCheckSum(),
-                            cpuPacket.getCalcCheckSum());
-                    break;
-                default:
-                    log.error("Node: {}, Packet parsing error: {}", nodeId, result);
-                    break;
+                log.error("parsing: errno({}), NodeId: {}, version: {}", nodeVo.getNodeId(), result, version);
+                log.error("parsing: {}", ByteBufUtil.hexDump(buf));
             }
             return false;
-        } catch (Exception e) {
+        }
+        catch (Exception e) {
             log.warn("Node: {}, CPU Packet parsing error: {}, connect: {}", nodeVo.getNodeId(), Thread.currentThread().getName(), nodeVo.isConnect(), e);
             return false;
         }
@@ -317,6 +295,7 @@ public class TsiCvimPacketWorker extends AbstractTsiCvimWorker implements Runnab
                         addNodePacket.setPar(packet.getPar());
                         addNodePacket.setEnd(packet.getEnd());
                         addNodePacket.setAvg(packet.getAvg());
+
                         this.loggingProcess.add(addNodePacket, nodeVo.getLogQIdx());
                     }
                 }

+ 13 - 11
tsi-comm-server/src/main/java/com/tsi/comm/server/protocol/TsiCpuDisconnected.java

@@ -1,35 +1,33 @@
 package com.tsi.comm.server.protocol;
 
 import com.tsi.comm.server.protocol.enums.eOpCode;
-import com.tsi.comm.server.xnet.NettyUtils;
-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.spring.SpringUtils;
+import com.tsi.comm.server.xnet.NettyUtils;
 import com.tsi.common.utils.ByteUtils;
 import com.tsi.common.utils.TimeUtils;
 import io.netty.channel.Channel;
 import lombok.Getter;
 import lombok.Setter;
 
+import static com.tsi.comm.server.protocol.TsiCvibProtocolSpec.*;
+
 @Getter
 @Setter
 public class TsiCpuDisconnected extends TsiCpuPacket {
 
-    private final TsiNodeAddManager nodeAddManager;
     public TsiCpuDisconnected(long nodeId, Channel channel) {
         this(nodeId, TimeUtils.currentTimeSeconds(), System.nanoTime(), channel);
     }
+
     public TsiCpuDisconnected(long nodeId, long msec, long nsec, Channel channel) {
         super(nodeId, msec, nsec, NettyUtils.getRemoteIpAddressToLong(channel), NettyUtils.getRemotePort(channel));
         setOpCode(eOpCode.TSI_CPU_DISCONNECTED.getValue());
-        this.nodeAddManager = SpringUtils.getBean(TsiNodeAddManager.class);
     }
 
     protected void makeAddNodeCvimPaket(TsiCpuPacket cpuPacket) {
-        final int headSize = SIZE_IPC_SIZE;
-        cpuPacket.cvimData = new byte[headSize];   // ipc head only
+        cpuPacket.cvimData = new byte[SIZE_IPC_SIZE];   // ipc head only
 
         // cvim-raw header
         System.arraycopy(this.timespec.bytes(), 0, cpuPacket.cvimData, POS_IPC_TIMESPEC, SIZE_TIMESPEC);
@@ -39,13 +37,18 @@ public class TsiCpuDisconnected extends TsiCpuPacket {
         ByteUtils.setUnsignedInt(cpuPacket.cvimData, POS_IPC_NODEID, cpuPacket.nodeId);
     }
 
-    public boolean parsing(TsiNodeVo obj) {
+    public void parsing(TsiNodeVo nodeVo) {
+
+        // nodeVo.getNodeId == this.nodeId
+        if (nodeVo == null) {
+            return;
+        }
 
-        TsiNodeAddVo tsiNodeAddVo = this.nodeAddManager.get(this.nodeId);
+        TsiNodeAddVo tsiNodeAddVo = TsiCpuPacket.nodeAddManager.get(this.nodeId);
         if (tsiNodeAddVo == null) {
             // 연등지 정보가 없는 경우
             makeCvimPacket();
-            return true;
+            return;
         }
 
         // 연등지 노드 카프카 패킷 생성
@@ -55,7 +58,6 @@ public class TsiCpuDisconnected extends TsiCpuPacket {
             makeAddNodeCvimPaket(addPacket);
             this.addNodes.add(addPacket);
         }
-        return true;
     }
 
 }

+ 34 - 162
tsi-comm-server/src/main/java/com/tsi/comm/server/protocol/TsiCpuPacket.java

@@ -13,7 +13,6 @@ 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.spring.SpringUtils;
 import com.tsi.common.utils.ByteUtils;
 import com.tsi.common.utils.CRC16Utils;
 import io.netty.channel.Channel;
@@ -26,158 +25,36 @@ import java.nio.ByteOrder;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
+import static com.tsi.comm.server.protocol.TsiCvibProtocolSpec.*;
+
 @Slf4j
 @Getter
 @Setter
 public class TsiCpuPacket extends AbstractTsiPacket {
 
-    // 헤더(10), 상태헤더(8), 상태정보(5)*상태정보건수, 체크섬(2)
-    // CVIB Protocol Format(CPU-->CENTER)
-    //TYPE    STX1    STX2    LEN                OPCODE  DataVer NodeID  DATA    CHKSUM
-    //Size    Byte    Byte    2Byte              Byte    1Byte   4Byte   NByte   2Byte
-    //Value   0x7E    0x7E    Size(LEN…CHKSUM)   0x13    0x01            …     CRC16
-    //- LEN   : LEN∼CHKSUM data length
-    //        - OPCODE: 0x13, 신호상태정보전송
-    //        - NodeID: Node ID
-    //- DATA  : Opcode에 따른 데이터 영역
-    //- CRC16 : CCITT / ITU / CRC - 16, bits shift right, final little(x) big(o) endian encoding.from LEN to DATA
-
-    /*
-    // 10 byte
-    uint8_t         stx1;                   // stx 0x7E
-    uint8_t         stx2;                   // stx 0x7E
-    uint8_t         length[2];              // length, length byte ~ check sum
-    uint8_t         opcode;                 // op code, 0x13
-    uint8_t         dataVer;                // Data Version
-    uint8_t         nodeid[4];              // signal node id
-    // 8 byte
-    tsc_cvim_hdr_t  hdr;                    // 8 byte, cvim signal status header
-    // 5 byte * count
-    tsc_cvim_stts_t stts[MAX_CVIM_STTS];    // 5 byte * 127 = 635 byte
-    */
-    // cvim-raw packet header
-    /*
-#define TIMESPEC_SIZE       (sizeof(struct timespec))   // 16 bytes
-    uint8_t pktTm[TIMESPEC_SIZE]; // little endian
-    uint8_t ipaddr[4];  // big endian
-    uint8_t port[2];    // big endian
-    uint8_t connect;
-    uint8_t nodeid[4];  // big endian
-    */
-
-//typedef struct _tsc_cvim_hdr_s
-//{
-//    uint8_t manual      : 1;    /* 수동, 1: 이상, 0: 정상 */
-//    uint8_t blink       : 1;    /* 점멸, 1: 점멸, 0: 정상 */
-//    uint8_t turnOff     : 1;    /* 소등, 1: 소등, 0: 정상 */
-//    uint8_t response    : 1;    /* 감응, 1: 감응, 0: 정상 */
-//    uint8_t trans       : 1;    /* 전이, 1: 전이중, 0: 전이완료 */
-//    uint8_t byte1Res0   : 3;    /* 예약, bit 7 ~ 5 */
-//
-//    uint8_t conflict    : 1;    /* 모순 이상, 1 : 이상, 0 : 정상 */
-//    uint8_t centerComm  : 1;    /* 센터 통신 이상, 1: 센터 통신이상, 0 : 정상 */
-//    uint8_t scuComm     : 1;    /* SCU 통신 이상,  1: MCU <--> SCU 통신 이상, 0: 정상 */
-//    uint8_t byte2Res0   : 5;    /* 예약, bit 7 ~ 3 */
-//
-//    uint8_t cycleCounter;       /* 주기 카운터, 초 */
-//
-//    uint8_t sttsCount   : 7;    /* 총 신호상태정보의 개수, N 개 */
-//    uint8_t splitFlag   : 1;    /* 데이터를 분할하여 전송할 경우 마지막 정보임을 나타내는 플래그(분할 패킷의 처음과 중간:0, 단일 또는 마지막 패킷:1) */
-//
-//    uint8_t currTime[4];        /* 현재시간, time_t형, Big Endian */
-//} tsc_cvim_hdr_t, *ptsc_cvim_hdr_t;
-//
-//typedef struct _tsc_cvim_stts_s
-//{
-//    uint8_t dirAdd      : 4;    /* 3 ~ 0, 방향추가정보, 해당 방향에 연등지 없음(0), 해당 방향의 첫번째 연등지(1), 해당 방향의 두번째 연등지(2) */
-//    uint8_t lightInfo   : 4;    /* 7 ~ 4, 신호등 정보, ■ 미지정(0), 직진(1), 좌회전(2), 보행자(3), 자전거(4), 우회전(5), 버스(6), 유턴(7) */
-//
-//    uint8_t lighting    : 3;    /* 2 ~ 0, 신호등 상태, ■ 소등(0), 적색점등(1), 황색점등(2), 녹색점등(3), 적색점멸(4), 황색점멸(5), 녹색점멸(6) */
-//    uint8_t unprotect   : 1;    /* 3, 비보호 상태, ■ 신호등 정보 유턴/좌회전에 대한 비보호 여부, ■ 비보호 아님(0), 비보호(1) */
-//    uint8_t Reserved0   : 2;    /* 5 ~ 4, 예비, ■ 예비 */
-//    uint8_t walkerPush  : 1;    /* 6, 보행자(푸쉬 또는 자동검지), ■ 없음(0), 버튼 눌림 or 자동검지(1) */
-//    uint8_t timeFlag    : 1;    /* 7, 시간 정보 신뢰성, ■ 고정신호시간(0), 가변신호시간(1) */
-//
-//    uint8_t displayTm;          /* 표출 시간, ■ 초 */
-//    uint8_t remainTm;           /* 잔여 시간, ■ 초 */
-//    uint8_t dirCode;            /* 방향 코드, ■ 출력지정 테이블에 지정된 방향코드 */
-//} tsc_cvim_stts_t, *ptsc_cvim_stts_t;
-
-    // TODO: 20240722 Protocol R28 Added
-    public static final byte PROTOCOL_R27 = 0x01;
-    public static final byte PROTOCOL_R28 = 0x1C;   // 28
-
-    public static final byte STX1 = 0x7E;
-    public static final byte STX2 = 0x7E;
-
-    public static final int SIZE_HEAD         = 10;
-    public static final int SIZE_STX1         = 1;
-    public static final int SIZE_STX2         = 1;
-    public static final int SIZE_LENGTH       = 2;
-    public static final int SIZE_OPCODE       = 1;
-    public static final int SIZE_VERSION      = 1;
-    public static final int SIZE_NODE_ID      = 4;
-    public static final int SIZE_STATUS_HDR   = 8;
-    public static final int SIZE_STATUS_DATA  = 5;
-    public static final int SIZE_CHECKSUM     = 2;
-    public static final int SIZE_PACKET_DATA  = 18; // length, opcode, version, node_id, status_hdr, checksum
-
-    public static final int INDEX_STX1        = 0;  // 0
-    public static final int INDEX_STX2        = 1;  // 1
-    public static final int INDEX_LENGTH      = 2;  // 2,3
-    public static final int INDEX_OPCODE      = 4;  // 4
-    public static final int INDEX_VERSION     = 5;  // 5
-    public static final int INDEX_NODE_ID     = 6;  // 6,7,8,9
-    public static final int INDEX_STATUS_HDR  = 10; // 10,11,12,13,14,15,16,17
-    public static final int INDEX_STATUS_DATA = 18; // 18,19,20,21,22
-    public static final int INDEX_STATUS_DIR_ADD = 0;       // 상태정보내 방향 추가 정보 인덱스
-    public static final int INDEX_STATUS_DIRECTION = 4;     // 상태정보내 방향코드
-
-    public static final int SIZE_NODE_DUMMY   = 1+1+2+1+1+2;    // stx1, stx1, length(2), opcode, version, checksum(2)
-    public static final int SIZE_NODE_HEAD = SIZE_NODE_ID + SIZE_STATUS_HDR;
-    public static final int POS_NODE_HEAD_NODEID = 0;       // node(4),
-    public static final int POS_NODE_HEAD_COUNT = 7;        // node(4),
-
-    public static final int SIZE_IPC_SIZE = 27;
-    public static final int SIZE_TIMESPEC = 16;
-    public static final int POS_IPC_TIMESPEC = 0;
-    public static final int POS_IPC_IPADDR = 16;
-    public static final int POS_IPC_PORT = 20;
-    public static final int POS_IPC_CONNECT = 22;
-    public static final int POS_IPC_NODEID = 23;
-    public static final int POS_IPC_PACKET = SIZE_IPC_SIZE;
-    public static final byte CONNECT = 0x01;
-    public static final byte DISCONNECT = 0x00;
-
-    // FOR Netty LengthFieldBasedFrameDecoder
-    public static final int MAX_FRAME_LENGTH = 2048;
-    public static final int LENGTH_FIELD_OFFSET = 2; // 길이 필드가 2번 인덱스에서 시작
-    public static final int LENGTH_FIELD_LENGTH = 2; // 길이 필드의 크기는 2바이트
-    public static final int LENGTH_ADJUSTMENT = -2; // 길이 필드 값에 더해야 할 조정값 (길이 필드 자체의 크기를 빼줌)
-    public static final int INITIAL_BYTES_TO_STRIP = 0; // 프레임에서 제거할 초기 바이트 수
-
+    protected static TsiNodeAddManager nodeAddManager;
 
     private Object obj;
     private int  length;
     private byte dataVer;
     private int  count;
-    private int  checkSum;
+
     protected byte[] cvimData;    // for cvim-raw topic
     protected byte[] nodeData;    // for node topic
 
     protected List<TsiCpuAddPacket> addNodes;
 
-    private final TsiNodeAddManager nodeAddManager;
-    private int  calcCheckSum;
+    public static void setNodeAddManager(TsiNodeAddManager nodeAddManager) {
+        TsiCpuPacket.nodeAddManager = nodeAddManager;
+    }
+
     public TsiCpuPacket(long nodeId, long msec, long nsec, Channel channel) {
         super(nodeId, msec, nsec, NettyUtils.getRemoteIpAddressToLong(channel), NettyUtils.getRemotePort(channel));
         setOpCode(eOpCode.TSI_CPU_SIGNAL_NOTIFY.getValue());
-        this.nodeAddManager = SpringUtils.getBean(TsiNodeAddManager.class);
     }
 
     public TsiCpuPacket(long nodeId, long msec, long nsec, long remoteIpAddressToLong, int remotePort) {
         super(nodeId, msec, nsec, remoteIpAddressToLong, remotePort);
-        this.nodeAddManager = SpringUtils.getBean(TsiNodeAddManager.class);
     }
 
     // FOR CVIM packet
@@ -261,8 +138,7 @@ public class TsiCpuPacket extends AbstractTsiPacket {
 
         // 0 단계. STX1, STX2 체크
         if (this.buf[INDEX_STX1] != STX1 || this.buf[INDEX_STX2] != STX2) {
-//            log.info("Node: {}, STX Error: {}, {}", nodeId, this.buf[INDEX_STX1], this.buf[INDEX_STX2]);
-//            log.error("{}", HexString.fromBytes(this.buf));
+            log.error("parsing: errno(-1), NodeId: {}, stx1: {}, stx2: {}", this.nodeId, this.buf[INDEX_STX1], this.buf[INDEX_STX2]);
             return -1;
         }
 
@@ -273,24 +149,19 @@ public class TsiCpuPacket extends AbstractTsiPacket {
 //            reqLength = SIZE_PACKET_DATA + (SIZE_STATUS_DATA * this.count) + 1; // ADD CPU byte packet
 //        }
 //        if (this.length != reqLength ) {
-//            log.info("Node: {}, Length Error: {}, Version: {}, status count: {}, {}", nodeId, this.length, this.buf[INDEX_VERSION],
-//                    this.count, reqLength);
-//            log.error("{}", HexString.fromBytes(this.buf));
 //            return false;
 //        }
-        int reqLength = SIZE_PACKET_DATA + (SIZE_STATUS_DATA * this.count);
+        final int reqLength = SIZE_PACKET_DATA + (SIZE_STATUS_DATA * this.count);
         if (this.length < reqLength ) {
-//            log.info("Node: {}, Length Error: {}, Version: {}, status count: {}, {}", nodeId, this.length, this.buf[INDEX_VERSION],
-//                    this.count, reqLength);
-//            log.error("{}", HexString.fromBytes(this.buf));
+            log.error("parsing: errno(-2), NodeId: {}, reqLength: {}, recvLength: {}", this.nodeId, reqLength, this.length);
             return -2;
         }
+
         // 2단계. 체크섬
-        this.checkSum = ByteUtils.getUnsignedShort(this.buf, this.buf.length-2);
-        this.calcCheckSum = CRC16Utils.CRC16_ccitt_cvim(this.buf, INDEX_LENGTH, this.length-2);  // 시작인덱스가 있으므로 전체길이로 계산
-        if (this.checkSum != this.calcCheckSum) {
-//            log.error("Node: {}, Check Sum Error: Version: {}, recv: {}, calc: {}", nodeId, this.buf[INDEX_VERSION], this.checkSum, this.calcCheckSum);
-//            log.error("{}", HexString.fromBytes(this.buf));
+        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) {
+            log.error("parsing: errno(-3), NodeId: {}, crc(recv/calc): {}/{}", this.nodeId, receivedCrc, calculatedCrc);
             return -3;
         }
         return 0;
@@ -299,6 +170,7 @@ public class TsiCpuPacket extends AbstractTsiPacket {
     public int parsing(TsiNodeVo obj, boolean isCheckPacket) {
 
         if (this.buf == null || this.buf.length < INDEX_STATUS_HDR+3) {
+            log.error("parsing: errno(-4), NodeId: {}, buf: {}, length: {}", this.nodeId, this.buf == null, this.buf == null ? 0 : this.buf.length);
             return -4;
         }
 
@@ -323,7 +195,7 @@ public class TsiCpuPacket extends AbstractTsiPacket {
             }
         }
 
-        TsiNodeAddVo tsiNodeAddVo = this.nodeAddManager.get(this.nodeId);
+        TsiNodeAddVo tsiNodeAddVo = TsiCpuPacket.nodeAddManager.get(this.nodeId);
         if (tsiNodeAddVo == null) {
             // 연등지 정보가 없는 경우
             // R25 인 경우 마지막 CPU 제조사 코드를 복사하지 않도록 수정
@@ -357,8 +229,8 @@ public class TsiCpuPacket extends AbstractTsiPacket {
             else {
                 // 추가 노드 정보
                 int originDirCode = status[INDEX_STATUS_DIRECTION]; // 원천방향코드
-                int direction  = originDirCode/10;  // 인천공항 노드 확인용
-                int addNodeIdx = originDirCode%10;  // 인천공항 노드 확인용
+                int direction  = originDirCode / 10;  // 인천공항 노드 확인용
+                int addNodeIdx = originDirCode % 10;  // 인천공항 노드 확인용
                 if (addNodeIdx > 4) {
                     // 인천공항 연등지 인 경우 2개 이상이기 때문에 연등지1 = 15, 연등지2=16, ....
                     // 즉, 일의 자리 5,6,7,8,9로 설정하고 1,2,3,4,5로 된다. 십의자리는 *10을 해서 원천방향코드가 된다.
@@ -415,7 +287,7 @@ public class TsiCpuPacket extends AbstractTsiPacket {
 
             TsiCpuAddPacket addPacket = new TsiCpuAddPacket(entry.getKey(), this.timespec, this.remoteIp, this.remotePort);
 
-            addPacket.setObj(this.nodeAddManager.get(entry.getKey()));
+            addPacket.setObj(TsiCpuPacket.nodeAddManager.get(entry.getKey()));
 
             addPacket.setNodeData(new byte[SIZE_NODE_HEAD + (statusCount*SIZE_STATUS_DATA)]);
             System.arraycopy(head, 0, addPacket.getNodeData(), 0, SIZE_NODE_HEAD);
@@ -425,7 +297,7 @@ public class TsiCpuPacket extends AbstractTsiPacket {
                 System.arraycopy(entry.getValue().get(ii), 0, addPacket.getNodeData(), SIZE_NODE_HEAD+(ii*SIZE_STATUS_DATA), SIZE_STATUS_DATA);
             }
             makeAddNodeCvimPaket(addPacket, addPacket.getNodeData());
-            addNodes.add(addPacket);
+            this.addNodes.add(addPacket);
         }
 /*
         log.error(" RAW: {}, {}", this.nodeId, HexString.fromBytes(getBuf()));
@@ -439,7 +311,7 @@ public class TsiCpuPacket extends AbstractTsiPacket {
     }
 
     public TcsNodeStatus getNodeStatus() {
-        int nodeLength = this.buf.length - TsiCpuPacket.SIZE_IPC_SIZE;
+        int nodeLength = this.buf.length - SIZE_IPC_SIZE;
         byte[] msec = new byte[8];
         byte[] nsec = new byte[8];
         System.arraycopy(this.cvimData, 0, msec, 0, 8);
@@ -452,8 +324,8 @@ public class TsiCpuPacket extends AbstractTsiPacket {
 
         long milliSeconds = byteMSec.getLong();
         long nanoSeconds = byteNSec.getLong();
-        this.remoteIp = ByteUtils.getUnsignedInt(this.cvimData, TsiCpuPacket.POS_IPC_IPADDR);
-        this.remotePort = ByteUtils.getUnsignedShort(this.cvimData, TsiCpuPacket.POS_IPC_PORT);
+        this.remoteIp = ByteUtils.getUnsignedInt(this.cvimData, POS_IPC_IPADDR);
+        this.remotePort = ByteUtils.getUnsignedShort(this.cvimData, POS_IPC_PORT);
 
         /////
         getTimespec().tv_nsec(nanoSeconds);     // recv tcp,
@@ -463,7 +335,7 @@ public class TsiCpuPacket extends AbstractTsiPacket {
         sdf.setTimeZone(java.util.TimeZone.getTimeZone("GMT+9"));
         String collectTime = sdf.format(date);
 
-        if (this.cvimData[TsiCpuPacket.POS_IPC_CONNECT] == TsiCpuPacket.DISCONNECT) {
+        if (this.cvimData[POS_IPC_CONNECT] == DISCONNECT) {
             return TcsNodeStatus.builder()
                     ._id(this.nodeId)
                     .nodeId(this.nodeId)
@@ -472,7 +344,7 @@ public class TsiCpuPacket extends AbstractTsiPacket {
                     .build();
         }
 
-        if (nodeLength < TsiCpuPacket.SIZE_HEAD + TsiCpuPacket.SIZE_STATUS_HDR) {
+        if (nodeLength < SIZE_HEAD + SIZE_STATUS_HDR) {
             // packet error
             return null;
         }
@@ -491,27 +363,27 @@ public class TsiCpuPacket extends AbstractTsiPacket {
         //int length = ByteUtils.getUnsignedShort(this.nodeData, TsiCpuPacket.INDEX_LENGTH);
         //int count = (int)(this.nodeData[TsiCpuPacket.INDEX_STATUS_HDR+3] & 0x7F);
 
-        byte control = this.cvimData[TsiCpuPacket.SIZE_IPC_SIZE+TsiCpuPacket.INDEX_STATUS_HDR+0];
+        byte control = this.cvimData[SIZE_IPC_SIZE + INDEX_STATUS_HDR];
         tscControlInfo.inManualControl     = ((control     ) & 0x01) == 0x01;  //수동;
         tscControlInfo.inFlashingControl   = ((control >> 1) & 0x01) == 0x01;  //점멸;
         tscControlInfo.inLightsOutControl  = ((control >> 2) & 0x01) == 0x01;  //소등
         tscControlInfo.inActuationControl  = ((control >> 3) & 0x01) == 0x01;  //감응;
         tscControlInfo.inTransitionControl = ((control >> 4) & 0x01) == 0x01;  //전이;
 
-        byte abnormal = this.cvimData[TsiCpuPacket.SIZE_IPC_SIZE+TsiCpuPacket.INDEX_STATUS_HDR+1];
+        byte abnormal = this.cvimData[SIZE_IPC_SIZE + INDEX_STATUS_HDR + 1];
         tscAbnormalInfo.inSignalConflict = ((abnormal     ) & 0x01) == 0x01;   //모순상태;
         tscAbnormalInfo.inCenterComm     = ((abnormal >> 1) & 0x01) == 0x01;   //센터상태;
         tscAbnormalInfo.inScuComm        = ((abnormal >> 2) & 0x01) == 0x01;   //SCU 상태
 
-        cycleElapsedTime = (int)(this.cvimData[TsiCpuPacket.SIZE_IPC_SIZE+TsiCpuPacket.INDEX_STATUS_HDR+2] & 0xFF);
+        cycleElapsedTime = (int)(this.cvimData[SIZE_IPC_SIZE + INDEX_STATUS_HDR + 2] & 0xFF);
 
-        byte stts = this.cvimData[TsiCpuPacket.SIZE_IPC_SIZE+TsiCpuPacket.INDEX_STATUS_HDR+3];;
+        byte stts = this.cvimData[SIZE_IPC_SIZE + INDEX_STATUS_HDR + 3];;
         signalStatusInfoCount = (int)(stts & 0x7F);
         //divFlag = (int)((stts >> 7) & 0x01);
 
-        localTime = ByteUtils.getUnsignedInt(this.cvimData, TsiCpuPacket.SIZE_IPC_SIZE+TsiCpuPacket.INDEX_STATUS_HDR+4);
+        localTime = ByteUtils.getUnsignedInt(this.cvimData, SIZE_IPC_SIZE + INDEX_STATUS_HDR + 4);
 
-        int ii = TsiCpuPacket.SIZE_IPC_SIZE+TsiCpuPacket.INDEX_STATUS_DATA;
+        int ii = SIZE_IPC_SIZE + INDEX_STATUS_DATA;
 
         for (int idx = 0; idx < signalStatusInfoCount; idx++) {
             TsiCvimStatus status = new TsiCvimStatus();
@@ -539,7 +411,7 @@ public class TsiCpuPacket extends AbstractTsiPacket {
 
             signalStatusInfos.add(status);
 
-            ii += TsiCpuPacket.SIZE_STATUS_DATA;
+            ii += SIZE_STATUS_DATA;
         }
 
         date = new Date(localTime * 1000L);

+ 131 - 0
tsi-comm-server/src/main/java/com/tsi/comm/server/protocol/TsiCvibProtocolSpec.java

@@ -0,0 +1,131 @@
+package com.tsi.comm.server.protocol;
+
+/**
+ * CVIB protocol
+ */
+public final class TsiCvibProtocolSpec {
+    /*
+    // 헤더(10), 상태헤더(8), 상태정보(5)*상태정보건수, 체크섬(2)
+    // CVIB Protocol Format(CPU-->CENTER)
+    //TYPE    STX1    STX2    LEN                OPCODE  DataVer NodeID  DATA    CHKSUM
+    //Size    Byte    Byte    2Byte              Byte    1Byte   4Byte   NByte   2Byte
+    //Value   0x7E    0x7E    Size(LEN…CHKSUM)   0x13    0x01            …     CRC16
+    //- LEN   : LEN∼CHKSUM data length
+    //        - OPCODE: 0x13, 신호상태정보전송
+    //        - NodeID: Node ID
+    //- DATA  : Opcode에 따른 데이터 영역
+    //- CRC16 : CCITT / ITU / CRC - 16, bits shift right, final little(x) big(o) endian encoding.from LEN to DATA
+
+    // 10 byte
+    uint8_t         stx1;                   // stx 0x7E
+    uint8_t         stx2;                   // stx 0x7E
+    uint8_t         length[2];              // length, length byte ~ check sum
+    uint8_t         opcode;                 // op code, 0x13
+    uint8_t         dataVer;                // Data Version
+    uint8_t         nodeid[4];              // signal node id
+    // 8 byte
+    tsc_cvim_hdr_t  hdr;                    // 8 byte, cvim signal status header
+    // 5 byte * count
+    tsc_cvim_stts_t stts[MAX_CVIM_STTS];    // 5 byte * 127 = 635 byte
+
+    // cvim-raw packet header
+#define TIMESPEC_SIZE       (sizeof(struct timespec))   // 16 bytes
+    uint8_t pktTm[TIMESPEC_SIZE]; // little endian
+    uint8_t ipaddr[4];  // big endian
+    uint8_t port[2];    // big endian
+    uint8_t connect;
+    uint8_t nodeid[4];  // big endian
+
+typedef struct _tsc_cvim_hdr_s
+{
+    uint8_t manual      : 1;    // 수동, 1: 이상, 0: 정상
+    uint8_t blink       : 1;    // 점멸, 1: 점멸, 0: 정상
+    uint8_t turnOff     : 1;    // 소등, 1: 소등, 0: 정상
+    uint8_t response    : 1;    // 감응, 1: 감응, 0: 정상
+    uint8_t trans       : 1;    // 전이, 1: 전이중, 0: 전이완료
+    uint8_t byte1Res0   : 3;    // 예약, bit 7 ~ 5
+
+    uint8_t conflict    : 1;    // 모순 이상, 1 : 이상, 0 : 정상
+    uint8_t centerComm  : 1;    // 센터 통신 이상, 1: 센터 통신이상, 0 : 정상
+    uint8_t scuComm     : 1;    // SCU 통신 이상,  1: MCU <--> SCU 통신 이상, 0: 정상
+    uint8_t byte2Res0   : 5;    // 예약, bit 7 ~ 3
+
+    uint8_t cycleCounter;       // 주기 카운터, 초
+
+    uint8_t sttsCount   : 7;    // 총 신호상태정보의 개수, N 개
+    uint8_t splitFlag   : 1;    // 데이터를 분할하여 전송할 경우 마지막 정보임을 나타내는 플래그(분할 패킷의 처음과 중간:0, 단일 또는 마지막 패킷:1)
+
+    uint8_t currTime[4];        // 현재시간, time_t형, Big Endian
+} tsc_cvim_hdr_t, *ptsc_cvim_hdr_t;
+
+typedef struct _tsc_cvim_stts_s
+{
+    uint8_t dirAdd      : 4;    // 3 ~ 0, 방향추가정보, 해당 방향에 연등지 없음(0), 해당 방향의 첫번째 연등지(1), 해당 방향의 두번째 연등지(2)
+    uint8_t lightInfo   : 4;    // 7 ~ 4, 신호등 정보, ■ 미지정(0), 직진(1), 좌회전(2), 보행자(3), 자전거(4), 우회전(5), 버스(6), 유턴(7)
+
+    uint8_t lighting    : 3;    // 2 ~ 0, 신호등 상태, ■ 소등(0), 적색점등(1), 황색점등(2), 녹색점등(3), 적색점멸(4), 황색점멸(5), 녹색점멸(6)
+    uint8_t unprotect   : 1;    // 3, 비보호 상태, ■ 신호등 정보 유턴/좌회전에 대한 비보호 여부, ■ 비보호 아님(0), 비보호(1)
+    uint8_t Reserved0   : 2;    // 5 ~ 4, 예비, ■ 예비
+    uint8_t walkerPush  : 1;    // 6, 보행자(푸쉬 또는 자동검지), ■ 없음(0), 버튼 눌림 or 자동검지(1)
+    uint8_t timeFlag    : 1;    // 7, 시간 정보 신뢰성, ■ 고정신호시간(0), 가변신호시간(1)
+
+    uint8_t displayTm;          // 표출 시간, ■ 초
+    uint8_t remainTm;           // 잔여 시간, ■ 초
+    uint8_t dirCode;            // 방향 코드, ■ 출력지정 테이블에 지정된 방향코드
+} tsc_cvim_stts_t, *ptsc_cvim_stts_t;
+    */
+
+    // TODO: 20240722 Protocol R28 Added
+    public static final byte PROTOCOL_R27 = 0x01;
+    public static final byte PROTOCOL_R28 = 0x1C;   // 28
+
+    public static final byte STX1 = 0x7E;
+    public static final byte STX2 = 0x7E;
+
+    public static final int SIZE_HEAD         = 10;
+    public static final int SIZE_STX1         = 1;
+    public static final int SIZE_STX2         = 1;
+    public static final int SIZE_LENGTH       = 2;
+    public static final int SIZE_OPCODE       = 1;
+    public static final int SIZE_VERSION      = 1;
+    public static final int SIZE_NODE_ID      = 4;
+    public static final int SIZE_STATUS_HDR   = 8;
+    public static final int SIZE_STATUS_DATA  = 5;
+    public static final int SIZE_CHECKSUM     = 2;
+    public static final int SIZE_PACKET_DATA  = 18; // length, opcode, version, node_id, status_hdr, checksum
+
+    public static final int INDEX_STX1        = 0;  // 0
+    public static final int INDEX_STX2        = 1;  // 1
+    public static final int INDEX_LENGTH      = 2;  // 2,3
+    public static final int INDEX_OPCODE      = 4;  // 4
+    public static final int INDEX_VERSION     = 5;  // 5
+    public static final int INDEX_NODE_ID     = 6;  // 6,7,8,9
+    public static final int INDEX_STATUS_HDR  = 10; // 10,11,12,13,14,15,16,17
+    public static final int INDEX_STATUS_DATA = 18; // 18,19,20,21,22
+    public static final int INDEX_STATUS_DIR_ADD = 0;       // 상태정보내 방향 추가 정보 인덱스
+    public static final int INDEX_STATUS_DIRECTION = 4;     // 상태정보내 방향코드
+
+    public static final int SIZE_NODE_DUMMY   = 1+1+2+1+1+2;    // stx1, stx1, length(2), opcode, version, checksum(2)
+    public static final int SIZE_NODE_HEAD = SIZE_NODE_ID + SIZE_STATUS_HDR;
+    public static final int POS_NODE_HEAD_NODEID = 0;       // node(4),
+    public static final int POS_NODE_HEAD_COUNT = 7;        // node(4),
+
+    public static final int SIZE_IPC_SIZE = 27;
+    public static final int SIZE_TIMESPEC = 16;
+    public static final int POS_IPC_TIMESPEC = 0;
+    public static final int POS_IPC_IPADDR = 16;
+    public static final int POS_IPC_PORT = 20;
+    public static final int POS_IPC_CONNECT = 22;
+    public static final int POS_IPC_NODEID = 23;
+    public static final int POS_IPC_PACKET = SIZE_IPC_SIZE;
+    public static final byte CONNECT = 0x01;
+    public static final byte DISCONNECT = 0x00;
+
+    // FOR Netty LengthFieldBasedFrameDecoder
+    public static final int MAX_FRAME_LENGTH = 2048;
+    public static final int LENGTH_FIELD_OFFSET = 2; // 길이 필드가 2번 인덱스에서 시작
+    public static final int LENGTH_FIELD_LENGTH = 2; // 길이 필드의 크기는 2바이트
+    public static final int LENGTH_ADJUSTMENT = -2; // 길이 필드 값에 더해야 할 조정값 (길이 필드 자체의 크기를 빼줌)
+    public static final int INITIAL_BYTES_TO_STRIP = 0; // 프레임에서 제거할 초기 바이트 수
+
+}

+ 7 - 7
tsi-comm-server/src/main/java/com/tsi/comm/server/repository/TsiNodeManager.java

@@ -87,12 +87,12 @@ public class TsiNodeManager {
         }
     }
 
-    public void initDump() {
-        for (Map.Entry<Long, TsiNodeVo> obj : this.tsiNodeVoMap.entrySet()) {
-            TsiNodeVo node = obj.getValue();
-            node.setDump(false);
-            node.setTcpDump(false);
-        }
-    }
+//    public void initDump() {
+//        for (Map.Entry<Long, TsiNodeVo> obj : this.tsiNodeVoMap.entrySet()) {
+//            TsiNodeVo node = obj.getValue();
+//            node.setDump(false);
+//            node.setTcpDump(false);
+//        }
+//    }
 
 }

+ 21 - 0
tsi-comm-server/src/main/java/com/tsi/comm/server/service/TsiCommPacketInitializer.java

@@ -0,0 +1,21 @@
+package com.tsi.comm.server.service;
+
+import com.tsi.comm.server.protocol.TsiCpuPacket;
+import com.tsi.comm.server.repository.TsiNodeAddManager;
+import lombok.RequiredArgsConstructor;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
+
+@RequiredArgsConstructor
+@Component
+public class TsiCommPacketInitializer {
+
+    private final TsiNodeAddManager nodeAddManager;
+
+    @PostConstruct
+    public void init() {
+        TsiCpuPacket.setNodeAddManager(this.nodeAddManager);
+    }
+
+}

+ 16 - 22
tsi-comm-server/src/main/java/com/tsi/comm/server/service/TsiCommServerService.java

@@ -78,37 +78,31 @@ public class TsiCommServerService {
 
         this.nodeManager.beforeLoading();
 
-        boolean installed;
-        TsiNodeVo node;
-
         int idx = 0;
         List<NodeVo> objLists = this.databaseMapper.getNodeInfoList();
         for (NodeVo obj : objLists) {
-            installed = "Y".equals(obj.getUseYn());
-            node = this.nodeManager.get(obj.getNodeId());
-            if (node != null) {
-                node.setCheckInstalled(installed);
-                node.setSendTest("Y".equals(obj.getTestYn()));
-                node.setSendNode("Y".equals(obj.getNodeYn()));
-                node.setSendCvim("Y".equals(obj.getCvimYn()));
-                node.setRegistered(true);
+            boolean installed = "Y".equals(obj.getUseYn());
+            TsiNodeVo nodeVo = this.nodeManager.get(obj.getNodeId());
+            if (nodeVo != null) {
+                nodeVo.setCheckInstalled(installed);
+                nodeVo.setSendTest("Y".equals(obj.getTestYn()));
+                nodeVo.setSendNode("Y".equals(obj.getNodeYn()));
+                nodeVo.setSendCvim("Y".equals(obj.getCvimYn()));
+                nodeVo.setRegistered(true);
             }
             else {
-                node = new TsiNodeVo(obj.getNodeId(), obj.getIpAddr(), obj.getTestYn().equals("Y"), obj.getNodeYn().equals("Y"), obj.getCvimYn().equals("Y"));
-                node.setRegistered(true);
-                node.setCheckInstalled(installed);
-                node.setPktQIdx(0);
-                node.setDbmsQIdx(0);
-                node.setLogQIdx(0);
-                this.nodeManager.put(obj.getNodeId(), node);
+                nodeVo = new TsiNodeVo(obj.getNodeId(), obj.getIpAddr(), obj.getTestYn().equals("Y"), obj.getNodeYn().equals("Y"), obj.getCvimYn().equals("Y"));
+                nodeVo.setRegistered(true);
+                nodeVo.setCheckInstalled(installed);
+                nodeVo.setPktQIdx(0);
+                nodeVo.setDbmsQIdx(0);
+                nodeVo.setLogQIdx(0);
+                this.nodeManager.put(obj.getNodeId(), nodeVo);
             }
-            node.setIdx(idx++);  // 인덱스 설정
-            //int hash = Long.hashCode(obj.getNodeId()); // 해시코드 생성, 필요시 사용
-            //int idx = Math.abs(hash % 9);
 
             final String ipAddr = obj.getIpAddr();
             if (!"0.0.0.0".equals(ipAddr)) {
-                this.nodeManager.putIpAddr(ipAddr, node);
+                this.nodeManager.putIpAddr(ipAddr, nodeVo);
             }
         }
 

+ 2 - 7
tsi-comm-server/src/main/java/com/tsi/comm/server/tcp/TsiCvimServer.java

@@ -24,7 +24,9 @@ public class TsiCvimServer extends NettyTcpServer {
 
     @PostConstruct
     public void initialize() {
+
         super.setChannelInitializer(new CvimServerInitializer(this.config));
+
         if (!OS.isWindows()) {
             if (!Epoll.isAvailable()) {
                 log.warn("TsiCvimServer Epoll not support: {}", Epoll.unavailabilityCause().toString());
@@ -38,11 +40,4 @@ public class TsiCvimServer extends NettyTcpServer {
         }
     }
 
-//    @PreDestroy
-//    public void terminate() {
-//        log.info("TsiCvimServer shutting down.");
-//        stop();
-//        log.info("TsiCvimServer shut down.");
-//    }
-
 }

+ 4 - 3
tsi-comm-server/src/main/java/com/tsi/comm/server/tcp/codec/CvimServerByteBufMessageDecoder.java

@@ -1,6 +1,7 @@
 package com.tsi.comm.server.tcp.codec;
 
 import com.tsi.comm.server.protocol.TsiCpuPacket;
+import com.tsi.comm.server.protocol.TsiCvibProtocolSpec;
 import com.tsi.common.utils.TimeUtils;
 import io.netty.buffer.ByteBuf;
 import io.netty.channel.ChannelHandler;
@@ -33,14 +34,14 @@ public class CvimServerByteBufMessageDecoder extends MessageToMessageDecoder<Byt
 
         // 패킷의 최소 유효성만 검사. (예: 최소 길이)
         final int readableBytes = byteBuf.readableBytes();
-        if (readableBytes < TsiCpuPacket.SIZE_HEAD) {
-            log.error("Receive: Packet readableBytes too small: {}, required min size: {}", readableBytes, TsiCpuPacket.SIZE_HEAD);
+        if (readableBytes < TsiCvibProtocolSpec.SIZE_HEAD) {
+            log.error("Receive: Packet readableBytes too small: {}, required min size: {}", readableBytes, TsiCvibProtocolSpec.SIZE_HEAD);
             ctx.close();
             return;
         }
 
         // 노드 ID 추출
-        final long nodeId = byteBuf.getUnsignedInt(TsiCpuPacket.INDEX_NODE_ID);
+        final long nodeId = byteBuf.getUnsignedInt(TsiCvibProtocolSpec.INDEX_NODE_ID);
 
         // 프로세스 패킷 생성
         TsiCpuPacket packet = new TsiCpuPacket(nodeId, msec, nsec, ctx.channel());

+ 6 - 6
tsi-comm-server/src/main/java/com/tsi/comm/server/tcp/initializer/CvimServerInitializer.java

@@ -1,7 +1,7 @@
 package com.tsi.comm.server.tcp.initializer;
 
 import com.tsi.comm.server.config.TsiCvimServerConfig;
-import com.tsi.comm.server.protocol.TsiCpuPacket;
+import com.tsi.comm.server.protocol.TsiCvibProtocolSpec;
 import com.tsi.comm.server.repository.TsiAlarmManager;
 import com.tsi.comm.server.repository.TsiNodeManager;
 import com.tsi.comm.server.repository.TsiSessionManager;
@@ -77,11 +77,11 @@ public class CvimServerInitializer extends ChannelInitializer<Channel> {
 
         // 패킷 프레이밍: ByteBuf -> ByteBuf (하나의 완전한 패킷, 패킷길이 체크)
         pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(
-                TsiCpuPacket.MAX_FRAME_LENGTH,
-                TsiCpuPacket.LENGTH_FIELD_OFFSET,
-                TsiCpuPacket.LENGTH_FIELD_LENGTH,
-                TsiCpuPacket.LENGTH_ADJUSTMENT,
-                TsiCpuPacket.INITIAL_BYTES_TO_STRIP
+                TsiCvibProtocolSpec.MAX_FRAME_LENGTH,
+                TsiCvibProtocolSpec.LENGTH_FIELD_OFFSET,
+                TsiCvibProtocolSpec.LENGTH_FIELD_LENGTH,
+                TsiCvibProtocolSpec.LENGTH_ADJUSTMENT,
+                TsiCvibProtocolSpec.INITIAL_BYTES_TO_STRIP
         ));
 
         // 패킷 디코딩: ByteBuf -> TsiCpuPacket

+ 2 - 0
tsi-comm-server/src/main/java/com/tsi/comm/server/vo/TsiNodeAddDetailVo.java

@@ -4,7 +4,9 @@ import lombok.Data;
 
 @Data
 public class TsiNodeAddDetailVo {
+
     public static int MAX_NODE_ADD = 10;
+
     private long nodeId;
     private int  originDirCode;
     private int  addNodeOrder;

+ 25 - 38
tsi-comm-server/src/main/java/com/tsi/comm/server/vo/TsiNodeVo.java

@@ -1,6 +1,5 @@
 package com.tsi.comm.server.vo;
 
-import com.tsi.comm.server.dto.TsiCvimDto;
 import com.tsi.comm.server.protocol.TsiCpuPacket;
 import com.tsi.comm.server.repository.TsiAlarmManager;
 import com.tsi.common.utils.Counter;
@@ -32,10 +31,6 @@ public class TsiNodeVo {
 
     private Counter connectCount    = new Counter();
     private Counter disconnectCount = new Counter();
-    private Counter recvPackets = new Counter();
-    private Counter sendPackets = new Counter();
-
-    private TsiCvimDto tsiCvimDto;
 
     TsiNodeAddVo tsiNodeAddVo;
 
@@ -48,12 +43,8 @@ public class TsiNodeVo {
     protected long queueTime;
     protected long endTime;
 
-    private byte[] rawBytes = new byte[1];
-    private byte[] nodePacket = new byte[1];
-
     private boolean dump;
     private boolean tcpDump;
-    private int idx;
 
     private int pktQIdx;
     private int dbmsQIdx;
@@ -91,18 +82,14 @@ public class TsiNodeVo {
         this.lastCommTm = 0;
         this.dump = false;
         this.tcpDump = false;
-        this.idx = 0;
         this.pktQIdx = 0;
         this.dbmsQIdx = 0;
         this.logQIdx = 0;
         this.sigCount = 0;
         this.crcError = false;
         this.packetError = false;
-    }
 
-    public void initPacket() {
-        this.tsiCvimDto = new TsiCvimDto();
-        this.tsiCvimDto.setNodeId(this.nodeId);
+        this.tsiNodeAddVo = null;
     }
 
     public boolean isConnect() {
@@ -212,29 +199,29 @@ public class TsiNodeVo {
         return String.valueOf(this.nodeId);
     }
 
-    public byte[] getTestPacket() {
-        return null;//this.packet;
-    }
-    public byte[] getCvimPacket() {
-        return null;//this.packet;
-    }
-
-    public void makeNodePacket(int length) {
-        this.nodePacket = null;
-        if (length > TsiCpuPacket.INDEX_NODE_ID) {
-            // STX1, STX2, LEN(2), OpCode(1), Version(1), NodeId
-            // LEN = LEN ~ CHECK SUM
-            int packetLen = length-2-1-1-2;
-            this.nodePacket = new byte[packetLen];
-            try {
-                //System.arraycopy(this.packet, 6, this.nodePacket, 0, packetLen);
-            }
-            catch(Exception e) {
-            }
-        }
-        else {
-            log.warn("makeNodePacket: The length must be at least {} bytes: {}, {}", TsiCpuPacket.INDEX_NODE_ID, this.nodeId, length);
-        }
-    }
+//    public byte[] getTestPacket() {
+//        return null;//this.packet;
+//    }
+//    public byte[] getCvimPacket() {
+//        return null;//this.packet;
+//    }
+//
+//    public void makeNodePacket(int length) {
+//        this.nodePacket = null;
+//        if (length > TsiCvibProtocolSpec.INDEX_NODE_ID) {
+//            // STX1, STX2, LEN(2), OpCode(1), Version(1), NodeId
+//            // LEN = LEN ~ CHECK SUM
+//            int packetLen = length-2-1-1-2;
+//            this.nodePacket = new byte[packetLen];
+//            try {
+//                //System.arraycopy(this.packet, 6, this.nodePacket, 0, packetLen);
+//            }
+//            catch(Exception e) {
+//            }
+//        }
+//        else {
+//            log.warn("makeNodePacket: The length must be at least {} bytes: {}, {}", TsiCvibProtocolSpec.INDEX_NODE_ID, this.nodeId, length);
+//        }
+//    }
 
 }

+ 4 - 0
tsi-comm-server/src/main/resources/logback-spring.xml

@@ -95,6 +95,10 @@
         </sift>
     </appender>
 
+    <logger name="com.tsi.comm.server.protocol" level="INFO" additivity="false">
+        <appender-ref ref="FILE_PROCESS"/>
+        <appender-ref ref="FILE_ERROR"/>
+    </logger>
     <logger name="com.tsi.comm.server.process.packet" level="INFO" additivity="false">
         <appender-ref ref="FILE_PROCESS"/>
         <appender-ref ref="FILE_ERROR"/>

+ 2 - 2
tsi-comm-server/src/test/java/com/tsi/comm/server/TsiCommServerApplicationTests.java

@@ -1,6 +1,6 @@
 package com.tsi.comm.server;
 
-import com.tsi.comm.server.protocol.TsiCpuPacket;
+import com.tsi.comm.server.protocol.TsiCvibProtocolSpec;
 import com.tsi.common.utils.ByteUtils;
 import com.tsi.common.utils.CRC16Utils;
 import com.tsi.common.utils.HexString;
@@ -132,7 +132,7 @@ public class TsiCommServerApplicationTests {
         String strHex = "7E7E004E1301068E77810002310C60F1375E10CB280B0A20CB321F0A30CB320D0A10CA03011420CA32011430CA322B1410C9280B1E20C9321F1E30C9320D1E10C903012820C928012830C9282B28FD89";
         byte[] packet = ByteUtils.hexToByteArray(strHex);
         log.error("{}", HexString.fromBytes(packet));
-        int dataLength = ByteUtils.getUnsignedShort(packet, TsiCpuPacket.INDEX_LENGTH);
+        int dataLength = ByteUtils.getUnsignedShort(packet, TsiCvibProtocolSpec.INDEX_LENGTH);
         log.error("dataLength: {}, packetLength: {}", dataLength, packet.length);
         int recvCheckSum = ByteUtils.getUnsignedShort(packet, packet.length-2);
         int calcCheckSum = CRC16Utils.CRC16_ccitt_cvim(packet, 2, dataLength-2);