/** * @file common.h * @brief 全局常量、平台宏与通用工具宏 * * 教材对应:项目一(程序结构)·项目二(数据类型)·项目九(位运算基础宏) */ #ifndef SHS_COMMON_H #define SHS_COMMON_H #include #include #include /* ---------------------------------------------------------------- 版本信息 */ #define SHS_VERSION_MAJOR 1 #define SHS_VERSION_MINOR 0 #define SHS_VERSION_PATCH 0 #define SHS_VERSION_STRING "1.0.0" #define SHS_PRODUCT_NAME "智能家居控制系统" /* ---------------------------------------------------------------- 容量上限 */ #define SHS_NAME_MAX 32 /**< 名称字段长度(含结尾 '\0') */ #define SHS_TAG_MAX 16 /**< 日志标签长度 */ #define SHS_MSG_MAX 96 /**< 日志正文长度 */ #define SHS_LINE_MAX 160 /**< 单行文本缓冲 */ #define SHS_CMD_MAX 64 /**< 指令串长度 */ #define SHS_MAX_DEVICES 32 /**< 设备数量上限(一维数组) */ #define SHS_MAX_ROOMS 8 /**< 房间数量上限 */ #define SHS_MAX_ZONES 16 /**< 区域节点上限(区域树) */ #define SHS_MAX_SAMPLES 16 /**< 采样点数量上限 */ #define SHS_DAYS 7 /**< 定时矩阵:一周 7 天(二维数组第一维) */ #define SHS_HOURS 24 /**< 定时矩阵:一天 24 小时(二维数组第二维) */ #define SHS_LOG_RING_MAX 64 /**< 内存日志环形缓冲条目数 */ #define SHS_JSON_BUF_MAX 8192 /**< JSON 输出缓冲 */ #define SHS_HTTP_BUF_MAX 16384 /**< HTTP 响应体缓冲(要装得下内嵌网页整页/整段脚本) */ #define SHS_HTTP_PATH_MAX 128 /**< HTTP 请求路径长度 */ #define SHS_HTTP_BODY_MAX 512 /**< HTTP 请求体长度 */ #define SHS_FRAME_MAX 16 /**< 通信帧最大字节数 */ /* ---------------------------------------------------------------- 通用宏 */ #define SHS_ARRAY_LEN(arr) ((int)(sizeof(arr) / sizeof((arr)[0]))) #define SHS_MIN(a, b) (((a) < (b)) ? (a) : (b)) #define SHS_MAX(a, b) (((a) > (b)) ? (a) : (b)) #define SHS_BIT(n) (1u << (n)) /**< 第 n 位置 1(位运算) */ #define SHS_UNUSED(x) ((void)(x)) /**< 显式忽略未使用参数 */ #define SHS_STRINGIFY(x) #x #define SHS_CONCAT(a, b) a##b #define SHS_IS_POWER_OF_TWO(x) (((x) > 0) && (((x) & ((x) - 1)) == 0)) /**< 位运算技巧 */ #define SHS_CLAMP(v, lo, hi) (((v) < (lo)) ? (lo) : (((v) > (hi)) ? (hi) : (v))) #ifdef _WIN32 # define SHS_PATH_SEP '\\' #else # define SHS_PATH_SEP '/' #endif #endif /* SHS_COMMON_H */