Lely core libraries 1.9.2
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
184 size_t size;
186 const void *buf;
188 size_t nbyte;
193 size_t offset;
200};
201
203#define CO_SDO_REQ_INIT \
204 { \
205 0, NULL, 0, 0, MEMBUF_INIT \
206 }
207
208#ifdef __cplusplus
209extern "C" {
210#endif
211
213const char *co_sdo_ac2str(co_unsigned32_t ac);
214
216void co_sdo_req_init(struct co_sdo_req *req);
217
219void co_sdo_req_fini(struct co_sdo_req *req);
220
222void co_sdo_req_clear(struct co_sdo_req *req);
223
228LELY_CO_SDO_INLINE int co_sdo_req_first(const struct co_sdo_req *req);
229
234LELY_CO_SDO_INLINE int co_sdo_req_last(const struct co_sdo_req *req);
235
252int co_sdo_req_dn(struct co_sdo_req *req, const void **pptr, size_t *pnbyte,
253 co_unsigned32_t *pac);
254
271int co_sdo_req_dn_val(struct co_sdo_req *req, co_unsigned16_t type, void *val,
272 co_unsigned32_t *pac);
273
288int co_sdo_req_dn_file(struct co_sdo_req *req, const char *filename,
289 co_unsigned32_t *pac);
290
304int co_sdo_req_up(struct co_sdo_req *req, const void *ptr, size_t n,
305 co_unsigned32_t *pac);
306
321int co_sdo_req_up_val(struct co_sdo_req *req, co_unsigned16_t type,
322 const void *val, co_unsigned32_t *pac);
323
336int co_sdo_req_up_file(struct co_sdo_req *req, const char *filename,
337 co_unsigned32_t *pac);
338
339inline int
340co_sdo_req_first(const struct co_sdo_req *req)
341{
342 return !req->offset;
343}
344
345inline int
346co_sdo_req_last(const struct co_sdo_req *req)
347{
348 return req->offset + req->nbyte >= req->size;
349}
350
351#ifdef __cplusplus
352}
353#endif
354
355#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:340
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:165
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:278
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:251
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:206
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:312
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:346
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:178
size_t offset
The offset of the bytes at buf.
Definition: sdo.h:193
size_t size
The total size (in bytes) of the value to be uploaded/downloaded.
Definition: sdo.h:184
const void * buf
A pointer to the next bytes to be uploaded/downloaded.
Definition: sdo.h:186
size_t nbyte
The number of bytes available at buf.
Definition: sdo.h:188
A memory buffer.
Definition: membuf.h:35
This header file is part of the CANopen library; it contains the CANopen type definitions.