Commit e9586687f735c4fbca5111e991f9074dc6642bf7
Merge remote-tracking branch 'origin/wvp-28181-2.0' into wvp-28181-2.0
Showing
7 changed files
with
102 additions
and
10 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
| ... | ... | @@ -29,6 +29,7 @@ import gov.nist.javax.sdp.TimeDescriptionImpl; |
| 29 | 29 | import gov.nist.javax.sdp.fields.TimeField; |
| 30 | 30 | import gov.nist.javax.sip.address.AddressImpl; |
| 31 | 31 | import gov.nist.javax.sip.address.SipUri; |
| 32 | +import gov.nist.javax.sip.header.Subject; | |
| 32 | 33 | import org.slf4j.Logger; |
| 33 | 34 | import org.slf4j.LoggerFactory; |
| 34 | 35 | import org.springframework.beans.factory.InitializingBean; |
| ... | ... | @@ -43,6 +44,7 @@ import javax.sip.SipException; |
| 43 | 44 | import javax.sip.address.SipURI; |
| 44 | 45 | import javax.sip.header.CallIdHeader; |
| 45 | 46 | import javax.sip.header.FromHeader; |
| 47 | +import javax.sip.header.Header; | |
| 46 | 48 | import javax.sip.message.Request; |
| 47 | 49 | import javax.sip.message.Response; |
| 48 | 50 | import java.text.ParseException; |
| ... | ... | @@ -114,7 +116,9 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 114 | 116 | try { |
| 115 | 117 | Request request = evt.getRequest(); |
| 116 | 118 | SipURI sipURI = (SipURI) request.getRequestURI(); |
| 117 | - String channelId = sipURI.getUser(); | |
| 119 | + //从subject读取channelId,不再从request-line读取。 有些平台request-line是平台国标编码,不是设备国标编码。 | |
| 120 | + //String channelId = sipURI.getUser(); | |
| 121 | + String channelId = SipUtils.getChannelIdFromHeader(request); | |
| 118 | 122 | String requesterId = SipUtils.getUserIdFromFromHeader(request); |
| 119 | 123 | CallIdHeader callIdHeader = (CallIdHeader)request.getHeader(CallIdHeader.NAME); |
| 120 | 124 | if (requesterId == null || channelId == null) { | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/CatalogNotifyMessageHandler.java
| ... | ... | @@ -86,7 +86,7 @@ public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent imple |
| 86 | 86 | deviceChannel.setParental(1); |
| 87 | 87 | deviceChannel.setParentId(catalog.getParentId()); |
| 88 | 88 | deviceChannel.setRegisterWay(1); |
| 89 | - deviceChannel.setCivilCode(config.getDomain().substring(0, config.getDomain().length() - 2)); | |
| 89 | + deviceChannel.setCivilCode(parentPlatform.getDeviceGBId().substring(0,6)); | |
| 90 | 90 | deviceChannel.setModel("live"); |
| 91 | 91 | deviceChannel.setOwner("wvp-pro"); |
| 92 | 92 | deviceChannel.setSecrecy("0"); |
| ... | ... | @@ -125,7 +125,7 @@ public class CatalogNotifyMessageHandler extends SIPRequestProcessorParent imple |
| 125 | 125 | deviceChannel.setStatus(gbStream.isStatus()?1:0); |
| 126 | 126 | deviceChannel.setParentId(gbStream.getCatalogId()); |
| 127 | 127 | deviceChannel.setRegisterWay(1); |
| 128 | - deviceChannel.setCivilCode(config.getDomain().substring(0, config.getDomain().length() - 2)); | |
| 128 | + deviceChannel.setCivilCode(parentPlatform.getDeviceGBId().substring(0,6)); | |
| 129 | 129 | deviceChannel.setModel("live"); |
| 130 | 130 | deviceChannel.setOwner("wvp-pro"); |
| 131 | 131 | deviceChannel.setParental(0); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/query/cmd/CatalogQueryMessageHandler.java
| ... | ... | @@ -89,7 +89,7 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem |
| 89 | 89 | deviceChannel.setParental(1); |
| 90 | 90 | deviceChannel.setParentId(catalog.getParentId()); |
| 91 | 91 | deviceChannel.setRegisterWay(1); |
| 92 | - deviceChannel.setCivilCode(config.getDomain().substring(0, config.getDomain().length() - 2)); | |
| 92 | + deviceChannel.setCivilCode(parentPlatform.getDeviceGBId().substring(0,6)); | |
| 93 | 93 | deviceChannel.setModel("live"); |
| 94 | 94 | deviceChannel.setOwner("wvp-pro"); |
| 95 | 95 | deviceChannel.setSecrecy("0"); |
| ... | ... | @@ -128,7 +128,7 @@ public class CatalogQueryMessageHandler extends SIPRequestProcessorParent implem |
| 128 | 128 | deviceChannel.setStatus(gbStream.isStatus()?1:0); |
| 129 | 129 | deviceChannel.setParentId(gbStream.getCatalogId()); |
| 130 | 130 | deviceChannel.setRegisterWay(1); |
| 131 | - deviceChannel.setCivilCode(config.getDomain().substring(0, config.getDomain().length() - 2)); | |
| 131 | + deviceChannel.setCivilCode(parentPlatform.getDeviceGBId().substring(0,6)); | |
| 132 | 132 | deviceChannel.setModel("live"); |
| 133 | 133 | deviceChannel.setOwner("wvp-pro"); |
| 134 | 134 | deviceChannel.setParental(0); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/response/cmd/CatalogResponseMessageHandler.java
| ... | ... | @@ -2,9 +2,8 @@ package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.respon |
| 2 | 2 | |
| 3 | 3 | import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| 4 | 4 | import com.genersoft.iot.vmp.conf.SipConfig; |
| 5 | -import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 6 | -import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel; | |
| 7 | -import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | |
| 5 | +import com.genersoft.iot.vmp.conf.UserSetup; | |
| 6 | +import com.genersoft.iot.vmp.gb28181.bean.*; | |
| 8 | 7 | import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; |
| 9 | 8 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 10 | 9 | import com.genersoft.iot.vmp.gb28181.session.CatalogDataCatch; |
| ... | ... | @@ -15,7 +14,9 @@ import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.IMessag |
| 15 | 14 | import com.genersoft.iot.vmp.gb28181.transmit.event.request.impl.message.response.ResponseMessageHandler; |
| 16 | 15 | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; |
| 17 | 16 | import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; |
| 17 | +import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | |
| 18 | 18 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 19 | +import com.genersoft.iot.vmp.utils.GpsUtil; | |
| 19 | 20 | import com.genersoft.iot.vmp.vmanager.bean.WVPResult; |
| 20 | 21 | import org.dom4j.DocumentException; |
| 21 | 22 | import org.dom4j.Element; |
| ... | ... | @@ -24,6 +25,7 @@ import org.slf4j.LoggerFactory; |
| 24 | 25 | import org.springframework.beans.factory.InitializingBean; |
| 25 | 26 | import org.springframework.beans.factory.annotation.Autowired; |
| 26 | 27 | import org.springframework.stereotype.Component; |
| 28 | +import org.springframework.util.StringUtils; | |
| 27 | 29 | |
| 28 | 30 | import javax.sip.InvalidArgumentException; |
| 29 | 31 | import javax.sip.RequestEvent; |
| ... | ... | @@ -67,6 +69,13 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp |
| 67 | 69 | @Autowired |
| 68 | 70 | private EventPublisher publisher; |
| 69 | 71 | |
| 72 | + //by brewswang | |
| 73 | + @Autowired | |
| 74 | + private UserSetup userSetup; | |
| 75 | + | |
| 76 | + @Autowired | |
| 77 | + private IRedisCatchStorage redisCatchStorage; | |
| 78 | + | |
| 70 | 79 | @Override |
| 71 | 80 | public void afterPropertiesSet() throws Exception { |
| 72 | 81 | responseMessageHandler.addHandler(cmdType, this); |
| ... | ... | @@ -108,6 +117,11 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp |
| 108 | 117 | if (channelDeviceElement == null) { |
| 109 | 118 | continue; |
| 110 | 119 | } |
| 120 | + //by brewswang | |
| 121 | + if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Longitude"))) {//如果包含位置信息,就更新一下位置 | |
| 122 | + processNotifyMobilePosition(evt, itemDevice); | |
| 123 | + } | |
| 124 | + | |
| 111 | 125 | DeviceChannel deviceChannel = XmlUtil.channelContentHander(itemDevice); |
| 112 | 126 | deviceChannel.setDeviceId(device.getDeviceId()); |
| 113 | 127 | logger.debug("收到来自设备【{}】的通道: {}【{}】", device.getDeviceId(), deviceChannel.getName(), deviceChannel.getChannelId()); |
| ... | ... | @@ -154,4 +168,69 @@ public class CatalogResponseMessageHandler extends SIPRequestProcessorParent imp |
| 154 | 168 | public void handForPlatform(RequestEvent evt, ParentPlatform parentPlatform, Element rootElement) { |
| 155 | 169 | |
| 156 | 170 | } |
| 171 | + | |
| 172 | + /** | |
| 173 | + * 处理设备位置的更新 | |
| 174 | + * | |
| 175 | + * @param evt, itemDevice | |
| 176 | + */ | |
| 177 | + private void processNotifyMobilePosition(RequestEvent evt, Element itemDevice) { | |
| 178 | + try { | |
| 179 | + // 回复 200 OK | |
| 180 | + Element rootElement = getRootElement(evt); | |
| 181 | + MobilePosition mobilePosition = new MobilePosition(); | |
| 182 | + Element deviceIdElement = rootElement.element("DeviceID"); | |
| 183 | + String deviceId = deviceIdElement.getTextTrim().toString(); | |
| 184 | + Device device = redisCatchStorage.getDevice(deviceId); | |
| 185 | + if (device != null) { | |
| 186 | + if (!StringUtils.isEmpty(device.getName())) { | |
| 187 | + mobilePosition.setDeviceName(device.getName()); | |
| 188 | + } | |
| 189 | + } | |
| 190 | + mobilePosition.setDeviceId(XmlUtil.getText(rootElement, "DeviceID")); | |
| 191 | + | |
| 192 | + String time = XmlUtil.getText(itemDevice, "Time"); | |
| 193 | + if(time==null){ | |
| 194 | + time = XmlUtil.getText(itemDevice, "EndTime"); | |
| 195 | + } | |
| 196 | + mobilePosition.setTime(time); | |
| 197 | + String longitude = XmlUtil.getText(itemDevice, "Longitude"); | |
| 198 | + if(longitude!=null) { | |
| 199 | + mobilePosition.setLongitude(Double.parseDouble(longitude)); | |
| 200 | + } | |
| 201 | + String latitude = XmlUtil.getText(itemDevice, "Latitude"); | |
| 202 | + if(latitude!=null) { | |
| 203 | + mobilePosition.setLatitude(Double.parseDouble(latitude)); | |
| 204 | + } | |
| 205 | + if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Speed"))) { | |
| 206 | + mobilePosition.setSpeed(Double.parseDouble(XmlUtil.getText(itemDevice, "Speed"))); | |
| 207 | + } else { | |
| 208 | + mobilePosition.setSpeed(0.0); | |
| 209 | + } | |
| 210 | + if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Direction"))) { | |
| 211 | + mobilePosition.setDirection(Double.parseDouble(XmlUtil.getText(itemDevice, "Direction"))); | |
| 212 | + } else { | |
| 213 | + mobilePosition.setDirection(0.0); | |
| 214 | + } | |
| 215 | + if (NumericUtil.isDouble(XmlUtil.getText(itemDevice, "Altitude"))) { | |
| 216 | + mobilePosition.setAltitude(Double.parseDouble(XmlUtil.getText(itemDevice, "Altitude"))); | |
| 217 | + } else { | |
| 218 | + mobilePosition.setAltitude(0.0); | |
| 219 | + } | |
| 220 | + mobilePosition.setReportSource("Mobile Position"); | |
| 221 | + BaiduPoint bp = new BaiduPoint(); | |
| 222 | + bp = GpsUtil.Wgs84ToBd09(String.valueOf(mobilePosition.getLongitude()), String.valueOf(mobilePosition.getLatitude())); | |
| 223 | + logger.info("百度坐标:" + bp.getBdLng() + ", " + bp.getBdLat()); | |
| 224 | + mobilePosition.setGeodeticSystem("BD-09"); | |
| 225 | + mobilePosition.setCnLng(bp.getBdLng()); | |
| 226 | + mobilePosition.setCnLat(bp.getBdLat()); | |
| 227 | + if (!userSetup.getSavePositionHistory()) { | |
| 228 | + storager.clearMobilePositionsByDeviceId(deviceId); | |
| 229 | + } | |
| 230 | + storager.insertMobilePosition(mobilePosition); | |
| 231 | + responseAck(evt, Response.OK); | |
| 232 | + } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) { | |
| 233 | + e.printStackTrace(); | |
| 234 | + } | |
| 235 | + } | |
| 157 | 236 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/utils/SipUtils.java
| ... | ... | @@ -2,8 +2,10 @@ package com.genersoft.iot.vmp.gb28181.utils; |
| 2 | 2 | |
| 3 | 3 | import gov.nist.javax.sip.address.AddressImpl; |
| 4 | 4 | import gov.nist.javax.sip.address.SipUri; |
| 5 | +import gov.nist.javax.sip.header.Subject; | |
| 5 | 6 | |
| 6 | 7 | import javax.sip.header.FromHeader; |
| 8 | +import javax.sip.header.Header; | |
| 7 | 9 | import javax.sip.message.Request; |
| 8 | 10 | |
| 9 | 11 | /** |
| ... | ... | @@ -18,6 +20,13 @@ public class SipUtils { |
| 18 | 20 | FromHeader fromHeader = (FromHeader)request.getHeader(FromHeader.NAME); |
| 19 | 21 | return getUserIdFromFromHeader(fromHeader); |
| 20 | 22 | } |
| 23 | + /** | |
| 24 | + * 从subject读取channelId | |
| 25 | + * */ | |
| 26 | + public static String getChannelIdFromHeader(Request request) { | |
| 27 | + Header subject = request.getHeader("subject"); | |
| 28 | + return ((Subject) subject).getSubject().split(":")[0]; | |
| 29 | + } | |
| 21 | 30 | |
| 22 | 31 | public static String getUserIdFromFromHeader(FromHeader fromHeader) { |
| 23 | 32 | AddressImpl address = (AddressImpl)fromHeader.getAddress(); | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/GbStreamServiceImpl.java
| ... | ... | @@ -103,7 +103,7 @@ public class GbStreamServiceImpl implements IGbStreamService { |
| 103 | 103 | deviceChannel.setStatus(gbStream.isStatus()?1:0); |
| 104 | 104 | deviceChannel.setParentId(catalogId ==null?gbStream.getCatalogId():catalogId); |
| 105 | 105 | deviceChannel.setRegisterWay(1); |
| 106 | - deviceChannel.setCivilCode(sipConfig.getDomain().substring(0, sipConfig.getDomain().length() - 2)); | |
| 106 | + deviceChannel.setCivilCode(deviceGBId.substring(0, 6)); | |
| 107 | 107 | deviceChannel.setModel("live"); |
| 108 | 108 | deviceChannel.setOwner("wvp-pro"); |
| 109 | 109 | deviceChannel.setParental(0); | ... | ... |
src/main/java/com/genersoft/iot/vmp/storager/impl/VideoManagerStoragerImpl.java
| ... | ... | @@ -1083,7 +1083,7 @@ public class VideoManagerStoragerImpl implements IVideoManagerStorager { |
| 1083 | 1083 | deviceChannel.setParentId(catalog.getParentId()); |
| 1084 | 1084 | deviceChannel.setRegisterWay(1); |
| 1085 | 1085 | // 行政区划应该是Domain的前八位 |
| 1086 | - deviceChannel.setCivilCode(sipConfig.getDomain().substring(0, sipConfig.getDomain().length() - 2)); | |
| 1086 | + deviceChannel.setCivilCode(parentPlatByServerGBId.getDeviceGBId().substring(0,6)); | |
| 1087 | 1087 | deviceChannel.setModel("live"); |
| 1088 | 1088 | deviceChannel.setOwner("wvp-pro"); |
| 1089 | 1089 | deviceChannel.setSecrecy("0"); | ... | ... |