Skip to content

Commit

Permalink
Fix ecu value spanning two bytes + parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Cedric PAILLE committed Dec 1, 2016
1 parent 68a7ed4 commit f5ed462
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 29 deletions.
29 changes: 13 additions & 16 deletions ddt4all.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@

app = None

class Ecu_list(gui.QDialog):
def __init__(self, ecuscan):
class Ecu_list(gui.QWidget):
def __init__(self, ecuscan, treeview_ecu):
super(Ecu_list, self).__init__()
self.selected = ''
self.treeview_ecu = treeview_ecu
layout = gui.QVBoxLayout()
self.setLayout(layout)
self.list = gui.QTreeWidget(self)
Expand Down Expand Up @@ -41,19 +42,19 @@ def __init__(self, ecuscan):
keys.sort(cmp=locale.strcoll)
for e in keys:
item = gui.QTreeWidgetItem(self.list, [e])
#stored_ecus[e].sort(cmp=locale.strcoll)
for t in stored_ecus[e]:
gui.QTreeWidgetItem(item, t)
self.list.sortItems(0, core.Qt.AscendingOrder)
self.list.doubleClicked.connect(self.ecuSel)

def ecuSel(self, index):
item = self.list.model().itemData(index)
self.selected = unicode(item[0].toPyObject().toUtf8(), encoding="UTF-8")
target = self.ecuscan.ecu_database.getTarget(self.selected)
selected = unicode(item[0].toPyObject().toUtf8(), encoding="UTF-8")
target = self.ecuscan.ecu_database.getTarget(selected)
if target:
self.ecuscan.addTarget(target)
self.close()
if selected:
self.treeview_ecu.addItem(selected)


class Main_widget(gui.QMainWindow):
Expand Down Expand Up @@ -107,6 +108,7 @@ def __init__(self, parent = None):
self.treeview_params.setHeaderLabels(["Screens"])
self.treeview_params.clicked.connect(self.changeScreen)


self.treedock_logs = gui.QDockWidget(self)
self.logview = gui.QTextEdit()
self.logview.setReadOnly(True)
Expand All @@ -117,6 +119,11 @@ def __init__(self, parent = None):
self.treedock_ecu.setWidget(self.treeview_ecu)
self.treeview_ecu.clicked.connect(self.changeECU)

self.eculistwidget = Ecu_list(self.ecu_scan, self.treeview_ecu)
self.treeview_eculist = gui.QDockWidget(self)
self.treeview_eculist.setWidget(self.eculistwidget)

self.addDockWidget(core.Qt.LeftDockWidgetArea, self.treeview_eculist)
self.addDockWidget(core.Qt.LeftDockWidgetArea, self.treedock_ecu)
self.addDockWidget(core.Qt.LeftDockWidgetArea, self.treedock_params)
self.addDockWidget(core.Qt.BottomDockWidgetArea, self.treedock_logs)
Expand Down Expand Up @@ -186,10 +193,6 @@ def __init__(self, parent = None):
ecuaction = diagmenu.addAction(ecuf)
ecuaction.triggered.connect(lambda state, a=ecuf: self.loadEcu(a))

ecumenu = menu.addMenu("Ecu")
selectecu = ecumenu.addAction("Selectionner ECU")
selectecu.triggered.connect(self.addEcu)

iskmenu = menu.addMenu("ISK")
meg2isk = iskmenu.addAction("Megane II")
meg2isk.triggered.connect(lambda: self.getISK('megane2'))
Expand Down Expand Up @@ -232,12 +235,6 @@ def getISK(self, vehicle):
if self.paramview:
self.paramview.initELM()

def addEcu(self):
eculist = Ecu_list(self.ecu_scan)
eculist.exec_()
if eculist.selected:
self.treeview_ecu.addItem(eculist.selected)

def scan(self):
msgBox = gui.QMessageBox()
msgBox.setText('Options de scan')
Expand Down
13 changes: 12 additions & 1 deletion ecu.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ def getDisplayValue(self, elm_data, dataitem, req_endian):
elif self.bytescount == 2:
value = hex16_tosigned(value)

if self.divideby == 0:
print "Division by zero : ", dataitem.name
return None

res = (value * float(self.step) + float(self.offset)) / float(self.divideby)
if len(self.format) and '.' in self.format:
acc = len(self.format.split('.')[1])
Expand Down Expand Up @@ -349,6 +353,9 @@ def getHexValue(self, resp, dataitem, req_endian):
startByte = dataitem.firstbyte
startBit = dataitem.bitoffset

if startBit + bits > (bytes * 8):
bytes += 1

sb = startByte - 1
if (sb * 2 + bytes * 2) > (len(resp)):
return None
Expand All @@ -372,7 +379,11 @@ def getHexValue(self, resp, dataitem, req_endian):
if little_endian:
offset = startBit
else:
offset = (self.bytescount * 8) - startBit - bits
offset = (bytes * 8) - startBit - bits

if (offset < 0):
print "negative offset : ", dataitem.name, bits, offset, little_endian, hexval
return None

val = int(hexval, 16)
val = (val >> int(offset)) & (2**bits - 1)
Expand Down
27 changes: 15 additions & 12 deletions parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def __init__(self, parent, ddtfile, ecu_addr, ecu_name, logview):
self.inputDict = {}
self.presend = []
self.ecu_addr = str(ecu_addr)
self.startsession_command = '10C0'
self.timer = core.QTimer()
self.timer.setSingleShot(True)
self.initXML()
Expand Down Expand Up @@ -232,16 +231,6 @@ def initXML(self):
self.xmlscreen[screen_name] = screen
self.categories[category_name].append(screen_name)

if "Start Diagnostic Session" in self.ecurequestsparser.requests:
diag_request = self.ecurequestsparser.requests["Start Diagnostic Session"]
self.startsession_command = diag_request.sentbytes
elif "StartDiagnosticSession" in self.ecurequestsparser.requests:
diag_request = self.ecurequestsparser.requests["StartDiagnosticSession"]
self.startsession_command = diag_request.sentbytes
else:
print "Cannot find a valid StartDiagnoticSession entry, using default"
self.startsession_command = '10C0'

def sendElm(self, command, auto=False):
txt = ''
elm_response = '00 ' * 70
Expand Down Expand Up @@ -373,7 +362,21 @@ def drawDisplays(self, screen):
rect = self.getRectangle(self.getChildNodesByName(display, "Rectangle")[0])
qfnt = self.getFont(display)
req = self.ecurequestsparser.requests[req_name]
dataitem = req.dataitems[text]
dataitem = None
if text in req.dataitems:
dataitem = req.dataitems[text]
else:
keys = req.dataitems.keys()
for k in keys:
if k.upper() == text.upper():
dataitem = req.dataitems[k]
print "Found similar", k, " vs ", text
break

if not dataitem:
print "DataItem not found", text
continue

data = self.ecurequestsparser.data[text]

qlabel = gui.QLabel(self.panel)
Expand Down

0 comments on commit f5ed462

Please sign in to comment.