|
Motion Master 6.0.0-alpha.50
Next-generation motion control software
|
Classes | |
| class | CyclicTimer |
| Precision cyclic timer for fixed-period loops. More... | |
| class | SingleInstanceLock |
| RAII holder of the process-wide single-instance lock. More... | |
| struct | SystemInfo |
Functions | |
| std::filesystem::path | exeDir () |
| Return the directory that contains the running executable. | |
| void | openInBrowser (const std::string &url) |
| Open the given URL in the system default browser. | |
| std::expected< SingleInstanceLock, std::string > | acquireSingleInstanceLock () |
| Acquire the process-wide lock that permits only one running Motion Master. | |
| SystemInfo | collectSystemInfo () |
| void | to_json (nlohmann::json &j, const SystemInfo &info) |
| bool | isUrlSafeId (std::string_view s) |
Whether s is a valid URL-safe identifier usable as a path segment and pub/sub topic. | |
| template<typename T > | |
| std::optional< T > | parseHexOrDec (std::string_view s) |
| Parses an unsigned integer from a string in decimal or hexadecimal notation. | |
| template<typename T > | |
| std::array< uint8_t, sizeof(T)> | toBytes (T value, std::endian order=std::endian::little) |
| Encodes an integer into a fixed-width byte array in the given byte order. | |
| template<typename T > | |
| T | fromBytes (std::span< const uint8_t > bytes, std::endian order=std::endian::little) |
| Decodes an integer from a raw byte buffer interpreted in the given byte order. | |
| std::expected< SingleInstanceLock, std::string > mm::core::acquireSingleInstanceLock | ( | ) |
Acquire the process-wide lock that permits only one running Motion Master.
Non-blocking. Returns the held lock when no other instance holds it; fails when one already does. The lock guards the whole process — acquired before the EtherCAT NIC is claimed and before the servers bind — so a second master can never drive the same bus alongside the first. The exclusive port bind is only a backstop: it fires too late (the NIC is already claimed by then) and misses instances configured on different ports, so the lock, not the port, is the real guard.
flock(LOCK_EX|LOCK_NB) on <temp_dir>/motion-master.lock (machine-wide).| SystemInfo mm::core::collectSystemInfo | ( | ) |
| std::filesystem::path mm::core::exeDir | ( | ) |
Return the directory that contains the running executable.
argv[0] is not used — it can be a relative path, a bare command name resolved via PATH, or a symlink.
Platform behaviour
/proc/self/exe via std::filesystem::canonical._NSGetExecutablePath (no /proc).GetModuleFileNameW. | T mm::core::fromBytes | ( | std::span< const uint8_t > | bytes, |
| std::endian | order = std::endian::little |
||
| ) |
Decodes an integer from a raw byte buffer interpreted in the given byte order.
Reads up to sizeof(T) bytes. A short buffer is treated as if zero-padded (the missing most-significant bytes read as zero) — defensive against a slave returning fewer bytes than the type implies; excess bytes are ignored. Accumulation is done in the unsigned representation so the shift is well-defined for signed T. Defaults to little-endian (EtherCAT/CoE wire order).
| T | Integral result type whose size fixes how many bytes are consumed. |
| bytes | Source buffer (a std::vector<uint8_t> binds implicitly). |
| order | Byte order to interpret bytes in (default little-endian). |
|
inline |
Whether s is a valid URL-safe identifier usable as a path segment and pub/sub topic.
Accepts a non-empty string of at most 64 characters drawn from [A-Za-z0-9._-] — the unreserved subset that needs no percent-encoding in a URL path segment and carries no special meaning to the uWebSockets topic parser. Rejecting '/' is doubly load-bearing: the id is a single REST path segment (e.g. GET /api/monitorings/{topic}), so a '/' would spill into extra segments and miss the route; and uWebSockets treats it as a topic hierarchy delimiter. Comparison is case-sensitive, so "Motor" and "motor" are distinct identifiers.
| s | Candidate identifier. |
true if every character is allowed and the length is in [1, 64]. | void mm::core::openInBrowser | ( | const std::string & | url | ) |
Open the given URL in the system default browser.
Non-blocking — returns immediately after spawning the browser process. Uses xdg-open on Linux, open on macOS, and ShellExecute on Windows.
| url | URL to open. |
| std::optional< T > mm::core::parseHexOrDec | ( | std::string_view | s | ) |
Parses an unsigned integer from a string in decimal or hexadecimal notation.
Accepts a 0x / 0X prefix (C-style) or a #x / #X prefix (as EtherCAT ESI/XML files write hex constants, e.g. "#x00000201") to select hexadecimal; any other input is parsed as decimal. Trailing characters and out-of-range values are rejected.
| T | Unsigned integer type to parse into (e.g. uint16_t, uint8_t). |
| s | Input string view. |
std::nullopt if s is not a valid decimal or hexadecimal representation of a T value. | void mm::core::to_json | ( | nlohmann::json & | j, |
| const SystemInfo & | info | ||
| ) |
| std::array< uint8_t, sizeof(T)> mm::core::toBytes | ( | T | value, |
| std::endian | order = std::endian::little |
||
| ) |
Encodes an integer into a fixed-width byte array in the given byte order.
The width is sizeof(T), so toBytes<uint8_t> yields one byte, uint16_t two, and so on. Signed values are encoded through their unsigned representation (two's complement), so the shift is always well-defined. Defaults to little-endian (EtherCAT/CoE wire order); pass std::endian::big for the reverse. The returned array is the natural argument for a byte-span sink such as FieldbusDriver::writeSdo — a temporary result lives to the end of the enclosing call.
| T | Integral type whose size fixes the byte count. |
| value | Value to encode. |
| order | Byte order of the output (default little-endian). |
std::array of sizeof(T) bytes in order.