Lely core libraries 2.3.4
csdo.c File Reference

This file is part of the CANopen library; it contains the implementation of the Client-SDO functions. More...

#include "co.h"
#include "sdo.h"
#include <lely/co/crc.h>
#include <lely/co/csdo.h>
#include <lely/co/dev.h>
#include <lely/co/obj.h>
#include <lely/co/val.h>
#include <lely/util/endian.h>
#include <lely/util/errnum.h>
#include <assert.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for csdo.c:

Go to the source code of this file.

Data Structures

struct  co_csdo_dn_dcf
 The state of a concise DCF download request. More...
 
struct  __co_csdo
 A CANopen Client-SDO. More...
 
struct  __co_csdo_state
 A CANopen Client-SDO state. More...
 

Typedefs

typedef const struct __co_csdo_state co_csdo_state_t
 An opaque CANopen Client-SDO state type.
 

Functions

static int co_csdo_update (co_csdo_t *sdo)
 Updates and (de)activates a Client-SDO service.
 
static co_unsigned32_t co_1280_dn_ind (co_sub_t *sub, struct co_sdo_req *req, void *data)
 The download indication function for (all sub-objects of) CANopen objects 1280..12FF (SDO client parameter).
 
static int co_csdo_recv (const struct can_msg *msg, void *data)
 The CAN receive callback function for a Client-SDO service.
 
static int co_csdo_timer (const struct timespec *tp, void *data)
 The CAN timer callback function for a Client-SDO service.
 
static void co_csdo_enter (co_csdo_t *sdo, co_csdo_state_t *next)
 Enters the specified state of a Client-SDO service and invokes the exit and entry functions.
 
static void co_csdo_emit_abort (co_csdo_t *sdo, co_unsigned32_t ac)
 Invokes the 'abort' transition function of the current state of a Client-SDO service.
 
static void co_csdo_emit_time (co_csdo_t *sdo, const struct timespec *tp)
 Invokes the 'timeout' transition function of the current state of a Client-SDO service.
 
static void co_csdo_emit_recv (co_csdo_t *sdo, const struct can_msg *msg)
 Invokes the 'CAN frame received' transition function of the current state of a Client-SDO service.
 
static co_csdo_state_tco_csdo_stopped_on_abort (co_csdo_t *sdo, co_unsigned32_t ac)
 The 'abort' transition function of the 'stopped' state.
 
static co_csdo_state_tco_csdo_wait_on_abort (co_csdo_t *sdo, co_unsigned32_t ac)
 The 'abort' transition function of the 'waiting' state.
 
static co_csdo_state_tco_csdo_wait_on_recv (co_csdo_t *sdo, const struct can_msg *msg)
 The 'CAN frame received' transition function of the 'waiting' state.
 
static co_csdo_state_tco_csdo_abort_on_enter (co_csdo_t *sdo)
 The entry function of the 'abort transfer' state.
 
static void co_csdo_abort_on_leave (co_csdo_t *sdo)
 The exit function of the 'abort transfer' state.
 
static co_csdo_state_tco_csdo_dn_ini_on_abort (co_csdo_t *sdo, co_unsigned32_t ac)
 The 'abort' transition function of the 'download initiate' state.
 
static co_csdo_state_tco_csdo_dn_ini_on_time (co_csdo_t *sdo, const struct timespec *tp)
 The 'timeout' transition function of the 'download initiate' state.
 
static co_csdo_state_tco_csdo_dn_ini_on_recv (co_csdo_t *sdo, const struct can_msg *msg)
 The 'CAN frame received' transition function of the 'download initiate' state.
 
static co_csdo_state_tco_csdo_dn_seg_on_enter (co_csdo_t *sdo)
 The entry function of the 'download segment' state.
 
static co_csdo_state_tco_csdo_dn_seg_on_abort (co_csdo_t *sdo, co_unsigned32_t ac)
 The 'abort' transition function of the 'download segment' state.
 
static co_csdo_state_tco_csdo_dn_seg_on_time (co_csdo_t *sdo, const struct timespec *tp)
 The 'timeout' transition function of the 'download segment' state.
 
static co_csdo_state_tco_csdo_dn_seg_on_recv (co_csdo_t *sdo, const struct can_msg *msg)
 The 'CAN frame received' transition function of the 'download segment' state.
 
static co_csdo_state_tco_csdo_up_ini_on_abort (co_csdo_t *sdo, co_unsigned32_t ac)
 The 'abort' transition function of the 'upload initiate' state.
 
static co_csdo_state_tco_csdo_up_ini_on_time (co_csdo_t *sdo, const struct timespec *tp)
 The 'timeout' transition function of the 'upload initiate' state.
 
static co_csdo_state_tco_csdo_up_ini_on_recv (co_csdo_t *sdo, const struct can_msg *msg)
 The 'CAN frame received' transition function of the 'upload initiate' state.
 
static co_csdo_state_tco_csdo_up_seg_on_abort (co_csdo_t *sdo, co_unsigned32_t ac)
 The 'abort' transition function of the 'upload segment' state.
 
static co_csdo_state_tco_csdo_up_seg_on_time (co_csdo_t *sdo, const struct timespec *tp)
 The 'timeout' transition function of the 'upload segment' state.
 
static co_csdo_state_tco_csdo_up_seg_on_recv (co_csdo_t *sdo, const struct can_msg *msg)
 The 'CAN frame received' transition function of the 'upload segment' state.
 
static co_csdo_state_tco_csdo_blk_dn_ini_on_abort (co_csdo_t *sdo, co_unsigned32_t ac)
 The 'abort' transition function of the 'block download initiate' state.
 
static co_csdo_state_tco_csdo_blk_dn_ini_on_time (co_csdo_t *sdo, const struct timespec *tp)
 The 'timeout' transition function of the 'block download initiate' state.
 
static co_csdo_state_tco_csdo_blk_dn_ini_on_recv (co_csdo_t *sdo, const struct can_msg *msg)
 The 'CAN frame received' transition function of the 'block download initiate' state.
 
static co_csdo_state_tco_csdo_blk_dn_sub_on_enter (co_csdo_t *sdo)
 The entry function of the 'block download sub-block' state.
 
static co_csdo_state_tco_csdo_blk_dn_sub_on_abort (co_csdo_t *sdo, co_unsigned32_t ac)
 The 'abort' transition function of the 'block download sub-block' state.
 
static co_csdo_state_tco_csdo_blk_dn_sub_on_time (co_csdo_t *sdo, const struct timespec *tp)
 The 'timeout' transition function of the 'block download sub-block' state.
 
static co_csdo_state_tco_csdo_blk_dn_sub_on_recv (co_csdo_t *sdo, const struct can_msg *msg)
 The 'CAN frame received' transition function of the 'block download sub-block' state.
 
static co_csdo_state_tco_csdo_blk_dn_end_on_abort (co_csdo_t *sdo, co_unsigned32_t ac)
 The 'abort' transition function of the 'block download end' state.
 
static co_csdo_state_tco_csdo_blk_dn_end_on_time (co_csdo_t *sdo, const struct timespec *tp)
 The 'timeout' transition function of the 'block download end' state.
 
static co_csdo_state_tco_csdo_blk_dn_end_on_recv (co_csdo_t *sdo, const struct can_msg *msg)
 The 'CAN frame received' transition function of the 'block download end' state.
 
static co_csdo_state_tco_csdo_blk_up_ini_on_abort (co_csdo_t *sdo, co_unsigned32_t ac)
 The 'abort' transition function of the 'block upload initiate' state.
 
static co_csdo_state_tco_csdo_blk_up_ini_on_time (co_csdo_t *sdo, const struct timespec *tp)
 The 'timeout' transition function of the 'block upload initiate' state.
 
static co_csdo_state_tco_csdo_blk_up_ini_on_recv (co_csdo_t *sdo, const struct can_msg *msg)
 The 'CAN frame received' transition function of the 'block upload initiate' state.
 
static co_csdo_state_tco_csdo_blk_up_sub_on_abort (co_csdo_t *sdo, co_unsigned32_t ac)
 The 'abort' transition function of the 'block upload sub-block' state.
 
static co_csdo_state_tco_csdo_blk_up_sub_on_time (co_csdo_t *sdo, const struct timespec *tp)
 The 'timeout' transition function of the 'block upload sub-block' state.
 
static co_csdo_state_tco_csdo_blk_up_sub_on_recv (co_csdo_t *sdo, const struct can_msg *msg)
 The 'CAN frame received' transition function of the 'block upload sub-block' state.
 
static co_csdo_state_tco_csdo_blk_up_end_on_abort (co_csdo_t *sdo, co_unsigned32_t ac)
 The 'abort' transition function of the 'block upload end' state.
 
static co_csdo_state_tco_csdo_blk_up_end_on_time (co_csdo_t *sdo, const struct timespec *tp)
 The 'timeout' transition function of the 'block upload end' state.
 
static co_csdo_state_tco_csdo_blk_up_end_on_recv (co_csdo_t *sdo, const struct can_msg *msg)
 The 'CAN frame received' transition function of the 'block upload end' state.
 
static co_csdo_state_tco_csdo_abort_ind (co_csdo_t *sdo, co_unsigned32_t ac)
 Processes an abort transfer indication by aborting any ongoing transfer of a Client-SDO and returning it to the waiting state after notifying the user.
 
static co_csdo_state_tco_csdo_abort_res (co_csdo_t *sdo, co_unsigned32_t ac)
 Sends an abort transfer request and aborts any ongoing transfer by invoking co_csdo_abort_ind().
 
static int co_csdo_dn_ind (co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, const void *ptr, size_t n, co_csdo_dn_con_t *con, void *data)
 Processes a download request from a Client-SDO by checking and updating the state and copying the value to the internal buffer.
 
static int co_csdo_up_ind (co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, struct membuf *buf, co_csdo_up_con_t *con, void *data)
 Processes an upload request from a Client-SDO by checking and updating the state.
 
static void co_csdo_send_abort (co_csdo_t *sdo, co_unsigned32_t ac)
 Sends an abort transfer request.
 
static void co_csdo_send_dn_exp_req (co_csdo_t *sdo)
 Sends a Client-SDO 'download initiate' (expedited) request.
 
static void co_csdo_send_dn_ini_req (co_csdo_t *sdo)
 Sends a Client-SDO 'download initiate' request.
 
static void co_csdo_send_dn_seg_req (co_csdo_t *sdo, co_unsigned32_t n, int last)
 Sends a Client-SDO 'download segment' request.
 
static void co_csdo_send_up_ini_req (co_csdo_t *sdo)
 Sends a Client-SDO 'upload initiate' request.
 
static void co_csdo_send_up_seg_req (co_csdo_t *sdo)
 Sends a Client-SDO 'upload segment' request.
 
static void co_csdo_send_blk_dn_ini_req (co_csdo_t *sdo)
 Sends a Client-SDO 'block download initiate' request.
 
static void co_csdo_send_blk_dn_sub_req (co_csdo_t *sdo, co_unsigned8_t seqno)
 Sends a Client-SDO 'block download sub-block' request.
 
static void co_csdo_send_blk_dn_end_req (co_csdo_t *sdo)
 Sends a Client-SDO 'block download end' request.
 
static void co_csdo_send_blk_up_ini_req (co_csdo_t *sdo, co_unsigned8_t pst)
 Sends a Client-SDO 'block upload initiate' request.
 
static void co_csdo_send_start_up_req (co_csdo_t *sdo)
 Sends a Client-SDO 'start upload' request.
 
static void co_csdo_send_blk_up_sub_res (co_csdo_t *sdo)
 Sends a Client-SDO 'block upload sub-block' response.
 
static void co_csdo_send_blk_up_end_res (co_csdo_t *sdo)
 Sends a Client-SDO 'block upload end' response.
 
static void co_csdo_init_ini_req (co_csdo_t *sdo, struct can_msg *msg, co_unsigned8_t cs)
 Initializes a Client-SDO download/upload initiate request CAN frame.
 
static void co_csdo_init_seg_req (co_csdo_t *sdo, struct can_msg *msg, co_unsigned8_t cs)
 Initializes a Client-SDO download/upload segment request CAN frame.
 
static void co_csdo_dn_dcf_dn_con (co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned32_t ac, void *data)
 The confirmation function of a single SDO download request during a concise DCF download.
 
int co_dev_dn_req (co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx, const void *ptr, size_t n, co_csdo_dn_con_t *con, void *data)
 Submits a download request to a local device.
 
int co_dev_dn_val_req (co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned16_t type, const void *val, co_csdo_dn_con_t *con, void *data)
 Submits a download request to a local device.
 
int co_dev_dn_dcf_req (co_dev_t *dev, const uint_least8_t *begin, const uint_least8_t *end, co_csdo_dn_con_t *con, void *data)
 Submits a series of download requests to a local device.
 
int co_dev_up_req (const co_dev_t *dev, co_unsigned16_t idx, co_unsigned8_t subidx, co_csdo_up_con_t *con, void *data)
 Submits an upload request to a local device.
 
co_csdo_tco_csdo_create (can_net_t *net, co_dev_t *dev, co_unsigned8_t num)
 Creates a new CANopen Client-SDO service.
 
void co_csdo_destroy (co_csdo_t *csdo)
 Destroys a CANopen Client-SDO service.
 
int co_csdo_start (co_csdo_t *sdo)
 Starts a Client-SDO service.
 
void co_csdo_stop (co_csdo_t *sdo)
 Stops a Client-SDO service.
 
int co_csdo_is_stopped (const co_csdo_t *sdo)
 Retuns 1 if the specified Client-SDO service is stopped, and 0 if not.
 
can_net_tco_csdo_get_net (const co_csdo_t *sdo)
 Returns a pointer to the CAN network of a Client-SDO.
 
co_dev_tco_csdo_get_dev (const co_csdo_t *sdo)
 Returns a pointer to the CANopen device of a Client-SDO.
 
co_unsigned8_t co_csdo_get_num (const co_csdo_t *sdo)
 Returns the SDO number of a Client-SDO.
 
const struct co_sdo_parco_csdo_get_par (const co_csdo_t *sdo)
 Returns a pointer to the SDO parameter record of a Client-SDO.
 
int co_csdo_get_timeout (const co_csdo_t *sdo)
 Returns the timeout (in milliseconds) of a Client-SDO.
 
void co_csdo_set_timeout (co_csdo_t *sdo, int timeout)
 Sets the timeout of a Client-SDO.
 
void co_csdo_get_dn_ind (const co_csdo_t *sdo, co_csdo_ind_t **pind, void **pdata)
 Retrieves the indication function used to notify the user of the progress of the current SDO download request.
 
void co_csdo_set_dn_ind (co_csdo_t *sdo, co_csdo_ind_t *ind, void *data)
 Sets the indication function used to notify the user of the progress of the current SDO download request.
 
void co_csdo_get_up_ind (const co_csdo_t *sdo, co_csdo_ind_t **pind, void **pdata)
 Retrieves the indication function used to notify the user of the progress of the current SDO upload request.
 
void co_csdo_set_up_ind (co_csdo_t *sdo, co_csdo_ind_t *ind, void *data)
 Sets the indication function used to notify the user of the progress of the current SDO upload request.
 
int co_csdo_is_valid (const co_csdo_t *sdo)
 Returns 1 of the COB-IDs of the specified Client-SDO service are valid, and 0 if not.
 
int co_csdo_is_idle (const co_csdo_t *sdo)
 Returns 1 if the specified Client-SDO service is idle, and 0 if a transfer is ongoing.
 
void co_csdo_abort_req (co_csdo_t *sdo, co_unsigned32_t ac)
 Submits an abort transfer request to a remote Server-SDO.
 
int co_csdo_dn_req (co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, const void *ptr, size_t n, co_csdo_dn_con_t *con, void *data)
 Submits a download request to a remote Server-SDO.
 
int co_csdo_dn_val_req (co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned16_t type, const void *val, co_csdo_dn_con_t *con, void *data)
 Submits a download request to a remote Server-SDO.
 
int co_csdo_dn_dcf_req (co_csdo_t *sdo, const uint_least8_t *begin, const uint_least8_t *end, co_csdo_dn_con_t *con, void *data)
 Submits a series of download requests to a remote Server-SDO.
 
int co_csdo_up_req (co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_csdo_up_con_t *con, void *data)
 Submits an upload request to a remote Server-SDO.
 
int co_csdo_blk_dn_req (co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, const void *ptr, size_t n, co_csdo_dn_con_t *con, void *data)
 Submits a block download request to a remote Server-SDO.
 
int co_csdo_blk_dn_val_req (co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned16_t type, const void *val, co_csdo_dn_con_t *con, void *data)
 Submits a block download request to a remote Server-SDO.
 
int co_csdo_blk_up_req (co_csdo_t *sdo, co_unsigned16_t idx, co_unsigned8_t subidx, co_unsigned8_t pst, co_csdo_up_con_t *con, void *data)
 Submits a block upload request to a remote Server-SDO.
 

Variables

static co_csdo_state_t *const co_csdo_stopped_state = &(co_csdo_state_t){ .on_abort = &co_csdo_stopped_on_abort }
 The 'stopped' state.
 
static co_csdo_state_t *const co_csdo_wait_state = &(co_csdo_state_t){ .on_abort = &co_csdo_wait_on_abort, .on_recv = &co_csdo_wait_on_recv }
 The 'waiting' state.
 
static co_csdo_state_t *const co_csdo_abort_state = &(co_csdo_state_t){ .on_enter = &co_csdo_abort_on_enter, .on_leave = &co_csdo_abort_on_leave }
 The 'abort transfer' state.
 
static co_csdo_state_t *const co_csdo_dn_ini_state = &(co_csdo_state_t){ .on_abort = &co_csdo_dn_ini_on_abort, .on_time = &co_csdo_dn_ini_on_time, .on_recv = &co_csdo_dn_ini_on_recv }
 The 'download initiate' state.
 
static co_csdo_state_t *const co_csdo_dn_seg_state = &(co_csdo_state_t){ .on_enter = &co_csdo_dn_seg_on_enter, .on_abort = &co_csdo_dn_seg_on_abort, .on_time = &co_csdo_dn_seg_on_time, .on_recv = &co_csdo_dn_seg_on_recv }
 The 'download segment' state.
 
static co_csdo_state_t *const co_csdo_up_ini_state = &(co_csdo_state_t){ .on_abort = &co_csdo_up_ini_on_abort, .on_time = &co_csdo_up_ini_on_time, .on_recv = &co_csdo_up_ini_on_recv }
 The 'upload initiate' state.
 
static co_csdo_state_t *const co_csdo_up_seg_state = &(co_csdo_state_t){ .on_abort = &co_csdo_up_seg_on_abort, .on_time = &co_csdo_up_seg_on_time, .on_recv = &co_csdo_up_seg_on_recv }
 The 'upload segment' state.
 
static co_csdo_state_t *const co_csdo_blk_dn_ini_state = &(co_csdo_state_t){ .on_abort = &co_csdo_blk_dn_ini_on_abort, .on_time = &co_csdo_blk_dn_ini_on_time, .on_recv = &co_csdo_blk_dn_ini_on_recv }
 The 'block download initiate' state.
 
static co_csdo_state_t *const co_csdo_blk_dn_sub_state = &(co_csdo_state_t){ .on_enter = &co_csdo_blk_dn_sub_on_enter, .on_abort = &co_csdo_blk_dn_sub_on_abort, .on_time = &co_csdo_blk_dn_sub_on_time, .on_recv = &co_csdo_blk_dn_sub_on_recv }
 The 'block download sub-block' state.
 
static co_csdo_state_t *const co_csdo_blk_dn_end_state = &(co_csdo_state_t){ .on_abort = &co_csdo_blk_dn_end_on_abort, .on_time = &co_csdo_blk_dn_end_on_time, .on_recv = &co_csdo_blk_dn_end_on_recv }
 The 'block download end' state.
 
static co_csdo_state_t *const co_csdo_blk_up_ini_state = &(co_csdo_state_t){ .on_abort = &co_csdo_blk_up_ini_on_abort, .on_time = &co_csdo_blk_up_ini_on_time, .on_recv = &co_csdo_blk_up_ini_on_recv }
 The 'block upload initiate' state.
 
static co_csdo_state_t *const co_csdo_blk_up_sub_state = &(co_csdo_state_t){ .on_abort = &co_csdo_blk_up_sub_on_abort, .on_time = &co_csdo_blk_up_sub_on_time, .on_recv = &co_csdo_blk_up_sub_on_recv }
 The 'block upload sub-block' state.
 
static co_csdo_state_t *const co_csdo_blk_up_end_state = &(co_csdo_state_t){ .on_abort = &co_csdo_blk_up_end_on_abort, .on_time = &co_csdo_blk_up_end_on_time, .on_recv = &co_csdo_blk_up_end_on_recv }
 The 'block upload end' state.
 

Detailed Description

This file is part of the CANopen library; it contains the implementation of the Client-SDO functions.

See also
lely/co/csdo.h, src/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 csdo.c.

Function Documentation

◆ co_csdo_update()

static int co_csdo_update ( co_csdo_t sdo)
static

Updates and (de)activates a Client-SDO service.

This function is invoked when one of the SDO client parameters (objects 1280..12FF) is updated.

Returns
0 on success, or -1 on error.

Definition at line 1378 of file csdo.c.

◆ co_1280_dn_ind()

static co_unsigned32_t co_1280_dn_ind ( co_sub_t sub,
struct co_sdo_req req,
void *  data 
)
static

The download indication function for (all sub-objects of) CANopen objects 1280..12FF (SDO client parameter).

See also
co_sub_dn_ind_t

Definition at line 1403 of file csdo.c.

◆ co_csdo_recv()

static int co_csdo_recv ( const struct can_msg msg,
void *  data 
)
static

The CAN receive callback function for a Client-SDO service.

See also
can_recv_func_t

Definition at line 1489 of file csdo.c.

◆ co_csdo_timer()

static int co_csdo_timer ( const struct timespec tp,
void *  data 
)
static

The CAN timer callback function for a Client-SDO service.

See also
can_timer_func_t

Definition at line 1511 of file csdo.c.

◆ co_csdo_emit_abort()

static void co_csdo_emit_abort ( co_csdo_t sdo,
co_unsigned32_t  ac 
)
inlinestatic

Invokes the 'abort' transition function of the current state of a Client-SDO service.

Parameters
sdoa pointer to a Client-SDO service.
acthe abort code.

Definition at line 1540 of file csdo.c.

◆ co_csdo_emit_time()

static void co_csdo_emit_time ( co_csdo_t sdo,
const struct timespec tp 
)
inlinestatic

Invokes the 'timeout' transition function of the current state of a Client-SDO service.

Parameters
sdoa pointer to a Client-SDO service.
tpa pointer to the current time.

Definition at line 1550 of file csdo.c.

◆ co_csdo_emit_recv()

static void co_csdo_emit_recv ( co_csdo_t sdo,
const struct can_msg msg 
)
inlinestatic

Invokes the 'CAN frame received' transition function of the current state of a Client-SDO service.

Parameters
sdoa pointer to a Client-SDO service.
msga pointer to the received CAN frame.

Definition at line 1560 of file csdo.c.

◆ co_csdo_abort_ind()

static co_csdo_state_t * co_csdo_abort_ind ( co_csdo_t sdo,
co_unsigned32_t  ac 
)
static

Processes an abort transfer indication by aborting any ongoing transfer of a Client-SDO and returning it to the waiting state after notifying the user.

Returns
co_csdo_wait_state

Definition at line 2283 of file csdo.c.

◆ co_csdo_abort_res()

static co_csdo_state_t * co_csdo_abort_res ( co_csdo_t sdo,
co_unsigned32_t  ac 
)
static

Sends an abort transfer request and aborts any ongoing transfer by invoking co_csdo_abort_ind().

Parameters
sdoa pointer to a Client-SDO service.
acthe SDO abort code.
Returns
co_csdo_wait_state
See also
co_csdo_send_abort()

Definition at line 2292 of file csdo.c.

◆ co_csdo_dn_ind()

static int co_csdo_dn_ind ( co_csdo_t sdo,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
const void *  ptr,
size_t  n,
co_csdo_dn_con_t con,
void *  data 
)
static

Processes a download request from a Client-SDO by checking and updating the state and copying the value to the internal buffer.

Returns
0 on success, or -1 on error.
See also
co_csdo_dn_req(), co_csdo_blk_dn_req()

Definition at line 2299 of file csdo.c.

◆ co_csdo_up_ind()

static int co_csdo_up_ind ( co_csdo_t sdo,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
struct membuf buf,
co_csdo_up_con_t con,
void *  data 
)
static

Processes an upload request from a Client-SDO by checking and updating the state.

Returns
0 on success, or -1 on error.
See also
co_csdo_up_req(), co_csdo_blk_up_req()

Definition at line 2334 of file csdo.c.

◆ co_csdo_send_abort()

static void co_csdo_send_abort ( co_csdo_t sdo,
co_unsigned32_t  ac 
)
static

Sends an abort transfer request.

Parameters
sdoa pointer to a Server-SDO service.
acthe SDO abort code.

Definition at line 2368 of file csdo.c.

◆ co_csdo_send_dn_seg_req()

static void co_csdo_send_dn_seg_req ( co_csdo_t sdo,
co_unsigned32_t  n,
int  last 
)
static

Sends a Client-SDO 'download segment' request.

Parameters
sdoa pointer to a Client-SDO service.
nthe number of bytes to be sent in this segment (in the range [1..7]).
lasta flag indicating whether this is the last segment.

Definition at line 2414 of file csdo.c.

◆ co_csdo_send_blk_dn_sub_req()

static void co_csdo_send_blk_dn_sub_req ( co_csdo_t sdo,
co_unsigned8_t  seqno 
)
static

Sends a Client-SDO 'block download sub-block' request.

Parameters
sdoa pointer to a Client-SDO service.
seqnothe sequence number (in the range [1..127]).

Definition at line 2478 of file csdo.c.

◆ co_csdo_send_blk_up_ini_req()

static void co_csdo_send_blk_up_ini_req ( co_csdo_t sdo,
co_unsigned8_t  pst 
)
static

Sends a Client-SDO 'block upload initiate' request.

Parameters
sdoa pointer to a Client-SDO service.
pstthe protocol switch threshold.

Definition at line 2522 of file csdo.c.

◆ co_csdo_init_ini_req()

static void co_csdo_init_ini_req ( co_csdo_t sdo,
struct can_msg msg,
co_unsigned8_t  cs 
)
static

Initializes a Client-SDO download/upload initiate request CAN frame.

Parameters
sdoa pointer to a Client-SDO service.
msga pointer to the CAN frame to be initialized.
csthe command specifier.

Definition at line 2585 of file csdo.c.

◆ co_csdo_init_seg_req()

static void co_csdo_init_seg_req ( co_csdo_t sdo,
struct can_msg msg,
co_unsigned8_t  cs 
)
static

Initializes a Client-SDO download/upload segment request CAN frame.

Parameters
sdoa pointer to a Client-SDO service.
msga pointer to the CAN frame to be initialized.
csthe command specifier.

Definition at line 2605 of file csdo.c.

◆ co_csdo_dn_dcf_dn_con()

static void co_csdo_dn_dcf_dn_con ( co_csdo_t sdo,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
co_unsigned32_t  ac,
void *  data 
)
static

The confirmation function of a single SDO download request during a concise DCF download.

See also
co_csdo_dn_dcf_req()

Definition at line 2623 of file csdo.c.

◆ co_dev_dn_req()

int co_dev_dn_req ( co_dev_t dev,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
const void *  ptr,
size_t  n,
co_csdo_dn_con_t con,
void *  data 
)

Submits a download request to a local device.

This is equivalent to a write operation into an dictionary.

Parameters
deva pointer to CANopen device.
idxthe remote object index.
subidxthe remote object sub-index.
ptra pointer to the bytes to be downloaded.
nthe number of bytes at ptr.
cona pointer to the confirmation function (can be NULL).
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to con.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 664 of file csdo.c.

◆ co_dev_dn_val_req()

int co_dev_dn_val_req ( co_dev_t dev,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
co_unsigned16_t  type,
const void *  val,
co_csdo_dn_con_t con,
void *  data 
)

Submits a download request to a local device.

This is equivalent to a write operation into an object dictionary.

Parameters
deva pointer to CANopen device.
idxthe remote object index.
subidxthe remote object sub-index.
typethe data type (in the range [1..27]). This MUST be the object index of one of the static data types.
valthe address of the value to be written. In case of string or domains, this MUST be the address of pointer.
cona pointer to the confirmation function (can be NULL).
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to con.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 701 of file csdo.c.

◆ co_dev_dn_dcf_req()

int co_dev_dn_dcf_req ( co_dev_t dev,
const uint_least8_t *  begin,
const uint_least8_t *  end,
co_csdo_dn_con_t con,
void *  data 
)

Submits a series of download requests to a local device.

This function calls co_dev_dn_req() for each entry in the specified concise DCF.

Parameters
deva pointer to CANopen device.
begina pointer the the first byte in a concise DCF (see object 1F22 in CiA 302-3 version 4.1.0).
enda pointer to one past the last byte in the concise DCF. At most end - begin bytes are read.
cona pointer to the confirmation function (can be NULL).
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to con.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 739 of file csdo.c.

◆ co_dev_up_req()

int co_dev_up_req ( const co_dev_t dev,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
co_csdo_up_con_t con,
void *  data 
)

Submits an upload request to a local device.

This is equivalent to a read operation from an object dictionary.

Parameters
deva pointer to CANopen device.
idxthe remote object index.
subidxthe remote object sub-index.
cona pointer to the confirmation function (can be NULL).
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to con.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 812 of file csdo.c.

◆ co_csdo_create()

co_csdo_t * co_csdo_create ( can_net_t net,
co_dev_t dev,
co_unsigned8_t  num 
)

Creates a new CANopen Client-SDO service.

The service is started as if by co_csdo_start().

Parameters
neta pointer to a CAN network.
deva pointer to a CANopen device describing the client (can be NULL).
numthe SDO number (in the range [1..128]). The SDO parameter record MUST exist in the object dictionary of dev. However, if dev is NULL, num is interpreted as a node-ID (in the range [1..127]) and the default SDO parameters are used.
Returns
a pointer to a new Client-SDO service, or NULL on error. In the latter case, the error number can be obtained with get_errc().
See also
co_csdo_destroy()

Definition at line 997 of file csdo.c.

◆ co_csdo_destroy()

void co_csdo_destroy ( co_csdo_t sdo)

Destroys a CANopen Client-SDO service.

See also
co_csdo_create()

Definition at line 1024 of file csdo.c.

◆ co_csdo_start()

int co_csdo_start ( co_csdo_t sdo)

Starts a Client-SDO service.

Postcondition
on success, co_csdo_is_stopped() returns 0.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().
See also
co_csdo_stop()

Definition at line 1034 of file csdo.c.

◆ co_csdo_stop()

void co_csdo_stop ( co_csdo_t sdo)

Stops a Client-SDO service.

Any ongoing request is aborted.

Postcondition
co_csdo_is_stopped() returns 1.
See also
co_csdo_start()

Definition at line 1069 of file csdo.c.

◆ co_csdo_is_stopped()

int co_csdo_is_stopped ( const co_csdo_t sdo)

Retuns 1 if the specified Client-SDO service is stopped, and 0 if not.

See also
co_csdo_start, co_csdo_stop()

Definition at line 1094 of file csdo.c.

◆ co_csdo_get_timeout()

int co_csdo_get_timeout ( const co_csdo_t sdo)

Returns the timeout (in milliseconds) of a Client-SDO.

A return value of 0 (the default) means no timeout is being used.

See also
co_csdo_set_timeout()

Definition at line 1134 of file csdo.c.

◆ co_csdo_set_timeout()

void co_csdo_set_timeout ( co_csdo_t sdo,
int  timeout 
)

Sets the timeout of a Client-SDO.

If the timeout expires before receiving a response from a server, the client aborts the transfer.

Parameters
sdoa pointer to a Client-SDO service.
timeoutthe timeout (in milliseconds). A value of 0 (the default) disables the timeout.
See also
co_csdo_get_timeout()

Definition at line 1142 of file csdo.c.

◆ co_csdo_get_dn_ind()

void co_csdo_get_dn_ind ( const co_csdo_t sdo,
co_csdo_ind_t **  pind,
void **  pdata 
)

Retrieves the indication function used to notify the user of the progress of the current SDO download request.

Parameters
sdoa pointer to a Client-SDO service.
pindthe address at which to store a pointer to the indication function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
co_csdo_set_dn_ind()

Definition at line 1153 of file csdo.c.

◆ co_csdo_set_dn_ind()

void co_csdo_set_dn_ind ( co_csdo_t sdo,
co_csdo_ind_t ind,
void *  data 
)

Sets the indication function used to notify the user of the progress of the current SDO download request.

Parameters
sdoa pointer to a Client-SDO service.
inda pointer to the function to be invoked.
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to ind.
See also
co_csdo_get_dn_ind()

Definition at line 1164 of file csdo.c.

◆ co_csdo_get_up_ind()

void co_csdo_get_up_ind ( const co_csdo_t sdo,
co_csdo_ind_t **  pind,
void **  pdata 
)

Retrieves the indication function used to notify the user of the progress of the current SDO upload request.

Parameters
sdoa pointer to a Client-SDO service.
pindthe address at which to store a pointer to the indication function (can be NULL).
pdatathe address at which to store a pointer to user-specified data (can be NULL).
See also
co_csdo_set_up_ind()

Definition at line 1173 of file csdo.c.

◆ co_csdo_set_up_ind()

void co_csdo_set_up_ind ( co_csdo_t sdo,
co_csdo_ind_t ind,
void *  data 
)

Sets the indication function used to notify the user of the progress of the current SDO upload request.

Parameters
sdoa pointer to a Client-SDO service.
inda pointer to the function to be invoked.
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to ind.
See also
co_csdo_get_up_ind()

Definition at line 1184 of file csdo.c.

◆ co_csdo_abort_req()

void co_csdo_abort_req ( co_csdo_t sdo,
co_unsigned32_t  ac 
)

Submits an abort transfer request to a remote Server-SDO.

This function has no effect if the Client-SDO service is idle (see co_csdo_is_idle()).

Parameters
sdoa pointer to a Client-SDO service.
acthe abort code.

Definition at line 1211 of file csdo.c.

◆ co_csdo_dn_req()

int co_csdo_dn_req ( co_csdo_t sdo,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
const void *  ptr,
size_t  n,
co_csdo_dn_con_t con,
void *  data 
)

Submits a download request to a remote Server-SDO.

This requests the server to download the value and is equivalent to a write operation into a remote object dictionary. Note that the request will fail if another transfer is in progress (see co_csdo_is_idle()).

Parameters
sdoa pointer to a Client-SDO service.
idxthe remote object index.
subidxthe remote object sub-index.
ptra pointer to the bytes to be downloaded. It is the responsibility of the user to ensure that the buffer remains valid until the operation completes.
nthe number of bytes at ptr.
cona pointer to the confirmation function (can be NULL).
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to con.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 1219 of file csdo.c.

◆ co_csdo_dn_val_req()

int co_csdo_dn_val_req ( co_csdo_t sdo,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
co_unsigned16_t  type,
const void *  val,
co_csdo_dn_con_t con,
void *  data 
)

Submits a download request to a remote Server-SDO.

This requests the server to download the value and is equivalent to a write operation into a remote object dictionary. Note that the request will fail if another transfer is in progress (see co_csdo_is_idle()).

Parameters
sdoa pointer to a Client-SDO service.
idxthe remote object index.
subidxthe remote object sub-index.
typethe data type (in the range [1..27]). This MUST be the object index of one of the static data types.
valthe address of the value to be written. In case of string or domains, this MUST be the address of pointer.
cona pointer to the confirmation function (can be NULL).
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to con.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 1241 of file csdo.c.

◆ co_csdo_dn_dcf_req()

int co_csdo_dn_dcf_req ( co_csdo_t sdo,
const uint_least8_t *  begin,
const uint_least8_t *  end,
co_csdo_dn_con_t con,
void *  data 
)

Submits a series of download requests to a remote Server-SDO.

This function calls co_csdo_dn_req() for each entry in the specified concise DCF.

Parameters
sdoa pointer to a Client-SDO service.
begina pointer the the first byte in a concise DCF (see object 1F22 in CiA 302-3 version 4.1.0).
enda pointer to one past the last byte in the concise DCF. At most end - begin bytes are read.
cona pointer to the confirmation function (can be NULL).
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to con.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 1265 of file csdo.c.

◆ co_csdo_up_req()

int co_csdo_up_req ( co_csdo_t sdo,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
co_csdo_up_con_t con,
void *  data 
)

Submits an upload request to a remote Server-SDO.

This requests the server to upload the value and is equivalent to a read operation from a remote object dictionary. Note that the request will fail if another transfer is in progress (see co_csdo_is_idle()).

Parameters
sdoa pointer to a Client-SDO service.
idxthe remote object index.
subidxthe remote object sub-index.
cona pointer to the confirmation function (can be NULL).
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to con.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 1294 of file csdo.c.

◆ co_csdo_blk_dn_req()

int co_csdo_blk_dn_req ( co_csdo_t sdo,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
const void *  ptr,
size_t  n,
co_csdo_dn_con_t con,
void *  data 
)

Submits a block download request to a remote Server-SDO.

This requests the server to download the value and is equivalent to a write operation into a remote object dictionary. Note that the request will fail if another transfer is in progress (see co_csdo_is_idle()).

Parameters
sdoa pointer to a Client-SDO service.
idxthe remote object index.
subidxthe remote object sub-index.
ptra pointer to the bytes to be downloaded.
nthe number of bytes at ptr.
cona pointer to the confirmation function (can be NULL).
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to con.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 1313 of file csdo.c.

◆ co_csdo_blk_dn_val_req()

int co_csdo_blk_dn_val_req ( co_csdo_t sdo,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
co_unsigned16_t  type,
const void *  val,
co_csdo_dn_con_t con,
void *  data 
)

Submits a block download request to a remote Server-SDO.

This requests the server to download the value and is equivalent to a write operation into a remote object dictionary. Note that the request will fail if another transfer is in progress (see co_csdo_is_idle()).

Parameters
sdoa pointer to a Client-SDO service.
idxthe remote object index.
subidxthe remote object sub-index.
typethe data type (in the range [1..27]). This MUST be the object index of one of the static data types.
valthe address of the value to be written. In case of string or domains, this MUST be the address of pointer.
cona pointer to the confirmation function (can be NULL).
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to con.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 1332 of file csdo.c.

◆ co_csdo_blk_up_req()

int co_csdo_blk_up_req ( co_csdo_t sdo,
co_unsigned16_t  idx,
co_unsigned8_t  subidx,
co_unsigned8_t  pst,
co_csdo_up_con_t con,
void *  data 
)

Submits a block upload request to a remote Server-SDO.

This requests the server to upload the value and is equivalent to a read operation from a remote object dictionary. Note that the request will fail if another transfer is in progress (see co_csdo_is_idle()).

Parameters
sdoa pointer to a Client-SDO service.
idxthe remote object index.
subidxthe remote object sub-index.
pstthe protocol switch threshold. If pst is non-zero, and the number of bytes to be uploaded is less than or equal to pst, the server may switch to the SDO upload protocol.
cona pointer to the confirmation function (can be NULL).
dataa pointer to user-specified data (can be NULL). data is passed as the last parameter to con.
Returns
0 on success, or -1 on error. In the latter case, the error number can be obtained with get_errc().

Definition at line 1356 of file csdo.c.