290 lines
7.4 KiB
C++
290 lines
7.4 KiB
C++
|
|
#ifndef C2SYS_CONFIG_HPP
|
|||
|
|
#define C2SYS_CONFIG_HPP
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @file config.hpp
|
|||
|
|
* @brief C2SYS 系统核心数据结构与配置参数定义。
|
|||
|
|
*
|
|||
|
|
* 本文件定义了联合作战指挥环境任务自主规划软件系统的所有核心数据实体、
|
|||
|
|
* 枚举类型、缓存结构与配置文件加载接口。
|
|||
|
|
* 数据实体对应 SRS-C2SYS 需求规格说明中的 I_PLAN_DATA、I_EVT_RAW、I_EVT_STD、
|
|||
|
|
* I_TMPL_SET、I_TASK_TELEM、I_NODE_ACK 等数据模型。
|
|||
|
|
*/
|
|||
|
|
|
|||
|
|
#include <string>
|
|||
|
|
#include <vector>
|
|||
|
|
#include <chrono>
|
|||
|
|
#include <unordered_map>
|
|||
|
|
#include <cstdint>
|
|||
|
|
#include <fstream>
|
|||
|
|
#include <sstream>
|
|||
|
|
#include <stdexcept>
|
|||
|
|
|
|||
|
|
namespace c2sys {
|
|||
|
|
|
|||
|
|
/// @brief 运行模式枚举
|
|||
|
|
enum class RunMode : uint8_t {
|
|||
|
|
/// 人在回路模式 — 人工干预决策
|
|||
|
|
HumanInLoop = 0,
|
|||
|
|
/// 自主执行模式 — 系统自动决策
|
|||
|
|
Autonomous = 1
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// @brief 方案类型枚举
|
|||
|
|
enum class PlanType : uint8_t {
|
|||
|
|
/// 集中式方案
|
|||
|
|
Centralized = 0,
|
|||
|
|
/// 分布式方案
|
|||
|
|
Distributed = 1
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// @brief 事件处理状态
|
|||
|
|
enum class EventStatus : uint8_t {
|
|||
|
|
/// 待处理
|
|||
|
|
Pending = 0,
|
|||
|
|
/// 已忽略
|
|||
|
|
Ignored = 1,
|
|||
|
|
/// 已处理
|
|||
|
|
Processed = 2
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// @brief 分发响应状态
|
|||
|
|
enum class AckStatus : uint8_t {
|
|||
|
|
/// 确认接收
|
|||
|
|
Confirmed = 0,
|
|||
|
|
/// 拒绝执行
|
|||
|
|
Rejected = 1,
|
|||
|
|
/// 响应超时
|
|||
|
|
Timeout = 2
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/// @brief 事件类型
|
|||
|
|
enum class EventType : uint8_t {
|
|||
|
|
/// 临机事件
|
|||
|
|
Contingency = 0,
|
|||
|
|
/// 规划事件
|
|||
|
|
Planned = 1
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 方案数据实体 (SRS-C2SYS_I_PLAN_DATA)
|
|||
|
|
*
|
|||
|
|
* 用于集中式与分布式作战方案的表示、对比与分发。
|
|||
|
|
*/
|
|||
|
|
struct PlanData {
|
|||
|
|
/// 方案唯一标识
|
|||
|
|
std::string id;
|
|||
|
|
/// 方案类型(集中式 / 分布式)
|
|||
|
|
PlanType type;
|
|||
|
|
/// 资源占用百分比 (0.0 ~ 100.0)
|
|||
|
|
double resourceUsage;
|
|||
|
|
/// 执行周期(秒)
|
|||
|
|
double executionPeriod;
|
|||
|
|
/// 预估成功率 (0.0 ~ 1.0)
|
|||
|
|
double successRate;
|
|||
|
|
/// 抗毁性评分 (0.0 ~ 1.0)
|
|||
|
|
double survivability;
|
|||
|
|
/// 协同效率评分 (0.0 ~ 1.0)
|
|||
|
|
double collaborationEfficiency;
|
|||
|
|
/// 子任务ID列表
|
|||
|
|
std::vector<std::string> subTaskIds;
|
|||
|
|
/// 创建时间(Unix 时间戳,毫秒)
|
|||
|
|
int64_t createTimestamp;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 原始事件实体 (SRS-C2SYS_I_EVT_RAW)
|
|||
|
|
*
|
|||
|
|
* 由外部情报源或侦察设备发送的原始事件流报文。
|
|||
|
|
*/
|
|||
|
|
struct EventRaw {
|
|||
|
|
/// 源设备标识
|
|||
|
|
std::string sourceId;
|
|||
|
|
/// 事件发生时间戳(毫秒)
|
|||
|
|
int64_t timestamp;
|
|||
|
|
/// 威胁等级 (1 ~ 5)
|
|||
|
|
int threatLevel;
|
|||
|
|
/// 原始报文 SHA256 哈希
|
|||
|
|
std::string payloadHash;
|
|||
|
|
/// 协议类型标识
|
|||
|
|
std::string protocolType;
|
|||
|
|
/// 报文内容体(十六进制字符串 or JSON)
|
|||
|
|
std::string payload;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 标准化事件实体 (SRS-C2SYS_I_EVT_STD)
|
|||
|
|
*
|
|||
|
|
* 经过过滤、转化、封装后的内部标准化事件包。
|
|||
|
|
*/
|
|||
|
|
struct StandardEvent {
|
|||
|
|
/// 统一事件 ID
|
|||
|
|
std::string id;
|
|||
|
|
/// 事件类型(临机 / 规划)
|
|||
|
|
EventType type;
|
|||
|
|
/// 处理状态
|
|||
|
|
EventStatus status;
|
|||
|
|
/// 关联的任务 ID(可为空)
|
|||
|
|
std::string relatedTaskId;
|
|||
|
|
/// 元数据标签键值对
|
|||
|
|
std::unordered_map<std::string, std::string> metadata;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 任务模板实体 (SRS-C2SYS_I_TMPL_SET)
|
|||
|
|
*
|
|||
|
|
* 任务模板先验知识库中的版本化模板。
|
|||
|
|
*/
|
|||
|
|
struct TaskTemplate {
|
|||
|
|
/// 模板唯一标识
|
|||
|
|
std::string id;
|
|||
|
|
/// 版本号
|
|||
|
|
std::string version;
|
|||
|
|
/// 适用场景描述
|
|||
|
|
std::string applicableScenario;
|
|||
|
|
/// 权重配置(JSON 序列化字符串)
|
|||
|
|
std::string weightConfig;
|
|||
|
|
/// 子任务需求列表
|
|||
|
|
std::vector<std::string> subTaskRequirements;
|
|||
|
|
/// 匹配度评分 (0.0 ~ 1.0)
|
|||
|
|
double matchScore;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 执行状态实体 (SRS-C2SYS_I_TASK_TELEM)
|
|||
|
|
*
|
|||
|
|
* 任务执行过程中的遥测状态监控数据。
|
|||
|
|
*/
|
|||
|
|
struct ExecutionStatus {
|
|||
|
|
/// 任务 ID
|
|||
|
|
std::string taskId;
|
|||
|
|
/// 当前阶段名称
|
|||
|
|
std::string currentPhase;
|
|||
|
|
/// 完成百分比 (0.0 ~ 100.0)
|
|||
|
|
double completionPercent;
|
|||
|
|
/// 心跳时间戳(毫秒)
|
|||
|
|
int64_t heartbeatTimestamp;
|
|||
|
|
/// 异常码(0 表示正常)
|
|||
|
|
int errorCode;
|
|||
|
|
/// 影响范围描述
|
|||
|
|
std::string impactScope;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 分发回执实体 (SRS-C2SYS_I_NODE_ACK)
|
|||
|
|
*
|
|||
|
|
* 执行节点对方案分发的响应确认。
|
|||
|
|
*/
|
|||
|
|
struct DistributionAck {
|
|||
|
|
/// 节点 ID
|
|||
|
|
std::string nodeId;
|
|||
|
|
/// 响应状态
|
|||
|
|
AckStatus status;
|
|||
|
|
/// 回执时间戳(毫秒)
|
|||
|
|
int64_t timestamp;
|
|||
|
|
/// 已重试次数
|
|||
|
|
int retryCount;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 操作日志结构
|
|||
|
|
*
|
|||
|
|
* 记录所有用户操作,用于审计追溯。
|
|||
|
|
*/
|
|||
|
|
struct OperationLog {
|
|||
|
|
/// 操作员标识
|
|||
|
|
std::string operatorId;
|
|||
|
|
/// 操作时间戳(毫秒)
|
|||
|
|
int64_t timestamp;
|
|||
|
|
/// 动作类型描述
|
|||
|
|
std::string actionType;
|
|||
|
|
/// 操作对象 ID
|
|||
|
|
std::string objectId;
|
|||
|
|
/// 操作结果状态
|
|||
|
|
std::string resultStatus;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 配置快照结构
|
|||
|
|
*
|
|||
|
|
* 知识库参数调整后的生效快照,支持版本控制与回滚。
|
|||
|
|
*/
|
|||
|
|
struct ConfigSnapshot {
|
|||
|
|
/// 快照版本号
|
|||
|
|
std::string version;
|
|||
|
|
/// 快照时间戳(毫秒)
|
|||
|
|
int64_t timestamp;
|
|||
|
|
/// 配置内容(JSON 序列化字符串)
|
|||
|
|
std::string configData;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 模式状态缓存
|
|||
|
|
*
|
|||
|
|
* 存储当前运行模式及上下文快照,确保切换时不丢失状态。
|
|||
|
|
*/
|
|||
|
|
struct ModeStateCache {
|
|||
|
|
/// 当前运行模式
|
|||
|
|
RunMode currentMode;
|
|||
|
|
/// 上下文快照(JSON 序列化字符串)
|
|||
|
|
std::string contextSnapshot;
|
|||
|
|
/// 最后更新时间戳(毫秒)
|
|||
|
|
int64_t lastUpdateTimestamp;
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 系统配置文件结构
|
|||
|
|
*
|
|||
|
|
* 支持通过 JSON 或 KV 配置文件调整网络参数、刷新频率、算法阈值等。
|
|||
|
|
*/
|
|||
|
|
struct SystemConfig {
|
|||
|
|
/// 刷新周期(毫秒),默认 50ms
|
|||
|
|
int refreshIntervalMs = 50;
|
|||
|
|
/// WebSocket 端口号
|
|||
|
|
int websocketPort = 8080;
|
|||
|
|
/// 事件队列最大容量
|
|||
|
|
int eventQueueCapacity = 10000;
|
|||
|
|
/// 分发重试最大次数
|
|||
|
|
int maxRetryCount = 3;
|
|||
|
|
/// 分发超时时间(毫秒)
|
|||
|
|
int ackTimeoutMs = 2000;
|
|||
|
|
/// 日志级别 (0=TRACE, 1=DEBUG, 2=INFO, 3=WARN, 4=ERROR)
|
|||
|
|
int logLevel = 2;
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* @brief 从简单的 KV 配置文件加载配置。
|
|||
|
|
* @param filepath 配置文件路径
|
|||
|
|
* @return 加载成功返回 true
|
|||
|
|
*
|
|||
|
|
* 文件格式示例(每行 key=value):
|
|||
|
|
* refreshIntervalMs=100
|
|||
|
|
* websocketPort=9090
|
|||
|
|
* maxRetryCount=5
|
|||
|
|
*/
|
|||
|
|
bool loadFromFile(const std::string& filepath) {
|
|||
|
|
std::ifstream file(filepath);
|
|||
|
|
if (!file.is_open()) {
|
|||
|
|
return false;
|
|||
|
|
}
|
|||
|
|
std::string line;
|
|||
|
|
while (std::getline(file, line)) {
|
|||
|
|
if (line.empty() || line[0] == '#') continue;
|
|||
|
|
auto eqPos = line.find('=');
|
|||
|
|
if (eqPos == std::string::npos) continue;
|
|||
|
|
std::string key = line.substr(0, eqPos);
|
|||
|
|
std::string val = line.substr(eqPos + 1);
|
|||
|
|
if (key == "refreshIntervalMs") refreshIntervalMs = std::stoi(val);
|
|||
|
|
else if (key == "websocketPort") websocketPort = std::stoi(val);
|
|||
|
|
else if (key == "eventQueueCapacity") eventQueueCapacity = std::stoi(val);
|
|||
|
|
else if (key == "maxRetryCount") maxRetryCount = std::stoi(val);
|
|||
|
|
else if (key == "ackTimeoutMs") ackTimeoutMs = std::stoi(val);
|
|||
|
|
else if (key == "logLevel") logLevel = std::stoi(val);
|
|||
|
|
}
|
|||
|
|
return true;
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
} // namespace c2sys
|
|||
|
|
|
|||
|
|
#endif // C2SYS_CONFIG_HPP
|