|
@@ -421,6 +421,58 @@ public class SipCommander {
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public Mono<Void> frontEndCmd(MediaDevice device, String channelId, int cmdCode, int horizonSpeed, int verticalSpeed, int zoomSpeed) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ String cmdStr= frontEndCmdString(cmdCode, horizonSpeed, verticalSpeed, zoomSpeed);
|
|
|
|
|
+ log.debug("控制字符串:" + cmdStr);
|
|
|
|
|
+ StringBuffer ptzXml = new StringBuffer(200);
|
|
|
|
|
+ ptzXml.append("<?xml version=\"1.0\" ?>\r\n");
|
|
|
|
|
+ ptzXml.append("<Control>\r\n");
|
|
|
|
|
+ ptzXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
|
|
|
|
+ ptzXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
|
|
|
|
+ ptzXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
|
|
|
|
|
+ ptzXml.append("<PTZCmd>" + cmdStr + "</PTZCmd>\r\n");
|
|
|
|
|
+ ptzXml.append("<Info>\r\n");
|
|
|
|
|
+ ptzXml.append("</Info>\r\n");
|
|
|
|
|
+ ptzXml.append("</Control>\r\n");
|
|
|
|
|
+
|
|
|
|
|
+ String tm = Long.toString(System.currentTimeMillis());
|
|
|
|
|
+
|
|
|
|
|
+ CallIdHeader callIdHeader = SipContext.getSipProvider().getNewCallId();
|
|
|
|
|
+
|
|
|
|
|
+ Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "z9hG4bK-ViaPtz-" + tm, "FromPtz" + tm, null, callIdHeader);
|
|
|
|
|
+ return transmitRequest(SipContext.getSipProvider(), request);
|
|
|
|
|
+ } catch (SipException | ParseException | InvalidArgumentException e) {
|
|
|
|
|
+ log.error("发送cmd命令失败,",e);
|
|
|
|
|
+ return Mono.error(new BusinessException("系统繁忙,请稍后再试"));
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 云台指令码计算
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param cmdCode 指令码
|
|
|
|
|
+ * @param parameter1 数据1
|
|
|
|
|
+ * @param parameter2 数据2
|
|
|
|
|
+ * @param combineCode2 组合码2
|
|
|
|
|
+ */
|
|
|
|
|
+ public static String frontEndCmdString(int cmdCode, int parameter1, int parameter2, int combineCode2) {
|
|
|
|
|
+ StringBuilder builder = new StringBuilder("A50F01");
|
|
|
|
|
+ String strTmp;
|
|
|
|
|
+ strTmp = String.format("%02X", cmdCode);
|
|
|
|
|
+ builder.append(strTmp, 0, 2);
|
|
|
|
|
+ strTmp = String.format("%02X", parameter1);
|
|
|
|
|
+ builder.append(strTmp, 0, 2);
|
|
|
|
|
+ strTmp = String.format("%02X", parameter2);
|
|
|
|
|
+ builder.append(strTmp, 0, 2);
|
|
|
|
|
+ strTmp = String.format("%X", combineCode2);
|
|
|
|
|
+ builder.append(strTmp, 0, 1).append("0");
|
|
|
|
|
+ //计算校验码
|
|
|
|
|
+ int checkCode = (0XA5 + 0X0F + 0X01 + cmdCode + parameter1 + parameter2 + (combineCode2 & 0XF0)) % 0X100;
|
|
|
|
|
+ strTmp = String.format("%02X", checkCode);
|
|
|
|
|
+ builder.append(strTmp, 0, 2);
|
|
|
|
|
+ return builder.toString();
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// private Mono<Void> transmitRequest(SipProvider sipProvider, Request request, SipSubscribe.Event event) throws SipException {
|
|
// private Mono<Void> transmitRequest(SipProvider sipProvider, Request request, SipSubscribe.Event event) throws SipException {
|
|
|
// ClientTransaction clientTransaction = sipProvider.getNewClientTransaction(request);
|
|
// ClientTransaction clientTransaction = sipProvider.getNewClientTransaction(request);
|