Lely core libraries  2.2.5
sdo.c File Reference
#include "co.h"
#include <lely/util/diag.h>
#include <lely/util/frbuf.h>
#include <lely/util/fwbuf.h>
#include <lely/co/sdo.h>
#include <lely/co/val.h>
#include <assert.h>
Include dependency graph for sdo.c:

Go to the source code of this file.

Functions

static int co_sdo_req_dn_buf (struct co_sdo_req *req, const void **pptr, size_t *pnbyte)
 Copies the next segment of the specified CANopen SDO download request to the internal buffer. More...
 
static void co_sdo_req_up_buf (struct co_sdo_req *req)
 Constructs a CANopen SDO upload request from its internal buffer.
 
const char * co_sdo_ac2str (co_unsigned32_t ac)
 Returns a string describing an SDO abort code.
 
void co_sdo_req_init (struct co_sdo_req *req)
 Initializes a CANopen SDO upload/download request. More...
 
void co_sdo_req_fini (struct co_sdo_req *req)
 Finalizes a CANopen SDO upload/download request. More...
 
void co_sdo_req_clear (struct co_sdo_req *req)
 Clears a CANopen SDO upload/download request, including its buffer.
 
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, on the last segment, returns the buffer. More...
 
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, on the last segment, reads the value. More...
 
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, on the last segment, writes the value to the specified file. More...
 
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. More...
 
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. More...
 
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. More...
 

Detailed Description

This file is part of the CANopen library; it contains the implementation of the Service Data Object (SDO) functions.

See also
lely/co/sdo.h
Author
J. S. Seldenthuis jseld.nosp@m.enth.nosp@m.uis@l.nosp@m.ely..nosp@m.com

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Definition in file sdo.c.

Function Documentation

◆ co_sdo_req_dn_buf()

static int co_sdo_req_dn_buf ( struct co_sdo_req req,
const void **  pptr,
size_t *  pnbyte 
)
static

Copies the next segment of the specified CANopen SDO download request to the internal buffer.

Parameters
reqa pointer to a CANopen SDO download request.
pptrthe address of a pointer which, on success, points to the first byte in the buffer (can be NULL).
pnbytethe address of a value which, on success, contains the total number of bytes in the buffer (can be NULL).
Returns
1 if all segments have been copied, 0 if one or more segments remain, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 369 of file sdo.c.

◆ co_sdo_req_init()

void co_sdo_req_init ( struct co_sdo_req req)

Initializes a CANopen SDO upload/download request.

See also
co_sdo_req_fini()

Definition at line 109 of file sdo.c.

◆ co_sdo_req_fini()

void co_sdo_req_fini ( struct co_sdo_req req)

Finalizes a CANopen SDO upload/download request.

See also
co_sdo_req_init()

Definition at line 121 of file sdo.c.

◆ co_sdo_req_dn()

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, on the last segment, returns the buffer.

Parameters
reqa pointer to a CANopen SDO download request.
pptrthe address of a pointer which, on success, points to the first byte in the buffer (can be NULL).
pnbytethe address of a value which, on success, contains the total number of bytes in the buffer (can be NULL).
pacthe address of a value which, on error, contains the SDO abort code (can be NULL).
Returns
0 if all segments have been copied, and -1 if one or more segments remain or an error has occurred. In the latter case, *pac contains the SDO abort code.

Definition at line 139 of file sdo.c.

◆ co_sdo_req_dn_val()

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, on the last segment, reads the value.

Parameters
reqa pointer to a CANopen SDO download request.
typethe data type of the value.
valthe address of the value to be downloaded (can be NULL).
pacthe address of a value which, on error, contains the SDO abort code (can be NULL).
Returns
0 if all segments have been copied and the value has been read, and -1 if one or more segments remain or an error has occurred. In the latter case, *pac contains the SDO abort code.
See also
co_val_read()

Definition at line 165 of file sdo.c.

◆ co_sdo_req_dn_file()

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, on the last segment, writes the value to the specified file.

Parameters
reqa pointer to a CANopen SDO download request.
filenamea pointer to the name of the file.
pacthe address of a value which, on error, contains the SDO abort code (can be NULL).
Returns
0 if all segments have been copied and the value has been read, and -1 if one or more segments remain or an error has occurred. In the latter case, *pac contains the SDO abort code.

Definition at line 207 of file sdo.c.

◆ co_sdo_req_up()

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.

Parameters
reqa pointer to a CANopen SDO upload request.
ptra pointer to the bytes to be uploaded.
nthe number of bytes at ptr.
pacthe address of a value which, on error, contains the SDO abort code (can be NULL).
Returns
0 on success, or -1 on error. In the latter case, *pac contains the SDO abort code.

Definition at line 253 of file sdo.c.

◆ co_sdo_req_up_val()

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.

Parameters
reqa pointer to a CANopen SDO upload request.
typethe data type of the value.
valthe address of the value to be uploaded. In case of string or domains, this MUST be the address of pointer.
pacthe address of a value which, on error, contains the SDO abort code (can be NULL).
Returns
0 on success, or -1 on error. In the latter case, *pac contains the SDO abort code.

Definition at line 280 of file sdo.c.

◆ co_sdo_req_up_file()

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.

Parameters
reqa pointer to a CANopen SDO upload request.
filenamea pointer to the name of the file.
pacthe address of a value which, on error, contains the SDO abort code (can be NULL).
Returns
0 on success, or -1 on error. In the latter case, *pac contains the SDO abort code.

Definition at line 314 of file sdo.c.