CANopenNode
SDO client

Files

file  CO_SDOclient.h
 CANopen Service Data Object - client protocol.
 

Data Structures

struct  CO_SDOclient_t
 SDO client object. More...
 

Functions

CO_ReturnError_t CO_SDOclient_init (CO_SDOclient_t *SDO_C, const OD_t *OD, const OD_entry_t *OD_1280_SDOcliPar, uint8_t nodeId, CO_CANmodule_t *CANdevRx, uint16_t CANdevRxIdx, CO_CANmodule_t *CANdevTx, uint16_t CANdevTxIdx)
 Initialize SDO client object. More...
 
void CO_SDOclient_initCallbackPre (CO_SDOclient_t *SDOclient, void *object, void(*pFunctSignal)(void *object))
 Initialize SDOclient callback function. More...
 
CO_SDO_return_t CO_SDOclient_setup (CO_SDOclient_t *SDO_C, uint32_t COB_IDClientToServer, uint32_t COB_IDServerToClient, uint8_t nodeIDOfTheSDOServer)
 Setup SDO client object. More...
 
CO_SDO_return_t CO_SDOclientDownloadInitiate (CO_SDOclient_t *SDO_C, uint16_t index, uint8_t subIndex, size_t sizeIndicated, uint16_t SDOtimeoutTime_ms, bool_t blockEnable)
 Initiate SDO download communication. More...
 
void CO_SDOclientDownloadInitiateSize (CO_SDOclient_t *SDO_C, size_t sizeIndicated)
 Initiate SDO download communication - update size. More...
 
size_t CO_SDOclientDownloadBufWrite (CO_SDOclient_t *SDO_C, const char *buf, size_t count)
 Write data into SDO client buffer. More...
 
CO_SDO_return_t CO_SDOclientDownload (CO_SDOclient_t *SDO_C, uint32_t timeDifference_us, bool_t abort, bool_t bufferPartial, CO_SDO_abortCode_t *SDOabortCode, size_t *sizeTransferred, uint32_t *timerNext_us)
 Process SDO download communication. More...
 
CO_SDO_return_t CO_SDOclientUploadInitiate (CO_SDOclient_t *SDO_C, uint16_t index, uint8_t subIndex, uint16_t SDOtimeoutTime_ms, bool_t blockEnable)
 Initiate SDO upload communication. More...
 
CO_SDO_return_t CO_SDOclientUpload (CO_SDOclient_t *SDO_C, uint32_t timeDifference_us, bool_t abort, CO_SDO_abortCode_t *SDOabortCode, size_t *sizeIndicated, size_t *sizeTransferred, uint32_t *timerNext_us)
 Process SDO upload communication. More...
 
size_t CO_SDOclientUploadBufRead (CO_SDOclient_t *SDO_C, char *buf, size_t count)
 Read data from SDO client buffer. More...
 
void CO_SDOclientClose (CO_SDOclient_t *SDO_C)
 Close SDO communication temporary. More...
 

Detailed Description

CANopen Service Data Object - client protocol (master functionality).

See also
SDO server

Function Documentation

◆ CO_SDOclient_init()

CO_ReturnError_t CO_SDOclient_init ( CO_SDOclient_t SDO_C,
const OD_t OD,
const OD_entry_t OD_1280_SDOcliPar,
uint8_t  nodeId,
CO_CANmodule_t CANdevRx,
uint16_t  CANdevRxIdx,
CO_CANmodule_t CANdevTx,
uint16_t  CANdevTxIdx 
)

Initialize SDO client object.

Function must be called in the communication reset section.

Parameters
SDO_CThis object will be initialized.
ODObject Dictionary. It is used in case, if client is accessing object dictionary from its own device. If NULL, it will be ignored.
OD_1280_SDOcliParOD entry for SDO client parameter (0x1280+). It may have IO extension enabled to allow dynamic configuration (see also CO_CONFIG_FLAG_OD_DYNAMIC). Entry is required.
nodeIdCANopen Node ID of this device. It is used in case, if client is accessing object dictionary from its own device. If 0, it will be ignored.
CANdevRxCAN device for SDO client reception.
CANdevRxIdxIndex of receive buffer in the above CAN device.
CANdevTxCAN device for SDO client transmission.
CANdevTxIdxIndex of transmit buffer in the above CAN device.
Returns
CO_ReturnError_t: CO_ERROR_NO or CO_ERROR_ILLEGAL_ARGUMENT.

◆ CO_SDOclient_initCallbackPre()

void CO_SDOclient_initCallbackPre ( CO_SDOclient_t SDOclient,
void *  object,
void(*)(void *object)  pFunctSignal 
)

Initialize SDOclient callback function.

Function initializes optional callback function, which should immediately start processing of CO_SDOclientDownload() or CO_SDOclientUpload() function. Callback is called after SDOclient message is received from the CAN bus or when new call without delay is necessary (exchange data with own SDO server or SDO block transfer is in progress).

Parameters
SDOclientThis object.
objectPointer to object, which will be passed to pFunctSignal(). Can be NULL.
pFunctSignalPointer to the callback function. Not called if NULL.

◆ CO_SDOclient_setup()

CO_SDO_return_t CO_SDOclient_setup ( CO_SDOclient_t SDO_C,
uint32_t  COB_IDClientToServer,
uint32_t  COB_IDServerToClient,
uint8_t  nodeIDOfTheSDOServer 
)

Setup SDO client object.

Function is called in from CO_SDOclient_init() and each time when "SDO client parameter" is written. Application can call this function before new SDO communication. If parameters to this function are the same as before, then CAN is not reconfigured.

Parameters
SDO_CThis object.
COB_IDClientToServerSee CO_SDOclient_t.
COB_IDServerToClientSee CO_SDOclient_t.
nodeIDOfTheSDOServerNode-ID of the SDO server. If it is the same as node-ID of this node, then data will be exchanged with this node (without CAN communication).
Returns
CO_SDO_return_t, CO_SDO_RT_ok_communicationEnd or CO_SDO_RT_wrongArguments

◆ CO_SDOclientDownloadInitiate()

CO_SDO_return_t CO_SDOclientDownloadInitiate ( CO_SDOclient_t SDO_C,
uint16_t  index,
uint8_t  subIndex,
size_t  sizeIndicated,
uint16_t  SDOtimeoutTime_ms,
bool_t  blockEnable 
)

Initiate SDO download communication.

Function initiates SDO download communication with server specified in CO_SDOclient_init() function. Data will be written to remote node. Function is non-blocking.

Parameters
SDO_CThis object.
indexIndex of object in object dictionary in remote node.
subIndexSubindex of object in object dictionary in remote node.
sizeIndicatedOptionally indicate size of data to be downloaded. Actual data are written with one or multiple CO_SDOclientDownloadBufWrite() calls.
  • If sizeIndicated is different than 0, then total number of data written by CO_SDOclientDownloadBufWrite() will be compared against sizeIndicated. Also sizeIndicated info will be passed to the server, which will compare actual data size downloaded. In case of mismatch, SDO abort message will be generated.
  • If sizeIndicated is 0, then actual data size will not be verified.
SDOtimeoutTime_msTimeout time for SDO communication in milliseconds.
blockEnableTry to initiate block transfer.
Returns
CO_SDO_return_t

◆ CO_SDOclientDownloadInitiateSize()

void CO_SDOclientDownloadInitiateSize ( CO_SDOclient_t SDO_C,
size_t  sizeIndicated 
)

Initiate SDO download communication - update size.

This is optional function, which updates sizeIndicated, if it was not known in the CO_SDOclientDownloadInitiate() function call. This function can be used after CO_SDOclientDownloadBufWrite(), but must be used before CO_SDOclientDownload().

Parameters
SDO_CThis object.
sizeIndicatedSame as in CO_SDOclientDownloadInitiate().

◆ CO_SDOclientDownloadBufWrite()

size_t CO_SDOclientDownloadBufWrite ( CO_SDOclient_t SDO_C,
const char *  buf,
size_t  count 
)

Write data into SDO client buffer.

This function copies data from buf into internal SDO client fifo buffer. Function returns number of bytes successfully copied. If there is not enough space in destination, not all bytes will be copied. Additional data can be copied in next cycles. If there is enough space in destination and sizeIndicated is different than zero, then all data must be written at once.

This function is basically a wrapper for CO_fifo_write() function. As alternative, other functions from CO_fifo can be used directly, for example CO_fifo_cpyTok2U8() or similar.

Parameters
SDO_CThis object.
bufBuffer which will be copied
countNumber of bytes in buf
Returns
number of bytes actually written.

◆ CO_SDOclientDownload()

CO_SDO_return_t CO_SDOclientDownload ( CO_SDOclient_t SDO_C,
uint32_t  timeDifference_us,
bool_t  abort,
bool_t  bufferPartial,
CO_SDO_abortCode_t SDOabortCode,
size_t *  sizeTransferred,
uint32_t timerNext_us 
)

Process SDO download communication.

Function must be called cyclically until it returns <=0. It Proceeds SDO download communication initiated with CO_SDOclientDownloadInitiate(). Function is non-blocking.

If function returns CO_SDO_RT_blockDownldInProgress and OS has buffer for CAN tx messages, then this function may be called multiple times within own loop. This can speed-up SDO block transfer.

Parameters
SDO_CThis object.
timeDifference_usTime difference from previous function call in [microseconds].
abortIf true, SDO client will send abort message from SDOabortCode and transmission will be aborted.
bufferPartialTrue indicates, not all data were copied to internal buffer yet. Buffer will be refilled later with CO_SDOclientDownloadBufWrite.
[out]SDOabortCodeIn case of error in communication, SDO abort code contains reason of error. Ignored if NULL.
[out]sizeTransferredActual size of data transferred. Ignored if NULL
[out]timerNext_usinfo to OS - see CO_process(). Ignored if NULL.
Returns
CO_SDO_return_t. If less than 0, then error occurred, SDOabortCode contains reason and state becomes idle. If 0, communication ends successfully and state becomes idle. If greater than 0, then communication is in progress.

◆ CO_SDOclientUploadInitiate()

CO_SDO_return_t CO_SDOclientUploadInitiate ( CO_SDOclient_t SDO_C,
uint16_t  index,
uint8_t  subIndex,
uint16_t  SDOtimeoutTime_ms,
bool_t  blockEnable 
)

Initiate SDO upload communication.

Function initiates SDO upload communication with server specified in CO_SDOclient_init() function. Data will be read from remote node. Function is non-blocking.

Parameters
SDO_CThis object.
indexIndex of object in object dictionary in remote node.
subIndexSubindex of object in object dictionary in remote node.
SDOtimeoutTime_msTimeout time for SDO communication in milliseconds.
blockEnableTry to initiate block transfer.
Returns
CO_SDO_return_t

◆ CO_SDOclientUpload()

CO_SDO_return_t CO_SDOclientUpload ( CO_SDOclient_t SDO_C,
uint32_t  timeDifference_us,
bool_t  abort,
CO_SDO_abortCode_t SDOabortCode,
size_t *  sizeIndicated,
size_t *  sizeTransferred,
uint32_t timerNext_us 
)

Process SDO upload communication.

Function must be called cyclically until it returns <=0. It Proceeds SDO upload communication initiated with CO_SDOclientUploadInitiate(). Function is non-blocking.

If this function returns CO_SDO_RT_uploadDataBufferFull, then data must be read from fifo buffer to make it empty. This function can then be called once again immediately to speed-up block transfer. Note also, that remaining data must be read after function returns CO_SDO_RT_ok_communicationEnd. Data must not be read, if function returns CO_SDO_RT_blockUploadInProgress.

Parameters
SDO_CThis object.
timeDifference_usTime difference from previous function call in [microseconds].
abortIf true, SDO client will send abort message from SDOabortCode and reception will be aborted.
[out]SDOabortCodeIn case of error in communication, SDO abort code contains reason of error. Ignored if NULL.
[out]sizeIndicatedIf larger than 0, then SDO server has indicated size of data transfer. Ignored if NULL.
[out]sizeTransferredActual size of data transferred. Ignored if NULL
[out]timerNext_usinfo to OS - see CO_process(). Ignored if NULL.
Returns
CO_SDO_return_t. If less than 0, then error occurred, SDOabortCode contains reason and state becomes idle. If 0, communication ends successfully and state becomes idle. If greater than 0, then communication is in progress.

◆ CO_SDOclientUploadBufRead()

size_t CO_SDOclientUploadBufRead ( CO_SDOclient_t SDO_C,
char *  buf,
size_t  count 
)

Read data from SDO client buffer.

This function copies data from internal fifo buffer of SDO client into buf. Function returns number of bytes successfully copied. It can be called in multiple cycles, if data length is large.

This function is basically a wrapper for CO_fifo_read() function. As alternative, other functions from CO_fifo can be used directly, for example CO_fifo_readU82a() or similar.

Warning
This function (or similar) must NOT be called when CO_SDOclientUpload() returns CO_SDO_RT_blockUploadInProgress!
Parameters
SDO_CThis object.
bufBuffer into which data will be copied
countCopy up to count bytes into buffer
Returns
number of bytes actually read.

◆ CO_SDOclientClose()

void CO_SDOclientClose ( CO_SDOclient_t SDO_C)

Close SDO communication temporary.

Function must be called after finish of each SDO client communication cycle. It disables reception of SDO client CAN messages. It is necessary, because CO_SDOclient_receive function may otherwise write into undefined SDO buffer.

Parameters
SDO_CThis object.