mirror of
https://github.com/emqx/neuron.git
synced 2026-10-28 22:59:34 +08:00
remove attribute: STATIC
This commit is contained in:
@@ -32,7 +32,6 @@ typedef enum {
|
||||
NEU_ATTRIBUTE_READ = 1,
|
||||
NEU_ATTRIBUTE_WRITE = 2,
|
||||
NEU_ATTRIBUTE_SUBSCRIBE = 4,
|
||||
NEU_ATTRIBUTE_STATIC = 8,
|
||||
} neu_attribute_e;
|
||||
|
||||
typedef enum {
|
||||
@@ -133,15 +132,4 @@ int neu_datatag_string_dtoh(char *str, int len);
|
||||
int neu_datatag_string_tod(char *str, int len, int buf_len);
|
||||
int neu_datatag_string_toe(char *str, int len, int buf_len);
|
||||
|
||||
int neu_tag_get_static_value(const neu_datatag_t *tag, neu_value_u *value);
|
||||
int neu_tag_set_static_value(neu_datatag_t *tag, const neu_value_u *value);
|
||||
|
||||
int neu_tag_get_static_value_json(neu_datatag_t *tag, neu_json_type_e *t,
|
||||
neu_json_value_u *v);
|
||||
int neu_tag_set_static_value_json(neu_datatag_t *tag, neu_json_type_e t,
|
||||
const neu_json_value_u *v);
|
||||
|
||||
char *neu_tag_dump_static_value(const neu_datatag_t *tag);
|
||||
int neu_tag_load_static_value(neu_datatag_t *tag, const char *s);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -434,11 +434,6 @@ static int json_to_gdatatags(neu_json_gtag_array_t *gtag_array,
|
||||
} else {
|
||||
gdatatags[i].tags[j].description = strdup("");
|
||||
}
|
||||
if (NEU_ATTRIBUTE_STATIC & gtag_array->gtags[i].tags[j].attribute) {
|
||||
neu_tag_set_static_value_json(
|
||||
&gdatatags[i].tags[j], gtag_array->gtags[i].tags[j].t,
|
||||
>ag_array->gtags[i].tags[j].value);
|
||||
}
|
||||
|
||||
gtag_array->gtags[i].tags[j].address = NULL; // moved
|
||||
gtag_array->gtags[i].tags[j].name = NULL; // moved
|
||||
|
||||
@@ -67,10 +67,6 @@ void handle_add_tags(nng_aio *aio)
|
||||
} else {
|
||||
cmd.tags[i].description = strdup("");
|
||||
}
|
||||
if (NEU_ATTRIBUTE_STATIC & req->tags[i].attribute) {
|
||||
neu_tag_set_static_value_json(
|
||||
&cmd.tags[i], req->tags[i].t, &req->tags[i].value);
|
||||
}
|
||||
}
|
||||
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
@@ -158,12 +154,6 @@ void handle_add_gtags(nng_aio *aio)
|
||||
} else {
|
||||
cmd.groups[i].tags[j].description = strdup("");
|
||||
}
|
||||
if (NEU_ATTRIBUTE_STATIC &
|
||||
req->groups[i].tags[j].attribute) {
|
||||
neu_tag_set_static_value_json(
|
||||
&cmd.groups[i].tags[j], req->groups[i].tags[j].t,
|
||||
&req->groups[i].tags[j].value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,10 +273,6 @@ void handle_update_tags(nng_aio *aio)
|
||||
} else {
|
||||
cmd.tags[i].description = strdup("");
|
||||
}
|
||||
if (NEU_ATTRIBUTE_STATIC & req->tags[i].attribute) {
|
||||
neu_tag_set_static_value_json(&cmd.tags[i], req->tags[i].t,
|
||||
&req->tags[i].value);
|
||||
}
|
||||
}
|
||||
|
||||
ret = neu_plugin_op(plugin, header, &cmd);
|
||||
@@ -367,12 +353,7 @@ void handle_get_tags_resp(nng_aio *aio, neu_resp_get_tag_t *tags)
|
||||
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);
|
||||
} else {
|
||||
tags_res.tags[index].t = NEU_JSON_UNDEFINE;
|
||||
}
|
||||
tags_res.tags[index].t = NEU_JSON_UNDEFINE;
|
||||
}
|
||||
|
||||
neu_json_encode_by_fn(&tags_res, neu_json_encode_get_tags_resp, &result);
|
||||
|
||||
@@ -823,12 +823,7 @@ static int get_tags_resp(context_t *ctx, neu_resp_get_tag_t *tags)
|
||||
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);
|
||||
} else {
|
||||
tags_res.tags[index].t = NEU_JSON_UNDEFINE;
|
||||
}
|
||||
tags_res.tags[index].t = NEU_JSON_UNDEFINE;
|
||||
}
|
||||
|
||||
// accumulate tag object in `tags` array
|
||||
@@ -908,15 +903,10 @@ static int get_driver_tags_resp(context_t *ctx, neu_resp_get_tag_t *tags)
|
||||
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);
|
||||
} else {
|
||||
gtag->tags[index].t = NEU_JSON_UNDEFINE;
|
||||
}
|
||||
tag->name = NULL; // moved
|
||||
tag->address = NULL; // moved
|
||||
tag->description = NULL; // moved
|
||||
gtag->tags[index].t = NEU_JSON_UNDEFINE;
|
||||
tag->name = NULL; // moved
|
||||
tag->address = NULL; // moved
|
||||
tag->description = NULL; // moved
|
||||
}
|
||||
|
||||
end:
|
||||
@@ -1191,11 +1181,6 @@ static int add_tag(context_t *ctx, neu_json_add_tags_req_t *data)
|
||||
ret = NEU_ERR_EINTERNAL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (NEU_ATTRIBUTE_STATIC & data->tags[i].attribute) {
|
||||
neu_tag_set_static_value_json(&cmd.tags[i], data->tags[i].t,
|
||||
&data->tags[i].value);
|
||||
}
|
||||
}
|
||||
|
||||
if (0 != neu_plugin_op(plugin, header, &cmd)) {
|
||||
|
||||
+21
-80
@@ -60,7 +60,6 @@ typedef struct group {
|
||||
|
||||
int64_t timestamp;
|
||||
neu_group_t * group;
|
||||
UT_array * static_tags;
|
||||
UT_array * wt_tags;
|
||||
pthread_mutex_t wt_mtx;
|
||||
|
||||
@@ -242,9 +241,6 @@ static void update_with_meta(neu_adapter_t *adapter, const char *group,
|
||||
|
||||
utarray_foreach(tags, neu_datatag_t *, t)
|
||||
{
|
||||
if (neu_tag_attribute_test(t, NEU_ATTRIBUTE_STATIC)) {
|
||||
continue;
|
||||
}
|
||||
neu_driver_cache_update(driver->cache, group, t->name,
|
||||
global_timestamp, value, NULL, 0);
|
||||
++err_count;
|
||||
@@ -478,7 +474,6 @@ int neu_adapter_driver_uninit(neu_adapter_driver_t *driver)
|
||||
neu_tag_free(tag->tag);
|
||||
}
|
||||
|
||||
utarray_free(el->static_tags);
|
||||
utarray_free(el->wt_tags);
|
||||
utarray_free(el->apps);
|
||||
neu_group_destroy(el->group);
|
||||
@@ -1114,7 +1109,6 @@ int neu_adapter_driver_write_tags(neu_adapter_driver_t *driver,
|
||||
}
|
||||
|
||||
if (tag != NULL && neu_tag_attribute_test(tag, NEU_ATTRIBUTE_WRITE) &&
|
||||
neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC) == false &&
|
||||
value_check == NEU_ERR_SUCCESS) {
|
||||
if (tag->type == NEU_TYPE_FLOAT || tag->type == NEU_TYPE_DOUBLE) {
|
||||
if (cmd->tags[i].value.type == NEU_TYPE_INT64) {
|
||||
@@ -1229,7 +1223,6 @@ int neu_adapter_driver_write_gtags(neu_adapter_driver_t *driver,
|
||||
|
||||
if (tag != NULL &&
|
||||
neu_tag_attribute_test(tag, NEU_ATTRIBUTE_WRITE) &&
|
||||
neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC) == false &&
|
||||
value_check == NEU_ERR_SUCCESS) {
|
||||
if (tag->type == NEU_TYPE_FLOAT ||
|
||||
tag->type == NEU_TYPE_DOUBLE) {
|
||||
@@ -1352,23 +1345,13 @@ int neu_adapter_driver_write_tag(neu_adapter_driver_t *driver,
|
||||
|
||||
fix_value(tag, cmd->value.type, &cmd->value);
|
||||
|
||||
if (neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC)) {
|
||||
neu_driver_cache_update(g->driver->cache, g->name, tag->name,
|
||||
global_timestamp, cmd->value, NULL, 0);
|
||||
neu_tag_set_static_value(tag, &cmd->value.value);
|
||||
neu_group_update_tag(g->group, tag);
|
||||
adapter_storage_update_tag_value(cmd->driver, cmd->group, tag);
|
||||
driver->adapter.cb_funs.driver.write_response(&driver->adapter, req,
|
||||
NEU_ERR_SUCCESS);
|
||||
} else {
|
||||
to_be_write_tag_t wtag = { 0 };
|
||||
wtag.single = true;
|
||||
wtag.req = (void *) req;
|
||||
wtag.value = cmd->value.value;
|
||||
wtag.tag = neu_tag_dup(tag);
|
||||
to_be_write_tag_t wtag = { 0 };
|
||||
wtag.single = true;
|
||||
wtag.req = (void *) req;
|
||||
wtag.value = cmd->value.value;
|
||||
wtag.tag = neu_tag_dup(tag);
|
||||
|
||||
store_write_tag(g, &wtag);
|
||||
}
|
||||
store_write_tag(g, &wtag);
|
||||
|
||||
neu_tag_free(tag);
|
||||
return NEU_ERR_SUCCESS;
|
||||
@@ -1403,8 +1386,7 @@ int neu_adapter_driver_add_group(neu_adapter_driver_t *driver, const char *name,
|
||||
find->grp.group_name = strdup(name);
|
||||
find->grp.interval = interval;
|
||||
find->grp.context = context;
|
||||
neu_group_split_static_tags(find->group, &find->static_tags,
|
||||
&find->grp.tags);
|
||||
find->grp.tags = neu_group_get_tag(find->group);
|
||||
|
||||
if (NEU_NODE_RUNNING_STATE_RUNNING == driver->adapter.state) {
|
||||
start_group_timer(driver, find);
|
||||
@@ -1523,11 +1505,6 @@ int neu_adapter_driver_del_group(neu_adapter_driver_t *driver, const char *name)
|
||||
free(find->grp.context);
|
||||
}
|
||||
|
||||
utarray_foreach(find->static_tags, neu_datatag_t *, tag)
|
||||
{
|
||||
neu_driver_cache_del(driver->cache, name, tag->name);
|
||||
}
|
||||
|
||||
utarray_foreach(find->grp.tags, neu_datatag_t *, tag)
|
||||
{
|
||||
neu_driver_cache_del(driver->cache, name, tag->name);
|
||||
@@ -1550,7 +1527,6 @@ int neu_adapter_driver_del_group(neu_adapter_driver_t *driver, const char *name)
|
||||
driver->adapter.cb_funs.update_metric(
|
||||
&driver->adapter, NEU_METRIC_TAGS_TOTAL, driver->tag_cnt, NULL);
|
||||
|
||||
utarray_free(find->static_tags);
|
||||
utarray_free(find->grp.tags);
|
||||
utarray_free(find->wt_tags);
|
||||
utarray_free(find->apps);
|
||||
@@ -1709,17 +1685,10 @@ int neu_adapter_driver_validate_tag(neu_adapter_driver_t *driver,
|
||||
}
|
||||
}
|
||||
|
||||
if (neu_tag_attribute_test(tag, NEU_ATTRIBUTE_SUBSCRIBE) &&
|
||||
neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC)) {
|
||||
return NEU_ERR_TAG_ATTRIBUTE_NOT_SUPPORT;
|
||||
}
|
||||
|
||||
if (!neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC)) {
|
||||
int ret = driver->adapter.module->intf_funs->driver.validate_tag(
|
||||
driver->adapter.plugin, tag);
|
||||
if (ret != NEU_ERR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
int ret = driver->adapter.module->intf_funs->driver.validate_tag(
|
||||
driver->adapter.plugin, tag);
|
||||
if (ret != NEU_ERR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
neu_datatag_parse_addr_option(tag, &tag->option);
|
||||
@@ -1806,12 +1775,10 @@ int neu_adapter_driver_update_tag(neu_adapter_driver_t *driver,
|
||||
return NEU_ERR_TAG_PRECISION_INVALID;
|
||||
}
|
||||
|
||||
if (!neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC)) {
|
||||
ret = driver->adapter.module->intf_funs->driver.validate_tag(
|
||||
driver->adapter.plugin, tag);
|
||||
if (ret != NEU_ERR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
ret = driver->adapter.module->intf_funs->driver.validate_tag(
|
||||
driver->adapter.plugin, tag);
|
||||
if (ret != NEU_ERR_SUCCESS) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
neu_datatag_parse_addr_option(tag, &tag->option);
|
||||
@@ -2089,8 +2056,8 @@ static int report_callback(void *usr_data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void group_change(void *arg, int64_t timestamp, UT_array *static_tags,
|
||||
UT_array *other_tags, uint32_t interval)
|
||||
static void group_change(void *arg, int64_t timestamp, UT_array *tags,
|
||||
uint32_t interval)
|
||||
{
|
||||
group_t *group = (group_t *) arg;
|
||||
group->timestamp = timestamp;
|
||||
@@ -2099,32 +2066,12 @@ static void group_change(void *arg, int64_t timestamp, UT_array *static_tags,
|
||||
if (group->grp.group_free != NULL)
|
||||
group->grp.group_free(&group->grp);
|
||||
|
||||
utarray_foreach(group->static_tags, neu_datatag_t *, tag)
|
||||
{
|
||||
neu_driver_cache_del(group->driver->cache, group->name, tag->name);
|
||||
}
|
||||
|
||||
utarray_foreach(group->grp.tags, neu_datatag_t *, tag)
|
||||
{
|
||||
neu_driver_cache_del(group->driver->cache, group->name, tag->name);
|
||||
}
|
||||
|
||||
utarray_foreach(static_tags, neu_datatag_t *, tag)
|
||||
{
|
||||
neu_dvalue_t value = { 0 };
|
||||
|
||||
value.precision = tag->precision;
|
||||
value.type = tag->type;
|
||||
if (0 != neu_tag_get_static_value(tag, &value.value)) {
|
||||
value.type = NEU_TYPE_ERROR;
|
||||
value.value.i32 = NEU_ERR_EINTERNAL;
|
||||
}
|
||||
|
||||
neu_driver_cache_add(group->driver->cache, group->name, tag->name,
|
||||
value);
|
||||
}
|
||||
|
||||
utarray_foreach(other_tags, neu_datatag_t *, tag)
|
||||
utarray_foreach(tags, neu_datatag_t *, tag)
|
||||
{
|
||||
neu_dvalue_t value = { 0 };
|
||||
|
||||
@@ -2146,17 +2093,14 @@ static void group_change(void *arg, int64_t timestamp, UT_array *static_tags,
|
||||
};
|
||||
|
||||
grp.context = group->grp.context;
|
||||
grp.tags = other_tags;
|
||||
grp.tags = tags;
|
||||
free(group->grp.group_name);
|
||||
if (group->static_tags != NULL) {
|
||||
utarray_free(group->static_tags);
|
||||
}
|
||||
if (group->grp.tags != NULL) {
|
||||
utarray_free(group->grp.tags);
|
||||
}
|
||||
|
||||
group->static_tags = static_tags;
|
||||
group->grp = grp;
|
||||
group->grp = grp;
|
||||
|
||||
nlog_notice("group: %s changed, timestamp: %" PRIi64, group->name,
|
||||
timestamp);
|
||||
}
|
||||
@@ -2381,7 +2325,6 @@ static void read_report_group(int64_t timestamp, int64_t timeout,
|
||||
}
|
||||
|
||||
if (cache_type != NEU_TAG_CACHE_TYPE_NEVER &&
|
||||
!neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC) &&
|
||||
(timestamp - value.timestamp) > timeout && timeout > 0) {
|
||||
if (value.value.type == NEU_TYPE_PTR) {
|
||||
free(value.value.value.ptr.ptr);
|
||||
@@ -2548,7 +2491,6 @@ static void read_group(int64_t timestamp, int64_t timeout,
|
||||
}
|
||||
|
||||
if (cache_type != NEU_TAG_CACHE_TYPE_NEVER &&
|
||||
!neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC) &&
|
||||
(timestamp - value.timestamp) > timeout) {
|
||||
if (value.value.type == NEU_TYPE_PTR) {
|
||||
free(value.value.value.ptr.ptr);
|
||||
@@ -2727,7 +2669,6 @@ static void read_group_paginate(int64_t timestamp, int64_t timeout,
|
||||
}
|
||||
|
||||
if (cache_type != NEU_TAG_CACHE_TYPE_NEVER &&
|
||||
!neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC) &&
|
||||
(timestamp - value.timestamp) > timeout) {
|
||||
if (value.value.type == NEU_TYPE_PTR) {
|
||||
free(value.value.value.ptr.ptr);
|
||||
|
||||
+4
-32
@@ -44,8 +44,6 @@ struct neu_group {
|
||||
};
|
||||
|
||||
static UT_array *to_array(tag_elem_t *tags);
|
||||
static void split_static_array(tag_elem_t *tags, UT_array **static_tags,
|
||||
UT_array **other_tags);
|
||||
static void update_timestamp(neu_group_t *group);
|
||||
|
||||
neu_group_t *neu_group_new(const char *name, uint32_t interval)
|
||||
@@ -241,8 +239,7 @@ static inline bool is_readable(const neu_datatag_t *tag, void *data)
|
||||
{
|
||||
(void) data;
|
||||
return neu_tag_attribute_test(tag, NEU_ATTRIBUTE_READ) ||
|
||||
neu_tag_attribute_test(tag, NEU_ATTRIBUTE_SUBSCRIBE) ||
|
||||
neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC);
|
||||
neu_tag_attribute_test(tag, NEU_ATTRIBUTE_SUBSCRIBE);
|
||||
}
|
||||
|
||||
static inline bool name_contains(const neu_datatag_t *tag, void *data)
|
||||
@@ -357,19 +354,12 @@ neu_datatag_t *neu_group_find_tag(neu_group_t *group, const char *tag)
|
||||
return result;
|
||||
}
|
||||
|
||||
void neu_group_split_static_tags(neu_group_t *group, UT_array **static_tags,
|
||||
UT_array **other_tags)
|
||||
{
|
||||
return split_static_array(group->tags, static_tags, other_tags);
|
||||
}
|
||||
|
||||
void neu_group_change_test(neu_group_t *group, int64_t timestamp, void *arg,
|
||||
neu_group_change_fn fn)
|
||||
{
|
||||
if (group->timestamp != timestamp) {
|
||||
UT_array *static_tags = NULL, *other_tags = NULL;
|
||||
split_static_array(group->tags, &static_tags, &other_tags);
|
||||
fn(arg, group->timestamp, static_tags, other_tags, group->interval);
|
||||
UT_array *tags = to_array(group->tags);
|
||||
fn(arg, group->timestamp, tags, group->interval);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -400,22 +390,4 @@ static UT_array *to_array(tag_elem_t *tags)
|
||||
HASH_ITER(hh, tags, el, tmp) { utarray_push_back(array, el->tag); }
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
static void split_static_array(tag_elem_t *tags, UT_array **static_tags,
|
||||
UT_array **other_tags)
|
||||
{
|
||||
tag_elem_t *el = NULL, *tmp = NULL;
|
||||
|
||||
utarray_new(*static_tags, neu_tag_get_icd());
|
||||
utarray_new(*other_tags, neu_tag_get_icd());
|
||||
HASH_ITER(hh, tags, el, tmp)
|
||||
{
|
||||
if (neu_tag_attribute_test(el->tag, NEU_ATTRIBUTE_STATIC)) {
|
||||
utarray_push_back(*static_tags, el->tag);
|
||||
} else if (neu_tag_attribute_test(el->tag, NEU_ATTRIBUTE_SUBSCRIBE) ||
|
||||
neu_tag_attribute_test(el->tag, NEU_ATTRIBUTE_READ)) {
|
||||
utarray_push_back(*other_tags, el->tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-4
@@ -49,12 +49,9 @@ UT_array * neu_group_query_read_tag_paginate(neu_group_t *group,
|
||||
int *total_count);
|
||||
uint16_t neu_group_tag_size(const neu_group_t *group);
|
||||
neu_datatag_t *neu_group_find_tag(neu_group_t *group, const char *tag);
|
||||
void neu_group_split_static_tags(neu_group_t *group, UT_array **static_tags,
|
||||
UT_array **other_tags);
|
||||
|
||||
typedef void (*neu_group_change_fn)(void *arg, int64_t timestamp,
|
||||
UT_array *static_tags, UT_array *other_tags,
|
||||
uint32_t interval);
|
||||
UT_array *tags, uint32_t interval);
|
||||
void neu_group_change_test(neu_group_t *group, int64_t timestamp, void *arg,
|
||||
neu_group_change_fn fn);
|
||||
bool neu_group_is_change(neu_group_t *group, int64_t timestamp);
|
||||
|
||||
+2
-349
@@ -26,16 +26,6 @@ config_ **/
|
||||
#include "errcodes.h"
|
||||
#include "tag.h"
|
||||
|
||||
#define GET_STATIC_VALUE_PTR(tag, out) \
|
||||
do { \
|
||||
memcpy(&(out), (tag)->meta, sizeof(neu_value_u *)); \
|
||||
} while (0)
|
||||
|
||||
#define SET_STATIC_VALUE_PTR(tag, ptr) \
|
||||
do { \
|
||||
memcpy((tag)->meta, &(ptr), sizeof(neu_value_u *)); \
|
||||
} while (0)
|
||||
|
||||
static void tag_array_copy(void *_dst, const void *_src)
|
||||
{
|
||||
neu_datatag_t *dst = (neu_datatag_t *) _dst;
|
||||
@@ -51,18 +41,7 @@ static void tag_array_copy(void *_dst, const void *_src)
|
||||
dst->name = strdup(src->name);
|
||||
dst->description = strdup(src->description);
|
||||
|
||||
if (NEU_ATTRIBUTE_STATIC & src->attribute) {
|
||||
neu_value_u *dst_val = NULL, *src_val = NULL;
|
||||
GET_STATIC_VALUE_PTR(src, src_val);
|
||||
if (src_val && (dst_val = calloc(1, sizeof(*dst_val)))) {
|
||||
memcpy(dst_val, src_val, sizeof(*dst_val));
|
||||
SET_STATIC_VALUE_PTR(dst, dst_val);
|
||||
} else {
|
||||
memset(dst->meta, 0, sizeof(dst->meta));
|
||||
}
|
||||
} else {
|
||||
memcpy(dst->meta, src->meta, sizeof(src->meta));
|
||||
}
|
||||
memcpy(dst->meta, src->meta, sizeof(src->meta));
|
||||
}
|
||||
|
||||
static void tag_array_free(void *_elt)
|
||||
@@ -72,13 +51,6 @@ static void tag_array_free(void *_elt)
|
||||
free(elt->name);
|
||||
free(elt->address);
|
||||
free(elt->description);
|
||||
|
||||
if (NEU_ATTRIBUTE_STATIC & elt->attribute) {
|
||||
neu_value_u *cur = NULL;
|
||||
GET_STATIC_VALUE_PTR(elt, cur);
|
||||
free(cur);
|
||||
memset(elt->meta, 0, sizeof(elt->meta));
|
||||
}
|
||||
}
|
||||
|
||||
static UT_icd tag_icd = { sizeof(neu_datatag_t), NULL, tag_array_copy,
|
||||
@@ -432,323 +404,4 @@ int neu_datatag_string_toe(char *str, int len, int buf_len)
|
||||
|
||||
free(t);
|
||||
return len * 2;
|
||||
}*/
|
||||
|
||||
int neu_tag_get_static_value(const neu_datatag_t *tag, neu_value_u *value)
|
||||
{
|
||||
neu_value_u *cur = NULL;
|
||||
|
||||
if (!neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
GET_STATIC_VALUE_PTR(tag, cur);
|
||||
if (NULL == cur) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(value, cur, sizeof(*cur));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int neu_tag_set_static_value(neu_datatag_t *tag, const neu_value_u *value)
|
||||
{
|
||||
neu_value_u *cur = NULL;
|
||||
|
||||
if (!neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
GET_STATIC_VALUE_PTR(tag, cur);
|
||||
if (NULL == cur) {
|
||||
cur = calloc(1, sizeof(*cur));
|
||||
if (NULL == cur) {
|
||||
return -1;
|
||||
}
|
||||
SET_STATIC_VALUE_PTR(tag, cur);
|
||||
}
|
||||
|
||||
memcpy(cur, value, sizeof(*cur));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int neu_tag_get_static_value_json(neu_datatag_t *tag, neu_json_type_e *t,
|
||||
neu_json_value_u *v)
|
||||
{
|
||||
neu_value_u *value = NULL;
|
||||
GET_STATIC_VALUE_PTR(tag, value);
|
||||
|
||||
if (NULL == value) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (tag->type) {
|
||||
case NEU_TYPE_BIT:
|
||||
*t = NEU_JSON_INT;
|
||||
v->val_bit = value->u8;
|
||||
break;
|
||||
case NEU_TYPE_BOOL:
|
||||
*t = NEU_JSON_BOOL;
|
||||
v->val_bool = value->boolean;
|
||||
break;
|
||||
case NEU_TYPE_INT8:
|
||||
*t = NEU_JSON_INT;
|
||||
v->val_int = value->i8;
|
||||
break;
|
||||
case NEU_TYPE_UINT8:
|
||||
*t = NEU_JSON_INT;
|
||||
v->val_int = value->u8;
|
||||
break;
|
||||
case NEU_TYPE_INT16:
|
||||
*t = NEU_JSON_INT;
|
||||
v->val_int = value->i16;
|
||||
break;
|
||||
case NEU_TYPE_WORD:
|
||||
case NEU_TYPE_UINT16:
|
||||
*t = NEU_JSON_INT;
|
||||
v->val_int = value->u16;
|
||||
break;
|
||||
case NEU_TYPE_INT32:
|
||||
*t = NEU_JSON_INT;
|
||||
v->val_int = value->i32;
|
||||
break;
|
||||
case NEU_TYPE_DWORD:
|
||||
case NEU_TYPE_UINT32:
|
||||
*t = NEU_JSON_INT;
|
||||
v->val_int = value->u32;
|
||||
break;
|
||||
case NEU_TYPE_INT64:
|
||||
*t = NEU_JSON_INT;
|
||||
v->val_int = value->i64;
|
||||
break;
|
||||
case NEU_TYPE_LWORD:
|
||||
case NEU_TYPE_UINT64:
|
||||
*t = NEU_JSON_INT;
|
||||
v->val_int = value->u64;
|
||||
break;
|
||||
case NEU_TYPE_FLOAT:
|
||||
*t = NEU_JSON_FLOAT;
|
||||
v->val_float = value->f32;
|
||||
break;
|
||||
case NEU_TYPE_DOUBLE:
|
||||
*t = NEU_JSON_DOUBLE;
|
||||
v->val_double = value->d64;
|
||||
break;
|
||||
case NEU_TYPE_STRING:
|
||||
case NEU_TYPE_TIME:
|
||||
case NEU_TYPE_DATA_AND_TIME:
|
||||
*t = NEU_JSON_STR;
|
||||
v->val_str = value->str;
|
||||
break;
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int neu_tag_set_static_value_json(neu_datatag_t *tag, neu_json_type_e t,
|
||||
const neu_json_value_u *v)
|
||||
{
|
||||
int rv = 0;
|
||||
neu_value_u value = { 0 };
|
||||
|
||||
if (!neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
switch (t) {
|
||||
case NEU_JSON_BIT: {
|
||||
if (NEU_TYPE_BIT == tag->type) {
|
||||
value.u8 = v->val_bit;
|
||||
} else {
|
||||
rv = -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_JSON_BOOL: {
|
||||
if (NEU_TYPE_BOOL == tag->type) {
|
||||
value.boolean = v->val_bool;
|
||||
} else {
|
||||
rv = -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_JSON_INT: {
|
||||
switch (tag->type) {
|
||||
case NEU_TYPE_BIT:
|
||||
value.u8 = v->val_int;
|
||||
break;
|
||||
case NEU_TYPE_INT8:
|
||||
value.i8 = v->val_int;
|
||||
break;
|
||||
case NEU_TYPE_UINT8:
|
||||
value.u8 = v->val_int;
|
||||
break;
|
||||
case NEU_TYPE_INT16:
|
||||
value.i16 = v->val_int;
|
||||
break;
|
||||
case NEU_TYPE_WORD:
|
||||
case NEU_TYPE_UINT16:
|
||||
value.u16 = v->val_int;
|
||||
break;
|
||||
case NEU_TYPE_INT32:
|
||||
value.i32 = v->val_int;
|
||||
break;
|
||||
case NEU_TYPE_DWORD:
|
||||
case NEU_TYPE_UINT32:
|
||||
value.u32 = v->val_int;
|
||||
break;
|
||||
case NEU_TYPE_INT64:
|
||||
value.i64 = v->val_int;
|
||||
break;
|
||||
case NEU_TYPE_LWORD:
|
||||
case NEU_TYPE_UINT64:
|
||||
value.u64 = v->val_int;
|
||||
break;
|
||||
case NEU_TYPE_FLOAT:
|
||||
value.f32 = v->val_int;
|
||||
break;
|
||||
case NEU_TYPE_DOUBLE:
|
||||
value.d64 = v->val_int;
|
||||
break;
|
||||
default:
|
||||
rv = -1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_JSON_FLOAT: {
|
||||
if (NEU_TYPE_FLOAT == tag->type) {
|
||||
value.f32 = v->val_float;
|
||||
} else if (NEU_TYPE_DOUBLE == tag->type) {
|
||||
value.d64 = v->val_float;
|
||||
} else {
|
||||
rv = -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_JSON_DOUBLE: {
|
||||
if (NEU_TYPE_FLOAT == tag->type) {
|
||||
value.f32 = v->val_double;
|
||||
} else if (NEU_TYPE_DOUBLE == tag->type) {
|
||||
value.d64 = v->val_double;
|
||||
} else {
|
||||
rv = -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_JSON_STR: {
|
||||
if (NEU_TYPE_STRING == tag->type || NEU_TYPE_TIME == tag->type ||
|
||||
NEU_TYPE_DATA_AND_TIME == tag->type) {
|
||||
snprintf(value.str, sizeof(value.str), "%s", v->val_str);
|
||||
} else {
|
||||
rv = -1;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
rv = -1;
|
||||
}
|
||||
|
||||
if (0 == rv) {
|
||||
rv = neu_tag_set_static_value(tag, &value);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
char *neu_tag_dump_static_value(const neu_datatag_t *tag)
|
||||
{
|
||||
json_t *jval = NULL;
|
||||
|
||||
if (!neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
neu_value_u value = { 0 };
|
||||
if (0 != neu_tag_get_static_value(tag, &value)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (tag->type) {
|
||||
case NEU_TYPE_BOOL:
|
||||
jval = json_boolean(value.boolean);
|
||||
break;
|
||||
case NEU_TYPE_INT8:
|
||||
jval = json_integer(value.i8);
|
||||
break;
|
||||
case NEU_TYPE_BIT:
|
||||
case NEU_TYPE_UINT8:
|
||||
jval = json_integer(value.u8);
|
||||
break;
|
||||
case NEU_TYPE_INT16:
|
||||
jval = json_integer(value.i16);
|
||||
break;
|
||||
case NEU_TYPE_WORD:
|
||||
case NEU_TYPE_UINT16:
|
||||
jval = json_integer(value.u16);
|
||||
break;
|
||||
case NEU_TYPE_INT32:
|
||||
jval = json_integer(value.i32);
|
||||
break;
|
||||
case NEU_TYPE_DWORD:
|
||||
case NEU_TYPE_UINT32:
|
||||
jval = json_integer(value.u32);
|
||||
break;
|
||||
case NEU_TYPE_INT64:
|
||||
jval = json_integer(value.i64);
|
||||
break;
|
||||
case NEU_TYPE_LWORD:
|
||||
case NEU_TYPE_UINT64:
|
||||
jval = json_integer(value.u64);
|
||||
break;
|
||||
case NEU_TYPE_FLOAT:
|
||||
jval = json_real(value.f32);
|
||||
break;
|
||||
case NEU_TYPE_DOUBLE:
|
||||
jval = json_real(value.d64);
|
||||
break;
|
||||
case NEU_TYPE_STRING:
|
||||
case NEU_TYPE_TIME:
|
||||
case NEU_TYPE_DATA_AND_TIME:
|
||||
jval = json_string(value.str);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
char *s = json_dumps(jval, JSON_ENCODE_ANY);
|
||||
json_decref(jval);
|
||||
return s;
|
||||
}
|
||||
|
||||
int neu_tag_load_static_value(neu_datatag_t *tag, const char *s)
|
||||
{
|
||||
if (!neu_tag_attribute_test(tag, NEU_ATTRIBUTE_STATIC) || !s) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
void *jval = neu_json_decode_new(s);
|
||||
if (NULL == jval) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
neu_json_elem_t elem = {
|
||||
.name = NULL,
|
||||
.t = NEU_JSON_VALUE,
|
||||
};
|
||||
|
||||
int rv = neu_json_decode_value(jval, &elem);
|
||||
if (0 == rv) {
|
||||
rv = neu_tag_set_static_value_json(tag, elem.t, &elem.v);
|
||||
}
|
||||
|
||||
if (NEU_JSON_STR == elem.t) {
|
||||
free(elem.v.val_str);
|
||||
}
|
||||
neu_json_decode_free(jval);
|
||||
|
||||
return rv;
|
||||
}
|
||||
}*/
|
||||
@@ -187,40 +187,8 @@ void neu_json_decode_tag_fini(neu_json_tag_t *tag)
|
||||
|
||||
int neu_json_tag_check_type(neu_json_tag_t *tag)
|
||||
{
|
||||
if (NEU_ATTRIBUTE_STATIC & tag->attribute) {
|
||||
switch (tag->type) {
|
||||
case NEU_TYPE_BIT:
|
||||
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_WORD:
|
||||
case NEU_TYPE_DWORD:
|
||||
case NEU_TYPE_LWORD:
|
||||
return NEU_JSON_INT == tag->t;
|
||||
case NEU_TYPE_FLOAT:
|
||||
case NEU_TYPE_DOUBLE:
|
||||
return NEU_JSON_INT == tag->t || NEU_JSON_FLOAT == tag->t ||
|
||||
NEU_JSON_DOUBLE == tag->t;
|
||||
case NEU_TYPE_BOOL:
|
||||
return NEU_JSON_BOOL == tag->t;
|
||||
case NEU_TYPE_BYTES:
|
||||
case NEU_TYPE_STRING:
|
||||
case NEU_TYPE_TIME:
|
||||
case NEU_TYPE_DATA_AND_TIME:
|
||||
return NEU_JSON_STR == tag->t &&
|
||||
strlen(tag->value.val_str) <= NEU_VALUE_SIZE;
|
||||
}
|
||||
} else {
|
||||
// non-static tag should have no initial value
|
||||
return NEU_JSON_UNDEFINE == tag->t;
|
||||
}
|
||||
|
||||
return true;
|
||||
// non-static tag should have no initial value
|
||||
return NEU_JSON_UNDEFINE == tag->t;
|
||||
}
|
||||
|
||||
int neu_json_encode_tag_array(void *json_obj, void *param)
|
||||
|
||||
+8
-23
@@ -572,8 +572,7 @@ int neu_sqlite_persister_store_tag(neu_persister_t * self,
|
||||
const char * group_name,
|
||||
const neu_datatag_t *tag)
|
||||
{
|
||||
char *val_str = neu_tag_dump_static_value(tag);
|
||||
int rv =
|
||||
int rv =
|
||||
execute_sql(((neu_sqlite_persister_t *) self)->db,
|
||||
"INSERT INTO tags ("
|
||||
" driver_name, group_name, name, address, attribute,"
|
||||
@@ -581,9 +580,8 @@ int neu_sqlite_persister_store_tag(neu_persister_t * self,
|
||||
") VALUES (%Q, %Q, %Q, %Q, %i, %i, %i, %lf, %lf, %Q, %Q)",
|
||||
driver_name, group_name, tag->name, tag->address,
|
||||
tag->attribute, tag->precision, tag->type, tag->decimal,
|
||||
tag->bias, tag->description, val_str);
|
||||
tag->bias, tag->description, "");
|
||||
|
||||
free(val_str);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -644,21 +642,16 @@ static int put_tags(sqlite3 *db, const char *query, sqlite3_stmt *stmt,
|
||||
return -1;
|
||||
}
|
||||
|
||||
char *val_str = neu_tag_dump_static_value(tag);
|
||||
if (SQLITE_OK != sqlite3_bind_text(stmt, 11, val_str, -1, NULL)) {
|
||||
nlog_error("bind `%s` with value=`%s` fail: %s", query, val_str,
|
||||
if (SQLITE_OK != sqlite3_bind_null(stmt, 11)) {
|
||||
nlog_error("bind `%s` with value=null fail: %s", query,
|
||||
sqlite3_errmsg(db));
|
||||
free(val_str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (SQLITE_DONE != sqlite3_step(stmt)) {
|
||||
nlog_error("sqlite3_step fail: %s", sqlite3_errmsg(db));
|
||||
free(val_str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
free(val_str);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -737,10 +730,6 @@ static int collect_tag_info(sqlite3_stmt *stmt, UT_array **tags)
|
||||
.description = (char *) sqlite3_column_text(stmt, 7),
|
||||
};
|
||||
utarray_push_back(*tags, &tag);
|
||||
if (neu_tag_attribute_test(&tag, NEU_ATTRIBUTE_STATIC)) {
|
||||
neu_tag_load_static_value(utarray_back(*tags),
|
||||
(char *) sqlite3_column_text(stmt, 8));
|
||||
}
|
||||
|
||||
step = sqlite3_step(stmt);
|
||||
}
|
||||
@@ -804,16 +793,14 @@ int neu_sqlite_persister_update_tag(neu_persister_t * self,
|
||||
const char * group_name,
|
||||
const neu_datatag_t *tag)
|
||||
{
|
||||
char *val_str = neu_tag_dump_static_value(tag);
|
||||
int rv = execute_sql(((neu_sqlite_persister_t *) self)->db,
|
||||
int rv = execute_sql(((neu_sqlite_persister_t *) self)->db,
|
||||
"UPDATE tags SET"
|
||||
" address=%Q, attribute=%i, precision=%i, type=%i,"
|
||||
" decimal=%lf, bias=%lf, description=%Q, value=%Q "
|
||||
"WHERE driver_name=%Q AND group_name=%Q AND name=%Q",
|
||||
tag->address, tag->attribute, tag->precision,
|
||||
tag->type, tag->decimal, tag->bias, tag->description,
|
||||
val_str, driver_name, group_name, tag->name);
|
||||
free(val_str);
|
||||
"", driver_name, group_name, tag->name);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -822,12 +809,10 @@ int neu_sqlite_persister_update_tag_value(neu_persister_t * self,
|
||||
const char * group_name,
|
||||
const neu_datatag_t *tag)
|
||||
{
|
||||
char *val_str = neu_tag_dump_static_value(tag);
|
||||
int rv = execute_sql(((neu_sqlite_persister_t *) self)->db,
|
||||
int rv = execute_sql(((neu_sqlite_persister_t *) self)->db,
|
||||
"UPDATE tags SET value=%Q "
|
||||
"WHERE driver_name=%Q AND group_name=%Q AND name=%Q",
|
||||
val_str, driver_name, group_name, tag->name);
|
||||
free(val_str);
|
||||
"", driver_name, group_name, tag->name);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
@@ -194,25 +194,6 @@ input_register_string = [{"name": "input_register_string", "address": "1!30120.1
|
||||
input_register_bytes = [{"name": "input_register_bytes", "address": "1!30130.10",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_READ, "type": config.NEU_TYPE_BYTES}]
|
||||
|
||||
hold_int16_s = [{"name": "hold_int16_s", "address": "1!400801",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW_STATIC, "type": config.NEU_TYPE_INT16, "value": 1}]
|
||||
hold_uint16_s = [{"name": "hold_uint16_s", "address": "1!400802",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW_STATIC, "type": config.NEU_TYPE_UINT16, "value": 1}]
|
||||
hold_int32_s = [{"name": "hold_int32_s", "address": "1!400803",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW_STATIC, "type": config.NEU_TYPE_INT32, "value": 1}]
|
||||
hold_uint32_s = [{"name": "hold_uint32_s", "address": "1!400815",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW_STATIC, "type": config.NEU_TYPE_UINT32, "value": 1}]
|
||||
hold_int64_s = [{"name": "hold_int64_s", "address": "1!400823",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW_STATIC, "type": config.NEU_TYPE_INT64, "value": 1}]
|
||||
hold_uint64_s = [{"name": "hold_uint64_s", "address": "1!400835",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW_STATIC, "type": config.NEU_TYPE_UINT64, "value": 1}]
|
||||
hold_float_s = [{"name": "hold_float_s", "address": "1!400847",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW_STATIC, "type": config.NEU_TYPE_FLOAT, "value": 1.0}]
|
||||
hold_double_s = [{"name": "hold_double_s", "address": "1!400857",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW_STATIC, "type": config.NEU_TYPE_DOUBLE, "value": 1.0}]
|
||||
hold_string_s = [{"name": "hold_string_s", "address": "1!400870.2",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW_STATIC, "type": config.NEU_TYPE_STRING, "value": "a"}]
|
||||
|
||||
hold_int16_decimal = [{"name": "hold_int16_decimal", "address": "1!40103",
|
||||
"attribute": config.NEU_TAG_ATTRIBUTE_RW, "type": config.NEU_TYPE_INT16, "decimal": 0.1}]
|
||||
hold_int16_decimal_w = [{"name": "hold_int16_decimal_w", "address": "1!40103",
|
||||
@@ -508,42 +489,6 @@ class TestModbus:
|
||||
api.add_tags_check(node=param[0], group='group', tags=hold_string_H)
|
||||
api.add_tags_check(node=param[0], group='group', tags=hold_string_L)
|
||||
|
||||
@description(given="created modbus node", when="add and read static tags", then="add and read success")
|
||||
def test_add_read_static_tags(self, param):
|
||||
api.add_tags_check(node=param[0], group='group', tags=hold_int16_s)
|
||||
api.add_tags_check(node=param[0], group='group', tags=hold_uint16_s)
|
||||
api.add_tags_check(node=param[0], group='group', tags=hold_int32_s)
|
||||
api.add_tags_check(node=param[0], group='group', tags=hold_uint32_s)
|
||||
api.add_tags_check(node=param[0], group='group', tags=hold_int64_s)
|
||||
api.add_tags_check(node=param[0], group='group', tags=hold_uint64_s)
|
||||
api.add_tags_check(node=param[0], group='group', tags=hold_float_s)
|
||||
api.add_tags_check(node=param[0], group='group', tags=hold_double_s)
|
||||
api.add_tags_check(node=param[0], group='group', tags=hold_string_s)
|
||||
|
||||
time.sleep(0.5)
|
||||
|
||||
response = api.get_tags(node=param[0], group="group")
|
||||
assert 200 == response.status_code
|
||||
|
||||
assert 1 == api.read_tag(
|
||||
node=param[0], group='group', tag=hold_int16_s[0]['name'])
|
||||
assert 1 == api.read_tag(
|
||||
node=param[0], group='group', tag=hold_uint16_s[0]['name'])
|
||||
assert 1 == api.read_tag(
|
||||
node=param[0], group='group', tag=hold_int32_s[0]['name'])
|
||||
assert 1 == api.read_tag(
|
||||
node=param[0], group='group', tag=hold_uint32_s[0]['name'])
|
||||
assert 1 == api.read_tag(
|
||||
node=param[0], group='group', tag=hold_int64_s[0]['name'])
|
||||
assert 1 == api.read_tag(
|
||||
node=param[0], group='group', tag=hold_uint64_s[0]['name'])
|
||||
assert 1.0 == api.read_tag(
|
||||
node=param[0], group='group', tag=hold_float_s[0]['name'])
|
||||
assert 1.0 == api.read_tag(
|
||||
node=param[0], group='group', tag=hold_double_s[0]['name'])
|
||||
assert 'a' == api.read_tag(
|
||||
node=param[0], group='group', tag=hold_string_s[0]['name'])
|
||||
|
||||
@description(given="created modbus node", when="add wrong tags", then="add failed")
|
||||
def test_add_wrong_tags(self, param):
|
||||
wrong_tag1 = [{"name": "winput_bit_1", "address": "1!100001",
|
||||
|
||||
@@ -42,14 +42,13 @@ global_config = {
|
||||
},
|
||||
{
|
||||
"type": 3,
|
||||
"name": "hold_int16_s",
|
||||
"attribute": 9,
|
||||
"name": "hold_int16_2",
|
||||
"attribute": 1,
|
||||
"precision": 0,
|
||||
"decimal": 0.0,
|
||||
"bias": 1.0,
|
||||
"address": "1!400002",
|
||||
"description": "",
|
||||
"value": 1
|
||||
"description": ""
|
||||
}
|
||||
],
|
||||
"driver": "modbus",
|
||||
@@ -160,14 +159,13 @@ driver_1 = {
|
||||
},
|
||||
{
|
||||
"type": 3,
|
||||
"name": "hold_int16_s",
|
||||
"attribute": 9,
|
||||
"name": "hold_int16_2",
|
||||
"attribute": 1,
|
||||
"precision": 0,
|
||||
"decimal": 0.0,
|
||||
"bias": 1.0,
|
||||
"address": "1!400002",
|
||||
"description": "",
|
||||
"value": 1
|
||||
"description": ""
|
||||
}
|
||||
],
|
||||
},
|
||||
@@ -208,14 +206,13 @@ driver_2 = {
|
||||
},
|
||||
{
|
||||
"type": 3,
|
||||
"name": "hold_int16_s",
|
||||
"attribute": 9,
|
||||
"name": "hold_int16_2",
|
||||
"attribute": 1,
|
||||
"precision": 0,
|
||||
"decimal": 0.0,
|
||||
"bias": 1.0,
|
||||
"address": "1!400002",
|
||||
"description": "",
|
||||
"value": 1
|
||||
"description": ""
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
@@ -18,9 +18,7 @@ NEU_NODE_LINK_STATE_CONNECTED = 1
|
||||
NEU_TAG_ATTRIBUTE_READ = 1
|
||||
NEU_TAG_ATTRIBUTE_WRITE = 2
|
||||
NEU_TAG_ATTRIBUTE_SUBSCRIBE = 4
|
||||
NEU_TAG_ATTRIBUTE_STATIC = 8
|
||||
NEU_TAG_ATTRIBUTE_RW = NEU_TAG_ATTRIBUTE_READ | NEU_TAG_ATTRIBUTE_WRITE
|
||||
NEU_TAG_ATTRIBUTE_RW_STATIC = NEU_TAG_ATTRIBUTE_RW | NEU_TAG_ATTRIBUTE_STATIC
|
||||
NEU_TAG_ATTRIBUTE_RW_SUBSCRIBE = NEU_TAG_ATTRIBUTE_RW | NEU_TAG_ATTRIBUTE_SUBSCRIBE
|
||||
NEU_TAG_ATTRIBUTE_READ_SUBSCRIBE = NEU_TAG_ATTRIBUTE_READ | NEU_TAG_ATTRIBUTE_SUBSCRIBE
|
||||
|
||||
|
||||
@@ -8,14 +8,6 @@ hold_int16 = [{"name": "hold_int16", "address": "1!400001",
|
||||
"attribute": NEU_TAG_ATTRIBUTE_RW, "type": NEU_TYPE_INT16}]
|
||||
hold_int16_to_int32 = [{"name": "hold_int16", "address": "1!400002",
|
||||
"attribute": NEU_TAG_ATTRIBUTE_RW, "type": NEU_TYPE_INT32}]
|
||||
hold_int16_to_static = [{"name": "hold_int16", "address": "1!400001",
|
||||
"attribute": NEU_TAG_ATTRIBUTE_RW_STATIC, "type": NEU_TYPE_INT16, "value": 1}]
|
||||
hold_int16_to_static_without_value = [{"name": "hold_int16", "address": "1!400001",
|
||||
"attribute": NEU_TAG_ATTRIBUTE_RW_STATIC, "type": NEU_TYPE_INT16}]
|
||||
hold_int16_static = [{"name": "hold_int16_static", "address": "1!400001",
|
||||
"attribute": NEU_TAG_ATTRIBUTE_RW_STATIC, "type": NEU_TYPE_INT16, "value": 1}]
|
||||
hold_int16_static_null = [{"name": "hold_int16", "address": "1!400001",
|
||||
"attribute": NEU_TAG_ATTRIBUTE_RW_STATIC, "type": NEU_TYPE_INT16}]
|
||||
hold_int16_bit = [{"name": "hold_int16_type", "address": "1!400001",
|
||||
"attribute": NEU_TAG_ATTRIBUTE_RW, "type": NEU_TYPE_INT16},
|
||||
{"name": "hold_bit_type", "address": "1!000001",
|
||||
@@ -26,6 +18,8 @@ hold_int16_decimal = [{"name": "hold_int16_decimal", "address": "1!400001",
|
||||
"attribute": NEU_TAG_ATTRIBUTE_RW, "type": NEU_TYPE_INT16, "decimal": 0.1}]
|
||||
hold_int16_bias = [{"name": "hold_int16_bias", "address": "1!400001",
|
||||
"attribute": NEU_TAG_ATTRIBUTE_READ, "type": NEU_TYPE_INT16, "bias": 1.0}]
|
||||
none= [{"name": "none", "address": "1!400001",
|
||||
"attribute": NEU_TAG_ATTRIBUTE_RW, "type": NEU_TYPE_INT16}]
|
||||
|
||||
class TestTag:
|
||||
|
||||
@@ -581,18 +575,6 @@ class TestTag:
|
||||
assert 200 == response.status_code
|
||||
assert NEU_ERR_SUCCESS == response.json()['error']
|
||||
|
||||
@description(given="static tag", when="add static tag", then="add success")
|
||||
def test_add_static_tag(self):
|
||||
response = api.add_tags(node="modbus-tcp", group="group1", tags=hold_int16_static)
|
||||
assert 200 == response.status_code
|
||||
assert NEU_ERR_SUCCESS == response.json()['error']
|
||||
|
||||
@description(given="static tag without value", when="add static tag without value", then="add failed")
|
||||
def test_add_static_tag_without_value(self):
|
||||
response = api.add_tags(node="modbus-tcp", group="group1", tags=hold_int16_static_null)
|
||||
assert 400 == response.status_code
|
||||
assert NEU_ERR_BODY_IS_WRONG == response.json()['error']
|
||||
|
||||
@description(given="node group", when="add different types of tags", then="add success")
|
||||
def test_add_different_types_tags(self):
|
||||
response = api.add_tags(node="modbus-tcp", group="group1", tags=hold_int16_bit)
|
||||
@@ -614,18 +596,6 @@ class TestTag:
|
||||
assert NEU_TAG_ATTRIBUTE_RW == response.json()["tags"][0]["attribute"]
|
||||
assert NEU_TYPE_INT16 == response.json()["tags"][0]["type"]
|
||||
|
||||
@description(given="node group tag", when="update tag to be static", then="update success")
|
||||
def test_update_tag_to_static(self):
|
||||
response = api.update_tags(node="modbus-tcp", group="group1", tags=hold_int16_to_static)
|
||||
assert 200 == response.status_code
|
||||
assert NEU_ERR_SUCCESS == response.json()['error']
|
||||
|
||||
@description(given="node group tag", when="update tag to be static without value", then="update failed")
|
||||
def test_update_tag_to_static_without_value(self):
|
||||
response = api.update_tags(node="modbus-tcp", group="group1", tags=hold_int16_to_static_without_value)
|
||||
assert 400 == response.status_code
|
||||
assert NEU_ERR_BODY_IS_WRONG == response.json()['error']
|
||||
|
||||
@description(given="node group tag", when="update tag", then="update success")
|
||||
def test_update_tag(self):
|
||||
response = api.update_tags(node="modbus-tcp", group="group1", tags=hold_int16_to_int32)
|
||||
@@ -641,7 +611,7 @@ class TestTag:
|
||||
|
||||
@description(given="non-existent tag", when="update non-existent tag", then="update failed")
|
||||
def test_update_non_existent_tag(self):
|
||||
response = api.update_tags(node="modbus-tcp", group="group", tags=hold_int16_to_static)
|
||||
response = api.update_tags(node="modbus-tcp", group="group", tags=none)
|
||||
assert 404 == response.status_code
|
||||
assert NEU_ERR_TAG_NOT_EXIST == response.json()['error']
|
||||
|
||||
@@ -653,7 +623,7 @@ class TestTag:
|
||||
|
||||
@description(given="node group tags", when="delete tags", then="delete success")
|
||||
def test_delete_tags(self):
|
||||
response = api.del_tags(node="modbus-tcp", group="group1", tags=["hold_int16", "hold_int16_static", "hold_int16_type", "hold_bit_type"])
|
||||
response = api.del_tags(node="modbus-tcp", group="group1", tags=["hold_int16", "hold_int16_type", "hold_bit_type"])
|
||||
assert 200 == response.status_code
|
||||
assert NEU_ERR_SUCCESS == response.json()['error']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user