Class LelyDriverBridge

Inheritance Relationships

Base Type

  • public canopen::FiberDriver

Class Documentation

class LelyDriverBridge : public canopen::FiberDriver

Lely Driver Bridge.

This class provides functionalities for bridging between Lelycore drivers and standard C++ functions. This means it provides async and sync functions for interacting with CANopen devices using synchronisation functionalities from C++ standard library.

Public Functions

inline LelyDriverBridge(ev_exec_t *exec, canopen::AsyncMaster &master, uint8_t id, std::string name, std::string eds, std::string bin)

Construct a new Lely Bridge object.

Parameters:
  • exec[in] Executor to use

  • master[in] Master to use

  • id[in] NodeId to connect to

  • eds[in] EDS file

  • bin[in] BIN file (concise dcf)

std::future<bool> async_sdo_write(COData data)

Asynchronous SDO Write.

Writes the data passed to the function via SDO to the connected device.

Parameters:

data[in] Data to written.

Returns:

std::future<bool> Returns an std::future<bool> that is fulfilled when the write request was done. An error is stored when the write request was unsuccessful.

template<typename T>
inline std::future<bool> async_sdo_write_typed(uint16_t idx, uint8_t subidx, T value)
template<typename T>
inline bool sync_sdo_write_typed(uint16_t idx, uint8_t subidx, T value, std::chrono::milliseconds timeout)
std::future<COData> async_sdo_read(COData data)

Aynchronous SDO Read.

Reads the indicated SDO object from the connected device.

Parameters:

data[in] Data to be read, the data entry is not used.

Returns:

std::future<COData> Returns an std::future<COData> that is fulfilled when the read request was done. The result of the request is stored in the future. An error is stored when the read request was unsuccessful.

template<typename T>
inline std::future<T> async_sdo_read_typed(uint16_t idx, uint8_t subidx)
template<typename T>
inline bool sync_sdo_read_typed(uint16_t idx, uint8_t subidx, T &value, std::chrono::milliseconds timeout)
std::future<canopen::NmtState> async_request_nmt()

Asynchronous request for NMT.

Waits for an NMT state change to occur. The new state is stored in the future returned by the function.

Returns:

std::future<canopen::NmtState> The returned future is set when NMT State changes.

std::shared_ptr<SafeQueue<COData>> get_rpdo_queue()

Asynchronous request for RPDO.

Waits for an RPDO write request to be received from the slave. The content of the request are stored in the returned future.

Todo:

This function should use a threadsafe queue not the icky implementation we have now.

Returns:

std::future<COData> The returned future is set when an RPDO event is detected.

std::shared_ptr<SafeQueue<COEmcy>> get_emcy_queue()

Asynchronous request for EMCY.

Todo:

This function should use a threadsafe queue not the icky implementation we have now.

Returns:

std::future<COEmcy> The returned future is set when an EMCY event is detected.

void tpdo_transmit(COData data)

Executes a TPDO transmission.

This function executes a TPDO transmission. The{false, true} object specified in the input data is sent if it is registered as a TPDO with the master.

Parameters:

data[in] Object and data to be written

void nmt_command(canopen::NmtCommand command)

Executes a NMT Command.

This function sends the NMT command specified as parameter.

Parameters:

command[in] NMT Command to execute

uint8_t get_id()

Get the nodeid.

Returns:

uint8_t

inline bool wait_for_boot()

Wait for device to be booted.

Returns:

true

Returns:

false

inline void set_sync_function(std::function<void()> on_sync_function)
inline void unset_sync_function()
inline void Boot()

Request master to boot device.

inline bool is_booted()

Indicates if Device is booted.

Returns:

true

Returns:

false

template<typename T>
inline void submit_write(COData data)
template<typename T>
inline void submit_read(COData data)
template<typename T>
inline const T universal_get_value(uint16_t index, uint8_t subindex)
template<typename T>
inline void universal_set_value(uint16_t index, uint8_t subindex, T value)

Protected Functions

inline void OnSync(uint8_t cnt, const time_point &t) noexcept override
void OnState(canopen::NmtState state) noexcept override

OnState Callback.

This callback function is called when an Nmt state change is detected on the connected device.

Parameters:

state[in] NMT State

virtual void OnBoot(canopen::NmtState st, char es, const ::std::string &what) noexcept override

OnBoot Callback This callback is called when the Boot process of the slave that was initiated by the master has been success fully finished.

Parameters:
  • st

  • es

  • what

void OnRpdoWrite(uint16_t idx, uint8_t subidx) noexcept override

OnRpdoWrite Callback.

This callback function is called when an RPDO write request is received from the connected device.

Todo:

This function should use a threadsafe queue not the icky implementation we have now.

Parameters:
  • idx[in] Object Index

  • subidx[in] Object Subindex

void OnEmcy(uint16_t eec, uint8_t er, uint8_t msef[5]) noexcept override

The function invoked when an EMCY message is received from the remote node.

Todo:

This function should use a threadsafe queue not the icky implementation we have now.

Parameters:
  • eec – the emergency error code.

  • er – the error register.

  • msef – the manufacturer-specific error code.

Protected Attributes

std::unique_ptr<DriverDictionary> dictionary_
std::mutex dictionary_mutex_
std::shared_ptr<PDOMap> pdo_map_
std::shared_ptr<std::promise<COData>> sdo_read_data_promise
std::shared_ptr<std::promise<bool>> sdo_write_data_promise
std::mutex sdo_mutex
bool running
std::condition_variable sdo_cond
std::promise<canopen::NmtState> nmt_state_promise
std::atomic<bool> nmt_state_is_set
std::mutex nmt_mtex
std::promise<COData> rpdo_promise
std::atomic<bool> rpdo_is_set
std::mutex pdo_mtex
std::shared_ptr<SafeQueue<COData>> rpdo_queue
std::promise<COEmcy> emcy_promise
std::atomic<bool> emcy_is_set
std::mutex emcy_mtex
std::shared_ptr<SafeQueue<COEmcy>> emcy_queue
std::atomic<bool> booted
char boot_status
std::string boot_what
canopen::NmtState boot_state
std::condition_variable boot_cond
std::mutex boot_mtex
uint8_t nodeid
std::string name_
std::function<void()> on_sync_function_