-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patha2l_generator.py
49 lines (43 loc) · 1.47 KB
/
a2l_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
"""
Program to build an A2L file.
Author: Ximu Zhang
Date: 11/21/2019
"""
def info_extract(symbol_info):
"""
This function extracts the useful information of the symbols to be written in the A2L.
:param symbol_info: information of the symbols
:return: extracted information
"""
extracted_symbol_info = []
for symbol in symbol_info:
name = symbol['name']
addr = symbol['address']
size = symbol['size']
extracted_symbol_info.append([name, addr, size])
return extracted_symbol_info
def a2l_variable_section_write(symbol_info):
"""
This function writes the variable section in a2l file
:param symbol_info: information of the symbols
:return: None
"""
extracted_symbol_info = info_extract(symbol_info)
sym_type = 'NO_TYPE'
sym_conversion_method = 'NO_COMPU_METHOD'
sym_standard_limits_lower = '0'
sym_standard_limits_upper = '0'
with open('.\\out\\file.a2l', 'w') as f:
for item in extracted_symbol_info:
sym_name = item[0]
if sym_name != '': # if no variable name, don't add to a2l file
sym_addr = str(hex(item[1])) # convert the address to hex format
sym_size = item[2]
# regard all the variables as measurements
f.write(" /begin MEASUREMENT %s \"\"\n" % sym_name)
f.write(" %s %s 0 0 %s %s\n" % (
sym_type, sym_conversion_method, sym_standard_limits_lower, sym_standard_limits_upper))
f.write(" ECU_ADDRESS %s\n" % sym_addr)
f.write(" SYMBOL_LINK %s 0\n" % sym_name)
f.write(" /end MEASUREMENT\n\n")
f.close()