mirror of
https://github.com/emqx/neuron.git
synced 2026-10-28 22:59:34 +08:00
Add datatag table tag JSON analysis and test modifications
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
/**
|
||||
* 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 <stdlib.h>
|
||||
|
||||
#include "neu_json_add_tag.h"
|
||||
#include "utils/json.h"
|
||||
|
||||
#define NODE_ID "node_id"
|
||||
|
||||
#define TAGS "tags"
|
||||
#define NAME "name"
|
||||
#define TYPE "type"
|
||||
#define DECIMAL "decimal"
|
||||
#define ADDRESS "address"
|
||||
#define FLAG "flag"
|
||||
|
||||
int neu_parse_decode_add_tags_req(char * buf,
|
||||
struct neu_parse_add_tags_req **result)
|
||||
{
|
||||
struct neu_parse_add_tags_req *req =
|
||||
calloc(1, sizeof(struct neu_parse_add_tags_req));
|
||||
neu_json_elem_t elem[] = { {
|
||||
.name = NEU_PARSE_UUID,
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = NODE_ID,
|
||||
.t = NEU_JSON_INT,
|
||||
} };
|
||||
|
||||
int ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(elem), elem);
|
||||
if (ret != 0) {
|
||||
free(req);
|
||||
return -1;
|
||||
}
|
||||
req->function = NEU_PARSE_OP_ADD_TAGS;
|
||||
req->uuid = elem[0].v.val_str;
|
||||
req->node_id = elem[1].v.val_int;
|
||||
|
||||
req->n_tag = neu_json_decode_array_size(buf, TAGS);
|
||||
req->tags = calloc(req->n_tag, sizeof(struct neu_parse_add_tags_req_tag));
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
neu_json_elem_t celem[] = { {
|
||||
.name = NAME,
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = TYPE,
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = DECIMAL,
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = ADDRESS,
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = FLAG,
|
||||
.t = NEU_JSON_INT,
|
||||
} };
|
||||
|
||||
neu_json_decode_array(buf, TAGS, i, NEU_JSON_ELEM_SIZE(celem), celem);
|
||||
req->tags[i].name = celem[0].v.val_str;
|
||||
req->tags[i].type = celem[1].v.val_int;
|
||||
req->tags[i].decimal = celem[2].v.val_int;
|
||||
req->tags[i].address = celem[3].v.val_str;
|
||||
req->tags[i].flag = celem[4].v.val_int;
|
||||
}
|
||||
|
||||
*result = req;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int neu_parse_encode_add_tags_res(struct neu_parse_add_tags_res *res,
|
||||
char ** buf)
|
||||
{
|
||||
neu_json_elem_t elems[] = { {
|
||||
.name = NEU_PARSE_FUNCTION,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = NEU_PARSE_OP_ADD_TAGS,
|
||||
},
|
||||
{
|
||||
.name = NEU_PARSE_UUID,
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = res->uuid,
|
||||
},
|
||||
{
|
||||
.name = NEU_PARSE_ERROR,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->error,
|
||||
} };
|
||||
|
||||
return neu_json_encode(elems, 3, buf);
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/**
|
||||
* 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 _NEU_JSON_API_ADD_TAG_H_
|
||||
#define _NEU_JSON_API_ADD_TAG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "neu_json_parser.h"
|
||||
|
||||
struct neu_parse_add_tags_req_tag {
|
||||
char *name;
|
||||
int type;
|
||||
int decimal;
|
||||
char *address;
|
||||
int flag;
|
||||
};
|
||||
|
||||
struct neu_parse_add_tags_req {
|
||||
enum neu_parse_function function;
|
||||
char * uuid;
|
||||
uint32_t node_id;
|
||||
int n_tag;
|
||||
struct neu_parse_add_tags_req_tag *tags;
|
||||
};
|
||||
|
||||
struct neu_parse_add_tags_res {
|
||||
enum neu_parse_function function;
|
||||
char * uuid;
|
||||
int error;
|
||||
};
|
||||
|
||||
int neu_parse_decode_add_tags_req(char * buf,
|
||||
struct neu_parse_add_tags_req **req);
|
||||
int neu_parse_encode_add_tags_res(struct neu_parse_add_tags_res *res,
|
||||
char ** buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,80 @@
|
||||
/**
|
||||
* 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 <stdlib.h>
|
||||
|
||||
#include "neu_json_delete_tag.h"
|
||||
#include "utils/json.h"
|
||||
|
||||
#define NODE_ID "node_id"
|
||||
#define TAG_ID "tag_id"
|
||||
|
||||
int neu_parse_decode_delete_tags_req(char * buf,
|
||||
struct neu_parse_delete_tags_req **result)
|
||||
{
|
||||
struct neu_parse_delete_tags_req *req =
|
||||
calloc(1, sizeof(struct neu_parse_delete_tags_req));
|
||||
neu_json_elem_t elem[] = { {
|
||||
.name = NEU_PARSE_UUID,
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = NODE_ID,
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = TAG_ID,
|
||||
.t = NEU_JSON_INT,
|
||||
} };
|
||||
|
||||
int ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(elem), elem);
|
||||
if (ret != 0) {
|
||||
free(req);
|
||||
return -1;
|
||||
}
|
||||
req->function = NEU_PARSE_OP_DELETE_TAGS;
|
||||
req->uuid = elem[0].v.val_str;
|
||||
req->node_id = elem[1].v.val_int;
|
||||
req->tag_id = elem[2].v.val_int;
|
||||
|
||||
*result = req;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int neu_parse_encode_delete_tags_res(struct neu_parse_delete_tags_res *res,
|
||||
char ** buf)
|
||||
{
|
||||
neu_json_elem_t elems[] = { {
|
||||
.name = NEU_PARSE_FUNCTION,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = NEU_PARSE_OP_DELETE_TAGS,
|
||||
},
|
||||
{
|
||||
.name = NEU_PARSE_UUID,
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = res->uuid,
|
||||
},
|
||||
{
|
||||
.name = NEU_PARSE_ERROR,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->error,
|
||||
} };
|
||||
|
||||
return neu_json_encode(elems, 3, buf);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* 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 _NEU_JSON_API_DELETE_TAG_H_
|
||||
#define _NEU_JSON_API_DELETE_TAG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "neu_json_parser.h"
|
||||
|
||||
struct neu_parse_delete_tags_req {
|
||||
enum neu_parse_function function;
|
||||
char * uuid;
|
||||
uint32_t node_id;
|
||||
uint32_t tag_id;
|
||||
};
|
||||
|
||||
struct neu_parse_delete_tags_res {
|
||||
enum neu_parse_function function;
|
||||
char * uuid;
|
||||
int error;
|
||||
};
|
||||
|
||||
int neu_parse_decode_delete_tags_req(char * buf,
|
||||
struct neu_parse_delete_tags_req **req);
|
||||
int neu_parse_encode_delete_tags_res(struct neu_parse_delete_tags_res *res,
|
||||
char ** buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,127 @@
|
||||
/**
|
||||
* 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 <stdlib.h>
|
||||
|
||||
#include "neu_json_get_tag.h"
|
||||
#include "utils/json.h"
|
||||
|
||||
#define NODE_ID "node_id"
|
||||
|
||||
#define TAGS "tags"
|
||||
#define NAME "name"
|
||||
#define TYPE "type"
|
||||
#define DECIMAL "decimal"
|
||||
#define ADDRESS "address"
|
||||
#define FLAG "flag"
|
||||
|
||||
int neu_parse_decode_get_tags_req(char * buf,
|
||||
struct neu_parse_get_tags_req **result)
|
||||
{
|
||||
struct neu_parse_get_tags_req *req =
|
||||
calloc(1, sizeof(struct neu_parse_get_tags_req));
|
||||
neu_json_elem_t elem[] = {
|
||||
{
|
||||
.name = NEU_PARSE_UUID,
|
||||
.t = NEU_JSON_STR,
|
||||
|
||||
},
|
||||
{
|
||||
.name = NODE_ID,
|
||||
.t = NEU_JSON_INT,
|
||||
}
|
||||
// {
|
||||
// .name = GROUP,
|
||||
// .t = NEU_JSON_STR,
|
||||
// },
|
||||
// {
|
||||
// .name = CONFIG,
|
||||
// .t = NEU_JSON_STR,
|
||||
// }
|
||||
|
||||
};
|
||||
|
||||
int ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(elem), elem);
|
||||
if (ret != 0) {
|
||||
free(req);
|
||||
return -1;
|
||||
}
|
||||
req->function = NEU_PARSE_OP_GET_TAGS;
|
||||
req->uuid = elem[0].v.val_str;
|
||||
req->node_id = elem[1].v.val_int;
|
||||
// req->group = elem[1].v.val_str;
|
||||
// req->config = elem[2].v.val_str;
|
||||
|
||||
*result = req;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int neu_parse_encode_get_tags_res(struct neu_parse_get_tags_res *res,
|
||||
char ** buf)
|
||||
{
|
||||
void *array = NULL;
|
||||
for (int i = 0; i < res->n_tag; i++) {
|
||||
neu_json_elem_t tag[] = { {
|
||||
.name = NAME,
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = res->tags[i].name,
|
||||
},
|
||||
{
|
||||
.name = TYPE,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->tags[i].type,
|
||||
},
|
||||
{
|
||||
.name = DECIMAL,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->tags[i].decimal,
|
||||
},
|
||||
{ .name = ADDRESS,
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = res->tags[i].address },
|
||||
{
|
||||
.name = FLAG,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->tags[i].flag,
|
||||
} };
|
||||
array = neu_json_encode_array(array, tag, 5);
|
||||
}
|
||||
neu_json_elem_t elems[] = { {
|
||||
.name = NEU_PARSE_FUNCTION,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = NEU_PARSE_OP_GET_TAGS,
|
||||
},
|
||||
{
|
||||
.name = NEU_PARSE_UUID,
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = res->uuid,
|
||||
},
|
||||
{
|
||||
.name = NEU_PARSE_ERROR,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->error,
|
||||
},
|
||||
{
|
||||
.name = TAGS,
|
||||
.t = NEU_JSON_OBJECT,
|
||||
.v.object = array,
|
||||
} };
|
||||
return neu_json_encode(elems, 4, buf);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* 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 _NEU_JSON_API_GTETAGLIST_H_
|
||||
#define _NEU_JSON_API_GTETAGLIST_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "neu_json_parser.h"
|
||||
|
||||
struct neu_parse_get_tags_res_tag {
|
||||
char *name;
|
||||
int type;
|
||||
int decimal;
|
||||
char *address;
|
||||
int flag;
|
||||
};
|
||||
|
||||
struct neu_parse_get_tags_req {
|
||||
enum neu_parse_function function;
|
||||
char * uuid;
|
||||
uint32_t node_id;
|
||||
// char * config;
|
||||
// char * group;
|
||||
};
|
||||
|
||||
struct neu_parse_get_tags_res {
|
||||
enum neu_parse_function function;
|
||||
char * uuid;
|
||||
int error;
|
||||
int n_tag;
|
||||
struct neu_parse_get_tags_res_tag *tags;
|
||||
};
|
||||
|
||||
int neu_parse_decode_get_tags_req(char * buf,
|
||||
struct neu_parse_get_tags_req **req);
|
||||
int neu_parse_encode_get_tags_res(struct neu_parse_get_tags_res *res,
|
||||
char ** buf);
|
||||
|
||||
#endif
|
||||
@@ -23,9 +23,13 @@
|
||||
#include "neu_log.h"
|
||||
#include "utils/json.h"
|
||||
|
||||
#include "neu_json_add_tag.h"
|
||||
#include "neu_json_delete_tag.h"
|
||||
#include "neu_json_get_tag.h"
|
||||
#include "neu_json_login.h"
|
||||
#include "neu_json_parser.h"
|
||||
#include "neu_json_read.h"
|
||||
#include "neu_json_updata_tag.h"
|
||||
#include "neu_json_write.h"
|
||||
|
||||
int neu_parse_decode(char *buf, void **result)
|
||||
@@ -54,6 +58,22 @@ int neu_parse_decode(char *buf, void **result)
|
||||
break;
|
||||
case NEU_PARSE_OP_LOGOUT:
|
||||
break;
|
||||
case NEU_PARSE_OP_ADD_TAGS:
|
||||
ret = neu_parse_decode_add_tags_req(
|
||||
buf, (struct neu_parse_add_tags_req **) result);
|
||||
break;
|
||||
case NEU_PARSE_OP_GET_TAGS:
|
||||
ret = neu_parse_decode_get_tags_req(
|
||||
buf, (struct neu_parse_get_tags_req **) result);
|
||||
break;
|
||||
case NEU_PARSE_OP_DELETE_TAGS:
|
||||
ret = neu_parse_decode_delete_tags_req(
|
||||
buf, (struct neu_parse_delete_tags_req **) result);
|
||||
break;
|
||||
case NEU_PARSE_OP_UPDATA_TAGS:
|
||||
ret = neu_parse_decode_updata_tags_req(
|
||||
buf, (struct neu_parse_updata_tags_req **) result);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -75,6 +95,22 @@ int neu_parse_encode(void *result, char **buf)
|
||||
break;
|
||||
case NEU_PARSE_OP_LOGOUT:
|
||||
break;
|
||||
case NEU_PARSE_OP_ADD_TAGS:
|
||||
neu_parse_encode_add_tags_res((struct neu_parse_add_tags_res *) result,
|
||||
buf);
|
||||
break;
|
||||
case NEU_PARSE_OP_GET_TAGS:
|
||||
neu_parse_encode_get_tags_res((struct neu_parse_get_tags_res *) result,
|
||||
buf);
|
||||
break;
|
||||
case NEU_PARSE_OP_DELETE_TAGS:
|
||||
neu_parse_encode_delete_tags_res(
|
||||
(struct neu_parse_delete_tags_res *) result, buf);
|
||||
break;
|
||||
case NEU_PARSE_OP_UPDATA_TAGS:
|
||||
neu_parse_encode_updata_tags_res(
|
||||
(struct neu_parse_updata_tags_res *) result, buf);
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -123,6 +159,40 @@ void neu_parse_decode_free(void *result)
|
||||
case NEU_PARSE_OP_LOGOUT: {
|
||||
break;
|
||||
}
|
||||
case NEU_PARSE_OP_ADD_TAGS: {
|
||||
struct neu_parse_add_tags_req *req = result;
|
||||
|
||||
free(req->uuid);
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
free(req->tags[i].name);
|
||||
free(req->tags[i].address);
|
||||
}
|
||||
free(req->tags);
|
||||
break;
|
||||
}
|
||||
case NEU_PARSE_OP_GET_TAGS: {
|
||||
struct neu_parse_get_tags_req *req = result;
|
||||
|
||||
free(req->uuid);
|
||||
break;
|
||||
}
|
||||
case NEU_PARSE_OP_DELETE_TAGS: {
|
||||
struct neu_parse_delete_tags_req *req = result;
|
||||
|
||||
free(req->uuid);
|
||||
break;
|
||||
}
|
||||
case NEU_PARSE_OP_UPDATA_TAGS: {
|
||||
struct neu_parse_updata_tags_req *req = result;
|
||||
|
||||
free(req->uuid);
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
free(req->tags[i].name);
|
||||
free(req->tags[i].address);
|
||||
}
|
||||
free(req->tags);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(result);
|
||||
|
||||
@@ -31,10 +31,14 @@ extern "C" {
|
||||
#define NEU_PARSE_ERROR "error"
|
||||
|
||||
enum neu_parse_function {
|
||||
NEU_PARSE_OP_READ = 50,
|
||||
NEU_PARSE_OP_WRITE = 51,
|
||||
NEU_PARSE_OP_LOGIN = 10,
|
||||
NEU_PARSE_OP_LOGOUT = 11
|
||||
NEU_PARSE_OP_READ = 50,
|
||||
NEU_PARSE_OP_WRITE = 51,
|
||||
NEU_PARSE_OP_LOGIN = 10,
|
||||
NEU_PARSE_OP_LOGOUT = 11,
|
||||
NEU_PARSE_OP_ADD_TAGS = 31,
|
||||
NEU_PARSE_OP_GET_TAGS = 32,
|
||||
NEU_PARSE_OP_DELETE_TAGS = 33,
|
||||
NEU_PARSE_OP_UPDATA_TAGS = 34
|
||||
};
|
||||
|
||||
int neu_parse_decode(char *buf, void **result);
|
||||
|
||||
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* 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 <stdlib.h>
|
||||
|
||||
#include "neu_json_updata_tag.h"
|
||||
#include "utils/json.h"
|
||||
|
||||
#define NODE_ID "node_id"
|
||||
#define TAG_ID "tag_id"
|
||||
|
||||
#define TAGS "tags"
|
||||
#define NAME "name"
|
||||
#define TYPE "type"
|
||||
#define DECIMAL "decimal"
|
||||
#define ADDRESS "address"
|
||||
#define FLAG "flag"
|
||||
|
||||
int neu_parse_decode_updata_tags_req(char * buf,
|
||||
struct neu_parse_updata_tags_req **result)
|
||||
{
|
||||
struct neu_parse_updata_tags_req *req =
|
||||
calloc(1, sizeof(struct neu_parse_updata_tags_req));
|
||||
neu_json_elem_t elem[] = { {
|
||||
.name = NEU_PARSE_UUID,
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = NODE_ID,
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = TAG_ID,
|
||||
.t = NEU_JSON_INT,
|
||||
}
|
||||
|
||||
};
|
||||
int ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(elem), elem);
|
||||
if (ret != 0) {
|
||||
free(req);
|
||||
return -1;
|
||||
}
|
||||
req->function = NEU_PARSE_OP_UPDATA_TAGS;
|
||||
req->uuid = elem[0].v.val_str;
|
||||
req->node_id = elem[1].v.val_int;
|
||||
req->tag_id = elem[2].v.val_int;
|
||||
|
||||
req->n_tag = neu_json_decode_array_size(buf, TAGS);
|
||||
req->tags =
|
||||
calloc(req->n_tag, sizeof(struct neu_parse_updata_tags_req_tag));
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
neu_json_elem_t celem[] = { {
|
||||
.name = NAME,
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = TYPE,
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = DECIMAL,
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = ADDRESS,
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = FLAG,
|
||||
.t = NEU_JSON_INT,
|
||||
} };
|
||||
|
||||
neu_json_decode_array(buf, TAGS, i, NEU_JSON_ELEM_SIZE(celem), celem);
|
||||
|
||||
req->tags[i].name = celem[0].v.val_str;
|
||||
req->tags[i].type = celem[1].v.val_int;
|
||||
req->tags[i].decimal = celem[2].v.val_int;
|
||||
req->tags[i].address = celem[3].v.val_str;
|
||||
req->tags[i].flag = celem[4].v.val_int;
|
||||
}
|
||||
|
||||
*result = req;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int neu_parse_encode_updata_tags_res(struct neu_parse_updata_tags_res *res,
|
||||
char ** buf)
|
||||
{
|
||||
neu_json_elem_t elems[] = { {
|
||||
.name = NEU_PARSE_FUNCTION,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = NEU_PARSE_OP_UPDATA_TAGS,
|
||||
},
|
||||
{
|
||||
.name = NEU_PARSE_UUID,
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = res->uuid,
|
||||
},
|
||||
{
|
||||
.name = NEU_PARSE_ERROR,
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->error,
|
||||
} };
|
||||
|
||||
return neu_json_encode(elems, 3, buf);
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* 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 _NEU_JSON_API_UPDATA_TAG_H_
|
||||
#define _NEU_JSON_API_UPDATA_TAG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "neu_json_parser.h"
|
||||
|
||||
struct neu_parse_updata_tags_req_tag {
|
||||
char *name;
|
||||
int type;
|
||||
int decimal;
|
||||
char *address;
|
||||
int flag;
|
||||
};
|
||||
|
||||
struct neu_parse_updata_tags_req {
|
||||
enum neu_parse_function function;
|
||||
char * uuid;
|
||||
uint32_t node_id;
|
||||
uint32_t tag_id;
|
||||
int n_tag;
|
||||
struct neu_parse_updata_tags_req_tag *tags;
|
||||
};
|
||||
|
||||
struct neu_parse_updata_tags_res {
|
||||
enum neu_parse_function function;
|
||||
char * uuid;
|
||||
int error;
|
||||
};
|
||||
|
||||
int neu_parse_decode_updata_tags_req(char * buf,
|
||||
struct neu_parse_updata_tags_req **req);
|
||||
int neu_parse_encode_updata_tags_res(struct neu_parse_updata_tags_res *res,
|
||||
char ** buf);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user