platform.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. #ifndef PLATFORM_H
  2. #define PLATFORM_H
  3. /**
  4. * @file platform.h
  5. * @brief ISUP平台注册管理头文件
  6. *
  7. * 本文件定义设备向ISUP平台(CMS)注册、心跳保活、
  8. * 登出等核心功能的接口。
  9. */
  10. #include "common.h"
  11. #include "config.h"
  12. /* 设备注册状态回调数据类型 */
  13. typedef enum {
  14. DEV_REG_TYPE_ON = 1, /* 设备上线 */
  15. DEV_REG_TYPE_OFF, /* 设备下线 */
  16. DEV_REG_TYPE_AUTH, /* 设备认证 */
  17. DEV_REG_TYPE_SESSIONKEY, /* 会话密钥 */
  18. DEV_REG_TYPE_ADDRESS_CHANGED, /* 地址变更 */
  19. DEV_REG_TYPE_HEARTBEAT, /* 心跳 */
  20. DEV_REG_TYPE_XMLCONFIG, /* XML配置 */
  21. DEV_REG_TYPE_VTDU_STREAM, /* VTDU流 */
  22. } DevRegDataType;
  23. /* 设备注册信息结构 */
  24. typedef struct {
  25. char sDeviceSerial[64]; /* 设备序列号 */
  26. char sDeviceID[64]; /* 设备ID */
  27. char sDeviceName[128]; /* 设备名称 */
  28. char sDeviceType[32]; /* 设备类型 */
  29. char sDeviceModel[64]; /* 设备型号 */
  30. char sSoftwareVersion[32]; /* 软件版本 */
  31. char sHardwareVersion[32]; /* 硬件版本 */
  32. char sIPAddress[MAX_IP_SIZE]; /* 设备IP地址 */
  33. short sIPAddressType; /* IP地址类型 */
  34. short sPort; /* 端口 */
  35. int byChanNum; /* 模拟通道数 */
  36. int byIPChanNum; /* 数字通道数 */
  37. int byStartDChan; /* 起始数字通道号 */
  38. int bySubChanNum; /* 子通道数 */
  39. int bySupportSubChan; /* 是否支持子通道 */
  40. time_t tOnlineTime; /* 上线时间 */
  41. } DevRegInfo;
  42. /* 设备注册回调函数类型 */
  43. /*
  44. * 原型: void (*DEVICE_REGISTER_CB)(int iUserID, DWORD dwDataType,
  45. * void* pOutBuffer, DWORD dwOutLen, void* pInBuffer, DWORD dwInLen, void* pUser)
  46. *
  47. * iUserID: 用户ID(登录成功后返回)
  48. * dwDataType: 数据类型(DEV_REG_TYPE_XXX)
  49. * pOutBuffer: 输出缓冲区(设备注册信息)
  50. * dwOutLen: 输出缓冲区长度
  51. * pInBuffer: 输入缓冲区
  52. * dwInLen: 输入缓冲区长度
  53. * pUser: 用户自定义参数
  54. */
  55. typedef void (*DEVICE_REGISTER_CB)(int iUserID, int dwDataType,
  56. void* pOutBuffer, int dwOutLen,
  57. void* pInBuffer, int dwInLen,
  58. void* pUser);
  59. /* 设备状态回调 */
  60. typedef void (*DeviceStatusCB)(const char* device_id, DeviceStatus status, void* user_data);
  61. /**
  62. * @brief 初始化CMS库
  63. * @return 成功返回SUCCESS, 失败返回FAILURE
  64. *
  65. * 说明: 必须在使用ISUP SDK任何其他接口之前调用此函数。
  66. * 初始化CMS库,分配SDK所需全局资源。
  67. */
  68. int platform_cms_init(void);
  69. /**
  70. * @brief 反初始化CMS库
  71. *
  72. * 说明: 程序退出前调用,释放CMS库占用的资源。
  73. */
  74. void platform_cms_cleanup(void);
  75. /**
  76. * @brief 启动CMS监听(接收设备注册请求)
  77. * @param listen_ip 监听IP地址, "0.0.0.0"表示监听所有接口
  78. * @param listen_port 监听端口
  79. * @param reg_callback 设备注册回调函数
  80. * @param user_data 用户自定义数据
  81. * @return 成功返回SUCCESS, 失败返回FAILURE
  82. *
  83. * 说明: 启动后CMS服务器开始监听来自设备的注册请求。
  84. * 当设备注册/上线/下线时,会回调reg_callback函数。
  85. */
  86. int platform_cms_start_listen(const char* listen_ip, short listen_port,
  87. DEVICE_REGISTER_CB reg_callback, void* user_data);
  88. /**
  89. * @brief 停止CMS监听
  90. *
  91. * 说明: 停止接收设备注册请求。
  92. */
  93. void platform_cms_stop_listen(void);
  94. /**
  95. * @brief 设备向CMS注册
  96. * @param server_ip CMS服务器IP地址
  97. * @param server_port CMS服务器端口
  98. * @param device_id 设备ID
  99. * @param protocol_version 协议版本
  100. * @param encrypt_key 加密密钥
  101. * @param user_data 用户自定义数据
  102. * @return 成功返回用户ID(>=0), 失败返回FAILURE
  103. *
  104. * 说明: 设备主动向CMS服务器发起注册请求。
  105. * 注册成功后返回用户ID,后续操作使用此ID。
  106. */
  107. int platform_device_register(const char* server_ip, short server_port,
  108. const char* device_id, const char* protocol_version,
  109. const char* encrypt_key, void* user_data);
  110. /**
  111. * @brief 设备登出CMS
  112. * @param user_id 用户ID
  113. * @return 成功返回SUCCESS, 失败返回FAILURE
  114. */
  115. int platform_device_logout(int user_id);
  116. /**
  117. * @brief 设置自动重连
  118. * @param user_id 用户ID
  119. * @param enable 是否启用自动重连
  120. * @param interval 重连间隔(秒)
  121. * @return 成功返回SUCCESS, 失败返回FAILURE
  122. */
  123. int platform_set_auto_reconnect(int user_id, int enable, int interval);
  124. /**
  125. * @brief 发送心跳包
  126. * @param user_id 用户ID
  127. * @return 成功返回SUCCESS, 失败返回FAILURE
  128. */
  129. int platform_send_heartbeat(int user_id);
  130. /**
  131. * @brief 注册设备状态回调
  132. * @param cb 状态回调函数
  133. * @param user_data 用户自定义数据
  134. */
  135. void platform_register_status_callback(DeviceStatusCB cb, void* user_data);
  136. /**
  137. * @brief 获取设备注册信息
  138. * @param device_id 设备ID
  139. * @param info 输出设备信息结构
  140. * @return 成功返回SUCCESS, 失败返回FAILURE
  141. */
  142. int platform_get_device_info(const char* device_id, DevRegInfo* info);
  143. /**
  144. * @brief 获取所有在线设备列表
  145. * @param devices 输出设备ID数组
  146. * @param max_devices 最大设备数
  147. * @return 返回在线设备数量
  148. */
  149. int platform_get_online_devices(char devices[][MAX_DEVICE_ID], int max_devices);
  150. #endif /* PLATFORM_H */