CANOPEN_CLIENT Driver 0.1.0
API reference
Loading...
Searching...
No Matches
Functions
Frame codecs

Pure builders and decoders for every frame the client sends or reads. More...

Functions

constexpr bool canopen_client::IsNodeId (uint8_t node) noexcept
 Whether a node identifier is in 1 to 127.
 
constexpr uint16_t canopen_client::SdoRequestId (uint8_t node) noexcept
 The identifier of the SDO request frames to node.
 
constexpr uint16_t canopen_client::SdoResponseId (uint8_t node) noexcept
 The identifier of the SDO reply frames from node.
 
constexpr uint16_t canopen_client::HeartbeatId (uint8_t node) noexcept
 The identifier of the heartbeat and node-guarding frames of node.
 
constexpr uint16_t canopen_client::EmcyId (uint8_t node) noexcept
 The identifier of the emergency frames of node.
 
constexpr bool canopen_client::IsNmtCommand (uint8_t command) noexcept
 Whether a command byte is one of the five NMT commands.
 
constexpr bool canopen_client::DecodeNmtState (uint8_t raw, NmtState &state) noexcept
 Decode the state byte of a heartbeat (bit 7 already cleared).
 
constexpr Result< CanFrame > canopen_client::MakeNmtFrame (NmtCommand command, uint8_t node) noexcept
 The NMT command frame: identifier 0x000, two data bytes.
 
constexpr Result< CanFrame > canopen_client::MakeSyncFrame (uint8_t counter) noexcept
 The SYNC frame: identifier 0x080, no data, or one counter byte.
 
constexpr Result< CanFrame > canopen_client::MakeGuardRequest (uint8_t node) noexcept
 The node-guarding request: a remote frame on 0x700 + node.
 
constexpr Result< CanFrame > canopen_client::MakePdoFrame (uint16_t cob_id, std::span< const uint8_t > data) noexcept
 A PDO frame: a valid identifier and 0 to 8 data bytes.
 
constexpr Result< CanFrame > canopen_client::MakeSdoUploadRequest (uint8_t node, uint16_t index, uint8_t sub) noexcept
 The initiate-upload request (read an object): command byte 0x40.
 
constexpr Result< CanFrame > canopen_client::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.
 
constexpr Result< CanFrame > canopen_client::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.
 
constexpr Result< CanFrame > canopen_client::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.
 
constexpr Result< CanFrame > canopen_client::MakeSdoUploadSegmentRequest (uint8_t node, bool toggle) noexcept
 The request for the next upload segment: command byte 0x60 | toggle << 4.
 
constexpr Result< CanFrame > canopen_client::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.
 
constexpr Result< SdoReply > canopen_client::ParseSdoReply (const CanFrame &frame, bool strict) noexcept
 Decode a frame from an SDO server (identifier 0x580 + node).
 
constexpr Result< HeartbeatInfo > canopen_client::ParseHeartbeat (const CanFrame &frame) noexcept
 Decode a heartbeat, boot-up or node-guarding reply: identifier 0x701 to 0x77F, one byte.
 
constexpr Result< EmcyEvent > canopen_client::ParseEmcy (const CanFrame &frame) noexcept
 Decode an emergency message: identifier 0x081 to 0x0FF, eight bytes (error code, error register, five manufacturer bytes). The timestamp is left 0 for the caller.
 
constexpr Result< uint16_t > canopen_client::PdoCommunicationIndex (PdoKind kind, uint16_t number) noexcept
 The index of the communication parameter record of a PDO.
 
constexpr Result< uint16_t > canopen_client::PdoMappingIndex (PdoKind kind, uint16_t number) noexcept
 The index of the mapping parameter record of a PDO.
 
constexpr uint32_t canopen_client::EncodePdoMapEntry (const PdoMapEntry &entry) noexcept
 The 32-bit mapping record: index << 16 | sub-index << 8 | length in bits.
 
constexpr PdoMapEntry canopen_client::DecodePdoMapEntry (uint32_t record) noexcept
 Split a 32-bit mapping record into its object and length.
 
constexpr Error canopen_client::ValidatePdoConfig (const PdoConfig &config) noexcept
 Check a PDO configuration: identifier range, a transmission type that is not reserved (241 to 251), 0 to kMaxPdoEntries entries, each of 1 to 64 bits at a non-zero index, and at most 64 bits in all.
 
constexpr uint32_t canopen_client::PdoBitLength (const PdoConfig &config) noexcept
 The bits the entries of a PDO occupy in all.
 
constexpr Result< uint64_t > canopen_client::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 significant bit of byte 0).
 
constexpr Result< void > canopen_client::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.
 
constexpr DriveState canopen_client::DecodeStatusword (uint16_t statusword) noexcept
 Decode the drive state from a statusword (object 0x6041): the masks 0x4F and 0x6F of the state machine, matched exactly.
 
constexpr bool canopen_client::EnableStepControlword (DriveState state, uint16_t &word) noexcept
 The controlword that moves a drive one step toward Operation enabled.
 

Detailed Description

Pure builders and decoders for every frame the client sends or reads.

Function Documentation

◆ DecodeNmtState()

constexpr bool canopen_client::DecodeNmtState ( uint8_t  raw,
NmtState &  state 
)
constexprnoexcept

Decode the state byte of a heartbeat (bit 7 already cleared).

Parameters
rawThe state, 0, 4, 5 or 127.
[out]stateThe state; unchanged when raw is not a state.
Returns
true when raw is a defined state.

◆ DecodePdoMapEntry()

constexpr PdoMapEntry canopen_client::DecodePdoMapEntry ( uint32_t  record)
constexprnoexcept

Split a 32-bit mapping record into its object and length.

Parameters
recordThe record.
Returns
The entry.

◆ DecodeStatusword()

constexpr DriveState canopen_client::DecodeStatusword ( uint16_t  statusword)
constexprnoexcept

Decode the drive state from a statusword (object 0x6041): the masks 0x4F and 0x6F of the state machine, matched exactly.

Parameters
statuswordThe statusword.
Returns
The state, or DriveState::Unknown for a bit pattern that is none of them.

◆ EmcyId()

constexpr uint16_t canopen_client::EmcyId ( uint8_t  node)
constexprnoexcept

The identifier of the emergency frames of node.

Parameters
nodeThe node, 1 to 127 (not checked here).
Returns
0x080 + node.

◆ EnableStepControlword()

constexpr bool canopen_client::EnableStepControlword ( DriveState  state,
uint16_t &  word 
)
constexprnoexcept

The controlword that moves a drive one step toward Operation enabled.

Parameters
stateThe drive's present state.
[out]wordThe controlword; unchanged when no write helps.
Returns
true when word is to be written: Switch on disabled (shutdown), Ready to switch on (switch on), Switched on (enable operation), Quick stop active (disable voltage). false for the states that only wait (Not ready to switch on, Fault reaction active) or end the walk (Operation enabled, Fault, Unknown).

◆ EncodePdoMapEntry()

constexpr uint32_t canopen_client::EncodePdoMapEntry ( const PdoMapEntry &  entry)
constexprnoexcept

The 32-bit mapping record: index << 16 | sub-index << 8 | length in bits.

Parameters
entryThe mapped object.
Returns
The record.

◆ ExtractBits()

constexpr Result< uint64_t > canopen_client::ExtractBits ( std::span< const uint8_t >  data,
uint32_t  offset,
uint32_t  bits 
)
constexprnoexcept

Read bits bits starting at bit offset of a PDO payload (Intel bit order: bit 0 is the least significant bit of byte 0).

Parameters
dataThe payload.
offsetThe first bit.
bitsThe width, 1 to 64.
Returns
The value, or InvalidArgument when the field is empty, wider than 64 bits or ends past the payload.

◆ HeartbeatId()

constexpr uint16_t canopen_client::HeartbeatId ( uint8_t  node)
constexprnoexcept

The identifier of the heartbeat and node-guarding frames of node.

Parameters
nodeThe node, 1 to 127 (not checked here).
Returns
0x700 + node.

◆ InsertBits()

constexpr Result< void > canopen_client::InsertBits ( std::span< uint8_t >  data,
uint32_t  offset,
uint32_t  bits,
uint64_t  value 
)
constexprnoexcept

Write the low bits bits of value at bit offset of a PDO payload; the other bits are unchanged.

Parameters
dataThe payload.
offsetThe first bit.
bitsThe width, 1 to 64.
valueThe value; higher bits are ignored.
Returns
Ok, or InvalidArgument when the field does not fit in the payload.

◆ IsNmtCommand()

constexpr bool canopen_client::IsNmtCommand ( uint8_t  command)
constexprnoexcept

Whether a command byte is one of the five NMT commands.

Parameters
commandThe byte.
Returns
true when command is a defined NmtCommand.

◆ IsNodeId()

constexpr bool canopen_client::IsNodeId ( uint8_t  node)
constexprnoexcept

Whether a node identifier is in 1 to 127.

Parameters
nodeThe node identifier.
Returns
true when valid (0, the broadcast address, is not).

◆ MakeGuardRequest()

constexpr Result< CanFrame > canopen_client::MakeGuardRequest ( uint8_t  node)
constexprnoexcept

The node-guarding request: a remote frame on 0x700 + node.

Parameters
nodeThe node, 1 to 127.
Returns
The frame, or InvalidArgument.

◆ MakeNmtFrame()

constexpr Result< CanFrame > canopen_client::MakeNmtFrame ( NmtCommand  command,
uint8_t  node 
)
constexprnoexcept

The NMT command frame: identifier 0x000, two data bytes.

Parameters
commandThe command.
nodeThe target, 1 to 127, or 0 for every node.
Returns
The frame, or InvalidArgument (node above 127 or a value that is not a command).

◆ MakePdoFrame()

constexpr Result< CanFrame > canopen_client::MakePdoFrame ( uint16_t  cob_id,
std::span< const uint8_t >  data 
)
constexprnoexcept

A PDO frame: a valid identifier and 0 to 8 data bytes.

Parameters
cob_idThe identifier, kPdoCobIdMin to kPdoCobIdMax.
dataThe payload, at most 8 bytes.
Returns
The frame, or InvalidArgument.

◆ MakeSdoAbort()

constexpr Result< CanFrame > canopen_client::MakeSdoAbort ( uint8_t  node,
uint16_t  index,
uint8_t  sub,
uint32_t  code 
)
constexprnoexcept

The abort frame the client sends to end a transfer: command byte 0x80.

Parameters
nodeThe server, 1 to 127.
indexThe object index of the transfer.
subThe sub-index of the transfer.
codeThe abort code.
Returns
The frame, or InvalidArgument.

◆ MakeSdoDownloadSegment()

constexpr Result< CanFrame > canopen_client::MakeSdoDownloadSegment ( uint8_t  node,
bool  toggle,
std::span< const uint8_t >  data,
bool  last 
)
constexprnoexcept

One download segment: command byte toggle << 4 | (7 - length) << 1 | last.

Parameters
nodeThe server, 1 to 127.
toggleThe toggle bit, starting at 0 and alternating.
data1 to 7 bytes.
lasttrue for the final segment.
Returns
The frame, or InvalidArgument.

◆ MakeSdoExpeditedDownload()

constexpr Result< CanFrame > canopen_client::MakeSdoExpeditedDownload ( uint8_t  node,
uint16_t  index,
uint8_t  sub,
std::span< const uint8_t >  data 
)
constexprnoexcept

The expedited initiate-download request (write 1 to 4 bytes): command byte 0x23 | (4 - size) << 2.

Parameters
nodeThe server, 1 to 127.
indexThe object index.
subThe sub-index.
data1 to 4 bytes.
Returns
The frame, or InvalidArgument.

◆ MakeSdoSegmentedDownload()

constexpr Result< CanFrame > canopen_client::MakeSdoSegmentedDownload ( uint8_t  node,
uint16_t  index,
uint8_t  sub,
uint32_t  size 
)
constexprnoexcept

The segmented initiate-download request announcing size bytes: command byte 0x21.

Parameters
nodeThe server, 1 to 127.
indexThe object index.
subThe sub-index.
sizeThe number of bytes that follow, at least 1.
Returns
The frame, or InvalidArgument.

◆ MakeSdoUploadRequest()

constexpr Result< CanFrame > canopen_client::MakeSdoUploadRequest ( uint8_t  node,
uint16_t  index,
uint8_t  sub 
)
constexprnoexcept

The initiate-upload request (read an object): command byte 0x40.

Parameters
nodeThe server, 1 to 127.
indexThe object index.
subThe sub-index.
Returns
The frame, or InvalidArgument.

◆ MakeSdoUploadSegmentRequest()

constexpr Result< CanFrame > canopen_client::MakeSdoUploadSegmentRequest ( uint8_t  node,
bool  toggle 
)
constexprnoexcept

The request for the next upload segment: command byte 0x60 | toggle << 4.

Parameters
nodeThe server, 1 to 127.
toggleThe toggle bit, starting at 0 and alternating.
Returns
The frame, or InvalidArgument.

◆ MakeSyncFrame()

constexpr Result< CanFrame > canopen_client::MakeSyncFrame ( uint8_t  counter)
constexprnoexcept

The SYNC frame: identifier 0x080, no data, or one counter byte.

Parameters
counter0 for a SYNC without data; 1 to 240 for the counter byte; else InvalidArgument.
Returns
The frame.

◆ ParseEmcy()

constexpr Result< EmcyEvent > canopen_client::ParseEmcy ( const CanFrame &  frame)
constexprnoexcept

Decode an emergency message: identifier 0x081 to 0x0FF, eight bytes (error code, error register, five manufacturer bytes). The timestamp is left 0 for the caller.

Parameters
frameThe frame.
Returns
The event, or InvalidFrame.

◆ ParseHeartbeat()

constexpr Result< HeartbeatInfo > canopen_client::ParseHeartbeat ( const CanFrame &  frame)
constexprnoexcept

Decode a heartbeat, boot-up or node-guarding reply: identifier 0x701 to 0x77F, one byte.

Parameters
frameThe frame.
Returns
The node, state and toggle bit, or InvalidFrame (remote frame, identifier outside the range, length other than 1, or a state that is not 0, 4, 5 or 127).

◆ ParseSdoReply()

constexpr Result< SdoReply > canopen_client::ParseSdoReply ( const CanFrame &  frame,
bool  strict 
)
constexprnoexcept

Decode a frame from an SDO server (identifier 0x580 + node).

The identifier is the caller's to check; this reads the payload. Block-transfer command specifiers (5 and 6) and the reserved 7 are not replies to a request this client sends and are InvalidFrame.

Parameters
frameThe frame.
stricttrue to require 8 data bytes in every SDO frame; false to accept a frame as short as its content needs (4 bytes for an initiate reply, 1 for a segment reply).
Returns
The reply, or InvalidFrame (remote frame, too short, or an unusable command specifier).

◆ PdoBitLength()

constexpr uint32_t canopen_client::PdoBitLength ( const PdoConfig &  config)
constexprnoexcept

The bits the entries of a PDO occupy in all.

Parameters
configThe configuration (not validated).
Returns
The sum of the entry lengths of the first entry_count entries.

◆ PdoCommunicationIndex()

constexpr Result< uint16_t > canopen_client::PdoCommunicationIndex ( PdoKind  kind,
uint16_t  number 
)
constexprnoexcept

The index of the communication parameter record of a PDO.

Parameters
kindReceive (0x1400 + n - 1) or transmit (0x1800 + n - 1).
numberThe PDO number, 1 to 512.
Returns
The index, or InvalidArgument.

◆ PdoMappingIndex()

constexpr Result< uint16_t > canopen_client::PdoMappingIndex ( PdoKind  kind,
uint16_t  number 
)
constexprnoexcept

The index of the mapping parameter record of a PDO.

Parameters
kindReceive (0x1600 + n - 1) or transmit (0x1A00 + n - 1).
numberThe PDO number, 1 to 512.
Returns
The index, or InvalidArgument.

◆ SdoRequestId()

constexpr uint16_t canopen_client::SdoRequestId ( uint8_t  node)
constexprnoexcept

The identifier of the SDO request frames to node.

Parameters
nodeThe node, 1 to 127 (not checked here).
Returns
0x600 + node.

◆ SdoResponseId()

constexpr uint16_t canopen_client::SdoResponseId ( uint8_t  node)
constexprnoexcept

The identifier of the SDO reply frames from node.

Parameters
nodeThe node, 1 to 127 (not checked here).
Returns
0x580 + node.

◆ ValidatePdoConfig()

constexpr Error canopen_client::ValidatePdoConfig ( const PdoConfig &  config)
constexprnoexcept

Check a PDO configuration: identifier range, a transmission type that is not reserved (241 to 251), 0 to kMaxPdoEntries entries, each of 1 to 64 bits at a non-zero index, and at most 64 bits in all.

Parameters
configThe configuration.
Returns
Ok or InvalidArgument.