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,142 +1,142 @@
1
- # Copyright 2024 Volvo Car Corporation
2
- # Licensed under Apache 2.0.
3
-
4
- """Module with generation utils."""
5
-
6
- import argparse
7
- from ruamel.yaml import YAML
8
- from pathlib import Path
9
- from powertrain_build.interface.application import Application, get_internal_domain
10
- from powertrain_build.interface.base import filter_signals
11
- from powertrain_build.lib import logger
12
-
13
- LOGGER = logger.create_logger("CSP interface generation utils")
14
-
15
-
16
- def add_base_args(parser: argparse.ArgumentParser):
17
- """ Base parser that adds config argument.
18
-
19
- Returns:
20
- parser (ArgumentParser): Base parser
21
- """
22
- parser.add_argument("config", help="The project configuration file", type=Path)
23
-
24
-
25
- def get_client_name(args, app):
26
- """ Get client name for app.
27
-
28
- Args:
29
- app (Application): Parsed project configuration
30
- Returns:
31
- name (str): Name of the project
32
- """
33
- return args.client_name if args.client_name else app.name
34
-
35
-
36
- def process_app(config):
37
- """ Get an app specification for the current project
38
-
39
- Entrypoint for external scripts.
40
-
41
- Args:
42
- config (pathlib.Path): Path to the ProjectCfg.json
43
- Returns:
44
- app (Application): powertrain-build project
45
- """
46
- app = Application()
47
- app.parse_definition(config)
48
- return app
49
-
50
-
51
- def get_interface(app, interface_type):
52
- """Get interface(hal/dp/zc/service) to application
53
-
54
- Args:
55
- app (Application): Pybuild project
56
- interface_type (BaseApplication): A type of interface
57
- Returns:
58
- spec (obj): obj for hal/dp/zc/service class
59
- """
60
- spec = {}
61
- rasters = app.get_rasters()
62
- LOGGER.debug("Rasters: %s", rasters)
63
- translation_files = app.get_translation_files()
64
- interface_type.parse_definition(translation_files)
65
- internal = get_internal_domain(rasters)
66
- properties_from_json = [
67
- {"destination": "min", "source": "min", "default": "-"},
68
- {"destination": "max", "source": "max", "default": "-"},
69
- {"destination": "variable_type", "source": "type"},
70
- {"destination": "offset", "source": "offset", "default": "-"},
71
- {"destination": "factor", "source": "lsb", "default": 1},
72
- {"destination": "description", "source": "description"},
73
- {"destination": "unit", "source": "unit", "default": "-"},
74
- ]
75
- # TODO We read all yaml files at once, should we "add_signals" for all rasters at once?
76
- # For example, service.check_endpoints will miss endpoint mismatches that reside in different rasters.
77
- for raster in rasters:
78
- interface_type.name = raster.name
79
- interface_type.clear_signal_names()
80
- interface_type.add_signals(
81
- filter_signals(raster.insignals, internal), "insignals", properties_from_json)
82
- interface_type.add_signals(raster.outsignals, "outsignals", properties_from_json)
83
- LOGGER.debug("Current communication interface: %s", interface_type)
84
- spec[raster.name] = interface_type.to_dict()
85
- return spec
86
-
87
-
88
- def get_method_interface(app):
89
- """ Get method interface
90
- Args:
91
- app (Application): Application
92
- Returns:
93
- spec (dict): Specification for csp methods
94
- """
95
- spec = {}
96
-
97
- for method in app.get_methods():
98
- method_spec = {}
99
- method_spec['name'] = method.name
100
- method_spec['primitive'] = method.get_primitive(method.name)
101
- method_spec['namespace'] = method.namespace
102
- if method.description:
103
- method_spec['description'] = method.description
104
- inports = {}
105
- outports = {}
106
- for signal in method.signals:
107
- signal_spec = {
108
- 'primitive': method.get_primitive(signal.name),
109
- 'type': signal.properties['type'],
110
- 'variable_type': signal.properties['type'],
111
- 'variable': signal.name,
112
- 'range': signal.properties['range'],
113
- 'init': 0,
114
- 'description': '',
115
- 'unit': ''
116
- }
117
- if signal in method.outsignals:
118
- outports[signal.name] = signal_spec
119
- else:
120
- inports[signal.name] = signal_spec
121
-
122
- ports = {'in': inports, 'out': outports}
123
- method_spec['ports'] = ports
124
- spec[method.name] = method_spec
125
- return spec
126
-
127
-
128
- def write_to_file(content, output, is_yaml=False):
129
- """ Write to cmake.
130
-
131
- Args:
132
- content (str): cmake
133
- output (Path): File to write.
134
- yaml (bool): Dump yaml
135
- """
136
- output.parent.mkdir(parents=True, exist_ok=True)
137
- with open(output, "w", encoding="utf-8") as file_handler:
138
- if is_yaml:
139
- yaml = YAML()
140
- yaml.dump(content, file_handler)
141
- else:
142
- file_handler.write(content)
1
+ # Copyright 2024 Volvo Car Corporation
2
+ # Licensed under Apache 2.0.
3
+
4
+ """Module with generation utils."""
5
+
6
+ import argparse
7
+ from ruamel.yaml import YAML
8
+ from pathlib import Path
9
+ from powertrain_build.interface.application import Application, get_internal_domain
10
+ from powertrain_build.interface.base import filter_signals
11
+ from powertrain_build.lib import logger
12
+
13
+ LOGGER = logger.create_logger("CSP interface generation utils")
14
+
15
+
16
+ def add_base_args(parser: argparse.ArgumentParser):
17
+ """ Base parser that adds config argument.
18
+
19
+ Returns:
20
+ parser (ArgumentParser): Base parser
21
+ """
22
+ parser.add_argument("config", help="The project configuration file", type=Path)
23
+
24
+
25
+ def get_client_name(args, app):
26
+ """ Get client name for app.
27
+
28
+ Args:
29
+ app (Application): Parsed project configuration
30
+ Returns:
31
+ name (str): Name of the project
32
+ """
33
+ return args.client_name if args.client_name else app.name
34
+
35
+
36
+ def process_app(config):
37
+ """ Get an app specification for the current project
38
+
39
+ Entrypoint for external scripts.
40
+
41
+ Args:
42
+ config (pathlib.Path): Path to the ProjectCfg.json
43
+ Returns:
44
+ app (Application): powertrain-build project
45
+ """
46
+ app = Application()
47
+ app.parse_definition(config)
48
+ return app
49
+
50
+
51
+ def get_interface(app, interface_type):
52
+ """Get interface(hal/dp/zc/service) to application
53
+
54
+ Args:
55
+ app (Application): Pybuild project
56
+ interface_type (BaseApplication): A type of interface
57
+ Returns:
58
+ spec (obj): obj for hal/dp/zc/service class
59
+ """
60
+ spec = {}
61
+ rasters = app.get_rasters()
62
+ LOGGER.debug("Rasters: %s", rasters)
63
+ translation_files = app.get_translation_files()
64
+ interface_type.parse_definition(translation_files)
65
+ internal = get_internal_domain(rasters)
66
+ properties_from_json = [
67
+ {"destination": "min", "source": "min", "default": "-"},
68
+ {"destination": "max", "source": "max", "default": "-"},
69
+ {"destination": "variable_type", "source": "type"},
70
+ {"destination": "offset", "source": "offset", "default": "-"},
71
+ {"destination": "factor", "source": "lsb", "default": 1},
72
+ {"destination": "description", "source": "description"},
73
+ {"destination": "unit", "source": "unit", "default": "-"},
74
+ ]
75
+ # TODO We read all yaml files at once, should we "add_signals" for all rasters at once?
76
+ # For example, service.check_endpoints will miss endpoint mismatches that reside in different rasters.
77
+ for raster in rasters:
78
+ interface_type.name = raster.name
79
+ interface_type.clear_signal_names()
80
+ interface_type.add_signals(
81
+ filter_signals(raster.insignals, internal), "insignals", properties_from_json)
82
+ interface_type.add_signals(raster.outsignals, "outsignals", properties_from_json)
83
+ LOGGER.debug("Current communication interface: %s", interface_type)
84
+ spec[raster.name] = interface_type.to_dict()
85
+ return spec
86
+
87
+
88
+ def get_method_interface(app):
89
+ """ Get method interface
90
+ Args:
91
+ app (Application): Application
92
+ Returns:
93
+ spec (dict): Specification for csp methods
94
+ """
95
+ spec = {}
96
+
97
+ for method in app.get_methods():
98
+ method_spec = {}
99
+ method_spec['name'] = method.name
100
+ method_spec['primitive'] = method.get_primitive(method.name)
101
+ method_spec['namespace'] = method.namespace
102
+ if method.description:
103
+ method_spec['description'] = method.description
104
+ inports = {}
105
+ outports = {}
106
+ for signal in method.signals:
107
+ signal_spec = {
108
+ 'primitive': method.get_primitive(signal.name),
109
+ 'type': signal.properties['type'],
110
+ 'variable_type': signal.properties['type'],
111
+ 'variable': signal.name,
112
+ 'range': signal.properties['range'],
113
+ 'init': 0,
114
+ 'description': '',
115
+ 'unit': ''
116
+ }
117
+ if signal in method.outsignals:
118
+ outports[signal.name] = signal_spec
119
+ else:
120
+ inports[signal.name] = signal_spec
121
+
122
+ ports = {'in': inports, 'out': outports}
123
+ method_spec['ports'] = ports
124
+ spec[method.name] = method_spec
125
+ return spec
126
+
127
+
128
+ def write_to_file(content, output, is_yaml=False):
129
+ """ Write to cmake.
130
+
131
+ Args:
132
+ content (str): cmake
133
+ output (Path): File to write.
134
+ yaml (bool): Dump yaml
135
+ """
136
+ output.parent.mkdir(parents=True, exist_ok=True)
137
+ with open(output, "w", encoding="utf-8") as file_handler:
138
+ if is_yaml:
139
+ yaml = YAML()
140
+ yaml.dump(content, file_handler)
141
+ else:
142
+ file_handler.write(content)
@@ -1,194 +1,194 @@
1
- # Copyright 2024 Volvo Car Corporation
2
- # Licensed under Apache 2.0.
3
-
4
- """Python module used for abstracting Hardware Abstraction Layer specifications"""
5
- import re
6
- from pathlib import Path
7
- from ruamel.yaml import YAML
8
- from powertrain_build.interface.csp_api import CspApi
9
- from powertrain_build.lib import logger
10
-
11
- LOGGER = logger.create_logger('base')
12
-
13
-
14
- def get_hal_list(app):
15
- """Get translated hal name from yaml file
16
-
17
- Args:
18
- app (Application): Pybuild project
19
- Returns:
20
- cmake (str): a string contains translated hal name
21
- """
22
- translation_files = app.get_translation_files()
23
- hala = HALA(app)
24
- hala.parse_definition(translation_files)
25
- hal_translations = hala.get_map()
26
-
27
- hals = set()
28
- for definitions in hala.translations.values():
29
- for definition in definitions:
30
- hal_abbreviation = definition[hala.position.api.value]
31
- real_hal_name = get_real_hal_name(hal_abbreviation, hal_translations)
32
- hals.add((hal_abbreviation, real_hal_name))
33
-
34
- cmake = ""
35
- for hal_abbreviation, real_hal_name in hals:
36
- lib = re.sub('-', '_', f'hal_{hal_abbreviation}' + '_libhal_' + real_hal_name).upper()
37
- include = re.sub('-', '_', f'hal_{hal_abbreviation}' + '_include_dir').upper()
38
- cmake += f"LIST(APPEND extra_libraries ${{{lib}}})\n"
39
- cmake += f"LIST(APPEND EXTRA_INCLUDE_DIRS ${{{include}}})\n"
40
- return cmake
41
-
42
-
43
- def strip_hal_name(hal_name):
44
- """Strip hal name
45
-
46
- Args:
47
- hal_name (str): hal name
48
- Returns:
49
- (str): stripped hal name
50
- """
51
- return hal_name.replace('_hal', '')
52
-
53
-
54
- def verify_name(hal_name, api_map):
55
- """Verify hal name
56
-
57
- Args:
58
- hal_name (str): hal name
59
- api_map (dict): hal translation map
60
- """
61
- if strip_hal_name(hal_name) not in api_map:
62
- raise HalTranslationException(
63
- f"{hal_name} does not exist in the hal translation file."
64
- )
65
-
66
-
67
- def get_real_hal_name(hal_name, translation_map):
68
- """Get real hal name from translation map file.
69
-
70
- Args:
71
- hal_name (str): hal abreviation
72
-
73
- Returns:
74
- real_hal_name (str): real name of a hal
75
- """
76
- verify_name(hal_name, translation_map)
77
- return translation_map.get(strip_hal_name(hal_name))
78
-
79
-
80
- class UnknownAccessorError(Exception):
81
- """Error when setting a producer and there already exists one"""
82
- def __init__(self, hal, signal, accessor):
83
- """Set error message
84
-
85
- Args:
86
- hal (HAL): Hal where the problem is
87
- signal (Signal): Signal with the problem
88
- accessor (str): Unknown accessor type
89
- """
90
- super().__init__()
91
- self.message = f"Accessor of type {accessor} for {signal.name} in {hal.name} is not handled"
92
-
93
-
94
- class HalTranslationException(Exception):
95
- """Class for hal translation exceptions"""
96
-
97
-
98
- class HALA(CspApi):
99
- """Hardware abstraction layer abstraction"""
100
-
101
- def __repr__(self):
102
- """String representation of HALA"""
103
- return (f"<HALA {self.name}"
104
- f" app_side insignals: {len(self.signal_names['app']['insignals'])}"
105
- f" app_side outsignals: {len(self.signal_names['app']['outsignals'])}>")
106
-
107
- def get_map(self):
108
- """Get hal translation map
109
-
110
- Returns:
111
- (dict): hal translation map
112
- """
113
- path = self.get_map_file()
114
- if path.is_file():
115
- return self._get_hal_translation(path)
116
- return {}
117
-
118
- @staticmethod
119
- def get_map_file():
120
- """Get hal translation map file
121
-
122
- Returns:
123
- (Path): hal translation map file
124
- """
125
- return Path("Projects", "CSP", "hal_list.yaml")
126
-
127
- def get_api_name(self, api_name):
128
- real_hal_name = get_real_hal_name(
129
- api_name,
130
- self.api_map
131
- )
132
- return real_hal_name
133
-
134
- def verify_api(self, api_name):
135
- verify_name(api_name, self.api_map)
136
-
137
- @staticmethod
138
- def _get_hal_translation(path):
139
- """Get translated hal names
140
-
141
- Args:
142
- path (Path): path to the hal translation list.
143
- Returns:
144
- hal_translation_content (dict): translated hal names
145
- """
146
- hal_translation_content = None
147
- if path and path.is_file():
148
- with path.open("r") as file_handler:
149
- yaml = YAML(typ="safe", pure=True)
150
- hal_translation_content = yaml.load(file_handler)
151
-
152
- if not hal_translation_content:
153
- if hal_translation_content is None:
154
- raise HalTranslationException(
155
- "No hal translation file given."
156
- )
157
- if isinstance(hal_translation_content, dict):
158
- raise HalTranslationException(
159
- "Hal translation file are empty."
160
- )
161
- raise HalTranslationException("Bad hal translation format.")
162
- return hal_translation_content
163
-
164
- def check_endpoints(self):
165
- pass
166
-
167
- def extract_endpoint_definitions(self, raw):
168
- """Extract endpoint definitions from raw data
169
-
170
- Args:
171
- (dict): endpoint definitions
172
- """
173
- self.parse_api_definitions(raw.get("hal", {}))
174
-
175
- @staticmethod
176
- def extract_definition(definition):
177
- """Extract definition from hal
178
-
179
- Args:
180
- definition (dict): hal definition
181
-
182
- Returns:
183
- (dict): hal definition
184
- """
185
- if isinstance(definition, list):
186
- specifications = {
187
- 'hals': definition
188
- }
189
- else:
190
- specifications = {
191
- 'properties': definition.get('properties', []),
192
- 'methods': definition.get('methods', [])
193
- }
194
- return specifications
1
+ # Copyright 2024 Volvo Car Corporation
2
+ # Licensed under Apache 2.0.
3
+
4
+ """Python module used for abstracting Hardware Abstraction Layer specifications"""
5
+ import re
6
+ from pathlib import Path
7
+ from ruamel.yaml import YAML
8
+ from powertrain_build.interface.csp_api import CspApi
9
+ from powertrain_build.lib import logger
10
+
11
+ LOGGER = logger.create_logger('base')
12
+
13
+
14
+ def get_hal_list(app):
15
+ """Get translated hal name from yaml file
16
+
17
+ Args:
18
+ app (Application): Pybuild project
19
+ Returns:
20
+ cmake (str): a string contains translated hal name
21
+ """
22
+ translation_files = app.get_translation_files()
23
+ hala = HALA(app)
24
+ hala.parse_definition(translation_files)
25
+ hal_translations = hala.get_map()
26
+
27
+ hals = set()
28
+ for definitions in hala.translations.values():
29
+ for definition in definitions:
30
+ hal_abbreviation = definition[hala.position.api.value]
31
+ real_hal_name = get_real_hal_name(hal_abbreviation, hal_translations)
32
+ hals.add((hal_abbreviation, real_hal_name))
33
+
34
+ cmake = ""
35
+ for hal_abbreviation, real_hal_name in hals:
36
+ lib = re.sub('-', '_', f'hal_{hal_abbreviation}' + '_libhal_' + real_hal_name).upper()
37
+ include = re.sub('-', '_', f'hal_{hal_abbreviation}' + '_include_dir').upper()
38
+ cmake += f"LIST(APPEND extra_libraries ${{{lib}}})\n"
39
+ cmake += f"LIST(APPEND EXTRA_INCLUDE_DIRS ${{{include}}})\n"
40
+ return cmake
41
+
42
+
43
+ def strip_hal_name(hal_name):
44
+ """Strip hal name
45
+
46
+ Args:
47
+ hal_name (str): hal name
48
+ Returns:
49
+ (str): stripped hal name
50
+ """
51
+ return hal_name.replace('_hal', '')
52
+
53
+
54
+ def verify_name(hal_name, api_map):
55
+ """Verify hal name
56
+
57
+ Args:
58
+ hal_name (str): hal name
59
+ api_map (dict): hal translation map
60
+ """
61
+ if strip_hal_name(hal_name) not in api_map:
62
+ raise HalTranslationException(
63
+ f"{hal_name} does not exist in the hal translation file."
64
+ )
65
+
66
+
67
+ def get_real_hal_name(hal_name, translation_map):
68
+ """Get real hal name from translation map file.
69
+
70
+ Args:
71
+ hal_name (str): hal abreviation
72
+
73
+ Returns:
74
+ real_hal_name (str): real name of a hal
75
+ """
76
+ verify_name(hal_name, translation_map)
77
+ return translation_map.get(strip_hal_name(hal_name))
78
+
79
+
80
+ class UnknownAccessorError(Exception):
81
+ """Error when setting a producer and there already exists one"""
82
+ def __init__(self, hal, signal, accessor):
83
+ """Set error message
84
+
85
+ Args:
86
+ hal (HAL): Hal where the problem is
87
+ signal (Signal): Signal with the problem
88
+ accessor (str): Unknown accessor type
89
+ """
90
+ super().__init__()
91
+ self.message = f"Accessor of type {accessor} for {signal.name} in {hal.name} is not handled"
92
+
93
+
94
+ class HalTranslationException(Exception):
95
+ """Class for hal translation exceptions"""
96
+
97
+
98
+ class HALA(CspApi):
99
+ """Hardware abstraction layer abstraction"""
100
+
101
+ def __repr__(self):
102
+ """String representation of HALA"""
103
+ return (f"<HALA {self.name}"
104
+ f" app_side insignals: {len(self.signal_names['app']['insignals'])}"
105
+ f" app_side outsignals: {len(self.signal_names['app']['outsignals'])}>")
106
+
107
+ def get_map(self):
108
+ """Get hal translation map
109
+
110
+ Returns:
111
+ (dict): hal translation map
112
+ """
113
+ path = self.get_map_file()
114
+ if path.is_file():
115
+ return self._get_hal_translation(path)
116
+ return {}
117
+
118
+ @staticmethod
119
+ def get_map_file():
120
+ """Get hal translation map file
121
+
122
+ Returns:
123
+ (Path): hal translation map file
124
+ """
125
+ return Path("Projects", "CSP", "hal_list.yaml")
126
+
127
+ def get_api_name(self, api_name):
128
+ real_hal_name = get_real_hal_name(
129
+ api_name,
130
+ self.api_map
131
+ )
132
+ return real_hal_name
133
+
134
+ def verify_api(self, api_name):
135
+ verify_name(api_name, self.api_map)
136
+
137
+ @staticmethod
138
+ def _get_hal_translation(path):
139
+ """Get translated hal names
140
+
141
+ Args:
142
+ path (Path): path to the hal translation list.
143
+ Returns:
144
+ hal_translation_content (dict): translated hal names
145
+ """
146
+ hal_translation_content = None
147
+ if path and path.is_file():
148
+ with path.open("r") as file_handler:
149
+ yaml = YAML(typ="safe", pure=True)
150
+ hal_translation_content = yaml.load(file_handler)
151
+
152
+ if not hal_translation_content:
153
+ if hal_translation_content is None:
154
+ raise HalTranslationException(
155
+ "No hal translation file given."
156
+ )
157
+ if isinstance(hal_translation_content, dict):
158
+ raise HalTranslationException(
159
+ "Hal translation file are empty."
160
+ )
161
+ raise HalTranslationException("Bad hal translation format.")
162
+ return hal_translation_content
163
+
164
+ def check_endpoints(self):
165
+ pass
166
+
167
+ def extract_endpoint_definitions(self, raw):
168
+ """Extract endpoint definitions from raw data
169
+
170
+ Args:
171
+ (dict): endpoint definitions
172
+ """
173
+ self.parse_api_definitions(raw.get("hal", {}))
174
+
175
+ @staticmethod
176
+ def extract_definition(definition):
177
+ """Extract definition from hal
178
+
179
+ Args:
180
+ definition (dict): hal definition
181
+
182
+ Returns:
183
+ (dict): hal definition
184
+ """
185
+ if isinstance(definition, list):
186
+ specifications = {
187
+ 'hals': definition
188
+ }
189
+ else:
190
+ specifications = {
191
+ 'properties': definition.get('properties', []),
192
+ 'methods': definition.get('methods', [])
193
+ }
194
+ return specifications