26 #ifndef LELY_NO_CO_SDEV 44 static int snprintf_c99_sobj(
char *s,
size_t n,
const co_obj_t *obj);
45 static int snprintf_c99_ssub(
char *s,
size_t n,
const co_sub_t *sub);
46 static int snprintf_c99_sval(
47 char *s,
size_t n, co_unsigned16_t type,
const void *val);
48 static int snprintf_c99_esc(
char *s,
size_t n,
const char *esc);
51 __co_dev_init_from_sdev(
struct __co_dev *dev,
const struct co_sdev *sdev)
67 if (
__unlikely(co_sdev_load(sdev, dev) == -1)) {
93 if (
__unlikely(!__co_dev_init_from_sdev(dev, sdev))) {
121 r = snprintf(s, n,
"{\n\t.id = 0x%02x,\n",
co_dev_get_id(dev));
124 goto error_print_dev;
127 r =
MIN((
size_t)r, n);
133 r = snprintf(s, n,
"\t.name = CO_SDEV_STRING(\"");
136 goto error_print_dev;
139 r =
MIN((
size_t)r, n);
142 r = snprintf_c99_esc(s, n,
name);
145 goto error_print_dev;
148 r =
MIN((
size_t)r, n);
151 r = snprintf(s, n,
"\"),\n");
153 r = snprintf(s, n,
"\t.name = NULL,\n");
157 goto error_print_dev;
160 r =
MIN((
size_t)r, n);
166 r = snprintf(s, n,
"\t.vendor_name = CO_SDEV_STRING(\"");
169 goto error_print_dev;
172 r =
MIN((
size_t)r, n);
175 r = snprintf_c99_esc(s, n,
name);
178 goto error_print_dev;
181 r =
MIN((
size_t)r, n);
184 r = snprintf(s, n,
"\"),\n");
186 r = snprintf(s, n,
"\t.vendor_name = NULL,\n");
190 goto error_print_dev;
193 r =
MIN((
size_t)r, n);
197 r = snprintf(s, n,
"\t.vendor_id = 0x%08" PRIx32
",\n",
201 goto error_print_dev;
204 r =
MIN((
size_t)r, n);
210 r = snprintf(s, n,
"\t.product_name = CO_SDEV_STRING(\"");
213 goto error_print_dev;
216 r =
MIN((
size_t)r, n);
219 r = snprintf_c99_esc(s, n,
name);
222 goto error_print_dev;
225 r =
MIN((
size_t)r, n);
228 r = snprintf(s, n,
"\"),\n");
230 r = snprintf(s, n,
"\t.product_name = NULL,\n");
234 goto error_print_dev;
237 r =
MIN((
size_t)r, n);
242 "\t.product_code = 0x%08" PRIx32
243 ",\n\t.revision = 0x%08" PRIx32
",\n",
247 goto error_print_dev;
250 r =
MIN((
size_t)r, n);
256 r = snprintf(s, n,
"\t.order_code = CO_SDEV_STRING(\"");
259 goto error_print_dev;
262 r =
MIN((
size_t)r, n);
265 r = snprintf_c99_esc(s, n,
name);
268 goto error_print_dev;
271 r =
MIN((
size_t)r, n);
274 r = snprintf(s, n,
"\"),\n");
276 r = snprintf(s, n,
"\t.order_code = NULL,\n");
280 goto error_print_dev;
283 r =
MIN((
size_t)r, n);
287 r = snprintf(s, n,
"\t.baud = 0");
290 goto error_print_dev;
293 r =
MIN((
size_t)r, n);
297 #define LELY_CO_DEFINE_BAUD(x) \ 298 if (baud & CO_BAUD_##x) { \ 299 r = snprintf(s, n, "\n\t\t| CO_BAUD_" #x); \ 300 if (__unlikely(r < 0)) { \ 302 goto error_print_dev; \ 305 r = MIN((size_t)r, n); \ 310 LELY_CO_DEFINE_BAUD(1000)
311 LELY_CO_DEFINE_BAUD(800)
312 LELY_CO_DEFINE_BAUD(500)
313 LELY_CO_DEFINE_BAUD(250)
314 LELY_CO_DEFINE_BAUD(125)
315 LELY_CO_DEFINE_BAUD(50)
316 LELY_CO_DEFINE_BAUD(20)
317 LELY_CO_DEFINE_BAUD(10)
318 LELY_CO_DEFINE_BAUD(AUTO)
320 #undef LELY_CO_DEFINE_BAUD 323 ",\n\t.rate = %d,\n\t.lss = %d,\n\t.dummy = 0x%08" PRIx32
329 goto error_print_dev;
332 r =
MIN((
size_t)r, n);
337 co_unsigned16_t *idx = malloc(maxidx *
sizeof(co_unsigned16_t));
340 goto error_malloc_idx;
344 r = snprintf(s, n,
"\t.nobj = %d,\n\t.objs = (const struct co_sobj[]){",
348 goto error_print_obj;
351 r =
MIN((
size_t)r, n);
355 for (
size_t i = 0; i < maxidx; i++) {
356 r = snprintf(s, n, i ?
", {\n" :
"{\n");
359 goto error_print_obj;
362 r =
MIN((
size_t)r, n);
368 goto error_print_obj;
371 r =
MIN((
size_t)r, n);
374 r = snprintf(s, n,
"\t}");
377 goto error_print_obj;
380 r =
MIN((
size_t)r, n);
385 r = snprintf(s, n,
"}\n}");
388 goto error_print_obj;
411 char *s = malloc(n + 1);
457 for (
size_t i = 0; i < sdev->
nobj; i++) {
468 if (
__unlikely(co_sobj_load(sobj, obj) == -1))
481 #ifndef LELY_NO_CO_OBJ_NAME 489 for (
size_t i = 0; i < sobj->
nsub; i++) {
500 if (
__unlikely(co_ssub_load(ssub, sub) == -1))
513 #ifndef LELY_NO_CO_OBJ_NAME 524 #ifndef LELY_NO_CO_OBJ_LIMITS 553 snprintf_c99_sobj(
char *s,
size_t n,
const co_obj_t *obj)
563 #ifndef LELY_NO_CO_OBJ_NAME 566 r = snprintf(s, n,
"\t\t.name = CO_SDEV_STRING(\"");
570 r =
MIN((
size_t)r, n);
573 r = snprintf_c99_esc(s, n,
name);
577 r =
MIN((
size_t)r, n);
580 r = snprintf(s, n,
"\"),\n");
583 r = snprintf(s, n,
"\t\t.name = NULL,\n");
584 #ifndef LELY_NO_CO_OBJ_NAME 590 r =
MIN((
size_t)r, n);
594 r = snprintf(s, n,
"\t\t.idx = 0x%04x,\n\t\t.code = ",
599 r =
MIN((
size_t)r, n);
605 case CO_OBJECT_NULL: r = snprintf(s, n,
"CO_OBJECT_NULL,\n");
break;
608 r = snprintf(s, n,
"CO_OBJECT_DEFTYPE,\n");
611 r = snprintf(s, n,
"CO_OBJECT_DEFSTRUCT,\n");
613 case CO_OBJECT_VAR: r = snprintf(s, n,
"CO_OBJECT_VAR,\n");
break;
616 default: r = snprintf(s, n,
"0x%02x,\n", code);
break;
621 r =
MIN((
size_t)r, n);
625 co_unsigned8_t
subidx[0xff];
629 "\t\t.nsub = %d,\n\t\t.subs = (const struct co_ssub[]){",
634 r =
MIN((
size_t)r, n);
638 for (
size_t i = 0; i < maxsubidx; i++) {
639 r = snprintf(s, n, i ?
", {\n" :
"{\n");
643 r =
MIN((
size_t)r, n);
650 r =
MIN((
size_t)r, n);
653 r = snprintf(s, n,
"\t\t}");
657 r =
MIN((
size_t)r, n);
662 r = snprintf(s, n,
"}\n");
671 snprintf_c99_ssub(
char *s,
size_t n,
const co_sub_t *sub)
681 #ifndef LELY_NO_CO_OBJ_NAME 684 r = snprintf(s, n,
"\t\t\t.name = CO_SDEV_STRING(\"");
688 r =
MIN((
size_t)r, n);
691 r = snprintf_c99_esc(s, n,
name);
695 r =
MIN((
size_t)r, n);
698 r = snprintf(s, n,
"\"),\n");
701 r = snprintf(s, n,
"\t\t\t.name = NULL,\n");
702 #ifndef LELY_NO_CO_OBJ_NAME 708 r =
MIN((
size_t)r, n);
712 r = snprintf(s, n,
"\t\t\t.subidx = 0x%02x,\n\t\t\t.type = ",
717 r =
MIN((
size_t)r, n);
723 #define LELY_CO_DEFINE_TYPE(a, b, c, d) \ 724 case CO_DEFTYPE_##a: \ 725 r = snprintf(s, n, "CO_DEFTYPE_" #a ",\n"); \ 727 #include <lely/co/def/type.def> 728 #undef LELY_CO_DEFINE_TYPE 729 default: r = snprintf(s, n,
"0x%04x,\n",
type);
break;
734 r =
MIN((
size_t)r, n);
738 r = snprintf(s, n,
"\t\t\t.min = ");
742 r =
MIN((
size_t)r, n);
745 #ifndef LELY_NO_CO_OBJ_LIMITS 750 r = snprintf_c99_sval(s, n, type, &min);
756 r =
MIN((
size_t)r, n);
760 r = snprintf(s, n,
",\n\t\t\t.max = ");
764 r =
MIN((
size_t)r, n);
767 #ifndef LELY_NO_CO_OBJ_LIMITS 772 r = snprintf_c99_sval(s, n, type, &max);
778 r =
MIN((
size_t)r, n);
782 r = snprintf(s, n,
",\n\t\t\t.def = ");
786 r =
MIN((
size_t)r, n);
793 r =
MIN((
size_t)r, n);
797 r = snprintf(s, n,
",\n\t\t\t.val = ");
801 r =
MIN((
size_t)r, n);
804 #ifndef LELY_NO_CO_OBJ_FILE 819 r =
MIN((
size_t)r, n);
823 r = snprintf(s, n,
",\n\t\t\t.access = ");
827 r =
MIN((
size_t)r, n);
832 case CO_ACCESS_RO: r = snprintf(s, n,
"CO_ACCESS_RO,\n");
break;
833 case CO_ACCESS_WO: r = snprintf(s, n,
"CO_ACCESS_WO,\n");
break;
834 case CO_ACCESS_RW: r = snprintf(s, n,
"CO_ACCESS_RW,\n");
break;
835 case CO_ACCESS_RWR: r = snprintf(s, n,
"CO_ACCESS_RWR,\n");
break;
836 case CO_ACCESS_RWW: r = snprintf(s, n,
"CO_ACCESS_RWW,\n");
break;
838 default: r = snprintf(s, n,
"0x%x,\n", access);
break;
843 r =
MIN((
size_t)r, n);
847 r = snprintf(s, n,
"\t\t\t.pdo_mapping = %d,\n",
852 r =
MIN((
size_t)r, n);
856 r = snprintf(s, n,
"\t\t\t.flags = 0\n");
860 r =
MIN((
size_t)r, n);
864 #define LELY_CO_DEFINE_FLAGS(x) \ 865 if (flags & CO_OBJ_FLAGS_##x) { \ 866 r = snprintf(s, n, "\t\t\t\t| CO_OBJ_FLAGS_" #x "\n"); \ 867 if (__unlikely(r < 0)) \ 870 r = MIN((size_t)r, n); \ 875 LELY_CO_DEFINE_FLAGS(READ)
876 LELY_CO_DEFINE_FLAGS(WRITE)
877 #ifndef LELY_NO_CO_OBJ_FILE 878 LELY_CO_DEFINE_FLAGS(UPLOAD_FILE)
879 LELY_CO_DEFINE_FLAGS(DOWNLOAD_FILE)
881 LELY_CO_DEFINE_FLAGS(MIN_NODEID)
882 LELY_CO_DEFINE_FLAGS(MAX_NODEID)
883 LELY_CO_DEFINE_FLAGS(DEF_NODEID)
884 LELY_CO_DEFINE_FLAGS(VAL_NODEID)
886 #undef LELY_CO_DEFINE_FLAGS 892 snprintf_c99_sval(
char *s,
size_t n, co_unsigned16_t type,
const void *val)
902 const union co_val *u = val;
905 r = snprintf(s, n,
"{ .b = %d }", !!u->b);
909 r = snprintf(s, n,
"{ .i8 = CO_INTEGER8_MIN }");
911 r = snprintf(s, n,
"{ .i8 = CO_INTEGER8_MAX }");
913 r = snprintf(s, n,
"{ .i8 = %" PRIi8
" }", u->i8);
918 r = snprintf(s, n,
"{ .i16 = CO_INTEGER16_MIN }");
920 r = snprintf(s, n,
"{ .i16 = CO_INTEGER16_MAX }");
922 r = snprintf(s, n,
"{ .i16 = %" PRIi16
" }", u->i16);
927 r = snprintf(s, n,
"{ .i32 = CO_INTEGER32_MIN }");
929 r = snprintf(s, n,
"{ .i32 = CO_INTEGER32_MAX }");
931 r = snprintf(s, n,
"{ .i32 = %" PRIi32
"l }", u->i32);
936 r = snprintf(s, n,
"{ .u8 = CO_UNSIGNED8_MIN }");
938 r = snprintf(s, n,
"{ .u8 = CO_UNSIGNED8_MAX }");
940 r = snprintf(s, n,
"{ .u8 = 0x%02" PRIx8
" }", u->u8);
945 r = snprintf(s, n,
"{ .u16 = CO_UNSIGNED16_MIN }");
947 r = snprintf(s, n,
"{ .u16 = CO_UNSIGNED16_MAX }");
949 r = snprintf(s, n,
"{ .u16 = 0x%04" PRIx16
"u }",
955 r = snprintf(s, n,
"{ .u32 = CO_UNSIGNED32_MIN }");
957 r = snprintf(s, n,
"{ .u32 = CO_UNSIGNED32_MAX }");
959 r = snprintf(s, n,
"{ .u32 = 0x%08" PRIx32
"lu }",
965 r = snprintf(s, n,
"{ .r32 = CO_REAL32_MIN }");
967 r = snprintf(s, n,
"{ .r32 = CO_REAL32_MAX }");
969 r = snprintf(s, n,
"{ .r32 = %.*g }", DECIMAL_DIG,
975 r = snprintf(s, n,
"{ .vs = CO_VISIBLE_STRING_C(\"");
979 r =
MIN((
size_t)r, n);
982 r = snprintf_c99_esc(s, n, u->vs);
986 r =
MIN((
size_t)r, n);
989 r = snprintf(s, n,
"\") }");
991 r = snprintf(s, n,
"{ .vs = NULL }");
997 "{ .os = CO_OCTET_STRING_C(\n\t\t\t\t\"");
1001 r =
MIN((
size_t)r, n);
1005 for (
size_t i = 0; i < size; i++) {
1007 r = snprintf(s, n, i && !(i % 8)
1008 ?
"\"\n\t\t\t\t\"\\x%02x" 1015 r =
MIN((
size_t)r, n);
1019 r = snprintf(s, n,
"\"\n\t\t\t) }");
1021 r = snprintf(s, n,
"{ .vs = NULL }");
1027 "{ .us = CO_UNICODE_STRING_C({\n\t\t\t\t");
1031 r =
MIN((
size_t)r, n);
1035 for (
size_t i = 0; i < size; i++) {
1037 r = snprintf(s, n, i && !(i % 4)
1038 ?
",\n\t\t\t\t0x%04x" 1039 : (i ?
", 0x%04x" :
"0x%04x"),
1045 r =
MIN((
size_t)r, n);
1049 r = snprintf(s, n,
"\n\t\t\t}) }");
1051 r = snprintf(s, n,
"{ .us = NULL }");
1057 ".ms = 0x%08" PRIx32
", " 1058 ".days = 0x%04" PRIx16
" " 1060 u->t.ms, u->t.days);
1065 ".ms = 0x%08" PRIx32
", " 1066 ".days = 0x%04" PRIx16
" " 1068 u->td.ms, u->td.days);
1073 "{ .dom = CO_DOMAIN_C(co_unsigned8_t, {\n\t\t\t\t");
1077 r =
MIN((
size_t)r, n);
1080 const co_unsigned8_t *bp = u->dom;
1082 for (
size_t i = 0; i < size; i++) {
1084 r = snprintf(s, n, i && !(i % 8)
1085 ?
",\n\t\t\t\t0x%02x" 1086 : (i ?
", 0x%02x" :
"0x%02x"),
1092 r =
MIN((
size_t)r, n);
1096 r = snprintf(s, n,
"\n\t\t\t}) }");
1098 r = snprintf(s, n,
"{ .dom = NULL }");
1103 r = snprintf(s, n,
"{ .i24 = CO_INTEGER24_MIN }");
1105 r = snprintf(s, n,
"{ .i24 = CO_INTEGER24_MAX }");
1107 r = snprintf(s, n,
"{ .i24 = %" PRIi32
"l }", u->i24);
1112 r = snprintf(s, n,
"{ .r64 = CO_REAL64_MIN }");
1114 r = snprintf(s, n,
"{ .r64 = CO_REAL64_MAX }");
1116 r = snprintf(s, n,
"{ .r64 = %.*g }", DECIMAL_DIG,
1122 r = snprintf(s, n,
"{ CO_INTEGER40_MIN }");
1124 r = snprintf(s, n,
"{ CO_INTEGER40_MAX }");
1126 r = snprintf(s, n,
"{ .i40 = %" PRIi64
"ll }", u->i40);
1131 r = snprintf(s, n,
"{ .i48 = CO_INTEGER48_MIN }");
1133 r = snprintf(s, n,
"{ .i48 = CO_INTEGER48_MAX }");
1135 r = snprintf(s, n,
"{ .i48 = %" PRIi64
"ll }", u->i48);
1140 r = snprintf(s, n,
"{ .i56 = CO_INTEGER56_MIN }");
1142 r = snprintf(s, n,
"{ .i56 = CO_INTEGER56_MAX }");
1144 r = snprintf(s, n,
"{ .i56 = %" PRIi64
"ll }", u->i56);
1149 r = snprintf(s, n,
"{ .i64 = CO_INTEGER64_MIN }");
1151 r = snprintf(s, n,
"{ .i64 = CO_INTEGER64_MAX }");
1153 r = snprintf(s, n,
"{ .i64 = %" PRIi64
"ll }", u->i64);
1158 r = snprintf(s, n,
"{ .u24 = CO_UNSIGNED24_MIN }");
1160 r = snprintf(s, n,
"{ .u24 = CO_UNSIGNED24_MAX }");
1162 r = snprintf(s, n,
"{ .u24 = 0x%06" PRIx32
"lu }",
1168 r = snprintf(s, n,
"{ .u40 = CO_UNSIGNED40_MIN }");
1170 r = snprintf(s, n,
"{ .u40 = CO_UNSIGNED40_MAX }");
1172 r = snprintf(s, n,
"{ .u40 = 0x%010" PRIx64
"llu }",
1178 r = snprintf(s, n,
"{ .u48 = CO_UNSIGNED48_MIN }");
1180 r = snprintf(s, n,
"{ .u48 = CO_UNSIGNED48_MAX }");
1182 r = snprintf(s, n,
"{ .u48 = 0x%012" PRIx64
"llu }",
1188 r = snprintf(s, n,
"{ .u56 = CO_UNSIGNED56_MIN }");
1190 r = snprintf(s, n,
"{ .u56 = CO_UNSIGNED56_MAX }");
1192 r = snprintf(s, n,
"{ .u56 = 0x%014" PRIx64
"llu }",
1198 r = snprintf(s, n,
"{ .u64 = CO_UNSIGNED64_MIN }");
1200 r = snprintf(s, n,
"{ .u64 = CO_UNSIGNED64_MAX }");
1202 r = snprintf(s, n,
"{ .u64 = 0x%016" PRIx64
"llu }",
1206 default: r = 0;
break;
1216 snprintf_c99_esc(
char *s,
size_t n,
const char *esc)
1230 chars =
lex_utf8(esc, NULL, NULL, &c32);
1235 char buf[12] = {
'\0' };
1239 r = snprintf(s, n,
"%s", buf);
1243 r =
MIN((
size_t)r, n);
1251 #endif // !LELY_NO_CO_SDEV size_t co_sub_set_def(co_sub_t *sub, const void *ptr, size_t n)
Sets the default value of a CANopen sub-object.
#define CO_ACCESS_RWW
Read or write on process output.
void co_dev_set_revision(co_dev_t *dev, co_unsigned32_t revision)
Sets the revision number of a CANopen device.
co_unsigned8_t id
The node-ID.
const char * name
A pointer to the name of the sub-object.
int co_obj_insert_sub(co_obj_t *obj, co_sub_t *sub)
Inserts a sub-object into a CANopen object.
#define CO_INTEGER8_MIN
The minimum value of an 8-bit signed integer.
#define CO_OBJ_FLAGS_UPLOAD_FILE
If a read access is performed for the object, the data is stored in a file.
#define CO_INTEGER56_MAX
The maximum value of a 56-bit signed integer (encoded as an int64_t).
void co_dev_set_lss(co_dev_t *dev, int lss)
Sets the LSS support flag.
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.
co_unsigned8_t code
The object code.
#define CO_OBJECT_DOMAIN
A large variable amount of data.
#define CO_INTEGER32_MIN
The minimum value of a 32-bit signed integer.
#define CO_DEFTYPE_UNSIGNED56
The data type (and object index) of a 56-bit unsigned integer.
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...
A static CANopen sub-object.
co_unsigned16_t type
The data type.
size_t co_sub_set_max(co_sub_t *sub, const void *ptr, size_t n)
Sets the upper limit of a value of a CANopen sub-object.
#define CO_DEFTYPE_TIME_DIFF
The data type (and object index) of a 48-bit structure representing a time difference.
#define CO_ACCESS_WO
Write-only access.
#define CO_INTEGER48_MAX
The maximum value of a 48-bit signed integer (encoded as an int64_t).
const struct co_ssub * subs
An array of sub-objects.
co_unsigned32_t revision
The revision number.
#define CO_DEFTYPE_VISIBLE_STRING
The data type (and object index) of an array of visible characters.
#define CO_UNSIGNED16_MAX
The maximum value of a 16-bit unsigned integer.
#define CO_INTEGER64_MAX
The maximum value of a 64-bit signed integer.
#define CO_INTEGER64_MIN
The minimum value of a 64-bit signed integer.
int errnum2c(errnum_t errnum)
Transforms a platform-independent error number to a native error code.
#define CO_DEFTYPE_DOMAIN
The data type (and object index) of an arbitrary large block of data.
int co_sub_set_name(co_sub_t *sub, const char *name)
Sets the name of a CANopen sub-object.
int co_obj_set_code(co_obj_t *obj, co_unsigned8_t code)
Sets the code (type) of a CANopen object.
#define CO_UNSIGNED64_MAX
The maximum value of a 64-bit unsigned integer.
#define CO_OBJ_FLAGS_DOWNLOAD_FILE
If a write access is performed for the object, the data is stored in a file.
void co_sub_set_flags(co_sub_t *sub, unsigned int flags)
Sets the object flags of a CANopen sub-object.
#define CO_DEFTYPE_INTEGER24
The data type (and object index) of a 24-bit signed integer.
#define CO_UNSIGNED24_MIN
The minimum value of a 24-bit unsigned integer (encoded as a uint32_t).
#define CO_ACCESS_RWR
Read or write on process input.
const char * name
A pointer to the name of the object.
A union of the CANopen static data types.
const void * co_sub_get_min(const co_sub_t *sub)
Returns a pointer to the lower limit of the value of a CANopen sub-object.
#define CO_DEFTYPE_INTEGER48
The data type (and object index) of a 48-bit signed integer.
union co_val def
The default value of val.
#define CO_UNSIGNED8_MIN
The minimum value of an 8-bit unsigned integer.
co_obj_t * co_obj_create(co_unsigned16_t idx)
Creates a CANopen object.
const void * co_sub_get_def(const co_sub_t *sub)
Returns a pointer to the default value of a CANopen sub-object.
const char * co_dev_get_name(const co_dev_t *dev)
Returns the name of a CANopen device.
#define CO_OBJECT_DEFTYPE
A type definitions.
const char * product_name
A pointer to the product name.
int snprintf_c99_sdev(char *s, size_t n, const co_dev_t *dev)
Prints a C99 static initializer code fragment for a static device description (struct co_sdev) to a s...
#define CO_DEFTYPE_UNSIGNED48
The data type (and object index) of a 48-bit unsigned integer.
co_unsigned8_t co_dev_get_id(const co_dev_t *dev)
Returns the node-ID of a CANopen device.
#define MIN(a, b)
Returns the minimum of a and b.
#define CO_UNSIGNED56_MAX
The maximum value of a 56-bit unsigned integer (encoded as a uint64_t).
#define CO_UNSIGNED16_MIN
The minimum value of a 16-bit unsigned integer.
int co_val_init_min(co_unsigned16_t type, void *val)
Initializes a value of the specified data type with its lower limit.
co_unsigned8_t co_obj_get_code(const co_obj_t *obj)
Returns the object code of a CANopen object.
co_unsigned32_t vendor_id
The vendor ID.
co_unsigned8_t subidx
The object sub-index.
void co_dev_set_product_code(co_dev_t *dev, co_unsigned32_t product_code)
Sets the product code 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.
unsigned baud
The supported bit rates.
#define CO_INTEGER16_MIN
The minimum value of a 16-bit signed integer.
void co_sub_destroy(co_sub_t *sub)
Destroys a CANopen sub-object.
co_unsigned32_t co_dev_get_vendor_id(const co_dev_t *dev)
Returns the vendor ID of a CANopen device.
co_unsigned32_t dummy
The data types supported for mapping dummy entries in PDOs.
int co_sub_get_pdo_mapping(const co_sub_t *sub)
Returns 1 if it is possible to map the specified CANopen sub-object into a PDO, and 0 if not...
#define CO_UNSIGNED40_MIN
The minimum value of a 40-bit unsigned integer (encoded as a uint64_t).
#define CO_UNSIGNED48_MIN
The minimum value of a 48-bit unsigned integer (encoded as a uint64_t).
char * name
A pointer to the name of the device.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
unsigned int co_sub_get_access(const co_sub_t *sub)
Returns the access type of a CANopen sub-object.
#define CO_OBJECT_RECORD
A multiple data field object where the data fields may be any combination of simple variables...
#define CO_INTEGER40_MAX
The maximum value of a 40-bit signed integer (encoded as an int64_t).
const struct co_sobj * objs
An array of objects.
#define CO_DEFTYPE_UNSIGNED32
The data type (and object index) of a 32-bit unsigned integer.
#define CO_DEFTYPE_UNSIGNED24
The data type (and object index) of a 24-bit unsigned integer.
#define CO_DEFTYPE_INTEGER64
The data type (and object index) of a 64-bit signed integer.
unsigned flags
The object flags.
const char * co_dev_get_product_name(const co_dev_t *dev)
Returns a pointer to the product name of a CANopen device.
This header file is part of the utilities library; it contains the native and platform-independent er...
#define CO_UNSIGNED24_MAX
The maximum value of a 24-bit unsigned integer (encoded as a uint32_t).
size_t lex_utf8(const char *begin, const char *end, struct floc *at, char32_t *pc32)
Lexes a UTF-8 encoded Unicode character from a memory buffer.
int lss
A flag specifying whether LSS is supported (1) or not (0).
#define CO_DEFTYPE_REAL32
The data type (and object index) of a 32-bit IEEE-754 floating-point number.
#define CO_ACCESS_RO
Read-only access.
size_t co_sub_set_min(co_sub_t *sub, const void *ptr, size_t n)
Sets the lower limit of a value of a CANopen sub-object.
const char * name
A pointer to the name of the device.
#define CO_DEFTYPE_INTEGER8
The data type (and object index) of an 8-bit signed integer.
co_unsigned16_t nobj
The number of objects in objs.
union co_val val
The sub-object value.
#define CO_DEFTYPE_UNSIGNED16
The data type (and object index) of a 16-bit unsigned integer.
unsigned baud
The supported bit rates.
#define CO_ACCESS_CONST
Constant value.
const void * co_sub_get_val(const co_sub_t *sub)
Returns a pointer to the current value of a CANopen sub-object.
This is the internal header file of the CANopen library.
co_unsigned16_t rate
The (pending) baudrate (in kbit/s).
int co_val_init_max(co_unsigned16_t type, void *val)
Initializes a value of the specified data type with its upper limit.
void co_sub_set_pdo_mapping(co_sub_t *sub, int pdo_mapping)
Enables or disables PDO mapping a CANopen sub-object.
#define CO_INTEGER40_MIN
The minimum value of a 40-bit signed integer (encoded as an int64_t).
#define CO_DEFTYPE_UNICODE_STRING
The data type (and object index) of an array of (16-bit) Unicode characters.
This header file is part of the CANopen library; it contains the static device description declaratio...
#define CO_ACCESS_RW
Read or write access.
This header file is part of the utilities library; it contains the lexer function declarations...
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_DEFTYPE_TIME_OF_DAY
The data type (and object index) of a 48-bit structure representing the absolute time.
int co_dev_insert_obj(co_dev_t *dev, co_obj_t *obj)
Inserts an object into the object dictionary of a CANopen device.
#define CO_UNSIGNED8_MAX
The maximum value of an 8-bit unsigned integer.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function...
int co_dev_set_order_code(co_dev_t *dev, const char *order_code)
Sets the order code of a CANopen device.
#define CO_DEFTYPE_UNSIGNED8
The data type (and object index) of an 8-bit unsigned integer.
#define CO_DEFTYPE_UNSIGNED40
The data type (and object index) of a 40-bit unsigned integer.
co_unsigned32_t co_dev_get_revision(const co_dev_t *dev)
Returns the revision number of a CANopen device.
union co_val min
The lower limit of val.
void co_dev_set_rate(co_dev_t *dev, co_unsigned16_t rate)
Sets the (pending) baudrate of a CANopen device.
#define CO_INTEGER8_MAX
The maximum value of an 8-bit signed integer.
#define CO_UNSIGNED48_MAX
The maximum value of a 48-bit unsigned integer (encoded as a uint64_t).
#define CO_INTEGER48_MIN
The minimum value of a 48-bit signed integer (encoded as an int64_t).
#define CO_INTEGER24_MIN
The minimum value of a 24-bit signed integer (encoded as an int32_t).
#define CO_OBJECT_VAR
A single value.
unsigned int co_sub_get_flags(const co_sub_t *sub)
Returns the object flags of a CANopen sub-object.
#define CO_DEFTYPE_INTEGER16
The data type (and object index) of a 16-bit signed integer.
co_unsigned8_t co_obj_get_subidx(const co_obj_t *obj, co_unsigned8_t maxsubidx, co_unsigned8_t *subidx)
Retrieves a list of sub-indices in a CANopen object.
#define __unlikely(x)
Indicates to the compiler that the expression is most-likely false.
#define CO_DEFTYPE_INTEGER56
The data type (and object index) of a 56-bit signed integer.
#define CO_INTEGER56_MIN
The minimum value of a 56-bit signed integer (encoded as an int64_t).
#define CO_UNSIGNED40_MAX
The maximum value of a 40-bit unsigned integer (encoded as a uint64_t).
#define CO_REAL64_MAX
The maximum value of a 64-bit IEEE-754 floating-point number.
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_sub_set_val(co_sub_t *sub, 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_BAUD_800, CO_BAUD_500, CO_BAUD_250, CO_BAUD_125, CO_BAUD_50, CO_BAUD_20, CO_BAUD_10 and CO_BAUD_AUTO).
union co_val max
The upper limit of val.
#define CO_DEFTYPE_OCTET_STRING
The data type (and object index) of an array of octets.
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.
#define CO_UNSIGNED32_MIN
The minimum value of a 32-bit unsigned integer.
co_unsigned8_t nsub
The number of sub-objects in subs.
#define CO_INTEGER16_MAX
The maximum value of a 16-bit signed integer.
const char * order_code
A pointer to the order code.
This header file is part of the C11 and POSIX compatibility library; it includes <stdio.h> and defines any missing functionality.
#define CO_INTEGER24_MAX
The maximum value of a 24-bit signed integer (encoded as an int32_t).
#define CO_OBJECT_NULL
An object with no data fields.
#define CO_DEFTYPE_UNSIGNED64
The data type (and object index) of a 64-bit unsigned integer.
void co_obj_destroy(co_obj_t *obj)
Destroys a CANopen object, including its sub-objects.
This header file is part of the utilities library; it contains the printing function declarations...
#define CO_OBJECT_DEFSTRUCT
A record type definition.
const char * co_dev_get_order_code(const co_dev_t *dev)
Returns a pointer to the order code of a CANopen device.
#define CO_INTEGER32_MAX
The maximum value of a 32-bit signed integer.
void co_val_fini(co_unsigned16_t type, void *val)
Finalizes a value of the specified data type.
unsigned pdo_mapping
A flag indicating if it is possible to map this object into a PDO.
#define CO_REAL32_MAX
The maximum value of a 32-bit IEEE-754 floating-point number.
int co_sub_set_access(co_sub_t *sub, unsigned int access)
Sets the access type of a CANopen sub-object.
co_sub_t * co_sub_create(co_unsigned8_t subidx, co_unsigned16_t type)
Creates a CANopen sub-object.
const char * co_dev_get_vendor_name(const co_dev_t *dev)
Returns a pointer to the vendor name of a CANopen device.
co_unsigned16_t idx
The object index.
#define CO_DEFTYPE_REAL64
The data type (and object index) of a 64-bit IEEE-754 floating-point number.
int co_dev_set_product_name(co_dev_t *dev, const char *product_name)
Sets the product name of a CANopen device.
const void * co_sub_get_max(const co_sub_t *sub)
Returns a pointer to the upper limit of the value of a CANopen sub-object.
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_obj_set_name(co_obj_t *obj, const char *name)
Sets the name of a CANopen object.
void co_dev_set_baud(co_dev_t *dev, unsigned int baud)
Sets the supported bit rates of a CANopen device.
co_dev_t * co_dev_create_from_sdev(const struct co_sdev *sdev)
Creates a CANopen device from a static device description.
co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub)
Returns the sub-index of a CANopen sub-object.
const char * vendor_name
A pointer to the vendor name.
This header file is part of the C11 and POSIX compatibility library; it includes <stdlib.h> and defines any missing functionality.
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.
co_unsigned32_t product_code
The product code.
const char * co_obj_get_name(const co_obj_t *obj)
Returns the name of a CANopen object.
#define CO_REAL64_MIN
The minimum value of a 64-bit IEEE-754 floating-point number.
#define CO_DEFTYPE_INTEGER32
The data type (and object index) of a 32-bit signed integer.
#define CO_REAL32_MIN
The minimum value of a 32-bit IEEE-754 floating-point number.
co_unsigned16_t co_sub_get_type(const co_sub_t *sub)
Returns the data type of a CANopen sub-object.
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_DEFTYPE_INTEGER40
The data type (and object index) of a 40-bit signed integer.
#define CO_UNSIGNED64_MIN
The minimum value of a 64-bit unsigned integer.
unsigned access
The access type.
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
#define CO_UNSIGNED56_MIN
The minimum value of a 56-bit unsigned integer (encoded as a uint64_t).
int co_dev_set_name(co_dev_t *dev, const char *name)
Sets the name of a CANopen device.
size_t print_c99_esc(char **pbegin, char *end, char32_t c32)
Prints a UTF-8 encoded Unicode character to a memory buffer.
const char * co_sub_get_name(const co_sub_t *sub)
Returns the name of a CANopen sub-object.
int co_dev_get_lss(const co_dev_t *dev)
Returns 1 if LSS is supported and 0 if not.
int asprintf_c99_sdev(char **ps, const co_dev_t *dev)
Equivalent to snprintf_c99_sdev(), except that it allocates a string large enough to hold the output...
#define CO_OBJECT_ARRAY
A multiple data field object where each data field is a simple variable of the same basic data type...
#define CO_UNSIGNED32_MAX
The maximum value of a 32-bit unsigned integer.
#define CO_DEFTYPE_BOOLEAN
The data type (and object index) of a boolean truth value.
void co_dev_set_vendor_id(co_dev_t *dev, co_unsigned32_t vendor_id)
Sets the vendor ID 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.