mirror of
https://github.com/emqx/neuron.git
synced 2026-10-28 14:07:20 +08:00
feat(core): add tag bias field
This commit is contained in:
@@ -1247,6 +1247,28 @@ int neu_adapter_driver_validate_tag(neu_adapter_driver_t *driver,
|
||||
return NEU_ERR_TAG_PRECISION_INVALID;
|
||||
}
|
||||
|
||||
if (tag->bias != 0) {
|
||||
switch (tag->type) {
|
||||
case NEU_TYPE_INT8:
|
||||
case NEU_TYPE_UINT8:
|
||||
case NEU_TYPE_INT16:
|
||||
case NEU_TYPE_UINT16:
|
||||
case NEU_TYPE_INT32:
|
||||
case NEU_TYPE_UINT32:
|
||||
case NEU_TYPE_INT64:
|
||||
case NEU_TYPE_UINT64:
|
||||
case NEU_TYPE_FLOAT:
|
||||
case NEU_TYPE_DOUBLE:
|
||||
if (tag->bias < -1000 || 1000 < tag->bias ||
|
||||
neu_tag_attribute_test(tag, NEU_ATTRIBUTE_WRITE)) {
|
||||
return NEU_ERR_TAG_BIAS_INVALID;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return NEU_ERR_TAG_BIAS_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
if (neu_tag_attribute_test(tag, NEU_ATTRIBUTE_SUBSCRIBE) &&
|
||||
neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC)) {
|
||||
return NEU_ERR_TAG_ATTRIBUTE_NOT_SUPPORT;
|
||||
|
||||
@@ -45,6 +45,7 @@ static void tag_array_copy(void *_dst, const void *_src)
|
||||
dst->attribute = src->attribute;
|
||||
dst->precision = src->precision;
|
||||
dst->decimal = src->decimal;
|
||||
dst->bias = src->bias;
|
||||
dst->option = src->option;
|
||||
dst->address = strdup(src->address);
|
||||
dst->name = strdup(src->name);
|
||||
|
||||
@@ -64,6 +64,11 @@ int neu_json_encode_tag(void *json_obj, void *param)
|
||||
.t = NEU_JSON_DOUBLE,
|
||||
.v.val_double = tag->decimal,
|
||||
},
|
||||
{
|
||||
.name = "bias",
|
||||
.t = NEU_JSON_DOUBLE,
|
||||
.v.val_double = tag->bias,
|
||||
},
|
||||
{
|
||||
.name = "address",
|
||||
.t = NEU_JSON_STR,
|
||||
@@ -130,6 +135,11 @@ int neu_json_decode_tag_json(void *json_obj, neu_json_tag_t *tag_p)
|
||||
.t = NEU_JSON_VALUE,
|
||||
.attribute = NEU_JSON_ATTRIBUTE_OPTIONAL,
|
||||
},
|
||||
{
|
||||
.name = "bias",
|
||||
.t = NEU_JSON_DOUBLE,
|
||||
.attribute = NEU_JSON_ATTRIBUTE_OPTIONAL,
|
||||
},
|
||||
};
|
||||
|
||||
int ret = neu_json_decode_by_json(json_obj, NEU_JSON_ELEM_SIZE(tag_elems),
|
||||
@@ -146,6 +156,7 @@ int neu_json_decode_tag_json(void *json_obj, neu_json_tag_t *tag_p)
|
||||
.description = tag_elems[6].v.val_str,
|
||||
.t = tag_elems[7].t,
|
||||
.value = tag_elems[7].v,
|
||||
.bias = tag_elems[8].v.val_double,
|
||||
};
|
||||
|
||||
if (0 != ret) {
|
||||
|
||||
@@ -39,6 +39,7 @@ typedef struct {
|
||||
int64_t attribute;
|
||||
int64_t precision;
|
||||
double decimal;
|
||||
double bias;
|
||||
neu_json_type_e t;
|
||||
neu_json_value_u value;
|
||||
} neu_json_tag_t;
|
||||
|
||||
@@ -321,6 +321,7 @@ int neu_http_response(nng_aio *aio, neu_err_code_e code, char *content)
|
||||
case NEU_ERR_TAG_NAME_TOO_LONG:
|
||||
case NEU_ERR_TAG_ADDRESS_TOO_LONG:
|
||||
case NEU_ERR_TAG_VALUE_INVALID:
|
||||
case NEU_ERR_TAG_BIAS_INVALID:
|
||||
case NEU_ERR_GROUP_MAX_GROUPS:
|
||||
case NEU_ERR_LICENSE_MAX_TAGS:
|
||||
case NEU_ERR_LICENSE_BAD_CLOCK:
|
||||
|
||||
Reference in New Issue
Block a user