| | |
| | | import org.springframework.integration.annotation.ServiceActivator; |
| | | import org.springframework.messaging.MessageHeaders; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.StringUtils; |
| | | |
| | | import java.util.*; |
| | | |
| | |
| | | RedisOpsUtils.setWithExpire(serviceIdentifier + RedisConst.DELIMITER + bid, sn, |
| | | RedisConst.DEVICE_ALIVE_SECOND * RedisConst.DEVICE_ALIVE_SECOND); |
| | | } |
| | | |
| | | //当执行返航指令时,删除图斑redis |
| | | if (serviceIdentifier == "return_home"){ |
| | | if (RedisOpsUtils.checkExist("tuban:" + sn)){ |
| | | RedisOpsUtils.del("tuban:" + sn); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | return ResponseResult.success(); |
| | | } |
| | | |
| | |
| | | eventsReceiver.getStatus().getMessage() : eventsReceiver.getResult().getErrorMsg()) |
| | | .result(eventsReceiver.getResult().getErrorCode()) |
| | | .build()); |
| | | |
| | | //当飞向目标点成功后 |
| | | if (eventsReceiver.getStatus().equals(FlyToStatusEnum.WAYLINE_OK)) { |
| | | JSONObject jsonObject = (JSONObject) RedisOpsUtils.get("tuban:" + dockSn); |
| | | if (jsonObject != null) { |
| | | List<PointPOJO> targetList = (List<PointPOJO>) jsonObject.get("targetList"); |
| | | int curIndex = (Integer) jsonObject.get("curIndex"); |
| | | String payloadIndex = jsonObject.getString("payloadIndex"); |
| | | flyToNextPoint(targetList, curIndex, dockSn, payloadIndex); |
| | | flyToNextPoint(targetList, curIndex+1, dockSn, payloadIndex); |
| | | } |
| | | } |
| | | return receiver; |
| | | } |
| | | |
| | | private ResponseResult flyToNextPoint(List<PointPOJO> targetList, int curIndex, String sn, String payloadIndex) throws Exception { |
| | | curIndex = curIndex + 1; |
| | | @Override |
| | | public ResponseResult flyToNextPoint(List<PointPOJO> targetList, int curIndex, String sn, String payloadIndex) throws Exception { |
| | | //当无人机状态为人工时再发布下一个命令 |
| | | while (true) { |
| | | Optional<DeviceDTO> dockOpt = deviceRedisService.getDeviceOnline(sn); |
| | | DeviceModeCodeEnum deviceMode = deviceService.getDeviceMode(dockOpt.get().getChildDeviceSn()); |
| | | |
| | | if (DeviceModeCodeEnum.MANUAL == deviceMode) { |
| | | |
| | | //执行拍照 |
| | | ResponseResult responseResult = takePhoto(sn, payloadIndex); |
| | | |
| | | //发布飞行指令 |
| | | if (curIndex == targetList.size()) { |
| | | //当前是最后一个点,返航 |
| | | ResponseResult returnHome = controlDockDebug(sn, "return_home", null); |
| | |
| | | pointDTO.setLatitude(targetList.get(curIndex).getLat()); |
| | | pointDTOS.add(pointDTO); |
| | | flyToPointParam.setPoints(pointDTOS); |
| | | |
| | | //执行拍照 |
| | | ResponseResult responseResult = takePhoto(sn, payloadIndex); |
| | | |
| | | //发布下一个飞行指令 |
| | | ResponseResult flyToRes = flyToPoint(sn, flyToPointParam); |
| | |
| | | @Override |
| | | public ResponseResult takeoffToPoint(String sn, TakeoffToPointParam param) { |
| | | checkTakeoffCondition(sn); |
| | | |
| | | param.setFlightId(UUID.randomUUID().toString()); |
| | | if (!StringUtils.hasText(param.getFlightId())){ |
| | | param.setFlightId(UUID.randomUUID().toString()); |
| | | } |
| | | ServiceReply reply = messageSenderService.publishServicesTopic(sn, DroneControlMethodEnum.TAKE_OFF_TO_POINT.getMethod(), param, param.getFlightId()); |
| | | return ResponseResult.CODE_SUCCESS != reply.getResult() ? |
| | | ResponseResult.error("无人机起飞失败 " + reply.getResult()) |
| | |
| | | } |
| | | |
| | | @Override |
| | | public ResponseResult payloadCommands(PayloadCommandsParam param, String bid) throws Exception { |
| | | param.getCmd().getClazz() |
| | | .getDeclaredConstructor(DronePayloadParam.class) |
| | | .newInstance(param.getData()) |
| | | .checkCondition(param.getSn()); |
| | | |
| | | Long timestamp = System.currentTimeMillis(); |
| | | |
| | | //拍照事件存redis |
| | | RedisOpsUtils.hashSet(RedisConst.COMMANDS_PREFIX + param.getSn() + RedisConst.DELIMITER + bid,bid,timestamp); |
| | | |
| | | ServiceReply serviceReply = messageSenderService.publishServicesTopic(param.getSn(), param.getCmd().getCmd(), param.getData(),bid,timestamp); |
| | | return ResponseResult.CODE_SUCCESS != serviceReply.getResult() ? |
| | | ResponseResult.error(serviceReply.getResult(), "错误码:" + serviceReply.getResult()) |
| | | : ResponseResult.success(bid); |
| | | } |
| | | |
| | | @Override |
| | | public ResponseResult requestsConfig(String sn, String method, RequestsParam param) { |
| | | ServiceReply serviceReply = messageSenderService.publishRequestsTopic(sn, method, param); |
| | | return ResponseResult.CODE_SUCCESS != serviceReply.getResult() ? |