CANOPEN_CLIENT Driver 0.1.0
API reference
Loading...
Searching...
No Matches
canopen_client_types.hpp
Go to the documentation of this file.
1
11#ifndef CANOPEN_CLIENT_TYPES_HPP
12#define CANOPEN_CLIENT_TYPES_HPP
13
14#include <array>
15#include <cstddef>
16#include <cstdint>
17
18#include "canopen_client_version.h"
19
21namespace canopen_client {
22
36enum class [[nodiscard]] Error : uint8_t {
37 Ok = 0,
38 NotInitialized = 1,
39 InvalidArgument = 2,
40 Bus = 3,
41 Timeout = 4,
43 Crc = 6,
44 Busy = 7,
45 DeviceFault = 8,
46 Unsupported = 9,
48 SdoAbort = 16,
49 Protocol = 17,
50 BufferTooSmall = 18,
51 InvalidFrame = 19,
52 NodeState = 20,
53 DriveFault = 21,
54};
55
61constexpr const char* ToString(Error error) noexcept {
62 switch (error) {
63 case Error::Ok:
64 return "Ok";
66 return "NotInitialized";
68 return "InvalidArgument";
69 case Error::Bus:
70 return "Bus";
71 case Error::Timeout:
72 return "Timeout";
74 return "DeviceIdMismatch";
75 case Error::Crc:
76 return "Crc";
77 case Error::Busy:
78 return "Busy";
80 return "DeviceFault";
82 return "Unsupported";
83 case Error::SdoAbort:
84 return "SdoAbort";
85 case Error::Protocol:
86 return "Protocol";
88 return "BufferTooSmall";
90 return "InvalidFrame";
92 return "NodeState";
94 return "DriveFault";
95 default:
96 break;
97 }
98 return "Unknown";
99}
100
105template <typename T>
106struct [[nodiscard]] Result {
107 T value{};
108 Error error{Error::Ok};
109
111 [[nodiscard]] constexpr bool ok() const noexcept {
112 return error == Error::Ok;
113 }
115 constexpr explicit operator bool() const noexcept {
116 return ok();
117 }
123 static constexpr Result Success(T v) noexcept {
124 return {v, Error::Ok};
125 }
131 static constexpr Result Failure(Error e) noexcept {
132 return {T{}, e};
133 }
134};
135
137template <>
138struct [[nodiscard]] Result<void> {
139 Error error{Error::Ok};
140
142 [[nodiscard]] constexpr bool ok() const noexcept {
143 return error == Error::Ok;
144 }
146 constexpr explicit operator bool() const noexcept {
147 return ok();
148 }
150 static constexpr Result Success() noexcept {
151 return {Error::Ok};
152 }
158 static constexpr Result Failure(Error e) noexcept {
159 return {e};
160 }
161};
162
164enum class LogLevel : uint8_t {
165 Error = 0,
166 Warning,
167 Info,
168 Debug,
169};
170
172enum class Verify : uint8_t {
173 None = 0,
174 ReadBack,
175};
176
177// --- The CAN frame ---------------------------------------------------------------------------
178
180inline constexpr uint16_t kMaxCanId = 0x7FF;
182inline constexpr uint8_t kMaxDlc = 8;
183
190struct CanFrame {
191 uint16_t id{0};
192 uint8_t dlc{0};
193 bool rtr{false};
194 std::array<uint8_t, 8> data{};
195};
196
202constexpr bool IsValid(const CanFrame& frame) noexcept {
203 return (frame.id <= kMaxCanId) && (frame.dlc <= kMaxDlc);
204}
205
207enum class RxStatus : uint8_t {
208 Frame = 0,
209 Timeout,
210 Error,
211};
212
213// --- Identifiers -----------------------------------------------------------------------------
214
216inline constexpr uint8_t kBroadcastNode = 0;
218inline constexpr uint8_t kMinNodeId = 1;
220inline constexpr uint8_t kMaxNodeId = 127;
221
223inline constexpr uint16_t kCobIdNmt = 0x000;
225inline constexpr uint16_t kCobIdSync = 0x080;
227inline constexpr uint16_t kCobIdEmcyBase = 0x080;
229inline constexpr uint16_t kCobIdSdoResponseBase = 0x580;
231inline constexpr uint16_t kCobIdSdoRequestBase = 0x600;
233inline constexpr uint16_t kCobIdHeartbeatBase = 0x700;
235inline constexpr uint16_t kPdoCobIdMin = 0x181;
237inline constexpr uint16_t kPdoCobIdMax = 0x57F;
238
239// --- Capacities (fixed, no heap) -----------------------------------------------------------------
240
242inline constexpr std::size_t kMonitorCapacity = 16;
244inline constexpr std::size_t kPdoSubscriptionCapacity = 16;
246inline constexpr std::size_t kEmcyQueueCapacity = 8;
248inline constexpr std::size_t kMaxPdoEntries = 16;
250inline constexpr uint32_t kMaxFramesPerWait = 256;
252inline constexpr uint32_t kMaxDrainFrames = 64;
254inline constexpr uint32_t kMaxSdoSegments = 65536;
258inline constexpr uint32_t kMaxReceivesPerWait = 65536;
259
260// --- NMT ---------------------------------------------------------------------------------------
261
263enum class NmtCommand : uint8_t {
264 Start = 0x01,
265 Stop = 0x02,
266 PreOperational = 0x80,
267 ResetNode = 0x81,
268 ResetCommunication = 0x82,
269};
270
272enum class NmtState : uint8_t {
273 BootUp = 0x00,
274 Stopped = 0x04,
275 Operational = 0x05,
276 PreOperational = 0x7F,
277};
278
279// --- SDO ---------------------------------------------------------------------------------------
280
285enum class SdoAbortCode : uint32_t {
286 ToggleNotAlternated = 0x05030000,
287 Timeout = 0x05040000,
289 0x05040001,
290 InvalidBlockSize = 0x05040002,
291 InvalidSequenceNumber = 0x05040003,
292 CrcError = 0x05040004,
293 OutOfMemory = 0x05040005,
294 UnsupportedAccess = 0x06010000,
295 WriteOnly = 0x06010001,
296 ReadOnly = 0x06010002,
297 ObjectNotFound = 0x06020000,
298 NotMappable = 0x06040041,
299 PdoLengthExceeded = 0x06040042,
300 ParameterIncompatible = 0x06040043,
301 InternalIncompatibility = 0x06040047,
302 HardwareError = 0x06060000,
304 0x06070010,
305 LengthTooHigh = 0x06070012,
306 LengthTooLow = 0x06070013,
307 SubIndexNotFound = 0x06090011,
308 InvalidValue = 0x06090030,
309 ValueTooHigh = 0x06090031,
310 ValueTooLow = 0x06090032,
311 MaxLessThanMin = 0x06090036,
312 SdoResourceUnavailable = 0x060A0023,
313 GeneralError = 0x08000000,
314 StoreFailed = 0x08000020,
315 LocalControl = 0x08000021,
316 DeviceState = 0x08000022,
317 NoDictionary = 0x08000023,
318 NoData = 0x08000024,
319};
320
321namespace detail {
322
324struct AbortName {
325 SdoAbortCode code;
326 const char* name;
327};
328
330inline constexpr std::array<AbortName, 31> kAbortNames{{
331 {.code = SdoAbortCode::ToggleNotAlternated, .name = "ToggleNotAlternated"},
332 {.code = SdoAbortCode::Timeout, .name = "Timeout"},
333 {.code = SdoAbortCode::InvalidCommandSpecifier, .name = "InvalidCommandSpecifier"},
334 {.code = SdoAbortCode::InvalidBlockSize, .name = "InvalidBlockSize"},
335 {.code = SdoAbortCode::InvalidSequenceNumber, .name = "InvalidSequenceNumber"},
336 {.code = SdoAbortCode::CrcError, .name = "CrcError"},
337 {.code = SdoAbortCode::OutOfMemory, .name = "OutOfMemory"},
338 {.code = SdoAbortCode::UnsupportedAccess, .name = "UnsupportedAccess"},
339 {.code = SdoAbortCode::WriteOnly, .name = "WriteOnly"},
340 {.code = SdoAbortCode::ReadOnly, .name = "ReadOnly"},
341 {.code = SdoAbortCode::ObjectNotFound, .name = "ObjectNotFound"},
342 {.code = SdoAbortCode::NotMappable, .name = "NotMappable"},
343 {.code = SdoAbortCode::PdoLengthExceeded, .name = "PdoLengthExceeded"},
344 {.code = SdoAbortCode::ParameterIncompatible, .name = "ParameterIncompatible"},
345 {.code = SdoAbortCode::InternalIncompatibility, .name = "InternalIncompatibility"},
346 {.code = SdoAbortCode::HardwareError, .name = "HardwareError"},
347 {.code = SdoAbortCode::LengthMismatch, .name = "LengthMismatch"},
348 {.code = SdoAbortCode::LengthTooHigh, .name = "LengthTooHigh"},
349 {.code = SdoAbortCode::LengthTooLow, .name = "LengthTooLow"},
350 {.code = SdoAbortCode::SubIndexNotFound, .name = "SubIndexNotFound"},
351 {.code = SdoAbortCode::InvalidValue, .name = "InvalidValue"},
352 {.code = SdoAbortCode::ValueTooHigh, .name = "ValueTooHigh"},
353 {.code = SdoAbortCode::ValueTooLow, .name = "ValueTooLow"},
354 {.code = SdoAbortCode::MaxLessThanMin, .name = "MaxLessThanMin"},
355 {.code = SdoAbortCode::SdoResourceUnavailable, .name = "SdoResourceUnavailable"},
356 {.code = SdoAbortCode::GeneralError, .name = "GeneralError"},
357 {.code = SdoAbortCode::StoreFailed, .name = "StoreFailed"},
358 {.code = SdoAbortCode::LocalControl, .name = "LocalControl"},
359 {.code = SdoAbortCode::DeviceState, .name = "DeviceState"},
360 {.code = SdoAbortCode::NoDictionary, .name = "NoDictionary"},
361 {.code = SdoAbortCode::NoData, .name = "NoData"},
362}};
363
364} // namespace detail
365
371constexpr const char* AbortCodeName(uint32_t code) noexcept {
372 for (const detail::AbortName& entry : detail::kAbortNames) {
373 if (static_cast<uint32_t>(entry.code) == code) {
374 return entry.name;
375 }
376 }
377 return "Unknown";
378}
379
382 uint8_t node{0};
383 uint16_t index{0};
384 uint8_t sub{0};
385 uint32_t code{0};
386 bool remote{false};
387};
388
390enum class SdoReplyKind : uint8_t {
391 InitiateDownload = 0,
395 Abort,
396};
397
399struct SdoReply {
401 uint16_t index{0};
402 uint8_t sub{0};
403 bool toggle{false};
404 bool last{false};
405 bool expedited{false};
406 bool size_indicated{false};
407 uint8_t data_len{0};
408 uint32_t size{0};
409 std::array<uint8_t, 7> data{};
410};
411
412// --- Heartbeat, guarding, EMCY, PDO
413// ---------------------------------------------------------------
414
417 uint8_t node{0};
419 bool toggle{false};
420};
421
425 bool seen{false};
426 bool bootup_seen{false};
427 bool alive{false};
428 uint32_t last_us{0};
429 uint32_t count{0};
430};
431
433struct EmcyEvent {
434 uint8_t node{0};
435 uint16_t code{0};
436 uint8_t error_register{0};
437 std::array<uint8_t, 5> manufacturer{};
438 uint32_t timestamp_us{0};
439};
440
442struct PdoSample {
443 uint16_t cob_id{0};
444 uint8_t dlc{0};
445 std::array<uint8_t, 8> data{};
446 uint32_t sequence{0};
447 uint32_t timestamp_us{0};
448};
449
451enum class FrameClass : uint8_t {
452 None = 0,
453 Heartbeat,
454 Emcy,
455 Pdo,
456 Sync,
457 Ignored,
458 Invalid,
459};
460
462struct Stats {
463 uint32_t frames_received{0};
464 uint32_t frames_invalid{0};
465 uint32_t sdo_stale{0};
466 uint32_t emcy_dropped{0};
467 uint32_t flood_aborts{0};
468};
469
471enum class PdoKind : uint8_t {
472 Receive = 0,
473 Transmit = 1,
474};
475
478 uint16_t index{0};
479 uint8_t sub{0};
480 uint8_t bits{0};
481};
482
484struct PdoConfig {
485 uint16_t cob_id{0};
486 uint8_t transmission_type{0xFF};
488 uint16_t inhibit_time_100us{0};
489 uint16_t event_timer_ms{0};
490 bool enabled{true};
491 uint8_t entry_count{0};
492 std::array<PdoMapEntry, kMaxPdoEntries> entries{};
493};
494
495// --- CiA 402 -----------------------------------------------------------------------------------
496
498enum class DriveState : uint8_t {
499 NotReadyToSwitchOn = 0,
500 SwitchOnDisabled,
501 ReadyToSwitchOn,
502 SwitchedOn,
503 OperationEnabled,
504 QuickStopActive,
505 FaultReactionActive,
506 Fault,
507 Unknown,
508};
509
515constexpr const char* ToString(DriveState state) noexcept {
516 switch (state) {
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:
524 return "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:
532 return "Fault";
534 return "Unknown";
535 default:
536 break;
537 }
538 return "Unknown";
539}
540
542enum class OperationMode : int8_t {
543 NoMode = 0,
544 ProfilePosition = 1,
545 Velocity = 2,
546 ProfileVelocity = 3,
547 ProfileTorque = 4,
548 Homing = 6,
549 InterpolatedPosition = 7,
550 CyclicSynchronousPosition = 8,
551 CyclicSynchronousVelocity = 9,
552 CyclicSynchronousTorque = 10,
553};
554
558 uint16_t controlword{0x6040};
559 uint16_t statusword{0x6041};
560 uint16_t mode{0x6060};
561 uint16_t mode_display{0x6061};
562};
563
565inline constexpr uint16_t kControlShutdown = 0x0006;
567inline constexpr uint16_t kControlSwitchOn = 0x0007;
569inline constexpr uint16_t kControlDisableVoltage = 0x0000;
571inline constexpr uint16_t kControlQuickStop = 0x0002;
573inline constexpr uint16_t kControlEnableOperation = 0x000F;
575inline constexpr uint16_t kControlFaultReset = 0x0080;
576
577// --- Configuration -----------------------------------------------------------------------------
578
580struct Config {
581 uint32_t sdo_timeout_us{200'000};
582 uint32_t guard_timeout_us{100'000};
583 uint32_t drive_timeout_us{2'000'000};
584 uint32_t drive_poll_interval_us{10'000};
585 uint8_t safety_attempts{3};
586 bool abort_on_timeout{true};
587 bool strict_sdo_length{true};
588};
589
591inline constexpr uint32_t kMaxSdoTimeoutUs = 60'000'000;
592
598constexpr Error Validate(const Config& config) noexcept {
599 const bool sdo_ok =
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);
605 const bool poll_ok =
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) {
609 return Error::Ok;
610 }
612}
613
618constexpr Config FastBusPreset() noexcept {
619 Config c{};
620 c.sdo_timeout_us = 50'000;
621 c.guard_timeout_us = 20'000;
622 c.drive_poll_interval_us = 2'000;
623 return c;
624}
625
630constexpr Config SlowBusPreset() noexcept {
631 Config c{};
632 c.sdo_timeout_us = 1'000'000;
633 c.guard_timeout_us = 500'000;
634 c.drive_timeout_us = 5'000'000;
635 c.drive_poll_interval_us = 50'000;
636 return c;
637}
638
640constexpr const char* GetDriverVersion() noexcept {
641 return CANOPEN_CLIENT_VERSION_STRING;
642}
644constexpr uint32_t GetDriverVersionMajor() noexcept {
645 return CANOPEN_CLIENT_VERSION_MAJOR;
646}
648constexpr uint32_t GetDriverVersionMinor() noexcept {
649 return CANOPEN_CLIENT_VERSION_MINOR;
650}
652constexpr uint32_t GetDriverVersionPatch() noexcept {
653 return CANOPEN_CLIENT_VERSION_PATCH;
654}
655
658} // namespace canopen_client
659
660#endif // CANOPEN_CLIENT_TYPES_HPP
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.
@ 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.
@ Info
Lifecycle events.
@ 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.
@ Ok
The call succeeded.
@ 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