diff --git a/ddt4all.py b/ddt4all.py index fdfb7f34..61c69414 100644 --- a/ddt4all.py +++ b/ddt4all.py @@ -175,7 +175,7 @@ def getISK(self, vehicle): options.elm.init_can() options.elm.set_can_addr('26', ecu_conf) # Entering service session - resp = options.elm.request(req='1086', positive='50', cache=False) + resp = options.elm.start_session_can('1086') if not resp.startswith("50"): self.logview.append("Connection a l'UCH pour recuperation ISK impossible") return @@ -205,7 +205,9 @@ def scan(self): self.progressstatus.setRange(0, self.ecu_scan.getNumAddr()) self.progressstatus.setValue(0) + self.ecu_scan.clear() self.ecu_scan.scan(self.progressstatus, self.infostatus) + self.ecu_scan.scan_kwp(self.progressstatus, self.infostatus) self.treeview_ecu.clear() self.treeview_params.clear() diff --git a/ecu.py b/ecu.py index 0bfa6d45..d480afdd 100644 --- a/ecu.py +++ b/ecu.py @@ -20,7 +20,7 @@ class Data_item: def __init__(self, item, req_endian): self.firstbyte = 0 self.bitoffset = 0 - self.ref = None + self.ref = False self.req_endian = req_endian self.endian = '' self.name = item.getAttribute("Name") @@ -503,18 +503,18 @@ def getNumAddr(self): def addTarget(self, target): self.ecus[target.name] = target - def scan(self, progress=None, label=None): + def clear(self): self.totalecu = 0 self.ecus = {} self.num_ecu_found = 0 + def scan(self, progress=None, label=None): if options.simulation_mode: self.ecus["UCH_84_J84_04_00"] = Ecu_ident("000", "000", "000", "00", "UCH", "GRP", "UCH_84_J84_04_00.xml", "DiagOnCan") self.ecus["Tdb_BCEKL84_serie_4emeRev."] = Ecu_ident("000", "000", "000", "00", "TdB", "GRP", "Tdb_BCEKL84_serie_4emeRev.xml", "DiagOnCan") self.ecus["ACU4_X84_MK2"] = Ecu_ident("000", "000", "000", "00", "ACU", "GRP", "ACU4_X84_MK2.xml", "DiagOnCan") self.ecus["Abs_X84_Bosch8.1"] = Ecu_ident("000", "000", "000", "00", "ACU", "GRP", "Abs_X84_Bosch8.1_V1.3.xml", "DiagOnCan") - # TODO : implement other protocols i = 0 options.elm.init_can() @@ -546,6 +546,35 @@ def scan(self, progress=None, label=None): self.num_ecu_found += 1 label.setText("Found %i ecu" % self.num_ecu_found) + def scan_kwp(self, progress=None, label=None): + if options.simulation_mode: + self.ecus["S2000_Atmo__SoftA3"] = Ecu_ident("004", "213", "00A5", "8300", "UCH", "GRP", "S2000_Atmo___SoftA3.xml", + "KWP2000 FastInit MonoPoint") + + i = 0 + options.elm.init_iso() + for addr in elm.snat.keys(): + progress.setValue(i) + i += 1 + txa, rxa = options.elm.set_can_addr(addr, {'idTx': '', 'idRx': '', 'ecuname': 'SCAN', 'protocol': "KWP2000"}) + options.elm.start_session_iso('10C0') + + if not options.simulation_mode: + can_response = options.elm.request(req='2180', positive='61', cache=False) + else: + continue + + if len(can_response) > 59: + diagversion = str(int(can_response[21:23], 16)) + supplier = can_response[24:32].replace(' ', '').decode('hex') + soft = can_response[48:53].replace(' ', '') + version = can_response[54:59].replace(' ', '') + + for target in self.ecu_database.targets: + if target.checkWith(diagversion, supplier, soft, version, addr): + self.ecus[target.name] = target + self.num_ecu_found += 1 + label.setText("Found %i ecu" % self.num_ecu_found) if __name__ == '__main__': ecur = Ecu_file("ecus/UCH_84_J84_04_00.xml", True) diff --git a/elm.py b/elm.py index a7baf7d8..1c8155ad 100644 --- a/elm.py +++ b/elm.py @@ -910,9 +910,6 @@ def set_can_addr(self, addr, ecu): if self.currentprotocol == "can" and self.currentaddress == addr: return - #if len(ecu['idTx']): dnat[addr] = ecu['idTx'] - #if len(ecu['idRx']): snat[addr] = ecu['idRx'] - if self.lf != 0: self.lf.write('#' * 60 + "\n#connect to: " + ecu['ecuname'] + " Addr:" + addr + "\n" + '#' * 60 + "\n") self.lf.flush() @@ -940,7 +937,7 @@ def set_can_addr(self, addr, ecu): def start_session_iso(self, start_session): self.startSession = start_session - # self.cmd("81") + if len(self.startSession) > 0: self.lastinitrsp = self.cmd(self.startSession) diff --git a/options.py b/options.py index cc47ae65..9e9db524 100644 --- a/options.py +++ b/options.py @@ -10,4 +10,5 @@ log_all = False auto_refresh = False elm_failed = False -opt_si=True +# KWP2000 Slow init +opt_si=False diff --git a/parameters.py b/parameters.py index f455a4de..44ce9f18 100644 --- a/parameters.py +++ b/parameters.py @@ -50,6 +50,9 @@ def __init__(self, parent, ddtfile, ecu_addr, ecu_name, logview): self.ecurequestsparser = None self.can_send_id = '' self.can_rcv_id = '' + self.iso_send_id = '' + self.iso_rcv_id = '' + self.iso_fastinit = False self.panel = None self.uiscale = 10 self.ecu_address = ecu_addr @@ -89,6 +92,11 @@ def initELM(self): ecu_conf = {'idTx': '', 'idRx': '', 'ecuname': str(self.ecu_name)} options.elm.init_can() options.elm.set_can_addr(self.ecu_addr, ecu_conf) + elif self.protocol == 'KWP2000': + ecu_conf = {'idTx': '', 'idRx': '', 'ecuname': str(self.ecu_name), 'protocol': 'KWP2000'} + options.elm.init_iso() + options.elm.set_iso_addr(self.iso_send_id, ecu_conf) + options.opt_si = not self.iso_fastinit else: self.logview.append("Protocole " + self.protocol + " non supporte") @@ -127,6 +135,20 @@ def initXML(self): if can_id: self.can_rcv_id = hex(int(can_id[0].getAttribute("Value"))) + k = self.getChildNodesByName(target, u"K") + if k: + kwp = self.getChildNodesByName(k[0], u"KWP") + if kwp: + kwp = kwp[0] + self.protocol = "KWP2000" + fastinit = self.getChildNodesByName(kwp, "FastInit") + if fastinit: + self.iso_fastinit = True + self.iso_rcv_id = hex(int(self.getChildNodesByName(fastinit[0], "KW1")[0].getAttribute("Value")))[2:].upper() + self.iso_send_id = hex(int(self.getChildNodesByName(fastinit[0], "KW2")[0].getAttribute("Value")))[2:].upper() + else: + self.logview.append("Determination protocol KWP2000 impossible") + categories = self.getChildNodesByName(target, u"Categories") for cats in categories: @@ -535,6 +557,8 @@ def updateDisplay(self, request_name, update_inputs=False): qlabel = data_struct.widget ecu_data = data_struct.data data_item = request.dataitems[ecu_data.name] + #if not data_item.ref: + # continue value = ecu_data.getDisplayValue(elm_response, data_item, request.endian) if value == None: @@ -556,7 +580,10 @@ def updateDisplay(self, request_name, update_inputs=False): def updateDisplays(self, update_inputs= False): # Begin diag session if not options.simulation_mode: - options.elm.start_session_can('10C0') + if self.protocol == "CAN": + options.elm.start_session_can('10C0') + elif self.protocol == "KWP2000": + options.elm.start_session_iso('10C0') # tag management # Manage pre send commands @@ -577,7 +604,10 @@ def updateDisplays(self, update_inputs= False): def readDTC(self): if not options.simulation_mode: - options.elm.start_session_can('10C0') + if self.protocol == "CAN": + options.elm.start_session_can('10C0') + elif self.protocol == "KWP2000": + options.elm.start_session_iso('10C0') request = self.ecurequestsparser.requests["ReadDTC"] sendbyte_dataitems = request.sendbyte_dataitems