mirror of
https://github.com/emqx/neuron.git
synced 2026-10-27 04:19:50 +08:00
Merge pull request #1825 from ZhouBox/main
feat(prgfile):add prgfile api
This commit is contained in:
@@ -110,6 +110,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[] = {
|
||||
@@ -182,6 +186,9 @@ static const char *neu_reqresp_type_string_t[] = {
|
||||
[NEU_REQ_ADD_DRIVERS] = "NEU_REQ_ADD_DRIVERS",
|
||||
|
||||
[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)
|
||||
@@ -894,6 +901,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
@@ -521,6 +521,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;
|
||||
}
|
||||
@@ -697,6 +711,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);
|
||||
@@ -1161,7 +1177,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));
|
||||
|
||||
@@ -89,7 +89,10 @@ extern "C" {
|
||||
XX(NEU_REQRESP_NODES_STATE, neu_reqresp_nodes_state_t) \
|
||||
XX(NEU_REQRESP_NODE_DELETED, neu_reqresp_node_deleted_t) \
|
||||
XX(NEU_REQ_ADD_DRIVERS, neu_req_driver_array_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
@@ -993,7 +993,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) {
|
||||
@@ -1187,6 +1188,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;
|
||||
|
||||
|
||||
+24
-2
@@ -168,6 +168,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
|
||||
@@ -205,6 +206,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)
|
||||
|
||||
@@ -243,45 +245,64 @@ def subscribe_group_update(app, driver, group, params={}):
|
||||
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)
|
||||
|
||||
|
||||
@gen_check
|
||||
def put_driver(name, plugin, params, groups=[], jwt=config.default_jwt):
|
||||
return put_drivers([{"name": name, "plugin": plugin, "params": params, "groups": groups}])
|
||||
|
||||
|
||||
@gen_check
|
||||
def put_drivers(drivers, jwt=config.default_jwt):
|
||||
return requests.put(url=config.BASE_URL + '/api/v2/global/drivers', headers={"Authorization": jwt}, json={"nodes": drivers})
|
||||
|
||||
|
||||
def get_driver(name, jwt=config.default_jwt):
|
||||
return get_drivers(names=[name])
|
||||
|
||||
|
||||
def get_drivers(names=None, jwt=config.default_jwt):
|
||||
if names and not isinstance(names, str):
|
||||
names = ','.join(names)
|
||||
return requests.get(url=config.BASE_URL + '/api/v2/global/drivers', headers={"Authorization": jwt}, params={"name": names})
|
||||
|
||||
|
||||
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 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
|
||||
|
||||
|
||||
@@ -296,7 +317,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