Lely core libraries
2.3.4
|
Go to the documentation of this file.
22 #ifndef LELY_CO_VAL_H_
23 #define LELY_CO_VAL_H_
31 #if !LELY_NO_CO_DCF || !LELY_NO_CO_OBJ_FILE
39 #define CO_BOOLEAN_INIT 0
42 #define CO_BOOLEAN_MIN 0
45 #define CO_BOOLEAN_MAX 1
48 #define CO_INTEGER8_INIT 0
51 #define CO_INTEGER8_MIN (-INT8_C(0x7f) - 1)
54 #define CO_INTEGER8_MAX INT8_C(0x7f)
57 #define CO_INTEGER16_INIT 0
60 #define CO_INTEGER16_MIN (-INT16_C(0x7fff) - 1)
63 #define CO_INTEGER16_MAX INT16_C(0x7fff)
66 #define CO_INTEGER32_INIT 0
69 #define CO_INTEGER32_MIN (-INT32_C(0x7fffffff) - 1)
72 #define CO_INTEGER32_MAX INT32_C(0x7fffffff)
75 #define CO_UNSIGNED8_INIT 0
78 #define CO_UNSIGNED8_MIN 0
81 #define CO_UNSIGNED8_MAX UINT8_C(0xff)
84 #define CO_UNSIGNED16_INIT 0
87 #define CO_UNSIGNED16_MIN 0
90 #define CO_UNSIGNED16_MAX UINT16_C(0xffff)
93 #define CO_UNSIGNED32_INIT 0
96 #define CO_UNSIGNED32_MIN 0
99 #define CO_UNSIGNED32_MAX UINT32_C(0xffffffff)
102 #define CO_REAL32_INIT 0
105 #define CO_REAL32_MIN (-FLT_MAX)
108 #define CO_REAL32_MAX FLT_MAX
111 #define CO_VISIBLE_STRING_INIT NULL
114 #define CO_VISIBLE_STRING_MIN CO_VISIBLE_STRING_INIT
117 #define CO_VISIBLE_STRING_MAX CO_VISIBLE_STRING_INIT
120 #define CO_OCTET_STRING_INIT NULL
123 #define CO_OCTET_STRING_MIN CO_OCTET_STRING_INIT
126 #define CO_OCTET_STRING_MAX CO_OCTET_STRING_INIT
129 #define CO_UNICODE_STRING_INIT NULL
132 #define CO_UNICODE_STRING_MIN CO_UNICODE_STRING_INIT
135 #define CO_UNICODE_STRING_MAX CO_UNICODE_STRING_INIT
138 #define CO_TIME_OF_DAY_INIT \
144 #define CO_TIME_OF_DAY_MIN \
150 #define CO_TIME_OF_DAY_MAX \
152 UINT32_C(0x0fffffff), UINT16_C(0xffff) \
156 #define CO_TIME_DIFF_INIT CO_TIME_OF_DAY_INIT
159 #define CO_TIME_DIFF_MIN CO_TIME_OF_DAY_MIN
162 #define CO_TIME_DIFF_MAX CO_TIME_OF_DAY_MAX
165 #define CO_DOMAIN_INIT NULL
168 #define CO_DOMAIN_MIN CO_DOMAIN_INIT
171 #define CO_DOMAIN_MAX CO_DOMAIN_INIT
174 #define CO_INTEGER24_INIT 0
177 #define CO_INTEGER24_MIN (-INT32_C(0x007fffff) - 1)
180 #define CO_INTEGER24_MAX INT32_C(0x007fffff)
183 #define CO_REAL64_INIT 0
186 #define CO_REAL64_MIN (-DBL_MAX)
189 #define CO_REAL64_MAX DBL_MAX
192 #define CO_INTEGER40_INIT 0
195 #define CO_INTEGER40_MIN (-INT64_C(0x0000007fffffffff) - 1)
198 #define CO_INTEGER40_MAX INT64_C(0x0000007fffffffff)
201 #define CO_INTEGER48_INIT 0
204 #define CO_INTEGER48_MIN (-INT64_C(0x00007fffffffffff) - 1)
207 #define CO_INTEGER48_MAX INT64_C(0x00007fffffffffff)
210 #define CO_INTEGER56_INIT 0
213 #define CO_INTEGER56_MIN (-INT64_C(0x007fffffffffffff) - 1)
216 #define CO_INTEGER56_MAX INT64_C(0x007fffffffffffff)
219 #define CO_INTEGER64_INIT 0
222 #define CO_INTEGER64_MIN (-INT64_C(0x7fffffffffffffff) - 1)
225 #define CO_INTEGER64_MAX INT64_C(0x7fffffffffffffff)
228 #define CO_UNSIGNED24_INIT 0
231 #define CO_UNSIGNED24_MIN 0
234 #define CO_UNSIGNED24_MAX UINT32_C(0x00ffffff)
237 #define CO_UNSIGNED40_INIT 0
240 #define CO_UNSIGNED40_MIN 0
243 #define CO_UNSIGNED40_MAX UINT64_C(0x000000ffffffffff)
246 #define CO_UNSIGNED48_INIT 0
249 #define CO_UNSIGNED48_MIN 0
252 #define CO_UNSIGNED48_MAX UINT64_C(0x0000ffffffffffff)
255 #define CO_UNSIGNED56_INIT 0
258 #define CO_UNSIGNED56_MIN 0
261 #define CO_UNSIGNED56_MAX UINT64_C(0x00ffffffffffffff)
264 #define CO_UNSIGNED64_INIT 0
267 #define CO_UNSIGNED64_MIN 0
270 #define CO_UNSIGNED64_MAX UINT64_C(0xffffffffffffffff)
274 #define LELY_CO_DEFINE_TYPE(a, b, c, d) co_##b##_t c;
275 #include <lely/co/def/type.def>
276 #undef LELY_CO_DEFINE_TYPE
287 #ifndef CO_ARRAY_CAPACITY
290 #define CO_ARRAY_CAPACITY 256
292 #define CO_ARRAY_CAPACITY 0
311 #define CO_ARRAY_INIT \
313 { CO_ARRAY_CAPACITY, 0 }, \
321 #endif // LELY_NO_MALLOC
323 #if __STDC_VERSION__ >= 199901L
330 #define CO_ARRAY_C ((void *)((struct co_array)CO_ARRAY_INIT).u.data)
333 #define _CO_ARRAY(...) __VA_ARGS__
340 #define CO_VISIBLE_STRING_NC(n, c) \
342 struct co_array_hdr hdr; \
344 char vs[MAX(n, sizeof(c))]; \
349 .capacity = MAX(n, sizeof(c)), \
350 .size = sizeof(c) - 1 \
357 #define CO_VISIBLE_STRING_C(c) CO_VISIBLE_STRING_NC(CO_ARRAY_CAPACITY, c)
364 #define CO_OCTET_STRING_NC(n, c) \
366 struct co_array_hdr hdr; \
368 uint_least8_t os[MAX(n, sizeof(c))]; \
373 .capacity = MAX(n, sizeof(c)), \
374 .size = sizeof(c) - 1 \
381 #define CO_OCTET_STRING_C(c) CO_OCTET_STRING_NC(CO_ARRAY_CAPACITY, c)
387 #define CO_UNICODE_STRING_NC(n, ...) \
388 _CO_UNICODE_STRING_NC(n, _CO_ARRAY(__VA_ARGS__))
391 #define _CO_UNICODE_STRING_NC(n, c) \
393 struct co_array_hdr hdr; \
395 char16_t us[MAX(ALIGN(n, sizeof(char16_t)), \
396 sizeof((char16_t[])c)) \
397 / sizeof(char16_t)]; \
402 .capacity = MAX(ALIGN(n, sizeof(char16_t)), \
403 sizeof((char16_t[])c)), \
404 .size = sizeof((char16_t[])c) - sizeof(char16_t) \
411 #define CO_UNICODE_STRING_C(...) \
412 _CO_UNICODE_STRING_NC(CO_ARRAY_CAPACITY, _CO_ARRAY(__VA_ARGS__))
418 #define CO_DOMAIN_NC(type, n, ...) \
419 _CO_DOMAIN_NC(type, n, _CO_ARRAY(__VA_ARGS__))
422 #define _CO_DOMAIN_NC(type, n, c) \
424 struct co_array_hdr hdr; \
426 type dom[MAX(ALIGN(n, sizeof(type)), sizeof((type[])c)) \
432 .capacity = MAX(ALIGN(n, sizeof(type)), \
433 sizeof((type[])c)), \
434 .size = sizeof((type[])c) \
444 #define CO_DOMAIN_C(type, ...) \
445 _CO_DOMAIN_NC(type, CO_ARRAY_CAPACITY, _CO_ARRAY(__VA_ARGS__))
447 #endif // __STDC_VERSION__ >= 199901L
551 int co_val_init_os(uint_least8_t **val,
const uint_least8_t *os,
size_t n);
607 static inline void co_val_init_array(
void *val,
struct co_array *array);
667 size_t co_val_make(co_unsigned16_t type,
void *val,
const void *ptr,
size_t n);
687 size_t co_val_copy(co_unsigned16_t type,
void *dst,
const void *src);
708 size_t co_val_move(co_unsigned16_t type,
void *dst,
void *src);
723 int co_val_cmp(co_unsigned16_t type,
const void *v1,
const void *v2);
745 size_t co_val_read(co_unsigned16_t type,
void *val,
const uint_least8_t *begin,
746 const uint_least8_t *end);
789 #endif // !LELY_NO_STDIO
809 co_unsigned16_t type,
void *val,
const void *ptr,
size_t n);
831 size_t co_val_write(co_unsigned16_t type,
const void *val, uint_least8_t *begin,
851 co_unsigned16_t type,
const void *val,
const char *
filename);
869 co_unsigned16_t type,
const void *val,
struct __fwbuf *buf);
891 size_t co_val_lex(co_unsigned16_t type,
void *val,
const char *begin,
892 const char *end,
struct floc *at);
912 size_t co_val_print(co_unsigned16_t type,
const void *val,
char **pbegin,
915 #endif // !LELY_NO_STDIO
919 co_val_init_array(
void *val,
struct co_array *array)
922 *(
char **)val = array ? array->u.data : NULL;
930 #endif // !LELY_CO_VAL_H_
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.
size_t co_val_copy(co_unsigned16_t type, void *dst, const void *src)
Copies one value to another.
int co_val_init_max(co_unsigned16_t type, void *val)
Initializes a value of the specified data type with its upper limit.
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.
int co_val_init_vs_n(char **val, const char *vs, size_t n)
Initializes an array of visible characters (CO_DEFTYPE_VISIBLE_STRING).
int co_val_init_min(co_unsigned16_t type, void *val)
Initializes a value of the specified data type with its lower limit.
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_move(co_unsigned16_t type, void *dst, void *src)
Moves one value to another.
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.
size_t size
The current size (in bytes).
A location in a text file.
int co_val_init_vs(char **val, const char *vs)
Initializes an array of visible characters (CO_DEFTYPE_VISIBLE_STRING).
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.
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.
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.
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.
#define CO_ARRAY_CAPACITY
The default capacity (in bytes) of a statically allocated CANopen array.
An read file buffer struct.
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.
size_t capacity
The total capacity (in bytes).
int co_val_init_us(char16_t **val, const char16_t *us)
Initializes an array of (16-bit) Unicode characters (CO_DEFTYPE_UNICODE_STRING).
An (atomic) write file buffer struct.
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).
int co_val_cmp(co_unsigned16_t type, const void *v1, const void *v2)
Compares two values of the specified data type.
A union of the CANopen static data types.
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.
int co_val_init_dom(void **val, const void *dom, size_t n)
Initializes an arbitrary large block of data (CO_DEFTYPE_DOMAIN).
int co_val_init(co_unsigned16_t type, void *val)
Initializes a value of the specified data type to zero.
const char * filename
The name of the file.
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.
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).
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.
The header directly preceding the bytes in a CANopen array.