Skip to content

Commit

Permalink
Resolve confict
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricp committed Jan 8, 2018
2 parents 7f57c83 + 37034f2 commit ad2a4c7
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 22 deletions.
30 changes: 22 additions & 8 deletions ddt4all.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def utf8(string):
import tempfile, errno

__author__ = "Cedric PAILLE"
__copyright__ = "Copyright 2016-2017"
__copyright__ = "Copyright 2016-2018"
__credits__ = []
__license__ = "GPL"
__version__ = "1.0.0"
Expand Down Expand Up @@ -115,11 +115,14 @@ def scanselvehicle(self):

def init(self):
self.list.clear()
self.list.setColumnCount(3)
self.list.setColumnCount(7)
self.list.model().setHeaderData(0, core.Qt.Horizontal, _('ECU name'))
self.list.model().setHeaderData(1, core.Qt.Horizontal, _('Projets'))
self.list.model().setHeaderData(2, core.Qt.Horizontal, _('Protocol'))

self.list.model().setHeaderData(1, core.Qt.Horizontal, _('Protocol'))
self.list.model().setHeaderData(2, core.Qt.Horizontal, "Supplier")
self.list.model().setHeaderData(3, core.Qt.Horizontal, "Diag")
self.list.model().setHeaderData(4, core.Qt.Horizontal, "Soft")
self.list.model().setHeaderData(5, core.Qt.Horizontal, "Version")
self.list.model().setHeaderData(6, core.Qt.Horizontal, _('Projets'))
stored_ecus = {"Custom": []}

custom_files = glob.glob("./json/*.json.targets")
Expand Down Expand Up @@ -165,8 +168,19 @@ def init(self):
projects = "/".join(ecu.projects)
projname = u' (' + projects + u')'

if not [ecu.name, projname, ecu.protocol] in stored_ecus[grp]:
stored_ecus[grp].append([ecu.name, projname, ecu.protocol])
soft = ecu.soft
version = ecu.version
supplier = ecu.supplier
diag = ecu.diagversion

row = [ecu.name, ecu.protocol, supplier, diag, soft, version, projname]
found = False
for r in stored_ecus[grp]:
if (r[0], r[1]) == (row[0], row[1]):
found = True
break
if not found:
stored_ecus[grp].append(row)

keys = stored_ecus.keys()
keys.sort(cmp=locale.strcoll)
Expand All @@ -187,7 +201,7 @@ def filterProject(self):

items = [root_item.child(i) for i in range(root_item.childCount())]
for item in items:
if (project.upper() in str(item.text(1)).upper()) or project == "ALL":
if (project.upper() in str(item.text(6)).upper()) or project == "ALL":
item.setHidden(False)
root_hidden = False
else:
Expand Down
86 changes: 74 additions & 12 deletions ecu.py
Original file line number Diff line number Diff line change
Expand Up @@ -1124,13 +1124,16 @@ def __init__(self, diagversion, supplier, soft, version, name, group, href, prot
def checkWith(self, diagversion, supplier, soft, version, addr):
if self.diagversion == "":
return
supplier_strip = self.supplier.strip()
soft_strip = self.soft.strip()
version_strip = self.version.strip()
if int("0x" + self.diagversion, 16) != int("0x" + diagversion, 16):
return False
if self.supplier.strip() != supplier.strip():
if supplier_strip != supplier.strip()[:len(supplier_strip)]:
return False
if self.soft.strip() != soft.strip():
if soft_strip != soft.strip()[:len(soft_strip)]:
return False
if self.version.strip() != version.strip():
if version_strip != version.strip()[:len(version_strip)]:
return False

self.addr = addr
Expand Down Expand Up @@ -1415,6 +1418,7 @@ def identify_old(self, addr, label):
self.check_ecu(can_response, label, addr, "CAN")

def identify_new(self, addr, label):
printable_chars = set(string.printable)
diagversion = ""
supplier = ""
soft_version = ''
Expand All @@ -1431,6 +1435,16 @@ def identify_new(self, addr, label):
# Give scanner something to eat...
if addr == '26':
can_response = "62 F1 A0 08"
elif addr == '13':
can_response = "62 F1 A0 0D"
elif addr == '26':
can_response = "62 F1 A0 08"
elif addr == '62':
can_response = "62 F1 A0 04"
elif addr == '01':
can_response = "62 F1 A0 04"
elif addr == '04':
can_response = "62 F1 A0 04"
else:
can_response = options.elm.request(req='22F1A0', positive='', cache=False)
if 'WRONG' in can_response:
Expand All @@ -1444,6 +1458,20 @@ def identify_new(self, addr, label):
can_response = "62 F1 8A 43 4F 4E 54 49 4E 45 4E 54 41 4C 20 41 55 54 4F 4D 4F 54 49 56 45 20 20 20 20 " \
"20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 " \
"20 20 20 20 20 20 20 20 20"
elif addr == '13':
can_response = "62 F1 8A 43 41 50"
elif addr == '26':
can_response = "62 F1 8A 43 4F 4E 54 49 4E 45 4E 54 41 4C 20 41 55 54 4F 4D 4F 54 49 56 45 20 20 20 20" \
"20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20" \
"20 20 20 20 20 20 20 20 20 FF FF"
elif addr == '62':
can_response = "62 F1 8A 41 46 4B"
elif addr == '01':
can_response = "62 F1 8A 43 41 53"
elif addr == '04':
can_response = "62 F1 8A 56 69 73 74 65 6F 6E 5F 4E 61 6D 65 73 74 6F 76 6F 5F 30 39 36 20 20 20 20"\
"20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20"\
"20 20 20 20 20 20 20 20 20 20 20 20 20"
else:
can_response = options.elm.request(req='22F18A', positive='', cache=False)
if 'WRONG' in can_response:
Expand All @@ -1457,11 +1485,22 @@ def identify_new(self, addr, label):
can_response = "62 F1 94 31 34 32 36 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 " \
"20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 " \
"20 20 20 20 20 20 20 20 20"
elif addr == '13':
can_response = "62 F1 94 32 32"
elif addr == '26':
can_response = "62 F1 94 31 34 32 36 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 FF FF FF FF FF FF"
elif addr == '62':
can_response = "62 F1 94 31 30 30 30 30 30 30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 FF FF FF FF FF FF"
elif addr == '01':
can_response = "62 F1 94 4E 33 32 52 41 46 30 30 30 31 31 00 00 00 00 00 00"
elif addr == '04':
can_response = "62 F1 94 56 30 36 30 32 F1 94 56 30 36"
else:
can_response = options.elm.request(req='22F194', positive='', cache=False)
if 'WRONG' in can_response:
return False
soft = can_response.replace(' ', '')[6:38].decode('hex')
soft= filter(lambda x: x in printable_chars, soft)

# Check soft version
if options.simulation_mode:
Expand All @@ -1470,15 +1509,27 @@ def identify_new(self, addr, label):
can_response = "62 F1 95 31 30 30 30 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 " \
"20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 " \
"20 20 20 20 20 20 20 20 20"
elif addr == '13':
can_response = "62 F1 95 31 38 35 39 30 FF FF FF FF FF"
elif addr == '26':
can_response = "62 F1 95 46 30 37 2F 34 6F 00 00 00 03"
elif addr == '62':
can_response = "62 F1 95 30 35 30 31 30 30 30 32 31 37 30 30 FF FF FF FF FF"
elif addr == '01':
can_response = "62 F1 95 46 30 37 2F 34 6F 00 00 00 03"
elif addr == '04':
can_response = "62 F1 95 56 30 36 30 32 F1 95 56 30 36"
else:
can_response = options.elm.request(req='22F195', positive='', cache=False)
if 'WRONG' in can_response:
return False

# Remove unwanted non-ascii FF from string
soft_version = can_response.replace(' ', '')[6:38].decode('hex')
soft_version = filter(lambda x: x in printable_chars, soft_version)
if diagversion == "":
return False

print diagversion, supplier, soft, soft_version
self.check_ecu2(diagversion, supplier, soft, soft_version, label, addr, "CAN")
# New method succeded, return the good news
return True
Expand Down Expand Up @@ -1609,6 +1660,10 @@ def check_ecu2(self, diagversion, supplier, soft, version, label, addr, protocol
approximate_ecu = []
found_exact = False
found_approximate = False
if addr in self.ecu_database.addr_group_mapping:
ecu_type = self.ecu_database.addr_group_mapping[addr]
else:
ecu_type = "UNKNOWN"

for target in self.ecu_database.targets:
if target.protocol == "CAN" and protocol != "CAN":
Expand All @@ -1624,16 +1679,15 @@ def check_ecu2(self, diagversion, supplier, soft, version, label, addr, protocol
label.setText("Found %i ecu" % self.num_ecu_found)
found_exact = True
href = target.href
line = "<font color='green'>Identified ECU : %s DIAGVERSION [%s]"\
line = "<font color='green'>Identified ECU [%s] : %s DIAGVERSION [%s]"\
"SUPPLIER [%s] SOFT [%s] VERSION [%s]</font>"\
% (href, diagversion, supplier, soft, version)
% (ecu_type, href, diagversion, supplier, soft, version)

options.main_window.logview.append(line)
elif target.checkApproximate(diagversion, supplier, soft, addr):
approximate_ecu.append(target)
found_approximate = True


# Try to find the closest possible version of an ECU
if not found_exact and found_approximate:
min_delta_version = 0xFFFFFF
Expand All @@ -1647,7 +1701,15 @@ def check_ecu2(self, diagversion, supplier, soft, version, label, addr, protocol
ecu_protocol = "KWP"
if ecu_protocol != protocol:
continue
delta = abs(int('0x' + tgt.version, 16) - int('0x' + version, 16))

# If version contains ASCII characters, I can do nothing for you...
try:
int_version = int('0x' + version, 16)
int_tgt_version = int('0x' + tgt.version, 16)
except ValueError:
continue

delta = abs(int_tgt_version - int_version)
if delta < min_delta_version:
min_delta_version = delta
kept_ecu = tgt
Expand All @@ -1657,16 +1719,16 @@ def check_ecu2(self, diagversion, supplier, soft, version, label, addr, protocol
self.num_ecu_found += 1
label.setText("Found %i ecu" % self.num_ecu_found)

line = "<font color='red'>Found ECU (not perfect match) :"\
line = "<font color='red'>Found ECU [%s] (not perfect match) :"\
"%s DIAGVERSION [%s] SUPPLIER [%s] SOFT [%s] VERSION [%s instead %s]</font>"\
% (kept_ecu.name, diagversion, supplier, soft, version, tgt.version)
% (ecu_type, kept_ecu.name, diagversion, supplier, soft, version, tgt.version)

options.main_window.logview.append(line)

if not found_exact and not found_approximate:
line = "<font color='red'>Found ECU (no relevant ECU file found) :" \
line = "<font color='red'>Found ECU [%s] (no relevant ECU file found) :" \
"DIAGVERSION [%s] SUPPLIER [%s] SOFT [%s] VERSION [%s]</font>" \
% (diagversion, supplier, soft, version)
% (ecu_type, diagversion, supplier, soft, version)

options.main_window.logview.append(line)

Expand Down
3 changes: 1 addition & 2 deletions parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os
import ecu, elm
import displaymod
from elm import elm_checker
from uiutils import *
import options
from xml.dom.minidom import parse
Expand Down Expand Up @@ -700,7 +699,7 @@ def sendElm(self, command, auto=False):

if not options.promode:
# Allow read only modes
if command[0:2] not in options.safe_commands:
if command[0:2] in options.safe_commands:

elm_response = options.elm.request(command, cache=False)
txt = '<font color=blue>' + _('Sending ELM request :') + '</font>'
Expand Down

0 comments on commit ad2a4c7

Please sign in to comment.