| | |
| | | package com.ard.tianyu.netty.handler;// MessageProtocolDecoder.java |
| | | |
| | | import com.ard.common.utils.ByteUtils; |
| | | 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.signal.SignalInfo; |
| | | import com.ard.tianyu.model.dto.state.UavState; |
| | | import com.ard.tianyu.model.dto.telemetry.TelemetryData; |
| | | import com.ard.tianyu.netty.command.BaseCmd; |
| | | import com.ard.tianyu.netty.command.camera.CameraModeReplyCmd; |
| | | import com.ard.tianyu.netty.command.camera.CapturePicReplyCmd; |
| | |
| | | case (byte) 0xA8: |
| | | byte[] uavStatus = new byte[dataLength - 1]; |
| | | in.readBytes(uavStatus); // 读取 ProtoBuf 数据 |
| | | TelemetryDataPB.UavState uavState = TelemetryDataPB.UavState.parseFrom(uavStatus); |
| | | TelemetryDataPB.UavState uavStatePB = TelemetryDataPB.UavState.parseFrom(uavStatus); |
| | | UavState uavState = UavStateConverter.convertProtoToEntity(uavStatePB); |
| | | baseCmd = new UavStateCmd(uavState); |
| | | log.debug("无人机状态数据: {}", uavState.getBoxSn()); |
| | | break; |
| | | case (byte) 0xA9: |
| | | byte[] telemetryDataBytes = new byte[dataLength - 1]; |
| | | in.readBytes(telemetryDataBytes); |
| | | TelemetryDataPB.TelemetryData telemetryData = TelemetryDataPB.TelemetryData.parseFrom(telemetryDataBytes); |
| | | TelemetryDataPB.TelemetryData telemetryDataPB = TelemetryDataPB.TelemetryData.parseFrom(telemetryDataBytes); |
| | | TelemetryData telemetryData = UavTelemetryDataConverter.convertProtoToEntity(telemetryDataPB); |
| | | baseCmd = new UavTelemetryDataCmd(telemetryData); |
| | | log.debug("遥测数据: {}", telemetryData.getBoxSn()); |
| | | break; |
| | |
| | | in.readBytes(signalInfoBytes); |
| | | signalInfoBytes = new byte[dataLength - 20]; |
| | | in.readBytes(signalInfoBytes); |
| | | TelemetryDataPB.SignalInfo signalInfo = TelemetryDataPB.SignalInfo.parseFrom(signalInfoBytes); |
| | | TelemetryDataPB.SignalInfo signalInfoPB = TelemetryDataPB.SignalInfo.parseFrom(signalInfoBytes); |
| | | SignalInfo signalInfo =UavSignalInfoConverter.convertProtoToEntity(signalInfoPB); |
| | | baseCmd = new SignalInfoCmd(signalInfo); |
| | | log.debug("信道质量数据: {}", delayTime); |
| | | break; |
| | |
| | | } |
| | | return null; |
| | | } |
| | | //处理D1指令回复 |
| | | //处理D2指令回复 |
| | | private BaseCmd processD2ReplyCmd(ByteBuf in, byte actionCode) { |
| | | byte result = in.readByte(); |
| | | int errorCode = in.readInt(); |
| | |
| | | return new UavReadyReplyCmd(boxSn, batteryPower, longitude, latitude, altitude); |
| | | //无人机初始化信息回复 |
| | | case 0x42: |
| | | byte[] uavData1 = new byte[in.readableBytes() - 15]; |
| | | in.readBytes(uavData1); |
| | | TelemetryDataPB.UavInitInfo uavInitInfo; |
| | | try { |
| | | uavInitInfo = TelemetryDataPB.UavInitInfo.parseFrom(uavData1); |
| | | } catch (InvalidProtocolBufferException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | return new UavInitReplyCmd(boxSn, uavInitInfo); |
| | | // byte[] uavData1 = new byte[in.readableBytes() - 15]; |
| | | // in.readBytes(uavData1); |
| | | // TelemetryDataPB.UavInitInfo uavInitInfo; |
| | | // try { |
| | | // uavInitInfo = TelemetryDataPB.UavInitInfo.parseFrom(uavData1); |
| | | // } catch (InvalidProtocolBufferException e) { |
| | | // throw new RuntimeException(e); |
| | | // } |
| | | // return new UavInitReplyCmd(boxSn, uavInitInfo); |
| | | default: |
| | | return null; |
| | | } |