2026-05-25 08:25:48 +00:00
|
|
|
|
#ifndef BATTLEFIELD_CORE_DISPATCH_HPP
|
|
|
|
|
|
#define BATTLEFIELD_CORE_DISPATCH_HPP
|
|
|
|
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
#include <chrono>
|
|
|
|
|
|
#include <cstdint>
|
2026-05-26 05:33:17 +00:00
|
|
|
|
#include <nlohmann/json.hpp>
|
2026-05-25 08:25:48 +00:00
|
|
|
|
#include "core/plan.hpp"
|
|
|
|
|
|
|
|
|
|
|
|
namespace battlefield {
|
|
|
|
|
|
|
2026-05-26 05:33:17 +00:00
|
|
|
|
/// @brief 分发状态枚举
|
|
|
|
|
|
enum class DispatchState : int32_t {
|
|
|
|
|
|
PENDING = 0, ///< 等待分发
|
|
|
|
|
|
IN_PROGRESS = 1, ///< 分发中
|
|
|
|
|
|
SUCCESS = 2, ///< 分发成功
|
|
|
|
|
|
FAILED = 3, ///< 分发失败
|
|
|
|
|
|
RETRYING = 4 ///< 重试中
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2026-05-25 08:25:48 +00:00
|
|
|
|
/// @brief 指令包数据结构,对应 IF-03 输出格式
|
|
|
|
|
|
struct CmdPacket {
|
|
|
|
|
|
std::string packetId; ///< 指令包ID
|
|
|
|
|
|
std::string planId; ///< 关联方案ID
|
|
|
|
|
|
std::string targetUnit; ///< 目标执行单元
|
|
|
|
|
|
std::string payload; ///< 指令载荷(JSON)
|
|
|
|
|
|
std::chrono::system_clock::time_point issueTime; ///< 下发时间
|
2026-05-26 05:33:17 +00:00
|
|
|
|
DispatchState state{DispatchState::PENDING}; ///< 分发状态
|
|
|
|
|
|
int32_t retryCount{0}; ///< 重试次数
|
|
|
|
|
|
int32_t maxRetries{3}; ///< 最大重试次数
|
2026-05-25 08:25:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 分发日志记录,对应 T_DISPATCH_LOG
|
|
|
|
|
|
struct DispatchLog {
|
|
|
|
|
|
std::string logId; ///< 日志ID
|
|
|
|
|
|
std::string planId; ///< 方案ID
|
|
|
|
|
|
std::string action; ///< 操作描述
|
|
|
|
|
|
std::chrono::system_clock::time_point timestamp; ///< 时间戳
|
|
|
|
|
|
bool success{true}; ///< 是否成功
|
2026-05-26 05:33:17 +00:00
|
|
|
|
DispatchState state{DispatchState::SUCCESS}; ///< 状态
|
2026-05-25 08:25:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 监控状态快照
|
|
|
|
|
|
struct MonitorStatus {
|
|
|
|
|
|
int32_t totalTasks{0}; ///< 总任务数
|
|
|
|
|
|
int32_t completedTasks{0}; ///< 已完成
|
|
|
|
|
|
int32_t inProgressTasks{0}; ///< 进行中
|
|
|
|
|
|
int32_t failedTasks{0}; ///< 失败
|
2026-05-26 05:33:17 +00:00
|
|
|
|
int32_t pendingTasks{0}; ///< 等待中
|
2026-05-25 08:25:48 +00:00
|
|
|
|
double progressPercent{0.0}; ///< 总体进度百分比
|
2026-05-26 05:33:17 +00:00
|
|
|
|
bool needsReplan{false}; ///< 是否需要重规划(反馈闭环触发)
|
2026-05-25 08:25:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
2026-05-26 05:33:17 +00:00
|
|
|
|
/// @brief 分发监控模块(SU-05,覆盖 SRS-F-06-001 ~ SRS-F-06-003)
|
2026-05-25 08:25:48 +00:00
|
|
|
|
class DispatchMonitor {
|
|
|
|
|
|
public:
|
2026-05-26 05:33:17 +00:00
|
|
|
|
/// @brief 驱动最终方案分发执行(SRS-F-06-001,对应 IF-03)
|
2026-05-25 08:25:48 +00:00
|
|
|
|
/// @param plan 待分发的最终方案
|
|
|
|
|
|
/// @param targetUnit 目标执行单元
|
|
|
|
|
|
/// @return 生成的指令包
|
|
|
|
|
|
CmdPacket DispatchPlan(const Plan& plan, const std::string& targetUnit);
|
|
|
|
|
|
|
2026-05-26 05:33:17 +00:00
|
|
|
|
/// @brief 模拟方案分发并返回 JSON 格式结果
|
|
|
|
|
|
CmdPacket DispatchPlanAsJson(const Plan& plan, const std::string& targetUnit);
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 重试失败的分发(可靠传输模拟)
|
|
|
|
|
|
/// @param packetId 指令包ID
|
|
|
|
|
|
/// @return 重试成功返回 true
|
|
|
|
|
|
bool RetryDispatch(const std::string& packetId);
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 获取当前状态监控仪表盘数据(SRS-F-06-002)
|
2026-05-25 08:25:48 +00:00
|
|
|
|
MonitorStatus GetMonitorStatus() const;
|
|
|
|
|
|
|
2026-05-26 05:33:17 +00:00
|
|
|
|
/// @brief 构建总览看板数据(SRS-F-06-003)
|
2026-05-25 08:25:48 +00:00
|
|
|
|
std::string GetDashboardData() const;
|
|
|
|
|
|
|
2026-05-26 05:33:17 +00:00
|
|
|
|
/// @brief 以 JSON 格式获取看板数据
|
|
|
|
|
|
nlohmann::json GetDashboardJson() const;
|
|
|
|
|
|
|
2026-05-25 08:25:48 +00:00
|
|
|
|
/// @brief 记录分发日志
|
2026-05-26 05:33:17 +00:00
|
|
|
|
void LogDispatch(const std::string& planId, const std::string& action,
|
|
|
|
|
|
bool success, DispatchState state = DispatchState::SUCCESS);
|
2026-05-25 08:25:48 +00:00
|
|
|
|
|
2026-05-26 05:33:17 +00:00
|
|
|
|
/// @brief 推进执行进度
|
2026-05-25 08:25:48 +00:00
|
|
|
|
/// @param completed 新完成的任务数
|
|
|
|
|
|
void AdvanceProgress(int32_t completed);
|
|
|
|
|
|
|
2026-05-26 05:33:17 +00:00
|
|
|
|
/// @brief 模拟任务失败(触发反馈闭环)
|
|
|
|
|
|
/// @param failed 新失败的任务数
|
|
|
|
|
|
void ReportFailure(int32_t failed);
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 获取分发日志列表
|
|
|
|
|
|
std::vector<DispatchLog> GetLogs() const { return logs_; }
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 获取已下发指令包(可修改)
|
|
|
|
|
|
std::vector<CmdPacket>& GetIssuedPackets() { return issuedPackets_; }
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 检查是否需要触发重规划
|
|
|
|
|
|
bool NeedsReplan() const { return status_.needsReplan; }
|
|
|
|
|
|
|
|
|
|
|
|
/// @brief 清除重规划标志
|
|
|
|
|
|
void ClearReplanFlag() { status_.needsReplan = false; }
|
|
|
|
|
|
|
2026-05-25 08:25:48 +00:00
|
|
|
|
private:
|
2026-05-26 05:33:17 +00:00
|
|
|
|
std::vector<CmdPacket> issuedPackets_; ///< 已下发指令包
|
2026-05-25 08:25:48 +00:00
|
|
|
|
std::vector<DispatchLog> logs_; ///< 分发日志
|
|
|
|
|
|
MonitorStatus status_; ///< 当前监控状态
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace battlefield
|
|
|
|
|
|
|
|
|
|
|
|
#endif // BATTLEFIELD_CORE_DISPATCH_HPP
|