KaCanOpen
 All Classes Functions Variables Typedefs Enumerations Pages
Public Types | Public Member Functions | List of all members
kaco::SDO Class Reference

This class implements the CanOpen SDO protocol. More...

#include <sdo.h>

Public Types

using SDOReceivedCallback = std::function< void(SDOResponse) >
 Type of a sdo message receiver function Important: Never call send_sdo_and_wait or process_incoming_message from within (-> deadlock)!
 

Public Member Functions

 SDO (Core &core)
 Constructor. More...
 
 SDO (const SDO &)=delete
 Copy constructor deleted because of mutexes.
 
void download (uint8_t node_id, uint16_t index, uint8_t subindex, uint32_t size, const std::vector< uint8_t > &bytes)
 SDO download: Write value into remote device's object dictionary. More...
 
std::vector< uint8_t > upload (uint8_t node_id, uint16_t index, uint8_t subindex)
 SDO download: Get value from remote device's object dictionary. More...
 
void process_incoming_message (const Message &message)
 Process incoming SDO message. More...
 
SDOResponse send_sdo_and_wait (uint8_t command, uint8_t node_id, uint16_t index, uint8_t subindex, const std::array< uint8_t, 4 > &data)
 Sends an SDO message and waits for the response. More...
 

Detailed Description

This class implements the CanOpen SDO protocol.

Todo:

Add add_client_sdo_callback(SDOReceivedCallback) (callback signature void(const SDOResponse&)) and/or add_request_callback(node_id, SDORequestCallback) (listening only for SDOs with slave's own node_id, callback signature void(index, subindex)).

Add send_response(node_id, index, subindex, vector<uint8_t> data) (chooses segmented/expedited transfer on it's own).

Add abort_transfer(node_id, index, subindex, errorcode).

All methods are thread-safe.

Definition at line 58 of file sdo.h.

Constructor & Destructor Documentation

kaco::SDO::SDO ( Core core)

Constructor.

Parameters
coreReference to the Core

Definition at line 45 of file sdo.cpp.

Member Function Documentation

void kaco::SDO::download ( uint8_t  node_id,
uint16_t  index,
uint8_t  subindex,
uint32_t  size,
const std::vector< uint8_t > &  bytes 
)

SDO download: Write value into remote device's object dictionary.

Parameters
node_idNode id of remote device
indexDictionary index
subindexSubindex
sizeSize of the entry/value in bytes
bytesVector containing the data bytes of the value in little-endian order. Vector size must be equal to size argument.
Remarks
thread-safe
Examples:
examples/core.cpp.

Definition at line 50 of file sdo.cpp.

void kaco::SDO::process_incoming_message ( const Message message)

Process incoming SDO message.

Parameters
messageThe received CanOpen message.
Todo:
Rename this to process_incoming_server_sdo() and add process_incoming_client_sdo()
Remarks
thread-safe

Definition at line 156 of file sdo.cpp.

SDOResponse kaco::SDO::send_sdo_and_wait ( uint8_t  command,
uint8_t  node_id,
uint16_t  index,
uint8_t  subindex,
const std::array< uint8_t, 4 > &  data 
)

Sends an SDO message and waits for the response.

Parameters
commandSDO command specifier
node_idNode id of remote device
indexDictionary index
subindexSubindex
databytes to send in little endian order
Returns
The response message.
Remarks
thread-safe

Definition at line 178 of file sdo.cpp.

std::vector< uint8_t > kaco::SDO::upload ( uint8_t  node_id,
uint16_t  index,
uint8_t  subindex 
)

SDO download: Get value from remote device's object dictionary.

Parameters
node_idNode id of remote device
indexDictionary index
subindexSubindex
Returns
Vector containing the data bytes of the value in little-endian order.
Remarks
thread-safe
Examples:
examples/core.cpp.

Definition at line 84 of file sdo.cpp.


The documentation for this class was generated from the following files: