From 456ef2c5e4f13340fff16dbabe33d0d3114921c5 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Wed, 27 Dec 2023 15:32:43 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gb28181/transmit/cmd/ISIPCommander.java | 4 +-- .../transmit/cmd/impl/SIPCommander.java | 18 +++++----- .../gb28181/device/DeviceControl.java | 34 ++++++++++++------- 3 files changed, 31 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java index db7809af..f89a2dd2 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java @@ -222,9 +222,9 @@ public interface ISIPCommander { * @param channelId 通道id,非通道则是设备本身 * @param enabled 看守位使能:1 = 开启,0 = 关闭 * @param resetTime 自动归位时间间隔,开启看守位时使用,单位:秒(s) - * @param presetIndex 调用预置位编号,开启看守位时使用,取值范围0~255 + * @param presetId 调用预置位编号,开启看守位时使用,取值范围0~255 */ - void homePositionCmd(Device device, String channelId, boolean enabled, String resetTime, String presetIndex, SipSubscribe.Event errorEvent,SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException; + void homePositionCmd(Device device, String channelId, boolean enabled, String resetTime, Integer presetId, SipSubscribe.Event errorEvent,SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException; /** * 设备配置命令 diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java index 6d07c0af..c4c5a998 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java @@ -691,7 +691,7 @@ public class SIPCommander implements ISIPCommander { * * @param device 视频设备 * @param channelId 预览通道 - * @param recordCmdStr 录像命令:Record / StopRecord + * @param record 录像命令:Record / StopRecord */ @Override public void recordCmd(Device device, String channelId, boolean record, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException { @@ -748,7 +748,7 @@ public class SIPCommander implements ISIPCommander { * 报警布防/撤防命令 * * @param device 视频设备 - * @param guardCmdStr "SetGuard"/"ResetGuard" + * @param setGuard "SetGuard"/"ResetGuard" */ @Override public void guardCmd(Device device, boolean setGuard, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException { @@ -843,10 +843,10 @@ public class SIPCommander implements ISIPCommander { * @param channelId 通道id,非通道则是设备本身 * @param enabled 看守位使能:1 = 开启,0 = 关闭 * @param resetTime 自动归位时间间隔,开启看守位时使用,单位:秒(s) - * @param presetIndex 调用预置位编号,开启看守位时使用,取值范围0~255 + * @param presetId 调用预置位编号,开启看守位时使用,取值范围0~255 */ @Override - public void homePositionCmd(Device device, String channelId, String enabled, String resetTime, String presetIndex, SipSubscribe.Event errorEvent,SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException { + public void homePositionCmd(Device device, String channelId, boolean enabled, String resetTime, Integer presetId, SipSubscribe.Event errorEvent,SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException { StringBuffer cmdXml = new StringBuffer(200); String charset = device.getCharset(); @@ -860,26 +860,24 @@ public class SIPCommander implements ISIPCommander { cmdXml.append("" + channelId + "\r\n"); } cmdXml.append("\r\n"); - if (NumericUtil.isInteger(enabled) && (!enabled.equals("0"))) { + if (enabled) { cmdXml.append("1\r\n"); if (NumericUtil.isInteger(resetTime)) { cmdXml.append("" + resetTime + "\r\n"); } else { cmdXml.append("0\r\n"); } - if (NumericUtil.isInteger(presetIndex)) { - cmdXml.append("" + presetIndex + "\r\n"); + if (presetId != null) { + cmdXml.append("" + presetId + "\r\n"); } else { cmdXml.append("0\r\n"); } - } else { + }else { cmdXml.append("0\r\n"); } cmdXml.append("\r\n"); cmdXml.append("\r\n"); - - Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport())); sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, errorEvent,okEvent); } diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceControl.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceControl.java index c71647ca..b5e370b5 100755 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceControl.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/device/DeviceControl.java @@ -14,7 +14,6 @@ import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander; -import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.storager.IVideoManagerStorage; import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; import io.swagger.v3.oas.annotations.Operation; @@ -71,9 +70,10 @@ public class DeviceControl { @Parameter(name = "deviceId", description = "设备国标编号", required = true) @Parameter(name = "channelId", description = "通道国标编号", required = true) @Parameter(name = "command", description = "控制命令,可选值:start(手动录像),stop(停止手动录像)", required = true) - @GetMapping("/record/{deviceId}/{channelId}/{command}") - public DeferredResult> recordApi(@PathVariable String deviceId, @PathVariable String channelId, - @PathVariable String command) { + @GetMapping("/record/{deviceId}/{channelId}") + public DeferredResult> recordApi(@PathVariable String deviceId, + @PathVariable String channelId, + String command) { if (logger.isDebugEnabled()) { logger.debug("开始/停止录像API调用"); } @@ -125,8 +125,8 @@ public class DeviceControl { @Parameter(name = "deviceId", description = "设备国标编号", required = true) @Parameter(name = "channelId", description = "通道国标编号", required = true) @Parameter(name = "command", description = "控制命令,可选值:start(布防),stop(撤防)", required = true) - @GetMapping("/guard/{deviceId}/{command}") - public DeferredResult guardApi(@PathVariable String deviceId, @PathVariable String command) { + @GetMapping("/guard/{deviceId}") + public DeferredResult guardApi(@PathVariable String deviceId, String command) { if (logger.isDebugEnabled()) { logger.debug("布防/撤防API调用"); } @@ -250,14 +250,14 @@ public class DeviceControl { @Parameter(name = "deviceId", description = "设备国标编号", required = true) @Parameter(name = "channelId", description = "通道国标编号", required = true) @Parameter(name = "command", description = "控制命令: start-开启看守位 stop-关闭看守位", required = true) - @Parameter(name = "presetIndex", description = "调用预置位编号, 取值范围为-255") + @Parameter(name = "presetId", description = "调用预置位编号, 取值范围为-255") @Parameter(name = "resetTime", description = "自动归位时间间隔,单位:秒(s)") - @GetMapping("/home_position/{deviceId}/{command}") + @GetMapping("/home_position/{deviceId}") public DeferredResult homePositionApi(@PathVariable String deviceId, - @PathVariable String command, - @RequestParam(required = false) String resetTime, - @RequestParam(required = false) String presetIndex, - String channelId) { + String command, + @RequestParam(required = false) String resetTime, + @RequestParam(required = false) Integer presetId, + String channelId) { if (logger.isDebugEnabled()) { logger.debug("报警复位API调用"); } @@ -267,8 +267,16 @@ public class DeviceControl { if (device == null) { throw new ControllerException(ErrorCode.ERROR100.getCode(), deviceId + "不存在"); } + boolean enabled; + if (command.equalsIgnoreCase("start")) { + enabled = true; + }else if (command.equalsIgnoreCase("stop")) { + enabled = false; + }else { + throw new ControllerException(ErrorCode.ERROR100.getCode(), "command参数不是规定值"); + } try { - cmder.homePositionCmd(device, channelId, enabled, resetTime, presetIndex, event -> { + cmder.homePositionCmd(device, channelId, enabled, resetTime, presetId, event -> { RequestMessage msg = new RequestMessage(); msg.setId(uuid); msg.setKey(key);