-
-
Notifications
You must be signed in to change notification settings - Fork 77
Open
Description
After updating to 0.14.5, I experience issues when parsing an a2l file. My code throws an exception;
The code:
def import_a2l_file(a2l_file: str, in_memory=False):
sys.path.append(str(Path(__file__).resolve().parent.parent))
a2l_file_path = Path(a2l_file).resolve()
a2l_db_file = create_program_data_path(a2l_file)
a2l_db_file = a2l_db_file.with_suffix('.a2ldb')
if a2l_db_file.exists():
logger.info(f"Overwriting existing file: {a2l_db_file}")
a2l_db_file.unlink()
db = DB()
print(f"Loading file from {a2l_file_path} as a database into: {os.getcwd()}")
return db.import_a2l(str(a2l_file_path), in_memory=in_memory, local=False, loglevel="INFO", remove_existing=True,
progress_bar=False, debug=False)
The exception:
┌───────────────────── Traceback (most recent call last) ─────────────────────┐
│ C:\Repositories\xcp\src\a2l_cli\parser.py:244 in <module> │
│ │
│ 241 │ from pathlib import Path │
│ 242 │ │
│ 243 │ # print_a2l_content("../demofiles/704_0_9_9-lb97_a331360ba.a2l") │
│ > 244 │ import_a2l_file("C:/Repositories/a2l_python/demofiles/704_ │
│ 245 │ # print_a2l_content("C:/Repositories/a2l_python/demofiles/ │
│ 246 │ # get_measurements_and_characteristics_with_properties("C:/Reposi │
│ 247 │ result = print_event_channel_name_and_cycle_data("C:/Repositories │
│ │
│ ┌──────────────────────────────── locals ─────────────────────────────────┐ │
│ │ Dict = typing.Dict │ │
│ │ json = <module 'json' from │ │
│ │ 'C:\\Users\\PatrickWegner\\AppData\\Local\\Programs… │ │
│ │ List = typing.List │ │
│ │ logger = <Logger __main__ (CRITICAL)> │ │
│ │ logging = <module 'logging' from │ │
│ │ 'C:\\Users\\PatrickWegner\\AppData\\Local\\Programs… │ │
│ │ model = <module 'pya2l.model' from │ │
│ │ 'C:\\Repositories\\xcp\\venv\\Lib\\site-packag… │ │
│ │ os = <module 'os' (frozen)> │ │
│ │ re = <module 're' from │ │
│ │ 'C:\\Users\\PatrickWegner\\AppData\\Local\\Programs… │ │
│ │ sys = <module 'sys' (built-in)> │ │
│ │ Tuple = typing.Tuple │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
│ │
│ C:\Repositories\xcp\src\a2l_cli\parser.py:38 in import_a2l_file │
│ │
│ 35 │ # """ $env:PYTHONPATH = "C:\Repositories\a2l_python" """ │
│ 36 │ # """ python -m a2l_cli.main create "C:\Repositories\a2l_python_ │
│ 37 │ print(f"Loading file from {a2l_file_path} as a database into: {os │
│ > 38 │ return db.import_a2l(str(a2l_file_path), in_memory=in_memory, loc │
│ 39 │ │ │ │ │ │ progress_bar=False, debug=False) │
│ 40 │
│ 41 │
│ │
│ ┌──────────────────────────────── locals ─────────────────────────────────┐ │
│ │ a2l_file = 'C:/Repositories/a2l_python/demofiles/704_0_11_… │ │
│ │ a2l_file_path = WindowsPath('C:/Repositories/a2l_python/demofil… │ │
│ │ db = <pya2l.DB object at 0x0000027103D09CD0> │ │
│ │ in_memory = False │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
│ │
│ ... 7 frames hidden ... │
│ │
│ C:\Repositories\xcp\venv\Lib\site-packages\pya2l\a2lparser.py:439 in │
│ traverse │
│ │
│ 436 │ │ │ │ inst = FakeRoot() │
│ 437 │ │ │ │ attr = "fake" │
│ 438 │ │ │ │ mult = False │
│ > 439 │ │ │ self.traverse(kw, inst, attr, mult, level + 1) │
│ 440 │ │ if name != "root" and not isinstance(inst, bool): │
│ 441 │ │ │ self.db.session.add(inst) │
│ 442 │
│ │
│ ┌──────────────────────────────── locals ─────────────────────────────────┐ │
│ │ attr = 'if_data' │ │
│ │ elem = ('if_data', True) │ │
│ │ if_data = '' │ │
│ │ inst = MemorySegment(name = 'PLATFORMCALPRM_ADDR_METHOD_FLASH', │ │
│ │ longIdentifier = '', prgType = 'DATA', memoryType = 'FLASH', │ │
│ │ attribute = 'INTERN', address = 328256, size = 180, offset_0 │ │
│ │ = -1, offset_1 = -1, offset_2 = -1, offset_3 = -1, offset_4 │ │
│ │ = -1, rid = None) │ │
│ │ kw = <pya2l.a2lparser_ext.ValueContainer object at │ │
│ │ 0x00000271048F50B0> │ │
│ │ level = 4 │ │
│ │ mult = True │ │
│ │ multiple = True │ │
│ │ name = 'MemorySegment' │ │
│ │ params = [ │ │
│ │ │ 'PLATFORMCALPRM_ADDR_METHOD_FLASH', │ │
│ │ │ '', │ │
│ │ │ 'DATA', │ │
│ │ │ 'FLASH', │ │
│ │ │ 'INTERN', │ │
│ │ │ 328256, │ │
│ │ │ 180, │ │
│ │ │ -1, │ │
│ │ │ -1, │ │
│ │ │ -1, │ │
│ │ │ ... +2 │ │
│ │ ] │ │
│ │ parent = ModPar(comment = '', rid = None, version_id = None) │ │
│ │ self = <pya2l.a2lparser.A2LParser object at 0x0000027103D09BB0> │ │
│ │ tree = <pya2l.a2lparser_ext.ValueContainer object at │ │
│ │ 0x000002710426C6B0> │ │
│ │ values = { │ │
│ │ │ 'name': 'PLATFORMCALPRM_ADDR_METHOD_FLASH', │ │
│ │ │ 'longIdentifier': '', │ │
│ │ │ 'prgType': 'DATA', │ │
│ │ │ 'memoryType': 'FLASH', │ │
│ │ │ 'attribute': 'INTERN', │ │
│ │ │ 'address': 328256, │ │
│ │ │ 'size': 180, │ │
│ │ │ 'offset_0': -1, │ │
│ │ │ 'offset_1': -1, │ │
│ │ │ 'offset_2': -1, │ │
│ │ │ ... +2 │ │
│ │ } │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
│ │
│ C:\Repositories\xcp\venv\Lib\site-packages\pya2l\a2lparser.py:406 in │
│ traverse │
│ │
│ 403 │ │ │ │ params = {} │
│ 404 │ │ │ │ # if_data = [] │
│ 405 │ │ │ mult = tree.get_multiple_values() │
│ > 406 │ │ │ if_data = tree.if_data │
│ 407 │ │ │ │
│ 408 │ │ │ values = zipper(params, mult) │
│ 409 │ │ │ if name not in ("ReadOnly", "GuardRails", "Discrete"): │
│ │
│ ┌──────────────────────────────── locals ─────────────────────────────────┐ │
│ │ attr = 'if_data' │ │
│ │ inst = None │ │
│ │ level = 5 │ │
│ │ mult = [] │ │
│ │ multiple = True │ │
│ │ name = 'IfData' │ │
│ │ params = ['CANAPE_ADDRESS_UPDATE'] │ │
│ │ parent = MemorySegment(name = 'PLATFORMCALPRM_ADDR_METHOD_FLASH', │ │
│ │ longIdentifier = '', prgType = 'DATA', memoryType = 'FLASH', │ │
│ │ attribute = 'INTERN', address = 328256, size = 180, offset_0 │ │
│ │ = -1, offset_1 = -1, offset_2 = -1, offset_3 = -1, offset_4 │ │
│ │ = -1, rid = None) │ │
│ │ self = <pya2l.a2lparser.A2LParser object at 0x0000027103D09BB0> │ │
│ │ tree = <pya2l.a2lparser_ext.ValueContainer object at │ │
│ │ 0x00000271048F50B0> │ │
│ └─────────────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xaa in position 0: invalid
start byte
My a2l File has the encoding "UTF-8-SIG"
I checked the encoding of the a2l File with this code:
from chardet.universaldetector import UniversalDetector
def detect_encoding(file_path):
detector = UniversalDetector()
with open(file_path, 'rb') as file:
for line in file:
detector.feed(line)
if detector.done:
break
detector.close()
return detector.result['encoding']
The failing part of the IF_DATA of this a2l file is:
/begin IF_DATA CANAPE_ADDRESS_UPDATE
/begin MAP_SYMBOL
FIRST
"Rte_CalprmRom_PLATFORMCALPRM_ADDR_METHOD"
0
LAST
"Rte_CalprmRom_PLATFORMCALPRM_ADDR_METHOD"
0
ADDRESS_MAPPING_XCP
"Rte_CalprmRom_PLATFORMCALPRM_ADDR_METHOD"
"Rte_CalprmInitRam_PLATFORMCALPRM_ADDR_METHOD"
/end MAP_SYMBOL
/end IF_DATA
/begin IF_DATA XCP
/begin SEGMENT
0x00
0x01
0x00
0x00
0x00
/begin PAGE
0x00
ECU_ACCESS_DONT_CARE
XCP_READ_ACCESS_DONT_CARE
XCP_WRITE_ACCESS_NOT_ALLOWED
/end PAGE
/begin ADDRESS_MAPPING
0x050240
0xFEBDE960
0xB4
/end ADDRESS_MAPPING
/end SEGMENT
/end IF_DATA
Metadata
Metadata
Assignees
Labels
No labels