| 
					
				 | 
			
			
				@@ -1,12 +1,14 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 package com.its.cctv.api.service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.its.app.utils.ByteUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.its.cctv.api.dto.CctvParamControlDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.its.cctv.api.dto.CctvPresetControlDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.its.cctv.api.dto.CctvPtzControlDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.its.cctv.api.dto.CctvStatusDto; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.its.cctv.domain.NET; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.its.cctv.entity.TbCctvCtlr; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.its.cctv.global.AppRepository; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+import com.its.cctv.xnettcp.cctv.protocol.CctvReqParamSet; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.its.cctv.xnettcp.cctv.protocol.CctvReqPresetMove; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.its.cctv.xnettcp.cctv.protocol.CctvReqPresetQry; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 import com.its.cctv.xnettcp.cctv.protocol.CctvReqPtzCtrl; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -101,7 +103,7 @@ public class CctvControlService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public CctvPtzControlDto.CctvPtzControlRes controlPtz(Long id, CctvPtzControlDto.CctvControlPtzReq req) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        log.info("{}", req); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        log.info("controlPtz: {}", req); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         TbCctvCtlr cctv = this.requireOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (cctv == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return new CctvPtzControlDto.CctvPtzControlRes(req.getCommand(), req.getAction(), 1, "알수없는 CCTV 관리번호 입니다."); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -158,10 +160,10 @@ public class CctvControlService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				      */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public CctvPresetControlDto.CctvPresetControlRes controlPreset(Long id, CctvPresetControlDto.CctvPresetControlReq req) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        log.info("{}", req); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        log.info("controlPreset: {}", req); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         TbCctvCtlr cctv = this.requireOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (cctv == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return new CctvPresetControlDto.CctvPresetControlRes(1, "unknown cctv type"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return new CctvPresetControlDto.CctvPresetControlRes(1, "CCTV 제어기 정보를 찾을 수 없습니다."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (cctv.getNetState() != NET.LOGINED) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return new CctvPresetControlDto.CctvPresetControlRes(2, "CCTV 통신연결이 되어 있지 않습니다."); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -179,26 +181,120 @@ public class CctvControlService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+     
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public CctvParamControlDto.CctvParamControlRes controlParam(Long id, CctvParamControlDto.CctvParamControlReq req) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        log.info("controlParam: {}", id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TbCctvCtlr cctv = this.requireOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (cctv == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return new CctvParamControlDto.CctvParamControlRes(1, "CCTV 제어기 정보를 찾을 수 없습니다."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (cctv.getNetState() != NET.LOGINED) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return new CctvParamControlDto.CctvParamControlRes(2, "CCTV 통신연결이 되어 있지 않습니다."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        CctvParamControlDto.CctvParamControlRes result = new CctvParamControlDto.CctvParamControlRes(0, "success"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        CctvReqParamSet pkt = new CctvReqParamSet(cctv.getAddress()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        pkt.setValue(req.getFanOnTmpr().byteValue(), req.getFanOffTmpr().byteValue(), req.getHetrOnTmpr().byteValue(), req.getHetrOffTmpr().byteValue()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        ByteBuffer sendBuffer = pkt.getByteBuffer(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (cctv.sendData(sendBuffer, 0, "cctv_ParamSet")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            log.info("PARAMETER SET send success."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            result.setResult(4, "CCTV PARAMETER 명령 전송이 실패하였습니다."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            log.error("PARAMETER SET send failed."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public CctvParamControlDto.CctvParamValueRes requestParam(Long id) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        log.info("requestParam: {}", id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TbCctvCtlr cctv = this.requireOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (cctv == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return new CctvParamControlDto.CctvParamValueRes(1, "CCTV 제어기 정보를 찾을 수 없습니다."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (cctv.getNetState() != NET.LOGINED) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return new CctvParamControlDto.CctvParamValueRes(2, "CCTV 통신연결이 되어 있지 않습니다."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        CctvParamControlDto.CctvParamValueRes result = new CctvParamControlDto.CctvParamValueRes(0, "success"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        synchronized (cctv.getParamVal()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                cctv.getParamVal().setCompleted(false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ByteBuffer sendBuffer = cctv.getReqParam().getByteBuffer(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (cctv.sendData(sendBuffer, 0, "cctv_ParamReq")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    log.info("PARAMETER QRY send success."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    cctv.getParamVal().wait(5000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (cctv.getParamVal().isCompleted()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        result.setValue(cctv.getParamVal().getFanOnTmpr(), cctv.getParamVal().getFanOffTmpr(), cctv.getParamVal().getHetrOnTmpr(), cctv.getParamVal().getHetrOffTmpr()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        result.setResult(5, "CCTV PARAMETER 값조회 명령 중 타임아웃이 발생하였습니다."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    result.setResult(4, "CCTV PARAMETER 값조회 명령 전송이 실패하였습니다."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    log.error("PARAMETER QRY send failed."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } catch (InterruptedException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                result.setResult(9, "CCTV PARAMETER 값조회 명령 전송 중 오류가 발생하였습니다."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     public CctvPresetControlDto.CctvPresetValueRes requestPresetValue(Long id) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        log.info("{}", id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        log.info("requestPresetValue: {}", id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         TbCctvCtlr cctv = this.requireOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (cctv == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            return new CctvPresetControlDto.CctvPresetValueRes(1, "unknown cctv type"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return new CctvPresetControlDto.CctvPresetValueRes(1, "CCTV 제어기 정보를 찾을 수 없습니다."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (cctv.getNetState() != NET.LOGINED) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             return new CctvPresetControlDto.CctvPresetValueRes(2, "CCTV 통신연결이 되어 있지 않습니다."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         CctvPresetControlDto.CctvPresetValueRes result = new CctvPresetControlDto.CctvPresetValueRes(0, "success"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        CctvReqPresetQry pkt = new CctvReqPresetQry(cctv.getAddress()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        pkt.setValue((byte)0x00); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        ByteBuffer sendBuffer = pkt.getByteBuffer(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (cctv.sendData(sendBuffer, 0, "cctv_PresetQry")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            log.info("PRESET QRY send success."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            result.setResult(4, "CCTV PRESET 값조회 명령 전송이 실패하였습니다."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            log.error("PRESET QRY send failed."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        synchronized (cctv.getPsetVal()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                cctv.getPsetVal().setCompleted(false); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                CctvReqPresetQry pkt = new CctvReqPresetQry(cctv.getAddress()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                pkt.setValue((byte)0x00); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                ByteBuffer sendBuffer = pkt.getByteBuffer(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (cctv.sendData(sendBuffer, 0, "cctv_PresetQry")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    log.info("PRESET QRY send success."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    cctv.getPsetVal().wait(5000); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    if (cctv.getPsetVal().isCompleted()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        result.setValue(cctv.getPsetVal().getPan(), cctv.getPsetVal().getTilt(), cctv.getPsetVal().getZoom(), cctv.getPsetVal().getFocus()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                        result.setResult(5, "CCTV PRESET 값조회 명령 중 타임아웃이 발생하였습니다."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    result.setResult(4, "CCTV PRESET 값조회 명령 전송이 실패하였습니다."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    log.error("PRESET QRY send failed."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } catch (InterruptedException e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                result.setResult(9, "CCTV PRESET 값조회 명령 전송 중 오류가 발생하였습니다."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    public CctvStatusDto.CctvStatusNotifyDtoRes notifyStatus(Long id) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        log.info("notifyStatus: {}", id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        TbCctvCtlr cctv = this.requireOne(id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (cctv == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return new CctvStatusDto.CctvStatusNotifyDtoRes(1, "CCTV 제어기 정보를 찾을 수 없습니다."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        if (cctv.getNetState() != NET.LOGINED) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            return new CctvStatusDto.CctvStatusNotifyDtoRes(2, "CCTV 통신연결이 되어 있지 않습니다."); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        CctvStatusDto.CctvStatusNotifyDtoRes result = new CctvStatusDto.CctvStatusNotifyDtoRes(0, "success"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        synchronized (cctv.getPsetVal()) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                cctv.getPsetVal().notifyAll(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            catch(Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                log.error("{}, {}", cctv.getPsetVal(), e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     } 
			 |