24
24
# arxml-files are the can-matrix-definitions and a lot more in AUTOSAR-Context
25
25
# currently Support for Autosar 3.2 and 4.0-4.3 is planned
26
26
27
- from __future__ import absolute_import
28
- from __future__ import division
29
- from __future__ import print_function
27
+ from __future__ import absolute_import , division , print_function
30
28
31
29
import decimal
32
30
import logging
33
31
import typing
34
32
from builtins import *
35
33
36
- from lxml import etree
34
+ import lxml . etree
37
35
38
36
import canmatrix
39
37
import canmatrix .types
47
45
48
46
49
47
class ArTree (object ):
50
- def __init__ (self , name = "" , ref = None ): # type: (str, etree._Element) -> None
48
+ def __init__ (self , name = "" , ref = None ): # type: (str, lxml. etree._Element) -> None
51
49
self ._name = name
52
50
self ._ref = ref
53
51
self ._array = [] # type: typing.List[ArTree]
@@ -65,20 +63,20 @@ def get_child_by_name(self, name): # type: (str) -> typing.Union[ArTree, None]
65
63
return None
66
64
67
65
@property
68
- def ref (self ): # type: () -> etree._Element
66
+ def ref (self ): # type: () -> lxml. etree._Element
69
67
return self ._ref
70
68
71
69
72
70
# for typing only
73
- _Element = etree ._Element
71
+ _Element = lxml . etree ._Element
74
72
_DocRoot = typing .Union [_Element , ArTree ]
75
73
_MultiplexId = typing .Union [str , int , None ]
76
74
_FloatFactory = typing .Callable [[typing .Any ], typing .Any ]
77
75
78
76
79
77
def create_sub_element (parent , element_name , text = None ):
80
78
# type: (_Element, str, typing.Optional[str]) -> _Element
81
- sn = etree .SubElement (parent , element_name )
79
+ sn = lxml . etree .SubElement (parent , element_name )
82
80
if text is not None :
83
81
sn .text = str (text )
84
82
return sn
@@ -135,7 +133,7 @@ def dump(dbs, f, **options):
135
133
136
134
if ar_version [0 ] == "3" :
137
135
xsi = 'http://www.w3.org/2001/XMLSchema-instance'
138
- root = etree .Element (
136
+ root = lxml . etree .Element (
139
137
'AUTOSAR' ,
140
138
nsmap = {
141
139
None : 'http://autosar.org/' + ar_version ,
@@ -145,7 +143,7 @@ def dump(dbs, f, **options):
145
143
top_level_packages = create_sub_element (root , 'TOP-LEVEL-PACKAGES' )
146
144
else :
147
145
xsi = 'http://www.w3.org/2001/XMLSchema-instance'
148
- root = etree .Element (
146
+ root = lxml . etree .Element (
149
147
'AUTOSAR' ,
150
148
nsmap = {
151
149
None : "http://autosar.org/schema/r4.0" ,
@@ -760,7 +758,7 @@ def dump(dbs, f, **options):
760
758
ipdu_ref .set ('DEST' , "I-SIGNAL-I-PDU" )
761
759
ipdu_ref .text = "/PDU/PDU_" + frame_name
762
760
763
- f .write (etree .tostring (root , pretty_print = True , xml_declaration = True ))
761
+ f .write (lxml . etree .tostring (root , pretty_print = True , xml_declaration = True ))
764
762
765
763
766
764
###################################
@@ -1000,7 +998,7 @@ def get_signals(signal_array, frame, root_or_cache, ns, multiplex_id, float_fact
1000
998
1001
999
base_type = get_child (isignal , "BASE-TYPE" , root_or_cache , ns )
1002
1000
try :
1003
- type_encoding = get_child (base_type ,"BASE-TYPE-ENCODING" , root_or_cache , ns ).text
1001
+ type_encoding = get_child (base_type , "BASE-TYPE-ENCODING" , root_or_cache , ns ).text
1004
1002
except AttributeError :
1005
1003
type_encoding = "None"
1006
1004
signal_name = None # type: typing.Optional[str]
@@ -1192,6 +1190,7 @@ def get_signals(signal_array, frame, root_or_cache, ns, multiplex_id, float_fact
1192
1190
new_signal .add_attribute ("LongName" , signal_name )
1193
1191
frame .add_signal (new_signal )
1194
1192
1193
+
1195
1194
def get_frame_from_multiplexed_ipdu (pdu , target_frame , multiplex_translation , root_or_cache , ns , float_factory ):
1196
1195
selector_byte_order = get_child (pdu , "SELECTOR-FIELD-BYTE-ORDER" , root_or_cache , ns )
1197
1196
selector_len = get_child (pdu , "SELECTOR-FIELD-LENGTH" , root_or_cache , ns )
@@ -1244,8 +1243,8 @@ def get_frame_from_container_ipdu(pdu, target_frame, root_or_cache, ns, float_fa
1244
1243
header_type = get_child (pdu , "HEADER-TYPE" , root_or_cache , ns ).text
1245
1244
if header_type == "SHORT-HEADER" :
1246
1245
header_length = 32
1247
- target_frame .add_signal (canmatrix .Signal (start_bit = 0 , size = 24 , name = "Header_ID" , multiplex = "Multiplexor" , is_little_endian = True ))
1248
- target_frame .add_signal (canmatrix .Signal (start_bit = 24 , size = 8 , name = "Header_DLC" , is_little_endian = True ))
1246
+ target_frame .add_signal (canmatrix .Signal (start_bit = 0 , size = 24 , name = "Header_ID" , multiplex = "Multiplexor" , is_little_endian = True ))
1247
+ target_frame .add_signal (canmatrix .Signal (start_bit = 24 , size = 8 , name = "Header_DLC" , is_little_endian = True ))
1249
1248
elif header_type == "LONG-HEADER" :
1250
1249
header_length = 64
1251
1250
target_frame .add_signal (canmatrix .Signal (start_bit = 0 , size = 32 , name = "Header_ID" , multiplex = "Multiplexor" ,
@@ -1254,7 +1253,7 @@ def get_frame_from_container_ipdu(pdu, target_frame, root_or_cache, ns, float_fa
1254
1253
else :
1255
1254
raise ("header " + header_type + " not supported for containers yet" )
1256
1255
# none type
1257
- #TODO
1256
+ # TODO
1258
1257
1259
1258
for cpdu in pdus :
1260
1259
ipdu = get_child (cpdu , "I-PDU" , root_or_cache , ns )
@@ -1264,7 +1263,7 @@ def get_frame_from_container_ipdu(pdu, target_frame, root_or_cache, ns, float_fa
1264
1263
elif header_type == "LONG-HEADER" :
1265
1264
header_id = get_child (ipdu , "HEADER-ID-LONG-HEADER" , root_or_cache , ns ).text
1266
1265
else :
1267
- #none type
1266
+ # none type
1268
1267
pass
1269
1268
except AttributeError :
1270
1269
header_id = "0"
@@ -1286,6 +1285,7 @@ def get_frame_from_container_ipdu(pdu, target_frame, root_or_cache, ns, float_fa
1286
1285
singnals_grouped += new_signals
1287
1286
signal_group_id += 1
1288
1287
1288
+
1289
1289
def store_frame_timings (target_frame , cyclic_timing , event_timing , minimum_delay , repeats , starting_time , time_offset , repeating_time , root_or_cache , time_period , ns , float_factory ):
1290
1290
if cyclic_timing is not None and event_timing is not None :
1291
1291
target_frame .add_attribute ("GenMsgSendType" , "cyclicAndSpontanX" ) # CycleAndSpontan
@@ -1602,7 +1602,7 @@ def load(file, **options):
1602
1602
1603
1603
result = {}
1604
1604
logger .debug ("Read arxml ..." )
1605
- tree = etree .parse (file )
1605
+ tree = lxml . etree .parse (file )
1606
1606
1607
1607
root = tree .getroot () # type: _Element
1608
1608
logger .debug (" Done\n " )
@@ -1650,7 +1650,7 @@ def load(file, **options):
1650
1650
logger .debug ("%d I-SIGNAL-TO-I-PDU-MAPPING in arxml..." , len (sig_ipdu ))
1651
1651
1652
1652
if ignore_cluster_info is True :
1653
- ccs = [etree .Element ("ignoreClusterInfo" )] # type: typing.Sequence[_Element]
1653
+ ccs = [lxml . etree .Element ("ignoreClusterInfo" )] # type: typing.Sequence[_Element]
1654
1654
else :
1655
1655
ccs = root .findall ('.//' + ns + 'CAN-CLUSTER' )
1656
1656
for cc in ccs : # type: _Element
0 commit comments