Commit 18c3b5931872fe1399440a89e1c17562b16b997c

Authored by lawrencehj
1 parent 693aac28

增加多种信令的支持

src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/DeferredResultHolder.java
... ... @@ -17,8 +17,16 @@ import org.springframework.web.context.request.async.DeferredResult;
17 17 @Component
18 18 public class DeferredResultHolder {
19 19  
  20 + public static final String CALLBACK_CMD_DEVICESTATUS = "CALLBACK_DEVICESTATUS";
  21 +
20 22 public static final String CALLBACK_CMD_DEVICEINFO = "CALLBACK_DEVICEINFO";
21 23  
  24 + public static final String CALLBACK_CMD_DEVICECONTROL = "CALLBACK_DEVICECONTROL";
  25 +
  26 + public static final String CALLBACK_CMD_DEVICECONFIG = "CALLBACK_DEVICECONFIG";
  27 +
  28 + public static final String CALLBACK_CMD_CONFIGDOWNLOAD = "CALLBACK_CONFIGDOWNLOAD";
  29 +
22 30 public static final String CALLBACK_CMD_CATALOG = "CALLBACK_CATALOG";
23 31  
24 32 public static final String CALLBACK_CMD_RECORDINFO = "CALLBACK_RECORDINFO";
... ... @@ -29,6 +37,10 @@ public class DeferredResultHolder {
29 37  
30 38 public static final String CALLBACK_CMD_MOBILEPOSITION = "CALLBACK_MOBILEPOSITION";
31 39  
  40 + public static final String CALLBACK_CMD_PRESETQUERY = "CALLBACK_PRESETQUERY";
  41 +
  42 + public static final String CALLBACK_CMD_ALARM = "CALLBACK_ALARM";
  43 +
32 44 private Map<String, DeferredResult> map = new ConcurrentHashMap<String, DeferredResult>();
33 45  
34 46 public void put(String key, DeferredResult result) {
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java
... ... @@ -115,24 +115,35 @@ public interface ISIPCommander {
115 115 /**
116 116 * 音视频录像控制
117 117 *
118   - * @param device 视频设备
119   - * @param channelId 预览通道
  118 + * @param device 视频设备
  119 + * @param channelId 预览通道
  120 + * @param recordCmdStr 录像命令:Record / StopRecord
120 121 */
121   - boolean recordCmd(Device device,String channelId);
  122 + boolean recordCmd(Device device, String channelId, String recordCmdStr, SipSubscribe.Event errorEvent);
122 123  
123 124 /**
  125 + * 远程启动控制命令
  126 + *
  127 + * @param device 视频设备
  128 + */
  129 + boolean teleBootCmd(Device device);
  130 +
  131 + /**
124 132 * 报警布防/撤防命令
125 133 *
126   - * @param device 视频设备
  134 + * @param device 视频设备
  135 + * @param setGuard true: SetGuard, false: ResetGuard
127 136 */
128   - boolean guardCmd(Device device);
  137 + boolean guardCmd(Device device, String guardCmdStr, SipSubscribe.Event errorEvent);
129 138  
130 139 /**
131 140 * 报警复位命令
132 141 *
133   - * @param device 视频设备
  142 + * @param device 视频设备
  143 + * @param alarmMethod 报警方式(可选)
  144 + * @param alarmType 报警类型(可选)
134 145 */
135   - boolean alarmCmd(Device device);
  146 + boolean alarmCmd(Device device, String alarmMethod, String alarmType, SipSubscribe.Event errorEvent);
136 147  
137 148 /**
138 149 * 强制关键帧命令,设备收到此命令应立刻发送一个IDR帧
... ... @@ -140,14 +151,17 @@ public interface ISIPCommander {
140 151 * @param device 视频设备
141 152 * @param channelId 预览通道
142 153 */
143   - boolean iFameCmd(Device device,String channelId);
  154 + boolean iFrameCmd(Device device, String channelId);
144 155  
145 156 /**
146 157 * 看守位控制命令
147 158 *
148   - * @param device 视频设备
  159 + * @param device 视频设备
  160 + * @param enabled 看守位使能:1 = 开启,0 = 关闭
  161 + * @param resetTime 自动归位时间间隔,开启看守位时使用,单位:秒(s)
  162 + * @param presetIndex 调用预置位编号,开启看守位时使用,取值范围0~255
149 163 */
150   - boolean homePositionCmd(Device device);
  164 + boolean homePositionCmd(Device device, String channelId, String enabled, String resetTime, String presetIndex, SipSubscribe.Event errorEvent);
151 165  
152 166 /**
153 167 * 设备配置命令
... ... @@ -156,13 +170,24 @@ public interface ISIPCommander {
156 170 */
157 171 boolean deviceConfigCmd(Device device);
158 172  
  173 + /**
  174 + * 设备配置命令:basicParam
  175 + *
  176 + * @param device 视频设备
  177 + * @param channelId 通道编码(可选)
  178 + * @param name 设备/通道名称(可选)
  179 + * @param expiration 注册过期时间(可选)
  180 + * @param heartBeatInterval 心跳间隔时间(可选)
  181 + * @param heartBeatCount 心跳超时次数(可选)
  182 + */
  183 + boolean deviceBasicConfigCmd(Device device, String channelId, String name, String expiration, String heartBeatInterval, String heartBeatCount, SipSubscribe.Event errorEvent);
159 184  
160 185 /**
161 186 * 查询设备状态
162 187 *
163 188 * @param device 视频设备
164 189 */
165   - boolean deviceStatusQuery(Device device);
  190 + boolean deviceStatusQuery(Device device, SipSubscribe.Event errorEvent);
166 191  
167 192 /**
168 193 * 查询设备信息
... ... @@ -191,23 +216,33 @@ public interface ISIPCommander {
191 216 /**
192 217 * 查询报警信息
193 218 *
194   - * @param device 视频设备
  219 + * @param device 视频设备
  220 + * @param startPriority 报警起始级别(可选)
  221 + * @param endPriority 报警终止级别(可选)
  222 + * @param alarmMethod 报警方式条件(可选)
  223 + * @param alarmType 报警类型
  224 + * @param startTime 报警发生起始时间(可选)
  225 + * @param endTime 报警发生终止时间(可选)
  226 + * @return true = 命令发送成功
195 227 */
196   - boolean alarmInfoQuery(Device device);
  228 + boolean alarmInfoQuery(Device device, String startPriority, String endPriority, String alarmMethod,
  229 + String alarmType, String startTime, String endTime, SipSubscribe.Event errorEvent);
197 230  
198 231 /**
199 232 * 查询设备配置
200 233 *
201   - * @param device 视频设备
  234 + * @param device 视频设备
  235 + * @param channelId 通道编码(可选)
  236 + * @param configType 配置类型:
202 237 */
203   - boolean configQuery(Device device);
  238 + boolean deviceConfigQuery(Device device, String channelId, String configType, SipSubscribe.Event errorEvent);
204 239  
205 240 /**
206 241 * 查询设备预置位置
207 242 *
208 243 * @param device 视频设备
209 244 */
210   - boolean presetQuery(Device device);
  245 + boolean presetQuery(Device device, String channelId, SipSubscribe.Event errorEvent);
211 246  
212 247 /**
213 248 * 查询移动设备位置数据
... ... @@ -222,10 +257,26 @@ public interface ISIPCommander {
222 257 * @param device 视频设备
223 258 * @param expires 订阅超时时间(值=0时为取消订阅)
224 259 * @param interval 上报时间间隔
  260 + * @return true = 命令发送成功
225 261 */
226 262 boolean mobilePositionSubscribe(Device device, int expires, int interval);
227 263  
228 264 /**
  265 + * 订阅、取消订阅报警信息
  266 + * @param device 视频设备
  267 + * @param expires 订阅过期时间(0 = 取消订阅)
  268 + * @param startPriority 报警起始级别(可选)
  269 + * @param endPriority 报警终止级别(可选)
  270 + * @param alarmMethods 报警方式条件(可选)
  271 + * @param alarmType 报警类型
  272 + * @param startTime 报警发生起始时间(可选)
  273 + * @param endTime 报警发生终止时间(可选)
  274 + * @return true = 命令发送成功
  275 + */
  276 + boolean alarmSubscribe(Device device, int expires, String startPriority, String endPriority, String alarmMethod, String alarmType, String startTime, String endTime);
  277 +
  278 +
  279 + /**
229 280 * 释放rtpserver
230 281 * @param device
231 282 * @param channelId
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java
... ... @@ -34,6 +34,8 @@ import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
34 34 import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
35 35 import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider;
36 36 import com.genersoft.iot.vmp.gb28181.utils.DateUtil;
  37 +import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
  38 +import com.genersoft.iot.vmp.gb28181.utils.XmlUtil;
37 39  
38 40 /**
39 41 * @Description:设备能力接口,用于定义设备的控制、查询能力
... ... @@ -577,24 +579,89 @@ public class SIPCommander implements ISIPCommander {
577 579 /**
578 580 * 音视频录像控制
579 581 *
580   - * @param device 视频设备
581   - * @param channelId 预览通道
  582 + * @param device 视频设备
  583 + * @param channelId 预览通道
  584 + * @param recordCmdStr 录像命令:Record / StopRecord
582 585 */
583 586 @Override
584   - public boolean recordCmd(Device device, String channelId) {
585   - // TODO Auto-generated method stub
586   - return false;
  587 + public boolean recordCmd(Device device, String channelId, String recordCmdStr, SipSubscribe.Event errorEvent) {
  588 + try {
  589 + StringBuffer cmdXml = new StringBuffer(200);
  590 + cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
  591 + cmdXml.append("<Control>\r\n");
  592 + cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
  593 + cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
  594 + if (XmlUtil.isEmpty(channelId)) {
  595 + cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
  596 + } else {
  597 + cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
  598 + }
  599 + cmdXml.append("<RecordCmd>" + recordCmdStr + "</RecordCmd>\r\n");
  600 + cmdXml.append("</Control>\r\n");
  601 +
  602 + String tm = Long.toString(System.currentTimeMillis());
  603 + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromRecord" + tm, null);
  604 + transmitRequest(device, request, errorEvent);
  605 + return true;
  606 + } catch (SipException | ParseException | InvalidArgumentException e) {
  607 + e.printStackTrace();
  608 + return false;
  609 + }
587 610 }
588 611  
589 612 /**
  613 + * 远程启动控制命令
  614 + *
  615 + * @param device 视频设备
  616 + */
  617 + @Override
  618 + public boolean teleBootCmd(Device device) {
  619 + try {
  620 + StringBuffer cmdXml = new StringBuffer(200);
  621 + cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
  622 + cmdXml.append("<Control>\r\n");
  623 + cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
  624 + cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
  625 + cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
  626 + cmdXml.append("<TeleBoot>Boot</TeleBoot>\r\n");
  627 + cmdXml.append("</Control>\r\n");
  628 +
  629 + String tm = Long.toString(System.currentTimeMillis());
  630 + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromBoot" + tm, null);
  631 + transmitRequest(device, request);
  632 + return true;
  633 + } catch (SipException | ParseException | InvalidArgumentException e) {
  634 + e.printStackTrace();
  635 + return false;
  636 + }
  637 + }
  638 +
  639 + /**
590 640 * 报警布防/撤防命令
591 641 *
592   - * @param device 视频设备
593   - */
  642 + * @param device 视频设备
  643 + * @param guardCmdStr "SetGuard"/"ResetGuard"
  644 + */
594 645 @Override
595   - public boolean guardCmd(Device device) {
596   - // TODO Auto-generated method stub
597   - return false;
  646 + public boolean guardCmd(Device device, String guardCmdStr, SipSubscribe.Event errorEvent) {
  647 + try {
  648 + StringBuffer cmdXml = new StringBuffer(200);
  649 + cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
  650 + cmdXml.append("<Control>\r\n");
  651 + cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
  652 + cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
  653 + cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
  654 + cmdXml.append("<GuardCmd>" + guardCmdStr + "</GuardCmd>\r\n");
  655 + cmdXml.append("</Control>\r\n");
  656 +
  657 + String tm = Long.toString(System.currentTimeMillis());
  658 + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromGuard" + tm, null);
  659 + transmitRequest(device, request, errorEvent);
  660 + return true;
  661 + } catch (SipException | ParseException | InvalidArgumentException e) {
  662 + e.printStackTrace();
  663 + return false;
  664 + }
598 665 }
599 666  
600 667 /**
... ... @@ -603,9 +670,37 @@ public class SIPCommander implements ISIPCommander {
603 670 * @param device 视频设备
604 671 */
605 672 @Override
606   - public boolean alarmCmd(Device device) {
607   - // TODO Auto-generated method stub
608   - return false;
  673 + public boolean alarmCmd(Device device, String alarmMethod, String alarmType, SipSubscribe.Event errorEvent) {
  674 + try {
  675 + StringBuffer cmdXml = new StringBuffer(200);
  676 + cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
  677 + cmdXml.append("<Control>\r\n");
  678 + cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
  679 + cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
  680 + cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
  681 + cmdXml.append("<AlarmCmd>ResetAlarm</AlarmCmd>\r\n");
  682 + if (!XmlUtil.isEmpty(alarmMethod) || !XmlUtil.isEmpty(alarmType)) {
  683 + cmdXml.append("<Info>\r\n");
  684 + }
  685 + if (!XmlUtil.isEmpty(alarmMethod)) {
  686 + cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
  687 + }
  688 + if (!XmlUtil.isEmpty(alarmType)) {
  689 + cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
  690 + }
  691 + if (!XmlUtil.isEmpty(alarmMethod) || !XmlUtil.isEmpty(alarmType)) {
  692 + cmdXml.append("</Info>\r\n");
  693 + }
  694 + cmdXml.append("</Control>\r\n");
  695 +
  696 + String tm = Long.toString(System.currentTimeMillis());
  697 + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromAlarm" + tm, null);
  698 + transmitRequest(device, request, errorEvent);
  699 + return true;
  700 + } catch (SipException | ParseException | InvalidArgumentException e) {
  701 + e.printStackTrace();
  702 + return false;
  703 + }
609 704 }
610 705  
611 706 /**
... ... @@ -615,20 +710,79 @@ public class SIPCommander implements ISIPCommander {
615 710 * @param channelId 预览通道
616 711 */
617 712 @Override
618   - public boolean iFameCmd(Device device, String channelId) {
619   - // TODO Auto-generated method stub
620   - return false;
  713 + public boolean iFrameCmd(Device device, String channelId) {
  714 + try {
  715 + StringBuffer cmdXml = new StringBuffer(200);
  716 + cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
  717 + cmdXml.append("<Control>\r\n");
  718 + cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
  719 + cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
  720 + if (XmlUtil.isEmpty(channelId)) {
  721 + cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
  722 + } else {
  723 + cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
  724 + }
  725 + cmdXml.append("<IFameCmd>Send</IFameCmd>\r\n");
  726 + cmdXml.append("</Control>\r\n");
  727 +
  728 + String tm = Long.toString(System.currentTimeMillis());
  729 + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromBoot" + tm, null);
  730 + transmitRequest(device, request);
  731 + return true;
  732 + } catch (SipException | ParseException | InvalidArgumentException e) {
  733 + e.printStackTrace();
  734 + return false;
  735 + }
621 736 }
622 737  
623 738 /**
624 739 * 看守位控制命令
625 740 *
626   - * @param device 视频设备
  741 + * @param device 视频设备
  742 + * @param enabled 看守位使能:1 = 开启,0 = 关闭
  743 + * @param resetTime 自动归位时间间隔,开启看守位时使用,单位:秒(s)
  744 + * @param presetIndex 调用预置位编号,开启看守位时使用,取值范围0~255
627 745 */
628 746 @Override
629   - public boolean homePositionCmd(Device device) {
630   - // TODO Auto-generated method stub
631   - return false;
  747 + public boolean homePositionCmd(Device device, String channelId, String enabled, String resetTime, String presetIndex, SipSubscribe.Event errorEvent) {
  748 + try {
  749 + StringBuffer cmdXml = new StringBuffer(200);
  750 + cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
  751 + cmdXml.append("<Control>\r\n");
  752 + cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
  753 + cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
  754 + if (XmlUtil.isEmpty(channelId)) {
  755 + cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
  756 + } else {
  757 + cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
  758 + }
  759 + cmdXml.append("<HomePosition>\r\n");
  760 + if (NumericUtil.isInteger(enabled) && (!enabled.equals("0"))) {
  761 + cmdXml.append("<Enabled>1</Enabled>\r\n");
  762 + if (NumericUtil.isInteger(resetTime)) {
  763 + cmdXml.append("<ResetTime>" + resetTime + "</ResetTime>\r\n");
  764 + } else {
  765 + cmdXml.append("<ResetTime>0</ResetTime>\r\n");
  766 + }
  767 + if (NumericUtil.isInteger(presetIndex)) {
  768 + cmdXml.append("<PresetIndex>" + presetIndex + "</PresetIndex>\r\n");
  769 + } else {
  770 + cmdXml.append("<PresetIndex>0</PresetIndex>\r\n");
  771 + }
  772 + } else {
  773 + cmdXml.append("<Enabled>0</Enabled>\r\n");
  774 + }
  775 + cmdXml.append("</HomePosition>\r\n");
  776 + cmdXml.append("</Control>\r\n");
  777 +
  778 + String tm = Long.toString(System.currentTimeMillis());
  779 + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromGuard" + tm, null);
  780 + transmitRequest(device, request, errorEvent);
  781 + return true;
  782 + } catch (SipException | ParseException | InvalidArgumentException e) {
  783 + e.printStackTrace();
  784 + return false;
  785 + }
632 786 }
633 787  
634 788 /**
... ... @@ -643,14 +797,87 @@ public class SIPCommander implements ISIPCommander {
643 797 }
644 798  
645 799 /**
  800 + * 设备配置命令:basicParam
  801 + *
  802 + * @param device 视频设备
  803 + * @param channelId 通道编码(可选)
  804 + * @param name 设备/通道名称(可选)
  805 + * @param expiration 注册过期时间(可选)
  806 + * @param heartBeatInterval 心跳间隔时间(可选)
  807 + * @param heartBeatCount 心跳超时次数(可选)
  808 + */
  809 + @Override
  810 + public boolean deviceBasicConfigCmd(Device device, String channelId, String name, String expiration,
  811 + String heartBeatInterval, String heartBeatCount, SipSubscribe.Event errorEvent) {
  812 + try {
  813 + StringBuffer cmdXml = new StringBuffer(200);
  814 + cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
  815 + cmdXml.append("<Control>\r\n");
  816 + cmdXml.append("<CmdType>DeviceConfig</CmdType>\r\n");
  817 + cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
  818 + if (XmlUtil.isEmpty(channelId)) {
  819 + cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
  820 + } else {
  821 + cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
  822 + }
  823 + cmdXml.append("<BasicParam>\r\n");
  824 + if (!XmlUtil.isEmpty(name)) {
  825 + cmdXml.append("<Name>" + name + "</Name>\r\n");
  826 + }
  827 + if (NumericUtil.isInteger(expiration)) {
  828 + if (Integer.valueOf(expiration) > 0) {
  829 + cmdXml.append("<Expiration>" + expiration + "</Expiration>\r\n");
  830 + }
  831 + }
  832 + if (NumericUtil.isInteger(heartBeatInterval)) {
  833 + if (Integer.valueOf(heartBeatInterval) > 0) {
  834 + cmdXml.append("<HeartBeatInterval>" + heartBeatInterval + "</HeartBeatInterval>\r\n");
  835 + }
  836 + }
  837 + if (NumericUtil.isInteger(heartBeatCount)) {
  838 + if (Integer.valueOf(heartBeatCount) > 0) {
  839 + cmdXml.append("<HeartBeatCount>" + heartBeatCount + "</HeartBeatCount>\r\n");
  840 + }
  841 + }
  842 + cmdXml.append("</BasicParam>\r\n");
  843 + cmdXml.append("</Control>\r\n");
  844 +
  845 + String tm = Long.toString(System.currentTimeMillis());
  846 + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromConfig" + tm, null);
  847 + transmitRequest(device, request, errorEvent);
  848 + return true;
  849 + } catch (SipException | ParseException | InvalidArgumentException e) {
  850 + e.printStackTrace();
  851 + return false;
  852 + }
  853 + }
  854 +
  855 + /**
646 856 * 查询设备状态
647 857 *
648 858 * @param device 视频设备
649 859 */
650 860 @Override
651   - public boolean deviceStatusQuery(Device device) {
652   - // TODO Auto-generated method stub
653   - return false;
  861 + public boolean deviceStatusQuery(Device device, SipSubscribe.Event errorEvent) {
  862 + try {
  863 + StringBuffer catalogXml = new StringBuffer(200);
  864 + catalogXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
  865 + catalogXml.append("<Query>\r\n");
  866 + catalogXml.append("<CmdType>DeviceStatus</CmdType>\r\n");
  867 + catalogXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
  868 + catalogXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
  869 + catalogXml.append("</Query>\r\n");
  870 +
  871 + String tm = Long.toString(System.currentTimeMillis());
  872 + Request request = headerProvider.createMessageRequest(device, catalogXml.toString(), null, "FromStatus" + tm, null);
  873 +
  874 + transmitRequest(device, request, errorEvent);
  875 + return true;
  876 +
  877 + } catch (SipException | ParseException | InvalidArgumentException e) {
  878 + e.printStackTrace();
  879 + return false;
  880 + }
654 881 }
655 882  
656 883 /**
... ... @@ -748,23 +975,86 @@ public class SIPCommander implements ISIPCommander {
748 975 /**
749 976 * 查询报警信息
750 977 *
751   - * @param device 视频设备
752   - */
  978 + * @param device 视频设备
  979 + * @param startPriority 报警起始级别(可选)
  980 + * @param endPriority 报警终止级别(可选)
  981 + * @param alarmMethods 报警方式条件(可选)
  982 + * @param alarmType 报警类型
  983 + * @param startTime 报警发生起始时间(可选)
  984 + * @param endTime 报警发生终止时间(可选)
  985 + * @return true = 命令发送成功
  986 + */
753 987 @Override
754   - public boolean alarmInfoQuery(Device device) {
755   - // TODO Auto-generated method stub
756   - return false;
  988 + public boolean alarmInfoQuery(Device device, String startPriority, String endPriority, String alarmMethod, String alarmType,
  989 + String startTime, String endTime, SipSubscribe.Event errorEvent) {
  990 + try {
  991 + StringBuffer cmdXml = new StringBuffer(200);
  992 + cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
  993 + cmdXml.append("<Query>\r\n");
  994 + cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
  995 + cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
  996 + cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
  997 + if (!XmlUtil.isEmpty(startPriority)) {
  998 + cmdXml.append("<StartAlarmPriority>" + startPriority + "</StartAlarmPriority>\r\n");
  999 + }
  1000 + if (!XmlUtil.isEmpty(endPriority)) {
  1001 + cmdXml.append("<EndAlarmPriority>" + endPriority + "</EndAlarmPriority>\r\n");
  1002 + }
  1003 + if (!XmlUtil.isEmpty(alarmMethod)) {
  1004 + cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
  1005 + }
  1006 + if (!XmlUtil.isEmpty(alarmType)) {
  1007 + cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
  1008 + }
  1009 + if (!XmlUtil.isEmpty(startTime)) {
  1010 + cmdXml.append("<StartAlarmTime>" + startTime + "</StartAlarmTime>\r\n");
  1011 + }
  1012 + if (!XmlUtil.isEmpty(endTime)) {
  1013 + cmdXml.append("<EndAlarmTime>" + endTime + "</EndAlarmTime>\r\n");
  1014 + }
  1015 + cmdXml.append("</Query>\r\n");
  1016 +
  1017 + String tm = Long.toString(System.currentTimeMillis());
  1018 + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromAlarm" + tm, null);
  1019 + transmitRequest(device, request, errorEvent);
  1020 + return true;
  1021 + } catch (SipException | ParseException | InvalidArgumentException e) {
  1022 + e.printStackTrace();
  1023 + return false;
  1024 + }
757 1025 }
758 1026  
759 1027 /**
760 1028 * 查询设备配置
761 1029 *
762   - * @param device 视频设备
763   - */
  1030 + * @param device 视频设备
  1031 + * @param channelId 通道编码(可选)
  1032 + * @param configType 配置类型:
  1033 + */
764 1034 @Override
765   - public boolean configQuery(Device device) {
766   - // TODO Auto-generated method stub
767   - return false;
  1035 + public boolean deviceConfigQuery(Device device, String channelId, String configType, SipSubscribe.Event errorEvent) {
  1036 + try {
  1037 + StringBuffer cmdXml = new StringBuffer(200);
  1038 + cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
  1039 + cmdXml.append("<Query>\r\n");
  1040 + cmdXml.append("<CmdType>ConfigDownload</CmdType>\r\n");
  1041 + cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
  1042 + if (XmlUtil.isEmpty(channelId)) {
  1043 + cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
  1044 + } else {
  1045 + cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
  1046 + }
  1047 + cmdXml.append("<ConfigType>" + configType + "</ConfigType>\r\n");
  1048 + cmdXml.append("</Query>\r\n");
  1049 +
  1050 + String tm = Long.toString(System.currentTimeMillis());
  1051 + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromConfig" + tm, null);
  1052 + transmitRequest(device, request, errorEvent);
  1053 + return true;
  1054 + } catch (SipException | ParseException | InvalidArgumentException e) {
  1055 + e.printStackTrace();
  1056 + return false;
  1057 + }
768 1058 }
769 1059  
770 1060 /**
... ... @@ -773,9 +1063,28 @@ public class SIPCommander implements ISIPCommander {
773 1063 * @param device 视频设备
774 1064 */
775 1065 @Override
776   - public boolean presetQuery(Device device) {
777   - // TODO Auto-generated method stub
778   - return false;
  1066 + public boolean presetQuery(Device device, String channelId, SipSubscribe.Event errorEvent) {
  1067 + try {
  1068 + StringBuffer cmdXml = new StringBuffer(200);
  1069 + cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
  1070 + cmdXml.append("<Query>\r\n");
  1071 + cmdXml.append("<CmdType>PresetQuery</CmdType>\r\n");
  1072 + cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
  1073 + if (XmlUtil.isEmpty(channelId)) {
  1074 + cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
  1075 + } else {
  1076 + cmdXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
  1077 + }
  1078 + cmdXml.append("</Query>\r\n");
  1079 +
  1080 + String tm = Long.toString(System.currentTimeMillis());
  1081 + Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, "FromConfig" + tm, null);
  1082 + transmitRequest(device, request, errorEvent);
  1083 + return true;
  1084 + } catch (SipException | ParseException | InvalidArgumentException e) {
  1085 + e.printStackTrace();
  1086 + return false;
  1087 + }
779 1088 }
780 1089  
781 1090 /**
... ... @@ -813,6 +1122,7 @@ public class SIPCommander implements ISIPCommander {
813 1122 * @param device 视频设备
814 1123 * @param expires 订阅超时时间
815 1124 * @param interval 上报时间间隔
  1125 + * @return true = 命令发送成功
816 1126 */
817 1127 public boolean mobilePositionSubscribe(Device device, int expires, int interval) {
818 1128 try {
... ... @@ -828,7 +1138,60 @@ public class SIPCommander implements ISIPCommander {
828 1138 subscribePostitionXml.append("</Query>\r\n");
829 1139  
830 1140 String tm = Long.toString(System.currentTimeMillis());
831   - Request request = headerProvider.createSubscribeRequest(device, subscribePostitionXml.toString(), "viaTagPos" + tm, "fromTagPos" + tm, null, expires, "Position;id=" + tm.substring(tm.length() - 4));
  1141 + Request request = headerProvider.createSubscribeRequest(device, subscribePostitionXml.toString(), "viaTagPos" + tm, "fromTagPos" + tm, null, expires, "presence" ); //Position;id=" + tm.substring(tm.length() - 4));
  1142 + transmitRequest(device, request);
  1143 +
  1144 + return true;
  1145 +
  1146 + } catch ( NumberFormatException | ParseException | InvalidArgumentException | SipException e) {
  1147 + e.printStackTrace();
  1148 + return false;
  1149 + }
  1150 + }
  1151 +
  1152 + /**
  1153 + * 订阅、取消订阅报警信息
  1154 + *
  1155 + * @param device 视频设备
  1156 + * @param expires 订阅过期时间(0 = 取消订阅)
  1157 + * @param startPriority 报警起始级别(可选)
  1158 + * @param endPriority 报警终止级别(可选)
  1159 + * @param alarmMethod 报警方式条件(可选)
  1160 + * @param alarmType 报警类型
  1161 + * @param startTime 报警发生起始时间(可选)
  1162 + * @param endTime 报警发生终止时间(可选)
  1163 + * @return true = 命令发送成功
  1164 + */
  1165 + public boolean alarmSubscribe(Device device, int expires, String startPriority, String endPriority, String alarmMethod, String alarmType, String startTime, String endTime) {
  1166 + try {
  1167 + StringBuffer cmdXml = new StringBuffer(200);
  1168 + cmdXml.append("<?xml version=\"1.0\" encoding=\"GB2312\"?>\r\n");
  1169 + cmdXml.append("<Query>\r\n");
  1170 + cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
  1171 + cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
  1172 + cmdXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
  1173 + if (!XmlUtil.isEmpty(startPriority)) {
  1174 + cmdXml.append("<StartAlarmPriority>" + startPriority + "</StartAlarmPriority>\r\n");
  1175 + }
  1176 + if (!XmlUtil.isEmpty(endPriority)) {
  1177 + cmdXml.append("<EndAlarmPriority>" + endPriority + "</EndAlarmPriority>\r\n");
  1178 + }
  1179 + if (!XmlUtil.isEmpty(alarmMethod)) {
  1180 + cmdXml.append("<AlarmMethod>" + alarmMethod + "</AlarmMethod>\r\n");
  1181 + }
  1182 + if (!XmlUtil.isEmpty(alarmType)) {
  1183 + cmdXml.append("<AlarmType>" + alarmType + "</AlarmType>\r\n");
  1184 + }
  1185 + if (!XmlUtil.isEmpty(startTime)) {
  1186 + cmdXml.append("<StartAlarmTime>" + startTime + "</StartAlarmTime>\r\n");
  1187 + }
  1188 + if (!XmlUtil.isEmpty(endTime)) {
  1189 + cmdXml.append("<EndAlarmTime>" + endTime + "</EndAlarmTime>\r\n");
  1190 + }
  1191 + cmdXml.append("</Query>\r\n");
  1192 +
  1193 + String tm = Long.toString(System.currentTimeMillis());
  1194 + Request request = headerProvider.createSubscribeRequest(device, cmdXml.toString(), "viaTagPos" + tm, "fromTagPos" + tm, null, expires, "presence" );
832 1195 transmitRequest(device, request);
833 1196  
834 1197 return true;
... ...
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/MessageRequestProcessor.java
... ... @@ -10,6 +10,7 @@ import javax.sip.SipException;
10 10 import javax.sip.message.Request;
11 11 import javax.sip.message.Response;
12 12  
  13 +import com.alibaba.fastjson.JSONObject;
13 14 import com.genersoft.iot.vmp.common.StreamInfo;
14 15 import com.genersoft.iot.vmp.common.VideoManagerConstants;
15 16 import com.genersoft.iot.vmp.conf.UserSetup;
... ... @@ -78,9 +79,12 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
78 79 private static final String MESSAGE_RECORD_INFO = "RecordInfo";
79 80 private static final String MESSAGE_MEDIA_STATUS = "MediaStatus";
80 81 // private static final String MESSAGE_BROADCAST = "Broadcast";
81   - // private static final String MESSAGE_DEVICE_STATUS = "DeviceStatus";
  82 + private static final String MESSAGE_DEVICE_STATUS = "DeviceStatus";
  83 + private static final String MESSAGE_DEVICE_CONTROL = "DeviceControl";
  84 + private static final String MESSAGE_DEVICE_CONFIG = "DeviceConfig";
82 85 private static final String MESSAGE_MOBILE_POSITION = "MobilePosition";
83 86 // private static final String MESSAGE_MOBILE_POSITION_INTERVAL = "Interval";
  87 + private static final String MESSAGE_PRESET_QUERY = "PresetQuery";
84 88  
85 89 /**
86 90 * 处理MESSAGE请求
... ... @@ -99,12 +103,22 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
99 103 processMessageKeepAlive(evt);
100 104 } else if (MESSAGE_CONFIG_DOWNLOAD.equals(cmd)) {
101 105 logger.info("接收到ConfigDownload消息");
  106 + processMessageConfigDownload(evt);
102 107 } else if (MESSAGE_CATALOG.equals(cmd)) {
103 108 logger.info("接收到Catalog消息");
104 109 processMessageCatalogList(evt);
105 110 } else if (MESSAGE_DEVICE_INFO.equals(cmd)) {
106 111 logger.info("接收到DeviceInfo消息");
107 112 processMessageDeviceInfo(evt);
  113 + } else if (MESSAGE_DEVICE_STATUS.equals(cmd)) {
  114 + logger.info("接收到DeviceStatus消息");
  115 + processMessageDeviceStatus(evt);
  116 + } else if (MESSAGE_DEVICE_CONTROL.equals(cmd)) {
  117 + logger.info("接收到DeviceControl消息");
  118 + processMessageDeviceControl(evt);
  119 + } else if (MESSAGE_DEVICE_CONFIG.equals(cmd)) {
  120 + logger.info("接收到DeviceConfig消息");
  121 + processMessageDeviceConfig(evt);
108 122 } else if (MESSAGE_ALARM.equals(cmd)) {
109 123 logger.info("接收到Alarm消息");
110 124 processMessageAlarm(evt);
... ... @@ -117,6 +131,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
117 131 } else if (MESSAGE_MOBILE_POSITION.equals(cmd)) {
118 132 logger.info("接收到MobilePosition消息");
119 133 processMessageMobilePosition(evt);
  134 + } else if (MESSAGE_PRESET_QUERY.equals(cmd)) {
  135 + logger.info("接收到PresetQuery消息");
  136 + processMessagePresetQuery(evt);
120 137 } else {
121 138 logger.info("接收到消息:" + cmd);
122 139 responseAck(evt);
... ... @@ -133,7 +150,6 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
133 150 */
134 151 private void processMessageMobilePosition(RequestEvent evt) {
135 152 try {
136   - //回复 200 OK
137 153 Element rootElement = getRootElement(evt);
138 154 MobilePosition mobilePosition = new MobilePosition();
139 155 Element deviceIdElement = rootElement.element("DeviceID");
... ... @@ -174,12 +190,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
174 190 storager.clearMobilePositionsByDeviceId(deviceId);
175 191 }
176 192 storager.insertMobilePosition(mobilePosition);
177   - // List<MobilePosition> all= storager.queryMobilePositions(deviceId, "2021-01-23T00:00:00", "2021-02-28T23:59:59");
178   - // all= storager.queryMobilePositions(deviceId, null, "2021-01-24T23:59:59");
179   - // all= storager.queryMobilePositions(deviceId, "2021-01-24T00:00:00", null);
180   - // //logger.debug(all.toString());
181   - // MobilePosition mp = storager.queryLatestPosition(deviceId);
182   - // logger.debug("最新位置:" + mp.getLongitude() + ", " + mp.getLatitude());
  193 + //回复 200 OK
183 194 responseAck(evt);
184 195 } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
185 196 e.printStackTrace();
... ... @@ -187,7 +198,169 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
187 198 }
188 199  
189 200 /**
190   - * 收到deviceInfo设备信息请求 处理
  201 + * 处理DeviceStatus设备状态Message
  202 + *
  203 + * @param evt
  204 + */
  205 + private void processMessageDeviceStatus(RequestEvent evt) {
  206 + try {
  207 + Element rootElement = getRootElement(evt);
  208 + String deviceId = XmlUtil.getText(rootElement, "DeviceID");
  209 + // 检查设备是否存在, 不存在则不回复
  210 + if (storager.exists(deviceId)) {
  211 + // 回复200 OK
  212 + responseAck(evt);
  213 + JSONObject json = new JSONObject();
  214 + XmlUtil.node2Json(rootElement, json);
  215 + if (logger.isDebugEnabled()) {
  216 + logger.debug(json.toJSONString());
  217 + }
  218 + RequestMessage msg = new RequestMessage();
  219 + msg.setDeviceId(deviceId);
  220 + msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS);
  221 + msg.setData(json);
  222 + deferredResultHolder.invokeResult(msg);
  223 +
  224 + if (offLineDetector.isOnline(deviceId)) {
  225 + publisher.onlineEventPublish(deviceId, VideoManagerConstants.EVENT_ONLINE_KEEPLIVE);
  226 + } else {
  227 + }
  228 + }
  229 + } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
  230 + e.printStackTrace();
  231 + }
  232 + }
  233 +
  234 + /**
  235 + * 处理DeviceControl设备状态Message
  236 + *
  237 + * @param evt
  238 + */
  239 + private void processMessageDeviceControl(RequestEvent evt) {
  240 + try {
  241 + Element rootElement = getRootElement(evt);
  242 + String deviceId = XmlUtil.getText(rootElement, "DeviceID");
  243 + String result = XmlUtil.getText(rootElement, "Result");
  244 + // 回复200 OK
  245 + responseAck(evt);
  246 + if (!XmlUtil.isEmpty(result)) {
  247 + // 此处是对本平台发出DeviceControl指令的应答
  248 + JSONObject json = new JSONObject();
  249 + XmlUtil.node2Json(rootElement, json);
  250 + if (logger.isDebugEnabled()) {
  251 + logger.debug(json.toJSONString());
  252 + }
  253 + RequestMessage msg = new RequestMessage();
  254 + msg.setDeviceId(deviceId);
  255 + msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL);
  256 + msg.setData(json);
  257 + deferredResultHolder.invokeResult(msg);
  258 + } else {
  259 + // 此处是上级发出的DeviceControl指令
  260 + }
  261 + } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
  262 + e.printStackTrace();
  263 + }
  264 + }
  265 +
  266 + /**
  267 + * 处理DeviceConfig设备状态Message
  268 + *
  269 + * @param evt
  270 + */
  271 + private void processMessageDeviceConfig(RequestEvent evt) {
  272 + try {
  273 + Element rootElement = getRootElement(evt);
  274 + String deviceId = XmlUtil.getText(rootElement, "DeviceID");
  275 + String result = XmlUtil.getText(rootElement, "Result");
  276 + // 回复200 OK
  277 + responseAck(evt);
  278 + //if (!XmlUtil.isEmpty(result)) {
  279 + // 此处是对本平台发出DeviceControl指令的应答
  280 + JSONObject json = new JSONObject();
  281 + XmlUtil.node2Json(rootElement, json);
  282 + if (logger.isDebugEnabled()) {
  283 + logger.debug(json.toJSONString());
  284 + }
  285 + RequestMessage msg = new RequestMessage();
  286 + msg.setDeviceId(deviceId);
  287 + msg.setType(DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG);
  288 + msg.setData(json);
  289 + deferredResultHolder.invokeResult(msg);
  290 + // } else {
  291 + // // 此处是上级发出的DeviceConfig指令
  292 + //}
  293 + } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
  294 + e.printStackTrace();
  295 + }
  296 + }
  297 +
  298 + /**
  299 + * 处理ConfigDownload设备状态Message
  300 + *
  301 + * @param evt
  302 + */
  303 + private void processMessageConfigDownload(RequestEvent evt) {
  304 + try {
  305 + Element rootElement = getRootElement(evt);
  306 + String deviceId = XmlUtil.getText(rootElement, "DeviceID");
  307 + String result = XmlUtil.getText(rootElement, "Result");
  308 + // 回复200 OK
  309 + responseAck(evt);
  310 + //if (!XmlUtil.isEmpty(result)) {
  311 + // 此处是对本平台发出DeviceControl指令的应答
  312 + JSONObject json = new JSONObject();
  313 + XmlUtil.node2Json(rootElement, json);
  314 + if (logger.isDebugEnabled()) {
  315 + logger.debug(json.toJSONString());
  316 + }
  317 + RequestMessage msg = new RequestMessage();
  318 + msg.setDeviceId(deviceId);
  319 + msg.setType(DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD);
  320 + msg.setData(json);
  321 + deferredResultHolder.invokeResult(msg);
  322 + // } else {
  323 + // // 此处是上级发出的DeviceConfig指令
  324 + //}
  325 + } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
  326 + e.printStackTrace();
  327 + }
  328 + }
  329 +
  330 + /**
  331 + * 处理PresetQuery预置位列表Message
  332 + *
  333 + * @param evt
  334 + */
  335 + private void processMessagePresetQuery(RequestEvent evt) {
  336 + try {
  337 + Element rootElement = getRootElement(evt);
  338 + String deviceId = XmlUtil.getText(rootElement, "DeviceID");
  339 + String result = XmlUtil.getText(rootElement, "Result");
  340 + // 回复200 OK
  341 + responseAck(evt);
  342 + if (rootElement.getName().equals("Response")) {// !XmlUtil.isEmpty(result)) {
  343 + // 此处是对本平台发出DeviceControl指令的应答
  344 + JSONObject json = new JSONObject();
  345 + XmlUtil.node2Json(rootElement, json);
  346 + if (logger.isDebugEnabled()) {
  347 + logger.debug(json.toJSONString());
  348 + }
  349 + RequestMessage msg = new RequestMessage();
  350 + msg.setDeviceId(deviceId);
  351 + msg.setType(DeferredResultHolder.CALLBACK_CMD_PRESETQUERY);
  352 + msg.setData(json);
  353 + deferredResultHolder.invokeResult(msg);
  354 + } else {
  355 + // 此处是上级发出的DeviceControl指令
  356 + }
  357 + } catch (ParseException | SipException | InvalidArgumentException | DocumentException e) {
  358 + e.printStackTrace();
  359 + }
  360 + }
  361 +
  362 + /**
  363 + * 处理DeviceInfo设备信息Message
191 364 *
192 365 * @param evt
193 366 */
... ... @@ -354,56 +527,72 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
354 527 Element rootElement = getRootElement(evt);
355 528 Element deviceIdElement = rootElement.element("DeviceID");
356 529 String deviceId = deviceIdElement.getText().toString();
  530 + // 回复200 OK
  531 + responseAck(evt);
357 532  
358 533 Device device = storager.queryVideoDevice(deviceId);
359 534 if (device == null) {
360 535 return;
361 536 }
362   - DeviceAlarm deviceAlarm = new DeviceAlarm();
363   - deviceAlarm.setDeviceId(deviceId);
364   - deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority"));
365   - deviceAlarm.setAlarmMethod(XmlUtil.getText(rootElement, "AlarmMethod"));
366   - deviceAlarm.setAlarmTime(XmlUtil.getText(rootElement, "AlarmTime"));
367   - if (XmlUtil.getText(rootElement, "AlarmDescription") == null) {
368   - deviceAlarm.setAlarmDescription("");
369   - } else {
370   - deviceAlarm.setAlarmDescription(XmlUtil.getText(rootElement, "AlarmDescription"));
371   - }
372   - if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Longitude"))) {
373   - deviceAlarm.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude")));
374   - } else {
375   - deviceAlarm.setLongitude(0.00);
376   - }
377   - if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Latitude"))) {
378   - deviceAlarm.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
379   - } else {
380   - deviceAlarm.setLatitude(0.00);
381   - }
382 537  
383   - if ( deviceAlarm.getAlarmMethod().equals("4")) {
384   - MobilePosition mobilePosition = new MobilePosition();
385   - mobilePosition.setDeviceId(deviceAlarm.getDeviceId());
386   - mobilePosition.setTime(deviceAlarm.getAlarmTime());
387   - mobilePosition.setLongitude(deviceAlarm.getLongitude());
388   - mobilePosition.setLatitude(deviceAlarm.getLatitude());
389   - mobilePosition.setReportSource("GPS Alarm");
390   - BaiduPoint bp = new BaiduPoint();
391   - bp = GpsUtil.Wgs84ToBd09(String.valueOf(mobilePosition.getLongitude()), String.valueOf(mobilePosition.getLatitude()));
392   - logger.info("百度坐标:" + bp.getBdLng() + ", " + bp.getBdLat());
393   - mobilePosition.setGeodeticSystem("BD-09");
394   - mobilePosition.setCnLng(bp.getBdLng());
395   - mobilePosition.setCnLat(bp.getBdLat());
396   - if (!userSetup.getSavePositionHistory()) {
397   - storager.clearMobilePositionsByDeviceId(deviceId);
  538 + if (rootElement.getName().equals("Notify")) { // 处理报警通知
  539 + DeviceAlarm deviceAlarm = new DeviceAlarm();
  540 + deviceAlarm.setDeviceId(deviceId);
  541 + deviceAlarm.setAlarmPriority(XmlUtil.getText(rootElement, "AlarmPriority"));
  542 + deviceAlarm.setAlarmMethod(XmlUtil.getText(rootElement, "AlarmMethod"));
  543 + deviceAlarm.setAlarmTime(XmlUtil.getText(rootElement, "AlarmTime"));
  544 + if (XmlUtil.getText(rootElement, "AlarmDescription") == null) {
  545 + deviceAlarm.setAlarmDescription("");
  546 + } else {
  547 + deviceAlarm.setAlarmDescription(XmlUtil.getText(rootElement, "AlarmDescription"));
398 548 }
399   - storager.insertMobilePosition(mobilePosition);
400   - }
401   - // TODO: 需要实现存储报警信息、报警分类
402   -
403   - // 回复200 OK
404   - responseAck(evt);
405   - if (offLineDetector.isOnline(deviceId)) {
406   - publisher.deviceAlarmEventPublish(deviceAlarm);
  549 + if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Longitude"))) {
  550 + deviceAlarm.setLongitude(Double.parseDouble(XmlUtil.getText(rootElement, "Longitude")));
  551 + } else {
  552 + deviceAlarm.setLongitude(0.00);
  553 + }
  554 + if (NumericUtil.isDouble(XmlUtil.getText(rootElement, "Latitude"))) {
  555 + deviceAlarm.setLatitude(Double.parseDouble(XmlUtil.getText(rootElement, "Latitude")));
  556 + } else {
  557 + deviceAlarm.setLatitude(0.00);
  558 + }
  559 +
  560 + if (!XmlUtil.isEmpty(deviceAlarm.getAlarmMethod())) {
  561 + if ( deviceAlarm.getAlarmMethod().equals("4")) {
  562 + MobilePosition mobilePosition = new MobilePosition();
  563 + mobilePosition.setDeviceId(deviceAlarm.getDeviceId());
  564 + mobilePosition.setTime(deviceAlarm.getAlarmTime());
  565 + mobilePosition.setLongitude(deviceAlarm.getLongitude());
  566 + mobilePosition.setLatitude(deviceAlarm.getLatitude());
  567 + mobilePosition.setReportSource("GPS Alarm");
  568 + BaiduPoint bp = new BaiduPoint();
  569 + bp = GpsUtil.Wgs84ToBd09(String.valueOf(mobilePosition.getLongitude()), String.valueOf(mobilePosition.getLatitude()));
  570 + logger.info("百度坐标:" + bp.getBdLng() + ", " + bp.getBdLat());
  571 + mobilePosition.setGeodeticSystem("BD-09");
  572 + mobilePosition.setCnLng(bp.getBdLng());
  573 + mobilePosition.setCnLat(bp.getBdLat());
  574 + if (!userSetup.getSavePositionHistory()) {
  575 + storager.clearMobilePositionsByDeviceId(deviceId);
  576 + }
  577 + storager.insertMobilePosition(mobilePosition);
  578 + }
  579 + }
  580 + // TODO: 需要实现存储报警信息、报警分类
  581 +
  582 + if (offLineDetector.isOnline(deviceId)) {
  583 + publisher.deviceAlarmEventPublish(deviceAlarm);
  584 + }
  585 + } else if (rootElement.getName().equals("Response")) { // 处理报警查询响应
  586 + JSONObject json = new JSONObject();
  587 + XmlUtil.node2Json(rootElement, json);
  588 + if (logger.isDebugEnabled()) {
  589 + logger.debug(json.toJSONString());
  590 + }
  591 + RequestMessage msg = new RequestMessage();
  592 + msg.setDeviceId(deviceId);
  593 + msg.setType(DeferredResultHolder.CALLBACK_CMD_ALARM);
  594 + msg.setData(json);
  595 + deferredResultHolder.invokeResult(msg);
407 596 }
408 597 } catch (DocumentException | SipException | InvalidArgumentException | ParseException e) {
409 598 // } catch (DocumentException e) {
... ... @@ -435,7 +624,7 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
435 624 }
436 625  
437 626 /***
438   - * 收到catalog设备目录列表请求 处理 TODO 过期时间暂时写死180秒,后续与DeferredResult超时时间保持一致
  627 + * 处理RecordInfo设备录像列表Message请求 TODO 过期时间暂时写死180秒,后续与DeferredResult超时时间保持一致
439 628 *
440 629 * @param evt
441 630 */
... ... @@ -522,12 +711,9 @@ public class MessageRequestProcessor extends SIPRequestAbstractProcessor {
522 711 // 2、有录像数据,且第一次即收到完整数据,返回响应数据,无redis操作
523 712 // 3、有录像数据,在超时时间内收到多次包组装后数量足够,返回数据
524 713  
525   - // 对记录进行排序
526 714 RequestMessage msg = new RequestMessage();
527 715 msg.setDeviceId(deviceId);
528 716 msg.setType(DeferredResultHolder.CALLBACK_CMD_RECORDINFO);
529   - // // 自然顺序排序, 元素进行升序排列
530   - // recordInfo.getRecordList().sort(Comparator.naturalOrder());
531 717 msg.setData(recordInfo);
532 718 deferredResultHolder.invokeResult(msg);
533 719 logger.info("处理完成,返回结果");
... ...