From 380bae660cbe076dedd06a89871ccc25f99f94bf Mon Sep 17 00:00:00 2001 From: fengzero Date: Tue, 13 Sep 2022 07:39:16 +0000 Subject: [PATCH 1/3] chore(driver): update tags in group table --- src/base/group.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/src/base/group.c b/src/base/group.c index e269f867..37bcb314 100644 --- a/src/base/group.c +++ b/src/base/group.c @@ -142,28 +142,19 @@ int neu_group_update_tag(neu_group_t *group, neu_datatag_t *tag) HASH_FIND_STR(group->tags, tag->name, el); if (el != NULL) { - HASH_DEL(group->tags, el); - free(el->name); - free(el->tag->name); free(el->tag->address); - free(el->tag->description); - free(el->tag); - free(el); + el->tag->address = strdup(tag->address); - el = calloc(1, sizeof(tag_elem_t)); - el->name = strdup(tag->name); - el->tag = calloc(1, sizeof(neu_datatag_t)); - el->tag->name = strdup(tag->name); - el->tag->address = strdup(tag->address); + free(el->tag->description); el->tag->description = strdup(tag->description); - el->tag->type = tag->type; - el->tag->attribute = tag->attribute; - el->tag->precision = tag->precision; - el->tag->decimal = tag->decimal; - el->tag->option = tag->option; + + el->tag->type = tag->type; + el->tag->attribute = tag->attribute; + el->tag->precision = tag->precision; + el->tag->decimal = tag->decimal; + el->tag->option = tag->option; memcpy(el->tag->meta, tag->meta, sizeof(tag->meta)); - HASH_ADD_STR(group->tags, name, el); update_timestamp(group); ret = NEU_ERR_SUCCESS; } From 3b0bdefd1a21d5a31885f4d3a8a05b4722a89c87 Mon Sep 17 00:00:00 2001 From: fengzero Date: Tue, 13 Sep 2022 08:20:45 +0000 Subject: [PATCH 2/3] fix(driver): negative multiplication --- src/adapter/driver/driver.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/adapter/driver/driver.c b/src/adapter/driver/driver.c index b76a185e..0598852a 100644 --- a/src/adapter/driver/driver.c +++ b/src/adapter/driver/driver.c @@ -862,21 +862,33 @@ static int read_report_group(int64_t timestamp, int64_t timeout, datas[index].value.type = NEU_TYPE_DOUBLE; switch (tag->type) { case NEU_TYPE_INT8: + datas[index].value.value.d64 = + (double) datas[index].value.value.i8 * tag->decimal; + break; case NEU_TYPE_UINT8: datas[index].value.value.d64 = (double) datas[index].value.value.u8 * tag->decimal; break; case NEU_TYPE_INT16: + datas[index].value.value.d64 = + (double) datas[index].value.value.i16 * tag->decimal; + break; case NEU_TYPE_UINT16: datas[index].value.value.d64 = (double) datas[index].value.value.u16 * tag->decimal; break; case NEU_TYPE_INT32: + datas[index].value.value.d64 = + (double) datas[index].value.value.i32 * tag->decimal; + break; case NEU_TYPE_UINT32: datas[index].value.value.d64 = (double) datas[index].value.value.u32 * tag->decimal; break; case NEU_TYPE_INT64: + datas[index].value.value.d64 = + (double) datas[index].value.value.i64 * tag->decimal; + break; case NEU_TYPE_UINT64: datas[index].value.value.d64 = (double) datas[index].value.value.u64 * tag->decimal; @@ -988,21 +1000,33 @@ static void read_group(int64_t timestamp, int64_t timeout, datas[index].value.type = NEU_TYPE_DOUBLE; switch (tag->type) { case NEU_TYPE_INT8: + datas[index].value.value.d64 = + (double) datas[index].value.value.i8 * tag->decimal; + break; case NEU_TYPE_UINT8: datas[index].value.value.d64 = (double) datas[index].value.value.u8 * tag->decimal; break; case NEU_TYPE_INT16: + datas[index].value.value.d64 = + (double) datas[index].value.value.i16 * tag->decimal; + break; case NEU_TYPE_UINT16: datas[index].value.value.d64 = (double) datas[index].value.value.u16 * tag->decimal; break; case NEU_TYPE_INT32: + datas[index].value.value.d64 = + (double) datas[index].value.value.i32 * tag->decimal; + break; case NEU_TYPE_UINT32: datas[index].value.value.d64 = (double) datas[index].value.value.u32 * tag->decimal; break; case NEU_TYPE_INT64: + datas[index].value.value.d64 = + (double) datas[index].value.value.i64 * tag->decimal; + break; case NEU_TYPE_UINT64: datas[index].value.value.d64 = (double) datas[index].value.value.u64 * tag->decimal; From 012c7b756c24e4284da50baf90d10680975ffc28 Mon Sep 17 00:00:00 2001 From: fengzero Date: Tue, 13 Sep 2022 08:30:42 +0000 Subject: [PATCH 3/3] fix(ft): update tag --- ft/tag_test.robot | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/ft/tag_test.robot b/ft/tag_test.robot index 8529e9db..fb6e6422 100644 --- a/ft/tag_test.robot +++ b/ft/tag_test.robot @@ -72,15 +72,15 @@ Update tag, it should return success. ${len} = Get Length ${res}[tags] Should Be Equal As Integers ${len} 2 - Should Be Equal As Strings ${res}[tags][1][name] tag1 - Should Be Equal As Strings ${res}[tags][1][address] 1!400002 - Should Be Equal As Strings ${res}[tags][1][attribute] ${TAG_ATTRIBUTE_RW} - Should Be Equal As Strings ${res}[tags][1][type] ${TAG_TYPE_INT32} - - Should Be Equal As Strings ${res}[tags][0][name] tag2 - Should Be Equal As Strings ${res}[tags][0][address] 1!00001 + Should Be Equal As Strings ${res}[tags][0][name] tag1 + Should Be Equal As Strings ${res}[tags][0][address] 1!400002 Should Be Equal As Strings ${res}[tags][0][attribute] ${TAG_ATTRIBUTE_RW} - Should Be Equal As Strings ${res}[tags][0][type] ${TAG_TYPE_BIT} + Should Be Equal As Strings ${res}[tags][0][type] ${TAG_TYPE_INT32} + + Should Be Equal As Strings ${res}[tags][1][name] tag2 + Should Be Equal As Strings ${res}[tags][1][address] 1!00001 + Should Be Equal As Strings ${res}[tags][1][attribute] ${TAG_ATTRIBUTE_RW} + Should Be Equal As Strings ${res}[tags][1][type] ${TAG_TYPE_BIT} Delete tag from non-existent group, it should return success ${res}= Del Tags modbus-node group1 "tag1" @@ -100,15 +100,15 @@ Update non-existent tag, it should return failure. ${len} = Get Length ${res}[tags] Should Be Equal As Integers ${len} 2 - Should Be Equal As Strings ${res}[tags][1][name] tag1 - Should Be Equal As Strings ${res}[tags][1][address] 1!400002 - Should Be Equal As Strings ${res}[tags][1][attribute] ${TAG_ATTRIBUTE_RW} - Should Be Equal As Strings ${res}[tags][1][type] ${TAG_TYPE_INT32} - - Should Be Equal As Strings ${res}[tags][0][name] tag2 - Should Be Equal As Strings ${res}[tags][0][address] 1!00001 + Should Be Equal As Strings ${res}[tags][0][name] tag1 + Should Be Equal As Strings ${res}[tags][0][address] 1!400002 Should Be Equal As Strings ${res}[tags][0][attribute] ${TAG_ATTRIBUTE_RW} - Should Be Equal As Strings ${res}[tags][0][type] ${TAG_TYPE_BIT} + Should Be Equal As Strings ${res}[tags][0][type] ${TAG_TYPE_INT32} + + Should Be Equal As Strings ${res}[tags][1][name] tag2 + Should Be Equal As Strings ${res}[tags][1][address] 1!00001 + Should Be Equal As Strings ${res}[tags][1][attribute] ${TAG_ATTRIBUTE_RW} + Should Be Equal As Strings ${res}[tags][1][type] ${TAG_TYPE_BIT} Delete tags, it should return success Del Tags modbus-node group "tag1","tag2"