Motion Master
|
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 > ¶metersMap, 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 > | |
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... | |
ObjectFlags & | operator|= (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... | |
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.
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.
|
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 |
|
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. |
|
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.
|
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 |
|
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"
data | The vector of bytes to convert. |
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"
.std::to_string()
.std::string
values are returned as-is.value | The parameter value to convert. |
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.
originalMacAddress | The input MAC address string, using either ':' or '-' as delimiter. |
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.
j | JSON object expected to contain a "pdoMapping" field. |
r | Reference to UiConfigJson struct to populate. |
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.
j | JSON object expected to contain "rx" and "tx" mappings. |
p | Reference to UiPdoMapping struct to populate with parsed data. |
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.
list | The vector of strings to join. |
delimiter | The delimiter to insert between each string. |
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.
parametersMap | A map where each key is a pair of (index, subindex) and the value is a Parameter object containing metadata. |
sortParameters | A 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. |
|
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.
index | The 16-bit index value (e.g., 0x2030). |
subindex | The 8-bit subindex value (e.g., 0x01). |
|
inline |
Bitwise AND operator for ObjectFlags enum class.
This operator allows for checking the intersection of two ObjectFlags
values using the bitwise AND operator.
lhs | Left-hand operand of the bitwise AND operation. |
rhs | Right-hand operand of the bitwise AND operation. |
ObjectFlags
value.
|
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.
lhs | The EtherCATVendorID enum value to compare. |
rhs | The raw vendor ID as a uint32_t. |
|
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.
lhs | The raw vendor ID as a uint32_t. |
rhs | The EtherCATVendorID enum value to compare. |
|
inline |
Bitwise OR operator for ObjectFlags enum class.
This operator allows for combining two ObjectFlags
values using the bitwise OR operator.
lhs | Left-hand operand of the bitwise OR operation. |
rhs | Right-hand operand of the bitwise OR operation. |
ObjectFlags
value.
|
inline |
Bitwise OR assignment operator for ObjectFlags enum class.
This operator allows the modification of an ObjectFlags
value by OR'ing it with another.
lhs | Left-hand operand, which will be modified with the OR operation. |
rhs | Right-hand operand to OR with the left-hand operand. |
ObjectFlags
value. 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
).
T | The unsigned integer type to parse to. Must be an unsigned integral type. |
s | The hexadecimal string to parse. |
std::invalid_argument | if the string is not a valid hex number. |
std::out_of_range | if the parsed value is out of range for type T. |
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.
filename | The path to the file to be read. |
std::vector<uint8_t>
containing the file's content. std::runtime_error | If the file cannot be opened. |
|
inline |
Combine multiple ObjectFlags
values into one.
This function is a convenience method that combines multiple ObjectFlags
values by OR'ing them together.
b | First ObjectFlags value. |
s | Second ObjectFlags value. |
p | Third ObjectFlags value. |
a | Fourth ObjectFlags value. |
ObjectFlags
values as a single ObjectFlags
value. 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.
T | The numeric type to convert the string_view to (e.g., int, long, double). |
sv | The string_view representing the numeric string to be converted. |
result | The variable where the result of the conversion will be stored. |
std::vector< uint8_t > common::toBytes | ( | T | 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.
T | The type of the value to convert. It must be trivially copyable. |
value | The value to convert to bytes. |
bigEndian | If true, the returned byte vector will be in big-endian order; if false, little-endian. |
static_assert | If the type T is not trivially copyable. |