powertrain-build 1.13.1__py3-none-any.whl → 1.13.3.dev3__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.
Files changed (132) hide show
  1. powertrain_build/__init__.py +40 -40
  2. powertrain_build/__main__.py +6 -6
  3. powertrain_build/a2l.py +582 -582
  4. powertrain_build/a2l_merge.py +650 -650
  5. powertrain_build/a2l_templates.py +717 -717
  6. powertrain_build/build.py +985 -985
  7. powertrain_build/build_defs.py +309 -309
  8. powertrain_build/build_proj_config.py +690 -690
  9. powertrain_build/check_interface.py +575 -575
  10. powertrain_build/cli.py +141 -141
  11. powertrain_build/config.py +542 -542
  12. powertrain_build/core.py +395 -395
  13. powertrain_build/core_dummy.py +343 -343
  14. powertrain_build/create_conversion_table.py +73 -73
  15. powertrain_build/dids.py +916 -916
  16. powertrain_build/dummy.py +157 -157
  17. powertrain_build/dummy_spm.py +252 -252
  18. powertrain_build/environmentcheck.py +52 -52
  19. powertrain_build/ext_dbg.py +255 -255
  20. powertrain_build/ext_var.py +327 -327
  21. powertrain_build/feature_configs.py +301 -301
  22. powertrain_build/gen_allsysteminfo.py +227 -227
  23. powertrain_build/gen_label_split.py +449 -449
  24. powertrain_build/handcode_replacer.py +124 -124
  25. powertrain_build/html_report.py +133 -133
  26. powertrain_build/interface/__init__.py +4 -4
  27. powertrain_build/interface/application.py +511 -511
  28. powertrain_build/interface/base.py +500 -500
  29. powertrain_build/interface/csp_api.py +490 -490
  30. powertrain_build/interface/device_proxy.py +677 -677
  31. powertrain_build/interface/ems.py +67 -67
  32. powertrain_build/interface/export_global_vars.py +121 -121
  33. powertrain_build/interface/generate_adapters.py +132 -132
  34. powertrain_build/interface/generate_hi_interface.py +87 -87
  35. powertrain_build/interface/generate_service.py +69 -69
  36. powertrain_build/interface/generate_wrappers.py +147 -147
  37. powertrain_build/interface/generation_utils.py +142 -142
  38. powertrain_build/interface/hal.py +194 -194
  39. powertrain_build/interface/model_yaml_verification.py +348 -348
  40. powertrain_build/interface/service.py +296 -296
  41. powertrain_build/interface/simulink.py +249 -249
  42. powertrain_build/interface/update_call_sources.py +180 -180
  43. powertrain_build/interface/update_model_yaml.py +186 -186
  44. powertrain_build/interface/zone_controller.py +362 -362
  45. powertrain_build/lib/__init__.py +4 -4
  46. powertrain_build/lib/helper_functions.py +127 -127
  47. powertrain_build/lib/logger.py +55 -55
  48. powertrain_build/matlab_scripts/CodeGen/BuildAutomationPyBuild.m +78 -78
  49. powertrain_build/matlab_scripts/CodeGen/Generate_A2L.m +154 -154
  50. powertrain_build/matlab_scripts/CodeGen/generateTLUnit.m +239 -239
  51. powertrain_build/matlab_scripts/CodeGen/getAsilClassification.m +28 -28
  52. powertrain_build/matlab_scripts/CodeGen/modelConfiguredForTL.m +28 -28
  53. powertrain_build/matlab_scripts/CodeGen/moveDefOutports.m +88 -88
  54. powertrain_build/matlab_scripts/CodeGen/parseCalMeasData.m +410 -410
  55. powertrain_build/matlab_scripts/CodeGen/parseCoreIdentifiers.m +139 -139
  56. powertrain_build/matlab_scripts/CodeGen/parseDIDs.m +141 -141
  57. powertrain_build/matlab_scripts/CodeGen/parseInPorts.m +106 -106
  58. powertrain_build/matlab_scripts/CodeGen/parseIncludeConfigs.m +25 -25
  59. powertrain_build/matlab_scripts/CodeGen/parseModelInfo.m +38 -38
  60. powertrain_build/matlab_scripts/CodeGen/parseNVM.m +81 -81
  61. powertrain_build/matlab_scripts/CodeGen/parseOutPorts.m +120 -120
  62. powertrain_build/matlab_scripts/CodeGen/parsePreProcBlks.m +23 -23
  63. powertrain_build/matlab_scripts/CodeGen/struct2JSON.m +128 -128
  64. powertrain_build/matlab_scripts/CodeGen/updateCodeSwConfig.m +31 -31
  65. powertrain_build/matlab_scripts/Init_PyBuild.m +91 -91
  66. powertrain_build/matlab_scripts/__init__.py +2 -2
  67. powertrain_build/matlab_scripts/helperFunctions/Get_Full_Name.m +46 -46
  68. powertrain_build/matlab_scripts/helperFunctions/Get_SrcLines.m +12 -12
  69. powertrain_build/matlab_scripts/helperFunctions/Init_Models.m +78 -78
  70. powertrain_build/matlab_scripts/helperFunctions/Init_Projects.m +67 -67
  71. powertrain_build/matlab_scripts/helperFunctions/Read_Units.m +34 -34
  72. powertrain_build/matlab_scripts/helperFunctions/SetProjectTimeSamples.m +26 -26
  73. powertrain_build/matlab_scripts/helperFunctions/Strip_Suffix.m +16 -16
  74. powertrain_build/matlab_scripts/helperFunctions/followLink.m +118 -118
  75. powertrain_build/matlab_scripts/helperFunctions/getCodeSwitches.m +50 -50
  76. powertrain_build/matlab_scripts/helperFunctions/getConsumerBlocks.m +30 -30
  77. powertrain_build/matlab_scripts/helperFunctions/getDefBlock.m +39 -39
  78. powertrain_build/matlab_scripts/helperFunctions/getDefOutport.m +58 -58
  79. powertrain_build/matlab_scripts/helperFunctions/getDstBlocks.m +19 -19
  80. powertrain_build/matlab_scripts/helperFunctions/getDstLines.m +13 -13
  81. powertrain_build/matlab_scripts/helperFunctions/getInterfaceSignals.m +37 -37
  82. powertrain_build/matlab_scripts/helperFunctions/getName.m +37 -37
  83. powertrain_build/matlab_scripts/helperFunctions/getPath.m +6 -6
  84. powertrain_build/matlab_scripts/helperFunctions/getProperValue.m +21 -21
  85. powertrain_build/matlab_scripts/helperFunctions/getSrcBlocks.m +19 -19
  86. powertrain_build/matlab_scripts/helperFunctions/getSrcLines.m +13 -13
  87. powertrain_build/matlab_scripts/helperFunctions/loadLibraries.m +10 -10
  88. powertrain_build/matlab_scripts/helperFunctions/loadjson.m +6 -6
  89. powertrain_build/matlab_scripts/helperFunctions/modifyEnumStructField.m +21 -21
  90. powertrain_build/matlab_scripts/helperFunctions/removeConfigDuplicates.m +31 -31
  91. powertrain_build/matlab_scripts/helperFunctions/sortSystemByClass.m +26 -26
  92. powertrain_build/matlab_scripts/helperFunctions/tl_getfast.m +89 -89
  93. powertrain_build/matlab_scripts/helperFunctions/topLevelSystem.m +20 -20
  94. powertrain_build/matlab_scripts/helperFunctions/updateModels.m +131 -131
  95. powertrain_build/memory_section.py +224 -224
  96. powertrain_build/nvm_def.py +729 -729
  97. powertrain_build/problem_logger.py +86 -86
  98. powertrain_build/pt_matlab.py +430 -430
  99. powertrain_build/pt_win32.py +144 -144
  100. powertrain_build/replace_compu_tab_ref.py +105 -105
  101. powertrain_build/rte_dummy.py +254 -254
  102. powertrain_build/sched_funcs.py +209 -207
  103. powertrain_build/signal.py +7 -7
  104. powertrain_build/signal_if_html_rep.py +221 -221
  105. powertrain_build/signal_if_html_rep_all.py +302 -302
  106. powertrain_build/signal_incons_html_rep.py +180 -180
  107. powertrain_build/signal_incons_html_rep_all.py +366 -366
  108. powertrain_build/signal_incons_html_rep_base.py +168 -168
  109. powertrain_build/signal_inconsistency_check.py +641 -641
  110. powertrain_build/signal_interfaces.py +864 -864
  111. powertrain_build/templates/Index_SigCheck_All.html +22 -22
  112. powertrain_build/templates/Index_SigIf_All.html +19 -19
  113. powertrain_build/types.py +218 -218
  114. powertrain_build/unit_configs.py +419 -419
  115. powertrain_build/user_defined_types.py +660 -660
  116. powertrain_build/versioncheck.py +66 -66
  117. powertrain_build/wrapper.py +512 -512
  118. powertrain_build/xlrd_csv.py +87 -87
  119. powertrain_build/zone_controller/__init__.py +4 -4
  120. powertrain_build/zone_controller/calibration.py +176 -176
  121. powertrain_build/zone_controller/composition_yaml.py +880 -878
  122. {powertrain_build-1.13.1.dist-info → powertrain_build-1.13.3.dev3.dist-info}/METADATA +100 -100
  123. powertrain_build-1.13.3.dev3.dist-info/RECORD +130 -0
  124. {powertrain_build-1.13.1.dist-info → powertrain_build-1.13.3.dev3.dist-info}/WHEEL +1 -1
  125. {powertrain_build-1.13.1.dist-info → powertrain_build-1.13.3.dev3.dist-info}/licenses/LICENSE +202 -202
  126. powertrain_build-1.13.3.dev3.dist-info/pbr.json +1 -0
  127. powertrain_build-1.13.1.dist-info/RECORD +0 -130
  128. powertrain_build-1.13.1.dist-info/pbr.json +0 -1
  129. {powertrain_build-1.13.1.dist-info → powertrain_build-1.13.3.dev3.dist-info}/entry_points.txt +0 -0
  130. {powertrain_build-1.13.1.dist-info → powertrain_build-1.13.3.dev3.dist-info}/licenses/AUTHORS +0 -0
  131. {powertrain_build-1.13.1.dist-info → powertrain_build-1.13.3.dev3.dist-info}/licenses/NOTICE +0 -0
  132. {powertrain_build-1.13.1.dist-info → powertrain_build-1.13.3.dev3.dist-info}/top_level.txt +0 -0
@@ -1,87 +1,87 @@
1
- # Copyright 2024 Volvo Car Corporation
2
- # Licensed under Apache 2.0.
3
-
4
- """Module for providing an xlrd interface for csv files.
5
-
6
- TODO: Handle sheet names in a better way!
7
- """
8
-
9
- import csv
10
- import os
11
- import re
12
-
13
-
14
- class WorkBook:
15
- """Emulate xlrd of csv files."""
16
-
17
- def __init__(self, csv_files):
18
- """Init."""
19
- self._worksheets = {}
20
- self._read_csv_files_to_worksheets(csv_files)
21
-
22
- def _read_csv_files_to_worksheets(self, csv_files):
23
- """Read CSV-files, and store them as worksheets."""
24
- csv_files = [csv_files] if isinstance(csv_files, str) else csv_files
25
- if len(csv_files) > 1:
26
- for file_ in csv_files:
27
- sheet_name = re.match(r'.*?\w*_([\w\$]+)\.\w+', file_).group(1)
28
- self._worksheets[sheet_name] = WorkSheet(sheet_name, file_)
29
- else:
30
- _, sheet_name = os.path.split(csv_files[0])
31
- self._worksheets[sheet_name] = WorkSheet(sheet_name, csv_files[0])
32
-
33
- def sheet_by_name(self, name):
34
- """Get a worksheet name from a workbook class."""
35
- return self._worksheets[name]
36
-
37
- def single_sheet(self):
38
- """Get single worksheet if only one file was read."""
39
- return next(iter(self._worksheets.values())) if len(self._worksheets) == 1 else None
40
-
41
-
42
- class WorkSheet:
43
- """Emulate xlrd for csv files."""
44
-
45
- def __init__(self, sheet_name, file_name):
46
- """Init."""
47
- self._sheet_name = sheet_name
48
- self._read_work_sheet(file_name)
49
-
50
- def _read_work_sheet(self, file_name):
51
- """Read csv-file as a worksheet."""
52
- with open(file_name, 'r', encoding="ISO-8859-1") as csvfile:
53
- reader = csv.reader(csvfile, delimiter=';')
54
- self._rows = [[Data(elem) for elem in row] for row in reader]
55
- self._nrows = len(self._rows)
56
-
57
- @property
58
- def nrows(self):
59
- """Get number of rows in a worksheet."""
60
- return self._nrows
61
-
62
- def row(self, row):
63
- """Get row from sheet."""
64
- return self._rows[row]
65
-
66
-
67
- class Data:
68
- """Class for wrapping data in a worksheet."""
69
-
70
- def __init__(self, value):
71
- """Init."""
72
- # TODO: Investigate quoting string values when exporting to CSV
73
- if re.fullmatch('[+-]?[0-9]+', value):
74
- self._value = int(value)
75
- elif re.fullmatch('[+-]?[0-9.]+', value):
76
- self._value = float(value)
77
- else:
78
- self._value = value
79
-
80
- def __repr__(self):
81
- """Get representation of object."""
82
- return self._value
83
-
84
- @property
85
- def value(self):
86
- """Provide the value of the data object."""
87
- return self._value
1
+ # Copyright 2024 Volvo Car Corporation
2
+ # Licensed under Apache 2.0.
3
+
4
+ """Module for providing an xlrd interface for csv files.
5
+
6
+ TODO: Handle sheet names in a better way!
7
+ """
8
+
9
+ import csv
10
+ import os
11
+ import re
12
+
13
+
14
+ class WorkBook:
15
+ """Emulate xlrd of csv files."""
16
+
17
+ def __init__(self, csv_files):
18
+ """Init."""
19
+ self._worksheets = {}
20
+ self._read_csv_files_to_worksheets(csv_files)
21
+
22
+ def _read_csv_files_to_worksheets(self, csv_files):
23
+ """Read CSV-files, and store them as worksheets."""
24
+ csv_files = [csv_files] if isinstance(csv_files, str) else csv_files
25
+ if len(csv_files) > 1:
26
+ for file_ in csv_files:
27
+ sheet_name = re.match(r'.*?\w*_([\w\$]+)\.\w+', file_).group(1)
28
+ self._worksheets[sheet_name] = WorkSheet(sheet_name, file_)
29
+ else:
30
+ _, sheet_name = os.path.split(csv_files[0])
31
+ self._worksheets[sheet_name] = WorkSheet(sheet_name, csv_files[0])
32
+
33
+ def sheet_by_name(self, name):
34
+ """Get a worksheet name from a workbook class."""
35
+ return self._worksheets[name]
36
+
37
+ def single_sheet(self):
38
+ """Get single worksheet if only one file was read."""
39
+ return next(iter(self._worksheets.values())) if len(self._worksheets) == 1 else None
40
+
41
+
42
+ class WorkSheet:
43
+ """Emulate xlrd for csv files."""
44
+
45
+ def __init__(self, sheet_name, file_name):
46
+ """Init."""
47
+ self._sheet_name = sheet_name
48
+ self._read_work_sheet(file_name)
49
+
50
+ def _read_work_sheet(self, file_name):
51
+ """Read csv-file as a worksheet."""
52
+ with open(file_name, 'r', encoding="ISO-8859-1") as csvfile:
53
+ reader = csv.reader(csvfile, delimiter=';')
54
+ self._rows = [[Data(elem) for elem in row] for row in reader]
55
+ self._nrows = len(self._rows)
56
+
57
+ @property
58
+ def nrows(self):
59
+ """Get number of rows in a worksheet."""
60
+ return self._nrows
61
+
62
+ def row(self, row):
63
+ """Get row from sheet."""
64
+ return self._rows[row]
65
+
66
+
67
+ class Data:
68
+ """Class for wrapping data in a worksheet."""
69
+
70
+ def __init__(self, value):
71
+ """Init."""
72
+ # TODO: Investigate quoting string values when exporting to CSV
73
+ if re.fullmatch('[+-]?[0-9]+', value):
74
+ self._value = int(value)
75
+ elif re.fullmatch('[+-]?[0-9.]+', value):
76
+ self._value = float(value)
77
+ else:
78
+ self._value = value
79
+
80
+ def __repr__(self):
81
+ """Get representation of object."""
82
+ return self._value
83
+
84
+ @property
85
+ def value(self):
86
+ """Provide the value of the data object."""
87
+ return self._value
@@ -1,4 +1,4 @@
1
- # Copyright 2024 Volvo Car Corporation
2
- # Licensed under Apache 2.0.
3
-
4
- """powertrain_build.zone_controller."""
1
+ # Copyright 2024 Volvo Car Corporation
2
+ # Licensed under Apache 2.0.
3
+
4
+ """powertrain_build.zone_controller."""
@@ -1,176 +1,176 @@
1
- # Copyright 2024 Volvo Car Corporation
2
- # Licensed under Apache 2.0.
3
-
4
- """Module for handling ZoneController calibration."""
5
-
6
- import re
7
- from pathlib import Path
8
- from powertrain_build.problem_logger import ProblemLogger
9
-
10
-
11
- class ZoneControllerCalibration(ProblemLogger):
12
- """Class for handling ZoneController calibration."""
13
-
14
- calibration_function_init_template = '{swc_name}_ZcCalibrationInit'
15
- calibration_function_step_template = '{swc_name}_ZcCalibrationStep'
16
- trigger_read_rte_cdata_signal = {
17
- 'name_template': 'c{swc_name}_TriggerReadRteCData',
18
- 'data_type': 'Float32'
19
- }
20
-
21
- def __init__(self, build_cfg, calib_data):
22
- """Init.
23
-
24
- Args:
25
- build_cfg (BuildProjConfig): Object with build configuration settings.
26
- calib_data (dict): Dictionary containing calibration data for a ZoneController project.
27
- """
28
- self.swc_name = build_cfg.get_composition_config("softwareComponentName")
29
- self.asil_level = re.sub("ASIL(?=[^_])", "ASIL_", build_cfg.get_composition_config("asil"))
30
- self.src_code_dst_dir = build_cfg.get_src_code_dst_dir()
31
- self.calibration_variables = calib_data['class_info']
32
- cal_interface_filename = f"calibration_interface_{build_cfg.get_scheduler_prefix()}".rstrip("_")
33
- self.calibration_interface_header = f'{cal_interface_filename}.h'
34
- self.calibration_interface_source = f'{cal_interface_filename}.c'
35
- self.trigger_read_rte_cdata_signal_name = self.trigger_read_rte_cdata_signal['name_template'].format(
36
- swc_name=self.swc_name
37
- )
38
-
39
- def _get_header_guard(self):
40
- header_guard_tmp = Path(self.calibration_interface_header).stem
41
- return header_guard_tmp.upper() + '_H'
42
-
43
- def _get_calibration_variables_write_string_list(self, indent=4):
44
- write_string_list = []
45
- for signal_name, signal_data in self.calibration_variables.items():
46
- rte_call = f'Rte_CData_{self.swc_name}_{signal_name}()'
47
- if isinstance(signal_data["width"], list):
48
- write_string_list.append(f'{"":{indent}}memcpy({signal_name}, {rte_call}, sizeof({signal_name}));\n')
49
- else:
50
- write_string_list.append(f'{"":{indent}}{signal_name} = {rte_call};\n')
51
- return write_string_list
52
-
53
- def _get_source_file_init_content(self):
54
- start_include = "CVC_CODE_START.h" if self.asil_level == "QM" else f"CVC_CODE_{self.asil_level}_START.h"
55
- stop_include = "CVC_CODE_END.h" if self.asil_level == "QM" else f"CVC_CODE_{self.asil_level}_END.h"
56
- header = [f'#include "{start_include}"\n']
57
- footer = [f'#include "{stop_include}"\n', '\n']
58
-
59
- body = [
60
- f'void {self.calibration_function_init_template.format(swc_name=self.swc_name)}(void)\n',
61
- '{\n',
62
- ]
63
- body.extend(self._get_calibration_variables_write_string_list())
64
- body.append('}\n')
65
-
66
- return header + body + footer
67
-
68
- def _get_source_file_step_content(self):
69
- start_include = "CVC_CODE_START.h" if self.asil_level == "QM" else f"CVC_CODE_{self.asil_level}_START.h"
70
- stop_include = "CVC_CODE_END.h" if self.asil_level == "QM" else f"CVC_CODE_{self.asil_level}_END.h"
71
- header = [f'#include "{start_include}"\n']
72
- footer = [f'#include "{stop_include}"\n']
73
-
74
- trigger_read_calibration_function = f'Rte_CData_{self.swc_name}_{self.trigger_read_rte_cdata_signal_name}()'
75
- body = [
76
- f'void {self.calibration_function_step_template.format(swc_name=self.swc_name)}(void)\n',
77
- '{\n',
78
- f' if ({self.trigger_read_rte_cdata_signal_name} != {trigger_read_calibration_function})\n'
79
- ]
80
- body.append(' {\n')
81
- body.extend(self._get_calibration_variables_write_string_list(indent=8))
82
- body.append(' }\n')
83
- body.append('}\n')
84
-
85
- return header + body + footer
86
-
87
- def get_header_file_content(self):
88
- """Get content for the calibration header file.
89
-
90
- Returns:
91
- (list(str)): List of lines to write to calibration header file.
92
- """
93
- lines_to_write = []
94
- start_include = "CVC_CAL_START.h" if self.asil_level == "QM" else f"CVC_CAL_{self.asil_level}_START.h"
95
- stop_include = "CVC_CAL_END.h" if self.asil_level == "QM" else f"CVC_CAL_{self.asil_level}_END.h"
96
- header = [
97
- f'#ifndef {self._get_header_guard()}\n',
98
- f'#define {self._get_header_guard()}\n',
99
- '#define CVC_CAL\n',
100
- '#include <string.h>\n',
101
- '#include "tl_basetypes.h"\n',
102
- f'#include "Rte_{self.swc_name}.h"\n',
103
- '\n'
104
- ]
105
- footer = [
106
- '\n',
107
- f'#endif /* {self._get_header_guard()} */\n'
108
- ]
109
-
110
- lines_to_write.append(f'#include "{start_include}"\n')
111
- for signal_name, signal_data in self.calibration_variables.items():
112
- if isinstance(signal_data["width"], list):
113
- rows, cols = signal_data["width"]
114
- if rows > 1:
115
- declaration = f'extern CVC_CAL {signal_data["type"]} {signal_name}[{rows}][{cols}];\n'
116
- else:
117
- declaration = f'extern CVC_CAL {signal_data["type"]} {signal_name}[{cols}];\n'
118
- else:
119
- declaration = f'extern CVC_CAL {signal_data["type"]} {signal_name};\n'
120
- lines_to_write.append(declaration)
121
- lines_to_write.append(f'#include "{stop_include}"\n')
122
-
123
- lines_to_write.append('\n')
124
- for signal_name, signal_data in self.calibration_variables.items():
125
- if isinstance(signal_data["width"], list):
126
- # MAPs get typedef:ed to structs and need special data type mapping in calibration.py
127
- if signal_name.startswith("m") and signal_name[-2:] not in ["_r", "_c"]:
128
- return_type = f'const {signal_data["autosar_type"]}*'
129
- else:
130
- return_type = f'const {signal_data["type"]}*'
131
- else:
132
- return_type = f'{signal_data["type"]}'
133
- lines_to_write.append(f'extern {return_type} Rte_CData_{self.swc_name}_{signal_name}(void);\n')
134
-
135
- lines_to_write.extend([
136
- '\n',
137
- f'void {self.calibration_function_init_template.format(swc_name=self.swc_name)}(void);\n',
138
- f'void {self.calibration_function_step_template.format(swc_name=self.swc_name)}(void);\n'
139
- ])
140
-
141
- return header + lines_to_write + footer
142
-
143
- def get_source_file_content(self):
144
- """Get content for the calibration source file.
145
-
146
- Returns:
147
- (list(str)): List of lines to write to calibration source file.
148
- """
149
- start_include = "CVC_CAL_START.h" if self.asil_level == "QM" else f"CVC_CAL_{self.asil_level}_START.h"
150
- stop_include = "CVC_CAL_END.h" if self.asil_level == "QM" else f"CVC_CAL_{self.asil_level}_END.h"
151
- header = [
152
- f'#include "{self.calibration_interface_header}"\n',
153
- '\n',
154
- f'#include "{start_include}"\n',
155
- f'CVC_CAL {self.trigger_read_rte_cdata_signal["data_type"]} '
156
- f'{self.trigger_read_rte_cdata_signal_name} = 0;\n',
157
- f'#include "{stop_include}"\n',
158
- '\n',
159
- ]
160
-
161
- body = self._get_source_file_init_content()
162
- body.extend(self._get_source_file_step_content())
163
-
164
- return header + body
165
-
166
- def generate_calibration_interface_files(self):
167
- """Generate calibration interface files."""
168
- header_file_content = self.get_header_file_content()
169
- calibration_interface_header_path = Path(self.src_code_dst_dir, self.calibration_interface_header)
170
- with calibration_interface_header_path.open(mode='w', encoding='utf-8') as file_handler:
171
- file_handler.writelines(header_file_content)
172
-
173
- source_file_content = self.get_source_file_content()
174
- calibration_interface_source_path = Path(self.src_code_dst_dir, self.calibration_interface_source)
175
- with calibration_interface_source_path.open(mode='w', encoding='utf-8') as file_handler:
176
- file_handler.writelines(source_file_content)
1
+ # Copyright 2024 Volvo Car Corporation
2
+ # Licensed under Apache 2.0.
3
+
4
+ """Module for handling ZoneController calibration."""
5
+
6
+ import re
7
+ from pathlib import Path
8
+ from powertrain_build.problem_logger import ProblemLogger
9
+
10
+
11
+ class ZoneControllerCalibration(ProblemLogger):
12
+ """Class for handling ZoneController calibration."""
13
+
14
+ calibration_function_init_template = '{swc_name}_ZcCalibrationInit'
15
+ calibration_function_step_template = '{swc_name}_ZcCalibrationStep'
16
+ trigger_read_rte_cdata_signal = {
17
+ 'name_template': 'c{swc_name}_TriggerReadRteCData',
18
+ 'data_type': 'Float32'
19
+ }
20
+
21
+ def __init__(self, build_cfg, calib_data):
22
+ """Init.
23
+
24
+ Args:
25
+ build_cfg (BuildProjConfig): Object with build configuration settings.
26
+ calib_data (dict): Dictionary containing calibration data for a ZoneController project.
27
+ """
28
+ self.swc_name = build_cfg.get_composition_config("softwareComponentName")
29
+ self.asil_level = re.sub("ASIL(?=[^_])", "ASIL_", build_cfg.get_composition_config("asil"))
30
+ self.src_code_dst_dir = build_cfg.get_src_code_dst_dir()
31
+ self.calibration_variables = calib_data['class_info']
32
+ cal_interface_filename = f"calibration_interface_{build_cfg.get_scheduler_prefix()}".rstrip("_")
33
+ self.calibration_interface_header = f'{cal_interface_filename}.h'
34
+ self.calibration_interface_source = f'{cal_interface_filename}.c'
35
+ self.trigger_read_rte_cdata_signal_name = self.trigger_read_rte_cdata_signal['name_template'].format(
36
+ swc_name=self.swc_name
37
+ )
38
+
39
+ def _get_header_guard(self):
40
+ header_guard_tmp = Path(self.calibration_interface_header).stem
41
+ return header_guard_tmp.upper() + '_H'
42
+
43
+ def _get_calibration_variables_write_string_list(self, indent=4):
44
+ write_string_list = []
45
+ for signal_name, signal_data in self.calibration_variables.items():
46
+ rte_call = f'Rte_CData_{self.swc_name}_{signal_name}()'
47
+ if isinstance(signal_data["width"], list):
48
+ write_string_list.append(f'{"":{indent}}memcpy({signal_name}, {rte_call}, sizeof({signal_name}));\n')
49
+ else:
50
+ write_string_list.append(f'{"":{indent}}{signal_name} = {rte_call};\n')
51
+ return write_string_list
52
+
53
+ def _get_source_file_init_content(self):
54
+ start_include = "CVC_CODE_START.h" if self.asil_level == "QM" else f"CVC_CODE_{self.asil_level}_START.h"
55
+ stop_include = "CVC_CODE_END.h" if self.asil_level == "QM" else f"CVC_CODE_{self.asil_level}_END.h"
56
+ header = [f'#include "{start_include}"\n']
57
+ footer = [f'#include "{stop_include}"\n', '\n']
58
+
59
+ body = [
60
+ f'void {self.calibration_function_init_template.format(swc_name=self.swc_name)}(void)\n',
61
+ '{\n',
62
+ ]
63
+ body.extend(self._get_calibration_variables_write_string_list())
64
+ body.append('}\n')
65
+
66
+ return header + body + footer
67
+
68
+ def _get_source_file_step_content(self):
69
+ start_include = "CVC_CODE_START.h" if self.asil_level == "QM" else f"CVC_CODE_{self.asil_level}_START.h"
70
+ stop_include = "CVC_CODE_END.h" if self.asil_level == "QM" else f"CVC_CODE_{self.asil_level}_END.h"
71
+ header = [f'#include "{start_include}"\n']
72
+ footer = [f'#include "{stop_include}"\n']
73
+
74
+ trigger_read_calibration_function = f'Rte_CData_{self.swc_name}_{self.trigger_read_rte_cdata_signal_name}()'
75
+ body = [
76
+ f'void {self.calibration_function_step_template.format(swc_name=self.swc_name)}(void)\n',
77
+ '{\n',
78
+ f' if ({self.trigger_read_rte_cdata_signal_name} != {trigger_read_calibration_function})\n'
79
+ ]
80
+ body.append(' {\n')
81
+ body.extend(self._get_calibration_variables_write_string_list(indent=8))
82
+ body.append(' }\n')
83
+ body.append('}\n')
84
+
85
+ return header + body + footer
86
+
87
+ def get_header_file_content(self):
88
+ """Get content for the calibration header file.
89
+
90
+ Returns:
91
+ (list(str)): List of lines to write to calibration header file.
92
+ """
93
+ lines_to_write = []
94
+ start_include = "PREDECL_CAL_START.h" if self.asil_level == "QM" else f"PREDECL_CAL_{self.asil_level}_START.h"
95
+ stop_include = "PREDECL_CAL_END.h" if self.asil_level == "QM" else f"PREDECL_CAL_{self.asil_level}_END.h"
96
+ header = [
97
+ f'#ifndef {self._get_header_guard()}\n',
98
+ f'#define {self._get_header_guard()}\n',
99
+ '#define CVC_CAL\n',
100
+ '#include <string.h>\n',
101
+ '#include "tl_basetypes.h"\n',
102
+ f'#include "Rte_{self.swc_name}.h"\n',
103
+ '\n'
104
+ ]
105
+ footer = [
106
+ '\n',
107
+ f'#endif /* {self._get_header_guard()} */\n'
108
+ ]
109
+
110
+ lines_to_write.append(f'#include "{start_include}"\n')
111
+ for signal_name, signal_data in self.calibration_variables.items():
112
+ if isinstance(signal_data["width"], list):
113
+ rows, cols = signal_data["width"]
114
+ if rows > 1:
115
+ declaration = f'extern CVC_CAL {signal_data["type"]} {signal_name}[{rows}][{cols}];\n'
116
+ else:
117
+ declaration = f'extern CVC_CAL {signal_data["type"]} {signal_name}[{cols}];\n'
118
+ else:
119
+ declaration = f'extern CVC_CAL {signal_data["type"]} {signal_name};\n'
120
+ lines_to_write.append(declaration)
121
+ lines_to_write.append(f'#include "{stop_include}"\n')
122
+
123
+ lines_to_write.append('\n')
124
+ for signal_name, signal_data in self.calibration_variables.items():
125
+ if isinstance(signal_data["width"], list):
126
+ # MAPs get typedef:ed to structs and need special data type mapping in calibration.py
127
+ if signal_name.startswith("m") and signal_name[-2:] not in ["_r", "_c"]:
128
+ return_type = f'const {signal_data["autosar_type"]}*'
129
+ else:
130
+ return_type = f'const {signal_data["type"]}*'
131
+ else:
132
+ return_type = f'{signal_data["type"]}'
133
+ lines_to_write.append(f'extern {return_type} Rte_CData_{self.swc_name}_{signal_name}(void);\n')
134
+
135
+ lines_to_write.extend([
136
+ '\n',
137
+ f'void {self.calibration_function_init_template.format(swc_name=self.swc_name)}(void);\n',
138
+ f'void {self.calibration_function_step_template.format(swc_name=self.swc_name)}(void);\n'
139
+ ])
140
+
141
+ return header + lines_to_write + footer
142
+
143
+ def get_source_file_content(self):
144
+ """Get content for the calibration source file.
145
+
146
+ Returns:
147
+ (list(str)): List of lines to write to calibration source file.
148
+ """
149
+ start_include = "CVC_CAL_START.h" if self.asil_level == "QM" else f"CVC_CAL_{self.asil_level}_START.h"
150
+ stop_include = "CVC_CAL_END.h" if self.asil_level == "QM" else f"CVC_CAL_{self.asil_level}_END.h"
151
+ header = [
152
+ f'#include "{self.calibration_interface_header}"\n',
153
+ '\n',
154
+ f'#include "{start_include}"\n',
155
+ f'CVC_CAL {self.trigger_read_rte_cdata_signal["data_type"]} '
156
+ f'{self.trigger_read_rte_cdata_signal_name} = 0;\n',
157
+ f'#include "{stop_include}"\n',
158
+ '\n',
159
+ ]
160
+
161
+ body = self._get_source_file_init_content()
162
+ body.extend(self._get_source_file_step_content())
163
+
164
+ return header + body
165
+
166
+ def generate_calibration_interface_files(self):
167
+ """Generate calibration interface files."""
168
+ header_file_content = self.get_header_file_content()
169
+ calibration_interface_header_path = Path(self.src_code_dst_dir, self.calibration_interface_header)
170
+ with calibration_interface_header_path.open(mode='w', encoding='utf-8') as file_handler:
171
+ file_handler.writelines(header_file_content)
172
+
173
+ source_file_content = self.get_source_file_content()
174
+ calibration_interface_source_path = Path(self.src_code_dst_dir, self.calibration_interface_source)
175
+ with calibration_interface_source_path.open(mode='w', encoding='utf-8') as file_handler:
176
+ file_handler.writelines(source_file_content)