HF-TMC9660 Driver 0.1.0-dev
Hardware Agnostic C++ Driver for the TMC9660
Loading...
Searching...
No Matches
tmc9660::TMCLReply Struct Reference

Reply structure returned by TMCL command operations. More...

#include <tmc9660_comm_interface.hpp>

Public Member Functions

bool isOK () const noexcept
 
uint32_t extractRawValue (size_t offset) const noexcept
 Extract 32-bit value from raw bytes at specified offset (MSB-first)
 
std::string getVersionString () const noexcept
 Extract version string from GetVersion reply (Command 136, Type 0)
 

Static Public Member Functions

static bool fromSpi (std::span< const uint8_t, 8 > in, TMCLReply &r, uint8_t sent_opcode=0, uint16_t sent_type=0) noexcept
 Decode and validate reply from SPI TMCL datagram.
 
static bool fromUart (std::span< const uint8_t, 9 > in, uint8_t addr, TMCLReply &r, uint8_t sent_opcode=0, uint16_t sent_type=0) noexcept
 Decode and validate reply from UART TMCL datagram.
 

Public Attributes

SPIStatus spi_status = SPIStatus::OK
 SPI status byte.
 
uint8_t status = 0
 TMCL status code (100=OK, 101=LOADED)
 
uint8_t opcode = 0
 Echoed operation code.
 
uint32_t value = 0
 Optional returned value.
 
std::array< uint8_t, 8 > rawBytes
 Raw SPI bytes (8-byte) or UART bytes mapped to 8-byte format.
 

Detailed Description

Reply structure returned by TMCL command operations.

This structure contains the decoded reply from a TMCL command, including SPI status, TMCL status, operation code, and the returned value. The structure also stores raw bytes for advanced parsing and provides helper methods for extracting version strings and handling protocol mismatches.

Member Function Documentation

◆ extractRawValue()

uint32_t tmc9660::TMCLReply::extractRawValue ( size_t offset) const
inlinenoexcept

Extract 32-bit value from raw bytes at specified offset (MSB-first)

Parameters
offsetStarting byte offset (0-4 for 32-bit value)
Returns
32-bit value extracted from rawBytes[offset..offset+3]

Useful for extracting misaligned data when protocol mismatch occurs (e.g., bootloader 5-byte SESSION_START parsed as 8-byte TMCL).

◆ fromSpi()

static bool tmc9660::TMCLReply::fromSpi ( std::span< const uint8_t, 8 > in,
TMCLReply & r,
uint8_t sent_opcode = 0,
uint16_t sent_type = 0 )
inlinestaticnoexcept

Decode and validate reply from SPI TMCL datagram.

Parses an 8-byte SPI reply, validates checksum, and handles special reply formats such as SESSION_START and GetVersion string replies. Raw bytes are always stored for advanced parsing even if initial parsing fails.

Parameters
inInput buffer containing 8 bytes from SPI
rOutput parameter to receive decoded reply
sent_opcodeOptional opcode of command that was sent (for handling special replies)
sent_typeOptional type field of command that was sent (for handling special replies)
Returns
true if reply was successfully decoded and validated
Note
Handles special cases: SESSION_START (0x13), GetVersion string format
Raw bytes are always stored for debugging protocol mismatches
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fromUart()

static bool tmc9660::TMCLReply::fromUart ( std::span< const uint8_t, 9 > in,
uint8_t addr,
TMCLReply & r,
uint8_t sent_opcode = 0,
uint16_t sent_type = 0 )
inlinestaticnoexcept

Decode and validate reply from UART TMCL datagram.

Parses a 9-byte UART reply, validates module address and checksum, and handles special reply formats. UART replies include host address and sync bits not present in SPI format.

Parameters
inInput buffer containing 9 bytes from UART
addrExpected 7-bit module address for address validation
rOutput parameter to receive decoded reply
sent_opcodeOptional opcode of command that was sent (for handling special replies)
sent_typeOptional type field of command that was sent (for handling special replies)
Returns
true if reply was successfully decoded and validated
Note
UART format: [HOST_ADDR] [SYNC+ADDR] [STATUS] [OPCODE] [VALUE(32)] [CRC8]
Validates module address and checksum before returning success
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getVersionString()

std::string tmc9660::TMCLReply::getVersionString ( ) const
inlinenoexcept

Extract version string from GetVersion reply (Command 136, Type 0)

Returns
Version string (up to 8 characters) or empty string if not a version reply

GetVersion with Type=0 returns: [Host Address][Version String 8 chars] This method extracts the version string portion

◆ isOK()

bool tmc9660::TMCLReply::isOK ( ) const
inlinenoexcept

Member Data Documentation

◆ opcode

uint8_t tmc9660::TMCLReply::opcode = 0

Echoed operation code.

◆ rawBytes

std::array<uint8_t, 8> tmc9660::TMCLReply::rawBytes
Initial value:
=
{}

Raw SPI bytes (8-byte) or UART bytes mapped to 8-byte format.

◆ spi_status

SPIStatus tmc9660::TMCLReply::spi_status = SPIStatus::OK

SPI status byte.

◆ status

uint8_t tmc9660::TMCLReply::status = 0

TMCL status code (100=OK, 101=LOADED)

◆ value

uint32_t tmc9660::TMCLReply::value = 0

Optional returned value.


The documentation for this struct was generated from the following file: