| | |
| | | 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.manual.ReturnHomeDTO; |
| | | import com.ard.tianyu.model.dto.manual.SwitchUavControlDTO; |
| | | import com.ard.tianyu.model.dto.manual.TakeOffDTO; |
| | | import com.ard.tianyu.model.dto.manual.*; |
| | | import com.ard.tianyu.model.dto.signal.SignalInfo; |
| | | import com.ard.tianyu.model.dto.state.UavState; |
| | | import com.ard.tianyu.model.dto.telemetry.TelemetryData; |
| | |
| | | import com.ard.tianyu.netty.command.register.*; |
| | | import com.ard.tianyu.netty.handler.ErrorCodeEnum; |
| | | import com.ard.tianyu.service.ITyService; |
| | | import com.ard.tianyu.websocket.utils.WebSocketUtil; |
| | | import io.netty.channel.Channel; |
| | | import io.netty.channel.ChannelFuture; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 取消返航 |
| | | */ |
| | | @Override |
| | | public void returnHomeCancel(ReturnHomeCancelDTO returnHomeCancelDTO) { |
| | | ReturnHomeCancelCmd returnHomeCancelCmd = new ReturnHomeCancelCmd(returnHomeCancelDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), returnHomeCancelCmd); |
| | | } |
| | | |
| | | /** |
| | | * 降落 |
| | | */ |
| | | @Override |
| | | public void land(LandDTO landDTO) { |
| | | LandCmd landCmd = new LandCmd(landDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), landCmd); |
| | | } |
| | | |
| | | /** |
| | | * 取消降落 |
| | | */ |
| | | @Override |
| | | public void landCancel(LandCancelDTO landCancelDTO) { |
| | | LandCancelCmd landCancelCmd = new LandCancelCmd(landCancelDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), landCancelCmd); |
| | | } |
| | | |
| | | /** |
| | | * 强制降落 |
| | | */ |
| | | @Override |
| | | public void landForced(LandForcedDTO landForcedDTO) { |
| | | LandForcedCmd landForcedCmd = new LandForcedCmd(landForcedDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), landForcedCmd); |
| | | } |
| | | |
| | | /** |
| | | * 方向控制 |
| | | */ |
| | | @Override |
| | | public void flyControl(FlyControlDTO flyControlDTO) { |
| | | FlyControlCmd flyControlCmd = new FlyControlCmd(flyControlDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), flyControlCmd); |
| | | } |
| | | |
| | | /** |
| | | * 指点飞行控制 |
| | | */ |
| | | @Override |
| | | public void flyPointControl(FlyPointControlDTO flyPointControlDTO) { |
| | | FlyPointControlCmd flyPointControlCmd = new FlyPointControlCmd(flyPointControlDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), flyPointControlCmd); |
| | | } |
| | | |
| | | /** |
| | | * 停止指点飞行控制 |
| | | */ |
| | | @Override |
| | | public void flyPointControlCancel(FlyPointControlCancelDTO flyPointControlCancelDTO) { |
| | | FlyPointControlCancelCmd flyPointControlCancelCmd = new FlyPointControlCancelCmd(flyPointControlCancelDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), flyPointControlCancelCmd); |
| | | } |
| | | |
| | | /** |
| | | * 紧急制动 |
| | | */ |
| | | @Override |
| | | public void emeragencyBrake(EmeragencyBrakeDTO emeragencyBrakeDTO) { |
| | | EmergencyBrakeCmd emergencyBrakeCmd=new EmergencyBrakeCmd(emeragencyBrakeDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), emergencyBrakeCmd); |
| | | } |
| | | |
| | | /** |
| | | * 获取无人机状态 |
| | | */ |
| | | @Override |
| | |
| | | UavState uavState = UavStateConverter.convertProtoToEntity(uavStateCmd.getUavState()); |
| | | UavStateCache.putUavState(uavState); |
| | | logPrint("无人机状态", uavState.getBoxSn()); |
| | | WebSocketUtil.sendMessageAll(uavState); |
| | | break; |
| | | case (byte) 0xA9: |
| | | // 处理无人机遥测消息 |
| | |
| | | ReturnHomeReplyCmd returnHomeReplyCmd = (ReturnHomeReplyCmd) tyCommand; |
| | | logPrint("无人机返航", returnHomeReplyCmd.getResult(), returnHomeReplyCmd.getErrorCode()); |
| | | } |
| | | //取消返航回复 |
| | | if (tyCommand instanceof ReturnHomeCancelReplyCmd) { |
| | | ReturnHomeCancelReplyCmd returnHomeCancelReplyCmd = (ReturnHomeCancelReplyCmd) tyCommand; |
| | | logPrint("取消无人机返航", returnHomeCancelReplyCmd.getResult(), returnHomeCancelReplyCmd.getErrorCode()); |
| | | } |
| | | //降落回复 |
| | | if (tyCommand instanceof LandReplyCmd) { |
| | | LandReplyCmd landReplyCmd = (LandReplyCmd) tyCommand; |
| | | logPrint("降落", landReplyCmd.getResult(), landReplyCmd.getErrorCode()); |
| | | } |
| | | //取消降落回复 |
| | | if (tyCommand instanceof LandCancelReplyCmd) { |
| | | LandCancelReplyCmd landCancelReplyCmd = (LandCancelReplyCmd) tyCommand; |
| | | logPrint("取消降落", landCancelReplyCmd.getResult(), landCancelReplyCmd.getErrorCode()); |
| | | } |
| | | //强制降落回复 |
| | | if (tyCommand instanceof LandForcedReplyCmd) { |
| | | LandForcedReplyCmd landForcedReplyCmd = (LandForcedReplyCmd) tyCommand; |
| | | logPrint("强制降落", landForcedReplyCmd.getResult(), landForcedReplyCmd.getErrorCode()); |
| | | } |
| | | //到达指点飞行位置回复 |
| | | if (tyCommand instanceof PointControlReachedReplyCmd) { |
| | | PointControlReachedReplyCmd pointControlReachedReplyCmd = (PointControlReachedReplyCmd) tyCommand; |
| | | logPrint("到达指点飞行位置", pointControlReachedReplyCmd.getResult(), pointControlReachedReplyCmd.getErrorCode()); |
| | | } |
| | | //紧急制动回复 |
| | | if (tyCommand instanceof EmergencyBrakeReplyCmd) { |
| | | EmergencyBrakeReplyCmd emergencyBrakeReplyCmd = (EmergencyBrakeReplyCmd) tyCommand; |
| | | logPrint("紧急制动回复", emergencyBrakeReplyCmd.getResult(), emergencyBrakeReplyCmd.getErrorCode()); |
| | | } |
| | | break; |
| | | default: |
| | | // 处理其他消息 |
| | |
| | | private void logPrint(String message, Object obj) { |
| | | log.debug("收到{}回复{}", message, obj); |
| | | } |
| | | |
| | | //公共日志打印 |
| | | private void logPrint(String message, byte result, Integer errorCode) { |
| | | log.info("收到{}回复:{} 错误码:{}【{}】", |