Skip to content

Commit

Permalink
Added UCDS XML config file loading
Browse files Browse the repository at this point in the history
  • Loading branch information
consp committed Jan 29, 2020
1 parent cee9cc9 commit 3032704
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 47 deletions.
80 changes: 40 additions & 40 deletions src/apim.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,38 +35,38 @@ def calc_change(block, loc, cfield, fields):
cfield.setText("%02X" % (sum(x) & 0x00FF))

class QtApp(object):
app = None

app = None
main_layout = None
main_window = None
button_open = None
button_exit = None
button_save = None
button_save_as = None

current_window = None

picker_window = None
picker_layout = None

selected_file = None
asbuilt = None
encoder = None

blockdata = None

block = 1

textblocks = []

def open_file(self):
window = self.current_window
options = QFileDialog.Options()
options |= QFileDialog.DontUseNativeDialog
files, _ = QFileDialog.getOpenFileName(window, "Select ASBuilt file...", "","ForScan files (*.abt);;Ford ASBuilt XML (*.ab);;All Files (*)", options=options)
files, _ = QFileDialog.getOpenFileName(window, "Select ASBuilt file...", "","ForScan files (*.abt);;Ford ASBuilt XML (*.ab);;UCDS XML files (*.xml);;All Files (*)", options=options)
if files:
self.selected_file = files

if self.selected_file is not None:
try:
self.asbuilt = AsBuilt(self.selected_file)
Expand All @@ -76,8 +76,8 @@ def open_file(self):
QMessageBox.critical(self.current_window, "Error opening file", str(e))
self.selected_file = None
self.current_window.show()


def save_file_as(self, window=None):
window = self.current_window
options = QFileDialog.Options()
Expand All @@ -89,18 +89,18 @@ def save_file_as(self, window=None):
self.selected_file = self.selected_file[:-3]
if not self.selected_file.endswith(".abt"):
self.selected_file = self.selected_file + ".abt"

if self.selected_file is not None and files is not None and len(files) > 0:
self.save(overwrite=True)

def save(self, overwrite=False):
for x in range(0, self.asbuilt.block_size()):
block = list(self.asbuilt.blocks[x])
for b in range(0, len(self.textblocks[x])):
block[b] = int(self.textblocks[x][b].text(), 16)
self.asbuilt.blocks[x] = bytes(block)
string = self.asbuilt.save()

print("Saving to %s" % self.selected_file)
print(string)
item = False
Expand All @@ -116,63 +116,63 @@ def save(self, overwrite=False):
except Exception as e:
QMessageBox.critical(self.current_window, "Error saving to file", str(e))
pass




def block_change(self):
print("Selected item %d" % (self.block_combo_box.currentIndex()))
self.block = self.block_combo_box.currentIndex() + 1
self.add_blockitems()


def launch_picker(self):
self.main_window.hide()
if self.picker_window is not None:
self.picker_window.hide()

self.picker_window = QWidget()
self.picker_window.resize(1024, 800)

self.picker_layout = QVBoxLayout()

## main group
self.button_group = QGroupBox("Main things")
self.button_group_layout = QHBoxLayout()
self.button_save = QPushButton("Save") if self.button_save is None else self.button_save
self.button_save_as = QPushButton("Save as ...") if self.button_save_as is None else self.button_save_as
self.button_save_as.clicked.connect(self.save_file_as)
self.button_save.clicked.connect(self.save)

self.button_group_layout.addWidget(self.button_open)
self.button_group_layout.addWidget(self.button_save)
self.button_group_layout.addWidget(self.button_save_as)
self.button_group_layout.addWidget(self.button_exit)
self.button_group.setLayout(self.button_group_layout)

## Block group
self.block_group = QGroupBox("Select block")
self.block_group_layout = QVBoxLayout()

#self.block_combo_box = QComboBox()

#self.block_combo_box.addItems(["7D0-%02X or DE%02X" % (x, x-1) for x in range(1, self.asbuilt.size()+1)])
#self.block_combo_box.currentIndexChanged.connect(self.block_change)

self.tabs = QTabWidget()
self.tab = []
self.textblocks = []
for x in range(1, self.asbuilt.block_size() + 1):
block_items_group = QGroupBox()
block_items_layout = QVBoxLayout()
block_items_group.setLayout(block_items_layout)

setup = QWidget()

scroll_area = QScrollArea()
scroll_area.setWidget(block_items_group)
scroll_area.setWidgetResizable(True)

blockview = QGroupBox("Binary")
blockview_layout = QHBoxLayout()
blockview.setLayout(blockview_layout)
Expand Down Expand Up @@ -230,31 +230,31 @@ def launch_picker(self):
setup_layout.addWidget(blockview)
setup_layout.addWidget(scroll_area)
setup.setLayout(setup_layout)

items = self.encoder.QtItemList(x, self.asbuilt, self.textblocks[x-1])
for item in items:
block_items_layout.addLayout(item)
self.tab.append(setup)
self.tabs.addTab(self.tab[x - 1], "7D0-%02X" % (x))



#self.block_group_layout.addWidget(self.block_combo_box)
self.block_group_layout.addWidget(self.tabs)
self.block_group.setLayout(self.block_group_layout)

self.picker_layout.addWidget(self.button_group)
self.picker_layout.addWidget(self.block_group)

self.picker_window.setLayout(self.picker_layout)
self.current_window = self.picker_window
#self.picker_window.setSizePolicy(QSizePolicy.Expanding)
self.picker_window.show()

def launch_qt(self):
self.app = QApplication([])
self.app.setStyle('Fusion')

self.main_window = QWidget()
self.main_layout = QVBoxLayout()

Expand Down
16 changes: 13 additions & 3 deletions src/asbuilt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class AsBuilt(object):
def __init__(self, filename):
bits = ""
print("Loading", filename)
if filename.endswith(".abt"):
if filename.lower().endswith(".abt"):
# file from ForScan
print("Forscan ABT format")
with open(filename, "r") as f:
Expand All @@ -25,7 +25,7 @@ def __init__(self, filename):
if len(line) == 0 or line[0] == ";":
continue
bits = bits + line[7:-2]
elif filename.endswith(".ab"):
elif filename.lower().endswith(".ab"):
print("Loading Ford XML file")
# ab file from motorcraft site / ford
tree = ET.parse(filename)
Expand All @@ -39,6 +39,16 @@ def __init__(self, filename):
if code.text is not None:
bits = bits + code.text
bits = bits[:-2]
elif filename.lower().endswith(".xml"):
print("Loading UCDS Direct configuration XML file")
# ab file from motorcraft site / ford
tree = ET.parse(filename)
root = tree.getroot()
data = root.find(".//VEHICLE")
for child in list(data):
block = child.attrib['ID']
if block.startswith('DE'):
bits = bits + child.text
else:
raise ValueError("File type not supported")
self.filename = filename
Expand Down Expand Up @@ -115,7 +125,7 @@ def start_bit(self, block):

def block(self, block):
return self.blocks[block]

def block_size(self):
return len(self.blocks)

Expand Down
64 changes: 60 additions & 4 deletions src/statics.py
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ def block(cls, block):


de01 = [

{
'name': 'First Letter of Country Code-ASCII',
'index': 70,
Expand Down Expand Up @@ -2588,10 +2588,10 @@ def block(cls, block):
{ 'name': 'Digital Camera Vehicle Setting',
'index': 214,
'byte': 6,
'bit': 2,
'bit': 0,
'type': 'mask',
'size': 3,
'items': 8,
'size': 6,
'items': 64,
'0': 'Vehicle 1',
'1': 'Vehicle 2',
'2': 'Vehicle 3',
Expand All @@ -2600,6 +2600,62 @@ def block(cls, block):
'5': 'Vehicle 6',
'6': 'Vehicle 7',
'7': 'Vehicle 8',
'8': 'Vehicle 9',
'9': 'Vehicle 10',
'10': 'Vehicle 11',
'11': 'Vehicle 12',
'12': 'Vehicle 13',
'13': 'Vehicle 14',
'14': 'Vehicle 15',
'15': 'Vehicle 16',
'16': 'Vehicle 17',
'17': 'Vehicle 18',
'18': 'Vehicle 19',
'19': 'Vehicle 20',
'20': 'Vehicle 21',
'21': 'Vehicle 22',
'22': 'Vehicle 23',
'23': 'Vehicle 24',
'24': 'Vehicle 25',
'25': 'Vehicle 26',
'26': 'Vehicle 27',
'27': 'Vehicle 28',
'28': 'Vehicle 29',
'29': 'Vehicle 30',
'30': 'Vehicle 31',
'31': 'Vehicle 32',
'32': 'Vehicle 33',
'33': 'Vehicle 34',
'34': 'Vehicle 35',
'35': 'Vehicle 36',
'36': 'Vehicle 37',
'37': 'Vehicle 38',
'38': 'Vehicle 39',
'39': 'Vehicle 40',
'40': 'Vehicle 41',
'41': 'Vehicle 42',
'42': 'Vehicle 43',
'43': 'Vehicle 44',
'44': 'Vehicle 45',
'45': 'Vehicle 46',
'46': 'Vehicle 47',
'47': 'Vehicle 48',
'48': 'Vehicle 49',
'49': 'Vehicle 50',
'50': 'Vehicle 51',
'51': 'Vehicle 52',
'52': 'Vehicle 53',
'53': 'Vehicle 54',
'54': 'Vehicle 55',
'55': 'Vehicle 56',
'56': 'Vehicle 57',
'57': 'Vehicle 58',
'58': 'Vehicle 59',
'59': 'Vehicle 60',
'60': 'Vehicle 61',
'61': 'Vehicle 62',
'62': 'Vehicle 63',
'63': 'Vehicle 64',
},
{ 'name': 'Steering Angle sensor',
'index': 215,
Expand Down

0 comments on commit 3032704

Please sign in to comment.