XNSim/XNCore/XNCore_global.h
2025-04-28 12:25:20 +08:00

165 lines
2.7 KiB
C++
Executable File

#ifndef XNCORE_GLOBAL_H
#define XNCORE_GLOBAL_H
#include <QtCore/qglobal.h>
#if defined(XNCORE_LIBRARY)
# define XNCORE_EXPORT Q_DECL_EXPORT
#else
# define XNCORE_EXPORT Q_DECL_IMPORT
#endif
#ifdef __linux__
# include <pthread.h>
# include <sched.h>
# include <sys/timeb.h>
# include <sys/mman.h>
# include <sys/stat.h>
# include <errno.h>
# include <time.h>
# include <memory>
# include <errno.h>
# include <unistd.h>
#endif
#define FAST_DDS_MACRO eprosima::fastdds::dds
/**
* @brief 默认基频定义,单位 Hz
*/
#define BASE_RUN_FREQ 100.0
/**
* @brief 默认基础运行间隔定义 单位纳秒
*/
#define BASE_RUN_INTER (1.0E9 / BASE_RUN_FREQ)
//模型周期性回调函数类型别名
using XNCallBack = std::function<void()>;
//DDS回调函数类型别名
using XNDDSCallBack = std::function<void(void *)>;
/**
* @brief 纳秒睡眠相关时间结构体
* @details 用于线程睡眠时间控制
*/
struct PERIOD_INFO {
/**
* @brief 系统提供的时间记录结构体,精确到纳秒
*/
timespec next_period;
/**
* @brief 睡眠时长,单位纳秒
*/
long period_ns;
};
/**
* @brief 系统运行状态枚举类
*/
enum class RunStatus {
/**
* @brief 未开始
*/
NotStart = 0,
/**
* @brief 运行中
*/
Runing,
/**
* @brief 暂停
*/
Suspend,
/**
* @brief 中止
*/
Aborted,
/**
* @brief 结束
*/
Finished
};
/**
* @brief 仿真控制命令枚举类
*/
enum class SimControlCmd {
/**
* @brief 开始
*/
Start,
/**
* @brief 继续
*/
Continue,
/**
* @brief 暂停
*/
Suspend,
/**
* @brief 中止
*/
Abort
};
/**
* @brief 运行频率族枚举类
*/
enum class FreqLevel {
/**
* @brief 基础频率
*/
BaseFreq = 0, // 120/100/60 Hz
/**
* @brief 半频
*/
HalfFreq, // 60/50/30 Hz
/**
* @brief 四分之一频
*/
QuarterFreq, // 30/25/15 Hz
/**
* @brief 八分之一频
*/
EighthFreq, // 15/12.5/7.5 Hz
/**
* @brief 十六分之一频
*/
SixteenthFreq, // 7.5/6.25/3.75 Hz
/**
* @brief 三十二分之一频
*/
ThirtyTwothFreq, // 3.75/3.125/1.875 Hz
};
/**
* @brief 框架对象状态枚举
*/
enum class XNFrameObjectStatus {
/**
* @brief 未初始化
*/
NotReady = 0,
/**
* @brief 已初始化
*/
Initialized,
/**
* @brief 已准备好
*/
Ready,
/**
* @brief 未知
*/
Unknown
};
#define XN_DLL_INITIALIZE(ClassName) \
extern "C" void Initial##ClassName() \
{ \
qRegisterMetaType<ClassName>(#ClassName); \
}
#endif // XNCORE_GLOBAL_H