Lely core libraries
2.2.5
|
Go to the documentation of this file.
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)
62 if (!__co_dev_init(dev, sdev->
id)) {
67 if (co_sdev_load(sdev, dev) == -1) {
93 if (!__co_dev_init_from_sdev(dev, sdev)) {
122 r = snprintf(s, n,
"{\n\t.id = 0x%02x,\n",
co_dev_get_id(dev));
125 goto error_print_dev;
128 r =
MIN((
size_t)r, n);
134 r = snprintf(s, n,
"\t.name = CO_SDEV_STRING(\"");
137 goto error_print_dev;
140 r =
MIN((
size_t)r, n);
143 r = snprintf_c99_esc(s, n,
name);
146 goto error_print_dev;
149 r =
MIN((
size_t)r, n);
152 r = snprintf(s, n,
"\"),\n");
154 r = snprintf(s, n,
"\t.name = NULL,\n");
158 goto error_print_dev;
161 r =
MIN((
size_t)r, n);
167 r = snprintf(s, n,
"\t.vendor_name = CO_SDEV_STRING(\"");
170 goto error_print_dev;
173 r =
MIN((
size_t)r, n);
176 r = snprintf_c99_esc(s, n,
name);
179 goto error_print_dev;
182 r =
MIN((
size_t)r, n);
185 r = snprintf(s, n,
"\"),\n");
187 r = snprintf(s, n,
"\t.vendor_name = NULL,\n");
191 goto error_print_dev;
194 r =
MIN((
size_t)r, n);
198 r = snprintf(s, n,
"\t.vendor_id = 0x%08" PRIx32
",\n",
202 goto error_print_dev;
205 r =
MIN((
size_t)r, n);
211 r = snprintf(s, n,
"\t.product_name = CO_SDEV_STRING(\"");
214 goto error_print_dev;
217 r =
MIN((
size_t)r, n);
220 r = snprintf_c99_esc(s, n,
name);
223 goto error_print_dev;
226 r =
MIN((
size_t)r, n);
229 r = snprintf(s, n,
"\"),\n");
231 r = snprintf(s, n,
"\t.product_name = NULL,\n");
235 goto error_print_dev;
238 r =
MIN((
size_t)r, n);
243 "\t.product_code = 0x%08" PRIx32
244 ",\n\t.revision = 0x%08" PRIx32
",\n",
248 goto error_print_dev;
251 r =
MIN((
size_t)r, n);
257 r = snprintf(s, n,
"\t.order_code = CO_SDEV_STRING(\"");
260 goto error_print_dev;
263 r =
MIN((
size_t)r, n);
266 r = snprintf_c99_esc(s, n,
name);
269 goto error_print_dev;
272 r =
MIN((
size_t)r, n);
275 r = snprintf(s, n,
"\"),\n");
277 r = snprintf(s, n,
"\t.order_code = NULL,\n");
281 goto error_print_dev;
284 r =
MIN((
size_t)r, n);
288 r = snprintf(s, n,
"\t.baud = 0");
291 goto error_print_dev;
294 r =
MIN((
size_t)r, n);
298 #define LELY_CO_DEFINE_BAUD(x) \
299 if (baud & CO_BAUD_##x) { \
300 r = snprintf(s, n, "\n\t\t| CO_BAUD_" #x); \
303 goto error_print_dev; \
306 r = MIN((size_t)r, n); \
311 LELY_CO_DEFINE_BAUD(1000)
312 LELY_CO_DEFINE_BAUD(800)
313 LELY_CO_DEFINE_BAUD(500)
314 LELY_CO_DEFINE_BAUD(250)
315 LELY_CO_DEFINE_BAUD(125)
316 LELY_CO_DEFINE_BAUD(50)
317 LELY_CO_DEFINE_BAUD(20)
318 LELY_CO_DEFINE_BAUD(10)
319 LELY_CO_DEFINE_BAUD(AUTO)
321 #undef LELY_CO_DEFINE_BAUD
324 ",\n\t.rate = %d,\n\t.lss = %d,\n\t.dummy = 0x%08" PRIx32
330 goto error_print_dev;
333 r =
MIN((
size_t)r, n);
338 co_unsigned16_t *idx = malloc(maxidx *
sizeof(co_unsigned16_t));
341 goto error_malloc_idx;
345 r = snprintf(s, n,
"\t.nobj = %d,\n\t.objs = (const struct co_sobj[]){",
349 goto error_print_obj;
352 r =
MIN((
size_t)r, n);
356 for (
size_t i = 0; i < maxidx; i++) {
357 r = snprintf(s, n, i ?
", {\n" :
"{\n");
360 goto error_print_obj;
363 r =
MIN((
size_t)r, n);
369 goto error_print_obj;
372 r =
MIN((
size_t)r, n);
375 r = snprintf(s, n,
"\t}");
378 goto error_print_obj;
381 r =
MIN((
size_t)r, n);
386 r = snprintf(s, n,
"}\n}");
389 goto error_print_obj;
412 char *s = malloc(n + 1);
458 for (
size_t i = 0; i < sdev->
nobj; i++) {
469 if (co_sobj_load(sobj, obj) == -1)
482 #ifndef LELY_NO_CO_OBJ_NAME
490 for (
size_t i = 0; i < sobj->
nsub; i++) {
501 if (co_ssub_load(ssub, sub) == -1)
514 #ifndef LELY_NO_CO_OBJ_NAME
525 #ifndef LELY_NO_CO_OBJ_LIMITS
537 #ifndef LELY_NO_CO_OBJ_DEFAULT
556 snprintf_c99_sobj(
char *s,
size_t n,
const co_obj_t *obj)
566 #ifndef LELY_NO_CO_OBJ_NAME
570 "#if !LELY_NO_CO_OBJ_NAME\n\t\t.name = CO_SDEV_STRING(\"");
574 r =
MIN((
size_t)r, n);
577 r = snprintf_c99_esc(s, n,
name);
581 r =
MIN((
size_t)r, n);
584 r = snprintf(s, n,
"\"),\n");
588 "#if !LELY_NO_CO_OBJ_NAME\n\t\t.name = NULL,\n");
589 #ifndef LELY_NO_CO_OBJ_NAME
595 r =
MIN((
size_t)r, n);
599 r = snprintf(s, n,
"#endif\n\t\t.idx = 0x%04x,\n\t\t.code = ",
604 r =
MIN((
size_t)r, n);
610 case CO_OBJECT_NULL: r = snprintf(s, n,
"CO_OBJECT_NULL,\n");
break;
613 r = snprintf(s, n,
"CO_OBJECT_DEFTYPE,\n");
616 r = snprintf(s, n,
"CO_OBJECT_DEFSTRUCT,\n");
618 case CO_OBJECT_VAR: r = snprintf(s, n,
"CO_OBJECT_VAR,\n");
break;
621 default: r = snprintf(s, n,
"0x%02x,\n", code);
break;
626 r =
MIN((
size_t)r, n);
630 co_unsigned8_t
subidx[0xff];
634 "\t\t.nsub = %d,\n\t\t.subs = (const struct co_ssub[]){",
639 r =
MIN((
size_t)r, n);
643 for (
size_t i = 0; i < maxsubidx; i++) {
644 r = snprintf(s, n, i ?
", {\n" :
"{\n");
648 r =
MIN((
size_t)r, n);
655 r =
MIN((
size_t)r, n);
658 r = snprintf(s, n,
"\t\t}");
662 r =
MIN((
size_t)r, n);
667 r = snprintf(s, n,
"}\n");
676 snprintf_c99_ssub(
char *s,
size_t n,
const co_sub_t *sub)
686 #ifndef LELY_NO_CO_OBJ_NAME
690 "#if !LELY_NO_CO_OBJ_NAME\n\t\t\t.name = CO_SDEV_STRING(\"");
694 r =
MIN((
size_t)r, n);
697 r = snprintf_c99_esc(s, n,
name);
701 r =
MIN((
size_t)r, n);
704 r = snprintf(s, n,
"\"),\n");
708 "#if !LELY_NO_CO_OBJ_NAME\n\t\t\t.name = NULL,\n");
709 #ifndef LELY_NO_CO_OBJ_NAME
715 r =
MIN((
size_t)r, n);
719 r = snprintf(s, n,
"#endif\n\t\t\t.subidx = 0x%02x,\n\t\t\t.type = ",
724 r =
MIN((
size_t)r, n);
730 #define LELY_CO_DEFINE_TYPE(a, b, c, d) \
731 case CO_DEFTYPE_##a: \
732 r = snprintf(s, n, "CO_DEFTYPE_" #a ",\n"); \
734 #include <lely/co/def/type.def>
735 #undef LELY_CO_DEFINE_TYPE
736 default: r = snprintf(s, n,
"0x%04x,\n",
type);
break;
741 r =
MIN((
size_t)r, n);
745 r = snprintf(s, n,
"#if !LELY_NO_CO_OBJ_LIMITS\n\t\t\t.min = ");
749 r =
MIN((
size_t)r, n);
752 #ifndef LELY_NO_CO_OBJ_LIMITS
757 r = snprintf_c99_sval(s, n, type, &min);
763 r =
MIN((
size_t)r, n);
767 r = snprintf(s, n,
",\n\t\t\t.max = ");
771 r =
MIN((
size_t)r, n);
774 #ifndef LELY_NO_CO_OBJ_LIMITS
779 r = snprintf_c99_sval(s, n, type, &max);
785 r =
MIN((
size_t)r, n);
790 ",\n#endif\n#if !LELY_NO_CO_OBJ_DEFAULT\n\t\t\t.def = ");
794 r =
MIN((
size_t)r, n);
797 #ifndef LELY_NO_CO_OBJ_DEFAULT
802 r = snprintf_c99_sval(s, n, type, &def);
808 r =
MIN((
size_t)r, n);
812 r = snprintf(s, n,
",\n#endif\n\t\t\t.val = ");
816 r =
MIN((
size_t)r, n);
819 #ifndef LELY_NO_CO_OBJ_FILE
834 r =
MIN((
size_t)r, n);
838 r = snprintf(s, n,
",\n\t\t\t.access = ");
842 r =
MIN((
size_t)r, n);
847 case CO_ACCESS_RO: r = snprintf(s, n,
"CO_ACCESS_RO,\n");
break;
848 case CO_ACCESS_WO: r = snprintf(s, n,
"CO_ACCESS_WO,\n");
break;
849 case CO_ACCESS_RW: r = snprintf(s, n,
"CO_ACCESS_RW,\n");
break;
850 case CO_ACCESS_RWR: r = snprintf(s, n,
"CO_ACCESS_RWR,\n");
break;
851 case CO_ACCESS_RWW: r = snprintf(s, n,
"CO_ACCESS_RWW,\n");
break;
853 default: r = snprintf(s, n,
"0x%x,\n", access);
break;
858 r =
MIN((
size_t)r, n);
862 r = snprintf(s, n,
"\t\t\t.pdo_mapping = %d,\n",
867 r =
MIN((
size_t)r, n);
871 r = snprintf(s, n,
"\t\t\t.flags = 0\n");
875 r =
MIN((
size_t)r, n);
879 #define LELY_CO_DEFINE_FLAGS(x) \
880 if (flags & CO_OBJ_FLAGS_##x) { \
881 r = snprintf(s, n, "\t\t\t\t| CO_OBJ_FLAGS_" #x "\n"); \
885 r = MIN((size_t)r, n); \
890 LELY_CO_DEFINE_FLAGS(READ)
891 LELY_CO_DEFINE_FLAGS(WRITE)
892 #ifndef LELY_NO_CO_OBJ_FILE
893 LELY_CO_DEFINE_FLAGS(UPLOAD_FILE)
894 LELY_CO_DEFINE_FLAGS(DOWNLOAD_FILE)
896 LELY_CO_DEFINE_FLAGS(MIN_NODEID)
897 LELY_CO_DEFINE_FLAGS(MAX_NODEID)
898 LELY_CO_DEFINE_FLAGS(DEF_NODEID)
901 LELY_CO_DEFINE_FLAGS(VAL_NODEID)
903 #undef LELY_CO_DEFINE_FLAGS
909 snprintf_c99_sval(
char *s,
size_t n, co_unsigned16_t type,
const void *val)
919 const union co_val *u = val;
922 r = snprintf(s, n,
"{ .b = %d }", !!u->b);
926 r = snprintf(s, n,
"{ .i8 = CO_INTEGER8_MIN }");
928 r = snprintf(s, n,
"{ .i8 = CO_INTEGER8_MAX }");
930 r = snprintf(s, n,
"{ .i8 = %" PRIi8
" }", u->i8);
935 r = snprintf(s, n,
"{ .i16 = CO_INTEGER16_MIN }");
937 r = snprintf(s, n,
"{ .i16 = CO_INTEGER16_MAX }");
939 r = snprintf(s, n,
"{ .i16 = %" PRIi16
" }", u->i16);
944 r = snprintf(s, n,
"{ .i32 = CO_INTEGER32_MIN }");
946 r = snprintf(s, n,
"{ .i32 = CO_INTEGER32_MAX }");
948 r = snprintf(s, n,
"{ .i32 = %" PRIi32
"l }", u->i32);
953 r = snprintf(s, n,
"{ .u8 = CO_UNSIGNED8_MIN }");
955 r = snprintf(s, n,
"{ .u8 = CO_UNSIGNED8_MAX }");
957 r = snprintf(s, n,
"{ .u8 = 0x%02" PRIx8
" }", u->u8);
962 r = snprintf(s, n,
"{ .u16 = CO_UNSIGNED16_MIN }");
964 r = snprintf(s, n,
"{ .u16 = CO_UNSIGNED16_MAX }");
966 r = snprintf(s, n,
"{ .u16 = 0x%04" PRIx16
"u }",
972 r = snprintf(s, n,
"{ .u32 = CO_UNSIGNED32_MIN }");
974 r = snprintf(s, n,
"{ .u32 = CO_UNSIGNED32_MAX }");
976 r = snprintf(s, n,
"{ .u32 = 0x%08" PRIx32
"lu }",
982 r = snprintf(s, n,
"{ .r32 = CO_REAL32_MIN }");
984 r = snprintf(s, n,
"{ .r32 = CO_REAL32_MAX }");
986 r = snprintf(s, n,
"{ .r32 = %.*g }", DECIMAL_DIG,
992 r = snprintf(s, n,
"{ .vs = CO_VISIBLE_STRING_C(\"");
996 r =
MIN((
size_t)r, n);
999 r = snprintf_c99_esc(s, n, u->vs);
1003 r =
MIN((
size_t)r, n);
1006 r = snprintf(s, n,
"\") }");
1008 r = snprintf(s, n,
"{ .vs = NULL }");
1014 "{ .os = CO_OCTET_STRING_C(\n\t\t\t\t\"");
1018 r =
MIN((
size_t)r, n);
1022 for (
size_t i = 0; i < size; i++) {
1024 r = snprintf(s, n, i && !(i % 8)
1025 ?
"\"\n\t\t\t\t\"\\x%02x"
1032 r =
MIN((
size_t)r, n);
1036 r = snprintf(s, n,
"\"\n\t\t\t) }");
1038 r = snprintf(s, n,
"{ .vs = NULL }");
1044 "{ .us = CO_UNICODE_STRING_C({\n\t\t\t\t");
1048 r =
MIN((
size_t)r, n);
1052 for (
size_t i = 0; i < size; i++) {
1054 r = snprintf(s, n, i && !(i % 4)
1055 ?
",\n\t\t\t\t0x%04x"
1056 : (i ?
", 0x%04x" :
"0x%04x"),
1062 r =
MIN((
size_t)r, n);
1066 r = snprintf(s, n,
"\n\t\t\t}) }");
1068 r = snprintf(s, n,
"{ .us = NULL }");
1074 ".ms = 0x%08" PRIx32
", "
1075 ".days = 0x%04" PRIx16
" "
1077 u->t.ms, u->t.days);
1082 ".ms = 0x%08" PRIx32
", "
1083 ".days = 0x%04" PRIx16
" "
1085 u->td.ms, u->td.days);
1090 "{ .dom = CO_DOMAIN_C(co_unsigned8_t, {\n\t\t\t\t");
1094 r =
MIN((
size_t)r, n);
1097 const co_unsigned8_t *bp = u->dom;
1099 for (
size_t i = 0; i < size; i++) {
1101 r = snprintf(s, n, i && !(i % 8)
1102 ?
",\n\t\t\t\t0x%02x"
1103 : (i ?
", 0x%02x" :
"0x%02x"),
1109 r =
MIN((
size_t)r, n);
1113 r = snprintf(s, n,
"\n\t\t\t}) }");
1115 r = snprintf(s, n,
"{ .dom = NULL }");
1120 r = snprintf(s, n,
"{ .i24 = CO_INTEGER24_MIN }");
1122 r = snprintf(s, n,
"{ .i24 = CO_INTEGER24_MAX }");
1124 r = snprintf(s, n,
"{ .i24 = %" PRIi32
"l }", u->i24);
1129 r = snprintf(s, n,
"{ .r64 = CO_REAL64_MIN }");
1131 r = snprintf(s, n,
"{ .r64 = CO_REAL64_MAX }");
1133 r = snprintf(s, n,
"{ .r64 = %.*g }", DECIMAL_DIG,
1139 r = snprintf(s, n,
"{ CO_INTEGER40_MIN }");
1141 r = snprintf(s, n,
"{ CO_INTEGER40_MAX }");
1143 r = snprintf(s, n,
"{ .i40 = %" PRIi64
"ll }", u->i40);
1148 r = snprintf(s, n,
"{ .i48 = CO_INTEGER48_MIN }");
1150 r = snprintf(s, n,
"{ .i48 = CO_INTEGER48_MAX }");
1152 r = snprintf(s, n,
"{ .i48 = %" PRIi64
"ll }", u->i48);
1157 r = snprintf(s, n,
"{ .i56 = CO_INTEGER56_MIN }");
1159 r = snprintf(s, n,
"{ .i56 = CO_INTEGER56_MAX }");
1161 r = snprintf(s, n,
"{ .i56 = %" PRIi64
"ll }", u->i56);
1166 r = snprintf(s, n,
"{ .i64 = CO_INTEGER64_MIN }");
1168 r = snprintf(s, n,
"{ .i64 = CO_INTEGER64_MAX }");
1170 r = snprintf(s, n,
"{ .i64 = %" PRIi64
"ll }", u->i64);
1175 r = snprintf(s, n,
"{ .u24 = CO_UNSIGNED24_MIN }");
1177 r = snprintf(s, n,
"{ .u24 = CO_UNSIGNED24_MAX }");
1179 r = snprintf(s, n,
"{ .u24 = 0x%06" PRIx32
"lu }",
1185 r = snprintf(s, n,
"{ .u40 = CO_UNSIGNED40_MIN }");
1187 r = snprintf(s, n,
"{ .u40 = CO_UNSIGNED40_MAX }");
1189 r = snprintf(s, n,
"{ .u40 = 0x%010" PRIx64
"llu }",
1195 r = snprintf(s, n,
"{ .u48 = CO_UNSIGNED48_MIN }");
1197 r = snprintf(s, n,
"{ .u48 = CO_UNSIGNED48_MAX }");
1199 r = snprintf(s, n,
"{ .u48 = 0x%012" PRIx64
"llu }",
1205 r = snprintf(s, n,
"{ .u56 = CO_UNSIGNED56_MIN }");
1207 r = snprintf(s, n,
"{ .u56 = CO_UNSIGNED56_MAX }");
1209 r = snprintf(s, n,
"{ .u56 = 0x%014" PRIx64
"llu }",
1215 r = snprintf(s, n,
"{ .u64 = CO_UNSIGNED64_MIN }");
1217 r = snprintf(s, n,
"{ .u64 = CO_UNSIGNED64_MAX }");
1219 r = snprintf(s, n,
"{ .u64 = 0x%016" PRIx64
"llu }",
1223 default: r = 0;
break;
1233 snprintf_c99_esc(
char *s,
size_t n,
const char *esc)
1246 size_t chars =
lex_utf8(esc, NULL, NULL, &c32);
1251 char buf[12] = {
'\0' };
1255 int r = snprintf(s, n,
"%s", buf);
1259 r =
MIN((
size_t)r, n);
1267 #endif // !LELY_NO_CO_SDEV
#define CO_DEFTYPE_UNSIGNED64
The data type (and object index) of a 64-bit unsigned integer.
int co_obj_set_name(co_obj_t *obj, const char *name)
Sets the name of a CANopen object.
#define CO_ACCESS_RW
Read or write access.
#define CO_DEFTYPE_INTEGER8
The data type (and object index) of an 8-bit signed integer.
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.
union co_val def
The default value of val.
int co_val_init_max(co_unsigned16_t type, void *val)
Initializes a value of the specified data type with its upper limit.
const char * vendor_name
A pointer to the vendor name.
#define CO_OBJ_FLAGS_DOWNLOAD_FILE
If a write access is performed for the object, the data is stored in a file.
co_unsigned32_t product_code
The product code.
co_dev_t * co_dev_create_from_sdev(const struct co_sdev *sdev)
Creates a CANopen device from a static device description.
#define CO_INTEGER16_MIN
The minimum value of a 16-bit signed integer.
#define CO_DEFTYPE_INTEGER64
The data type (and object index) of a 64-bit signed integer.
const void * co_sub_get_val(const co_sub_t *sub)
Returns a pointer to the current value of a CANopen sub-object.
#define CO_UNSIGNED32_MIN
The minimum value of a 32-bit unsigned integer.
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,...
union co_val val
The sub-object value.
#define CO_REAL64_MIN
The minimum value of a 64-bit IEEE-754 floating-point number.
void co_val_fini(co_unsigned16_t type, void *val)
Finalizes a value of the specified data type.
#define CO_DEFTYPE_INTEGER40
The data type (and object index) of a 40-bit signed integer.
#define CO_DEFTYPE_UNSIGNED32
The data type (and object index) of a 32-bit unsigned integer.
co_unsigned32_t co_dev_get_vendor_id(const co_dev_t *dev)
Returns the vendor ID of a CANopen device.
co_unsigned16_t co_dev_get_rate(const co_dev_t *dev)
Returns the (pending) baudrate of a CANopen device (in kbit/s).
#define CO_ACCESS_RWW
Read or write on process output.
#define CO_DEFTYPE_INTEGER32
The data type (and object index) of a 32-bit signed integer.
A static CANopen sub-object.
int co_val_init_min(co_unsigned16_t type, void *val)
Initializes a value of the specified data type with its lower limit.
#define CO_DEFTYPE_UNSIGNED16
The data type (and object index) of a 16-bit unsigned integer.
#define CO_INTEGER56_MAX
The maximum value of a 56-bit signed integer (encoded as an int64_t).
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.
const char * name
A pointer to the name of the sub-object.
const char * co_sub_get_name(const co_sub_t *sub)
Returns the name of a CANopen sub-object.
const void * co_sub_get_def(const co_sub_t *sub)
Returns a pointer to the default value 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.
unsigned baud
The supported bit rates.
#define MIN(a, b)
Returns the minimum of a and b.
co_unsigned16_t co_obj_get_idx(const co_obj_t *obj)
Returns the index of a CANopen object.
void co_dev_set_rate(co_dev_t *dev, co_unsigned16_t rate)
Sets the (pending) baudrate of a CANopen device.
#define CO_INTEGER56_MIN
The minimum value of a 56-bit signed integer (encoded as an int64_t).
#define CO_INTEGER40_MIN
The minimum value of a 40-bit signed integer (encoded as an int64_t).
#define CO_UNSIGNED8_MIN
The minimum value of an 8-bit unsigned integer.
const char * co_dev_get_name(const co_dev_t *dev)
Returns the name of a CANopen device.
#define CO_DEFTYPE_TIME_DIFF
The data type (and object index) of a 48-bit structure representing a time difference.
co_unsigned8_t co_dev_get_id(const co_dev_t *dev)
Returns the node-ID of a CANopen device.
int get_errc(void)
Returns the last (thread-specific) native error code set by a system call or library function.
const char * co_dev_get_product_name(const co_dev_t *dev)
Returns a pointer to the product name of a CANopen device.
#define CO_DEFTYPE_BOOLEAN
The data type (and object index) of a boolean truth value.
#define CO_DEFTYPE_VISIBLE_STRING
The data type (and object index) of an array of visible characters.
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.
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.
#define CO_DEFTYPE_UNSIGNED8
The data type (and object index) of an 8-bit unsigned integer.
#define CO_DEFTYPE_DOMAIN
The data type (and object index) of an arbitrary large block of data.
void co_dev_set_product_code(co_dev_t *dev, co_unsigned32_t product_code)
Sets the product code of a CANopen device.
#define CO_INTEGER64_MIN
The minimum value of a 64-bit signed integer.
#define CO_UNSIGNED16_MIN
The minimum value of a 16-bit unsigned integer.
#define CO_INTEGER48_MIN
The minimum value of a 48-bit signed integer (encoded as an int64_t).
#define CO_UNSIGNED48_MIN
The minimum value of a 48-bit unsigned integer (encoded as a uint64_t).
#define CO_INTEGER32_MIN
The minimum value of a 32-bit signed integer.
#define CO_REAL32_MIN
The minimum value of a 32-bit IEEE-754 floating-point number.
void co_dev_set_lss(co_dev_t *dev, int lss)
Sets the LSS support flag.
co_unsigned32_t dummy
The data types supported for mapping dummy entries in PDOs.
co_unsigned32_t co_dev_get_revision(const co_dev_t *dev)
Returns the revision number of a CANopen device.
unsigned long access
The access type.
co_sub_t * co_obj_find_sub(const co_obj_t *obj, co_unsigned8_t subidx)
Finds a sub-object in a CANopen object.
const struct co_sobj * objs
An array of objects.
#define CO_OBJECT_DOMAIN
A large variable amount of data.
#define CO_DEFTYPE_OCTET_STRING
The data type (and object index) of an array of octets.
#define CO_DEFTYPE_INTEGER56
The data type (and object index) of a 56-bit signed integer.
#define CO_OBJECT_DEFTYPE
A type definitions.
#define CO_DEFTYPE_REAL64
The data type (and object index) of a 64-bit IEEE-754 floating-point number.
void co_sub_set_flags(co_sub_t *sub, unsigned int flags)
Sets the object flags of a CANopen sub-object.
co_obj_t * co_obj_create(co_unsigned16_t idx)
Creates a CANopen object.
int lss
A flag specifying whether LSS is supported (1) or not (0).
#define CO_ACCESS_RWR
Read or write on process input.
const char * name
A pointer to the name of the device.
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...
unsigned int co_sub_get_flags(const co_sub_t *sub)
Returns the object flags of a CANopen sub-object.
void co_sub_destroy(co_sub_t *sub)
Destroys a CANopen sub-object.
int co_sub_set_name(co_sub_t *sub, const char *name)
Sets the name of a CANopen sub-object.
void set_errc(int errc)
Sets the current (thread-specific) native error code to errc.
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.
#define CO_DEFTYPE_UNSIGNED56
The data type (and object index) of a 56-bit unsigned integer.
co_unsigned8_t code
The object code.
const char * product_name
A pointer to the product name.
co_unsigned32_t vendor_id
The vendor ID.
#define CO_INTEGER8_MIN
The minimum value of an 8-bit signed integer.
#define CO_UNSIGNED56_MAX
The maximum value of a 56-bit unsigned integer (encoded as a uint64_t).
int errnum2c(errnum_t errnum)
Transforms a platform-independent error number to a native error code.
co_unsigned16_t rate
The (pending) baudrate (in kbit/s).
#define CO_INTEGER40_MAX
The maximum value of a 40-bit signed integer (encoded as an int64_t).
#define CO_INTEGER48_MAX
The maximum value of a 48-bit signed integer (encoded as an int64_t).
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.
unsigned long pdo_mapping
A flag indicating if it is possible to map this object into a PDO.
const char * co_obj_get_name(const co_obj_t *obj)
Returns the name of a CANopen object.
#define CO_UNSIGNED24_MAX
The maximum value of a 24-bit unsigned integer (encoded as a uint32_t).
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_UNSIGNED16_MAX
The maximum value of a 16-bit unsigned integer.
#define CO_DEFTYPE_UNSIGNED24
The data type (and object index) of a 24-bit unsigned integer.
co_unsigned8_t id
The node-ID.
@ ERRNUM_INVAL
Invalid argument.
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.
#define CO_UNSIGNED64_MAX
The maximum value of a 64-bit unsigned integer.
#define CO_UNSIGNED64_MIN
The minimum value of a 64-bit unsigned integer.
#define CO_DEFTYPE_INTEGER48
The data type (and object index) of a 48-bit signed integer.
const char * co_dev_get_vendor_name(const co_dev_t *dev)
Returns a pointer to the vendor name of a CANopen device.
#define CO_OBJECT_ARRAY
A multiple data field object where each data field is a simple variable of the same basic data type.
int co_dev_set_order_code(co_dev_t *dev, const char *order_code)
Sets the order code 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.
unsigned int co_sub_get_access(const co_sub_t *sub)
Returns the access type of a CANopen sub-object.
int co_dev_set_vendor_name(co_dev_t *dev, const char *vendor_name)
Sets the vendor name of a CANopen device.
#define CO_OBJECT_DEFSTRUCT
A record type definition.
#define CO_OBJECT_NULL
An object with no data fields.
union co_val max
The upper limit of val.
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...
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.
char * name
A pointer to the name of the device.
#define CO_INTEGER24_MAX
The maximum value of a 24-bit signed integer (encoded as an int32_t).
#define CO_DEFTYPE_TIME_OF_DAY
The data type (and object index) of a 48-bit structure representing the absolute time.
#define CO_UNSIGNED40_MAX
The maximum value of a 40-bit unsigned integer (encoded as a uint64_t).
const char * name
A pointer to the name of the object.
A union of the CANopen static data types.
unsigned baud
The supported bit rates.
const char * co_dev_get_order_code(const co_dev_t *dev)
Returns a pointer to the order code of a CANopen device.
void co_sub_set_pdo_mapping(co_sub_t *sub, int pdo_mapping)
Enables or disables PDO mapping a CANopen sub-object.
void co_dev_set_baud(co_dev_t *dev, unsigned int baud)
Sets the supported bit rates of a CANopen device.
const char * order_code
A pointer to the order code.
#define CO_DEFTYPE_REAL32
The data type (and object index) of a 32-bit IEEE-754 floating-point number.
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.
int co_dev_set_product_name(co_dev_t *dev, const char *product_name)
Sets the product name of a CANopen device.
co_unsigned16_t type
The data type.
co_unsigned8_t nsub
The number of sub-objects in subs.
#define CO_INTEGER64_MAX
The maximum value of a 64-bit signed integer.
#define CO_UNSIGNED8_MAX
The maximum value of an 8-bit unsigned integer.
union co_val min
The lower limit of val.
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.
size_t print_c99_esc(char **pbegin, char *end, char32_t c32)
Prints a UTF-8 encoded Unicode character to a memory buffer.
co_unsigned32_t revision
The revision number.
#define CO_OBJECT_RECORD
A multiple data field object where the data fields may be any combination of simple variables.
#define CO_DEFTYPE_INTEGER16
The data type (and object index) of a 16-bit signed integer.
#define CO_DEFTYPE_UNICODE_STRING
The data type (and object index) of an array of (16-bit) Unicode characters.
co_unsigned16_t idx
The object index.
#define CO_REAL64_MAX
The maximum value of a 64-bit IEEE-754 floating-point number.
#define CO_ACCESS_WO
Write-only access.
#define CO_DEFTYPE_INTEGER24
The data type (and object index) of a 24-bit signed integer.
int co_sub_set_access(co_sub_t *sub, unsigned int access)
Sets the access type of a CANopen sub-object.
#define CO_REAL32_MAX
The maximum value of a 32-bit IEEE-754 floating-point number.
int co_dev_get_lss(const co_dev_t *dev)
Returns 1 if LSS is supported and 0 if not.
#define CO_ACCESS_CONST
Constant value.
#define CO_INTEGER24_MIN
The minimum value of a 24-bit signed integer (encoded as an int32_t).
co_unsigned8_t co_obj_get_code(const co_obj_t *obj)
Returns the object code of a CANopen object.
void co_dev_set_vendor_id(co_dev_t *dev, co_unsigned32_t vendor_id)
Sets the vendor ID of a CANopen device.
co_unsigned8_t co_sub_get_subidx(const co_sub_t *sub)
Returns the sub-index of a CANopen sub-object.
int co_dev_set_name(co_dev_t *dev, const char *name)
Sets the name of a CANopen device.
unsigned long flags
The object flags.
co_sub_t * co_sub_create(co_unsigned8_t subidx, co_unsigned16_t type)
Creates a CANopen sub-object.
#define CO_UNSIGNED24_MIN
The minimum value of a 24-bit unsigned integer (encoded as a uint32_t).
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.
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_unsigned16_t nobj
The number of objects in objs.
co_unsigned8_t subidx
The object sub-index.
#define CO_INTEGER16_MAX
The maximum value of a 16-bit signed integer.
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,...
#define CO_OBJ_FLAGS_UPLOAD_FILE
If a read access is performed for the object, the data is stored in a file.
#define CO_INTEGER8_MAX
The maximum value of an 8-bit signed integer.
co_unsigned16_t co_sub_get_type(const co_sub_t *sub)
Returns the data type of a CANopen sub-object.
#define CO_UNSIGNED32_MAX
The maximum value of a 32-bit unsigned integer.
#define CO_ACCESS_RO
Read-only access.
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_DEFTYPE_UNSIGNED40
The data type (and object index) of a 40-bit unsigned integer.
#define CO_INTEGER32_MAX
The maximum value of a 32-bit signed integer.
#define CO_OBJECT_VAR
A single value.
const struct co_ssub * subs
An array of sub-objects.
void co_obj_destroy(co_obj_t *obj)
Destroys a CANopen object, including its sub-objects.
co_unsigned32_t co_dev_get_product_code(const co_dev_t *dev)
Returns the product code of a CANopen device.
#define CO_DEFTYPE_UNSIGNED48
The data type (and object index) of a 48-bit unsigned integer.
#define CO_UNSIGNED56_MIN
The minimum value of a 56-bit unsigned integer (encoded as a uint64_t).
int co_obj_insert_sub(co_obj_t *obj, co_sub_t *sub)
Inserts a sub-object into a CANopen object.
#define CO_UNSIGNED40_MIN
The minimum value of a 40-bit unsigned integer (encoded as a uint64_t).
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.
#define CO_UNSIGNED48_MAX
The maximum value of a 48-bit unsigned integer (encoded as a uint64_t).