Skip to content

Commit a2873b7

Browse files
committed
* Add +NODEID message on COB-IDs
* Add new option --nodeid to odg
1 parent 9cd086e commit a2873b7

2 files changed

Lines changed: 18 additions & 5 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: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,11 @@ def format_od_object(
226226
# Fetch the dictionary values and the parameters, if present
227227
if index in node.Dictionary:
228228
values = node.GetEntry(index, aslist=True, compute=not raw)
229+
raw_values = node.GetEntry(index, aslist=True, compute=False)
229230
else:
230231
# Fill the values with N/A if the entry is not present
231232
values = ['__N/A__'] * len(obj["values"])
233+
raw_values = values
232234

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

240242
# For mypy to ensure that values and entries are lists
241-
assert isinstance(values, list) and isinstance(params, list)
243+
assert isinstance(values, list) and isinstance(raw_values, list) and isinstance(params, list)
242244

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

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

253+
# Adding +NODEID text?
254+
if 'COB ID' in info["name"] and isinstance(raw_value, str) and "$NODEID" in raw_value and not node.ID:
255+
t_node = f"{Fore.GREEN}+NODEID{Style.RESET_ALL}"
256+
else:
257+
t_node = ''
258+
251259
# Type specific formatting of the value
252260
if value == "__N/A__":
253261
t_value = f'{Fore.LIGHTBLACK_EX}N/A{Style.RESET_ALL}'
@@ -269,11 +277,11 @@ def format_od_object(
269277
t_value = f"0x{value:x}{suffix}"
270278
elif index_range and index_range.name in ('rpdop', 'tpdop'):
271279
assert isinstance(value, int)
272-
t_value = f"0x{value:x}" if 'COB ID' in info["name"] else str(value)
280+
t_value = f"0x{value:x}{t_node}" if 'COB ID' in info["name"] else f"{value}{t_node}"
273281
if i == 1 and value & 0x80000000:
274-
t_value += f" {Fore.LIGHTYELLOW_EX}DISABLED{Style.RESET_ALL}"
282+
t_value += f" {Fore.LIGHTYELLOW_EX}<DISABLED>{Style.RESET_ALL}"
275283
elif i and value and (index in (4120, ) or 'COB ID' in info["name"]):
276-
t_value = f"0x{value:x}"
284+
t_value = f"0x{value:x}{t_node}"
277285
else:
278286
t_value = str(value)
279287

0 commit comments

Comments
 (0)