Commit 65b4c5cec92e4c024fc868f1ae668d08eb354170
1 parent
c1d4e194
增加多种信令的API调用接口
Showing
4 changed files
with
492 additions
and
24 deletions
src/main/java/com/genersoft/iot/vmp/vmanager/device/DeviceConfig.java
0 → 100644
| 1 | +/** | |
| 2 | + * 设备设置命令API接口 | |
| 3 | + * | |
| 4 | + * @author lawrencehj | |
| 5 | + * @date 2021年2月2日 | |
| 6 | + */ | |
| 7 | + | |
| 8 | +package com.genersoft.iot.vmp.vmanager.device; | |
| 9 | + | |
| 10 | +import javax.sip.message.Response; | |
| 11 | + | |
| 12 | +import com.alibaba.fastjson.JSONObject; | |
| 13 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 14 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | |
| 15 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | |
| 16 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | |
| 17 | +import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; | |
| 18 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | |
| 19 | + | |
| 20 | +import org.slf4j.Logger; | |
| 21 | +import org.slf4j.LoggerFactory; | |
| 22 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 23 | +import org.springframework.http.HttpStatus; | |
| 24 | +import org.springframework.http.ResponseEntity; | |
| 25 | +import org.springframework.web.bind.annotation.*; | |
| 26 | +import org.springframework.web.context.request.async.DeferredResult; | |
| 27 | + | |
| 28 | +@CrossOrigin | |
| 29 | +@RestController | |
| 30 | +@RequestMapping("/api") | |
| 31 | +public class DeviceConfig { | |
| 32 | + | |
| 33 | + private final static Logger logger = LoggerFactory.getLogger(DeviceQuery.class); | |
| 34 | + | |
| 35 | + @Autowired | |
| 36 | + private IVideoManagerStorager storager; | |
| 37 | + | |
| 38 | + @Autowired | |
| 39 | + private SIPCommander cmder; | |
| 40 | + | |
| 41 | + @Autowired | |
| 42 | + private DeferredResultHolder resultHolder; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * 看守位控制命令API接口 | |
| 46 | + * | |
| 47 | + * @param deviceId | |
| 48 | + * @param enabled 看守位使能1:开启,0:关闭 | |
| 49 | + * @param resetTime 自动归位时间间隔(可选) | |
| 50 | + * @param presetIndex 调用预置位编号(可选) | |
| 51 | + * @param channelId 通道编码(可选) | |
| 52 | + */ | |
| 53 | + @GetMapping("/config/{deviceId}/basicParam") | |
| 54 | + public DeferredResult<ResponseEntity<String>> homePositionApi(@PathVariable String deviceId, | |
| 55 | + @RequestParam(required = false) String channelId, | |
| 56 | + @RequestParam(required = false) String name, | |
| 57 | + @RequestParam(required = false) String expiration, | |
| 58 | + @RequestParam(required = false) String heartBeatInterval, | |
| 59 | + @RequestParam(required = false) String heartBeatCount) { | |
| 60 | + if (logger.isDebugEnabled()) { | |
| 61 | + logger.debug("报警复位API调用"); | |
| 62 | + } | |
| 63 | + Device device = storager.queryVideoDevice(deviceId); | |
| 64 | + cmder.deviceBasicConfigCmd(device, channelId, name, expiration, heartBeatInterval, heartBeatCount, event -> { | |
| 65 | + Response response = event.getResponse(); | |
| 66 | + RequestMessage msg = new RequestMessage(); | |
| 67 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + (XmlUtil.isEmpty(channelId) ? deviceId : channelId)); | |
| 68 | + msg.setData(String.format("设备配置操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 69 | + resultHolder.invokeResult(msg); | |
| 70 | + }); | |
| 71 | + DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); | |
| 72 | + result.onTimeout(() -> { | |
| 73 | + logger.warn(String.format("设备配置操作超时, 设备未返回应答指令")); | |
| 74 | + // 释放rtpserver | |
| 75 | + RequestMessage msg = new RequestMessage(); | |
| 76 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + (XmlUtil.isEmpty(channelId) ? deviceId : channelId)); | |
| 77 | + JSONObject json = new JSONObject(); | |
| 78 | + json.put("DeviceID", deviceId); | |
| 79 | + json.put("Status", "Timeout"); | |
| 80 | + json.put("Description", "设备配置操作超时, 设备未返回应答指令"); | |
| 81 | + msg.setData(json); //("看守位控制操作超时, 设备未返回应答指令"); | |
| 82 | + resultHolder.invokeResult(msg); | |
| 83 | + }); | |
| 84 | + resultHolder.put(DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + (XmlUtil.isEmpty(channelId) ? deviceId : channelId), result); | |
| 85 | + return result; | |
| 86 | + } | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * 设备配置查询请求API接口 | |
| 90 | + * | |
| 91 | + * @param deviceId | |
| 92 | + */ | |
| 93 | + @GetMapping("/config/{deviceId}/query/{configType}") | |
| 94 | + public DeferredResult<ResponseEntity<String>> configDownloadApi(@PathVariable String deviceId, | |
| 95 | + @PathVariable String configType, | |
| 96 | + @RequestParam(required = false) String channelId) { | |
| 97 | + if (logger.isDebugEnabled()) { | |
| 98 | + logger.debug("设备状态查询API调用"); | |
| 99 | + } | |
| 100 | + Device device = storager.queryVideoDevice(deviceId); | |
| 101 | + cmder.deviceConfigQuery(device, channelId, configType, event -> { | |
| 102 | + Response response = event.getResponse(); | |
| 103 | + RequestMessage msg = new RequestMessage(); | |
| 104 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (XmlUtil.isEmpty(channelId) ? deviceId : channelId)); | |
| 105 | + msg.setData(String.format("获取设备配置失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 106 | + resultHolder.invokeResult(msg); | |
| 107 | + }); | |
| 108 | + DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String >> (3 * 1000L); | |
| 109 | + result.onTimeout(()->{ | |
| 110 | + logger.warn(String.format("获取设备配置超时")); | |
| 111 | + // 释放rtpserver | |
| 112 | + RequestMessage msg = new RequestMessage(); | |
| 113 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (XmlUtil.isEmpty(channelId) ? deviceId : channelId)); | |
| 114 | + msg.setData("Timeout. Device did not response to this command."); | |
| 115 | + resultHolder.invokeResult(msg); | |
| 116 | + }); | |
| 117 | + resultHolder.put(DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (XmlUtil.isEmpty(channelId) ? deviceId : channelId), result); | |
| 118 | + return result; | |
| 119 | + } | |
| 120 | + | |
| 121 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/device/DeviceControl.java
0 → 100644
| 1 | +/** | |
| 2 | + * 设备控制命令API接口 | |
| 3 | + * | |
| 4 | + * @author lawrencehj | |
| 5 | + * @date 2021年2月1日 | |
| 6 | + */ | |
| 7 | + | |
| 8 | +package com.genersoft.iot.vmp.vmanager.device; | |
| 9 | + | |
| 10 | +import javax.sip.message.Response; | |
| 11 | + | |
| 12 | +import com.alibaba.fastjson.JSONObject; | |
| 13 | +import com.genersoft.iot.vmp.gb28181.bean.Device; | |
| 14 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | |
| 15 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | |
| 16 | +import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; | |
| 17 | +import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; | |
| 18 | +import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | |
| 19 | + | |
| 20 | +import org.slf4j.Logger; | |
| 21 | +import org.slf4j.LoggerFactory; | |
| 22 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 23 | +import org.springframework.http.HttpStatus; | |
| 24 | +import org.springframework.http.ResponseEntity; | |
| 25 | +import org.springframework.web.bind.annotation.*; | |
| 26 | +import org.springframework.web.context.request.async.DeferredResult; | |
| 27 | + | |
| 28 | +@CrossOrigin | |
| 29 | +@RestController | |
| 30 | +@RequestMapping("/api") | |
| 31 | +public class DeviceControl { | |
| 32 | + | |
| 33 | + private final static Logger logger = LoggerFactory.getLogger(DeviceQuery.class); | |
| 34 | + | |
| 35 | + @Autowired | |
| 36 | + private IVideoManagerStorager storager; | |
| 37 | + | |
| 38 | + @Autowired | |
| 39 | + private SIPCommander cmder; | |
| 40 | + | |
| 41 | + @Autowired | |
| 42 | + private DeferredResultHolder resultHolder; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * 远程启动控制命令API接口 | |
| 46 | + * | |
| 47 | + * @param deviceId | |
| 48 | + */ | |
| 49 | + @GetMapping("/control/{deviceId}/teleboot") | |
| 50 | + @PostMapping("/control/{deviceId}/teleboot") | |
| 51 | + public ResponseEntity<String> teleBootApi(@PathVariable String deviceId) { | |
| 52 | + if (logger.isDebugEnabled()) { | |
| 53 | + logger.debug("设备远程启动API调用"); | |
| 54 | + } | |
| 55 | + Device device = storager.queryVideoDevice(deviceId); | |
| 56 | + boolean sucsess = cmder.teleBootCmd(device); | |
| 57 | + if (sucsess) { | |
| 58 | + JSONObject json = new JSONObject(); | |
| 59 | + json.put("DeviceID", deviceId); | |
| 60 | + json.put("Result", "OK"); | |
| 61 | + return new ResponseEntity<>(json.toJSONString(), HttpStatus.OK); | |
| 62 | + } else { | |
| 63 | + logger.warn("设备远程启动API调用失败!"); | |
| 64 | + return new ResponseEntity<String>("设备远程启动API调用失败!", HttpStatus.INTERNAL_SERVER_ERROR); | |
| 65 | + } | |
| 66 | + } | |
| 67 | + | |
| 68 | + /** | |
| 69 | + * 录像控制命令API接口 | |
| 70 | + * | |
| 71 | + * @param deviceId | |
| 72 | + * @param recordCmdStr Record:手动录像,StopRecord:停止手动录像 | |
| 73 | + * @param channelId 通道编码(可选) | |
| 74 | + */ | |
| 75 | + @GetMapping("/control/{deviceId}/record/{recordCmdStr}") | |
| 76 | + public DeferredResult<ResponseEntity<String>> recordApi(@PathVariable String deviceId, | |
| 77 | + @PathVariable String recordCmdStr, @RequestParam(required = false) String channelId) { | |
| 78 | + if (logger.isDebugEnabled()) { | |
| 79 | + logger.debug("开始/停止录像API调用"); | |
| 80 | + } | |
| 81 | + Device device = storager.queryVideoDevice(deviceId); | |
| 82 | + cmder.recordCmd(device, channelId, recordCmdStr, event -> { | |
| 83 | + Response response = event.getResponse(); | |
| 84 | + RequestMessage msg = new RequestMessage(); | |
| 85 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (XmlUtil.isEmpty(channelId) ? deviceId : channelId)); | |
| 86 | + msg.setData(String.format("开始/停止录像操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 87 | + resultHolder.invokeResult(msg); | |
| 88 | + }); | |
| 89 | + DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); | |
| 90 | + result.onTimeout(() -> { | |
| 91 | + logger.warn(String.format("开始/停止录像操作超时, 设备未返回应答指令")); | |
| 92 | + // 释放rtpserver | |
| 93 | + RequestMessage msg = new RequestMessage(); | |
| 94 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (XmlUtil.isEmpty(channelId) ? deviceId : channelId)); | |
| 95 | + msg.setData("Timeout. Device did not response to this command."); | |
| 96 | + resultHolder.invokeResult(msg); | |
| 97 | + }); | |
| 98 | + resultHolder.put(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (XmlUtil.isEmpty(channelId) ? deviceId : channelId), result); | |
| 99 | + return result; | |
| 100 | + } | |
| 101 | + | |
| 102 | + /** | |
| 103 | + * 报警布防/撤防命令API接口 | |
| 104 | + * | |
| 105 | + * @param deviceId | |
| 106 | + * @param guardCmdStr SetGuard:布防,ResetGuard:撤防 | |
| 107 | + */ | |
| 108 | + @GetMapping("/control/{deviceId}/guard/{guardCmdStr}") | |
| 109 | + public DeferredResult<ResponseEntity<String>> guardApi(@PathVariable String deviceId, @PathVariable String guardCmdStr) { | |
| 110 | + if (logger.isDebugEnabled()) { | |
| 111 | + logger.debug("布防/撤防API调用"); | |
| 112 | + } | |
| 113 | + Device device = storager.queryVideoDevice(deviceId); | |
| 114 | + cmder.guardCmd(device, guardCmdStr, event -> { | |
| 115 | + Response response = event.getResponse(); | |
| 116 | + RequestMessage msg = new RequestMessage(); | |
| 117 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId); | |
| 118 | + msg.setData(String.format("布防/撤防操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 119 | + resultHolder.invokeResult(msg); | |
| 120 | + }); | |
| 121 | + DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); | |
| 122 | + result.onTimeout(() -> { | |
| 123 | + logger.warn(String.format("布防/撤防操作超时, 设备未返回应答指令")); | |
| 124 | + // 释放rtpserver | |
| 125 | + RequestMessage msg = new RequestMessage(); | |
| 126 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId); | |
| 127 | + msg.setData("Timeout. Device did not response to this command."); | |
| 128 | + resultHolder.invokeResult(msg); | |
| 129 | + }); | |
| 130 | + resultHolder.put(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId, result); | |
| 131 | + return result; | |
| 132 | + } | |
| 133 | + | |
| 134 | + /** | |
| 135 | + * 报警复位API接口 | |
| 136 | + * | |
| 137 | + * @param deviceId | |
| 138 | + * @param alarmMethod 报警方式(可选) | |
| 139 | + * @param alarmType 报警类型(可选) | |
| 140 | + */ | |
| 141 | + @GetMapping("/control/{deviceId}/resetAlarm") | |
| 142 | + public DeferredResult<ResponseEntity<String>> resetAlarmApi(@PathVariable String deviceId, | |
| 143 | + @RequestParam(required = false) String alarmMethod, | |
| 144 | + @RequestParam(required = false) String alarmType) { | |
| 145 | + if (logger.isDebugEnabled()) { | |
| 146 | + logger.debug("报警复位API调用"); | |
| 147 | + } | |
| 148 | + Device device = storager.queryVideoDevice(deviceId); | |
| 149 | + cmder.alarmCmd(device, alarmMethod, alarmType, event -> { | |
| 150 | + Response response = event.getResponse(); | |
| 151 | + RequestMessage msg = new RequestMessage(); | |
| 152 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId); | |
| 153 | + msg.setData(String.format("报警复位操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 154 | + resultHolder.invokeResult(msg); | |
| 155 | + }); | |
| 156 | + DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); | |
| 157 | + result.onTimeout(() -> { | |
| 158 | + logger.warn(String.format("报警复位操作超时, 设备未返回应答指令")); | |
| 159 | + // 释放rtpserver | |
| 160 | + RequestMessage msg = new RequestMessage(); | |
| 161 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId); | |
| 162 | + msg.setData("Timeout. Device did not response to this command."); | |
| 163 | + resultHolder.invokeResult(msg); | |
| 164 | + }); | |
| 165 | + resultHolder.put(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + deviceId, result); | |
| 166 | + return result; | |
| 167 | + } | |
| 168 | + | |
| 169 | + /** | |
| 170 | + * 强制关键帧API接口 | |
| 171 | + * | |
| 172 | + * @param deviceId | |
| 173 | + * @param channelId | |
| 174 | + */ | |
| 175 | + @GetMapping("/control/{deviceId}/iFrame") | |
| 176 | + @PostMapping("/control/{deviceId}/iFrame") | |
| 177 | + public ResponseEntity<String> iFrame(@PathVariable String deviceId, | |
| 178 | + @RequestParam(required = false) String channelId) { | |
| 179 | + if (logger.isDebugEnabled()) { | |
| 180 | + logger.debug("强制关键帧API调用"); | |
| 181 | + } | |
| 182 | + Device device = storager.queryVideoDevice(deviceId); | |
| 183 | + boolean sucsess = cmder.iFrameCmd(device, channelId); | |
| 184 | + if (sucsess) { | |
| 185 | + JSONObject json = new JSONObject(); | |
| 186 | + json.put("DeviceID", deviceId); | |
| 187 | + json.put("ChannelID", channelId); | |
| 188 | + json.put("Result", "OK"); | |
| 189 | + return new ResponseEntity<>(json.toJSONString(), HttpStatus.OK); | |
| 190 | + } else { | |
| 191 | + logger.warn("强制关键帧API调用失败!"); | |
| 192 | + return new ResponseEntity<String>("强制关键帧API调用失败!", HttpStatus.INTERNAL_SERVER_ERROR); | |
| 193 | + } | |
| 194 | + } | |
| 195 | + | |
| 196 | + /** | |
| 197 | + * 看守位控制命令API接口 | |
| 198 | + * | |
| 199 | + * @param deviceId | |
| 200 | + * @param enabled 看守位使能1:开启,0:关闭 | |
| 201 | + * @param resetTime 自动归位时间间隔(可选) | |
| 202 | + * @param presetIndex 调用预置位编号(可选) | |
| 203 | + * @param channelId 通道编码(可选) | |
| 204 | + */ | |
| 205 | + @GetMapping("/control/{deviceId}/homePosition/{enabled}") | |
| 206 | + public DeferredResult<ResponseEntity<String>> homePositionApi(@PathVariable String deviceId, | |
| 207 | + @PathVariable String enabled, | |
| 208 | + @RequestParam(required = false) String resetTime, | |
| 209 | + @RequestParam(required = false) String presetIndex, | |
| 210 | + @RequestParam(required = false) String channelId) { | |
| 211 | + if (logger.isDebugEnabled()) { | |
| 212 | + logger.debug("报警复位API调用"); | |
| 213 | + } | |
| 214 | + Device device = storager.queryVideoDevice(deviceId); | |
| 215 | + cmder.homePositionCmd(device, channelId, enabled, resetTime, presetIndex, event -> { | |
| 216 | + Response response = event.getResponse(); | |
| 217 | + RequestMessage msg = new RequestMessage(); | |
| 218 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (XmlUtil.isEmpty(channelId) ? deviceId : channelId)); | |
| 219 | + msg.setData(String.format("看守位控制操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 220 | + resultHolder.invokeResult(msg); | |
| 221 | + }); | |
| 222 | + DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); | |
| 223 | + result.onTimeout(() -> { | |
| 224 | + logger.warn(String.format("看守位控制操作超时, 设备未返回应答指令")); | |
| 225 | + // 释放rtpserver | |
| 226 | + RequestMessage msg = new RequestMessage(); | |
| 227 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (XmlUtil.isEmpty(channelId) ? deviceId : channelId)); | |
| 228 | + JSONObject json = new JSONObject(); | |
| 229 | + json.put("DeviceID", deviceId); | |
| 230 | + json.put("Status", "Timeout"); | |
| 231 | + json.put("Description", "看守位控制操作超时, 设备未返回应答指令"); | |
| 232 | + msg.setData(json); //("看守位控制操作超时, 设备未返回应答指令"); | |
| 233 | + resultHolder.invokeResult(msg); | |
| 234 | + }); | |
| 235 | + resultHolder.put(DeferredResultHolder.CALLBACK_CMD_DEVICECONTROL + (XmlUtil.isEmpty(channelId) ? deviceId : channelId), result); | |
| 236 | + return result; | |
| 237 | + } | |
| 238 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/device/DeviceController.java renamed to src/main/java/com/genersoft/iot/vmp/vmanager/device/DeviceQuery.java
| ... | ... | @@ -17,6 +17,7 @@ import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 17 | 17 | import com.genersoft.iot.vmp.gb28181.event.DeviceOffLineDetector; |
| 18 | 18 | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; |
| 19 | 19 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; |
| 20 | +import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; | |
| 20 | 21 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 21 | 22 | |
| 22 | 23 | import javax.sip.message.Response; |
| ... | ... | @@ -24,9 +25,9 @@ import javax.sip.message.Response; |
| 24 | 25 | @CrossOrigin |
| 25 | 26 | @RestController |
| 26 | 27 | @RequestMapping("/api") |
| 27 | -public class DeviceController { | |
| 28 | +public class DeviceQuery { | |
| 28 | 29 | |
| 29 | - private final static Logger logger = LoggerFactory.getLogger(DeviceController.class); | |
| 30 | + private final static Logger logger = LoggerFactory.getLogger(DeviceQuery.class); | |
| 30 | 31 | |
| 31 | 32 | @Autowired |
| 32 | 33 | private IVideoManagerStorager storager; |
| ... | ... | @@ -77,11 +78,9 @@ public class DeviceController { |
| 77 | 78 | int page, int count, |
| 78 | 79 | @RequestParam(required = false) String query, |
| 79 | 80 | @RequestParam(required = false) Boolean online, |
| 80 | - @RequestParam(required = false) Boolean channelType | |
| 81 | - ){ | |
| 82 | - | |
| 81 | + @RequestParam(required = false) Boolean channelType) { | |
| 83 | 82 | if (logger.isDebugEnabled()) { |
| 84 | - logger.debug("查询所有视频设备API调用"); | |
| 83 | + logger.debug("查询视频设备通道API调用"); | |
| 85 | 84 | } |
| 86 | 85 | if (StringUtils.isEmpty(query)) { |
| 87 | 86 | query = null; |
| ... | ... | @@ -135,8 +134,8 @@ public class DeviceController { |
| 135 | 134 | json.put("deviceId", deviceId); |
| 136 | 135 | return new ResponseEntity<>(json.toString(),HttpStatus.OK); |
| 137 | 136 | } else { |
| 138 | - logger.warn("设备预览API调用失败!"); | |
| 139 | - return new ResponseEntity<String>("设备预览API调用失败!", HttpStatus.INTERNAL_SERVER_ERROR); | |
| 137 | + logger.warn("设备信息删除API调用失败!"); | |
| 138 | + return new ResponseEntity<String>("设备信息删除API调用失败!", HttpStatus.INTERNAL_SERVER_ERROR); | |
| 140 | 139 | } |
| 141 | 140 | } |
| 142 | 141 | |
| ... | ... | @@ -157,7 +156,7 @@ public class DeviceController { |
| 157 | 156 | @RequestParam(required = false) Boolean channelType){ |
| 158 | 157 | |
| 159 | 158 | if (logger.isDebugEnabled()) { |
| 160 | - logger.debug("查询所有视频设备API调用"); | |
| 159 | + logger.debug("查询所有视频通道API调用"); | |
| 161 | 160 | } |
| 162 | 161 | DeviceChannel deviceChannel = storager.queryChannel(deviceId,channelId); |
| 163 | 162 | if (deviceChannel == null) { |
| ... | ... | @@ -183,4 +182,74 @@ public class DeviceController { |
| 183 | 182 | storager.updateDevice(device); |
| 184 | 183 | return new ResponseEntity<>(null,HttpStatus.OK); |
| 185 | 184 | } |
| 185 | + | |
| 186 | + /** | |
| 187 | + * 设备状态查询请求API接口 | |
| 188 | + * | |
| 189 | + * @param deviceId | |
| 190 | + */ | |
| 191 | + @GetMapping("/devices/{deviceId}/status") | |
| 192 | + public DeferredResult<ResponseEntity<String>> deviceStatusApi(@PathVariable String deviceId) { | |
| 193 | + if (logger.isDebugEnabled()) { | |
| 194 | + logger.debug("设备状态查询API调用"); | |
| 195 | + } | |
| 196 | + Device device = storager.queryVideoDevice(deviceId); | |
| 197 | + cmder.deviceStatusQuery(device, event -> { | |
| 198 | + Response response = event.getResponse(); | |
| 199 | + RequestMessage msg = new RequestMessage(); | |
| 200 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId); | |
| 201 | + msg.setData(String.format("获取设备状态失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 202 | + resultHolder.invokeResult(msg); | |
| 203 | + }); | |
| 204 | + DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(2*1000L); | |
| 205 | + result.onTimeout(()->{ | |
| 206 | + logger.warn(String.format("获取设备状态超时")); | |
| 207 | + // 释放rtpserver | |
| 208 | + RequestMessage msg = new RequestMessage(); | |
| 209 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId); | |
| 210 | + msg.setData("Timeout. Device did not response to this command."); | |
| 211 | + resultHolder.invokeResult(msg); | |
| 212 | + }); | |
| 213 | + resultHolder.put(DeferredResultHolder.CALLBACK_CMD_DEVICESTATUS + deviceId, result); | |
| 214 | + return result; | |
| 215 | + } | |
| 216 | + | |
| 217 | + /** | |
| 218 | + * 设备报警查询请求API接口 | |
| 219 | + * | |
| 220 | + * @param deviceId | |
| 221 | + */ | |
| 222 | + @GetMapping("/alarm/{deviceId}") | |
| 223 | + public DeferredResult<ResponseEntity<String>> alarmApi(@PathVariable String deviceId, | |
| 224 | + @RequestParam(required = false) String startPriority, | |
| 225 | + @RequestParam(required = false) String endPriority, | |
| 226 | + @RequestParam(required = false) String alarmMethod, | |
| 227 | + @RequestParam(required = false) String alarmType, | |
| 228 | + @RequestParam(required = false) String startTime, | |
| 229 | + @RequestParam(required = false) String endTime) { | |
| 230 | + if (logger.isDebugEnabled()) { | |
| 231 | + logger.debug("设备报警查询API调用"); | |
| 232 | + } | |
| 233 | + Device device = storager.queryVideoDevice(deviceId); | |
| 234 | + cmder.alarmInfoQuery(device, startPriority, endPriority, alarmMethod, alarmType, startTime, endTime, event -> { | |
| 235 | + Response response = event.getResponse(); | |
| 236 | + RequestMessage msg = new RequestMessage(); | |
| 237 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_ALARM + deviceId); | |
| 238 | + msg.setData(String.format("设备报警查询失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 239 | + resultHolder.invokeResult(msg); | |
| 240 | + }); | |
| 241 | + DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String >> (3 * 1000L); | |
| 242 | + result.onTimeout(()->{ | |
| 243 | + logger.warn(String.format("设备报警查询超时")); | |
| 244 | + // 释放rtpserver | |
| 245 | + RequestMessage msg = new RequestMessage(); | |
| 246 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_ALARM + deviceId); | |
| 247 | + msg.setData("设备报警查询超时"); | |
| 248 | + resultHolder.invokeResult(msg); | |
| 249 | + }); | |
| 250 | + resultHolder.put(DeferredResultHolder.CALLBACK_CMD_ALARM + deviceId, result); | |
| 251 | + return result; | |
| 252 | + } | |
| 253 | + | |
| 254 | + | |
| 186 | 255 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/ptz/PtzController.java
| ... | ... | @@ -5,14 +5,16 @@ import org.slf4j.LoggerFactory; |
| 5 | 5 | import org.springframework.beans.factory.annotation.Autowired; |
| 6 | 6 | import org.springframework.http.HttpStatus; |
| 7 | 7 | import org.springframework.http.ResponseEntity; |
| 8 | -import org.springframework.web.bind.annotation.CrossOrigin; | |
| 9 | -import org.springframework.web.bind.annotation.PathVariable; | |
| 10 | -import org.springframework.web.bind.annotation.PostMapping; | |
| 11 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 12 | -import org.springframework.web.bind.annotation.RestController; | |
| 8 | +import org.springframework.web.bind.annotation.*; | |
| 9 | +import org.springframework.web.context.request.async.DeferredResult; | |
| 10 | + | |
| 11 | +import javax.sip.message.Response; | |
| 13 | 12 | |
| 14 | 13 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 14 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; | |
| 15 | +import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; | |
| 15 | 16 | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; |
| 17 | +import com.genersoft.iot.vmp.gb28181.utils.XmlUtil; | |
| 16 | 18 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| 17 | 19 | |
| 18 | 20 | @CrossOrigin |
| ... | ... | @@ -28,6 +30,9 @@ public class PtzController { |
| 28 | 30 | @Autowired |
| 29 | 31 | private IVideoManagerStorager storager; |
| 30 | 32 | |
| 33 | + @Autowired | |
| 34 | + private DeferredResultHolder resultHolder; | |
| 35 | + | |
| 31 | 36 | /*** |
| 32 | 37 | * 云台控制 |
| 33 | 38 | * @param deviceId 设备id |
| ... | ... | @@ -49,16 +54,18 @@ public class PtzController { |
| 49 | 54 | cmder.frontEndCmd(device, channelId, cmdCode, horizonSpeed, verticalSpeed, zoomSpeed); |
| 50 | 55 | return new ResponseEntity<String>("success",HttpStatus.OK); |
| 51 | 56 | } |
| 52 | - // public ResponseEntity<String> ptz(@PathVariable String deviceId,@PathVariable String channelId,int leftRight, int upDown, int inOut, int moveSpeed, int zoomSpeed){ | |
| 53 | - | |
| 54 | - // if (logger.isDebugEnabled()) { | |
| 55 | - // logger.debug(String.format("设备云台控制 API调用,deviceId:%s ,channelId:%s ,leftRight:%d ,upDown:%d ,inOut:%d ,moveSpeed:%d ,zoomSpeed:%d",deviceId, channelId, leftRight, upDown, inOut, moveSpeed, zoomSpeed)); | |
| 56 | - // } | |
| 57 | - // Device device = storager.queryVideoDevice(deviceId); | |
| 58 | - | |
| 59 | - // cmder.ptzCmd(device, channelId, leftRight, upDown, inOut, moveSpeed, zoomSpeed); | |
| 60 | - // return new ResponseEntity<String>("success",HttpStatus.OK); | |
| 61 | - // } | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * 通用前端控制命令API接口 | |
| 60 | + * | |
| 61 | + * @param deviceId | |
| 62 | + * @param channelId | |
| 63 | + * @param cmdCode | |
| 64 | + * @param parameter1 | |
| 65 | + * @param parameter2 | |
| 66 | + * @param combindCode2 | |
| 67 | + * @return | |
| 68 | + */ | |
| 62 | 69 | @PostMapping("/frontEndCommand/{deviceId}/{channelId}") |
| 63 | 70 | public ResponseEntity<String> frontEndCommand(@PathVariable String deviceId,@PathVariable String channelId,int cmdCode, int parameter1, int parameter2, int combindCode2){ |
| 64 | 71 | |
| ... | ... | @@ -70,4 +77,37 @@ public class PtzController { |
| 70 | 77 | cmder.frontEndCmd(device, channelId, cmdCode, parameter1, parameter2, combindCode2); |
| 71 | 78 | return new ResponseEntity<String>("success",HttpStatus.OK); |
| 72 | 79 | } |
| 80 | + | |
| 81 | + /** | |
| 82 | + * 预置位查询命令API接口 | |
| 83 | + * | |
| 84 | + * @param deviceId | |
| 85 | + * @param channelId | |
| 86 | + * @return | |
| 87 | + */ | |
| 88 | + @GetMapping("/presetQuery/{deviceId}/{channelId}") | |
| 89 | + public DeferredResult<ResponseEntity<String>> presetQueryApi(@PathVariable String deviceId, @PathVariable String channelId) { | |
| 90 | + if (logger.isDebugEnabled()) { | |
| 91 | + logger.debug("设备预置位查询API调用"); | |
| 92 | + } | |
| 93 | + Device device = storager.queryVideoDevice(deviceId); | |
| 94 | + cmder.presetQuery(device, channelId, event -> { | |
| 95 | + Response response = event.getResponse(); | |
| 96 | + RequestMessage msg = new RequestMessage(); | |
| 97 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (XmlUtil.isEmpty(channelId) ? deviceId : channelId)); | |
| 98 | + msg.setData(String.format("获取设备预置位失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); | |
| 99 | + resultHolder.invokeResult(msg); | |
| 100 | + }); | |
| 101 | + DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String >> (3 * 1000L); | |
| 102 | + result.onTimeout(()->{ | |
| 103 | + logger.warn(String.format("获取设备预置位超时")); | |
| 104 | + // 释放rtpserver | |
| 105 | + RequestMessage msg = new RequestMessage(); | |
| 106 | + msg.setId(DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (XmlUtil.isEmpty(channelId) ? deviceId : channelId)); | |
| 107 | + msg.setData("获取设备预置位超时"); | |
| 108 | + resultHolder.invokeResult(msg); | |
| 109 | + }); | |
| 110 | + resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PRESETQUERY + (XmlUtil.isEmpty(channelId) ? deviceId : channelId), result); | |
| 111 | + return result; | |
| 112 | + } | |
| 73 | 113 | } | ... | ... |