فهرست منبع

dev stopimage

shjung 2 سال پیش
والد
کامیت
41168440f5

+ 3 - 3
src/main/java/com/its/vds/entity/TbVdsCtlr.java

@@ -279,7 +279,7 @@ public class TbVdsCtlr {
 			log.error("Reset Data Send Failed: [{}]", this);
 			return false;
 		} else {
-			log.error("Reset Data Send Failed: [{}]", this);
+			log.info("Reset Data Send: [{}]", this);
 			return true;
 		}
 	}
@@ -296,7 +296,7 @@ public class TbVdsCtlr {
 			log.error("Initialize Data Send Failed: [{}]", this);
 			return false;
 		} else {
-			log.error("Initialize Data Send Failed: [{}]", this);
+			log.info("Initialize Data Send: [{}]", this);
 			return true;
 		}
 	}
@@ -318,7 +318,7 @@ public class TbVdsCtlr {
 			log.error("StopImage Data Send Failed: [{}]", this);
 			return false;
 		} else {
-			log.error("StopImage Data Send Failed: [{}]", this);
+			log.info("StopImage Data Send: [{}]", this);
 			return true;
 		}
 	}

+ 9 - 9
src/main/java/com/its/vds/xnettcp/center/handler/CenterTcpServerInboundHandler.java

@@ -18,7 +18,6 @@ import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Component;
 
 import java.nio.ByteBuffer;
-import java.util.Map;
 
 @Slf4j
 @Component
@@ -37,15 +36,16 @@ public class CenterTcpServerInboundHandler extends ChannelInboundHandlerAdapter
         short groupNo = vdsReqHead.getGroupNo();
         short ctlrNo = vdsReqHead.getControllerNo();
         byte opCode = vdsReqHead.getOpCode();
+        String vdsCtlrNmbr = String.valueOf(ctlrNo);
 
-        TbVdsCtlr obj = null;
-        for (Map.Entry<String, TbVdsCtlr> e : AppRepository.getInstance().getCtlrMap().entrySet()) {
-            TbVdsCtlr tmp = e.getValue();
-            if (tmp.getVDS_CTLR_LOCAL_NO() == ctlrNo) {
-                obj = tmp;
-                break;
-            }
-        }
+        TbVdsCtlr obj = AppRepository.getInstance().getCtlrMap().get(vdsCtlrNmbr);
+//        for (Map.Entry<String, TbVdsCtlr> e : AppRepository.getInstance().getCtlrMap().entrySet()) {
+//            TbVdsCtlr tmp = e.getValue();
+//            if (tmp.getVDS_CTLR_LOCAL_NO() == ctlrNo) {
+//                obj = tmp;
+//                break;
+//            }
+//        }
         if (obj == null) {
             log.error("CenterTcpServerInboundHandler: Center Request Unknown VDS: [{}]", ctlrNo);
             ByteBuffer sendBuffer = CenterResProtocol.getResponse(opCode, (byte)(0xFF));

+ 77 - 0
src/main/java/com/its/vds/xnettcp/center/protocol/CenterProtocol.java

@@ -1,5 +1,11 @@
 package com.its.vds.xnettcp.center.protocol;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+import java.net.Socket;
+import java.net.SocketAddress;
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 
@@ -178,6 +184,14 @@ public class CenterProtocol {
     public static final int INT_DSRC_MAX_OPER_ID         = 20;
     public static final int INT_DSRC_MAX_STATE           = 200;     /* 최대 DSRC 시설물 상태정보 */
 
+    /**
+     * 센터 내부 통신 헤더 패킷 생성
+     * @param sndSystem
+     * @param rcvSystem
+     * @param opCode
+     * @param length
+     * @return
+     */
     public static byte[] getRequestHead(int sndSystem, int rcvSystem, byte opCode, int length) {
 
         ByteBuffer byteBuffer = ByteBuffer.allocate(10);
@@ -194,4 +208,67 @@ public class CenterProtocol {
         return byteBuffer.array();
     }
 
+    /**
+     * 통신 서버와 통신 연결
+     * @param ipAddress
+     * @param port
+     * @param connTimeout
+     * @param readTimeout
+     * @return
+     * @throws IOException
+     */
+    public static Socket connectServer(String ipAddress, int port, int connTimeout, int readTimeout) throws IOException {
+        SocketAddress socketAddress = new InetSocketAddress(ipAddress, port);
+        Socket socket = null;
+        try {
+            socket = new Socket();
+            socket.setSoTimeout(readTimeout);                /* InputStream 에서 데이터읽을때의 timeout */
+            socket.connect(socketAddress, connTimeout);  /* socket 연결 자체에대한 timeout */
+        } catch (IOException e) {
+            throw e;
+        }
+        return socket;
+    }
+
+    /**
+     * 소켓 입력 버퍼로 부터 데이터 길이만큼 읽어 온다
+     * @param inStream
+     * @param buffSize
+     * @return
+     * @throws IOException
+     */
+    public static byte[] receiveBytes(InputStream inStream, int buffSize) throws IOException {
+        byte[] buffer;
+        int bytesRead = 0;
+        int readThisTime;
+        buffer = new byte[buffSize];
+        while (bytesRead < buffSize)
+        {
+            readThisTime = inStream.read(buffer, bytesRead, buffSize - bytesRead);
+            if (readThisTime == -1)
+            {
+                throw new IOException("Socket.receive(): Socket closed unexpectedly");
+            }
+            bytesRead += readThisTime;
+        }
+        return buffer;
+    }
+
+    /**
+     * 소켓으로 데이터 전송
+     * @param socket
+     * @param data
+     * @return
+     */
+    public static boolean sendData(Socket socket, byte[] data) {
+        try {
+            OutputStream os = socket.getOutputStream();
+            os.write(data);
+            os.flush();
+        } catch (IOException e) {
+            return false;
+        }
+        return true;
+    }
+
 }

+ 7 - 2
src/main/java/com/its/vds/xnettcp/vds/process/Job_Image.java

@@ -53,7 +53,7 @@ public class Job_Image implements JobProtocol {
 			byteBuffer.get(imageData);
 			obj.addImageSize(imageSize);
 			obj.addImageData(imageData);
-			log.info("[{}]. Job_Image: image data save: currentSize {}, totalSize {}", obj.getVDS_CTLR_ID(), imageSize, obj.getImageData().array().length);
+			log.info("[{}]. Job_Image: image data save: total {}, current {}, currentSize {}, totalSize {}", obj.getVDS_CTLR_ID(), total, current, imageSize, obj.getImageData().array().length);
 		}
 		else {
 			log.error("[{}]. Job_Image: image data receive size error: total {}, current {}, dataLen {}", obj.getVDS_CTLR_ID(), total, current, dataLen);
@@ -61,7 +61,12 @@ public class Job_Image implements JobProtocol {
 			return 0;
 		}
 
-		int nextFrame = current;
+		if (obj.getImageSize() > 1024 * 1024 * 1024) {
+			log.error("[{}]. Job_Image: Total Image Data Size Error, will be closed.", obj.getVDS_CTLR_ID());
+			obj.channelClose();
+			return 0;
+		}
+		int nextFrame = current+1;
 		if (total == nextFrame) {
 			log.info("[{}]. Job_Image: completed image data receive: {}", obj.getVDS_CTLR_ID(), obj.getImageSize());
 			List<Channel> channels = obj.getRequestImageList();