| | |
| | | import com.ard.tianyu.model.dto.control.AbsAngleControlDTO; |
| | | import com.ard.tianyu.model.dto.control.AngleControlDTO; |
| | | import com.ard.tianyu.model.dto.control.SpeedControlDTO; |
| | | import com.ard.tianyu.model.dto.converter.UavSignalInfoConverter; |
| | | import com.ard.tianyu.model.dto.converter.UavStateConverter; |
| | | import com.ard.tianyu.model.dto.converter.UavTelemetryDataConverter; |
| | | import com.ard.tianyu.model.dto.converter.realdata.UavSignalInfoConverter; |
| | | import com.ard.tianyu.model.dto.converter.realdata.UavStateConverter; |
| | | import com.ard.tianyu.model.dto.converter.realdata.UavTelemetryDataConverter; |
| | | import com.ard.tianyu.model.dto.converter.wayline.PlanLineDataConverter; |
| | | import com.ard.tianyu.model.dto.manual.*; |
| | | import com.ard.tianyu.model.dto.settings.ReturnHeightSettingDTO; |
| | | import com.ard.tianyu.model.dto.settings.ReturnPointSettingDTO; |
| | | import com.ard.tianyu.model.dto.settings.VideoStreamSettingDTO; |
| | | import com.ard.tianyu.model.dto.signal.SignalInfo; |
| | | import com.ard.tianyu.model.dto.speaker.*; |
| | | import com.ard.tianyu.model.dto.state.UavState; |
| | |
| | | import com.ard.tianyu.netty.command.real.UavStateCmd; |
| | | import com.ard.tianyu.netty.command.real.UavTelemetryDataCmd; |
| | | import com.ard.tianyu.netty.command.register.*; |
| | | import com.ard.tianyu.netty.command.settings.*; |
| | | import com.ard.tianyu.netty.command.speaker.*; |
| | | import com.ard.tianyu.netty.command.wayline.*; |
| | | import com.ard.tianyu.netty.handler.ErrorCodeEnum; |
| | | import com.ard.tianyu.netty.protobuf.TelemetryDataPB; |
| | | import com.ard.tianyu.service.ITyService; |
| | | import com.ard.tianyu.websocket.utils.WebSocketUtil; |
| | | import com.ard.vtdu.domain.ArdVtdu; |
| | | import com.ard.vtdu.service.IMediaService; |
| | | import io.netty.channel.Channel; |
| | | import io.netty.channel.ChannelFuture; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | import javax.annotation.Resource; |
| | | import java.net.InetSocketAddress; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | |
| | | /** |
| | | * TyServiceImpl |
| | |
| | | @Resource |
| | | private TyConfiguration tyConfiguration; |
| | | |
| | | // 存储每个无人机的最后遥测处理时间 |
| | | private Map<String, Long> lastTelemetryTimes = new ConcurrentHashMap<>(); |
| | | @Resource |
| | | private IMediaService mediaService; |
| | | |
| | | /** |
| | | * 获取天宇token信息 |
| | |
| | | public List<BoxInfoReceiver> getBoxList() { |
| | | //请求云盒列表 |
| | | try { |
| | | TyHttpCommonReceiver<List<BoxInfoReceiver>> boxListReveiver = tyClient.getBoxList(tyConfiguration.getAccessToken().convertFromDTO()); |
| | | TyHttpCommonReceiver<List<BoxInfoReceiver>> boxListReveiver = tyClient.getBoxList(); |
| | | return boxListReveiver.getContent(); |
| | | } catch (Exception e) { |
| | | log.error("获取云盒列表失败:{}", e.getMessage()); |
| | |
| | | @Override |
| | | public BoxStreamUrlReceiver getBoxLiveUrl(String boxSn) { |
| | | |
| | | TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(boxSn, tyConfiguration.getAccessToken().convertFromDTO()); |
| | | TyHttpCommonReceiver<BoxStreamUrlReceiver> boxLiveUrl = tyClient.getBoxLiveUrl(boxSn); |
| | | return boxLiveUrl.getContent(); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public List<BoxHistoryReceiver> getBoxHistory(BoxHistoryDTO boxHistoryDTO) { |
| | | TyHttpCommonReceiver<List<BoxHistoryReceiver>> boxHistory = tyClient.getBoxHistory(boxHistoryDTO, tyConfiguration.getAccessToken().convertFromDTO()); |
| | | TyHttpCommonReceiver<List<BoxHistoryReceiver>> boxHistory = tyClient.getBoxHistory(boxHistoryDTO); |
| | | return boxHistory.getContent(); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public List<BoxPhotosReceiver> getBoxPhotos(BoxPhotosDTO boxPhotosDTO) { |
| | | TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(boxPhotosDTO, tyConfiguration.getAccessToken().convertFromDTO()); |
| | | TyHttpCommonReceiver<List<BoxPhotosReceiver>> boxPhotos = tyClient.getBoxPhotos(boxPhotosDTO); |
| | | return boxPhotos.getContent(); |
| | | } |
| | | |
| | |
| | | */ |
| | | @Override |
| | | public Boolean updateBoxSettings(BoxSettingsDTO boxSettingsDTO) { |
| | | TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(boxSettingsDTO, tyConfiguration.getAccessToken().convertFromDTO()); |
| | | TyHttpCommonReceiver<?> result = tyClient.updateBoxSettings(boxSettingsDTO); |
| | | return result.getState() == 1; |
| | | } |
| | | |
| | | /** |
| | | * 设置返航高度 |
| | | */ |
| | | @Override |
| | | public void updateReturnHeight(ReturnHeightSettingDTO returnHeightSettingDTO) { |
| | | ReturnHeightSettingCmd returnHeightSettingCmd = new ReturnHeightSettingCmd(returnHeightSettingDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), returnHeightSettingCmd); |
| | | } |
| | | |
| | | /** |
| | | * 设置返航点 |
| | | */ |
| | | @Override |
| | | public void updateReturnPoint(ReturnPointSettingDTO returnPointSettingDTO) { |
| | | ReturnPointSettingCmd returnPointSettingCmd = new ReturnPointSettingCmd(returnPointSettingDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), returnPointSettingCmd); |
| | | } |
| | | |
| | | /** |
| | | * 设置视频码流 |
| | | */ |
| | | @Override |
| | | public void updateVideoStream(VideoStreamSettingDTO videoStreamSettingDTO) { |
| | | VideoStreamSettingCmd videoStreamSettingCmd = new VideoStreamSettingCmd(videoStreamSettingDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), videoStreamSettingCmd); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 点播 |
| | | */ |
| | | @Override |
| | | public String play(String boxSn) { |
| | | BoxStreamUrlReceiver boxLiveUrl = getBoxLiveUrl(boxSn); |
| | | if(boxLiveUrl == null||boxLiveUrl.getRtsp() == null) { |
| | | return ""; |
| | | } |
| | | ArdVtdu ardVtdu = ArdVtdu.builder().name(boxSn).rtspSource(boxLiveUrl.getRtsp()).build(); |
| | | ardVtdu = mediaService.addPath(ardVtdu); |
| | | return ardVtdu.getWebrtcUrl(); |
| | | } |
| | | |
| | | /** |
| | | * 处理天宇服务器返回的消息 |
| | | */ |
| | | @Override |
| | |
| | | case (byte) 0xA8: |
| | | // 处理无人机状态消息 |
| | | UavStateCmd uavStateCmd = (UavStateCmd) tyCommand; |
| | | UavState uavState = UavStateConverter.convertProtoToEntity(uavStateCmd.getUavState()); |
| | | UavStateCache.putUavState(uavState); |
| | | logPrint("无人机状态", uavState.getBoxSn()); |
| | | WebSocketUtil.sendMessageAll(uavState); |
| | | UavStateCache.putUavState(uavStateCmd.getUavState()); |
| | | logPrint("无人机状态", uavStateCmd.getUavState().getBoxSn()); |
| | | WebSocketUtil.sendMessageAll(uavStateCmd.getUavState()); |
| | | break; |
| | | case (byte) 0xA9: |
| | | // 处理无人机遥测消息 |
| | | UavTelemetryDataCmd uavTelemetryDataCmd = (UavTelemetryDataCmd) tyCommand; |
| | | if (uavTelemetryDataCmd.getBoxSn() == null) { |
| | | return; |
| | | } |
| | | String boxSn = ByteUtils.bytesToString(uavTelemetryDataCmd.getBoxSn()); // 假设有获取无人机ID的方法 |
| | | long currentTime = System.currentTimeMillis(); |
| | | |
| | | // 获取无人机的最后处理时间,如果没有则设置为0 |
| | | long lastTelemetryTime = lastTelemetryTimes.getOrDefault(boxSn, 0L); |
| | | |
| | | // 检查与上次处理时间的间隔 |
| | | if (currentTime - lastTelemetryTime >= 1000) { // 1秒 |
| | | TelemetryData telemetryData = UavTelemetryDataConverter.convertProtoToEntity(uavTelemetryDataCmd.getTelemetryData()); |
| | | UavTelemetryDataCache.putUavTelemetryData(telemetryData); |
| | | logPrint("无人机遥测", telemetryData.getBoxSn()); |
| | | |
| | | // 更新最后处理时间 |
| | | lastTelemetryTimes.put(boxSn, currentTime); |
| | | } else { |
| | | log.debug("无人机 " + boxSn + " 遥测数据接收过于频繁,已跳过处理"); |
| | | } |
| | | UavTelemetryDataCache.putUavTelemetryData(uavTelemetryDataCmd.getTelemetryData()); |
| | | logPrint("无人机遥测", uavTelemetryDataCmd.getTelemetryData().getBoxSn()); |
| | | WebSocketUtil.sendMessageAll(uavTelemetryDataCmd.getTelemetryData()); |
| | | break; |
| | | |
| | | case (byte) 0x0C: |
| | | // 处理无人机信道质量数据 |
| | | SignalInfoCmd signalInfoCmd = (SignalInfoCmd) tyCommand; |
| | | SignalInfo signalInfo = UavSignalInfoConverter.convertProtoToEntity(signalInfoCmd.getSignalInfo()); |
| | | UavSignalInfoCache.putUavSignalInfoCache(signalInfo); |
| | | logPrint("无人机信道质量", signalInfo.getBoxSn()); |
| | | UavSignalInfoCache.putUavSignalInfoCache(signalInfoCmd.getSignalInfo()); |
| | | logPrint("无人机信道质量", signalInfoCmd.getSignalInfo().getBoxSn()); |
| | | break; |
| | | case (byte) 0xD1: |
| | | // 处理无人机 |
| | |
| | | WayLineUploadReplyCmd wayLineUploadReplyCmd = (WayLineUploadReplyCmd) tyCommand; |
| | | logPrint("上传航线", wayLineUploadReplyCmd.getResult(), wayLineUploadReplyCmd.getErrorCode()); |
| | | } |
| | | //开始航线回复 |
| | | if (tyCommand instanceof WayLineBeginReplyCmd) { |
| | | WayLineBeginReplyCmd wayLineBeginReplyCmd = (WayLineBeginReplyCmd) tyCommand; |
| | | logPrint("开始航线", wayLineBeginReplyCmd.getResult(), wayLineBeginReplyCmd.getErrorCode()); |
| | | } |
| | | //暂停航线回复 |
| | | if (tyCommand instanceof WayLinePauseReplyCmd) { |
| | | WayLinePauseReplyCmd wayLinePauseReplyCmd = (WayLinePauseReplyCmd) tyCommand; |
| | | logPrint("暂停航线", wayLinePauseReplyCmd.getResult(), wayLinePauseReplyCmd.getErrorCode()); |
| | | } |
| | | //恢复航线回复 |
| | | if (tyCommand instanceof WayLineResumeReplyCmd) { |
| | | WayLineResumeReplyCmd wayLineResumeReplyCmd = (WayLineResumeReplyCmd) tyCommand; |
| | | logPrint("恢复航线", wayLineResumeReplyCmd.getResult(), wayLineResumeReplyCmd.getErrorCode()); |
| | | } |
| | | //结束航线回复 |
| | | if (tyCommand instanceof WayLineEndReplyCmd) { |
| | | WayLineEndReplyCmd wayLineEndReplyCmd = (WayLineEndReplyCmd) tyCommand; |
| | | logPrint("结束航线", wayLineEndReplyCmd.getResult(), wayLineEndReplyCmd.getErrorCode()); |
| | | } |
| | | //设置返航高度回复 |
| | | if (tyCommand instanceof ReturnHeightSettingReplyCmd) { |
| | | ReturnHeightSettingReplyCmd returnHeightSettingReplyCmd = (ReturnHeightSettingReplyCmd) tyCommand; |
| | | logPrint("设置返航高度", returnHeightSettingReplyCmd.getResult(), returnHeightSettingReplyCmd.getErrorCode()); |
| | | } |
| | | //设置返航点回复 |
| | | if (tyCommand instanceof ReturnPointSettingReplyCmd) { |
| | | ReturnPointSettingReplyCmd returnPointSettingReplyCmd = (ReturnPointSettingReplyCmd) tyCommand; |
| | | logPrint("设置返航点", returnPointSettingReplyCmd.getResult(), returnPointSettingReplyCmd.getErrorCode()); |
| | | } |
| | | break; |
| | | case (byte) 0xD2: |
| | | //设置视频码流回复 |
| | | if (tyCommand instanceof VideoStreamSettingReplyCmd) { |
| | | VideoStreamSettingReplyCmd videoStreamSettingReplyCmd = (VideoStreamSettingReplyCmd) tyCommand; |
| | | logPrint("设置视频码流", videoStreamSettingReplyCmd.getResult(), videoStreamSettingReplyCmd.getErrorCode()); |
| | | } |
| | | break; |
| | | default: |
| | | // 处理其他消息 |
| | |
| | | log.error("发送消息异常:{}", e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | } |