| | |
| | | package com.ard.work.service.impl; |
| | | |
| | | 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.aspect.annotation.CheckTakeoffAltitude; |
| | | import com.ard.work.component.forest.TyClient; |
| | | import com.ard.work.component.netty.TcpClientUtil; |
| | | 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.register.*; |
| | | 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.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.UavSignalInfoCache; |
| | | import com.ard.work.domain.cache.UavStateCache; |
| | | import com.ard.work.domain.cache.UavTelemetryDataCache; |
| | | import com.ard.work.domain.dto.BoxHistoryDTO; |
| | | import com.ard.work.domain.dto.BoxPhotosDTO; |
| | | import com.ard.work.domain.dto.BoxSettingsDTO; |
| | | import com.ard.work.domain.dto.control.AbsAngleControlDTO; |
| | | import com.ard.work.domain.dto.control.AngleControlDTO; |
| | | import com.ard.work.domain.dto.control.SpeedControlDTO; |
| | | import com.ard.work.domain.dto.converter.wayline.PlanLineDataConverter; |
| | | import com.ard.work.domain.dto.settings.ReturnHeightSettingDTO; |
| | | import com.ard.work.domain.dto.settings.ReturnPointSettingDTO; |
| | | import com.ard.work.domain.dto.settings.VideoStreamSettingDTO; |
| | | 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.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.manual.*; |
| | | import com.ard.work.component.netty.command.notice.BoxPowerStatusReplyCmd; |
| | | import com.ard.work.component.netty.command.notice.FlyWayEndReplyCmd; |
| | | import com.ard.work.component.netty.command.notice.UavReadyReplyCmd; |
| | | import com.ard.work.component.netty.command.real.SignalInfoCmd; |
| | | import com.ard.work.component.netty.command.real.UavStateCmd; |
| | | import com.ard.work.component.netty.command.real.UavTelemetryDataCmd; |
| | | import com.ard.work.component.netty.command.register.*; |
| | | 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.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.cache.UavSignalInfoCache; |
| | | import com.ard.work.domain.cache.UavStateCache; |
| | | import com.ard.work.domain.cache.UavTelemetryDataCache; |
| | | import com.ard.work.domain.dto.BoxHistoryDTO; |
| | | import com.ard.work.domain.dto.BoxPhotosDTO; |
| | | import com.ard.work.domain.dto.BoxSettingsDTO; |
| | | import com.ard.work.domain.dto.camera.*; |
| | | import com.ard.work.domain.dto.control.AbsAngleControlDTO; |
| | | import com.ard.work.domain.dto.control.AngleControlDTO; |
| | | import com.ard.work.domain.dto.control.SpeedControlDTO; |
| | | import com.ard.work.domain.dto.converter.wayline.PlanLineDataConverter; |
| | | import com.ard.work.domain.dto.manual.*; |
| | | import com.ard.work.domain.dto.settings.ReturnHeightSettingDTO; |
| | | import com.ard.work.domain.dto.settings.ReturnPointSettingDTO; |
| | | import com.ard.work.domain.dto.settings.VideoStreamSettingDTO; |
| | | import com.ard.work.domain.dto.signal.SignalInfo; |
| | | import com.ard.work.domain.dto.speaker.*; |
| | | import com.ard.work.domain.dto.state.UavState; |
| | | import com.ard.work.domain.dto.telemetry.TelemetryData; |
| | | 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.message.UavControlType; |
| | | import io.netty.channel.Channel; |
| | | import io.netty.channel.ChannelFuture; |
| | | import com.ard.work.domain.receiver.*; |
| | | import com.ard.work.service.IArdDroneInfoService; |
| | | import com.ard.work.service.IArdServerInfoService; |
| | | import com.ard.work.service.ITyService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.net.InetSocketAddress; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | import java.util.stream.Stream; |
| | | |
| | | import static com.ard.work.component.netty.TyTcpClientManager.channels; |
| | | |
| | | /** |
| | | * TyServiceImpl |
| | |
| | | @Service |
| | | public class TyServiceImpl implements ITyService { |
| | | @Resource |
| | | private IArdServerService ardServerService; |
| | | private IArdServerInfoService ardServerService; |
| | | @Resource |
| | | private IArdDroneService ardDroneService; |
| | | private IArdDroneInfoService ardDroneService; |
| | | @Resource |
| | | private TyClient tyClient; |
| | | |
| | | /** |
| | | * 获取六合token信息 |
| | | * 获取边缘服务器token信息 |
| | | * |
| | | * @return AccessTokenReceiver |
| | | */ |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取云盒列表 |
| | | * 获取全部云盒列表 |
| | | * |
| | | * @return List<BoxInfoReceiver> |
| | | */ |
| | | @Override |
| | | public List<BoxInfoReceiver> getBoxList() { |
| | | List<ArdServerInfo> ardServerInfos = ardServerService.selectArdServerManagementList(new ArdServerInfo()); |
| | | List<ArdServerInfo> ardServerInfos = ardServerService.selectArdServerInfoList(new ArdServerInfo()); |
| | | return getBoxList(ardServerInfos); |
| | | } |
| | | |
| | | /** |
| | | * 获取指定服务器云盒列表 |
| | | * |
| | | * @return List<BoxInfoReceiver> |
| | | */ |
| | | @Override |
| | | public List<BoxInfoReceiver> getBoxList(String serverId) { |
| | | TyHttpCommonReceiver<List<BoxInfoReceiver>> boxList = tyClient.getBoxList(serverId); |
| | | return boxList == null ? null : boxList.getContent(); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public BoxStreamUrlReceiver getBoxLiveUrl(String 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(); |
| | | if (ardDroneInfo == null) { |
| | | log.warn("未找到对应的飞行器信息,boxSn:{}", boxSn); |
| | | return null; |
| | | } |
| | | TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(ardDroneInfo.getServerId(), |
| | | boxSn); |
| | | return boxLiveUrl == null ? null : boxLiveUrl.getContent(); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public List<BoxHistoryReceiver> getBoxHistory(BoxHistoryDTO 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(); |
| | | TyHttpCommonReceiver<List<BoxHistoryReceiver>> boxHistory = tyClient.getBoxHistory(ardDroneInfo.getServerId(), |
| | | boxHistoryDTO); |
| | | return boxHistory == null ? null : boxHistory.getContent(); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public List<BoxPhotosReceiver> getBoxPhotos(BoxPhotosDTO 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(); |
| | | TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(ardDroneInfo.getServerId(), |
| | | boxPhotosDTO); |
| | | return boxPhotos == null ? null : boxPhotos.getContent(); |
| | | } |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public Boolean updateBoxSettings(BoxSettingsDTO boxSettingsDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSettingsDTO.getBoxSn()); |
| | | String baseUrl="http://"+ardDroneInfo.getArdServerInfo().getHost()+":"+ardDroneInfo.getArdServerInfo().getHttpPort(); |
| | | TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(baseUrl,boxSettingsDTO); |
| | | TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(ardDroneInfo.getServerId(), boxSettingsDTO); |
| | | return result.getState() == 1; |
| | | } |
| | | |
| | |
| | | public Boolean updateReturnHeight(ReturnHeightSettingDTO returnHeightSettingDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(returnHeightSettingDTO.getBoxSn()); |
| | | ReturnHeightSettingCmd returnHeightSettingCmd = new ReturnHeightSettingCmd(returnHeightSettingDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), returnHeightSettingCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), returnHeightSettingCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean updateReturnPoint(ReturnPointSettingDTO returnPointSettingDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(returnPointSettingDTO.getBoxSn()); |
| | | ReturnPointSettingCmd returnPointSettingCmd = new ReturnPointSettingCmd(returnPointSettingDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), returnPointSettingCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), returnPointSettingCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean updateVideoStream(VideoStreamSettingDTO videoStreamSettingDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(videoStreamSettingDTO.getBoxSn()); |
| | | VideoStreamSettingCmd videoStreamSettingCmd = new VideoStreamSettingCmd(videoStreamSettingDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), videoStreamSettingCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), videoStreamSettingCmd); |
| | | return true; |
| | | } |
| | | |
| | | /** |
| | | * 注册六合平台 |
| | | * 注册边缘服务器平台 |
| | | */ |
| | | @Override |
| | | public Boolean registerMessage(String serverId) { |
| | |
| | | RegisterCmd registerMessage = new RegisterCmd(tyToken.getCompanyId(), tyToken.getAccessToken().getBytes()); |
| | | this.sendMessage(serverId, registerMessage); |
| | | } catch (Exception e) { |
| | | log.error("注册六合平台失败:{}", e.getMessage()); |
| | | log.error("注册边缘服务器平台失败:{}", e.getMessage()); |
| | | } |
| | | return true; |
| | | } |
| | |
| | | public Boolean angleControl(AngleControlDTO angleControlDto) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(angleControlDto.getBoxSn()); |
| | | AngleControlCmd controlAngleCommand = new AngleControlCmd(angleControlDto); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), controlAngleCommand); |
| | | this.sendMessage(ardDroneInfo.getServerId(), controlAngleCommand); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean absAngleControl(AbsAngleControlDTO absAngleControlDto) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(absAngleControlDto.getBoxSn()); |
| | | AbsAngleControlCmd absAngleControlCommand = new AbsAngleControlCmd(absAngleControlDto); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), absAngleControlCommand); |
| | | this.sendMessage(ardDroneInfo.getServerId(), absAngleControlCommand); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean speedControl(SpeedControlDTO speedControlDto) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(speedControlDto.getBoxSn()); |
| | | SpeedControlCmd speedControlCommand = new SpeedControlCmd(speedControlDto); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), speedControlCommand); |
| | | this.sendMessage(ardDroneInfo.getServerId(), speedControlCommand); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean updateCameraMode(CameraModeDTO cameraModeDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(cameraModeDTO.getBoxSn()); |
| | | CameraModeCmd cameraModeCommand = new CameraModeCmd(cameraModeDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), cameraModeCommand); |
| | | this.sendMessage(ardDroneInfo.getServerId(), cameraModeCommand); |
| | | return true; |
| | | } |
| | | |
| | |
| | | photoReturnToggle(PhotoReturnToggleDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01).build()); |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(capturePicDto.getBoxSn()); |
| | | CapturePicCmd capturePicCommand = new CapturePicCmd(capturePicDto); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), capturePicCommand); |
| | | this.sendMessage(ardDroneInfo.getServerId(), capturePicCommand); |
| | | return true; |
| | | } |
| | | |
| | |
| | | baseCmd = new RecordStopCmd(recordDto); |
| | | } |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(recordDto.getBoxSn()); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), baseCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), baseCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean zoom(ZoomDTO zoomDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(zoomDTO.getBoxSn()); |
| | | ZoomCmd zoomCommand = new ZoomCmd(zoomDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), zoomCommand); |
| | | this.sendMessage(ardDroneInfo.getServerId(), zoomCommand); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean zoomToLevel(ZoomToLevelDTO zoomToLevelDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(zoomToLevelDTO.getBoxSn()); |
| | | ZoomToLevelCmd zoomToLevelCommand = new ZoomToLevelCmd(zoomToLevelDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), zoomToLevelCommand); |
| | | this.sendMessage(ardDroneInfo.getServerId(), zoomToLevelCommand); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean switchCamera(SwitchCameraDTO switchCameraDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(switchCameraDTO.getBoxSn()); |
| | | SwitchCameraCmd switchCameraCmd = new SwitchCameraCmd(switchCameraDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), switchCameraCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), switchCameraCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean switchSource(SwitchSourceDTO switchSourceDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(switchSourceDTO.getBoxSn()); |
| | | SwitchSourceCmd switchSourceCmd = new SwitchSourceCmd(switchSourceDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), switchSourceCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), switchSourceCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean photoReturnToggle(PhotoReturnToggleDTO photoReturnToggleDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(photoReturnToggleDTO.getBoxSn()); |
| | | PhotoReturnToggleCmd photoReturnToggleCmd = new PhotoReturnToggleCmd(photoReturnToggleDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), photoReturnToggleCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), photoReturnToggleCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean switchUavControl(SwitchUavControlDTO switchUavControlDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(switchUavControlDTO.getBoxSn()); |
| | | SwitchUavControlCmd switchUavControlCmd = new SwitchUavControlCmd(switchUavControlDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), switchUavControlCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), switchUavControlCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean takeOff(TakeOffDTO takeOffDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(takeOffDTO.getBoxSn()); |
| | | TakeOffCmd takeOffCmd = new TakeOffCmd(takeOffDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), takeOffCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), takeOffCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean returnHome(ReturnHomeDTO returnHomeDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(returnHomeDTO.getBoxSn()); |
| | | ReturnHomeCmd returnHomeCmd = new ReturnHomeCmd(returnHomeDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), returnHomeCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), returnHomeCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean returnHomeCancel(ReturnHomeCancelDTO returnHomeCancelDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(returnHomeCancelDTO.getBoxSn()); |
| | | ReturnHomeCancelCmd returnHomeCancelCmd = new ReturnHomeCancelCmd(returnHomeCancelDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), returnHomeCancelCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), returnHomeCancelCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean land(LandDTO landDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(landDTO.getBoxSn()); |
| | | LandCmd landCmd = new LandCmd(landDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), landCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), landCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean landCancel(LandCancelDTO landCancelDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(landCancelDTO.getBoxSn()); |
| | | LandCancelCmd landCancelCmd = new LandCancelCmd(landCancelDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), landCancelCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), landCancelCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean landForced(LandForcedDTO landForcedDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(landForcedDTO.getBoxSn()); |
| | | LandForcedCmd landForcedCmd = new LandForcedCmd(landForcedDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), landForcedCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), landForcedCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean flyControl(FlyControlDTO flyControlDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(flyControlDTO.getBoxSn()); |
| | | FlyControlCmd flyControlCmd = new FlyControlCmd(flyControlDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), flyControlCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), flyControlCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean flyPointControl(FlyPointControlDTO flyPointControlDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(flyPointControlDTO.getBoxSn()); |
| | | FlyPointControlCmd flyPointControlCmd = new FlyPointControlCmd(flyPointControlDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), flyPointControlCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), flyPointControlCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean flyPointControlCancel(FlyPointControlCancelDTO flyPointControlCancelDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(flyPointControlCancelDTO.getBoxSn()); |
| | | FlyPointControlCancelCmd flyPointControlCancelCmd = new FlyPointControlCancelCmd(flyPointControlCancelDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), flyPointControlCancelCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), flyPointControlCancelCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | public Boolean emeragencyBrake(EmeragencyBrakeDTO emeragencyBrakeDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(emeragencyBrakeDTO.getBoxSn()); |
| | | EmergencyBrakeCmd emergencyBrakeCmd = new EmergencyBrakeCmd(emeragencyBrakeDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), emergencyBrakeCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), emergencyBrakeCmd); |
| | | return true; |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public UavState getUavState(String boxSn) { |
| | | return UavStateCache.getUavState(boxSn); |
| | | return UavStateCache.get(boxSn); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public TelemetryData getUavTelemetryData(String boxSn) { |
| | | return UavTelemetryDataCache.getUavTelemetryData(boxSn); |
| | | return UavTelemetryDataCache.get(boxSn); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Override |
| | | public SignalInfo getSignalInfo(String boxSn) { |
| | | return UavSignalInfoCache.getUavSignalInfo(boxSn); |
| | | return UavSignalInfoCache.get(boxSn); |
| | | } |
| | | |
| | | /** |
| | |
| | | public void speakModeSwitch(SpeakModeSwitchDTO speakModeSwitchDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(speakModeSwitchDTO.getBoxSn()); |
| | | SpeakModeSwitchCmd speakModeSwitchCmd = new SpeakModeSwitchCmd(speakModeSwitchDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), speakModeSwitchCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), speakModeSwitchCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | public void textSpeak(TextSpeakDTO textSpeakDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(textSpeakDTO.getBoxSn()); |
| | | TextSpeakCmd textSpeakCmd = new TextSpeakCmd(textSpeakDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), textSpeakCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), textSpeakCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | public void realSpeak(RealSpeakDTO realSpeakDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(realSpeakDTO.getBoxSn()); |
| | | RealSpeakCmd realSpeakCmd = new RealSpeakCmd(realSpeakDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), realSpeakCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), realSpeakCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | public void recordSpeak(RecordSpeakDTO recordSpeakDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(recordSpeakDTO.getBoxSn()); |
| | | RecordSpeakCmd recordSpeakCmd = new RecordSpeakCmd(recordSpeakDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), recordSpeakCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), recordSpeakCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | public void volumeSetting(VolumeSettingDTO volumeSettingDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(volumeSettingDTO.getBoxSn()); |
| | | VolumeSettingCmd volumeSettingCmd = new VolumeSettingCmd(volumeSettingDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), volumeSettingCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), volumeSettingCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | public void loopSetting(LoopSettingDTO loopSettingDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(loopSettingDTO.getBoxSn()); |
| | | LoopSettingCmd loopSettingCmd = new LoopSettingCmd(loopSettingDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), loopSettingCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), loopSettingCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | public void stopSpeak(StopSpeakDTO stopSpeakDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(stopSpeakDTO.getBoxSn()); |
| | | StopSpeakCmd stopSpeakCmd = new StopSpeakCmd(stopSpeakDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), stopSpeakCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), stopSpeakCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(wayLineUploadDTO.getBoxSn()); |
| | | wayLineUploadDTO.setWayLineData(this.CreatePlanLineData());//设置航线数据 |
| | | WayLineUploadCmd wayLineUploadCmd = new WayLineUploadCmd(wayLineUploadDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), wayLineUploadCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), wayLineUploadCmd); |
| | | } |
| | | |
| | | //创建航线 |
| | |
| | | public void wayLineBegin(WayLineBeginDTO wayLineBeginDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(wayLineBeginDTO.getBoxSn()); |
| | | WayLineBeginCmd wayLineBeginCmd = new WayLineBeginCmd(wayLineBeginDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), wayLineBeginCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), wayLineBeginCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | public void wayLinePause(WayLinePauseDTO wayLinePauseDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(wayLinePauseDTO.getBoxSn()); |
| | | WayLinePauseCmd wayLinePauseCmd = new WayLinePauseCmd(wayLinePauseDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), wayLinePauseCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), wayLinePauseCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | public void wayLineResume(WayLineResumeDTO wayLineResumeDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(wayLineResumeDTO.getBoxSn()); |
| | | WayLineResumeCmd wayLineResumeCmd = new WayLineResumeCmd(wayLineResumeDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), wayLineResumeCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), wayLineResumeCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | public void wayLineEnd(WayLineEndDTO wayLineEndDTO) { |
| | | ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(wayLineEndDTO.getBoxSn()); |
| | | WayLineEndCmd wayLineEndCmd = new WayLineEndCmd(wayLineEndDTO); |
| | | this.sendMessage(ardDroneInfo.getServerInfoId(), wayLineEndCmd); |
| | | this.sendMessage(ardDroneInfo.getServerId(), wayLineEndCmd); |
| | | } |
| | | |
| | | /** |
| | | * 处理六合服务器返回的消息 |
| | | * 处理边缘服务器返回的消息 |
| | | */ |
| | | @Override |
| | | public void processReplyMessage(String key, BaseCmd tyCommand) { |
| | |
| | | break; |
| | | case 0x02: |
| | | // 处理注册消息 |
| | | HeartbeatReplyCmd heartbeatReplyCmd = (HeartbeatReplyCmd) tyCommand; |
| | | logPrint("心跳消息", heartbeatReplyCmd.getTimestamp()); |
| | | HeartbeatReplyCmd heartbeatReplyCmd = (HeartbeatReplyCmd) tyCommand; |
| | | logPrint("心跳消息", heartbeatReplyCmd.getTimestamp()); |
| | | break; |
| | | case 0x03: |
| | | // 处理订阅消息 |
| | |
| | | case (byte) 0xA8: |
| | | // 处理无人机状态消息 |
| | | UavStateCmd uavStateCmd = (UavStateCmd) tyCommand; |
| | | UavStateCache.putUavState(uavStateCmd.getUavState()); |
| | | UavStateCache.put(uavStateCmd.getUavState()); |
| | | //logPrint("无人机状态", uavStateCmd.getUavState().getBoxSn()); |
| | | // WebSocketUtil.sendMessageAll(uavStateCmd.getUavState()); |
| | | break; |
| | | case (byte) 0xA9: |
| | | // 处理无人机遥测消息 |
| | | UavTelemetryDataCmd uavTelemetryDataCmd = (UavTelemetryDataCmd) tyCommand; |
| | | UavTelemetryDataCache.putUavTelemetryData(uavTelemetryDataCmd.getTelemetryData()); |
| | | UavTelemetryDataCache.put(uavTelemetryDataCmd.getTelemetryData()); |
| | | //logPrint("无人机遥测", uavTelemetryDataCmd.getTelemetryData().getBoxSn()); |
| | | //WebSocketUtil.sendMessageAll(uavTelemetryDataCmd.getTelemetryData()); |
| | | break; |
| | |
| | | case (byte) 0x0C: |
| | | // 处理无人机信道质量数据 |
| | | SignalInfoCmd signalInfoCmd = (SignalInfoCmd) tyCommand; |
| | | UavSignalInfoCache.putUavSignalInfoCache(signalInfoCmd.getSignalInfo()); |
| | | UavSignalInfoCache.put(signalInfoCmd.getSignalInfo()); |
| | | //logPrint("无人机信道质量", signalInfoCmd.getSignalInfo().getBoxSn()); |
| | | break; |
| | | case (byte) 0xD1: |
| | |
| | | } |
| | | |
| | | /** |
| | | * 根据boxSn获取六合盒子列表 |
| | | * @return List<BoxInfoReceiver> |
| | | * 根据[服务器id]获取边缘服务器盒子列表 |
| | | */ |
| | | @Override |
| | | public List<BoxInfoReceiver> getBoxSnToList(String boxSn) { |
| | | ArdServerInfo serverInfo = new ArdServerInfo(); |
| | | serverInfo.setHost(boxSn); |
| | | List<ArdServerInfo> ardServerInfos = ardServerService.selectArdServerManagementList(serverInfo); |
| | | return getBoxList(ardServerInfos); |
| | | public List<BoxInfoReceiver> getBoxSnToList(String id) { |
| | | try { |
| | | List<BoxInfoReceiver> remoteBoxList = tyClient.getBoxList(id).getContent(); |
| | | List<ArdDroneInfo> existingDrones = getDroneLs(id); |
| | | return existingDrones.isEmpty() ? remoteBoxList : filterBoxInfoReceivers(remoteBoxList, existingDrones); |
| | | } catch (Exception e) { |
| | | log.error("获取云盒列表失败, 服务器id: {}", id, e); |
| | | return Collections.emptyList(); // 返回不可变空列表,更安全 |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 根据[服务器id]查询无人机盒子列表 |
| | | */ |
| | | private List<ArdDroneInfo> getDroneLs(String serverId) { |
| | | ArdDroneInfo query = new ArdDroneInfo(); |
| | | query.setServerId(serverId); |
| | | return ardDroneService.selectArdDroneList(query); |
| | | } |
| | | |
| | | /** |
| | | * 过滤掉在ardDroneInfos中已存在的boxSn |
| | | */ |
| | | public List<BoxInfoReceiver> filterBoxInfoReceivers( |
| | | List<BoxInfoReceiver> boxInfoReceivers, |
| | | List<ArdDroneInfo> ardDroneInfos) { |
| | | |
| | | Set<String> existingBoxSns = ardDroneInfos.stream() |
| | | .map(ArdDroneInfo::getBoxSn) |
| | | .filter(Objects::nonNull) |
| | | .collect(Collectors.toSet()); |
| | | |
| | | return boxInfoReceivers.stream() |
| | | .filter(box -> box.getBoxSn() != null && !existingBoxSns.contains(box.getBoxSn())) |
| | | .collect(Collectors.toList()); |
| | | } |
| | | |
| | | private List<BoxInfoReceiver> getBoxList(List<ArdServerInfo> ls) { |
| | | return ls.stream() |
| | | .filter(ardServerInfo -> ardServerInfo.getServerStatus().equals("1")) |
| | | .flatMap(ardServerInfo -> { |
| | | String baseUrl = "http://" + ardServerInfo.getHost() + ":" + ardServerInfo.getHttpPort(); |
| | | try { |
| | | List<BoxInfoReceiver> boxes = tyClient.getBoxList(baseUrl).getContent(); |
| | | List<BoxInfoReceiver> boxes = tyClient.getBoxList(ardServerInfo.getId()).getContent(); |
| | | return Optional.ofNullable(boxes).orElse(Collections.emptyList()).stream(); |
| | | } catch (Exception e) { |
| | | log.error("获取云盒列表失败: {}", baseUrl, e); |
| | | log.error("获取云盒列表失败: {}", ardServerInfo.getId(), e); |
| | | return Stream.empty(); |
| | | } |
| | | }) |
| | |
| | | |
| | | |
| | | /** |
| | | * 定时向所有已连接的六合服务器发送心跳 |
| | | */ |
| | | @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 = 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)); |
| | | } else { |
| | | log.error("与六合服务器链接断开,无法发送数据!"); |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("发送消息异常:{}", e.getMessage()); |
| | | } |
| | | TcpClientUtil.sendMessage(key, msg); |
| | | } |
| | | |
| | | } |