#ifndef COMMON_H #define COMMON_H /** * @file common.h * @brief 公共定义与常量声明 * * 本文件定义了整个ISUP平台客户端项目的公共常量、宏定义、 * 通用数据结构和对齐指令。 */ #include #include #include #include #include #include #include #include #include #include #include #include #include /* 版本信息 */ #define PROJECT_NAME "Hikvision ISUP Client" #define PROJECT_VERSION "1.0.0" #define PROJECT_BUILD_DATE __DATE__ " " __TIME__ /* 日志级别 */ typedef enum { LOG_LEVEL_DEBUG = 0, LOG_LEVEL_INFO, LOG_LEVEL_WARN, LOG_LEVEL_ERROR, LOG_LEVEL_FATAL } LogLevel; /* 日志宏定义 */ #define LOG_TAG "ISUP" #define LOG_PRINT(level, fmt, ...) \ do { \ fprintf(stderr, "[%s] [%s] [%s:%d:%s()] " fmt "\n", \ LOG_TAG, \ (level == LOG_LEVEL_DEBUG ? "DEBUG" : \ level == LOG_LEVEL_INFO ? "INFO" : \ level == LOG_LEVEL_WARN ? "WARN" : \ level == LOG_LEVEL_ERROR ? "ERROR" : "FATAL"), \ __FILE__, __LINE__, __func__, ##__VA_ARGS__); \ } while(0) #define LOG_DEBUG(fmt, ...) LOG_PRINT(LOG_LEVEL_DEBUG, fmt, ##__VA_ARGS__) #define LOG_INFO(fmt, ...) LOG_PRINT(LOG_LEVEL_INFO, fmt, ##__VA_ARGS__) #define LOG_WARN(fmt, ...) LOG_PRINT(LOG_LEVEL_WARN, fmt, ##__VA_ARGS__) #define LOG_ERROR(fmt, ...) LOG_PRINT(LOG_LEVEL_ERROR, fmt, ##__VA_ARGS__) #define LOG_FATAL(fmt, ...) LOG_PRINT(LOG_LEVEL_FATAL, fmt, ##__VA_ARGS__) /* 缓冲区大小 */ #define MAX_BUF_SIZE 65536 #define MAX_IP_SIZE 64 #define MAX_PATH_SIZE 256 #define MAX_DEVICE_ID 64 #define MAX_CHANNEL_NUM 32 #define MAX_ALARM_NUM 128 #define MAX_PLAYBACK_NUM 16 #define MAX_STREAM_NUM 32 /* 默认端口配置 */ #define DEFAULT_CMS_PORT 7031 /* CMS注册服务器端口 */ #define DEFAULT_SMS_PORT 7660 /* SMS流媒体服务器端口 */ #define DEFAULT_ALARM_PORT 9000 /* 报警服务器端口 */ #define DEFAULT_RTMP_PORT 1935 /* RTMP推流端口 */ #define DEFAULT_HTTP_PORT 8080 /* HTTP管理接口端口 */ /* ISUP协议相关 */ #define ISUP_PROTO_VERSION "ISUP5.0" #define REG_RETRY_INTERVAL 5 /* 注册重试间隔(秒) */ #define HEARTBEAT_INTERVAL 30 /* 心跳间隔(秒) */ #define STREAM_TIMEOUT 30 /* 流超时(秒) */ /* 模拟图片配置 */ #define SIM_IMAGE_DIR "./sim_images" #define SIM_IMAGE_WIDTH 1920 #define SIM_IMAGE_HEIGHT 1080 #define SIM_FPS 25 #define SIM_BITRATE 4096000 /* 4Mbps */ /* 状态码 */ #define SUCCESS 0 #define FAILURE -1 #define NOT_FOUND -2 #define INVALID_PARAM -3 #define TIMEOUT -4 #define UNAUTHORIZED -5 /* 设备状态 */ typedef enum { DEVICE_STATUS_OFFLINE = 0, DEVICE_STATUS_ONLINE, DEVICE_STATUS_REGISTERS, DEVICE_STATUS_STREAMING, DEVICE_STATUS_PLAYBACK } DeviceStatus; /* 日志函数指针类型 */ typedef void (*LogCallback)(LogLevel level, const char* tag, const char* fmt, va_list args); /* 全局日志回调 */ extern LogCallback g_log_callback; /** * @brief 设置日志回调函数 * @param cb 日志回调函数指针 */ void set_log_callback(LogCallback cb); /** * @brief 格式化时间戳字符串 * @param buf 输出缓冲区 * @param bufsize 缓冲区大小 * @param fmt 时间格式字符串(strftime格式) * @return 格式化后的字符串指针 */ char* get_timestamp(char* buf, size_t bufsize, const char* fmt); /** * @brief 字符串转小写 * @param str 输入字符串 * @return 转换后的字符串指针 */ char* str_tolower(char* str); /** * @brief 安全字符串复制 * @param dest 目标缓冲区 * @param src 源字符串 * @param size 目标缓冲区大小 * @return 复制的字符数 */ size_t safe_strcpy(char* dest, const char* src, size_t size); #endif /* COMMON_H */