From 2a729cd545ddbbab1eae6cbcf819783ef11da4ab Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Mon, 24 Nov 2025 09:56:07 +0800
Subject: [PATCH] 增加格式化存储卡接口
---
ard-work/src/main/java/com/ard/work/component/netty/handler/MessageProtocolDecoder.java | 8 +-
ard-work/src/main/java/com/ard/work/domain/dto/camera/FormatSdCardDTO.java | 19 ++++++
ard-work/src/main/java/com/ard/work/component/netty/command/camera/FormatSdCardCmd.java | 35 +++++++++++
ard-work/src/main/java/com/ard/work/component/netty/command/camera/FormatSdCardReplyCmd.java | 30 ++++++++++
ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java | 17 +++++
ard-admin/src/main/java/com/ard/web/controller/work/UavCameraController.java | 11 +++
ard-work/src/main/java/com/ard/work/service/ITyService.java | 5 +
7 files changed, 120 insertions(+), 5 deletions(-)
diff --git a/ard-admin/src/main/java/com/ard/web/controller/work/UavCameraController.java b/ard-admin/src/main/java/com/ard/web/controller/work/UavCameraController.java
index 4562849..e613605 100644
--- a/ard-admin/src/main/java/com/ard/web/controller/work/UavCameraController.java
+++ b/ard-admin/src/main/java/com/ard/web/controller/work/UavCameraController.java
@@ -73,6 +73,15 @@
return AjaxResult.success();
}
+ @ApiOperation("格式化存储卡")
+ @ApiOperationSupport(order = 9)
+ @PostMapping("/formatSdCard")
+ public AjaxResult formatSdCard(@RequestBody FormatSdCardDTO formatSdCardDTO) {
+ tyService.formatSdCard(formatSdCardDTO);
+ return AjaxResult.success();
+ }
+
+
@ApiOperation(value = "打开或关闭照片回传", notes = "actionParam值:0-关闭,1-打开")
@ApiOperationSupport(order = 10)
@PostMapping("/photoReturnToggle")
@@ -81,4 +90,6 @@
return AjaxResult.success();
}
+
+
}
\ No newline at end of file
diff --git a/ard-work/src/main/java/com/ard/work/component/netty/command/camera/FormatSdCardCmd.java b/ard-work/src/main/java/com/ard/work/component/netty/command/camera/FormatSdCardCmd.java
new file mode 100644
index 0000000..4a09997
--- /dev/null
+++ b/ard-work/src/main/java/com/ard/work/component/netty/command/camera/FormatSdCardCmd.java
@@ -0,0 +1,35 @@
+package com.ard.work.component.netty.command.camera;
+
+import com.ard.work.component.netty.command.BaseCmd;
+import com.ard.work.domain.dto.camera.FormatSdCardDTO;
+import io.netty.buffer.ByteBuf;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * Description: 格式化存储卡指令
+ * Author: lsy
+ * Date: 2025年11月24日9:31
+ **/
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class FormatSdCardCmd extends BaseCmd {
+ private final byte encryptFlag = 0x00; // 加密标志
+ private final byte actionCode = 0x40; // 动作编号
+
+ public FormatSdCardCmd(FormatSdCardDTO formatSdCardDTO) {
+ setDataHeader((short) 0x7479);
+ setDataLength((short) 18);
+ setBoxSn(formatSdCardDTO.getBoxSn().getBytes());
+ setCmdCode((byte) 0xD1);
+ }
+ @Override
+ public void encode(ByteBuf out) {
+ out.writeShort(getDataHeader()); // 写入数据头
+ out.writeShort(getDataLength()); // 写入数据长度
+ out.writeBytes(getBoxSn()); // 写入盒子SN
+ out.writeByte(getCmdCode()); // 写入命令码
+ out.writeByte(encryptFlag); // 写入加密标志
+ out.writeByte(actionCode); // 写入动作编号
+ }
+}
diff --git a/ard-work/src/main/java/com/ard/work/component/netty/command/camera/FormatSdCardReplyCmd.java b/ard-work/src/main/java/com/ard/work/component/netty/command/camera/FormatSdCardReplyCmd.java
new file mode 100644
index 0000000..6c4f054
--- /dev/null
+++ b/ard-work/src/main/java/com/ard/work/component/netty/command/camera/FormatSdCardReplyCmd.java
@@ -0,0 +1,30 @@
+package com.ard.work.component.netty.command.camera;
+
+import com.ard.work.component.netty.command.BaseCmd;
+import io.netty.buffer.ByteBuf;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+
+/**
+ * Description: 格式化存储卡回复指令
+ * Author: lsy
+ * Date: 2025年11月24日9:31
+ **/
+@Data
+@EqualsAndHashCode(callSuper = false)
+public class FormatSdCardReplyCmd extends BaseCmd {
+ private final byte result; // 执行结果
+ private final Integer errorCode; // 错误码
+ public FormatSdCardReplyCmd(String boxSn, Byte result, Integer errorCode) {
+ setDataHeader((short) 0x6A77);
+ setDataLength((short) 20);
+ setBoxSn(boxSn.getBytes());
+ setCmdCode((byte) 0xD1);
+ this.result = result;
+ this.errorCode = errorCode;
+ }
+ @Override
+ public void encode(ByteBuf out) {
+
+ }
+}
diff --git a/ard-work/src/main/java/com/ard/work/component/netty/handler/MessageProtocolDecoder.java b/ard-work/src/main/java/com/ard/work/component/netty/handler/MessageProtocolDecoder.java
index 10ea780..a36e068 100644
--- a/ard-work/src/main/java/com/ard/work/component/netty/handler/MessageProtocolDecoder.java
+++ b/ard-work/src/main/java/com/ard/work/component/netty/handler/MessageProtocolDecoder.java
@@ -1,6 +1,7 @@
package com.ard.work.component.netty.handler;// MessageProtocolDecoder.java
import com.ard.common.utils.ByteUtils;
+import com.ard.work.component.netty.command.camera.*;
import com.ard.work.component.netty.command.manual.*;
import com.ard.work.component.netty.command.wayline.*;
import com.ard.work.domain.dto.converter.realdata.UavSignalInfoConverter;
@@ -10,13 +11,8 @@
import com.ard.work.domain.dto.state.UavState;
import com.ard.work.domain.dto.telemetry.TelemetryData;
import com.ard.work.component.netty.command.BaseCmd;
-import com.ard.work.component.netty.command.camera.CameraModeReplyCmd;
-import com.ard.work.component.netty.command.camera.CapturePicReplyCmd;
-import com.ard.work.component.netty.command.camera.RecordStartReplyCmd;
-import com.ard.work.component.netty.command.camera.RecordStopReplyCmd;
import com.ard.work.component.netty.command.notice.BoxPowerStatusReplyCmd;
import com.ard.work.component.netty.command.notice.FlyWayEndReplyCmd;
-import com.ard.work.component.netty.command.camera.PicUploadCompletedReplyCmd;
import com.ard.work.component.netty.command.notice.UavReadyReplyCmd;
import com.ard.work.component.netty.command.real.SignalInfoCmd;
import com.ard.work.component.netty.command.real.UavStateCmd;
@@ -190,6 +186,8 @@
return new FlyWayEndReplyCmd(boxSn, result, errorCode);
// Special cases
case 0x3D:
+ case 0x40:
+ return new FormatSdCardReplyCmd(boxSn, result, errorCode);
case 0x42:
return processSpecialD1ReplyCmd(in, actionCode, boxSn);
// Add other cases...
diff --git a/ard-work/src/main/java/com/ard/work/domain/dto/camera/FormatSdCardDTO.java b/ard-work/src/main/java/com/ard/work/domain/dto/camera/FormatSdCardDTO.java
new file mode 100644
index 0000000..bc28d8d
--- /dev/null
+++ b/ard-work/src/main/java/com/ard/work/domain/dto/camera/FormatSdCardDTO.java
@@ -0,0 +1,19 @@
+package com.ard.work.domain.dto.camera;
+
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * Description: 格式化存储卡实体对象
+ * Author: lsy
+ * Date: 2025年11月24日9:39
+ **/
+@Data
+@Builder
+@AllArgsConstructor
+@NoArgsConstructor
+public class FormatSdCardDTO {
+ private String boxSn;
+}
diff --git a/ard-work/src/main/java/com/ard/work/service/ITyService.java b/ard-work/src/main/java/com/ard/work/service/ITyService.java
index c8fd86e..b5b1350 100644
--- a/ard-work/src/main/java/com/ard/work/service/ITyService.java
+++ b/ard-work/src/main/java/com/ard/work/service/ITyService.java
@@ -112,6 +112,11 @@
Boolean speedControl(SpeedControlDTO speedControlDto);
/**
+ * 格式化存储卡
+ */
+ Boolean formatSdCard(FormatSdCardDTO formatSdCardDTO);
+
+ /**
* 设置相机模式
*/
Boolean updateCameraMode(CameraModeDTO cameraModeDTO);
diff --git a/ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java b/ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java
index 5908682..6543a15 100644
--- a/ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java
+++ b/ard-work/src/main/java/com/ard/work/service/impl/TyServiceImpl.java
@@ -287,6 +287,18 @@
return true;
}
+ @Override
+ public Boolean formatSdCard(FormatSdCardDTO formatSdCardDTO) {
+ String boxSn = formatSdCardDTO.getBoxSn();
+ ArdDroneInfo ardDroneInfo = ardDroneService.selectArdDroneByboxSn(boxSn);
+ if (ardDroneInfo == null) {
+ throw new ControlException("未找到对应的飞行器信息,boxSn:{}" + boxSn);
+ }
+ FormatSdCardCmd formatSdCardCmd = new FormatSdCardCmd(formatSdCardDTO);
+ this.sendMessage(ardDroneInfo.getServerId(), formatSdCardCmd);
+ return true;
+ }
+
/**
* 设置相机模式
*/
@@ -934,6 +946,11 @@
FlyWayEndReplyCmd flyWayEndReplyCmd = (FlyWayEndReplyCmd) tyCommand;
logPrint("无人机飞行结束", flyWayEndReplyCmd.getResult(), flyWayEndReplyCmd.getErrorCode());
}
+ //格式化存储卡
+ if (tyCommand instanceof FormatSdCardReplyCmd) {
+ FormatSdCardReplyCmd formatSdCardReplyCmd = (FormatSdCardReplyCmd) tyCommand;
+ logPrint("格式化存储卡", formatSdCardReplyCmd.getResult(), formatSdCardReplyCmd.getErrorCode());
+ }
if (tyCommand instanceof CapturePicReplyCmd) {
CapturePicReplyCmd capturePicReplyCommand = (CapturePicReplyCmd) tyCommand;
logPrint("无人机拍照", capturePicReplyCommand.getResult(), capturePicReplyCommand.getErrorCode());
--
Gitblit v1.9.3