Lely core libraries 2.3.4
|
This file is part of the CANopen library; it contains the implementation of the CANopen value functions. More...
#include "co.h"
#include <lely/co/sdo.h>
#include <lely/co/val.h>
#include <lely/libc/string.h>
#include <lely/libc/sys/types.h>
#include <lely/util/cmp.h>
#include <lely/util/diag.h>
#include <lely/util/endian.h>
#include <lely/util/frbuf.h>
#include <lely/util/fwbuf.h>
#include <lely/util/lex.h>
#include <lely/util/print.h>
#include <lely/util/ustring.h>
#include <assert.h>
#include <inttypes.h>
#include <stdlib.h>
#include <lely/co/def/basic.def>
#include <lely/co/def/time.def>
#include <lely/co/def/array.def>
Go to the source code of this file.
Functions | |
int | co_val_init (co_unsigned16_t type, void *val) |
Initializes a value of the specified data type to zero. More... | |
int | co_val_init_min (co_unsigned16_t type, void *val) |
Initializes a value of the specified data type with its lower limit. More... | |
int | co_val_init_max (co_unsigned16_t type, void *val) |
Initializes a value of the specified data type with its upper limit. More... | |
int | co_val_init_vs (char **val, const char *vs) |
Initializes an array of visible characters (CO_DEFTYPE_VISIBLE_STRING). More... | |
int | co_val_init_vs_n (char **val, const char *vs, size_t n) |
Initializes an array of visible characters (CO_DEFTYPE_VISIBLE_STRING). More... | |
int | co_val_init_os (uint_least8_t **val, const uint_least8_t *os, size_t n) |
Initializes an array of octets (CO_DEFTYPE_OCTET_STRING). More... | |
int | co_val_init_us (char16_t **val, const char16_t *us) |
Initializes an array of (16-bit) Unicode characters (CO_DEFTYPE_UNICODE_STRING). More... | |
int | co_val_init_us_n (char16_t **val, const char16_t *us, size_t n) |
Initializes an array of (16-bit) Unicode characters (CO_DEFTYPE_UNICODE_STRING). More... | |
int | co_val_init_dom (void **val, const void *dom, size_t n) |
Initializes an arbitrary large block of data (CO_DEFTYPE_DOMAIN). More... | |
void | co_val_fini (co_unsigned16_t type, void *val) |
Finalizes a value of the specified data type. More... | |
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. More... | |
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. More... | |
size_t | co_val_make (co_unsigned16_t type, void *val, const void *ptr, size_t n) |
Constructs a value of the specified data type. More... | |
size_t | co_val_copy (co_unsigned16_t type, void *dst, const void *src) |
Copies one value to another. More... | |
size_t | co_val_move (co_unsigned16_t type, void *dst, void *src) |
Moves one value to another. More... | |
int | co_val_cmp (co_unsigned16_t type, const void *v1, const void *v2) |
Compares two values of the specified data type. More... | |
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. More... | |
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. More... | |
size_t | co_val_read_frbuf (co_unsigned16_t type, void *val, frbuf_t *buf) |
Reads a value of the specified data type from the current position in a read file buffer. More... | |
co_unsigned32_t | co_val_read_sdo (co_unsigned16_t type, void *val, const void *ptr, size_t n) |
Reads a value of the specified data type from an SDO buffer. More... | |
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. More... | |
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. More... | |
size_t | co_val_write_fwbuf (co_unsigned16_t type, const void *val, fwbuf_t *buf) |
Writes a value of the specified data type to the current position in a write file buffer. More... | |
size_t | co_val_lex (co_unsigned16_t type, void *val, const char *begin, const char *end, struct floc *at) |
Lexes a value of the specified data type from a memory buffer. More... | |
size_t | co_val_print (co_unsigned16_t type, const void *val, char **pbegin, char *end) |
Prints a value of the specified data type to a memory buffer. More... | |
This file is part of the CANopen library; it contains the implementation of the CANopen value functions.
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 val.c.
int co_val_init | ( | co_unsigned16_t | type, |
void * | val | ||
) |
Initializes a value of the specified data type to zero.
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
val | the address of the value to be initialized. In the case of strings or domains, this MUST be the address of pointer. |
int co_val_init_min | ( | co_unsigned16_t | type, |
void * | val | ||
) |
Initializes a value of the specified data type with its lower limit.
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
val | the address of the value to be initialized. In the case of strings or domains, this MUST be the address of pointer, which will be set to NULL. |
int co_val_init_max | ( | co_unsigned16_t | type, |
void * | val | ||
) |
Initializes a value of the specified data type with its upper limit.
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
val | the address of the value to be initialized. In the case of strings or domains, this MUST be the address of pointer, which will be set to NULL. |
int co_val_init_vs | ( | char ** | val, |
const char * | vs | ||
) |
Initializes an array of visible characters (CO_DEFTYPE_VISIBLE_STRING).
val | the address of a pointer. On success, *val points to the first character in the string. |
vs | a pointer to the (null-terminated) string with which *val should be initialized (can be NULL). |
int co_val_init_vs_n | ( | char ** | val, |
const char * | vs, | ||
size_t | n | ||
) |
Initializes an array of visible characters (CO_DEFTYPE_VISIBLE_STRING).
val | the address of a pointer. On success, *val points to the first character in the string. |
vs | a pointer to the string with which *val should be initialized (can be NULL). |
n | the number of characters in the value to be created (excluding the terminating null byte) and the maximum number of characters to copy from vs (unless vs is NULL). |
int co_val_init_os | ( | uint_least8_t ** | val, |
const uint_least8_t * | os, | ||
size_t | n | ||
) |
Initializes an array of octets (CO_DEFTYPE_OCTET_STRING).
val | the address of a pointer. On success, *val points to the first octet in the string. |
os | a pointer to the array of octets with which *val should be initialized (can be NULL). |
n | the number of octets in the value to be created (and the number of octets at os unless os is NULL). |
int co_val_init_us | ( | char16_t ** | val, |
const char16_t * | us | ||
) |
Initializes an array of (16-bit) Unicode characters (CO_DEFTYPE_UNICODE_STRING).
val | the address of a pointer. On success, *val points to the first character in the string. |
us | a pointer to the (null-terminated) string with which *val should be initialized (can be NULL). |
int co_val_init_us_n | ( | char16_t ** | val, |
const char16_t * | us, | ||
size_t | n | ||
) |
Initializes an array of (16-bit) Unicode characters (CO_DEFTYPE_UNICODE_STRING).
val | the address of a pointer. On success, *val points to the first character in the string. |
us | a pointer to the string with which *val should be initialized (can be NULL). |
n | the number of (16-bit) Unicode characters in the value to be created (excluding the terminating null bytes) and the maximum number of characters to copy from us (unless us is NULL). |
int co_val_init_dom | ( | void ** | val, |
const void * | dom, | ||
size_t | n | ||
) |
Initializes an arbitrary large block of data (CO_DEFTYPE_DOMAIN).
val | the address of a pointer. On success, *val points to the first byte. |
dom | a pointer to the bytes with which *val should be initialized (can be NULL). |
n | the number of bytes in the value to be created (and the number of bytes at dom unless dom is NULL). |
void co_val_fini | ( | co_unsigned16_t | type, |
void * | val | ||
) |
Finalizes a value of the specified data type.
It is safe to invoke this function multiple times on the same value.
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
val | the address of the value to be finalized (can be NULL). In the case of strings or domains, this MUST be the address of pointer. |
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.
In the case of strings or domains, this is the address of the first byte in the array.
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
val | the address of the value (can be NULL). In the case of strings or domains, this MUST be the address of pointer. |
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.
In the case of strings or domains, this is the number of bytes in the array.
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
val | the address of the value (can be NULL). In the case of strings or domains, this MUST be the address of pointer. |
size_t co_val_make | ( | co_unsigned16_t | type, |
void * | val, | ||
const void * | ptr, | ||
size_t | n | ||
) |
Constructs a value of the specified data type.
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
val | the address of the value to be constructed. In the case of strings or domains, this MUST be the address of pointer. Note that this value is not finalized before the copy is performed. |
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_val_copy | ( | co_unsigned16_t | type, |
void * | dst, | ||
const void * | src | ||
) |
Copies one value to another.
In case of strings or domains, this function performs a deep copy (i.e, it copies the array).
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
dst | a pointer to the destination value. In the case of strings or domains, this MUST be the address of pointer. Note that this value is not finalized before the copy is performed. |
src | a pointer to the source value. In the case of strings or domains, this MUST be the address of pointer. |
co_val_sizeof(type, src)
), or 0 on error. In the latter case, the error number can be obtained with get_errc().size_t co_val_move | ( | co_unsigned16_t | type, |
void * | dst, | ||
void * | src | ||
) |
Moves one value to another.
In case of strings or domains, this function performs a shallow copy (i.e., it copies the pointer to the array).
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
dst | a pointer to the destination value. In the case of strings or domains, this MUST be the address of pointer. Note that this value is not finalized before the move is performed. |
src | a pointer to the source value. In the case of strings or domains, this MUST be the address of pointer (which is set to NULL on exit). |
co_type_sizeof(type)
), or 0 on error. In the latter case, the error number can be obtained with get_errc().int co_val_cmp | ( | co_unsigned16_t | type, |
const void * | v1, | ||
const void * | v2 | ||
) |
Compares two values of the specified data type.
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
v1 | a pointer to the first value. In case of string or domains, this MUST be the address of pointer. |
v2 | a pointer to the second value. In case of string or domains, this MUST be the address of pointer. |
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.
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
val | the address at which to store the value. On success, if val is not NULL, *val contains the read value. On error, *val is left untouched. In the case of strings or domains, val MUST be the address of a pointer. Note that this value is not finalized before the read value is stored. |
begin | a pointer to the start of the buffer. |
end | a pointer to one past the last byte in the buffer. At most end - begin bytes are read. For strings and domains, all bytes are considered to be part of the value. |
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.
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
val | the address at which to store the value. On success, if val is not NULL, *val contains the read value. In the case of strings or domains, val MUST be the address of a pointer. Note that this value is not finalized before the read value is stored. |
filename | a pointer to the name of the file. |
size_t co_val_read_frbuf | ( | co_unsigned16_t | type, |
void * | val, | ||
struct __frbuf * | buf | ||
) |
Reads a value of the specified data type from the current position in a read file buffer.
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
val | the address at which to store the value. On success, if val is not NULL, *val contains the read value. In the case of strings or domains, val MUST be the address of a pointer. Note that this value is not finalized before the read value is stored. |
buf | a pointer to a read file buffer. |
co_unsigned32_t co_val_read_sdo | ( | co_unsigned16_t | type, |
void * | val, | ||
const void * | ptr, | ||
size_t | n | ||
) |
Reads a value of the specified data type from an SDO buffer.
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
val | the address at which to store the value. On success, if val is not NULL, *val contains the read value. On error, *val is left untouched. In the case of strings or domains, val MUST be the address of pointer. Note that this value is not finalized before the read value is stored. |
ptr | a pointer to the bytes in the SDO. |
n | the number of bytes at ptr. |
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.
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
val | the address of the value to be written. In case of strings or domains, this MUST be the address of pointer. |
begin | a pointer to the start of the buffer. If begin is NULL, nothing is written. |
end | a pointer to one past the last byte in 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. |
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.
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
val | the address of the value to be written. In case of strings or domains, this MUST be the address of pointer. |
filename | a pointer to the name of the file. |
size_t co_val_write_fwbuf | ( | co_unsigned16_t | type, |
const void * | val, | ||
struct __fwbuf * | buf | ||
) |
Writes a value of the specified data type to the current position in a write file buffer.
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
val | the address of the value to be written. In case of strings or domains, this MUST be the address of pointer. |
buf | a pointer to a write file buffer. |
size_t co_val_lex | ( | co_unsigned16_t | type, |
void * | val, | ||
const char * | begin, | ||
const char * | end, | ||
struct floc * | at | ||
) |
Lexes a value of the specified data type from a memory buffer.
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
val | the address at which to store the value. On success, if val is not NULL, *val contains the lexed value. On error, *val is left untouched. In the case of strings or domains, val MUST be the address of pointer. Note that this value is not finalized before the parsed value is stored. |
begin | a pointer to the start of the buffer. |
end | a pointer to one past the last character in the buffer (can be NULL if the buffer is null-terminated). |
at | an optional pointer to the file location of begin (used for diagnostic purposes). On success, if at != NULL , *at points to one past the last character lexed. On error, *at is left untouched. |
size_t co_val_print | ( | co_unsigned16_t | type, |
const void * | val, | ||
char ** | pbegin, | ||
char * | end | ||
) |
Prints a value of the specified data type to a memory buffer.
type | the data type (in the range [1..27]). This MUST be the object index of one of the static data types. |
val | the address of the value to be written. In case of string or domains, this MUST be the address of pointer. |
pbegin | the address of a pointer to the start of the buffer. If pbegin or *pbegin is NULL, nothing is written; Otherwise, on exit, *pbegin points to one past the last character written. |
end | a pointer to one past the last character in the buffer. If end is not NULL, at most end - *pbegin characters are written, and the output may be truncated. |