4270 lines
152 KiB
C
4270 lines
152 KiB
C
#include "../inc/hart_slave_req.h"
|
||
#include "../inc/hart_slave_frame.h"
|
||
|
||
/**
|
||
* @brief 未定义命令
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_undef_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取唯一标识命令V5
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static void command_0_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
*resp->data_p++ = 254; // 默认254
|
||
*resp->data_p++ = HI_UINT16(hart_device_attribute.flash_variable.extended_device_type); // 扩展设备类型
|
||
*resp->data_p++ = LO_UINT16(hart_device_attribute.flash_variable.extended_device_type);
|
||
*resp->data_p++ = HART_PREAMBLE_DEFAULT_LEN; // 主设备到从设备的最少同步前导码数量
|
||
*resp->data_p++ = hart_get_current_protocol_version(); // 本设备实施的HART协议主要版本号。对于HART版本7。该值必须是数字7
|
||
*resp->data_p++ = hart_device_attribute.flash_variable.device_revision; // 设备版本
|
||
*resp->data_p++ = hart_device_attribute.flash_variable.device_software_revision; // 设备软件版本,254,255保留
|
||
*resp->data_p++ = hart_device_attribute.flash_variable.device_hardware_revision.version; // (高5bits)硬件版本号,31保留;(低3bits)5.10 物理信号
|
||
resp->data_p++; // 保留
|
||
osel_memcpy(resp->data_p, hart_device_attribute.flash_variable.long_address + 2, 3); // 设备ID,长ID的后3个字节
|
||
resp->data_p += 3;
|
||
uint16_t cfg_cnt = req->master == HART_MASTER ? hart_device_attribute.flash_variable.master_cfg_update_count : hart_device_attribute.flash_variable.slave_cfg_update_count; // 配置更新计数
|
||
if (hart_get_current_protocol_version() == HART_PROTOCOL_VERSION_7)
|
||
{
|
||
*resp->data_p++ = hart_device_attribute.flash_variable.s2m_preambles; // 从设备到主设备的响应前导码个数
|
||
*resp->data_p++ = 10; //*hart_device_attribute.last_device_variable; //ZKBW // 上一个设备变量,这表示应用程序应在现场设备中找到的最后一个设备变量代码(在执行Command 54时读取设备的变量)
|
||
*resp->data_p++ = HI_UINT16(cfg_cnt); // 配置被更新的次数
|
||
*resp->data_p++ = LO_UINT16(cfg_cnt);
|
||
*resp->data_p++ = hart_device_attribute.device_status.additional_device_status.extended_device_status; // 扩展现场设备状态未指定的任何位都是未定义的,必须设置为零。
|
||
*resp->data_p++ = HI_UINT16(hart_device_attribute.flash_variable.manufacturer_identification_code); // 制造商标识码
|
||
*resp->data_p++ = LO_UINT16(hart_device_attribute.flash_variable.manufacturer_identification_code);
|
||
*resp->data_p++ = HI_UINT16(hart_device_attribute.flash_variable.private_label_distributor_code); // 私有标签分销商代码
|
||
*resp->data_p++ = LO_UINT16(hart_device_attribute.flash_variable.private_label_distributor_code);
|
||
*resp->data_p++ = hart_device_attribute.flash_variable.device_profile; // 设备配置文件
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @brief 读取唯一标识命令V5 2023-05-06
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_0_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
command_0_req(req, resp);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取主变量
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_1_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
float32_u tmp;
|
||
hart_device_variable_t *variable = NULL;
|
||
variable = get_device_variable_by_standard_code(DIN_246);
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
osel_memcpy((uint8_t *)&tmp.f, (uint8_t *)variable->value, sizeof(float32));
|
||
tmp.f -= variable->trim_point.value;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
*resp->data_p++ = variable->units_code; // 主变量单位代码
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u)); // 主要变量
|
||
resp->data_p += sizeof(float32_u);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取主变量的回路电流和量程百分比
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_2_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
float32_u tmp;
|
||
hart_device_variable_t *variable = NULL;
|
||
variable = get_device_variable_by_standard_code(DIN_245); // 回路电流
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
osel_memcpy((uint8_t *)&tmp.f, (uint8_t *)variable->value, sizeof(float32));
|
||
tmp.f -= variable->trim_point.value;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
variable = get_device_variable_by_standard_code(DIN_244); // 百分百
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
osel_memcpy((uint8_t *)&tmp.f, (uint8_t *)variable->value, sizeof(float32));
|
||
tmp.f -= variable->trim_point.value;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取动态变量和回路电流
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_3_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
float32_u tmp;
|
||
hart_device_variable_t *variable = NULL;
|
||
variable = get_device_variable_by_standard_code(DIN_245); // 回路电流
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_12;
|
||
return TRUE;
|
||
}
|
||
osel_memcpy((uint8_t *)&tmp.f, (uint8_t *)variable->value, sizeof(float32));
|
||
tmp.f -= variable->trim_point.value;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
/**
|
||
* 响应数据在每个设备类型支持的最后一个动态变量之后被截断(请参见表1)对于给定的设备类型和设备版本,响应数据字节数必须是固定的。换句话说,一个设备类型可能在一种操作模式下不返回PV、SV和TV,后来(在不同的操作中)只返回PV和SV。返回的动态变量数可能随着设备版本的增加而增加。返回的动态变量的数量永远不会减少
|
||
*/
|
||
variable = get_device_variable_by_standard_code(DIN_246); // 主变量
|
||
if (variable->code == DIN_250)
|
||
{
|
||
return TRUE;
|
||
}
|
||
osel_memcpy((uint8_t *)&tmp.f, (uint8_t *)variable->value, sizeof(float32));
|
||
tmp.f -= variable->trim_point.value;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
*resp->data_p++ = variable->units_code;
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
variable = get_device_variable_by_standard_code(DIN_247); // 次要变量
|
||
if (variable->code == DIN_250)
|
||
{
|
||
return TRUE;
|
||
}
|
||
osel_memcpy((uint8_t *)&tmp.f, (uint8_t *)variable->value, sizeof(float32));
|
||
tmp.f -= variable->trim_point.value;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
*resp->data_p++ = variable->units_code;
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
variable = get_device_variable_by_standard_code(DIN_248); // 三级变量
|
||
if (variable->code == DIN_250)
|
||
{
|
||
return TRUE;
|
||
}
|
||
osel_memcpy((uint8_t *)&tmp.f, (uint8_t *)variable->value, sizeof(float32));
|
||
tmp.f -= variable->trim_point.value;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
*resp->data_p++ = variable->units_code;
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
variable = get_device_variable_by_standard_code(DIN_249); // 四级变量
|
||
if (variable->code == DIN_250)
|
||
{
|
||
return TRUE;
|
||
}
|
||
osel_memcpy((uint8_t *)&tmp.f, (uint8_t *)variable->value, sizeof(float32));
|
||
tmp.f -= variable->trim_point.value;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
*resp->data_p++ = variable->units_code;
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 写入轮训地址V5 2023-05-08
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_6_req(const hart_command_req_t *const req, hart_response_t *resp) // ZKBW
|
||
{
|
||
BOOL change = FALSE;
|
||
if (req->data_length < 1)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
if (req->data.command_6.poll_address > 63)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
if (req->data_length == 2 && req->data.command_6.loop_current_mode > 1)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
else
|
||
{
|
||
if (req->data_length == 1)
|
||
{
|
||
if (req->data.command_6.poll_address != hart_device_attribute.flash_variable.poll_address)
|
||
{
|
||
hart_device_attribute.flash_variable.poll_address = req->data.command_6.poll_address;
|
||
hart_storage_write_item(HART_STORAGE_PARAMS, HPB_POLL_ADDRESS,
|
||
&hart_device_attribute.flash_variable.poll_address);
|
||
change = TRUE;
|
||
}
|
||
if (hart_device_attribute.flash_variable.poll_address == 0)
|
||
{
|
||
hart_device_attribute.flash_variable.loop_current_mode = 0x01;
|
||
}
|
||
else
|
||
{
|
||
hart_device_attribute.flash_variable.loop_current_mode = 0x00;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
if (req->data.command_6.loop_current_mode != hart_device_attribute.flash_variable.loop_current_mode)
|
||
{
|
||
hart_device_attribute.flash_variable.loop_current_mode = req->data.command_6.loop_current_mode;
|
||
|
||
hart_storage_write_item(HART_STORAGE_PARAMS, HPB_LOOP_CURRENT_MODE,
|
||
&hart_device_attribute.flash_variable.loop_current_mode);
|
||
change = TRUE;
|
||
}
|
||
}
|
||
|
||
if (change)
|
||
{
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
}
|
||
|
||
// 回复数据
|
||
{
|
||
*resp->data_p++ = hart_device_attribute.flash_variable.poll_address;
|
||
*resp->data_p++ = hart_device_attribute.flash_variable.loop_current_mode;
|
||
|
||
if (hart_device_attribute.flash_variable.loop_current_mode == 0)
|
||
{
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_4);
|
||
}
|
||
else
|
||
{
|
||
hart_device_status_clr_operational_state(DEVICE_OPERATIONAL_STATE_4);
|
||
}
|
||
}
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取循环配置 2023-05-08
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_7_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
*resp->data_p++ = hart_device_attribute.flash_variable.poll_address; // 轮询地址
|
||
*resp->data_p++ = hart_device_attribute.flash_variable.loop_current_mode; // 回路电流模式
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取动态变量分类 2023-05-08
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_8_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_device_variable_t *variable = NULL;
|
||
variable = get_device_variable_by_standard_code(DIN_246); // 主变量
|
||
*resp->data_p++ = variable->classification;
|
||
variable = get_device_variable_by_standard_code(DIN_247); // 主变量
|
||
*resp->data_p++ = variable->classification;
|
||
variable = get_device_variable_by_standard_code(DIN_248); // 主变量
|
||
*resp->data_p++ = variable->classification;
|
||
variable = get_device_variable_by_standard_code(DIN_249); // 主变量
|
||
*resp->data_p++ = variable->classification;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取具有状态的设备变量 2023-05-08
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_9_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_device_variable_t *variable = NULL;
|
||
slot_device_variable_rsp_t slot;
|
||
hart_command_9_rsp_t rsp;
|
||
float32_u tmp;
|
||
uint8_t *code = NULL;
|
||
uint8_t uclength_temp = 0;
|
||
variable_e type = VARIABLE;
|
||
uclength_temp = req->data_length;
|
||
if (uclength_temp == 0)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
|
||
if (uclength_temp > 8)
|
||
{
|
||
uclength_temp = 8;
|
||
}
|
||
if (uclength_temp == 4 && (req->data.command_9.hart_command_9_req.slot0 == 0xff) &&
|
||
(req->data.command_9.hart_command_9_req.slot1 == 0xff) && (req->data.command_9.hart_command_9_req.slot2 == 0xff) && (req->data.command_9.hart_command_9_req.slot3 == 0xff))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
|
||
osel_memset((uint8_t *)&rsp, 0, sizeof(hart_command_9_rsp_t));
|
||
rsp.extended_field_device_status = hart_device_attribute.device_status.additional_device_status.extended_device_status; // 扩展现场设备状态
|
||
for (uint8_t i = 0; i < uclength_temp; i++)
|
||
{
|
||
code = (uint8_t *)(&req->data.command_9.hart_command_9_req.slot0) + i;
|
||
type = get_variable_type(*code);
|
||
osel_memset((uint8_t *)&slot, 0, sizeof(slot_device_variable_rsp_t));
|
||
if (type == VARIABLE)
|
||
{
|
||
variable = get_device_variable(*code);
|
||
}
|
||
else if (type == CONSTANT)
|
||
{
|
||
variable = &hart_device_variable_invalid;
|
||
}
|
||
else
|
||
{
|
||
variable = get_device_variable_by_standard_code(*code);
|
||
}
|
||
variable->code = *code; // ZKBW
|
||
slot.code = variable->code;
|
||
slot.classification = variable->classification;
|
||
slot.units_code = variable->units_code;
|
||
tmp.f = covert_float(variable->user_param.type, (void *)variable->value);
|
||
tmp.f -= variable->trim_point.value;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
slot.value.f = tmp.f;
|
||
slot.status = variable->status.data;
|
||
osel_memcpy((uint8_t *)&rsp.slot[i], (uint8_t *)&slot, sizeof(slot_device_variable_rsp_t));
|
||
}
|
||
rsp.slot_data_timestamp = hart_get_timestamp();
|
||
rsp.slot_data_timestamp = S2B_UINT32(rsp.slot_data_timestamp);
|
||
|
||
*resp->data_p++ = rsp.extended_field_device_status;
|
||
osel_memcpy(resp->data_p, (uint8_t *)&rsp.slot, sizeof(slot_device_variable_rsp_t) * uclength_temp);
|
||
resp->data_p += sizeof(slot_device_variable_rsp_t) * uclength_temp;
|
||
osel_memcpy(resp->data_p, (uint8_t *)&rsp.slot_data_timestamp, sizeof(uint32_t));
|
||
resp->data_p += sizeof(uint32_t);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取与标签关联的唯一标识符 2023-05-08
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_11_req(const hart_command_req_t *const req, hart_response_t *resp) // ZKBW
|
||
{
|
||
BOOL same = TRUE;
|
||
uint8_t buf[HART_PACKED8_LEN];
|
||
if (req->data_length == 0)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
|
||
encode_ascii_6(hart_device_attribute.flash_variable.tag, HART_PACKED8_LEN, buf);
|
||
for (uint8_t i = 0; i < HART_PACKED6_LEN; i++)
|
||
{
|
||
if (req->data.command_11.tag[i] != buf[i])
|
||
{
|
||
same = FALSE;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (same)
|
||
{
|
||
command_0_req(req, resp); ///< 与命令0相同
|
||
return TRUE;
|
||
}
|
||
else
|
||
{
|
||
// resp->code = RESPONSE_COMMUNICATION_CODE_38;
|
||
return FALSE;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* @brief 读取消息 2023-05-08
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_12_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
uint8_t buf[HART_PACKED32_LEN];
|
||
osel_memset(buf, 0x00, HART_PACKED32_LEN);
|
||
encode_ascii_6(hart_device_attribute.flash_variable.message, HART_PACKED32_LEN, buf);
|
||
for (uint8_t i = 0; i < HART_PACKED24_LEN; i++)
|
||
{
|
||
*resp->data_p++ = buf[i];
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取标签、描述符、日期 2023-05-08
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_13_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
uint8_t buf[HART_PACKED24_LEN];
|
||
osel_memset(buf, 0x00, HART_PACKED24_LEN);
|
||
encode_ascii_6(hart_device_attribute.flash_variable.tag, HART_PACKED8_LEN, buf);
|
||
// LOG_HEX(hart_device_attribute.flash_variable.tag, HART_PACKED8_LEN);
|
||
// LOG_HEX(buf, HART_PACKED8_LEN);
|
||
for (uint8_t i = 0; i < HART_PACKED6_LEN; i++)
|
||
{
|
||
*resp->data_p++ = buf[i]; // 标签
|
||
}
|
||
|
||
osel_memset(buf, 0x00, HART_PACKED24_LEN);
|
||
encode_ascii_6(hart_device_attribute.flash_variable.descriptor, HART_PACKED16_LEN, buf);
|
||
// LOG_HEX(hart_device_attribute.flash_variable.descriptor, HART_PACKED16_LEN);
|
||
// LOG_HEX(buf, HART_PACKED16_LEN);
|
||
for (uint8_t i = 0; i < HART_PACKED12_LEN; i++)
|
||
{
|
||
*resp->data_p++ = buf[i]; // 描述符
|
||
}
|
||
|
||
for (uint8_t i = 0; i < HART_DATE_LEN; i++)
|
||
{
|
||
*resp->data_p++ = hart_device_attribute.flash_variable.date[i];
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取主变量传感器信息 2023-05-08
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_14_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_command_14_t data;
|
||
hart_device_variable_t *variable = NULL;
|
||
variable = get_device_variable_by_standard_code(DIN_246); // 主变量
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
return TRUE;
|
||
}
|
||
osel_memcpy(data.pv_transducer_serial_number.bs, variable->transducer.serial_number.bs, sizeof(uint24_t));
|
||
data.pv_transducer_limits_and_minimum_span_units_code = variable->transducer.limits_and_minimum_span_units_code;
|
||
data.pv_upper_transducer_limit = variable->transducer.upper_limit;
|
||
data.pv_lower_transducer_limit = variable->transducer.lower_limit;
|
||
data.pv_minimum_span = variable->transducer.minimum_span;
|
||
|
||
data.pv_upper_transducer_limit.c = S2B_UINT32(data.pv_upper_transducer_limit.c); // 主变量上限
|
||
data.pv_lower_transducer_limit.c = S2B_UINT32(data.pv_lower_transducer_limit.c); // 主变量下限
|
||
data.pv_minimum_span.c = S2B_UINT32(data.pv_minimum_span.c); // 主变量最小跨度
|
||
|
||
osel_memcpy(resp->data_p, (uint8_t *)&data, sizeof(hart_command_14_t)); // 主变量传感器信息
|
||
resp->data_p += sizeof(hart_command_14_t);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取设备信息 2023-05-09
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_15_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_device_variable_t *variable = NULL;
|
||
hart_command_15_t data;
|
||
variable = get_device_variable_by_standard_code(DIN_246); // 主变量
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
|
||
data.pv_alarm_selection_code = variable->attribute.alarm_selection_code;
|
||
data.pv_transfer_function_code = variable->attribute.transfer_function_code;
|
||
data.pv_upper_and_lower_range_values_units_code = variable->transducer.upper_and_lower_range_values_units_code;
|
||
data.pv_damping_value.f = variable->attribute.damping_value;
|
||
osel_memcpy((uint8_t *)&data.pv_upper_range_value.f, (uint8_t *)&variable->transducer.upper_limit.f, sizeof(float32));
|
||
osel_memcpy((uint8_t *)&data.pv_lower_range_value.f, (uint8_t *)&variable->transducer.lower_limit.f, sizeof(float32));
|
||
data.pv_upper_range_value.c = S2B_UINT32(data.pv_upper_range_value.c); // 主变量上限
|
||
data.pv_lower_range_value.c = S2B_UINT32(data.pv_lower_range_value.c); // 主变量下限
|
||
data.pv_damping_value.c = S2B_UINT32(data.pv_damping_value.c); // 主变量阻尼
|
||
|
||
data.write_protect_code = hart_device_attribute.flash_variable.write_protect_code;
|
||
data.reserved = 250;
|
||
data.pv_analog_channel_flags = variable->attribute.analog_channel_flags;
|
||
osel_memcpy(resp->data_p, (uint8_t *)&data, sizeof(hart_command_15_t)); // 设备信息
|
||
resp->data_p += sizeof(hart_command_15_t);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取最终总装编号 2023-05-09
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_16_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
osel_memcpy(resp->data_p, hart_device_attribute.flash_variable.final_assembly_number, HART_PACKED3_LEN); // 最终总装编号
|
||
resp->data_p += sizeof(uint24_t);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 写入消息V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_17_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
uint8_t buf[HART_PACKED32_LEN];
|
||
if (req->data_length < HART_PACKED24_LEN)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
osel_memset(buf, 0x00, HART_PACKED32_LEN);
|
||
decode_ascii_6(req->data.command_17.message, HART_PACKED24_LEN, buf);
|
||
|
||
if (osel_memcmp(hart_device_attribute.flash_variable.message, buf, HART_PACKED32_LEN) != 0)
|
||
{
|
||
osel_memset(hart_device_attribute.flash_variable.message, 0x00, HART_PACKED32_LEN);
|
||
osel_memcpy(hart_device_attribute.flash_variable.message, buf, HART_PACKED32_LEN);
|
||
hart_storage_write_item(HART_STORAGE_PARAMS, HPB_MESSAGE,
|
||
hart_device_attribute.flash_variable.message);
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
}
|
||
|
||
// 回复数据
|
||
osel_memset(buf, 0x20, HART_PACKED32_LEN);
|
||
encode_ascii_6(hart_device_attribute.flash_variable.message, HART_PACKED32_LEN, buf);
|
||
osel_memcpy(resp->data_p, buf, HART_PACKED24_LEN);
|
||
resp->data_p += HART_PACKED24_LEN;
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 写标签、描述符、日期V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_18_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
BOOL change = FALSE;
|
||
uint8_t buf[HART_PACKED24_LEN];
|
||
if (req->data_length < (HART_PACKED6_LEN + HART_PACKED12_LEN + HART_DATE_LEN))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
|
||
osel_memset(buf, 0x00, HART_PACKED24_LEN);
|
||
decode_ascii_6(req->data.command_18.tag, HART_PACKED6_LEN, buf);
|
||
if (osel_memcmp(hart_device_attribute.flash_variable.tag, buf, HART_PACKED8_LEN) != 0)
|
||
{
|
||
osel_memset(hart_device_attribute.flash_variable.tag, 0x00, HART_PACKED8_LEN);
|
||
osel_memcpy(hart_device_attribute.flash_variable.tag, buf, HART_PACKED8_LEN); // 更新标签
|
||
hart_storage_write_item(HART_STORAGE_PARAMS, HPB_TAG,
|
||
hart_device_attribute.flash_variable.tag);
|
||
change = TRUE;
|
||
}
|
||
|
||
osel_memset(buf, 0x00, HART_PACKED24_LEN);
|
||
decode_ascii_6(req->data.command_18.descriptor, HART_PACKED12_LEN, buf);
|
||
if (osel_memcmp(hart_device_attribute.flash_variable.descriptor, buf, HART_PACKED8_LEN) != 0)
|
||
{
|
||
osel_memset(hart_device_attribute.flash_variable.descriptor, 0x00, HART_PACKED16_LEN);
|
||
osel_memcpy(hart_device_attribute.flash_variable.descriptor, buf, HART_PACKED16_LEN); // 更新描述符
|
||
hart_storage_write_item(HART_STORAGE_PARAMS, HPB_DESCRIPTOR,
|
||
hart_device_attribute.flash_variable.descriptor);
|
||
change = TRUE;
|
||
}
|
||
|
||
osel_memset(buf, 0x00, HART_PACKED24_LEN);
|
||
osel_memcpy(buf, req->data.command_18.date, HART_DATE_LEN);
|
||
if (osel_memcmp(hart_device_attribute.flash_variable.date, buf, HART_DATE_LEN) != 0)
|
||
{
|
||
osel_memset(hart_device_attribute.flash_variable.date, 0x00, HART_DATE_LEN);
|
||
osel_memcpy(hart_device_attribute.flash_variable.date, req->data.command_18.date, HART_DATE_LEN); // 更新日期
|
||
hart_storage_write_item(HART_STORAGE_PARAMS, HPB_DATE,
|
||
hart_device_attribute.flash_variable.date);
|
||
change = TRUE;
|
||
}
|
||
|
||
if (change)
|
||
{
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
}
|
||
|
||
// 回复数据
|
||
osel_memset(buf, 0x20, HART_PACKED24_LEN);
|
||
encode_ascii_6(hart_device_attribute.flash_variable.tag, HART_PACKED8_LEN, buf);
|
||
osel_memcpy(resp->data_p, buf, HART_PACKED6_LEN); // 标签
|
||
resp->data_p += HART_PACKED6_LEN;
|
||
|
||
osel_memset(buf, 0x20, HART_PACKED24_LEN);
|
||
encode_ascii_6(hart_device_attribute.flash_variable.descriptor, HART_PACKED16_LEN, buf);
|
||
osel_memcpy(resp->data_p, buf, HART_PACKED12_LEN); // 描述符
|
||
resp->data_p += HART_PACKED12_LEN;
|
||
|
||
osel_memcpy(resp->data_p, hart_device_attribute.flash_variable.date, HART_DATE_LEN); // 日期
|
||
resp->data_p += HART_DATE_LEN;
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 编写总装编号V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_19_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length < HART_PACKED3_LEN)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
|
||
if (osel_memcmp(hart_device_attribute.flash_variable.final_assembly_number, req->data.command_19.final_assembly_number, HART_PACKED3_LEN) != 0)
|
||
{
|
||
osel_memset(hart_device_attribute.flash_variable.final_assembly_number, 0x00, HART_PACKED3_LEN);
|
||
osel_memcpy(hart_device_attribute.flash_variable.final_assembly_number, req->data.command_19.final_assembly_number, HART_PACKED3_LEN); // 更新总装编号
|
||
|
||
hart_storage_write_item(HART_STORAGE_PARAMS, HPB_FINAL_ASSEMBLY_NUMBER,
|
||
hart_device_attribute.flash_variable.final_assembly_number);
|
||
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
}
|
||
|
||
// 回复数据
|
||
osel_memcpy(resp->data_p, hart_device_attribute.flash_variable.final_assembly_number, HART_PACKED3_LEN);
|
||
resp->data_p += HART_PACKED3_LEN;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取长标签
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_20_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
osel_memcpy(resp->data_p, hart_device_attribute.flash_variable.long_tag, HART_PACKED32_LEN); // 长标签
|
||
resp->data_p += HART_PACKED32_LEN;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取与长标签关联的唯一标识符
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_21_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
BOOL same = TRUE;
|
||
if (req->data_length == 0)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
|
||
for (uint8_t i = 0; i < HART_PACKED32_LEN; i++)
|
||
{
|
||
if (req->data.command_21.long_tag[i] != hart_device_attribute.flash_variable.long_tag[i])
|
||
{
|
||
same = FALSE;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (same)
|
||
{
|
||
command_0_req(req, resp);
|
||
}
|
||
else
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_38;
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 写长标签
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_22_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length < HART_PACKED32_LEN)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
|
||
if (osel_memcmp(hart_device_attribute.flash_variable.long_tag, req->data.command_22.long_tag, HART_PACKED32_LEN) != 0)
|
||
{
|
||
osel_memset(hart_device_attribute.flash_variable.long_tag, 0x00, HART_PACKED32_LEN);
|
||
osel_memcpy(hart_device_attribute.flash_variable.long_tag, req->data.command_22.long_tag, HART_PACKED32_LEN); // 更新长标签
|
||
|
||
hart_storage_write_item(HART_STORAGE_PARAMS, HPB_LONG_TAG,
|
||
hart_device_attribute.flash_variable.long_tag);
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
}
|
||
|
||
// 回复数据
|
||
osel_memcpy(resp->data_p, hart_device_attribute.flash_variable.long_tag, HART_PACKED32_LEN);
|
||
resp->data_p += HART_PACKED32_LEN;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 重置配置更改标志
|
||
* 配置恢复,配置更改在未写入到EEPROM中是先存在RAM中。command6等写入指令会更新计数器,通过计数器的数值不同来判断配置是否更新
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_38_req(const hart_command_req_t *const req, hart_response_t *resp) // ZKBW
|
||
{
|
||
uint16_t cfg_cnt = req->master == HART_MASTER ? hart_device_attribute.flash_variable.master_cfg_update_count : hart_device_attribute.flash_variable.slave_cfg_update_count; // 配置更新计数
|
||
|
||
if (req->data_length == 1) // ZKBW
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
else if (req->data_length == 2)
|
||
{
|
||
uint16_t configuration_change_counter = B2S_UINT16(req->data.command_38.configuration_change_counter);
|
||
if (configuration_change_counter != cfg_cnt)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_9;
|
||
return TRUE;
|
||
}
|
||
}
|
||
|
||
// 将配置从falsh中重新读取到缓存
|
||
if (FALSE == hart_storage_read(HART_STORAGE_PARAMS, (uint8_t *)&hart_device_attribute.flash_variable))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
}
|
||
else
|
||
{
|
||
*resp->data_p++ = HI_UINT16(cfg_cnt);
|
||
*resp->data_p++ = LO_UINT16(cfg_cnt);
|
||
hart_device_status_clr_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取其他设备状态
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_48_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
additional_device_status_t command_48;
|
||
uint8_t *ptr = NULL;
|
||
osel_memset((uint8_t *)&command_48, 0x00, sizeof(additional_device_status_t));
|
||
ptr = command_48.device_specific_status;
|
||
for (uint8_t i = 0; i < ARRAY_LEN(hart_device_attribute.device_status.additional_device_status.device_specific_status); i++)
|
||
{
|
||
*ptr = hart_device_attribute.device_status.additional_device_status.device_specific_status[i];
|
||
ptr++;
|
||
}
|
||
|
||
ptr = &command_48.extended_device_status;
|
||
*ptr = hart_device_attribute.device_status.additional_device_status.extended_device_status;
|
||
ptr++;
|
||
*ptr = hart_device_attribute.device_status.additional_device_status.device_operating_mode;
|
||
ptr++;
|
||
*ptr = hart_device_attribute.device_status.additional_device_status.standardized_status0;
|
||
ptr++;
|
||
*ptr = hart_device_attribute.device_status.additional_device_status.standardized_status1;
|
||
ptr++;
|
||
// *ptr = hart_device_attribute.device_status.additional_device_status.analog_channel_saturated;
|
||
// ptr++;
|
||
// *ptr = hart_device_attribute.device_status.additional_device_status.standardized_status2;
|
||
// ptr++;
|
||
// *ptr = hart_device_attribute.device_status.additional_device_status.standardized_status3;
|
||
// ptr++;
|
||
// *ptr = hart_device_attribute.device_status.additional_device_status.analog_channel_fixed;
|
||
// ptr++;
|
||
|
||
// ptr = command_48.extended_device_specific_status;
|
||
// for (uint8_t i = 0; i < 11; i++)
|
||
// {
|
||
// *ptr = hart_device_attribute.device_status.additional_device_status.extended_device_specific_status[i];
|
||
// }
|
||
|
||
// 回复数据
|
||
osel_memcpy(resp->data_p, (uint8_t *)&command_48, sizeof(additional_device_status_t));
|
||
resp->data_p += sizeof(additional_device_status_t);
|
||
return TRUE;
|
||
}
|
||
// 扩展命令
|
||
static BOOL hart_slave_command_31_req(const hart_command_req_t *const req, hart_response_t *resp) // ZKBW
|
||
{
|
||
// uint8_t *code = NULL;
|
||
// hart_device_variable_t *variable = NULL;
|
||
// float32_u tmp;
|
||
if (req->data_length < 2)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
else
|
||
{
|
||
// 处理大号命令
|
||
}
|
||
return TRUE;
|
||
}
|
||
// 通用命令
|
||
|
||
/**
|
||
* @brief 读取设备变量V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_33_req(const hart_command_req_t *const req, hart_response_t *resp) // ZKBW
|
||
{
|
||
uint8_t *code = NULL;
|
||
hart_device_variable_t *variable = NULL;
|
||
float32_u tmp;
|
||
uint8_t uctemp_length = 0;
|
||
uctemp_length = req->data_length;
|
||
variable_e type = VARIABLE;
|
||
if (uctemp_length == 0)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
if(uctemp_length > 4)
|
||
{
|
||
uctemp_length = 4;
|
||
}
|
||
if(uctemp_length == 4 && req->data.command_33.slot_0 == 0xff && req->data.command_33.slot_1 == 0xff
|
||
&& req->data.command_33.slot_2 == 0xff && req->data.command_33.slot_3)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
|
||
code = (uint8_t *)&req->data.command_33;
|
||
for (uint8_t i = 0; i < uctemp_length; i++)
|
||
{
|
||
|
||
type = get_variable_type(*code);
|
||
if (type == VARIABLE)
|
||
{
|
||
variable = get_device_variable(*code);
|
||
}
|
||
else if (type == CONSTANT)
|
||
{
|
||
variable = &hart_device_variable_invalid;
|
||
}
|
||
else
|
||
{
|
||
variable = get_device_variable_by_standard_code(*code);
|
||
}
|
||
|
||
osel_memcpy((uint8_t *)&tmp.f, (uint8_t *)variable->value, sizeof(float32));
|
||
tmp.f -= variable->trim_point.value;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
*resp->data_p++ = variable->code;
|
||
*resp->data_p++ = variable->units_code;
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
code++;
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 写入主变量范围值V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_35_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
BOOL change = FALSE;
|
||
hart_device_variable_t *variable = NULL;
|
||
float32_u tmpupper, tmplower;
|
||
hart_command_req_t user_req;
|
||
uint8_t i = 0;
|
||
if (req->data_length < sizeof(hart_command_35_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
osel_memcpy((uint8_t *)&user_req.data.command_35, (uint8_t *)&req->data.command_35, sizeof(hart_command_35_t));
|
||
variable = get_device_variable_by_standard_code(DIN_246); // 主变量
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_11;
|
||
return TRUE;
|
||
}
|
||
|
||
for (i = 0; i < sizeof(variable->units_code_allow); i++)
|
||
{
|
||
if (variable->units_code_allow[i] == req->data.command_35.pv_upper_and_lower_range_values_units_code)
|
||
{
|
||
if (variable->transducer.upper_and_lower_range_values_units_code != req->data.command_35.pv_upper_and_lower_range_values_units_code)
|
||
{
|
||
variable->transducer.upper_and_lower_range_values_units_code = req->data.command_35.pv_upper_and_lower_range_values_units_code;
|
||
change = TRUE;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
if (i >= sizeof(variable->units_code_allow))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
tmpupper.f = req->data.command_35.pv_upper_range_value;
|
||
tmpupper.c = B2S_UINT32(tmpupper.c);
|
||
tmplower.f = req->data.command_35.pv_lower_range_value;
|
||
tmplower.c = B2S_UINT32(tmplower.c);
|
||
if ((tmpupper.f > variable->transducer.upper_limit.f && tmplower.f < variable->transducer.lower_limit.f) || (tmpupper.f < variable->transducer.lower_limit.f && tmplower.f > variable->transducer.upper_limit.f))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_13;
|
||
|
||
return TRUE;
|
||
}
|
||
if (tmplower.f > variable->transducer.upper_limit.f)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_9;
|
||
|
||
return TRUE;
|
||
}
|
||
if (tmpupper.f > variable->transducer.upper_limit.f)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_11;
|
||
|
||
return TRUE;
|
||
}
|
||
if (tmpupper.f < variable->transducer.lower_limit.f)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_12;
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
if (tmplower.f < variable->transducer.lower_limit.f)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_10;
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
if (tmpupper.f == tmplower.f)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_29;
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
if (((tmpupper.f - tmplower.f) <= 0) && ((tmplower.f - tmpupper.f) < variable->transducer.minimum_span.f))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_14;
|
||
}
|
||
if (((tmpupper.f - tmplower.f) > 0) && ((tmpupper.f - tmplower.f) < variable->transducer.minimum_span.f))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_14;
|
||
}
|
||
|
||
if (variable->transducer.upper_limit.f != tmpupper.f)
|
||
{
|
||
osel_memcpy((uint8_t *)&variable->transducer.upper_limit.f, (uint8_t *)&tmpupper.f, sizeof(float32));
|
||
change = TRUE;
|
||
}
|
||
|
||
if (variable->transducer.lower_limit.f != tmplower.f)
|
||
{
|
||
osel_memcpy((uint8_t *)&variable->transducer.lower_limit.f, (uint8_t *)&tmplower.f, sizeof(float32));
|
||
change = TRUE;
|
||
}
|
||
|
||
if (change)
|
||
{
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
}
|
||
// 回复数据
|
||
*resp->data_p++ = variable->transducer.upper_and_lower_range_values_units_code;
|
||
osel_memcpy((uint8_t *)&tmpupper.f, (uint8_t *)&variable->transducer.upper_limit.f, sizeof(float32));
|
||
tmpupper.c = S2B_UINT32(tmpupper.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmpupper, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
osel_memcpy((uint8_t *)&tmplower.f, (uint8_t *)&variable->transducer.lower_limit.f, sizeof(float32));
|
||
tmplower.c = S2B_UINT32(tmplower.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmplower, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
hart_user_common_event(HART_COMMAND_35_EVENT, (void *)&user_req); // 同步单位到udevice
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 执行设备重置V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_42_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
// hart_device_reset();
|
||
// 7.9之后不再支持复位命令
|
||
return FALSE;
|
||
}
|
||
|
||
/**
|
||
* @brief 编写主变量单元V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_44_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
BOOL change = FALSE;
|
||
hart_device_variable_t *variable = NULL;
|
||
hart_command_req_t user_req;
|
||
uint8_t i = 0;
|
||
if (req->data_length < sizeof(hart_command_44_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
osel_memcpy((uint8_t *)&user_req.data.command_44, (uint8_t *)&req->data.command_44, sizeof(hart_command_44_t));
|
||
variable = get_device_variable_by_standard_code(DIN_246); // 主变量
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_11;
|
||
return TRUE;
|
||
}
|
||
if (req->data.command_44.pv_units_code == 0xFA)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
|
||
for (i = 0; i < sizeof(variable->units_code_allow); i++)
|
||
{
|
||
if (variable->units_code_allow[i] == req->data.command_44.pv_units_code)
|
||
{
|
||
if (variable->units_code != req->data.command_44.pv_units_code)
|
||
{
|
||
variable->units_code = req->data.command_44.pv_units_code;
|
||
change = TRUE;
|
||
}
|
||
if (variable->transducer.upper_and_lower_range_values_units_code != req->data.command_44.pv_units_code)
|
||
{
|
||
variable->transducer.upper_and_lower_range_values_units_code = req->data.command_44.pv_units_code;
|
||
change = TRUE;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
if (i >= sizeof(variable->units_code_allow))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
|
||
if (change)
|
||
{
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
}
|
||
|
||
// 回复数据
|
||
*resp->data_p++ = variable->units_code;
|
||
hart_user_common_event(HART_COMMAND_44_EVENT, (void *)&user_req); // 同步单位到udevice
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取动态变量赋值V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_50_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_device_standard_variable_t *variable = NULL;
|
||
variable = get_device_standard_variable(DIN_246); // 主变量
|
||
*resp->data_p++ = variable->dynamic_variable_code;
|
||
variable = get_device_standard_variable(DIN_247); // 次要变量
|
||
*resp->data_p++ = variable->dynamic_variable_code;
|
||
variable = get_device_standard_variable(DIN_248); // 第三变量
|
||
*resp->data_p++ = variable->dynamic_variable_code;
|
||
variable = get_device_standard_variable(DIN_249); // 第四变量
|
||
*resp->data_p++ = variable->dynamic_variable_code;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 编写动态变量赋值V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_51_req(const hart_command_req_t *const req, hart_response_t *resp) // zkbw
|
||
{
|
||
if (req->data_length == 0)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
BOOL ret = FALSE;
|
||
BOOL change = FALSE;
|
||
uint8_t *ptr = NULL;
|
||
uint8_t code = 0;
|
||
// uint16_t invalid_selection[] = {DIN_244, DIN_245, DIN_246, DIN_247,
|
||
// DIN_248, DIN_249};
|
||
uint8_t device_variables[4];
|
||
osel_memset(device_variables, DIN_250, ARRAY_LEN(device_variables));
|
||
for (uint8_t i = 0; i < req->data_length; i++)
|
||
{
|
||
ptr = (uint8_t *)&req->data.command_51.device_ariables[i];
|
||
// 设备变量代码244-249是无效的选择
|
||
if (req->data.command_51.device_ariables[i] > 0x0A)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
else
|
||
{
|
||
device_variables[i] = *ptr;
|
||
}
|
||
}
|
||
|
||
// 更新动态变量赋值
|
||
/* The above code is iterating through an array of device variables and setting their dynamic variable
|
||
codes based on their position in the array. It uses a switch statement to determine which device
|
||
variable to set and then adds the dynamic variable code to a response data buffer. */
|
||
for (uint8_t i = 0; i < ARRAY_LEN(device_variables); i++)
|
||
{
|
||
code = DIN_246 + i;
|
||
if (code != device_variables[i])
|
||
{
|
||
change = TRUE;
|
||
}
|
||
|
||
ret = copy_device_dynamic_variable(code, device_variables[i]);
|
||
if (ret == FALSE)
|
||
{
|
||
*resp->data_p++ = DIN_250;
|
||
}
|
||
else
|
||
{
|
||
*resp->data_p++ = device_variables[i];
|
||
}
|
||
}
|
||
|
||
if (change)
|
||
{
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 设置设备变量零V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_52_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_device_variable_t *variable = NULL;
|
||
BOOL find = FALSE;
|
||
if (req->data_length < sizeof(hart_command_52_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5; // 无效的数据长度
|
||
return TRUE;
|
||
}
|
||
|
||
/* The above code is iterating through an array of HART device variables and checking if the code of
|
||
each variable matches a specific device variable code provided in the request data. If a match is
|
||
found, the value of that device variable is set to 0 and the loop is exited. */
|
||
|
||
variable = get_device_variable(req->data.command_52.device_ariable);
|
||
if (variable->code == DIN_250)
|
||
{
|
||
find = FALSE;
|
||
}
|
||
else
|
||
{
|
||
if (variable->trim_point.trim_points != TRIM_POINTS_0)
|
||
{
|
||
find = TRUE;
|
||
// 数据处理
|
||
if (set_trim_point(variable, &resp->code) == TRUE)
|
||
{
|
||
hart_storage_write_item(HART_STORAGE_VARIABLE, variable->code,
|
||
(uint8_t *)variable);
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
}
|
||
}
|
||
}
|
||
|
||
// 回复数据
|
||
if (FALSE == find)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2; // 无效的设备变量代码
|
||
return TRUE;
|
||
}
|
||
else
|
||
{
|
||
*resp->data_p++ = variable->code; // 设备变量代码
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 写入设备变量单位V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_53_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_device_variable_t *hart_device_variable_p = NULL;
|
||
hart_command_req_t user_req;
|
||
variable_e type;
|
||
if (req->data_length < sizeof(hart_command_53_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
osel_memcpy((uint8_t *)&user_req.data.command_53, (uint8_t *)&req->data.command_53, sizeof(hart_command_53_t));
|
||
hart_device_variable_p = get_device_variable(req->data.command_53.device_ariable);
|
||
|
||
|
||
type = get_variable_type(req->data.command_53.device_ariable);
|
||
if (type == VARIABLE)
|
||
{
|
||
hart_device_variable_p = get_device_variable(req->data.command_53.device_ariable);
|
||
}
|
||
else if (type == CONSTANT)
|
||
{
|
||
hart_device_variable_p = &hart_device_variable_invalid;
|
||
}
|
||
else
|
||
{
|
||
hart_device_variable_p = get_device_variable_by_standard_code(req->data.command_53.device_ariable);
|
||
}
|
||
if(req->data.command_53.device_ariable_unit_code == 0xFA)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_12;
|
||
return TRUE;
|
||
}
|
||
// 回复数据
|
||
if (hart_device_variable_p->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_11; // 无效的设备变量代码
|
||
}
|
||
else
|
||
{
|
||
BOOL allow = FALSE;
|
||
// 判断传过来的单位是否在允许的范围内
|
||
for (uint8_t i = 0; i < HART_VARIABLE_UNITS_ALLOWED_CNT; i++)
|
||
{
|
||
if (req->data.command_53.device_ariable_unit_code == hart_device_variable_p->units_code_allow[i])
|
||
{
|
||
allow = TRUE;
|
||
break;
|
||
}
|
||
}
|
||
|
||
if (allow == FALSE)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_12;
|
||
}
|
||
else
|
||
{
|
||
|
||
if (hart_device_variable_p->units_code != req->data.command_53.device_ariable_unit_code)
|
||
{
|
||
hart_device_variable_p->units_code = req->data.command_53.device_ariable_unit_code;
|
||
|
||
hart_storage_write_item(HART_STORAGE_VARIABLE, hart_device_variable_p->code,
|
||
(uint8_t *)hart_device_variable_p);
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
}
|
||
|
||
// hart_user_common_event(HART_COMMAND_53_EVENT, (void *)&user_req); // 如果写入设备变量单位为压力或者电流,同步到命令129的变量单位中
|
||
|
||
*resp->data_p++ = hart_device_variable_p->code; // 设备变量代码
|
||
*resp->data_p++ = hart_device_variable_p->units_code; // 设备变量单位代码
|
||
}
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取设备变量信息V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_54_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_device_variable_t *hart_device_variable_p = NULL;
|
||
float32_u tmp;
|
||
uint32_t acquisition_period = 0;
|
||
if (req->data_length < sizeof(hart_command_54_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
hart_device_variable_p = get_device_variable(req->data.command_54.device_ariable);
|
||
if (hart_device_variable_p->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_11; // 无效的设备变量代码
|
||
return TRUE;
|
||
}
|
||
*hart_device_attribute.last_device_variable = hart_device_variable_p->code;
|
||
|
||
// 回复数据
|
||
*resp->data_p++ = hart_device_variable_p->code; // 设备变量代码
|
||
osel_memcpy(resp->data_p, hart_device_variable_p->transducer.serial_number.bs, sizeof(uint24_t)); // 设备可变传感器序列号
|
||
resp->data_p += sizeof(uint24_t);
|
||
*resp->data_p++ = hart_device_variable_p->transducer.limits_and_minimum_span_units_code; // 设备变量限制/最小量程单位代码
|
||
|
||
// 设备变量传感器上限
|
||
tmp.f = hart_device_variable_p->transducer.upper_limit.f;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
// 装置可变传感器下限
|
||
tmp.f = hart_device_variable_p->transducer.lower_limit.f;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
// 设备可变阻尼值
|
||
tmp.f = hart_device_variable_p->attribute.damping_value;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
// 设备变量最小量程
|
||
tmp.f = hart_device_variable_p->transducer.minimum_span.f;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
if (hart_get_current_protocol_version() == HART_PROTOCOL_VERSION_7)
|
||
{
|
||
*resp->data_p++ = hart_device_variable_p->classification; // 设备变量分类
|
||
*resp->data_p++ = hart_device_variable_p->family; // 设备变量系列
|
||
|
||
acquisition_period = hart_device_variable_p->acquisition_period;
|
||
acquisition_period = S2B_UINT32(acquisition_period);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&acquisition_period, sizeof(uint32_t)); // 采集周期,表示设备变量更新之间的最长周期
|
||
resp->data_p += sizeof(uint32_t);
|
||
|
||
*resp->data_p++ = hart_device_variable_p->properties; // 设备变量属性
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 写入响应序码数V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_59_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length < sizeof(hart_command_59_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
if (req->data.command_59.s2m_preambles < 5)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_4;
|
||
return TRUE;
|
||
}
|
||
else if (req->data.command_59.s2m_preambles > 20)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_3;
|
||
return TRUE;
|
||
}
|
||
else
|
||
{
|
||
if (hart_device_attribute.flash_variable.s2m_preambles != req->data.command_59.s2m_preambles)
|
||
{
|
||
hart_device_attribute.flash_variable.s2m_preambles = req->data.command_59.s2m_preambles;
|
||
|
||
hart_storage_write_item(HART_STORAGE_PARAMS, HPB_S2M_PREAMBLES,
|
||
&hart_device_attribute.flash_variable.s2m_preambles);
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
}
|
||
|
||
*resp->data_p++ = hart_device_attribute.flash_variable.s2m_preambles;
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取精简状态映射数组
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_523_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_user_req_t user_req;
|
||
if (hart_frame_data_length_check(req->data_length, sizeof(hart_command_523_t), (uint8_t *)&resp->code) == FALSE)
|
||
{
|
||
return TRUE;
|
||
}
|
||
osel_memcpy((uint8_t *)&user_req.data.command_523, (uint8_t *)&req->data.command_523, sizeof(hart_command_523_t));
|
||
if (FALSE == hart_user_common_event(HART_COMMAND_523_EVENT, (void *)&user_req))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_64;
|
||
return TRUE;
|
||
}
|
||
if (user_req.rsp.len != 0)
|
||
{
|
||
osel_memcpy(resp->data_p, user_req.rsp.pbuf, user_req.rsp.len);
|
||
resp->data_p += user_req.rsp.len;
|
||
}
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief 写入精简状态映射
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_524_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
#if 0
|
||
/**
|
||
* @brief 写入主变量阻尼值V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_34_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
float32_u tmp;
|
||
hart_device_variable_t *variable = NULL;
|
||
if (req->data_length < sizeof(hart_command_34_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
variable = get_device_variable_by_standard_code(DIN_246); // 主变量
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
|
||
tmp.f = req->data.command_34.pv_damping_value;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
variable->attribute.damping_value = tmp.f;
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
tmp.f = variable->attribute.damping_value;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
return TRUE;
|
||
}
|
||
|
||
|
||
/**
|
||
* @brief 设置主变量上限值V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_36_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_device_variable_t *variable = NULL;
|
||
variable = get_device_variable_by_standard_code(DIN_246); // 主变量
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
osel_memcpy((uint8_t *)variable->value, (uint8_t *)&variable->transducer.upper_limit.f, sizeof(float32)); // 将主要变量上限值复制到主变量
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 设置主变量下限值V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_37_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_device_variable_t *variable = NULL;
|
||
variable = get_device_variable_by_standard_code(DIN_246); // 主变量
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
osel_memcpy((uint8_t *)variable->value, (uint8_t *)&variable->transducer.lower_limit.f, sizeof(float32)); // 将主要变量下限值复制到主变量
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
return TRUE;
|
||
}
|
||
|
||
|
||
/**
|
||
* @brief EEPROM控制V5 0 刻录EEPROM 1 恢复影子内存
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_39_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
BOOL ret = FALSE;
|
||
if (req->data_length < sizeof(hart_command_39_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
|
||
if (0 == req->data.command_39.control_code)
|
||
{
|
||
hart_storage_write_sem_update();
|
||
}
|
||
else
|
||
{
|
||
ret = hart_storage_read(HART_STORAGE_PARAMS, (uint8_t *)&hart_device_attribute.flash_variable, sizeof(hart_storage_variable_t));
|
||
}
|
||
if (TRUE == ret)
|
||
{
|
||
// BIT_CLR(hart_device_attribute.device_status.operational_state, DEVICE_OPERATIONAL_STATE_7 | DEVICE_OPERATIONAL_STATE_8);
|
||
}
|
||
else
|
||
{
|
||
// BIT_SET(hart_device_attribute.device_status.operational_state, DEVICE_OPERATIONAL_STATE_8);
|
||
}
|
||
|
||
// 回复数据
|
||
*resp->data_p++ = req->data.command_39.control_code;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 执行自检V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_41_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_perform_self_test(); // TODO 跳转到自检画面
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 进入/退出固定电流模式V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_40_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
float32_u tmp;
|
||
if (req->data_length < sizeof(hart_command_40_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
tmp.f = req->data.command_40.pv_fixed_current_level;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
hart_device_attribute.pv_fixed_current_level = tmp.f;
|
||
|
||
// 回复数据
|
||
tmp.f = *hart_device_attribute.actual_pv_current_level;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 设置主变量零V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_43_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_device_variable_t *variable = NULL;
|
||
variable = get_device_variable_by_standard_code(DIN_246); // 主变量
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
*variable->value = 0;
|
||
return TRUE;
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* @brief 微调回路电流归零V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_45_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
float32_u tmp;
|
||
if (req->data_length < sizeof(hart_command_45_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
hart_device_variable_t *variable = NULL;
|
||
variable = get_device_variable_by_standard_code(DIN_245); // 回路电流
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
tmp.f = req->data.command_45.pv_loop_current_level;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
hart_device_attribute.pv_loop_current_level = tmp.f;
|
||
|
||
// 回复数据
|
||
tmp.f = *variable->value;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 微调回路电流增益V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_46_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
float32_u tmp;
|
||
if (req->data_length < sizeof(hart_command_46_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
hart_device_variable_t *variable = NULL;
|
||
variable = get_device_variable_by_standard_code(DIN_245); // 回路电流
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
tmp.f = req->data.command_46.pv_loop_current_level;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
hart_device_attribute.pv_loop_current_level = tmp.f;
|
||
|
||
// 回复数据
|
||
tmp.f = *variable->value;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 编写主变量传递函数V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_47_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_device_variable_t *variable = NULL;
|
||
if (req->data_length < sizeof(hart_command_47_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
|
||
variable = get_device_variable_by_standard_code(DIN_246); // 主变量
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
variable->attribute.transfer_function_code = req->data.command_47.pv_transfer_function_code;
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
// 回复数据
|
||
*resp->data_p++ = variable->attribute.transfer_function_code;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 写入主变量传感器序列号V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_49_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_device_variable_t *variable = NULL;
|
||
if (req->data_length < sizeof(hart_command_49_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
variable = get_device_variable_by_standard_code(DIN_246); // 主变量
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
osel_memcpy(variable->transducer.serial_number.bs, req->data.command_49.pv_transducer_serial_number.bs, sizeof(uint24_t));
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
osel_memcpy(resp->data_p, variable->transducer.serial_number.bs, sizeof(uint24_t));
|
||
resp->data_p += sizeof(uint24_t);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 写入设备可变阻尼值V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_55_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
float32_u tmp;
|
||
if (req->data_length < sizeof(hart_command_55_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
hart_device_variable_t *variable = NULL;
|
||
variable = get_device_variable(req->data.command_55.device_ariable);
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
tmp.f = req->data.command_55.damping_value;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
variable->attribute.damping_value = tmp.f;
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
// 回复数据
|
||
*resp->data_p++ = variable->code; // 设备变量代码
|
||
tmp.f = variable->attribute.damping_value;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u)); // 设备可变阻尼值
|
||
resp->data_p += sizeof(float32_u);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 写入设备可变传感器序列号V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_56_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length < sizeof(hart_command_56_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
hart_device_variable_t *variable = NULL;
|
||
variable = get_device_variable(req->data.command_56.device_ariable);
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
osel_memcpy(variable->transducer.serial_number.bs, req->data.command_56.serial_number.bs, sizeof(uint24_t));
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
// 回复数据
|
||
*resp->data_p++ = variable->code; // 设备变量代码
|
||
osel_memcpy(resp->data_p, variable->transducer.serial_number.bs, sizeof(uint24_t)); // 设备可变传感器序列号
|
||
resp->data_p += sizeof(uint24_t);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取单位标签、描述符、日期V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_57_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
osel_memcpy(resp->data_p, (uint8_t *)&hart_device_attribute.flash_variable.unit_device, sizeof(unit_device_t));
|
||
resp->data_p += sizeof(unit_device_t);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 编写单位标签、描述符、日期V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_58_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length < sizeof(hart_command_58_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
osel_memcpy((uint8_t *)&hart_device_attribute.flash_variable.unit_device, (uint8_t *)&req->data.command_58, sizeof(hart_command_58_t));
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&hart_device_attribute.flash_variable.unit_device, sizeof(unit_device_t));
|
||
resp->data_p += sizeof(unit_device_t);
|
||
return TRUE;
|
||
}
|
||
|
||
|
||
/**
|
||
* @brief 读取模拟通道和范围百分比V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_60_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
float32_u tmp;
|
||
analog_channel_t *analog_channel = NULL;
|
||
if (req->data_length < sizeof(hart_command_60_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
analog_channel = get_analog_channel((analog_channel_number_codes_e)req->data.command_60.analog_channel_number_code);
|
||
if (analog_channel == NULL)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
|
||
/* The above code is writing data to a response buffer. It is taking values from an analog channel
|
||
structure (code, units_code, level, percent_range) and converting them to a byte representation
|
||
using a union (tmp). The byte representation is then copied to the response buffer using memcpy. The
|
||
response buffer pointer is incremented after each write to ensure that the next write goes to the
|
||
correct location in the buffer. */
|
||
*resp->data_p++ = analog_channel->code;
|
||
*resp->data_p++ = analog_channel->units_code;
|
||
|
||
tmp.f = analog_channel->level.f;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
tmp.f = analog_channel->percent_range.f;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief读取动态变量和主变量模拟通道V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_61_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
float32_u tmp;
|
||
hart_device_variable_t *variable = NULL;
|
||
analog_channel_t *analog_channel = get_analog_channel(ANALOG_CHANNEL_NUMBER_CODES_0);
|
||
if (analog_channel == NULL)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
*resp->data_p++ = analog_channel->units_code; // 主要模拟通道单元代码
|
||
|
||
tmp.f = analog_channel->level.f;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u)); // 主要可变模拟电平
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
variable = get_device_variable_by_standard_code(DIN_246);
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
*resp->data_p++ = variable->units_code; // 主要变量单元代码
|
||
tmp.f = *variable->value;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u)); // 主要变量值
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
variable = get_device_variable_by_standard_code(DIN_247);
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
*resp->data_p++ = variable->units_code; // 次要变量单元代码
|
||
tmp.f = *variable->value;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u)); // 次要变量值
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
variable = get_device_variable_by_standard_code(DIN_248);
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
*resp->data_p++ = variable->units_code; // 第三变量单元代码
|
||
tmp.f = *variable->value;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u)); // 第三变量值
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
variable = get_device_variable_by_standard_code(DIN_249);
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
*resp->data_p++ = variable->units_code; // 第四变量单元代码
|
||
tmp.f = *variable->value;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u)); // 第四变量值
|
||
resp->data_p += sizeof(float32_u);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief读取模拟通道V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_62_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
float32_u tmp;
|
||
if (req->data_length == 0)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
analog_channel_t *analog_channel = NULL;
|
||
uint8_t *code = (uint8_t *)&req->data.command_62;
|
||
for (uint8_t i = 0; i < req->data_length; i++)
|
||
{
|
||
analog_channel = get_analog_channel((analog_channel_number_codes_e)(*(code + i)));
|
||
if (analog_channel == NULL)
|
||
{
|
||
analog_channel = get_analog_channel(ANALOG_CHANNEL_NUMBER_CODES_0);
|
||
}
|
||
*resp->data_p++ = analog_channel->code; // 模拟通道代码
|
||
*resp->data_p++ = analog_channel->units_code; // 模拟通道单元代码
|
||
|
||
tmp.f = analog_channel->level.f;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u)); // 主要可变模拟电平
|
||
resp->data_p += sizeof(float32_u);
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief读取模拟通道信息V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_63_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length == 0)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
analog_channel_t *analog_channel = NULL;
|
||
float32_u tmp;
|
||
analog_channel = get_analog_channel((analog_channel_number_codes_e)req->data.command_63.analog_channel_number_code);
|
||
if (analog_channel == NULL)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
*resp->data_p++ = analog_channel->code; // 模拟通道代码
|
||
*resp->data_p++ = analog_channel->attribute.alarm_selection_code; // 模拟通道报警选择代码
|
||
*resp->data_p++ = analog_channel->attribute.transfer_function_code; // 模拟通道单元代码
|
||
*resp->data_p++ = analog_channel->transducer.upper_and_lower_range_values_units_code; // 模拟通道上下限值单位代码
|
||
|
||
// 模拟通道上限值
|
||
osel_memcpy((uint8_t *)&tmp.f, (uint8_t *)&analog_channel->transducer.upper_limit.f, sizeof(float32));
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
// 模拟通道下限值
|
||
osel_memcpy((uint8_t *)&tmp.f, (uint8_t *)&analog_channel->transducer.lower_limit.f, sizeof(float32));
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
tmp.f = analog_channel->attribute.damping_value; // 模拟通道阻尼值
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
if (hart_get_current_protocol_version() == HART_PROTOCOL_VERSION_7)
|
||
{
|
||
*resp->data_p++ = analog_channel->attribute.analog_channel_flags; // 模拟通道标志
|
||
}
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief写入模拟通道附加阻尼值V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_64_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length < sizeof(hart_command_64_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
analog_channel_t *analog_channel = NULL;
|
||
float32_u tmp;
|
||
analog_channel = get_analog_channel((analog_channel_number_codes_e)req->data.command_64.analog_channel_number_code);
|
||
if (analog_channel == NULL)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
tmp.f = req->data.command_64.damping_value;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
analog_channel->attribute.damping_value = tmp.f;
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
// 回复数据
|
||
*resp->data_p++ = analog_channel->code; // 模拟通道代码
|
||
tmp.f = analog_channel->attribute.damping_value;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u)); // 模拟通道阻尼值
|
||
resp->data_p += sizeof(float32_u);
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief写入模拟通道范围值V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_65_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length < sizeof(hart_command_65_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
analog_channel_t *analog_channel = NULL;
|
||
float32_u tmp;
|
||
analog_channel = get_analog_channel((analog_channel_number_codes_e)req->data.command_65.analog_channel_number_code);
|
||
if (analog_channel == NULL)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
analog_channel->transducer.upper_and_lower_range_values_units_code = req->data.command_65.upper_and_lower_range_values_units_code; // 模拟通道上下限值单位代码
|
||
|
||
tmp.f = req->data.command_65.upper_range_value;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
// 模拟通道上限值
|
||
osel_memcpy((uint8_t *)&analog_channel->transducer.upper_limit.f, (uint8_t *)&tmp.f, sizeof(float32));
|
||
|
||
tmp.f = req->data.command_65.lower_range_value;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
// 模拟通道下限值
|
||
osel_memcpy((uint8_t *)&analog_channel->transducer.lower_limit.f, (uint8_t *)&tmp.f, sizeof(float32));
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
// 回复数据
|
||
*resp->data_p++ = analog_channel->code; // 模拟通道代码
|
||
*resp->data_p++ = analog_channel->transducer.upper_and_lower_range_values_units_code;
|
||
|
||
osel_memcpy((uint8_t *)&tmp.f, (uint8_t *)&analog_channel->transducer.upper_limit.f, sizeof(float32));
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u)); // 模拟通道上限值
|
||
resp->data_p += sizeof(float32_u);
|
||
|
||
osel_memcpy((uint8_t *)&tmp.f, (uint8_t *)&analog_channel->transducer.lower_limit.f, sizeof(float32));
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp, sizeof(float32_u)); // 模拟通道下限值
|
||
resp->data_p += sizeof(float32_u);
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief进入/退出固定模拟通道模式V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_66_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length < sizeof(hart_command_66_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
float32_u tmp;
|
||
analog_channel_t *analog_channel = NULL;
|
||
analog_channel = get_analog_channel((analog_channel_number_codes_e)req->data.command_66.analog_channel_number_code);
|
||
if (analog_channel == NULL)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
analog_channel->units_code = req->data.command_66.units_code; // 模拟通道单元代码
|
||
/**
|
||
* A level containing "0x7F. 0xA0. 0x00. 0x00'with any Units Code exits the Fixed Analog Channel Mode
|
||
*/
|
||
|
||
osel_memcpy((uint8_t *)&tmp.f, (uint8_t *)&req->data.command_66.fixed_analog_channel_level, sizeof(int32_t)); // 这里不能直接赋值,因为0x7F. 0xA0. 0x00. 0x00会丢字节
|
||
if (tmp.c == HART_INVALID_VALUE)
|
||
{
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy((uint8_t *)&analog_channel->fixed_analog_channel_level.c, (uint8_t *)&tmp.c, sizeof(int32_t));
|
||
LOG_PRINT("%08x", analog_channel->fixed_analog_channel_level.c);
|
||
}
|
||
else
|
||
{
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
analog_channel->fixed_analog_channel_level.f = tmp.f; // 模拟通道电平
|
||
LOG_PRINT("%f", analog_channel->fixed_analog_channel_level.f);
|
||
}
|
||
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
// 回复数据
|
||
*resp->data_p++ = analog_channel->code; // 模拟通道代码
|
||
*resp->data_p++ = analog_channel->units_code;
|
||
tmp.c = B2S_UINT32(analog_channel->fixed_analog_channel_level.c);
|
||
if (tmp.c == HART_INVALID_VALUE)
|
||
{
|
||
osel_memcpy((uint8_t *)&tmp.c, (uint8_t *)&analog_channel->fixed_analog_channel_level.c, sizeof(int32_t));
|
||
}
|
||
else
|
||
{
|
||
tmp.c = B2S_UINT32(analog_channel->fixed_analog_channel_level.c);
|
||
}
|
||
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp.c, sizeof(int32_t)); // 模拟通道电平
|
||
resp->data_p += sizeof(int32_t);
|
||
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief调整模拟通道零V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_67_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length < sizeof(hart_command_67_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
float32_u tmp;
|
||
analog_channel_t *analog_channel = NULL;
|
||
analog_channel = get_analog_channel((analog_channel_number_codes_e)req->data.command_67.analog_channel_number_code);
|
||
if (analog_channel == NULL)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
tmp.c = B2S_UINT32(analog_channel->fixed_analog_channel_level.c);
|
||
if (tmp.c != HART_INVALID_VALUE)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_9;
|
||
return TRUE;
|
||
}
|
||
|
||
analog_channel->units_code = req->data.command_67.units_code; // 模拟通道单元代码
|
||
|
||
tmp.f = req->data.command_67.actual_analog_channel_level;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
analog_channel->actual_analog_channel_level.f = tmp.f; // 模拟通道电平
|
||
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
|
||
// 回复数据
|
||
*resp->data_p++ = analog_channel->code; // 模拟通道代码
|
||
*resp->data_p++ = analog_channel->units_code;
|
||
tmp.f = analog_channel->actual_analog_channel_level.f;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp.c, sizeof(int32_t)); // 模拟通道电平
|
||
resp->data_p += sizeof(int32_t);
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief微调模拟通道增益V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_68_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length < sizeof(hart_command_68_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
float32_u tmp;
|
||
analog_channel_t *analog_channel = NULL;
|
||
analog_channel = get_analog_channel((analog_channel_number_codes_e)req->data.command_68.analog_channel_number_code);
|
||
if (analog_channel == NULL)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
tmp.c = B2S_UINT32(analog_channel->fixed_analog_channel_level.c);
|
||
if (tmp.c != HART_INVALID_VALUE)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_9;
|
||
return TRUE;
|
||
}
|
||
|
||
analog_channel->units_code = req->data.command_68.units_code; // 模拟通道单元代码
|
||
|
||
tmp.f = req->data.command_68.externally_measured_analog_channel_level;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
analog_channel->externally_measured_analog_channel_level.f = tmp.f; // 模拟通道电平
|
||
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
|
||
// 回复数据
|
||
*resp->data_p++ = analog_channel->code; // 模拟通道代码
|
||
*resp->data_p++ = analog_channel->units_code;
|
||
tmp.f = analog_channel->externally_measured_analog_channel_level.f;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp.c, sizeof(int32_t)); // 模拟通道电平
|
||
resp->data_p += sizeof(int32_t);
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief写入模拟通道传递函数V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_69_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length < sizeof(hart_command_69_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
analog_channel_t *analog_channel = NULL;
|
||
analog_channel = get_analog_channel((analog_channel_number_codes_e)req->data.command_69.analog_channel_number_code);
|
||
if (analog_channel == NULL)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
analog_channel->attribute.transfer_function_code = req->data.command_69.transfer_function_code;
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
// 回复数据
|
||
*resp->data_p++ = analog_channel->code; // 模拟通道代码
|
||
*resp->data_p++ = analog_channel->attribute.transfer_function_code;
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief读取模拟通道端点值V5
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_70_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length < sizeof(hart_command_70_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
float32_u tmp;
|
||
analog_channel_t *analog_channel = NULL;
|
||
analog_channel = get_analog_channel((analog_channel_number_codes_e)req->data.command_70.analog_channel_number_code);
|
||
if (analog_channel == NULL)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
// 回复数据
|
||
*resp->data_p++ = analog_channel->code; // 模拟通道代码
|
||
*resp->data_p++ = analog_channel->transducer.upper_and_lower_range_values_units_code; // 模拟通道上下限值单位代码
|
||
|
||
tmp.f = analog_channel->externally_measured_analog_channel_level.f;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp.c, sizeof(int32_t)); // 模拟通道上端点值
|
||
resp->data_p += sizeof(int32_t);
|
||
|
||
tmp.f = analog_channel->actual_analog_channel_level.f;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp.c, sizeof(int32_t)); // 模拟通道下端点值
|
||
resp->data_p += sizeof(int32_t);
|
||
|
||
if (hart_get_current_protocol_version() == HART_PROTOCOL_VERSION_7)
|
||
{
|
||
// 模拟通道上限值
|
||
osel_memcpy((uint8_t *)&tmp.f, (uint8_t *)&analog_channel->transducer.upper_limit.f, sizeof(float32));
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp.c, sizeof(int32_t));
|
||
resp->data_p += sizeof(int32_t);
|
||
|
||
// 模拟通道下限值
|
||
osel_memcpy((uint8_t *)&tmp.f, (uint8_t *)&analog_channel->transducer.lower_limit.f, sizeof(float32));
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp.c, sizeof(int32_t));
|
||
resp->data_p += sizeof(int32_t);
|
||
}
|
||
return TRUE;
|
||
}
|
||
|
||
|
||
/**
|
||
* @brief 锁定装置
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_71_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length < sizeof(hart_command_71_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
uint8_t lock_code = hart_device_attribute.flash_variable.lock_code;
|
||
if (req->data.command_71.lock_code == LOCK_DEVICE_CODE_0)
|
||
{
|
||
if (lock_code != LOCK_DEVICE_CODE_0) // 判断当前锁定状态
|
||
{
|
||
if (req->master == 0)
|
||
{
|
||
if (lock_code != LOCK_DEVICE_CODE_3)
|
||
{
|
||
// 第二主机 不能解锁
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_10; // 不能解锁
|
||
return TRUE;
|
||
}
|
||
}
|
||
}
|
||
hart_device_attribute.flash_variable.lock_code = req->data.command_71.lock_code;
|
||
}
|
||
else
|
||
{
|
||
if (req->master == 0 && req->data.command_71.lock_code != LOCK_DEVICE_CODE_3)
|
||
{
|
||
// 第二主机 不能锁定
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_11;
|
||
return TRUE;
|
||
}
|
||
|
||
hart_device_attribute.flash_variable.lock_code = req->data.command_71.lock_code;
|
||
}
|
||
|
||
// 更改锁定代码不会影响配置更改计数器或配置更改位
|
||
// 回复数据
|
||
*resp->data_p++ = hart_device_attribute.flash_variable.lock_code;
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 呼叫
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_72_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
uint8_t squawk_control_code = 0;
|
||
if (req->data_length < sizeof(hart_command_72_t))
|
||
{
|
||
squawk_control_code = SQUAWK_CONTROL_CODE_2;
|
||
}
|
||
else
|
||
{
|
||
squawk_control_code = req->data.command_72.squawk_control_code;
|
||
}
|
||
|
||
if (squawk_control_code == SQUAWK_CONTROL_CODE_0)
|
||
{
|
||
squawk_control(FALSE, 0);
|
||
}
|
||
else
|
||
{
|
||
if (squawk_control_code == SQUAWK_CONTROL_CODE_2)
|
||
{
|
||
squawk_control(TRUE, HART_SQUAWK_CONTROL_ONCE_TIME);
|
||
}
|
||
else if (squawk_control_code == SQUAWK_CONTROL_CODE_1)
|
||
{
|
||
squawk_control(TRUE, 0);
|
||
}
|
||
else
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_9;
|
||
return TRUE;
|
||
}
|
||
}
|
||
// 回复数据
|
||
*resp->data_p++ = squawk_control_code;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 查找设备
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_73_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (TRUE == armed())
|
||
{
|
||
command_0_req(resp);
|
||
}
|
||
else
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_38;
|
||
return TRUE;
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取I/O系统功能
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_74_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 轮询子设备
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_75_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读锁定设备状态
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_76_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
*resp->data_p++ = hart_device_attribute.flash_variable.lock_code;
|
||
return TRUE;
|
||
}
|
||
|
||
|
||
/**
|
||
* @brief 写入设备变量
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_79_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_device_variable_t *hart_device_variable_p = NULL;
|
||
float32_u tmp;
|
||
if (req->data_length < sizeof(hart_command_79_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
hart_device_variable_p = get_device_variable(req->data.command_79.device_ariable);
|
||
if (hart_device_variable_p->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_11; // 无效的设备变量代码
|
||
return TRUE;
|
||
}
|
||
hart_device_variable_p->write_device_variable_command_code = req->data.command_79.device_ariable_command_code;
|
||
hart_device_variable_p->units_code = req->data.command_79.device_ariable_unit_code;
|
||
tmp.f = req->data.command_79.device_ariable_value;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy((uint8_t *)hart_device_variable_p->value, (uint8_t *)&tmp.f, sizeof(float32));
|
||
hart_device_variable_p->status.data = req->data.command_79.status;
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
|
||
// 回复数据
|
||
*resp->data_p++ = hart_device_variable_p->code;
|
||
*resp->data_p++ = hart_device_variable_p->write_device_variable_command_code;
|
||
*resp->data_p++ = hart_device_variable_p->units_code;
|
||
osel_memcpy((uint8_t *)&tmp.f, (uint8_t *)hart_device_variable_p->value, sizeof(float32));
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp.c, sizeof(int32_t));
|
||
resp->data_p += sizeof(int32_t);
|
||
*resp->data_p++ = hart_device_variable_p->status.data;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取设备可变微调点
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_80_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_device_variable_t *hart_device_variable_p = NULL;
|
||
float32_u tmp;
|
||
if (req->data_length < sizeof(hart_command_80_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
hart_device_variable_p = get_device_variable(req->data.command_80.device_ariable);
|
||
if (hart_device_variable_p->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_11; // 无效的设备变量代码
|
||
return TRUE;
|
||
}
|
||
// 回复数据
|
||
*resp->data_p++ = hart_device_variable_p->code;
|
||
*resp->data_p++ = hart_device_variable_p->trim_point.units_code;
|
||
|
||
tmp.f = hart_device_variable_p->trim_point.lower;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp.c, sizeof(int32_t));
|
||
resp->data_p += sizeof(int32_t);
|
||
|
||
tmp.f = hart_device_variable_p->trim_point.upper;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp.c, sizeof(int32_t));
|
||
resp->data_p += sizeof(int32_t);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取设备变量调整指南
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_81_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
float32_u tmp;
|
||
hart_device_variable_t *variable = NULL;
|
||
variable = get_device_variable(req->data.command_81.device_ariable);
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
|
||
// 回复数据
|
||
*resp->data_p++ = variable->code;
|
||
*resp->data_p++ = variable->trim_point.trim_points;
|
||
*resp->data_p++ = variable->trim_point.units_code;
|
||
|
||
tmp.f = variable->trim_point.mini_lower;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp.c, sizeof(int32_t));
|
||
resp->data_p += sizeof(int32_t);
|
||
|
||
tmp.f = variable->trim_point.max_lower;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp.c, sizeof(int32_t));
|
||
resp->data_p += sizeof(int32_t);
|
||
|
||
tmp.f = variable->trim_point.mini_upper;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp.c, sizeof(int32_t));
|
||
resp->data_p += sizeof(int32_t);
|
||
|
||
tmp.f = variable->trim_point.max_upper;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp.c, sizeof(int32_t));
|
||
resp->data_p += sizeof(int32_t);
|
||
|
||
tmp.f = variable->trim_point.mini_differential;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp.c, sizeof(int32_t));
|
||
resp->data_p += sizeof(int32_t);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 写入设备可变微调点
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_82_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
float32_u tmp;
|
||
hart_device_variable_t *variable = NULL;
|
||
if (req->data_length < sizeof(hart_command_82_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
variable = get_device_variable(req->data.command_82.device_ariable);
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
variable->trim_point.trim_points = req->data.command_82.trim_points;
|
||
variable->trim_point.units_code = req->data.command_82.units_code;
|
||
tmp.f = req->data.command_82.value;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
variable->trim_point.value = tmp.f;
|
||
|
||
// 回复数据
|
||
*resp->data_p++ = variable->code;
|
||
*resp->data_p++ = variable->trim_point.trim_points;
|
||
*resp->data_p++ = variable->trim_point.units_code;
|
||
tmp.f = variable->trim_point.value;
|
||
tmp.c = B2S_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp.c, sizeof(int32_t));
|
||
resp->data_p += sizeof(int32_t);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 重置设备变量调整
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_83_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
hart_device_variable_t *variable = NULL;
|
||
trim_point_t *ptr;
|
||
if (req->data_length < sizeof(hart_command_83_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
variable = get_device_variable(req->data.command_83.device_ariable);
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
ptr = &variable->trim_point;
|
||
osel_memset((uint8_t *)ptr, 0, sizeof(trim_point_t));
|
||
|
||
// 回复数据
|
||
*resp->data_p++ = variable->code;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取子设备标识摘要
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_84_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取I/O通道统计信息
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_85_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取子设备统计信息
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_86_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 写入I/O系统主模式
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_87_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 写入I/O系统重试计数
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_88_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
return TRUE;
|
||
}
|
||
|
||
|
||
/**
|
||
* @brief 设置实时时钟
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_89_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
uint32_t time;
|
||
uint8_t year, month, day, hour, min, sec;
|
||
real_time_clock_t *pd = &hart_device_attribute.real_time_clock;
|
||
if (req->data_length < sizeof(hart_command_89_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
if (req->data.command_89.time_set_code >= TIME_SETTING_CODE_MAX)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
|
||
pd->time_set_code = req->data.command_89.time_set_code;
|
||
osel_memcpy(pd->date, req->data.command_89.date, HART_DATE_LEN);
|
||
time = B2S_UINT32(req->data.command_89.time);
|
||
pd->time = time;
|
||
pd->transmission_time = req->data.command_89.transmission_time;
|
||
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
|
||
year = pd->date[2];
|
||
covert_year_rtc(&year);
|
||
year = dec_format_hex(year);
|
||
month = dec_format_hex(pd->date[1]);
|
||
day = dec_format_hex(pd->date[0]);
|
||
|
||
convert_time(time, &hour, &min, &sec);
|
||
hart_set_real_time_clock(year, month, day, hour, min, sec);
|
||
pd->rtc_flags = REAL_TIME_CLOCK_FLAGS_1;
|
||
|
||
// LOG_PRINT("%d,%d,%d", hour, min, sec);
|
||
// 回复数据
|
||
|
||
*resp->data_p++ = pd->time_set_code;
|
||
osel_memcpy(resp->data_p, pd->date, HART_DATE_LEN);
|
||
resp->data_p += HART_DATE_LEN;
|
||
time = pd->time;
|
||
time = S2B_UINT32(time);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&time, sizeof(uint32_t));
|
||
resp->data_p += sizeof(uint32_t);
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取实时时钟
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_90_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
real_time_clock_t *pd = &hart_device_attribute.real_time_clock;
|
||
uint8_t year, month, day, hour, min, sec;
|
||
uint32_t time;
|
||
hart_get_real_time_clock(&year, &month, &day, &hour, &min, &sec);
|
||
convert_timestrap(&time, hour, min, sec, 0);
|
||
time = hart_get_timestamp();
|
||
// 当前日期
|
||
*resp->data_p++ = day;
|
||
*resp->data_p++ = month;
|
||
*resp->data_p++ = year > 0 ? (year + 100) : 0;
|
||
// 当前时间
|
||
time = S2B_UINT32(time);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&time, sizeof(uint32_t));
|
||
resp->data_p += sizeof(uint32_t);
|
||
|
||
// 上一次设置的日期
|
||
osel_memcpy(resp->data_p, pd->date, HART_DATE_LEN);
|
||
resp->data_p += HART_DATE_LEN;
|
||
// 上一次设置的时间
|
||
time = pd->time;
|
||
time = S2B_UINT32(time);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&time, sizeof(uint32_t));
|
||
resp->data_p += sizeof(uint32_t);
|
||
// RTC标志
|
||
*resp->data_p++ = pd->rtc_flags;
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取趋势配置
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_91_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
uint32_t time = 0;
|
||
if (req->data_length < sizeof(hart_command_91_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
if (req->data.command_91.trend_number > TREND_CONFIGURATIONS_LEN)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_11;
|
||
return TRUE;
|
||
}
|
||
|
||
trend_configuration_t *cnf = &hart_device_attribute.flash_variable.trend_configurations[req->data.command_91.trend_number];
|
||
// 回复数据
|
||
*resp->data_p++ = req->data.command_91.trend_number;
|
||
*resp->data_p++ = TREND_CONFIGURATIONS_LEN;
|
||
*resp->data_p++ = cnf->trend_code;
|
||
*resp->data_p++ = cnf->device_variable_code;
|
||
time = cnf->trend_sample_interval;
|
||
time = B2S_UINT32(time);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&time, sizeof(uint32_t));
|
||
resp->data_p += sizeof(uint32_t);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 写入趋势配置
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_92_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
uint32_t time = 0;
|
||
if (req->data_length < sizeof(hart_command_92_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
if (req->data.command_92.trend_code >= TREND_CONTROL_CODE_MAX)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
return TRUE;
|
||
}
|
||
if (req->data.command_92.trend_number > TREND_CONFIGURATIONS_LEN)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_11;
|
||
return TRUE;
|
||
}
|
||
time = S2B_UINT32(req->data.command_92.trend_sample_interval);
|
||
if (time > 2 * 3600 * 1000)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_3;
|
||
return TRUE;
|
||
}
|
||
|
||
trend_configuration_t *cnf = &hart_device_attribute.flash_variable.trend_configurations[req->data.command_92.trend_number];
|
||
cnf->trend_code = req->data.command_92.trend_code;
|
||
cnf->device_variable_code = req->data.command_92.device_variable_code;
|
||
cnf->trend_sample_interval = time;
|
||
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
|
||
// 回复数据
|
||
*resp->data_p++ = req->data.command_92.trend_number;
|
||
*resp->data_p++ = cnf->trend_code;
|
||
*resp->data_p++ = cnf->device_variable_code;
|
||
time = cnf->trend_sample_interval;
|
||
time = B2S_UINT32(time);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&time, sizeof(uint32_t));
|
||
resp->data_p += sizeof(uint32_t);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取趋势
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_93_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
uint32_t time = 0;
|
||
trend_value_t *value = NULL;
|
||
float32_u tmp;
|
||
if (req->data_length < sizeof(hart_command_93_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
if (req->data.command_93.trend_number > TREND_CONFIGURATIONS_LEN)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_11;
|
||
return TRUE;
|
||
}
|
||
trend_configuration_t *cnf = &hart_device_attribute.flash_variable.trend_configurations[req->data.command_93.trend_number];
|
||
// 回复数据
|
||
// 趋势编号
|
||
*resp->data_p++ = req->data.command_93.trend_number;
|
||
// 设备变量代码
|
||
*resp->data_p++ = cnf->device_variable_code;
|
||
// 设备变量分类
|
||
*resp->data_p++ = cnf->device_variable_classification;
|
||
// 设备变量单位代码
|
||
*resp->data_p++ = cnf->device_variable_unit_code;
|
||
// 趋势值的日期戳
|
||
osel_memcpy(resp->data_p, cnf->trend_value_date, HART_DATE_LEN);
|
||
resp->data_p += HART_DATE_LEN;
|
||
// 趋势值的时间戳
|
||
time = cnf->trend_value_time;
|
||
time = S2B_UINT32(time);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&time, sizeof(uint32_t));
|
||
resp->data_p += sizeof(uint32_t);
|
||
// 采样间隔
|
||
time = cnf->trend_sample_interval;
|
||
time = S2B_UINT32(time);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&time, sizeof(uint32_t));
|
||
resp->data_p += sizeof(uint32_t);
|
||
|
||
// 趋势值
|
||
if (cnf->trend_code == TREND_CONTROL_CODE_0)
|
||
{
|
||
// 当趋势未启用时,设备应返回最后收集的数据与相应的日期和时间,响应代码应设置为趋势不活跃
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_8;
|
||
}
|
||
else
|
||
{
|
||
for (uint8_t i = 0; i < TREND_VALUES_LEN; i++)
|
||
{
|
||
value = &cnf->trend_values[i];
|
||
tmp.f = value->value;
|
||
tmp.c = S2B_UINT32(tmp.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&tmp.c, sizeof(int32_t));
|
||
resp->data_p += sizeof(int32_t);
|
||
*resp->data_p++ = value->status.data;
|
||
}
|
||
}
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取I/O系统客户端通信统计信息
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_94_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取设备通信统计信息
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_95_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
*resp->data_p++ = HI_UINT16(hart_device_attribute.message_count.stx);
|
||
*resp->data_p++ = LO_UINT16(hart_device_attribute.message_count.stx);
|
||
*resp->data_p++ = HI_UINT16(hart_device_attribute.message_count.ack);
|
||
*resp->data_p++ = LO_UINT16(hart_device_attribute.message_count.ack);
|
||
*resp->data_p++ = HI_UINT16(hart_device_attribute.message_count.back);
|
||
*resp->data_p++ = LO_UINT16(hart_device_attribute.message_count.back);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取同步操作
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_96_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
uint32_t time = 0;
|
||
if (req->data_length < sizeof(hart_command_96_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
if (req->data.command_96.action_number > SYNCHRONIZATION_OPERATION_LEN)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_11;
|
||
return TRUE;
|
||
}
|
||
synchronization_operation_t *tmp = &hart_device_attribute.flash_variable.synchronization_operations[req->data.command_96.action_number];
|
||
// 回复数据
|
||
*resp->data_p++ = req->data.command_96.action_number; // 同步操作编号
|
||
*resp->data_p++ = SYNCHRONIZATION_OPERATION_LEN; // 同步操作总数
|
||
|
||
*resp->data_p++ = tmp->action_control_code; // 同步操作控制代码
|
||
if (tmp->action_control_code == 0)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_2;
|
||
// 未使用的
|
||
*resp->data_p++ = DIN_251; // 同步操作设备变量代码
|
||
*resp->data_p++ = 0xff; // 同步操作命令编号
|
||
*resp->data_p++ = 0xff;
|
||
}
|
||
else
|
||
{
|
||
*resp->data_p++ = tmp->device_variable_code; // 同步操作设备变量代码
|
||
*resp->data_p++ = HI_UINT16(tmp->command_number); // 同步操作命令编号
|
||
*resp->data_p++ = LO_UINT16(tmp->command_number);
|
||
}
|
||
|
||
osel_memcpy(resp->data_p, tmp->trigger_date, HART_DATE_LEN); // 同步操作日期
|
||
resp->data_p += HART_DATE_LEN;
|
||
time = tmp->trigger_time; // 同步操作时间
|
||
time = S2B_UINT32(time);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&time, sizeof(uint32_t));
|
||
resp->data_p += sizeof(uint32_t);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 配置同步操作
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_97_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
uint32_t time = 0;
|
||
/**
|
||
* 0 Success No Command-Specific Errors
|
||
1 Undefined
|
||
2 Error Invalid Selection
|
||
3-4 Undefined
|
||
5 Error Too Few Data Bytes Received
|
||
6 Error Device-Specific Command Error
|
||
7 Error In Write Protect Mode
|
||
8 Warning Sampling Time Adjusted
|
||
9 Error Bad Trigger Action
|
||
10 Error Invalid Date
|
||
11 Error Invalid Time
|
||
12 Error Invalid Device Variable
|
||
13 Error Command Number Not Supported
|
||
14-15 Undefined
|
||
*/
|
||
if (req->data_length < sizeof(hart_command_97_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
if (req->data.command_97.action_number > SYNCHRONIZATION_OPERATION_LEN)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_9;
|
||
return TRUE;
|
||
}
|
||
synchronization_operation_t *tmp = &hart_device_attribute.flash_variable.synchronization_operations[req->data.command_97.action_number];
|
||
tmp->action_control_code = req->data.command_97.action_control_code; // 同步操作控制代码
|
||
|
||
// 设备变量代码。如果动作执行命令,设备变量代码必须设置为251。“NONE”。
|
||
if (tmp->action_control_code == SYNCHRONIZATION_OPERATION_CONTROL_CODE_1)
|
||
{
|
||
tmp->device_variable_code = req->data.command_97.device_variable_code; // 同步操作设备变量代码
|
||
}
|
||
else
|
||
{
|
||
tmp->device_variable_code = DIN_251;
|
||
}
|
||
|
||
// 命令编号。如果操作是对设备变量进行采样,则命令编号必须设置为0xFFFF。
|
||
if (tmp->action_control_code == SYNCHRONIZATION_OPERATION_CONTROL_CODE_1)
|
||
{
|
||
tmp->command_number = 0xffff;
|
||
}
|
||
else
|
||
{
|
||
|
||
tmp->command_number = S2B_UINT16(req->data.command_97.command_number); // 同步操作命令编号
|
||
}
|
||
|
||
osel_memcpy(tmp->trigger_date, req->data.command_97.trigger_date, HART_DATE_LEN);
|
||
time = S2B_UINT32(req->data.command_97.trigger_time); // 同步操作时间
|
||
tmp->trigger_time = time;
|
||
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
|
||
// 回复数据
|
||
*resp->data_p++ = req->data.command_97.action_number; // 同步操作编号
|
||
*resp->data_p++ = tmp->action_control_code; // 同步操作控制代码
|
||
*resp->data_p++ = tmp->device_variable_code; // 同步操作设备变量代码
|
||
*resp->data_p++ = HI_UINT16(tmp->command_number); // 同步操作命令编号
|
||
*resp->data_p++ = LO_UINT16(tmp->command_number);
|
||
osel_memcpy(resp->data_p, tmp->trigger_date, HART_DATE_LEN); // 同步操作日期
|
||
resp->data_p += HART_DATE_LEN;
|
||
time = tmp->trigger_time; // 同步操作时间
|
||
time = S2B_UINT32(time);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&time, sizeof(uint32_t));
|
||
resp->data_p += sizeof(uint32_t);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取命令操作
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_98_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length < sizeof(hart_command_98_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
if (req->data.command_98.action_number > SYNCHRONIZATION_OPERATION_LEN)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_11;
|
||
return TRUE;
|
||
}
|
||
synchronization_operation_t *tmp = &hart_device_attribute.flash_variable.synchronization_operations[req->data.command_98.action_number];
|
||
// 回复数据
|
||
*resp->data_p++ = req->data.command_98.action_number; // 同步操作编号
|
||
*resp->data_p++ = HI_UINT16(tmp->command_number); // 同步操作命令编号
|
||
*resp->data_p++ = LO_UINT16(tmp->command_number);
|
||
*resp->data_p++ = tmp->command_data_length; // 字节计数
|
||
osel_memcpy(resp->data_p, tmp->command_data, tmp->command_data_length); // 命令数据
|
||
resp->data_p += tmp->command_data_length;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 配置命令操作
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_99_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length < (4 + req->data.command_99.command_data_length))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
if (req->data.command_99.action_number > SYNCHRONIZATION_OPERATION_LEN)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_11;
|
||
return TRUE;
|
||
}
|
||
if (req->data.command_99.command_data_length > SYNCHRONIZATION_OPERATION_COMMAND_DATA_LEN)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_10;
|
||
return TRUE;
|
||
}
|
||
|
||
synchronization_operation_t *tmp = &hart_device_attribute.flash_variable.synchronization_operations[req->data.command_99.action_number];
|
||
tmp->command_number = req->data.command_99.command_number;
|
||
tmp->command_data_length = req->data.command_99.command_data_length;
|
||
osel_memcpy(tmp->command_data, req->data.command_99.command_data, tmp->command_data_length);
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
|
||
// 回复数据
|
||
*resp->data_p++ = req->data.command_99.action_number; // 同步操作编号
|
||
*resp->data_p++ = HI_UINT16(tmp->command_number); // 同步操作命令编号
|
||
*resp->data_p++ = LO_UINT16(tmp->command_number);
|
||
*resp->data_p++ = tmp->command_data_length; // 字节计数
|
||
osel_memcpy(resp->data_p, tmp->command_data, tmp->command_data_length); // 命令数据
|
||
resp->data_p += tmp->command_data_length;
|
||
return TRUE;
|
||
}
|
||
|
||
|
||
/**
|
||
* @brief 写入主变量报警码
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_100_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length < sizeof(hart_command_100_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
hart_device_variable_t *variable = NULL;
|
||
variable = get_device_variable_by_standard_code(DIN_246);
|
||
if (variable->code == DIN_250)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_6;
|
||
return TRUE;
|
||
}
|
||
variable->alarm_code = req->data.command_100.pv_alarm_selection_code;
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
// 回复数据
|
||
*resp->data_p++ = variable->alarm_code;
|
||
return TRUE;
|
||
}
|
||
|
||
|
||
/**
|
||
* @brief 读取子设备到突发消息映射
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_101_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief 将子设备映射到突发信息
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_102_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 读取突发模式配置
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_105_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
uint32_t time;
|
||
float32_u f;
|
||
hart_device_variable_t *solt;
|
||
if (req->data.command_105.burst_message > BURST_MESSAGE_LEN)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_9;
|
||
return TRUE;
|
||
}
|
||
burst_message_t *tmp = &hart_device_attribute.flash_variable.burst_messages[req->data.command_105.burst_message];
|
||
|
||
*resp->data_p++ = tmp->burst_mode_control_code; // 突发模式控制代码
|
||
*resp->data_p++ = tmp->command_number_expansion_flag; // 命令编号扩展标志
|
||
for (uint8_t i = 0; i < HART_DEVICE_VARIABLE_LEN; i++)
|
||
{
|
||
solt = &hart_device_attribute.device_variable[i];
|
||
*resp->data_p++ = solt->code; // 设备变量代码
|
||
}
|
||
*resp->data_p++ = req->data.command_105.burst_message; // 突发消息编号
|
||
*resp->data_p++ = BURST_MESSAGE_LEN; // 设备支持的最大突发消息数
|
||
*resp->data_p++ = HI_UINT16(tmp->extended_command_number); // 扩展命令编号
|
||
*resp->data_p++ = LO_UINT16(tmp->extended_command_number); // 扩展命令编号
|
||
time = S2B_UINT32(tmp->update_period_time); // 更新周期时间
|
||
osel_memcpy(resp->data_p, (uint8_t *)&time, sizeof(uint32_t));
|
||
resp->data_p += sizeof(uint32_t);
|
||
time = S2B_UINT32(tmp->max_update_period_time); // 最大更新周期时间
|
||
osel_memcpy(resp->data_p, (uint8_t *)&time, sizeof(uint32_t));
|
||
resp->data_p += sizeof(uint32_t);
|
||
*resp->data_p++ = tmp->burst_message_trigger_code; // 突发触发器代码
|
||
*resp->data_p++ = tmp->device_variable_vlassification_for_trigger_level; // 触发器级别的设备变量分类
|
||
*resp->data_p++ = tmp->units_code; // 突发触发器单位代码
|
||
f.f = tmp->trigger_level; // 触发电平
|
||
f.c = S2B_UINT32(f.c);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&f, sizeof(float32_u));
|
||
resp->data_p += sizeof(float32_u);
|
||
return TRUE;
|
||
}
|
||
|
||
|
||
|
||
/**
|
||
* @brief注册事件管理器
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_514_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
if (req->data_length < sizeof(hart_command_514_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
if (req->data.command_514.event_manager_registration_control_code == EVENT_MANAGER_REGISTRATION_CONTROL_CODE_0 &&
|
||
hart_device_attribute.flash_variable.event_manager_registration_control_code == EVENT_MANAGER_REGISTRATION_CONTROL_CODE_0)
|
||
{
|
||
// Access Restricted (e.g., an Event Manager is already registered)
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
return TRUE;
|
||
}
|
||
hart_device_attribute.flash_variable.event_manager_registration_control_code = req->data.command_514.event_manager_registration_control_code;
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
// 回复数据
|
||
*resp->data_p++ = hart_device_attribute.flash_variable.event_manager_registration_control_code;
|
||
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief读取事件管理器注册状态
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_515_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
// 回复数据
|
||
*resp->data_p++ = hart_device_attribute.flash_variable.event_manager_registration_control_code;
|
||
return TRUE;
|
||
}
|
||
|
||
|
||
/**
|
||
* @brief读取进程单元标签
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_520_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief写入进程单元标记
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_521_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief写入进程单元标记
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_522_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief重置精简状态图
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_525_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief写入状态模拟模式
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_526_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief模拟状态位
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_527_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief读取子设备分配列表信息
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_528_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief读取子设备分配
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_529_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief写入子设备分配
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_530_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief将实时列表传输到分配列表
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_531_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief读取客户端订阅摘要
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_532_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief写入客户端订阅标志
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_533_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
|
||
|
||
/**
|
||
* @brief 读取设备变量命令代码
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_534_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief写入模拟通道端点值
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_535_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief写入应用时间操作
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_536_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief读取应用时间操作
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_537_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief读取HART-IP服务器端口
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_538_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief写入HART-IP UDP端口
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_539_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief写入HART-IP TCP端口
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_540_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief写入客户端PAKE密码
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_541_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief写入客户端预共享密钥
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_542_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief读取系统日志服务器主机名和端口
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_543_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief写入系统日志端口
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_544_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief写入系统日志服务器主机名
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_545_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief写入系统日志服务器预共享密钥
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_546_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
/**
|
||
* @brief写入系统日志服务器PAKE密码
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_547_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
return TRUE;
|
||
}
|
||
#endif
|
||
|
||
// /**
|
||
// * @brief 向子设备发送命令
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_77_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
// return TRUE;
|
||
// }
|
||
|
||
// /**
|
||
// * @brief 读取聚合命令
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_78_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
// return TRUE;
|
||
// }
|
||
|
||
/**
|
||
* @brief 写入突发周期
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_103_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
uint32_t time1, time2;
|
||
if (req->data_length < sizeof(hart_command_103_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
if (req->data.command_103.burst_message > BURST_MESSAGE_LEN)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_9;
|
||
return TRUE;
|
||
}
|
||
burst_message_t *tmp = &hart_device_attribute.flash_variable.burst_messages[req->data.command_103.burst_message];
|
||
|
||
// 校验更新时间
|
||
time1 = B2S_UINT32(req->data.command_103.update_period_time);
|
||
time1 = time1 / 32;
|
||
if (time1 > BURST_MESSAGE_UPDATE_TIME_MAX * 1000)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_9;
|
||
return TRUE;
|
||
}
|
||
time2 = B2S_UINT32(req->data.command_103.max_update_period_time);
|
||
time2 = time2 / 32;
|
||
if (time2 > BURST_MESSAGE_UPDATE_TIME_MAX * 1000)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_9;
|
||
return TRUE;
|
||
}
|
||
|
||
tmp->update_period_time = time1;
|
||
tmp->max_update_period_time = time2;
|
||
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
|
||
// 回复数据
|
||
*resp->data_p++ = req->data.command_103.burst_message; // 突发消息编号
|
||
time1 = S2B_UINT32(tmp->update_period_time * 32);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&time1, sizeof(uint32_t)); // 更新周期时间
|
||
resp->data_p += sizeof(uint32_t);
|
||
time2 = S2B_UINT32(tmp->max_update_period_time * 32);
|
||
osel_memcpy(resp->data_p, (uint8_t *)&time2, sizeof(uint32_t)); // 最大更新周期时间
|
||
resp->data_p += sizeof(uint32_t);
|
||
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 写入突发触发器
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_104_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
float32_u f;
|
||
if (req->data_length < sizeof(hart_command_104_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
if (req->data.command_104.burst_message > BURST_MESSAGE_LEN)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_9;
|
||
return TRUE;
|
||
}
|
||
f.f = req->data.command_104.trigger_level;
|
||
f.c = B2S_UINT32(f.c);
|
||
burst_message_t *tmp = &hart_device_attribute.flash_variable.burst_messages[req->data.command_104.burst_message];
|
||
tmp->burst_message_trigger_code = req->data.command_104.burst_message_trigger_code; // 突发触发器代码
|
||
tmp->device_variable_vlassification_for_trigger_level = req->data.command_104.device_variable_vlassification_for_trigger_level; // 触发器级别的设备变量分类
|
||
tmp->units_code = req->data.command_104.units_code; // 突发触发器单位代码
|
||
tmp->trigger_level = f.f; // 触发电平
|
||
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
|
||
// 回复数据
|
||
f.f = tmp->trigger_level;
|
||
f.c = S2B_UINT32(f.c);
|
||
*resp->data_p++ = req->data.command_104.burst_message; // 突发消息编号
|
||
*resp->data_p++ = tmp->burst_message_trigger_code; // 突发触发器代码
|
||
*resp->data_p++ = tmp->device_variable_vlassification_for_trigger_level; // 触发器级别的设备变量分类
|
||
*resp->data_p++ = tmp->units_code; // 突发触发器单位代码
|
||
osel_memcpy(resp->data_p, (uint8_t *)&f, sizeof(float32_u)); // 触发电平
|
||
resp->data_p += sizeof(float32_u);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 写入突发设备变量
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_107_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
burst_message_t *solt;
|
||
uint8_t count = HART_PACKED8_LEN;
|
||
if (req->data_length < sizeof(hart_command_107_t))
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
return TRUE;
|
||
}
|
||
|
||
if (*hart_device_attribute.hart_protocol_version == HART_PROTOCOL_VERSION_7)
|
||
{
|
||
if (req->data_length != 9)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
return TRUE;
|
||
}
|
||
}
|
||
else if (*hart_device_attribute.hart_protocol_version == HART_PROTOCOL_VERSION_5)
|
||
{
|
||
if (req->data_length != 5)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
return TRUE;
|
||
}
|
||
count = HART_PACKED8_LEN >> 1; // 5版本只有4个设备变量
|
||
}
|
||
|
||
// 分配给插槽设备变量代码
|
||
for (uint8_t i = 0; i < count; i++)
|
||
{
|
||
solt = &hart_device_attribute.flash_variable.burst_messages[i];
|
||
solt->code = req->data.command_107.solt_device_variable_codes[i];
|
||
}
|
||
|
||
// 回复数据
|
||
for (uint8_t i = 0; i < count; i++)
|
||
{
|
||
solt = &hart_device_attribute.flash_variable.burst_messages[i];
|
||
*resp->data_p++ = solt->code;
|
||
}
|
||
*resp->data_p++ = req->data.command_107.burst_message; // 突发消息编号
|
||
|
||
hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
return TRUE;
|
||
}
|
||
|
||
/**
|
||
* @brief 写入突发模式命令编号
|
||
* @param {hart_command_req_t} *req
|
||
* @param {hart_response_t} *resp
|
||
* @return {*}
|
||
*/
|
||
static BOOL hart_slave_command_108_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
{
|
||
resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
return TRUE;
|
||
}
|
||
|
||
// /**
|
||
// * @brief 刷新延迟响应
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_106_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
// return TRUE;
|
||
// }
|
||
|
||
// /**
|
||
// * @brief 读取所有动态变量V5 (新设计不建议使用此命令)
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_110_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// hart_device_variable_t *dv;
|
||
// float32_u f;
|
||
|
||
// dv = get_device_variable_by_standard_code(DIN_246); // 主变量
|
||
// *resp->data_p++ = dv->code;
|
||
// f.f = *dv->value;
|
||
// f.c = S2B_UINT32(f.c);
|
||
// osel_memcpy(resp->data_p, (uint8_t *)&f, sizeof(float32_u));
|
||
// resp->data_p += sizeof(float32_u);
|
||
|
||
// dv = get_device_variable_by_standard_code(DIN_247); // 第二变量
|
||
// *resp->data_p++ = dv->code;
|
||
// f.f = *dv->value;
|
||
// f.c = S2B_UINT32(f.c);
|
||
// osel_memcpy(resp->data_p, (uint8_t *)&f, sizeof(float32_u));
|
||
// resp->data_p += sizeof(float32_u);
|
||
|
||
// dv = get_device_variable_by_standard_code(DIN_248); // 第三变量
|
||
// *resp->data_p++ = dv->code;
|
||
// f.f = *dv->value;
|
||
// f.c = S2B_UINT32(f.c);
|
||
// osel_memcpy(resp->data_p, (uint8_t *)&f, sizeof(float32_u));
|
||
// resp->data_p += sizeof(float32_u);
|
||
|
||
// dv = get_device_variable_by_standard_code(DIN_249); // 第四变量
|
||
// *resp->data_p++ = dv->code;
|
||
// f.f = *dv->value;
|
||
// f.c = S2B_UINT32(f.c);
|
||
// osel_memcpy(resp->data_p, (uint8_t *)&f, sizeof(float32_u));
|
||
// resp->data_p += sizeof(float32_u);
|
||
// return TRUE;
|
||
// }
|
||
|
||
// /**
|
||
// * @brief转移服务控制
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_111_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
// return TRUE;
|
||
// }
|
||
// /**
|
||
// * @brief传输服务
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_112_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
// return TRUE;
|
||
// }
|
||
// /**
|
||
// * @brief捕获设备变量
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_113_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
// return TRUE;
|
||
// }
|
||
// /**
|
||
// * @brief读取捕获的设备变量
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_114_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
// return TRUE;
|
||
// }
|
||
// /**
|
||
// * @brief读取事件通知摘要
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_115_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
// return TRUE;
|
||
// }
|
||
// /**
|
||
// * @brief写入事件通知位掩码
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_116_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
// return TRUE;
|
||
// }
|
||
// /**
|
||
// * @brief写入事件通知时序
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_117_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
// return TRUE;
|
||
// }
|
||
// /**
|
||
// * @brief事件通知控制
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_118_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
// return TRUE;
|
||
// }
|
||
// /**
|
||
// * @brief确认事件通知
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_119_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// resp->code = RESPONSE_COMMUNICATION_CODE_16;
|
||
// return TRUE;
|
||
// }
|
||
|
||
// /**
|
||
// * @brief 读取国家代码
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_512_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// *resp->data_p++ = HI_UINT16(hart_device_attribute.flash_variable.country_code);
|
||
// *resp->data_p++ = LO_UINT16(hart_device_attribute.flash_variable.country_code);
|
||
// *resp->data_p++ = hart_device_attribute.flash_variable.si_units_control_code;
|
||
// return TRUE;
|
||
// }
|
||
|
||
// /**
|
||
// * @brief 编写国家代码
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_513_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// if (req->data_length < sizeof(hart_command_513_t))
|
||
// {
|
||
// resp->code = RESPONSE_COMMUNICATION_CODE_5;
|
||
// return TRUE;
|
||
// }
|
||
// if (req->data.command_513.si_units_control_code >= SI_UNITS_CONTROL_CODE_MAX)
|
||
// {
|
||
// resp->code = RESPONSE_COMMUNICATION_CODE_8;
|
||
// return TRUE;
|
||
// }
|
||
// hart_device_attribute.flash_variable.country_code = B2S_UINT16(req->data.command_513.country_code);
|
||
// hart_device_attribute.flash_variable.si_units_control_code = req->data.command_513.si_units_control_code;
|
||
// hart_device_status_set_operational_state(DEVICE_OPERATIONAL_STATE_7);
|
||
// // 回复数据
|
||
// *resp->data_p++ = HI_UINT16(hart_device_attribute.flash_variable.country_code);
|
||
// *resp->data_p++ = LO_UINT16(hart_device_attribute.flash_variable.country_code);
|
||
// *resp->data_p++ = hart_device_attribute.flash_variable.si_units_control_code;
|
||
// return TRUE;
|
||
// }
|
||
|
||
// /**
|
||
// * @brief读取设备位置
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_516_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// return TRUE;
|
||
// }
|
||
// /**
|
||
// * @brief写入设备位置
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_517_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// return TRUE;
|
||
// }
|
||
// /**
|
||
// * @brief读取位置说明
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_518_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// return TRUE;
|
||
// }
|
||
// /**
|
||
// * @brief写入位置说明
|
||
// * @param {hart_command_req_t} *req
|
||
// * @param {hart_response_t} *resp
|
||
// * @return {*}
|
||
// */
|
||
// static BOOL hart_slave_command_519_req(const hart_command_req_t *const req, hart_response_t *resp)
|
||
// {
|
||
// return TRUE;
|
||
// }
|
||
|
||
/**
|
||
* @brief 初始化哈希表,用于注册从端发送给主端的命令的处理函数。
|
||
* @return 无
|
||
* @note 此函数通常在哈希表的初始化时调用,以设置默认的未定义命令。
|
||
*/
|
||
void hart_slave_req_init(void)
|
||
{
|
||
for (uint16_t i = 0; i < HART_COMMAND_MAX; i++)
|
||
{
|
||
hart_command_ptr_arr[i] = hart_slave_command_undef_req; // 默认为未定义命令
|
||
}
|
||
|
||
// 通用命令 23条
|
||
hart_command_ptr_arr[HART_COMMAND_0] = hart_slave_command_0_req; // 读取唯一标识命令
|
||
hart_command_ptr_arr[HART_COMMAND_1] = hart_slave_command_1_req; // 读取主变量
|
||
hart_command_ptr_arr[HART_COMMAND_2] = hart_slave_command_2_req; // 读取主变量的回路电流和量程百分比
|
||
hart_command_ptr_arr[HART_COMMAND_3] = hart_slave_command_3_req; // 读取动态变量和回路电流
|
||
/*命令4和命令5设备不需要支持*/
|
||
hart_command_ptr_arr[HART_COMMAND_6] = hart_slave_command_6_req; // 写入轮训地址
|
||
hart_command_ptr_arr[HART_COMMAND_7] = hart_slave_command_7_req; // 读取循环配置
|
||
hart_command_ptr_arr[HART_COMMAND_8] = hart_slave_command_8_req; // 读取动态变量分类
|
||
hart_command_ptr_arr[HART_COMMAND_9] = hart_slave_command_9_req; // 读取具有状态的设备变量
|
||
hart_command_ptr_arr[HART_COMMAND_11] = hart_slave_command_11_req; // 读取与标签关联的唯一标识符
|
||
hart_command_ptr_arr[HART_COMMAND_12] = hart_slave_command_12_req; // 读取消息
|
||
hart_command_ptr_arr[HART_COMMAND_13] = hart_slave_command_13_req; // 读取标签、描述符、日期
|
||
hart_command_ptr_arr[HART_COMMAND_14] = hart_slave_command_14_req; // 读取主变量传感器信息
|
||
hart_command_ptr_arr[HART_COMMAND_15] = hart_slave_command_15_req; // 读取设备信息
|
||
hart_command_ptr_arr[HART_COMMAND_16] = hart_slave_command_16_req; // 读取最终总装编号
|
||
hart_command_ptr_arr[HART_COMMAND_17] = hart_slave_command_17_req; // 写入消息
|
||
hart_command_ptr_arr[HART_COMMAND_18] = hart_slave_command_18_req; // 写标签、描述符、日期
|
||
hart_command_ptr_arr[HART_COMMAND_19] = hart_slave_command_19_req; // 编写总装编号
|
||
hart_command_ptr_arr[HART_COMMAND_20] = hart_slave_command_20_req; // 读取长标签
|
||
hart_command_ptr_arr[HART_COMMAND_21] = hart_slave_command_21_req; // 读取与长标签关联的唯一标识符
|
||
hart_command_ptr_arr[HART_COMMAND_22] = hart_slave_command_22_req; // 写长标签
|
||
hart_command_ptr_arr[HART_COMMAND_31] = hart_slave_command_31_req; // 处理大号命令
|
||
hart_command_ptr_arr[HART_COMMAND_38] = hart_slave_command_38_req; // 重置配置更改标志
|
||
hart_command_ptr_arr[HART_COMMAND_48] = hart_slave_command_48_req; // 读取其他设备状态
|
||
|
||
// 常用命令
|
||
hart_command_ptr_arr[HART_COMMAND_33] = hart_slave_command_33_req; // 读取设备变量
|
||
hart_command_ptr_arr[HART_COMMAND_35] = hart_slave_command_35_req; // 写入主变量范围值
|
||
hart_command_ptr_arr[HART_COMMAND_42] = hart_slave_command_42_req; // 执行设备重置
|
||
hart_command_ptr_arr[HART_COMMAND_44] = hart_slave_command_44_req; // 编写主变量单元
|
||
hart_command_ptr_arr[HART_COMMAND_50] = hart_slave_command_50_req; // 读取动态变量赋值
|
||
hart_command_ptr_arr[HART_COMMAND_51] = hart_slave_command_51_req; // 编写动态变量赋值
|
||
hart_command_ptr_arr[HART_COMMAND_52] = hart_slave_command_52_req; // 设置设备变量零
|
||
hart_command_ptr_arr[HART_COMMAND_53] = hart_slave_command_53_req; // 写入设备变量单元
|
||
hart_command_ptr_arr[HART_COMMAND_54] = hart_slave_command_54_req; // 读取设备变量信息
|
||
hart_command_ptr_arr[HART_COMMAND_59] = hart_slave_command_59_req; // 写入设备变量单元
|
||
|
||
// hart_command_ptr_arr[HART_COMMAND_512] = hart_slave_command_512_req; // 读取国家代码
|
||
// hart_command_ptr_arr[HART_COMMAND_513] = hart_slave_command_513_req; // 编写国家代码
|
||
// hart_command_ptr_arr[HART_COMMAND_516] = hart_slave_command_516_req; // 读取设备位置
|
||
// hart_command_ptr_arr[HART_COMMAND_517] = hart_slave_command_517_req; // 写入设备位置
|
||
// hart_command_ptr_arr[HART_COMMAND_518] = hart_slave_command_518_req; // 读取位置说明
|
||
// hart_command_ptr_arr[HART_COMMAND_519] = hart_slave_command_519_req; // 写入位置说明
|
||
|
||
// hart_command_ptr_arr[HART_COMMAND_34] = hart_slave_command_34_req; // 写入主变量阻尼值
|
||
// hart_command_ptr_arr[HART_COMMAND_36] = hart_slave_command_36_req; // 设置主变量上限值
|
||
// hart_command_ptr_arr[HART_COMMAND_37] = hart_slave_command_37_req; // 设置主变量下限值
|
||
// hart_command_ptr_arr[HART_COMMAND_39] = hart_slave_command_39_req; // EEPROM控制
|
||
// hart_command_ptr_arr[HART_COMMAND_41] = hart_slave_command_41_req; // 执行自检
|
||
// hart_command_ptr_arr[HART_COMMAND_40] = hart_slave_command_40_req; // 进入/退出固定电流模式
|
||
// hart_command_ptr_arr[HART_COMMAND_43] = hart_slave_command_43_req; // 设置主变量零
|
||
// hart_command_ptr_arr[HART_COMMAND_45] = hart_slave_command_45_req; // 微调回路电流归零
|
||
// hart_command_ptr_arr[HART_COMMAND_46] = hart_slave_command_46_req; // 微调回路电流增益
|
||
// hart_command_ptr_arr[HART_COMMAND_47] = hart_slave_command_47_req; // 编写主变量传递函数
|
||
// hart_command_ptr_arr[HART_COMMAND_49] = hart_slave_command_49_req; // 写入主变量传感器序列号
|
||
|
||
// hart_command_ptr_arr[HART_COMMAND_55] = hart_slave_command_55_req; // 写入设备可变阻尼值
|
||
// hart_command_ptr_arr[HART_COMMAND_56] = hart_slave_command_56_req; // 写入设备可变传感器序列号
|
||
// hart_command_ptr_arr[HART_COMMAND_57] = hart_slave_command_57_req; // 读取单位标签、描述符、日期
|
||
// hart_command_ptr_arr[HART_COMMAND_58] = hart_slave_command_58_req; // 编写单位标签、描述符、日期
|
||
// hart_command_ptr_arr[HART_COMMAND_59] = hart_slave_command_59_req; // 写入响应序码数
|
||
// hart_command_ptr_arr[HART_COMMAND_60] = hart_slave_command_60_req; // 读取模拟通道和范围百分比
|
||
// hart_command_ptr_arr[HART_COMMAND_61] = hart_slave_command_61_req; // 读取动态变量和主变量模拟通道
|
||
// hart_command_ptr_arr[HART_COMMAND_62] = hart_slave_command_62_req; // 读取模拟通道
|
||
// hart_command_ptr_arr[HART_COMMAND_63] = hart_slave_command_63_req; // 读取模拟通道信息
|
||
// hart_command_ptr_arr[HART_COMMAND_64] = hart_slave_command_64_req; // 写入模拟通道附加阻尼值
|
||
// hart_command_ptr_arr[HART_COMMAND_65] = hart_slave_command_65_req; // 写入模拟通道范围值
|
||
// hart_command_ptr_arr[HART_COMMAND_66] = hart_slave_command_66_req; // 进入/退出固定模拟通道模式
|
||
// hart_command_ptr_arr[HART_COMMAND_67] = hart_slave_command_67_req; // 调整模拟通道零
|
||
// hart_command_ptr_arr[HART_COMMAND_68] = hart_slave_command_68_req; // 微调模拟通道增益
|
||
// hart_command_ptr_arr[HART_COMMAND_69] = hart_slave_command_69_req; // 写入模拟通道传递函数
|
||
// hart_command_ptr_arr[HART_COMMAND_70] = hart_slave_command_70_req; // 读取模拟通道端点值
|
||
// hart_command_ptr_arr[HART_COMMAND_71] = hart_slave_command_71_req; // 锁定装置
|
||
// hart_command_ptr_arr[HART_COMMAND_72] = hart_slave_command_72_req; // 呼叫
|
||
// hart_command_ptr_arr[HART_COMMAND_73] = hart_slave_command_73_req; // 查找设备
|
||
// hart_command_ptr_arr[HART_COMMAND_74] = hart_slave_command_74_req; // 读取I/O系统功能
|
||
// hart_command_ptr_arr[HART_COMMAND_75] = hart_slave_command_75_req; // 轮询子设备
|
||
// hart_command_ptr_arr[HART_COMMAND_76] = hart_slave_command_76_req; // 读锁定设备状态
|
||
// hart_command_ptr_arr[HART_COMMAND_79] = hart_slave_command_79_req; // 写入设备变量
|
||
// hart_command_ptr_arr[HART_COMMAND_80] = hart_slave_command_80_req; // 读取设备可变微调点
|
||
// hart_command_ptr_arr[HART_COMMAND_81] = hart_slave_command_81_req; // 读取设备变量调整指南
|
||
// hart_command_ptr_arr[HART_COMMAND_82] = hart_slave_command_82_req; // 写入设备可变微调点
|
||
// hart_command_ptr_arr[HART_COMMAND_83] = hart_slave_command_83_req; // 重置设备变量调整
|
||
// hart_command_ptr_arr[HART_COMMAND_84] = hart_slave_command_84_req; // 读取子设备标识摘要
|
||
// hart_command_ptr_arr[HART_COMMAND_85] = hart_slave_command_85_req; // 读取I/O通道统计信息
|
||
// hart_command_ptr_arr[HART_COMMAND_86] = hart_slave_command_86_req; // 读取子设备统计信息
|
||
// hart_command_ptr_arr[HART_COMMAND_87] = hart_slave_command_87_req; // 写入I/O系统主模式
|
||
// hart_command_ptr_arr[HART_COMMAND_88] = hart_slave_command_88_req; // 写入I/O系统重试计数
|
||
// hart_command_ptr_arr[HART_COMMAND_89] = hart_slave_command_89_req; // 设置实时时钟
|
||
// hart_command_ptr_arr[HART_COMMAND_90] = hart_slave_command_90_req; // 读取实时时钟
|
||
// hart_command_ptr_arr[HART_COMMAND_91] = hart_slave_command_91_req; // 读取趋势配置
|
||
// hart_command_ptr_arr[HART_COMMAND_92] = hart_slave_command_92_req; // 写入趋势配置
|
||
// hart_command_ptr_arr[HART_COMMAND_93] = hart_slave_command_93_req; // 读取趋势
|
||
// hart_command_ptr_arr[HART_COMMAND_94] = hart_slave_command_94_req; // 读取I/O系统客户端通信统计信息
|
||
// hart_command_ptr_arr[HART_COMMAND_95] = hart_slave_command_95_req; // 读取设备通信统计信息
|
||
// hart_command_ptr_arr[HART_COMMAND_96] = hart_slave_command_96_req; // 读取同步操作
|
||
// hart_command_ptr_arr[HART_COMMAND_97] = hart_slave_command_97_req; // 配置同步操作
|
||
// hart_command_ptr_arr[HART_COMMAND_98] = hart_slave_command_98_req; // 读取命令操作
|
||
// hart_command_ptr_arr[HART_COMMAND_99] = hart_slave_command_99_req; // 配置命令操作
|
||
// hart_command_ptr_arr[HART_COMMAND_100] = hart_slave_command_100_req; // 写入主变量报警码
|
||
hart_command_ptr_arr[HART_COMMAND_103] = hart_slave_command_103_req; // 写入突发周期
|
||
hart_command_ptr_arr[HART_COMMAND_104] = hart_slave_command_104_req; // 写入突发触发器
|
||
// hart_command_ptr_arr[HART_COMMAND_105] = hart_slave_command_105_req; // 读取突发模式配置
|
||
hart_command_ptr_arr[HART_COMMAND_107] = hart_slave_command_107_req; // 写入突发设备变量V5
|
||
// hart_command_ptr_arr[HART_COMMAND_514] = hart_slave_command_514_req; // 注册事件管理器
|
||
// hart_command_ptr_arr[HART_COMMAND_515] = hart_slave_command_515_req; // 读取事件管理器注册状态
|
||
// hart_command_ptr_arr[HART_COMMAND_520] = hart_slave_command_520_req; // 读取进程单元标签
|
||
// hart_command_ptr_arr[HART_COMMAND_521] = hart_slave_command_521_req; // 写入进程单元标记
|
||
// hart_command_ptr_arr[HART_COMMAND_522] = hart_slave_command_522_req; // 写入体积流分类
|
||
hart_command_ptr_arr[HART_COMMAND_523] = hart_slave_command_523_req; // 读取精简状态映射数组
|
||
hart_command_ptr_arr[HART_COMMAND_524] = hart_slave_command_524_req; // 写入精简状态映射
|
||
// hart_command_ptr_arr[HART_COMMAND_525] = hart_slave_command_525_req; // 重置精简状态图
|
||
// hart_command_ptr_arr[HART_COMMAND_526] = hart_slave_command_526_req; // 写入状态模拟模式
|
||
// hart_command_ptr_arr[HART_COMMAND_527] = hart_slave_command_527_req; // 模拟状态位
|
||
// hart_command_ptr_arr[HART_COMMAND_528] = hart_slave_command_528_req; // 读取子设备分配列表信息
|
||
// hart_command_ptr_arr[HART_COMMAND_529] = hart_slave_command_529_req; // 读取子设备分配
|
||
// hart_command_ptr_arr[HART_COMMAND_530] = hart_slave_command_530_req; // 写入子设备分配
|
||
// hart_command_ptr_arr[HART_COMMAND_531] = hart_slave_command_531_req; // 将实时列表传输到分配列表
|
||
// hart_command_ptr_arr[HART_COMMAND_532] = hart_slave_command_532_req; // 读取客户端订阅摘要
|
||
// hart_command_ptr_arr[HART_COMMAND_533] = hart_slave_command_533_req; // 写入客户端订阅标志
|
||
// hart_command_ptr_arr[HART_COMMAND_534] = hart_slave_command_534_req; // 读取设备变量命令代码
|
||
// hart_command_ptr_arr[HART_COMMAND_535] = hart_slave_command_535_req; // 写入模拟通道端点值
|
||
// hart_command_ptr_arr[HART_COMMAND_536] = hart_slave_command_536_req; // 写入应用时间操作
|
||
// hart_command_ptr_arr[HART_COMMAND_537] = hart_slave_command_537_req; // 读取应用时间操作
|
||
// hart_command_ptr_arr[HART_COMMAND_538] = hart_slave_command_538_req; // 读取HART-IP服务器端口
|
||
// hart_command_ptr_arr[HART_COMMAND_539] = hart_slave_command_539_req; // 写入HART-IP UDP端口
|
||
// hart_command_ptr_arr[HART_COMMAND_540] = hart_slave_command_540_req; // 写入HART-IP TCP端口
|
||
// hart_command_ptr_arr[HART_COMMAND_541] = hart_slave_command_541_req; // 写入客户端PAKE密码
|
||
// hart_command_ptr_arr[HART_COMMAND_542] = hart_slave_command_542_req; // 写入客户端预共享密钥
|
||
// hart_command_ptr_arr[HART_COMMAND_543] = hart_slave_command_543_req; // 读取系统日志服务器主机名和端口
|
||
// hart_command_ptr_arr[HART_COMMAND_544] = hart_slave_command_544_req; // 写入系统日志端口
|
||
// hart_command_ptr_arr[HART_COMMAND_545] = hart_slave_command_545_req; // 写入系统日志服务器主机名
|
||
// hart_command_ptr_arr[HART_COMMAND_546] = hart_slave_command_546_req; // 写入系统日志服务器预共享密钥
|
||
// hart_command_ptr_arr[HART_COMMAND_547] = hart_slave_command_547_req; // 写入系统日志服务器PAKE密码
|
||
|
||
// hart_command_ptr_arr[HART_COMMAND_77] = hart_slave_command_77_req; // 向子设备发送命令
|
||
// hart_command_ptr_arr[HART_COMMAND_78] = hart_slave_command_78_req; // 读取聚合命令
|
||
// hart_command_ptr_arr[HART_COMMAND_101] = hart_slave_command_101_req; // 读取子设备到突发消息映射
|
||
// hart_command_ptr_arr[HART_COMMAND_102] = hart_slave_command_102_req; // 将子设备映射到突发信息
|
||
// hart_command_ptr_arr[HART_COMMAND_106] = hart_slave_command_106_req; // 刷新延迟响应
|
||
hart_command_ptr_arr[HART_COMMAND_108] = hart_slave_command_108_req; // 写入突发模式命令编号V5
|
||
// hart_command_ptr_arr[HART_COMMAND_110] = hart_slave_command_110_req; // 读取所有动态变量V5
|
||
// hart_command_ptr_arr[HART_COMMAND_111] = hart_slave_command_111_req; // 转移服务控制
|
||
// hart_command_ptr_arr[HART_COMMAND_112] = hart_slave_command_112_req; // 传输服务
|
||
// hart_command_ptr_arr[HART_COMMAND_113] = hart_slave_command_113_req; // 捕获设备变量
|
||
// hart_command_ptr_arr[HART_COMMAND_114] = hart_slave_command_114_req; // 读取捕获的设备变量
|
||
// hart_command_ptr_arr[HART_COMMAND_115] = hart_slave_command_115_req; // 读取事件通知摘要
|
||
// hart_command_ptr_arr[HART_COMMAND_116] = hart_slave_command_116_req; // 写入事件通知位掩码
|
||
// hart_command_ptr_arr[HART_COMMAND_117] = hart_slave_command_117_req; // 写入事件通知时序
|
||
// hart_command_ptr_arr[HART_COMMAND_118] = hart_slave_command_118_req; // 事件通知控制
|
||
// hart_command_ptr_arr[HART_COMMAND_119] = hart_slave_command_119_req; // 确认事件通知
|
||
|
||
// 暂不支持指令 end
|
||
hart_slave_req_init_user(); // 用户自定义命令
|
||
}
|