From 73cf35e733197c8a2177007f9559f3dd93291ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?LAPTOP-S9HJSOEB=5C=E6=98=8A=E5=A4=A9?= Date: Thu, 4 Jan 2024 19:56:11 +0800 Subject: [PATCH] =?UTF-8?q?1.=E5=85=89=E6=BA=90=E5=A2=9E=E5=8A=A0tcp?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=202.=E9=87=8D=E7=BD=AE=E7=90=83=E6=9C=BA?= =?UTF-8?q?=E6=96=B9=E5=90=91=E5=A2=9E=E5=8A=A0=E5=BB=B6=E6=97=B6=E6=89=A9?= =?UTF-8?q?=E5=B1=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/config/ConfigProperties.java | 1 + .../web/controller/StreetController.java | 8 +++ .../web/service/LightSourceService.java | 54 +++++++++++++++++++ .../com/zhehekeji/web/service/PlcService.java | 5 ++ 4 files changed, 68 insertions(+) diff --git a/web/src/main/java/com/zhehekeji/web/config/ConfigProperties.java b/web/src/main/java/com/zhehekeji/web/config/ConfigProperties.java index 8e870af..003dd9b 100644 --- a/web/src/main/java/com/zhehekeji/web/config/ConfigProperties.java +++ b/web/src/main/java/com/zhehekeji/web/config/ConfigProperties.java @@ -65,6 +65,7 @@ public class ConfigProperties { private Long delayDownloadMp4; + public Long verticalAdjustmentTime = 2L; } @Data diff --git a/web/src/main/java/com/zhehekeji/web/controller/StreetController.java b/web/src/main/java/com/zhehekeji/web/controller/StreetController.java index 2e39603..93164fd 100644 --- a/web/src/main/java/com/zhehekeji/web/controller/StreetController.java +++ b/web/src/main/java/com/zhehekeji/web/controller/StreetController.java @@ -103,6 +103,8 @@ public class StreetController { }else if(configProperties.getLightSource().getType() == 2){ HikControlSocket.openLight(lightSource.getIp(),lightSource.getPort(),configProperties.getLightSource().getIndex(),1); + }else if (configProperties.getLightSource().getType() == 3){ + LightSourceService.lightController(lightSource.getIp(),lightSource.getPort(),1); } }); @@ -126,6 +128,8 @@ public class StreetController { log.info("ip:{},status:{}",lightSource.getIp(),status); }else if(configProperties.getLightSource().getType() == 2){ HikControlSocket.openLight(lightSource.getIp(),lightSource.getPort(),configProperties.getLightSource().getIndex(),0); + }else if (configProperties.getLightSource().getType() == 3){ + LightSourceService.lightController(lightSource.getIp(),lightSource.getPort(),0); } }); @@ -146,6 +150,8 @@ public class StreetController { equip.DisConnect(); }else if(configProperties.getLightSource().getType() == 2){ HikControlSocket.openLight(lightSource.getIp(),lightSource.getPort(),configProperties.getLightSource().getIndex(),1); + }else if (configProperties.getLightSource().getType() == 3){ + LightSourceService.lightController(lightSource.getIp(),lightSource.getPort(),1); } }); @@ -166,6 +172,8 @@ public class StreetController { equip.DisConnect(); }else if(configProperties.getLightSource().getType() == 2){ HikControlSocket.openLight(lightSource.getIp(),lightSource.getPort(),configProperties.getLightSource().getIndex(),0); + }else if (configProperties.getLightSource().getType() == 3){ + LightSourceService.lightController(lightSource.getIp(),lightSource.getPort(),0); } }); diff --git a/web/src/main/java/com/zhehekeji/web/service/LightSourceService.java b/web/src/main/java/com/zhehekeji/web/service/LightSourceService.java index 3f60d19..0da209e 100644 --- a/web/src/main/java/com/zhehekeji/web/service/LightSourceService.java +++ b/web/src/main/java/com/zhehekeji/web/service/LightSourceService.java @@ -6,6 +6,12 @@ import com.zhehekeji.web.mapper.LightSourceMapper; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.InetSocketAddress; +import java.net.Socket; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; @@ -22,4 +28,52 @@ public class LightSourceService { public List getLightSourceByStreetId(Integer streetId){ return lightSourceMapper.selectList(new QueryWrapper().eq("street_id",streetId)); } + + /** + * + * @param ip + * @param port + * @param stat 1开启,2关闭 + */ + public static void lightController(String ip ,Integer port,Integer stat){ + Socket socket = new Socket(); + OutputStream os = null; + InputStream is = null; + try { + socket.connect(new InetSocketAddress(ip,port),3000); + os = socket.getOutputStream(); + is = socket.getInputStream(); + int i = 0; + socket.setSoTimeout(1000); + String startCmd = "<1,"+stat+",post>"; + byte[]bytes = startCmd.getBytes(StandardCharsets.UTF_8); + os.write(bytes); + + + } catch (IOException e) { + + }finally { + if(os != null){ + try { + os.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if(is != null){ + try { + is.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + try { + socket.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } + + } } diff --git a/web/src/main/java/com/zhehekeji/web/service/PlcService.java b/web/src/main/java/com/zhehekeji/web/service/PlcService.java index 13feda9..8f43b06 100644 --- a/web/src/main/java/com/zhehekeji/web/service/PlcService.java +++ b/web/src/main/java/com/zhehekeji/web/service/PlcService.java @@ -157,6 +157,11 @@ public class PlcService { public void verticalAdjustmentByStreet(String SRMNumber){ Street street = streetService.getStreetByPlcId(SRMNumber); + try { + Thread.sleep(configProperties.getCameraConfig().getVerticalAdjustmentTime()*1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } if(street.getCamera1Id()!=null){ //重置垂直方向球机 verticalAdjustment(street.getCamera1Id());