38 static void co_obj_set_id(
39 co_obj_t *obj, co_unsigned8_t new_id, co_unsigned8_t old_id);
40 static void co_sub_set_id(
41 co_sub_t *sub, co_unsigned8_t new_id, co_unsigned8_t old_id);
42 static void co_val_set_id(co_unsigned16_t type,
void *val,
43 co_unsigned8_t new_id, co_unsigned8_t old_id);
50 void *ptr = malloc(
sizeof(
struct __co_dev));
59 __co_dev_free(
void *ptr)
67 __co_dev_init(
struct __co_dev *dev, co_unsigned8_t
id)
81 #if !LELY_NO_CO_OBJ_NAME
87 #if !LELY_NO_CO_OBJ_NAME
92 #if !LELY_NO_CO_OBJ_NAME
125 #if !LELY_NO_CO_OBJ_NAME
145 goto error_alloc_dev;
148 if (!__co_dev_init(dev,
id)) {
224 co_unsigned16_t *idx)
233 for (
size_t i = 0; node && i < maxidx;
247 if (obj->
dev && obj->
dev != dev)
314 #if !LELY_NO_CO_OBJ_NAME
329 if (!name || !*name) {
335 void *ptr = realloc(dev->
name, strlen(name) + 1);
343 strcpy(dev->
name, name);
361 if (!vendor_name || !*vendor_name) {
367 void *ptr = realloc(dev->
vendor_name, strlen(vendor_name) + 1);
398 #if !LELY_NO_CO_OBJ_NAME
413 if (!product_name || !*product_name) {
419 void *ptr = realloc(dev->
product_name, strlen(product_name) + 1);
466 #if !LELY_NO_CO_OBJ_NAME
481 if (!order_code || !*order_code) {
487 void *ptr = realloc(dev->
order_code, strlen(order_code) + 1);
575 const void *ptr,
size_t n)
588 #define LELY_CO_DEFINE_TYPE(a, b, c, d) \
589 co_##b##_t co_dev_get_val_##c(const co_dev_t *dev, \
590 co_unsigned16_t idx, co_unsigned8_t subidx) \
593 co_sub_t *sub = dev \
594 ? co_dev_find_sub(dev, idx, subidx) \
597 return co_sub_get_val_##c(sub); \
600 size_t co_dev_set_val_##c(co_dev_t *dev, co_unsigned16_t idx, \
601 co_unsigned8_t subidx, co_##b##_t c) \
605 co_sub_t *sub = co_dev_find_sub(dev, idx, subidx); \
607 set_errnum(ERRNUM_INVAL); \
611 return co_sub_set_val_##c(sub, c); \
613 #include <lely/co/def/basic.def>
614 #undef LELY_CO_DEFINE_TYPE
618 const uint_least8_t *begin,
const uint_least8_t *end)
620 if (!begin || !end || end - begin < 2 + 1 + 4)
629 co_unsigned8_t subidx;
634 co_unsigned32_t size;
639 if (end - begin < (ptrdiff_t)size)
648 struct co_array array = CO_ARRAY_INIT;
650 co_val_init_array(&val, &array);
654 if (
co_val_read(type, &val, begin, begin + size) == size)
667 return 2 + 1 + 4 + size;
672 co_unsigned8_t subidx, uint_least8_t *begin, uint_least8_t *end)
680 co_unsigned32_t size =
co_val_write(type, val, NULL, NULL);
684 if (begin && (!end || end - begin >= (ptrdiff_t)(2 + 1 + 4 + size))) {
703 return 2 + 1 + 4 + size;
717 const uint_least8_t *begin = *ptr;
718 const uint_least8_t *end = begin + size;
727 for (
size_t i = 0; i < n; i++) {
751 co_unsigned16_t *pmax,
const char *filename)
775 co_unsigned32_t n = 0;
798 uint_least8_t *begin = *ptr;
799 uint_least8_t *end = begin + size;
825 co_unsigned16_t max,
const char *filename)
877 for (co_unsigned16_t i = 0; i <
CO_NUM_PDOS && !obj_1800; i++)
879 for (; obj_1800; obj_1800 =
co_obj_next(obj_1800)) {
900 for (
size_t j = 0; j <
map->n; j++) {
901 if (((
map->map[j] >> 16) & 0xffff) != idx)
903 if (((
map->map[j] >> 8) & 0xff) != subidx)
953 for (co_unsigned16_t i = 0; i <
CO_NUM_PDOS && !obj_1800; i++)
955 for (; obj_1800; obj_1800 =
co_obj_next(obj_1800)) {
964 || comm->
trans < 0xfe)
990 co_obj_set_id(
co_obj_t *obj, co_unsigned8_t new_id, co_unsigned8_t old_id)
999 co_sub_set_id(
co_sub_t *sub, co_unsigned8_t new_id, co_unsigned8_t old_id)
1005 #if !LELY_NO_CO_OBJ_LIMITS
1007 co_val_set_id(type, &sub->
min, new_id, old_id);
1009 co_val_set_id(type, &sub->
max, new_id, old_id);
1011 #if !LELY_NO_CO_OBJ_DEFAULT
1013 co_val_set_id(type, &sub->
def, new_id, old_id);
1016 co_val_set_id(type, sub->
val, new_id, old_id);
1020 co_val_set_id(co_unsigned16_t type,
void *val, co_unsigned8_t new_id,
1021 co_unsigned8_t old_id)
1027 #define LELY_CO_DEFINE_TYPE(a, b, c, d) \
1028 case CO_DEFTYPE_##a: \
1029 u->c += new_id - old_id; \
1031 #include <lely/co/def/basic.def>
1032 #undef LELY_CO_DEFINE_TYPE
This header file is part of the utilities library; it contains the comparison function definitions.
This is the internal header file of the device description.
void co_dev_sam_mpdo_event(co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx)
Checks if the specified sub-object in the object dictionary of a CANopen device can be mapped into a ...
void co_dev_get_tpdo_event_ind(const co_dev_t *dev, co_dev_tpdo_event_ind_t **pind, void **pdata)
Retrieves the indication function invoked by co_dev_tpdo_event() when an event is indicated for (a su...
co_sub_t * co_dev_find_sub(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx)
Finds a sub-object in the object dictionary of a CANopen device.
co_unsigned16_t co_dev_get_idx(const co_dev_t *dev, co_unsigned16_t maxidx, co_unsigned16_t *idx)
Retrieves a list of object indices in the object dictionary of a CANopen device.
co_dev_t * co_dev_create(co_unsigned8_t id)
Creates a new CANopen device.
int co_dev_read_dcf(co_dev_t *dev, co_unsigned16_t *pmin, co_unsigned16_t *pmax, void *const *ptr)
Reads the values of a range of objects from a memory buffer, in the concise DCF format,...
size_t co_dev_read_sub(co_dev_t *dev, co_unsigned16_t *pidx, co_unsigned8_t *psubidx, const uint_least8_t *begin, const uint_least8_t *end)
Reads a value from a memory buffer, in the concise DCF format, and stores it in a sub-object in the o...
co_unsigned8_t co_dev_get_id(const co_dev_t *dev)
Returns the node-ID of a CANopen device.
int co_dev_set_vendor_name(co_dev_t *dev, const char *vendor_name)
Sets the vendor name of a CANopen device.
const void * co_dev_get_val(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx)
Returns a pointer to the current value of a CANopen sub-object.
void co_dev_get_sam_mpdo_event_ind(const co_dev_t *dev, co_dev_sam_mpdo_event_ind_t **pind, void **pdata)
Retrieves the indication function invoked by co_dev_sam_mpdo_event() when an event is indicated for (...
void co_dev_set_product_code(co_dev_t *dev, co_unsigned32_t product_code)
Sets the product code of a CANopen device.
void co_dev_set_dummy(co_dev_t *dev, co_unsigned32_t dummy)
Sets the data types supported by a CANopen device for mapping dummy entries in PDOs.
int co_dev_insert_obj(co_dev_t *dev, co_obj_t *obj)
Inserts an object into the object dictionary of a CANopen device.
void co_dev_set_vendor_id(co_dev_t *dev, co_unsigned32_t vendor_id)
Sets the vendor ID of a CANopen device.
const char * co_dev_get_name(const co_dev_t *dev)
Returns the name of a CANopen device.
int co_dev_set_id(co_dev_t *dev, co_unsigned8_t id)
Sets the node-ID of a CANopen device.
int co_dev_set_netid(co_dev_t *dev, co_unsigned8_t id)
Sets the network-ID of a CANopen device.
void co_dev_set_revision(co_dev_t *dev, co_unsigned32_t revision)
Sets the revision number of a CANopen device.
co_unsigned16_t co_dev_get_rate(const co_dev_t *dev)
Returns the (pending) baudrate of a CANopen device (in kbit/s).
int co_dev_write_dcf(const co_dev_t *dev, co_unsigned16_t min, co_unsigned16_t max, void **ptr)
Loads the values of a range of objects in the object dictionary of a CANopen device,...
co_obj_t * co_dev_first_obj(const co_dev_t *dev)
Finds the first object (with the lowest index) in the object dictionary of a CANopen device.
int co_dev_remove_obj(co_dev_t *dev, co_obj_t *obj)
Removes an object from the object dictionary a CANopen device.
int co_dev_get_lss(const co_dev_t *dev)
Returns 1 if LSS is supported and 0 if not.
void co_dev_set_sam_mpdo_event_ind(co_dev_t *dev, co_dev_sam_mpdo_event_ind_t *ind, void *data)
Sets the indication function invoked by co_dev_sam_mpdo_event() when an event is indicated for (a sub...
co_obj_t * co_dev_last_obj(const co_dev_t *dev)
Finds the last object (with the highest index) in the object dictionary of a CANopen device.
co_unsigned8_t co_dev_get_netid(const co_dev_t *dev)
Returns the network-ID of a CANopen device.
co_unsigned32_t co_dev_get_vendor_id(const co_dev_t *dev)
Returns the vendor ID of a CANopen device.
void co_dev_set_lss(co_dev_t *dev, int lss)
Sets the LSS support flag.
int co_dev_set_order_code(co_dev_t *dev, const char *order_code)
Sets the order code of a CANopen device.
co_unsigned32_t co_dev_get_dummy(const co_dev_t *dev)
Returns the data types supported by a CANopen device for mapping dummy entries in PDOs (one bit for e...
const char * co_dev_get_product_name(const co_dev_t *dev)
Returns a pointer to the product name of a CANopen device.
int co_dev_write_dcf_file(const co_dev_t *dev, co_unsigned16_t min, co_unsigned16_t max, const char *filename)
Loads the values of a range of objects in the object dictionary of a CANopen device,...
void co_dev_destroy(co_dev_t *dev)
Destroys a CANopen device, including all objects in its object dictionary.
co_obj_t * co_dev_find_obj(const co_dev_t *dev, co_unsigned16_t idx)
Finds an object in the object dictionary of a CANopen device.
void co_dev_tpdo_event(co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx)
Checks if the specified sub-object in the object dictionary of a CANopen device can be mapped into a ...
void co_dev_set_rate(co_dev_t *dev, co_unsigned16_t rate)
Sets the (pending) baudrate of a CANopen device.
size_t co_dev_set_val(co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx, const void *ptr, size_t n)
Sets the current value of a CANopen sub-object.
unsigned int co_dev_get_baud(const co_dev_t *dev)
Returns the supported bit rates of a CANopen device (any combination of CO_BAUD_1000,...
co_unsigned32_t co_dev_get_product_code(const co_dev_t *dev)
Returns the product code of a CANopen device.
int co_dev_set_product_name(co_dev_t *dev, const char *product_name)
Sets the product name of a CANopen device.
void co_dev_set_baud(co_dev_t *dev, unsigned int baud)
Sets the supported bit rates of a CANopen device.
void co_dev_set_tpdo_event_ind(co_dev_t *dev, co_dev_tpdo_event_ind_t *ind, void *data)
Sets the indication function invoked by co_dev_tpdo_event() when an event is indicated for (a sub-obj...
int co_dev_read_dcf_file(co_dev_t *dev, co_unsigned16_t *pmin, co_unsigned16_t *pmax, const char *filename)
Reads the values of a range of objects from a file, in the concise DCF format, and stores them in the...
const char * co_dev_get_vendor_name(const co_dev_t *dev)
Returns a pointer to the vendor name of a CANopen device.
size_t co_dev_write_sub(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx, uint_least8_t *begin, uint_least8_t *end)
Loads the value of a sub-object from the object dictionary of a CANopen device, and writes it to a me...
const char * co_dev_get_order_code(const co_dev_t *dev)
Returns a pointer to the order code of a CANopen device.
int co_dev_set_name(co_dev_t *dev, const char *name)
Sets the name of a CANopen device.
co_unsigned32_t co_dev_get_revision(const co_dev_t *dev)
Returns the revision number of a CANopen device.
void co_dev_tpdo_event_ind_t(co_unsigned16_t num, void *data)
The type of a CANopen Transmit-PDO event indication function, invoked by co_dev_tpdo_event() when an ...
#define CO_NUM_NODES
The maximum number of nodes in a CANopen network.
#define CO_NUM_NETWORKS
The maximum number of CANopen networks.
void co_dev_sam_mpdo_event_ind_t(co_unsigned16_t num, co_unsigned16_t idx, co_unsigned8_t subidx, void *data)
The type of a CANopen source address mode multiplex PDO event indication function,...
This is the internal header file of the object dictionary.
This header file is part of the utilities library; it contains the diagnostic declarations.
@ ERRNUM_INVAL
Invalid argument.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
int errno2c(int errnum)
Transforms a standard C error number to a native error code.
void set_errnum(errnum_t errnum)
Sets the current (thread-specific) platform-independent error number to errnum.
#define structof(ptr, type, member)
Obtains the address of a structure from the address of one of its members.
#define MIN(a, b)
Returns the minimum of a and b.
#define MAX(a, b)
Returns the maximum of a and b.
co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub)
Returns the sub-index of a CANopen sub-object.
const void * co_sub_get_val(const co_sub_t *sub)
Returns a pointer to the current value of a CANopen sub-object.
#define CO_OBJ_FLAGS_MAX_NODEID
The upper limit of the object value is of the form $NODEID { "+" number }.
co_sub_t * co_sub_next(const co_sub_t *sub)
Finds the next sub-object in a CANopen object.
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
void * co_obj_addressof_val(const co_obj_t *obj)
Returns the address of the value of a CANopen object.
size_t co_sub_set_val(co_sub_t *sub, const void *ptr, size_t n)
Sets the current value of a CANopen sub-object.
#define CO_OBJ_FLAGS_DEF_NODEID
The default object value is of the form $NODEID { "+" number }.
unsigned int co_sub_get_flags(const co_sub_t *sub)
Returns the object flags of a CANopen sub-object.
co_obj_t * co_obj_next(const co_obj_t *obj)
Finds the next object in the object dictionary of a CANopen device.
co_sub_t * co_obj_find_sub(const co_obj_t *obj, co_unsigned8_t subidx)
Finds a sub-object in a CANopen object.
#define CO_OBJ_FLAGS_MIN_NODEID
The lower limit of the object value is of the form $NODEID { "+" number }.
#define CO_OBJ_FLAGS_VAL_NODEID
The current object value is of the form $NODEID { "+" number }.
co_sub_t * co_obj_first_sub(const co_obj_t *obj)
Finds the first sub-object (with the lowest sub-index) in a CANopen object.
void co_obj_destroy(co_obj_t *obj)
Destroys a CANopen object, including its sub-objects.
co_unsigned16_t co_sub_get_type(const co_sub_t *sub)
Returns the data type of a CANopen sub-object.
This header file is part of the CANopen library; it contains the Process Data Object (PDO) declaratio...
co_unsigned32_t co_dev_chk_tpdo(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx)
Checks if the specified object is valid and can be mapped into a Transmit-PDO.
#define CO_PDO_COBID_VALID
The bit in the PDO COB-ID specifying whether the PDO exists and is valid.
#define CO_NUM_PDOS
The maximum number of Receive/Transmit-PDOs.
int co_dev_chk_sam_mpdo(const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx)
Checks if the specified object is part of the object scanner list (objects 1FA0..1FCF) and can be tra...
#define CO_PDO_MAP_SAM_MPDO
The value of sub-index 0 of the PDO mapping parameter record indicating a a source address mode multi...
void rbnode_init(struct rbnode *node, const void *key)
Initializes a node in a red-black tree.
void rbtree_insert(struct rbtree *tree, struct rbnode *node)
Inserts a node into a red-black tree.
struct rbnode * rbtree_last(const struct rbtree *tree)
Returns a pointer to the last (rightmost) node in a red-black tree.
void rbtree_init(struct rbtree *tree, rbtree_cmp_t *cmp)
Initializes a red-black tree.
size_t rbtree_size(const struct rbtree *tree)
Returns the size (in number of nodes) of a red-black tree.
void rbtree_remove(struct rbtree *tree, struct rbnode *node)
Removes a node from a red-black tree.
struct rbnode * rbtree_first(const struct rbtree *tree)
Returns a pointer to the first (leftmost) node in a red-black tree.
#define rbtree_foreach(tree, node)
Iterates over each node in a red-black tree in ascending order.
struct rbnode * rbtree_find(const struct rbtree *tree, const void *key)
Finds a node in a red-black tree.
struct rbnode * rbnode_next(const struct rbnode *node)
Returns a pointer to the next (in-order) node in a red-black tree with respect to node.
This is the internal header file of the CANopen library.
This header file is part of the C11 and POSIX compatibility library; it includes <stdlib....
struct rbtree tree
The tree containing the object dictionary.
co_unsigned32_t product_code
The product code.
char * product_name
A pointer to the product name.
co_unsigned16_t rate
The (pending) baudrate (in kbit/s).
char * vendor_name
A pointer to the vendor name.
char * order_code
A pointer to the order code.
co_dev_tpdo_event_ind_t * tpdo_event_ind
A pointer to the Transmit-PDO event indication function.
co_unsigned8_t netid
The network-ID.
co_unsigned8_t id
The node-ID.
void * sam_mpdo_event_data
A pointer to user-specified data for sam_mpdo_event_ind.
unsigned baud
The supported bit rates.
int lss
A flag specifying whether LSS is supported (1) or not (0).
co_unsigned32_t vendor_id
The vendor ID.
co_dev_sam_mpdo_event_ind_t * sam_mpdo_event_ind
A pointer to the SAM-MPDO event indication function.
co_unsigned32_t revision
The revision number.
co_unsigned32_t dummy
The data types supported for mapping dummy entries in PDOs.
void * tpdo_event_data
A pointer to user-specified data for tpdo_event_ind.
char * name
A pointer to the name of the device.
co_unsigned16_t idx
The object index.
struct rbtree tree
The tree containing all the sub-objects.
struct rbnode node
The node of this object in the tree of objects.
co_dev_t * dev
A pointer to the CANopen device containing this object.
union co_val def
The default value.
union co_val min
The lower limit of the object value.
union co_val max
The upper limit of the object value.
void * val
A pointer to the sub-object value.
A PDO communication parameter record.
co_unsigned32_t cobid
COB-ID.
co_unsigned8_t trans
Transmission type.
co_unsigned8_t n
Highest sub-index supported.
A PDO mapping parameter record.
co_unsigned32_t map[CO_PDO_NUM_MAPS]
An array of objects to be mapped.
A node in a red-black tree.
const void * key
A pointer to the key for this node.
#define CO_DEFTYPE_UNSIGNED16
The data type (and object index) of a 16-bit unsigned integer.
int co_type_is_array(co_unsigned16_t type)
Returns 1 if the specified (static) data type is an array, and 0 if not.
#define CO_DEFTYPE_DOMAIN
The data type (and object index) of an arbitrary large block of data.
#define CO_DEFTYPE_UNSIGNED8
The data type (and object index) of an 8-bit unsigned integer.
#define CO_DEFTYPE_UNSIGNED32
The data type (and object index) of a 32-bit unsigned integer.
A union of the CANopen static data types.
size_t co_val_read(co_unsigned16_t type, void *val, const uint_least8_t *begin, const uint_least8_t *end)
Reads a value of the specified data type from a memory buffer.
int co_val_init(co_unsigned16_t type, void *val)
Initializes a value of the specified data type to zero.
#define CO_UNSIGNED16_MIN
The minimum value of a 16-bit unsigned integer.
size_t co_val_write(co_unsigned16_t type, const void *val, uint_least8_t *begin, uint_least8_t *end)
Writes a value of the specified data type to a memory buffer.
int co_val_init_dom(void **val, const void *dom, size_t n)
Initializes an arbitrary large block of data (CO_DEFTYPE_DOMAIN).
const void * co_val_addressof(co_unsigned16_t type, const void *val)
Returns the address of the first byte in a value of the specified data type.
size_t co_val_sizeof(co_unsigned16_t type, const void *val)
Returns the size (in bytes) of a value of the specified data type.
size_t co_val_read_file(co_unsigned16_t type, void *val, const char *filename)
Reads a value of the specified data type from a file.
void co_val_fini(co_unsigned16_t type, void *val)
Finalizes a value of the specified data type.
size_t co_val_write_file(co_unsigned16_t type, const void *val, const char *filename)
Writes a value of the specified data type to a file.
#define CO_UNSIGNED16_MAX
The maximum value of a 16-bit unsigned integer.