mirror of
https://github.com/emqx/neuron.git
synced 2026-10-18 13:41:22 +08:00
Merge pull request #1897 from ZhouBox/v2.7
[V2.7]feat(prgfile):add prgfile api
This commit is contained in:
@@ -137,6 +137,10 @@ typedef enum neu_reqresp_type {
|
||||
|
||||
NEU_REQ_UPDATE_LOG_LEVEL,
|
||||
|
||||
NEU_REQ_PRGFILE_UPLOAD,
|
||||
NEU_REQ_PRGFILE_PROCESS,
|
||||
NEU_RESP_PRGFILE_PROCESS,
|
||||
|
||||
} neu_reqresp_type_e;
|
||||
|
||||
static const char *neu_reqresp_type_string_t[] = {
|
||||
@@ -236,6 +240,9 @@ static const char *neu_reqresp_type_string_t[] = {
|
||||
[NEU_RESP_GET_NDRIVER_TAGS] = "NEU_RESP_GET_NDRIVER_TAGS",
|
||||
|
||||
[NEU_REQ_UPDATE_LOG_LEVEL] = "NEU_REQ_UPDATE_LOG_LEVEL",
|
||||
[NEU_REQ_PRGFILE_UPLOAD] = "NEU_REQ_PRGFILE_UPLOAD",
|
||||
[NEU_REQ_PRGFILE_PROCESS] = "NEU_REQ_PRGFILE_PROCESS",
|
||||
[NEU_RESP_PRGFILE_PROCESS] = "NEU_RESP_PRGFILE_PROCESS",
|
||||
};
|
||||
|
||||
inline static const char *neu_reqresp_type_string(neu_reqresp_type_e type)
|
||||
@@ -1138,6 +1145,25 @@ inline static void neu_msg_exchange(neu_reqresp_head_t *header)
|
||||
strcpy(header->receiver, tmp);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char driver[NEU_NODE_NAME_LEN];
|
||||
char path[128];
|
||||
int prg_int_param1;
|
||||
int prg_int_param2;
|
||||
char prg_str_param1[128];
|
||||
char prg_str_param2[128];
|
||||
} neu_req_prgfile_upload_t;
|
||||
|
||||
typedef struct {
|
||||
char driver[NEU_NODE_NAME_LEN];
|
||||
} neu_req_prgfile_process_t;
|
||||
|
||||
typedef struct {
|
||||
char path[128];
|
||||
int state;
|
||||
char reason[256];
|
||||
} neu_resp_prgfile_process_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
+21
-1
@@ -513,6 +513,20 @@ static int adapter_command(neu_adapter_t *adapter, neu_reqresp_head_t header,
|
||||
strcpy(pheader->receiver, cmd->node);
|
||||
break;
|
||||
}
|
||||
case NEU_REQ_PRGFILE_UPLOAD: {
|
||||
neu_req_prgfile_upload_t *cmd = (neu_req_prgfile_upload_t *) data;
|
||||
strcpy(pheader->receiver, cmd->driver);
|
||||
break;
|
||||
}
|
||||
case NEU_REQ_PRGFILE_PROCESS: {
|
||||
neu_req_prgfile_process_t *cmd = (neu_req_prgfile_process_t *) data;
|
||||
strcpy(pheader->receiver, cmd->driver);
|
||||
break;
|
||||
}
|
||||
case NEU_RESP_PRGFILE_PROCESS: {
|
||||
strcpy(pheader->receiver, DEFAULT_DASHBOARD_PLUGIN_NAME);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -696,6 +710,8 @@ static int adapter_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
case NEU_RESP_GET_GROUP:
|
||||
case NEU_RESP_ERROR:
|
||||
case NEU_REQRESP_NODES_STATE:
|
||||
case NEU_REQ_PRGFILE_PROCESS:
|
||||
case NEU_RESP_PRGFILE_PROCESS:
|
||||
adapter->module->intf_funs->request(
|
||||
adapter->plugin, (neu_reqresp_head_t *) header, &header[1]);
|
||||
neu_msg_free(msg);
|
||||
@@ -1228,7 +1244,11 @@ static int adapter_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case NEU_REQ_PRGFILE_UPLOAD: {
|
||||
adapter->module->intf_funs->request(
|
||||
adapter->plugin, (neu_reqresp_head_t *) header, &header[1]);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
nlog_warn("adapter: %s recv msg type error, type: %s", adapter->name,
|
||||
neu_reqresp_type_string(header->type));
|
||||
|
||||
@@ -115,7 +115,10 @@ extern "C" {
|
||||
XX(NEU_REQ_UPDATE_NDRIVER_TAG_INFO, neu_req_update_ndriver_tag_info_t) \
|
||||
XX(NEU_REQ_GET_NDRIVER_TAGS, neu_req_get_ndriver_tags_t) \
|
||||
XX(NEU_RESP_GET_NDRIVER_TAGS, neu_resp_get_ndriver_tags_t) \
|
||||
XX(NEU_REQ_UPDATE_LOG_LEVEL, neu_req_update_log_level_t)
|
||||
XX(NEU_REQ_UPDATE_LOG_LEVEL, neu_req_update_log_level_t) \
|
||||
XX(NEU_REQ_PRGFILE_UPLOAD, neu_req_prgfile_upload_t) \
|
||||
XX(NEU_REQ_PRGFILE_PROCESS, neu_req_prgfile_process_t) \
|
||||
XX(NEU_RESP_PRGFILE_PROCESS, neu_resp_prgfile_process_t)
|
||||
|
||||
static inline size_t neu_reqresp_size(neu_reqresp_type_e t)
|
||||
{
|
||||
|
||||
+3
-1
@@ -1296,7 +1296,8 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case NEU_REQ_PRGFILE_PROCESS:
|
||||
case NEU_REQ_PRGFILE_UPLOAD:
|
||||
case NEU_REQ_GET_NODE_STATE: {
|
||||
if (neu_node_manager_find(manager->node_manager, header->receiver) ==
|
||||
NULL) {
|
||||
@@ -1509,6 +1510,7 @@ static int manager_loop(enum neu_event_io_type type, int fd, void *usr_data)
|
||||
case NEU_RESP_GET_NODE_SETTING:
|
||||
case NEU_RESP_ERROR:
|
||||
case NEU_RESP_READ_GROUP:
|
||||
case NEU_RESP_PRGFILE_PROCESS:
|
||||
forward_msg(manager, header, header->receiver);
|
||||
break;
|
||||
|
||||
|
||||
+31
-4
@@ -165,6 +165,7 @@ def read_tag(node, group, tag, sync=False):
|
||||
finally:
|
||||
return x[0]['value']
|
||||
|
||||
|
||||
def read_tag_error(node, group, tag, sync=False):
|
||||
response = read_tags(node, group, sync)
|
||||
assert 200 == response.status_code
|
||||
@@ -202,6 +203,7 @@ def write_tag(node, group, tag, value):
|
||||
def write_tags(node, group, tag_values):
|
||||
return requests.post(url=config.BASE_URL + "/api/v2/write/tags", headers={"Authorization": config.default_jwt}, json={"node": node, "group": group, "tags": tag_values})
|
||||
|
||||
|
||||
def write_gtags(json):
|
||||
return requests.post(url=config.BASE_URL + "/api/v2/write/gtags", headers={"Authorization": config.default_jwt}, json=json)
|
||||
|
||||
@@ -296,54 +298,78 @@ def del_template_tags(tmpl, group, tags):
|
||||
def get_template_tags(tmpl, group, name):
|
||||
return requests.get(url=config.BASE_URL + "/api/v2/template/tag", headers={"Authorization": config.default_jwt}, params={"template": tmpl, "group": group, "name": name})
|
||||
|
||||
|
||||
@gen_check
|
||||
def subscribe_group(app, driver, group, params={}):
|
||||
return requests.post(url=config.BASE_URL + "/api/v2/subscribe", headers={"Authorization": config.default_jwt}, json={"app": app, "driver": driver, "group": group, "params": params})
|
||||
|
||||
|
||||
@gen_check
|
||||
def subscribe_groups(app, groups):
|
||||
return requests.post(url=config.BASE_URL + "/api/v2/subscribes", headers={"Authorization": config.default_jwt}, json={"app": app, "groups": groups})
|
||||
|
||||
|
||||
@gen_check
|
||||
def unsubscribe_group(app, driver, group):
|
||||
return requests.delete(url=config.BASE_URL + "/api/v2/subscribe", headers={"Authorization": config.default_jwt}, json={"app": app, "driver": driver, "group": group})
|
||||
|
||||
|
||||
def get_metrics(category="global", node=""):
|
||||
return requests.get(url=config.BASE_URL + "/api/v2/metrics?category=" + category + "&node=" + node, headers={"Authorization": config.default_jwt})
|
||||
|
||||
|
||||
def get_global_config():
|
||||
return requests.get(url=config.BASE_URL + "/api/v2/global/config", headers={"Authorization": config.default_jwt})
|
||||
|
||||
|
||||
def put_global_config(json):
|
||||
return requests.put(url=config.BASE_URL + "/api/v2/global/config", headers={"Authorization": config.default_jwt}, json=json)
|
||||
|
||||
|
||||
def get_plugin_schema(plugin):
|
||||
return requests.get(url=config.BASE_URL + "/api/v2/schema?schema_name=" + plugin, headers={"Authorization": config.default_jwt})
|
||||
|
||||
|
||||
def get_plugin():
|
||||
return requests.get(url=config.BASE_URL + "/api/v2/plugin", headers={"Authorization": config.default_jwt})
|
||||
|
||||
|
||||
def get_version():
|
||||
return requests.get(url=config.BASE_URL + "/api/v2/version", headers={"Authorization": config.default_jwt})
|
||||
|
||||
|
||||
def post_ndriver_map(ndriver, driver, group):
|
||||
return requests.post(url=config.BASE_URL + "/api/v2/ndriver/map", headers={"Authorization": config.default_jwt}, json={"ndriver": ndriver, "driver": driver, "group":group})
|
||||
return requests.post(url=config.BASE_URL + "/api/v2/ndriver/map", headers={"Authorization": config.default_jwt}, json={"ndriver": ndriver, "driver": driver, "group": group})
|
||||
|
||||
|
||||
def delete_ndriver_map(ndriver, driver, group):
|
||||
return requests.delete(url=config.BASE_URL + "/api/v2/ndriver/map", headers={"Authorization": config.default_jwt}, json={"ndriver": ndriver, "driver": driver, "group":group})
|
||||
return requests.delete(url=config.BASE_URL + "/api/v2/ndriver/map", headers={"Authorization": config.default_jwt}, json={"ndriver": ndriver, "driver": driver, "group": group})
|
||||
|
||||
|
||||
def get_ndriver_map(ndriver):
|
||||
return requests.get(url=config.BASE_URL + "/api/v2/ndriver/map?ndriver=" + ndriver, headers={"Authorization": config.default_jwt})
|
||||
|
||||
|
||||
def put_ndriver_tag_param(json):
|
||||
return requests.put(url=config.BASE_URL + "/api/v2/ndriver/tag/param", headers={"Authorization": config.default_jwt}, json=json)
|
||||
|
||||
|
||||
def put_ndriver_tag_info(json):
|
||||
return requests.put(url=config.BASE_URL + "/api/v2/ndriver/tag/info", headers={"Authorization": config.default_jwt}, json=json)
|
||||
|
||||
|
||||
def get_ndriver_tag(ndriver, driver, group):
|
||||
return requests.get(url=config.BASE_URL + "/api/v2/ndriver/tag?ndriver=" + ndriver + "&driver=" + driver + "&group=" + group, headers={"Authorization": config.default_jwt})
|
||||
|
||||
|
||||
def prgfile_upload(driver, path, params):
|
||||
return requests.post(url=config.BASE_URL + "/api/v2/prgfile", headers={"Authorization": config.default_jwt}, json={"driver": driver, "path": path, "parameters": params})
|
||||
|
||||
|
||||
def prgfile_process(driver):
|
||||
return requests.get(url=config.BASE_URL + "/api/v2/prgfile?driver=" + driver, headers={"Authorization": config.default_jwt})
|
||||
|
||||
|
||||
# plugin setting
|
||||
|
||||
|
||||
@@ -358,7 +384,8 @@ def modbus_rtu_node_setting(node, port, connection_mode=0, transport_mode=0, int
|
||||
"max_retries": max_retries, "link": link, "device": device, "stop": stop,
|
||||
"parity": parity, "baud": baud, "data": data})
|
||||
|
||||
|
||||
def mqtt_node_setting(node):
|
||||
return node_setting(node, json={"client-id": "neuron_aBcDeF", "qos":0, "format": 0,
|
||||
return node_setting(node, json={"client-id": "neuron_aBcDeF", "qos": 0, "format": 0,
|
||||
"write-req-topic": f"/neuron/{node}/write/req", "write-resp-topic": f"/neuron/{node}/write/resp",
|
||||
"offline-cache": False, "cache-sync-interval": 100, "host": "broker.emqx.io", "port": 1883, "username": "", "password": "", "ssl": False})
|
||||
"offline-cache": False, "cache-sync-interval": 100, "host": "broker.emqx.io", "port": 1883, "username": "", "password": "", "ssl": False})
|
||||
|
||||
@@ -127,9 +127,12 @@ static int driver_config(neu_plugin_t *plugin, const char *config)
|
||||
static int driver_request(neu_plugin_t *plugin, neu_reqresp_head_t *head,
|
||||
void *data)
|
||||
{
|
||||
(void) plugin;
|
||||
(void) head;
|
||||
(void) data;
|
||||
switch (head->type) {
|
||||
default:
|
||||
plog_warn(plugin, "unhandle msg type: %d", head->type);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user