zhangqiankun 3 years ago
parent
commit
8ff5f2f5e7

+ 3 - 2
src/main/java/com/persagy/cameractl/controller/HelloController.java

@@ -133,9 +133,10 @@ public class HelloController {
         
         ResultClass executeResult = operType.equals("currentVideo") ? dahCameraExecuteApi.currentVideo(sceneConfig.getNvrSceneRelation())
         		: operType.equals("currentlunx") ? dahCameraExecuteApi.currentlunx(sceneConfig.getNvrSceneRelation())
-        				: operType.equals("lunx") ? dahCameraExecuteApi.lunx(sceneConfig) 
+        				: operType.equals("transitionScene") ? dahCameraExecuteApi.transitionScene(sceneConfig)
         						: operType.equals("toup") ? dahCameraExecuteApi.toup(sceneConfig) 
-        								: new ResultClass(false, "非法请求");
+        								: operType.equals("lunx") ? dahCameraExecuteApi.lunx(sceneConfig) 
+        										: new ResultClass(false, "非法请求");
 
         switch (String.valueOf(executeResult.name)) {
             case "true":

+ 17 - 12
src/main/java/com/persagy/cameractl/service/socket/TclSocketClient.java

@@ -24,25 +24,30 @@ import lombok.extern.slf4j.Slf4j;
 @Slf4j
 public class TclSocketClient {
 
+	public static final String COMMAND = "gload {} {}\\r";
+	
 	public static final EventLoopGroup GROUP = new NioEventLoopGroup();
 
 	public static final Bootstrap BS = new Bootstrap();
 
+	static {
+		// 注册线程池、使用NioSocketChannel来作为连接用的channel类
+		BS.group(GROUP).channel(NioSocketChannel.class);
+	}
+	
 	public static void connectAndSend(String host, int port, String command) {
 		ChannelFuture cf = null;
 		try {
-			BS.group(GROUP) // 注册线程池
-					.channel(NioSocketChannel.class) // 使用NioSocketChannel来作为连接用的channel类
-					.remoteAddress(new InetSocketAddress(host, port)) // 绑定连接端口和host信息
-					.handler(new ChannelInitializer<SocketChannel>() { // 绑定连接初始化器
-						@Override
-						protected void initChannel(SocketChannel ch) throws Exception {
-							log.info("正在连接中...");
-							ch.pipeline().addLast(new StringEncoder(CharsetUtil.UTF_8));
-							ch.pipeline().addLast(new StringDecoder(CharsetUtil.UTF_8));
-							ch.pipeline().addLast(new TclClientHandler(command));
-						}
-					});
+			BS.remoteAddress(new InetSocketAddress(host, port)) // 绑定连接端口和host信息
+				.handler(new ChannelInitializer<SocketChannel>() { // 绑定连接初始化器
+					@Override
+					protected void initChannel(SocketChannel ch) throws Exception {
+						log.info("正在连接中...");
+						ch.pipeline().addLast(new StringEncoder(CharsetUtil.UTF_8));
+						ch.pipeline().addLast(new StringDecoder(CharsetUtil.UTF_8));
+						ch.pipeline().addLast(new TclClientHandler(command));
+					}
+				});
 
 			cf = BS.connect().sync(); // 异步连接服务器
 			log.info("服务端连接成功...");

+ 27 - 2
src/main/java/com/persagy/cameractl/service/windows/Nvr9CameraExecuteApi.java

@@ -12,6 +12,7 @@ import com.persagy.cameractl.model.Camera;
 import com.persagy.cameractl.model.Channel;
 import com.persagy.cameractl.model.NvrSceneRelation;
 import com.persagy.cameractl.model.SceneConfig;
+import com.persagy.cameractl.service.socket.TclSocketClient;
 import com.persagy.cameractl.utils.OtherTools;
 import com.persagy.cameractl.utils.ResultClass;
 import com.persagy.vsknet.structure.CurShowDevEx;
@@ -28,6 +29,7 @@ import com.sun.jna.platform.win32.WinDef.UINT;
 
 import cn.hutool.core.collection.CollectionUtil;
 import cn.hutool.core.util.BooleanUtil;
+import cn.hutool.core.util.StrUtil;
 import lombok.extern.slf4j.Slf4j;
 
 /**
@@ -39,11 +41,34 @@ import lombok.extern.slf4j.Slf4j;
  */
 @Slf4j
 public class Nvr9CameraExecuteApi {
-
+	
 	/** 当前登陆者 */
 	private UINT login_id;
 	
+	/**
+	 * 切换场景
+	 * 
+	 * @param sceneConfig
+	 * @return
+	 * @date 2021年10月27日 下午6:01:38
+	 */
+	public ResultClass transitionScene(SceneConfig sceneConfig) {
+		if (sceneConfig.getGroup() <= 0 || sceneConfig.getScene() <= 0) {
+			return this.executeErr(false, null, "非法场景参数");
+		}
+		
+		TclSocketClient.connectAndSend(NVR9Config.tclIp, NVR9Config.tclPort, 
+				StrUtil.format(TclSocketClient.COMMAND, sceneConfig.getGroup(), sceneConfig.getScene()));
+		return this.executeSuccess(false, "场景已切换");
+	}
 	
+	/**
+	 * 轮询设置
+	 * 
+	 * @param sceneConfig
+	 * @return
+	 * @date 2021年10月27日 下午6:01:31
+	 */
 	public ResultClass lunx(SceneConfig sceneConfig) {
 		List<Channel> channels = sceneConfig.getChannels();
 		for (Channel channel : channels) {
@@ -472,5 +497,5 @@ public class Nvr9CameraExecuteApi {
 			}
 		}
 	}
-	
+
 }