Lely core libraries 2.3.4
sdo.h
Go to the documentation of this file.
1
22#ifndef LELY_CO_SDO_H_
23#define LELY_CO_SDO_H_
24
25#include <lely/co/type.h>
26#include <lely/util/membuf.h>
27
28#ifndef LELY_CO_SDO_INLINE
29#define LELY_CO_SDO_INLINE static inline
30#endif
31
33#define CO_SDO_COBID_VALID UINT32_C(0x80000000)
34
39#define CO_SDO_COBID_FRAME UINT32_C(0x20000000)
40
42#define CO_DEFSTRUCT_SDO_PAR 0x0022
43
45struct co_sdo_par {
47 co_unsigned8_t n;
49 co_unsigned32_t cobid_req;
51 co_unsigned32_t cobid_res;
53 co_unsigned8_t id;
54};
55
57#define CO_SDO_PAR_INIT \
58 { \
59 3, CO_SDO_COBID_VALID, CO_SDO_COBID_VALID, 0 \
60 }
61
63#define CO_SDO_AC_TOGGLE UINT32_C(0x05030000)
64
66#define CO_SDO_AC_TIMEOUT UINT32_C(0x05040000)
67
69#define CO_SDO_AC_NO_CS UINT32_C(0x05040001)
70
72#define CO_SDO_AC_BLK_SIZE UINT32_C(0x05040002)
73
75#define CO_SDO_AC_BLK_SEQ UINT32_C(0x05040003)
76
78#define CO_SDO_AC_BLK_CRC UINT32_C(0x05040004)
79
81#define CO_SDO_AC_NO_MEM UINT32_C(0x05040005)
82
84#define CO_SDO_AC_NO_ACCESS UINT32_C(0x06010000)
85
87#define CO_SDO_AC_NO_READ UINT32_C(0x06010001)
88
90#define CO_SDO_AC_NO_WRITE UINT32_C(0x06010002)
91
93#define CO_SDO_AC_NO_OBJ UINT32_C(0x06020000)
94
96#define CO_SDO_AC_NO_PDO UINT32_C(0x06040041)
97
102#define CO_SDO_AC_PDO_LEN UINT32_C(0x06040042)
103
105#define CO_SDO_AC_PARAM UINT32_C(0x06040043)
106
108#define CO_SDO_AC_COMPAT UINT32_C(0x06040047)
109
111#define CO_SDO_AC_HARDWARE UINT32_C(0x06060000)
112
117#define CO_SDO_AC_TYPE_LEN UINT32_C(0x06070010)
118
123#define CO_SDO_AC_TYPE_LEN_HI UINT32_C(0x06070012)
124
129#define CO_SDO_AC_TYPE_LEN_LO UINT32_C(0x06070013)
130
132#define CO_SDO_AC_NO_SUB UINT32_C(0x06090011)
133
135#define CO_SDO_AC_PARAM_VAL UINT32_C(0x06090030)
136
138#define CO_SDO_AC_PARAM_HI UINT32_C(0x06090031)
139
141#define CO_SDO_AC_PARAM_LO UINT32_C(0x06090032)
142
144#define CO_SDO_AC_PARAM_RANGE UINT32_C(0x06090036)
145
147#define CO_SDO_AC_NO_SDO UINT32_C(0x060a0023)
148
150#define CO_SDO_AC_ERROR UINT32_C(0x08000000)
151
153#define CO_SDO_AC_DATA UINT32_C(0x08000020)
154
159#define CO_SDO_AC_DATA_CTL UINT32_C(0x08000021)
160
165#define CO_SDO_AC_DATA_DEV UINT32_C(0x08000022)
166
172#define CO_SDO_AC_NO_OD UINT32_C(0x08000023)
173
175#define CO_SDO_AC_NO_DATA UINT32_C(0x08000024)
176
178#define CO_NUM_SDOS 128
179
187 size_t size;
189 const void *buf;
191 size_t nbyte;
196 size_t offset;
203};
204
206#define CO_SDO_REQ_INIT \
207 { \
208 0, NULL, 0, 0, MEMBUF_INIT \
209 }
210
211#ifdef __cplusplus
212extern "C" {
213#endif
214
216const char *co_sdo_ac2str(co_unsigned32_t ac);
217
219void co_sdo_req_init(struct co_sdo_req *req);
220
222void co_sdo_req_fini(struct co_sdo_req *req);
223
225void co_sdo_req_clear(struct co_sdo_req *req);
226
231LELY_CO_SDO_INLINE int co_sdo_req_first(const struct co_sdo_req *req);
232
237LELY_CO_SDO_INLINE int co_sdo_req_last(const struct co_sdo_req *req);
238
255int co_sdo_req_dn(struct co_sdo_req *req, const void **pptr, size_t *pnbyte,
256 co_unsigned32_t *pac);
257
274int co_sdo_req_dn_val(struct co_sdo_req *req, co_unsigned16_t type, void *val,
275 co_unsigned32_t *pac);
276
291int co_sdo_req_dn_file(struct co_sdo_req *req, const char *filename,
292 co_unsigned32_t *pac);
293
307int co_sdo_req_up(struct co_sdo_req *req, const void *ptr, size_t n,
308 co_unsigned32_t *pac);
309
324int co_sdo_req_up_val(struct co_sdo_req *req, co_unsigned16_t type,
325 const void *val, co_unsigned32_t *pac);
326
339int co_sdo_req_up_file(struct co_sdo_req *req, const char *filename,
340 co_unsigned32_t *pac);
341
342LELY_CO_SDO_INLINE int
343co_sdo_req_first(const struct co_sdo_req *req)
344{
345 return !req->offset;
346}
347
348LELY_CO_SDO_INLINE int
349co_sdo_req_last(const struct co_sdo_req *req)
350{
351 return req->offset + req->nbyte >= req->size;
352}
353
354#ifdef __cplusplus
355}
356#endif
357
358#endif // !LELY_CO_SDO_H_
int co_sdo_req_first(const struct co_sdo_req *req)
Returns 1 if the specified request includes the first segment, and 0 otherwise.
Definition: sdo.h:343
int co_sdo_req_dn_val(struct co_sdo_req *req, co_unsigned16_t type, void *val, co_unsigned32_t *pac)
Copies the next segment of the specified CANopen SDO download request to the internal buffer and,...
Definition: sdo.c:170
int co_sdo_req_up_val(struct co_sdo_req *req, co_unsigned16_t type, const void *val, co_unsigned32_t *pac)
Writes the specified value to a buffer and constructs a CANopen SDO upload request.
Definition: sdo.c:287
int co_sdo_req_up(struct co_sdo_req *req, const void *ptr, size_t n, co_unsigned32_t *pac)
Writes the specified bytes to a buffer and constructs a CANopen SDO upload request.
Definition: sdo.c:258
void co_sdo_req_fini(struct co_sdo_req *req)
Finalizes a CANopen SDO upload/download request.
Definition: sdo.c:121
int co_sdo_req_dn_file(struct co_sdo_req *req, const char *filename, co_unsigned32_t *pac)
Copies the next segment of the specified CANopen SDO download request to the internal buffer and,...
Definition: sdo.c:212
int co_sdo_req_up_file(struct co_sdo_req *req, const char *filename, co_unsigned32_t *pac)
Loads the specified file into a buffer and constructs a CANopen SDO upload request.
Definition: sdo.c:323
void co_sdo_req_clear(struct co_sdo_req *req)
Clears a CANopen SDO upload/download request, including its buffer.
Definition: sdo.c:129
const char * co_sdo_ac2str(co_unsigned32_t ac)
Returns a string describing an SDO abort code.
Definition: sdo.c:57
int co_sdo_req_last(const struct co_sdo_req *req)
Returns 1 if the specified request includes the last segment, and 0 otherwise.
Definition: sdo.h:349
void co_sdo_req_init(struct co_sdo_req *req)
Initializes a CANopen SDO upload/download request.
Definition: sdo.c:109
int co_sdo_req_dn(struct co_sdo_req *req, const void **pptr, size_t *pnbyte, co_unsigned32_t *pac)
Copies the next segment of the specified CANopen SDO download request to the internal buffer and,...
Definition: sdo.c:139
This header file is part of the utilities library; it contains the memory buffer declarations.
An SDO parameter record.
Definition: sdo.h:45
co_unsigned32_t cobid_res
COB-ID server -> client.
Definition: sdo.h:51
co_unsigned8_t n
Highest sub-index supported.
Definition: sdo.h:47
co_unsigned32_t cobid_req
COB-ID client -> server.
Definition: sdo.h:49
co_unsigned8_t id
Node-ID of SDO's client resp. server.
Definition: sdo.h:53
A CANopen SDO upload/download request.
Definition: sdo.h:181
size_t offset
The offset of the bytes at buf.
Definition: sdo.h:196
size_t size
The total size (in bytes) of the value to be uploaded/downloaded.
Definition: sdo.h:187
const void * buf
A pointer to the next bytes to be uploaded/downloaded.
Definition: sdo.h:189
size_t nbyte
The number of bytes available at buf.
Definition: sdo.h:191
A memory buffer.
Definition: membuf.h:36
This header file is part of the CANopen library; it contains the CANopen type definitions.