Skip to content

Commit 1b026d6

Browse files
authored
XLSX fixes (#392)
XLSX: fixes #240 (signal init value in excel template) XLSX: fixes #367 (2.)
1 parent f1af9f0 commit 1b026d6

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

examples/cmTemplate.xlsx

4.79 KB
Binary file not shown.

src/canmatrix/formats/xls.py

+22-9
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,22 @@ def parse_value_name_column(value_name, value_str, signal_size, float_factory):
322322
return mini, maxi, offset, value_table
323323

324324

325+
def read_additional_signal_attributes(signal, attribute_name, attribute_value):
326+
attribute_mapping = {"initial_value": "GenSigStartValue"}
327+
if not attribute_name.startswith("signal"):
328+
return
329+
if attribute_name.replace("signal.", "") in vars(signal):
330+
command_str = attribute_name + "="
331+
command_str += str(attribute_value)
332+
if len(str(attribute_value)) > 0:
333+
exec(command_str)
334+
elif attribute_name.replace("signal.", "") in attribute_mapping:
335+
signal_attribute = attribute_mapping[attribute_name.replace("signal.", "")]
336+
if len(str(attribute_value)) > 0:
337+
signal.add_attribute(signal_attribute, attribute_value)
338+
else:
339+
pass
340+
325341
def load(file, **options):
326342
# type: (typing.IO, **typing.Any) -> canmatrix.CanMatrix
327343
motorola_bit_format = options.get("xlsMotorolaBitFormat", "msbreverse")
@@ -341,7 +357,7 @@ def load(file, **options):
341357
db.add_frame_defines("GenMsgNrOfRepetitions", 'INT 0 65535')
342358
# db.addFrameDefines("GenMsgStartValue", 'STRING')
343359
launch_types = [] # type: typing.List[str]
344-
# db.addSignalDefines("GenSigStartValue", 'HEX 0 4294967295')
360+
db.add_signal_defines("GenSigStartValue", 'HEX 0 4294967295')
345361
db.add_signal_defines("GenSigSNA", 'STRING')
346362

347363
# eval search for correct columns:
@@ -426,9 +442,10 @@ def load(file, **options):
426442

427443
# eval launch_type
428444
if launch_type is not None:
429-
new_frame.add_attribute("GenMsgSendType", launch_type)
430-
if launch_type not in launch_types:
431-
launch_types.append(launch_type)
445+
if len(launch_type) > 0:
446+
new_frame.add_attribute("GenMsgSendType", launch_type)
447+
if launch_type not in launch_types:
448+
launch_types.append(launch_type)
432449

433450
# eval cycle time
434451
try:
@@ -506,11 +523,7 @@ def load(file, **options):
506523

507524
for additional_index in additional_inputs: # todo explain this possibly dangerous code with eval
508525
if "signal" in additional_inputs[additional_index]:
509-
command_str = additional_inputs[additional_index].replace("signal", "new_signal")
510-
command_str += "="
511-
command_str += str(sh.cell(row_num, additional_index).value)
512-
if len(str(sh.cell(row_num, additional_index).value)) > 0:
513-
exec(command_str)
526+
read_additional_signal_attributes(new_signal, additional_inputs[additional_index], sh.cell(row_num, additional_index).value)
514527

515528
new_frame.add_signal(new_signal)
516529
new_signal.add_comment(signal_comment)

0 commit comments

Comments
 (0)