| | |
| | | requireText(action, "action"); |
| | | requireText(command, "command"); |
| | | |
| | | Integer[] directions = resolvePtzDirections(command); |
| | | if (directions.length > 1) { |
| | | JSONObject result = null; |
| | | for (Integer direction : directions) { |
| | | result = ptzControlByDirection(deviceSerial, channelNo, action, direction, speed); |
| | | if (!SUCCESS_CODE.equals(result.getString("code"))) { |
| | | return result; |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | return ptzControlByDirection(deviceSerial, channelNo, action, directions[0], speed); |
| | | } |
| | | |
| | | private JSONObject ptzControlByDirection(String deviceSerial, Integer channelNo, String action, Integer direction, Integer speed) { |
| | | Map<String, Object> form = new LinkedHashMap<>(); |
| | | form.put("deviceSerial", deviceSerial); |
| | | form.put("channelNo", channelNo == null ? 1 : channelNo); |
| | | form.put("direction", direction); |
| | | form.put("direction", resolvePtzDirection(command)); |
| | | if ("start".equalsIgnoreCase(action)) { |
| | | form.put("speed", normalizePtzSpeed(speed)); |
| | | return postFormWithToken("/api/lapp/device/ptz/start", form); |
| | |
| | | throw new IllegalArgumentException("action仅支持start/stop"); |
| | | } |
| | | |
| | | private Integer[] resolvePtzDirections(String command) { |
| | | private Integer resolvePtzDirection(String command) { |
| | | switch (command) { |
| | | case "up": |
| | | return new Integer[]{0}; |
| | | return 0; |
| | | case "down": |
| | | return new Integer[]{1}; |
| | | return 1; |
| | | case "left": |
| | | return new Integer[]{2}; |
| | | return 2; |
| | | case "right": |
| | | return new Integer[]{3}; |
| | | return 3; |
| | | case "upleft": |
| | | return new Integer[]{0, 2}; |
| | | return 4; |
| | | case "downleft": |
| | | return new Integer[]{1, 2}; |
| | | return 5; |
| | | case "upright": |
| | | return new Integer[]{0, 3}; |
| | | return 6; |
| | | case "downright": |
| | | return new Integer[]{1, 3}; |
| | | return 7; |
| | | case "zoomin": |
| | | return new Integer[]{8}; |
| | | return 8; |
| | | case "zoomout": |
| | | return new Integer[]{9}; |
| | | return 9; |
| | | case "focusin": |
| | | return new Integer[]{10}; |
| | | return 10; |
| | | case "focusout": |
| | | return new Integer[]{11}; |
| | | return 11; |
| | | default: |
| | | throw new IllegalArgumentException("不支持的云台控制命令:" + command); |
| | | } |