Motion Master
Loading...
Searching...
No Matches
Classes | Typedefs | Enumerations | Functions
common Namespace Reference

Classes

class  Device
 Abstract interface representing a generic device. More...
 
class  Parameter
 Represents a device parameter identified by index and subindex. More...
 
struct  PdoMappingEntry
 Represents a single PDO (Process Data Object) mapping entry. More...
 
struct  PdoMappings
 Represents the mapped PDO entries for a slave device. More...
 
struct  UiConfigJson
 Top-level UI configuration JSON structure. More...
 
struct  UiPdoMapping
 Represents the PDO mapping for RX and TX channels. More...
 

Typedefs

using ParameterKey = std::pair< uint16_t, uint8_t >
 Alias for a pair of uint16_t and uint8_t representing a parameter key. More...
 
using ParameterValue = std::variant< bool, std::int8_t, std::int16_t, std::int32_t, std::int64_t, std::uint8_t, std::uint16_t, std::uint32_t, std::uint64_t, float, double, std::string, std::vector< std::uint8_t > >
 

Enumerations

enum class  EtherCATVendorID : uint32_t { SYNAPTICON = 0x000022d2 }
 Enum class representing EtherCAT vendor IDs. More...
 
enum class  ObjectFlags : uint16_t {
  None = 0x0000 , PO_RD = 0x0001 , SO_RD = 0x0002 , OP_RD = 0x0004 ,
  ALL_RD = PO_RD | SO_RD | OP_RD , PO_WR = 0x0008 , SO_WR = 0x0010 , OP_WR = 0x0020 ,
  ALL_WR = PO_WR | SO_WR | OP_WR , PO_RDWR = PO_RD | PO_WR , SO_RDWR = SO_RD | SO_WR , OP_RDWR = OP_RD | OP_WR ,
  ALL_RDWR = PO_RDWR | SO_RDWR | OP_RDWR , RXPDO_MAP = 0x0040 , TXPDO_MAP = 0x0080 , RXTXPDO_MAP = 0x00C0 ,
  BACKUP = 0x0100 , STARTUP = 0x0200 , ALL_LIST_FLAGS = RXPDO_MAP | TXPDO_MAP | BACKUP | STARTUP
}
 Enum class representing various object flags. More...
 
enum class  ObjectDataType : uint16_t {
  UNSPECIFIED = 0x0000 , BOOLEAN = 0x0001 , BYTE = 0x001E , WORD = 0x001F ,
  DWORD = 0x0020 , BIT1 = 0x0030 , BIT2 = 0x0031 , BIT3 = 0x0032 ,
  BIT4 = 0x0033 , BIT5 = 0x0034 , BIT6 = 0x0035 , BIT7 = 0x0036 ,
  BIT8 = 0x0037 , BIT9 = 0x0038 , BIT10 = 0x0039 , BIT11 = 0x003A ,
  BIT12 = 0x003B , BIT13 = 0x003C , BIT14 = 0x003D , BIT15 = 0x003E ,
  BIT16 = 0x003F , BITARR8 = 0x002D , BITARR16 = 0x002E , BITARR32 = 0x002F ,
  INTEGER8 = 0x0002 , INTEGER16 = 0x0003 , INTEGER24 = 0x0010 , INTEGER32 = 0x0004 ,
  INTEGER40 = 0x0012 , INTEGER48 = 0x0013 , INTEGER56 = 0x0014 , INTEGER64 = 0x0015 ,
  UNSIGNED8 = 0x0005 , UNSIGNED16 = 0x0006 , UNSIGNED24 = 0x0016 , UNSIGNED32 = 0x0007 ,
  UNSIGNED40 = 0x0018 , UNSIGNED48 = 0x0019 , UNSIGNED56 = 0x001A , UNSIGNED64 = 0x001B ,
  REAL32 = 0x0008 , REAL64 = 0x0011 , GUID = 0x001D , VISIBLE_STRING = 0x0009 ,
  OCTET_STRING = 0x000A , UNICODE_STRING = 0x000B , ARRAY_OF_INT = 0x0260 , ARRAY_OF_SINT = 0x0261 ,
  ARRAY_OF_DINT = 0x0262 , ARRAY_OF_UDINT = 0x0263 , PDO_MAPPING = 0x0021 , IDENTITY = 0x0023 ,
  COMMAND_PAR = 0x0025 , PDO_PARAMETER = 0x0027 , ENUM = 0x0028 , SM_SYNCHRONIZATION ,
  RECORD = 0x002A , BACKUP_PARAMETER = 0x002B , MODULAR_DEVICE_PARAMETER = 0x002C , ERROR_SETTING = 0x0281 ,
  DIAGNOSIS_HISTORY , EXTERNAL_SYNC_STATUS = 0x0283 , EXTERNAL_SYNC_SETTINGS = 0x0284 , DEFTYPE_FSOEFRAME = 0x0285 ,
  DEFTYPE_FSOECOMMPAR , TIME_OF_DAY = 0x000C , TIME_DIFFERENCE , UTYPE_START = 0x0800 ,
  UTYPE_END = 0x0FFF
}
 Enumerates the supported data types for parameters. More...
 
enum class  ObjectCode : uint16_t {
  DEFTYPE = 0x0005 , DEFSTRUCT = 0x0006 , VAR = 0x0007 , ARRAY = 0x0008 ,
  RECORD = 0x0009
}
 Enum class representing different object types used in the EtherCAT protocol. More...
 

Functions

void from_json (const nlohmann::json &j, UiPdoMapping &p)
 Deserialize a JSON object into a UiPdoMapping structure. More...
 
void from_json (const nlohmann::json &j, UiConfigJson &r)
 Deserialize a JSON object into a UiConfigJson structure. More...
 
std::string convertParameterValueToString (const ParameterValue &value)
 Converts a ParameterValue to a string representation. More...
 
void logParametersMap (const std::unordered_map< std::pair< uint16_t, uint8_t >, Parameter > &parametersMap, bool sortParameters=true)
 Logs the contents of a map of parameters with an option to sort them. More...
 
std::vector< uint8_t > readBinaryFile (const std::string &filename)
 Reads the contents of a binary file into a vector of uint8_t. More...
 
std::string joinStrings (const std::vector< std::string > &list, const std::string &delimiter)
 Joins a list of strings into a single string with a delimiter. More...
 
std::string formatMacAddress (const std::string &originalMacAddress)
 Formats a MAC address string to ensure each component is two digits and uppercase. More...
 
template<typename T >
parseHex (const std::string &s)
 Parses a hexadecimal string into an unsigned integer of type T. More...
 
bool operator== (uint32_t lhs, EtherCATVendorID rhs)
 Compares a uint32_t value with an EtherCATVendorID enum value. More...
 
bool operator== (EtherCATVendorID lhs, uint32_t rhs)
 Compares an EtherCATVendorID enum value with a uint32_t value. More...
 
ObjectFlags operator| (ObjectFlags lhs, ObjectFlags rhs)
 Bitwise OR operator for ObjectFlags enum class. More...
 
ObjectFlags operator& (ObjectFlags lhs, ObjectFlags rhs)
 Bitwise AND operator for ObjectFlags enum class. More...
 
ObjectFlagsoperator|= (ObjectFlags &lhs, ObjectFlags rhs)
 Bitwise OR assignment operator for ObjectFlags enum class. More...
 
ObjectFlags SetObjectFlags (ObjectFlags b, ObjectFlags s, ObjectFlags p, ObjectFlags a)
 Combine multiple ObjectFlags values into one. More...
 
template<typename T >
bool stringViewToNumber (std::string_view sv, T &result)
 Converts a string_view to a numeric type. More...
 
template<typename T >
std::vector< uint8_t > toBytes (T value, bool bigEndian=false)
 Converts a value of type T to a vector of bytes (uint8_t) in the specified byte order. More...
 
std::string makeParameterId (int index, int subindex)
 Formats the given index and subindex into a parameter identifier string. More...
 
std::string bytesToHexString (const std::vector< uint8_t > &data)
 Converts a vector of bytes into a space-separated hexadecimal string. More...
 

Typedef Documentation

◆ ParameterKey

using common::ParameterKey = typedef std::pair<uint16_t, uint8_t>

Alias for a pair of uint16_t and uint8_t representing a parameter key.

This alias simplifies the use of a std::pair<uint16_t, uint8_t>, where the first element (uint16_t) represents the index, and the second element (uint8_t) represents the subindex in a parameter lookup.

◆ ParameterValue

using common::ParameterValue = typedef std::variant<bool, std::int8_t, std::int16_t, std::int32_t, std::int64_t, std::uint8_t, std::uint16_t, std::uint32_t, std::uint64_t, float, double, std::string, std::vector<std::uint8_t> >

Alias for a variant type holding multiple value types.

Enumeration Type Documentation

◆ EtherCATVendorID

enum class common::EtherCATVendorID : uint32_t
strong

Enum class representing EtherCAT vendor IDs.

This enum class defines vendor IDs for EtherCAT devices, with each vendor ID being represented by a unique 32-bit unsigned integer value. It is used to identify different EtherCAT vendors in the system.

Enumerator
SYNAPTICON 

Vendor ID for Synapticon GmbH.

Synapticon GmbH provides high-performance and compact servo drives. Vendor ID for Synapticon GmbH

◆ ObjectCode

enum class common::ObjectCode : uint16_t
strong

Enum class representing different object types used in the EtherCAT protocol.

This enum class defines various object types that represent the kind of object in an EtherCAT device. Each value corresponds to a specific type of object, such as a definition, variable, array, or record, in the EtherCAT protocol.

Enumerator
DEFTYPE 

Definition type object.

DEFSTRUCT 

Definition structure object.

VAR 

Variable object type.

ARRAY 

Array object type.

RECORD 

Record object type.

◆ ObjectDataType

enum class common::ObjectDataType : uint16_t
strong

Enumerates the supported data types for parameters.

This enumeration defines the various data types that parameters can use. Each entry is explicitly mapped to a 16-bit unsigned integer value. It includes basic types such as integers, floating-point numbers, strings, time-related types, bitfields, and user-defined types.

Note
The values in this enumeration are defined in the ETG.1020 document, which outlines the EtherCAT protocol and its supported data types.
Enumerator
UNSPECIFIED 

Undefined or unknown data type.

BOOLEAN 

Boolean value (true or false).

BYTE 

8-bit unsigned integer.

WORD 

Two octets (16 bits) unsigned integer.

DWORD 

Four octets (32 bits) unsigned integer.

BIT1 

1-bit field.

BIT2 

2-bit field.

BIT3 

3-bit field.

BIT4 

4-bit field.

BIT5 

5-bit field.

BIT6 

6-bit field.

BIT7 

7-bit field.

BIT8 

8-bit field.

BIT9 

9-bit field.

BIT10 

10-bit field.

BIT11 

11-bit field.

BIT12 

12-bit field.

BIT13 

13-bit field.

BIT14 

14-bit field.

BIT15 

15-bit field.

BIT16 

16-bit field.

BITARR8 

Array of 8 bits.

BITARR16 

Array of 16 bits.

BITARR32 

Array of 32 bits.

INTEGER8 

8-bit signed integer.

INTEGER16 

16-bit signed integer.

INTEGER24 

24-bit signed integer.

INTEGER32 

32-bit signed integer.

INTEGER40 

40-bit signed integer.

INTEGER48 

48-bit signed integer.

INTEGER56 

56-bit signed integer.

INTEGER64 

64-bit signed integer.

UNSIGNED8 

8-bit unsigned integer.

UNSIGNED16 

16-bit unsigned integer.

UNSIGNED24 

24-bit unsigned integer.

UNSIGNED32 

32-bit unsigned integer.

UNSIGNED40 

40-bit unsigned integer.

UNSIGNED48 

48-bit unsigned integer.

UNSIGNED56 

56-bit unsigned integer.

UNSIGNED64 

64-bit unsigned integer.

REAL32 

32-bit floating-point number.

REAL64 

64-bit floating-point number (double).

GUID 

128-bit globally unique identifier.

VISIBLE_STRING 

Null-terminated ASCII string.

OCTET_STRING 

Array of raw bytes.

UNICODE_STRING 

Null-terminated Unicode string (UTF-16/UTF-32 depending on platform).

ARRAY_OF_INT 

Sequence of INT.

ARRAY_OF_SINT 

Sequence of SINT.

ARRAY_OF_DINT 

Sequence of DINT.

ARRAY_OF_UDINT 

Sequence of UDINT.

PDO_MAPPING 

For PDO_MAPPING definition see ETG.1000.

IDENTITY 

For IDENTITY definition see ETG.1000.

COMMAND_PAR 

For COMMAND_PAR definition see ETG.1000.

PDO_PARAMETER 

For PDO_PARAMETER definition see ETG.1020.

ENUM 

For ENUM definition see ETG.1020.

SM_SYNCHRONIZATION 

For SM_SYNCHRONIZATION definition see ETG.1000.

RECORD 

No pre-defined Record structure. Can be used as a general data type for Records.

BACKUP_PARAMETER 

For BACKUP_PARAMETER definition see ETG.1020.

MODULAR_DEVICE_PARAMETER 

For MODULAR_DEVICE_PARAMETER definition see ETG.5001

ERROR_SETTING 

For ERROR_SETTING definition see ETG.1020.

DIAGNOSIS_HISTORY 

For DIAGNOSIS_HISTORY definition see ETG.1020.

EXTERNAL_SYNC_STATUS 

For EXTERNAL_SYNC_STATUS definition see ETG.1020

EXTERNAL_SYNC_SETTINGS 

For EXTERNAL_SYNC_SETTINGS definition see ETG.1020

DEFTYPE_FSOEFRAME 

For DEFTYPE_FSOEFRAME definition see ETG.5120

DEFTYPE_FSOECOMMPAR 

For DEFTYPE_FSOECOMMPAR definition see ETG.5120

TIME_OF_DAY 

Time of day format (implementation-defined).

TIME_DIFFERENCE 

Time difference format (implementation-defined).

UTYPE_START 

Start of user-defined type range.

UTYPE_END 

End of user-defined type range.

◆ ObjectFlags

enum class common::ObjectFlags : uint16_t
strong

Enum class representing various object flags.

This enum class defines different flags used for controlling access, mapping, and other attributes. It is represented as a 16-bit unsigned integer.

Enumerator
None 
PO_RD 
SO_RD 
OP_RD 
ALL_RD 
PO_WR 
SO_WR 
OP_WR 
ALL_WR 
PO_RDWR 
SO_RDWR 
OP_RDWR 
ALL_RDWR 
RXPDO_MAP 
TXPDO_MAP 
RXTXPDO_MAP 
BACKUP 
STARTUP 
ALL_LIST_FLAGS 

Function Documentation

◆ bytesToHexString()

std::string common::bytesToHexString ( const std::vector< uint8_t > &  data)
inline

Converts a vector of bytes into a space-separated hexadecimal string.

Each byte is formatted as "0xXX" using lowercase hexadecimal digits, with two-digit zero-padded formatting. The resulting string has each byte separated by a single space.

Example: Input: {0xFF, 0x01, 0x0a} Output: "0xff 0x01 0x0a"

Parameters
dataThe vector of bytes to convert.
Returns
A string representing the bytes in hexadecimal format.

◆ convertParameterValueToString()

std::string common::convertParameterValueToString ( const ParameterValue value)

Converts a ParameterValue to a string representation.

This function uses std::visit to convert the given ParameterValue (a std::variant of numeric and string types) to a human-readable string.

  • bool values are converted to "true" or "false".
  • Integral and floating-point values are converted using std::to_string().
  • std::string values are returned as-is.
Parameters
valueThe parameter value to convert.
Returns
A string representation of the value.

◆ formatMacAddress()

std::string common::formatMacAddress ( const std::string &  originalMacAddress)

Formats a MAC address string to ensure each component is two digits and uppercase.

This function takes a MAC address string in formats such as "a-b-c-d-e-f" or "a:b:c:d:e:f", and returns a standardized format like "0A:0B:0C:0D:0E:0F". It ensures that each component is two characters long (adding leading zeros if necessary), uses ':' as the delimiter, and converts all letters to uppercase.

Parameters
originalMacAddressThe input MAC address string, using either ':' or '-' as delimiter.
Returns
A formatted MAC address string with two-digit uppercase hexadecimal components, separated by colons.

◆ from_json() [1/2]

void common::from_json ( const nlohmann::json &  j,
UiConfigJson r 
)

Deserialize a JSON object into a UiConfigJson structure.

Extracts the "pdoMapping" field from the JSON object and converts it into a UiPdoMapping instance, which is assigned to the pdoMapping member.

Parameters
jJSON object expected to contain a "pdoMapping" field.
rReference to UiConfigJson struct to populate.

◆ from_json() [2/2]

void common::from_json ( const nlohmann::json &  j,
UiPdoMapping p 
)

Deserialize a JSON object into a UiPdoMapping structure.

This function parses the JSON object representing the PDO mappings, extracting the "rx" and "tx" maps. The JSON keys are hex strings (e.g., "0x1600") which are converted to uint16_t keys in the maps. The values are arrays of hex strings representing uint32_t entries.

Parameters
jJSON object expected to contain "rx" and "tx" mappings.
pReference to UiPdoMapping struct to populate with parsed data.

◆ joinStrings()

std::string common::joinStrings ( const std::vector< std::string > &  list,
const std::string &  delimiter 
)

Joins a list of strings into a single string with a delimiter.

Concatenates all elements in the given vector of strings, inserting the specified delimiter between each element. If the list is empty, returns an empty string.

Parameters
listThe vector of strings to join.
delimiterThe delimiter to insert between each string.
Returns
A single string composed of the input strings separated by the delimiter.

◆ logParametersMap()

void common::logParametersMap ( const std::unordered_map< std::pair< uint16_t, uint8_t >, Parameter > &  parametersMap,
bool  sortParameters = true 
)

Logs the contents of a map of parameters with an option to sort them.

This function takes a map of parameters indexed by (index, subindex) pairs, optionally sorts them by index and subindex (based on the sortParameters flag), and logs each parameter's details including its name, access type, bit length, and other relevant information.

If the sortParameters flag is true, the parameters will be sorted by index and subindex before logging. If sortParameters is false, the parameters will be logged in their original order as they appear in the map.

Parameters
parametersMapA map where each key is a pair of (index, subindex) and the value is a Parameter object containing metadata.
sortParametersA boolean flag indicating whether to sort the parameters before logging. Default is true. If true, the parameters are sorted by index and subindex; if false, they are logged in their original order.

◆ makeParameterId()

std::string common::makeParameterId ( int  index,
int  subindex 
)
inline

Formats the given index and subindex into a parameter identifier string.

This function takes an index and a subindex and formats them into a string of the form "0xINDEX:SUBINDEX". The index is formatted as a 4-digit hexadecimal number, and the subindex is formatted as a 2-digit hexadecimal number.

Parameters
indexThe 16-bit index value (e.g., 0x2030).
subindexThe 8-bit subindex value (e.g., 0x01).
Returns
std::string The formatted parameter ID string in the format "0xINDEX:SUBINDEX".

◆ operator&()

ObjectFlags common::operator& ( ObjectFlags  lhs,
ObjectFlags  rhs 
)
inline

Bitwise AND operator for ObjectFlags enum class.

This operator allows for checking the intersection of two ObjectFlags values using the bitwise AND operator.

Parameters
lhsLeft-hand operand of the bitwise AND operation.
rhsRight-hand operand of the bitwise AND operation.
Returns
The result of the bitwise AND operation as an ObjectFlags value.

◆ operator==() [1/2]

bool common::operator== ( EtherCATVendorID  lhs,
uint32_t  rhs 
)
inline

Compares an EtherCATVendorID enum value with a uint32_t value.

This operator allows comparison between an EtherCATVendorID enum value and a raw vendor ID (uint32_t). It converts the enum value to its underlying uint32_t type for the comparison.

Parameters
lhsThe EtherCATVendorID enum value to compare.
rhsThe raw vendor ID as a uint32_t.
Returns
true if the enum value matches the vendor ID, false otherwise.

◆ operator==() [2/2]

bool common::operator== ( uint32_t  lhs,
EtherCATVendorID  rhs 
)
inline

Compares a uint32_t value with an EtherCATVendorID enum value.

This operator allows comparison between a raw vendor ID (uint32_t) and an EtherCATVendorID enum value. It converts the enum to its underlying uint32_t type for the comparison.

Parameters
lhsThe raw vendor ID as a uint32_t.
rhsThe EtherCATVendorID enum value to compare.
Returns
true if the vendor ID matches the enum value, false otherwise.

◆ operator|()

ObjectFlags common::operator| ( ObjectFlags  lhs,
ObjectFlags  rhs 
)
inline

Bitwise OR operator for ObjectFlags enum class.

This operator allows for combining two ObjectFlags values using the bitwise OR operator.

Parameters
lhsLeft-hand operand of the bitwise OR operation.
rhsRight-hand operand of the bitwise OR operation.
Returns
The result of the bitwise OR operation as an ObjectFlags value.

◆ operator|=()

ObjectFlags & common::operator|= ( ObjectFlags lhs,
ObjectFlags  rhs 
)
inline

Bitwise OR assignment operator for ObjectFlags enum class.

This operator allows the modification of an ObjectFlags value by OR'ing it with another.

Parameters
lhsLeft-hand operand, which will be modified with the OR operation.
rhsRight-hand operand to OR with the left-hand operand.
Returns
The modified left-hand operand as an ObjectFlags value.

◆ parseHex()

template<typename T >
T common::parseHex ( const std::string &  s)

Parses a hexadecimal string into an unsigned integer of type T.

This function converts a hex string (e.g., "0x1A3F" or "1A3F") to an unsigned integer of the specified type T. It supports any unsigned integer type such as uint16_t, uint32_t, uint64_t, etc.

The function uses std::stoul for types up to the size of unsigned long, and std::stoull for larger types (e.g., uint64_t).

Template Parameters
TThe unsigned integer type to parse to. Must be an unsigned integral type.
Parameters
sThe hexadecimal string to parse.
Returns
Parsed value as type T.
Exceptions
std::invalid_argumentif the string is not a valid hex number.
std::out_of_rangeif the parsed value is out of range for type T.

◆ readBinaryFile()

std::vector< uint8_t > common::readBinaryFile ( const std::string &  filename)

Reads the contents of a binary file into a vector of uint8_t.

This function opens the specified file in binary mode and reads its content into a std::vector<uint8_t>. It uses std::istreambuf_iterator to read the entire file efficiently. If the file cannot be opened, a std::runtime_error is thrown.

Parameters
filenameThe path to the file to be read.
Returns
A std::vector<uint8_t> containing the file's content.
Exceptions
std::runtime_errorIf the file cannot be opened.

◆ SetObjectFlags()

ObjectFlags common::SetObjectFlags ( ObjectFlags  b,
ObjectFlags  s,
ObjectFlags  p,
ObjectFlags  a 
)
inline

Combine multiple ObjectFlags values into one.

This function is a convenience method that combines multiple ObjectFlags values by OR'ing them together.

Parameters
bFirst ObjectFlags value.
sSecond ObjectFlags value.
pThird ObjectFlags value.
aFourth ObjectFlags value.
Returns
The result of combining the four ObjectFlags values as a single ObjectFlags value.

◆ stringViewToNumber()

template<typename T >
bool common::stringViewToNumber ( std::string_view  sv,
T &  result 
)

Converts a string_view to a numeric type.

This function uses std::from_chars to convert a given std::string_view into a numeric value of type T. The conversion is done without allocating memory, and the function returns true if the conversion succeeds, false otherwise.

Template Parameters
TThe numeric type to convert the string_view to (e.g., int, long, double).
Parameters
svThe string_view representing the numeric string to be converted.
resultThe variable where the result of the conversion will be stored.
Returns
True if the conversion was successful, false otherwise.
Note
This function only supports arithmetic types (integers and floating-point types).

◆ toBytes()

template<typename T >
std::vector< uint8_t > common::toBytes ( value,
bool  bigEndian = false 
)

Converts a value of type T to a vector of bytes (uint8_t) in the specified byte order.

This function converts a trivially copyable value to its byte representation and returns the result as a vector of uint8_t. The resulting byte order can be controlled explicitly by passing either little-endian or big-endian.

Template Parameters
TThe type of the value to convert. It must be trivially copyable.
Parameters
valueThe value to convert to bytes.
bigEndianIf true, the returned byte vector will be in big-endian order; if false, little-endian.
Returns
A vector of uint8_t containing the byte representation of the value in the specified byte order.
Exceptions
static_assertIf the type T is not trivially copyable.