-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathARXML_GEN.py
76 lines (55 loc) · 2 KB
/
ARXML_GEN.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import re
from Tkinter import *
from textwrap import wrap
import tkFileDialog
import math
from DBC_Parser import DBCParse
from prettytable import PrettyTable
import xml.etree.ElementTree as ET
# Functions:
def AddBool(name,DataTypeElementsRoot):
boolType = ET.SubElement(DataTypeElementsRoot,'BOOLEAN-TYPE')
shortName = ET.SubElement(boolType,'SHORT-NAME')
shortName.text = name
def AddStruct(message,DataTypeElementsRoot):
recordType = ET.SubElement(DataTypeElementsRoot,'RECORD-TYPE')
shortName = ET.SubElement(recordType,'SHORT-NAME')
shortName.text = message.name + '_GEN_S'
Elements = ET.SubElement(recordType,'ELEMENTS')
for signal in message.signals:
recordElement = ET.SubElement(Elements,'RECORD-ELEMENT')
shortName = ET.SubElement(recordElement,'SHORT-NAME')
shortName.text = signal
typeRef = ET.SubElement(recordElement,'TYPE-TREF')
typeRef.attrib = {'DEST':'BOOLEAN-TYPE'}
typeRef.text = '/DataType/DT_'+signal
ET.register_namespace('', "http://autosar.org/3.2.2")
tree = ET.parse('COMH_Try_swc.arxml')
#---------------------------- Read DBC File --------------------------------------------------------
fileName = 'RIV_ADAS_Mule1_v8.dbc'
if fileName == None:
sys.exit()
DBC_Name = fileName
DBCParsObj = DBCParse(DBC_Name,'PARK')
DBCParsObj.printdbc()
#---------------------------- Read DBC File --------------------------------------------------------
root = tree.getroot()
topLevelPacks = root[0]
# for AR_Packs in topLevelPacks:
# for AR_Pack in AR_Packs:
# if 'SHORT-NAME' in AR_Pack.tag:
# print AR_Pack.text
for AR_Packs in topLevelPacks:
for AR_Pack in AR_Packs:
if 'SHORT-NAME' in AR_Pack.tag:
if AR_Pack.text == 'DataType':
#print 'Datatype found'
#print AR_Packs[1].tag
DataType_Elements = AR_Packs[1]
# for Element in DataType_Elements:
# print Element.tag
AddBool('DT_Raziur',DataType_Elements)
for message in DBCParsObj.Messages:
if message == 'Misc_Report':
AddStruct(DBCParsObj.Messages[message],DataType_Elements)
tree.write('new.xml')