remove the range check for bias

This commit is contained in:
fengzero
2026-06-22 02:24:44 +00:00
parent b3497ff7cc
commit 07040cbc2e
3 changed files with 63 additions and 98 deletions
+63
View File
@@ -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;
-4
View File
@@ -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;
-94
View File
@@ -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",