feat: 完善机巢任务安全控制与状态诊断
同步新版飞控与 WebSocket 回执合同,完善独立指令等待、暂停继续和返航状态;增加真机诊断并优化倒计时与素材库展示。
This commit is contained in:
@@ -4,7 +4,7 @@ import Foundation
|
||||
protocol DroneDockCommandSending: Sendable {
|
||||
/// 提交任务 ID 和白名单指令,不创建任务、不选机,也不自动重试。
|
||||
@MainActor
|
||||
func sendCommand(taskID: Int, command: DroneDockSafetyCommand) async throws -> DroneDockCommandResponse
|
||||
func sendCommand(taskID: Int, command: DroneDockSafetyCommand, clientRequestID: String) async throws -> DroneDockCommandResponse
|
||||
}
|
||||
|
||||
/// 朱工 command 合同适配,真实传输仍受统一 Debug 禁飞策略阻断。
|
||||
@@ -15,15 +15,17 @@ final class DroneDockCommandAPI: DroneDockCommandSending {
|
||||
/// 注入统一客户端;模拟调试使用完全不转发网络的响应替身。
|
||||
init(client: APIClient) { self.client = client }
|
||||
|
||||
/// 每次仅发送 id 和 command,回执必须对应同一任务及同一指令。
|
||||
func sendCommand(taskID: Int, command: DroneDockSafetyCommand) async throws -> DroneDockCommandResponse {
|
||||
/// 每次点击使用独立幂等键,回执必须对应同一任务、指令及请求。
|
||||
func sendCommand(taskID: Int, command: DroneDockSafetyCommand, clientRequestID: String) async throws -> DroneDockCommandResponse {
|
||||
try Task.checkCancellation()
|
||||
guard taskID > 0 else { throw APIError.networkFailed("缺少有效拍摄任务 ID,请返回任务页确认") }
|
||||
guard taskID > 0, !clientRequestID.isEmpty else { throw APIError.networkFailed("缺少有效拍摄任务或指令标识,请返回任务页确认") }
|
||||
let response: DroneDockCommandResponse = try await client.send(APIRequest(
|
||||
method: .post, path: "/api/app/airport/command",
|
||||
body: CommandBody(taskID: taskID, command: command.rawValue)
|
||||
body: CommandBody(taskID: taskID, command: command.rawValue, clientRequestID: clientRequestID)
|
||||
))
|
||||
guard response.orderFlightTaskID == taskID, response.command == command.rawValue else {
|
||||
guard response.orderFlightTaskID == taskID, response.command == command.rawValue,
|
||||
DroneDockHomeMetric.usableText(response.commandID) != nil,
|
||||
response.clientRequestID == nil || response.clientRequestID == clientRequestID else {
|
||||
throw APIError.decodeFailed("安全指令回执的任务或指令不一致,请核对原任务状态")
|
||||
}
|
||||
return response
|
||||
@@ -33,8 +35,9 @@ final class DroneDockCommandAPI: DroneDockCommandSending {
|
||||
private struct CommandBody: Encodable {
|
||||
let taskID: Int
|
||||
let command: String
|
||||
let clientRequestID: String
|
||||
|
||||
/// 朱工请求字段映射,不附加飞机或模拟标志。
|
||||
private enum CodingKeys: String, CodingKey { case taskID = "id", command }
|
||||
private enum CodingKeys: String, CodingKey { case taskID = "id", command, clientRequestID = "client_request_id" }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user