Robotran C Documentation
Functions
mbs_json.h File Reference
#include "json.h"
#include "mbs_data.h"

Go to the source code of this file.

Functions

int count_json_array_elements (JsonNode *node)
 Counts the number of element in the Json array. More...
 
int count_json_elements (JsonNode *node)
 Counts the number of element in the json node. More...
 
int mbs_json_double (JsonNode *node, double *val_ptr, char *key, int read_write, int allow_missing)
 Link between double value and the specific key of a Json node or the current node. More...
 
int mbs_json_get_double (JsonNode *node, double *val_ptr)
 Get the node value content a double. More...
 
int mbs_json_set_double (JsonNode *node, double value)
 Set a double into a node. More...
 
int mbs_json_string (JsonNode *node, char **str_ptr, const char *key, int mission, int allow_missing)
 Link between string value and the specific key of a Json node. More...
 
int mbs_json_get_string (JsonNode *node, char **str_ptr)
 Get the node value content a double. More...
 
int mbs_json_set_string (JsonNode *node, const char *string)
 Set a double into a node. More...
 
int mbs_json_array (JsonNode *node, double **tab_ptr, int *size, const char *key, int mission, int allow_missing)
 Link an array (1D) value and the specific key of a Json node or the current node. More...
 
JsonNodembs_json_add_array (JsonNode *root_node, double *array, int size, const char *key, int *err)
 Add or replace the array in the specified children of the root node. More...
 
int mbs_json_tab (JsonNode *node, double ***tab_ptr, int size_1, int size_2, const char *key, int mission)
 Link between array (2D) value and the specific key of a Json node or the current node. More...
 
int mbs_json_bool (JsonNode *node, int *val_ptr, char *key, int mission, int allow_missing)
 Link between bool value (int) and the specific key of a Json node or the current node. More...
 
int mbs_json_get_bool (JsonNode *node, int *val_ptr)
 Get the node value content a bool as int. More...
 
int mbs_json_set_bool (JsonNode *node, int value)
 Set a bool (int) into a node. More...
 
int mbs_json_int (JsonNode *node, int *val_ptr, char *key, int read_write, int allow_missing)
 Link between integer value and the specific key of a Json node or the current node. More...
 
int mbs_json_get_int (JsonNode *node, int *val_ptr)
 Get the node value content an integer. More...
 
int mbs_json_set_int (JsonNode *node, int value)
 Set an integer into a node. More...
 
JsonNodembs_json_save_mbs (MbsData *mbs_data, char *filename, int flag_q, int flag_qd, int flag_qdd, int flag_mass, int *err)
 Save the speficied status of the mbs in a json configuration node and file. More...
 
JsonNodeload_and_create_json (const char *mbs_json_filename, int *err)
 

Function Documentation

◆ count_json_array_elements()

int count_json_array_elements ( JsonNode node)

Counts the number of element in the Json array.

Parameters
[in]nodeThe array node, if this is not a JSON_ARRAY then MBS_INFO_FAILURE is returned.
Returns
The number of element (>=0) or -9 (should be equal to `MBS_INFO_FAILURE.).

◆ count_json_elements()

int count_json_elements ( JsonNode node)

Counts the number of element in the json node.

Parameters
[in]nodeThe Json node
Returns
The number of element (>=0) or -9 (should be equal to `MBS_INFO_FAILURE.).

◆ load_and_create_json()

JsonNode* load_and_create_json ( const char *  mbs_json_filename,
int *  err 
)

◆ mbs_json_add_array()

JsonNode* mbs_json_add_array ( JsonNode root_node,
double *  array,
int  size,
const char *  key,
int *  err 
)

Add or replace the array in the specified children of the root node.

Parameters
[in,out]root_nodeThe json node in which the array must be saved. NULL can be provided, in this case the array node has no parent
[in]arrayThe array of double to be saved.
[in]sizeThe number of element in the array.
[in]keyThe name of the json array to be created. If a json node already exist with this key on the root node, it is freed then replaced by the array. If root_node is NULL, key is disregarded.
[in,out]errStatus code among MBS_INFO_SUCCESS and MBS_INFO_FAILURE. NULL can be provided, error will not be registered.
Returns
A pointer to the json node array or NULL in case of error.

◆ mbs_json_array()

int mbs_json_array ( JsonNode node,
double **  tab_ptr,
int *  size,
const char *  key,
int  mission,
int  allow_missing 
)

Link an array (1D) value and the specific key of a Json node or the current node.

Parameters
[in,out]nodeThe Json node containing the targeted value.
[in,out]tab_ptrThe memory adress of the pointer to the array (to be read or set). if the pointer (tab_ptr[0]) is NULL and mission is READER a new array is allocated.
[in,out]sizeThe size of the array pointer by tab_ptr (if tab_ptr[0] is not NULL).
[in]keyThe key of the json node to be used (to be read or set), if NULL the node is the array.
[in]missionThe mission, implemented are MBS_INFO_READER and MBS_INFO_UPDATER.
[in]allow_missingFlag to disable failure (and message) if the key is missing,
Returns
MBS_INFO_SUCCESS, MBS_INFO_FAILURE or MBS_INFO_WARNING if the key is not located.

◆ mbs_json_bool()

int mbs_json_bool ( JsonNode node,
int *  val_ptr,
char *  key,
int  mission,
int  allow_missing 
)

Link between bool value (int) and the specific key of a Json node or the current node.

Parameters
nodeThe Json node containing the targeted value.
val_ptrThe memory containing the bool as integer (to be read or set)
keyThe key of the json node to be used (to be read or set). If null the node is used as target.
missionThe mission, implemented are MBS_INFO_READER and MBS_INFO_UPDATER.
allow_missingFlag to disable failure (and message) if the key is missing. The return code is MBS_INFO_WARNING.
Returns
MBS_INFO_SUCCESS, MBS_INFO_FAILURE or MBS_INFO_WARNING.

◆ mbs_json_double()

int mbs_json_double ( JsonNode node,
double *  val_ptr,
char *  key,
int  read_write,
int  allow_missing 
)

Link between double value and the specific key of a Json node or the current node.

Parameters
nodeThe Json node containing the targeted value.
val_ptrThe memory containing the double (to be read or set)
keyThe key of the json node to be used (to be read or set). If null the node is used as target.
read_writeThe mission, implemented are MBS_INFO_READER and MBS_INFO_UPDATER.
allow_missingFlag to disable failure (and message) if the key is missing. The return code is MBS_INFO_WARNING.
Returns
MBS_INFO_SUCCESS, MBS_INFO_WARNING or MBS_INFO_FAILURE.

◆ mbs_json_get_bool()

int mbs_json_get_bool ( JsonNode node,
int *  val_ptr 
)

Get the node value content a bool as int.

The function convert the content of the node to double according to the node type. If the node is a JSON_STRING the following value are accepted:

  • as true: "TRUE", "True", "true"
  • as false: "FALSE", "False", "false" Other value will generate a MBS_INFO_FAILURE.
Parameters
nodeThe node to whose value must be read.
val_ptrThe memory where to set the number.
Returns
MBS_INFO_SUCCESS or MBS_INFO_FAILURE.

◆ mbs_json_get_double()

int mbs_json_get_double ( JsonNode node,
double *  val_ptr 
)

Get the node value content a double.

The function convert the content of the node to double according to the node type.

Parameters
[in]nodeThe node to whose value must be read.
[out]val_ptrThe memory where to set the number.
Returns
MBS_INFO_SUCCESS or MBS_INFO_FAILURE.

◆ mbs_json_get_int()

int mbs_json_get_int ( JsonNode node,
int *  val_ptr 
)

Get the node value content an integer.

The function convert the content of the node to integer according to the node type.

Parameters
[in]nodeThe node to whose value must be read.
[out]val_ptrThe memory where to set the number.
Returns
MBS_INFO_SUCCESS or MBS_INFO_FAILURE.

◆ mbs_json_get_string()

int mbs_json_get_string ( JsonNode node,
char **  str_ptr 
)

Get the node value content a double.

The function convert the content of the node to double according to the node type.

If the string pointer is not pointing to NULL, memory is freed before allocating.

Parameters
nodeThe node to whose value must be read.
str_ptrThe memory adress of the pointer to the string (to be read or set).
Returns
Zero for success, Non-zero value for error.

◆ mbs_json_int()

int mbs_json_int ( JsonNode node,
int *  val_ptr,
char *  key,
int  read_write,
int  allow_missing 
)

Link between integer value and the specific key of a Json node or the current node.

Parameters
nodeThe Json node containing the targeted value.
val_ptrThe memory containing the integer (to be read or set)
keyThe key of the json node to be used (to be read or set). If null the node is used as target.
read_writeThe mission, implemented are MBS_INFO_READER and MBS_INFO_UPDATER.
allow_missingFlag to disable failure (and message) if the key is missing. The return code is MBS_INFO_WARNING.
Returns
MBS_INFO_SUCCESS, MBS_INFO_FAILURE or MBS_INFO_WARNING

◆ mbs_json_save_mbs()

JsonNode* mbs_json_save_mbs ( MbsData mbs_data,
char *  filename,
int  flag_q,
int  flag_qd,
int  flag_qdd,
int  flag_mass,
int *  err 
)

Save the speficied status of the mbs in a json configuration node and file.

Empty configuration files are not saved to disk, but are returned.

If unable to write the configuration to disk, the json configuration node is returned, but an error is set.

Parameters
[in]mbs_dataThe multibody sytem to be saved
[in]filenameThe name of the configuration file to be created. It contains path and extension. NULL can be provided, no file are created.
[in]flag_qFlag to save joint coordinates.
[in]flag_qdFlag to save joint velocities.
[in]flag_qddFlag to save joint accelerations.
[in]flag_massFlag to save bodies mass.
[in,out]errerr Status code among MBS_INFO_SUCCESS, MBS_INFO_FAILURE and MBS_INFO_WARNING. NULL can be provided, error will not be registered.
Returns
A pointer to the json configuration root node if successfully created. NULL is returned in case of configuration creation failure.

◆ mbs_json_set_bool()

int mbs_json_set_bool ( JsonNode node,
int  value 
)

Set a bool (int) into a node.

The function only accept JSON_BOOL, JSON_NUMBER and JSON_STRING nodes. The function convert the node to a JSON_BOOL.

Parameters
nodeThe node to whose value must be set.
valueThe value to be set.
Returns
MBS_INFO_SUCCESS or MBS_INFO_FAILURE

◆ mbs_json_set_double()

int mbs_json_set_double ( JsonNode node,
double  value 
)

Set a double into a node.

The function only accept JSON_NUMBER and JSON_STRING nodes. In case of JSON_STRING an attempt is done to convert the node to JSON_NUMBER.

Parameters
nodeThe node to whose value must be set.
valuleThe value to be set.
Returns
MBS_INFO_SUCCESS or MBS_INFO_FAILURE

◆ mbs_json_set_int()

int mbs_json_set_int ( JsonNode node,
int  value 
)

Set an integer into a node.

The function only accept JSON_NUMBER and JSON_STRING nodes. In case of JSON_STRING an attempt is done to convert the node to JSON_NUMBER.

Parameters
nodeThe node to whose value must be set.
valuleThe value to be set.
Returns
MBS_INFO_SUCCESS or MBS_INFO_FAILURE

◆ mbs_json_set_string()

int mbs_json_set_string ( JsonNode node,
const char *  string 
)

Set a double into a node.

The function only accept JSON_NUMBER and JSON_STRING nodes. In case of JSON_STRING an attempt is done to convert the node to JSON_NUMBER.

Parameters
nodeThe node to whose value must be set.
stringThe pointer to the string to be read.
Returns
MBS_INFO_SUCCESS or MBS_INFO_FAILURE.

◆ mbs_json_string()

int mbs_json_string ( JsonNode node,
char **  str_ptr,
const char *  key,
int  mission,
int  allow_missing 
)

Link between string value and the specific key of a Json node.

Parameters
nodeThe Json node containing the targeted value.
str_ptrThe memory adress of the pointer to the string (to be read or set). For MBS_INFO_READER mission, if the pointer pointed by this variable is not NULL the memory is reallocated.
keyThe key of the json node to be used (to be read or set).
missionThe mission, implemented are MBS_INFO_READER and MBS_INFO_UPDATER.
allow_missingFlag to disable failure (and message) if the key is missing. The return code is MBS_INFO_WARNING.
Returns
MBS_INFO_SUCCESS, MBS_INFO_FAILURE or MBS_INFO_WARNING

◆ mbs_json_tab()

int mbs_json_tab ( JsonNode node,
double ***  tab_ptr,
int  size_1,
int  size_2,
const char *  key,
int  mission 
)

Link between array (2D) value and the specific key of a Json node or the current node.

Parameters
nodeThe Json node containing the targeted value.
tab_ptrThe memory adress of the pointer to pointer to the array (to be read or set). if the pointer (tab_ptr[0]) is NULL and mission is READER a new array is allocated will be allocated but memory is NOT contigous.
size_1The size along first axis of the array pointer by tab_ptr (if tab_ptr[0] is not NULL).
size_2The size along second axis of the array pointer by tab_ptr (if tab_ptr[0] is not NULL).
keyThe key of the json node to be used (to be read or set), if NULL the node is the array.
missionThe mission, implemented are MBS_INFO_READER and MBS_INFO_UPDATER.
Returns
MBS_INFO_SUCCESS or MBS_INFO_FAILURE