feat(drone-dock): 添加安全控制接口本地模拟调试
接入 command 请求合同与底部暂停、继续、返航、取消返航交互;支持同任务单次回查、防重复提交及未知结果锁。保留真实指令禁飞拦截,补充隔离测试、模拟回执与截图。
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
import Foundation
|
||||
|
||||
/// 基于既有订单飞行任务发送单次安全指令;禁飞期间仅向本地模拟页面注入。
|
||||
protocol DroneDockCommandSending: Sendable {
|
||||
/// 提交任务 ID 和白名单指令,不创建任务、不选机,也不自动重试。
|
||||
@MainActor
|
||||
func sendCommand(taskID: Int, command: DroneDockSafetyCommand) async throws -> DroneDockCommandResponse
|
||||
}
|
||||
|
||||
/// 朱工 command 合同适配,真实传输仍受统一 Debug 禁飞策略阻断。
|
||||
@MainActor
|
||||
final class DroneDockCommandAPI: DroneDockCommandSending {
|
||||
private let client: APIClient
|
||||
|
||||
/// 注入统一客户端;模拟调试使用完全不转发网络的响应替身。
|
||||
init(client: APIClient) { self.client = client }
|
||||
|
||||
/// 每次仅发送 id 和 command,回执必须对应同一任务及同一指令。
|
||||
func sendCommand(taskID: Int, command: DroneDockSafetyCommand) async throws -> DroneDockCommandResponse {
|
||||
try Task.checkCancellation()
|
||||
guard taskID > 0 else { throw APIError.networkFailed("缺少有效拍摄任务 ID,请返回任务页确认") }
|
||||
let response: DroneDockCommandResponse = try await client.send(APIRequest(
|
||||
method: .post, path: "/api/app/airport/command",
|
||||
body: CommandBody(taskID: taskID, command: command.rawValue)
|
||||
))
|
||||
guard response.orderFlightTaskID == taskID, response.command == command.rawValue else {
|
||||
throw APIError.decodeFailed("安全指令回执的任务或指令不一致,请核对原任务状态")
|
||||
}
|
||||
return response
|
||||
}
|
||||
|
||||
/// 指令请求只携带任务身份及已确认的指令码。
|
||||
private struct CommandBody: Encodable {
|
||||
let taskID: Int
|
||||
let command: String
|
||||
|
||||
/// 朱工请求字段映射,不附加飞机或模拟标志。
|
||||
private enum CodingKeys: String, CodingKey { case taskID = "id", command }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user