elemy-sensortree 1.0.0
el_sensorsnode_json.h
Go to the documentation of this file.
1
7#ifndef LIBELSENSORTREE_ELSENSORTREE_EL_SENSORSNODE_JSON_H_
8#define LIBELSENSORTREE_ELSENSORTREE_EL_SENSORSNODE_JSON_H_
9
10#include <json-c/json.h>
11
14
15#include "elutils/c_decls.h"
16__BEGIN_DECLS /* till __END_DECLS */
17
18
19#define NODE_FW_VERSION_KEY "fw_version"
20
21#define NODE_FW_VERSION_SW_PATCH_KEY "sw_patch"
22#define NODE_FW_VERSION_SW_MINOR_KEY "sw_minor"
23#define NODE_FW_VERSION_SW_MAJOR_KEY "sw_major"
24#define NODE_FW_VERSION_BOOT_KEY "boot"
25#define NODE_FW_VERSION_HW_REVISION_KEY "hw_revision"
26#define NODE_FW_VERSION_PROTOCOL_KEY "protocol"
27
28#define NODE_ADDR_KEY "addr"
29#define NODE_ADDR_A0_KEY "a0"
30#define NODE_ADDR_A1_KEY "a1"
31#define NODE_ADDR_A2_KEY "a2"
32#define NODE_ADDR_A3_KEY "a3"
33
34
35#define NODE_INFO_KEY "node_info"
36
37#define NODE_INFO_MODEL_KEY "model"
38#define NODE_INFO_SERIAL_NUMBER_KEY "serialNumber"
39#define NODE_INFO_FW_VERSION_KEY "fw_version"
40#define NODE_INFO_ADDR_KEY "addr"
41#define NODE_INFO_CONFIG_CRC_KEY "configCrc"
42
43//will be array
44#define SENSOR_VALUES_KEY "sensor_values"
45
46#define SENSOR_VALUE_STATE_KEY "value state"
47//#define SENSOR_VALUE_STATE_UKNOWN_STR "SN_VAL_UKNOWN"
48//#define SENSOR_VALUE_STATE_INVALID_STR "SN_VAL_INVALID"
49//#define SENSOR_VALUE_STATE_VALID_STR "SN_VAL_VALID"
50
51#define SENSOR_VALUE_TYPE_KEY "value_type"
52//#define SENSOR_VALUE_TYPE_ABSENT_STR "SN_VAL_ABSENT"
53//#define SENSOR_VALUE_TYPE_ANALOG_STR "SN_VAL_ANALOG"
54//#define SENSOR_VALUE_TYPE_DISCRETE_STR "SN_VAL_DISCRETE"
55#define IO_INPUT "IO_INPUT"
56#define IO_OUTPUT "IO_OUTPUT"
57
58
59
60#define SENSOR_VALUE_ANALOG_KEY "analog"
61#define SENSOR_VALUE_ANALOG_VALUE_KEY "value"
62#define SENSOR_VALUE_DISCRETE_KEY "discrete"
63#define SENSOR_VALUE_DISCRETE_VALUE_KEY "value"
64#define SENSOR_VALUE_DISCRETE_COUNT_KEY "count"
65
66#define NODE_STATUS_KEY "node_status"
67#define NODE_STATUS_AVAILABALE_KEY "available"
68#define NODE_STATUS_AVAILABALE_YES_STR "yes"
69#define NODE_STATUS_AVAILABALE_NO_STR "no"
70#define NODE_STATUS_DATA_ERROR_KEY "data_error"
71#define NODE_STATUS_DATA_ERROR_YES_STR "yes"
72#define NODE_STATUS_DATA_ERROR_NO_STR "no"
73
74#define VALUES_COUNT_KEY "values_count"
75//#define SENSORS_NODE_KEY "sensors_node"
76#define SENSORS_NODE_KEY "node_data"
77
78#define SENSOR_DATA_KEY "sensor_data"
79
80#define SENSOR_DATA_DATA_KEY "data"
81#define SENSOR_DATA_UPDATE_COUNTER_KEY "updateCounter"
82#define SENSOR_DATA_NODES_COUNT_KEY "nodesСount"
83#define SENSOR_DATA_NODES_KEY "nodes"
84#define SENSOR_DATA_CRC_KEY "crc"
85
86#define PRINT_JSONED(DATA, METHOD, MSG) { \
87 struct json_object *jo = METHOD(DATA); \
88 const char *t_str = json_object_to_json_string_ext(jo, JSON_C_TO_STRING_PLAIN); \
89 MB_DBG("%s: '%s'\n", MSG, t_str); \
90 json_object_put(jo); \
91}
92
93int parse_node_fw_version(struct json_object *pobj, node_fw_version_t *p);
94struct json_object* json_node_fw_version(node_fw_version_t *p);
95#define PRINT_JSONED_NODE_FW_VERSION(FWS, MSG) PRINT_JSONED(FWS, json_node_fw_version, MSG)
96
97int parse_node_addr(struct json_object *pobj, node_addr_t *paddr);
98struct json_object* json_node_addr(node_addr_t *addr, int as_string);
99#define PRINT_JSONED_NODE_ADDR(ADDR, MSG) { \
100 struct json_object *jo = json_node_addr(ADDR, 1); \
101 const char *t_str = json_object_to_json_string_ext(jo, JSON_C_TO_STRING_PLAIN); \
102 MB_DBG("%s: '%s'\n", MSG, t_str); \
103 json_object_put(jo); \
104 }
105
106
107
108int parse_serialnum(struct json_object *pobj, node_serial_num_t *sn);
109struct json_object* json_serialnum(node_serial_num_t *sernum);
110#define PRINT_JSONED_SERIAL_NUM(FWS, MSG) PRINT_JSONED(FWS, json_serialnum, MSG)
111
112int parse_node_info(struct json_object *pobj, node_info_t *p);
113struct json_object* json_node_info(node_info_t *p);
114#define PRINT_JSONED_NODE_INFO(FWS, MSG) PRINT_JSONED(FWS, json_node_info, MSG)
115
116int parse_sensor_value(struct json_object *pobj, sensor_value_t *p);
117struct json_object* json_sensor_value(sensor_value_t *p);
118#define PRINT_JSONED_SENSOR_VALUE(FWS, MSG) PRINT_JSONED(FWS, json_sensor_value, MSG)
119
120int parse_node_status(struct json_object *pobj, node_status_t *p);
121struct json_object* json_node_status(node_status_t *p);
122#define PRINT_JSONED_NODE_STATUS(FWS, MSG) PRINT_JSONED(FWS, json_node_status, MSG)
123
124int parse_sensors_node(struct json_object *pobj, sensors_node_t *p);
125struct json_object* json_sensors_node(sensors_node_t *p);
126void print_sensors_node(sensors_node_t *p, char *msg);
127#define PRINT_JSONED_SENSORS_NODE(FWS, MSG) PRINT_JSONED(FWS, json_sensors_node, MSG)
128
129int parse_sensors_data(struct json_object *pobj, sensors_data_t **pp);
130struct json_object* json_sensors_data(sensors_data_t *p);
131void print_sensors_data(sensors_data_t *p, char *msg);
132
134#endif /* LIBELSENSORTREE_ELSENSORTREE_EL_SENSORSNODE_JSON_H_ */
#define __END_DECLS
#define __BEGIN_DECLS
header with defines and structs for sensor
node_addr_t addr
Definition: el_sensorsnode.h:3
int parse_node_status(struct json_object *pobj, node_status_t *p)
Definition: el_sensorsnode_json.c:667
int parse_node_fw_version(struct json_object *pobj, node_fw_version_t *p)
parse json obj for node_fw_version_t
Definition: el_sensorsnode_json.c:31
struct json_object * json_sensors_data(sensors_data_t *p)
Definition: el_sensorsnode_json.c:1060
struct json_object * json_node_info(node_info_t *p)
create and fill json object from node_info_t as object
Definition: el_sensorsnode_json.c:412
int parse_sensor_value(struct json_object *pobj, sensor_value_t *p)
parse json obj for sensor_value_t
Definition: el_sensorsnode_json.c:498
int parse_node_info(struct json_object *pobj, node_info_t *p)
parse json obj for node_info_t
Definition: el_sensorsnode_json.c:320
struct json_object * json_node_addr(node_addr_t *addr, int as_string)
create and fill json object from node_addr_t as object
Definition: el_sensorsnode_json.c:212
struct json_object * json_serialnum(node_serial_num_t *sernum)
create and fill json object from node_serial_num_t as object
Definition: el_sensorsnode_json.c:289
void print_sensors_data(sensors_data_t *p, char *msg)
Definition: el_sensorsnode_json.c:1146
int parse_sensors_data(struct json_object *pobj, sensors_data_t **pp)
parse json with sensors_data
Definition: el_sensorsnode_json.c:974
struct json_object * json_sensors_node(sensors_node_t *p)
Definition: el_sensorsnode_json.c:862
struct json_object * json_node_status(node_status_t *p)
Definition: el_sensorsnode_json.c:721
struct json_object * json_sensor_value(sensor_value_t *p)
create and fill json object from sensor_value_t as object
Definition: el_sensorsnode_json.c:590
struct json_object * json_node_fw_version(node_fw_version_t *p)
create and fill json object from node_fw_version_t
Definition: el_sensorsnode_json.c:65
void print_sensors_node(sensors_node_t *p, char *msg)
Definition: el_sensorsnode_json.c:944
int parse_serialnum(struct json_object *pobj, node_serial_num_t *sn)
parse json obj for serialnum node_serial_num_t
Definition: el_sensorsnode_json.c:261
int parse_sensors_node(struct json_object *pobj, sensors_node_t *p)
Definition: el_sensorsnode_json.c:779
int parse_node_addr(struct json_object *pobj, node_addr_t *paddr)
parse json obj for node_addr_t
Definition: el_sensorsnode_json.c:128
Definition: el_sensorsnode.h:83
адрес узла a0 - top level
Definition: el_sensorsnode.h:50