feat(core): add tag bias field

This commit is contained in:
eeff
2024-04-10 14:42:36 +08:00
parent 7f9aa4cfc8
commit bb793f6e14
10 changed files with 46 additions and 0 deletions
+22
View File
@@ -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;
+1
View File
@@ -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);
+11
View File
@@ -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) {
+1
View File
@@ -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;
+1
View File
@@ -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: