Skip to content

Commit

Permalink
Editor work...
Browse files Browse the repository at this point in the history
  • Loading branch information
Cedric PAILLE committed May 30, 2017
1 parent 979d774 commit b05bdbb
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 21 deletions.
108 changes: 95 additions & 13 deletions dataeditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, data, num, parent=None):
self.layout.addLayout(cblayout)
self.setLayout(self.layout)

def set_byte(self, byte):
def set_byte_value(self, byte):
if 'L' in byte:
byte = byte.replace('L', '')

Expand All @@ -46,6 +46,17 @@ def set_byte(self, byte):
else:
self.checkboxes[i].setChecked(False)

def set_byte(self, byte):
if 'L' in byte:
byte = byte.replace('L', '')

binary = bin(int("0x" + byte, 16))[2:].zfill(8)
for i in range(8):
if binary[i] == "1":
self.checkboxes[i].setStyleSheet("background-color:#00FF00;")
else:
self.checkboxes[i].setStyleSheet("background-color:#FFFFFF;")


class Bit_viewer(gui.QScrollArea):
def __init__(self, parent=None):
Expand All @@ -71,6 +82,17 @@ def init(self, num):
self.mainwidget.setLayout(self.layout)
self.setWidget(self.mainwidget)

def set_bytes_value(self, byte_list):
num = len(byte_list)

for i in range(num):
if i >= len(self.bc):
break
self.bc[i].set_byte_value(byte_list[i])

for i in range(num, len(self.bc)):
self.bc[i].set_byte_value("00")

def set_bytes(self, byte_list):
num = len(byte_list)

Expand Down Expand Up @@ -164,7 +186,7 @@ def __init__(self, parent=None):
self.setSelectionBehavior(gui.QAbstractItemView.SelectRows)
self.setSelectionMode(gui.QAbstractItemView.SingleSelection)
self.verticalHeader().hide()
self.setShowGrid(False)
#self.setShowGrid(False)
self.currentreq = None

def cellModified(self, r, c):
Expand Down Expand Up @@ -252,6 +274,7 @@ class paramEditor(gui.QFrame):
def __init__(self, issend=True, parent=None):
super(paramEditor, self).__init__(parent)
self.send = issend
self.currentdataitem = None
self.setFrameStyle(gui.QFrame.Sunken)
self.setFrameShape(gui.QFrame.Box)
self.layoutv = gui.QVBoxLayout()
Expand Down Expand Up @@ -304,7 +327,7 @@ def __init__(self, issend=True, parent=None):
self.table.verticalHeader().hide()
self.table.setSelectionBehavior(gui.QAbstractItemView.SelectRows)
self.table.setSelectionMode(gui.QAbstractItemView.SingleSelection)
self.table.setShowGrid(False)
#self.table.setShowGrid(False)
self.layoutv.addWidget(self.table)
self.ecufile = None
self.current_request = None
Expand Down Expand Up @@ -356,7 +379,9 @@ def cell_clicked(self):
item = self.table.item(r, 0)
if not item: return
dataname = unicode(item.text().toUtf8(), encoding="UTF-8")
self.currentdataitem = dataname
self.update_bitview(dataname)
self.update_bitview_value(dataname)

def update_bitview(self, dataname):
bytes = self.current_request.minbytes
Expand All @@ -372,14 +397,17 @@ def update_bitview(self, dataname):

bitscount = ecudata.bitscount
valuetosend = hex(int("0b" + str("1" * bitscount), 2))[2:]

if "L" in valuetosend:
valuetosend = valuetosend.replace("L", "")
valuetosend = valuetosend.replace("L", "")

bytesarray = ["00" for a in range(bytes)]
bytesarray = ecudata.setValue(valuetosend, bytesarray, dataitem, self.current_request.endian, True)
self.bitviewer.set_bytes(bytesarray)

def update_bitview_value(self, dataname):
bytestosend = str(unicode(self.inputreq.text().toUtf8(), encoding="UTF8"))
byteslisttosend = [bytestosend[a*2:a*2+2] for a in range(len(bytestosend ) / 2)]
self.bitviewer.set_bytes_value(byteslisttosend)

def set_ecufile(self, ef):
self.ecufile = ef
self.table.clear()
Expand All @@ -392,6 +420,7 @@ def set_request(self, req):
def init(self, req):
self.table.clear()
self.data_list.clear()
self.currentdataitem = None

if self.send:
self.inputreq.setText(req.sentbytes)
Expand Down Expand Up @@ -493,15 +522,21 @@ def endian_changed(self, di, slf):
di.endian = "Little"
elif slf.currentText() == "Big":
di.endian = "Big"
self.update_bitview(di.name)
self.currentdataitem = di.name
self.update_bitview(self.currentdataitem)
self.update_bitview_value(self.currentdataitem)

def start_byte_changed(self, di, slf):
di.firstbyte = slf.value()
self.update_bitview(di.name)
self.currentdataitem = di.name
self.update_bitview(self.currentdataitem)
self.update_bitview_value(self.currentdataitem)

def bit_offset_changed(self, di, slf):
di.bitoffset = slf.value()
self.update_bitview(di.name)
self.currentdataitem = di.name
self.update_bitview(self.currentdataitem)
self.update_bitview_value(self.currentdataitem)

def request_changed(self):
if not self.current_request:
Expand All @@ -520,6 +555,9 @@ def request_changed(self):
if len(text) % 2 == 1:
return

if self.currentdataitem:
self.update_bitview_value(self.currentdataitem)

self.inputreq.setStyleSheet("background-color: green")
if self.send:
self.current_request.sentbytes = text
Expand Down Expand Up @@ -868,7 +906,7 @@ def __init__(self, parent=None):
self.datatable.verticalHeader().hide()
self.datatable.setSelectionBehavior(gui.QAbstractItemView.SelectRows)
self.datatable.setSelectionMode(gui.QAbstractItemView.SingleSelection)
self.datatable.setShowGrid(False)
#self.datatable.setShowGrid(False)

self.layouth.addWidget(self.datatable)

Expand Down Expand Up @@ -1105,22 +1143,27 @@ def __init__(self, parent=None):
self.requestdelbutton = gui.QPushButton("Del")
self.requestrefbutton = gui.QPushButton("Refresh")
self.requestmoveupbutton = gui.QPushButton("Move up")
self.requestcheckbutton = gui.QPushButton("Check")

layoutbar.addWidget(self.delaybox)
layoutbar.addWidget(self.requestcombo)
layoutbar.addWidget(self.requestmoveupbutton)
layoutbar.addWidget(self.requestaddbutton)
layoutbar.addWidget(self.requestdelbutton)
layoutbar.addWidget(self.requestrefbutton)
layoutbar.addWidget(self.requestcheckbutton)

self.requestrefbutton.setFixedWidth(80)
self.requestdelbutton.setFixedWidth(60)
self.requestaddbutton.setFixedWidth(60)
self.requestmoveupbutton.setFixedWidth(70)
self.requestcheckbutton.setFixedWidth(80)

self.requestrefbutton.clicked.connect(self.refresh_request)
self.requestdelbutton.clicked.connect(self.delete_request)
self.requestaddbutton.clicked.connect(self.add_request)
self.requestmoveupbutton.clicked.connect(self.move_up)
self.requestcheckbutton.clicked.connect(self.check_data)

layout.addLayout(layoutbar)

Expand All @@ -1130,15 +1173,54 @@ def __init__(self, parent=None):
self.requesttable.verticalHeader().hide()
self.requesttable.setSelectionBehavior(gui.QAbstractItemView.SelectRows)
self.requesttable.setSelectionMode(gui.QAbstractItemView.SingleSelection)
self.requesttable.setShowGrid(False)
#self.requesttable.setShowGrid(False)

def check_data(self):
if not self.ecurequests or not self.buttonlayout:
return

items = self.requesttable.selectedItems()
if len(items) == 0:
return

currentrowidx = items[-1].row()
requestname = self.currentbuttonparams[currentrowidx]['RequestName']

if requestname not in self.ecurequests.requests.keys():
options.main_window.logview.append("Request %s not found" % requestname)
return

request = self.ecurequests.requests[requestname]
datasenditems = request.sendbyte_dataitems
inputlayout = self.layout['inputs']

itemsfound = {}
numfound = 0
for dataitemname in datasenditems.keys():
for inp in inputlayout:
itemsfound[dataitemname] = False
if dataitemname == inp['text']:
if requestname == inp['request']:
itemsfound[dataitemname] = True
numfound += 1
break

if len(itemsfound) == numfound:
options.main_window.logview.append("<font color=green>Request <font color=blue>'%s'</font> has no missing input values</font>" % requestname)
return

options.main_window.logview.append("<font color=red>Request <font color=blue>'%s'</font> has missing inputs :</font>" % requestname)
for k, v in itemsfound.iteritems():
if not v:
options.main_window.logview.append("<font color=orange> - '%s'</font>" % k)

def clear(self):
self.requesttable.clear()

def refresh_request(self):
if not self.ecurequests or not self.buttonlayout:
return
self.init(self.ecurequests, self.buttonlayout)
self.init(self.ecurequests, self.layout)

def init(self, ecureq, layout):
self.buttonlayout = layout['buttons']
Expand Down Expand Up @@ -1256,7 +1338,7 @@ def __init__(self, parent=None):
self.buttontable.verticalHeader().hide()
self.buttontable.setSelectionBehavior(gui.QAbstractItemView.SelectRows)
self.buttontable.setSelectionMode(gui.QAbstractItemView.SingleSelection)
self.buttontable.setShowGrid(False)
#self.buttontable.setShowGrid(False)
self.buttontable.itemSelectionChanged.connect(self.selection_changed)
self.enable_view(False)

Expand Down
16 changes: 9 additions & 7 deletions ddt4all.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,6 @@ def __init__(self, parent = None):
self.progressstatus.setFixedWidth(150)
self.infostatus.setFixedWidth(200)

self.setConnected(True)

self.refreshtimebox = gui.QSpinBox()
self.refreshtimebox.setRange(100, 2000)
self.refreshtimebox.setSingleStep(100)
Expand All @@ -311,6 +309,7 @@ def __init__(self, parent = None):
self.scrollview.setWidgetResizable(False)

self.tabbedview.addTab(self.scrollview, "Screen")

if options.simulation_mode:
self.buttonEditor = dataeditor.buttonEditor()
self.requesteditor = dataeditor.requestEditor()
Expand Down Expand Up @@ -446,6 +445,8 @@ def __init__(self, parent = None):
c4ev.triggered.connect(lambda: self.virginECU('clio4EPS'))
c3ev.triggered.connect(lambda: self.virginECU('clio3EPS'))

self.setConnected(True)

def screenRename(self):
item = self.treeview_params.currentItem()
if not item:
Expand Down Expand Up @@ -649,7 +650,7 @@ def scan(self):
self.ecu_scan.send_report()

def setConnected(self, on):
if options.simultation_mode:
if options.simulation_mode:
self.connectedstatus.setStyleSheet("background : orange")
self.connectedstatus.setText("EDITION MODE")
return
Expand Down Expand Up @@ -787,10 +788,11 @@ def changeECU(self, index):
self.requesteditor.set_ecu(self.paramview.ecurequestsparser)
self.dataitemeditor.set_ecu(self.paramview.ecurequestsparser)
self.buttonEditor.set_ecu(self.paramview.ecurequestsparser)
if isxml:
self.requesteditor.enable_view(False)
self.dataitemeditor.enable_view(False)
self.buttonEditor.enable_view(False)
if isxml:
self.requesteditor.enable_view(False)
self.dataitemeditor.enable_view(False)
self.buttonEditor.enable_view(False)

self.paramview.uiscale = uiscale_mem

self.scrollview.setWidget(self.paramview)
Expand Down
2 changes: 1 addition & 1 deletion elm.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class ELM:

def __init__(self, portName, speed, startSession='10C0'):
for s in [int(speed), 38400, 115200, 230400, 57600, 9600, 500000]:
print "Tryi opening port %s at %i" % (portName, s)
print "Trying to open port %s at %i" % (portName, s)
self.sim_mode = options.simulation_mode
self.portName = portName

Expand Down

0 comments on commit b05bdbb

Please sign in to comment.