From f5f485b1b1919e6d312ed72628ed7c01d2f57def Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Wed, 19 Mar 2025 16:57:48 +0800
Subject: [PATCH] 增加图片回传完成通知解析
---
ard-work/src/main/java/com/ard/tianyu/netty/handler/MessageProtocolDecoder.java | 23 ++++++++++-
ard-work/src/main/java/com/ard/tianyu/service/impl/TyServiceImpl.java | 33 +++++++++++-----
ard-work/src/main/java/com/ard/tianyu/netty/command/camera/PicUploadCompletedReplyCmd.java | 42 +++++++++++++++++++++
3 files changed, 86 insertions(+), 12 deletions(-)
diff --git a/ard-work/src/main/java/com/ard/tianyu/netty/command/camera/PicUploadCompletedReplyCmd.java b/ard-work/src/main/java/com/ard/tianyu/netty/command/camera/PicUploadCompletedReplyCmd.java
new file mode 100644
index 0000000..f3ed622
--- /dev/null
+++ b/ard-work/src/main/java/com/ard/tianyu/netty/command/camera/PicUploadCompletedReplyCmd.java
@@ -0,0 +1,42 @@
+package com.ard.tianyu.netty.command.camera;
+
+import com.ard.tianyu.netty.command.BaseCmd;
+import io.netty.buffer.ByteBuf;
+import lombok.Data;
+
+import java.io.UnsupportedEncodingException;
+import java.nio.charset.StandardCharsets;
+
+/**
+ * 图片上传完成通知回复指令
+ *
+ * @author liusuyi
+ * @date 2024年10月26日11:54
+ **/
+@Data
+public class PicUploadCompletedReplyCmd extends BaseCmd {
+ private final byte encryptFlag = 0x00; // 加密标志
+ private final byte actionCode = 0x3D; // 动作编号
+ private final double longitude; // 经度
+ private final double latitude; // 纬度
+ private final long timestamp; // 时间戳
+ private final long picLength; // 图片大小
+ private final String picUrl; // 原图地址
+
+ public PicUploadCompletedReplyCmd(double longitude, double latitude, long timestamp, long picLength,
+ byte[] boxSn, byte[] pic) {
+ setDataHeader((short) 0x6A77); // 设置帧头
+ setCmdCode((byte) 0x09); // 设置指令编号
+ //setDataLength((short) 39); // 数据长度
+ this.longitude = longitude;
+ this.latitude = latitude;
+ this.timestamp = timestamp;
+ this.picLength = picLength;
+ setBoxSn(boxSn);
+ this.picUrl = new String(pic, StandardCharsets.UTF_8); // 指定编码为 UTF-8;
+ }
+
+ public void encode(ByteBuf out) {
+
+ }
+}
diff --git a/ard-work/src/main/java/com/ard/tianyu/netty/handler/MessageProtocolDecoder.java b/ard-work/src/main/java/com/ard/tianyu/netty/handler/MessageProtocolDecoder.java
index dc3490c..7ad74d6 100644
--- a/ard-work/src/main/java/com/ard/tianyu/netty/handler/MessageProtocolDecoder.java
+++ b/ard-work/src/main/java/com/ard/tianyu/netty/handler/MessageProtocolDecoder.java
@@ -15,6 +15,7 @@
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;
@@ -30,6 +31,7 @@
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.ByteToMessageDecoder;
import lombok.extern.slf4j.Slf4j;
+
import java.util.List;
@Slf4j
@@ -66,11 +68,25 @@
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 数据
@@ -82,7 +98,8 @@
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());
@@ -94,7 +111,7 @@
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;
@@ -179,6 +196,7 @@
}
return null;
}
+
//处理D2指令回复
private BaseCmd processD2ReplyCmd(ByteBuf in, byte actionCode) {
byte result = in.readByte();
@@ -195,6 +213,7 @@
}
return null;
}
+
//处理特殊D1指令回复
private BaseCmd processSpecialD1ReplyCmd(ByteBuf in, byte actionCode, String boxSn) {
switch (actionCode) {
diff --git a/ard-work/src/main/java/com/ard/tianyu/service/impl/TyServiceImpl.java b/ard-work/src/main/java/com/ard/tianyu/service/impl/TyServiceImpl.java
index 359228f..675a2d9 100644
--- a/ard-work/src/main/java/com/ard/tianyu/service/impl/TyServiceImpl.java
+++ b/ard-work/src/main/java/com/ard/tianyu/service/impl/TyServiceImpl.java
@@ -242,7 +242,11 @@
*/
@Override
public Boolean capturePic(CapturePicDTO capturePicDto) {
+ //设置相机模式为拍照模式
updateCameraMode(CameraModeDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01).build());
+ //设置拍照回传
+ photoReturnToggle(PhotoReturnToggleDTO.builder().boxSn(capturePicDto.getBoxSn()).actionParam((byte) 0x01).build());
+
CapturePicCmd capturePicCommand = new CapturePicCmd(capturePicDto);
this.sendMessage(tyConfiguration.getIpPort(), capturePicCommand);
return true;
@@ -629,13 +633,18 @@
case 0x02:
// 处理注册消息
HeartbeatReplyCmd heartbeatReplyCmd = (HeartbeatReplyCmd) tyCommand;
- logPrint("心跳消息", heartbeatReplyCmd.getTimestamp());
+ //logPrint("心跳消息", heartbeatReplyCmd.getTimestamp());
break;
case 0x03:
// 处理订阅消息
break;
case 0x04:
// 处理取消订阅消息
+ break;
+ case 0x09:
+ // 处理图片上传完成通知
+ PicUploadCompletedReplyCmd picUploadCompletedReplyCmd = (PicUploadCompletedReplyCmd) tyCommand;
+ logPrint("图片上传完成", picUploadCompletedReplyCmd.getPicUrl());
break;
case 0x0A:
// 处理云盒开关机通知消息
@@ -646,14 +655,14 @@
// 处理无人机状态消息
UavStateCmd uavStateCmd = (UavStateCmd) tyCommand;
UavStateCache.putUavState(uavStateCmd.getUavState());
- logPrint("无人机状态", uavStateCmd.getUavState().getBoxSn());
- // WebSocketUtil.sendMessageAll(uavStateCmd.getUavState());
+ //logPrint("无人机状态", uavStateCmd.getUavState().getBoxSn());
+ // WebSocketUtil.sendMessageAll(uavStateCmd.getUavState());
break;
case (byte) 0xA9:
// 处理无人机遥测消息
UavTelemetryDataCmd uavTelemetryDataCmd = (UavTelemetryDataCmd) tyCommand;
UavTelemetryDataCache.putUavTelemetryData(uavTelemetryDataCmd.getTelemetryData());
- logPrint("无人机遥测", uavTelemetryDataCmd.getTelemetryData().getBoxSn());
+ //logPrint("无人机遥测", uavTelemetryDataCmd.getTelemetryData().getBoxSn());
//WebSocketUtil.sendMessageAll(uavTelemetryDataCmd.getTelemetryData());
break;
@@ -661,7 +670,7 @@
// 处理无人机信道质量数据
SignalInfoCmd signalInfoCmd = (SignalInfoCmd) tyCommand;
UavSignalInfoCache.putUavSignalInfoCache(signalInfoCmd.getSignalInfo());
- logPrint("无人机信道质量", signalInfoCmd.getSignalInfo().getBoxSn());
+ //logPrint("无人机信道质量", signalInfoCmd.getSignalInfo().getBoxSn());
break;
case (byte) 0xD1:
// 处理无人机
@@ -728,7 +737,8 @@
//到达指点飞行位置回复
if (tyCommand instanceof PointControlReachedReplyCmd) {
PointControlReachedReplyCmd pointControlReachedReplyCmd = (PointControlReachedReplyCmd) tyCommand;
- logPrint("到达指点飞行位置", pointControlReachedReplyCmd.getResult(), pointControlReachedReplyCmd.getErrorCode());
+ logPrint("到达指点飞行位置", pointControlReachedReplyCmd.getResult(),
+ pointControlReachedReplyCmd.getErrorCode());
}
//紧急制动回复
if (tyCommand instanceof EmergencyBrakeReplyCmd) {
@@ -763,19 +773,22 @@
//设置返航高度回复
if (tyCommand instanceof ReturnHeightSettingReplyCmd) {
ReturnHeightSettingReplyCmd returnHeightSettingReplyCmd = (ReturnHeightSettingReplyCmd) tyCommand;
- logPrint("设置返航高度", returnHeightSettingReplyCmd.getResult(), returnHeightSettingReplyCmd.getErrorCode());
+ logPrint("设置返航高度", returnHeightSettingReplyCmd.getResult(),
+ returnHeightSettingReplyCmd.getErrorCode());
}
//设置返航点回复
if (tyCommand instanceof ReturnPointSettingReplyCmd) {
ReturnPointSettingReplyCmd returnPointSettingReplyCmd = (ReturnPointSettingReplyCmd) tyCommand;
- logPrint("设置返航点", returnPointSettingReplyCmd.getResult(), returnPointSettingReplyCmd.getErrorCode());
+ logPrint("设置返航点", returnPointSettingReplyCmd.getResult(),
+ returnPointSettingReplyCmd.getErrorCode());
}
break;
case (byte) 0xD2:
//设置视频码流回复
if (tyCommand instanceof VideoStreamSettingReplyCmd) {
VideoStreamSettingReplyCmd videoStreamSettingReplyCmd = (VideoStreamSettingReplyCmd) tyCommand;
- logPrint("设置视频码流", videoStreamSettingReplyCmd.getResult(), videoStreamSettingReplyCmd.getErrorCode());
+ logPrint("设置视频码流", videoStreamSettingReplyCmd.getResult(),
+ videoStreamSettingReplyCmd.getErrorCode());
}
break;
default:
@@ -786,7 +799,7 @@
//公共日志打印
private void logPrint(String message, Object obj) {
- log.debug("收到{}回复{}", message, obj);
+ log.warn("收到{}回复{}", message, obj);
}
//公共日志打印
--
Gitblit v1.9.3