ehatool 6.0.0.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ehatool/VERSION +1 -0
- ehatool/__init__.py +4 -0
- ehatool/acceptance.py +92 -0
- ehatool/brt27.py +105 -0
- ehatool/brt27_sim.py +114 -0
- ehatool/calibration.py +111 -0
- ehatool/can_sniff.py +162 -0
- ehatool/cia402.py +31 -0
- ehatool/cli.py +541 -0
- ehatool/console.py +31 -0
- ehatool/device/__init__.py +4 -0
- ehatool/device/can.py +201 -0
- ehatool/device/can_discovery.py +387 -0
- ehatool/device/can_discovery.toml +19 -0
- ehatool/device/io.py +20 -0
- ehatool/devices.py +187 -0
- ehatool/diagnostics.py +58 -0
- ehatool/diagnostics.toml +208 -0
- ehatool/discovery.py +95 -0
- ehatool/display.toml +127 -0
- ehatool/ecat.py +520 -0
- ehatool/ecat.toml +17 -0
- ehatool/ecat_probe.py +401 -0
- ehatool/ecat_probe.toml +14 -0
- ehatool/eha_od.json +5871 -0
- ehatool/experiment.py +576 -0
- ehatool/image.py +70 -0
- ehatool/info.py +121 -0
- ehatool/info.toml +41 -0
- ehatool/install_host.py +243 -0
- ehatool/install_host.toml +27 -0
- ehatool/link.py +811 -0
- ehatool/link.toml +18 -0
- ehatool/live.py +112 -0
- ehatool/motor.py +86 -0
- ehatool/od.py +200 -0
- ehatool/odrive.py +450 -0
- ehatool/output.py +208 -0
- ehatool/ram_load.py +62 -0
- ehatool/scope.py +50 -0
- ehatool/sil.py +260 -0
- ehatool/update.py +320 -0
- ehatool/usb_discovery.py +164 -0
- ehatool/usb_discovery.toml +16 -0
- ehatool/web/__init__.py +28 -0
- ehatool/web/brt_sim.py +130 -0
- ehatool/web/canbus.py +95 -0
- ehatool/web/devices.py +216 -0
- ehatool/web/experiments.py +226 -0
- ehatool/web/job_params.py +208 -0
- ehatool/web/layout.toml +61 -0
- ehatool/web/longrun.py +430 -0
- ehatool/web/polling.py +41 -0
- ehatool/web/recipes/bench.toml +18 -0
- ehatool/web/records.py +333 -0
- ehatool/web/requests.py +254 -0
- ehatool/web/server.py +1051 -0
- ehatool/web/session.py +1552 -0
- ehatool/web/static/THIRD_PARTY_LICENSES.txt +133 -0
- ehatool/web/static/assets/ehapower-logo-Cr84XeX3.png +0 -0
- ehatool/web/static/assets/ehapower-mark-Con0OjPM.png +0 -0
- ehatool/web/static/assets/index-CdLvwKa-.css +1 -0
- ehatool/web/static/assets/index-DiLUQD1i.js +134 -0
- ehatool/web/static/index.html +16 -0
- ehatool/web/streams.py +64 -0
- ehatool/web/workspaces.py +124 -0
- ehatool/workflows/__init__.py +4 -0
- ehatool/workflows/cancheck.py +394 -0
- ehatool/workflows/cancheck.toml +9 -0
- ehatool/workflows/checks.py +43 -0
- ehatool/workflows/usbcheck.py +212 -0
- ehatool-6.0.0.dev0.dist-info/METADATA +38 -0
- ehatool-6.0.0.dev0.dist-info/RECORD +77 -0
- ehatool-6.0.0.dev0.dist-info/WHEEL +5 -0
- ehatool-6.0.0.dev0.dist-info/entry_points.txt +2 -0
- ehatool-6.0.0.dev0.dist-info/licenses/LICENSE +21 -0
- ehatool-6.0.0.dev0.dist-info/top_level.txt +1 -0
ehatool/odrive.py
ADDED
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
# Copyright The eha-firmware Contributors
|
|
2
|
+
|
|
3
|
+
## @file
|
|
4
|
+
## @brief ehatool odrive:经驱动器自身的 USB 读写 MKS ODrive Mini 的设置。设置的事实来源是设备描述的
|
|
5
|
+
## [settings] 与本型号 devices.toml 的 [instance.pump_drive.settings],合并后逐项写入并读回比对;两处都没有
|
|
6
|
+
## 列出的设置保持设备原值。只用于产品集成侧,固件与设备上的其他入口不用它。
|
|
7
|
+
##
|
|
8
|
+
## ehatool odrive status
|
|
9
|
+
## ehatool odrive watch
|
|
10
|
+
## ehatool odrive read
|
|
11
|
+
## ehatool odrive configure --no-save
|
|
12
|
+
## ehatool odrive configure
|
|
13
|
+
## ehatool odrive save
|
|
14
|
+
## ehatool odrive reboot
|
|
15
|
+
## ehatool odrive verify
|
|
16
|
+
##
|
|
17
|
+
## odrive(PyPI odrive==0.5.1.post0)随包安装,只在 find_any 里导入;环境和包不同步时以中文提示与安装命令报错。
|
|
18
|
+
|
|
19
|
+
import math
|
|
20
|
+
import pathlib
|
|
21
|
+
import struct
|
|
22
|
+
import sys
|
|
23
|
+
import time
|
|
24
|
+
|
|
25
|
+
from .devices import ROOT, load_binding, load_board, product_board_file
|
|
26
|
+
from .od import ObjectDictionary
|
|
27
|
+
|
|
28
|
+
## @brief 设置的事实来源:本型号的设备绑定。设备描述由它引用,本模块不另写设置。
|
|
29
|
+
BINDING = "firmware/products/split/stm32_split/devices.toml"
|
|
30
|
+
INSTANCE = "pump_drive"
|
|
31
|
+
PACKAGE = "odrive==0.5.1.post0"
|
|
32
|
+
## @brief 驱动器固件的 AxisState 码;其余状态显示为“其他”。
|
|
33
|
+
AXIS_STATES = {1: "空闲", 8: "闭环"}
|
|
34
|
+
## @brief 0.5.1 的 can.error 只有 DUPLICATE_CAN_IDS(值 1)这一位。它不覆盖总线错误:CAN 服务线程在
|
|
35
|
+
## HAL_CAN_GetError 既非 NONE 也非 TIMEOUT 时不再收发(interface_can.cpp),该缺陷在这里没有对应位。
|
|
36
|
+
## 因此 can.error 为 0 不能说明“CAN 正常”,status 也不这样写。
|
|
37
|
+
CAN_ERRORS = {1: "DuplicateCanIds"}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## @brief 把 TOML 的嵌套表展开成 设备属性路径 -> 值;值不是数值或真假值时报错。
|
|
41
|
+
def flatten(table, prefix=""):
|
|
42
|
+
values = {}
|
|
43
|
+
for key, value in table.items():
|
|
44
|
+
path = prefix + key
|
|
45
|
+
if isinstance(value, dict):
|
|
46
|
+
values.update(flatten(value, path + "."))
|
|
47
|
+
elif isinstance(value, (bool, int, float)):
|
|
48
|
+
values[path] = value
|
|
49
|
+
else:
|
|
50
|
+
raise ValueError(f"设置 {path} 的值须为数值或 true/false")
|
|
51
|
+
return values
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
## @brief 读取设备绑定,总线的速率与帧型取本型号所属板的 board.toml(devices.toml 只写端口名)。
|
|
55
|
+
## @return (总线表, 实例名到 (实例, 设备描述) 的表)。
|
|
56
|
+
def _binding(binding=BINDING):
|
|
57
|
+
path = ROOT / binding
|
|
58
|
+
if not path.is_file():
|
|
59
|
+
raise ValueError(f"设备绑定 {binding} 不存在")
|
|
60
|
+
return load_binding(str(path), board=load_board(product_board_file(path.parent)))
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
## @brief 合并设备描述与实例的设置:设备描述的 [settings] 在前,实例的 [settings] 覆盖同名路径。
|
|
64
|
+
## 两处都没有列出的设置保持设备原值,本工具不读也不写它们。
|
|
65
|
+
def merged_settings(binding=BINDING, instance_name=INSTANCE):
|
|
66
|
+
_, instances = _binding(binding)
|
|
67
|
+
if instance_name not in instances:
|
|
68
|
+
raise ValueError(f"{binding} 没有实例 {instance_name}")
|
|
69
|
+
instance, device = instances[instance_name]
|
|
70
|
+
settings = flatten(device.get("settings", {}))
|
|
71
|
+
settings.update(flatten(instance.get("settings", {})))
|
|
72
|
+
return settings
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
## @brief 按点号路径读设备属性;路径不存在时报错,不以 None 冒充读到的值。
|
|
76
|
+
def read_attribute(device, path):
|
|
77
|
+
value = device
|
|
78
|
+
for part in path.split("."):
|
|
79
|
+
try:
|
|
80
|
+
value = getattr(value, part)
|
|
81
|
+
except AttributeError:
|
|
82
|
+
raise ValueError(f"设备没有属性 {path}") from None
|
|
83
|
+
return value
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
## @brief 按点号路径写设备属性;路径不存在或设备拒绝写入时抛出中文错误。
|
|
87
|
+
def write_attribute(device, path, value):
|
|
88
|
+
*parents, name = path.split(".")
|
|
89
|
+
target = device
|
|
90
|
+
for part in parents:
|
|
91
|
+
try:
|
|
92
|
+
target = getattr(target, part)
|
|
93
|
+
except AttributeError:
|
|
94
|
+
raise ValueError(f"设备没有属性 {path}") from None
|
|
95
|
+
try:
|
|
96
|
+
setattr(target, name, value)
|
|
97
|
+
except (AttributeError, ValueError) as error:
|
|
98
|
+
raise ValueError(f"写入 {path} 被设备拒绝:{error}") from None
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
## @brief 按设备的 float32 精度取值:ODrive 的浮点属性就是 float32。
|
|
102
|
+
def float32(value):
|
|
103
|
+
return struct.unpack("<f", struct.pack("<f", float(value)))[0]
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
## @brief 期望值与读回值是否一致。浮点按 float32 比较:设备存的是 float32,写入 0.064 会读回
|
|
107
|
+
## 0.06400000303983688,逐位相等会误报差异。
|
|
108
|
+
def same(desired, current):
|
|
109
|
+
if isinstance(desired, bool):
|
|
110
|
+
return bool(current) == desired
|
|
111
|
+
if isinstance(desired, int):
|
|
112
|
+
return current == desired
|
|
113
|
+
try:
|
|
114
|
+
return float32(desired) == float32(current)
|
|
115
|
+
except (TypeError, ValueError, OverflowError, struct.error):
|
|
116
|
+
return False
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
## @brief 与设备当前值不同的设置,按属性路径排序,每项为 (路径, 期望值, 当前值)。只写这些差异,其余保持设备原值。
|
|
120
|
+
def differences(device, settings):
|
|
121
|
+
found = []
|
|
122
|
+
for path in sorted(settings):
|
|
123
|
+
current = read_attribute(device, path)
|
|
124
|
+
if not same(settings[path], current):
|
|
125
|
+
found.append((path, settings[path], current))
|
|
126
|
+
return found
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
## @brief 打印用的值:真假值写作 true/false,浮点去掉 float32 的尾数噪声。
|
|
130
|
+
def format_value(value):
|
|
131
|
+
if isinstance(value, bool):
|
|
132
|
+
return "true" if value else "false"
|
|
133
|
+
if isinstance(value, float):
|
|
134
|
+
return f"{value:g}"
|
|
135
|
+
return str(value)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
## @brief 保存设备自身的配置(save_configuration);持久结果要重新上电后才能核对。
|
|
139
|
+
def save_configuration(device, out=None):
|
|
140
|
+
out = sys.stdout if out is None else out
|
|
141
|
+
device.save_configuration()
|
|
142
|
+
print("已保存配置;断开并重新上电驱动器后再运行 ehatool odrive read 核对持久值", file=out)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
## @brief 写入差异、逐项读回比对,全部一致后才保存配置。save=False 只写不保存。
|
|
146
|
+
def configure(device, settings, save=True, out=None):
|
|
147
|
+
out = sys.stdout if out is None else out
|
|
148
|
+
diffs = differences(device, settings)
|
|
149
|
+
if not diffs:
|
|
150
|
+
print("设备已与合并设置一致,无需写入", file=out)
|
|
151
|
+
for path, desired, current in diffs:
|
|
152
|
+
try:
|
|
153
|
+
write_attribute(device, path, desired)
|
|
154
|
+
except ValueError as error:
|
|
155
|
+
# 保存只在读回全部一致后进行;被拒绝的写入不会到达保存,此前写入的项也只在 RAM。
|
|
156
|
+
raise ValueError(f"{error};未保存,此前写入的设置只在设备 RAM,重新上电后恢复上次保存的值") from None
|
|
157
|
+
print(f"写入 {path}:{format_value(current)} → {format_value(desired)}", file=out)
|
|
158
|
+
# 读回比对在保存前进行:保存会把不一致的值写进设备闪存。
|
|
159
|
+
mismatched = differences(device, settings)
|
|
160
|
+
if mismatched:
|
|
161
|
+
lines = [f" {path}:期望 {format_value(desired)},读回 {format_value(current)}"
|
|
162
|
+
for path, desired, current in mismatched]
|
|
163
|
+
raise ValueError("读回与合并设置不一致,未保存:\n" + "\n".join(lines))
|
|
164
|
+
print(f"读回一致:{len(settings)} 项", file=out)
|
|
165
|
+
if not save:
|
|
166
|
+
print("未保存(--no-save):驱动器复位后这些设置回到上次保存的值", file=out)
|
|
167
|
+
return
|
|
168
|
+
save_configuration(device, out)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
## @brief 装配时的核对项:设备绑定与设备描述里“换板或恢复设备设置后可能被覆盖”的前提。
|
|
172
|
+
## 节点号与总线速率不在 [settings] 里(前者在实例顶层,后者在 [bus.*]),configure 不会写它们,所以单独读回比对。
|
|
173
|
+
## 看门狗使能与超时、心跳周期虽在 [settings] 里,configure 只在写入路径上比对;换板或恢复设备设置后
|
|
174
|
+
## 驱动器可能保留闭环并关闭了看门狗,装配验收要单独确认,不能只凭 configure 曾经通过。
|
|
175
|
+
def prerequisites(binding=BINDING, instance_name=INSTANCE):
|
|
176
|
+
buses, instances = _binding(binding)
|
|
177
|
+
if instance_name not in instances:
|
|
178
|
+
raise ValueError(f"{binding} 没有实例 {instance_name}")
|
|
179
|
+
instance, device = instances[instance_name]
|
|
180
|
+
roles = device.get("roles", {})
|
|
181
|
+
checks = []
|
|
182
|
+
for role, spec in roles.items():
|
|
183
|
+
if "via" in spec:
|
|
184
|
+
# via 是只写函数(如 can.set_baud_rate),读回走同一配置类的只读属性。
|
|
185
|
+
if role == "bus_bitrate":
|
|
186
|
+
bus = instance.get("bus")
|
|
187
|
+
if bus is None:
|
|
188
|
+
raise ValueError(f"[instance.{instance_name}] 的 bus_bitrate 须挂总线")
|
|
189
|
+
checks.append((role, "can.config.baud_rate", buses[bus]["bitrate_bps"]))
|
|
190
|
+
continue
|
|
191
|
+
if role == "node":
|
|
192
|
+
checks.append((role, spec["path"], instance["node"]))
|
|
193
|
+
else:
|
|
194
|
+
settings = flatten(instance.get("settings", {}))
|
|
195
|
+
device_settings = flatten(device.get("settings", {}))
|
|
196
|
+
value = settings.get(spec["path"], device_settings.get(spec["path"]))
|
|
197
|
+
if value is not None:
|
|
198
|
+
checks.append((role, spec["path"], value))
|
|
199
|
+
checks.append(("watchdog_enabled", "axis0.config.enable_watchdog", True))
|
|
200
|
+
return checks
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
## @brief 读回装配前提并逐项比对;任一项不一致即失败,报告每一项的期望与读回值。
|
|
204
|
+
def check_prerequisites(device, checks, out=None):
|
|
205
|
+
out = sys.stdout if out is None else out
|
|
206
|
+
mismatched = []
|
|
207
|
+
for role, path, desired in checks:
|
|
208
|
+
current = read_attribute(device, path)
|
|
209
|
+
if not same(desired, current):
|
|
210
|
+
mismatched.append((role, path, desired, current))
|
|
211
|
+
if mismatched:
|
|
212
|
+
lines = [f" {role}({path}):期望 {format_value(desired)},读回 {format_value(current)}"
|
|
213
|
+
for role, path, desired, current in mismatched]
|
|
214
|
+
raise ValueError("装配前提与设备不一致,暂停本次实物接入验收:\n" + "\n".join(lines))
|
|
215
|
+
print(f"装配前提一致:{len(checks)} 项", file=out)
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
## @brief 型号的字典:型号名取设备绑定所在的产品目录的叶子名(firmware/products/<拓扑>/<型号>/devices.toml)。
|
|
219
|
+
## 力上限 0x6072、额定力 0x6076、活塞面积 0x2200 与泵排量 0x2201 的型号默认值由它给出,与设备、EDS 和 SIL 用同一份。
|
|
220
|
+
def model_dictionary(binding=BINDING):
|
|
221
|
+
return ObjectDictionary(model=pathlib.Path(binding).parent.name)
|
|
222
|
+
|
|
223
|
+
|
|
224
|
+
## @brief 力 → 电机电流:力 ÷ 面积(MPa)× 泵排量(mm³/rev)÷ 2π × 10⁻³(N·m)÷ 转矩常数(Nm/A)。
|
|
225
|
+
## 与固件 eha_ctrl_force_current_a 同一公式(理想泵,不计机械效率)。
|
|
226
|
+
def force_current_a(force_n, area_mm2, pump_mm3_per_rev, torque_constant_nm_a):
|
|
227
|
+
return force_n / area_mm2 * pump_mm3_per_rev / (2.0 * math.pi) * 1e-3 / torque_constant_nm_a
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
## @brief 电流 → 力:force_current_a 的反算,用于把驱动器的电流限折算成它能给出的力。
|
|
231
|
+
def current_force_n(current_a, area_mm2, pump_mm3_per_rev, torque_constant_nm_a):
|
|
232
|
+
return current_a * torque_constant_nm_a * area_mm2 * 2.0 * math.pi * 1e3 / pump_mm3_per_rev
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
## @brief 装配时核对驱动器的电流限与力上限 0x6072 的只读值。分体型号的 0x6072 只读,值取型号默认值(额定力 0x6076
|
|
236
|
+
## 的千分比),只在 CST 与阻抗中经压力环钳位;驱动器的 current_lim 不随产品力限变化,是 CSP、CSV 与模式 −2 的最后上限。
|
|
237
|
+
## 读回 current_lim 与设备绑定的值比对,并按同一换算核对它不小于 0x6072 折算的电流:小于时驱动器给不出产品力限,钳位
|
|
238
|
+
## 不起作用。几何与额定力取型号字典的默认值,转矩常数与电流限取设备描述与型号的 devices.toml,不另写常数。
|
|
239
|
+
## @exception ValueError current_lim 与设备绑定不一致,或低于 0x6072 折算的电流。
|
|
240
|
+
def check_force_limit(device, od=None, settings=None, out=None):
|
|
241
|
+
out = sys.stdout if out is None else out
|
|
242
|
+
od = model_dictionary() if od is None else od
|
|
243
|
+
settings = merged_settings() if settings is None else settings
|
|
244
|
+
torque_constant = settings["axis0.motor.config.torque_constant"]
|
|
245
|
+
current_lim = read_attribute(device, "axis0.motor.config.current_lim")
|
|
246
|
+
area = od.by_name["piston_area_mm2"]["default"]
|
|
247
|
+
pump = od.by_name["pump_mm3_per_rev"]["default"]
|
|
248
|
+
force_n = od.by_name["max_force_permille"]["default"] * 1e-3 * od.by_name["rated_force_mn"]["default"] * 1e-3
|
|
249
|
+
required = force_current_a(force_n, area, pump, torque_constant)
|
|
250
|
+
print(f"力上限 0x6072(只读):{force_n:g} N,按面积 {area:g} mm²、泵排量 {pump:g} mm³/rev、"
|
|
251
|
+
f"转矩常数 {torque_constant:g} Nm/A 折算 {required:.2f} A", file=out)
|
|
252
|
+
print(f"驱动器电流限:{format_value(current_lim)} A,按同一换算为 "
|
|
253
|
+
f"{current_force_n(current_lim, area, pump, torque_constant):.0f} N", file=out)
|
|
254
|
+
problems = []
|
|
255
|
+
# 设备绑定给出的值:换板或恢复设备设置后驱动器可能被单独改过,与 0x6072 的核对只在绑定的电流限上有意义。
|
|
256
|
+
bound = settings.get("axis0.motor.config.current_lim")
|
|
257
|
+
if bound is not None and not same(bound, current_lim):
|
|
258
|
+
problems.append(f" current_lim:期望 {format_value(bound)},读回 {format_value(current_lim)}")
|
|
259
|
+
if not required <= float32(current_lim):
|
|
260
|
+
problems.append(f" 0x6072 折算 {required:.2f} A,超过 current_lim {format_value(current_lim)} A:"
|
|
261
|
+
"驱动器给不出产品力限,压力环的钳位不起作用")
|
|
262
|
+
if problems:
|
|
263
|
+
raise ValueError("驱动器电流限与力上限不一致,暂停本次实物接入验收:\n" + "\n".join(problems))
|
|
264
|
+
print("电流限核对一致:0x6072 由压力环钳位,电流限与溢流阀是其余模式的上限", file=out)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
## @brief 驱动器状态:固件版本、序列号、母线电压、轴状态、四个错误字与 can.error。只读,不写设置。
|
|
268
|
+
def status(device, out=None):
|
|
269
|
+
out = sys.stdout if out is None else out
|
|
270
|
+
version = ".".join(str(read_attribute(device, f"fw_version_{part}"))
|
|
271
|
+
for part in ("major", "minor", "revision"))
|
|
272
|
+
if read_attribute(device, "fw_version_unreleased"):
|
|
273
|
+
version += "-dev"
|
|
274
|
+
print(f"固件版本:{version}", file=out)
|
|
275
|
+
print(f"序列号:0x{read_attribute(device, 'serial_number'):08X}", file=out)
|
|
276
|
+
print(f"母线电压:{read_attribute(device, 'vbus_voltage'):.1f} V", file=out)
|
|
277
|
+
state = read_attribute(device, "axis0.current_state")
|
|
278
|
+
print(f"轴状态:{state}({AXIS_STATES.get(state, '其他')})", file=out)
|
|
279
|
+
for name in ("axis0", "axis0.motor", "axis0.encoder", "axis0.controller"):
|
|
280
|
+
print(f"{name}.error:0x{read_attribute(device, name + '.error'):08X}", file=out)
|
|
281
|
+
can_error = read_attribute(device, "can.error")
|
|
282
|
+
known = 0
|
|
283
|
+
names = []
|
|
284
|
+
for bit, name in CAN_ERRORS.items():
|
|
285
|
+
known |= bit
|
|
286
|
+
if can_error & bit:
|
|
287
|
+
names.append(name)
|
|
288
|
+
unknown = can_error & ~known
|
|
289
|
+
if unknown:
|
|
290
|
+
# 未知位照原值列出:非零的 can.error 不能写成“未置位”,否则与同一行的十六进制值矛盾。
|
|
291
|
+
names.append(f"未知位 0x{unknown:08X}")
|
|
292
|
+
flags = "、".join(names) if names else "未置位"
|
|
293
|
+
print(f"can.error:0x{can_error:08X}({flags};0.5.1 的 can.error 不含总线错误)", file=out)
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
## @brief 运动观测项:显示名、设备属性路径与单位。只读,供第 6 步核对 EHA 的设备实测转速、驱动器读到的转速、
|
|
297
|
+
## 位置(圈)与 Iq;轴错误与 status 的 axis0.error 是同一个字。
|
|
298
|
+
MOTION_FIELDS = (
|
|
299
|
+
("输入转速", "axis0.controller.input_vel", "turn/s"),
|
|
300
|
+
("实测转速", "axis0.encoder.vel_estimate", "turn/s"),
|
|
301
|
+
("位置", "axis0.encoder.pos_estimate", "turn"),
|
|
302
|
+
("Iq", "axis0.motor.current_control.Iq_measured", "A"),
|
|
303
|
+
("轴错误", "axis0.error", ""),
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
## @brief 按 MOTION_FIELDS 读当前值,顺序与 MOTION_FIELDS 一致。只读,不写设备。
|
|
308
|
+
def motion(device):
|
|
309
|
+
return [read_attribute(device, path) for _, path, _ in MOTION_FIELDS]
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
## @brief 测速观测:每 interval 秒打印一行,count 次后停止;count 为 0 时直到 Ctrl-C。只读,不写设备。
|
|
313
|
+
## clock 与 sleep 可注入,测试不走真实时间。
|
|
314
|
+
def watch(device, out=None, interval=0.1, count=0, clock=time.monotonic, sleep=time.sleep):
|
|
315
|
+
out = sys.stdout if out is None else out
|
|
316
|
+
if not math.isfinite(interval) or interval <= 0:
|
|
317
|
+
raise ValueError("采样间隔须为正数")
|
|
318
|
+
if count < 0:
|
|
319
|
+
raise ValueError("采样次数须为非负数,0 表示直到 Ctrl-C")
|
|
320
|
+
print("时刻 s " + " ".join(f"{name} {unit}".strip() for name, _, unit in MOTION_FIELDS), file=out)
|
|
321
|
+
start = clock()
|
|
322
|
+
samples = 0
|
|
323
|
+
try:
|
|
324
|
+
while count == 0 or samples < count:
|
|
325
|
+
values = motion(device)
|
|
326
|
+
cells = [f"{clock() - start:8.3f}"]
|
|
327
|
+
for value, (_, _, unit) in zip(values, MOTION_FIELDS):
|
|
328
|
+
cells.append(f"{value:12.4f}" if unit else f"0x{value:08X}")
|
|
329
|
+
print(" ".join(cells), file=out)
|
|
330
|
+
samples += 1
|
|
331
|
+
if count != 0 and samples >= count:
|
|
332
|
+
break
|
|
333
|
+
sleep(interval)
|
|
334
|
+
except KeyboardInterrupt:
|
|
335
|
+
pass
|
|
336
|
+
return samples
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
## @brief 经 ODrive 自身的 USB 找设备(odrive.find_any(path='usb'))。odrive 是可选依赖,只在调用时导入:
|
|
340
|
+
## 没装时抛出带安装命令的 ImportError,ehatool 以非零退出码与中文提示报告。
|
|
341
|
+
## serial_number 按 fibre 的写法(大写十六进制、无 0x、无前导零)过滤;timeout 到期未找到时返回 None。
|
|
342
|
+
def find_any(serial_number=None, timeout=None):
|
|
343
|
+
try:
|
|
344
|
+
import odrive as package
|
|
345
|
+
except ImportError:
|
|
346
|
+
raise ImportError(f"未安装 {PACKAGE}(ehatool odrive 用到);安装:pip install {PACKAGE}") from None
|
|
347
|
+
return package.find_any(path="usb", serial_number=serial_number, timeout=timeout)
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
## @brief 重启驱动器并按原序列号回连、等轴回到空闲。0.5.1 的 CAN 服务线程在 CAN 错误被闩住后不再收发
|
|
351
|
+
## (interface_can.cpp 只在 HAL_CAN_ERROR_TIMEOUT 时重置),只能重启恢复。重启是显式动作:不并入
|
|
352
|
+
## configure/read,也不自动重试。timeout 是发出 reboot 之后等待回连与轴回到空闲的时间;回连超时抛出
|
|
353
|
+
## TimeoutError,消息写明请求已发出、是否重启未知。
|
|
354
|
+
def reboot(device, timeout=15.0, out=None, clock=time.monotonic, sleep=time.sleep):
|
|
355
|
+
out = sys.stdout if out is None else out
|
|
356
|
+
serial = read_attribute(device, "serial_number")
|
|
357
|
+
call_reboot = read_attribute(device, "reboot")
|
|
358
|
+
print(f"已发出 reboot:序列号 0x{serial:08X}", file=out)
|
|
359
|
+
try:
|
|
360
|
+
call_reboot()
|
|
361
|
+
except Exception:
|
|
362
|
+
# 设备在函数处理线程里直接 NVIC_SystemReset,来不及回包;调用报错不代表请求没送到,也不代表
|
|
363
|
+
# 重启失败——能否按序列号回连、轴是否回到空闲才是可观察的结果。
|
|
364
|
+
pass
|
|
365
|
+
deadline = clock() + timeout
|
|
366
|
+
# fibre 按 大写十六进制、无 0x、无前导零 的序列号过滤设备(get_serial_number_str)。
|
|
367
|
+
found = find_any(serial_number=f"{serial:X}", timeout=timeout)
|
|
368
|
+
if found is None:
|
|
369
|
+
raise TimeoutError(
|
|
370
|
+
f"{timeout:g} s 内未按序列号 0x{serial:08X} 回连:已发出,是否重启未知(不自动重试)")
|
|
371
|
+
# 回连成功只证明设备重新出现:重启请求没送到、设备一直在时也会回连成功。输出因此不写“已重启”。
|
|
372
|
+
print(f"回连成功:序列号 0x{serial:08X}", file=out)
|
|
373
|
+
while True:
|
|
374
|
+
state = read_attribute(found, "axis0.current_state")
|
|
375
|
+
if state == 1:
|
|
376
|
+
print(f"轴状态:{state}({AXIS_STATES.get(state, '其他')})", file=out)
|
|
377
|
+
return
|
|
378
|
+
remaining = deadline - clock()
|
|
379
|
+
if remaining <= 0:
|
|
380
|
+
print(f"轴状态:{state}({AXIS_STATES.get(state, '其他')},超时前未回到空闲)", file=out)
|
|
381
|
+
raise TimeoutError(f"回连成功,但轴在 {timeout:g} s 内未回到空闲(当前状态 {state})")
|
|
382
|
+
sleep(min(0.1, remaining))
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
## @brief ehatool odrive status:打印驱动器的固件版本与当前状态。
|
|
386
|
+
def run_status(args):
|
|
387
|
+
status(find_any())
|
|
388
|
+
|
|
389
|
+
|
|
390
|
+
## @brief ehatool odrive watch:周期打印 axis0 的运动量;只读,不写设备。
|
|
391
|
+
def run_watch(args):
|
|
392
|
+
watch(find_any(), interval=args.interval, count=args.count)
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
## @brief ehatool odrive read:按合并后的设备属性路径读出设备当前值。
|
|
396
|
+
def run_read(args):
|
|
397
|
+
settings = merged_settings()
|
|
398
|
+
device = find_any()
|
|
399
|
+
for path in sorted(settings):
|
|
400
|
+
print(f"{path} = {format_value(read_attribute(device, path))}")
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
## @brief ehatool odrive configure:写入差异并读回比对,成功后保存;--no-save 只写不保存。
|
|
404
|
+
def run_configure(args):
|
|
405
|
+
settings = merged_settings()
|
|
406
|
+
configure(find_any(), settings, save=not args.no_save)
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
## @brief ehatool odrive save:保存设备当前的配置。
|
|
410
|
+
def run_save(args):
|
|
411
|
+
save_configuration(find_any())
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
## @brief ehatool odrive reboot:重启驱动器,回连后报告轴状态。
|
|
415
|
+
def run_reboot(args):
|
|
416
|
+
reboot(find_any(), timeout=args.timeout)
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
## @brief ehatool odrive verify:读回装配前提(节点号、总线速率、心跳、看门狗使能与超时)并与绑定比对,再核对驱动器
|
|
420
|
+
## 电流限与 0x6072 的只读值。
|
|
421
|
+
def run_verify(args):
|
|
422
|
+
device = find_any()
|
|
423
|
+
check_prerequisites(device, prerequisites())
|
|
424
|
+
check_force_limit(device)
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
def register(sub):
|
|
428
|
+
p = sub.add_parser("odrive", help="经驱动器自身的 USB 读写 MKS ODrive Mini 的设置(产品集成侧,需要可选依赖 odrive)")
|
|
429
|
+
actions = p.add_subparsers(dest="odrive_cmd", required=True, metavar="动作")
|
|
430
|
+
status_parser = actions.add_parser("status", help="固件版本、母线电压、轴状态与错误字")
|
|
431
|
+
status_parser.set_defaults(func=run_status, device=False)
|
|
432
|
+
watch_parser = actions.add_parser("watch", help="周期打印 axis0 的输入/实测转速、位置、Iq 与轴错误(只读)")
|
|
433
|
+
watch_parser.add_argument("--interval", type=float, default=0.1, help="采样间隔 s")
|
|
434
|
+
watch_parser.add_argument("--count", type=int, default=0, help="采样次数,0 为直到 Ctrl-C")
|
|
435
|
+
watch_parser.set_defaults(func=run_watch, device=False)
|
|
436
|
+
read_parser = actions.add_parser("read", help="读出合并设置(设备描述与实例)在设备中的当前值")
|
|
437
|
+
read_parser.set_defaults(func=run_read, device=False)
|
|
438
|
+
configure_parser = actions.add_parser("configure", help="写入合并设置与设备的差异,读回比对后保存配置")
|
|
439
|
+
configure_parser.add_argument("--no-save", action="store_true",
|
|
440
|
+
help="只写入,不保存配置(驱动器复位后回到上次保存的值)")
|
|
441
|
+
configure_parser.set_defaults(func=run_configure, device=False)
|
|
442
|
+
save_parser = actions.add_parser("save", help="保存设备当前的配置(save_configuration)")
|
|
443
|
+
save_parser.set_defaults(func=run_save, device=False)
|
|
444
|
+
verify_parser = actions.add_parser("verify", help="读回装配前提(节点号、总线速率、心跳、看门狗)并与设备绑定比对,"
|
|
445
|
+
"核对驱动器电流限与力上限 0x6072")
|
|
446
|
+
verify_parser.set_defaults(func=run_verify, device=False)
|
|
447
|
+
reboot_parser = actions.add_parser("reboot", help="重启驱动器(CAN 错误被闩住后只能重启恢复),回连后报告轴状态")
|
|
448
|
+
reboot_parser.add_argument("--timeout", type=float, default=15.0,
|
|
449
|
+
help="发出 reboot 后等待回连与轴回到空闲的时间 s")
|
|
450
|
+
reboot_parser.set_defaults(func=run_reboot, device=False)
|
ehatool/output.py
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
# Copyright The eha-firmware Contributors
|
|
2
|
+
|
|
3
|
+
## @file
|
|
4
|
+
## @brief 由共享记录生成 JSON 或 Rich 终端输出,展示标签取自包内 TOML。
|
|
5
|
+
|
|
6
|
+
import io
|
|
7
|
+
import json
|
|
8
|
+
import math
|
|
9
|
+
import pathlib
|
|
10
|
+
import tomllib
|
|
11
|
+
|
|
12
|
+
from .od import REACTIONS, format_address
|
|
13
|
+
|
|
14
|
+
with (pathlib.Path(__file__).resolve().parent / "display.toml").open("rb") as file:
|
|
15
|
+
DISPLAY = tomllib.load(file)
|
|
16
|
+
LABELS = DISPLAY["labels"]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def object_attributes(obj):
|
|
20
|
+
labels = DISPLAY["attributes"]
|
|
21
|
+
attributes = [labels[obj["access"]]]
|
|
22
|
+
if obj.get("pdo"):
|
|
23
|
+
attributes.append(labels[obj["pdo"]])
|
|
24
|
+
attributes.extend(labels[key] for key in ("disabled_only", "developer", "persist", "object_ref") if obj.get(key))
|
|
25
|
+
return " · ".join(attributes)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
## @brief 错误文本供异常和终端共用,保留完整原文,避免异常字符串受终端宽度截断。
|
|
29
|
+
def render_diagnostic(record):
|
|
30
|
+
from rich.console import Console
|
|
31
|
+
from rich.text import Text
|
|
32
|
+
|
|
33
|
+
stream = io.StringIO()
|
|
34
|
+
console = Console(file=stream, color_system=None, highlight=False, markup=False)
|
|
35
|
+
code = record["code"]
|
|
36
|
+
if record["kind"] == "sdo_abort":
|
|
37
|
+
header = Text.assemble(LABELS["sdo_abort"], f" 0x{code:08X}")
|
|
38
|
+
else:
|
|
39
|
+
header = Text.assemble(LABELS["device_error"], f" 0x{code:04X}", "(", LABELS["decimal"], f" {code})")
|
|
40
|
+
console.print(header, soft_wrap=True)
|
|
41
|
+
fields = [("name", record.get("name") or LABELS["unknown_name"]),
|
|
42
|
+
("original_zh", record["description_zh"]), ("meaning_zh", record["meaning_zh"])]
|
|
43
|
+
if "motor_subcode" in record:
|
|
44
|
+
fields.append(("motor_subcode", f"0x{record['motor_subcode']:X}"))
|
|
45
|
+
if record.get("request"):
|
|
46
|
+
request = record["request"]
|
|
47
|
+
fields.append(("request", " ".join((LABELS[request["operation"]],
|
|
48
|
+
format_address(request["index"], request["subindex"])))))
|
|
49
|
+
if record.get("context"):
|
|
50
|
+
fields.append(("request", record["context"]))
|
|
51
|
+
for key, value in fields:
|
|
52
|
+
label = Text(LABELS[key])
|
|
53
|
+
label.align("left", max(10, label.cell_len + 2))
|
|
54
|
+
console.print(Text.assemble(label, str(value)), soft_wrap=True)
|
|
55
|
+
return stream.getvalue().rstrip("\n")
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
## @brief 长列表由 Rich 按当前终端宽度计算列宽并折行,TOML 内容始终作为字面文本。
|
|
59
|
+
def print_object_list(objects, out):
|
|
60
|
+
from rich import box
|
|
61
|
+
from rich.console import Console
|
|
62
|
+
from rich.table import Table
|
|
63
|
+
from rich.text import Text
|
|
64
|
+
|
|
65
|
+
console = Console(file=out, highlight=False, markup=False)
|
|
66
|
+
if console.width < 72:
|
|
67
|
+
for obj in objects:
|
|
68
|
+
console.print(Text.assemble(format_address(obj["index"], obj["sub"]), " ", obj["name"]))
|
|
69
|
+
console.print(Text(obj.get("desc", "")))
|
|
70
|
+
console.print(Text.assemble(object_attributes(obj), " ", obj.get("unit") or "—"))
|
|
71
|
+
console.print()
|
|
72
|
+
return
|
|
73
|
+
table = Table(box=box.SIMPLE, show_edge=False, padding=(0, 1))
|
|
74
|
+
for key, ratio in (("address", None), ("name", 2), ("unit", None), ("attributes", 1), ("description", 3)):
|
|
75
|
+
table.add_column(LABELS[key], ratio=ratio, overflow="fold", no_wrap=key in ("address", "unit"))
|
|
76
|
+
for obj in objects:
|
|
77
|
+
table.add_row(Text(format_address(obj["index"], obj["sub"])), Text(obj["name"]), Text(obj.get("unit") or "—"),
|
|
78
|
+
Text(object_attributes(obj)), Text(obj.get("desc", "")))
|
|
79
|
+
console.print(table)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
## @brief 对象详情保留原始字典字段,故障表同样由对象字典提供。
|
|
83
|
+
def print_object_detail(od, obj, out):
|
|
84
|
+
from rich import box
|
|
85
|
+
from rich.console import Console
|
|
86
|
+
from rich.table import Table
|
|
87
|
+
from rich.text import Text
|
|
88
|
+
|
|
89
|
+
console = Console(file=out, highlight=False, markup=False)
|
|
90
|
+
console.print(Text.assemble(format_address(obj["index"], obj["sub"]), " ", obj["name"]))
|
|
91
|
+
console.print(Text(obj.get("desc", "")))
|
|
92
|
+
table = Table.grid(padding=(0, 2))
|
|
93
|
+
table.add_column(no_wrap=True)
|
|
94
|
+
table.add_column(overflow="fold")
|
|
95
|
+
unit = obj.get("unit", "")
|
|
96
|
+
# 未选型号时型号无关的视图没有默认值(各型号不同),显示为由型号决定。
|
|
97
|
+
default = "(由型号决定)" if "default" not in obj else f"{obj['default']} {unit}".rstrip()
|
|
98
|
+
rows = [("type", obj["type"]), ("attributes", object_attributes(obj)), ("default", default)]
|
|
99
|
+
if "values" in obj:
|
|
100
|
+
rows.append(("values", "、".join(map(str, obj["values"]))))
|
|
101
|
+
rows.extend((key, f"{obj[key]} {unit}".rstrip()) for key in ("min", "max") if key in obj)
|
|
102
|
+
for key, value in rows:
|
|
103
|
+
table.add_row(Text(LABELS[key]), Text(value))
|
|
104
|
+
console.print(table)
|
|
105
|
+
if obj["name"] == "error_code":
|
|
106
|
+
if console.width < 72:
|
|
107
|
+
for fault in od.errors:
|
|
108
|
+
console.print(Text.assemble(f"0x{fault['code']:04X}", " ", fault["name"]))
|
|
109
|
+
console.print(Text(REACTIONS[fault["reaction"]]))
|
|
110
|
+
console.print(Text(fault["desc"]))
|
|
111
|
+
console.print()
|
|
112
|
+
return
|
|
113
|
+
faults = Table(box=box.SIMPLE, show_edge=False, padding=(0, 1))
|
|
114
|
+
for key in ("code", "name", "reaction", "description"):
|
|
115
|
+
faults.add_column(LABELS[key], overflow="fold", no_wrap=key == "code", min_width=6 if key == "code" else None)
|
|
116
|
+
for fault in od.errors:
|
|
117
|
+
faults.add_row(Text(f"0x{fault['code']:04X}"), Text(fault["name"]),
|
|
118
|
+
Text(REACTIONS[fault["reaction"]]), Text(fault["desc"]))
|
|
119
|
+
console.print(faults)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
## @brief 生成可序列化的快照,JSON 不能表示的非有限浮点在原位置写成 null。
|
|
123
|
+
def json_value(value):
|
|
124
|
+
if isinstance(value, float) and not math.isfinite(value):
|
|
125
|
+
return None
|
|
126
|
+
if isinstance(value, dict):
|
|
127
|
+
# 设备线程可能在递归期间加入读数或日志,每一层都先固定本次处理的成员。
|
|
128
|
+
return {key: json_value(item) for key, item in value.copy().items()}
|
|
129
|
+
if isinstance(value, (list, tuple)):
|
|
130
|
+
return [json_value(item) for item in list(value)]
|
|
131
|
+
return value
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
## @brief 输出单个 UTF-8 JSON 文档;序列化先完成,避免失败时写出半份结果。
|
|
135
|
+
def emit_json(payload, out):
|
|
136
|
+
text = json.dumps(json_value(payload), ensure_ascii=False, allow_nan=False, indent=2)
|
|
137
|
+
out.write(text + "\n")
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def print_devices(result, out):
|
|
141
|
+
"""在终端展示与 JSON 相同的路径、身份来源和扫描问题。"""
|
|
142
|
+
from rich import box
|
|
143
|
+
from rich.console import Console
|
|
144
|
+
from rich.table import Table
|
|
145
|
+
from rich.text import Text
|
|
146
|
+
|
|
147
|
+
labels = DISPLAY["discovery"]
|
|
148
|
+
states = DISPLAY["discovery_states"]
|
|
149
|
+
console = Console(file=out, highlight=False, markup=False)
|
|
150
|
+
visible = [row for row in result["devices"] if row["state"] != "excluded" and not (
|
|
151
|
+
row["via"] == "ecat" and row["state"] == "down" and not row.get("physical"))]
|
|
152
|
+
if visible:
|
|
153
|
+
table = Table(box=box.SIMPLE, show_edge=False, padding=(0, 1))
|
|
154
|
+
coverage = []
|
|
155
|
+
for key in ("route", "name", "serial", "state"):
|
|
156
|
+
table.add_column(labels[key], overflow="fold")
|
|
157
|
+
for row in visible:
|
|
158
|
+
via = row["via"]
|
|
159
|
+
if via == "usb":
|
|
160
|
+
route = row.get("port")
|
|
161
|
+
elif via == "can":
|
|
162
|
+
route = f'{row.get("interface", "")}:{row.get("channel", "")}'
|
|
163
|
+
if row.get("node") is not None:
|
|
164
|
+
route += f' / {labels["node"]} {row["node"]}'
|
|
165
|
+
else:
|
|
166
|
+
route = row.get("ifname", "")
|
|
167
|
+
if row.get("slave") is not None:
|
|
168
|
+
route += f' / {labels["slave"]} {row["slave"]}'
|
|
169
|
+
state = states.get(row["state"], row["state"])
|
|
170
|
+
if row.get("count") is not None and row["role"] == "interface":
|
|
171
|
+
state += f' · {labels["responses"]} {row["count"]}'
|
|
172
|
+
identity = str(row.get("serial") or "—")
|
|
173
|
+
source = row.get("serial_source") or (row.get("method") if row.get("serial") else None)
|
|
174
|
+
if source in ("usb_descriptor", "sdo", "coe"):
|
|
175
|
+
identity += f'\n{labels[source]}'
|
|
176
|
+
if row.get("adapter_serial"):
|
|
177
|
+
identity += f'\n{labels["adapter_serial"]} {row["adapter_serial"]}'
|
|
178
|
+
name = str(row.get("name") or "—")
|
|
179
|
+
if via == "usb" and row.get("name"):
|
|
180
|
+
name += f'\n{labels["usb_descriptor"]}'
|
|
181
|
+
table.add_row(Text(f'{via.upper()} {route or "—"}'), Text(name), Text(identity), Text(state))
|
|
182
|
+
if "scanned" in row:
|
|
183
|
+
coverage.append(labels["coverage"].format(route=route, scanned=len(row["scanned"]),
|
|
184
|
+
pending=len(row.get("pending", [])), unresolved=len(row.get("unresolved", []))))
|
|
185
|
+
console.print(table)
|
|
186
|
+
for summary in coverage:
|
|
187
|
+
console.print(Text(summary), soft_wrap=True)
|
|
188
|
+
for row in visible:
|
|
189
|
+
if (row["via"] == "can" and row.get("interface") != "socketcan"
|
|
190
|
+
and row.get("role") == "adapter" and row.get("bitrate") is None
|
|
191
|
+
and row["state"] == "candidate"):
|
|
192
|
+
route = f'{row["interface"]}:{row["channel"]}'
|
|
193
|
+
console.print(Text(labels["bitrate_required"].format(route=route)), soft_wrap=True)
|
|
194
|
+
for command in dict.fromkeys(row.get("selection") for row in visible):
|
|
195
|
+
if command:
|
|
196
|
+
if "--identify" in command:
|
|
197
|
+
label = "ecat_identify_command" if "--via ecat" in command else "identify_command"
|
|
198
|
+
command = labels[label].format(command=command)
|
|
199
|
+
console.print(Text(command), soft_wrap=True)
|
|
200
|
+
elif not result["issues"]:
|
|
201
|
+
console.print(Text(labels["empty"]))
|
|
202
|
+
hidden = len(result["devices"]) - len(visible)
|
|
203
|
+
if hidden:
|
|
204
|
+
console.print(Text(labels["hidden_interfaces"].format(count=hidden)))
|
|
205
|
+
for issue in result["issues"]:
|
|
206
|
+
scope = issue.get("port") or issue.get("ifname") or issue.get("channel") or issue.get("interface")
|
|
207
|
+
prefix = f'{issue["via"].upper()} {scope}' if scope else issue["via"].upper()
|
|
208
|
+
console.print(Text(f'{prefix} · {issue["message"]}'))
|