feat(drone-dock): 添加安全控制接口本地模拟调试

接入 command 请求合同与底部暂停、继续、返航、取消返航交互;支持同任务单次回查、防重复提交及未知结果锁。保留真实指令禁飞拦截,补充隔离测试、模拟回执与截图。
This commit is contained in:
2026-10-30 10:32:31 +08:00
parent b95b251de1
commit 20877b425c
21 changed files with 2668 additions and 43 deletions
@@ -0,0 +1,67 @@
import Foundation
/// 朱工 command 接口明确允许的四类安全指令,不接受服务端未知动作直接透传。
enum DroneDockSafetyCommand: String, CaseIterable, Sendable {
/// 暂停航线并悬停待命。
case pause = "flighttask_pause"
/// 恢复已暂停的航线。
case resume = "flighttask_recovery"
/// 立即返航;服务端会中断当前任务并释放飞行锁。
case returnHome = "return_home"
/// 取消返航,不代表已恢复或重新创建原拍摄任务。
case cancelReturn = "return_home_cancel"
}
/// 指令受理回执;仅保留后端返回的身份、读数与状态,不推断设备已完成动作。
struct DroneDockCommandResponse: Decodable, Equatable, Sendable {
/// 文档要求回显的订单飞行任务 ID。
let orderFlightTaskID: Int?
/// 本次回显的指令码,API 核验其与请求一致。
let command: String?
/// 任务实际锁定的机场标识,客户端不提交或覆盖它。
let airportSN: String?
/// 司空状态允许任意 JSON 类型;null 与缺失都不构成执行成功证据。
let djiStatus: DroneDockHomeJSONValue?
/// 非实时采集的六项读数,不替代 shooting 完整快照。
let metrics: [DroneDockHomeMetric]
/// 完整 data 格式化 JSON,供本地模拟联调查看未知字段与原始类型。
let dataJSON: String
/// 朱工指令回执字段映射。
private enum CodingKeys: String, CodingKey {
case orderFlightTaskID = "order_flight_task_id", command, airportSN = "airport_sn"
case djiStatus = "dji_status", metrics
}
/// 不补造身份、状态或读数,完整 JSON 仍保留实际出现的 null 字段。
init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: CodingKeys.self)
orderFlightTaskID = try container.decodeIfPresent(Int.self, forKey: .orderFlightTaskID)
command = try container.decodeIfPresent(String.self, forKey: .command)
airportSN = try container.decodeIfPresent(String.self, forKey: .airportSN)
djiStatus = try container.decodeIfPresent(DroneDockHomeJSONValue.self, forKey: .djiStatus)
metrics = try container.decodeIfPresent([DroneDockHomeMetric].self, forKey: .metrics) ?? []
let raw = try DroneDockHomeJSONValue(from: decoder)
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted, .sortedKeys, .withoutEscapingSlashes]
dataJSON = String(decoding: try encoder.encode(DroneDockCommandJSONSnapshot(value: raw)), as: UTF8.self)
}
}
/// 将现有 JSON 值完整格式化,不更改指令回执的原始值与结构。
private struct DroneDockCommandJSONSnapshot: Encodable {
let value: DroneDockHomeJSONValue
/// 保留字符串、数字、布尔、null 和嵌套对象,不添加业务成功推断。
func encode(to encoder: Encoder) throws {
var container = encoder.singleValueContainer()
switch value {
case .object(let object): try container.encode(object.mapValues { DroneDockCommandJSONSnapshot(value: $0) })
case .array(let array): try container.encode(array.map { DroneDockCommandJSONSnapshot(value: $0) })
case .string(let text): try container.encode(text)
case .number(let number): try container.encode(number)
case .bool(let flag): try container.encode(flag)
case .null: try container.encodeNil()
}
}
}
@@ -189,6 +189,26 @@ struct DroneDockShootingUI: Decodable, Equatable, Sendable {
let title: String?
/// 服务端阶段说明,不由 GET 请求成功拼造飞行进度。
let message: String?
/// 服务端实际提供的安全指令;缺失时保持未知,不据阶段文案自行补齐。
let commands: [DroneDockShootingCommand]?
/// 保留既有展示构造方式,新增动作列表默认为未知。
init(phase: String?, title: String?, message: String?, commands: [DroneDockShootingCommand]? = nil) {
self.phase = phase
self.title = title
self.message = message
self.commands = commands
}
}
/// shooting 或 start-shoot 的指令展示项;原始字符串保留,执行时另作白名单校验。
struct DroneDockShootingCommand: Decodable, Equatable, Sendable {
/// 服务端指令码,未知值不应开放动作。
let command: String?
/// 服务端按钮标题。
let label: String?
/// 服务端按钮副标题。
let sub: String?
}
/// 将现有 JSON 值解码结果重新格式化,完整保留 shooting 的未建模字段。