CANopenNode
CANopen protocol stack
Loading...
Searching...
No Matches
SDO client

CANopen Service Data Object - client protocol. More...

+ Collaboration diagram for 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, OD_t *OD, OD_entry_t *OD_1280_SDOcliPar, uint8_t nodeId, CO_CANmodule_t *CANdevRx, uint16_t CANdevRxIdx, CO_CANmodule_t *CANdevTx, uint16_t CANdevTxIdx, uint32_t *errInfo)
 Initialize SDO client object.
 
void CO_SDOclient_initCallbackPre (CO_SDOclient_t *SDOclient, void *object, void(*pFunctSignal)(void *object))
 Initialize SDOclient callback function.
 
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.
 
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.
 
void CO_SDOclientDownloadInitSize (CO_SDOclient_t *SDO_C, size_t sizeIndicated)
 Initiate SDO download communication - update size.
 
size_t CO_SDOclientDownloadBufWrite (CO_SDOclient_t *SDO_C, const uint8_t *buf, size_t count)
 Write data into SDO client buffer.
 
CO_SDO_return_t CO_SDOclientDownload (CO_SDOclient_t *SDO_C, uint32_t timeDifference_us, bool_t send_abort, bool_t bufferPartial, CO_SDO_abortCode_t *SDOabortCode, size_t *sizeTransferred, uint32_t *timerNext_us)
 Process SDO download communication.
 
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.
 
CO_SDO_return_t CO_SDOclientUpload (CO_SDOclient_t *SDO_C, uint32_t timeDifference_us, bool_t send_abort, CO_SDO_abortCode_t *SDOabortCode, size_t *sizeIndicated, size_t *sizeTransferred, uint32_t *timerNext_us)
 Process SDO upload communication.
 
size_t CO_SDOclientUploadBufRead (CO_SDOclient_t *SDO_C, uint8_t *buf, size_t count)
 Read data from SDO client buffer.
 
void CO_SDOclientClose (CO_SDOclient_t *SDO_C)
 Close SDO communication temporary.
 

Detailed Description

CANopen Service Data Object - client protocol.

SDO client is able to access Object Dictionary variables from remote nodes. Usually there is one SDO client on CANopen network, which is able to configure other CANopen nodes. It is also possible to establish individual SDO client-server communication channels between devices.

SDO client is used in CANopenNode from CO_gateway_ascii.c with default SDO CAN identifiers. There is quite advanced usage in non-blocking function.

If enabled, SDO client is initialized in CANopen.c file with CO_SDOclient_init() function.

Basic usage:

read_SDO(CO_SDOclient_t* SDO_C, uint8_t nodeId, uint16_t index, uint8_t subIndex, uint8_t* buf, size_t bufSize,
size_t* readSize) {
CO_SDO_return_t SDO_ret;
// setup client (this can be skipped, if remote device don't change)
SDO_ret = CO_SDOclient_setup(SDO_C, CO_CAN_ID_SDO_CLI + nodeId, CO_CAN_ID_SDO_SRV + nodeId, nodeId);
}
// initiate upload
SDO_ret = CO_SDOclientUploadInitiate(SDO_C, index, subIndex, 1000, false);
}
// upload data
do {
uint32_t timeDifference_us = 10000;
SDO_ret = CO_SDOclientUpload(SDO_C, timeDifference_us, false, &abortCode, NULL, NULL, NULL);
if (SDO_ret < 0) {
return abortCode;
}
sleep_us(timeDifference_us);
} while (SDO_ret > 0);
// copy data to the user buffer (for long data function must be called several times inside the loop)
*readSize = CO_SDOclientUploadBufRead(SDO_C, buf, bufSize);
}
write_SDO(CO_SDOclient_t* SDO_C, uint8_t nodeId, uint16_t index, uint8_t subIndex, uint8_t* data, size_t dataSize) {
CO_SDO_return_t SDO_ret;
bool_t bufferPartial = false;
// setup client (this can be skipped, if remote device is the same)
SDO_ret = CO_SDOclient_setup(SDO_C, CO_CAN_ID_SDO_CLI + nodeId, CO_CAN_ID_SDO_SRV + nodeId, nodeId);
return -1
}
// initiate download
SDO_ret = CO_SDOclientDownloadInitiate(SDO_C, index, subIndex, dataSize, 1000, false);
return -1
}
// fill data
size_t nWritten = CO_SDOclientDownloadBufWrite(SDO_C, data, dataSize);
if (nWritten < dataSize) {
bufferPartial = true;
// If SDO Fifo buffer is too small, data can be refilled in the loop.
}
// download data
do {
uint32_t timeDifference_us = 10000;
SDO_ret = CO_SDOclientDownload(SDO_C, timeDifference_us, false, bufferPartial, &abortCode, NULL, NULL);
if (SDO_ret < 0) {
return abortCode;
}
sleep_us(timeDifference_us);
} while (SDO_ret > 0);
}
#define CO_CAN_ID_SDO_CLI
0x600 SDO request from client (+nodeID)
Definition CO_driver.h:406
#define CO_CAN_ID_SDO_SRV
0x580 SDO response from server (+nodeID)
Definition CO_driver.h:405
CO_SDO_return_t CO_SDOclientDownload(CO_SDOclient_t *SDO_C, uint32_t timeDifference_us, bool_t send_abort, bool_t bufferPartial, CO_SDO_abortCode_t *SDOabortCode, size_t *sizeTransferred, uint32_t *timerNext_us)
Process SDO download communication.
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.
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.
size_t CO_SDOclientDownloadBufWrite(CO_SDOclient_t *SDO_C, const uint8_t *buf, size_t count)
Write data into SDO client buffer.
size_t CO_SDOclientUploadBufRead(CO_SDOclient_t *SDO_C, uint8_t *buf, size_t count)
Read data from SDO client buffer.
CO_SDO_return_t CO_SDOclientUpload(CO_SDOclient_t *SDO_C, uint32_t timeDifference_us, bool_t send_abort, CO_SDO_abortCode_t *SDOabortCode, size_t *sizeIndicated, size_t *sizeTransferred, uint32_t *timerNext_us)
Process SDO upload communication.
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.
CO_SDO_abortCode_t
SDO abort codes.
Definition CO_SDOserver.h:296
CO_SDO_return_t
Return values from SDO server or client functions.
Definition CO_SDOserver.h:341
@ CO_SDO_AB_GENERAL
0x08000000, General error
Definition CO_SDOserver.h:327
@ CO_SDO_AB_NONE
0x00000000, No abort
Definition CO_SDOserver.h:297
@ CO_SDO_RT_ok_communicationEnd
Success, end of communication.
Definition CO_SDOserver.h:350
#define NULL
NULL, for general usage.
Definition CO_driver.h:123
unsigned int uint16_t
UNSIGNED16 in CANopen (0006h), 16-bit unsigned integer.
Definition CO_driver.h:132
unsigned long int uint32_t
UNSIGNED32 in CANopen (0007h), 32-bit unsigned integer.
Definition CO_driver.h:133
uint_fast8_t bool_t
Boolean data type for general use.
Definition CO_driver.h:126
unsigned char uint8_t
UNSIGNED8 in CANopen (0005h), 8-bit unsigned integer.
Definition CO_driver.h:131
SDO client object.
Definition CO_SDOclient.h:151
See also
SDO server

Function Documentation

◆ CO_SDOclient_init()

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

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.
[out]errInfoAdditional information in case of error, may be NULL.
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(* pFunctSignal )(void *object) )

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_SDOclientDownloadInitSize()

void CO_SDOclientDownloadInitSize ( 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 uint8_t * 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 send_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].
send_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 send_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].
send_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,
uint8_t * 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.