From 25fca14e6224909811d96c348fc2427cf7fe13d1 Mon Sep 17 00:00:00 2001
From: gaofw189 <gaofw189@chinatelecom.cn>
Date: 星期一, 06 二月 2023 10:35:32 +0800
Subject: [PATCH] 修复WVP作为下级平台接受deviceControl指令的问题-修复指令响应
---
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/control/cmd/DeviceControlQueryMessageHandler.java | 240 ++++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 216 insertions(+), 24 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/control/cmd/DeviceControlQueryMessageHandler.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/control/cmd/DeviceControlQueryMessageHandler.java
index f97a659..fa54a0f 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/control/cmd/DeviceControlQueryMessageHandler.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/control/cmd/DeviceControlQueryMessageHandler.java
@@ -1,8 +1,9 @@
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.control.cmd;
-import com.genersoft.iot.vmp.VManageBootstrap;
+import com.genersoft.iot.vmp.common.enums.DeviceControlType;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
+import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent;
@@ -28,6 +29,7 @@
import javax.sip.message.Response;
import java.text.ParseException;
import java.util.Iterator;
+import java.util.Objects;
import static com.genersoft.iot.vmp.gb28181.utils.XmlUtil.getText;
@@ -101,13 +103,11 @@
// logger.error("[浠诲姟鎵ц澶辫触] 鏈嶅姟閲嶅惎: {}", e.getMessage());
// }
});
- } else {
- // 杩滅▼鍚姩鎸囧畾璁惧
}
}
- // 浜戝彴/鍓嶇鎺у埗鍛戒护
- if (!ObjectUtils.isEmpty(getText(rootElement,"PTZCmd")) && !parentPlatform.getServerGBId().equals(targetGBId)) {
- String cmdString = getText(rootElement,"PTZCmd");
+ DeviceControlType deviceControlType = DeviceControlType.typeOf(rootElement);
+ if (!ObjectUtils.isEmpty(deviceControlType) && !parentPlatform.getServerGBId().equals(targetGBId)){
+ //鍒ゆ柇鏄惁瀛樺湪璇ラ�氶亾
Device deviceForPlatform = storager.queryVideoDeviceByPlatformIdAndChannelId(parentPlatform.getServerGBId(), channelId);
if (deviceForPlatform == null) {
try {
@@ -117,25 +117,217 @@
}
return;
}
- try {
- cmder.fronEndCmd(deviceForPlatform, channelId, cmdString, eventResult -> {
- // 澶辫触鐨勫洖澶�
- try {
- responseAck(request, eventResult.statusCode, eventResult.msg);
- } catch (SipException | InvalidArgumentException | ParseException e) {
- logger.error("[鍛戒护鍙戦�佸け璐 浜戝彴/鍓嶇鍥炲: {}", e.getMessage());
- }
- }, eventResult -> {
- // 鎴愬姛鐨勫洖澶�
- try {
- responseAck(request, eventResult.statusCode);
- } catch (SipException | InvalidArgumentException | ParseException e) {
- logger.error("[鍛戒护鍙戦�佸け璐 浜戝彴/鍓嶇鍥炲: {}", e.getMessage());
- }
- });
- } catch (InvalidArgumentException | SipException | ParseException e) {
- logger.error("[鍛戒护鍙戦�佸け璐 浜戝彴/鍓嶇: {}", e.getMessage());
+ switch (deviceControlType){
+ case PTZ:
+ handlePtzCmd(deviceForPlatform,channelId,rootElement,request,DeviceControlType.PTZ);
+ break;
+ case ALARM:
+ handleAlarmCmd(deviceForPlatform,rootElement,request);
+ break;
+ case GUARD:
+ handleGuardCmd(deviceForPlatform,rootElement,request,DeviceControlType.GUARD);
+ break;
+ case RECORD:
+ handleRecordCmd(deviceForPlatform,channelId,rootElement,request,DeviceControlType.RECORD);
+ break;
+ case I_FRAME:
+ handleIFameCmd(deviceForPlatform,request,channelId);
+ break;
+ case TELE_BOOT:
+ handleTeleBootCmd(deviceForPlatform,request);
+ break;
+ case DRAG_ZOOM_IN:
+ handleDragZoom(deviceForPlatform,channelId,rootElement,request,DeviceControlType.DRAG_ZOOM_IN);
+ break;
+ case DRAG_ZOOM_OUT:
+ handleDragZoom(deviceForPlatform,channelId,rootElement,request,DeviceControlType.DRAG_ZOOM_OUT);
+ break;
+ case HOME_POSITION:
+ handleHomePositionCmd(deviceForPlatform,channelId,rootElement,request,DeviceControlType.HOME_POSITION);
+ break;
+ default:
+ break;
}
}
}
+
+ /**
+ * 澶勭悊浜戝彴鎸囦护
+ * @param device 璁惧
+ * @param channelId 閫氶亾id
+ * @param rootElement
+ * @param request
+ */
+ private void handlePtzCmd(Device device,String channelId,Element rootElement,SIPRequest request,DeviceControlType type){
+ String cmdString = getText(rootElement,type.getVal());
+ try {
+ cmder.fronEndCmd(device, channelId, cmdString,
+ errorResult -> onError(request,errorResult),
+ okResult -> onOk(request,okResult));
+ } catch (InvalidArgumentException | SipException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 浜戝彴/鍓嶇: {}", e.getMessage());
+ }
+ }
+
+ /**
+ * 澶勭悊寮哄埗鍏抽敭甯�
+ * @param device 璁惧
+ * @param channelId 閫氶亾id
+ */
+ private void handleIFameCmd(Device device,SIPRequest request,String channelId){
+ try {
+ cmder.iFrameCmd(device,channelId);
+ responseAck(request, Response.OK);
+ } catch (InvalidArgumentException | SipException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 寮哄埗鍏抽敭甯�: {}", e.getMessage());
+ }
+ }
+
+ /**
+ * 澶勭悊閲嶅惎鍛戒护
+ * @param device 璁惧淇℃伅
+ */
+ private void handleTeleBootCmd(Device device,SIPRequest request){
+ try {
+ cmder.teleBootCmd(device);
+ responseAck(request, Response.OK);
+ } catch (InvalidArgumentException | SipException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 閲嶅惎: {}", e.getMessage());
+ }
+
+ }
+
+ /**
+ * 澶勭悊鎷夋鎺у埗
+ * @param device 璁惧淇℃伅
+ * @param channelId 閫氶亾id
+ * @param rootElement 鏍硅妭鐐�
+ * @param type 娑堟伅绫诲瀷
+ */
+ private void handleDragZoom(Device device,String channelId,Element rootElement,SIPRequest request,DeviceControlType type){
+ String cmdString = getText(rootElement,type.getVal());
+ StringBuffer cmdXml = new StringBuffer(200);
+ cmdXml.append("<" + type.getVal() + ">\r\n");
+ cmdXml.append(cmdString);
+ cmdXml.append("</" + type.getVal() + ">\r\n");
+ try {
+ cmder.dragZoomCmd(device,channelId,cmdXml.toString());
+ responseAck(request, Response.OK);
+ } catch (InvalidArgumentException | SipException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鎷夋鎺у埗: {}", e.getMessage());
+ }
+
+ }
+
+ /**
+ * 澶勭悊鐪嬪畧浣嶅懡浠�
+ * @param device 璁惧淇℃伅
+ * @param channelId 閫氶亾id
+ * @param rootElement 鏍硅妭鐐�
+ * @param request 璇锋眰淇℃伅
+ * @param type 娑堟伅绫诲瀷
+ */
+ private void handleHomePositionCmd(Device device,String channelId,Element rootElement,SIPRequest request,DeviceControlType type){
+ //鑾峰彇鏁翠釜娑堟伅涓讳綋锛屾垜浠彧闇�瑕佷慨鏀硅姹傚ご鍗冲彲
+ String cmdString = getText(rootElement,type.getVal());
+ try {
+ cmder.homePositionCmd(device, channelId, cmdString,null,null,null,
+ errorResult -> onError(request,errorResult),
+ okResult -> onOk(request,okResult));
+ } catch (InvalidArgumentException | SipException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鐪嬪畧浣嶈缃�: {}", e.getMessage());
+ }
+ }
+
+ /**
+ * 澶勭悊鍛婅娑堟伅
+ * @param device 璁惧淇℃伅
+ * @param rootElement 鏍硅妭鐐�
+ * @param request 璇锋眰淇℃伅
+ */
+ private void handleAlarmCmd(Device device,Element rootElement,SIPRequest request){
+ //鍛婅鏂规硶
+ String alarmMethod = "";
+ //鍛婅绫诲瀷
+ String alarmType = "";
+ Element info = rootElement.element("Info");
+ if (info !=null){
+ alarmMethod = getText(rootElement,"AlarmMethod");
+ alarmType = getText(rootElement,"AlarmType");
+ }
+ try {
+ cmder.alarmCmd(device, alarmMethod,alarmType,
+ errorResult -> onError(request,errorResult),
+ okResult -> onOk(request,okResult));
+ } catch (InvalidArgumentException | SipException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍛婅娑堟伅: {}", e.getMessage());
+ }
+ }
+
+ /**
+ * 澶勭悊褰曞儚鎺у埗
+ * @param device 璁惧淇℃伅
+ * @param channelId 閫氶亾id
+ * @param rootElement 鏍硅妭鐐�
+ * @param request 璇锋眰淇℃伅
+ * @param type 娑堟伅绫诲瀷
+ */
+ private void handleRecordCmd(Device device,String channelId,Element rootElement,SIPRequest request,DeviceControlType type){
+ //鑾峰彇鏁翠釜娑堟伅涓讳綋锛屾垜浠彧闇�瑕佷慨鏀硅姹傚ご鍗冲彲
+ String cmdString = getText(rootElement,type.getVal());
+ try {
+ cmder.recordCmd(device, channelId,cmdString,
+ errorResult -> onError(request,errorResult),
+ okResult -> onOk(request,okResult));
+ } catch (InvalidArgumentException | SipException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 褰曞儚鎺у埗: {}", e.getMessage());
+ }
+ }
+
+ /**
+ * 澶勭悊鎶ヨ甯冮槻/鎾ら槻鍛戒护
+ * @param device 璁惧淇℃伅
+ * @param rootElement 鏍硅妭鐐�
+ * @param request 璇锋眰淇℃伅
+ * @param type 娑堟伅绫诲瀷
+ */
+ private void handleGuardCmd(Device device,Element rootElement,SIPRequest request,DeviceControlType type){
+ //鑾峰彇鏁翠釜娑堟伅涓讳綋锛屾垜浠彧闇�瑕佷慨鏀硅姹傚ご鍗冲彲
+ String cmdString = getText(rootElement,type.getVal());
+ try {
+ cmder.guardCmd(device, cmdString,
+ errorResult -> onError(request,errorResult),
+ okResult -> onOk(request,okResult));
+ } catch (InvalidArgumentException | SipException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 甯冮槻/鎾ら槻鍛戒护: {}", e.getMessage());
+ }
+ }
+
+
+ /**
+ * 閿欒鍝嶅簲澶勭悊
+ * @param request 璇锋眰
+ * @param eventResult 鍝嶅簲缁撴瀯
+ */
+ private void onError(SIPRequest request, SipSubscribe.EventResult eventResult){
+ // 澶辫触鐨勫洖澶�
+ try {
+ responseAck(request, eventResult.statusCode, eventResult.msg);
+ } catch (SipException | InvalidArgumentException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥炲: {}", e.getMessage());
+ }
+ }
+ /**
+ * 鎴愬姛鍝嶅簲澶勭悊
+ * @param request 璇锋眰
+ * @param eventResult 鍝嶅簲缁撴瀯
+ */
+ private void onOk(SIPRequest request, SipSubscribe.EventResult eventResult){
+ // 鎴愬姛鐨勫洖澶�
+ try {
+ responseAck(request, eventResult.statusCode);
+ } catch (SipException | InvalidArgumentException | ParseException e) {
+ logger.error("[鍛戒护鍙戦�佸け璐 鍥炲: {}", e.getMessage());
+ }
+ }
}
--
Gitblit v1.8.0