CANOPEN_CLIENT Driver 0.1.0
API reference
Loading...
Searching...
No Matches
Classes | Namespaces | Concepts
canopen_client_can_interface.hpp File Reference

The CAN port of the CANopen client driver: the CRTP base and the CanPort and CanRxPort concepts. More...

#include <concepts>
#include <cstdint>
#include "canopen_client_detail.hpp"
#include "canopen_client_types.hpp"

Go to the source code of this file.

Classes

class  canopen_client::CanInterface< Derived >
 CRTP base of the platform CAN port. More...
 

Namespaces

namespace  canopen_client
 The CANopen client driver: everything it declares lives here; internals in detail.
 

Concepts

concept  canopen_client::CanPort
 Satisfied by a class that derives from CanInterface<Port> and implements the required hooks with exactly the types above, noexcept (handbook KB-CPP20-006).
 
concept  canopen_client::CanRxPort
 Satisfied by a CanPort that also receives frames and keeps time: the full client port.
 

Detailed Description

The CAN port of the CANopen client driver: the CRTP base and the CanPort and CanRxPort concepts.

The driver reaches the bus through hooks on a class you derive from canopen_client::CanInterface<Self>. The controller is configured for classic CAN with 11-bit identifiers at the bit rate of the network (for example 500 kbit/s) by the port; the driver never changes it.

Hook Contract
bool EnsureInitialized() noexcept Start the controller on the first call; true at once afterwards
bool Send(const CanFrame& frame) noexcept Queue one frame; true when the controller accepted it
RxStatus Receive(CanFrame& frame, uint32_t timeout_us) noexcept Wait up to timeout_us for one frame (0 polls); Frame, Timeout or Error
uint32_t NowUs() noexcept A monotonic microsecond counter that wraps at 2^32

Send and EnsureInitialized make a transmit-only port (NMT, SYNC, RPDO and unconfirmed SDO writes). Receive and NowUs come as a pair: with both, the port is a full client port. A port must drop extended-identifier, CAN FD and error frames before Receive returns; the driver validates what it gets and counts what it drops.

Send gets a frame the driver owns: it is valid only during the call, so copy it if you queue it for later. When Receive returns Error the driver drops what it was waiting for and reports Bus; the switch-off calls (DriveDisable, DriveQuickStop, SendNmt(Stop)) still send. After a bus-off the port recovers the controller, and the application calls Deinitialize() then EnsureInitialized() so the driver starts from a clean state.