362 lines
12 KiB
C
362 lines
12 KiB
C
#ifndef __HART_FRAME_USER_H__
|
||
#define __HART_FRAME_USER_H__
|
||
#include "lib.h"
|
||
#include "hart_common_tables_specification.h"
|
||
#if defined(__CC_ARM)
|
||
#pragma anon_unions
|
||
#endif
|
||
|
||
#define HART_RESPONSE_MAX_LEN 254U // HART响应数据最大长度
|
||
#define USER_PARAM_MAX_NUM 16U // 用户响应参数最大数量
|
||
#define USER_RESPONSE_MAX_LEN USER_PARAM_MAX_NUM * 4 // 用户响应数据最大长度
|
||
|
||
typedef enum
|
||
{
|
||
USER_BYTE = DATA_TYPE_UINT8,
|
||
USER_WORD = DATA_TYPE_UINT16,
|
||
USER_UINT32 = DATA_TYPE_UINT32,
|
||
USER_FLOAT = DATA_TYPE_FLOAT,
|
||
} user_param_type_e;
|
||
|
||
typedef enum
|
||
{
|
||
USER_READ_ONLY = 0,
|
||
USER_READ_WRITE = 1,
|
||
USER_WRITE,
|
||
} user_param_access_e;
|
||
|
||
typedef enum
|
||
{
|
||
COMMAND_187_CLEAR_MORE_STATUS_BIT_AND_WRITE_PROTECT_OFF = 0, // 清除更多状态位并关闭写保护
|
||
// COMMAND_187_SET_PV_CLOSE_TO_LOWER_RANGE_VALUE = 1, // 将主变量设置为接近下限值
|
||
// COMMAND_187_SET_PV_TO_1_PERCENT_OF_RANGE = 2, // 将主变量设置为范围的1%
|
||
// COMMAND_187_SET_PV_TO_MID_SENSOR_RANGE = 3, // 将主变量设置为传感器范围的中间值
|
||
// COMMAND_187_SET_PV_CLOSE_TO_UPPER_TRANSDUCER_LIMIT = 4, // 将主变量设置为接近(但不超过)上限值
|
||
// COMMAND_187_SET_PV_BELOW_LOWER_TRANSDUCER_LIMIT = 5, // 将主变量设置为低于下限值
|
||
// COMMAND_187_SET_PV_ABOVE_UPPER_TRANSDUCER_LIMIT = 6, // 将主变量设置为高于上限值 / 将主变量设置为过高以重新归零
|
||
// COMMAND_187_SET_PV_TOO_LOW_TO_RE_ZERO = 7, // 将主变量设置为过低以重新归零
|
||
// COMMAND_187_SET_PV_EQUAL_TO_UPPER_TRANSDUCER_LIMIT = 8, // 将主变量设置为等于上限值
|
||
// COMMAND_187_SET_PV_TO_ZERO = 9, // 将主变量设置为0.0
|
||
COMMAND_187_SET_MORE_STATUS_AVAILABLE_STATUS_BIT = 10, // 请更改设备条件以设置“更多状态可用”状态位
|
||
COMMAND_187_PLACE_DEVICE_INTO_WRITE_PROTECT = 11, // 将设备置于写保护状态
|
||
COMMAND_187_RESET_IT_IN_COMMAND_48 = 13, // 请更改设备条件以重置命令48中设置的状态
|
||
// COMMAND_187_ENABLE_4_20MA_CURRENT_TEST = 14, // 开启4-20mA电流测试
|
||
// COMMAND_187_DISABLE_4_20MA_CURRENT_TEST = 15 // 关闭4-20mA电流测试
|
||
} command_187_e;
|
||
|
||
typedef enum
|
||
{
|
||
HART_COMMAND_35_EVENT = HART_COMMAND_35, // 写入电流上下限
|
||
HART_COMMAND_44_EVENT = HART_COMMAND_44, // 写入设备变量单位
|
||
HART_COMMAND_53_EVENT = HART_COMMAND_53, // 写入主变量单位
|
||
HART_COMMAND_109_EVENT = HART_COMMAND_109, // 突发模式控制
|
||
HART_COMMAND_131_EVENT = HART_COMMAND_131, // 写入整定参数
|
||
HART_COMMAND_132_EVENT = HART_COMMAND_132, // 读取整定参数
|
||
HART_COMMAND_133_EVENT = HART_COMMAND_133, // 获取打开的文件信息
|
||
HART_COMMAND_134_EVENT = HART_COMMAND_134, // 读取文件
|
||
HART_COMMAND_135_EVENT = HART_COMMAND_135, // 写入文件
|
||
HART_COMMAND_136_EVENT = HART_COMMAND_136, // 读取/解除/写入EEPROM
|
||
HART_COMMAND_138_EVENT = HART_COMMAND_138, // 读取其他状态
|
||
HART_COMMAND_140_EVENT = HART_COMMAND_140, // 读取触发器定义的内容
|
||
HART_COMMAND_142_EVENT = HART_COMMAND_142, // 执行校准
|
||
HART_COMMAND_143_EVENT = HART_COMMAND_143, // 设置阀门序列号
|
||
HART_COMMAND_144_EVENT = HART_COMMAND_144, // 读取阀门序列号
|
||
HART_COMMAND_145_EVENT = HART_COMMAND_145, // 读取仪器序列号
|
||
HART_COMMAND_146_EVENT = HART_COMMAND_146, // 读取标准跨度信息
|
||
HART_COMMAND_147_EVENT = HART_COMMAND_147, // 读取设备等级
|
||
HART_COMMAND_149_EVENT = HART_COMMAND_149, // 设置仪器时间
|
||
HART_COMMAND_150_EVENT = HART_COMMAND_150, // 读取仪器时间
|
||
HART_COMMAND_151_EVENT = HART_COMMAND_151, // 读取版本信息
|
||
HART_COMMAND_153_EVENT = HART_COMMAND_153, // 读取校准记录
|
||
HART_COMMAND_154_EVENT = HART_COMMAND_154, // 设置仪器序列号
|
||
HART_COMMAND_155_EVENT = HART_COMMAND_155, // 执行诊断
|
||
HART_COMMAND_156_EVENT = HART_COMMAND_156, // 读取诊断状态
|
||
HART_COMMAND_157_EVENT = HART_COMMAND_157, // 停止诊断
|
||
HART_COMMAND_158_EVENT = HART_COMMAND_158, // 在线诊断测试
|
||
HART_COMMAND_162_EVENT = HART_COMMAND_162, // 设置气源气压/A口/B口
|
||
HART_COMMAND_164_EVENT = HART_COMMAND_164, // 读取规格表数据
|
||
HART_COMMAND_165_EVENT = HART_COMMAND_165, // 写入规格表数据
|
||
HART_COMMAND_167_EVENT = HART_COMMAND_167, // 写入操作日期和用户
|
||
HART_COMMAND_168_EVENT = HART_COMMAND_168, // 读取部分行程警报
|
||
HART_COMMAND_170_EVENT = HART_COMMAND_170, // 读取制造信息序列号
|
||
HART_COMMAND_187_EVENT = HART_COMMAND_187,
|
||
HART_COMMAND_200_EVENT = HART_COMMAND_200, // 读取制造信息序列号
|
||
|
||
HART_COMMAND_523_EVENT = HART_COMMAND_523, // 读取精简状态映射数组
|
||
HART_COMMAND_524_EVENT = HART_COMMAND_524, // 写入精简状态映射
|
||
} hart_interface_user_event_e;
|
||
|
||
typedef enum
|
||
{
|
||
DVC_FILE_ID_CUSTOM_CHAR = 1, // 自定义数据特性
|
||
DVC_FILE_ID_DIAG_SCRIPT = 2, // 诊断脚本
|
||
DVC_FILE_ID_DIAG_DATA_BUFFER = 3, // 诊断数据缓冲区
|
||
DVC_FILE_ID_FACTORY_DEFAULTS = 5, // 出厂默认值
|
||
DVC_FILE_ID_PARAMETER_IMPORT = 20, // 参数导入
|
||
} dvc_file_id_e;
|
||
|
||
typedef enum
|
||
{
|
||
EEPROM_COMMAND_WRITE = 1,
|
||
EEPROM_COMMAND_UNLOCK = 2,
|
||
EEPROM_COMMAND_READ = 3,
|
||
} eeprom_lock_command_e;
|
||
|
||
typedef enum
|
||
{
|
||
EEPROM_STATE_UNLOCK = 0,
|
||
EEPROM_STATE_FLASH_APP_CODE = 1,
|
||
EEPROM_STATE_FLASH_BOOT_CODE = 3,
|
||
EEPROM_STATE_FLASH_TEMPCOMP = 5,
|
||
EEPROM_STATE_DIAGNOSTIOCS = 16,
|
||
} eeprom_lock_state_e;
|
||
|
||
#pragma pack(1)
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t len;
|
||
user_param_type_e type;
|
||
user_param_access_e access;
|
||
} user_variable_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t burst_mode; // 1:yes 0:no
|
||
uint8_t message_no; // 消息号
|
||
} hart_command_109_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t pbuf[USER_PARAM_MAX_NUM];
|
||
} hart_command_129_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t pbuf[USER_RESPONSE_MAX_LEN];
|
||
} hart_command_130_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t tuning_type; // 整定类型
|
||
uint8_t tuning_data; // 整定数据
|
||
} hart_command_131_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t pos_tuning_set; // 位置整定参数
|
||
uint8_t press_tuning_set; // 压力整定参数
|
||
} hart_command_132_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t file_function; // 文件功能
|
||
uint8_t file_id; // 文件ID
|
||
uint16_t write_data_number; // 写数据个数
|
||
} hart_command_133_t; // 命令133请求数据
|
||
|
||
typedef struct
|
||
{
|
||
dvc_file_id_e file_index;
|
||
uint16_t file_offset;
|
||
uint8_t read_length;
|
||
} hart_command_134_t;
|
||
|
||
typedef struct
|
||
{
|
||
dvc_file_id_e file_index; // 文件编号
|
||
uint16_t address; // 起始地址
|
||
uint8_t pbuf[HART_PACKED128_LEN];
|
||
} hart_command_135_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t sub_cmd; // 命令 eeprom_lock_command_e
|
||
uint8_t lock_type; // 锁类型
|
||
} hart_command_136_t; // 读取/解除/写入EEPROM
|
||
|
||
typedef struct
|
||
{
|
||
uint16_t start_addr; // 起始地址
|
||
uint8_t read_data_len; // 读取数据长度
|
||
} hart_command_140_t; // 命令140请求数据
|
||
|
||
typedef struct
|
||
{
|
||
write_protect_code_e protection_code;
|
||
uint16_t count;
|
||
} hart_command_141_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t code;
|
||
uint8_t subcode;
|
||
} hart_command_142_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t pbuf[HART_PACKED16_LEN];
|
||
} hart_command_143_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t seed; // 参与Seed计算:随机数
|
||
uint16_t level; // 设备等级
|
||
uint8_t update_count; // 临时更新次数
|
||
} hart_command_147_t; // 读取设备等级
|
||
|
||
typedef struct
|
||
{
|
||
uint32_t secs; // 校准时间
|
||
} hart_command_149_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint32_t secs; // 校准时间
|
||
uint32_t reserve; // 预留四位
|
||
} hart_command_150_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t nvm_version; // NVM版本
|
||
uint8_t valvelink_version; // 上位机编译版本
|
||
uint8_t date[HART_PACKED3_LEN]; // 日期
|
||
uint8_t reserve[7]; // 保留
|
||
} hart_command_151_t; // 读取版本信息
|
||
|
||
typedef struct
|
||
{
|
||
uint32_t calibration_time; // 校准时间
|
||
uint8_t control_byte; // 控制字节
|
||
uint8_t operator[HART_PACKED25_LEN]; // 操作员
|
||
} hart_command_153_t; // 读取校准记录
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t pbuf[HART_PACKED16_LEN];
|
||
} hart_command_154_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t pbuf[HART_PACKED16_LEN];
|
||
} hart_command_155_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t diagnostic_state; ///< 诊断状态
|
||
} hart_command_156_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t diagnostic_type; ///< 诊断类型
|
||
uint8_t variable_code[HART_PACKED4_LEN]; ///< 设备变量,和HART中的设备变量有关系
|
||
uint8_t sampling_time; ///< 采集时间
|
||
uint16_t points; ///< 总数据点数
|
||
} hart_command_158_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t press_type; // 压力类型,参考 pressure_type_e
|
||
uint8_t press_unit; // 压力单位,参考 press_unit_e
|
||
float32 press_value; // 压力值
|
||
} hart_command_162_t;
|
||
typedef struct
|
||
{
|
||
uint16_t address; // 起始地址
|
||
uint8_t length; // 数据长度
|
||
} hart_command_164_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint16_t address; // 起始地址
|
||
uint8_t pbuf[HART_PACKED30_LEN]; // 数据
|
||
} hart_command_165_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint32_t operation_time; // 时间 4字节
|
||
uint8_t control_byte; // 控制字节
|
||
uint8_t operator[HART_PACKED25_LEN]; // 人员 25字节
|
||
} hart_command_167_t; // 设置校准记录
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t pbuf[HART_PACKED6_LEN];
|
||
} hart_command_168_t; // 读取部分行程警报
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t code; // 类别 0:制造主要信息 1:制造方案信息
|
||
} hart_command_170_t; // 读取制造信息序列号
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t code;
|
||
} hart_command_187_t;
|
||
|
||
typedef struct
|
||
{
|
||
uint16_t start_addr; // 起始地址
|
||
uint16_t length; // 读取数据长度
|
||
} hart_command_200_t; // 读取NVM非易失性存储器数据
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t address;
|
||
uint8_t count; // 这里的长度不是字节,需要*0.5
|
||
} hart_command_523_t;
|
||
|
||
typedef struct
|
||
{
|
||
hart_command_523_t;
|
||
} hart_command_524_t;
|
||
|
||
typedef union
|
||
{
|
||
hart_command_109_t command_109; // 突发模式控制
|
||
hart_command_129_t command_129; // 读取用户自定义参数
|
||
hart_command_130_t command_130; // 写入用户自定义参数
|
||
hart_command_131_t command_131; // 写入整定参数
|
||
hart_command_133_t command_133; // 写入整定参数
|
||
hart_command_134_t command_134; // 读取文件
|
||
hart_command_135_t command_135; // 写入文件
|
||
hart_command_136_t command_136; // 读取/解除/写入EEPROM
|
||
hart_command_140_t command_140; // 读取触发器定义的内容
|
||
hart_command_141_t command_141; // 写保护
|
||
hart_command_142_t command_142; // 自整定
|
||
hart_command_143_t command_143; // 设置阀门序列号
|
||
hart_command_149_t command_149; // 设置仪器时间
|
||
hart_command_154_t command_154; // 设置仪器序列号
|
||
hart_command_155_t command_155; // 执行诊断
|
||
hart_command_156_t command_156; // 读取诊断状态
|
||
hart_command_158_t command_158; // 读取诊断状态
|
||
hart_command_162_t command_162; // 设置气源气压/A口/B口
|
||
hart_command_164_t command_164; // 读取规格表数据
|
||
hart_command_165_t command_165; // 写入规格表数据
|
||
hart_command_167_t command_167; // 写入操作日期和用户
|
||
hart_command_170_t command_170; // 读取制造信息序列号
|
||
hart_command_187_t command_187; // 测试指令
|
||
hart_command_200_t command_200; // 读取NVM非易失性存储器数据
|
||
hart_command_523_t command_523; // 读取压缩状态映射
|
||
hart_command_524_t command_524; // 写入压缩状态映射
|
||
} hart_user_command_req_data_u; // 用户自定义请求指令数据域
|
||
|
||
typedef struct
|
||
{
|
||
uint8_t pbuf[HART_RESPONSE_MAX_LEN];
|
||
uint8_t len;
|
||
} hart_user_rsp_t;
|
||
|
||
typedef struct
|
||
{
|
||
hart_user_command_req_data_u data; // 用户自定义请求指令数据域
|
||
uint8_t data_length; // 数据长度
|
||
response_communication_code_e code; // 响应通信代码
|
||
uint64_t uuid; // 唯一标识
|
||
hart_user_rsp_t rsp; // 用户自定义响应数据
|
||
} hart_user_req_t;
|
||
|
||
#pragma pack()
|
||
|
||
#endif // __HART_FRAME_USER_H__
|