Lely core libraries
2.2.5
|
This file is part of the CANopen library; it contains the implementation of the device description. More...
#include "co.h"
#include <lely/util/cmp.h>
#include <lely/util/diag.h>
#include <lely/util/frbuf.h>
#include <lely/util/fwbuf.h>
#include "obj.h"
#include <lely/co/dev.h>
#include <lely/co/pdo.h>
#include <assert.h>
#include <stdlib.h>
#include <lely/co/def/basic.def>
Go to the source code of this file.
Data Structures | |
struct | __co_dev |
A CANopen device. More... | |
Functions | |
co_dev_t * | co_dev_create (co_unsigned8_t id) |
Creates a new CANopen device. More... | |
void | co_dev_destroy (co_dev_t *dev) |
Destroys a CANopen device, including all objects in its object dictionary. More... | |
co_unsigned8_t | co_dev_get_netid (const co_dev_t *dev) |
Returns the network-ID of a CANopen device. More... | |
int | co_dev_set_netid (co_dev_t *dev, co_unsigned8_t id) |
Sets the network-ID of a CANopen device. More... | |
co_unsigned8_t | co_dev_get_id (const co_dev_t *dev) |
Returns the node-ID of a CANopen device. More... | |
int | co_dev_set_id (co_dev_t *dev, co_unsigned8_t id) |
Sets the node-ID of a CANopen device. More... | |
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. More... | |
int | co_dev_insert_obj (co_dev_t *dev, co_obj_t *obj) |
Inserts an object into the object dictionary of a CANopen device. More... | |
int | co_dev_remove_obj (co_dev_t *dev, co_obj_t *obj) |
Removes an object from the object dictionary a CANopen device. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
const char * | co_dev_get_name (const co_dev_t *dev) |
Returns the name of a CANopen device. More... | |
int | co_dev_set_name (co_dev_t *dev, const char *name) |
Sets the name of a CANopen device. More... | |
const char * | co_dev_get_vendor_name (const co_dev_t *dev) |
Returns a pointer to the vendor name of a CANopen device. More... | |
int | co_dev_set_vendor_name (co_dev_t *dev, const char *vendor_name) |
Sets the vendor name of a CANopen device. More... | |
co_unsigned32_t | co_dev_get_vendor_id (const co_dev_t *dev) |
Returns the vendor ID of a CANopen device. More... | |
void | co_dev_set_vendor_id (co_dev_t *dev, co_unsigned32_t vendor_id) |
Sets the vendor ID of a CANopen device. More... | |
const char * | co_dev_get_product_name (const co_dev_t *dev) |
Returns a pointer to the product name of a CANopen device. More... | |
int | co_dev_set_product_name (co_dev_t *dev, const char *product_name) |
Sets the product name of a CANopen device. More... | |
co_unsigned32_t | co_dev_get_product_code (const co_dev_t *dev) |
Returns the product code of a CANopen device. More... | |
void | co_dev_set_product_code (co_dev_t *dev, co_unsigned32_t product_code) |
Sets the product code of a CANopen device. More... | |
co_unsigned32_t | co_dev_get_revision (const co_dev_t *dev) |
Returns the revision number of a CANopen device. More... | |
void | co_dev_set_revision (co_dev_t *dev, co_unsigned32_t revision) |
Sets the revision number of a CANopen device. More... | |
const char * | co_dev_get_order_code (const co_dev_t *dev) |
Returns a pointer to the order code of a CANopen device. More... | |
int | co_dev_set_order_code (co_dev_t *dev, const char *order_code) |
Sets the order code of a CANopen device. More... | |
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_BAUD_800, CO_BAUD_500, CO_BAUD_250, CO_BAUD_125, CO_BAUD_50, CO_BAUD_20, CO_BAUD_10 and CO_BAUD_AUTO). More... | |
void | co_dev_set_baud (co_dev_t *dev, unsigned int baud) |
Sets the supported bit rates of a CANopen device. More... | |
co_unsigned16_t | co_dev_get_rate (const co_dev_t *dev) |
Returns the (pending) baudrate of a CANopen device (in kbit/s). More... | |
void | co_dev_set_rate (co_dev_t *dev, co_unsigned16_t rate) |
Sets the (pending) baudrate of a CANopen device. More... | |
int | co_dev_get_lss (const co_dev_t *dev) |
Returns 1 if LSS is supported and 0 if not. More... | |
void | co_dev_set_lss (co_dev_t *dev, int lss) |
Sets the LSS support flag. More... | |
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 each of the basic types). More... | |
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. More... | |
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. More... | |
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. More... | |
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 object dictionary of a CANopen device. More... | |
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 memory buffer, in the concise DCF format. More... | |
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, and stores them in the object dictionary of a CANopen device. More... | |
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 object dictionary of a CANopen device. More... | |
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, and writes them to a memory buffer, in the concise DCF format. More... | |
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, and writes them to a file, in the concise DCF format. More... | |
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 sub-object mapped into) an acyclic or event-driven Transmit-PDO. More... | |
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-object mapped into) an acyclic or event-driven Transmit-PDO. More... | |
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 PDO and, if so, issues an indication for every valid, acylic or event-driven Transmit-PDO into which the sub-object is mapped by invoking the user-defined callback function set with co_dev_set_tpdo_event_ind(). More... | |
This file is part of the CANopen library; it contains the implementation of the device description.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Definition in file dev.c.
co_dev_t* co_dev_create | ( | co_unsigned8_t | id | ) |
Creates a new CANopen device.
id | the node-ID of the device (in the range [1..127, 255]). |
void co_dev_destroy | ( | co_dev_t * | dev | ) |
Destroys a CANopen device, including all objects in its object dictionary.
co_unsigned8_t co_dev_get_netid | ( | const co_dev_t * | dev | ) |
Returns the network-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.
co_unsigned8_t co_dev_get_id | ( | const co_dev_t * | dev | ) |
Returns the node-ID 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.
This function will also update any sub-object values of the form $NODEID { "+" number }
.
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.
dev | a pointer to a CANopen device. |
maxidx | the maximum number of object indices to return. |
idx | an array of at least maxidx indices (can be NULL). On success, *idx contains the object indices. |
Inserts an object into the object dictionary of a CANopen device.
This function fails if the object is already part of the object dictionary of another device, or if another object with the same index already exists.
dev | a pointer to a CANopen device. |
obj | a pointer to the object to be inserted. |
Removes an object from the object dictionary a CANopen device.
dev | a pointer to a CANopen device. |
obj | a pointer to the object to be removed. |
Finds an object in the object dictionary of a CANopen device.
dev | a pointer to a CANopen device. |
idx | the object index. |
Finds the first object (with the lowest index) in the object dictionary of a CANopen device.
Finds the last object (with the highest index) in the object dictionary 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_name | ( | co_dev_t * | dev, |
const char * | name | ||
) |
Sets the name of a CANopen device.
const char* co_dev_get_vendor_name | ( | const co_dev_t * | dev | ) |
Returns a pointer to the vendor name 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.
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_vendor_id | ( | co_dev_t * | dev, |
co_unsigned32_t | vendor_id | ||
) |
Sets the vendor ID of a CANopen device.
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_set_product_name | ( | co_dev_t * | dev, |
const char * | product_name | ||
) |
Sets the product name of a CANopen device.
co_unsigned32_t co_dev_get_product_code | ( | const co_dev_t * | dev | ) |
Returns the product code of a CANopen device.
void co_dev_set_product_code | ( | co_dev_t * | dev, |
co_unsigned32_t | product_code | ||
) |
Sets the product code 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_set_revision | ( | co_dev_t * | dev, |
co_unsigned32_t | revision | ||
) |
Sets the revision number of a CANopen device.
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_order_code | ( | co_dev_t * | dev, |
const char * | order_code | ||
) |
Sets the order code of a CANopen device.
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_BAUD_800, CO_BAUD_500, CO_BAUD_250, CO_BAUD_125, CO_BAUD_50, CO_BAUD_20, CO_BAUD_10 and CO_BAUD_AUTO).
void co_dev_set_baud | ( | co_dev_t * | dev, |
unsigned int | baud | ||
) |
Sets the supported bit rates of a CANopen device.
dev | a pointer to a CANopen device. |
baud | the supported bit rates (any combination of CO_BAUD_1000, CO_BAUD_800, CO_BAUD_500, CO_BAUD_250, CO_BAUD_125, CO_BAUD_50, CO_BAUD_20, CO_BAUD_10 and CO_BAUD_AUTO). |
co_unsigned16_t co_dev_get_rate | ( | const co_dev_t * | dev | ) |
Returns the (pending) baudrate of a CANopen device (in kbit/s).
void co_dev_set_rate | ( | co_dev_t * | dev, |
co_unsigned16_t | rate | ||
) |
Sets the (pending) baudrate of a CANopen device.
dev | a pointer to a CANopen device. |
rate | the baudrate (in kbit/s). |
int co_dev_get_lss | ( | const co_dev_t * | dev | ) |
Returns 1 if LSS is supported and 0 if not.
void co_dev_set_lss | ( | co_dev_t * | dev, |
int | lss | ||
) |
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 each of the basic types).
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.
dev | a pointer to a CANopen device. |
dummy | the data types supported for mapping dummy entries in PDOs (one bit for each of the basic types). |
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.
In the case of strings or domains, this is the address of a pointer to the first byte in the array.
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.
dev | a pointer to a CANopen device. |
idx | the object index. |
subidx | the object sub-index. |
ptr | a pointer to the bytes to be copied. In case of strings or domains, ptr MUST point to the first byte in the array. |
n | the number of bytes at ptr. In case of strings, n SHOULD exclude the terminating null byte(s). |
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 object dictionary of a CANopen device.
If the sub-object does not exist, the value is discarded.
dev | a pointer to a CANopen device. |
pidx | the address at which to store the object index (can be NULL). |
psubidx | the address at which to store the object sub-index (can be NULL). |
begin | a pointer to the start of the buffer. |
end | a pointer to the end of the buffer. |
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 memory buffer, in the concise DCF format.
dev | a pointer to a CANopen device. |
idx | the object index. |
subidx | the object sub-index. |
begin | a pointer to the start of the buffer. If begin is NULL, nothing is written. |
end | a pointer to the end of the buffer. If end is not NULL, and the buffer is too small (i.e., end - begin is less than the return value), nothing is written. |
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, and stores them in the object dictionary of a CANopen device.
If an object does not exist, the value is discarded.
dev | a pointer to a CANopen device. |
pmin | the address at which to store the minimum object index (can be NULL). |
pmax | the address at which to store the maximum object index (can be NULL). |
ptr | the address of a pointer to a DOMAIN value. |
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 object dictionary of a CANopen device.
If an object does not exist, the value is discarded.
dev | a pointer to a CANopen device. |
pmin | the address at which to store the minimum object index (can be NULL). |
pmax | the address at which to store the maximum object index (can be NULL). |
filename | a pointer to the name of the file. |
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, and writes them to a memory buffer, in the concise DCF format.
dev | a pointer to a CANopen device. |
min | the minimum object index. |
max | the maximum object index. |
ptr | the address of a pointer. On success, *ptr points to a DOMAIN value. |
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, and writes them to a file, in the concise DCF format.
dev | a pointer to a CANopen device. |
min | the minimum object index. |
max | the maximum object index. |
filename | a pointer to the name of the file. |
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 sub-object mapped into) an acyclic or event-driven Transmit-PDO.
dev | a pointer to a CANopen device. |
pind | the address at which to store a pointer to the indication function (can be NULL). |
pdata | the address at which to store a pointer to user-specified data (can be NULL). |
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-object mapped into) an acyclic or event-driven Transmit-PDO.
dev | a pointer to a CANopen device. |
ind | a pointer to the function to be invoked. |
data | a pointer to user-specified data (can be NULL). data is passed as the last parameter to ind. |
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 PDO and, if so, issues an indication for every valid, acylic or event-driven Transmit-PDO into which the sub-object is mapped by invoking the user-defined callback function set with co_dev_set_tpdo_event_ind().
At most one event is indicated for every matching TPDO.
dev | a pointer to a CANopen device. |
idx | the object index. |
subidx | the object sub-index. |