浏览代码

control cctv probe update

shjung 3 年之前
父节点
当前提交
6e00230b8e

+ 1 - 0
src/main/java/com/its/op/controller/bis/BisController.java

@@ -45,6 +45,7 @@ public class BisController {
     @ApiOperation(value = "BIT 상태현황(Summary+List)", response = FcltSttsListDto.class, responseContainer = "ArrayList")
     @GetMapping(value = "/stts/bit/total", produces = {"application/json; charset=utf8"})
     public FcltSttsListDto findAllBitSttsTotal() {
+        // TODO: 쿼리 확인 요망
         return this.bitService.findAllListSttsTotal(true);
     }
 

+ 3 - 3
src/main/java/com/its/op/controller/its/LoginController.java

@@ -110,9 +110,9 @@ public class LoginController {
 
     public UserInfoDto getSessionUserInfo(HttpServletRequest request) {
         Cookie[] cookies = request.getCookies();
-        for (int ii = 0; ii < cookies.length; ii++) {
-            log.error("getSessionUserInfo: {}, {}", cookies[ii].getName(), cookies[ii].getValue());
-        }
+//        for (int ii = 0; ii < cookies.length; ii++) {
+//            log.info("getSessionUserInfo: {}, {}", cookies[ii].getName(), cookies[ii].getValue());
+//        }
         String encUserId = "";
         String loginHms = "";
         if (cookies != null && cookies.length > 0) {

+ 88 - 27
src/main/java/com/its/op/service/its/cctv/CctvControlProbeService.java

@@ -14,53 +14,114 @@ import java.util.Map;
 @Service
 public class CctvControlProbeService {
 
-    Map<String, String> startCmd = new HashMap<>();
-    Map<String, String> stopCmd = new HashMap<>();
-    Map<String, String> presetCmd = new HashMap<>();
+    Map<String, ProbeCommand> startCmd = new HashMap<>();
+    Map<String, ProbeCommand> stopCmd = new HashMap<>();
+    Map<String, ProbeCommand> presetCmd = new HashMap<>();
 
     @PostConstruct
     void init() {
-        this.startCmd.put("tilt-up",   "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=4&PTZCTRL.speed=");
-        this.startCmd.put("tilt-down", "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=5&PTZCTRL.speed=");
-        this.startCmd.put("pan-left",  "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=2&PTZCTRL.speed=");
-        this.startCmd.put("pan-right", "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=3&PTZCTRL.speed=");
-        this.startCmd.put("zoom-in",   "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=13&PTZCTRL.speed=");
-        this.startCmd.put("zoom-out",  "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=14&PTZCTRL.speed=");
-        this.startCmd.put("focus-in",  "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=15&PTZCTRL.speed=");
-        this.startCmd.put("focus-out", "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=16&PTZCTRL.speed=");
+        this.startCmd.put("tilt-up",   new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=4&PTZCTRL.speed=",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x30, (byte)0x34 }));
+        this.startCmd.put("tilt-down", new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=5&PTZCTRL.speed=",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x30, (byte)0x35 }));
+        this.startCmd.put("pan-left",  new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=2&PTZCTRL.speed=",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x30, (byte)0x32 }));
+        this.startCmd.put("pan-right", new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=3&PTZCTRL.speed=",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x30, (byte)0x33 }));
+        this.startCmd.put("zoom-in",   new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=13&PTZCTRL.speed=",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x33 }));
+        this.startCmd.put("zoom-out",  new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=14&PTZCTRL.speed=",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x34 }));
+        this.startCmd.put("focus-in",  new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=15&PTZCTRL.speed=",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x35 }));
+        this.startCmd.put("focus-out", new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=16&PTZCTRL.speed=",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x36 }));
 
-        this.stopCmd.put("tilt-up",   "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=0");
-        this.stopCmd.put("tilt-down", "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=0");
-        this.stopCmd.put("pan-left",  "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=0");
-        this.stopCmd.put("pan-right", "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=0");
-        this.stopCmd.put("zoom-in",   "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=0");
-        this.stopCmd.put("zoom-out",  "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=0");
-        this.stopCmd.put("focus-in",  "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=0");
-        this.stopCmd.put("focus-out", "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=0");
+        this.stopCmd.put("tilt-up",   new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=0",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x32, (byte)0x30, (byte)0x30 }));
+        this.stopCmd.put("tilt-down", new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=0",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x32, (byte)0x30, (byte)0x30 }));
+        this.stopCmd.put("pan-left",  new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=0",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x32, (byte)0x30, (byte)0x30 }));
+        this.stopCmd.put("pan-right", new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=0",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x32, (byte)0x30, (byte)0x30 }));
+        this.stopCmd.put("zoom-in",   new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=0",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x32, (byte)0x30, (byte)0x30 }));
+        this.stopCmd.put("zoom-out",  new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=0",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x32, (byte)0x30, (byte)0x30 }));
+        this.stopCmd.put("focus-in",  new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=0",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x32, (byte)0x30, (byte)0x30 }));
+        this.stopCmd.put("focus-out", new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=0",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x32, (byte)0x30, (byte)0x30 }));
 
-        this.presetCmd.put("call",    "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=11&PTZCTRL.no=");
-        this.presetCmd.put("save",    "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=10&PTZCTRL.no=");
-        this.presetCmd.put("delete",  "/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=12&PTZCTRL.no=");
+        this.presetCmd.put("call",    new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=11&PTZCTRL.no=",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x31 }));
+        this.presetCmd.put("save",    new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=10&PTZCTRL.no=",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x30 }));
+        this.presetCmd.put("delete",  new ProbeCommand("/cgi-bin/control.cgi?action=update&group=PTZCTRL&channel=0&PTZCTRL.action=12&PTZCTRL.no=",
+                new byte[]{ (byte)0x38, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x30, (byte)0x31, (byte)0x30 }));
     }
 
     public String getPtzCmd(String control, String action, int speed) {
         if (StringUtils.equalsIgnoreCase("start", action)) {
-            String command = this.startCmd.get(control);
+            ProbeCommand command = this.startCmd.get(control);
             if (command != null) {
-                return command + speed;
+                return command.getUri() + speed;
             }
         } else if (StringUtils.equalsIgnoreCase("stop", action)) {
-            return this.stopCmd.get(control);
+            ProbeCommand command = this.stopCmd.get(control);
+            if (command != null) {
+                return command.getUri();
+            }
+        }
+        return null;
+    }
+    public byte[] getPtzControlCmd(String control, String action, int speed) {
+        if (StringUtils.equalsIgnoreCase("start", action)) {
+            ProbeCommand command = this.startCmd.get(control);
+            if (command != null) {
+                return command.getCmd();
+            }
+        } else if (StringUtils.equalsIgnoreCase("stop", action)) {
+            ProbeCommand command = this.stopCmd.get(control);
+            if (command != null) {
+                return command.getCmd();
+            }
         }
         return null;
     }
 
     public String getPresetCmd(String action, Integer psetNmbr) {
-        String command = this.presetCmd.get(action);
+        ProbeCommand command = this.presetCmd.get(action);
         if (command != null) {
-            return command + psetNmbr;
+            return command.getUri() + psetNmbr;
         }
         return null;
     }
+    public byte[] getPresetControlCmd(String action, Integer psetNmbr) {
+        ProbeCommand command = this.presetCmd.get(action);
+        if (command != null) {
+            return command.getCmd();
+        }
+        return null;
+    }
+
+    public static class ProbeCommand {
+        private String uri;
+        private byte[] cmd;
+        public ProbeCommand(String uri, byte[] cmd) {
+            this.uri = uri;
+            if (cmd != null && cmd.length > 0) {
+                this.cmd = new byte[cmd.length];
+                System.arraycopy(cmd, 0, this.cmd, 0, cmd.length);
+            }
+        }
+        public String getUri() {
+            return this.uri;
+        }
+        public byte[] getCmd() {
+            return this.cmd;
+        }
+    }
 
 }

+ 7 - 4
src/main/java/com/its/op/service/its/cctv/CctvControlService.java

@@ -53,11 +53,12 @@ public class CctvControlService {
     public CctvControlDto.CctvControlRes controlPresetProbe(String ipAddr, String userId, String userPswd, CctvControlDto.CctvControlPresetReq req) {
         CctvControlDto.CctvControlRes result = new CctvControlDto.CctvControlRes(req.getCommand(), req.getAction(), 0, "success");
         String controlUri = this.probeControl.getPresetCmd(req.getAction(), req.getNo());
+        byte[] controlData = this.probeControl.getPresetControlCmd(req.getAction(), req.getNo());
         if (controlUri == null) {
             result.setResult(9, "unknown command");
             return result;
         }
-        return requestHttpPostProbe(result, controlUri, ipAddr, userId, userPswd);
+        return requestHttpPostProbe(result, controlUri, controlData, ipAddr, userId, userPswd);
     }
 
     /**
@@ -71,13 +72,14 @@ public class CctvControlService {
     public CctvControlDto.CctvControlRes controlPtzProbe(String ipAddr, String userId, String userPswd, CctvControlDto.CctvControlPtzReq req) {
         CctvControlDto.CctvControlRes result = new CctvControlDto.CctvControlRes(req.getCommand(), req.getAction(), 0, "success");
         String controlUri = this.probeControl.getPtzCmd(req.getCommand(), req.getAction(), req.getSpeed());
+        byte[] controlData = this.probeControl.getPtzControlCmd(req.getCommand(), req.getAction(), req.getSpeed());
         if (controlUri == null) {
             result.setResult(9, "unknown command");
             return result;
         }
-        return requestHttpPostProbe(result, controlUri, ipAddr, userId, userPswd);
+        return requestHttpPostProbe(result, controlUri, controlData, ipAddr, userId, userPswd);
     }
-    public CctvControlDto.CctvControlRes requestHttpPostProbe(CctvControlDto.CctvControlRes result, String controlUri, String ipAddr, String userId, String userPswd) {
+    public CctvControlDto.CctvControlRes requestHttpPostProbe(CctvControlDto.CctvControlRes result, String controlUri, byte[] controlData, String ipAddr, String userId, String userPswd) {
         String encoding = Base64.getEncoder().encodeToString((userId + ":" + userPswd).getBytes());
         String apiUrl = "http://" + ipAddr + controlUri;
         log.info("{}, Basis: {}", apiUrl, encoding);
@@ -97,13 +99,14 @@ public class CctvControlService {
             connection.setRequestProperty("Accept-Encoding", "identity");
             connection.setRequestProperty("Authorization", "Basic " + encoding);
             //connection.setRequestProperty("charset", "UTF-8");
-            //connection.setRequestProperty("Content-Length", Integer.toString(controlData.length));
+            connection.setRequestProperty("Content-Length", Integer.toString(controlData.length));
             connection.setRequestProperty("User-Agent", "Mozilla/3.0");
 
             //connection.setUseCaches(false);
             //connection.setDefaultUseCaches(false);
 
             DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
+            wr.write(controlData);
             wr.flush();
             wr.close();