Motion Master 6.0.0-alpha.86
Next-generation motion control software
Loading...
Searching...
No Matches
esi_entry.h
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5#include <expected>
6#include <nlohmann/json_fwd.hpp>
7#include <optional>
8#include <string>
9#include <vector>
10
11#include "etg/esi.h"
12#include "etg/esi_data_type.h"
13
14namespace mm::etg {
15
23 std::string label;
24 int64_t value = 0;
25};
26
33 enum class Kind : uint8_t { Device, Module };
34
36 uint32_t moduleIdent = 0;
37 int32_t slot = -1;
38 uint32_t indexOffset = 0;
39
40 // The module's *name* is deliberately not here: it would be the same string on every one of
41 // that module's entries. Resolve `moduleIdent` against the file's module list instead.
42};
43
57struct EsiEntry {
58 uint16_t index = 0;
59 uint8_t subindex = 0;
60 uint16_t rawIndex = 0;
61
62 std::string objectName;
63 std::string entryName;
64 std::string displayName;
65
69 uint8_t numberOfEntries = 0;
70
71 std::string dataTypeName;
72 uint16_t dataType = 0;
73
82 bool isSigned = false;
84 uint16_t bitSize = 0;
85 uint16_t bitOffset = 0;
86
87 std::optional<std::vector<uint8_t>> defaultData;
88 std::optional<std::vector<uint8_t>> minData;
89 std::optional<std::vector<uint8_t>> maxData;
90
91 std::optional<uint32_t> unit;
92 std::string unitSymbol;
93
99 bool backup = false;
100 bool setting = false;
101 std::optional<uint32_t> attribute;
102
108 uint16_t objAccess = 0;
109
123 std::vector<Property> properties;
124
125 std::string description;
126 std::vector<EsiEnumOption> options;
127
129
131 uint32_t key() const { return (static_cast<uint32_t>(index) << 8) | subindex; }
132};
133
135enum class EsiCollisionPolicy : uint8_t {
136 LastWins,
137 FirstWins,
138 Error,
139};
140
143 uint32_t lcId = kDefaultLcId;
144
152 std::vector<uint32_t> moduleIdents;
153
154 bool applySlotOffsets = true;
155
163
165
170 bool padShortValues = true;
171
172 bool sortByAddress = true;
173
174 std::size_t maxWarnings = 1000;
175};
176
179 std::vector<EsiEntry> entries;
180 std::vector<std::string> warnings;
181};
182
195std::expected<EsiEntryTable, std::string> buildDeviceEntries(const EsiFile& file,
196 const EsiDevice& device,
197 const EsiEntryOptions& options = {});
198
202void to_json(nlohmann::json& j, const EsiEnumOption& v);
203void to_json(nlohmann::json& j, const EsiEntrySource& v);
204void to_json(nlohmann::json& j, const EsiEntry& v);
205void to_json(nlohmann::json& j, const EsiEntryTable& v);
207
208} // 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
ObjectCode
CoE object code (ETG.1000.6 §5 Table 41 "Object Code").
Definition esi_data_type.h:29
@ Var
A single value: no subindices beyond 0.
std::expected< EsiEntryTable, std::string > buildDeviceEntries(const EsiFile &file, const EsiDevice &device, const EsiEntryOptions &options)
Expands a device into a flat, slot-merged vector of object-dictionary entries.
Definition esi_entry.cc:322
constexpr uint32_t kDefaultLcId
The default LcId — 1033, en-US.
Definition esi.h:62
SdoAccess
SDO transfer granularity (Object/Flags/SdoAccess).
Definition esi.h:114
PdoMapping
PDO mappability (Flags/PdoMapping). Spec default None — not mappable.
Definition esi.h:103
EsiCollisionPolicy
What to do when two dictionaries declare the same (index, subindex).
Definition esi_entry.h:135
@ LastWins
The later definition replaces the earlier one.
@ FirstWins
The earlier definition is kept (device dictionary, then slots in order).
@ Error
Fail the whole build.
Category
Whether an entry must be implemented (Flags/Category). Spec default Optional.
Definition esi.h:97
SafetyMapping
Safety mappability (Flags/SafetyMapping, ETG.5120). Spec default None.
Definition esi.h:106
ValueKind
The C++ type an entry's value maps to.
Definition esi_data_type.h:167
@ Bytes
Everything else, including any type/width contradiction.
An <Access> element together with its two restriction attributes.
Definition esi.h:120
One device description (ETG.2000 DeviceType) — the dictionary-relevant subset.
Definition esi.h:502
Knobs for buildDeviceEntries.
Definition esi_entry.h:142
bool applySlotOffsets
Apply SlotIndexIncrement / SlotPdoIncrement.
Definition esi_entry.h:154
uint32_t lcId
Preferred locale for names and descriptions.
Definition esi_entry.h:143
EsiCollisionPolicy collisionPolicy
Definition esi_entry.h:164
std::size_t maxWarnings
Cap before warnings are summarised.
Definition esi_entry.h:174
std::vector< uint32_t > moduleIdents
Restricts the merge to these module idents, in the order the slots declare them.
Definition esi_entry.h:152
bool requireDependOnSlot
Only relocate objects whose <Index> carries DependOnSlot="1".
Definition esi_entry.h:162
bool padShortValues
Zero-pad or sign-extend a hexBinary value shorter than its declared width.
Definition esi_entry.h:170
bool sortByAddress
Sort by (index, subindex); false keeps document order.
Definition esi_entry.h:172
Which dictionary an entry came from.
Definition esi_entry.h:31
uint32_t moduleIdent
0 for the device dictionary.
Definition esi_entry.h:36
uint32_t indexOffset
Offset actually applied to rawIndex to arrive at index.
Definition esi_entry.h:38
Kind
The device's own dictionary, or a module plugged into one of its slots.
Definition esi_entry.h:33
Kind kind
Definition esi_entry.h:35
int32_t slot
−1 for the device dictionary; the 0-based slot number otherwise.
Definition esi_entry.h:37
A device's flat dictionary, plus everything questionable found while building it.
Definition esi_entry.h:178
std::vector< EsiEntry > entries
Definition esi_entry.h:179
std::vector< std::string > warnings
Definition esi_entry.h:180
One (index, subindex) row of a device's fully expanded object dictionary.
Definition esi_entry.h:57
uint16_t rawIndex
The index exactly as written in the source dictionary.
Definition esi_entry.h:60
Access access
Resolved mode plus read/write AL-state restrictions.
Definition esi_entry.h:94
std::optional< uint32_t > unit
Packed ETG.1004 notation value, e.g. 0xFD260000.
Definition esi_entry.h:91
uint16_t bitSize
Width of this entry.
Definition esi_entry.h:84
std::string entryName
This subindex's own name; equals objectName for a VAR.
Definition esi_entry.h:63
std::optional< std::vector< uint8_t > > defaultData
Raw bytes, first byte least significant.
Definition esi_entry.h:87
uint8_t subindex
CoE subindex.
Definition esi_entry.h:59
std::optional< uint32_t > attribute
SoE IDN, when declared.
Definition esi_entry.h:101
PdoMapping pdoMapping
Definition esi_entry.h:96
std::string unitSymbol
Rendered symbol, e.g. "mV"; empty when unresolvable.
Definition esi_entry.h:92
bool setting
Definition esi_entry.h:100
uint8_t numberOfEntries
The subindex-0 value (highest subindex); 0 for a VAR.
Definition esi_entry.h:69
SafetyMapping safetyMapping
Definition esi_entry.h:97
std::string dataTypeName
Resolved ESI type name, e.g. "UDINT", "STRING(50)".
Definition esi_entry.h:71
uint16_t dataType
ETG.1020 code; 0 when the name could not be resolved.
Definition esi_entry.h:72
std::string objectName
Object/Name — identical across every subindex of an object.
Definition esi_entry.h:62
ObjectCode objectCode
Definition esi_entry.h:68
uint16_t objAccess
ETG.1000.6 ObjAccess bitfield synthesised from the resolved flags.
Definition esi_entry.h:108
uint32_t key() const
Packed (index << 8) | subindex — the same key as mm::node::makeParameterKey.
Definition esi_entry.h:131
uint16_t index
Effective CoE index, with any slot offset applied.
Definition esi_entry.h:58
std::optional< std::vector< uint8_t > > minData
Definition esi_entry.h:88
std::vector< Property > properties
Every <Property> as written, for whatever this row describes.
Definition esi_entry.h:123
Category category
Definition esi_entry.h:95
EsiEntrySource source
Definition esi_entry.h:128
bool isSigned
Definition esi_entry.h:82
std::string description
The "description" property of properties, decoded to text.
Definition esi_entry.h:125
ValueKind valueKind
The C++ type this entry's value maps to (resolveValueKind of dataType and bitSize).
Definition esi_entry.h:81
std::vector< EsiEnumOption > options
Definition esi_entry.h:126
bool backup
Definition esi_entry.h:99
SdoAccess sdoAccess
Definition esi_entry.h:98
uint16_t bitOffset
Offset within the object's complete-access image.
Definition esi_entry.h:85
std::string displayName
Info/DisplayName when the ESI overrides it, else entryName.
Definition esi_entry.h:64
std::optional< std::vector< uint8_t > > maxData
Definition esi_entry.h:89
One label/value pair of an enumerated entry.
Definition esi_entry.h:22
int64_t value
Definition esi_entry.h:24
std::string label
Definition esi_entry.h:23
A parsed ESI file.
Definition esi.h:546