diff --git a/include/neuron/msg.h b/include/neuron/msg.h index a7f34277d..7b69194dd 100644 --- a/include/neuron/msg.h +++ b/include/neuron/msg.h @@ -1001,6 +1001,12 @@ static inline void neu_tag_value_to_json(neu_resp_tag_value_meta_t *tag_value, tag_value->value.value.i8s.length; tag_json->value.val_array_int8.i8s = tag_value->value.value.i8s.i8s; break; + case NEU_TYPE_ARRAY_UINT8: + tag_json->t = NEU_JSON_ARRAY_UINT8; + tag_json->value.val_array_uint8.length = + tag_value->value.value.u8s.length; + tag_json->value.val_array_uint8.u8s = tag_value->value.value.u8s.u8s; + break; case NEU_TYPE_ARRAY_INT16: tag_json->t = NEU_JSON_ARRAY_INT16; tag_json->value.val_array_int16.length = @@ -1190,6 +1196,12 @@ neu_tag_value_to_json_paginate(neu_resp_tag_value_meta_paginate_t *tag_value, tag_value->value.value.i8s.length; tag_json->value.val_array_int8.i8s = tag_value->value.value.i8s.i8s; break; + case NEU_TYPE_ARRAY_UINT8: + tag_json->t = NEU_JSON_ARRAY_UINT8; + tag_json->value.val_array_uint8.length = + tag_value->value.value.u8s.length; + tag_json->value.val_array_uint8.u8s = tag_value->value.value.u8s.u8s; + break; case NEU_TYPE_ARRAY_INT16: tag_json->t = NEU_JSON_ARRAY_INT16; tag_json->value.val_array_int16.length = diff --git a/include/neuron/type.h b/include/neuron/type.h index 895c029e3..ec1bcfeb7 100644 --- a/include/neuron/type.h +++ b/include/neuron/type.h @@ -56,15 +56,16 @@ typedef enum { NEU_TYPE_DATA_AND_TIME = 21, NEU_TYPE_ARRAY_CHAR = 22, NEU_TYPE_ARRAY_INT8 = 23, - NEU_TYPE_ARRAY_INT16 = 24, - NEU_TYPE_ARRAY_UINT16 = 25, - NEU_TYPE_ARRAY_INT32 = 26, - NEU_TYPE_ARRAY_UINT32 = 27, - NEU_TYPE_ARRAY_INT64 = 28, - NEU_TYPE_ARRAY_UINT64 = 29, - NEU_TYPE_ARRAY_FLOAT = 30, - NEU_TYPE_ARRAY_DOUBLE = 31, - NEU_TYPE_ARRAY_BOOL = 32, + NEU_TYPE_ARRAY_UINT8 = 24, + NEU_TYPE_ARRAY_INT16 = 25, + NEU_TYPE_ARRAY_UINT16 = 26, + NEU_TYPE_ARRAY_INT32 = 27, + NEU_TYPE_ARRAY_UINT32 = 28, + NEU_TYPE_ARRAY_INT64 = 29, + NEU_TYPE_ARRAY_UINT64 = 30, + NEU_TYPE_ARRAY_FLOAT = 31, + NEU_TYPE_ARRAY_DOUBLE = 32, + NEU_TYPE_ARRAY_BOOL = 33, NEU_TYPE_CUSTOM = 40, } neu_type_e; @@ -117,6 +118,8 @@ inline static const char *neu_type_string(neu_type_e type) return "NEU_TYPE_ARRAY_CHAR"; case NEU_TYPE_ARRAY_INT8: return "NEU_TYPE_ARRAY_INT8"; + case NEU_TYPE_ARRAY_UINT8: + return "NEU_TYPE_ARRAY_UINT8"; case NEU_TYPE_ARRAY_INT16: return "NEU_TYPE_ARRAY_INT16"; case NEU_TYPE_ARRAY_UINT16: @@ -160,6 +163,11 @@ typedef struct { uint8_t length; } neu_value_array_int8_t; +typedef struct { + uint8_t u8s[NEU_VALUE_SIZE]; + uint8_t length; +} neu_value_array_uint8_t; + typedef struct { int16_t i16s[NEU_VALUE_SIZE]; uint8_t length; @@ -222,6 +230,7 @@ typedef union { neu_value_ptr_t ptr; json_t * json; neu_value_array_int8_t i8s; + neu_value_array_uint8_t u8s; neu_value_array_int16_t i16s; neu_value_array_uint16_t u16s; neu_value_array_int32_t i32s; diff --git a/src/adapter/driver/cache.c b/src/adapter/driver/cache.c index 14e35c387..31fd318d0 100644 --- a/src/adapter/driver/cache.c +++ b/src/adapter/driver/cache.c @@ -285,6 +285,18 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache, } } break; + case NEU_TYPE_ARRAY_UINT8: + if (elem->value_old.value.u8s.length != + value.value.u8s.length) { + elem->changed = true; + } else { + if (memcmp(elem->value_old.value.u8s.u8s, + value.value.u8s.u8s, + value.value.u8s.length) != 0) { + elem->changed = true; + } + } + break; case NEU_TYPE_ARRAY_INT16: if (elem->value_old.value.i16s.length != value.value.i16s.length) { @@ -492,6 +504,16 @@ void neu_driver_cache_update_change(neu_driver_cache_t *cache, } } break; + case NEU_TYPE_ARRAY_UINT8: + if (elem->value.value.u8s.length != value.value.u8s.length) { + elem->changed = true; + } else { + if (memcmp(elem->value.value.u8s.u8s, value.value.u8s.u8s, + value.value.u8s.length) != 0) { + elem->changed = true; + } + } + break; case NEU_TYPE_ARRAY_INT16: if (elem->value.value.i16s.length != value.value.i16s.length) { elem->changed = true; @@ -746,6 +768,11 @@ int neu_driver_cache_meta_get(neu_driver_cache_t *cache, const char *group, memcpy(value->value.value.i8s.i8s, elem->value.value.i8s.i8s, elem->value.value.i8s.length); break; + case NEU_TYPE_ARRAY_UINT8: + value->value.value.u8s.length = elem->value.value.u8s.length; + memcpy(value->value.value.u8s.u8s, elem->value.value.u8s.u8s, + elem->value.value.u8s.length); + break; case NEU_TYPE_ARRAY_INT16: value->value.value.i16s.length = elem->value.value.i16s.length; memcpy(value->value.value.i16s.i16s, elem->value.value.i16s.i16s, @@ -885,6 +912,11 @@ int neu_driver_cache_meta_get_changed(neu_driver_cache_t *cache, memcpy(value->value.value.i8s.i8s, elem->value.value.i8s.i8s, elem->value.value.i8s.length); break; + case NEU_TYPE_ARRAY_UINT8: + value->value.value.u8s.length = elem->value.value.u8s.length; + memcpy(value->value.value.u8s.u8s, elem->value.value.u8s.u8s, + elem->value.value.u8s.length); + break; case NEU_TYPE_ARRAY_INT16: value->value.value.i16s.length = elem->value.value.i16s.length; memcpy(value->value.value.i16s.i16s, elem->value.value.i16s.i16s, diff --git a/src/adapter/driver/driver.c b/src/adapter/driver/driver.c index 049cd7315..4961d7c78 100644 --- a/src/adapter/driver/driver.c +++ b/src/adapter/driver/driver.c @@ -1119,6 +1119,8 @@ int neu_adapter_driver_write_tags(neu_adapter_driver_t *driver, } if (tag->type == NEU_TYPE_BYTES) { if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->tags[i].value.value.bytes.length = + cmd->tags[i].value.value.i64s.length; for (int j = 0; j < cmd->tags[i].value.value.i64s.length; j++) { cmd->tags[i].value.value.bytes.bytes[j] = @@ -1132,6 +1134,8 @@ int neu_adapter_driver_write_tags(neu_adapter_driver_t *driver, } if (tag->type == NEU_TYPE_ARRAY_INT8) { if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->tags[i].value.value.i8s.length = + cmd->tags[i].value.value.i64s.length; for (int j = 0; j < cmd->tags[i].value.value.i64s.length; j++) { cmd->tags[i].value.value.i8s.i8s[j] = @@ -1143,8 +1147,25 @@ int neu_adapter_driver_write_tags(neu_adapter_driver_t *driver, } } } + if (tag->type == NEU_TYPE_ARRAY_UINT8) { + if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->tags[i].value.value.u8s.length = + cmd->tags[i].value.value.i64s.length; + for (int j = 0; j < cmd->tags[i].value.value.i64s.length; + j++) { + cmd->tags[i].value.value.u8s.u8s[j] = + (int8_t) cmd->tags[i].value.value.i64s.i64s[j]; + } + for (int j = cmd->tags[i].value.value.i64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->tags[i].value.value.u8s.u8s[j] = 0; + } + } + } if (tag->type == NEU_TYPE_ARRAY_INT16) { if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->tags[i].value.value.i16s.length = + cmd->tags[i].value.value.i64s.length; for (int j = 0; j < cmd->tags[i].value.value.i64s.length; j++) { cmd->tags[i].value.value.i16s.i16s[j] = @@ -1158,6 +1179,8 @@ int neu_adapter_driver_write_tags(neu_adapter_driver_t *driver, } if (tag->type == NEU_TYPE_ARRAY_UINT16) { if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->tags[i].value.value.u16s.length = + cmd->tags[i].value.value.i64s.length; for (int j = 0; j < cmd->tags[i].value.value.i64s.length; j++) { cmd->tags[i].value.value.u16s.u16s[j] = @@ -1171,6 +1194,8 @@ int neu_adapter_driver_write_tags(neu_adapter_driver_t *driver, } if (tag->type == NEU_TYPE_ARRAY_INT32) { if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->tags[i].value.value.i32s.length = + cmd->tags[i].value.value.i64s.length; for (int j = 0; j < cmd->tags[i].value.value.i64s.length; j++) { cmd->tags[i].value.value.i32s.i32s[j] = @@ -1184,6 +1209,8 @@ int neu_adapter_driver_write_tags(neu_adapter_driver_t *driver, } if (tag->type == NEU_TYPE_ARRAY_UINT32) { if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->tags[i].value.value.u32s.length = + cmd->tags[i].value.value.i64s.length; for (int j = 0; j < cmd->tags[i].value.value.i64s.length; j++) { cmd->tags[i].value.value.u32s.u32s[j] = @@ -1197,6 +1224,8 @@ int neu_adapter_driver_write_tags(neu_adapter_driver_t *driver, } if (tag->type == NEU_TYPE_ARRAY_UINT64) { if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->tags[i].value.value.u64s.length = + cmd->tags[i].value.value.i64s.length; for (int j = 0; j < cmd->tags[i].value.value.i64s.length; j++) { cmd->tags[i].value.value.u64s.u64s[i] = @@ -1210,6 +1239,8 @@ int neu_adapter_driver_write_tags(neu_adapter_driver_t *driver, } if (tag->type == NEU_TYPE_ARRAY_FLOAT) { if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_DOUBLE) { + cmd->tags[i].value.value.f32s.length = + cmd->tags[i].value.value.f64s.length; for (int j = 0; j < cmd->tags[i].value.value.f64s.length; j++) { cmd->tags[i].value.value.f32s.f32s[j] = @@ -1221,6 +1252,8 @@ int neu_adapter_driver_write_tags(neu_adapter_driver_t *driver, } } if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->tags[i].value.value.f32s.length = + cmd->tags[i].value.value.i64s.length; for (int j = 0; j < cmd->tags[i].value.value.f64s.length; j++) { cmd->tags[i].value.value.f32s.f32s[j] = @@ -1234,6 +1267,8 @@ int neu_adapter_driver_write_tags(neu_adapter_driver_t *driver, } if (tag->type == NEU_TYPE_ARRAY_DOUBLE) { if (cmd->tags[i].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->tags[i].value.value.f64s.length = + cmd->tags[i].value.value.i64s.length; for (int j = 0; j < cmd->tags[i].value.value.i64s.length; j++) { cmd->tags[i].value.value.f64s.f64s[j] = @@ -1360,6 +1395,8 @@ int neu_adapter_driver_write_gtags(neu_adapter_driver_t *driver, if (tag->type == NEU_TYPE_BYTES) { if (cmd->groups[i].tags[k].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->groups[i].tags[k].value.value.bytes.length = + cmd->groups[i].tags[k].value.value.i64s.length; for (int j = 0; j < cmd->groups[i].tags[k].value.value.i64s.length; j++) { @@ -1379,6 +1416,8 @@ int neu_adapter_driver_write_gtags(neu_adapter_driver_t *driver, if (tag->type == NEU_TYPE_ARRAY_INT8) { if (cmd->groups[i].tags[k].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->groups[i].tags[k].value.value.i8s.length = + cmd->groups[i].tags[k].value.value.i64s.length; for (int j = 0; j < cmd->groups[i].tags[k].value.value.i64s.length; j++) { @@ -1394,9 +1433,31 @@ int neu_adapter_driver_write_gtags(neu_adapter_driver_t *driver, } } } + if (tag->type == NEU_TYPE_ARRAY_UINT8) { + if (cmd->groups[i].tags[k].value.type == + NEU_TYPE_ARRAY_INT64) { + cmd->groups[i].tags[k].value.value.u8s.length = + cmd->groups[i].tags[k].value.value.i64s.length; + for (int j = 0; + j < cmd->groups[i].tags[k].value.value.i64s.length; + j++) { + cmd->groups[i].tags[k].value.value.u8s.u8s[j] = + (int8_t) cmd->groups[i] + .tags[k] + .value.value.i64s.i64s[j]; + } + for (int j = + cmd->groups[i].tags[k].value.value.i64s.length; + j < NEU_VALUE_SIZE; j++) { + cmd->groups[i].tags[k].value.value.u8s.u8s[j] = 0; + } + } + } if (tag->type == NEU_TYPE_ARRAY_INT16) { if (cmd->groups[i].tags[k].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->groups[i].tags[k].value.value.i16s.length = + cmd->groups[i].tags[k].value.value.i64s.length; for (int j = 0; j < cmd->groups[i].tags[k].value.value.i64s.length; j++) { @@ -1415,6 +1476,8 @@ int neu_adapter_driver_write_gtags(neu_adapter_driver_t *driver, if (tag->type == NEU_TYPE_ARRAY_UINT16) { if (cmd->groups[i].tags[k].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->groups[i].tags[k].value.value.u16s.length = + cmd->groups[i].tags[k].value.value.i64s.length; for (int j = 0; j < cmd->groups[i].tags[k].value.value.i64s.length; j++) { @@ -1433,6 +1496,8 @@ int neu_adapter_driver_write_gtags(neu_adapter_driver_t *driver, if (tag->type == NEU_TYPE_ARRAY_INT32) { if (cmd->groups[i].tags[k].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->groups[i].tags[k].value.value.i32s.length = + cmd->groups[i].tags[k].value.value.i64s.length; for (int j = 0; j < cmd->groups[i].tags[k].value.value.i64s.length; j++) { @@ -1451,6 +1516,8 @@ int neu_adapter_driver_write_gtags(neu_adapter_driver_t *driver, if (tag->type == NEU_TYPE_ARRAY_UINT32) { if (cmd->groups[i].tags[k].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->groups[i].tags[k].value.value.u32s.length = + cmd->groups[i].tags[k].value.value.i64s.length; for (int j = 0; j < cmd->groups[i].tags[k].value.value.i64s.length; j++) { @@ -1469,6 +1536,8 @@ int neu_adapter_driver_write_gtags(neu_adapter_driver_t *driver, if (tag->type == NEU_TYPE_ARRAY_UINT64) { if (cmd->groups[i].tags[k].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->groups[i].tags[k].value.value.u64s.length = + cmd->groups[i].tags[k].value.value.i64s.length; for (int j = 0; j < cmd->groups[i].tags[k].value.value.i64s.length; j++) { @@ -1487,6 +1556,8 @@ int neu_adapter_driver_write_gtags(neu_adapter_driver_t *driver, if (tag->type == NEU_TYPE_ARRAY_FLOAT) { if (cmd->groups[i].tags[k].value.type == NEU_TYPE_ARRAY_DOUBLE) { + cmd->groups[i].tags[k].value.value.f32s.length = + cmd->groups[i].tags[k].value.value.f64s.length; for (int j = 0; j < cmd->groups[i].tags[k].value.value.f64s.length; j++) { @@ -1503,6 +1574,8 @@ int neu_adapter_driver_write_gtags(neu_adapter_driver_t *driver, } if (cmd->groups[i].tags[k].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->groups[i].tags[k].value.value.f32s.length = + cmd->groups[i].tags[k].value.value.i64s.length; for (int j = 0; j < cmd->groups[i].tags[k].value.value.f64s.length; j++) { @@ -1521,6 +1594,8 @@ int neu_adapter_driver_write_gtags(neu_adapter_driver_t *driver, if (tag->type == NEU_TYPE_ARRAY_DOUBLE) { if (cmd->groups[i].tags[k].value.type == NEU_TYPE_ARRAY_INT64) { + cmd->groups[i].tags[k].value.value.f64s.length = + cmd->groups[i].tags[k].value.value.i64s.length; for (int j = 0; j < cmd->groups[i].tags[k].value.value.i64s.length; j++) { @@ -1640,6 +1715,7 @@ int neu_adapter_driver_write_tag(neu_adapter_driver_t *driver, } if (tag->type == NEU_TYPE_BYTES) { if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + cmd->value.value.bytes.length = cmd->value.value.i64s.length; for (int i = 0; i < cmd->value.value.i64s.length; i++) { cmd->value.value.bytes.bytes[i] = (uint8_t) cmd->value.value.i64s.i64s[i]; @@ -1652,6 +1728,7 @@ int neu_adapter_driver_write_tag(neu_adapter_driver_t *driver, } if (tag->type == NEU_TYPE_ARRAY_INT8) { if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + cmd->value.value.i8s.length = cmd->value.value.i64s.length; for (int i = 0; i < cmd->value.value.i64s.length; i++) { cmd->value.value.i8s.i8s[i] = (int8_t) cmd->value.value.i64s.i64s[i]; @@ -1662,8 +1739,22 @@ int neu_adapter_driver_write_tag(neu_adapter_driver_t *driver, } } } + if (tag->type == NEU_TYPE_ARRAY_UINT8) { + if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + cmd->value.value.u8s.length = cmd->value.value.i64s.length; + for (int i = 0; i < cmd->value.value.i64s.length; i++) { + cmd->value.value.u8s.u8s[i] = + (uint8_t) cmd->value.value.i64s.i64s[i]; + } + for (int i = cmd->value.value.i64s.length; i < NEU_VALUE_SIZE; + i++) { + cmd->value.value.u8s.u8s[i] = 0; + } + } + } if (tag->type == NEU_TYPE_ARRAY_INT16) { if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + cmd->value.value.i16s.length = cmd->value.value.i64s.length; for (int i = 0; i < cmd->value.value.i64s.length; i++) { cmd->value.value.i16s.i16s[i] = (int16_t) cmd->value.value.i64s.i64s[i]; @@ -1676,6 +1767,7 @@ int neu_adapter_driver_write_tag(neu_adapter_driver_t *driver, } if (tag->type == NEU_TYPE_ARRAY_UINT16) { if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + cmd->value.value.u16s.length = cmd->value.value.i64s.length; for (int i = 0; i < cmd->value.value.i64s.length; i++) { cmd->value.value.u16s.u16s[i] = (uint16_t) cmd->value.value.i64s.i64s[i]; @@ -1688,6 +1780,7 @@ int neu_adapter_driver_write_tag(neu_adapter_driver_t *driver, } if (tag->type == NEU_TYPE_ARRAY_INT32) { if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + cmd->value.value.i32s.length = cmd->value.value.i64s.length; for (int i = 0; i < cmd->value.value.i64s.length; i++) { cmd->value.value.i32s.i32s[i] = (int32_t) cmd->value.value.i64s.i64s[i]; @@ -1700,6 +1793,7 @@ int neu_adapter_driver_write_tag(neu_adapter_driver_t *driver, } if (tag->type == NEU_TYPE_ARRAY_UINT32) { if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + cmd->value.value.u32s.length = cmd->value.value.i64s.length; for (int i = 0; i < cmd->value.value.i64s.length; i++) { cmd->value.value.u32s.u32s[i] = (uint32_t) cmd->value.value.i64s.i64s[i]; @@ -1712,6 +1806,7 @@ int neu_adapter_driver_write_tag(neu_adapter_driver_t *driver, } if (tag->type == NEU_TYPE_ARRAY_UINT64) { if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + cmd->value.value.u64s.length = cmd->value.value.i64s.length; for (int i = 0; i < cmd->value.value.i64s.length; i++) { cmd->value.value.u64s.u64s[i] = (uint64_t) cmd->value.value.i64s.i64s[i]; @@ -1724,6 +1819,7 @@ int neu_adapter_driver_write_tag(neu_adapter_driver_t *driver, } if (tag->type == NEU_TYPE_ARRAY_FLOAT) { if (cmd->value.type == NEU_TYPE_ARRAY_DOUBLE) { + cmd->value.value.f32s.length = cmd->value.value.f64s.length; for (int i = 0; i < cmd->value.value.f64s.length; i++) { cmd->value.value.f32s.f32s[i] = (float) cmd->value.value.f64s.f64s[i]; @@ -1734,6 +1830,7 @@ int neu_adapter_driver_write_tag(neu_adapter_driver_t *driver, } } if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + cmd->value.value.f32s.length = cmd->value.value.i64s.length; for (int i = 0; i < cmd->value.value.f64s.length; i++) { cmd->value.value.f32s.f32s[i] = (float) cmd->value.value.i64s.i64s[i]; @@ -1746,6 +1843,7 @@ int neu_adapter_driver_write_tag(neu_adapter_driver_t *driver, } if (tag->type == NEU_TYPE_ARRAY_DOUBLE) { if (cmd->value.type == NEU_TYPE_ARRAY_INT64) { + cmd->value.value.f64s.length = cmd->value.value.i64s.length; for (int i = 0; i < cmd->value.value.i64s.length; i++) { cmd->value.value.f64s.f64s[i] = (double) cmd->value.value.i64s.i64s[i];