ARXML文件是以AUTOSAR XML (ARXML)格式保存的配置文件。它被AUTOSAR使用,AUTOSAR是2003年由汽车制造商和供应商组成的一个项目,用于为汽车电子控制单元(ECUs)建立软件体系结构。ARXML文件包含ECU的XML格式的配置和规范信息,ECU用于控制引擎组件,以确保引擎达到最佳性能。
import re
import xml.etree.ElementTree as ET
tree = ET.parse('FLC2_SystemExtract_19011.arxml')
root = tree.getroot()
root.tag
'{http://autosar.org/schema/r4.0}AUTOSAR'
root = root[0]
for child in root:# root下面的所有子标签
print(child)
root1 = root[0] # 第一个 AR-PACKAGE 标签
ECUExtractFLC
VehicleProject
XMA19011
ECU_EXTRACT
0.0.0;19/04/17, ECU.Cfg.Ver: 0
/EcuInstances/FLC2
```
```python
root1.find("./{http://autosar.org/schema/r4.0}SHORT-NAME")
root1.find("./{http://autosar.org/schema/r4.0}SHORT-NAME").text
'ECUExtractFLC'
root1.find("./{http://autosar.org/schema/r4.0}AR-PACKAGES")
root1.findall("./{http://autosar.org/schema/r4.0}AR-PACKAGES/{http://autosar.org/schema/r4.0}AR-PACKAGE/{http://autosar.org/schema/r4.0}ELEMENTS/{http://autosar.org/schema/r4.0}SYSTEM/*")
[,
,
,
,
,
,
]
root1.findall(".//{http://autosar.org/schema/r4.0}FIBEX-ELEMENT-REF-CONDITIONAL") # 注意 .// 才行;./ 是不行的
[,
,
,
,
,
,
,
,
,
,
,
,
...]
root2 = root[1] # 第2个 AR-PACKAGE 标签
Communication = root2.findall("./{http://autosar.org/schema/r4.0}AR-PACKAGES/{http://autosar.org/schema/r4.0}AR-PACKAGE")
Communication
[,
,
,
,
,
,
,
]
for child in Communication:
print(child.tag ,child.attrib)
{http://autosar.org/schema/r4.0}AR-PACKAGE {'UUID': '74a341ea-6fb6-4673-a778-ea0131d1e5eb-Communication-Frame'}
{http://autosar.org/schema/r4.0}AR-PACKAGE {'UUID': '74a341ea-6fb6-4673-a778-ea0131d1e5eb-Communication-Gateway'}
{http://autosar.org/schema/r4.0}AR-PACKAGE {'UUID': '74a341ea-6fb6-4673-a778-ea0131d1e5eb-Communication-ISignal'}
{http://autosar.org/schema/r4.0}AR-PACKAGE {'UUID': '74a341ea-6fb6-4673-a778-ea0131d1e5eb-Communication-ISignalGroup'}
{http://autosar.org/schema/r4.0}AR-PACKAGE {'UUID': '74a341ea-6fb6-4673-a778-ea0131d1e5eb-Communication-ISignalPduGroup'}
{http://autosar.org/schema/r4.0}AR-PACKAGE {'UUID': '74a341ea-6fb6-4673-a778-ea0131d1e5eb-Communication-NmConfig'}
{http://autosar.org/schema/r4.0}AR-PACKAGE {'UUID': '74a341ea-6fb6-4673-a778-ea0131d1e5eb-Communication-Pdu'}
{http://autosar.org/schema/r4.0}AR-PACKAGE {'UUID': '74a341ea-6fb6-4673-a778-ea0131d1e5eb-Communication-TpConfig'}
ELEMENTS = Communication[0].findall(".//{http://autosar.org/schema/r4.0}ELEMENTS/*")
for child in ELEMENTS:
print(child[0].text)
ASDMCanFD2TimeSynchFr
ASDMFlcFlexTimeSynchFr
ASDMSafetyCANFD2Frame5
ASDMSafetyCANFD2Frame6
AsdmFLC_FlexrayFr00
AsdmFLC_FlexrayFr01
AsdmFLC_FlexrayFr02
AsdmFLC_FlexrayFr03
AsdmFLC_FlexrayNMFr
AsdmFlcFrDiagReqFrame1
AsdmFlcFrDiagReqFrame2
AsdmFlcFrDiagReqFrame3
AsdmFlcFrDiagReqFrame4
BbmAdRedundancyFr01
BbmAdRedundancyFr02
BbmAdRedundancyFr03
Pscm2ADRedundancyNMFr
PscmAdRedundancyFr01
PscmAdRedundancyFr02
frames = [child[0].text for child in ELEMENTS]
frames
['ASDMCanFD2TimeSynchFr',
'ASDMFlcFlexTimeSynchFr',
'ASDMSafetyCANFD2Frame5',
'ASDMSafetyCANFD2Frame6',
'FlcFLC_FlexrayFr300',
'FlcFLC_FlexrayFr303',
'FlcFLC_FlexrayFr306',
'FlcFLC_FlexrayFr309',
'FlcFLC_FlexrayFr341',
'FlcFLC_FlexrayFr344',
'FlcFLC_FlexrayFr347',
'FlcFLC_FlexrayFr35',
'FlcFLC_FlexrayFr350',
'FlrSafetyCanFD2NmFr',
'IMUPrivateSafeADCanFr01',
'IMUPrivateSafeADCanFr02',
'Pscm2ADRedundancyNMFr',
'PscmAdRedundancyFr01',
'PscmAdRedundancyFr02']
len(frames)
227
root_signal = root[5]
Signal
ADataRawSafeALat
IMU acceleration data Lateral acceleration
VALUE
false
‘’’
siganls = root_signal.findall("./{http://autosar.org/schema/r4.0}ELEMENTS/{http://autosar.org/schema/r4.0}SYSTEM-SIGNAL/{http://autosar.orcg/schema/r4.0}SHORT-NAME")
len(siganls)
7363
root_signal_group = root[6]
SignalGroup
ADataRawSafe
/Signal/ADataRawSafeAVertQf
/Signal/ADataRawSafeALgt
/Signal/ADataRawSafeALat
/Signal/ADataRawSafeChks
/Signal/ADataRawSafeALat1Qf
/Signal/ADataRawSafeCntr
/Signal/ADataRawSafeALgt1Qf
/Signal/ADataRawSafeAVert
‘’’
siganls_group = root_signal_group.findall("./{http://autosar.org/schema/r4.0}ELEMENTS/{http://autosar.org/schema/r4.0}SYSTEM-SIGNAL-GROUP/{http://autosar.org/schema/r4.0}SHORT-NAME")
len(siganls_group)
576
siganls_group_list = [i.text for i in siganls_group]#迭代取出signal——group的文本组成列表
siganls_group_list
['ADataRawSafe',
'AdPSSGroupSafe0',
'AdPSSGroupSafe1',
'AgDataRawSafe',
'AmbTRaw',
'AsyALgtReqForCmft',
'VisnObj21Msg1',
'VisnObj21Msg2',
'VisnObj21Msg3',
'VisnObj22Msg1',
'VisnObj22Msg2',
'VisnObj22Msg3',
'WhlSpdCircumlReForBkp',
'WipgInfo']
siganls_group_ref = root_signal_group.findall("./{http://autosar.org/schema/r4.0}ELEMENTS/{http://autosar.org/schema/r4.0}SYSTEM-SIGNAL-GROUP/{http://autosar.org/schema/r4.0}SYSTEM-SIGNAL-REFS")
all_signal_list=[]
for signal_each_group in siganls_group_ref:
signal_list =[]
for content_signal in signal_each_group:
signal_text = content_signal.text
signal=signal_text.split(r"/")[-1] #根据“/”c拆分获取到的包含信号的字符串“/Signal/ADataRawSafeAVertQf”,通过split 拆分成列表,最后一就是信号名字
signal_list.append(signal)
all_signal_list.append(signal_list)
print(all_signal_list)
print(len(all_signal_list))