CANOPEN_CLIENT Driver 0.1.0
API reference
Loading...
Searching...
No Matches
canopen_client_protocol.hpp
Go to the documentation of this file.
1
13#ifndef CANOPEN_CLIENT_PROTOCOL_HPP
14#define CANOPEN_CLIENT_PROTOCOL_HPP
15
16#include <array>
17#include <cstddef>
18#include <cstdint>
19#include <span>
20
23
24namespace canopen_client {
25
37constexpr bool IsNodeId(uint8_t node) noexcept {
38 return (node >= kMinNodeId) && (node <= kMaxNodeId);
39}
40
46constexpr uint16_t SdoRequestId(uint8_t node) noexcept {
47 return static_cast<uint16_t>(detail::Widen(kCobIdSdoRequestBase) + detail::Widen(node));
48}
49
55constexpr uint16_t SdoResponseId(uint8_t node) noexcept {
56 return static_cast<uint16_t>(detail::Widen(kCobIdSdoResponseBase) + detail::Widen(node));
57}
58
64constexpr uint16_t HeartbeatId(uint8_t node) noexcept {
65 return static_cast<uint16_t>(detail::Widen(kCobIdHeartbeatBase) + detail::Widen(node));
66}
67
73constexpr uint16_t EmcyId(uint8_t node) noexcept {
74 return static_cast<uint16_t>(detail::Widen(kCobIdEmcyBase) + detail::Widen(node));
75}
76
82constexpr bool IsNmtCommand(uint8_t command) noexcept {
83 return (command == static_cast<uint8_t>(NmtCommand::Start)) ||
84 (command == static_cast<uint8_t>(NmtCommand::Stop)) ||
85 (command == static_cast<uint8_t>(NmtCommand::PreOperational)) ||
86 (command == static_cast<uint8_t>(NmtCommand::ResetNode)) ||
87 (command == static_cast<uint8_t>(NmtCommand::ResetCommunication));
88}
89
96constexpr bool DecodeNmtState(uint8_t raw, NmtState& state) noexcept {
97 switch (raw) {
98 case static_cast<uint8_t>(NmtState::BootUp):
99 state = NmtState::BootUp;
100 return true;
101 case static_cast<uint8_t>(NmtState::Stopped):
102 state = NmtState::Stopped;
103 return true;
104 case static_cast<uint8_t>(NmtState::Operational):
105 state = NmtState::Operational;
106 return true;
107 case static_cast<uint8_t>(NmtState::PreOperational):
109 return true;
110 default:
111 break;
112 }
113 return false;
114}
115
116// --- Builders ----------------------------------------------------------------------------------
117
124constexpr Result<CanFrame> MakeNmtFrame(NmtCommand command, uint8_t node) noexcept {
125 using detail::operator""_u8;
126 const auto raw = static_cast<uint8_t>(command);
127 if ((node > kMaxNodeId) || !IsNmtCommand(raw)) {
129 }
130 CanFrame f{};
131 f.id = kCobIdNmt;
132 f.dlc = 2_u8;
133 f.data[0] = raw;
134 f.data[1] = node;
136}
137
143constexpr Result<CanFrame> MakeSyncFrame(uint8_t counter) noexcept {
144 using detail::operator""_u8;
145 if (counter > 240_u8) {
147 }
148 CanFrame f{};
149 f.id = kCobIdSync;
150 if (counter != 0_u8) {
151 f.dlc = 1_u8;
152 f.data[0] = counter;
153 }
155}
156
162constexpr Result<CanFrame> MakeGuardRequest(uint8_t node) noexcept {
163 if (!IsNodeId(node)) {
165 }
166 CanFrame f{};
167 f.id = HeartbeatId(node);
168 f.rtr = true;
170}
171
178constexpr Result<CanFrame> MakePdoFrame(uint16_t cob_id, std::span<const uint8_t> data) noexcept {
179 if ((cob_id < kPdoCobIdMin) || (cob_id > kPdoCobIdMax) || (data.size() > kMaxDlc)) {
181 }
182 CanFrame f{};
183 f.id = cob_id;
184 f.dlc = static_cast<uint8_t>(data.size());
185 for (std::size_t i = 0; i < data.size(); ++i) {
186 f.data[i] = data[i];
187 }
189}
190
191namespace detail {
192
194constexpr CanFrame SdoRequestBase(uint8_t node, uint8_t command, uint16_t index,
195 uint8_t sub) noexcept {
196 using detail::operator""_u8;
197 CanFrame f{};
198 f.id = SdoRequestId(node);
199 f.dlc = 8_u8;
200 f.data[0] = command;
201 f.data[1] = static_cast<uint8_t>(Widen(index) & 0xFFU);
202 f.data[2] = static_cast<uint8_t>(Widen(index) >> 8U);
203 f.data[3] = sub;
204 return f;
205}
206
207} // namespace detail
208
216constexpr Result<CanFrame> MakeSdoUploadRequest(uint8_t node, uint16_t index,
217 uint8_t sub) noexcept {
218 using detail::operator""_u8;
219 if (!IsNodeId(node)) {
221 }
222 return Result<CanFrame>::Success(detail::SdoRequestBase(node, 0x40_u8, index, sub));
223}
224
234constexpr Result<CanFrame> MakeSdoExpeditedDownload(uint8_t node, uint16_t index, uint8_t sub,
235 std::span<const uint8_t> data) noexcept {
236 if (!IsNodeId(node) || data.empty() || (data.size() > 4U)) {
238 }
239 const auto unused = static_cast<uint32_t>(4U - data.size());
240 const auto command = static_cast<uint8_t>(0x23U | (unused << 2U));
241 CanFrame f = detail::SdoRequestBase(node, command, index, sub);
242 for (std::size_t i = 0; i < data.size(); ++i) {
243 f.data[4U + i] = data[i];
244 }
246}
247
256constexpr Result<CanFrame> MakeSdoSegmentedDownload(uint8_t node, uint16_t index, uint8_t sub,
257 uint32_t size) noexcept {
258 using detail::operator""_u8;
259 if (!IsNodeId(node) || (size == 0U)) {
261 }
262 CanFrame f = detail::SdoRequestBase(node, 0x21_u8, index, sub);
263 detail::StoreLe32At4(f.data, size);
265}
266
275constexpr Result<CanFrame> MakeSdoDownloadSegment(uint8_t node, bool toggle,
276 std::span<const uint8_t> data,
277 bool last) noexcept {
278 using detail::operator""_u8;
279 if (!IsNodeId(node) || data.empty() || (data.size() > 7U)) {
281 }
282 const uint32_t unused = 7U - static_cast<uint32_t>(data.size());
283 const uint32_t command = (toggle ? 0x10U : 0U) | (unused << 1U) | (last ? 1U : 0U);
284 CanFrame f{};
285 f.id = SdoRequestId(node);
286 f.dlc = 8_u8;
287 f.data[0] = static_cast<uint8_t>(command);
288 for (std::size_t i = 0; i < data.size(); ++i) {
289 f.data[1U + i] = data[i];
290 }
292}
293
300constexpr Result<CanFrame> MakeSdoUploadSegmentRequest(uint8_t node, bool toggle) noexcept {
301 using detail::operator""_u8;
302 if (!IsNodeId(node)) {
304 }
305 CanFrame f{};
306 f.id = SdoRequestId(node);
307 f.dlc = 8_u8;
308 f.data[0] = toggle ? 0x70_u8 : 0x60_u8;
310}
311
320constexpr Result<CanFrame> MakeSdoAbort(uint8_t node, uint16_t index, uint8_t sub,
321 uint32_t code) noexcept {
322 using detail::operator""_u8;
323 if (!IsNodeId(node)) {
325 }
326 CanFrame f = detail::SdoRequestBase(node, 0x80_u8, index, sub);
327 detail::StoreLe32At4(f.data, code);
329}
330
331// --- Decoders ----------------------------------------------------------------------------------
332
333namespace detail {
334
336constexpr Result<SdoReply> ParseInitiateUpload(const CanFrame& f, SdoReply r,
337 bool strict) noexcept {
338 using detail::operator""_u8;
339 const uint32_t b0 = Widen(f.data[0]);
340 const bool expedited = TestBit(b0, 1U);
341 const bool sized = TestBit(b0, 0U);
342 r.expedited = expedited;
343 r.size_indicated = sized;
344 if (expedited) {
345 const uint32_t len = sized ? (4U - ((b0 >> 2U) & 3U)) : 4U;
346 if ((Widen(f.dlc) < (4U + len)) || (strict && (f.dlc != 8_u8))) {
348 }
349 r.data_len = static_cast<uint8_t>(len);
350 for (uint32_t i = 0U; i < len; ++i) {
351 r.data[i] = f.data[4U + i];
352 }
354 }
355 const uint32_t need = sized ? 8U : 4U;
356 if ((Widen(f.dlc) < need) || (strict && (f.dlc != 8_u8))) {
358 }
359 r.size = sized ? LoadLe32At4(f.data) : 0U;
361}
362
364constexpr Result<SdoReply> ParseUploadSegment(const CanFrame& f, SdoReply r, bool strict) noexcept {
365 using detail::operator""_u8;
366 const uint32_t b0 = Widen(f.data[0]);
367 const uint32_t len = 7U - ((b0 >> 1U) & 7U);
368 if ((Widen(f.dlc) < (1U + len)) || (strict && (f.dlc != 8_u8))) {
370 }
371 r.toggle = TestBit(b0, 4U);
372 r.last = TestBit(b0, 0U);
373 r.data_len = static_cast<uint8_t>(len);
374 for (uint32_t i = 0U; i < len; ++i) {
375 r.data[i] = f.data[1U + i];
376 }
378}
379
381constexpr Result<SdoReply> ParseDownloadSegment(const CanFrame& f, SdoReply r,
382 bool strict) noexcept {
383 using detail::operator""_u8;
385 r.toggle = TestBit(Widen(f.data[0]), 4U);
386 return (strict && (f.dlc != 8_u8)) ? Result<SdoReply>::Failure(Error::InvalidFrame)
387 : Result<SdoReply>::Success(r);
388}
389
391constexpr Result<SdoReply> ParseAbort(const CanFrame& f, SdoReply r, uint32_t scs) noexcept {
392 using detail::operator""_u8;
393 if ((scs == 4U) && (f.dlc == 8_u8)) {
394 r.kind = SdoReplyKind::Abort;
395 r.size = LoadLe32At4(f.data);
397 }
399}
400
401} // namespace detail
402
415constexpr Result<SdoReply> ParseSdoReply(const CanFrame& frame, bool strict) noexcept {
416 using detail::operator""_u8;
417 if (frame.rtr || (frame.dlc < 1_u8) || (frame.dlc > kMaxDlc)) {
419 }
420 SdoReply r{};
421 const uint32_t b0 = detail::Widen(frame.data[0]);
422 const uint32_t scs = b0 >> 5U;
423 const bool header_ok = (frame.dlc >= 4_u8);
424 if (scs == 1U) { // download segment response
425 return detail::ParseDownloadSegment(frame, r, strict);
426 }
427 if (scs == 0U) { // upload segment
429 return detail::ParseUploadSegment(frame, r, strict);
430 }
431 if (!header_ok || ((scs != 4U) && strict && (frame.dlc != 8_u8))) {
433 }
434 r.index = detail::Le16(frame.data[1], frame.data[2]);
435 r.sub = frame.data[3];
436 if (scs == 3U) { // initiate download response
439 }
440 if (scs == 2U) { // initiate upload response
442 return detail::ParseInitiateUpload(frame, r, strict);
443 }
444 return detail::ParseAbort(frame, r, scs);
445}
446
453constexpr Result<HeartbeatInfo> ParseHeartbeat(const CanFrame& frame) noexcept {
454 using detail::operator""_u8;
455 const uint32_t id = detail::Widen(frame.id);
456 const uint32_t base = detail::Widen(kCobIdHeartbeatBase);
457 if (frame.rtr || (frame.dlc != 1_u8) || (id <= base) ||
458 (id > (base + detail::Widen(kMaxNodeId)))) {
460 }
461 HeartbeatInfo h{};
462 h.node = static_cast<uint8_t>(id - base);
463 h.toggle = detail::TestBit(detail::Widen(frame.data[0]), 7U);
464 const auto raw = static_cast<uint8_t>(detail::Widen(frame.data[0]) & 0x7FU);
465 if (!DecodeNmtState(raw, h.state)) {
467 }
469}
470
477constexpr Result<EmcyEvent> ParseEmcy(const CanFrame& frame) noexcept {
478 using detail::operator""_u8;
479 const uint32_t id = detail::Widen(frame.id);
480 const uint32_t base = detail::Widen(kCobIdEmcyBase);
481 if (frame.rtr || (frame.dlc != 8_u8) || (id <= base) ||
482 (id > (base + detail::Widen(kMaxNodeId)))) {
484 }
485 EmcyEvent e{};
486 e.node = static_cast<uint8_t>(id - base);
487 e.code = detail::Le16(frame.data[0], frame.data[1]);
488 e.error_register = frame.data[2];
489 for (std::size_t i = 0; i < e.manufacturer.size(); ++i) {
490 e.manufacturer[i] = frame.data[3U + i];
491 }
493}
494
495// --- PDO ----------------------------------------------------------------------------------------
496
503constexpr Result<uint16_t> PdoCommunicationIndex(PdoKind kind, uint16_t number) noexcept {
504 using detail::operator""_u16;
505 if ((number < 1_u16) || (number > 512_u16)) {
507 }
508 const uint32_t base = (kind == PdoKind::Receive) ? 0x1400U : 0x1800U;
509 return Result<uint16_t>::Success(static_cast<uint16_t>(base + detail::Widen(number) - 1U));
510}
511
518constexpr Result<uint16_t> PdoMappingIndex(PdoKind kind, uint16_t number) noexcept {
519 const auto comm = PdoCommunicationIndex(kind, number);
520 if (!comm) {
521 return comm;
522 }
523 return Result<uint16_t>::Success(static_cast<uint16_t>(detail::Widen(comm.value) + 0x200U));
524}
525
531constexpr uint32_t EncodePdoMapEntry(const PdoMapEntry& entry) noexcept {
532 return (detail::Widen(entry.index) << 16U) | (detail::Widen(entry.sub) << 8U) |
533 detail::Widen(entry.bits);
534}
535
541constexpr PdoMapEntry DecodePdoMapEntry(uint32_t record) noexcept {
542 PdoMapEntry e{};
543 e.index = static_cast<uint16_t>(record >> 16U);
544 e.sub = static_cast<uint8_t>((record >> 8U) & 0xFFU);
545 e.bits = static_cast<uint8_t>(record & 0xFFU);
546 return e;
547}
548
556constexpr Error ValidatePdoConfig(const PdoConfig& config) noexcept {
557 using detail::operator""_u8;
558 using detail::operator""_u16;
559 if ((config.cob_id < kPdoCobIdMin) || (config.cob_id > kPdoCobIdMax) ||
560 (config.entry_count > kMaxPdoEntries)) {
562 }
563 if ((config.transmission_type >= 241_u8) && (config.transmission_type <= 251_u8)) {
564 return Error::InvalidArgument; // reserved
565 }
566 uint32_t total = 0U;
567 for (std::size_t i = 0; i < config.entry_count; ++i) {
568 const PdoMapEntry& e = config.entries[i];
569 if ((e.index == 0_u16) || (e.bits < 1_u8) || (e.bits > 64_u8)) {
571 }
572 total += detail::Widen(e.bits);
573 }
574 return (total <= 64U) ? Error::Ok : Error::InvalidArgument;
575}
576
582constexpr uint32_t PdoBitLength(const PdoConfig& config) noexcept {
583 uint32_t total = 0U;
584 for (std::size_t i = 0; (i < config.entry_count) && (i < config.entries.size()); ++i) {
585 total += detail::Widen(config.entries[i].bits);
586 }
587 return total;
588}
589
599constexpr Result<uint64_t> ExtractBits(std::span<const uint8_t> data, uint32_t offset,
600 uint32_t bits) noexcept {
601 const uint64_t end = static_cast<uint64_t>(offset) + bits;
602 if ((bits < 1U) || (bits > 64U) || (end > (static_cast<uint64_t>(data.size()) * 8U))) {
604 }
605 uint64_t value = 0U;
606 for (uint32_t i = 0U; i < bits; ++i) {
607 const uint32_t bit = offset + i;
608 const uint32_t b = (detail::Widen(data[bit / 8U]) >> (bit % 8U)) & 1U;
609 value |= static_cast<uint64_t>(b) << i;
610 }
611 return Result<uint64_t>::Success(value);
612}
613
623constexpr Result<void> InsertBits(std::span<uint8_t> data, uint32_t offset, uint32_t bits,
624 uint64_t value) noexcept {
625 const uint64_t end = static_cast<uint64_t>(offset) + bits;
626 if ((bits < 1U) || (bits > 64U) || (end > (static_cast<uint64_t>(data.size()) * 8U))) {
628 }
629 for (uint32_t i = 0U; i < bits; ++i) {
630 const uint32_t bit = offset + i;
631 const uint32_t mask = 1U << (bit % 8U);
632 const uint32_t old = detail::Widen(data[bit / 8U]);
633 const bool set = ((value >> i) & 1U) != 0U;
634 data[bit / 8U] = static_cast<uint8_t>(set ? (old | mask) : (old & ~mask));
635 }
636 return Result<void>::Success();
637}
638
639// --- CiA 402 -----------------------------------------------------------------------------------
640
647constexpr DriveState DecodeStatusword(uint16_t statusword) noexcept {
648 const uint32_t sw = detail::Widen(statusword);
649 const uint32_t low = sw & 0x4FU;
650 const uint32_t quick = sw & 0x6FU;
651 if (low == 0x00U) {
652 return DriveState::NotReadyToSwitchOn;
653 }
654 if (low == 0x40U) {
655 return DriveState::SwitchOnDisabled;
656 }
657 if (low == 0x0FU) {
658 return DriveState::FaultReactionActive;
659 }
660 if (low == 0x08U) {
661 return DriveState::Fault;
662 }
663 if (quick == 0x21U) {
664 return DriveState::ReadyToSwitchOn;
665 }
666 if (quick == 0x23U) {
667 return DriveState::SwitchedOn;
668 }
669 if (quick == 0x27U) {
670 return DriveState::OperationEnabled;
671 }
672 if (quick == 0x07U) {
673 return DriveState::QuickStopActive;
674 }
675 return DriveState::Unknown;
676}
677
687constexpr bool EnableStepControlword(DriveState state, uint16_t& word) noexcept {
688 switch (state) {
689 case DriveState::SwitchOnDisabled:
690 word = kControlShutdown;
691 return true;
692 case DriveState::ReadyToSwitchOn:
693 word = kControlSwitchOn;
694 return true;
695 case DriveState::SwitchedOn:
697 return true;
698 case DriveState::QuickStopActive:
700 return true;
701 case DriveState::NotReadyToSwitchOn:
702 case DriveState::OperationEnabled:
703 case DriveState::FaultReactionActive:
704 case DriveState::Fault:
706 break;
707 default:
708 break;
709 }
710 return false;
711}
712
715} // namespace canopen_client
716
717#endif // CANOPEN_CLIENT_PROTOCOL_HPP
Compile-time helpers of the CANOPEN_CLIENT driver: typed integer literals, exact hook matching,...
Public types of the CANopen client driver: errors, Result<T>, the CAN frame, the protocol vocabulary ...
constexpr uint32_t PdoBitLength(const PdoConfig &config) noexcept
The bits the entries of a PDO occupy in all.
Definition canopen_client_protocol.hpp:582
constexpr Result< CanFrame > MakeSyncFrame(uint8_t counter) noexcept
The SYNC frame: identifier 0x080, no data, or one counter byte.
Definition canopen_client_protocol.hpp:143
constexpr uint16_t SdoRequestId(uint8_t node) noexcept
The identifier of the SDO request frames to node.
Definition canopen_client_protocol.hpp:46
constexpr Result< CanFrame > MakeSdoAbort(uint8_t node, uint16_t index, uint8_t sub, uint32_t code) noexcept
The abort frame the client sends to end a transfer: command byte 0x80.
Definition canopen_client_protocol.hpp:320
constexpr Result< SdoReply > ParseSdoReply(const CanFrame &frame, bool strict) noexcept
Decode a frame from an SDO server (identifier 0x580 + node).
Definition canopen_client_protocol.hpp:415
constexpr uint16_t EmcyId(uint8_t node) noexcept
The identifier of the emergency frames of node.
Definition canopen_client_protocol.hpp:73
constexpr Result< CanFrame > MakeSdoSegmentedDownload(uint8_t node, uint16_t index, uint8_t sub, uint32_t size) noexcept
The segmented initiate-download request announcing size bytes: command byte 0x21.
Definition canopen_client_protocol.hpp:256
constexpr bool EnableStepControlword(DriveState state, uint16_t &word) noexcept
The controlword that moves a drive one step toward Operation enabled.
Definition canopen_client_protocol.hpp:687
constexpr uint32_t EncodePdoMapEntry(const PdoMapEntry &entry) noexcept
The 32-bit mapping record: index << 16 | sub-index << 8 | length in bits.
Definition canopen_client_protocol.hpp:531
constexpr Result< CanFrame > MakeSdoExpeditedDownload(uint8_t node, uint16_t index, uint8_t sub, std::span< const uint8_t > data) noexcept
The expedited initiate-download request (write 1 to 4 bytes): command byte 0x23 | (4 - size) << 2.
Definition canopen_client_protocol.hpp:234
constexpr Result< CanFrame > MakeNmtFrame(NmtCommand command, uint8_t node) noexcept
The NMT command frame: identifier 0x000, two data bytes.
Definition canopen_client_protocol.hpp:124
constexpr Result< CanFrame > MakeSdoUploadSegmentRequest(uint8_t node, bool toggle) noexcept
The request for the next upload segment: command byte 0x60 | toggle << 4.
Definition canopen_client_protocol.hpp:300
constexpr Result< CanFrame > MakeGuardRequest(uint8_t node) noexcept
The node-guarding request: a remote frame on 0x700 + node.
Definition canopen_client_protocol.hpp:162
constexpr Result< uint16_t > PdoMappingIndex(PdoKind kind, uint16_t number) noexcept
The index of the mapping parameter record of a PDO.
Definition canopen_client_protocol.hpp:518
constexpr bool IsNodeId(uint8_t node) noexcept
Whether a node identifier is in 1 to 127.
Definition canopen_client_protocol.hpp:37
constexpr uint16_t HeartbeatId(uint8_t node) noexcept
The identifier of the heartbeat and node-guarding frames of node.
Definition canopen_client_protocol.hpp:64
constexpr Result< uint16_t > PdoCommunicationIndex(PdoKind kind, uint16_t number) noexcept
The index of the communication parameter record of a PDO.
Definition canopen_client_protocol.hpp:503
constexpr PdoMapEntry DecodePdoMapEntry(uint32_t record) noexcept
Split a 32-bit mapping record into its object and length.
Definition canopen_client_protocol.hpp:541
constexpr uint16_t SdoResponseId(uint8_t node) noexcept
The identifier of the SDO reply frames from node.
Definition canopen_client_protocol.hpp:55
constexpr Result< HeartbeatInfo > ParseHeartbeat(const CanFrame &frame) noexcept
Decode a heartbeat, boot-up or node-guarding reply: identifier 0x701 to 0x77F, one byte.
Definition canopen_client_protocol.hpp:453
constexpr Result< CanFrame > MakeSdoDownloadSegment(uint8_t node, bool toggle, std::span< const uint8_t > data, bool last) noexcept
One download segment: command byte toggle << 4 | (7 - length) << 1 | last.
Definition canopen_client_protocol.hpp:275
constexpr Result< CanFrame > MakePdoFrame(uint16_t cob_id, std::span< const uint8_t > data) noexcept
A PDO frame: a valid identifier and 0 to 8 data bytes.
Definition canopen_client_protocol.hpp:178
constexpr Result< void > InsertBits(std::span< uint8_t > data, uint32_t offset, uint32_t bits, uint64_t value) noexcept
Write the low bits bits of value at bit offset of a PDO payload; the other bits are unchanged.
Definition canopen_client_protocol.hpp:623
constexpr Result< EmcyEvent > ParseEmcy(const CanFrame &frame) noexcept
Decode an emergency message: identifier 0x081 to 0x0FF, eight bytes (error code, error register,...
Definition canopen_client_protocol.hpp:477
constexpr bool DecodeNmtState(uint8_t raw, NmtState &state) noexcept
Decode the state byte of a heartbeat (bit 7 already cleared).
Definition canopen_client_protocol.hpp:96
constexpr Error ValidatePdoConfig(const PdoConfig &config) noexcept
Check a PDO configuration: identifier range, a transmission type that is not reserved (241 to 251),...
Definition canopen_client_protocol.hpp:556
constexpr Result< uint64_t > ExtractBits(std::span< const uint8_t > data, uint32_t offset, uint32_t bits) noexcept
Read bits bits starting at bit offset of a PDO payload (Intel bit order: bit 0 is the least significa...
Definition canopen_client_protocol.hpp:599
constexpr bool IsNmtCommand(uint8_t command) noexcept
Whether a command byte is one of the five NMT commands.
Definition canopen_client_protocol.hpp:82
constexpr Result< CanFrame > MakeSdoUploadRequest(uint8_t node, uint16_t index, uint8_t sub) noexcept
The initiate-upload request (read an object): command byte 0x40.
Definition canopen_client_protocol.hpp:216
constexpr DriveState DecodeStatusword(uint16_t statusword) noexcept
Decode the drive state from a statusword (object 0x6041): the masks 0x4F and 0x6F of the state machin...
Definition canopen_client_protocol.hpp:647
constexpr uint8_t kMinNodeId
Lowest valid node identifier.
Definition canopen_client_types.hpp:218
NmtCommand
NMT master command (the first data byte of the frame on identifier 0x000).
Definition canopen_client_types.hpp:263
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 uint16_t kCobIdEmcyBase
EMCY identifiers are this plus the node identifier.
Definition canopen_client_types.hpp:227
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 uint16_t kCobIdSdoResponseBase
SDO response (server to client) identifiers are this plus the node identifier.
Definition canopen_client_types.hpp:229
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
constexpr uint16_t kControlDisableVoltage
Controlword: disable voltage (to Switch on disabled).
Definition canopen_client_types.hpp:569
constexpr uint16_t kControlSwitchOn
Controlword: switch on (to Switched on).
Definition canopen_client_types.hpp:567
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 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.
@ BootUp
The boot-up message; the node continues to Pre-operational.
@ Operational
SDO and PDO are on.
@ PreOperational
SDO is on, PDO is off.
@ Stopped
Only NMT and heartbeat; SDO and PDO are off.
@ 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).
@ Receive
RPDO: the node consumes it.
@ InvalidArgument
An argument or a Config field is out of range; nothing was sent.
@ InvalidFrame
A frame fails validation (identifier, length or content).
@ Ok
The call succeeded.
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
std::array< uint8_t, 8 > data
The payload; bytes at and past dlc are not meaningful.
Definition canopen_client_types.hpp:194
uint16_t id
The 11-bit identifier (COB-ID).
Definition canopen_client_types.hpp:191
One emergency message (EMCY).
Definition canopen_client_types.hpp:433
uint8_t node
The node that sent it.
Definition canopen_client_types.hpp:434
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
The communication and mapping parameters of one PDO.
Definition canopen_client_types.hpp:484
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
The value of a call, or why there is none.
Definition canopen_client_types.hpp:106
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
A decoded SDO server reply.
Definition canopen_client_types.hpp:399