From a60e1102c41b5fa89c5e2cbbef81f668b0495240 Mon Sep 17 00:00:00 2001 From: Lawrence <1934378145@qq.com> Date: 星期五, 06 十一月 2020 12:37:08 +0800 Subject: [PATCH] 完善前端控制信令,实现GB28181 A.3前端设备控制协议 --- src/main/java/com/genersoft/iot/vmp/vmanager/ptz/PtzController.java | 27 ++++++ /dev/null | 0 src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java | 61 +++++++++++++++ src/main/java/com/genersoft/iot/vmp/vmanager/device/DeviceController.java | 2 web_src/src/components/gb28181/devicePlayer.vue | 100 +++++++++++++++++++++--- src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java | 12 +++ 6 files changed, 183 insertions(+), 19 deletions(-) diff --git a/libs/jain-sip-ri-1.3.0-91.jar b/libs/jain-sip-ri-1.3.0-91.jar deleted file mode 100644 index 960c83e..0000000 --- a/libs/jain-sip-ri-1.3.0-91.jar +++ /dev/null Binary files differ diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java index 7d5d10c..923f211 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/ISIPCommander.java @@ -65,6 +65,18 @@ public boolean ptzCmd(Device device,String channelId,int leftRight, int upDown, int inOut, int moveSpeed, int zoomSpeed); /** + * 鍓嶇鎺у埗锛屽寘鎷琍TZ鎸囦护銆丗I鎸囦护銆侀缃綅鎸囦护銆佸贰鑸寚浠ゃ�佹壂鎻忔寚浠ゅ拰杈呭姪寮�鍏虫寚浠� + * + * @param device 鎺у埗璁惧 + * @param channelId 棰勮閫氶亾 + * @param cmdCode 鎸囦护鐮� + * @param parameter1 鏁版嵁1 + * @param parameter2 鏁版嵁2 + * @param combineCode2 缁勫悎鐮�2 + */ + public boolean frontEndCmd(Device device, String channelId, int cmdCode, int parameter1, int parameter2, int combineCode2); + + /** * 璇锋眰棰勮瑙嗛娴� * * @param device 瑙嗛璁惧 diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java index a33678c..4ac0c73 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java @@ -163,6 +163,32 @@ return builder.toString(); } + /** + * 浜戝彴鎸囦护鐮佽绠� + * + * @param leftRight 闀滃ご宸︾Щ鍙崇Щ 0:鍋滄 1:宸︾Щ 2:鍙崇Щ + * @param upDown 闀滃ご涓婄Щ涓嬬Щ 0:鍋滄 1:涓婄Щ 2:涓嬬Щ + * @param inOut 闀滃ご鏀惧ぇ缂╁皬 0:鍋滄 1:缂╁皬 2:鏀惧ぇ + * @param moveSpeed 闀滃ご绉诲姩閫熷害 榛樿 0XFF (0-255) + * @param zoomSpeed 闀滃ご缂╂斁閫熷害 榛樿 0X1 (0-255) + */ + 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(); + } /** * 浜戝彴鎺у埗锛屾敮鎸佹柟鍚戜笌缂╂斁鎺у埗 @@ -202,6 +228,41 @@ } /** + * 鍓嶇鎺у埗锛屽寘鎷琍TZ鎸囦护銆丗I鎸囦护銆侀缃綅鎸囦护銆佸贰鑸寚浠ゃ�佹壂鎻忔寚浠ゅ拰杈呭姪寮�鍏虫寚浠� + * + * @param device 鎺у埗璁惧 + * @param channelId 棰勮閫氶亾 + * @param cmdCode 鎸囦护鐮� + * @param parameter1 鏁版嵁1 + * @param parameter2 鏁版嵁2 + * @param combineCode2 缁勫悎鐮�2 + */ + @Override + public boolean frontEndCmd(Device device, String channelId, int cmdCode, int parameter1, int parameter2, int combineCode2) { + try { + String cmdStr= frontEndCmdString(cmdCode, parameter1, parameter2, combineCode2); + System.out.println("鎺у埗瀛楃涓诧細" + 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"); + + Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "ViaPtzBranch", "FromPtzTag", "ToPtzTag"); + + transmitRequest(device, request); + return true; + } catch (SipException | ParseException | InvalidArgumentException e) { + e.printStackTrace(); + } + return false; + } + /** * 璇锋眰棰勮瑙嗛娴� * * @param device 瑙嗛璁惧 diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/device/DeviceController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/device/DeviceController.java index 8c0ecfb..34a02ee 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/device/DeviceController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/device/DeviceController.java @@ -138,7 +138,7 @@ DeviceChannel deviceChannel = storager.queryChannel(deviceId,channelId); if (deviceChannel == null) { PageResult<DeviceChannel> deviceChannelPageResult = new PageResult<>(); - new ResponseEntity<>(deviceChannelPageResult,HttpStatus.OK); + return new ResponseEntity<>(deviceChannelPageResult,HttpStatus.OK); } PageResult pageResult = storager.querySubChannels(deviceId, channelId, query, channelType, online, page, count); diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/ptz/PtzController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/ptz/PtzController.java index 87e6bf2..1a90977 100644 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/ptz/PtzController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/ptz/PtzController.java @@ -40,14 +40,35 @@ * @return */ @PostMapping("/ptz/{deviceId}/{channelId}") - public ResponseEntity<String> ptz(@PathVariable String deviceId,@PathVariable String channelId,int leftRight, int upDown, int inOut, int moveSpeed, int zoomSpeed){ + public ResponseEntity<String> ptz(@PathVariable String deviceId,@PathVariable String channelId,int cmdCode, int horizonSpeed, int verticalSpeed, int zoomSpeed){ if (logger.isDebugEnabled()) { - logger.debug(String.format("璁惧浜戝彴鎺у埗 API璋冪敤锛宒eviceId锛�%s 锛宑hannelId锛�%s 锛宭eftRight锛�%d 锛寀pDown锛�%d 锛宨nOut锛�%d 锛宮oveSpeed锛�%d 锛寊oomSpeed锛�%d",deviceId, channelId, leftRight, upDown, inOut, moveSpeed, zoomSpeed)); + logger.debug(String.format("璁惧浜戝彴鎺у埗 API璋冪敤锛宒eviceId锛�%s 锛宑hannelId锛�%s 锛宑mdCode锛�%d 锛宧orizonSpeed锛�%d 锛寁erticalSpeed锛�%d 锛寊oomSpeed锛�%d",deviceId, channelId, cmdCode, horizonSpeed, verticalSpeed, zoomSpeed)); } Device device = storager.queryVideoDevice(deviceId); - cmder.ptzCmd(device, channelId, leftRight, upDown, inOut, moveSpeed, zoomSpeed); + cmder.frontEndCmd(device, channelId, cmdCode, horizonSpeed, verticalSpeed, zoomSpeed); + return new ResponseEntity<String>("success",HttpStatus.OK); + } + // public ResponseEntity<String> ptz(@PathVariable String deviceId,@PathVariable String channelId,int leftRight, int upDown, int inOut, int moveSpeed, int zoomSpeed){ + + // if (logger.isDebugEnabled()) { + // logger.debug(String.format("璁惧浜戝彴鎺у埗 API璋冪敤锛宒eviceId锛�%s 锛宑hannelId锛�%s 锛宭eftRight锛�%d 锛寀pDown锛�%d 锛宨nOut锛�%d 锛宮oveSpeed锛�%d 锛寊oomSpeed锛�%d",deviceId, channelId, leftRight, upDown, inOut, moveSpeed, zoomSpeed)); + // } + // Device device = storager.queryVideoDevice(deviceId); + + // cmder.ptzCmd(device, channelId, leftRight, upDown, inOut, moveSpeed, zoomSpeed); + // return new ResponseEntity<String>("success",HttpStatus.OK); + // } + @PostMapping("/frontEndCommand/{deviceId}/{channelId}") + public ResponseEntity<String> frontEndCommand(@PathVariable String deviceId,@PathVariable String channelId,int cmdCode, int parameter1, int parameter2, int combindCode2){ + + if (logger.isDebugEnabled()) { + logger.debug(String.format("璁惧浜戝彴鎺у埗 API璋冪敤锛宒eviceId锛�%s 锛宑hannelId锛�%s 锛宑mdCode锛�%d parameter1锛�%d parameter2锛�%d",deviceId, channelId, cmdCode, parameter1, parameter2)); + } + Device device = storager.queryVideoDevice(deviceId); + + cmder.frontEndCmd(device, channelId, cmdCode, parameter1, parameter2, combindCode2); return new ResponseEntity<String>("success",HttpStatus.OK); } } diff --git a/web_src/src/components/gb28181/devicePlayer.vue b/web_src/src/components/gb28181/devicePlayer.vue index 8c23ced..493f5d5 100644 --- a/web_src/src/components/gb28181/devicePlayer.vue +++ b/web_src/src/components/gb28181/devicePlayer.vue @@ -40,7 +40,7 @@ <!-- <el-date-picker v-model="videoHistory.endTime" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="缁撴潫鏃堕棿"--> <!-- @change="recordList()"></el-date-picker>--> - <el-table :data="videoHistory.searchHistoryResult" height="150" v-load="recordsLoading"> + <el-table :data="videoHistory.searchHistoryResult" height="150" v-loading="recordsLoading"> <el-table-column label="鍚嶇О" prop="name"></el-table-column> <el-table-column label="鏂囦欢" prop="filePath"></el-table-column> <el-table-column label="寮�濮嬫椂闂�" prop="startTime" :formatter="timeFormatter"></el-table-column> @@ -55,32 +55,61 @@ </el-tab-pane> <!--閬ユ帶鐣岄潰--> <el-tab-pane label="浜戝彴鎺у埗" name="control"> - <div style="display: flex; justify-content: center;"> + <div style="display: flex; justify-content: left;"> <div class="control-wrapper"> - <div class="control-btn control-top" @mousedown="ptzCamera(0, 1, 0)" @mouseup="ptzCamera(0, 0, 0)"> + <div class="control-btn control-top" @mousedown="ptzCamera(0, 2, 0)" @mouseup="ptzCamera(0, 0, 0)"> <i class="el-icon-caret-top"></i> <div class="control-inner-btn control-inner"></div> </div> - <div class="control-btn control-left" @mousedown="ptzCamera(1, 0, 0)" @mouseup="ptzCamera(0, 0, 0)"> + <div class="control-btn control-left" @mousedown="ptzCamera(2, 0, 0)" @mouseup="ptzCamera(0, 0, 0)"> <i class="el-icon-caret-left"></i> <div class="control-inner-btn control-inner"></div> </div> - <div class="control-btn control-bottom" @mousedown="ptzCamera(0, 2, 0)" @mouseup="ptzCamera(0, 0, 0)"> + <div class="control-btn control-bottom" @mousedown="ptzCamera(0, 1, 0)" @mouseup="ptzCamera(0, 0, 0)"> <i class="el-icon-caret-bottom"></i> <div class="control-inner-btn control-inner"></div> </div> - <div class="control-btn control-right" @mousedown="ptzCamera(2, 0, 0)" @mouseup="ptzCamera(0, 0, 0)"> + <div class="control-btn control-right" @mousedown="ptzCamera(1, 0, 0)" @mouseup="ptzCamera(0, 0, 0)"> <i class="el-icon-caret-right"></i> <div class="control-inner-btn control-inner"></div> </div> <div class="control-round"> <div class="control-round-inner"><i class="fa fa-pause-circle"></i></div> </div> - <div style="position: absolute; left: 7.25rem; top: 1.25rem" @mousedown="ptzCamera(0, 0, 2)" @mouseup="ptzCamera(0, 0, 0)"><i class="el-icon-zoom-in" style="font-size: 1.875rem;"></i></div> - <div style="position: absolute; left: 7.25rem; top: 3.25rem; font-size: 1.875rem;" @mousedown="ptzCamera(0, 0, 1)" @mouseup="ptzCamera(0, 0, 0)"><i class="el-icon-zoom-out"></i></div> + <div style="position: absolute; left: 7.25rem; top: 1.25rem" @mousedown="ptzCamera(0, 0, 1)" @mouseup="ptzCamera(0, 0, 0)"><i class="el-icon-zoom-in" style="font-size: 1.875rem;"></i></div> + <div style="position: absolute; left: 7.25rem; top: 3.25rem; font-size: 1.875rem;" @mousedown="ptzCamera(0, 0, 2)" @mouseup="ptzCamera(0, 0, 0)"><i class="el-icon-zoom-out"></i></div> + </div> + <div class="control-panel"> + <el-button-group> + <el-tag style="position :absolute; left: 0rem; top: 0rem; width: 5rem; text-align: center" size="medium" type="info">棰勭疆浣嶇紪鍙�</el-tag> + <el-input-number style="position: absolute; left: 5rem; top: 0rem; width: 6rem" size="mini" v-model="presetPos" controls-position="right" :precision="0" :step="1" :min="1" :max="255"></el-input-number> + <el-button style="position: absolute; left: 11rem; top: 0rem; width: 5rem" size="mini" icon="el-icon-add-location" @click="presetPosition(129, presetPos)">璁剧疆</el-button> + <el-button style="position: absolute; left: 27rem; top: 0rem; width: 5rem" size="mini" type="primary" icon="el-icon-place" @click="presetPosition(130, presetPos)">璋冪敤</el-button> + <el-button style="position: absolute; left: 16rem; top: 0rem; width: 5rem" size="mini" icon="el-icon-delete-location" @click="presetPosition(131, presetPos)">鍒犻櫎</el-button> + <el-tag style="position :absolute; left: 0rem; top: 2.5rem; width: 5rem; text-align: center" size="medium" type="info">宸¤埅閫熷害</el-tag> + <el-input-number style="position: absolute; left: 5rem; top: 2.5rem; width: 6rem" size="mini" v-model="cruisingSpeed" controls-position="right" :precision="0" :min="1" :max="4095"></el-input-number> + <el-button style="position: absolute; left: 11rem; top: 2.5rem; width: 5rem" size="mini" icon="el-icon-loading" @click="setSpeedOrTime(134, cruisingGroup, cruisingSpeed)">璁剧疆</el-button> + <el-tag style="position :absolute; left: 16rem; top: 2.5rem; width: 5rem; text-align: center" size="medium" type="info">鍋滅暀鏃堕棿</el-tag> + <el-input-number style="position: absolute; left: 21rem; top: 2.5rem; width: 6rem" size="mini" v-model="cruisingTime" controls-position="right" :precision="0" :min="1" :max="4095"></el-input-number> + <el-button style="position: absolute; left: 27rem; top: 2.5rem; width: 5rem" size="mini" icon="el-icon-timer" @click="setSpeedOrTime(135, cruisingGroup, cruisingTime)">璁剧疆</el-button> + <el-tag style="position :absolute; left: 0rem; top: 4.5rem; width: 5rem; text-align: center" size="medium" type="info">宸¤埅缁勭紪鍙�</el-tag> + <el-input-number style="position: absolute; left: 5rem; top: 4.5rem; width: 6rem" size="mini" v-model="cruisingGroup" controls-position="right" :precision="0" :min="0" :max="255"></el-input-number> + <el-button style="position: absolute; left: 11rem; top: 4.5rem; width: 5rem" size="mini" icon="el-icon-add-location" @click="setCommand(132, cruisingGroup, presetPos)">娣诲姞鐐�</el-button> + <el-button style="position: absolute; left: 16rem; top: 4.5rem; width: 5rem" size="mini" icon="el-icon-delete-location" @click="setCommand(133, cruisingGroup, presetPos)">鍒犻櫎鐐�</el-button> + <el-button style="position: absolute; left: 21rem; top: 4.5rem; width: 5rem" size="mini" icon="el-icon-delete" @click="setCommand(133, cruisingGroup, 0)">鍒犻櫎缁�</el-button> + <el-button style="position: absolute; left: 27rem; top: 5rem; width: 5rem" size="mini" type="primary" icon="el-icon-video-camera-solid" @click="setCommand(136, cruisingGroup, 0)">宸¤埅</el-button> + <el-tag style="position :absolute; left: 0rem; top: 7rem; width: 5rem; text-align: center" size="medium" type="info">鎵弿閫熷害</el-tag> + <el-input-number style="position: absolute; left: 5rem; top: 7rem; width: 6rem" size="mini" v-model="scanSpeed" controls-position="right" :precision="0" :min="1" :max="4095"></el-input-number> + <el-button style="position: absolute; left: 11rem; top: 7rem; width: 5rem" size="mini" icon="el-icon-loading" @click="setSpeedOrTime(138, scanGroup, scanSpeed)">璁剧疆</el-button> + <el-tag style="position :absolute; left: 0rem; top: 9rem; width: 5rem; text-align: center" size="medium" type="info">鎵弿缁勭紪鍙�</el-tag> + <el-input-number style="position: absolute; left: 5rem; top: 9rem; width: 6rem" size="mini" v-model="scanGroup" controls-position="right" :precision="0" :step="1" :min="0" :max="255"></el-input-number> + <el-button style="position: absolute; left: 11rem; top: 9rem; width: 5rem" size="mini" icon="el-icon-d-arrow-left" @click="setCommand(137, scanGroup, 1)">宸﹁竟鐣�</el-button> + <el-button style="position: absolute; left: 16rem; top: 9rem; width: 5rem" size="mini" icon="el-icon-d-arrow-right" @click="setCommand(137, scanGroup, 2)">鍙宠竟鐣�</el-button> + <el-button style="position: absolute; left: 27rem; top: 7rem; width: 5rem" size="mini" type="primary" icon="el-icon-video-camera-solid" @click="setCommand(137, scanGroup, 0)">鎵弿</el-button> + <el-button style="position: absolute; left: 27rem; top: 9rem; width: 5rem" size="mini" type="danger" icon="el-icon-switch-button" @click="ptzCamera(0, 0, 0)">鍋滄</el-button> + </el-button-group> </div> </div> - </el-tab-pane> </el-tabs> </div> @@ -152,7 +181,12 @@ timeVal: 0, timeMin: 0, timeMax: 1440, - + presetPos: 1, + cruisingSpeed: 100, + cruisingTime: 5, + cruisingGroup: 0, + scanSpeed: 100, + scanGroup: 0, }; }, methods: { @@ -291,13 +325,40 @@ let that = this; this.$axios({ method: 'post', - url: '/api/ptz/' + this.deviceId + '/' + this.channelId + '?leftRight=' + leftRight + '&upDown=' + upDown + - '&inOut=' + zoom + '&moveSpeed=50&zoomSpeed=50' + // url: '/api/ptz/' + this.deviceId + '/' + this.channelId + '?leftRight=' + leftRight + '&upDown=' + upDown + + // '&inOut=' + zoom + '&moveSpeed=50&zoomSpeed=50' + url: '/api/ptz/' + this.deviceId + '/' + this.channelId + '?cmdCode=' + (zoom * 16 + upDown * 4 + leftRight) + '&horizonSpeed=30&verticalSpeed=30&zoomSpeed=' + (2 * 16) }).then(function (res) {}); }, //////////////////////鎾斁鍣ㄤ簨浠跺鐞�////////////////////////// videoError: function (e) { console.log("鎾斁鍣ㄩ敊璇細" + JSON.stringify(e)); + }, + presetPosition: function (cmdCode, presetPos) { + console.log('棰勭疆浣嶆帶鍒讹細' + this.presetPos + ' : 0x' + cmdCode.toString(16)); + let that = this; + this.$axios({ + method: 'post', + url: '/api/frontEndCommand/' + this.deviceId + '/' + this.channelId + '?cmdCode=' + cmdCode + '¶meter1=0¶meter2=' + presetPos + '&combindCode2=0' + }).then(function (res) {}); + }, + setSpeedOrTime: function (cmdCode, groupNum, parameter) { + let that = this; + let parameter2 = parameter % 256; + let combindCode2 = Math.floor(parameter / 256) * 16; + console.log('鍓嶇鎺у埗锛�0x' + cmdCode.toString(16) + ' 0x' + groupNum.toString(16) + ' 0x' + parameter2.toString(16) + ' 0x' + combindCode2.toString(16)); + this.$axios({ + method: 'post', + url: '/api/frontEndCommand/' + this.deviceId + '/' + this.channelId + '?cmdCode=' + cmdCode + '¶meter1=' + groupNum + '¶meter2=' + parameter2 + '&combindCode2=' + combindCode2 + }).then(function (res) {}); + }, + setCommand: function (cmdCode, groupNum, parameter) { + let that = this; + console.log('鍓嶇鎺у埗锛�0x' + cmdCode.toString(16) + ' 0x' + groupNum.toString(16) + ' 0x' + parameter.toString(16) + ' 0x0'); + this.$axios({ + method: 'post', + url: '/api/frontEndCommand/' + this.deviceId + '/' + this.channelId + '?cmdCode=' + cmdCode + '¶meter1=' + groupNum + '¶meter2=' + parameter + '&combindCode2=0' + }).then(function (res) {}); }, formatTooltip: function (val) { var h = parseInt(val / 60); @@ -356,9 +417,18 @@ height: 6.25rem; max-width: 6.25rem; max-height: 6.25rem; - margin: 0 auto; border-radius: 100%; + margin-top: 2.5rem; + margin-left: 0.5rem; float: left; +} + +.control-panel { + position: relative; + top: 0; + left: 5rem; + height: 11rem; + max-height: 11rem; } .control-btn { @@ -393,8 +463,8 @@ .control-round-inner { position: absolute; - left: 15%; - top: 15%; + left: 13%; + top: 13%; display: flex; justify-content: center; align-items: center; -- Gitblit v1.8.0