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

This class implements the Core of KaCanOpen It communicates with the CAN driver, sends CAN messages and listens for incoming CAN messages. You can access CanOpen sub- protocols using public members nmt, sdo and pdo. More...

#include <core.h>

Collaboration diagram for kaco::Core:
Collaboration graph
[legend]

Public Types

using MessageReceivedCallback = std::function< void(const Message &) >
 Type of a message receiver function Important: Never call register_receive_callback() from within (-> deadlock)!
 

Public Member Functions

 Core ()
 Constructor.
 
 ~Core ()
 Destructor.
 
 Core (const Core &)=delete
 Copy constructor deleted because of mutexes.
 
bool start (const std::string busname, const std::string &baudrate)
 Opens CAN driver and starts CAN message receive loop. More...
 
bool start (const std::string busname, const unsigned baudrate)
 Opens CAN driver and starts CAN message receive loop. More...
 
void stop ()
 Stops the receive loop and closes the driver. More...
 
void send (const Message &message)
 Sends a message. More...
 
void register_receive_callback (const MessageReceivedCallback &callback)
 Registers a callback function which is called when a message has been received. More...
 

Public Attributes

NMT nmt
 The NMT sub-protocol.
 
SDO sdo
 The SDO sub-protocol.
 
PDO pdo
 The PDO sub-protocol.
 

Detailed Description

This class implements the Core of KaCanOpen It communicates with the CAN driver, sends CAN messages and listens for incoming CAN messages. You can access CanOpen sub- protocols using public members nmt, sdo and pdo.

All methods except start() and stop() are thread-safe.

Examples:
examples/core.cpp.

Definition at line 59 of file core.h.

Member Function Documentation

void kaco::Core::register_receive_callback ( const MessageReceivedCallback callback)

Registers a callback function which is called when a message has been received.

Remarks
thread-safe

Definition at line 137 of file core.cpp.

void kaco::Core::send ( const Message message)

Sends a message.

Remarks
thread-safe if m_lock_send==true or driver is thread-safe.

Definition at line 243 of file core.cpp.

bool kaco::Core::start ( const std::string  busname,
const std::string &  baudrate 
)

Opens CAN driver and starts CAN message receive loop.

Parameters
busnameName of the bus which will be passed to the CAN driver, e.g. slcan0
baudrateBaudrate as a string which will be passed to the CAN driver. Most drivers from the CanFestival project accept the following values: "1M", "500K", "125K", "100K", "50K", "20K", "10K" and "5K".
Returns
true if successful
Remarks
Core must not run yet.
Examples:
examples/core.cpp.

Definition at line 84 of file core.cpp.

bool kaco::Core::start ( const std::string  busname,
const unsigned  baudrate 
)

Opens CAN driver and starts CAN message receive loop.

Parameters
busnameName of the bus which will be passed to the CAN driver, e.g. slcan0
baudrateBaudrate in 1/s. The value will be passed to the CAN driver in string representation. Attention: For full compatibility with CanFestival drivers, values > 1000000 are postfixed with "M" and values > 1000 are postfixed with "K". E.g. 1000000->"1M", 500000->"500K" and 5000->"5K".
Returns
true if successful
Remarks
Core must not run yet.

Definition at line 102 of file core.cpp.

void kaco::Core::stop ( )

Stops the receive loop and closes the driver.

Remarks
Core must be running.

Definition at line 112 of file core.cpp.


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