task_auto_execute_plan/include/app.hpp

300 lines
8.5 KiB
C++
Raw Normal View History

2026-04-27 03:50:37 +00:00
#ifndef FZKJ_APP_HPP
#define FZKJ_APP_HPP
#include <cstdint>
#include <string>
#include <vector>
#include <chrono>
#include <memory>
#include <functional>
// ============================================================
// 常量定义
// ============================================================
namespace fzkj {
/// 事件负载固定长度256字节
constexpr std::size_t kEventPayloadSize = 256;
/// 最大传输单元MTU
constexpr std::size_t kMtuSize = 1500;
/// 数据缓存容量1GB
constexpr std::size_t kCacheCapacity = 1024ULL * 1024 * 1024;
/// 持久化周期5分钟单位
constexpr int kPersistIntervalSec = 300;
/// 事件处理延迟阈值500ms
constexpr std::chrono::milliseconds kEventLatencyThreshold(500);
/// 方案分发成功率目标 99.9%
constexpr double kDispatchSuccessRate = 0.999;
} // namespace fzkj
// ============================================================
// 战场事件数据包EvtData / struct_EventPayload
// 定长结构体 256 字节,字节对齐
// ============================================================
namespace fzkj {
#pragma pack(push, 1)
struct EventPayload {
uint8_t event_type; // 事件类型(枚举 0~255
uint64_t timestamp_ms; // 时间戳(毫秒)
uint32_t source_id; // 来源标识
uint8_t payload_data[kEventPayloadSize - 13]; // 载荷数据
uint8_t checksum; // 校验码
};
#pragma pack(pop)
/// 事件合法性校验结果
enum class EventValidationResult {
kValid,
kInvalidType,
kInvalidChecksum,
kRedundantDuplicate
};
/// 事件处理结果
enum class EventProcessResult {
kSuccess,
kValidationFailed,
kTemplateNotFound,
kTaskGenerated
};
} // namespace fzkj
// ============================================================
// 工作模式枚举
// ============================================================
namespace fzkj {
enum class WorkMode {
kNormal, // 正常模式
kDegraded, // 降级模式
kConfigMaintain // 配置维护模式
};
/// 模式名称转字符串
inline const char* WorkModeName(WorkMode m) noexcept {
switch (m) {
case WorkMode::kNormal: return "正常模式";
case WorkMode::kDegraded: return "降级模式";
case WorkMode::kConfigMaintain: return "配置维护模式";
default: return "未知";
}
}
} // namespace fzkj
// ============================================================
// 作战任务基类
// ============================================================
namespace fzkj {
struct Task {
uint64_t task_id = 0;
uint32_t source_event_id = 0;
std::string description;
std::string priority; // "高"/"中"/"低"
std::string criticality; // "关键"/"重要"/"一般"
std::chrono::system_clock::time_point created_at;
std::string ToString() const;
};
} // namespace fzkj
// ============================================================
// 战斗方案(作战方案)
// ============================================================
namespace fzkj {
struct BattleSolution {
uint64_t solution_id = 0;
uint64_t task_id = 0;
std::string name;
std::string description;
double score = 0.0; // 方案评分
bool is_distributed = false; // 是否分布式方案
std::string ToString() const;
};
/// 方案对比结果
struct SolutionComparison {
uint64_t solution_a_id;
uint64_t solution_b_id;
double score_diff;
std::string summary;
};
} // namespace fzkj
// ============================================================
// 执行状态
// ============================================================
namespace fzkj {
enum class ExecutionStatus {
kPending,
kInProgress,
kSuccess,
kFailed,
kTimeout
};
inline const char* ExecutionStatusName(ExecutionStatus s) noexcept {
switch (s) {
case ExecutionStatus::kPending: return "待执行";
case ExecutionStatus::kInProgress: return "执行中";
case ExecutionStatus::kSuccess: return "执行成功";
case ExecutionStatus::kFailed: return "执行失败";
case ExecutionStatus::kTimeout: return "超时";
default: return "未知";
}
}
struct ExecutionUnit {
uint64_t unit_id;
std::string name;
ExecutionStatus status = ExecutionStatus::kPending;
std::string ToString() const;
};
} // namespace fzkj
// ============================================================
// 地图与态势数据
// ============================================================
namespace fzkj {
struct GeoPoint {
double latitude; // 纬度
double longitude; // 经度
double altitude; // 海拔(米)
};
struct SituationLayer {
std::string layer_name;
bool visible = true;
};
struct MapViewState {
GeoPoint center_point;
double zoom_level = 1.0;
bool grid_visible = false;
};
/// 量算结果
struct MeasureResult {
double distance_m = 0.0; // 距离(米)
double area_sqm = 0.0; // 面积(平方米)
double azimuth_deg = 0.0; // 方位角(度)
};
} // namespace fzkj
// ============================================================
// 系统配置
// ============================================================
namespace fzkj {
struct SystemConfig {
// 算法参数
std::string algorithm_name;
double algorithm_param = 1.0;
// 运行模式
WorkMode mode = WorkMode::kNormal;
// 网络配置
std::string ip_address = "192.168.1.100";
uint16_t port = 8080;
bool use_encryption = true;
// 想定参数
std::string scenario_name = "默认想定";
std::string ToString() const;
};
} // namespace fzkj
// ============================================================
// FZKJ Application 核心类
// ============================================================
namespace fzkj {
class App {
public:
App();
~App() = default;
// 禁止拷贝
App(const App&) = delete;
App& operator=(const App&) = delete;
// ======== 事件处理SRS-FZKJ_F-001 ========
EventProcessResult ReceiveEvent(const EventPayload& evt);
EventProcessResult GenerateTaskFromTemplate(uint32_t event_type);
// ======== 方案管理SRS-FZKJ_F-002 ========
bool AddSolution(const BattleSolution& solution);
std::vector<BattleSolution> GetSolutions() const;
void SortByPreference(const std::string& criteria);
SolutionComparison CompareSolutions(uint64_t id_a, uint64_t id_b) const;
// ======== 方案驱动与状态监控SRS-FZKJ_F-003 ========
bool DispatchPlan(uint64_t solution_id);
ExecutionStatus MonitorExecutionStatus(uint64_t unit_id) const;
bool TriggerAlertOnFailure(uint64_t unit_id);
// ======== 共用态势与地图展示SRS-FZKJ_F-004 ========
bool LoadGisMap(const std::string& map_path);
bool OverlaySituationLayer(const SituationLayer& layer);
MeasureResult MeasureDistance(const GeoPoint& p1, const GeoPoint& p2) const;
void ToggleGridDisplay();
// ======== 数据中转与存储管理SRS-FZKJ_F-005 ========
bool ForwardDataToModule(const std::string& module_name, const uint8_t* data, std::size_t len);
bool PersistCacheToDb();
bool ClearScenarioCache();
// ======== 系统设置与想定切换SRS-FZKJ_F-006 ========
void SetAlgorithmConfig(const std::string& name, double param);
bool SwitchExecutionMode(WorkMode new_mode);
bool LoadScenarioParams(const std::string& scenario_name);
bool ApplyNetworkConfiguration(const std::string& ip, uint16_t port);
// ======== 通用查询 ========
WorkMode GetCurrentMode() const noexcept { return current_mode_; }
const SystemConfig& GetConfig() const noexcept { return config_; }
// ======== 自检 ========
bool SelfTest();
private:
WorkMode current_mode_ = WorkMode::kNormal;
SystemConfig config_;
std::vector<EventPayload> event_history_;
std::vector<Task> tasks_;
std::vector<BattleSolution> solutions_;
std::vector<ExecutionUnit> exec_units_;
MapViewState map_state_;
std::vector<SituationLayer> situation_layers_;
std::size_t cache_size_ = 0;
uint64_t NextTaskId();
uint64_t NextSolutionId();
uint64_t NextUnitId();
};
} // namespace fzkj
#endif // FZKJ_APP_HPP