| | |
| | | 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.handler.ErrorCodeEnum; |
| | | import com.ard.tianyu.service.ITyService; |
| | | import io.netty.channel.Channel; |
| | | import io.netty.channel.ChannelFuture; |
| | |
| | | */ |
| | | @Override |
| | | public void returnHome(ReturnHomeDTO returnHomeDTO) { |
| | | ReturnHomeCmd returnHomeCmd=new ReturnHomeCmd(returnHomeDTO); |
| | | ReturnHomeCmd returnHomeCmd = new ReturnHomeCmd(returnHomeDTO); |
| | | this.sendMessage(tyConfiguration.getIpPort(), returnHomeCmd); |
| | | } |
| | | |
| | |
| | | case 0x01: |
| | | // 处理心跳消息 |
| | | RegisterReplyCmd registerReplyCommand = (RegisterReplyCmd) tyCommand; |
| | | log.debug("收到注册消息-->处理注册消息:{}", registerReplyCommand.getSuccess()); |
| | | logPrint("注册消息", registerReplyCommand.getSuccess()); |
| | | if (registerReplyCommand.getSuccess() != 1) { |
| | | // 注册失败,重新注册 |
| | | log.info("注册失败,重新注册"); |
| | |
| | | case 0x02: |
| | | // 处理注册消息 |
| | | HeartbeatReplyCmd heartbeatReplyCmd = (HeartbeatReplyCmd) tyCommand; |
| | | log.debug("收到心跳消息-->处理心跳消息:{}", heartbeatReplyCmd.getTimestamp()); |
| | | logPrint("心跳消息", heartbeatReplyCmd.getTimestamp()); |
| | | break; |
| | | case 0x03: |
| | | // 处理订阅消息 |
| | |
| | | case 0x0A: |
| | | // 处理云盒开关机通知消息 |
| | | BoxPowerStatusReplyCmd boxPowerStatusReplyCmd = (BoxPowerStatusReplyCmd) tyCommand; |
| | | log.debug("收到云盒开关机通知消息-->状态:{}", boxPowerStatusReplyCmd.getStatus()); |
| | | logPrint("云盒开关机通知消息", boxPowerStatusReplyCmd.getStatus()); |
| | | break; |
| | | case (byte) 0xA8: |
| | | // 处理无人机状态消息 |
| | | log.debug("收到无人机状态消息-->无人机状态消息"); |
| | | UavStateCmd uavStateCmd = (UavStateCmd) tyCommand; |
| | | UavState uavState = UavStateConverter.convertProtoToEntity(uavStateCmd.getUavState()); |
| | | UavStateCache.putUavState(uavState); |
| | | logPrint("无人机状态", uavState.getBoxSn()); |
| | | break; |
| | | case (byte) 0xA9: |
| | | // 处理无人机遥测消息 |
| | | log.debug("收到无人机遥测消息-->无人机遥测消息"); |
| | | UavTelemetryDataCmd uavTelemetryDataCmd = (UavTelemetryDataCmd) tyCommand; |
| | | TelemetryData telemetryData = UavTelemetryDataConverter.convertProtoToEntity(uavTelemetryDataCmd.getTelemetryData()); |
| | | UavTelemetryDataCache.putUavTelemetryData(telemetryData); |
| | | logPrint("无人机遥测", telemetryData.getBoxSn()); |
| | | break; |
| | | case (byte) 0x0C: |
| | | // 处理无人机信道质量数据 |
| | | log.debug("收到无人机信道质量数据消息-->无人机信道质量数据消息"); |
| | | SignalInfoCmd signalInfoCmd = (SignalInfoCmd) tyCommand; |
| | | SignalInfo signalInfo = UavSignalInfoConverter.convertProtoToEntity(signalInfoCmd.getSignalInfo()); |
| | | UavSignalInfoCache.putUavSignalInfoCache(signalInfo); |
| | | logPrint("无人机信道质量", signalInfo.getBoxSn()); |
| | | break; |
| | | case (byte) 0xD1: |
| | | // 处理无人机 |
| | |
| | | UavInitReplyCmd uavInitReplyCmd = (UavInitReplyCmd) tyCommand; |
| | | UavInitInfoCmd uavInitCommand = new UavInitInfoCmd(uavInitReplyCmd.getBoxSn()); |
| | | this.sendMessage(tyConfiguration.getIpPort(), uavInitCommand); |
| | | log.info("收到无人机初始化详情-回复防止再次发送"); |
| | | logPrint("无人机初始化详情", uavInitCommand.getBoxSn()); |
| | | } |
| | | if (tyCommand instanceof UavReadyReplyCmd) { |
| | | UavReadyReplyCmd uavReadyReplyCmd = (UavReadyReplyCmd) tyCommand; |
| | | log.info("收到无人机准备完成通知,电池电量{} 经度{} 纬度{} 海拔{}", uavReadyReplyCmd.getBatteryPower(), uavReadyReplyCmd.getLongitude(), uavReadyReplyCmd.getLatitude(), uavReadyReplyCmd.getAltitude()); |
| | | logPrint("无人机准备完成通知", uavReadyReplyCmd.getBatteryPower()); |
| | | } |
| | | if (tyCommand instanceof CameraModeReplyCmd) { |
| | | CameraModeReplyCmd cameraModeReplyCommand = (CameraModeReplyCmd) tyCommand; |
| | | log.info("收到无人机设置相机模式回复:{} 错误码:{}", String.format("0x%02X", cameraModeReplyCommand.getResult() & 0xFF), cameraModeReplyCommand.getErrorCode()); |
| | | logPrint("无人机设置相机模式", cameraModeReplyCommand.getResult(), cameraModeReplyCommand.getErrorCode()); |
| | | } |
| | | if (tyCommand instanceof FlyWayEndReplyCmd) { |
| | | FlyWayEndReplyCmd flyWayEndReplyCmd = (FlyWayEndReplyCmd) tyCommand; |
| | | log.info("收到无人机飞行结束通知:状态:{}", flyWayEndReplyCmd.getResult()); |
| | | logPrint("无人机飞行结束", flyWayEndReplyCmd.getResult(), flyWayEndReplyCmd.getErrorCode()); |
| | | } |
| | | if (tyCommand instanceof CapturePicReplyCmd) { |
| | | CapturePicReplyCmd capturePicReplyCommand = (CapturePicReplyCmd) tyCommand; |
| | | log.info("收到无人机拍照回复:{} 错误码:{}", String.format("0x%02X", capturePicReplyCommand.getResult() & 0xFF), capturePicReplyCommand.getErrorCode()); |
| | | logPrint("无人机拍照", capturePicReplyCommand.getResult(), capturePicReplyCommand.getErrorCode()); |
| | | } |
| | | if (tyCommand instanceof RecordStartReplyCmd) { |
| | | RecordStartReplyCmd recordStartReplyCommand = (RecordStartReplyCmd) tyCommand; |
| | | log.info("收到无人机开始录像回复:{} 错误码:{}", String.format("0x%02X", recordStartReplyCommand.getResult() & 0xFF), recordStartReplyCommand.getErrorCode()); |
| | | logPrint("无人机开始录像", recordStartReplyCommand.getResult(), recordStartReplyCommand.getErrorCode()); |
| | | } |
| | | if (tyCommand instanceof RecordStopReplyCmd) { |
| | | RecordStopReplyCmd recordStopReplyCommand = (RecordStopReplyCmd) tyCommand; |
| | | log.info("收到无人机停止录像回复:{} 错误码:{}", String.format("0x%02X", recordStopReplyCommand.getResult() & 0xFF), recordStopReplyCommand.getErrorCode()); |
| | | logPrint("无人机停止录像", recordStopReplyCommand.getResult(), recordStopReplyCommand.getErrorCode()); |
| | | } |
| | | //起飞回复 |
| | | if (tyCommand instanceof TakeOffReplyCmd) { |
| | | TakeOffReplyCmd takeOffReplyCommand = (TakeOffReplyCmd) tyCommand; |
| | | log.info("收到无人机起飞回复:{} 错误码:{}", String.format("0x%02X", takeOffReplyCommand.getResult() & 0xFF), takeOffReplyCommand.getErrorCode()); |
| | | logPrint("无人机起飞", takeOffReplyCommand.getResult(), takeOffReplyCommand.getErrorCode()); |
| | | } |
| | | //返航回复 |
| | | if (tyCommand instanceof ReturnHomeReplyCmd) { |
| | | ReturnHomeReplyCmd returnHomeReplyCmd = (ReturnHomeReplyCmd) tyCommand; |
| | | log.info("收到无人机返航回复:{} 错误码:{}", String.format("0x%02X", returnHomeReplyCmd.getResult() & 0xFF), returnHomeReplyCmd.getErrorCode()); |
| | | logPrint("无人机返航", returnHomeReplyCmd.getResult(), returnHomeReplyCmd.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("收到{}回复:{} 错误码:{}【{}】", |
| | | message, |
| | | String.format("0x%02X", result & 0xFF), |
| | | errorCode, |
| | | ErrorCodeEnum.getDescByCode(errorCode)); |
| | | } |
| | | |
| | | /** |
| | | * 定时3秒发送心跳指令 |
| | | */ |