Motion Master 6.0.0-alpha.86
Next-generation motion control software
Loading...
Searching...
No Matches
esi_unit.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <nlohmann/json_fwd.hpp>
5#include <span>
6#include <string>
7#include <string_view>
8
9namespace mm::etg {
10
17struct UnitType {
18 uint8_t notationIndex = 0;
19 uint32_t index = 0;
20 std::string name;
21 std::string symbol;
22};
23
26 uint8_t notationIndex = 0;
27 std::string_view symbol;
28 std::string_view name;
29};
30
37struct UnitParts {
38 uint8_t prefix = 0;
39 uint8_t numerator = 0;
40 uint8_t denominator = 0;
41 uint8_t reserved = 0;
42};
43
45constexpr UnitParts esiUnitParts(uint32_t unit) {
46 return UnitParts{
47 .prefix = static_cast<uint8_t>((unit >> 24) & 0xFF),
48 .numerator = static_cast<uint8_t>((unit >> 16) & 0xFF),
49 .denominator = static_cast<uint8_t>((unit >> 8) & 0xFF),
50 .reserved = static_cast<uint8_t>(unit & 0xFF),
51 };
52}
53
66std::string esiUnitSymbol(uint32_t unit, std::span<const UnitType> local = {});
67
69void to_json(nlohmann::json& j, const UnitType& unit);
70
71} // namespace mm::etg
Definition eni.cc:18
void to_json(nlohmann::json &j, const EniNetwork &network)
Serialises a network as JSON, for a client that renders rather than replays it.
Definition eni.cc:907
std::string esiUnitSymbol(uint32_t unit, std::span< const UnitType > local)
Renders a packed unit notation value as a display symbol.
Definition esi_unit.cc:128
constexpr UnitParts esiUnitParts(uint32_t unit)
Splits a packed ETG.1004 unit notation value into its four bytes.
Definition esi_unit.h:45
One entry of the built-in ETG.1004 notation catalogue.
Definition esi_unit.h:25
uint8_t notationIndex
Definition esi_unit.h:26
std::string_view symbol
Definition esi_unit.h:27
std::string_view name
Definition esi_unit.h:28
The four bytes of an ETG.1004 unit notation value, split out.
Definition esi_unit.h:37
uint8_t reserved
Definition esi_unit.h:41
uint8_t numerator
Definition esi_unit.h:39
uint8_t prefix
Definition esi_unit.h:38
uint8_t denominator
Definition esi_unit.h:40
A dictionary-local unit definition (ETG.2000 UnitType, Dictionary/UnitTypes).
Definition esi_unit.h:17
std::string name
Human-readable name, e.g. "Increments".
Definition esi_unit.h:20
uint32_t index
Object index of the unit in the 0x0400.. area (informational).
Definition esi_unit.h:19
uint8_t notationIndex
The byte this definition overrides.
Definition esi_unit.h:18
std::string symbol
Rendered symbol, e.g. "Inc".
Definition esi_unit.h:21