From 07040cbc2e319dfbe34ac27c77d9678d72572288 Mon Sep 17 00:00:00 2001 From: fengzero Date: Mon, 22 Jun 2026 02:24:44 +0000 Subject: [PATCH] remove the range check for bias --- persistence/0121_2.15.1_tag.sql | 63 ++++++++++++++++++++++ src/adapter/driver/driver.c | 4 -- tests/ft/tag/test_tag.py | 94 --------------------------------- 3 files changed, 63 insertions(+), 98 deletions(-) create mode 100644 persistence/0121_2.15.1_tag.sql diff --git a/persistence/0121_2.15.1_tag.sql b/persistence/0121_2.15.1_tag.sql new file mode 100644 index 00000000..b4f800ab --- /dev/null +++ b/persistence/0121_2.15.1_tag.sql @@ -0,0 +1,63 @@ +/** +* NEURON IIoT System for Industry 4.0 +* Copyright (C) 2020-2024 EMQ Technologies Co., Ltd All rights reserved. +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU Lesser General Public +* License as published by the Free Software Foundation; either +* version 3 of the License, or (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +* Lesser General Public License for more details. +* +* You should have received a copy of the GNU Lesser General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +**/ +BEGIN TRANSACTION; + +ALTER TABLE tags RENAME TO temp_tags; + +CREATE TABLE + IF NOT EXISTS tags ( + driver_name TEXT NOT NULL, + group_name TEXT NOT NULL, + name TEXT NULL check (length (name) <= 128), + address TEXT NULL check (length (address) <= 128), + attribute INTEGER NOT NULL check (attribute BETWEEN 0 AND 15), + precision INTEGER NOT NULL check (precision BETWEEN 0 AND 17), + decimal REAL NOT NULL, + bias REAL NOT NULL, + type INTEGER NOT NULL check (type BETWEEN 0 AND 34 OR type = 40), + description TEXT NULL check (length (description) <= 512), + value TEXT, + format TEXT, + unit TEXT NULL check (length(unit) <= 128), + UNIQUE (driver_name, group_name, name), + FOREIGN KEY (driver_name, group_name) REFERENCES groups (driver_name, name) ON UPDATE CASCADE ON DELETE CASCADE + ); + +INSERT INTO + tags +SELECT + driver_name, + group_name, + name, + address, + attribute, + precision, + decimal, + bias, + type, + description, + value, + format, + unit +FROM + temp_tags; + +DROP TABLE temp_tags; + +COMMIT; diff --git a/src/adapter/driver/driver.c b/src/adapter/driver/driver.c index b7c795c1..9b445626 100644 --- a/src/adapter/driver/driver.c +++ b/src/adapter/driver/driver.c @@ -2211,10 +2211,6 @@ int neu_adapter_driver_validate_tag(neu_adapter_driver_t *driver, 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; diff --git a/tests/ft/tag/test_tag.py b/tests/ft/tag/test_tag.py index 9c64979c..074c898f 100644 --- a/tests/ft/tag/test_tag.py +++ b/tests/ft/tag/test_tag.py @@ -695,48 +695,6 @@ class TestTag: node="modbus-tcp", group="group1", tags=["hold_int16_bias"] ) - @description( - given="node group", - when="add a tag with bias out of range", - then="add fail", - ) - def test_add_tag_with_bias_out_of_range(self): - tag = { - **hold_int16_bias[0], - "bias": 10000, - } - try: - response = api.add_tags( - node="modbus-tcp", group="group1", tags=[tag] - ) - assert 400 == response.status_code - assert ( - NEU_ERR_TAG_BIAS_INVALID == response.json()["error"] - ) - finally: - api.del_tags(node="modbus-tcp", group="group1", tags=[tag["name"]]) - - @description( - given="node group", - when="add a tag with bias and write attr", - then="add fail", - ) - def test_add_tag_with_bias_and_write_attr(self): - tag = { - **hold_int16_bias[0], - "attribute": NEU_TAG_ATTRIBUTE_RW, - } - try: - response = api.add_tags( - node="modbus-tcp", group="group1", tags=[tag] - ) - assert 400 == response.status_code - assert ( - NEU_ERR_TAG_BIAS_INVALID == response.json()["error"] - ) - finally: - api.del_tags(node="modbus-tcp", group="group1", tags=[tag["name"]]) - @description( given="node group", when="add a tag with bias and non-numeral type", @@ -800,58 +758,6 @@ class TestTag: finally: api.del_tags(node="modbus-tcp", group="group1", tags=[tag["name"]]) - @description( - given="node group tag with bias", - when="update tag bias out of range", - then="update fail", - ) - def test_update_tag_with_bias_out_of_range(self): - api.add_tags_check( - node="modbus-tcp", group="group1", tags=hold_int16_bias - ) - - tag = { - **hold_int16_bias[0], - "bias": -1001, - } - try: - response = api.update_tags( - node="modbus-tcp", group="group1", tags=[tag] - ) - assert 400 == response.status_code - assert ( - NEU_ERR_TAG_BIAS_INVALID == response.json()["error"] - ) - - finally: - api.del_tags(node="modbus-tcp", group="group1", tags=[tag["name"]]) - - @description( - given="node group tag with bias", - when="update tag with write attribute", - then="update fail", - ) - def test_update_tag_with_bias_and_write_attr(self): - api.add_tags_check( - node="modbus-tcp", group="group1", tags=hold_int16_bias - ) - - tag = { - **hold_int16_bias[0], - "attribute": NEU_TAG_ATTRIBUTE_RW, - } - try: - response = api.update_tags( - node="modbus-tcp", group="group1", tags=[tag] - ) - assert 400 == response.status_code - assert ( - NEU_ERR_TAG_BIAS_INVALID == response.json()["error"] - ) - - finally: - api.del_tags(node="modbus-tcp", group="group1", tags=[tag["name"]]) - @description( given="node group tag with bias", when="update tag with bad type",