Lely core libraries 1.9.2
val.h
Go to the documentation of this file.
1
22#ifndef LELY_CO_VAL_H_
23#define LELY_CO_VAL_H_
24
25#include <lely/co/type.h>
26
27#include <float.h>
28#include <stddef.h>
29
31#define CO_BOOLEAN_MIN 0
32
34#define CO_BOOLEAN_MAX 1
35
37#define CO_INTEGER8_MIN INT8_MIN
38
40#define CO_INTEGER8_MAX INT8_MAX
41
43#define CO_INTEGER16_MIN INT16_MIN
44
46#define CO_INTEGER16_MAX INT16_MAX
47
49#define CO_INTEGER32_MIN INT32_MIN
50
52#define CO_INTEGER32_MAX INT32_MAX
53
55#define CO_UNSIGNED8_MIN 0
56
58#define CO_UNSIGNED8_MAX UINT8_MAX
59
61#define CO_UNSIGNED16_MIN 0
62
64#define CO_UNSIGNED16_MAX UINT16_MAX
65
67#define CO_UNSIGNED32_MIN 0
68
70#define CO_UNSIGNED32_MAX UINT32_MAX
71
73#define CO_REAL32_MIN (-FLT_MAX)
74
76#define CO_REAL32_MAX FLT_MAX
77
79#define CO_TIME_OF_DAY_MIN \
80 { \
81 0, 0 \
82 }
83
85#define CO_TIME_OF_DAY_MAX \
86 { \
87 UINT32_C(0x0fffffff), UINT16_MAX \
88 }
89
91#define CO_TIME_DIFF_MIN CO_TIME_OF_DAY_MIN
92
94#define CO_TIME_DIFF_MAX CO_TIME_OF_DAY_MAX
95
97#define CO_INTEGER24_MIN (-INT32_C(0x00800000))
98
100#define CO_INTEGER24_MAX INT32_C(0x007fffff)
101
103#define CO_REAL64_MIN (-DBL_MAX)
104
106#define CO_REAL64_MAX DBL_MAX
107
109#define CO_INTEGER40_MIN (-INT64_C(0x0000008000000000))
110
112#define CO_INTEGER40_MAX INT64_C(0x0000007fffffffff)
113
115#define CO_INTEGER48_MIN (-INT64_C(0x0000800000000000))
116
118#define CO_INTEGER48_MAX INT64_C(0x00007fffffffffff)
119
121#define CO_INTEGER56_MIN (-INT64_C(0x0080000000000000))
122
124#define CO_INTEGER56_MAX INT64_C(0x007fffffffffffff)
125
127#define CO_INTEGER64_MIN INT64_MIN
128
130#define CO_INTEGER64_MAX INT64_MAX
131
133#define CO_UNSIGNED24_MIN 0
134
136#define CO_UNSIGNED24_MAX UINT32_C(0x00ffffff)
137
139#define CO_UNSIGNED40_MIN 0
140
142#define CO_UNSIGNED40_MAX UINT64_C(0x000000ffffffffff)
143
145#define CO_UNSIGNED48_MIN 0
146
148#define CO_UNSIGNED48_MAX UINT64_C(0x0000ffffffffffff)
149
151#define CO_UNSIGNED56_MIN 0
152
154#define CO_UNSIGNED56_MAX UINT64_C(0x00ffffffffffffff)
155
157#define CO_UNSIGNED64_MIN 0
158
160#define CO_UNSIGNED64_MAX UINT64_MAX
161
163union co_val {
164#define LELY_CO_DEFINE_TYPE(a, b, c, d) co_##b##_t c;
165#include <lely/co/def/type.def>
166#undef LELY_CO_DEFINE_TYPE
167};
168
169#if __STDC_VERSION__ >= 199901L
170
171#define _CO_ARRAY(...) __VA_ARGS__
172
174#define CO_VISIBLE_STRING_C(c) \
175 (((struct { \
176 size_t size; \
177 union { \
178 union co_val val; \
179 char vs[sizeof(c)]; \
180 } u; \
181 }){ .size = sizeof(c) - 1, .u = { .vs = c } }) \
182 .u.vs)
183
185#define CO_OCTET_STRING_C(c) \
186 (((struct { \
187 size_t size; \
188 union { \
189 union co_val val; \
190 uint8_t os[sizeof(c)]; \
191 } u; \
192 }){ .size = sizeof(c) - 1, .u = { .os = c } }) \
193 .u.os)
194
196#define CO_UNICODE_STRING_C(...) _CO_UNICODE_STRING_C(_CO_ARRAY(__VA_ARGS__))
197
198// clang-format off
199#define _CO_UNICODE_STRING_C(c) \
200 (((struct { \
201 size_t size; \
202 union { \
203 union co_val val; \
204 char16_t us[sizeof((char16_t[])c) / sizeof(char16_t)]; \
205 } u; \
206 }){ .size = sizeof((char16_t[])c) - sizeof(char16_t), \
207 .u = { .us = c } }) \
208 .u.us)
209// clang-format on
210
215#define CO_DOMAIN_C(type, ...) _CO_DOMAIN_C(type, _CO_ARRAY(__VA_ARGS__))
216
217#define _CO_DOMAIN_C(type, c) \
218 (((struct { \
219 size_t size; \
220 union { \
221 union co_val val; \
222 type dom[sizeof((type[])c) / sizeof(type)]; \
223 } u; \
224 }){ .size = sizeof((type[])c), .u = { .dom = c } }) \
225 .u.dom)
226
227#endif // __STDC_VERSION__ >= 199901L
228
229// The file location struct from <lely/util/diag.h>.
230struct floc;
231
232#ifdef __cplusplus
233extern "C" {
234#endif
235
249int co_val_init(co_unsigned16_t type, void *val);
250
265int co_val_init_min(co_unsigned16_t type, void *val);
266
281int co_val_init_max(co_unsigned16_t type, void *val);
282
296int co_val_init_vs(char **val, const char *vs);
297
314int co_val_init_vs_n(char **val, const char *vs, size_t n);
315
331int co_val_init_os(uint8_t **val, const uint8_t *os, size_t n);
332
347int co_val_init_us(char16_t **val, const char16_t *us);
348
367int co_val_init_us_n(char16_t **val, const char16_t *us, size_t n);
368
384int co_val_init_dom(void **val, const void *dom, size_t n);
385
397void co_val_fini(co_unsigned16_t type, void *val);
398
411const void *co_val_addressof(co_unsigned16_t type, const void *val);
412
424size_t co_val_sizeof(co_unsigned16_t type, const void *val);
425
442size_t co_val_make(co_unsigned16_t type, void *val, const void *ptr, size_t n);
443
462size_t co_val_copy(co_unsigned16_t type, void *dst, const void *src);
463
483size_t co_val_move(co_unsigned16_t type, void *dst, void *src);
484
498int co_val_cmp(co_unsigned16_t type, const void *v1, const void *v2);
499
520size_t co_val_read(co_unsigned16_t type, void *val, const uint8_t *begin,
521 const uint8_t *end);
522
540co_unsigned32_t co_val_read_sdo(
541 co_unsigned16_t type, void *val, const void *ptr, size_t n);
542
562size_t co_val_write(co_unsigned16_t type, const void *val, uint8_t *begin,
563 uint8_t *end);
564
585size_t co_val_lex(co_unsigned16_t type, void *val, const char *begin,
586 const char *end, struct floc *at);
587
606size_t co_val_print(co_unsigned16_t type, const void *val, char **pbegin,
607 char *end);
608
609#ifdef __cplusplus
610}
611#endif
612
613#endif // !LELY_CO_VAL_H_
This header file is part of the utilities library; it contains the IEEE 754 floating-point format typ...
This header file is part of the C11 and POSIX compatibility library; it includes <stddef....
A location in a text file.
Definition: diag.h:31
This header file is part of the CANopen library; it contains the CANopen type definitions.
A union of the CANopen static data types.
Definition: val.h:163
size_t co_val_write(co_unsigned16_t type, const void *val, uint8_t *begin, uint8_t *end)
Writes a value of the specified data type to a memory buffer.
Definition: val.c:718
int co_val_init(co_unsigned16_t type, void *val)
Initializes a value of the specified data type to zero.
Definition: val.c:120
size_t co_val_move(co_unsigned16_t type, void *dst, void *src)
Moves one value to another.
Definition: val.c:371
int co_val_init_os(uint8_t **val, const uint8_t *os, size_t n)
Initializes an array of octets (CO_DEFTYPE_OCTET_STRING).
Definition: val.c:203
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.
Definition: val.c:284
int co_val_init_dom(void **val, const void *dom, size_t n)
Initializes an arbitrary large block of data (CO_DEFTYPE_DOMAIN).
Definition: val.c:254
size_t co_val_read(co_unsigned16_t type, void *val, const uint8_t *begin, const uint8_t *end)
Reads a value of the specified data type from a memory buffer.
Definition: val.c:470
size_t co_val_copy(co_unsigned16_t type, void *dst, const void *src)
Copies one value to another.
Definition: val.c:333
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.
Definition: val.c:293
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).
Definition: val.c:235
int co_val_init_vs_n(char **val, const char *vs, size_t n)
Initializes an array of visible characters (CO_DEFTYPE_VISIBLE_STRING).
Definition: val.c:184
int co_val_init_us(char16_t **val, const char16_t *us)
Initializes an array of (16-bit) Unicode characters (CO_DEFTYPE_UNICODE_STRING).
Definition: val.c:222
int co_val_cmp(co_unsigned16_t type, const void *v1, const void *v2)
Compares two values of the specified data type.
Definition: val.c:386
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.
Definition: val.c:698
int co_val_init_min(co_unsigned16_t type, void *val)
Initializes a value of the specified data type with its lower limit.
Definition: val.c:137
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.
Definition: val.c:1314
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.
Definition: val.c:306
void co_val_fini(co_unsigned16_t type, void *val)
Finalizes a value of the specified data type.
Definition: val.c:273
int co_val_init_vs(char **val, const char *vs)
Initializes an array of visible characters (CO_DEFTYPE_VISIBLE_STRING).
Definition: val.c:171
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.
Definition: val.c:869
int co_val_init_max(co_unsigned16_t type, void *val)
Initializes a value of the specified data type with its upper limit.
Definition: val.c:154