| | |
| | | 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.domain.dto.converter.realdata.UavSignalInfoConverter; |
| | | import com.ard.tianyu.domain.dto.converter.realdata.UavStateConverter; |
| | | import com.ard.tianyu.domain.dto.converter.realdata.UavTelemetryDataConverter; |
| | | import com.ard.tianyu.domain.dto.signal.SignalInfo; |
| | | import com.ard.tianyu.domain.dto.state.UavState; |
| | | import com.ard.tianyu.domain.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; |
| | |
| | | import com.ard.tianyu.netty.command.manual.*; |
| | | import com.ard.tianyu.netty.command.notice.BoxPowerStatusReplyCmd; |
| | | import com.ard.tianyu.netty.command.notice.FlyWayEndReplyCmd; |
| | | import com.ard.tianyu.netty.command.camera.PicUploadCompletedReplyCmd; |
| | | import com.ard.tianyu.netty.command.notice.UavReadyReplyCmd; |
| | | import com.ard.tianyu.netty.command.real.SignalInfoCmd; |
| | | import com.ard.tianyu.netty.command.real.UavStateCmd; |
| | | import com.ard.tianyu.netty.command.real.UavTelemetryDataCmd; |
| | | import com.ard.tianyu.netty.command.register.HeartbeatReplyCmd; |
| | | import com.ard.tianyu.netty.command.register.RegisterReplyCmd; |
| | | import com.ard.tianyu.netty.command.register.UavInitReplyCmd; |
| | | import com.ard.tianyu.netty.command.settings.ReturnHeightSettingReplyCmd; |
| | | import com.ard.tianyu.netty.command.settings.ReturnPointSettingReplyCmd; |
| | | import com.ard.tianyu.netty.command.settings.VideoStreamSettingReplyCmd; |
| | | import com.ard.tianyu.netty.command.wayline.*; |
| | | import com.ard.tianyu.netty.protobuf.TelemetryDataPB; |
| | | import com.google.protobuf.InvalidProtocolBufferException; |
| | | import io.netty.buffer.ByteBuf; |
| | | import io.netty.channel.ChannelHandlerContext; |
| | | import io.netty.handler.codec.ByteToMessageDecoder; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Slf4j |
| | |
| | | baseCmd = new HeartbeatReplyCmd(timestamp); |
| | | log.debug("心跳回复: 时间戳 {}", timestamp); |
| | | break; |
| | | case 0x09: |
| | | in.readByte();//加密标志 |
| | | double longitude = in.readDouble(); |
| | | double latitude = in.readDouble(); |
| | | timestamp = in.readLong(); // 读取时间戳 |
| | | long picLength = in.readLong(); // 读取原图大小 |
| | | byte[] boxSn = new byte[15]; |
| | | in.readBytes(boxSn);// 读取boxSn |
| | | byte[] pic = new byte[dataLength - 49]; |
| | | in.readBytes(pic);// 读取原图地址 |
| | | baseCmd = new PicUploadCompletedReplyCmd(longitude, latitude, timestamp, picLength, boxSn, pic); |
| | | log.debug("图片上传完成通知回复: 图片长度 {}", picLength); |
| | | break; |
| | | case 0x0A: |
| | | byte status = in.readByte(); |
| | | baseCmd = new BoxPowerStatusReplyCmd(status); |
| | | log.debug("云盒开机/关机通知回复: 状态 {}", ByteUtils.byteToHex(status)); |
| | | break; |
| | | |
| | | case (byte) 0xA8: |
| | | byte[] uavStatus = new byte[dataLength - 1]; |
| | | in.readBytes(uavStatus); // 读取 ProtoBuf 数据 |
| | |
| | | case (byte) 0xA9: |
| | | byte[] telemetryDataBytes = new byte[dataLength - 1]; |
| | | in.readBytes(telemetryDataBytes); |
| | | TelemetryDataPB.TelemetryData telemetryDataPB = TelemetryDataPB.TelemetryData.parseFrom(telemetryDataBytes); |
| | | TelemetryDataPB.TelemetryData telemetryDataPB = |
| | | TelemetryDataPB.TelemetryData.parseFrom(telemetryDataBytes); |
| | | TelemetryData telemetryData = UavTelemetryDataConverter.convertProtoToEntity(telemetryDataPB); |
| | | baseCmd = new UavTelemetryDataCmd(telemetryData); |
| | | log.debug("遥测数据: {}", telemetryData.getBoxSn()); |
| | |
| | | signalInfoBytes = new byte[dataLength - 20]; |
| | | in.readBytes(signalInfoBytes); |
| | | TelemetryDataPB.SignalInfo signalInfoPB = TelemetryDataPB.SignalInfo.parseFrom(signalInfoBytes); |
| | | SignalInfo signalInfo =UavSignalInfoConverter.convertProtoToEntity(signalInfoPB); |
| | | SignalInfo signalInfo = UavSignalInfoConverter.convertProtoToEntity(signalInfoPB); |
| | | baseCmd = new SignalInfoCmd(signalInfo); |
| | | log.debug("信道质量数据: {}", delayTime); |
| | | break; |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | //处理D2指令回复 |
| | | private BaseCmd processD2ReplyCmd(ByteBuf in, byte actionCode) { |
| | | byte result = in.readByte(); |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | //处理特殊D1指令回复 |
| | | private BaseCmd processSpecialD1ReplyCmd(ByteBuf in, byte actionCode, String boxSn) { |
| | | switch (actionCode) { |
| | |
| | | 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; |
| | | } |