From c59d557535591b27baabd6a79b9a25efec831b41 Mon Sep 17 00:00:00 2001 From: gc87 Date: Tue, 8 Oct 2024 11:05:42 +0800 Subject: [PATCH 1/3] fix: add attributes field for update meta --- include/neuron/define.h | 2 +- src/parser/neu_json_rw.c | 15 +++++++++++---- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/include/neuron/define.h b/include/neuron/define.h index 8c3837ba7..dd7e3668b 100644 --- a/include/neuron/define.h +++ b/include/neuron/define.h @@ -53,7 +53,7 @@ #define NEU_MSG_MAX_SIZE 2048 #define NEU_TAG_META_LENGTH 20 -#define NEU_TAG_META_SIZE 8 +#define NEU_TAG_META_SIZE 32 #define NEU_LOG_LEVEL_DEBUG "debug" #define NEU_LOG_LEVEL_INFO "info" diff --git a/src/parser/neu_json_rw.c b/src/parser/neu_json_rw.c index f14e7e394..579aeb2fb 100644 --- a/src/parser/neu_json_rw.c +++ b/src/parser/neu_json_rw.c @@ -157,14 +157,21 @@ int neu_json_encode_read_paginate_resp(void *json_object, void *param) } } + void *attributes_object = neu_json_encode_new(); for (int k = 0; k < p_tag->n_meta; k++) { - tag_elems[if_precision + 9 + k].name = p_tag->metas[k].name; - tag_elems[if_precision + 9 + k].t = p_tag->metas[k].t; - tag_elems[if_precision + 9 + k].v = p_tag->metas[k].value; + neu_json_elem_t meta_elem = { 0 }; + meta_elem.name = p_tag->metas[k].name; + meta_elem.t = p_tag->metas[k].t; + meta_elem.v = p_tag->metas[k].value; + neu_json_encode_field(attributes_object, &meta_elem, 1); } + tag_elems[if_precision + 9].name = "attributes"; + tag_elems[if_precision + 9].t = NEU_JSON_OBJECT; + tag_elems[if_precision + 9].v.val_object = attributes_object; + tag_array = neu_json_encode_array(tag_array, tag_elems, - 9 + if_precision + p_tag->n_meta); + 10 + if_precision); free(p_tag->datatag.name); free(p_tag->datatag.address); From a8ba92945706aea5f2d52447ec0c2b05e789058d Mon Sep 17 00:00:00 2001 From: gc87 Date: Mon, 28 Oct 2024 17:44:09 +0800 Subject: [PATCH 2/3] feat: cyclic reporting for 61850 gi --- src/adapter/driver/driver.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/adapter/driver/driver.c b/src/adapter/driver/driver.c index d1374b15d..24b65bc16 100644 --- a/src/adapter/driver/driver.c +++ b/src/adapter/driver/driver.c @@ -99,7 +99,7 @@ static void read_group_paginate(int64_t timestamp, int64_t timeout, neu_tag_cache_type_e cache_type, neu_driver_cache_t *cache, const char *group, UT_array *tags, UT_array *tag_values); -static void read_report_group(int64_t timestamp, int64_t timeout, +static void read_report_group(bool sub, int64_t timestamp, int64_t timeout, neu_tag_cache_type_e cache_type, neu_driver_cache_t *cache, const char *group, UT_array *tags, UT_array *tag_values); @@ -328,7 +328,7 @@ static void update_im(neu_adapter_t *adapter, const char *group, data->group = strdup(group); utarray_new(data->tags, neu_resp_tag_value_meta_icd()); - read_report_group(global_timestamp, 0, + read_report_group(true,global_timestamp, 0, neu_adapter_get_tag_cache_type(&driver->adapter), driver->cache, group, tags, data->tags); @@ -2106,7 +2106,7 @@ static int report_callback(void *usr_data) } } - read_report_group(global_timestamp, + read_report_group(false, global_timestamp, neu_group_get_interval(group->group) * NEU_DRIVER_TAG_CACHE_EXPIRE_TIME, neu_adapter_get_tag_cache_type(&group->driver->adapter), @@ -2348,7 +2348,7 @@ static int read_callback(void *usr_data) return 0; } -static void read_report_group(int64_t timestamp, int64_t timeout, +static void read_report_group(bool sub, int64_t timestamp, int64_t timeout, neu_tag_cache_type_e cache_type, neu_driver_cache_t *cache, const char *group, UT_array *tags, UT_array *tag_values) @@ -2358,7 +2358,7 @@ static void read_report_group(int64_t timestamp, int64_t timeout, neu_driver_cache_value_t value = { 0 }; neu_resp_tag_value_meta_t tag_value = { 0 }; - if (neu_tag_attribute_test(tag, NEU_ATTRIBUTE_SUBSCRIBE)) { + if (sub && neu_tag_attribute_test(tag, NEU_ATTRIBUTE_SUBSCRIBE)) { if (neu_driver_cache_meta_get_changed(cache, group, tag->name, &value, tag_value.metas, NEU_TAG_META_SIZE) != 0) { From 08eea75ac8d5417ea52e162c656f8d137a070f0d Mon Sep 17 00:00:00 2001 From: gc87 Date: Tue, 29 Oct 2024 18:58:42 +0800 Subject: [PATCH 3/3] fix(cid): co's address missing prefix and inst --- include/neuron/define.h | 4 +++- include/neuron/utils/cid.h | 2 ++ src/adapter/driver/driver.c | 10 +++++----- src/parser/neu_json_rw.c | 8 ++++---- src/utils/cid.c | 31 +++++++++++++++++++++++++++---- 5 files changed, 41 insertions(+), 14 deletions(-) diff --git a/include/neuron/define.h b/include/neuron/define.h index dd7e3668b..004e92b50 100644 --- a/include/neuron/define.h +++ b/include/neuron/define.h @@ -64,11 +64,13 @@ #define NEU_CID_LNCLASS_LEN 12 #define NEU_CID_LNTYPE_LEN 32 +#define NEU_CID_LNPREFIX_LEN 10 +#define NEU_CID_LNINST_LEN 2 #define NEU_CID_IED_NAME_LEN 32 #define NEU_CID_LDEVICE_LEN 32 #define NEU_CID_LNO_NAME_LEN 32 #define NEU_CID_LNO_TYPE_LEN 32 -#define NEU_CID_INST_LEN 32 +#define NEU_CID_INST_LEN 16 #define NEU_CID_SDI_NAME_LEN 16 #define NEU_CID_DO_NAME_LEN 32 #define NEU_CID_DO_ID_LEN 32 diff --git a/include/neuron/utils/cid.h b/include/neuron/utils/cid.h index 2b7ce7647..75bb0151b 100644 --- a/include/neuron/utils/cid.h +++ b/include/neuron/utils/cid.h @@ -62,6 +62,8 @@ typedef struct { typedef struct { char lnclass[NEU_CID_LNCLASS_LEN]; char lntype[NEU_CID_LNTYPE_LEN]; + char lnprefix[NEU_CID_LNPREFIX_LEN]; + char lninst[NEU_CID_LNINST_LEN]; cid_dataset_t *datasets; int n_datasets; diff --git a/src/adapter/driver/driver.c b/src/adapter/driver/driver.c index 24b65bc16..d1374b15d 100644 --- a/src/adapter/driver/driver.c +++ b/src/adapter/driver/driver.c @@ -99,7 +99,7 @@ static void read_group_paginate(int64_t timestamp, int64_t timeout, neu_tag_cache_type_e cache_type, neu_driver_cache_t *cache, const char *group, UT_array *tags, UT_array *tag_values); -static void read_report_group(bool sub, int64_t timestamp, int64_t timeout, +static void read_report_group(int64_t timestamp, int64_t timeout, neu_tag_cache_type_e cache_type, neu_driver_cache_t *cache, const char *group, UT_array *tags, UT_array *tag_values); @@ -328,7 +328,7 @@ static void update_im(neu_adapter_t *adapter, const char *group, data->group = strdup(group); utarray_new(data->tags, neu_resp_tag_value_meta_icd()); - read_report_group(true,global_timestamp, 0, + read_report_group(global_timestamp, 0, neu_adapter_get_tag_cache_type(&driver->adapter), driver->cache, group, tags, data->tags); @@ -2106,7 +2106,7 @@ static int report_callback(void *usr_data) } } - read_report_group(false, global_timestamp, + read_report_group(global_timestamp, neu_group_get_interval(group->group) * NEU_DRIVER_TAG_CACHE_EXPIRE_TIME, neu_adapter_get_tag_cache_type(&group->driver->adapter), @@ -2348,7 +2348,7 @@ static int read_callback(void *usr_data) return 0; } -static void read_report_group(bool sub, int64_t timestamp, int64_t timeout, +static void read_report_group(int64_t timestamp, int64_t timeout, neu_tag_cache_type_e cache_type, neu_driver_cache_t *cache, const char *group, UT_array *tags, UT_array *tag_values) @@ -2358,7 +2358,7 @@ static void read_report_group(bool sub, int64_t timestamp, int64_t timeout, neu_driver_cache_value_t value = { 0 }; neu_resp_tag_value_meta_t tag_value = { 0 }; - if (sub && neu_tag_attribute_test(tag, NEU_ATTRIBUTE_SUBSCRIBE)) { + if (neu_tag_attribute_test(tag, NEU_ATTRIBUTE_SUBSCRIBE)) { if (neu_driver_cache_meta_get_changed(cache, group, tag->name, &value, tag_value.metas, NEU_TAG_META_SIZE) != 0) { diff --git a/src/parser/neu_json_rw.c b/src/parser/neu_json_rw.c index 579aeb2fb..6504e2cab 100644 --- a/src/parser/neu_json_rw.c +++ b/src/parser/neu_json_rw.c @@ -166,12 +166,12 @@ int neu_json_encode_read_paginate_resp(void *json_object, void *param) neu_json_encode_field(attributes_object, &meta_elem, 1); } - tag_elems[if_precision + 9].name = "attributes"; - tag_elems[if_precision + 9].t = NEU_JSON_OBJECT; + tag_elems[if_precision + 9].name = "attributes"; + tag_elems[if_precision + 9].t = NEU_JSON_OBJECT; tag_elems[if_precision + 9].v.val_object = attributes_object; - tag_array = neu_json_encode_array(tag_array, tag_elems, - 10 + if_precision); + tag_array = + neu_json_encode_array(tag_array, tag_elems, 10 + if_precision); free(p_tag->datatag.name); free(p_tag->datatag.address); diff --git a/src/utils/cid.c b/src/utils/cid.c index ff2644983..4fdc43321 100644 --- a/src/utils/cid.c +++ b/src/utils/cid.c @@ -181,9 +181,11 @@ void neu_cid_to_msg(char *driver, cid_t *cid, neu_req_add_gtag_t *cmd) tag->address = calloc(1, NEU_TAG_ADDRESS_LEN); tag->description = strdup(""); snprintf(tag->address, NEU_TAG_ADDRESS_LEN - 1, - "%s%s/%s$%s$%s$%s", cid->ied.name, + "%s%s/%s%s%s$%s$%s$%s", cid->ied.name, cid->ied.ldevices[i].inst, - cid->ied.ldevices[i].lns[j].lnclass, "CO", + cid->ied.ldevices[i].lns[j].lnprefix, + cid->ied.ldevices[i].lns[j].lnclass, + cid->ied.ldevices[i].lns[j].lninst, "CO", cid->ied.ldevices[i].lns[j].ctrls[k].do_name, cid->ied.ldevices[i].lns[j].ctrls[k].sdi_name); } @@ -391,11 +393,28 @@ static int parse_lnode(xmlNode *xml_ldevice, cid_ldevice_t *ldev, (char *) xmlGetProp(lnode, (const xmlChar *) "lnClass"); char *ln_type = (char *) xmlGetProp(lnode, (const xmlChar *) "lnType"); + char *ln_prefix = + (char *) xmlGetProp(lnode, (const xmlChar *) "prefix"); + if (NULL == ln_prefix) { + ln_prefix = strdup(""); + } + + char *ln_inst = + (char *) xmlGetProp(lnode, (const xmlChar *) "inst"); + if (NULL == ln_inst) { + ln_inst = strdup(""); + } + if (strlen(ln_class) >= NEU_CID_LNCLASS_LEN || - strlen(ln_type) >= NEU_CID_LNTYPE_LEN) { + strlen(ln_type) >= NEU_CID_LNTYPE_LEN || + strlen(ln_prefix) >= NEU_CID_LNPREFIX_LEN || + strlen(ln_inst) >= NEU_CID_LNINST_LEN) { xmlFree(ln_class); xmlFree(ln_type); - nlog_warn("LN class/type is too long %d", (int) lnode->line); + xmlFree(ln_prefix); + xmlFree(ln_inst); + nlog_warn("LN class/type/prefix/inst is too long %d", + (int) lnode->line); return -1; } else { ldev->n_lns += 1; @@ -412,8 +431,12 @@ static int parse_lnode(xmlNode *xml_ldevice, cid_ldevice_t *ldev, strcpy(ln->lnclass, ln_class); strcpy(ln->lntype, ln_type); + strcpy(ln->lnprefix, ln_prefix); + strcpy(ln->lninst, ln_inst); xmlFree(ln_class); xmlFree(ln_type); + xmlFree(ln_prefix); + xmlFree(ln_inst); xmlNode *child = lnode->children; while (child != NULL) {