| | |
| | | |
| | | package com.genersoft.iot.vmp.vmanager.gb28181.device; |
| | | |
| | | import javax.sip.message.Response; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | 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.gb28181.utils.XmlUtil; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| | | |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.context.request.async.DeferredResult; |
| | | |
| | | import java.util.UUID; |
| | | |
| | | @Api(tags = "国标设备配置") |
| | | @CrossOrigin |
| | |
| | | private final static Logger logger = LoggerFactory.getLogger(DeviceQuery.class); |
| | | |
| | | @Autowired |
| | | private IVideoManagerStorager storager; |
| | | private IVideoManagerStorage storager; |
| | | |
| | | @Autowired |
| | | private SIPCommander cmder; |
| | |
| | | * @param heartBeatCount 心跳计数 |
| | | * @return |
| | | */ |
| | | @ApiOperation("看守位控制命令") |
| | | @ApiOperation("基本配置设置命令") |
| | | @GetMapping("/basicParam/{deviceId}") |
| | | @ApiImplicitParams({ |
| | | @ApiImplicitParam(name = "deviceId", value ="设备ID" ,dataTypeClass = String.class), |
| | |
| | | @ApiImplicitParam(name = "heartBeatCount", value ="心跳计数" ,dataTypeClass = String.class), |
| | | }) |
| | | public DeferredResult<ResponseEntity<String>> homePositionApi(@PathVariable String deviceId, |
| | | @RequestParam(required = false) String channelId, |
| | | String channelId, |
| | | @RequestParam(required = false) String name, |
| | | @RequestParam(required = false) String expiration, |
| | | @RequestParam(required = false) String heartBeatInterval, |
| | |
| | | logger.debug("报警复位API调用"); |
| | | } |
| | | 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 -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + (XmlUtil.isEmpty(channelId) ? deviceId : channelId)); |
| | | msg.setData(String.format("设备配置操作失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | 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); |
| | |
| | | logger.warn(String.format("设备配置操作超时, 设备未返回应答指令")); |
| | | // 释放rtpserver |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + (XmlUtil.isEmpty(channelId) ? deviceId : channelId)); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | JSONObject json = new JSONObject(); |
| | | json.put("DeviceID", deviceId); |
| | | json.put("Status", "Timeout"); |
| | |
| | | msg.setData(json); //("看守位控制操作超时, 设备未返回应答指令"); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | resultHolder.put(DeferredResultHolder.CALLBACK_CMD_DEVICECONFIG + (XmlUtil.isEmpty(channelId) ? deviceId : channelId), result); |
| | | resultHolder.put(key, uuid, result); |
| | | return result; |
| | | } |
| | | |
| | |
| | | if (logger.isDebugEnabled()) { |
| | | logger.debug("设备状态查询API调用"); |
| | | } |
| | | String key = DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (StringUtils.isEmpty(channelId) ? deviceId : channelId); |
| | | String uuid = UUID.randomUUID().toString(); |
| | | Device device = storager.queryVideoDevice(deviceId); |
| | | cmder.deviceConfigQuery(device, channelId, configType, event -> { |
| | | Response response = event.getResponse(); |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (XmlUtil.isEmpty(channelId) ? deviceId : channelId)); |
| | | msg.setData(String.format("获取设备配置失败,错误码: %s, %s", response.getStatusCode(), response.getReasonPhrase())); |
| | | 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); |
| | |
| | | logger.warn(String.format("获取设备配置超时")); |
| | | // 释放rtpserver |
| | | RequestMessage msg = new RequestMessage(); |
| | | msg.setId(DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (XmlUtil.isEmpty(channelId) ? deviceId : channelId)); |
| | | msg.setId(uuid); |
| | | msg.setKey(key); |
| | | msg.setData("Timeout. Device did not response to this command."); |
| | | resultHolder.invokeResult(msg); |
| | | }); |
| | | resultHolder.put(DeferredResultHolder.CALLBACK_CMD_CONFIGDOWNLOAD + (XmlUtil.isEmpty(channelId) ? deviceId : channelId), result); |
| | | resultHolder.put(key, uuid, result); |
| | | return result; |
| | | } |
| | | |