Merge remote-tracking branch 'origin/master' into wvp-28181-2.0
# Conflicts: # README.md # src/main/java/com/genersoft/iot/vmp/gb28181/event/EventPublisher.java # src/main/java/com/genersoft/iot/vmp/gb28181/event/alarm/AlarmEvent.java # src/main/java/com/genersoft/iot/vmp/gb28181/transmit/SIPProcessorFactory.java # src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/SIPRequestHeaderProvider.java # src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java # src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java # src/main/java/com/genersoft/iot/vmp/storager/IVideoManagerStorager.java # src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java # src/main/java/com/genersoft/iot/vmp/vmanager/SseController/SseController.java # src/main/java/com/genersoft/iot/vmp/vmanager/service/IPlayService.java # src/main/java/com/genersoft/iot/vmp/vmanager/service/impl/PlayServiceImpl.java # src/main/resources/wvp.sqlite # web_src/.postcssrc.js # web_src/src/components/UiHeader.vue # web_src/src/main.js # web_src/src/router/index.js
This commit is contained in:
@@ -149,8 +149,6 @@ public class SipLayer implements SipListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
// } else if (status == Response.TRYING) {
|
||||
// trying不会回复
|
||||
} else if ((status >= 100) && (status < 200)) {
|
||||
// 增加其它无需回复的响应,如101、180等
|
||||
} else {
|
||||
|
||||
@@ -91,8 +91,10 @@ public class DigestServerAuthenticationHelper {
|
||||
long time = date.getTime();
|
||||
Random rand = new Random();
|
||||
long pad = rand.nextLong();
|
||||
String nonceString = (new Long(time)).toString()
|
||||
+ (new Long(pad)).toString();
|
||||
// String nonceString = (new Long(time)).toString()
|
||||
// + (new Long(pad)).toString();
|
||||
String nonceString = Long.valueOf(time).toString()
|
||||
+ Long.valueOf(pad).toString();
|
||||
byte mdbytes[] = messageDigest.digest(nonceString.getBytes());
|
||||
// Convert the mdbytes array into a hex string.
|
||||
return toHexString(mdbytes);
|
||||
@@ -191,7 +193,7 @@ public class DigestServerAuthenticationHelper {
|
||||
|
||||
// 客户端随机数,这是一个不透明的字符串值,由客户端提供,并且客户端和服务器都会使用,以避免用明文文本。
|
||||
// 这使得双方都可以查验对方的身份,并对消息的完整性提供一些保护
|
||||
String cNonce = authHeader.getCNonce();
|
||||
//String cNonce = authHeader.getCNonce();
|
||||
|
||||
// nonce计数器,是一个16进制的数值,表示同一nonce下客户端发送出请求的数量
|
||||
int nc = authHeader.getNonceCount();
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
public class BaiduPoint {
|
||||
|
||||
String bdLng;
|
||||
|
||||
String bdLat;
|
||||
|
||||
public String getBdLng() {
|
||||
return bdLng;
|
||||
}
|
||||
|
||||
public void setBdLng(String bdLng) {
|
||||
this.bdLng = bdLng;
|
||||
}
|
||||
|
||||
public String getBdLat() {
|
||||
return bdLat;
|
||||
}
|
||||
|
||||
public void setBdLat(String bdLat) {
|
||||
this.bdLat = bdLat;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
/**
|
||||
* @Description: 移动位置bean
|
||||
* @author: lawrencehj
|
||||
* @date: 2021年1月23日
|
||||
*/
|
||||
|
||||
public class MobilePosition {
|
||||
/**
|
||||
* 设备Id
|
||||
*/
|
||||
private String deviceId;
|
||||
|
||||
/**
|
||||
* 设备名称
|
||||
*/
|
||||
private String deviceName;
|
||||
|
||||
/**
|
||||
* 通知时间
|
||||
*/
|
||||
private String time;
|
||||
|
||||
/**
|
||||
* 经度
|
||||
*/
|
||||
private double longitude;
|
||||
|
||||
/**
|
||||
* 纬度
|
||||
*/
|
||||
private double latitude;
|
||||
|
||||
/**
|
||||
* 海拔高度
|
||||
*/
|
||||
private double altitude;
|
||||
|
||||
/**
|
||||
* 速度
|
||||
*/
|
||||
private double speed;
|
||||
|
||||
/**
|
||||
* 方向
|
||||
*/
|
||||
private double direction;
|
||||
|
||||
/**
|
||||
* 位置信息上报来源(Mobile Position、GPS Alarm)
|
||||
*/
|
||||
private String reportSource;
|
||||
|
||||
/**
|
||||
* 国内地理坐标系(GCJ-02 / BD-09)
|
||||
*/
|
||||
private String GeodeticSystem;
|
||||
|
||||
/**
|
||||
* 国内坐标系:经度坐标
|
||||
*/
|
||||
private String cnLng;
|
||||
|
||||
/**
|
||||
* 国内坐标系:纬度坐标
|
||||
*/
|
||||
private String cnLat;
|
||||
|
||||
|
||||
public String getDeviceId() {
|
||||
return deviceId;
|
||||
}
|
||||
|
||||
public void setDeviceId(String deviceId) {
|
||||
this.deviceId = deviceId;
|
||||
}
|
||||
|
||||
public String getDeviceName() {
|
||||
return deviceName;
|
||||
}
|
||||
|
||||
public void setDeviceName(String deviceName) {
|
||||
this.deviceName = deviceName;
|
||||
}
|
||||
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public double getAltitude() {
|
||||
return altitude;
|
||||
}
|
||||
|
||||
public void setAltitude(double altitude) {
|
||||
this.altitude = altitude;
|
||||
}
|
||||
|
||||
public double getSpeed() {
|
||||
return speed;
|
||||
}
|
||||
|
||||
public void setSpeed(double speed) {
|
||||
this.speed = speed;
|
||||
}
|
||||
|
||||
public double getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setDirection(double direction) {
|
||||
this.direction = direction;
|
||||
}
|
||||
|
||||
public String getReportSource() {
|
||||
return reportSource;
|
||||
}
|
||||
|
||||
public void setReportSource(String reportSource) {
|
||||
this.reportSource = reportSource;
|
||||
}
|
||||
|
||||
public String getGeodeticSystem() {
|
||||
return GeodeticSystem;
|
||||
}
|
||||
|
||||
public void setGeodeticSystem(String geodeticSystem) {
|
||||
GeodeticSystem = geodeticSystem;
|
||||
}
|
||||
|
||||
public String getCnLng() {
|
||||
return cnLng;
|
||||
}
|
||||
|
||||
public void setCnLng(String cnLng) {
|
||||
this.cnLng = cnLng;
|
||||
}
|
||||
|
||||
public String getCnLat() {
|
||||
return cnLat;
|
||||
}
|
||||
|
||||
public void setCnLat(String cnLat) {
|
||||
this.cnLat = cnLat;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
|
||||
import gov.nist.javax.sip.header.SIPDate;
|
||||
//import gov.nist.javax.sip.header.SIPDate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -1,14 +1,100 @@
|
||||
package com.genersoft.iot.vmp.gb28181.bean;
|
||||
|
||||
import gov.nist.core.InternalErrorHandler;
|
||||
import gov.nist.javax.sip.header.SIPDate;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 重写jain sip的SIPDate解决与国标时间格式不一致的问题
|
||||
*/
|
||||
public class WvpSipDate extends SIPDate {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private Calendar javaCal;
|
||||
|
||||
public WvpSipDate(long timeMillis) {
|
||||
super(timeMillis);
|
||||
this.javaCal = new GregorianCalendar(TimeZone.getDefault(), Locale.getDefault());
|
||||
Date date = new Date(timeMillis);
|
||||
this.javaCal.setTime(date);
|
||||
this.wkday = this.javaCal.get(7);
|
||||
switch(this.wkday) {
|
||||
case 1:
|
||||
this.sipWkDay = "Sun";
|
||||
break;
|
||||
case 2:
|
||||
this.sipWkDay = "Mon";
|
||||
break;
|
||||
case 3:
|
||||
this.sipWkDay = "Tue";
|
||||
break;
|
||||
case 4:
|
||||
this.sipWkDay = "Wed";
|
||||
break;
|
||||
case 5:
|
||||
this.sipWkDay = "Thu";
|
||||
break;
|
||||
case 6:
|
||||
this.sipWkDay = "Fri";
|
||||
break;
|
||||
case 7:
|
||||
this.sipWkDay = "Sat";
|
||||
break;
|
||||
default:
|
||||
InternalErrorHandler.handleException("No date map for wkday " + this.wkday);
|
||||
}
|
||||
|
||||
this.day = this.javaCal.get(5);
|
||||
this.month = this.javaCal.get(2);
|
||||
switch(this.month) {
|
||||
case 0:
|
||||
this.sipMonth = "Jan";
|
||||
break;
|
||||
case 1:
|
||||
this.sipMonth = "Feb";
|
||||
break;
|
||||
case 2:
|
||||
this.sipMonth = "Mar";
|
||||
break;
|
||||
case 3:
|
||||
this.sipMonth = "Apr";
|
||||
break;
|
||||
case 4:
|
||||
this.sipMonth = "May";
|
||||
break;
|
||||
case 5:
|
||||
this.sipMonth = "Jun";
|
||||
break;
|
||||
case 6:
|
||||
this.sipMonth = "Jul";
|
||||
break;
|
||||
case 7:
|
||||
this.sipMonth = "Aug";
|
||||
break;
|
||||
case 8:
|
||||
this.sipMonth = "Sep";
|
||||
break;
|
||||
case 9:
|
||||
this.sipMonth = "Oct";
|
||||
break;
|
||||
case 10:
|
||||
this.sipMonth = "Nov";
|
||||
break;
|
||||
case 11:
|
||||
this.sipMonth = "Dec";
|
||||
break;
|
||||
default:
|
||||
InternalErrorHandler.handleException("No date map for month " + this.month);
|
||||
}
|
||||
|
||||
this.year = this.javaCal.get(1);
|
||||
this.hour = this.javaCal.get(11);
|
||||
this.minute = this.javaCal.get(12);
|
||||
this.second = this.javaCal.get(13);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,7 +134,7 @@ public class WvpSipDate extends SIPDate {
|
||||
var6 = "" + this.second;
|
||||
}
|
||||
|
||||
int var8 = this.getJavaCal().get(14);
|
||||
int var8 = this.javaCal.get(14);
|
||||
String var7;
|
||||
if (var8 < 10) {
|
||||
var7 = "00" + var8;
|
||||
|
||||
@@ -65,4 +65,5 @@ public class EventPublisher {
|
||||
alarmEvent.setAlarmInfo(deviceAlarm);
|
||||
applicationEventPublisher.publishEvent(alarmEvent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,14 @@
|
||||
package com.genersoft.iot.vmp.gb28181.event;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.sip.ResponseEvent;
|
||||
import javax.sip.message.Request;
|
||||
import java.util.EventObject;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@Component
|
||||
public class SipSubscribe {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(SipSubscribe.class);
|
||||
|
||||
private Map<String, SipSubscribe.Event> errorSubscribes = new ConcurrentHashMap<>();
|
||||
|
||||
private Map<String, SipSubscribe.Event> okSubscribes = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -10,6 +10,11 @@ import org.springframework.context.ApplicationEvent;
|
||||
*/
|
||||
|
||||
public class AlarmEvent extends ApplicationEvent {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public AlarmEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
@@ -3,18 +3,17 @@ package com.genersoft.iot.vmp.gb28181.event.offline;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* @Description:TODO(这里用一句话描述这个类的作用)
|
||||
* @Description: 离线事件类
|
||||
* @author: swwheihei
|
||||
* @date: 2020年5月6日 上午11:33:13
|
||||
*/
|
||||
public class OfflineEvent extends ApplicationEvent {
|
||||
|
||||
/**
|
||||
* @Title: OutlineEvent
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* @param: @param source
|
||||
* @throws
|
||||
*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public OfflineEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
@@ -3,18 +3,17 @@ package com.genersoft.iot.vmp.gb28181.event.online;
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
/**
|
||||
* @Description:TODO(这里用一句话描述这个类的作用)
|
||||
* @Description: 在线事件类
|
||||
* @author: swwheihei
|
||||
* @date: 2020年5月6日 上午11:32:56
|
||||
*/
|
||||
public class OnlineEvent extends ApplicationEvent {
|
||||
|
||||
/**
|
||||
* @Title: OnlineEvent
|
||||
* @Description: TODO(这里用一句话描述这个方法的作用)
|
||||
* @param: @param source
|
||||
* @throws
|
||||
*/
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public OnlineEvent(Object source) {
|
||||
super(source);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,8 @@ import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.vmanager.service.IPlayService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
// import org.slf4j.Logger;
|
||||
// import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
@@ -36,6 +38,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.request.impl.ByeRequestProcessor;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.request.impl.CancelRequestProcessor;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.request.impl.InviteRequestProcessor;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.request.impl.MessageRequestProcessor;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.request.impl.NotifyRequestProcessor;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.request.impl.OtherRequestProcessor;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.request.impl.RegisterRequestProcessor;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.request.impl.SubscribeRequestProcessor;
|
||||
@@ -49,7 +52,7 @@ import com.genersoft.iot.vmp.utils.SpringBeanFactory;
|
||||
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
||||
|
||||
/**
|
||||
* @Description:TODO(这里用一句话描述这个类的作用)
|
||||
* @Description: SIP信令处理分配
|
||||
* @author: swwheihei
|
||||
* @date: 2020年5月3日 下午4:24:37
|
||||
*/
|
||||
@@ -78,7 +81,7 @@ public class SIPProcessorFactory {
|
||||
|
||||
@Autowired
|
||||
private SIPCommanderFroPlatform cmderFroPlatform;
|
||||
|
||||
|
||||
@Autowired
|
||||
private RedisUtil redis;
|
||||
|
||||
@@ -122,6 +125,7 @@ public class SIPProcessorFactory {
|
||||
Request request = evt.getRequest();
|
||||
String method = request.getMethod();
|
||||
// logger.info("接收到消息:"+request.getMethod());
|
||||
// sipSubscribe.getSubscribe(evt.getServerTransaction().getBranchId()).response(evt);
|
||||
if (Request.INVITE.equals(method)) {
|
||||
InviteRequestProcessor processor = new InviteRequestProcessor();
|
||||
processor.setRequestEvent(evt);
|
||||
@@ -161,7 +165,6 @@ public class SIPProcessorFactory {
|
||||
processor.setRequestEvent(evt);
|
||||
return processor;
|
||||
} else if (Request.MESSAGE.equals(method)) {
|
||||
|
||||
MessageRequestProcessor processor = new MessageRequestProcessor();
|
||||
processor.setRequestEvent(evt);
|
||||
processor.setTcpSipProvider(getTcpSipProvider());
|
||||
@@ -175,8 +178,23 @@ public class SIPProcessorFactory {
|
||||
processor.setStorager(storager);
|
||||
processor.setRedisCatchStorage(redisCatchStorage);
|
||||
return processor;
|
||||
} else if (Request.NOTIFY.equalsIgnoreCase(method)) {
|
||||
NotifyRequestProcessor processor = new NotifyRequestProcessor();
|
||||
processor.setRequestEvent(evt);
|
||||
processor.setTcpSipProvider(getTcpSipProvider());
|
||||
processor.setUdpSipProvider(getUdpSipProvider());
|
||||
processor.setPublisher(publisher);
|
||||
processor.setRedis(redis);
|
||||
processor.setDeferredResultHolder(deferredResultHolder);
|
||||
processor.setOffLineDetector(offLineDetector);
|
||||
processor.setCmder(cmder);
|
||||
processor.setStorager(storager);
|
||||
processor.setRedisCatchStorage(redisCatchStorage);
|
||||
return processor;
|
||||
} else {
|
||||
return new OtherRequestProcessor();
|
||||
OtherRequestProcessor processor = new OtherRequestProcessor();
|
||||
processor.setRequestEvent(evt);
|
||||
return processor;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.genersoft.iot.vmp.gb28181.transmit.callback;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.genersoft.iot.vmp.gb28181.bean.RecordInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.RecordItem;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.request.impl.MessageRequestProcessor;
|
||||
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class CheckForAllRecordsThread extends Thread {
|
||||
|
||||
private String key;
|
||||
|
||||
private RecordInfo recordInfo;
|
||||
|
||||
private RedisUtil redis;
|
||||
|
||||
private Logger logger;
|
||||
|
||||
private DeferredResultHolder deferredResultHolder;
|
||||
|
||||
public CheckForAllRecordsThread(String key, RecordInfo recordInfo) {
|
||||
this.key = key;
|
||||
this.recordInfo = recordInfo;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
String cacheKey = this.key;
|
||||
|
||||
for (long stop = System.nanoTime() + TimeUnit.SECONDS.toNanos(10); stop > System.nanoTime();) {
|
||||
List<Object> cacheKeys = redis.scan(cacheKey + "_*");
|
||||
List<RecordItem> totalRecordList = new ArrayList<RecordItem>();
|
||||
for (int i = 0; i < cacheKeys.size(); i++) {
|
||||
totalRecordList.addAll((List<RecordItem>) redis.get(cacheKeys.get(i).toString()));
|
||||
}
|
||||
if (totalRecordList.size() < this.recordInfo.getSumNum()) {
|
||||
logger.info("已获取" + totalRecordList.size() + "项录像数据,共" + this.recordInfo.getSumNum() + "项");
|
||||
} else {
|
||||
logger.info("录像数据已全部获取,共" + this.recordInfo.getSumNum() + "项");
|
||||
this.recordInfo.setRecordList(totalRecordList);
|
||||
for (int i = 0; i < cacheKeys.size(); i++) {
|
||||
redis.del(cacheKeys.get(i).toString());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
// 自然顺序排序, 元素进行升序排列
|
||||
this.recordInfo.getRecordList().sort(Comparator.naturalOrder());
|
||||
RequestMessage msg = new RequestMessage();
|
||||
String deviceId = recordInfo.getDeviceId();
|
||||
msg.setDeviceId(deviceId);
|
||||
msg.setType(DeferredResultHolder.CALLBACK_CMD_RECORDINFO);
|
||||
msg.setData(recordInfo);
|
||||
deferredResultHolder.invokeResult(msg);
|
||||
logger.info("处理完成,返回结果");
|
||||
MessageRequestProcessor.threadNameList.remove(cacheKey);
|
||||
}
|
||||
|
||||
public void setRedis(RedisUtil redis) {
|
||||
this.redis = redis;
|
||||
}
|
||||
|
||||
public void setDeferredResultHolder(DeferredResultHolder deferredResultHolder) {
|
||||
this.deferredResultHolder = deferredResultHolder;
|
||||
}
|
||||
|
||||
public void setLogger(Logger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.genersoft.iot.vmp.gb28181.transmit.callback;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
@@ -10,15 +9,24 @@ import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.context.request.async.DeferredResult;
|
||||
|
||||
/**
|
||||
* @Description:TODO(这里用一句话描述这个类的作用)
|
||||
* @Description: 异步请求处理
|
||||
* @author: swwheihei
|
||||
* @date: 2020年5月8日 下午7:59:05
|
||||
*/
|
||||
@SuppressWarnings(value = {"rawtypes", "unchecked"})
|
||||
@Component
|
||||
public class DeferredResultHolder {
|
||||
|
||||
public static final String CALLBACK_CMD_DEVICESTATUS = "CALLBACK_DEVICESTATUS";
|
||||
|
||||
public static final String CALLBACK_CMD_DEVICEINFO = "CALLBACK_DEVICEINFO";
|
||||
|
||||
public static final String CALLBACK_CMD_DEVICECONTROL = "CALLBACK_DEVICECONTROL";
|
||||
|
||||
public static final String CALLBACK_CMD_DEVICECONFIG = "CALLBACK_DEVICECONFIG";
|
||||
|
||||
public static final String CALLBACK_CMD_CONFIGDOWNLOAD = "CALLBACK_CONFIGDOWNLOAD";
|
||||
|
||||
public static final String CALLBACK_CMD_CATALOG = "CALLBACK_CATALOG";
|
||||
|
||||
public static final String CALLBACK_CMD_RECORDINFO = "CALLBACK_RECORDINFO";
|
||||
@@ -27,6 +35,12 @@ public class DeferredResultHolder {
|
||||
|
||||
public static final String CALLBACK_CMD_STOP = "CALLBACK_STOP";
|
||||
|
||||
public static final String CALLBACK_CMD_MOBILEPOSITION = "CALLBACK_MOBILEPOSITION";
|
||||
|
||||
public static final String CALLBACK_CMD_PRESETQUERY = "CALLBACK_PRESETQUERY";
|
||||
|
||||
public static final String CALLBACK_CMD_ALARM = "CALLBACK_ALARM";
|
||||
|
||||
private Map<String, DeferredResult> map = new ConcurrentHashMap<String, DeferredResult>();
|
||||
|
||||
public void put(String key, DeferredResult result) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.genersoft.iot.vmp.gb28181.transmit.callback;
|
||||
|
||||
/**
|
||||
* @Description:TODO(这里用一句话描述这个类的作用)
|
||||
* @Description: 请求信息定义
|
||||
* @author: swwheihei
|
||||
* @date: 2020年5月8日 下午1:09:18
|
||||
*/
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.genersoft.iot.vmp.gb28181.transmit.cmd;
|
||||
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
|
||||
@@ -115,24 +114,35 @@ public interface ISIPCommander {
|
||||
/**
|
||||
* 音视频录像控制
|
||||
*
|
||||
* @param device 视频设备
|
||||
* @param channelId 预览通道
|
||||
* @param device 视频设备
|
||||
* @param channelId 预览通道
|
||||
* @param recordCmdStr 录像命令:Record / StopRecord
|
||||
*/
|
||||
boolean recordCmd(Device device,String channelId);
|
||||
boolean recordCmd(Device device, String channelId, String recordCmdStr, SipSubscribe.Event errorEvent);
|
||||
|
||||
/**
|
||||
* 远程启动控制命令
|
||||
*
|
||||
* @param device 视频设备
|
||||
*/
|
||||
boolean teleBootCmd(Device device);
|
||||
|
||||
/**
|
||||
* 报警布防/撤防命令
|
||||
*
|
||||
* @param device 视频设备
|
||||
* @param device 视频设备
|
||||
* @param setGuard true: SetGuard, false: ResetGuard
|
||||
*/
|
||||
boolean guardCmd(Device device);
|
||||
boolean guardCmd(Device device, String guardCmdStr, SipSubscribe.Event errorEvent);
|
||||
|
||||
/**
|
||||
* 报警复位命令
|
||||
*
|
||||
* @param device 视频设备
|
||||
* @param device 视频设备
|
||||
* @param alarmMethod 报警方式(可选)
|
||||
* @param alarmType 报警类型(可选)
|
||||
*/
|
||||
boolean alarmCmd(Device device);
|
||||
boolean alarmCmd(Device device, String alarmMethod, String alarmType, SipSubscribe.Event errorEvent);
|
||||
|
||||
/**
|
||||
* 强制关键帧命令,设备收到此命令应立刻发送一个IDR帧
|
||||
@@ -140,14 +150,17 @@ public interface ISIPCommander {
|
||||
* @param device 视频设备
|
||||
* @param channelId 预览通道
|
||||
*/
|
||||
boolean iFameCmd(Device device,String channelId);
|
||||
boolean iFrameCmd(Device device, String channelId);
|
||||
|
||||
/**
|
||||
* 看守位控制命令
|
||||
*
|
||||
* @param device 视频设备
|
||||
* @param device 视频设备
|
||||
* @param enabled 看守位使能:1 = 开启,0 = 关闭
|
||||
* @param resetTime 自动归位时间间隔,开启看守位时使用,单位:秒(s)
|
||||
* @param presetIndex 调用预置位编号,开启看守位时使用,取值范围0~255
|
||||
*/
|
||||
boolean homePositionCmd(Device device);
|
||||
boolean homePositionCmd(Device device, String channelId, String enabled, String resetTime, String presetIndex, SipSubscribe.Event errorEvent);
|
||||
|
||||
/**
|
||||
* 设备配置命令
|
||||
@@ -156,13 +169,24 @@ public interface ISIPCommander {
|
||||
*/
|
||||
boolean deviceConfigCmd(Device device);
|
||||
|
||||
/**
|
||||
* 设备配置命令:basicParam
|
||||
*
|
||||
* @param device 视频设备
|
||||
* @param channelId 通道编码(可选)
|
||||
* @param name 设备/通道名称(可选)
|
||||
* @param expiration 注册过期时间(可选)
|
||||
* @param heartBeatInterval 心跳间隔时间(可选)
|
||||
* @param heartBeatCount 心跳超时次数(可选)
|
||||
*/
|
||||
boolean deviceBasicConfigCmd(Device device, String channelId, String name, String expiration, String heartBeatInterval, String heartBeatCount, SipSubscribe.Event errorEvent);
|
||||
|
||||
/**
|
||||
* 查询设备状态
|
||||
*
|
||||
* @param device 视频设备
|
||||
*/
|
||||
boolean deviceStatusQuery(Device device);
|
||||
boolean deviceStatusQuery(Device device, SipSubscribe.Event errorEvent);
|
||||
|
||||
/**
|
||||
* 查询设备信息
|
||||
@@ -191,30 +215,65 @@ public interface ISIPCommander {
|
||||
/**
|
||||
* 查询报警信息
|
||||
*
|
||||
* @param device 视频设备
|
||||
* @param device 视频设备
|
||||
* @param startPriority 报警起始级别(可选)
|
||||
* @param endPriority 报警终止级别(可选)
|
||||
* @param alarmMethod 报警方式条件(可选)
|
||||
* @param alarmType 报警类型
|
||||
* @param startTime 报警发生起始时间(可选)
|
||||
* @param endTime 报警发生终止时间(可选)
|
||||
* @return true = 命令发送成功
|
||||
*/
|
||||
boolean alarmInfoQuery(Device device);
|
||||
boolean alarmInfoQuery(Device device, String startPriority, String endPriority, String alarmMethod,
|
||||
String alarmType, String startTime, String endTime, SipSubscribe.Event errorEvent);
|
||||
|
||||
/**
|
||||
* 查询设备配置
|
||||
*
|
||||
* @param device 视频设备
|
||||
* @param device 视频设备
|
||||
* @param channelId 通道编码(可选)
|
||||
* @param configType 配置类型:
|
||||
*/
|
||||
boolean configQuery(Device device);
|
||||
boolean deviceConfigQuery(Device device, String channelId, String configType, SipSubscribe.Event errorEvent);
|
||||
|
||||
/**
|
||||
* 查询设备预置位置
|
||||
*
|
||||
* @param device 视频设备
|
||||
*/
|
||||
boolean presetQuery(Device device);
|
||||
boolean presetQuery(Device device, String channelId, SipSubscribe.Event errorEvent);
|
||||
|
||||
/**
|
||||
* 查询移动设备位置数据
|
||||
*
|
||||
* @param device 视频设备
|
||||
*/
|
||||
boolean mobilePostitionQuery(Device device);
|
||||
boolean mobilePostitionQuery(Device device, SipSubscribe.Event errorEvent);
|
||||
|
||||
/**
|
||||
* 订阅、取消订阅移动位置
|
||||
*
|
||||
* @param device 视频设备
|
||||
* @param expires 订阅超时时间(值=0时为取消订阅)
|
||||
* @param interval 上报时间间隔
|
||||
* @return true = 命令发送成功
|
||||
*/
|
||||
boolean mobilePositionSubscribe(Device device, int expires, int interval);
|
||||
|
||||
/**
|
||||
* 订阅、取消订阅报警信息
|
||||
* @param device 视频设备
|
||||
* @param expires 订阅过期时间(0 = 取消订阅)
|
||||
* @param startPriority 报警起始级别(可选)
|
||||
* @param endPriority 报警终止级别(可选)
|
||||
* @param alarmMethods 报警方式条件(可选)
|
||||
* @param alarmType 报警类型
|
||||
* @param startTime 报警发生起始时间(可选)
|
||||
* @param endTime 报警发生终止时间(可选)
|
||||
* @return true = 命令发送成功
|
||||
*/
|
||||
boolean alarmSubscribe(Device device, int expires, String startPriority, String endPriority, String alarmMethod, String alarmType, String startTime, String endTime);
|
||||
|
||||
|
||||
/**
|
||||
* 释放rtpserver
|
||||
|
||||
@@ -168,4 +168,51 @@ public class SIPRequestHeaderProvider {
|
||||
request.setContent(content, contentTypeHeader);
|
||||
return request;
|
||||
}
|
||||
|
||||
public Request createSubscribeRequest(Device device, String content, String viaTag, String fromTag, String toTag, Integer expires, String event) throws ParseException, InvalidArgumentException, PeerUnavailableException {
|
||||
Request request = null;
|
||||
// sipuri
|
||||
SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress());
|
||||
// via
|
||||
ArrayList<ViaHeader> viaHeaders = new ArrayList<ViaHeader>();
|
||||
ViaHeader viaHeader = sipFactory.createHeaderFactory().createViaHeader(sipConfig.getSipIp(), sipConfig.getSipPort(),
|
||||
device.getTransport(), viaTag);
|
||||
viaHeader.setRPort();
|
||||
viaHeaders.add(viaHeader);
|
||||
// from
|
||||
SipURI fromSipURI = sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(),
|
||||
sipConfig.getSipIp() + ":" + sipConfig.getSipPort());
|
||||
Address fromAddress = sipFactory.createAddressFactory().createAddress(fromSipURI);
|
||||
FromHeader fromHeader = sipFactory.createHeaderFactory().createFromHeader(fromAddress, fromTag);
|
||||
// to
|
||||
SipURI toSipURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), sipConfig.getSipDomain());
|
||||
Address toAddress = sipFactory.createAddressFactory().createAddress(toSipURI);
|
||||
ToHeader toHeader = sipFactory.createHeaderFactory().createToHeader(toAddress, toTag);
|
||||
// callid
|
||||
CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
||||
: udpSipProvider.getNewCallId();
|
||||
// Forwards
|
||||
MaxForwardsHeader maxForwards = sipFactory.createHeaderFactory().createMaxForwardsHeader(70);
|
||||
// ceq
|
||||
CSeqHeader cSeqHeader = sipFactory.createHeaderFactory().createCSeqHeader(1L, Request.SUBSCRIBE);
|
||||
|
||||
request = sipFactory.createMessageFactory().createRequest(requestURI, Request.SUBSCRIBE, callIdHeader, cSeqHeader, fromHeader,
|
||||
toHeader, viaHeaders, maxForwards);
|
||||
|
||||
|
||||
Address concatAddress = sipFactory.createAddressFactory().createAddress(sipFactory.createAddressFactory().createSipURI(sipConfig.getSipId(), sipConfig.getSipIp()+":"+sipConfig.getSipPort()));
|
||||
request.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
|
||||
|
||||
// Expires
|
||||
ExpiresHeader expireHeader = sipFactory.createHeaderFactory().createExpiresHeader(expires);
|
||||
request.addHeader(expireHeader);
|
||||
|
||||
// Event
|
||||
EventHeader eventHeader = sipFactory.createHeaderFactory().createEventHeader(event);
|
||||
request.addHeader(eventHeader);
|
||||
|
||||
ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "MANSCDP+xml");
|
||||
request.setContent(content, contentTypeHeader);
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
package com.genersoft.iot.vmp.gb28181.transmit.cmd.impl;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.sip.*;
|
||||
import javax.sip.address.SipURI;
|
||||
import javax.sip.header.CallIdHeader;
|
||||
import javax.sip.header.Header;
|
||||
import javax.sip.header.ViaHeader;
|
||||
import javax.sip.message.Request;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMHttpHookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
|
||||
@@ -34,6 +31,8 @@ import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
|
||||
|
||||
/**
|
||||
* @Description:设备能力接口,用于定义设备的控制、查询能力
|
||||
@@ -235,7 +234,8 @@ public class SIPCommander implements ISIPCommander {
|
||||
ptzXml.append("</Info>\r\n");
|
||||
ptzXml.append("</Control>\r\n");
|
||||
|
||||
Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", null);
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtz" + tm, null);
|
||||
|
||||
transmitRequest(device, request);
|
||||
return true;
|
||||
@@ -271,7 +271,8 @@ public class SIPCommander implements ISIPCommander {
|
||||
ptzXml.append("</Info>\r\n");
|
||||
ptzXml.append("</Control>\r\n");
|
||||
|
||||
Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", null);
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtz" + tm, null);
|
||||
transmitRequest(device, request);
|
||||
return true;
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
@@ -383,7 +384,8 @@ public class SIPCommander implements ISIPCommander {
|
||||
|
||||
content.append("y="+ssrc+"\r\n");//ssrc
|
||||
|
||||
Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "live", null, ssrc);
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), null, "FromInvt" + tm, null, ssrc);
|
||||
|
||||
ClientTransaction transaction = transmitRequest(device, request, errorEvent);
|
||||
streamSession.put(streamId, transaction);
|
||||
@@ -482,7 +484,8 @@ public class SIPCommander implements ISIPCommander {
|
||||
|
||||
content.append("y="+ssrc+"\r\n");//ssrc
|
||||
|
||||
Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "playback", null);
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "fromplybck" + tm, null);
|
||||
|
||||
ClientTransaction transaction = transmitRequest(device, request, errorEvent);
|
||||
streamSession.put(streamId, transaction);
|
||||
@@ -573,24 +576,89 @@ public class SIPCommander implements ISIPCommander {
|
||||
/**
|
||||
* 音视频录像控制
|
||||
*
|
||||
* @param device 视频设备
|
||||
* @param channelId 预览通道
|
||||
* @param device 视频设备
|
||||
* @param channelId 预览通道
|
||||
* @param recordCmdStr 录像命令:Record / StopRecord
|
||||
*/
|
||||
@Override
|
||||
public boolean recordCmd(Device device, String channelId) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean recordCmd(Device device, String channelId, String recordCmdStr, SipSubscribe.Event errorEvent) {
|
||||
try {
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
||||
cmdXml.append("<Control>\r\n");
|
||||
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
||||
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
||||
if (XmlUtil.isEmpty(channelId)) {
|
||||
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
} else {
|
||||
cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
|
||||
}
|
||||
cmdXml.append("<RecordCmd>" + recordCmdStr + "</RecordCmd>\r\n");
|
||||
cmdXml.append("</Control>\r\n");
|
||||
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromRecord" + tm, null);
|
||||
transmitRequest(device, request, errorEvent);
|
||||
return true;
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 远程启动控制命令
|
||||
*
|
||||
* @param device 视频设备
|
||||
*/
|
||||
@Override
|
||||
public boolean teleBootCmd(Device device) {
|
||||
try {
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
||||
cmdXml.append("<Control>\r\n");
|
||||
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
||||
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
||||
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
cmdXml.append("<TeleBoot>Boot</TeleBoot>\r\n");
|
||||
cmdXml.append("</Control>\r\n");
|
||||
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromBoot" + tm, null);
|
||||
transmitRequest(device, request);
|
||||
return true;
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 报警布防/撤防命令
|
||||
*
|
||||
* @param device 视频设备
|
||||
*/
|
||||
* @param device 视频设备
|
||||
* @param guardCmdStr "SetGuard"/"ResetGuard"
|
||||
*/
|
||||
@Override
|
||||
public boolean guardCmd(Device device) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean guardCmd(Device device, String guardCmdStr, SipSubscribe.Event errorEvent) {
|
||||
try {
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
||||
cmdXml.append("<Control>\r\n");
|
||||
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
||||
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
||||
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
cmdXml.append("<GuardCmd>" + guardCmdStr + "</GuardCmd>\r\n");
|
||||
cmdXml.append("</Control>\r\n");
|
||||
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromGuard" + tm, null);
|
||||
transmitRequest(device, request, errorEvent);
|
||||
return true;
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -599,9 +667,37 @@ public class SIPCommander implements ISIPCommander {
|
||||
* @param device 视频设备
|
||||
*/
|
||||
@Override
|
||||
public boolean alarmCmd(Device device) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean alarmCmd(Device device, String alarmMethod, String alarmType, SipSubscribe.Event errorEvent) {
|
||||
try {
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
||||
cmdXml.append("<Control>\r\n");
|
||||
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
||||
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
||||
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
cmdXml.append("<AlarmCmd>ResetAlarm</AlarmCmd>\r\n");
|
||||
if (!XmlUtil.isEmpty(alarmMethod) || !XmlUtil.isEmpty(alarmType)) {
|
||||
cmdXml.append("<Info>\r\n");
|
||||
}
|
||||
if (!XmlUtil.isEmpty(alarmMethod)) {
|
||||
cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
|
||||
}
|
||||
if (!XmlUtil.isEmpty(alarmType)) {
|
||||
cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
|
||||
}
|
||||
if (!XmlUtil.isEmpty(alarmMethod) || !XmlUtil.isEmpty(alarmType)) {
|
||||
cmdXml.append("</Info>\r\n");
|
||||
}
|
||||
cmdXml.append("</Control>\r\n");
|
||||
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromAlarm" + tm, null);
|
||||
transmitRequest(device, request, errorEvent);
|
||||
return true;
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -611,20 +707,79 @@ public class SIPCommander implements ISIPCommander {
|
||||
* @param channelId 预览通道
|
||||
*/
|
||||
@Override
|
||||
public boolean iFameCmd(Device device, String channelId) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean iFrameCmd(Device device, String channelId) {
|
||||
try {
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
||||
cmdXml.append("<Control>\r\n");
|
||||
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
||||
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
||||
if (XmlUtil.isEmpty(channelId)) {
|
||||
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
} else {
|
||||
cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
|
||||
}
|
||||
cmdXml.append("<IFameCmd>Send</IFameCmd>\r\n");
|
||||
cmdXml.append("</Control>\r\n");
|
||||
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromBoot" + tm, null);
|
||||
transmitRequest(device, request);
|
||||
return true;
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 看守位控制命令
|
||||
*
|
||||
* @param device 视频设备
|
||||
* @param device 视频设备
|
||||
* @param enabled 看守位使能:1 = 开启,0 = 关闭
|
||||
* @param resetTime 自动归位时间间隔,开启看守位时使用,单位:秒(s)
|
||||
* @param presetIndex 调用预置位编号,开启看守位时使用,取值范围0~255
|
||||
*/
|
||||
@Override
|
||||
public boolean homePositionCmd(Device device) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean homePositionCmd(Device device, String channelId, String enabled, String resetTime, String presetIndex, SipSubscribe.Event errorEvent) {
|
||||
try {
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
||||
cmdXml.append("<Control>\r\n");
|
||||
cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
||||
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
||||
if (XmlUtil.isEmpty(channelId)) {
|
||||
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
} else {
|
||||
cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
|
||||
}
|
||||
cmdXml.append("<HomePosition>\r\n");
|
||||
if (NumericUtil.isInteger(enabled) && (!enabled.equals("0"))) {
|
||||
cmdXml.append("<Enabled>1</Enabled>\r\n");
|
||||
if (NumericUtil.isInteger(resetTime)) {
|
||||
cmdXml.append("<ResetTime>" + resetTime + "</ResetTime>\r\n");
|
||||
} else {
|
||||
cmdXml.append("<ResetTime>0</ResetTime>\r\n");
|
||||
}
|
||||
if (NumericUtil.isInteger(presetIndex)) {
|
||||
cmdXml.append("<PresetIndex>" + presetIndex + "</PresetIndex>\r\n");
|
||||
} else {
|
||||
cmdXml.append("<PresetIndex>0</PresetIndex>\r\n");
|
||||
}
|
||||
} else {
|
||||
cmdXml.append("<Enabled>0</Enabled>\r\n");
|
||||
}
|
||||
cmdXml.append("</HomePosition>\r\n");
|
||||
cmdXml.append("</Control>\r\n");
|
||||
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromGuard" + tm, null);
|
||||
transmitRequest(device, request, errorEvent);
|
||||
return true;
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -638,15 +793,88 @@ public class SIPCommander implements ISIPCommander {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设备配置命令:basicParam
|
||||
*
|
||||
* @param device 视频设备
|
||||
* @param channelId 通道编码(可选)
|
||||
* @param name 设备/通道名称(可选)
|
||||
* @param expiration 注册过期时间(可选)
|
||||
* @param heartBeatInterval 心跳间隔时间(可选)
|
||||
* @param heartBeatCount 心跳超时次数(可选)
|
||||
*/
|
||||
@Override
|
||||
public boolean deviceBasicConfigCmd(Device device, String channelId, String name, String expiration,
|
||||
String heartBeatInterval, String heartBeatCount, SipSubscribe.Event errorEvent) {
|
||||
try {
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
||||
cmdXml.append("<Control>\r\n");
|
||||
cmdXml.append("<CmdType>DeviceConfig</CmdType>\r\n");
|
||||
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
||||
if (XmlUtil.isEmpty(channelId)) {
|
||||
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
} else {
|
||||
cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
|
||||
}
|
||||
cmdXml.append("<BasicParam>\r\n");
|
||||
if (!XmlUtil.isEmpty(name)) {
|
||||
cmdXml.append("<Name>" + name + "</Name>\r\n");
|
||||
}
|
||||
if (NumericUtil.isInteger(expiration)) {
|
||||
if (Integer.valueOf(expiration) > 0) {
|
||||
cmdXml.append("<Expiration>" + expiration + "</Expiration>\r\n");
|
||||
}
|
||||
}
|
||||
if (NumericUtil.isInteger(heartBeatInterval)) {
|
||||
if (Integer.valueOf(heartBeatInterval) > 0) {
|
||||
cmdXml.append("<HeartBeatInterval>" + heartBeatInterval + "</HeartBeatInterval>\r\n");
|
||||
}
|
||||
}
|
||||
if (NumericUtil.isInteger(heartBeatCount)) {
|
||||
if (Integer.valueOf(heartBeatCount) > 0) {
|
||||
cmdXml.append("<HeartBeatCount>" + heartBeatCount + "</HeartBeatCount>\r\n");
|
||||
}
|
||||
}
|
||||
cmdXml.append("</BasicParam>\r\n");
|
||||
cmdXml.append("</Control>\r\n");
|
||||
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromConfig" + tm, null);
|
||||
transmitRequest(device, request, errorEvent);
|
||||
return true;
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备状态
|
||||
*
|
||||
* @param device 视频设备
|
||||
*/
|
||||
@Override
|
||||
public boolean deviceStatusQuery(Device device) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean deviceStatusQuery(Device device, SipSubscribe.Event errorEvent) {
|
||||
try {
|
||||
StringBuffer catalogXml = new StringBuffer(200);
|
||||
catalogXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
|
||||
catalogXml.append("<Query>\r\n");
|
||||
catalogXml.append("<CmdType>DeviceStatus</CmdType>\r\n");
|
||||
catalogXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
||||
catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
catalogXml.append("</Query>\r\n");
|
||||
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), null, "FromStatus" + tm, null);
|
||||
|
||||
transmitRequest(device, request, errorEvent);
|
||||
return true;
|
||||
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -665,7 +893,8 @@ public class SIPCommander implements ISIPCommander {
|
||||
catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
catalogXml.append("</Query>\r\n");
|
||||
|
||||
Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaDeviceInfoBranch", "FromDeviceInfoTag", null);
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaDeviceInfoBranch", "FromDev" + tm, null);
|
||||
|
||||
transmitRequest(device, request);
|
||||
|
||||
@@ -694,7 +923,8 @@ public class SIPCommander implements ISIPCommander {
|
||||
catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
catalogXml.append("</Query>\r\n");
|
||||
|
||||
Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaCatalogBranch", "FromCatalogTag", null);
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), "ViaCatalogBranch", "FromCat" + tm, null);
|
||||
|
||||
transmitRequest(device, request, errorEvent);
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
@@ -728,7 +958,8 @@ public class SIPCommander implements ISIPCommander {
|
||||
recordInfoXml.append("<Type>all</Type>\r\n");
|
||||
recordInfoXml.append("</Query>\r\n");
|
||||
|
||||
Request request = headerProvider.createMessageRequest(device, recordInfoXml.toString(), "ViaRecordInfoBranch", "FromRecordInfoTag", null);
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createMessageRequest(device, recordInfoXml.toString(), "ViaRecordInfoBranch", "fromRec" + tm, null);
|
||||
|
||||
transmitRequest(device, request);
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
@@ -741,23 +972,86 @@ public class SIPCommander implements ISIPCommander {
|
||||
/**
|
||||
* 查询报警信息
|
||||
*
|
||||
* @param device 视频设备
|
||||
*/
|
||||
* @param device 视频设备
|
||||
* @param startPriority 报警起始级别(可选)
|
||||
* @param endPriority 报警终止级别(可选)
|
||||
* @param alarmMethods 报警方式条件(可选)
|
||||
* @param alarmType 报警类型
|
||||
* @param startTime 报警发生起始时间(可选)
|
||||
* @param endTime 报警发生终止时间(可选)
|
||||
* @return true = 命令发送成功
|
||||
*/
|
||||
@Override
|
||||
public boolean alarmInfoQuery(Device device) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean alarmInfoQuery(Device device, String startPriority, String endPriority, String alarmMethod, String alarmType,
|
||||
String startTime, String endTime, SipSubscribe.Event errorEvent) {
|
||||
try {
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
||||
cmdXml.append("<Query>\r\n");
|
||||
cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
|
||||
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
||||
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
if (!XmlUtil.isEmpty(startPriority)) {
|
||||
cmdXml.append("<StartAlarmPriority>" + startPriority + "</StartAlarmPriority>\r\n");
|
||||
}
|
||||
if (!XmlUtil.isEmpty(endPriority)) {
|
||||
cmdXml.append("<EndAlarmPriority>" + endPriority + "</EndAlarmPriority>\r\n");
|
||||
}
|
||||
if (!XmlUtil.isEmpty(alarmMethod)) {
|
||||
cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
|
||||
}
|
||||
if (!XmlUtil.isEmpty(alarmType)) {
|
||||
cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
|
||||
}
|
||||
if (!XmlUtil.isEmpty(startTime)) {
|
||||
cmdXml.append("<StartAlarmTime>" + startTime + "</StartAlarmTime>\r\n");
|
||||
}
|
||||
if (!XmlUtil.isEmpty(endTime)) {
|
||||
cmdXml.append("<EndAlarmTime>" + endTime + "</EndAlarmTime>\r\n");
|
||||
}
|
||||
cmdXml.append("</Query>\r\n");
|
||||
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromAlarm" + tm, null);
|
||||
transmitRequest(device, request, errorEvent);
|
||||
return true;
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询设备配置
|
||||
*
|
||||
* @param device 视频设备
|
||||
*/
|
||||
* @param device 视频设备
|
||||
* @param channelId 通道编码(可选)
|
||||
* @param configType 配置类型:
|
||||
*/
|
||||
@Override
|
||||
public boolean configQuery(Device device) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean deviceConfigQuery(Device device, String channelId, String configType, SipSubscribe.Event errorEvent) {
|
||||
try {
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
||||
cmdXml.append("<Query>\r\n");
|
||||
cmdXml.append("<CmdType>ConfigDownload</CmdType>\r\n");
|
||||
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
||||
if (XmlUtil.isEmpty(channelId)) {
|
||||
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
} else {
|
||||
cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
|
||||
}
|
||||
cmdXml.append("<ConfigType>" + configType + "</ConfigType>\r\n");
|
||||
cmdXml.append("</Query>\r\n");
|
||||
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromConfig" + tm, null);
|
||||
transmitRequest(device, request, errorEvent);
|
||||
return true;
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -766,9 +1060,28 @@ public class SIPCommander implements ISIPCommander {
|
||||
* @param device 视频设备
|
||||
*/
|
||||
@Override
|
||||
public boolean presetQuery(Device device) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean presetQuery(Device device, String channelId, SipSubscribe.Event errorEvent) {
|
||||
try {
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
||||
cmdXml.append("<Query>\r\n");
|
||||
cmdXml.append("<CmdType>PresetQuery</CmdType>\r\n");
|
||||
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
||||
if (XmlUtil.isEmpty(channelId)) {
|
||||
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
} else {
|
||||
cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
|
||||
}
|
||||
cmdXml.append("</Query>\r\n");
|
||||
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromConfig" + tm, null);
|
||||
transmitRequest(device, request, errorEvent);
|
||||
return true;
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -777,11 +1090,116 @@ public class SIPCommander implements ISIPCommander {
|
||||
* @param device 视频设备
|
||||
*/
|
||||
@Override
|
||||
public boolean mobilePostitionQuery(Device device) {
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
public boolean mobilePostitionQuery(Device device, SipSubscribe.Event errorEvent) {
|
||||
try {
|
||||
StringBuffer mobilePostitionXml = new StringBuffer(200);
|
||||
mobilePostitionXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
|
||||
mobilePostitionXml.append("<Query>\r\n");
|
||||
mobilePostitionXml.append("<CmdType>MobilePosition</CmdType>\r\n");
|
||||
mobilePostitionXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
||||
mobilePostitionXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
mobilePostitionXml.append("<Interval>60</Interval>\r\n");
|
||||
mobilePostitionXml.append("</Query>\r\n");
|
||||
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createMessageRequest(device, mobilePostitionXml.toString(), "viaTagPos" + tm, "fromTagPos" + tm, null);
|
||||
|
||||
transmitRequest(device, request, errorEvent);
|
||||
|
||||
} catch (SipException | ParseException | InvalidArgumentException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 订阅、取消订阅移动位置
|
||||
*
|
||||
* @param device 视频设备
|
||||
* @param expires 订阅超时时间
|
||||
* @param interval 上报时间间隔
|
||||
* @return true = 命令发送成功
|
||||
*/
|
||||
public boolean mobilePositionSubscribe(Device device, int expires, int interval) {
|
||||
try {
|
||||
StringBuffer subscribePostitionXml = new StringBuffer(200);
|
||||
subscribePostitionXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
|
||||
subscribePostitionXml.append("<Query>\r\n");
|
||||
subscribePostitionXml.append("<CmdType>MobilePosition</CmdType>\r\n");
|
||||
subscribePostitionXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
||||
subscribePostitionXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
if (expires > 0) {
|
||||
subscribePostitionXml.append("<Interval>" + String.valueOf(interval) + "</Interval>\r\n");
|
||||
}
|
||||
subscribePostitionXml.append("</Query>\r\n");
|
||||
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createSubscribeRequest(device, subscribePostitionXml.toString(), "viaTagPos" + tm, "fromTagPos" + tm, null, expires, "presence" ); //Position;id=" + tm.substring(tm.length() - 4));
|
||||
transmitRequest(device, request);
|
||||
|
||||
return true;
|
||||
|
||||
} catch ( NumberFormatException | ParseException | InvalidArgumentException | SipException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 订阅、取消订阅报警信息
|
||||
*
|
||||
* @param device 视频设备
|
||||
* @param expires 订阅过期时间(0 = 取消订阅)
|
||||
* @param startPriority 报警起始级别(可选)
|
||||
* @param endPriority 报警终止级别(可选)
|
||||
* @param alarmMethod 报警方式条件(可选)
|
||||
* @param alarmType 报警类型
|
||||
* @param startTime 报警发生起始时间(可选)
|
||||
* @param endTime 报警发生终止时间(可选)
|
||||
* @return true = 命令发送成功
|
||||
*/
|
||||
public boolean alarmSubscribe(Device device, int expires, String startPriority, String endPriority, String alarmMethod, String alarmType, String startTime, String endTime) {
|
||||
try {
|
||||
StringBuffer cmdXml = new StringBuffer(200);
|
||||
cmdXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
|
||||
cmdXml.append("<Query>\r\n");
|
||||
cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
|
||||
cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
||||
cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
||||
if (!XmlUtil.isEmpty(startPriority)) {
|
||||
cmdXml.append("<StartAlarmPriority>" + startPriority + "</StartAlarmPriority>\r\n");
|
||||
}
|
||||
if (!XmlUtil.isEmpty(endPriority)) {
|
||||
cmdXml.append("<EndAlarmPriority>" + endPriority + "</EndAlarmPriority>\r\n");
|
||||
}
|
||||
if (!XmlUtil.isEmpty(alarmMethod)) {
|
||||
cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
|
||||
}
|
||||
if (!XmlUtil.isEmpty(alarmType)) {
|
||||
cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
|
||||
}
|
||||
if (!XmlUtil.isEmpty(startTime)) {
|
||||
cmdXml.append("<StartAlarmTime>" + startTime + "</StartAlarmTime>\r\n");
|
||||
}
|
||||
if (!XmlUtil.isEmpty(endTime)) {
|
||||
cmdXml.append("<EndAlarmTime>" + endTime + "</EndAlarmTime>\r\n");
|
||||
}
|
||||
cmdXml.append("</Query>\r\n");
|
||||
|
||||
String tm = Long.toString(System.currentTimeMillis());
|
||||
Request request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), "viaTagPos" + tm, "fromTagPos" + tm, null, expires, "presence" );
|
||||
transmitRequest(device, request);
|
||||
|
||||
return true;
|
||||
|
||||
} catch ( NumberFormatException | ParseException | InvalidArgumentException | SipException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private ClientTransaction transmitRequest(Device device, Request request) throws SipException {
|
||||
return transmitRequest(device, request, null, null);
|
||||
}
|
||||
|
||||
@@ -26,6 +26,10 @@ import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.RecordInfo;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.RecordItem;
|
||||
import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector;
|
||||
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
|
||||
@@ -73,9 +77,12 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
private static final String MESSAGE_RECORD_INFO = "RecordInfo";
|
||||
private static final String MESSAGE_MEDIA_STATUS = "MediaStatus";
|
||||
// private static final String MESSAGE_BROADCAST = "Broadcast";
|
||||
// private static final String MESSAGE_DEVICE_STATUS = "DeviceStatus";
|
||||
// private static final String MESSAGE_MOBILE_POSITION = "MobilePosition";
|
||||
private static final String MESSAGE_DEVICE_STATUS = "DeviceStatus";
|
||||
private static final String MESSAGE_DEVICE_CONTROL = "DeviceControl";
|
||||
private static final String MESSAGE_DEVICE_CONFIG = "DeviceConfig";
|
||||
private static final String MESSAGE_MOBILE_POSITION = "MobilePosition";
|
||||
// private static final String MESSAGE_MOBILE_POSITION_INTERVAL = "Interval";
|
||||
private static final String MESSAGE_PRESET_QUERY = "PresetQuery";
|
||||
|
||||
/**
|
||||
* 处理MESSAGE请求
|
||||
@@ -94,12 +101,22 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
processMessageKeepAlive(evt);
|
||||
} else if (MESSAGE_CONFIG_DOWNLOAD.equals(cmd)) {
|
||||
logger.info("接收到ConfigDownload消息");
|
||||
processMessageConfigDownload(evt);
|
||||
} else if (MESSAGE_CATALOG.equals(cmd)) {
|
||||
logger.info("接收到Catalog消息");
|
||||
processMessageCatalogList(evt);
|
||||
} else if (MESSAGE_DEVICE_INFO.equals(cmd)) {
|
||||
logger.info("接收到DeviceInfo消息");
|
||||
processMessageDeviceInfo(evt);
|
||||
} else if (MESSAGE_DEVICE_STATUS.equals(cmd)) {
|
||||
logger.info("接收到DeviceStatus消息");
|
||||
processMessageDeviceStatus(evt);
|
||||
} else if (MESSAGE_DEVICE_CONTROL.equals(cmd)) {
|
||||
logger.info("接收到DeviceControl消息");
|
||||
processMessageDeviceControl(evt);
|
||||
} else if (MESSAGE_DEVICE_CONFIG.equals(cmd)) {
|
||||
logger.info("接收到DeviceConfig消息");
|
||||
processMessageDeviceConfig(evt);
|
||||
} else if (MESSAGE_ALARM.equals(cmd)) {
|
||||
logger.info("接收到Alarm消息");
|
||||
processMessageAlarm(evt);
|
||||
@@ -109,16 +126,236 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
}else if (MESSAGE_MEDIA_STATUS.equals(cmd)) {
|
||||
logger.info("接收到MediaStatus消息");
|
||||
processMessageMediaStatus(evt);
|
||||
} else if (MESSAGE_MOBILE_POSITION.equals(cmd)) {
|
||||
logger.info("接收到MobilePosition消息");
|
||||
processMessageMobilePosition(evt);
|
||||
} else if (MESSAGE_PRESET_QUERY.equals(cmd)) {
|
||||
logger.info("接收到PresetQuery消息");
|
||||
processMessagePresetQuery(evt);
|
||||
} else {
|
||||
logger.info("接收到消息:" + cmd);
|
||||
responseAck(evt);
|
||||
}
|
||||
} catch (DocumentException e) {
|
||||
} catch (DocumentException | SipException |InvalidArgumentException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 收到deviceInfo设备信息请求 处理
|
||||
* 处理MobilePosition移动位置消息
|
||||
*
|
||||
* @param evt
|
||||
*/
|
||||
private void processMessageMobilePosition(RequestEvent evt) {
|
||||
try {
|
||||
Element rootElement = getRootElement(evt);
|
||||
MobilePosition mobilePosition = new MobilePosition();
|
||||
Element deviceIdElement = rootElement.element("DeviceID");
|
||||
String deviceId = deviceIdElement.getTextTrim().toString();
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
if (device != null) {
|
||||
if (!StringUtils.isEmpty(device.getName())) {
|
||||
mobilePosition.setDeviceName(device.getName());
|
||||
}
|
||||
}
|
||||
mobilePosition.setDeviceId(XmlUtil.getText(rootElement, "DeviceID"));
|
||||
mobilePosition.setTime(XmlUtil.getText(rootElement, "Time"));
|
||||
mobilePosition.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude")));
|
||||
mobilePosition.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
|
||||
if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Speed"))) {
|
||||
mobilePosition.setSpeed(Double.parseDouble(XmlUtil.getText(rootElement, "Speed")));
|
||||
} else {
|
||||
mobilePosition.setSpeed(0.0);
|
||||
}
|
||||
if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Direction"))) {
|
||||
mobilePosition.setDirection(Double.parseDouble(XmlUtil.getText(rootElement, "Direction")));
|
||||
} else {
|
||||
mobilePosition.setDirection(0.0);
|
||||
}
|
||||
if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Altitude"))) {
|
||||
mobilePosition.setAltitude(Double.parseDouble(XmlUtil.getText(rootElement, "Altitude")));
|
||||
} else {
|
||||
mobilePosition.setAltitude(0.0);
|
||||
}
|
||||
mobilePosition.setReportSource("Mobile Position");
|
||||
BaiduPoint bp = new BaiduPoint();
|
||||
bp = GpsUtil.Wgs84ToBd09(String.valueOf(mobilePosition.getLongitude()), String.valueOf(mobilePosition.getLatitude()));
|
||||
logger.info("百度坐标:" + bp.getBdLng() + ", " + bp.getBdLat());
|
||||
mobilePosition.setGeodeticSystem("BD-09");
|
||||
mobilePosition.setCnLng(bp.getBdLng());
|
||||
mobilePosition.setCnLat(bp.getBdLat());
|
||||
if (!userSetup.getSavePositionHistory()) {
|
||||
storager.clearMobilePositionsByDeviceId(deviceId);
|
||||
}
|
||||
storager.insertMobilePosition(mobilePosition);
|
||||
//回复 200 OK
|
||||
responseAck(evt);
|
||||
} catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理DeviceStatus设备状态Message
|
||||
*
|
||||
* @param evt
|
||||
*/
|
||||
private void processMessageDeviceStatus(RequestEvent evt) {
|
||||
try {
|
||||
Element rootElement = getRootElement(evt);
|
||||
String deviceId = XmlUtil.getText(rootElement, "DeviceID");
|
||||
// 检查设备是否存在, 不存在则不回复
|
||||
if (storager.exists(deviceId)) {
|
||||
// 回复200 OK
|
||||
responseAck(evt);
|
||||
JSONObject json = new JSONObject();
|
||||
XmlUtil.node2Json(rootElement, json);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(json.toJSONString());
|
||||
}
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setDeviceId(deviceId);
|
||||
msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS);
|
||||
msg.setData(json);
|
||||
deferredResultHolder.invokeResult(msg);
|
||||
|
||||
if (offLineDetector.isOnline(deviceId)) {
|
||||
publisher.onlineEventPublish(deviceId, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
} catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理DeviceControl设备状态Message
|
||||
*
|
||||
* @param evt
|
||||
*/
|
||||
private void processMessageDeviceControl(RequestEvent evt) {
|
||||
try {
|
||||
Element rootElement = getRootElement(evt);
|
||||
String deviceId = XmlUtil.getText(rootElement, "DeviceID");
|
||||
//String result = XmlUtil.getText(rootElement, "Result");
|
||||
// 回复200 OK
|
||||
responseAck(evt);
|
||||
if (rootElement.getName().equals("Response")) {//} !XmlUtil.isEmpty(result)) {
|
||||
// 此处是对本平台发出DeviceControl指令的应答
|
||||
JSONObject json = new JSONObject();
|
||||
XmlUtil.node2Json(rootElement, json);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(json.toJSONString());
|
||||
}
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setDeviceId(deviceId);
|
||||
msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL);
|
||||
msg.setData(json);
|
||||
deferredResultHolder.invokeResult(msg);
|
||||
} else {
|
||||
// 此处是上级发出的DeviceControl指令
|
||||
}
|
||||
} catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理DeviceConfig设备状态Message
|
||||
*
|
||||
* @param evt
|
||||
*/
|
||||
private void processMessageDeviceConfig(RequestEvent evt) {
|
||||
try {
|
||||
Element rootElement = getRootElement(evt);
|
||||
String deviceId = XmlUtil.getText(rootElement, "DeviceID");
|
||||
// 回复200 OK
|
||||
responseAck(evt);
|
||||
if (rootElement.getName().equals("Response")) {
|
||||
// 此处是对本平台发出DeviceControl指令的应答
|
||||
JSONObject json = new JSONObject();
|
||||
XmlUtil.node2Json(rootElement, json);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(json.toJSONString());
|
||||
}
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setDeviceId(deviceId);
|
||||
msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG);
|
||||
msg.setData(json);
|
||||
deferredResultHolder.invokeResult(msg);
|
||||
} else {
|
||||
// 此处是上级发出的DeviceConfig指令
|
||||
}
|
||||
} catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理ConfigDownload设备状态Message
|
||||
*
|
||||
* @param evt
|
||||
*/
|
||||
private void processMessageConfigDownload(RequestEvent evt) {
|
||||
try {
|
||||
Element rootElement = getRootElement(evt);
|
||||
String deviceId = XmlUtil.getText(rootElement, "DeviceID");
|
||||
// 回复200 OK
|
||||
responseAck(evt);
|
||||
if (rootElement.getName().equals("Response")) {
|
||||
// 此处是对本平台发出DeviceControl指令的应答
|
||||
JSONObject json = new JSONObject();
|
||||
XmlUtil.node2Json(rootElement, json);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(json.toJSONString());
|
||||
}
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setDeviceId(deviceId);
|
||||
msg.setType(DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD);
|
||||
msg.setData(json);
|
||||
deferredResultHolder.invokeResult(msg);
|
||||
} else {
|
||||
// 此处是上级发出的DeviceConfig指令
|
||||
}
|
||||
} catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理PresetQuery预置位列表Message
|
||||
*
|
||||
* @param evt
|
||||
*/
|
||||
private void processMessagePresetQuery(RequestEvent evt) {
|
||||
try {
|
||||
Element rootElement = getRootElement(evt);
|
||||
String deviceId = XmlUtil.getText(rootElement, "DeviceID");
|
||||
// 回复200 OK
|
||||
responseAck(evt);
|
||||
if (rootElement.getName().equals("Response")) {// !XmlUtil.isEmpty(result)) {
|
||||
// 此处是对本平台发出DeviceControl指令的应答
|
||||
JSONObject json = new JSONObject();
|
||||
XmlUtil.node2Json(rootElement, json);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(json.toJSONString());
|
||||
}
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setDeviceId(deviceId);
|
||||
msg.setType(DeferredResultHolder.CALLBACK_CMD_PRESETQUERY);
|
||||
msg.setData(json);
|
||||
deferredResultHolder.invokeResult(msg);
|
||||
} else {
|
||||
// 此处是上级发出的DeviceControl指令
|
||||
}
|
||||
} catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理DeviceInfo设备信息Message
|
||||
*
|
||||
* @param evt
|
||||
*/
|
||||
@@ -126,7 +363,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
try {
|
||||
Element rootElement = getRootElement(evt);
|
||||
Element deviceIdElement = rootElement.element("DeviceID");
|
||||
String deviceId = deviceIdElement.getText().toString();
|
||||
String deviceId = deviceIdElement.getTextTrim().toString();
|
||||
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
if (device == null) {
|
||||
@@ -228,80 +465,78 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
deviceChannel.setStatus(0);
|
||||
}
|
||||
|
||||
deviceChannel.setManufacture(XmlUtil.getText(itemDevice, "Manufacturer"));
|
||||
deviceChannel.setModel(XmlUtil.getText(itemDevice, "Model"));
|
||||
deviceChannel.setOwner(XmlUtil.getText(itemDevice, "Owner"));
|
||||
deviceChannel.setCivilCode(XmlUtil.getText(itemDevice, "CivilCode"));
|
||||
deviceChannel.setBlock(XmlUtil.getText(itemDevice, "Block"));
|
||||
deviceChannel.setAddress(XmlUtil.getText(itemDevice, "Address"));
|
||||
if (XmlUtil.getText(itemDevice, "Parental") == null || XmlUtil.getText(itemDevice, "Parental") == "") {
|
||||
deviceChannel.setParental(0);
|
||||
} else {
|
||||
deviceChannel.setParental(Integer.parseInt(XmlUtil.getText(itemDevice, "Parental")));
|
||||
}
|
||||
deviceChannel.setParentId(XmlUtil.getText(itemDevice, "ParentID"));
|
||||
if (XmlUtil.getText(itemDevice, "SafetyWay") == null || XmlUtil.getText(itemDevice, "SafetyWay")== "") {
|
||||
deviceChannel.setSafetyWay(0);
|
||||
} else {
|
||||
deviceChannel.setSafetyWay(Integer.parseInt(XmlUtil.getText(itemDevice, "SafetyWay")));
|
||||
}
|
||||
if (XmlUtil.getText(itemDevice, "RegisterWay") == null || XmlUtil.getText(itemDevice, "RegisterWay") =="") {
|
||||
deviceChannel.setRegisterWay(1);
|
||||
} else {
|
||||
deviceChannel.setRegisterWay(Integer.parseInt(XmlUtil.getText(itemDevice, "RegisterWay")));
|
||||
}
|
||||
deviceChannel.setCertNum(XmlUtil.getText(itemDevice, "CertNum"));
|
||||
if (XmlUtil.getText(itemDevice, "Certifiable") == null || XmlUtil.getText(itemDevice, "Certifiable") == "") {
|
||||
deviceChannel.setCertifiable(0);
|
||||
} else {
|
||||
deviceChannel.setCertifiable(Integer.parseInt(XmlUtil.getText(itemDevice, "Certifiable")));
|
||||
}
|
||||
if (XmlUtil.getText(itemDevice, "ErrCode") == null || XmlUtil.getText(itemDevice, "ErrCode") == "") {
|
||||
deviceChannel.setErrCode(0);
|
||||
} else {
|
||||
deviceChannel.setErrCode(Integer.parseInt(XmlUtil.getText(itemDevice, "ErrCode")));
|
||||
}
|
||||
deviceChannel.setEndTime(XmlUtil.getText(itemDevice, "EndTime"));
|
||||
deviceChannel.setSecrecy(XmlUtil.getText(itemDevice, "Secrecy"));
|
||||
deviceChannel.setIpAddress(XmlUtil.getText(itemDevice, "IPAddress"));
|
||||
if (XmlUtil.getText(itemDevice, "Port") == null || XmlUtil.getText(itemDevice, "Port") =="") {
|
||||
deviceChannel.setPort(0);
|
||||
} else {
|
||||
deviceChannel.setPort(Integer.parseInt(XmlUtil.getText(itemDevice, "Port")));
|
||||
}
|
||||
deviceChannel.setPassword(XmlUtil.getText(itemDevice, "Password"));
|
||||
if (XmlUtil.getText(itemDevice, "Longitude") == null || XmlUtil.getText(itemDevice, "Longitude") == "") {
|
||||
deviceChannel.setLongitude(0.00);
|
||||
} else {
|
||||
deviceChannel.setLongitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Longitude")));
|
||||
}
|
||||
if (XmlUtil.getText(itemDevice, "Latitude") == null || XmlUtil.getText(itemDevice, "Latitude") =="") {
|
||||
deviceChannel.setLatitude(0.00);
|
||||
} else {
|
||||
deviceChannel.setLatitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Latitude")));
|
||||
}
|
||||
if (XmlUtil.getText(itemDevice, "PTZType") == null || XmlUtil.getText(itemDevice, "PTZType") == "") {
|
||||
deviceChannel.setPTZType(0);
|
||||
} else {
|
||||
deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(itemDevice, "PTZType")));
|
||||
}
|
||||
deviceChannel.setHasAudio(true); // 默认含有音频,播放时再检查是否有音频及是否AAC
|
||||
storager.updateChannel(device.getDeviceId(), deviceChannel);
|
||||
deviceChannel.setManufacture(XmlUtil.getText(itemDevice, "Manufacturer"));
|
||||
deviceChannel.setModel(XmlUtil.getText(itemDevice, "Model"));
|
||||
deviceChannel.setOwner(XmlUtil.getText(itemDevice, "Owner"));
|
||||
deviceChannel.setCivilCode(XmlUtil.getText(itemDevice, "CivilCode"));
|
||||
deviceChannel.setBlock(XmlUtil.getText(itemDevice, "Block"));
|
||||
deviceChannel.setAddress(XmlUtil.getText(itemDevice, "Address"));
|
||||
if (XmlUtil.getText(itemDevice, "Parental") == null || XmlUtil.getText(itemDevice, "Parental") == "") {
|
||||
deviceChannel.setParental(0);
|
||||
} else {
|
||||
deviceChannel.setParental(Integer.parseInt(XmlUtil.getText(itemDevice, "Parental")));
|
||||
}
|
||||
deviceChannel.setParentId(XmlUtil.getText(itemDevice, "ParentID"));
|
||||
if (XmlUtil.getText(itemDevice, "SafetyWay") == null || XmlUtil.getText(itemDevice, "SafetyWay")== "") {
|
||||
deviceChannel.setSafetyWay(0);
|
||||
} else {
|
||||
deviceChannel.setSafetyWay(Integer.parseInt(XmlUtil.getText(itemDevice, "SafetyWay")));
|
||||
}
|
||||
if (XmlUtil.getText(itemDevice, "RegisterWay") == null || XmlUtil.getText(itemDevice, "RegisterWay") =="") {
|
||||
deviceChannel.setRegisterWay(1);
|
||||
} else {
|
||||
deviceChannel.setRegisterWay(Integer.parseInt(XmlUtil.getText(itemDevice, "RegisterWay")));
|
||||
}
|
||||
deviceChannel.setCertNum(XmlUtil.getText(itemDevice, "CertNum"));
|
||||
if (XmlUtil.getText(itemDevice, "Certifiable") == null || XmlUtil.getText(itemDevice, "Certifiable") == "") {
|
||||
deviceChannel.setCertifiable(0);
|
||||
} else {
|
||||
deviceChannel.setCertifiable(Integer.parseInt(XmlUtil.getText(itemDevice, "Certifiable")));
|
||||
}
|
||||
if (XmlUtil.getText(itemDevice, "ErrCode") == null || XmlUtil.getText(itemDevice, "ErrCode") == "") {
|
||||
deviceChannel.setErrCode(0);
|
||||
} else {
|
||||
deviceChannel.setErrCode(Integer.parseInt(XmlUtil.getText(itemDevice, "ErrCode")));
|
||||
}
|
||||
deviceChannel.setEndTime(XmlUtil.getText(itemDevice, "EndTime"));
|
||||
deviceChannel.setSecrecy(XmlUtil.getText(itemDevice, "Secrecy"));
|
||||
deviceChannel.setIpAddress(XmlUtil.getText(itemDevice, "IPAddress"));
|
||||
if (XmlUtil.getText(itemDevice, "Port") == null || XmlUtil.getText(itemDevice, "Port") =="") {
|
||||
deviceChannel.setPort(0);
|
||||
} else {
|
||||
deviceChannel.setPort(Integer.parseInt(XmlUtil.getText(itemDevice, "Port")));
|
||||
}
|
||||
deviceChannel.setPassword(XmlUtil.getText(itemDevice, "Password"));
|
||||
if (XmlUtil.getText(itemDevice, "Longitude") == null || XmlUtil.getText(itemDevice, "Longitude") == "") {
|
||||
deviceChannel.setLongitude(0.00);
|
||||
} else {
|
||||
deviceChannel.setLongitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Longitude")));
|
||||
}
|
||||
if (XmlUtil.getText(itemDevice, "Latitude") == null || XmlUtil.getText(itemDevice, "Latitude") =="") {
|
||||
deviceChannel.setLatitude(0.00);
|
||||
} else {
|
||||
deviceChannel.setLatitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Latitude")));
|
||||
}
|
||||
if (XmlUtil.getText(itemDevice, "PTZType") == null || XmlUtil.getText(itemDevice, "PTZType") == "") {
|
||||
deviceChannel.setPTZType(0);
|
||||
} else {
|
||||
deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(itemDevice, "PTZType")));
|
||||
}
|
||||
deviceChannel.setHasAudio(true); // 默认含有音频,播放时再检查是否有音频及是否AAC
|
||||
storager.updateChannel(device.getDeviceId(), deviceChannel);
|
||||
}
|
||||
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setDeviceId(deviceId);
|
||||
msg.setType(DeferredResultHolder.CALLBACK_CMD_CATALOG);
|
||||
msg.setData(device);
|
||||
deferredResultHolder.invokeResult(msg);
|
||||
// 回复200 OK
|
||||
responseAck(evt);
|
||||
if (offLineDetector.isOnline(deviceId)) {
|
||||
publisher.onlineEventPublish(deviceId, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE);
|
||||
}
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setDeviceId(deviceId);
|
||||
msg.setType(DeferredResultHolder.CALLBACK_CMD_CATALOG);
|
||||
msg.setData(device);
|
||||
deferredResultHolder.invokeResult(msg);
|
||||
// 回复200 OK
|
||||
responseAck(evt);
|
||||
if (offLineDetector.isOnline(deviceId)) {
|
||||
publisher.onlineEventPublish(deviceId, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -324,41 +559,19 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
// storager.queryChannel(deviceId)
|
||||
return;
|
||||
}
|
||||
|
||||
DeviceAlarm deviceAlarm = new DeviceAlarm();
|
||||
deviceAlarm.setDeviceId(deviceId);
|
||||
deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority"));
|
||||
deviceAlarm.setAlarmMethod(XmlUtil.getText(rootElement, "AlarmMethod"));
|
||||
deviceAlarm.setAlarmTime(XmlUtil.getText(rootElement, "AlarmTime"));
|
||||
if (XmlUtil.getText(rootElement, "AlarmDescription") == null) {
|
||||
deviceAlarm.setAlarmDescription("");
|
||||
} else {
|
||||
deviceAlarm.setAlarmDescription(XmlUtil.getText(rootElement, "AlarmDescription"));
|
||||
device.setName(XmlUtil.getText(rootElement, "DeviceName"));
|
||||
device.setManufacturer(XmlUtil.getText(rootElement, "Manufacturer"));
|
||||
device.setModel(XmlUtil.getText(rootElement, "Model"));
|
||||
device.setFirmware(XmlUtil.getText(rootElement, "Firmware"));
|
||||
if (StringUtils.isEmpty(device.getStreamMode())) {
|
||||
device.setStreamMode("UDP");
|
||||
}
|
||||
if (XmlUtil.getText(rootElement, "Longitude") == null || XmlUtil.getText(rootElement, "Longitude") == "") {
|
||||
deviceAlarm.setLongitude(0.00);
|
||||
} else {
|
||||
deviceAlarm.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude")));
|
||||
}
|
||||
if (XmlUtil.getText(rootElement, "Latitude") == null || XmlUtil.getText(rootElement, "Latitude") =="") {
|
||||
deviceAlarm.setLatitude(0.00);
|
||||
} else {
|
||||
deviceAlarm.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
|
||||
}
|
||||
|
||||
// device.setName(XmlUtil.getText(rootElement, "DeviceName"));
|
||||
// device.setManufacturer(XmlUtil.getText(rootElement, "Manufacturer"));
|
||||
// device.setModel(XmlUtil.getText(rootElement, "Model"));
|
||||
// device.setFirmware(XmlUtil.getText(rootElement, "Firmware"));
|
||||
// if (StringUtils.isEmpty(device.getStreamMode())) {
|
||||
// device.setStreamMode("UDP");
|
||||
// }
|
||||
// storager.updateDevice(device);
|
||||
storager.updateDevice(device);
|
||||
//cmder.catalogQuery(device, null);
|
||||
// 回复200 OK
|
||||
responseAck(evt);
|
||||
if (offLineDetector.isOnline(deviceId)) {
|
||||
publisher.deviceAlarmEventPublish(deviceAlarm);
|
||||
publisher.onlineEventPublish(deviceId, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE);
|
||||
}
|
||||
} catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
|
||||
// } catch (DocumentException e) {
|
||||
@@ -384,14 +597,13 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
} else {
|
||||
}
|
||||
}
|
||||
|
||||
} catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* 收到catalog设备目录列表请求 处理 TODO 过期时间暂时写死180秒,后续与DeferredResult超时时间保持一致
|
||||
* 处理RecordInfo设备录像列表Message请求 TODO 过期时间暂时写死180秒,后续与DeferredResult超时时间保持一致
|
||||
*
|
||||
* @param evt
|
||||
*/
|
||||
@@ -415,8 +627,11 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
Element recordListElement = rootElement.element("RecordList");
|
||||
if (recordListElement == null || recordInfo.getSumNum() == 0) {
|
||||
logger.info("无录像数据");
|
||||
// responseAck(evt);
|
||||
// return;
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setDeviceId(deviceId);
|
||||
msg.setType(DeferredResultHolder.CALLBACK_CMD_RECORDINFO);
|
||||
msg.setData(recordInfo);
|
||||
deferredResultHolder.invokeResult(msg);
|
||||
} else {
|
||||
Iterator<Element> recordListIterator = recordListElement.elementIterator();
|
||||
List<RecordItem> recordList = new ArrayList<RecordItem>();
|
||||
@@ -446,53 +661,73 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
record.setRecorderId(XmlUtil.getText(itemRecord, "RecorderID"));
|
||||
recordList.add(record);
|
||||
}
|
||||
// recordList.sort(Comparator.naturalOrder());
|
||||
recordInfo.setRecordList(recordList);
|
||||
}
|
||||
|
||||
// 存在录像且如果当前录像明细个数小于总条数,说明拆包返回,需要组装,暂不返回
|
||||
if (recordInfo.getSumNum() > 0 && recordList.size() > 0 && recordList.size() < recordInfo.getSumNum()) {
|
||||
// 为防止连续请求该设备的录像数据,返回数据错乱,特增加sn进行区分
|
||||
String cacheKey = CACHE_RECORDINFO_KEY + deviceId + sn;
|
||||
|
||||
redis.set(cacheKey + "_" + uuid, recordList, 90);
|
||||
List<Object> cacheKeys = redis.scan(cacheKey + "_*");
|
||||
List<RecordItem> totalRecordList = new ArrayList<RecordItem>();
|
||||
for (int i = 0; i < cacheKeys.size(); i++) {
|
||||
totalRecordList.addAll((List<RecordItem>) redis.get(cacheKeys.get(i).toString()));
|
||||
// 改用单独线程统计已获取录像文件数量,避免多包并行分别统计不完整的问题
|
||||
String cacheKey = CACHE_RECORDINFO_KEY + deviceId + sn;
|
||||
redis.set(cacheKey + "_" + uuid, recordList, 90);
|
||||
if (!threadNameList.contains(cacheKey)) {
|
||||
threadNameList.add(cacheKey);
|
||||
CheckForAllRecordsThread chk = new CheckForAllRecordsThread(cacheKey, recordInfo);
|
||||
chk.setName(cacheKey);
|
||||
chk.setDeferredResultHolder(deferredResultHolder);
|
||||
chk.setRedis(redis);
|
||||
chk.setLogger(logger);
|
||||
chk.start();
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Start Thread " + cacheKey + ".");
|
||||
}
|
||||
if (totalRecordList.size() < recordInfo.getSumNum()) {
|
||||
logger.info("已获取" + totalRecordList.size() + "项录像数据,共" + recordInfo.getSumNum() + "项");
|
||||
return;
|
||||
}
|
||||
logger.info("录像数据已全部获取,共" + recordInfo.getSumNum() + "项");
|
||||
recordInfo.setRecordList(totalRecordList);
|
||||
for (int i = 0; i < cacheKeys.size(); i++) {
|
||||
redis.del(cacheKeys.get(i).toString());
|
||||
} else {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Thread " + cacheKey + " already started.");
|
||||
}
|
||||
}
|
||||
// 自然顺序排序, 元素进行升序排列
|
||||
recordInfo.getRecordList().sort(Comparator.naturalOrder());
|
||||
|
||||
// 存在录像且如果当前录像明细个数小于总条数,说明拆包返回,需要组装,暂不返回
|
||||
// if (recordInfo.getSumNum() > 0 && recordList.size() > 0 && recordList.size() < recordInfo.getSumNum()) {
|
||||
// // 为防止连续请求该设备的录像数据,返回数据错乱,特增加sn进行区分
|
||||
// String cacheKey = CACHE_RECORDINFO_KEY + deviceId + sn;
|
||||
|
||||
// redis.set(cacheKey + "_" + uuid, recordList, 90);
|
||||
// List<Object> cacheKeys = redis.scan(cacheKey + "_*");
|
||||
// List<RecordItem> totalRecordList = new ArrayList<RecordItem>();
|
||||
// for (int i = 0; i < cacheKeys.size(); i++) {
|
||||
// totalRecordList.addAll((List<RecordItem>) redis.get(cacheKeys.get(i).toString()));
|
||||
// }
|
||||
// if (totalRecordList.size() < recordInfo.getSumNum()) {
|
||||
// logger.info("已获取" + totalRecordList.size() + "项录像数据,共" + recordInfo.getSumNum() + "项");
|
||||
// return;
|
||||
// }
|
||||
// logger.info("录像数据已全部获取,共" + recordInfo.getSumNum() + "项");
|
||||
// recordInfo.setRecordList(totalRecordList);
|
||||
// for (int i = 0; i < cacheKeys.size(); i++) {
|
||||
// redis.del(cacheKeys.get(i).toString());
|
||||
// }
|
||||
// }
|
||||
// // 自然顺序排序, 元素进行升序排列
|
||||
// recordInfo.getRecordList().sort(Comparator.naturalOrder());
|
||||
}
|
||||
// 走到这里,有以下可能:1、没有录像信息,第一次收到recordinfo的消息即返回响应数据,无redis操作
|
||||
// 2、有录像数据,且第一次即收到完整数据,返回响应数据,无redis操作
|
||||
// 3、有录像数据,在超时时间内收到多次包组装后数量足够,返回数据
|
||||
|
||||
// 对记录进行排序
|
||||
RequestMessage msg = new RequestMessage();
|
||||
msg.setDeviceId(deviceId);
|
||||
msg.setType(DeferredResultHolder.CALLBACK_CMD_RECORDINFO);
|
||||
// // 自然顺序排序, 元素进行升序排列
|
||||
// recordInfo.getRecordList().sort(Comparator.naturalOrder());
|
||||
msg.setData(recordInfo);
|
||||
deferredResultHolder.invokeResult(msg);
|
||||
logger.info("处理完成,返回结果");
|
||||
// RequestMessage msg = new RequestMessage();
|
||||
// msg.setDeviceId(deviceId);
|
||||
// msg.setType(DeferredResultHolder.CALLBACK_CMD_RECORDINFO);
|
||||
// msg.setData(recordInfo);
|
||||
// deferredResultHolder.invokeResult(msg);
|
||||
// logger.info("处理完成,返回结果");
|
||||
} catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 收到MediaStatus消息处理
|
||||
*
|
||||
* @param evt
|
||||
*/
|
||||
private void processMessageMediaStatus(RequestEvent evt){
|
||||
try {
|
||||
// 回复200 OK
|
||||
|
||||
@@ -0,0 +1,384 @@
|
||||
package com.genersoft.iot.vmp.gb28181.transmit.request.impl;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.text.ParseException;
|
||||
import java.util.Iterator;
|
||||
|
||||
import javax.sip.InvalidArgumentException;
|
||||
import javax.sip.RequestEvent;
|
||||
import javax.sip.SipException;
|
||||
import javax.sip.message.Request;
|
||||
import javax.sip.message.Response;
|
||||
|
||||
import com.genersoft.iot.vmp.common.VideoManagerConstants;
|
||||
import com.genersoft.iot.vmp.conf.UserSetup;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.BaiduPoint;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceAlarm;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.MobilePosition;
|
||||
import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector;
|
||||
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcessor;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
|
||||
import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import com.genersoft.iot.vmp.utils.GpsUtil;
|
||||
import com.genersoft.iot.vmp.utils.SpringBeanFactory;
|
||||
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
||||
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
import org.dom4j.Element;
|
||||
import org.dom4j.io.SAXReader;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @Description: Notify请求处理器
|
||||
* @author: lawrencehj
|
||||
* @date: 2021年1月27日
|
||||
*/
|
||||
|
||||
public class NotifyRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
|
||||
private UserSetup userSetup = (UserSetup) SpringBeanFactory.getBean("userSetup");
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(MessageRequestProcessor.class);
|
||||
|
||||
private IVideoManagerStorager storager;
|
||||
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
private EventPublisher publisher;
|
||||
|
||||
private DeviceOffLineDetector offLineDetector;
|
||||
|
||||
private static final String NOTIFY_CATALOG = "Catalog";
|
||||
private static final String NOTIFY_ALARM = "Alarm";
|
||||
private static final String NOTIFY_MOBILE_POSITION = "MobilePosition";
|
||||
|
||||
@Override
|
||||
public void process(RequestEvent evt) {
|
||||
try {
|
||||
Element rootElement = getRootElement(evt);
|
||||
String cmd = XmlUtil.getText(rootElement, "CmdType");
|
||||
|
||||
if (NOTIFY_CATALOG.equals(cmd)) {
|
||||
logger.info("接收到Catalog通知");
|
||||
processNotifyCatalogList(evt);
|
||||
} else if (NOTIFY_ALARM.equals(cmd)) {
|
||||
logger.info("接收到Alarm通知");
|
||||
processNotifyAlarm(evt);
|
||||
} else if (NOTIFY_MOBILE_POSITION.equals(cmd)) {
|
||||
logger.info("接收到MobilePosition通知");
|
||||
processNotifyMobilePosition(evt);
|
||||
} else {
|
||||
logger.info("接收到消息:" + cmd);
|
||||
response200Ok(evt);
|
||||
}
|
||||
} catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理MobilePosition移动位置Notify
|
||||
*
|
||||
* @param evt
|
||||
*/
|
||||
private void processNotifyMobilePosition(RequestEvent evt) {
|
||||
try {
|
||||
// 回复 200 OK
|
||||
Element rootElement = getRootElement(evt);
|
||||
MobilePosition mobilePosition = new MobilePosition();
|
||||
Element deviceIdElement = rootElement.element("DeviceID");
|
||||
String deviceId = deviceIdElement.getTextTrim().toString();
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
if (device != null) {
|
||||
if (!StringUtils.isEmpty(device.getName())) {
|
||||
mobilePosition.setDeviceName(device.getName());
|
||||
}
|
||||
}
|
||||
mobilePosition.setDeviceId(XmlUtil.getText(rootElement, "DeviceID"));
|
||||
mobilePosition.setTime(XmlUtil.getText(rootElement, "Time"));
|
||||
mobilePosition.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude")));
|
||||
mobilePosition.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
|
||||
if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Speed"))) {
|
||||
mobilePosition.setSpeed(Double.parseDouble(XmlUtil.getText(rootElement, "Speed")));
|
||||
} else {
|
||||
mobilePosition.setSpeed(0.0);
|
||||
}
|
||||
if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Direction"))) {
|
||||
mobilePosition.setDirection(Double.parseDouble(XmlUtil.getText(rootElement, "Direction")));
|
||||
} else {
|
||||
mobilePosition.setDirection(0.0);
|
||||
}
|
||||
if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Altitude"))) {
|
||||
mobilePosition.setAltitude(Double.parseDouble(XmlUtil.getText(rootElement, "Altitude")));
|
||||
} else {
|
||||
mobilePosition.setAltitude(0.0);
|
||||
}
|
||||
mobilePosition.setReportSource("Mobile Position");
|
||||
BaiduPoint bp = new BaiduPoint();
|
||||
bp = GpsUtil.Wgs84ToBd09(String.valueOf(mobilePosition.getLongitude()), String.valueOf(mobilePosition.getLatitude()));
|
||||
logger.info("百度坐标:" + bp.getBdLng() + ", " + bp.getBdLat());
|
||||
mobilePosition.setGeodeticSystem("BD-09");
|
||||
mobilePosition.setCnLng(bp.getBdLng());
|
||||
mobilePosition.setCnLat(bp.getBdLat());
|
||||
if (!userSetup.getSavePositionHistory()) {
|
||||
storager.clearMobilePositionsByDeviceId(deviceId);
|
||||
}
|
||||
storager.insertMobilePosition(mobilePosition);
|
||||
response200Ok(evt);
|
||||
} catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* 处理alarm设备报警Notify
|
||||
*
|
||||
* @param evt
|
||||
*/
|
||||
private void processNotifyAlarm(RequestEvent evt) {
|
||||
try {
|
||||
Element rootElement = getRootElement(evt);
|
||||
Element deviceIdElement = rootElement.element("DeviceID");
|
||||
String deviceId = deviceIdElement.getText().toString();
|
||||
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
if (device == null) {
|
||||
return;
|
||||
}
|
||||
DeviceAlarm deviceAlarm = new DeviceAlarm();
|
||||
deviceAlarm.setDeviceId(deviceId);
|
||||
deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority"));
|
||||
deviceAlarm.setAlarmMethod(XmlUtil.getText(rootElement, "AlarmMethod"));
|
||||
deviceAlarm.setAlarmTime(XmlUtil.getText(rootElement, "AlarmTime"));
|
||||
if (XmlUtil.getText(rootElement, "AlarmDescription") == null) {
|
||||
deviceAlarm.setAlarmDescription("");
|
||||
} else {
|
||||
deviceAlarm.setAlarmDescription(XmlUtil.getText(rootElement, "AlarmDescription"));
|
||||
}
|
||||
if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Longitude"))) {
|
||||
deviceAlarm.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude")));
|
||||
} else {
|
||||
deviceAlarm.setLongitude(0.00);
|
||||
}
|
||||
if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Latitude"))) {
|
||||
deviceAlarm.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
|
||||
} else {
|
||||
deviceAlarm.setLatitude(0.00);
|
||||
}
|
||||
|
||||
if (deviceAlarm.getAlarmMethod().equals("4")) {
|
||||
MobilePosition mobilePosition = new MobilePosition();
|
||||
mobilePosition.setDeviceId(deviceAlarm.getDeviceId());
|
||||
mobilePosition.setTime(deviceAlarm.getAlarmTime());
|
||||
mobilePosition.setLongitude(deviceAlarm.getLongitude());
|
||||
mobilePosition.setLatitude(deviceAlarm.getLatitude());
|
||||
mobilePosition.setReportSource("GPS Alarm");
|
||||
BaiduPoint bp = new BaiduPoint();
|
||||
bp = GpsUtil.Wgs84ToBd09(String.valueOf(mobilePosition.getLongitude()), String.valueOf(mobilePosition.getLatitude()));
|
||||
logger.info("百度坐标:" + bp.getBdLng() + ", " + bp.getBdLat());
|
||||
mobilePosition.setGeodeticSystem("BD-09");
|
||||
mobilePosition.setCnLng(bp.getBdLng());
|
||||
mobilePosition.setCnLat(bp.getBdLat());
|
||||
if (!userSetup.getSavePositionHistory()) {
|
||||
storager.clearMobilePositionsByDeviceId(deviceId);
|
||||
}
|
||||
storager.insertMobilePosition(mobilePosition);
|
||||
}
|
||||
// TODO: 需要实现存储报警信息、报警分类
|
||||
|
||||
// 回复200 OK
|
||||
response200Ok(evt);
|
||||
if (offLineDetector.isOnline(deviceId)) {
|
||||
publisher.deviceAlarmEventPublish(deviceAlarm);
|
||||
}
|
||||
} catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* 处理catalog设备目录列表Notify
|
||||
*
|
||||
* @param evt
|
||||
*/
|
||||
private void processNotifyCatalogList(RequestEvent evt) {
|
||||
try {
|
||||
Element rootElement = getRootElement(evt);
|
||||
Element deviceIdElement = rootElement.element("DeviceID");
|
||||
String deviceId = deviceIdElement.getText();
|
||||
Element deviceListElement = rootElement.element("DeviceList");
|
||||
if (deviceListElement == null) {
|
||||
return;
|
||||
}
|
||||
Iterator<Element> deviceListIterator = deviceListElement.elementIterator();
|
||||
if (deviceListIterator != null) {
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
if (device == null) {
|
||||
return;
|
||||
}
|
||||
// 遍历DeviceList
|
||||
while (deviceListIterator.hasNext()) {
|
||||
Element itemDevice = deviceListIterator.next();
|
||||
Element channelDeviceElement = itemDevice.element("DeviceID");
|
||||
if (channelDeviceElement == null) {
|
||||
continue;
|
||||
}
|
||||
String channelDeviceId = channelDeviceElement.getTextTrim();
|
||||
Element channdelNameElement = itemDevice.element("Name");
|
||||
String channelName = channdelNameElement != null ? channdelNameElement.getTextTrim().toString() : "";
|
||||
Element statusElement = itemDevice.element("Status");
|
||||
String status = statusElement != null ? statusElement.getTextTrim().toString() : "ON";
|
||||
DeviceChannel deviceChannel = new DeviceChannel();
|
||||
deviceChannel.setName(channelName);
|
||||
deviceChannel.setChannelId(channelDeviceId);
|
||||
// ONLINE OFFLINE HIKVISION DS-7716N-E4 NVR的兼容性处理
|
||||
if (status.equals("ON") || status.equals("On") || status.equals("ONLINE")) {
|
||||
deviceChannel.setStatus(1);
|
||||
}
|
||||
if (status.equals("OFF") || status.equals("Off") || status.equals("OFFLINE")) {
|
||||
deviceChannel.setStatus(0);
|
||||
}
|
||||
|
||||
deviceChannel.setManufacture(XmlUtil.getText(itemDevice, "Manufacturer"));
|
||||
deviceChannel.setModel(XmlUtil.getText(itemDevice, "Model"));
|
||||
deviceChannel.setOwner(XmlUtil.getText(itemDevice, "Owner"));
|
||||
deviceChannel.setCivilCode(XmlUtil.getText(itemDevice, "CivilCode"));
|
||||
deviceChannel.setBlock(XmlUtil.getText(itemDevice, "Block"));
|
||||
deviceChannel.setAddress(XmlUtil.getText(itemDevice, "Address"));
|
||||
if (XmlUtil.getText(itemDevice, "Parental") == null
|
||||
|| XmlUtil.getText(itemDevice, "Parental") == "") {
|
||||
deviceChannel.setParental(0);
|
||||
} else {
|
||||
deviceChannel.setParental(Integer.parseInt(XmlUtil.getText(itemDevice, "Parental")));
|
||||
}
|
||||
deviceChannel.setParentId(XmlUtil.getText(itemDevice, "ParentID"));
|
||||
if (XmlUtil.getText(itemDevice, "SafetyWay") == null
|
||||
|| XmlUtil.getText(itemDevice, "SafetyWay") == "") {
|
||||
deviceChannel.setSafetyWay(0);
|
||||
} else {
|
||||
deviceChannel.setSafetyWay(Integer.parseInt(XmlUtil.getText(itemDevice, "SafetyWay")));
|
||||
}
|
||||
if (XmlUtil.getText(itemDevice, "RegisterWay") == null
|
||||
|| XmlUtil.getText(itemDevice, "RegisterWay") == "") {
|
||||
deviceChannel.setRegisterWay(1);
|
||||
} else {
|
||||
deviceChannel.setRegisterWay(Integer.parseInt(XmlUtil.getText(itemDevice, "RegisterWay")));
|
||||
}
|
||||
deviceChannel.setCertNum(XmlUtil.getText(itemDevice, "CertNum"));
|
||||
if (XmlUtil.getText(itemDevice, "Certifiable") == null
|
||||
|| XmlUtil.getText(itemDevice, "Certifiable") == "") {
|
||||
deviceChannel.setCertifiable(0);
|
||||
} else {
|
||||
deviceChannel.setCertifiable(Integer.parseInt(XmlUtil.getText(itemDevice, "Certifiable")));
|
||||
}
|
||||
if (XmlUtil.getText(itemDevice, "ErrCode") == null
|
||||
|| XmlUtil.getText(itemDevice, "ErrCode") == "") {
|
||||
deviceChannel.setErrCode(0);
|
||||
} else {
|
||||
deviceChannel.setErrCode(Integer.parseInt(XmlUtil.getText(itemDevice, "ErrCode")));
|
||||
}
|
||||
deviceChannel.setEndTime(XmlUtil.getText(itemDevice, "EndTime"));
|
||||
deviceChannel.setSecrecy(XmlUtil.getText(itemDevice, "Secrecy"));
|
||||
deviceChannel.setIpAddress(XmlUtil.getText(itemDevice, "IPAddress"));
|
||||
if (XmlUtil.getText(itemDevice, "Port") == null || XmlUtil.getText(itemDevice, "Port") == "") {
|
||||
deviceChannel.setPort(0);
|
||||
} else {
|
||||
deviceChannel.setPort(Integer.parseInt(XmlUtil.getText(itemDevice, "Port")));
|
||||
}
|
||||
deviceChannel.setPassword(XmlUtil.getText(itemDevice, "Password"));
|
||||
if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Longitude"))) {
|
||||
deviceChannel.setLongitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Longitude")));
|
||||
} else {
|
||||
deviceChannel.setLongitude(0.00);
|
||||
}
|
||||
if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Latitude"))) {
|
||||
deviceChannel.setLatitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Latitude")));
|
||||
} else {
|
||||
deviceChannel.setLatitude(0.00);
|
||||
}
|
||||
if (XmlUtil.getText(itemDevice, "PTZType") == null
|
||||
|| XmlUtil.getText(itemDevice, "PTZType") == "") {
|
||||
deviceChannel.setPTZType(0);
|
||||
} else {
|
||||
deviceChannel.setPTZType(Integer.parseInt(XmlUtil.getText(itemDevice, "PTZType")));
|
||||
}
|
||||
deviceChannel.setHasAudio(true); // 默认含有音频,播放时再检查是否有音频及是否AAC
|
||||
storager.updateChannel(device.getDeviceId(), deviceChannel);
|
||||
}
|
||||
|
||||
// RequestMessage msg = new RequestMessage();
|
||||
// msg.setDeviceId(deviceId);
|
||||
// msg.setType(DeferredResultHolder.CALLBACK_CMD_CATALOG);
|
||||
// msg.setData(device);
|
||||
// deferredResultHolder.invokeResult(msg);
|
||||
// 回复200 OK
|
||||
response200Ok(evt);
|
||||
if (offLineDetector.isOnline(deviceId)) {
|
||||
publisher.onlineEventPublish(deviceId, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE);
|
||||
}
|
||||
}
|
||||
} catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/***
|
||||
* 回复200 OK
|
||||
*
|
||||
* @param evt
|
||||
* @throws SipException
|
||||
* @throws InvalidArgumentException
|
||||
* @throws ParseException
|
||||
*/
|
||||
private void response200Ok(RequestEvent evt) throws SipException, InvalidArgumentException, ParseException {
|
||||
Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest());
|
||||
getServerTransaction(evt).sendResponse(response);
|
||||
}
|
||||
|
||||
private Element getRootElement(RequestEvent evt) throws DocumentException {
|
||||
Request request = evt.getRequest();
|
||||
SAXReader reader = new SAXReader();
|
||||
reader.setEncoding("gbk");
|
||||
Document xml = reader.read(new ByteArrayInputStream(request.getRawContent()));
|
||||
return xml.getRootElement();
|
||||
}
|
||||
|
||||
public void setCmder(SIPCommander cmder) {
|
||||
}
|
||||
|
||||
public void setStorager(IVideoManagerStorager storager) {
|
||||
this.storager = storager;
|
||||
}
|
||||
|
||||
public void setPublisher(EventPublisher publisher) {
|
||||
this.publisher = publisher;
|
||||
}
|
||||
|
||||
public void setRedis(RedisUtil redis) {
|
||||
}
|
||||
|
||||
public void setDeferredResultHolder(DeferredResultHolder deferredResultHolder) {
|
||||
}
|
||||
|
||||
public void setOffLineDetector(DeviceOffLineDetector offLineDetector) {
|
||||
this.offLineDetector = offLineDetector;
|
||||
}
|
||||
|
||||
public IRedisCatchStorage getRedisCatchStorage() {
|
||||
return redisCatchStorage;
|
||||
}
|
||||
|
||||
public void setRedisCatchStorage(IRedisCatchStorage redisCatchStorage) {
|
||||
this.redisCatchStorage = redisCatchStorage;
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@ public class OtherRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
*/
|
||||
@Override
|
||||
public void process(RequestEvent evt) {
|
||||
System.out.println("no support the method! Method:" + evt.getRequest().getMethod());
|
||||
System.out.println("Unsupported the method: " + evt.getRequest().getMethod());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ public class RegisterRequestProcessor extends SIPRequestAbstractProcessor {
|
||||
// 下发catelog查询目录
|
||||
if (registerFlag == 1 && device != null) {
|
||||
logger.info("注册成功! deviceId:" + device.getDeviceId());
|
||||
boolean exists = storager.exists(device.getDeviceId());
|
||||
// boolean exists = storager.exists(device.getDeviceId());
|
||||
device.setRegisterTimeMillis(System.currentTimeMillis());
|
||||
storager.updateDevice(device);
|
||||
publisher.onlineEventPublish(device.getDeviceId(), VideoManagerConstants.EVENT_ONLINE_REGISTER);
|
||||
|
||||
@@ -12,14 +12,12 @@ import javax.sip.header.ViaHeader;
|
||||
import javax.sip.message.Request;
|
||||
import javax.sip.message.Response;
|
||||
|
||||
import gov.nist.javax.sip.header.CSeq;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
// import org.slf4j.Logger;
|
||||
// import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.SipConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.SipLayer;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorFactory;
|
||||
import com.genersoft.iot.vmp.gb28181.transmit.response.ISIPResponseProcessor;
|
||||
|
||||
|
||||
@@ -31,7 +29,7 @@ import com.genersoft.iot.vmp.gb28181.transmit.response.ISIPResponseProcessor;
|
||||
@Component
|
||||
public class InviteResponseProcessor implements ISIPResponseProcessor {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(InviteResponseProcessor.class);
|
||||
// private final static Logger logger = LoggerFactory.getLogger(InviteResponseProcessor.class);
|
||||
|
||||
/**
|
||||
* 处理invite响应
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.genersoft.iot.vmp.gb28181.utils;
|
||||
|
||||
/**
|
||||
* 数值格式判断和处理
|
||||
* @author lawrencehj
|
||||
* @date 2021年1月27日
|
||||
*/
|
||||
public class NumericUtil {
|
||||
|
||||
/**
|
||||
* 判断是否Double格式
|
||||
* @param str
|
||||
* @return true/false
|
||||
*/
|
||||
public static boolean isDouble(String str) {
|
||||
try {
|
||||
Double num2 = Double.valueOf(str);
|
||||
System.out.println(num2 + " is a valid numeric string!");
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
System.out.println(str + " is an invalid numeric string!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否Double格式
|
||||
* @param str
|
||||
* @return true/false
|
||||
*/
|
||||
public static boolean isInteger(String str) {
|
||||
try {
|
||||
int num2 = Integer.valueOf(str);
|
||||
System.out.println(num2 + " is an integer!");
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
System.out.println(str + " is not an integer!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,9 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import org.dom4j.Attribute;
|
||||
import org.dom4j.Document;
|
||||
import org.dom4j.DocumentException;
|
||||
@@ -20,8 +23,7 @@ import org.slf4j.LoggerFactory;
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class XmlUtil
|
||||
{
|
||||
public class XmlUtil {
|
||||
/**
|
||||
* 日志服务
|
||||
*/
|
||||
@@ -30,22 +32,18 @@ public class XmlUtil
|
||||
/**
|
||||
* 解析XML为Document对象
|
||||
*
|
||||
* @param xml
|
||||
* 被解析的XMl
|
||||
* @param xml 被解析的XMl
|
||||
*
|
||||
* @return Document
|
||||
*/
|
||||
public static Element parseXml(String xml)
|
||||
{
|
||||
public static Element parseXml(String xml) {
|
||||
Document document = null;
|
||||
//
|
||||
StringReader sr = new StringReader(xml);
|
||||
SAXReader saxReader = new SAXReader();
|
||||
try
|
||||
{
|
||||
try {
|
||||
document = saxReader.read(sr);
|
||||
}
|
||||
catch (DocumentException e)
|
||||
{
|
||||
} catch (DocumentException e) {
|
||||
LOG.error("解析失败", e);
|
||||
}
|
||||
return null == document ? null : document.getRootElement();
|
||||
@@ -54,16 +52,12 @@ public class XmlUtil
|
||||
/**
|
||||
* 获取element对象的text的值
|
||||
*
|
||||
* @param em
|
||||
* 节点的对象
|
||||
* @param tag
|
||||
* 节点的tag
|
||||
* @param em 节点的对象
|
||||
* @param tag 节点的tag
|
||||
* @return 节点
|
||||
*/
|
||||
public static String getText(Element em, String tag)
|
||||
{
|
||||
if (null == em)
|
||||
{
|
||||
public static String getText(Element em, String tag) {
|
||||
if (null == em) {
|
||||
return null;
|
||||
}
|
||||
Element e = em.element(tag);
|
||||
@@ -74,16 +68,12 @@ public class XmlUtil
|
||||
/**
|
||||
* 递归解析xml节点,适用于 多节点数据
|
||||
*
|
||||
* @param node
|
||||
* node
|
||||
* @param nodeName
|
||||
* nodeName
|
||||
* @param node node
|
||||
* @param nodeName nodeName
|
||||
* @return List<Map<String, Object>>
|
||||
*/
|
||||
public static List<Map<String, Object>> listNodes(Element node, String nodeName)
|
||||
{
|
||||
if (null == node)
|
||||
{
|
||||
public static List<Map<String, Object>> listNodes(Element node, String nodeName) {
|
||||
if (null == node) {
|
||||
return null;
|
||||
}
|
||||
// 初始化返回
|
||||
@@ -93,12 +83,9 @@ public class XmlUtil
|
||||
|
||||
Map<String, Object> map = null;
|
||||
// 遍历属性节点
|
||||
for (Attribute attribute : list)
|
||||
{
|
||||
if (nodeName.equals(node.getName()))
|
||||
{
|
||||
if (null == map)
|
||||
{
|
||||
for (Attribute attribute : list) {
|
||||
if (nodeName.equals(node.getName())) {
|
||||
if (null == map) {
|
||||
map = new HashMap<String, Object>();
|
||||
listMap.add(map);
|
||||
}
|
||||
@@ -110,12 +97,74 @@ public class XmlUtil
|
||||
// 遍历当前节点下的所有节点 ,nodeName 要解析的节点名称
|
||||
// 使用递归
|
||||
Iterator<Element> iterator = node.elementIterator();
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
while (iterator.hasNext()) {
|
||||
Element e = iterator.next();
|
||||
listMap.addAll(listNodes(e, nodeName));
|
||||
}
|
||||
return listMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* xml转json
|
||||
*
|
||||
* @param element
|
||||
* @param json
|
||||
*/
|
||||
public static void node2Json(Element element, JSONObject json) {
|
||||
// 如果是属性
|
||||
for (Object o : element.attributes()) {
|
||||
Attribute attr = (Attribute) o;
|
||||
if (!isEmpty(attr.getValue())) {
|
||||
json.put("@" + attr.getName(), attr.getValue());
|
||||
}
|
||||
}
|
||||
List<Element> chdEl = element.elements();
|
||||
if (chdEl.isEmpty() && !isEmpty(element.getText())) {// 如果没有子元素,只有一个值
|
||||
json.put(element.getName(), element.getText());
|
||||
}
|
||||
|
||||
for (Element e : chdEl) { // 有子元素
|
||||
if (!e.elements().isEmpty()) { // 子元素也有子元素
|
||||
JSONObject chdjson = new JSONObject();
|
||||
node2Json(e, chdjson);
|
||||
Object o = json.get(e.getName());
|
||||
if (o != null) {
|
||||
JSONArray jsona = null;
|
||||
if (o instanceof JSONObject) { // 如果此元素已存在,则转为jsonArray
|
||||
JSONObject jsono = (JSONObject) o;
|
||||
json.remove(e.getName());
|
||||
jsona = new JSONArray();
|
||||
jsona.add(jsono);
|
||||
jsona.add(chdjson);
|
||||
}
|
||||
if (o instanceof JSONArray) {
|
||||
jsona = (JSONArray) o;
|
||||
jsona.add(chdjson);
|
||||
}
|
||||
json.put(e.getName(), jsona);
|
||||
} else {
|
||||
if (!chdjson.isEmpty()) {
|
||||
json.put(e.getName(), chdjson);
|
||||
}
|
||||
}
|
||||
} else { // 子元素没有子元素
|
||||
for (Object o : element.attributes()) {
|
||||
Attribute attr = (Attribute) o;
|
||||
if (!isEmpty(attr.getValue())) {
|
||||
json.put("@" + attr.getName(), attr.getValue());
|
||||
}
|
||||
}
|
||||
if (!e.getText().isEmpty()) {
|
||||
json.put(e.getName(), e.getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEmpty(String str) {
|
||||
if (str == null || str.trim().isEmpty() || "null".equals(str)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user