Skip to content

Commit d03beb4

Browse files
authored
Add printing disabled cob-ids (#78)
* Add +NODEID message on COB-IDs * Add new option --nodeid to odg
1 parent bba6a96 commit d03beb4

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎src/objdictgen/__main__.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def main(debugopts: DebugOpts, args: Sequence[str]|None = None):
174174
subp.add_argument('--unused', action="store_true", help="Include unused profile parameters")
175175
subp.add_argument('--internal', action="store_true", help="Show internal data")
176176
subp.add_argument('--minus', help="Show only parameters that are not in this OD")
177+
subp.add_argument('-n', '--nodeid', type=int, help="Set the $NODEID to this value")
177178

178179
# -- NETWORK --
179180
subp = subparser.add_parser('network', parents=[common_opts], help="""
@@ -313,6 +314,10 @@ def main(debugopts: DebugOpts, args: Sequence[str]|None = None):
313314
print(Fore.LIGHTBLUE_EX + name + '\n' + "=" * len(name) + Style.RESET_ALL)
314315

315316
od = open_od(name, validate=not opts.novalidate)
317+
318+
if opts.nodeid:
319+
od.ID = opts.nodeid
320+
316321
for line in format_node(od, name, index=opts.index, minus=minus, opts=opts):
317322
print(line)
318323

‎src/objdictgen/printing.py‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,11 @@ def format_od_object(
227227
# Fetch the dictionary values and the parameters, if present
228228
if index in node.Dictionary:
229229
values = node.GetEntry(index, aslist=True, compute=not raw)
230+
raw_values = node.GetEntry(index, aslist=True, compute=False)
230231
else:
231232
# Fill the values with N/A if the entry is not present
232233
values = ['__N/A__'] * len(obj["values"])
234+
raw_values = values
233235

234236
if index in node.ParamsDictionary:
235237
# FIXME: Is there a risk that this return less than the length of
@@ -239,16 +241,22 @@ def format_od_object(
239241
params = [maps.DEFAULT_PARAMS] * len(values)
240242

241243
# For mypy to ensure that values and entries are lists
242-
assert isinstance(values, list) and isinstance(params, list)
244+
assert isinstance(values, list) and isinstance(raw_values, list) and isinstance(params, list)
243245

244246
infos = []
245247
# The strict=True will capture if the values and params are not the same
246-
for i, (value, param) in enumerate(zip(values, params, strict=True)):
248+
for i, (value, raw_value, param) in enumerate(zip(values, raw_values, params, strict=True)):
247249

248250
# Prepare data for printing
249251
info = node.GetSubentryInfos(index, i)
250252
typename = node.GetTypeName(info['type'])
251253

254+
# Adding +NODEID text?
255+
if 'COB ID' in info["name"] and isinstance(raw_value, str) and "$NODEID" in raw_value and not node.ID:
256+
t_node = f"{Fore.GREEN}+NODEID{Style.RESET_ALL}"
257+
else:
258+
t_node = ''
259+
252260
# Type specific formatting of the value
253261
if value == "__N/A__":
254262
t_value = f'{Fore.LIGHTBLACK_EX}N/A{Style.RESET_ALL}'
@@ -268,8 +276,13 @@ def format_od_object(
268276
except ValueError:
269277
suffix = ' ???' if value else ''
270278
t_value = f"0x{value:x}{suffix}"
279+
elif index_range and index_range.name in ('rpdop', 'tpdop'):
280+
assert isinstance(value, int)
281+
t_value = f"0x{value:x}{t_node}" if 'COB ID' in info["name"] else f"{value}{t_node}"
282+
if i == 1 and value & 0x80000000:
283+
t_value += f" {Fore.LIGHTYELLOW_EX}<DISABLED>{Style.RESET_ALL}"
271284
elif i and value and (index in (4120, ) or 'COB ID' in info["name"]):
272-
t_value = f"0x{value:x}"
285+
t_value = f"0x{value:x}{t_node}"
273286
else:
274287
t_value = str(value)
275288

0 commit comments

Comments
 (0)