diff --git a/include/neuron/errcodes.h b/include/neuron/errcodes.h index d54bf9cc..32b654e5 100644 --- a/include/neuron/errcodes.h +++ b/include/neuron/errcodes.h @@ -83,6 +83,7 @@ typedef enum { NEU_ERR_TAG_PRECISION_INVALID = 2209, NEU_ERR_TAG_EXIST = 2210, NEU_ERR_TAG_VALUE_INVALID = 2211, + NEU_ERR_TAG_BIAS_INVALID = 2212, NEU_ERR_LIBRARY_NOT_FOUND = 2301, NEU_ERR_LIBRARY_INFO_INVALID = 2302, diff --git a/include/neuron/tag.h b/include/neuron/tag.h index e4055f7e..9fb5d71a 100644 --- a/include/neuron/tag.h +++ b/include/neuron/tag.h @@ -87,6 +87,7 @@ typedef struct { neu_type_e type; uint8_t precision; double decimal; + double bias; char * description; neu_datatag_addr_option_u option; uint8_t meta[NEU_TAG_META_LENGTH]; diff --git a/plugins/restful/adapter_handle.c b/plugins/restful/adapter_handle.c index 48260d91..37904abd 100644 --- a/plugins/restful/adapter_handle.c +++ b/plugins/restful/adapter_handle.c @@ -417,6 +417,7 @@ static int json_to_gdatatags(neu_json_gtag_array_t *gtag_array, gdatatags[i].tags[j].precision = gtag_array->gtags[i].tags[j].precision; gdatatags[i].tags[j].decimal = gtag_array->gtags[i].tags[j].decimal; + gdatatags[i].tags[j].bias = gtag_array->gtags[i].tags[j].bias; gdatatags[i].tags[j].address = gtag_array->gtags[i].tags[j].address; gdatatags[i].tags[j].name = gtag_array->gtags[i].tags[j].name; if (gtag_array->gtags[i].tags[j].description != NULL) { diff --git a/plugins/restful/datatag_handle.c b/plugins/restful/datatag_handle.c index 61a4419a..da6cc616 100644 --- a/plugins/restful/datatag_handle.c +++ b/plugins/restful/datatag_handle.c @@ -57,6 +57,7 @@ void handle_add_tags(nng_aio *aio) cmd.tags[i].type = req->tags[i].type; cmd.tags[i].precision = req->tags[i].precision; cmd.tags[i].decimal = req->tags[i].decimal; + cmd.tags[i].bias = req->tags[i].bias; cmd.tags[i].address = strdup(req->tags[i].address); cmd.tags[i].name = strdup(req->tags[i].name); if (req->tags[i].description != NULL) { @@ -144,6 +145,7 @@ void handle_add_gtags(nng_aio *aio) req->groups[i].tags[j].precision; cmd.groups[i].tags[j].decimal = req->groups[i].tags[j].decimal; + cmd.groups[i].tags[j].bias = req->groups[i].tags[j].bias; cmd.groups[i].tags[j].address = strdup(req->groups[i].tags[j].address); cmd.groups[i].tags[j].name = @@ -269,6 +271,7 @@ void handle_update_tags(nng_aio *aio) cmd.tags[i].type = req->tags[i].type; cmd.tags[i].precision = req->tags[i].precision; cmd.tags[i].decimal = req->tags[i].decimal; + cmd.tags[i].bias = req->tags[i].bias; cmd.tags[i].address = strdup(req->tags[i].address); cmd.tags[i].name = strdup(req->tags[i].name); if (req->tags[i].description != NULL) { @@ -358,6 +361,7 @@ void handle_get_tags_resp(nng_aio *aio, neu_resp_get_tag_t *tags) tags_res.tags[index].attribute = tag->attribute; tags_res.tags[index].precision = tag->precision; tags_res.tags[index].decimal = tag->decimal; + tags_res.tags[index].bias = tag->bias; if (neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC)) { neu_tag_get_static_value_json(tag, &tags_res.tags[index].t, &tags_res.tags[index].value); diff --git a/plugins/restful/global_config_handle.c b/plugins/restful/global_config_handle.c index a82806af..44f803ca 100644 --- a/plugins/restful/global_config_handle.c +++ b/plugins/restful/global_config_handle.c @@ -819,6 +819,7 @@ static int get_tags_resp(context_t *ctx, neu_resp_get_tag_t *tags) tags_res.tags[index].attribute = tag->attribute; tags_res.tags[index].precision = tag->precision; tags_res.tags[index].decimal = tag->decimal; + tags_res.tags[index].bias = tag->bias; if (neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC)) { neu_tag_get_static_value_json(tag, &tags_res.tags[index].t, &tags_res.tags[index].value); @@ -903,6 +904,7 @@ static int get_driver_tags_resp(context_t *ctx, neu_resp_get_tag_t *tags) gtag->tags[index].attribute = tag->attribute; gtag->tags[index].precision = tag->precision; gtag->tags[index].decimal = tag->decimal; + gtag->tags[index].bias = tag->bias; if (neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC)) { neu_tag_get_static_value_json(tag, >ag->tags[index].t, >ag->tags[index].value); @@ -1169,6 +1171,7 @@ static int add_tag(context_t *ctx, neu_json_add_tags_req_t *data) cmd.tags[i].type = data->tags[i].type; cmd.tags[i].precision = data->tags[i].precision; cmd.tags[i].decimal = data->tags[i].decimal; + cmd.tags[i].bias = data->tags[i].bias; cmd.tags[i].address = strdup(data->tags[i].address); cmd.tags[i].name = strdup(data->tags[i].name); cmd.tags[i].description = diff --git a/src/adapter/driver/driver.c b/src/adapter/driver/driver.c index 27e10238..2e1b7e00 100644 --- a/src/adapter/driver/driver.c +++ b/src/adapter/driver/driver.c @@ -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; diff --git a/src/base/tag.c b/src/base/tag.c index 4d1e60e1..c28b6de4 100644 --- a/src/base/tag.c +++ b/src/base/tag.c @@ -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); diff --git a/src/parser/neu_json_tag.c b/src/parser/neu_json_tag.c index e29052ca..63224009 100644 --- a/src/parser/neu_json_tag.c +++ b/src/parser/neu_json_tag.c @@ -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) { diff --git a/src/parser/neu_json_tag.h b/src/parser/neu_json_tag.h index e9436f9b..fd6043e5 100644 --- a/src/parser/neu_json_tag.h +++ b/src/parser/neu_json_tag.h @@ -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; diff --git a/src/utils/http.c b/src/utils/http.c index 5c6c83ee..fef9228c 100644 --- a/src/utils/http.c +++ b/src/utils/http.c @@ -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: