| | |
| | | package com.genersoft.iot.vmp.vmanager.gb28181.device; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.genersoft.iot.vmp.conf.exception.ControllerException; |
| | | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| | | |
| | | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.util.ObjectUtils; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.context.request.async.DeferredResult; |
| | | |
| | | import javax.sip.InvalidArgumentException; |
| | | import javax.sip.SipException; |
| | | import java.text.ParseException; |
| | | import java.util.UUID; |
| | | |
| | | @Tag(name = "国标设备配置") |
| | |
| | | @Parameter(name = "expiration", description = "到期时间") |
| | | @Parameter(name = "heartBeatInterval", description = "心跳间隔") |
| | | @Parameter(name = "heartBeatCount", description = "心跳计数") |
| | | public DeferredResult<ResponseEntity<String>> homePositionApi(@PathVariable String deviceId, |
| | | public DeferredResult<String> homePositionApi(@PathVariable String deviceId, |
| | | String channelId, |
| | | @RequestParam(required = false) String name, |
| | | @RequestParam(required = false) String expiration, |
| | |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | String uuid = UUID.randomUUID().toString(); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + deviceId + channelId; |
| | | cmder.deviceBasicConfigCmd(device, channelId, name, expiration, heartBeatInterval, heartBeatCount, event -> { |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | msg.setData(String.format("设备配置操作失败,错误码: %s, %s", event.statusCode, event.msg)); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L); |
| | | try { |
| | | cmder.deviceBasicConfigCmd(device, channelId, name, expiration, heartBeatInterval, heartBeatCount, event -> { |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | msg.setData(String.format("设备配置操作失败,错误码: %s, %s", event.statusCode, event.msg)); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | } catch (InvalidArgumentException | SipException | ParseException e) { |
| | | logger.error("[命令发送失败] 设备配置: {}", e.getMessage()); |
| | | throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage()); |
| | | } |
| | | DeferredResult<String> result = new DeferredResult<String>(3 * 1000L); |
| | | result.onTimeout(() -> { |
| | | logger.warn(String.format("设备配置操作超时, 设备未返回应答指令")); |
| | | // 释放rtpserver |
| | |
| | | @Parameter(name = "channelId", description = "通道国标编号", required = true) |
| | | @Parameter(name = "configType", description = "配置类型") |
| | | @GetMapping("/query/{deviceId}/{configType}") |
| | | public DeferredResult<ResponseEntity<String>> configDownloadApi(@PathVariable String deviceId, |
| | | public DeferredResult<String> configDownloadApi(@PathVariable String deviceId, |
| | | @PathVariable String configType, |
| | | @RequestParam(required = false) String channelId) { |
| | | if (logger.isDebugEnabled()) { |
| | | logger.debug("设备状态查询API调用"); |
| | | } |
| | | String key = DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (StringUtils.isEmpty(channelId) ? deviceId : channelId); |
| | | String key = DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (ObjectUtils.isEmpty(channelId) ? deviceId : channelId); |
| | | String uuid = UUID.randomUUID().toString(); |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | cmder.deviceConfigQuery(device, channelId, configType, event -> { |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | msg.setData(String.format("获取设备配置失败,错误码: %s, %s", event.statusCode, event.msg)); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String >> (3 * 1000L); |
| | | try { |
| | | cmder.deviceConfigQuery(device, channelId, configType, event -> { |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | msg.setData(String.format("获取设备配置失败,错误码: %s, %s", event.statusCode, event.msg)); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | } catch (InvalidArgumentException | SipException | ParseException e) { |
| | | logger.error("[命令发送失败] 获取设备配置: {}", e.getMessage()); |
| | | throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage()); |
| | | } |
| | | DeferredResult<String> result = new DeferredResult<String > (3 * 1000L); |
| | | result.onTimeout(()->{ |
| | | logger.warn(String.format("获取设备配置超时")); |
| | | // 释放rtpserver |