mirror of
https://github.com/emqx/neuron.git
synced 2026-10-29 15:09:11 +08:00
Remove message_handle.*
The code split in the file with the prefix command_
This commit is contained in:
@@ -8,7 +8,6 @@ set(src
|
||||
${CONFIG_SRC}
|
||||
plugin_mqtt.c
|
||||
paho_client.c
|
||||
message_handle.c
|
||||
common.c
|
||||
command_rw.c
|
||||
command_group_config.c
|
||||
|
||||
@@ -1,737 +0,0 @@
|
||||
/**
|
||||
* NEURON IIoT System for Industry 4.0
|
||||
* Copyright (C) 2020-2021 EMQ Technologies Co., Ltd All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "message_handle.h"
|
||||
|
||||
#define UNUSED(x) (void) (x)
|
||||
#define GROUP_CONFIGS_UINIT(configs) \
|
||||
{ \
|
||||
VECTOR_FOR_EACH(&configs, iter) \
|
||||
{ \
|
||||
neu_taggrp_config_t *cur_grp_config; \
|
||||
cur_grp_config = *(neu_taggrp_config_t **) iterator_get(&iter); \
|
||||
neu_taggrp_cfg_free(cur_grp_config); \
|
||||
} \
|
||||
vector_uninit(&configs); \
|
||||
}
|
||||
|
||||
static paho_client_t *g_paho;
|
||||
static uint32_t req_node_id;
|
||||
|
||||
static const char tags[5][20] = { "1!400001", "1!400003", "1!00001", "1!00002",
|
||||
"1!00003" };
|
||||
static datatag_id_t ids[5];
|
||||
|
||||
void message_handle_set_paho_client(paho_client_t *paho)
|
||||
{
|
||||
g_paho = paho;
|
||||
}
|
||||
|
||||
static int send_mqtt_response(char *buff, const size_t len)
|
||||
{
|
||||
client_error error = paho_client_publish(g_paho, "neuronlite/response", 0,
|
||||
(unsigned char *) buff, len);
|
||||
return error;
|
||||
}
|
||||
|
||||
static int node_id_exist(vector_t *v, const uint32_t node_id)
|
||||
{
|
||||
neu_node_info_t *node_info;
|
||||
VECTOR_FOR_EACH(v, iter)
|
||||
{
|
||||
node_info = (neu_node_info_t *) iterator_get(&iter);
|
||||
log_info("node info id:%ld, name:%s", node_info->node_id,
|
||||
node_info->node_name);
|
||||
if (node_id == node_info->node_id) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
static int config_exist(vector_t *v, const char *config_name)
|
||||
{
|
||||
neu_taggrp_config_t *config;
|
||||
|
||||
VECTOR_FOR_EACH(v, iter)
|
||||
{
|
||||
config = *(neu_taggrp_config_t **) iterator_get(&iter);
|
||||
if (NULL == config) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (0 == strcmp(config_name, neu_taggrp_cfg_get_name(config))) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void message_handle_init_tags(neu_plugin_t *plugin)
|
||||
{
|
||||
vector_t nodes = neu_system_get_nodes(plugin, NEU_NODE_TYPE_DRIVER);
|
||||
neu_node_info_t *node_info;
|
||||
node_info = (neu_node_info_t *) vector_get(&nodes, 1); // modbus nodeid
|
||||
uint32_t dest_node_id = node_info->node_id;
|
||||
|
||||
neu_datatag_table_t *table =
|
||||
neu_system_get_datatags_table(plugin, dest_node_id);
|
||||
if (NULL == table) {
|
||||
return;
|
||||
}
|
||||
|
||||
neu_datatag_id_t id;
|
||||
neu_addr_str_t addr_str = (char *) tags[0];
|
||||
id = 0;
|
||||
neu_datatag_t *datatag0 = malloc(sizeof(neu_datatag_t));
|
||||
datatag0->id = id;
|
||||
datatag0->attribute = NEU_ATTRIBUTETYPE_READ;
|
||||
datatag0->type = NEU_DATATYPE_WORD;
|
||||
datatag0->addr_str = addr_str;
|
||||
ids[0] = neu_datatag_tbl_add(table, datatag0);
|
||||
|
||||
addr_str = (char *) tags[1];
|
||||
id = 1;
|
||||
neu_datatag_t *datatag1 = malloc(sizeof(neu_datatag_t));
|
||||
datatag1->id = id;
|
||||
datatag1->attribute = NEU_ATTRIBUTETYPE_READ;
|
||||
datatag1->type = NEU_DATATYPE_UWORD;
|
||||
datatag1->addr_str = addr_str;
|
||||
ids[1] = neu_datatag_tbl_add(table, datatag1);
|
||||
|
||||
addr_str = (char *) tags[2];
|
||||
id = 2;
|
||||
neu_datatag_t *datatag2 = malloc(sizeof(neu_datatag_t));
|
||||
datatag2->id = id;
|
||||
datatag2->attribute = NEU_ATTRIBUTETYPE_READ;
|
||||
datatag2->type = NEU_DATATYPE_BYTE;
|
||||
datatag2->addr_str = addr_str;
|
||||
ids[2] = neu_datatag_tbl_add(table, datatag2);
|
||||
}
|
||||
|
||||
void message_handle_read(neu_plugin_t *plugin, neu_parse_mqtt_t *mqtt,
|
||||
neu_parse_read_req_t *req)
|
||||
{
|
||||
log_info("READ uuid:%s, node id:%u", mqtt->uuid, req->node_id);
|
||||
|
||||
req_node_id = req->node_id;
|
||||
vector_t nodes = neu_system_get_nodes(plugin, NEU_NODE_TYPE_DRIVER);
|
||||
int rc = node_id_exist(&nodes, req->node_id);
|
||||
vector_uninit(&nodes);
|
||||
if (0 != rc) {
|
||||
return;
|
||||
}
|
||||
|
||||
vector_t configs = neu_system_get_group_configs(plugin, req->node_id);
|
||||
neu_taggrp_config_t *config;
|
||||
neu_taggrp_config_t *c;
|
||||
config = *(neu_taggrp_config_t **) vector_get(&configs, 0);
|
||||
c = (neu_taggrp_config_t *) neu_taggrp_cfg_ref(config);
|
||||
uint32_t req_id = neu_plugin_send_read_cmd(plugin, req->node_id, c);
|
||||
|
||||
GROUP_CONFIGS_UINIT(configs);
|
||||
UNUSED(req_id);
|
||||
}
|
||||
|
||||
void message_handle_get_tag_list(neu_plugin_t *plugin, neu_parse_mqtt_t *mqtt,
|
||||
neu_parse_get_tags_req_t *req)
|
||||
{
|
||||
log_info("Get tag list uuid:%s", mqtt->uuid);
|
||||
char * result = NULL;
|
||||
neu_parse_get_tags_res_t res = { 0 };
|
||||
neu_parse_error_t error = { 0 };
|
||||
|
||||
uint32_t dest_node_id = req->node_id;
|
||||
vector_t nodes = neu_system_get_nodes(plugin, NEU_NODE_TYPE_DRIVER);
|
||||
int rc = node_id_exist(&nodes, dest_node_id);
|
||||
vector_uninit(&nodes);
|
||||
|
||||
if (0 != rc) {
|
||||
error.error = -1;
|
||||
rc = neu_json_encode_with_mqtt(&error, neu_parse_encode_error, mqtt,
|
||||
neu_parse_encode_mqtt_param, &result);
|
||||
if (0 == rc) {
|
||||
send_mqtt_response(result, strlen(result));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
neu_datatag_table_t *table =
|
||||
neu_system_get_datatags_table(plugin, dest_node_id);
|
||||
if (NULL == table) {
|
||||
error.error = -2;
|
||||
rc = neu_json_encode_with_mqtt(&error, neu_parse_encode_error, mqtt,
|
||||
neu_parse_encode_mqtt_param, &result);
|
||||
if (0 == rc) {
|
||||
send_mqtt_response(result, strlen(result));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
res.tags = (neu_parse_get_tags_res_tag_t *) calloc(
|
||||
5, sizeof(neu_parse_get_tags_res_tag_t));
|
||||
|
||||
int i;
|
||||
for (i = 0; i < 5; i++) {
|
||||
neu_datatag_t *ret = NULL;
|
||||
|
||||
ret = neu_datatag_tbl_get(table, ids[i]);
|
||||
if (NULL == ret) {
|
||||
continue;
|
||||
}
|
||||
|
||||
res.tags[i].name = strdup(ret->addr_str);
|
||||
res.tags[i].type = 0;
|
||||
res.tags[i].address = strdup(ret->addr_str);
|
||||
res.tags[i].attribute = 0;
|
||||
}
|
||||
|
||||
rc = neu_json_encode_with_mqtt(&res, neu_parse_encode_get_tags, mqtt,
|
||||
neu_parse_encode_mqtt_param, &result);
|
||||
if (0 == rc) {
|
||||
send_mqtt_response(result, strlen(result));
|
||||
}
|
||||
|
||||
for (i = 0; i < 5; i++) {
|
||||
free(res.tags[i].name);
|
||||
free(res.tags[i].address);
|
||||
}
|
||||
free(res.tags);
|
||||
free(result);
|
||||
}
|
||||
|
||||
void message_handle_add_tag(neu_plugin_t *plugin, neu_parse_mqtt_t *mqtt,
|
||||
neu_parse_add_tags_req_t *req)
|
||||
{
|
||||
char *result = NULL;
|
||||
|
||||
uint32_t dest_node_id = req->node_id;
|
||||
vector_t nodes = neu_system_get_nodes(plugin, NEU_NODE_TYPE_DRIVER);
|
||||
int rc = node_id_exist(&nodes, dest_node_id);
|
||||
neu_parse_error_t error = { 0 };
|
||||
|
||||
vector_uninit(&nodes);
|
||||
|
||||
if (0 != rc) {
|
||||
error.error = -1;
|
||||
rc = neu_json_encode_with_mqtt(&error, neu_parse_encode_error, mqtt,
|
||||
neu_parse_encode_mqtt_param, &result);
|
||||
if (0 == rc) {
|
||||
send_mqtt_response(result, strlen(result));
|
||||
}
|
||||
free(result);
|
||||
return;
|
||||
}
|
||||
|
||||
neu_datatag_table_t *table =
|
||||
neu_system_get_datatags_table(plugin, dest_node_id);
|
||||
if (NULL == table) {
|
||||
error.error = -1;
|
||||
rc = neu_json_encode_with_mqtt(&error, neu_parse_encode_error, mqtt,
|
||||
neu_parse_encode_mqtt_param, &result);
|
||||
if (0 == rc) {
|
||||
send_mqtt_response(result, strlen(result));
|
||||
}
|
||||
free(result);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
neu_datatag_t *datatag = malloc(sizeof(neu_datatag_t));
|
||||
datatag->name = strdup(req->tags[i].name);
|
||||
datatag->attribute = req->tags[i].attribute;
|
||||
datatag->type = req->tags[i].type;
|
||||
datatag->addr_str = strdup(req->tags[i].address);
|
||||
datatag_id_t id = neu_datatag_tbl_add(table, datatag);
|
||||
|
||||
log_info("Add datatag to the datatag table, id:%ld", id);
|
||||
}
|
||||
|
||||
rc = neu_json_encode_with_mqtt(&error, neu_parse_encode_error, mqtt,
|
||||
neu_parse_encode_mqtt_param, &result);
|
||||
if (0 == rc) {
|
||||
send_mqtt_response(result, strlen(result));
|
||||
}
|
||||
free(result);
|
||||
}
|
||||
|
||||
static void get_group_config_by_name(neu_plugin_t * plugin,
|
||||
const uint32_t node_id,
|
||||
const char * config_name,
|
||||
neu_parse_get_group_config_res_t *res)
|
||||
{
|
||||
vector_t nodes = neu_system_get_nodes(plugin, NEU_NODE_TYPE_DRIVER);
|
||||
int rc = node_id_exist(&nodes, node_id);
|
||||
if (0 != rc) {
|
||||
vector_uninit(&nodes);
|
||||
return;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
vector_t configs = neu_system_get_group_configs(plugin, node_id);
|
||||
if (0 == configs.size) {
|
||||
GROUP_CONFIGS_UINIT(configs);
|
||||
return;
|
||||
}
|
||||
|
||||
neu_taggrp_config_t *config;
|
||||
VECTOR_FOR_EACH(&configs, iter)
|
||||
{
|
||||
config = *(neu_taggrp_config_t **) iterator_get(&iter);
|
||||
if (NULL == config) {
|
||||
continue;
|
||||
}
|
||||
if (0 != strcmp(config_name, neu_taggrp_cfg_get_name(config))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (NULL == res->rows) {
|
||||
res->rows = (neu_parse_get_group_config_res_row_t *) malloc(
|
||||
sizeof(neu_parse_get_group_config_res_row_t));
|
||||
}
|
||||
if (NULL != res->rows) {
|
||||
res->rows = realloc(
|
||||
res->rows,
|
||||
(count + 1) * sizeof(neu_parse_get_group_config_res_row_t));
|
||||
}
|
||||
|
||||
res->rows[count].name =
|
||||
strdup((char *) neu_taggrp_cfg_get_name(config));
|
||||
res->rows[count].interval = neu_taggrp_cfg_get_interval(config);
|
||||
|
||||
vector_t *pipes = neu_taggrp_cfg_get_subpipes(config);
|
||||
if (NULL != pipes) {
|
||||
res->rows[count].pipe_count = pipes->size;
|
||||
}
|
||||
|
||||
vector_t *ids = neu_taggrp_cfg_get_datatag_ids(config);
|
||||
if (NULL != ids) {
|
||||
res->rows[count].tag_count = ids->size;
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
res->n_config = count;
|
||||
|
||||
GROUP_CONFIGS_UINIT(configs);
|
||||
}
|
||||
|
||||
static void get_group_config_all(neu_plugin_t *plugin, const uint32_t node_id,
|
||||
neu_parse_get_group_config_res_t *res)
|
||||
{
|
||||
vector_t nodes = neu_system_get_nodes(plugin, NEU_NODE_TYPE_DRIVER);
|
||||
int rc = node_id_exist(&nodes, node_id);
|
||||
if (0 != rc) {
|
||||
vector_uninit(&nodes);
|
||||
return;
|
||||
}
|
||||
|
||||
int count = 0;
|
||||
vector_t configs = neu_system_get_group_configs(plugin, node_id);
|
||||
if (0 == configs.size) {
|
||||
GROUP_CONFIGS_UINIT(configs);
|
||||
return;
|
||||
}
|
||||
|
||||
neu_taggrp_config_t *config;
|
||||
VECTOR_FOR_EACH(&configs, iter)
|
||||
{
|
||||
config = *(neu_taggrp_config_t **) iterator_get(&iter);
|
||||
if (NULL == config) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (NULL == res->rows) {
|
||||
res->rows = (neu_parse_get_group_config_res_row_t *) malloc(
|
||||
sizeof(neu_parse_get_group_config_res_row_t));
|
||||
}
|
||||
if (NULL != res->rows) {
|
||||
res->rows = realloc(
|
||||
res->rows,
|
||||
(count + 1) * sizeof(neu_parse_get_group_config_res_row_t));
|
||||
}
|
||||
|
||||
res->rows[count].name =
|
||||
strdup((char *) neu_taggrp_cfg_get_name(config));
|
||||
res->rows[count].interval = neu_taggrp_cfg_get_interval(config);
|
||||
|
||||
vector_t *pipes = neu_taggrp_cfg_get_subpipes(config);
|
||||
if (NULL != pipes) {
|
||||
res->rows[count].pipe_count = pipes->size;
|
||||
}
|
||||
|
||||
vector_t *ids = neu_taggrp_cfg_get_datatag_ids(config);
|
||||
if (NULL != ids) {
|
||||
res->rows[count].tag_count = ids->size;
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
res->n_config = count;
|
||||
GROUP_CONFIGS_UINIT(configs);
|
||||
}
|
||||
|
||||
void message_handle_get_group_config(neu_plugin_t * plugin,
|
||||
neu_parse_mqtt_t * mqtt,
|
||||
neu_parse_get_group_config_req_t *req)
|
||||
{
|
||||
log_debug("uuid:%s, node id:%d, config:%s", mqtt->uuid, req->node_id,
|
||||
req->name);
|
||||
|
||||
char * json_str = NULL;
|
||||
neu_parse_get_group_config_res_t res = { 0 };
|
||||
|
||||
if (NULL != req->name && 0 != strlen(req->name)) {
|
||||
get_group_config_by_name(plugin, req->node_id, req->name, &res);
|
||||
} else {
|
||||
get_group_config_all(plugin, req->node_id, &res);
|
||||
}
|
||||
|
||||
int rc =
|
||||
neu_json_encode_with_mqtt(&res, neu_parse_encode_get_group_config, mqtt,
|
||||
neu_parse_encode_mqtt_param, &json_str);
|
||||
if (0 == rc) {
|
||||
send_mqtt_response(json_str, strlen(json_str));
|
||||
}
|
||||
|
||||
int i;
|
||||
for (i = 0; i < res.n_config; i++) {
|
||||
free(res.rows[i].name);
|
||||
}
|
||||
free(res.rows);
|
||||
free(json_str);
|
||||
}
|
||||
|
||||
static int add_config(neu_plugin_t *plugin, const char *config_name,
|
||||
const uint32_t node_id, const int read_interval)
|
||||
{
|
||||
if (0 == node_id) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
vector_t nodes = neu_system_get_nodes(plugin, NEU_NODE_TYPE_DRIVER);
|
||||
int rc = node_id_exist(&nodes, node_id);
|
||||
if (0 != rc) {
|
||||
vector_uninit(&nodes);
|
||||
return -2;
|
||||
}
|
||||
vector_uninit(&nodes);
|
||||
|
||||
vector_t configs = neu_system_get_group_configs(plugin, node_id);
|
||||
rc = config_exist(&configs, config_name);
|
||||
VECTOR_FOR_EACH(&configs, iter)
|
||||
{
|
||||
neu_taggrp_config_t *cur_grp_config;
|
||||
cur_grp_config = *(neu_taggrp_config_t **) iterator_get(&iter);
|
||||
neu_taggrp_cfg_free(cur_grp_config);
|
||||
}
|
||||
vector_uninit(&configs);
|
||||
|
||||
if (0 == rc) {
|
||||
return -4;
|
||||
}
|
||||
|
||||
neu_taggrp_config_t *grp_config = neu_taggrp_cfg_new((char *) config_name);
|
||||
if (NULL == grp_config) {
|
||||
return -5;
|
||||
}
|
||||
neu_taggrp_cfg_set_interval(grp_config, read_interval);
|
||||
intptr_t error = neu_system_add_group_config(plugin, node_id, grp_config);
|
||||
if (0 != error) {
|
||||
return -6;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void message_handle_add_group_config(neu_plugin_t * plugin,
|
||||
neu_parse_mqtt_t * mqtt,
|
||||
neu_parse_add_group_config_req_t *req)
|
||||
{
|
||||
log_debug("uuid:%s, config:%s, node id:%d, "
|
||||
"read interval:%d",
|
||||
mqtt->uuid, req->name, req->node_id, req->interval);
|
||||
|
||||
int rc = add_config(plugin, req->name, req->node_id, req->interval);
|
||||
|
||||
char * json_str = NULL;
|
||||
neu_parse_error_t error = { .error = rc };
|
||||
|
||||
rc = neu_json_encode_with_mqtt(&error, neu_parse_encode_error, mqtt,
|
||||
neu_parse_encode_mqtt_param, &json_str);
|
||||
if (0 == rc) {
|
||||
send_mqtt_response(json_str, strlen(json_str));
|
||||
}
|
||||
|
||||
free(json_str);
|
||||
}
|
||||
|
||||
static int update_config(neu_plugin_t *plugin, const char *config_name,
|
||||
const uint32_t node_id, const int read_interval)
|
||||
{
|
||||
if (0 == node_id) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
vector_t nodes = neu_system_get_nodes(plugin, NEU_NODE_TYPE_DRIVER);
|
||||
int rc = node_id_exist(&nodes, node_id);
|
||||
if (0 != rc) {
|
||||
vector_uninit(&nodes);
|
||||
return -2;
|
||||
}
|
||||
vector_uninit(&nodes);
|
||||
|
||||
vector_t configs = neu_system_get_group_configs(plugin, node_id);
|
||||
rc = config_exist(&configs, config_name);
|
||||
VECTOR_FOR_EACH(&configs, iter)
|
||||
{
|
||||
neu_taggrp_config_t *cur_grp_config;
|
||||
cur_grp_config = *(neu_taggrp_config_t **) iterator_get(&iter);
|
||||
neu_taggrp_cfg_free(cur_grp_config);
|
||||
}
|
||||
vector_uninit(&configs);
|
||||
|
||||
if (0 != rc) {
|
||||
return -4;
|
||||
}
|
||||
|
||||
neu_taggrp_config_t *grp_config = neu_taggrp_cfg_new((char *) config_name);
|
||||
if (NULL == grp_config) {
|
||||
return -5;
|
||||
}
|
||||
neu_taggrp_cfg_set_interval(grp_config, read_interval);
|
||||
|
||||
intptr_t error =
|
||||
neu_system_update_group_config(plugin, node_id, grp_config);
|
||||
if (0 != error) {
|
||||
return -6;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void message_handle_update_group_config(
|
||||
neu_plugin_t *plugin, neu_parse_mqtt_t *mqtt,
|
||||
neu_parse_update_group_config_req_t *req)
|
||||
{
|
||||
log_debug("uuid:%s, config:%s, src node id:%d,"
|
||||
"read interval:%d",
|
||||
mqtt->uuid, req->name, req->node_id, req->interval);
|
||||
|
||||
int rc = update_config(plugin, req->name, req->node_id, req->interval);
|
||||
|
||||
char * json_str = NULL;
|
||||
neu_parse_error_t error = { .error = rc };
|
||||
|
||||
rc = neu_json_encode_with_mqtt(&error, neu_parse_encode_error, mqtt,
|
||||
neu_parse_encode_mqtt_param, &json_str);
|
||||
if (0 == rc) {
|
||||
send_mqtt_response(json_str, strlen(json_str));
|
||||
}
|
||||
|
||||
free(json_str);
|
||||
}
|
||||
|
||||
static int delete_config(neu_plugin_t *plugin, const char *config_name,
|
||||
const uint32_t node_id)
|
||||
{
|
||||
if (0 == node_id) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
vector_t nodes = neu_system_get_nodes(plugin, NEU_NODE_TYPE_DRIVER);
|
||||
int rc = node_id_exist(&nodes, node_id);
|
||||
if (0 != rc) {
|
||||
vector_uninit(&nodes);
|
||||
return -2;
|
||||
}
|
||||
rc = node_id_exist(&nodes, node_id);
|
||||
if (0 != rc) {
|
||||
vector_uninit(&nodes);
|
||||
return -3;
|
||||
}
|
||||
vector_uninit(&nodes);
|
||||
|
||||
vector_t configs = neu_system_get_group_configs(plugin, node_id);
|
||||
rc = config_exist(&configs, config_name);
|
||||
VECTOR_FOR_EACH(&configs, iter)
|
||||
{
|
||||
neu_taggrp_config_t *cur_grp_config;
|
||||
cur_grp_config = *(neu_taggrp_config_t **) iterator_get(&iter);
|
||||
neu_taggrp_cfg_free(cur_grp_config);
|
||||
}
|
||||
vector_uninit(&configs);
|
||||
|
||||
if (0 != rc) {
|
||||
return -4;
|
||||
}
|
||||
|
||||
intptr_t error =
|
||||
neu_system_del_group_config(plugin, node_id, (char *) config_name);
|
||||
if (0 != error) {
|
||||
return -5;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void message_handle_delete_group_config(neu_plugin_t * plugin,
|
||||
neu_parse_mqtt_t *mqtt,
|
||||
neu_parse_del_group_config_req_t *req)
|
||||
{
|
||||
log_debug("uuid:%s, config:%s, src node id:%d", mqtt->uuid, req->name,
|
||||
req->node_id);
|
||||
|
||||
int rc = delete_config(plugin, req->name, req->node_id);
|
||||
|
||||
char * json_str = NULL;
|
||||
neu_parse_error_t error = { .error = rc };
|
||||
|
||||
rc = neu_json_encode_with_mqtt(&error, neu_parse_encode_error, mqtt,
|
||||
neu_parse_encode_mqtt_param, &json_str);
|
||||
if (0 == rc) {
|
||||
send_mqtt_response(json_str, strlen(json_str));
|
||||
}
|
||||
|
||||
free(json_str);
|
||||
}
|
||||
|
||||
// static int add_datatag_ids(neu_plugin_t * plugin,
|
||||
// struct neu_parse_add_tag_ids_req *req)
|
||||
//{
|
||||
// if (0 == req->node_id) {
|
||||
// return -1;
|
||||
//}
|
||||
|
||||
// vector_t nodes = neu_system_get_nodes(plugin, NEU_NODE_TYPE_DRIVER);
|
||||
// int rc = node_id_exist(&nodes, req->node_id);
|
||||
// if (0 != rc) {
|
||||
// vector_uninit(&nodes);
|
||||
// return -2;
|
||||
//}
|
||||
// vector_uninit(&nodes);
|
||||
|
||||
// vector_t configs = neu_system_get_group_configs(plugin, req->node_id);
|
||||
// neu_taggrp_config_t *config = get_group_config(&configs, req->config);
|
||||
// if (NULL == config) {
|
||||
// GROUP_CONFIGS_UINIT(configs);
|
||||
// return -3;
|
||||
//}
|
||||
|
||||
// vector_t *v = neu_taggrp_cfg_get_datatag_ids(config);
|
||||
// if (NULL == v) {
|
||||
// GROUP_CONFIGS_UINIT(configs);
|
||||
// return -4;
|
||||
//}
|
||||
|
||||
// int exist;
|
||||
// for (int i = 0; i < req->n_id; i++) {
|
||||
// int index;
|
||||
// exist = datatag_id_exist(v, req->rows[i].datatag_id, &index);
|
||||
// if (0 == exist) {
|
||||
// continue;
|
||||
//}
|
||||
// uint32_t *new_datatag_id = malloc(sizeof(uint32_t));
|
||||
//*new_datatag_id = req->rows[i].datatag_id;
|
||||
// vector_push_back(v, new_datatag_id);
|
||||
//}
|
||||
|
||||
// GROUP_CONFIGS_UINIT(configs);
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
// void message_handle_add_datatag_ids(neu_plugin_t * plugin,
|
||||
// struct neu_parse_add_tag_ids_req *req)
|
||||
//{
|
||||
// char * json_str = NULL;
|
||||
// struct neu_parse_add_tag_ids_res res = {
|
||||
//.function = NEU_PARSE_OP_ADD_DATATAG_IDS_CONFIG,
|
||||
//.uuid = req->uuid,
|
||||
//};
|
||||
|
||||
// int error = add_datatag_ids(plugin, req);
|
||||
// res.error = error;
|
||||
|
||||
// int rc = neu_parse_encode(&res, &json_str);
|
||||
// if (0 == rc) {
|
||||
// send_mqtt_response(json_str, strlen(json_str));
|
||||
// free(json_str);
|
||||
//}
|
||||
//}
|
||||
|
||||
// static int delete_datatag_ids(neu_plugin_t * plugin,
|
||||
// struct neu_parse_delete_tag_ids_req *req)
|
||||
//{
|
||||
// if (0 == req->node_id) {
|
||||
// return -1;
|
||||
//}
|
||||
|
||||
// vector_t nodes = neu_system_get_nodes(plugin, NEU_NODE_TYPE_DRIVER);
|
||||
// int rc = node_id_exist(&nodes, req->node_id);
|
||||
// if (0 != rc) {
|
||||
// vector_uninit(&nodes);
|
||||
// return -2;
|
||||
//}
|
||||
// vector_uninit(&nodes);
|
||||
|
||||
// vector_t configs = neu_system_get_group_configs(plugin, req->node_id);
|
||||
// neu_taggrp_config_t *config = get_group_config(&configs, req->config);
|
||||
// if (NULL == config) {
|
||||
// GROUP_CONFIGS_UINIT(configs);
|
||||
// return -3;
|
||||
//}
|
||||
|
||||
// vector_t *v = neu_taggrp_cfg_get_datatag_ids(config);
|
||||
// if (NULL == v) {
|
||||
// GROUP_CONFIGS_UINIT(configs);
|
||||
// return -4;
|
||||
//}
|
||||
|
||||
// int exist = 0;
|
||||
// for (int i = 0; i < req->n_id; i++) {
|
||||
// int index;
|
||||
// exist = datatag_id_exist(v, req->rows[i].datatag_id, &index);
|
||||
// if (0 == exist) {
|
||||
// vector_erase(v, index);
|
||||
//}
|
||||
//}
|
||||
|
||||
// GROUP_CONFIGS_UINIT(configs);
|
||||
// return 0;
|
||||
//}
|
||||
|
||||
// void message_handle_delete_datatag_ids(neu_plugin_t *plugin,
|
||||
// struct neu_parse_delete_tag_ids_req *req)
|
||||
//{
|
||||
// char * json_str = NULL;
|
||||
// struct neu_parse_delete_tag_ids_res res = {
|
||||
//.function = NEU_PARSE_OP_DELETE_DATATAG_IDS_CONFIG,
|
||||
//.uuid = req->uuid,
|
||||
//};
|
||||
|
||||
// int error = delete_datatag_ids(plugin, req);
|
||||
// res.error = error;
|
||||
|
||||
// int rc = neu_parse_encode(&res, &json_str);
|
||||
// if (0 == rc) {
|
||||
// send_mqtt_response(json_str, strlen(json_str));
|
||||
// free(json_str);
|
||||
//}
|
||||
//}
|
||||
@@ -1,65 +0,0 @@
|
||||
/**
|
||||
* NEURON IIoT System for Industry 4.0
|
||||
* Copyright (C) 2020-2021 EMQ Technologies Co., Ltd All rights reserved.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this program; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
**/
|
||||
|
||||
#ifndef NEURON_PLUGIN_MESSAGE_HANDLE
|
||||
#define NEURON_PLUGIN_MESSAGE_HANDLE
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <neuron.h>
|
||||
|
||||
#include "option.h"
|
||||
#include "paho_client.h"
|
||||
#include "parser/neu_json_fn.h"
|
||||
#include "parser/neu_json_group_config.h"
|
||||
#include "parser/neu_json_mqtt.h"
|
||||
#include "parser/neu_json_rw.h"
|
||||
#include "parser/neu_json_tag.h"
|
||||
|
||||
void message_handle_set_paho_client(paho_client_t *paho);
|
||||
|
||||
void message_handle_init_tags(neu_plugin_t *plugin);
|
||||
|
||||
void message_handle_get_tag_list(neu_plugin_t *plugin, neu_parse_mqtt_t *mqtt,
|
||||
neu_parse_get_tags_req_t *req);
|
||||
void message_handle_add_tag(neu_plugin_t *plugin, neu_parse_mqtt_t *mqtt,
|
||||
neu_parse_add_tags_req_t *req);
|
||||
void message_handle_get_group_config(neu_plugin_t * plugin,
|
||||
neu_parse_mqtt_t * mqtt,
|
||||
neu_parse_get_group_config_req_t *req);
|
||||
void message_handle_add_group_config(neu_plugin_t * plugin,
|
||||
neu_parse_mqtt_t * mqtt,
|
||||
neu_parse_add_group_config_req_t *req);
|
||||
void message_handle_update_group_config(
|
||||
neu_plugin_t *plugin, neu_parse_mqtt_t *mqtt,
|
||||
neu_parse_update_group_config_req_t *req);
|
||||
void message_handle_delete_group_config(neu_plugin_t * plugin,
|
||||
neu_parse_mqtt_t *mqtt,
|
||||
neu_parse_del_group_config_req_t *req);
|
||||
// void message_handle_add_datatag_ids(neu_plugin_t * plugin,
|
||||
// struct neu_parse_add_tag_ids_req *req);
|
||||
// void message_handle_delete_datatag_ids(
|
||||
// neu_plugin_t *plugin, struct neu_parse_delete_tag_ids_req *req);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -27,7 +27,6 @@
|
||||
#include "command_datatag.h"
|
||||
#include "command_group_config.h"
|
||||
#include "command_rw.h"
|
||||
#include "message_handle.h"
|
||||
|
||||
#include "option.h"
|
||||
#include "paho_client.h"
|
||||
@@ -288,7 +287,6 @@ static int mqtt_plugin_init(neu_plugin_t *plugin)
|
||||
plugin_subscribe(plugin, "neuronlite/request", 0, plugin_response_handle);
|
||||
log_info("Initialize plugin: %s", neu_plugin_module.module_name);
|
||||
|
||||
message_handle_set_paho_client(plugin->paho);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -302,8 +300,6 @@ static int mqtt_plugin_uninit(neu_plugin_t *plugin)
|
||||
|
||||
static int mqtt_plugin_config(neu_plugin_t *plugin, neu_config_t *configs)
|
||||
{
|
||||
message_handle_init_tags(plugin);
|
||||
|
||||
UNUSED(plugin);
|
||||
|
||||
UNUSED(configs);
|
||||
|
||||
Reference in New Issue
Block a user