207 lines
4.8 KiB
C
207 lines
4.8 KiB
C
/**
|
||
* @file myMms_s.h
|
||
* @brief libmms_s 库对外的公共接口头文件
|
||
*
|
||
* @details 本文件定义了:
|
||
* - 自定义数据类型码(DATA_TYPE_*),用于标识 RTU 系统中各种数据类型的枚举值
|
||
* - 公共数据结构体:参数基类(stru_mms_s_param_base)、定值(stru_mms_s_setting)、
|
||
* 参数组(stru_mms_s_param)、控制(stru_mms_s_control)
|
||
* - 回调函数类型定义
|
||
* - 库初始化与注册接口函数声明
|
||
*/
|
||
|
||
#pragma once
|
||
|
||
#include <stdint.h>
|
||
#include <stdbool.h>
|
||
|
||
#ifdef __cplusplus
|
||
extern "C" {
|
||
#endif /* __cplusplus */
|
||
|
||
// ===================== 自定义数据类型码 =====================
|
||
|
||
/* 布尔类型 */
|
||
#ifndef DATA_TYPE_B
|
||
#define DATA_TYPE_B 1
|
||
#endif
|
||
|
||
/* 有符号8位整数 */
|
||
#ifndef DATA_TYPE_S8
|
||
#define DATA_TYPE_S8 43
|
||
#endif
|
||
/* 无符号8位整数 */
|
||
#ifndef DATA_TYPE_U8
|
||
#define DATA_TYPE_U8 32
|
||
#endif
|
||
/* 有符号16位整数 */
|
||
#ifndef DATA_TYPE_S16
|
||
#define DATA_TYPE_S16 33
|
||
#endif
|
||
/* 无符号16位整数 */
|
||
#ifndef DATA_TYPE_U16
|
||
#define DATA_TYPE_U16 45
|
||
#endif
|
||
/* 有符号32位整数 */
|
||
#ifndef DATA_TYPE_S32
|
||
#define DATA_TYPE_S32 2
|
||
#endif
|
||
/* 无符号32位整数 */
|
||
#ifndef DATA_TYPE_U32
|
||
#define DATA_TYPE_U32 35
|
||
#endif
|
||
/* 有符号64位整数 */
|
||
#ifndef DATA_TYPE_L64
|
||
#define DATA_TYPE_L64 36
|
||
#endif
|
||
/* 无符号64位整数 */
|
||
#ifndef DATA_TYPE_UL64
|
||
#define DATA_TYPE_UL64 37
|
||
#endif
|
||
/* 单精度浮点数 */
|
||
#ifndef DATA_TYPE_F32
|
||
#define DATA_TYPE_F32 38
|
||
#endif
|
||
/* 双精度浮点数 */
|
||
#ifndef DATA_TYPE_D64
|
||
#define DATA_TYPE_D64 39
|
||
#endif
|
||
/* IP地址类型 */
|
||
#ifndef DATA_TYPE_IP
|
||
#define DATA_TYPE_IP 100
|
||
#endif
|
||
/* MAC地址类型 */
|
||
#ifndef DATA_TYPE_MAC
|
||
#define DATA_TYPE_MAC 101
|
||
#endif
|
||
/* 8字符定长字符串 */
|
||
#ifndef DATA_TYPE_C8
|
||
#define DATA_TYPE_C8 102
|
||
#endif
|
||
/* 32字符定长字符串 */
|
||
#ifndef DATA_TYPE_C32
|
||
#define DATA_TYPE_C32 103
|
||
#endif
|
||
/* 64字符定长字符串 */
|
||
#ifndef DATA_TYPE_C64
|
||
#define DATA_TYPE_C64 104
|
||
#endif
|
||
/* 128字符定长字符串 */
|
||
#ifndef DATA_TYPE_C128
|
||
#define DATA_TYPE_C128 105
|
||
#endif
|
||
/* 单字符 */
|
||
#ifndef DATA_TYPE_C1
|
||
#define DATA_TYPE_C1 106
|
||
#endif
|
||
/* 可变长字符串 */
|
||
#ifndef DATA_TYPE_STR
|
||
#define DATA_TYPE_STR 107
|
||
#endif
|
||
|
||
|
||
/* 短地址字符串最大长度 */
|
||
#define MMS_S_STR_LEN 64
|
||
/* 参数组最大分组数(定值区最大数量) */
|
||
#define MMS_S_PARAM_MAX 16
|
||
|
||
|
||
typedef void (*mms_s_value_update_cb)(const char * saddr, const char * val);
|
||
|
||
/**
|
||
* @brief 注册值更新回调函数
|
||
* @param cb 值更新回调函数指针
|
||
*/
|
||
void mms_s_value_update_register(mms_s_value_update_cb *cb);
|
||
|
||
|
||
typedef struct
|
||
{
|
||
char saddr[MMS_S_STR_LEN];
|
||
char desc[MMS_S_STR_LEN];
|
||
uint8_t type;
|
||
uint8_t ctrl_model;
|
||
}stru_mms_s_signal_base;
|
||
|
||
typedef struct
|
||
{
|
||
stru_mms_s_signal_base base;
|
||
void *p_data;
|
||
}stru_mms_s_setting;
|
||
|
||
|
||
typedef void (*mms_s_setting_cb)(stru_mms_s_setting *p_setting, const char *p_data);
|
||
|
||
typedef struct
|
||
{
|
||
stru_mms_s_signal_base base;
|
||
uint8_t param_num;
|
||
void *p_data[MMS_S_PARAM_MAX];
|
||
}stru_mms_s_param;
|
||
|
||
|
||
typedef void (*mms_s_param_cb)(stru_mms_s_param *p_param, const char *p_data, int setting_zone);
|
||
|
||
typedef struct
|
||
{
|
||
stru_mms_s_signal_base base;
|
||
void *p_data;
|
||
}stru_mms_s_control;
|
||
|
||
|
||
typedef void (*mms_s_control_cb)(stru_mms_s_control *p_control, uint8_t state);
|
||
|
||
|
||
/**
|
||
* 初始化 MMS 服务器
|
||
* @param icd_path ICD 模型文件路径
|
||
* @param port MMS 服务监听端口
|
||
* @return 0 成功,-1 失败
|
||
*/
|
||
int mms_s_init(const char* icd_path, int port);
|
||
|
||
/**
|
||
* 开启/关闭调试输出开关
|
||
* @param on true 开启,false 关闭
|
||
*/
|
||
void mms_s_dbg_switch(bool on);
|
||
|
||
/**
|
||
* 注册控制对象列表
|
||
* @param p_control 控制对象数组
|
||
* @param num 数组元素个数
|
||
* @param cb 控制操作回调函数(可选,传 NULL 则不注册)
|
||
* @return 0 成功,-1 失败
|
||
*/
|
||
int mms_s_control_register(stru_mms_s_control *p_control, uint16_t num, mms_s_control_cb cb);
|
||
|
||
/**
|
||
* 注册定值列表
|
||
* @param p_setting 定值对象数组
|
||
* @param num 数组元素个数
|
||
* @param cb 定值写入回调函数(可选,传 NULL 则不注册)
|
||
* @return 0 成功,-1 失败
|
||
*/
|
||
int mms_s_setting_register(stru_mms_s_setting *p_setting, uint16_t num, mms_s_setting_cb cb);
|
||
|
||
/**
|
||
* 注册参数列表(参数支持多定值区)
|
||
* @param p_param 参数对象数组
|
||
* @param num 数组元素个数
|
||
* @param cb 参数回调函数(可选,传 NULL 则不注册)
|
||
* @return 0 成功,-1 失败
|
||
*/
|
||
int mms_s_param_register(stru_mms_s_param *p_param, uint16_t num, mms_s_param_cb cb);
|
||
|
||
/**
|
||
* 设置 MMS 文件服务的根路径
|
||
* @param file_path 文件存储路径,传 NULL 或空串则禁用文件服务
|
||
* @return 0 成功
|
||
*/
|
||
int mms_s_file_path_set(const char* file_path);
|
||
|
||
|
||
#ifdef __cplusplus
|
||
}
|
||
#endif /* __cplusplus */
|