11#ifndef CANOPEN_CLIENT_TYPES_HPP
12#define CANOPEN_CLIENT_TYPES_HPP
18#include "canopen_client_version.h"
36enum class [[nodiscard]]
Error : uint8_t {
66 return "NotInitialized";
68 return "InvalidArgument";
74 return "DeviceIdMismatch";
88 return "BufferTooSmall";
90 return "InvalidFrame";
111 [[nodiscard]]
constexpr bool ok() const noexcept {
112 return error == Error::Ok;
115 constexpr explicit operator bool() const noexcept {
124 return {v, Error::Ok};
142 [[nodiscard]]
constexpr bool ok() const noexcept {
143 return error == Error::Ok;
146 constexpr explicit operator bool() const noexcept {
330inline constexpr std::array<AbortName, 31> kAbortNames{{
372 for (
const detail::AbortName& entry : detail::kAbortNames) {
373 if (
static_cast<uint32_t
>(entry.code) == code) {
492 std::array<PdoMapEntry, kMaxPdoEntries>
entries{};
499 NotReadyToSwitchOn = 0,
517 case DriveState::NotReadyToSwitchOn:
518 return "NotReadyToSwitchOn";
519 case DriveState::SwitchOnDisabled:
520 return "SwitchOnDisabled";
521 case DriveState::ReadyToSwitchOn:
522 return "ReadyToSwitchOn";
523 case DriveState::SwitchedOn:
525 case DriveState::OperationEnabled:
526 return "OperationEnabled";
527 case DriveState::QuickStopActive:
528 return "QuickStopActive";
529 case DriveState::FaultReactionActive:
530 return "FaultReactionActive";
531 case DriveState::Fault:
549 InterpolatedPosition = 7,
550 CyclicSynchronousPosition = 8,
551 CyclicSynchronousVelocity = 9,
552 CyclicSynchronousTorque = 10,
600 (config.sdo_timeout_us >= 1'000U) && (config.sdo_timeout_us <=
kMaxSdoTimeoutUs);
601 const bool guard_ok =
602 (config.guard_timeout_us >= 1'000U) && (config.guard_timeout_us <= 10'000'000U);
603 const bool drive_ok =
604 (config.drive_timeout_us >= 1'000U) && (config.drive_timeout_us <=
kMaxSdoTimeoutUs);
606 (config.drive_poll_interval_us >= 100U) && (config.drive_poll_interval_us <= 1'000'000U);
607 const bool attempts_ok = (config.safety_attempts >= 1U) && (config.safety_attempts <= 8U);
608 if (sdo_ok && guard_ok && drive_ok && poll_ok && attempts_ok) {
621 c.guard_timeout_us = 20'000;
622 c.drive_poll_interval_us = 2'000;
633 c.guard_timeout_us = 500'000;
634 c.drive_timeout_us = 5'000'000;
635 c.drive_poll_interval_us = 50'000;
641 return CANOPEN_CLIENT_VERSION_STRING;
645 return CANOPEN_CLIENT_VERSION_MAJOR;
649 return CANOPEN_CLIENT_VERSION_MINOR;
653 return CANOPEN_CLIENT_VERSION_PATCH;
constexpr std::size_t kMonitorCapacity
Nodes the heartbeat and guarding consumer can watch at once.
Definition canopen_client_types.hpp:242
constexpr uint16_t kControlQuickStop
Controlword: quick stop.
Definition canopen_client_types.hpp:571
constexpr uint32_t GetDriverVersionPatch() noexcept
Definition canopen_client_types.hpp:652
OperationMode
Modes of operation (object 0x6060), as the profile numbers them.
Definition canopen_client_types.hpp:542
constexpr uint8_t kMinNodeId
Lowest valid node identifier.
Definition canopen_client_types.hpp:218
constexpr uint32_t kMaxSdoTimeoutUs
Longest SDO timeout in microseconds.
Definition canopen_client_types.hpp:591
NmtCommand
NMT master command (the first data byte of the frame on identifier 0x000).
Definition canopen_client_types.hpp:263
constexpr const char * AbortCodeName(uint32_t code) noexcept
The name of an abort code, for logs.
Definition canopen_client_types.hpp:371
constexpr uint16_t kPdoCobIdMax
Highest identifier the driver accepts for a PDO (the last pre-defined RPDO4 identifier).
Definition canopen_client_types.hpp:237
DriveState
The drive state machine states, decoded from the statusword.
Definition canopen_client_types.hpp:498
constexpr uint8_t kMaxDlc
Longest classic CAN payload in bytes.
Definition canopen_client_types.hpp:182
constexpr uint16_t kControlEnableOperation
Controlword: enable operation (to Operation enabled).
Definition canopen_client_types.hpp:573
constexpr uint8_t kBroadcastNode
Node identifier of "every node" in an NMT command.
Definition canopen_client_types.hpp:216
constexpr std::size_t kEmcyQueueCapacity
EMCY events queued between two PopEmcy() calls.
Definition canopen_client_types.hpp:246
constexpr Config FastBusPreset() noexcept
Short timeouts for a fast, lightly loaded bus.
Definition canopen_client_types.hpp:618
constexpr uint16_t kCobIdEmcyBase
EMCY identifiers are this plus the node identifier.
Definition canopen_client_types.hpp:227
constexpr const char * GetDriverVersion() noexcept
Definition canopen_client_types.hpp:640
constexpr Config SlowBusPreset() noexcept
Long timeouts for a slow or busy bus (for example 125 kbit/s with many nodes).
Definition canopen_client_types.hpp:630
constexpr uint16_t kPdoCobIdMin
Lowest identifier the driver accepts for a PDO (the first pre-defined TPDO1 of node 1).
Definition canopen_client_types.hpp:235
constexpr uint32_t kMaxDrainFrames
Frames drained and routed before a request is sent.
Definition canopen_client_types.hpp:252
FrameClass
What Poll() did with the frame it received.
Definition canopen_client_types.hpp:451
constexpr uint32_t kMaxSdoSegments
Segments of one segmented SDO transfer (7 bytes each).
Definition canopen_client_types.hpp:254
RxStatus
What a port's Receive() hook reports.
Definition canopen_client_types.hpp:207
constexpr uint16_t kCobIdSdoResponseBase
SDO response (server to client) identifiers are this plus the node identifier.
Definition canopen_client_types.hpp:229
constexpr uint32_t GetDriverVersionMinor() noexcept
Definition canopen_client_types.hpp:648
NmtState
NMT state a node reports in its heartbeat or guarding reply (bit 7 masked off).
Definition canopen_client_types.hpp:272
constexpr uint8_t kMaxNodeId
Highest valid node identifier.
Definition canopen_client_types.hpp:220
Verify
Whether a setter or a transfer reads back what it wrote (extra bus traffic).
Definition canopen_client_types.hpp:172
constexpr uint32_t kMaxFramesPerWait
Frames one blocking wait looks at before it gives up (a flooded bus must not stall a call).
Definition canopen_client_types.hpp:250
constexpr uint32_t kMaxReceivesPerWait
Definition canopen_client_types.hpp:258
constexpr const char * ToString(Error error) noexcept
The name of an error, for logs.
Definition canopen_client_types.hpp:61
constexpr uint32_t GetDriverVersionMajor() noexcept
Definition canopen_client_types.hpp:644
constexpr uint16_t kControlFaultReset
Controlword: fault reset (bit 7, acts on the rising edge).
Definition canopen_client_types.hpp:575
constexpr uint16_t kControlDisableVoltage
Controlword: disable voltage (to Switch on disabled).
Definition canopen_client_types.hpp:569
constexpr bool IsValid(const CanFrame &frame) noexcept
Whether a frame is representable on the bus: identifier at most 0x7FF, length at most 8.
Definition canopen_client_types.hpp:202
constexpr uint16_t kMaxCanId
Largest 11-bit CAN identifier.
Definition canopen_client_types.hpp:180
constexpr uint16_t kControlSwitchOn
Controlword: switch on (to Switched on).
Definition canopen_client_types.hpp:567
SdoAbortCode
SDO abort codes the driver names. Any 32-bit value can arrive; SdoAbortInfo::code keeps the raw value...
Definition canopen_client_types.hpp:285
SdoReplyKind
The kind of an SDO server reply.
Definition canopen_client_types.hpp:390
LogLevel
Severity passed to the optional Log() hook.
Definition canopen_client_types.hpp:164
constexpr std::size_t kPdoSubscriptionCapacity
TPDO identifiers the receive path can hold the latest frame of.
Definition canopen_client_types.hpp:244
constexpr uint16_t kCobIdSync
SYNC identifier.
Definition canopen_client_types.hpp:225
constexpr uint16_t kCobIdHeartbeatBase
Heartbeat and node-guarding identifiers are this plus the node identifier.
Definition canopen_client_types.hpp:233
constexpr uint16_t kControlShutdown
Controlword: shutdown (to Ready to switch on).
Definition canopen_client_types.hpp:565
constexpr uint16_t kCobIdSdoRequestBase
SDO request (client to server) identifiers are this plus the node identifier.
Definition canopen_client_types.hpp:231
PdoKind
Whether a PDO is a receive PDO (client to node) or a transmit PDO (node to client).
Definition canopen_client_types.hpp:471
constexpr uint16_t kCobIdNmt
NMT command identifier (pre-defined connection set).
Definition canopen_client_types.hpp:223
Error
Why a call failed. Values 0 to 9 are the shared base set; client-specific values start at 16.
Definition canopen_client_types.hpp:36
constexpr Error Validate(const Config &config) noexcept
Check a configuration without touching the bus.
Definition canopen_client_types.hpp:598
constexpr std::size_t kMaxPdoEntries
Entries of one PDO mapping the helpers handle.
Definition canopen_client_types.hpp:248
@ PreOperational
Go to Pre-operational.
@ Start
Go to Operational.
@ ResetNode
Reset the whole application and communication.
@ ResetCommunication
Reset the communication parameters only.
@ Unknown
The statusword matches no state.
@ Invalid
A frame that fails validation; counted and dropped.
@ Pdo
A subscribed TPDO; its sample is updated.
@ Heartbeat
A heartbeat or boot-up message; the node table is updated.
@ Emcy
An emergency message; queued for PopEmcy().
@ Sync
A SYNC frame from another producer.
@ Ignored
A valid frame nobody here asked for (including a stale SDO reply).
@ Frame
A frame was received into the argument.
@ BootUp
The boot-up message; the node continues to Pre-operational.
@ Operational
SDO and PDO are on.
@ Stopped
Only NMT and heartbeat; SDO and PDO are off.
@ None
No read-back: the node's acknowledgement is the only check.
@ ReadBack
Read the object again and compare; costs one more SDO exchange.
@ ValueTooHigh
Value of parameter written too high (download only).
@ ReadOnly
Attempt to write a read-only object.
@ UnsupportedAccess
Unsupported access to an object.
@ InvalidValue
Invalid value for parameter (download only).
@ DeviceState
... because of the present device state.
@ SdoResourceUnavailable
Resource not available: SDO connection.
@ InvalidSequenceNumber
Invalid sequence number (block mode only).
@ HardwareError
Access failed due to a hardware error.
@ WriteOnly
Attempt to read a write-only object.
@ NoDictionary
Object dictionary dynamic generation fails or none present.
@ ParameterIncompatible
General parameter incompatibility.
@ LengthTooLow
Data type does not match, length of service parameter too low.
@ ValueTooLow
Value of parameter written too low (download only).
@ GeneralError
General error.
@ NotMappable
Object cannot be mapped to the PDO.
@ PdoLengthExceeded
The mapped objects would exceed the PDO length.
@ InvalidBlockSize
Invalid block size (block mode only).
@ InternalIncompatibility
General internal incompatibility in the device.
@ MaxLessThanMin
Maximum value is less than minimum value.
@ OutOfMemory
Out of memory.
@ ObjectNotFound
Object does not exist in the object dictionary.
@ StoreFailed
Data cannot be transferred or stored to the application.
@ Timeout
SDO protocol timed out.
@ NoData
No data available.
@ ToggleNotAlternated
Toggle bit not alternated.
@ CrcError
CRC error (block mode only).
@ LengthTooHigh
Data type does not match, length of service parameter too high.
@ LocalControl
... because of local control.
@ LengthMismatch
Data type does not match, length of service parameter does not match.
@ SubIndexNotFound
Sub-index does not exist.
@ InvalidCommandSpecifier
Client or server command specifier not valid or unknown.
@ InitiateDownload
Response to an initiate download request (scs 3).
@ Abort
Abort transfer (scs 4).
@ SegmentDownload
Response to a download segment (scs 1).
@ SegmentUpload
A segment of upload data (scs 0).
@ InitiateUpload
Response to an initiate upload request (scs 2).
@ Warning
Something unexpected that the driver recovered from.
@ Debug
Detail for bring-up.
@ Receive
RPDO: the node consumes it.
@ Transmit
TPDO: the node produces it.
@ DriveFault
The drive is in the Fault state or reports a state no transition leaves.
@ NodeState
The node is known to be in an NMT state that ignores the request.
@ InvalidArgument
An argument or a Config field is out of range; nothing was sent.
@ InvalidFrame
A frame fails validation (identifier, length or content).
@ SdoAbort
The node aborted the SDO transfer; see GetLastAbort().
@ DeviceIdMismatch
Not returned by this driver.
@ Crc
Not returned by this driver.
@ Bus
The port failed to send or to receive a frame.
@ Protocol
A reply broke the protocol (command specifier, toggle bit, size).
@ DeviceFault
A read-back showed a value other than the one written.
@ NotInitialized
EnsureInitialized() has not succeeded, or Deinitialize() ran since.
@ BufferTooSmall
An upload is larger than the caller's buffer.
@ Timeout
No valid reply arrived in time (SDO, node guarding, drive state).
@ Busy
Not returned by this driver.
The CANopen client driver: everything it declares lives here; internals in detail.
Definition canopen_client.hpp:28
One classic CAN frame with an 11-bit identifier.
Definition canopen_client_types.hpp:190
uint8_t dlc
Number of data bytes, 0 to 8.
Definition canopen_client_types.hpp:192
bool rtr
Remote transmission request (used by node guarding only).
Definition canopen_client_types.hpp:193
std::array< uint8_t, 8 > data
The payload; bytes at and past dlc are not meaningful.
Definition canopen_client_types.hpp:194
Everything the client uses; the defaults suit a node on a 500 kbit/s bus.
Definition canopen_client_types.hpp:580
uint32_t drive_poll_interval_us
Pause between statusword reads, 100 us to 1 s.
Definition canopen_client_types.hpp:584
bool abort_on_timeout
Send an SDO abort (0x05040000) to the node after a timeout.
Definition canopen_client_types.hpp:586
uint32_t guard_timeout_us
Wait for a node-guarding reply, 1 ms to 10 s.
Definition canopen_client_types.hpp:582
uint32_t sdo_timeout_us
Wait for each SDO reply, 1 ms to 60 s.
Definition canopen_client_types.hpp:581
uint8_t safety_attempts
Sends of a stop or disable command before it gives up, 1 to 8.
Definition canopen_client_types.hpp:585
bool strict_sdo_length
Require every SDO frame to carry 8 data bytes.
Definition canopen_client_types.hpp:587
uint32_t drive_timeout_us
Wait for a drive state change, 1 ms to 60 s.
Definition canopen_client_types.hpp:583
The object indices of a drive; the defaults are the profile's, a remapped drive overrides them.
Definition canopen_client_types.hpp:557
uint16_t mode
Modes of operation.
Definition canopen_client_types.hpp:560
uint16_t statusword
Statusword.
Definition canopen_client_types.hpp:559
uint16_t controlword
Controlword.
Definition canopen_client_types.hpp:558
uint16_t mode_display
Modes of operation display.
Definition canopen_client_types.hpp:561
One emergency message (EMCY).
Definition canopen_client_types.hpp:433
std::array< uint8_t, 5 > manufacturer
Manufacturer-specific bytes.
Definition canopen_client_types.hpp:437
uint8_t node
The node that sent it.
Definition canopen_client_types.hpp:434
uint8_t error_register
Object 0x1001 as the node reported it.
Definition canopen_client_types.hpp:436
uint32_t timestamp_us
NowUs() when the frame was received.
Definition canopen_client_types.hpp:438
uint16_t code
The emergency error code; 0x0000 means error reset.
Definition canopen_client_types.hpp:435
A decoded heartbeat or node-guarding reply.
Definition canopen_client_types.hpp:416
uint8_t node
The node (identifier minus 0x700).
Definition canopen_client_types.hpp:417
bool toggle
Bit 7: the node-guarding toggle (always 0 in a heartbeat).
Definition canopen_client_types.hpp:419
NmtState state
The reported state.
Definition canopen_client_types.hpp:418
What the heartbeat consumer knows about one node.
Definition canopen_client_types.hpp:423
uint32_t count
Heartbeats and guarding replies received.
Definition canopen_client_types.hpp:429
uint32_t last_us
NowUs() at the last heartbeat.
Definition canopen_client_types.hpp:428
NmtState state
The last reported state; meaningful when seen.
Definition canopen_client_types.hpp:424
bool bootup_seen
A boot-up message arrived since the node was registered.
Definition canopen_client_types.hpp:426
bool seen
At least one heartbeat or guarding reply arrived.
Definition canopen_client_types.hpp:425
bool alive
The last heartbeat is younger than the registered timeout.
Definition canopen_client_types.hpp:427
The communication and mapping parameters of one PDO.
Definition canopen_client_types.hpp:484
uint16_t event_timer_ms
Event timer (TPDO), 0 leaves the node's value.
Definition canopen_client_types.hpp:489
std::array< PdoMapEntry, kMaxPdoEntries > entries
The mapping.
Definition canopen_client_types.hpp:492
uint16_t inhibit_time_100us
Inhibit time (TPDO), 0 leaves the node's value.
Definition canopen_client_types.hpp:488
uint8_t entry_count
Valid entries, 0 to kMaxPdoEntries.
Definition canopen_client_types.hpp:491
bool enabled
The PDO is valid (COB-ID bit 31 clear) when configured.
Definition canopen_client_types.hpp:490
uint16_t cob_id
The identifier (kPdoCobIdMin to kPdoCobIdMax).
Definition canopen_client_types.hpp:485
uint8_t transmission_type
Definition canopen_client_types.hpp:486
One mapped object of a PDO.
Definition canopen_client_types.hpp:477
uint8_t bits
Length in bits, 1 to 64.
Definition canopen_client_types.hpp:480
uint16_t index
Object index.
Definition canopen_client_types.hpp:478
uint8_t sub
Sub-index.
Definition canopen_client_types.hpp:479
The latest frame received on a subscribed TPDO identifier.
Definition canopen_client_types.hpp:442
uint16_t cob_id
The identifier.
Definition canopen_client_types.hpp:443
uint32_t timestamp_us
NowUs() at the last frame.
Definition canopen_client_types.hpp:447
std::array< uint8_t, 8 > data
The payload.
Definition canopen_client_types.hpp:445
uint32_t sequence
Frames received on this identifier; 0 means none yet.
Definition canopen_client_types.hpp:446
uint8_t dlc
Valid bytes in data.
Definition canopen_client_types.hpp:444
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition canopen_client_types.hpp:158
constexpr bool ok() const noexcept
Definition canopen_client_types.hpp:142
static constexpr Result Success() noexcept
Definition canopen_client_types.hpp:150
The value of a call, or why there is none.
Definition canopen_client_types.hpp:106
constexpr bool ok() const noexcept
Definition canopen_client_types.hpp:111
static constexpr Result Success(T v) noexcept
A successful result.
Definition canopen_client_types.hpp:123
static constexpr Result Failure(Error e) noexcept
A failed result.
Definition canopen_client_types.hpp:131
The last SDO abort, from the node or from this driver.
Definition canopen_client_types.hpp:381
uint8_t sub
The sub-index of the transfer.
Definition canopen_client_types.hpp:384
uint8_t node
The node of the transfer.
Definition canopen_client_types.hpp:382
uint16_t index
The object index of the transfer.
Definition canopen_client_types.hpp:383
bool remote
true when the node sent it, false when this driver aborted the transfer.
Definition canopen_client_types.hpp:386
uint32_t code
The raw abort code; 0 when no transfer has aborted.
Definition canopen_client_types.hpp:385
A decoded SDO server reply.
Definition canopen_client_types.hpp:399
uint32_t size
Indicated size, or the abort code for an abort.
Definition canopen_client_types.hpp:408
bool expedited
Expedited transfer (initiate upload).
Definition canopen_client_types.hpp:405
SdoReplyKind kind
Which reply this is.
Definition canopen_client_types.hpp:400
uint16_t index
Object index (initiate replies and abort).
Definition canopen_client_types.hpp:401
uint8_t data_len
Valid bytes in data.
Definition canopen_client_types.hpp:407
uint8_t sub
Sub-index (initiate replies and abort).
Definition canopen_client_types.hpp:402
std::array< uint8_t, 7 > data
Expedited data or the segment's bytes.
Definition canopen_client_types.hpp:409
bool toggle
Toggle bit (segment replies).
Definition canopen_client_types.hpp:403
bool last
Last segment (segment upload replies).
Definition canopen_client_types.hpp:404
bool size_indicated
size is valid (initiate upload).
Definition canopen_client_types.hpp:406
Counters of the receive path, for diagnostics.
Definition canopen_client_types.hpp:462
uint32_t frames_received
Frames the port delivered.
Definition canopen_client_types.hpp:463
uint32_t emcy_dropped
EMCY events dropped because the queue was full.
Definition canopen_client_types.hpp:466
uint32_t flood_aborts
Waits that gave up after kMaxFramesPerWait frames.
Definition canopen_client_types.hpp:467
uint32_t sdo_stale
SDO replies that matched no outstanding request.
Definition canopen_client_types.hpp:465
uint32_t frames_invalid
Frames dropped by validation.
Definition canopen_client_types.hpp:464