Merge pull request #1921 from eeff/v2.8

Pick to v2.8 feat(core): add NEU_TYPE_TIME and NEU_TYPE_DATA_AND_TIME
This commit is contained in:
fengzeroz
2024-03-22 16:27:50 +08:00
committed by GitHub
8 changed files with 91 additions and 21 deletions
+2
View File
@@ -859,6 +859,8 @@ static inline void neu_tag_value_to_json(neu_resp_tag_value_meta_t *tag_value,
tag_json->value.val_bit = tag_value->value.value.u8;
break;
case NEU_TYPE_STRING:
case NEU_TYPE_TIME:
case NEU_TYPE_DATA_AND_TIME:
tag_json->t = NEU_JSON_STR;
tag_json->value.val_str = tag_value->value.value.str;
break;
+28 -20
View File
@@ -31,25 +31,27 @@ extern "C" {
#include <stdio.h>
typedef enum {
NEU_TYPE_INT8 = 1,
NEU_TYPE_UINT8 = 2,
NEU_TYPE_INT16 = 3,
NEU_TYPE_UINT16 = 4,
NEU_TYPE_INT32 = 5,
NEU_TYPE_UINT32 = 6,
NEU_TYPE_INT64 = 7,
NEU_TYPE_UINT64 = 8,
NEU_TYPE_FLOAT = 9,
NEU_TYPE_DOUBLE = 10,
NEU_TYPE_BIT = 11,
NEU_TYPE_BOOL = 12,
NEU_TYPE_STRING = 13,
NEU_TYPE_BYTES = 14,
NEU_TYPE_ERROR = 15,
NEU_TYPE_WORD = 16,
NEU_TYPE_DWORD = 17,
NEU_TYPE_LWORD = 18,
NEU_TYPE_PTR = 19,
NEU_TYPE_INT8 = 1,
NEU_TYPE_UINT8 = 2,
NEU_TYPE_INT16 = 3,
NEU_TYPE_UINT16 = 4,
NEU_TYPE_INT32 = 5,
NEU_TYPE_UINT32 = 6,
NEU_TYPE_INT64 = 7,
NEU_TYPE_UINT64 = 8,
NEU_TYPE_FLOAT = 9,
NEU_TYPE_DOUBLE = 10,
NEU_TYPE_BIT = 11,
NEU_TYPE_BOOL = 12,
NEU_TYPE_STRING = 13,
NEU_TYPE_BYTES = 14,
NEU_TYPE_ERROR = 15,
NEU_TYPE_WORD = 16,
NEU_TYPE_DWORD = 17,
NEU_TYPE_LWORD = 18,
NEU_TYPE_PTR = 19,
NEU_TYPE_TIME = 20,
NEU_TYPE_DATA_AND_TIME = 21,
} neu_type_e;
inline static const char *neu_type_string(neu_type_e type)
@@ -93,6 +95,10 @@ inline static const char *neu_type_string(neu_type_e type)
return "NEU_TYPE_LWORD";
case NEU_TYPE_PTR:
return "NEU_TYPE_PTR";
case NEU_TYPE_TIME:
return "NEU_TYPE_TIME";
case NEU_TYPE_DATA_AND_TIME:
return "NEU_TYPE_DATA_AND_TIME";
}
return "";
@@ -188,7 +194,9 @@ static inline char *neu_value_str(neu_type_e type, neu_value_u value)
snprintf(str, sizeof(str), "type: %s, value: %u", neu_type_string(type),
value.boolean);
break;
case NEU_TYPE_STRING: {
case NEU_TYPE_STRING:
case NEU_TYPE_TIME:
case NEU_TYPE_DATA_AND_TIME: {
snprintf(str, sizeof(str), "type: %s, value: %c%c%c",
neu_type_string(type), value.str[0], value.str[1],
value.str[2]);
+43
View File
@@ -0,0 +1,43 @@
/**
* 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,
type INTEGER NOT NULL check (type BETWEEN 0 AND 21),
description TEXT NULL check (length (description) <= 512),
value TEXT,
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 * FROM temp_tags;
DROP TABLE temp_tags;
COMMIT;
+6
View File
@@ -157,6 +157,8 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache,
case NEU_TYPE_BIT:
case NEU_TYPE_BOOL:
case NEU_TYPE_STRING:
case NEU_TYPE_TIME:
case NEU_TYPE_DATA_AND_TIME:
case NEU_TYPE_WORD:
case NEU_TYPE_DWORD:
case NEU_TYPE_LWORD:
@@ -299,6 +301,8 @@ int neu_driver_cache_meta_get(neu_driver_cache_t *cache, const char *group,
value->value.value.boolean = elem->value.value.boolean;
break;
case NEU_TYPE_STRING:
case NEU_TYPE_TIME:
case NEU_TYPE_DATA_AND_TIME:
memcpy(value->value.value.str, elem->value.value.str,
sizeof(elem->value.value.str));
break;
@@ -381,6 +385,8 @@ int neu_driver_cache_meta_get_changed(neu_driver_cache_t *cache,
value->value.value.boolean = elem->value.value.boolean;
break;
case NEU_TYPE_STRING:
case NEU_TYPE_TIME:
case NEU_TYPE_DATA_AND_TIME:
memcpy(value->value.value.str, elem->value.value.str,
sizeof(elem->value.value.str));
break;
+2
View File
@@ -472,6 +472,8 @@ static void fix_value(neu_datatag_t *tag, neu_type_e value_type,
switch (tag->type) {
case NEU_TYPE_BOOL:
case NEU_TYPE_STRING:
case NEU_TYPE_TIME:
case NEU_TYPE_DATA_AND_TIME:
case NEU_TYPE_BYTES:
break;
case NEU_TYPE_BIT:
+6 -1
View File
@@ -523,6 +523,8 @@ int neu_tag_get_static_value_json(neu_datatag_t *tag, neu_json_type_e *t,
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;
@@ -625,7 +627,8 @@ int neu_tag_set_static_value_json(neu_datatag_t *tag, neu_json_type_e t,
break;
}
case NEU_JSON_STR: {
if (NEU_TYPE_STRING == tag->type) {
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;
@@ -695,6 +698,8 @@ char *neu_tag_dump_static_value(const neu_datatag_t *tag)
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:
+2
View File
@@ -579,6 +579,8 @@ void neu_json_metas_to_json(neu_tag_meta_t *metas, int n_meta,
json_tag->metas[k].value.val_bit = metas[k].value.value.u8;
break;
case NEU_TYPE_STRING:
case NEU_TYPE_TIME:
case NEU_TYPE_DATA_AND_TIME:
json_tag->metas[k].t = NEU_JSON_STR;
json_tag->metas[k].value.val_str = metas[k].value.value.str;
break;
+2
View File
@@ -199,6 +199,8 @@ int neu_json_tag_check_type(neu_json_tag_t *tag)
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;
}