elemy-sensortree 1.0.0
Macros | Functions
el_sensorsnode_json.h File Reference
#include <json-c/json.h>
#include "elsensortree/el_sensorsnode.h"
#include "elsensortree/io_type_t.h"
#include "elutils/c_decls.h"
Include dependency graph for el_sensorsnode_json.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define NODE_FW_VERSION_KEY   "fw_version"
 
#define NODE_FW_VERSION_SW_PATCH_KEY   "sw_patch"
 
#define NODE_FW_VERSION_SW_MINOR_KEY   "sw_minor"
 
#define NODE_FW_VERSION_SW_MAJOR_KEY   "sw_major"
 
#define NODE_FW_VERSION_BOOT_KEY   "boot"
 
#define NODE_FW_VERSION_HW_REVISION_KEY   "hw_revision"
 
#define NODE_FW_VERSION_PROTOCOL_KEY   "protocol"
 
#define NODE_ADDR_KEY   "addr"
 
#define NODE_ADDR_A0_KEY   "a0"
 
#define NODE_ADDR_A1_KEY   "a1"
 
#define NODE_ADDR_A2_KEY   "a2"
 
#define NODE_ADDR_A3_KEY   "a3"
 
#define NODE_INFO_KEY   "node_info"
 
#define NODE_INFO_MODEL_KEY   "model"
 
#define NODE_INFO_SERIAL_NUMBER_KEY   "serialNumber"
 
#define NODE_INFO_FW_VERSION_KEY   "fw_version"
 
#define NODE_INFO_ADDR_KEY   "addr"
 
#define NODE_INFO_CONFIG_CRC_KEY   "configCrc"
 
#define SENSOR_VALUES_KEY   "sensor_values"
 
#define SENSOR_VALUE_STATE_KEY   "value state"
 
#define SENSOR_VALUE_TYPE_KEY   "value_type"
 
#define IO_INPUT   "IO_INPUT"
 
#define IO_OUTPUT   "IO_OUTPUT"
 
#define SENSOR_VALUE_ANALOG_KEY   "analog"
 
#define SENSOR_VALUE_ANALOG_VALUE_KEY   "value"
 
#define SENSOR_VALUE_DISCRETE_KEY   "discrete"
 
#define SENSOR_VALUE_DISCRETE_VALUE_KEY   "value"
 
#define SENSOR_VALUE_DISCRETE_COUNT_KEY   "count"
 
#define NODE_STATUS_KEY   "node_status"
 
#define NODE_STATUS_AVAILABALE_KEY   "available"
 
#define NODE_STATUS_AVAILABALE_YES_STR   "yes"
 
#define NODE_STATUS_AVAILABALE_NO_STR   "no"
 
#define NODE_STATUS_DATA_ERROR_KEY   "data_error"
 
#define NODE_STATUS_DATA_ERROR_YES_STR   "yes"
 
#define NODE_STATUS_DATA_ERROR_NO_STR   "no"
 
#define VALUES_COUNT_KEY   "values_count"
 
#define SENSORS_NODE_KEY   "node_data"
 
#define SENSOR_DATA_KEY   "sensor_data"
 
#define SENSOR_DATA_DATA_KEY   "data"
 
#define SENSOR_DATA_UPDATE_COUNTER_KEY   "updateCounter"
 
#define SENSOR_DATA_NODES_COUNT_KEY   "nodesСount"
 
#define SENSOR_DATA_NODES_KEY   "nodes"
 
#define SENSOR_DATA_CRC_KEY   "crc"
 
#define PRINT_JSONED(DATA, METHOD, MSG)
 
#define PRINT_JSONED_NODE_FW_VERSION(FWS, MSG)   PRINT_JSONED(FWS, json_node_fw_version, MSG)
 
#define PRINT_JSONED_NODE_ADDR(ADDR, MSG)
 
#define PRINT_JSONED_SERIAL_NUM(FWS, MSG)   PRINT_JSONED(FWS, json_serialnum, MSG)
 
#define PRINT_JSONED_NODE_INFO(FWS, MSG)   PRINT_JSONED(FWS, json_node_info, MSG)
 
#define PRINT_JSONED_SENSOR_VALUE(FWS, MSG)   PRINT_JSONED(FWS, json_sensor_value, MSG)
 
#define PRINT_JSONED_NODE_STATUS(FWS, MSG)   PRINT_JSONED(FWS, json_node_status, MSG)
 
#define PRINT_JSONED_SENSORS_NODE(FWS, MSG)   PRINT_JSONED(FWS, json_sensors_node, MSG)
 

Functions

int parse_node_fw_version (struct json_object *pobj, node_fw_version_t *p)
 parse json obj for node_fw_version_t More...
 
struct json_object * json_node_fw_version (node_fw_version_t *p)
 create and fill json object from node_fw_version_t More...
 
int parse_node_addr (struct json_object *pobj, node_addr_t *paddr)
 parse json obj for node_addr_t More...
 
struct json_object * json_node_addr (node_addr_t *addr, int as_string)
 create and fill json object from node_addr_t as object More...
 
int parse_serialnum (struct json_object *pobj, node_serial_num_t *sn)
 parse json obj for serialnum node_serial_num_t More...
 
struct json_object * json_serialnum (node_serial_num_t *sernum)
 create and fill json object from node_serial_num_t as object More...
 
int parse_node_info (struct json_object *pobj, node_info_t *p)
 parse json obj for node_info_t More...
 
struct json_object * json_node_info (node_info_t *p)
 create and fill json object from node_info_t as object More...
 
int parse_sensor_value (struct json_object *pobj, sensor_value_t *p)
 parse json obj for sensor_value_t More...
 
struct json_object * json_sensor_value (sensor_value_t *p)
 create and fill json object from sensor_value_t as object More...
 
int parse_node_status (struct json_object *pobj, node_status_t *p)
 
struct json_object * json_node_status (node_status_t *p)
 
int parse_sensors_node (struct json_object *pobj, sensors_node_t *p)
 
struct json_object * json_sensors_node (sensors_node_t *p)
 
void print_sensors_node (sensors_node_t *p, char *msg)
 
int parse_sensors_data (struct json_object *pobj, sensors_data_t **pp)
 parse json with sensors_data More...
 
struct json_object * json_sensors_data (sensors_data_t *p)
 
void print_sensors_data (sensors_data_t *p, char *msg)
 

Detailed Description

Created on: 25 мар. 2024 г. Author: ps

Macro Definition Documentation

◆ IO_INPUT

#define IO_INPUT   "IO_INPUT"

◆ IO_OUTPUT

#define IO_OUTPUT   "IO_OUTPUT"

◆ NODE_ADDR_A0_KEY

#define NODE_ADDR_A0_KEY   "a0"

◆ NODE_ADDR_A1_KEY

#define NODE_ADDR_A1_KEY   "a1"

◆ NODE_ADDR_A2_KEY

#define NODE_ADDR_A2_KEY   "a2"

◆ NODE_ADDR_A3_KEY

#define NODE_ADDR_A3_KEY   "a3"

◆ NODE_ADDR_KEY

#define NODE_ADDR_KEY   "addr"

◆ NODE_FW_VERSION_BOOT_KEY

#define NODE_FW_VERSION_BOOT_KEY   "boot"

◆ NODE_FW_VERSION_HW_REVISION_KEY

#define NODE_FW_VERSION_HW_REVISION_KEY   "hw_revision"

◆ NODE_FW_VERSION_KEY

#define NODE_FW_VERSION_KEY   "fw_version"

◆ NODE_FW_VERSION_PROTOCOL_KEY

#define NODE_FW_VERSION_PROTOCOL_KEY   "protocol"

◆ NODE_FW_VERSION_SW_MAJOR_KEY

#define NODE_FW_VERSION_SW_MAJOR_KEY   "sw_major"

◆ NODE_FW_VERSION_SW_MINOR_KEY

#define NODE_FW_VERSION_SW_MINOR_KEY   "sw_minor"

◆ NODE_FW_VERSION_SW_PATCH_KEY

#define NODE_FW_VERSION_SW_PATCH_KEY   "sw_patch"

◆ NODE_INFO_ADDR_KEY

#define NODE_INFO_ADDR_KEY   "addr"

◆ NODE_INFO_CONFIG_CRC_KEY

#define NODE_INFO_CONFIG_CRC_KEY   "configCrc"

◆ NODE_INFO_FW_VERSION_KEY

#define NODE_INFO_FW_VERSION_KEY   "fw_version"

◆ NODE_INFO_KEY

#define NODE_INFO_KEY   "node_info"

◆ NODE_INFO_MODEL_KEY

#define NODE_INFO_MODEL_KEY   "model"

◆ NODE_INFO_SERIAL_NUMBER_KEY

#define NODE_INFO_SERIAL_NUMBER_KEY   "serialNumber"

◆ NODE_STATUS_AVAILABALE_KEY

#define NODE_STATUS_AVAILABALE_KEY   "available"

◆ NODE_STATUS_AVAILABALE_NO_STR

#define NODE_STATUS_AVAILABALE_NO_STR   "no"

◆ NODE_STATUS_AVAILABALE_YES_STR

#define NODE_STATUS_AVAILABALE_YES_STR   "yes"

◆ NODE_STATUS_DATA_ERROR_KEY

#define NODE_STATUS_DATA_ERROR_KEY   "data_error"

◆ NODE_STATUS_DATA_ERROR_NO_STR

#define NODE_STATUS_DATA_ERROR_NO_STR   "no"

◆ NODE_STATUS_DATA_ERROR_YES_STR

#define NODE_STATUS_DATA_ERROR_YES_STR   "yes"

◆ NODE_STATUS_KEY

#define NODE_STATUS_KEY   "node_status"

◆ PRINT_JSONED

#define PRINT_JSONED (   DATA,
  METHOD,
  MSG 
)
Value:
{ \
struct json_object *jo = METHOD(DATA); \
const char *t_str = json_object_to_json_string_ext(jo, JSON_C_TO_STRING_PLAIN); \
MB_DBG("%s: '%s'\n", MSG, t_str); \
json_object_put(jo); \
}

◆ PRINT_JSONED_NODE_ADDR

#define PRINT_JSONED_NODE_ADDR (   ADDR,
  MSG 
)
Value:
{ \
struct json_object *jo = json_node_addr(ADDR, 1); \
const char *t_str = json_object_to_json_string_ext(jo, JSON_C_TO_STRING_PLAIN); \
MB_DBG("%s: '%s'\n", MSG, t_str); \
json_object_put(jo); \
}
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

◆ PRINT_JSONED_NODE_FW_VERSION

#define PRINT_JSONED_NODE_FW_VERSION (   FWS,
  MSG 
)    PRINT_JSONED(FWS, json_node_fw_version, MSG)

◆ PRINT_JSONED_NODE_INFO

#define PRINT_JSONED_NODE_INFO (   FWS,
  MSG 
)    PRINT_JSONED(FWS, json_node_info, MSG)

◆ PRINT_JSONED_NODE_STATUS

#define PRINT_JSONED_NODE_STATUS (   FWS,
  MSG 
)    PRINT_JSONED(FWS, json_node_status, MSG)

◆ PRINT_JSONED_SENSOR_VALUE

#define PRINT_JSONED_SENSOR_VALUE (   FWS,
  MSG 
)    PRINT_JSONED(FWS, json_sensor_value, MSG)

◆ PRINT_JSONED_SENSORS_NODE

#define PRINT_JSONED_SENSORS_NODE (   FWS,
  MSG 
)    PRINT_JSONED(FWS, json_sensors_node, MSG)

◆ PRINT_JSONED_SERIAL_NUM

#define PRINT_JSONED_SERIAL_NUM (   FWS,
  MSG 
)    PRINT_JSONED(FWS, json_serialnum, MSG)

◆ SENSOR_DATA_CRC_KEY

#define SENSOR_DATA_CRC_KEY   "crc"

◆ SENSOR_DATA_DATA_KEY

#define SENSOR_DATA_DATA_KEY   "data"

◆ SENSOR_DATA_KEY

#define SENSOR_DATA_KEY   "sensor_data"

◆ SENSOR_DATA_NODES_COUNT_KEY

#define SENSOR_DATA_NODES_COUNT_KEY   "nodesСount"

◆ SENSOR_DATA_NODES_KEY

#define SENSOR_DATA_NODES_KEY   "nodes"

◆ SENSOR_DATA_UPDATE_COUNTER_KEY

#define SENSOR_DATA_UPDATE_COUNTER_KEY   "updateCounter"

◆ SENSOR_VALUE_ANALOG_KEY

#define SENSOR_VALUE_ANALOG_KEY   "analog"

◆ SENSOR_VALUE_ANALOG_VALUE_KEY

#define SENSOR_VALUE_ANALOG_VALUE_KEY   "value"

◆ SENSOR_VALUE_DISCRETE_COUNT_KEY

#define SENSOR_VALUE_DISCRETE_COUNT_KEY   "count"

◆ SENSOR_VALUE_DISCRETE_KEY

#define SENSOR_VALUE_DISCRETE_KEY   "discrete"

◆ SENSOR_VALUE_DISCRETE_VALUE_KEY

#define SENSOR_VALUE_DISCRETE_VALUE_KEY   "value"

◆ SENSOR_VALUE_STATE_KEY

#define SENSOR_VALUE_STATE_KEY   "value state"

◆ SENSOR_VALUE_TYPE_KEY

#define SENSOR_VALUE_TYPE_KEY   "value_type"

◆ SENSOR_VALUES_KEY

#define SENSOR_VALUES_KEY   "sensor_values"

◆ SENSORS_NODE_KEY

#define SENSORS_NODE_KEY   "node_data"

◆ VALUES_COUNT_KEY

#define VALUES_COUNT_KEY   "values_count"

Function Documentation

◆ json_node_addr()

struct json_object * json_node_addr ( node_addr_t addr,
int  as_string 
)

create and fill json object from node_addr_t as object

Parameters
addrnode_addr_t ptr of node address
as_stringif 0 - create json_object as {"a0":0....} else create json_object as string "0x1234"
Returns
ptr to addr object on success,
NULL on error
Here is the caller graph for this function:

◆ json_node_fw_version()

struct json_object * json_node_fw_version ( node_fw_version_t *  p)

create and fill json object from node_fw_version_t

Parameters
pobject of node_fw_version_t
Returns
ptr to object on success
NULL on error
Here is the caller graph for this function:

◆ json_node_info()

struct json_object * json_node_info ( node_info_t p)

create and fill json object from node_info_t as object

Parameters
sernumptr to node_info_t
Returns
ptr to object on success,
NULL on error
Here is the call graph for this function:
Here is the caller graph for this function:

◆ json_node_status()

struct json_object * json_node_status ( node_status_t *  p)
Here is the caller graph for this function:

◆ json_sensor_value()

struct json_object * json_sensor_value ( sensor_value_t *  p)

create and fill json object from sensor_value_t as object

Parameters
sernumptr to sensor_value_t
Returns
ptr to object on success,
NULL on error
Here is the caller graph for this function:

◆ json_sensors_data()

struct json_object * json_sensors_data ( sensors_data_t *  p)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ json_sensors_node()

struct json_object * json_sensors_node ( sensors_node_t *  p)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ json_serialnum()

struct json_object * json_serialnum ( node_serial_num_t *  sernum)

create and fill json object from node_serial_num_t as object

Parameters
addrnode_addr_t ptr of node address
as_stringif 1 create object as json_string
Returns
ptr to object on success,
NULL on error
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_node_addr()

int parse_node_addr ( struct json_object *  pobj,
node_addr_t paddr 
)

parse json obj for node_addr_t

Parameters
pobjptr to json obj
paddrptr to node_addr_t
Returns
0 success,
-1 error

on error rollback all mallocs

accept two variants in json:

  • "0x1234"
  • {"a0":1,"a1":2,"a2":3,"a3":4}
Here is the caller graph for this function:

◆ parse_node_fw_version()

int parse_node_fw_version ( struct json_object *  pobj,
node_fw_version_t *  p 
)

parse json obj for node_fw_version_t

Parameters
pobjptr to json obj
dsdptr to node_fw_version_t
Returns
0 success,
-1 error

on error rollback all mallocs

Here is the caller graph for this function:

◆ parse_node_info()

int parse_node_info ( struct json_object *  pobj,
node_info_t p 
)

parse json obj for node_info_t

Parameters
pobjptr to json obj
pptr to node_info_t
Returns
0 success,
-1 error
Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_node_status()

int parse_node_status ( struct json_object *  pobj,
node_status_t *  p 
)
Here is the caller graph for this function:

◆ parse_sensor_value()

int parse_sensor_value ( struct json_object *  pobj,
sensor_value_t *  p 
)

parse json obj for sensor_value_t

Parameters
pobjptr to json obj
pptr to sensor_value_t
Returns
0 success,
-1 error
Here is the caller graph for this function:

◆ parse_sensors_data()

int parse_sensors_data ( struct json_object *  pobj,
sensors_data_t **  pp 
)

parse json with sensors_data

Parameters
pobjobject of "sensor_data"
ppholder of pointer to sensors_data struct
Returns
- on success
-1 on error
1 in data rebuilded (parsed)

if (*pp == NULL) parsing is needed. NEW struct sensors_data_t is malloc into *pp if (*pp != NULL && **pp.crc == new_crc && **pp.data.updateCounter == new_updateCounter && **p.data.nodesСount == new_nodesСount) do nothing return 0; if (*pp != NULL && **p.data.nodesСount == new_nodesСount && (**pp.crc != new_crc || **pp.data.updateCounter || new_updateCounter) parse into existing struct sensors_data_t. return 1 if (*pp != NULL && **p.data.nodesСount != new_nodesСount) parse into new struct sensors_data_t

Here is the call graph for this function:

◆ parse_sensors_node()

int parse_sensors_node ( struct json_object *  pobj,
sensors_node_t *  p 
)
Here is the call graph for this function:

◆ parse_serialnum()

int parse_serialnum ( struct json_object *  pobj,
node_serial_num_t *  sn 
)

parse json obj for serialnum node_serial_num_t

Parameters
pobjptr to json obj
paddrptr to node_addr_t
Returns
0 success, -1 error

on error rollback all mallocs

Here is the call graph for this function:

◆ print_sensors_data()

void print_sensors_data ( sensors_data_t *  p,
char *  msg 
)
Here is the call graph for this function:

◆ print_sensors_node()

void print_sensors_node ( sensors_node_t *  p,
char *  msg 
)
Here is the call graph for this function: