| | |
| | | import com.ard.common.utils.ByteUtils; |
| | | import com.ard.work.aspect.annotation.CheckTakeoffAltitude; |
| | | import com.ard.work.aspect.annotation.CheckControlRight; |
| | | import com.ard.work.component.netty.TcpClientSession; |
| | | import com.ard.work.component.netty.TyTcpClientManager; |
| | | import com.ard.work.component.netty.command.BaseCmd; |
| | | import com.ard.work.component.netty.command.camera.*; |
| | | import com.ard.work.component.netty.command.manual.*; |
| | |
| | | import com.ard.work.component.netty.command.settings.*; |
| | | import com.ard.work.component.netty.command.speaker.*; |
| | | import com.ard.work.component.netty.command.wayline.*; |
| | | import com.ard.work.config.TyConfiguration; |
| | | import com.ard.work.domain.dto.camera.*; |
| | | import com.ard.work.domain.dto.manual.*; |
| | | import com.ard.work.domain.dto.speaker.*; |
| | | import com.ard.work.domain.dto.wayline.*; |
| | | import com.ard.work.domain.entity.ArdDroneInfo; |
| | | import com.ard.work.domain.entity.ArdServerInfo; |
| | | import com.ard.work.domain.receiver.*; |
| | | import com.ard.work.component.forest.TyClient; |
| | | import com.ard.work.domain.cache.TyTcpServerCache; |
| | | import com.ard.work.domain.cache.UavSignalInfoCache; |
| | | import com.ard.work.domain.cache.UavStateCache; |
| | | import com.ard.work.domain.cache.UavTelemetryDataCache; |
| | |
| | | import com.ard.work.domain.dto.signal.SignalInfo; |
| | | import com.ard.work.domain.dto.state.UavState; |
| | | import com.ard.work.domain.dto.telemetry.TelemetryData; |
| | | import com.ard.work.component.netty.NettyTcpClient; |
| | | import com.ard.work.component.netty.command.control.AbsAngleControlCmd; |
| | | import com.ard.work.component.netty.command.control.AngleControlCmd; |
| | | import com.ard.work.component.netty.command.control.SpeedControlCmd; |
| | |
| | | import com.ard.work.component.netty.command.real.UavTelemetryDataCmd; |
| | | import com.ard.work.component.netty.handler.ErrorCodeEnum; |
| | | import com.ard.work.component.netty.protobuf.TelemetryDataPB; |
| | | import com.ard.work.service.IArdDroneService; |
| | | import com.ard.work.service.IArdServerService; |
| | | import com.ard.work.service.ITyService; |
| | | import com.ard.work.domain.message.UavControlType; |
| | | import io.netty.channel.Channel; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.net.InetSocketAddress; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | import static com.ard.work.component.netty.TyTcpClientManager.channels; |
| | | |
| | | /** |
| | | * TyServiceImpl |
| | |
| | | @Slf4j |
| | | @Service |
| | | public class TyServiceImpl implements ITyService { |
| | | |
| | | @Resource |
| | | private IArdServerService ardServerService; |
| | | @Resource |
| | | private IArdDroneService ardDroneService; |
| | | @Resource |
| | | private TyClient tyClient; |
| | | |
| | | @Resource |
| | | private TyConfiguration tyConfiguration; |
| | | |
| | | |
| | | /** |
| | | * 获取天宇token信息 |
| | | * 获取六合token信息 |
| | | * |
| | | * @return AccessTokenReceiver |
| | | */ |
| | | @Override |
| | | public AccessTokenReceiver getAccessToken() { |
| | | return tyConfiguration.getAccessToken(); |
| | | public AccessTokenReceiver getAccessToken(String serverId) { |
| | | return ardServerService.getAccessToken(serverId); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public List<BoxInfoReceiver> getBoxList() { |
| | | //请求云盒列表 |
| | | try { |
| | | TyHttpCommonReceiver<List<BoxInfoReceiver>> boxListReceiver = tyClient.getBoxList(); |
| | | return boxListReceiver.getContent(); |
| | | } catch (Exception e) { |
| | | log.error("获取云盒列表失败:{}", e.getMessage()); |
| | | return new ArrayList<>(); |
| | | } |
| | | List<ArdServerInfo> ardServerInfos = ardServerService.selectArdServerManagementList(new ArdServerInfo()); |
| | | |
| | | return ardServerInfos.stream() |
| | | .flatMap(ardServerInfo -> { |
| | | String baseUrl = "http://" + ardServerInfo.getHost() + ":" + ardServerInfo.getHttpPort(); |
| | | try { |
| | | List<BoxInfoReceiver> boxes = tyClient.getBoxList(baseUrl).getContent(); |
| | | return Optional.ofNullable(boxes).orElse(Collections.emptyList()).stream(); |
| | | } catch (Exception e) { |
| | | log.error("获取云盒列表失败: {}", baseUrl, e); |
| | | return Stream.empty(); |
| | | } |
| | | }) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取直播地址 |
| | |
| | | */ |
| | | @Override |
| | | public BoxStreamUrlReceiver getBoxLiveUrl(String boxSn) { |
| | | |
| | | TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(boxSn); |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn); |
| | | String baseUrl="http://"+ardDroneInfo.getArdServerInfo().getHost()+":"+ardDroneInfo.getArdServerInfo().getHttpPort(); |
| | | TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(baseUrl,boxSn); |
| | | return boxLiveUrl.getContent(); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public List<BoxHistoryReceiver> getBoxHistory(BoxHistoryDTO boxHistoryDTO) { |
| | | TyHttpCommonReceiver<List<BoxHistoryReceiver>> boxHistory = tyClient.getBoxHistory(boxHistoryDTO); |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxHistoryDTO.getBoxSn()); |
| | | String baseUrl="http://"+ardDroneInfo.getArdServerInfo().getHost()+":"+ardDroneInfo.getArdServerInfo().getHttpPort(); |
| | | TyHttpCommonReceiver<List<BoxHistoryReceiver>> boxHistory = tyClient.getBoxHistory(baseUrl,boxHistoryDTO); |
| | | return boxHistory.getContent(); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public List<BoxPhotosReceiver> getBoxPhotos(BoxPhotosDTO boxPhotosDTO) { |
| | | TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(boxPhotosDTO); |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxPhotosDTO.getBoxSn()); |
| | | String baseUrl="http://"+ardDroneInfo.getArdServerInfo().getHost()+":"+ardDroneInfo.getArdServerInfo().getHttpPort(); |
| | | TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(baseUrl,boxPhotosDTO); |
| | | return boxPhotos.getContent(); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public Boolean updateBoxSettings(BoxSettingsDTO boxSettingsDTO) { |
| | | TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(boxSettingsDTO); |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSettingsDTO.getBoxSn()); |
| | | String baseUrl="http://"+ardDroneInfo.getArdServerInfo().getHost()+":"+ardDroneInfo.getArdServerInfo().getHttpPort(); |
| | | TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(baseUrl,boxSettingsDTO); |
| | | return result.getState() == 1; |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public Boolean updateReturnHeight(ReturnHeightSettingDTO returnHeightSettingDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(returnHeightSettingDTO.getBoxSn()); |
| | | ReturnHeightSettingCmd returnHeightSettingCmd = new ReturnHeightSettingCmd(returnHeightSettingDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), returnHeightSettingCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), returnHeightSettingCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public Boolean updateReturnPoint(ReturnPointSettingDTO returnPointSettingDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(returnPointSettingDTO.getBoxSn()); |
| | | ReturnPointSettingCmd returnPointSettingCmd = new ReturnPointSettingCmd(returnPointSettingDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), returnPointSettingCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), returnPointSettingCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public Boolean updateVideoStream(VideoStreamSettingDTO videoStreamSettingDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(videoStreamSettingDTO.getBoxSn()); |
| | | VideoStreamSettingCmd videoStreamSettingCmd = new VideoStreamSettingCmd(videoStreamSettingDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), videoStreamSettingCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), videoStreamSettingCmd); |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 注册天宇平台 |
| | | * 注册六合平台 |
| | | */ |
| | | @Override |
| | | public Boolean registerMessage() { |
| | | public Boolean registerMessage(String serverId) { |
| | | try { |
| | | AccessTokenReceiver tyToken = tyConfiguration.getAccessToken(); |
| | | AccessTokenReceiver tyToken = ardServerService.getAccessToken(serverId); |
| | | RegisterCmd registerMessage = new RegisterCmd(tyToken.getCompanyId(), tyToken.getAccessToken().getBytes()); |
| | | this.sendMessage(tyConfiguration.getIpPort(), registerMessage); |
| | | this.sendMessage(serverId, registerMessage); |
| | | } catch (Exception e) { |
| | | log.error("注册天宇平台失败:{}", e.getMessage()); |
| | | log.error("注册六合平台失败:{}", e.getMessage()); |
| | | } |
| | | return true; |
| | | } |
| | |
| | | @CheckControlRight(UavControlType.PAYLOAD) |
| | | @Override |
| | | public Boolean angleControl(AngleControlDTO angleControlDto) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(angleControlDto.getBoxSn()); |
| | | AngleControlCmd controlAngleCommand = new AngleControlCmd(angleControlDto); |
| | | this.sendMessage(tyConfiguration.getIpPort(), controlAngleCommand); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), controlAngleCommand); |
| | | return true; |
| | | } |
| | | |
| | |
| | | @CheckControlRight(UavControlType.PAYLOAD) |
| | | @Override |
| | | public Boolean absAngleControl(AbsAngleControlDTO absAngleControlDto) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(absAngleControlDto.getBoxSn()); |
| | | AbsAngleControlCmd absAngleControlCommand = new AbsAngleControlCmd(absAngleControlDto); |
| | | this.sendMessage(tyConfiguration.getIpPort(), absAngleControlCommand); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), absAngleControlCommand); |
| | | return true; |
| | | } |
| | | |
| | |
| | | @CheckControlRight(UavControlType.PAYLOAD) |
| | | @Override |
| | | public Boolean speedControl(SpeedControlDTO speedControlDto) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(speedControlDto.getBoxSn()); |
| | | SpeedControlCmd speedControlCommand = new SpeedControlCmd(speedControlDto); |
| | | this.sendMessage(tyConfiguration.getIpPort(), speedControlCommand); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), speedControlCommand); |
| | | return true; |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public Boolean updateCameraMode(CameraModeDTO cameraModeDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(cameraModeDTO.getBoxSn()); |
| | | CameraModeCmd cameraModeCommand = new CameraModeCmd(cameraModeDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), cameraModeCommand); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), cameraModeCommand); |
| | | return true; |
| | | } |
| | | |
| | |
| | | updateCameraMode(CameraModeDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01).build()); |
| | | //设置拍照回传 |
| | | photoReturnToggle(PhotoReturnToggleDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01).build()); |
| | | |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(capturePicDto.getBoxSn()); |
| | | CapturePicCmd capturePicCommand = new CapturePicCmd(capturePicDto); |
| | | this.sendMessage(tyConfiguration.getIpPort(), capturePicCommand); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), capturePicCommand); |
| | | return true; |
| | | } |
| | | |
| | |
| | | } else { |
| | | baseCmd = new RecordStopCmd(recordDto); |
| | | } |
| | | this.sendMessage(tyConfiguration.getIpPort(), baseCmd); |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(recordDto.getBoxSn()); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), baseCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | @CheckControlRight(UavControlType.PAYLOAD) |
| | | @Override |
| | | public Boolean zoom(ZoomDTO zoomDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(zoomDTO.getBoxSn()); |
| | | ZoomCmd zoomCommand = new ZoomCmd(zoomDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), zoomCommand); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), zoomCommand); |
| | | return true; |
| | | } |
| | | |
| | |
| | | @CheckControlRight(UavControlType.PAYLOAD) |
| | | @Override |
| | | public Boolean zoomToLevel(ZoomToLevelDTO zoomToLevelDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(zoomToLevelDTO.getBoxSn()); |
| | | ZoomToLevelCmd zoomToLevelCommand = new ZoomToLevelCmd(zoomToLevelDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), zoomToLevelCommand); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), zoomToLevelCommand); |
| | | return true; |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public Boolean switchCamera(SwitchCameraDTO switchCameraDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(switchCameraDTO.getBoxSn()); |
| | | SwitchCameraCmd switchCameraCmd = new SwitchCameraCmd(switchCameraDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), switchCameraCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), switchCameraCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public Boolean switchSource(SwitchSourceDTO switchSourceDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(switchSourceDTO.getBoxSn()); |
| | | SwitchSourceCmd switchSourceCmd = new SwitchSourceCmd(switchSourceDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), switchSourceCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), switchSourceCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public Boolean photoReturnToggle(PhotoReturnToggleDTO photoReturnToggleDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(photoReturnToggleDTO.getBoxSn()); |
| | | PhotoReturnToggleCmd photoReturnToggleCmd = new PhotoReturnToggleCmd(photoReturnToggleDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), photoReturnToggleCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), photoReturnToggleCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public Boolean switchUavControl(SwitchUavControlDTO switchUavControlDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(switchUavControlDTO.getBoxSn()); |
| | | SwitchUavControlCmd switchUavControlCmd = new SwitchUavControlCmd(switchUavControlDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), switchUavControlCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), switchUavControlCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | @CheckControlRight(UavControlType.FLY) |
| | | @Override |
| | | public Boolean takeOff(TakeOffDTO takeOffDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(takeOffDTO.getBoxSn()); |
| | | TakeOffCmd takeOffCmd = new TakeOffCmd(takeOffDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), takeOffCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), takeOffCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | @CheckControlRight(UavControlType.FLY) |
| | | @Override |
| | | public Boolean returnHome(ReturnHomeDTO returnHomeDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(returnHomeDTO.getBoxSn()); |
| | | ReturnHomeCmd returnHomeCmd = new ReturnHomeCmd(returnHomeDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), returnHomeCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), returnHomeCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | @CheckControlRight(UavControlType.FLY) |
| | | @Override |
| | | public Boolean returnHomeCancel(ReturnHomeCancelDTO returnHomeCancelDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(returnHomeCancelDTO.getBoxSn()); |
| | | ReturnHomeCancelCmd returnHomeCancelCmd = new ReturnHomeCancelCmd(returnHomeCancelDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), returnHomeCancelCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), returnHomeCancelCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | @CheckControlRight(UavControlType.FLY) |
| | | @Override |
| | | public Boolean land(LandDTO landDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(landDTO.getBoxSn()); |
| | | LandCmd landCmd = new LandCmd(landDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), landCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), landCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | @CheckControlRight(UavControlType.FLY) |
| | | @Override |
| | | public Boolean landCancel(LandCancelDTO landCancelDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(landCancelDTO.getBoxSn()); |
| | | LandCancelCmd landCancelCmd = new LandCancelCmd(landCancelDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), landCancelCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), landCancelCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | @CheckControlRight(UavControlType.FLY) |
| | | @Override |
| | | public Boolean landForced(LandForcedDTO landForcedDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(landForcedDTO.getBoxSn()); |
| | | LandForcedCmd landForcedCmd = new LandForcedCmd(landForcedDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), landForcedCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), landForcedCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | @CheckTakeoffAltitude(minAltitude = 30.0) |
| | | @Override |
| | | public Boolean flyControl(FlyControlDTO flyControlDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(flyControlDTO.getBoxSn()); |
| | | FlyControlCmd flyControlCmd = new FlyControlCmd(flyControlDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), flyControlCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), flyControlCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | @CheckTakeoffAltitude(minAltitude = 30.0) |
| | | @Override |
| | | public Boolean flyPointControl(FlyPointControlDTO flyPointControlDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(flyPointControlDTO.getBoxSn()); |
| | | FlyPointControlCmd flyPointControlCmd = new FlyPointControlCmd(flyPointControlDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), flyPointControlCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), flyPointControlCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | @CheckControlRight(UavControlType.FLY) |
| | | @Override |
| | | public Boolean flyPointControlCancel(FlyPointControlCancelDTO flyPointControlCancelDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(flyPointControlCancelDTO.getBoxSn()); |
| | | FlyPointControlCancelCmd flyPointControlCancelCmd = new FlyPointControlCancelCmd(flyPointControlCancelDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), flyPointControlCancelCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), flyPointControlCancelCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | @CheckControlRight(UavControlType.FLY) |
| | | @Override |
| | | public Boolean emeragencyBrake(EmeragencyBrakeDTO emeragencyBrakeDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(emeragencyBrakeDTO.getBoxSn()); |
| | | EmergencyBrakeCmd emergencyBrakeCmd = new EmergencyBrakeCmd(emeragencyBrakeDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), emergencyBrakeCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), emergencyBrakeCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public void speakModeSwitch(SpeakModeSwitchDTO speakModeSwitchDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(speakModeSwitchDTO.getBoxSn()); |
| | | SpeakModeSwitchCmd speakModeSwitchCmd = new SpeakModeSwitchCmd(speakModeSwitchDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), speakModeSwitchCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), speakModeSwitchCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public void textSpeak(TextSpeakDTO textSpeakDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(textSpeakDTO.getBoxSn()); |
| | | TextSpeakCmd textSpeakCmd = new TextSpeakCmd(textSpeakDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), textSpeakCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), textSpeakCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public void realSpeak(RealSpeakDTO realSpeakDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(realSpeakDTO.getBoxSn()); |
| | | RealSpeakCmd realSpeakCmd = new RealSpeakCmd(realSpeakDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), realSpeakCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), realSpeakCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public void recordSpeak(RecordSpeakDTO recordSpeakDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(recordSpeakDTO.getBoxSn()); |
| | | RecordSpeakCmd recordSpeakCmd = new RecordSpeakCmd(recordSpeakDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), recordSpeakCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), recordSpeakCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public void volumeSetting(VolumeSettingDTO volumeSettingDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(volumeSettingDTO.getBoxSn()); |
| | | VolumeSettingCmd volumeSettingCmd = new VolumeSettingCmd(volumeSettingDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), volumeSettingCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), volumeSettingCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public void loopSetting(LoopSettingDTO loopSettingDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(loopSettingDTO.getBoxSn()); |
| | | LoopSettingCmd loopSettingCmd = new LoopSettingCmd(loopSettingDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), loopSettingCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), loopSettingCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public void stopSpeak(StopSpeakDTO stopSpeakDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(stopSpeakDTO.getBoxSn()); |
| | | StopSpeakCmd stopSpeakCmd = new StopSpeakCmd(stopSpeakDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), stopSpeakCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), stopSpeakCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public void wayLineUpload(WayLineUploadDTO wayLineUploadDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(wayLineUploadDTO.getBoxSn()); |
| | | wayLineUploadDTO.setWayLineData(this.CreatePlanLineData());//设置航线数据 |
| | | WayLineUploadCmd wayLineUploadCmd = new WayLineUploadCmd(wayLineUploadDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), wayLineUploadCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), wayLineUploadCmd); |
| | | } |
| | | |
| | | //创建航线 |
| | |
| | | @CheckControlRight(UavControlType.FLY) |
| | | @Override |
| | | public void wayLineBegin(WayLineBeginDTO wayLineBeginDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(wayLineBeginDTO.getBoxSn()); |
| | | WayLineBeginCmd wayLineBeginCmd = new WayLineBeginCmd(wayLineBeginDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), wayLineBeginCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), wayLineBeginCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | @CheckControlRight(UavControlType.FLY) |
| | | @Override |
| | | public void wayLinePause(WayLinePauseDTO wayLinePauseDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(wayLinePauseDTO.getBoxSn()); |
| | | WayLinePauseCmd wayLinePauseCmd = new WayLinePauseCmd(wayLinePauseDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), wayLinePauseCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), wayLinePauseCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | @CheckControlRight(UavControlType.FLY) |
| | | @Override |
| | | public void wayLineResume(WayLineResumeDTO wayLineResumeDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(wayLineResumeDTO.getBoxSn()); |
| | | WayLineResumeCmd wayLineResumeCmd = new WayLineResumeCmd(wayLineResumeDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), wayLineResumeCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), wayLineResumeCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | @CheckControlRight(UavControlType.FLY) |
| | | @Override |
| | | public void wayLineEnd(WayLineEndDTO wayLineEndDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(wayLineEndDTO.getBoxSn()); |
| | | WayLineEndCmd wayLineEndCmd = new WayLineEndCmd(wayLineEndDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), wayLineEndCmd); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), wayLineEndCmd); |
| | | } |
| | | |
| | | /** |
| | | * 处理天宇服务器返回的消息 |
| | | * 处理六合服务器返回的消息 |
| | | */ |
| | | @Override |
| | | public void processReplyMessage(String key, BaseCmd tyCommand) { |
| | |
| | | if (registerReplyCommand.getSuccess() != 1) { |
| | | // 注册失败,重新注册 |
| | | log.info("注册失败,重新注册"); |
| | | registerMessage(); |
| | | registerMessage(key); |
| | | } |
| | | break; |
| | | case 0x02: |
| | |
| | | if (tyCommand instanceof UavInitReplyCmd) { |
| | | UavInitReplyCmd uavInitReplyCmd = (UavInitReplyCmd) tyCommand; |
| | | UavInitInfoCmd uavInitCommand = new UavInitInfoCmd(uavInitReplyCmd.getBoxSn()); |
| | | this.sendMessage(tyConfiguration.getIpPort(), uavInitCommand); |
| | | this.sendMessage(key, uavInitCommand); |
| | | logPrint("无人机初始化详情", uavInitCommand.getBoxSn()); |
| | | } |
| | | if (tyCommand instanceof UavReadyReplyCmd) { |
| | |
| | | ErrorCodeEnum.getDescByCode(errorCode)); |
| | | } |
| | | |
| | | /** |
| | | * 定时3秒发送心跳指令 |
| | | */ |
| | | @Scheduled(fixedRate = 3000) |
| | | public void sendHeartBeat() { |
| | | if (!TyTcpServerCache.getTcpServerCache(tyConfiguration.getTcpserver() + ":" + tyConfiguration.getTcpport())) { |
| | | return; |
| | | } |
| | | long timestamp = System.currentTimeMillis(); |
| | | log.debug("定时向天宇发送⼼跳,时间戳{}", timestamp); |
| | | HeartbeatCmd heartbeatMessage = new HeartbeatCmd(timestamp); |
| | | this.sendMessage(tyConfiguration.getIpPort(), heartbeatMessage); |
| | | } |
| | | |
| | | /** |
| | | * 定时向所有已连接的六合服务器发送心跳 |
| | | */ |
| | | @Scheduled(fixedRate = 5000) // 每5秒执行一次 |
| | | public void sendHeartBeat() { |
| | | long timestamp = System.currentTimeMillis(); |
| | | |
| | | for (TcpClientSession session : channels.values()) { |
| | | ChannelFuture future = session.getChannelFuture(); |
| | | if (future == null || !future.channel().isActive()) { |
| | | log.warn("边缘服务器 [{}] 连接未激活,跳过心跳发送", session.getServerId()); |
| | | continue; |
| | | } |
| | | |
| | | HeartbeatCmd heartbeat = new HeartbeatCmd(timestamp); |
| | | future.channel().writeAndFlush(heartbeat); |
| | | |
| | | log.info("→ 向边缘服务器 [{}] ({}:{}) 发送心跳,时间戳={}", |
| | | session.getServerId(), session.getHost(), session.getPort(), timestamp); |
| | | } |
| | | } |
| | | /** |
| | | * 发送消息 |
| | | */ |
| | | private void sendMessage(String key, BaseCmd msg) { |
| | | try { |
| | | ChannelFuture future = NettyTcpClient.channels.get(key).getChannelFuture(); |
| | | ChannelFuture future = channels.get(key).getChannelFuture(); |
| | | Channel channel = future.channel(); |
| | | if (channel.isActive()) { |
| | | InetSocketAddress ipSocket = (InetSocketAddress) channel.remoteAddress(); |
| | | String host = ipSocket.getHostString(); |
| | | int port = ipSocket.getPort(); |
| | | channel.writeAndFlush(msg); // 发送编码后的数据 |
| | | log.debug("向天宇服务器【{}:{}】发送数据,命令码:{}", host, port, String.format("0x%02X", msg.getCmdCode() & 0xFF)); |
| | | log.debug("向六合服务器【{}:{}】发送数据,命令码:{}", host, port, String.format("0x%02X", msg.getCmdCode() & 0xFF)); |
| | | } else { |
| | | log.error("与天宇服务器链接断开,无法发送数据!"); |
| | | log.error("与六合服务器链接断开,无法发送数据!"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("发送消息异常:{}", e.getMessage()); |