mirror of
https://github.com/emqx/neuron.git
synced 2026-10-17 04:40:42 +08:00
Automatically generated code replace neu_json_tag
This commit is contained in:
+1
-1
@@ -45,7 +45,7 @@ typedef union neu_json_value {
|
||||
double val_double;
|
||||
bool val_bool;
|
||||
char * val_str;
|
||||
void * object;
|
||||
void * val_object;
|
||||
} neu_json_value_u;
|
||||
|
||||
typedef struct neu_json_elem {
|
||||
|
||||
@@ -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.
|
||||
**/
|
||||
|
||||
/*
|
||||
* DO NOT EDIT THIS FILE MANUALLY!
|
||||
* It was automatically generated by `json-autotype`.
|
||||
*/
|
||||
|
||||
#ifndef _NEU_JSON_API_NEU_JSON_ADD_TAG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char * address;
|
||||
char * name;
|
||||
int64_t type;
|
||||
int64_t attribute;
|
||||
} neu_parse_add_tags_req_tag_t;
|
||||
|
||||
typedef struct {
|
||||
int n_tag;
|
||||
neu_parse_add_tags_req_tag_t *tags;
|
||||
char * group_config_name;
|
||||
int64_t node_id;
|
||||
} neu_parse_add_tags_req_t;
|
||||
|
||||
int neu_parse_decode_add_tags_req(char *buf, neu_parse_add_tags_req_t **result);
|
||||
void neu_parse_decode_add_tags_req_free(neu_parse_add_tags_req_t *req);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
/*
|
||||
* DO NOT EDIT THIS FILE MANUALLY!
|
||||
* It was automatically generated by `json-autotype`.
|
||||
*/
|
||||
|
||||
#ifndef _NEU_JSON_API_NEU_JSON_DEL_TAG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef int64_t neu_parse_del_tags_req_tag_id_t;
|
||||
|
||||
typedef struct {
|
||||
char * group_config_name;
|
||||
int n_tag_id;
|
||||
neu_parse_del_tags_req_tag_id_t *tag_ids;
|
||||
int64_t node_id;
|
||||
} neu_parse_del_tags_req_t;
|
||||
|
||||
int neu_parse_decode_del_tags_req(char *buf, neu_parse_del_tags_req_t **result);
|
||||
void neu_parse_decode_del_tags_req_free(neu_parse_del_tags_req_t *req);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
/*
|
||||
* DO NOT EDIT THIS FILE MANUALLY!
|
||||
* It was automatically generated by `json-autotype`.
|
||||
*/
|
||||
|
||||
#ifndef _NEU_JSON_API_NEU_JSON_GET_TAG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char * group_config_name;
|
||||
int64_t node_id;
|
||||
} neu_parse_get_tags_req_t;
|
||||
|
||||
int neu_parse_decode_get_tags_req(char *buf, neu_parse_get_tags_req_t **result);
|
||||
void neu_parse_decode_get_tags_req_free(neu_parse_get_tags_req_t *req);
|
||||
|
||||
typedef struct {
|
||||
char * group_config_name;
|
||||
char * address;
|
||||
char * name;
|
||||
int64_t type;
|
||||
int64_t attribute;
|
||||
int64_t id;
|
||||
} neu_parse_get_tags_resp_tag_t;
|
||||
|
||||
typedef struct {
|
||||
int n_tag;
|
||||
neu_parse_get_tags_resp_tag_t *tags;
|
||||
} neu_parse_get_tags_resp_t;
|
||||
|
||||
int neu_parse_encode_get_tags_resp(void *json_object, void *param);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -1,98 +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 _NEU_JSON_API_ADD_TAG_H_
|
||||
#define _NEU_JSON_API_ADD_TAG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
char *name;
|
||||
char *address;
|
||||
int type;
|
||||
int attribute;
|
||||
} neu_parse_add_tags_req_tag_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t node_id;
|
||||
char * group_config_name;
|
||||
int n_tag;
|
||||
neu_parse_add_tags_req_tag_t *tags;
|
||||
} neu_parse_add_tags_req_t;
|
||||
|
||||
int neu_parse_decode_add_tags(char *buf, neu_parse_add_tags_req_t **req);
|
||||
void neu_parse_decode_add_tags_free(neu_parse_add_tags_req_t *req);
|
||||
|
||||
typedef struct {
|
||||
char * group_config_name;
|
||||
uint32_t node_id;
|
||||
int n_tag_id;
|
||||
uint32_t *tag_ids;
|
||||
} neu_parse_del_tags_req_t;
|
||||
|
||||
int neu_parse_decode_del_tags(char *buf, neu_parse_del_tags_req_t **req);
|
||||
void neu_parse_decode_del_tags_free(neu_parse_del_tags_req_t *req);
|
||||
|
||||
typedef struct {
|
||||
uint32_t tag_id;
|
||||
char * name;
|
||||
int type;
|
||||
char * address;
|
||||
int attribute;
|
||||
} neu_parse_update_tags_req_tag_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t node_id;
|
||||
int n_tag;
|
||||
neu_parse_update_tags_req_tag_t *tags;
|
||||
} neu_parse_update_tags_req_t;
|
||||
|
||||
int neu_parse_decode_update_tags(char *buf, neu_parse_update_tags_req_t **req);
|
||||
void neu_parse_decode_update_tags_free(neu_parse_update_tags_req_t *req);
|
||||
|
||||
typedef struct {
|
||||
uint32_t id;
|
||||
char * name;
|
||||
char * group_config_name;
|
||||
char * address;
|
||||
int type;
|
||||
int attribute;
|
||||
} neu_parse_get_tags_res_tag_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t node_id;
|
||||
} neu_parse_get_tags_req_t;
|
||||
|
||||
typedef struct {
|
||||
int n_tag;
|
||||
neu_parse_get_tags_res_tag_t *tags;
|
||||
} neu_parse_get_tags_res_t;
|
||||
|
||||
int neu_parse_decode_get_tags(char *buf, neu_parse_get_tags_req_t **req);
|
||||
void neu_parse_decode_get_tags_free(neu_parse_get_tags_req_t *req);
|
||||
int neu_parse_encode_get_tags(void *json_object, void *param);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
/*
|
||||
* DO NOT EDIT THIS FILE MANUALLY!
|
||||
* It was automatically generated by `json-autotype`.
|
||||
*/
|
||||
|
||||
#ifndef _NEU_JSON_API_NEU_JSON_UPDATE_TAG_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
char * address;
|
||||
char * name;
|
||||
int64_t type;
|
||||
int64_t attribute;
|
||||
int64_t id;
|
||||
} neu_parse_update_tags_req_tag_t;
|
||||
|
||||
typedef struct {
|
||||
int n_tag;
|
||||
neu_parse_update_tags_req_tag_t *tags;
|
||||
int64_t node_id;
|
||||
} neu_parse_update_tags_req_t;
|
||||
|
||||
int neu_parse_decode_update_tags_req(char * buf,
|
||||
neu_parse_update_tags_req_t **result);
|
||||
void neu_parse_decode_update_tags_req_free(neu_parse_update_tags_req_t *req);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"add_tags_req": {
|
||||
"node_id": 4,
|
||||
"group_config_name": "config_modbus_tcp_sample_2",
|
||||
"tags": [
|
||||
{
|
||||
"name": "tag1",
|
||||
"address": "1!400001",
|
||||
"attribute": 1,
|
||||
"type": 4
|
||||
},
|
||||
{
|
||||
"name": "tag2",
|
||||
"address": "1!00001",
|
||||
"attribute": 3,
|
||||
"type": 14
|
||||
},
|
||||
{
|
||||
"name": "tag3",
|
||||
"address": "1!400009",
|
||||
"attribute": 3,
|
||||
"type": 11
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"del_tags_req": {
|
||||
"node_id": 4,
|
||||
"group_config_name": "config_modbus_tcp_sample_2",
|
||||
"tag_ids": [
|
||||
4,
|
||||
5
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"get_tags_req": {
|
||||
"node_id": 4,
|
||||
"group_config_name": "config_modbus_tcp_sample_2"
|
||||
},
|
||||
"get_tags_resp": {
|
||||
"tags": [
|
||||
{
|
||||
"name": "tag1",
|
||||
"type": 4,
|
||||
"address": "1!400001",
|
||||
"attribute": 1,
|
||||
"group_config_name": "config_modbus_tcp_sample_2",
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"name": "tag2",
|
||||
"type": 14,
|
||||
"address": "1!00001",
|
||||
"attribute": 3,
|
||||
"group_config_name": "config_modbus_tcp_sample_2",
|
||||
"id": 4
|
||||
},
|
||||
{
|
||||
"name": "tag3",
|
||||
"type": 11,
|
||||
"address": "1!400009",
|
||||
"attribute": 3,
|
||||
"group_config_name": "config_modbus_tcp_sample_2",
|
||||
"id": 5
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"update_tags_req": {
|
||||
"node_id": 4,
|
||||
"tags": [
|
||||
{
|
||||
"id": 4,
|
||||
"name": "tag1",
|
||||
"type": 6,
|
||||
"attribute": 0,
|
||||
"address": "1!400001"
|
||||
},
|
||||
{
|
||||
"id": 5,
|
||||
"name": "tag2",
|
||||
"type": 6,
|
||||
"attribute": 0,
|
||||
"address": "1!400002"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -95,37 +95,37 @@ void command_response_handle(mqtt_response_t *response)
|
||||
}
|
||||
case NEU_MQTT_OP_GET_TAGS: {
|
||||
neu_parse_get_tags_req_t *req = NULL;
|
||||
rc = neu_parse_decode_get_tags(json_str, &req);
|
||||
rc = neu_parse_decode_get_tags_req(json_str, &req);
|
||||
if (0 == rc) {
|
||||
ret_str = command_get_tags(plugin, mqtt, req);
|
||||
neu_parse_decode_get_tags_free(req);
|
||||
neu_parse_decode_get_tags_req_free(req);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_MQTT_OP_ADD_TAGS: {
|
||||
neu_parse_add_tags_req_t *req = NULL;
|
||||
rc = neu_parse_decode_add_tags(json_str, &req);
|
||||
rc = neu_parse_decode_add_tags_req(json_str, &req);
|
||||
if (0 == rc) {
|
||||
ret_str = command_add_tags(plugin, mqtt, req);
|
||||
neu_parse_decode_add_tags_free(req);
|
||||
neu_parse_decode_add_tags_req_free(req);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_MQTT_OP_UPDATE_TAGS: {
|
||||
neu_parse_update_tags_req_t *req = NULL;
|
||||
rc = neu_parse_decode_update_tags(json_str, &req);
|
||||
rc = neu_parse_decode_update_tags_req(json_str, &req);
|
||||
if (0 == rc) {
|
||||
ret_str = command_update_tags(plugin, mqtt, req);
|
||||
neu_parse_decode_update_tags_free(req);
|
||||
neu_parse_decode_update_tags_req_free(req);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NEU_MQTT_OP_DELETE_TAGS: {
|
||||
neu_parse_del_tags_req_t *req = NULL;
|
||||
rc = neu_parse_decode_del_tags(json_str, &req);
|
||||
rc = neu_parse_decode_del_tags_req(json_str, &req);
|
||||
if (0 == rc) {
|
||||
ret_str = command_delete_tags(plugin, mqtt, req);
|
||||
neu_parse_decode_del_tags_free(req);
|
||||
neu_parse_decode_del_tags_req_free(req);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -25,12 +25,17 @@ extern "C" {
|
||||
|
||||
#include <neuron.h>
|
||||
|
||||
// #include "json/neu_group_config.h"
|
||||
#include "json/neu_json_add_tag.h"
|
||||
#include "json/neu_json_del_tag.h"
|
||||
#include "json/neu_json_fn.h"
|
||||
#include "json/neu_json_get_tag.h"
|
||||
#include "json/neu_json_group_config.h"
|
||||
#include "json/neu_json_mqtt.h"
|
||||
#include "json/neu_json_node.h"
|
||||
#include "json/neu_json_rw.h"
|
||||
#include "json/neu_json_tag.h"
|
||||
#include "json/neu_json_update_tag.h"
|
||||
// #include "json/neu_json_tag.h"
|
||||
|
||||
#define UNUSED(x) (void) (x)
|
||||
|
||||
|
||||
@@ -108,12 +108,12 @@ static int get_all_tag(neu_plugin_t *plugin, const uint32_t node_id,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int wrap_get_tags_response_json_object(vector_t * tags,
|
||||
neu_parse_get_tags_res_t *json)
|
||||
static int wrap_get_tags_response_json_object(vector_t * tags,
|
||||
neu_parse_get_tags_resp_t *json)
|
||||
{
|
||||
json->n_tag = tags->size;
|
||||
json->tags = malloc(tags->size * sizeof(neu_parse_get_tags_res_tag_t));
|
||||
memset(json->tags, 0, tags->size * sizeof(neu_parse_get_tags_res_tag_t));
|
||||
json->tags = malloc(tags->size * sizeof(neu_parse_get_tags_resp_tag_t));
|
||||
memset(json->tags, 0, tags->size * sizeof(neu_parse_get_tags_resp_tag_t));
|
||||
|
||||
tag_t *tag = NULL;
|
||||
int size = tags->size;
|
||||
@@ -134,8 +134,8 @@ static int wrap_get_tags_response_json_object(vector_t * tags,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void free_get_tags_response_object(vector_t * tags,
|
||||
neu_parse_get_tags_res_t *json)
|
||||
static void free_get_tags_response_object(vector_t * tags,
|
||||
neu_parse_get_tags_resp_t *json)
|
||||
{
|
||||
tag_t *tag = NULL;
|
||||
int size = tags->size;
|
||||
@@ -165,9 +165,9 @@ char *command_get_tags(neu_plugin_t *plugin, neu_parse_mqtt_t *mqtt,
|
||||
neu_parse_get_tags_req_t *req)
|
||||
{
|
||||
log_info("Get tag list uuid:%s, node id:%d", mqtt->uuid, req->node_id);
|
||||
char * json_str = NULL;
|
||||
neu_parse_get_tags_res_t res = { 0 };
|
||||
neu_parse_error_t error = { 0 };
|
||||
char * json_str = NULL;
|
||||
neu_parse_get_tags_resp_t res = { 0 };
|
||||
neu_parse_error_t error = { 0 };
|
||||
|
||||
uint32_t node_id = req->node_id;
|
||||
vector_t tags;
|
||||
@@ -185,7 +185,7 @@ char *command_get_tags(neu_plugin_t *plugin, neu_parse_mqtt_t *mqtt,
|
||||
}
|
||||
|
||||
rc = wrap_get_tags_response_json_object(&tags, &res);
|
||||
rc = neu_json_encode_with_mqtt(&res, neu_parse_encode_get_tags, mqtt,
|
||||
rc = neu_json_encode_with_mqtt(&res, neu_parse_encode_get_tags_resp, mqtt,
|
||||
neu_parse_encode_mqtt_param, &json_str);
|
||||
|
||||
free_get_tags_response_object(&tags, &res);
|
||||
@@ -302,8 +302,7 @@ char *command_update_tags(neu_plugin_t *plugin, neu_parse_mqtt_t *mqtt,
|
||||
}
|
||||
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
neu_datatag_t *datatag =
|
||||
neu_datatag_tbl_get(table, req->tags[i].tag_id);
|
||||
neu_datatag_t *datatag = neu_datatag_tbl_get(table, req->tags[i].id);
|
||||
|
||||
if (NULL == datatag) {
|
||||
continue;
|
||||
@@ -312,12 +311,12 @@ char *command_update_tags(neu_plugin_t *plugin, neu_parse_mqtt_t *mqtt,
|
||||
free(datatag->name);
|
||||
free(datatag->addr_str);
|
||||
|
||||
datatag->id = req->tags[i].tag_id;
|
||||
datatag->id = req->tags[i].id;
|
||||
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);
|
||||
rc = neu_datatag_tbl_update(table, req->tags[i].tag_id, datatag);
|
||||
rc = neu_datatag_tbl_update(table, req->tags[i].id, datatag);
|
||||
|
||||
log_info("Update datatag to the datatag table, id:%ld", datatag->id);
|
||||
}
|
||||
|
||||
@@ -45,8 +45,9 @@ char *command_get_nodes(neu_plugin_t *plugin, neu_parse_mqtt_t *mqtt,
|
||||
}
|
||||
|
||||
char *json_str = NULL;
|
||||
int rc = neu_json_encode_with_mqtt(&res, neu_parse_encode_get_tags, mqtt,
|
||||
neu_parse_encode_mqtt_param, &json_str);
|
||||
int rc =
|
||||
neu_json_encode_with_mqtt(&res, neu_parse_encode_get_tags_resp, mqtt,
|
||||
neu_parse_encode_mqtt_param, &json_str);
|
||||
if (0 == rc) {
|
||||
return json_str;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,12 @@
|
||||
#include "neu_datatag_table.h"
|
||||
#include "neu_log.h"
|
||||
#include "neu_plugin.h"
|
||||
#include "json/neu_json_add_tag.h"
|
||||
#include "json/neu_json_del_tag.h"
|
||||
#include "json/neu_json_fn.h"
|
||||
#include "json/neu_json_tag.h"
|
||||
#include "json/neu_json_get_tag.h"
|
||||
#include "json/neu_json_update_tag.h"
|
||||
// #include "json/neu_json_tag.h"
|
||||
|
||||
#include "handle.h"
|
||||
#include "http.h"
|
||||
@@ -36,7 +40,7 @@ void handle_add_tags(nng_aio *aio)
|
||||
neu_plugin_t *plugin = neu_rest_get_plugin();
|
||||
|
||||
REST_PROCESS_HTTP_REQUEST(
|
||||
aio, neu_parse_add_tags_req_t, neu_parse_decode_add_tags, {
|
||||
aio, neu_parse_add_tags_req_t, neu_parse_decode_add_tags_req, {
|
||||
neu_taggrp_config_t *config = neu_system_find_group_config(
|
||||
plugin, req->node_id, req->group_config_name);
|
||||
neu_datatag_table_t *table =
|
||||
@@ -70,7 +74,7 @@ void handle_del_tags(nng_aio *aio)
|
||||
neu_plugin_t *plugin = neu_rest_get_plugin();
|
||||
|
||||
REST_PROCESS_HTTP_REQUEST(
|
||||
aio, neu_parse_del_tags_req_t, neu_parse_decode_del_tags, {
|
||||
aio, neu_parse_del_tags_req_t, neu_parse_decode_del_tags_req, {
|
||||
neu_taggrp_config_t *config = neu_system_find_group_config(
|
||||
plugin, req->node_id, req->group_config_name);
|
||||
neu_datatag_table_t *table =
|
||||
@@ -103,7 +107,7 @@ void handle_update_tags(nng_aio *aio)
|
||||
neu_plugin_t *plugin = neu_rest_get_plugin();
|
||||
|
||||
REST_PROCESS_HTTP_REQUEST(
|
||||
aio, neu_parse_update_tags_req_t, neu_parse_decode_update_tags, {
|
||||
aio, neu_parse_update_tags_req_t, neu_parse_decode_update_tags_req, {
|
||||
neu_datatag_table_t *table =
|
||||
neu_system_get_datatags_table(plugin, req->node_id);
|
||||
if (table == NULL) {
|
||||
@@ -111,7 +115,7 @@ void handle_update_tags(nng_aio *aio)
|
||||
} else {
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
neu_datatag_t *tag =
|
||||
neu_datatag_tbl_get(table, req->tags[i].tag_id);
|
||||
neu_datatag_tbl_get(table, req->tags[i].id);
|
||||
|
||||
free(tag->addr_str);
|
||||
free(tag->name);
|
||||
@@ -120,7 +124,7 @@ void handle_update_tags(nng_aio *aio)
|
||||
tag->type = req->tags[i].type;
|
||||
tag->attribute = req->tags[i].attribute;
|
||||
|
||||
neu_datatag_tbl_update(table, req->tags[i].tag_id, tag);
|
||||
neu_datatag_tbl_update(table, req->tags[i].id, tag);
|
||||
}
|
||||
|
||||
http_ok(aio, "{\"error\": 0}");
|
||||
@@ -147,9 +151,9 @@ void handle_get_tags(nng_aio *aio)
|
||||
http_not_found(aio, "{\"error\": 1}");
|
||||
} else {
|
||||
vector_t grp_configs = neu_system_get_group_configs(plugin, node_id);
|
||||
neu_parse_get_tags_res_t tags_res = { 0 };
|
||||
int index = 0;
|
||||
char * result = NULL;
|
||||
neu_parse_get_tags_resp_t tags_res = { 0 };
|
||||
int index = 0;
|
||||
char * result = NULL;
|
||||
|
||||
VECTOR_FOR_EACH(&grp_configs, iter)
|
||||
{
|
||||
@@ -166,7 +170,7 @@ void handle_get_tags(nng_aio *aio)
|
||||
}
|
||||
|
||||
tags_res.tags =
|
||||
calloc(tags_res.n_tag, sizeof(neu_parse_get_tags_res_tag_t));
|
||||
calloc(tags_res.n_tag, sizeof(neu_parse_get_tags_resp_tag_t));
|
||||
|
||||
VECTOR_FOR_EACH(&grp_configs, iter)
|
||||
{
|
||||
@@ -198,7 +202,8 @@ void handle_get_tags(nng_aio *aio)
|
||||
}
|
||||
}
|
||||
|
||||
neu_json_encode_by_fn(&tags_res, neu_parse_encode_get_tags, &result);
|
||||
neu_json_encode_by_fn(&tags_res, neu_parse_encode_get_tags_resp,
|
||||
&result);
|
||||
|
||||
http_ok(aio, result);
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "neu_log.h"
|
||||
#include "neu_plugin.h"
|
||||
#include "neu_subscribe.h"
|
||||
// #include "json/neu_group_config.h"
|
||||
#include "json/neu_json_fn.h"
|
||||
#include "json/neu_json_group_config.h"
|
||||
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
/*
|
||||
* DO NOT EDIT THIS FILE MANUALLY!
|
||||
* It was automatically generated by `json-autotype`.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "json/json.h"
|
||||
|
||||
#include "json/neu_json_add_tag.h"
|
||||
|
||||
int neu_parse_decode_add_tags_req(char *buf, neu_parse_add_tags_req_t **result)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
neu_parse_add_tags_req_t *req = calloc(1, sizeof(neu_parse_add_tags_req_t));
|
||||
neu_json_elem_t req_elems[] = { {
|
||||
.name = "node_id",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "group_config_name",
|
||||
.t = NEU_JSON_STR,
|
||||
} };
|
||||
ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(req_elems), req_elems);
|
||||
if (ret != 0) {
|
||||
goto decode_fail;
|
||||
}
|
||||
|
||||
req->node_id = req_elems[0].v.val_int;
|
||||
req->group_config_name = req_elems[1].v.val_str;
|
||||
|
||||
req->n_tag = neu_json_decode_array_size(buf, "tags");
|
||||
req->tags = calloc(req->n_tag, sizeof(neu_parse_add_tags_req_tag_t));
|
||||
neu_parse_add_tags_req_tag_t *p_tag = req->tags;
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
neu_json_elem_t tag_elems[] = { {
|
||||
.name = "type",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "name",
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = "attribute",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "address",
|
||||
.t = NEU_JSON_STR,
|
||||
} };
|
||||
ret = neu_json_decode_array(buf, "tags", i,
|
||||
NEU_JSON_ELEM_SIZE(tag_elems), tag_elems);
|
||||
if (ret != 0) {
|
||||
goto decode_fail;
|
||||
}
|
||||
|
||||
p_tag->type = tag_elems[0].v.val_int;
|
||||
p_tag->name = tag_elems[1].v.val_str;
|
||||
p_tag->attribute = tag_elems[2].v.val_int;
|
||||
p_tag->address = tag_elems[3].v.val_str;
|
||||
p_tag++;
|
||||
}
|
||||
|
||||
*result = req;
|
||||
return ret;
|
||||
|
||||
decode_fail:
|
||||
if (req->tags != NULL) {
|
||||
free(req->tags);
|
||||
}
|
||||
if (req != NULL) {
|
||||
free(req);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void neu_parse_decode_add_tags_req_free(neu_parse_add_tags_req_t *req)
|
||||
{
|
||||
|
||||
neu_parse_add_tags_req_tag_t *p_tag = req->tags;
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
free(p_tag->name);
|
||||
free(p_tag->address);
|
||||
p_tag++;
|
||||
}
|
||||
|
||||
free(req->tags);
|
||||
free(req->group_config_name);
|
||||
|
||||
free(req);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
/*
|
||||
* DO NOT EDIT THIS FILE MANUALLY!
|
||||
* It was automatically generated by `json-autotype`.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "json/json.h"
|
||||
|
||||
#include "json/neu_json_del_tag.h"
|
||||
|
||||
int neu_parse_decode_del_tags_req(char *buf, neu_parse_del_tags_req_t **result)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
neu_parse_del_tags_req_t *req = calloc(1, sizeof(neu_parse_del_tags_req_t));
|
||||
neu_json_elem_t req_elems[] = { {
|
||||
.name = "node_id",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "group_config_name",
|
||||
.t = NEU_JSON_STR,
|
||||
} };
|
||||
ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(req_elems), req_elems);
|
||||
if (ret != 0) {
|
||||
goto decode_fail;
|
||||
}
|
||||
|
||||
req->node_id = req_elems[0].v.val_int;
|
||||
req->group_config_name = req_elems[1].v.val_str;
|
||||
|
||||
req->n_tag_id = neu_json_decode_array_size(buf, "tag_ids");
|
||||
req->tag_ids =
|
||||
calloc(req->n_tag_id, sizeof(neu_parse_del_tags_req_tag_id_t));
|
||||
neu_parse_del_tags_req_tag_id_t *p_tag_id = req->tag_ids;
|
||||
for (int i = 0; i < req->n_tag_id; i++) {
|
||||
neu_json_elem_t tag_id_elems[] = { {
|
||||
.name = NULL,
|
||||
.t = NEU_JSON_INT,
|
||||
} };
|
||||
ret = neu_json_decode_array(
|
||||
buf, "tag_ids", i, NEU_JSON_ELEM_SIZE(tag_id_elems), tag_id_elems);
|
||||
if (ret != 0) {
|
||||
goto decode_fail;
|
||||
}
|
||||
|
||||
*p_tag_id = tag_id_elems[0].v.val_int;
|
||||
p_tag_id++;
|
||||
}
|
||||
|
||||
*result = req;
|
||||
return ret;
|
||||
|
||||
decode_fail:
|
||||
if (req->tag_ids != NULL) {
|
||||
free(req->tag_ids);
|
||||
}
|
||||
if (req != NULL) {
|
||||
free(req);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void neu_parse_decode_del_tags_req_free(neu_parse_del_tags_req_t *req)
|
||||
{
|
||||
|
||||
free(req->tag_ids);
|
||||
free(req->group_config_name);
|
||||
|
||||
free(req);
|
||||
}
|
||||
@@ -93,7 +93,7 @@ int neu_parse_param(char *buf, char **err_param, int n, neu_json_elem_t *ele,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (neu_json_decode_value(params_ele.v.object, ele) != 0) {
|
||||
if (neu_json_decode_value(params_ele.v.val_object, ele) != 0) {
|
||||
*err_param = strdup(ele->name);
|
||||
neu_json_decode_free(json);
|
||||
return -1;
|
||||
@@ -102,7 +102,7 @@ int neu_parse_param(char *buf, char **err_param, int n, neu_json_elem_t *ele,
|
||||
va_start(ap, ele);
|
||||
for (int i = 1; i < n; i++) {
|
||||
neu_json_elem_t *tmp_ele = va_arg(ap, neu_json_elem_t *);
|
||||
if (neu_json_decode_value(params_ele.v.object, tmp_ele) != 0) {
|
||||
if (neu_json_decode_value(params_ele.v.val_object, tmp_ele) != 0) {
|
||||
*err_param = strdup(tmp_ele->name);
|
||||
ret = -1;
|
||||
break;
|
||||
|
||||
@@ -0,0 +1,124 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
/*
|
||||
* DO NOT EDIT THIS FILE MANUALLY!
|
||||
* It was automatically generated by `json-autotype`.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "json/json.h"
|
||||
|
||||
#include "json/neu_json_get_tag.h"
|
||||
|
||||
int neu_parse_decode_get_tags_req(char *buf, neu_parse_get_tags_req_t **result)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
neu_parse_get_tags_req_t *req = calloc(1, sizeof(neu_parse_get_tags_req_t));
|
||||
neu_json_elem_t req_elems[] = { {
|
||||
.name = "node_id",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "group_config_name",
|
||||
.t = NEU_JSON_STR,
|
||||
} };
|
||||
ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(req_elems), req_elems);
|
||||
if (ret != 0) {
|
||||
goto decode_fail;
|
||||
}
|
||||
|
||||
req->node_id = req_elems[0].v.val_int;
|
||||
req->group_config_name = req_elems[1].v.val_str;
|
||||
|
||||
*result = req;
|
||||
return ret;
|
||||
|
||||
decode_fail:
|
||||
if (req != NULL) {
|
||||
free(req);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void neu_parse_decode_get_tags_req_free(neu_parse_get_tags_req_t *req)
|
||||
{
|
||||
|
||||
free(req->group_config_name);
|
||||
|
||||
free(req);
|
||||
}
|
||||
|
||||
int neu_parse_encode_get_tags_resp(void *json_object, void *param)
|
||||
{
|
||||
int ret = 0;
|
||||
neu_parse_get_tags_resp_t *resp = (neu_parse_get_tags_resp_t *) param;
|
||||
|
||||
void * tag_array = NULL;
|
||||
neu_parse_get_tags_resp_tag_t *p_tag = resp->tags;
|
||||
for (int i = 0; i < resp->n_tag; i++) {
|
||||
neu_json_elem_t tag_elems[] = { {
|
||||
.name = "type",
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = p_tag->type,
|
||||
},
|
||||
{
|
||||
.name = "name",
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = p_tag->name,
|
||||
},
|
||||
{
|
||||
.name = "id",
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = p_tag->id,
|
||||
},
|
||||
{
|
||||
.name = "group_config_name",
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str =
|
||||
p_tag->group_config_name,
|
||||
},
|
||||
{
|
||||
.name = "attribute",
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = p_tag->attribute,
|
||||
},
|
||||
{
|
||||
.name = "address",
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = p_tag->address,
|
||||
} };
|
||||
tag_array = neu_json_encode_array(tag_array, tag_elems,
|
||||
NEU_JSON_ELEM_SIZE(tag_elems));
|
||||
p_tag++;
|
||||
}
|
||||
|
||||
neu_json_elem_t resp_elems[] = { {
|
||||
.name = "tags",
|
||||
.t = NEU_JSON_OBJECT,
|
||||
.v.val_object = tag_array,
|
||||
} };
|
||||
ret = neu_json_encode_field(json_object, resp_elems,
|
||||
NEU_JSON_ELEM_SIZE(resp_elems));
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -211,9 +211,9 @@ int neu_parse_encode_get_group_config(void *json_object, void *param)
|
||||
array = neu_json_encode_array(array, group, 4);
|
||||
}
|
||||
neu_json_elem_t elems[] = { {
|
||||
.name = "group_configs",
|
||||
.t = NEU_JSON_OBJECT,
|
||||
.v.object = array,
|
||||
.name = "group_configs",
|
||||
.t = NEU_JSON_OBJECT,
|
||||
.v.val_object = array,
|
||||
} };
|
||||
|
||||
return neu_json_encode_field(json_object, elems, 1);
|
||||
@@ -323,9 +323,9 @@ int neu_parse_encode_get_subscribe(void *json_object, void *param)
|
||||
}
|
||||
|
||||
neu_json_elem_t elems[] = { {
|
||||
.name = "groups",
|
||||
.t = NEU_JSON_OBJECT,
|
||||
.v.object = array,
|
||||
.name = "groups",
|
||||
.t = NEU_JSON_OBJECT,
|
||||
.v.val_object = array,
|
||||
} };
|
||||
|
||||
return neu_json_encode_field(json_object, elems, 1);
|
||||
|
||||
@@ -177,9 +177,9 @@ int neu_parse_encode_get_nodes(void *json_object, void *param)
|
||||
array = neu_json_encode_array(array, nodes, NEU_JSON_ELEM_SIZE(nodes));
|
||||
}
|
||||
neu_json_elem_t elems[] = { {
|
||||
.name = "nodes",
|
||||
.t = NEU_JSON_OBJECT,
|
||||
.v.object = array,
|
||||
.name = "nodes",
|
||||
.t = NEU_JSON_OBJECT,
|
||||
.v.val_object = array,
|
||||
} };
|
||||
|
||||
return neu_json_encode_field(json_object, elems, 1);
|
||||
|
||||
@@ -192,9 +192,9 @@ int neu_parse_encode_get_plugins(void *json_object, void *param)
|
||||
array = neu_json_encode_array(array, plugin_libs, 5);
|
||||
}
|
||||
neu_json_elem_t elems[] = { {
|
||||
.name = "plugin_libs",
|
||||
.t = NEU_JSON_OBJECT,
|
||||
.v.object = array,
|
||||
.name = "plugin_libs",
|
||||
.t = NEU_JSON_OBJECT,
|
||||
.v.val_object = array,
|
||||
} };
|
||||
|
||||
return neu_json_encode_field(json_object, elems, 1);
|
||||
|
||||
@@ -77,9 +77,9 @@ int neu_parse_encode_read(void *json_object, void *param)
|
||||
array = neu_json_encode_array(array, tag, 2);
|
||||
}
|
||||
neu_json_elem_t elems[] = { {
|
||||
.name = "tags",
|
||||
.t = NEU_JSON_OBJECT,
|
||||
.v.object = array,
|
||||
.name = "tags",
|
||||
.t = NEU_JSON_OBJECT,
|
||||
.v.val_object = array,
|
||||
} };
|
||||
|
||||
return neu_json_encode_field(json_object, elems, 1);
|
||||
|
||||
@@ -1,279 +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 <stdlib.h>
|
||||
|
||||
#include "json/json.h"
|
||||
#include "json/neu_json_tag.h"
|
||||
|
||||
int neu_parse_decode_add_tags(char *buf, neu_parse_add_tags_req_t **result)
|
||||
{
|
||||
neu_parse_add_tags_req_t *req = calloc(1, sizeof(neu_parse_add_tags_req_t));
|
||||
neu_json_elem_t elem[] = {
|
||||
{
|
||||
.name = "node_id",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "group_config_name",
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
};
|
||||
|
||||
int ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(elem), elem);
|
||||
if (ret != 0) {
|
||||
free(req);
|
||||
return -1;
|
||||
}
|
||||
req->node_id = elem[0].v.val_int;
|
||||
req->group_config_name = elem[1].v.val_str;
|
||||
|
||||
req->n_tag = neu_json_decode_array_size(buf, "tags");
|
||||
req->tags = calloc(req->n_tag, sizeof(neu_parse_add_tags_req_tag_t));
|
||||
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 = "address",
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = "attribute",
|
||||
.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].address = celem[2].v.val_str;
|
||||
req->tags[i].attribute = celem[3].v.val_int;
|
||||
}
|
||||
|
||||
*result = req;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void neu_parse_decode_add_tags_free(neu_parse_add_tags_req_t *req)
|
||||
{
|
||||
free(req->group_config_name);
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
free(req->tags[i].name);
|
||||
free(req->tags[i].address);
|
||||
}
|
||||
|
||||
free(req->tags);
|
||||
free(req);
|
||||
}
|
||||
|
||||
int neu_parse_decode_del_tags(char *buf, neu_parse_del_tags_req_t **result)
|
||||
{
|
||||
neu_parse_del_tags_req_t *req = calloc(1, sizeof(neu_parse_del_tags_req_t));
|
||||
neu_json_elem_t elem[] = {
|
||||
{
|
||||
.name = "node_id",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "group_config_name",
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
};
|
||||
|
||||
int ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(elem), elem);
|
||||
if (ret != 0) {
|
||||
free(req);
|
||||
return -1;
|
||||
}
|
||||
req->node_id = elem[0].v.val_int;
|
||||
req->group_config_name = elem[1].v.val_str;
|
||||
|
||||
req->n_tag_id = neu_json_decode_array_size(buf, "ids");
|
||||
req->tag_ids = calloc(req->n_tag_id, sizeof(uint32_t));
|
||||
for (int i = 0; i < req->n_tag_id; i++) {
|
||||
neu_json_elem_t celem[] = {
|
||||
{
|
||||
.name = NULL,
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
};
|
||||
|
||||
neu_json_decode_array(buf, "ids", i, NEU_JSON_ELEM_SIZE(celem), celem);
|
||||
req->tag_ids[i] = celem[0].v.val_int;
|
||||
}
|
||||
|
||||
*result = req;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void neu_parse_decode_del_tags_free(neu_parse_del_tags_req_t *req)
|
||||
{
|
||||
free(req->group_config_name);
|
||||
free(req->tag_ids);
|
||||
free(req);
|
||||
}
|
||||
|
||||
int neu_parse_decode_update_tags(char * buf,
|
||||
neu_parse_update_tags_req_t **result)
|
||||
{
|
||||
neu_parse_update_tags_req_t *req =
|
||||
calloc(1, sizeof(neu_parse_update_tags_req_t));
|
||||
neu_json_elem_t elem[] = {
|
||||
{
|
||||
.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->node_id = elem[0].v.val_int;
|
||||
|
||||
req->n_tag = neu_json_decode_array_size(buf, "tags");
|
||||
req->tags = calloc(req->n_tag, sizeof(neu_parse_update_tags_req_tag_t));
|
||||
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 = "address",
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = "attribute",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "id",
|
||||
.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].address = celem[2].v.val_str;
|
||||
req->tags[i].attribute = celem[3].v.val_int;
|
||||
req->tags[i].tag_id = celem[4].v.val_int;
|
||||
}
|
||||
|
||||
*result = req;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void neu_parse_decode_update_tags_free(neu_parse_update_tags_req_t *req)
|
||||
{
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
free(req->tags[i].address);
|
||||
free(req->tags[i].name);
|
||||
}
|
||||
free(req->tags);
|
||||
free(req);
|
||||
}
|
||||
|
||||
int neu_parse_decode_get_tags(char *buf, neu_parse_get_tags_req_t **result)
|
||||
{
|
||||
neu_parse_get_tags_req_t *req = calloc(1, sizeof(neu_parse_get_tags_req_t));
|
||||
neu_json_elem_t elem[] = {
|
||||
{
|
||||
.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->node_id = elem[0].v.val_int;
|
||||
|
||||
*result = req;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void neu_parse_decode_get_tags_free(neu_parse_get_tags_req_t *req)
|
||||
{
|
||||
free(req);
|
||||
}
|
||||
|
||||
int neu_parse_encode_get_tags(void *json_object, void *param)
|
||||
{
|
||||
neu_parse_get_tags_res_t *res = (neu_parse_get_tags_res_t *) param;
|
||||
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 = "address",
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = res->tags[i].address,
|
||||
},
|
||||
{
|
||||
.name = "attribute",
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->tags[i].attribute,
|
||||
},
|
||||
{
|
||||
.name = "group_config_name",
|
||||
.t = NEU_JSON_STR,
|
||||
.v.val_str = res->tags[i].group_config_name,
|
||||
},
|
||||
{
|
||||
.name = "id",
|
||||
.t = NEU_JSON_INT,
|
||||
.v.val_int = res->tags[i].id,
|
||||
},
|
||||
};
|
||||
array = neu_json_encode_array(array, tag, 6);
|
||||
}
|
||||
neu_json_elem_t elems[] = { {
|
||||
.name = "tags",
|
||||
.t = NEU_JSON_OBJECT,
|
||||
.v.object = array,
|
||||
} };
|
||||
|
||||
return neu_json_encode_field(json_object, elems, 1);
|
||||
}
|
||||
@@ -37,9 +37,9 @@ int neu_parse_encode_get_tty(void *json_object, void *param)
|
||||
}
|
||||
|
||||
neu_json_elem_t elems = {
|
||||
.name = "ttys",
|
||||
.t = NEU_JSON_OBJECT,
|
||||
.v.object = json_array,
|
||||
.name = "ttys",
|
||||
.t = NEU_JSON_OBJECT,
|
||||
.v.val_object = json_array,
|
||||
};
|
||||
|
||||
return neu_json_encode_field(json_object, &elems, 1);
|
||||
|
||||
@@ -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.
|
||||
**/
|
||||
|
||||
/*
|
||||
* DO NOT EDIT THIS FILE MANUALLY!
|
||||
* It was automatically generated by `json-autotype`.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "json/json.h"
|
||||
|
||||
#include "json/neu_json_update_tag.h"
|
||||
|
||||
int neu_parse_decode_update_tags_req(char * buf,
|
||||
neu_parse_update_tags_req_t **result)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
neu_parse_update_tags_req_t *req =
|
||||
calloc(1, sizeof(neu_parse_update_tags_req_t));
|
||||
neu_json_elem_t req_elems[] = { {
|
||||
.name = "node_id",
|
||||
.t = NEU_JSON_INT,
|
||||
} };
|
||||
ret = neu_json_decode(buf, NEU_JSON_ELEM_SIZE(req_elems), req_elems);
|
||||
if (ret != 0) {
|
||||
goto decode_fail;
|
||||
}
|
||||
|
||||
req->node_id = req_elems[0].v.val_int;
|
||||
|
||||
req->n_tag = neu_json_decode_array_size(buf, "tags");
|
||||
req->tags = calloc(req->n_tag, sizeof(neu_parse_update_tags_req_tag_t));
|
||||
neu_parse_update_tags_req_tag_t *p_tag = req->tags;
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
neu_json_elem_t tag_elems[] = { {
|
||||
.name = "type",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "name",
|
||||
.t = NEU_JSON_STR,
|
||||
},
|
||||
{
|
||||
.name = "id",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "attribute",
|
||||
.t = NEU_JSON_INT,
|
||||
},
|
||||
{
|
||||
.name = "address",
|
||||
.t = NEU_JSON_STR,
|
||||
} };
|
||||
ret = neu_json_decode_array(buf, "tags", i,
|
||||
NEU_JSON_ELEM_SIZE(tag_elems), tag_elems);
|
||||
if (ret != 0) {
|
||||
goto decode_fail;
|
||||
}
|
||||
|
||||
p_tag->type = tag_elems[0].v.val_int;
|
||||
p_tag->name = tag_elems[1].v.val_str;
|
||||
p_tag->id = tag_elems[2].v.val_int;
|
||||
p_tag->attribute = tag_elems[3].v.val_int;
|
||||
p_tag->address = tag_elems[4].v.val_str;
|
||||
p_tag++;
|
||||
}
|
||||
|
||||
*result = req;
|
||||
return ret;
|
||||
|
||||
decode_fail:
|
||||
if (req->tags != NULL) {
|
||||
free(req->tags);
|
||||
}
|
||||
if (req != NULL) {
|
||||
free(req);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void neu_parse_decode_update_tags_req_free(neu_parse_update_tags_req_t *req)
|
||||
{
|
||||
|
||||
neu_parse_update_tags_req_tag_t *p_tag = req->tags;
|
||||
for (int i = 0; i < req->n_tag; i++) {
|
||||
free(p_tag->name);
|
||||
free(p_tag->address);
|
||||
p_tag++;
|
||||
}
|
||||
|
||||
free(req->tags);
|
||||
|
||||
free(req);
|
||||
}
|
||||
+11
-11
@@ -49,7 +49,7 @@ neu_schema_valid_t *neu_schema_load(char *buf, char *plugin)
|
||||
neu_json_decode_free(json);
|
||||
return st;
|
||||
}
|
||||
size = neu_json_decode_array_size_by_json(elem.v.object, "tag_type");
|
||||
size = neu_json_decode_array_size_by_json(elem.v.val_object, "tag_type");
|
||||
|
||||
if (size <= 0) {
|
||||
neu_json_decode_free(json);
|
||||
@@ -61,7 +61,7 @@ neu_schema_valid_t *neu_schema_load(char *buf, char *plugin)
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
neu_json_elem_t e = { .name = NULL, .t = NEU_JSON_INT };
|
||||
if (neu_json_decode_array_by_json(elem.v.object, "tag_type", i, 1,
|
||||
if (neu_json_decode_array_by_json(elem.v.val_object, "tag_type", i, 1,
|
||||
&e) == 0) {
|
||||
st->types[st->n_type] = e.v.val_int;
|
||||
st->n_type++;
|
||||
@@ -69,7 +69,7 @@ neu_schema_valid_t *neu_schema_load(char *buf, char *plugin)
|
||||
}
|
||||
|
||||
st->root = json;
|
||||
st->plugin_json = elem.v.object;
|
||||
st->plugin_json = elem.v.val_object;
|
||||
|
||||
return st;
|
||||
}
|
||||
@@ -98,7 +98,7 @@ static bool valid_init(void *json, neu_json_elem_t *vele, char *name)
|
||||
vele->t = NEU_JSON_OBJECT;
|
||||
|
||||
return neu_json_decode_value(json, &ele) == 0 &&
|
||||
neu_json_decode_value(ele.v.object, vele) == 0;
|
||||
neu_json_decode_value(ele.v.val_object, vele) == 0;
|
||||
}
|
||||
|
||||
int neu_schema_valid_param_int(neu_schema_valid_t *v, int64_t value, char *name)
|
||||
@@ -111,8 +111,8 @@ int neu_schema_valid_param_int(neu_schema_valid_t *v, int64_t value, char *name)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (neu_json_decode_value(valid_ele.v.object, &min_ele) != 0 ||
|
||||
neu_json_decode_value(valid_ele.v.object, &max_ele) != 0) {
|
||||
if (neu_json_decode_value(valid_ele.v.val_object, &min_ele) != 0 ||
|
||||
neu_json_decode_value(valid_ele.v.val_object, &max_ele) != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -133,8 +133,8 @@ int neu_schema_valid_param_real(neu_schema_valid_t *v, double value, char *name)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (neu_json_decode_value(valid_ele.v.object, &min_ele) != 0 ||
|
||||
neu_json_decode_value(valid_ele.v.object, &max_ele) != 0) {
|
||||
if (neu_json_decode_value(valid_ele.v.val_object, &min_ele) != 0 ||
|
||||
neu_json_decode_value(valid_ele.v.val_object, &max_ele) != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ int neu_schema_valid_param_string(neu_schema_valid_t *v, char *value,
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (neu_json_decode_value(valid_ele.v.object, &len_ele) != 0) {
|
||||
if (neu_json_decode_value(valid_ele.v.val_object, &len_ele) != 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -176,14 +176,14 @@ int neu_schema_valid_param_enum(neu_schema_valid_t *v, int64_t value,
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = neu_json_decode_array_size_by_json(valid_ele.v.object, "value");
|
||||
size = neu_json_decode_array_size_by_json(valid_ele.v.val_object, "value");
|
||||
if (size <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < size; i++) {
|
||||
neu_json_elem_t ve = { .name = NULL, .t = NEU_JSON_INT };
|
||||
if (neu_json_decode_array_by_json(valid_ele.v.object, "value", i, 1,
|
||||
if (neu_json_decode_array_by_json(valid_ele.v.val_object, "value", i, 1,
|
||||
&ve) == 0) {
|
||||
if (ve.v.val_int == value) {
|
||||
return 0;
|
||||
|
||||
+2
-2
@@ -79,7 +79,7 @@ static json_t *encode_object(json_t *object, neu_json_elem_t ele)
|
||||
json_object_set_new(ob, ele.name, json_boolean(ele.v.val_bool));
|
||||
break;
|
||||
case NEU_JSON_OBJECT:
|
||||
json_object_set_new(ob, ele.name, ele.v.object);
|
||||
json_object_set_new(ob, ele.name, ele.v.val_object);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
@@ -135,7 +135,7 @@ static int decode_object(json_t *root, neu_json_elem_t *ele)
|
||||
ele->v.val_bool = json_boolean_value(ob);
|
||||
break;
|
||||
case NEU_JSON_OBJECT:
|
||||
ele->v.object = ob;
|
||||
ele->v.val_object = ob;
|
||||
break;
|
||||
default:
|
||||
log_error("json decode unknown type: %d", ele->t);
|
||||
|
||||
@@ -2,20 +2,24 @@
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "json/neu_json_add_tag.h"
|
||||
#include "json/neu_json_del_tag.h"
|
||||
#include "json/neu_json_fn.h"
|
||||
#include "json/neu_json_tag.h"
|
||||
#include "json/neu_json_get_tag.h"
|
||||
#include "json/neu_json_update_tag.h"
|
||||
// #include "json/neu_json_tag.h"
|
||||
|
||||
TEST(JsonDatatagTableTest, AddTagDecode)
|
||||
{
|
||||
char *buf = (char *) "{\"node_id\":123456, \"group_config_name\": \"name\","
|
||||
"\"tags\": "
|
||||
"[{\"name\":\"name1\", \"type\":0,\"decimal\":1, "
|
||||
"\"address\":\"1!400001\",\"flag\":0}, "
|
||||
"{\"name\":\"name2\", \"type\":1,\"decimal\":1, "
|
||||
"\"address\":\"1!400002\",\"flag\":0} ] }";
|
||||
"[{\"name\":\"name1\", \"attribute\":1, "
|
||||
"\"address\":\"1!400001\", \"type\":0}, "
|
||||
"{\"name\":\"name2\", \"attribute\":3,"
|
||||
"\"address\":\"1!400002\", \"type\":1} ] }";
|
||||
neu_parse_add_tags_req_t *req = NULL;
|
||||
|
||||
EXPECT_EQ(0, neu_parse_decode_add_tags(buf, &req));
|
||||
EXPECT_EQ(0, neu_parse_decode_add_tags_req(buf, &req));
|
||||
|
||||
EXPECT_EQ(123456, req->node_id);
|
||||
EXPECT_STREQ("name", req->group_config_name);
|
||||
@@ -23,61 +27,72 @@ TEST(JsonDatatagTableTest, AddTagDecode)
|
||||
EXPECT_STREQ("name1", req->tags[0].name);
|
||||
EXPECT_EQ(0, req->tags[0].type);
|
||||
EXPECT_STREQ("1!400001", req->tags[0].address);
|
||||
EXPECT_EQ(0, req->tags[0].attribute);
|
||||
EXPECT_EQ(1, req->tags[0].attribute);
|
||||
|
||||
EXPECT_STREQ("name2", req->tags[1].name);
|
||||
EXPECT_EQ(1, req->tags[1].type);
|
||||
EXPECT_STREQ("1!400002", req->tags[1].address);
|
||||
EXPECT_EQ(0, req->tags[1].attribute);
|
||||
EXPECT_EQ(3, req->tags[1].attribute);
|
||||
|
||||
neu_parse_decode_add_tags_free(req);
|
||||
neu_parse_decode_add_tags_req_free(req);
|
||||
}
|
||||
|
||||
TEST(JsonDatatagTableTest, GetTagDecode)
|
||||
{
|
||||
char * buf = (char *) "{\"node_id\": 123456}";
|
||||
char *buf = (char *) "{\"node_id\": 123456, \"group_config_name\": "
|
||||
"\"config_modbus_tcp_sample_2\"}";
|
||||
neu_parse_get_tags_req_t *req = NULL;
|
||||
|
||||
EXPECT_EQ(0, neu_parse_decode_get_tags(buf, &req));
|
||||
EXPECT_EQ(0, neu_parse_decode_get_tags_req(buf, &req));
|
||||
|
||||
EXPECT_EQ(123456, req->node_id);
|
||||
|
||||
neu_parse_decode_get_tags_free(req);
|
||||
neu_parse_decode_get_tags_req_free(req);
|
||||
}
|
||||
|
||||
TEST(JsonDatatagTableTest, GetTagEncode)
|
||||
{
|
||||
char *buf =
|
||||
(char
|
||||
*) "{\"tags\": [{\"name\": \"Tag0001\", \"type\": 0, \"address\": "
|
||||
"\"1!400001\", \"attribute\": 0, \"id\": 0}, {\"name\": "
|
||||
"\"Tag0002\", \"type\": 1, \"address\": \"1!400002\", "
|
||||
"\"attribute\": 0, \"id\": 0}]}";
|
||||
char * result = NULL;
|
||||
neu_parse_get_tags_res_t res = { 0 };
|
||||
(char *) "{\"tags\": [{\"type\": 0, \"name\": \"Tag0001\", \"id\": 0, "
|
||||
"\"group_config_name\": \"config_modbus_tcp_sample_2\", "
|
||||
"\"attribute\": 0, \"address\": \"1!400001\"}, {\"type\": 1, "
|
||||
"\"name\": \"Tag0002\", \"id\": 1, \"group_config_name\": "
|
||||
"\"config_modbus_tcp_sample_2\", \"attribute\": 1, "
|
||||
"\"address\": \"1!400002\"}]}";
|
||||
char * result = NULL;
|
||||
neu_parse_get_tags_resp_t res = { 0 };
|
||||
|
||||
res.n_tag = 2;
|
||||
|
||||
res.tags = (neu_parse_get_tags_res_tag_t *) calloc(
|
||||
2, sizeof(neu_parse_get_tags_res_tag_t));
|
||||
res.tags[0].name = strdup((char *) "Tag0001");
|
||||
res.tags = (neu_parse_get_tags_resp_tag_t *) calloc(
|
||||
2, sizeof(neu_parse_get_tags_resp_tag_t));
|
||||
res.tags[0].type = 0;
|
||||
res.tags[0].address = strdup((char *) "1!400001");
|
||||
res.tags[0].name = strdup((char *) "Tag0001");
|
||||
res.tags[0].id = 0;
|
||||
res.tags[0].attribute = 0;
|
||||
res.tags[0].address = strdup((char *) "1!400001");
|
||||
res.tags[0].group_config_name =
|
||||
strdup((char *) "config_modbus_tcp_sample_2");
|
||||
|
||||
res.tags[1].name = strdup((char *) "Tag0002");
|
||||
res.tags[1].type = 1;
|
||||
res.tags[1].name = strdup((char *) "Tag0002");
|
||||
res.tags[1].id = 1;
|
||||
res.tags[1].attribute = 1;
|
||||
res.tags[1].address = strdup((char *) "1!400002");
|
||||
res.tags[1].attribute = 0;
|
||||
res.tags[1].group_config_name =
|
||||
strdup((char *) "config_modbus_tcp_sample_2");
|
||||
|
||||
EXPECT_EQ(0,
|
||||
neu_json_encode_by_fn(&res, neu_parse_encode_get_tags, &result));
|
||||
EXPECT_EQ(
|
||||
0,
|
||||
neu_json_encode_by_fn(&res, neu_parse_encode_get_tags_resp, &result));
|
||||
EXPECT_STREQ(buf, result);
|
||||
|
||||
free(res.tags[0].name);
|
||||
free(res.tags[1].name);
|
||||
free(res.tags[0].address);
|
||||
free(res.tags[1].address);
|
||||
free(res.tags[0].group_config_name);
|
||||
free(res.tags[1].group_config_name);
|
||||
free(res.tags);
|
||||
free(result);
|
||||
}
|
||||
@@ -86,10 +101,10 @@ TEST(JsonDatatagTableTest, DeleteTagDecode)
|
||||
{
|
||||
char *buf =
|
||||
(char *) "{\"node_id\": 123456, \"group_config_name\": \"name\", "
|
||||
"\"ids\": [123, 456]}";
|
||||
"\"tag_ids\": [123, 456]}";
|
||||
neu_parse_del_tags_req_t *req = NULL;
|
||||
|
||||
EXPECT_EQ(0, neu_parse_decode_del_tags(buf, &req));
|
||||
EXPECT_EQ(0, neu_parse_decode_del_tags_req(buf, &req));
|
||||
|
||||
EXPECT_EQ(123456, req->node_id);
|
||||
EXPECT_STREQ("name", req->group_config_name);
|
||||
@@ -97,33 +112,34 @@ TEST(JsonDatatagTableTest, DeleteTagDecode)
|
||||
EXPECT_EQ(123, req->tag_ids[0]);
|
||||
EXPECT_EQ(456, req->tag_ids[1]);
|
||||
|
||||
neu_parse_decode_del_tags_free(req);
|
||||
neu_parse_decode_del_tags_req_free(req);
|
||||
}
|
||||
|
||||
TEST(JsonDatatagTableTest, UpdateTaDecode)
|
||||
{
|
||||
char *buf = (char *) "{\"node_id\":123456, "
|
||||
"\"tag_id\":123, "
|
||||
"\"tags\": "
|
||||
"[{\"name\":\"name1\", \"type\":0,\"decimal\":1, "
|
||||
"\"address\":\"1!400001\",\"flag\":0}, "
|
||||
"{\"name\":\"name2\", \"type\":1,\"decimal\":1, "
|
||||
"\"address\":\"1!400003\",\"flag\":0} ] }";
|
||||
"[{\"id\":12,\"name\":\"name1\",\"type\":0,"
|
||||
"\"address\":\"1!400001\",\"attribute\":0}, "
|
||||
"{\"id\":13,\"name\":\"name2\",\"type\":1, "
|
||||
"\"address\":\"1!400003\",\"attribute\":1} ] }";
|
||||
neu_parse_update_tags_req_t *req = NULL;
|
||||
|
||||
EXPECT_EQ(0, neu_parse_decode_update_tags(buf, &req));
|
||||
EXPECT_EQ(0, neu_parse_decode_update_tags_req(buf, &req));
|
||||
|
||||
EXPECT_EQ(123456, req->node_id);
|
||||
|
||||
EXPECT_EQ(12, req->tags[0].id);
|
||||
EXPECT_STREQ("name1", req->tags[0].name);
|
||||
EXPECT_EQ(0, req->tags[0].type);
|
||||
EXPECT_STREQ("1!400001", req->tags[0].address);
|
||||
EXPECT_EQ(0, req->tags[0].attribute);
|
||||
|
||||
EXPECT_EQ(13, req->tags[1].id);
|
||||
EXPECT_STREQ("name2", req->tags[1].name);
|
||||
EXPECT_EQ(1, req->tags[1].type);
|
||||
EXPECT_STREQ("1!400003", req->tags[1].address);
|
||||
EXPECT_EQ(0, req->tags[1].attribute);
|
||||
EXPECT_EQ(1, req->tags[1].attribute);
|
||||
|
||||
neu_parse_decode_update_tags_free(req);
|
||||
neu_parse_decode_update_tags_req_free(req);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <cstdlib>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
// #include "json/neu_group_config.h"
|
||||
#include "json/neu_json_fn.h"
|
||||
#include "json/neu_json_group_config.h"
|
||||
|
||||
|
||||
+3
-3
@@ -247,9 +247,9 @@ TEST(JsonTest, EncodeArray)
|
||||
json_array2 =
|
||||
neu_json_encode_array(json_array2, array2, NEU_JSON_ELEM_SIZE(array2));
|
||||
|
||||
elems[0].v.val_int = 12345;
|
||||
elems[1].v.object = json_array1;
|
||||
elems[2].v.object = json_array2;
|
||||
elems[0].v.val_int = 12345;
|
||||
elems[1].v.val_object = json_array1;
|
||||
elems[2].v.val_object = json_array2;
|
||||
EXPECT_EQ(3, NEU_JSON_ELEM_SIZE(elems));
|
||||
void *ob = neu_json_encode_new();
|
||||
EXPECT_EQ(0, neu_json_encode_field(ob, elems, NEU_JSON_ELEM_SIZE(elems)));
|
||||
|
||||
Reference in New Issue
Block a user