| | |
| | | package com.ard.tianyu.service.control; |
| | | |
| | | import com.ard.common.exception.NoPermissionException; |
| | | import com.ard.common.exception.ControlException; |
| | | import com.ard.common.utils.SecurityUtils; |
| | | import com.ard.tianyu.websocket.domain.UavControlType; |
| | | import com.ard.tianyu.websocket.handler.UavControlManager; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | /** |
| | |
| | | requestMap.put(boxSn, requester); |
| | | uavControlManager.sendControlRequest(controller, boxSn, controlType.getType(), requester); |
| | | } else { |
| | | throw new NoPermissionException("当前已拥有控制权"); |
| | | throw new ControlException("当前已拥有控制权"); |
| | | } |
| | | return false; |
| | | } |
| | |
| | | Long requester = requestMap.get(boxSn); |
| | | |
| | | if (requester == null || requester.equals(controller)) { |
| | | throw new NoPermissionException("无控制请求"); |
| | | throw new ControlException("无控制请求"); |
| | | } |
| | | |
| | | if (approve) { |
| | |
| | | ConcurrentHashMap<String, Long> controlMap = getControlMap(controlType); |
| | | |
| | | if (!controller.equals(controlMap.get(boxSn))) { |
| | | throw new NoPermissionException("没有该设备的" + controlType.getType().toUpperCase() + "控制权"); |
| | | throw new ControlException("没有该设备的" + controlType.getType().toUpperCase() + "控制权"); |
| | | } |
| | | |
| | | controlMap.remove(boxSn); |
| | |
| | | UavControlType controlType = UavControlType.fromString(type); |
| | | return getControlMap(controlType).get(boxSn); |
| | | } |
| | | |
| | | public Map<String,Long> getCurrentController(String boxSn) { |
| | | Long flyController = uavFlyControlMap.get(boxSn); |
| | | Map<String,Long> map=new HashMap<>(); |
| | | map.put("flyController",flyController); |
| | | Long payloadController = uavPayloadControlMap.get(boxSn); |
| | | map.put("payloadController",payloadController); |
| | | return map; |
| | | } |
| | | /** |
| | | * 根据控制类型获取对应的控制 Map |
| | | */ |