shjung 2 years ago
parent
commit
2ba5e9f110

+ 6 - 0
pom.xml

@@ -77,6 +77,12 @@
             <version>1.15</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.httpcomponents</groupId>
+            <artifactId>httpclient</artifactId>
+            <version>4.5.13</version>
+        </dependency>
+
         <dependency>
             <groupId>com.oracle</groupId>
             <artifactId>ojdbc7</artifactId>

+ 1 - 2
src/main/java/com/its/op/ItsOpServerApplication.java

@@ -8,7 +8,6 @@ import com.its.op.xnetudp.CenterCommUdpServer;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.DisposableBean;
 import org.springframework.beans.factory.InitializingBean;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.Banner;
 import org.springframework.boot.CommandLineRunner;
 import org.springframework.boot.SpringApplication;
@@ -46,7 +45,7 @@ public class ItsOpServerApplication extends SpringBootServletInitializer impleme
 
     private static final String applicationName = "its-op-server";
 
-    @Autowired
+    //@Autowired
     public ItsOpServerApplication() {
         super();
         setRegisterErrorPageFilter(false);

+ 22 - 0
src/main/java/com/its/op/entity/its/cctv/TbCctvCtlr.java

@@ -377,6 +377,25 @@ public class TbCctvCtlr implements Serializable {
                     .zoom(0)
                     .focus(0)
                     .build();
+            if ("N".equals(this.syopCntlYn)) {
+                // 제어불가 CCTV 는 정상으로 설정
+                // 운영단말 화면에서 제어 못하도록 화면설정 해야함
+                state.setUpdtDt(ItsUtils.getSysTime());
+
+                state.setCmncSttsCd(CmmnCdManager.CMNC_STTS_NORMAL);
+                state.setCboxDoorSttsCd("CDS0");
+                state.setFrontDoorSttsCd("CDS0");
+                state.setBackDoorSttsCd("CDS0");
+                state.setFanSttsCd("PAS0");
+                state.setHetrSttsCd("HTS0");
+                state.setVideoInput("VDI0");
+                state.setCboxTmpr(0);
+                state.setCboxHmdt(0);
+                state.setPan(0);
+                state.setTilt(0);
+                state.setZoom(0);
+                state.setFocus(0);
+            }
             this.state = state;
         }
         return this.state;
@@ -386,6 +405,9 @@ public class TbCctvCtlr implements Serializable {
         if (alarm == null || "N".equals(alarm.getUseYn())) {
             return;
         }
+        if ("N".equals(this.syopCntlYn)) {
+            return;
+        }
         if ("N".equals(alarm.getCmncStts())) {
             getState().setCmncSttsCd(CmmnCdManager.CMNC_STTS_NORMAL);
             getState().setUpdtDt(ItsUtils.getSysTime());

+ 115 - 0
src/main/java/com/its/op/service/its/cctv/CctvControlHanwhaService.java

@@ -0,0 +1,115 @@
+package com.its.op.service.its.cctv;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.HttpClientBuilder;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Base64;
+
+/**
+ * Hanwha Techwin 네트워크 카메라
+ * SNP-3120VH
+ */
+public class CctvControlHanwhaService {
+    private static final String CAMERA_IP = "192.168.0.10"; // 카메라 IP 주소
+    private static final int CAMERA_PORT = 80; // 카메라 포트
+    private static final String USERNAME = "admin"; // 카메라 로그인 사용자 이름
+    private static final String PASSWORD = "4321"; // 카메라 로그인 비밀번호
+
+    public static void test() {
+        panLeft(10); // 왼쪽으로 10도 이동
+        panRight(10); // 오른쪽으로 10도 이동
+        tiltUp(10); // 위쪽으로 10도 이동
+        tiltDown(10); // 아래쪽으로 10도 이동
+        zoomIn(); // 줌 인
+        zoomOut(); // 줌 아웃
+        focusNear(); // 초점을 가까이 조정
+        focusFar(); // 초점을 멀리 조정
+    }
+
+    // 팬을 좌측으로 angle 만큼 이동시키는 메소드
+    private static void panLeft(int angle) {
+        String command = "/stw-cgi/ptz.cgi?action=start&channel=0&code=PanLeft&arg1=" + angle + "&arg2=0&arg3=0";
+        executeCommand(command);
+    }
+
+    // 팬을 우측으로 angle만큼 이동시키는 메소드
+    private static void panRight(int angle) {
+        String command = "/stw-cgi/ptz.cgi?action=start&channel=0&code=PanRight&arg1=" + angle + "&arg2=0&arg3=0";
+        executeCommand(command);
+    }
+
+    // 틸트를 위쪽으로 angle만큼 이동시키는 메소드
+    private static void tiltUp(int angle) {
+        String command = "/stw-cgi/ptz.cgi?action=start&channel=0&code=TiltUp&arg1=0&arg2=" + angle + "&arg3=0";
+        executeCommand(command);
+    }
+
+    // 틸트를 아래쪽으로 angle만큼 이동시키는 메소드
+    private static void tiltDown(int angle) {
+        String command = "/stw-cgi/ptz.cgi?action=start&channel=0&code=TiltDown&arg1=0&arg2=" + angle + "&arg3=0";
+        executeCommand(command);
+    }
+    // 줌 인하는 메소드
+    private static void zoomIn() {
+        String command = "/stw-cgi/ptz.cgi?action=start&channel=0&code=ZoomTele&arg1=0&arg2=0&arg3=0";
+        executeCommand(command);
+    }
+
+    // 줌 아웃하는 메소드
+    private static void zoomOut() {
+        String command = "/stw-cgi/ptz.cgi?action=start&channel=0&code=ZoomWide&arg1=0&arg2=0&arg3=0";
+        executeCommand(command);
+    }
+
+    // 초점을 가까이 조정하는 메소드
+    private static void focusNear() {
+        String command = "/stw-cgi/ptz.cgi?action=start&channel=0&code=FocusNear&arg1=0&arg2=0&arg3=0";
+        executeCommand(command);
+    }
+
+    // 초점을 멀리 조정하는 메소드
+    private static void focusFar() {
+        String command = "/stw-cgi/ptz.cgi?action=start&channel=0&code=FocusFar&arg1=0&arg2=0&arg3=0";
+        executeCommand(command);
+    }
+    private String getEncodeCommand(String userId, String userPswd) {
+        String encoding;
+        String command = userId + ":" + userPswd;
+        encoding = Base64.getEncoder().encodeToString(command.getBytes(StandardCharsets.UTF_8));
+        return encoding;
+    }
+    // 카메라 로그인 정보를 Base64로 인코딩하여 반환하는 메소드
+    private static String encodeCredentials(String username, String password) {
+        String credentials = username + ":" + password;
+        byte[] credentialsBytes = credentials.getBytes();
+        return new String(Base64.getEncoder().encode(credentialsBytes));
+    }
+
+
+    // 카메라에 PTZ 제어 명령을 전송하는 메소드
+    private static void executeCommand(String command) {
+        try {
+            // 카메라에 전송할 URL 생성
+            String url = "http://" + CAMERA_IP + ":" + CAMERA_PORT + command;
+
+            // HttpGet 객체 생성 및 Header 에 인증 정보 추가
+            HttpClient httpClient = HttpClientBuilder.create().build();
+            HttpGet request = new HttpGet(url);
+            request.addHeader("Authorization", "Basic " + encodeCredentials(USERNAME, PASSWORD));
+
+            // 카메라에 명령 전송
+            HttpResponse response = httpClient.execute(request);
+
+            // 응답 코드 확인
+            int statusCode = response.getStatusLine().getStatusCode();
+            if (statusCode != 200) {
+                System.out.println("Error: Failed to execute command. Response code - " + statusCode);
+            }
+        } catch (Exception e) {
+            System.out.println("Error: Failed to execute command. Exception - " + e.getMessage());
+        }
+    }
+}

+ 109 - 0
src/main/java/com/its/op/service/its/cctv/SNP3120VHControl.java

@@ -0,0 +1,109 @@
+package com.its.op.service.its.cctv;
+
+import org.apache.http.HttpStatus;
+import org.apache.http.client.config.RequestConfig;
+import org.apache.http.client.methods.CloseableHttpResponse;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.CloseableHttpClient;
+import org.apache.http.impl.client.HttpClients;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+
+public class SNP3120VHControl {
+    private String baseUrl;
+    private int timeout;
+
+    private CloseableHttpClient httpClient;
+    private RequestConfig requestConfig;
+
+    public SNP3120VHControl(String ipAddress, int port, String username, String password) {
+
+        this.requestConfig = RequestConfig.custom()
+                .setConnectTimeout(3000)
+                .setConnectionRequestTimeout(3000)
+                .setSocketTimeout(5000)
+                .build();
+        this.httpClient = HttpClients.custom()
+                .setDefaultRequestConfig(requestConfig)
+                .build();
+    }
+
+    public void moveUp(int speed) throws IOException {
+        String command = "/cgi-bin/stw-cgi/ptzcontrol.cgi?msubmenu=continuous&action=control&tilt=up&speed=" + speed;
+        executeCommand(command);
+    }
+
+    public void moveDown(int speed) throws IOException {
+        String command = "/cgi-bin/stw-cgi/ptzcontrol.cgi?msubmenu=continuous&action=control&tilt=down&speed=" + speed;
+        executeCommand(command);
+    }
+
+    public void moveLeft(int speed) throws IOException {
+        String command = "/cgi-bin/stw-cgi/ptzcontrol.cgi?msubmenu=continuous&action=control&pan=left&speed=" + speed;
+        executeCommand(command);
+    }
+
+    public void moveRight(int speed) throws IOException {
+        String command = "/cgi-bin/stw-cgi/ptzcontrol.cgi?msubmenu=continuous&action=control&pan=right&speed=" + speed;
+        executeCommand(command);
+    }
+
+    public void zoomIn(int speed) throws IOException {
+        String command = "/cgi-bin/stw-cgi/ptzcontrol.cgi?msubmenu=continuous&action=control&zoom=tele&speed=" + speed;
+        executeCommand(command);
+    }
+
+    public void zoomOut(int speed) throws IOException {
+        String command = "/cgi-bin/stw-cgi/ptzcontrol.cgi?msubmenu=continuous&action=control&zoom=wide&speed=" + speed;
+        executeCommand(command);
+    }
+
+    public void focusNear(int speed) throws IOException {
+        String command = "/cgi-bin/stw-cgi/ptzcontrol.cgi?msubmenu=continuous&action=control&focus=near&speed=" + speed;
+        executeCommand(command);
+    }
+
+    public void focusFar(int speed) throws IOException {
+        String command = "/cgi-bin/stw-cgi/ptzcontrol.cgi?msubmenu=continuous&action=control&focus=far&speed=" + speed;
+        executeCommand(command);
+    }
+
+    public void goToPreset(int presetNumber) throws IOException {
+        String command = "/cgi-bin/stw-cgi/presetcontrol.cgi?action=goto&number=" + presetNumber;
+        executeCommand(command);
+    }
+
+    public void setPreset(int presetNumber) throws IOException {
+        String command = "/cgi-bin/stw-cgi/presetcontrol.cgi?action=set&number=" + presetNumber;
+        executeCommand(command);
+    }
+    public void deletePreset(String presetNumber) throws IOException {
+        String url = String.format("%s/stw-cgi/presetcontrol.cgi?action=remove&name=%s", this.baseUrl, presetNumber);
+        HttpGet httpGet = new HttpGet(url);
+        RequestConfig requestConfig = RequestConfig.custom()
+                .setSocketTimeout(this.timeout)
+                .setConnectTimeout(this.timeout)
+                .build();
+        httpGet.setConfig(requestConfig);
+        try (CloseableHttpResponse response = this.httpClient.execute(httpGet)) {
+            int statusCode = response.getStatusLine().getStatusCode();
+            if (statusCode != HttpStatus.SC_OK) {
+                throw new IOException(String.format("Failed to delete preset %s: HTTP status code %d", presetNumber, statusCode));
+            }
+        }
+    }
+    private String executeCommand(String command) throws IOException {
+        String[] commandArray = new String[]{"bash", "-c", command};
+        Process process = Runtime.getRuntime().exec(commandArray);
+        try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
+            StringBuilder stringBuilder = new StringBuilder();
+            String line;
+            while ((line = reader.readLine()) != null) {
+                stringBuilder.append(line).append("\n");
+            }
+            return stringBuilder.toString();
+        }
+    }
+}

+ 3 - 0
src/main/java/com/its/op/service/its/cctv/TbCctvCtlrService.java

@@ -169,6 +169,9 @@ public class TbCctvCtlrService {
                 if (alarm != null && "Y".equals(alarm.getUseYn()) && "N".equals(alarm.getCmncStts())) {
                     return;
                 }
+                if ("N".equals(obj.getSyopCntlYn())) {
+                    return;
+                }
                 SttsCommErrDto commErrorDto = new SttsCommErrDto();
                 commErrorDto.setCtlrNmbr(String.valueOf(dto.getCctvCtlrNmbr()));
                 commErrorDto.setCtlrId(dto.getCctvCtlrId());