Merge pull request #384 from fengzeroz/main

replace node id with node name in read request
This commit is contained in:
fengzeroz
2022-04-01 11:24:20 +08:00
committed by GitHub
12 changed files with 108 additions and 47 deletions
+2 -2
View File
@@ -220,8 +220,8 @@ Get Tag ID
[Return] ${id}
Read Tags
[Arguments] ${node_id} ${group}
POST /api/v2/read {"node_id": ${node_id}, "group_config_name": "${group}"}
[Arguments] ${node_name} ${group}
POST /api/v2/read {"node_name": "${node_name}", "group_config_name": "${group}"}
${res} = Object response body
[RETURN] ${res}[0]
+2 -2
View File
@@ -263,8 +263,8 @@ Get Tag ID
[Return] ${id}
Read Tags
[Arguments] ${node_id} ${group}
${res} = Pub And Recv ${MQTT_CMD_NONE} {"node_id": ${node_id}, "group_config_name": "${group}"} ${TOPIC_READ_REQ} ${TOPIC_READ_RES}
[Arguments] ${node_name} ${group}
${res} = Pub And Recv ${MQTT_CMD_NONE} {"node_name": "${node_name}", "group_config_name": "${group}"} ${TOPIC_READ_REQ} ${TOPIC_READ_RES}
[Return] ${res}
+30 -29
View File
@@ -5,6 +5,7 @@ Suite Teardown Stop All Processes
*** Variables ***
${test_node_id}
${test_node_name} modbus-tcp-adapter
${group} config_modbus_tcp_sample_2
${tag_bit} {"name": "tag_bit", "address": "1!000001", "attribute": ${TAG_ATTRIBUTE_RW}, "type": ${TAG_DATA_TYPE_BIT}}
@@ -33,7 +34,7 @@ Read unsubscribed point, it should return failure
${res} = Add Tags ${test_node_id} xxgrp ${tag_int16}
Sleep 1s 500ms
${res} = Read Tags ${test_node_id} xxgrp
${res} = Read Tags ${test_node_name} xxgrp
Check Response Status ${res} 200
Integer $.tags[0].error ${ERR_PLUGIN_GRP_NOT_SUBSCRIBE}
@@ -43,21 +44,21 @@ Read unsubscribed point, it should return failure
Read/Write a point in the hold reg or coil area, and the data as bit/int16/uint16/int32/uint32/float type, it should return success
[Template] Read Write A Point In The hold/coil Reg Area Should Success
${test_node_id} ${group} ${tag_bit} coil bit 1
${test_node_id} ${group} ${tag_int16} hold reg int16 123
${test_node_id} ${group} ${tag_uint16} hold reg uint16 456
${test_node_id} ${group} ${tag_int32} hold reg int32 66778899
${test_node_id} ${group} ${tag_uint32} hold reg int32 667788995
${test_node_id} ${group} ${tag_float} hold reg float 11.22
${test_node_id} ${test_node_name} ${group} ${tag_bit} coil bit 1
${test_node_id} ${test_node_name} ${group} ${tag_int16} hold reg int16 123
${test_node_id} ${test_node_name} ${group} ${tag_uint16} hold reg uint16 456
${test_node_id} ${test_node_name} ${group} ${tag_int32} hold reg int32 66778899
${test_node_id} ${test_node_name} ${group} ${tag_uint32} hold reg int32 667788995
${test_node_id} ${test_node_name} ${group} ${tag_float} hold reg float 11.22
Read a point in the input or input reg area, and the data as bit/int16/uint16/int32/uint32/float type, it should return success
[Template] Read A Point In The Input Or Input Reg Area Should Return Success
${test_node_id} ${group} input bit ${tag1_bit} 0 ${tag2_bit} 1
${test_node_id} ${group} input reg int16 ${tag1_int16} 1020 ${tag2_int16} 1021
${test_node_id} ${group} input reg uint16 ${tag1_uint16} 1018 ${tag2_uint16} 1019
${test_node_id} ${group} input reg int32 ${tag1_int32} 66126834 ${tag2_int32} 66191360
${test_node_id} ${group} input reg uint32 ${tag1_uint32} 66585593 ${tag2_uint32} 66650112
${test_node_id} ${group} input reg float ${tag1_float} 7.346839692639297e-40 ${tag2_float} 6.428596834936531e-40
${test_node_id} ${test_node_name} ${group} input bit ${tag1_bit} 0 ${tag2_bit} 1
${test_node_id} ${test_node_name} ${group} input reg int16 ${tag1_int16} 1020 ${tag2_int16} 1021
${test_node_id} ${test_node_name} ${group} input reg uint16 ${tag1_uint16} 1018 ${tag2_uint16} 1019
${test_node_id} ${test_node_name} ${group} input reg int32 ${tag1_int32} 66126834 ${tag2_int32} 66191360
${test_node_id} ${test_node_name} ${group} input reg uint32 ${tag1_uint32} 66585593 ${tag2_uint32} 66650112
${test_node_id} ${test_node_name} ${group} input reg float ${tag1_float} 7.346839692639297e-40 ${tag2_float} 6.428596834936531e-40
Read multiple points in the coil area, the point address includes continuous and non-continuous, and the data as bit type, it should return success
${tag1_id} = Add Tag And Return ID ${test_node_id} ${group} {"name": "tag1", "address": "1!000001", "attribute": ${TAG_ATTRIBUTE_RW}, "type": ${TAG_DATA_TYPE_BIT}}
@@ -79,7 +80,7 @@ Read multiple points in the coil area, the point address includes continuous and
Should Not Be Equal As Integers ${tag8_id} -1
Sleep 1s 500ms
${res} = Read Tags ${test_node_id} ${group}
${res} = Read Tags ${test_node_name} ${group}
Compare Tag Value As Int ${res}[tags] tag1 1
Compare Tag Value As Int ${res}[tags] tag2 0
@@ -97,7 +98,7 @@ Read multiple points in the coil area, the point address includes continuous and
Write Tags ${test_node_id} ${group} {"id": ${tag7_id}, "value": 1}
Sleep 1s 500ms
${res} = Read Tags ${test_node_id} ${group}
${res} = Read Tags ${test_node_name} ${group}
Compare Tag Value As Int ${res}[tags] tag1 1
Compare Tag Value As Int ${res}[tags] tag2 1
@@ -130,7 +131,7 @@ Read multiple points in the input area, the point address includes continuous an
Should Not Be Equal As Integers ${tag8_id} -1
Sleep 1s 500ms
${res} = Read Tags ${test_node_id} ${group}
${res} = Read Tags ${test_node_name} ${group}
Compare Tag Value As Int ${res}[tags] tag1 0
Compare Tag Value As Int ${res}[tags] tag2 1
@@ -164,7 +165,7 @@ Read multiple points in the input reg area, the point address includes continuou
Should Not Be Equal As Integers ${tag8_id} -1
Sleep 1s 500ms
${res} = Read Tags ${test_node_id} ${group}
${res} = Read Tags ${test_node_name} ${group}
Compare Tag Value As Int ${res}[tags] tag1 0
Compare Tag Value As Int ${res}[tags] tag2 1
@@ -197,7 +198,7 @@ Read multiple points in the hold reg area, the point address includes continuous
Should Not Be Equal As Integers ${tag8_id} -1
Sleep 1s 500ms
${res} = Read Tags ${test_node_id} ${group}
${res} = Read Tags ${test_node_name} ${group}
Compare Tag Value As Int ${res}[tags] tag1 123
Compare Tag Value As Int ${res}[tags] tag2 456
@@ -218,7 +219,7 @@ Read multiple points in the hold reg area, the point address includes continuous
Write Tags ${test_node_id} ${group} {"id": ${tag8_id}, "value": 11.234}
Sleep 1s 500ms
${res} = Read Tags ${test_node_id} ${group}
${res} = Read Tags ${test_node_name} ${group}
Compare Tag Value As Int ${res}[tags] tag1 1
Compare Tag Value As Int ${res}[tags] tag2 2
@@ -255,7 +256,7 @@ Read multiple points belonging to different areas(coil/input/input reg/hold reg)
Should Not Be Equal As Integers ${tag10_id} -1
Sleep 1s 500ms
${res} = Read Tags ${test_node_id} ${group}
${res} = Read Tags ${test_node_name} ${group}
Compare Tag Value As Int ${res}[tags] tag1 0
Compare Tag Value As Int ${res}[tags] tag2 0
@@ -276,7 +277,7 @@ Read multiple points belonging to different areas(coil/input/input reg/hold reg)
Write Tags ${test_node_id} ${group} {"id": ${tag10_id}, "value": 11.123}
Sleep 1s 500ms
${res} = Read Tags ${test_node_id} ${group}
${res} = Read Tags ${test_node_name} ${group}
Compare Tag Value As Int ${res}[tags] tag1 1
Compare Tag Value As Int ${res}[tags] tag2 1
@@ -315,7 +316,7 @@ Read multiple points belonging to different areas(coil/input/input reg/hold reg)
Should Not Be Equal As Integers ${tag10_id} -1
Sleep 1s 500ms
${res} = Read Tags ${test_node_id} ${group}
${res} = Read Tags ${test_node_name} ${group}
Compare Tag Value As Int ${res}[tags] tag1 0
Compare Tag Value As Int ${res}[tags] tag2 0
@@ -336,7 +337,7 @@ Read multiple points belonging to different areas(coil/input/input reg/hold reg)
Write Tags ${test_node_id} ${group} {"id": ${tag10_id}, "value": 11.789}
Sleep 1s 500ms
${res} = Read Tags ${test_node_id} ${group}
${res} = Read Tags ${test_node_name} ${group}
Compare Tag Value As Int ${res}[tags] tag1 1
Compare Tag Value As Int ${res}[tags] tag2 1
@@ -360,7 +361,7 @@ Neuron Context Ready
LOGIN
Add Node type=${${NODE_DRIVER}} name=modbus-tcp-adapter plugin_name=modbus-tcp
Add Node type=${${NODE_DRIVER}} name=${test_node_name} plugin_name=modbus-tcp
${id} = Get Node ID ${NODE_DRIVER} modbus-tcp-adapter
${mqtt_id} = Get Node ID ${NODE_MQTT} mqtt-adapter
@@ -378,7 +379,7 @@ Stop All Processes
Terminate All Processes kill=false
Read Write A Point In The hold/coil Reg Area Should Success
[Arguments] ${node_id} ${group} ${tag} ${area} ${type} ${value}
[Arguments] ${node_id} ${node_name} ${group} ${tag} ${area} ${type} ${value}
Log Read a point in the ${area} reg area, and the data as ${type}, it should return success
Log To Console Read a point in the ${area} reg area, and the data as ${type}, it should return success
@@ -392,7 +393,7 @@ Read Write A Point In The hold/coil Reg Area Should Success
Should Not Be Equal As Integers ${tag_id} -1
Sleep 1s 500ms
${res} = Read Tags ${node_id} ${group}
${res} = Read Tags ${node_name} ${group}
Check Response Status ${res} 200
#Check Error Code ${res} ${ERR_SUCCESS}
Run Keyword ${cmp} ${res}[tags] ${res}[tags][0][name] 0
@@ -400,7 +401,7 @@ Read Write A Point In The hold/coil Reg Area Should Success
${res} = Write Tags ${node_id} ${group} {"id": ${tag_id}, "value": ${value}}
Sleep 1s 500ms
${res} = Read Tags ${node_id} ${group}
${res} = Read Tags ${node_name} ${group}
Check Response Status ${res} 200
#Check Error Code ${res} ${ERR_SUCCESS}
Run Keyword ${cmp} ${res}[tags] ${res}[tags][0][name] ${value}
@@ -409,7 +410,7 @@ Read Write A Point In The hold/coil Reg Area Should Success
[Teardown] Del Tags ${node_id} ${group} ${tag_id}
Read A Point In The Input Or Input Reg Area Should Return Success
[Arguments] ${node_id} ${group} ${area} ${type} ${tag1} ${value1} ${tag2} ${value2}
[Arguments] ${node_id} ${node_name} ${group} ${area} ${type} ${tag1} ${value1} ${tag2} ${value2}
Log Read a point in the ${area} area, and the data as ${type}, it should return success
Log To Console Read a point in the ${area} area, and the data as ${type}, it should return success
@@ -426,7 +427,7 @@ Read A Point In The Input Or Input Reg Area Should Return Success
Should Not Be Equal As Integers ${tag2_id} -1
Sleep 1s 500ms
${res} = Read Tags ${node_id} ${group}
${res} = Read Tags ${node_name} ${group}
Check Response Status ${res} 200
#Check Error Code ${res} ${ERR_SUCCESS}
+2 -2
View File
@@ -69,8 +69,8 @@ int neu_json_decode_write_req(char *buf, neu_json_write_req_t **result);
void neu_json_decode_write_req_free(neu_json_write_req_t *req);
typedef struct {
char * group_config_name;
int64_t node_id;
char *group_config_name;
char *node_name;
} neu_json_read_req_t;
int neu_json_decode_read_req(char *buf, neu_json_read_req_t **result);
+6
View File
@@ -74,6 +74,7 @@ typedef enum neu_reqresp_type {
NEU_REQRESP_NODE_ID,
NEU_REQRESP_SELF_NODE_NAME,
NEU_REQRESP_NODE_NAME,
NEU_REQRESP_GET_NODE_ID_BY_NAME,
NEU_REQRESP_SET_NODE_SETTING,
NEU_REQRESP_GET_NODE_SETTING,
NEU_REQRESP_GET_NODE_SETTING_RESP,
@@ -264,6 +265,11 @@ typedef struct neu_cmd_self_node_id {
uint32_t reserved;
} neu_cmd_self_node_id_t;
/* NEU_REQRESP_GET_NODE_ID_BY_NAME */
typedef struct neu_cmd_get_node_id_by_name {
const char *name;
} neu_cmd_get_node_id_by_name_t;
/* NEU_REQRESP_NODE_ID */
typedef struct neu_represp_node_id {
neu_node_id_t node_id;
+2
View File
@@ -119,6 +119,8 @@ void neu_plugin_response_trans_data(neu_plugin_t * plugin,
neu_data_val_t *data, uint32_t event_id);
neu_node_id_t neu_plugin_self_node_id(neu_plugin_t *plugin);
const char * neu_plugin_self_node_name(neu_plugin_t *plugin);
neu_node_id_t neu_plugin_get_node_id_by_node_name(neu_plugin_t *plugin,
const char * node_name);
intptr_t neu_system_add_plugin(neu_plugin_t *plugin,
const char * plugin_lib_name);
+14 -4
View File
@@ -35,15 +35,21 @@ static uint64_t current_time()
int command_rw_read_once_request(neu_plugin_t *plugin, neu_json_mqtt_t *mqtt,
neu_json_read_req_t *req, uint32_t req_id)
{
log_info("READ uuid:%s, node id:%u", mqtt->uuid, req->node_id);
neu_taggrp_config_t *config = neu_system_find_group_config(
plugin, req->node_id, req->group_config_name);
neu_node_id_t node_id =
neu_plugin_get_node_id_by_node_name(plugin, req->node_name);
if (node_id == 0) {
log_debug("node %s does not exist", req->node_name);
return -1;
}
log_info("READ uuid:%s, node id:%u", mqtt->uuid, node_id);
neu_taggrp_config_t *config =
neu_system_find_group_config(plugin, node_id, req->group_config_name);
if (NULL == config) {
log_debug("The requested config does not exist");
return -2;
}
neu_plugin_send_read_cmd(plugin, req_id, req->node_id, config);
neu_plugin_send_read_cmd(plugin, req_id, node_id, config);
return 0;
}
@@ -72,6 +78,10 @@ static int wrap_read_response_json_object(neu_fixed_array_t * array,
neu_datatag_t *tag = neu_datatag_tbl_get(datatag_table, int_val->key);
if (tag == NULL) {
continue;
}
json->tags[i].name = tag->name;
json->tags[i].error = NEU_ERR_SUCCESS;
+20 -3
View File
@@ -147,11 +147,28 @@ void handle_read(nng_aio *aio)
REST_PROCESS_HTTP_REQUEST_VALIDATE_JWT(
aio, neu_json_read_req_t, neu_json_decode_read_req, {
neu_node_id_t node_id =
neu_plugin_get_node_id_by_node_name(plugin, req->node_name);
if (node_id == 0) {
NEU_JSON_RESPONSE_ERROR(NEU_ERR_NODE_NOT_EXIST, {
http_response(aio, NEU_ERR_NODE_NOT_EXIST, result_error);
})
return;
}
neu_taggrp_config_t *config = neu_system_find_group_config(
plugin, req->node_id, req->group_config_name);
plugin, node_id, req->group_config_name);
if (config == NULL) {
NEU_JSON_RESPONSE_ERROR(NEU_ERR_GRP_CONFIG_NOT_EXIST, {
http_response(aio, NEU_ERR_GRP_CONFIG_NOT_EXIST,
result_error);
})
return;
}
uint32_t event_id = neu_plugin_get_event_id(plugin);
read_add_ctx(event_id, aio, plugin, req->node_id);
neu_plugin_send_read_cmd(plugin, event_id, req->node_id, config);
read_add_ctx(event_id, aio, plugin, node_id);
neu_plugin_send_read_cmd(plugin, event_id, node_id, config);
})
}
+12
View File
@@ -1510,6 +1510,18 @@ static int adapter_command(neu_adapter_t *adapter, neu_request_t *cmd,
break;
}
case NEU_REQRESP_GET_NODE_ID_BY_NAME: {
ADAPTER_RESP_CMD(
adapter, cmd, neu_reqresp_node_id_t, neu_cmd_get_node_id_by_name_t,
rv, NEU_REQRESP_NODE_ID, p_result, {
ret = calloc(1, sizeof(neu_reqresp_node_id_t));
int err = neu_manager_get_node_id_by_name(
adapter->manager, req_cmd->name, &ret->node_id);
(void) err;
})
break;
}
case NEU_REQRESP_SELF_NODE_NAME: {
ADAPTER_RESP_CMD(
adapter, cmd, neu_reqresp_node_name_t, neu_cmd_self_node_name_t, rv,
+12
View File
@@ -400,6 +400,18 @@ const char *neu_plugin_self_node_name(neu_plugin_t *plugin)
return node_name;
}
neu_node_id_t neu_plugin_get_node_id_by_node_name(neu_plugin_t *plugin,
const char * node_name)
{
neu_cmd_get_node_id_by_name_t get_id = { .name = node_name };
neu_node_id_t node_id = { 0 };
PLUGIN_CALL_CMD(plugin, NEU_REQRESP_GET_NODE_ID_BY_NAME, get_id,
neu_reqresp_node_id_t, { node_id = resp->node_id; })
return node_id;
}
intptr_t neu_system_add_plugin(neu_plugin_t *plugin,
const char * plugin_lib_name)
{
+4 -3
View File
@@ -190,8 +190,8 @@ int neu_json_decode_read_req(char *buf, neu_json_read_req_t **result)
json_obj = neu_json_decode_new(buf);
neu_json_elem_t req_elems[] = { {
.name = "node_id",
.t = NEU_JSON_INT,
.name = "node_name",
.t = NEU_JSON_STR,
},
{
.name = "group_config_name",
@@ -203,7 +203,7 @@ int neu_json_decode_read_req(char *buf, neu_json_read_req_t **result)
goto decode_fail;
}
req->node_id = req_elems[0].v.val_int;
req->node_name = req_elems[0].v.val_str;
req->group_config_name = req_elems[1].v.val_str;
*result = req;
@@ -226,6 +226,7 @@ void neu_json_decode_read_req_free(neu_json_read_req_t *req)
{
free(req->group_config_name);
free(req->node_name);
free(req);
}
+2 -2
View File
@@ -10,7 +10,7 @@ TEST(JsonAPITest, ReadReqDecode)
{
char *buf = (char *) "{\"command\":\"\", "
"\"uuid\":\"554f5fd8-f437-11eb-975c-7704b9e17821\", "
"\"node_id\": 123 ,"
"\"node_name\": \"name1\" ,"
"\"group_config_name\": \"group1\"}";
neu_json_read_req_t *req = NULL;
neu_json_mqtt_t * mqtt = NULL;
@@ -19,7 +19,7 @@ TEST(JsonAPITest, ReadReqDecode)
EXPECT_EQ(0, neu_json_decode_read_req(buf, &req));
EXPECT_STREQ("554f5fd8-f437-11eb-975c-7704b9e17821", mqtt->uuid);
EXPECT_EQ(123, req->node_id);
EXPECT_STREQ("name1", req->node_name);
EXPECT_STREQ("group1", req->group_config_name);
neu_json_decode_mqtt_req_free(mqtt);