diff --git a/pyren/README.md b/pyren/README.md index 2c5dd96..aceb566 100644 --- a/pyren/README.md +++ b/pyren/README.md @@ -26,6 +26,7 @@ This mode allows you: Getting started video https://www.youtube.com/watch?v=DazsvlnLCoA + ## Included tools * **doc_maker.py** - build diagnostic documentation for your car (require BVMEXTRACTION folder and extracted DocDB_xx.7ze) * **bus_monitor.py** - catch, parse and shows the content of system frames on your CAN bus. diff --git a/pyren/bus_monitor.py b/pyren/bus_monitor.py index 0b30f23..f09ff81 100755 --- a/pyren/bus_monitor.py +++ b/pyren/bus_monitor.py @@ -7,6 +7,7 @@ import pickle import codecs import string import threading +import mod_ddt_utils os.chdir(os.path.dirname(os.path.realpath(sys.argv[0]))) @@ -88,6 +89,8 @@ class DDT_MON(): clearScreen() print "Starting DDT process" + + mod_ddt_utils.searchddtroot() #make or load ddt ecu decucashfile = "./cache/ddt_"+xmlfile+".p" @@ -97,7 +100,7 @@ class DDT_MON(): else: #else self.decu = DDTECU( None ) #init class self.decu.setELM(self.elm) #define ELM for it - self.decu.loadXml( '../ecus/'+xmlfile ) #loading original data for chosen ECU + self.decu.loadXml( mod_globals.ddtroot+'/ecus/'+xmlfile )#loading original data for chosen ECU self.decu.setELM( None ) #clear elm before serialization if len(self.decu.ecufname)>0: pickle.dump( self.decu, open( decucashfile, "wb" ) ) #and save cache diff --git a/pyren/mod_ddt.py b/pyren/mod_ddt.py index 03628d5..dc25e12 100755 --- a/pyren/mod_ddt.py +++ b/pyren/mod_ddt.py @@ -136,6 +136,10 @@ class DDT(): self.decu.saveDump() # Load XML + if not self.decu.ecufname.startswith(mod_globals.ddtroot): + tmp_f_name = self.decu.ecufname.split('/')[-1] + self.decu.ecufname = mod_globals.ddtroot+'/ecus/'+tmp_f_name + if not os.path.isfile(self.decu.ecufname): print "No such file: ", self.decu.ecufname return None @@ -270,131 +274,6 @@ def optParser(): else: mod_globals.opt_protocol = '500' - -def get_addr_from_xml(xmlfile): - if '/ecus/' not in xmlfile: - xmlfile = '../ecus/' + xmlfile - - # Load XML - xdom = xml.dom.minidom.parse(xmlfile) - xdoc = xdom.documentElement - if not xdoc: - print "No such file:", xmlfile - return - - faddr = '' - cans = xdoc.getElementsByTagName("CAN") - if cans: - for can in cans: - sendid = can.getElementsByTagName("SendId") - if sendid: - for sid in sendid: - canid = sid.getElementsByTagName("CANId") - if canid: - for cid in canid: - send_can_addr = cid.getAttribute("Value") - if len(send_can_addr) > 0: - sca = hex(int(send_can_addr))[2:].upper().zfill(3) - for k in mod_elm.dnat.keys(): - if sca == mod_elm.dnat[k]: - faddr = k - - # if faddr=='': - # faddr = raw_input('Please define functional address : ') - - return faddr - - -def main_old(): - '''Main function''' - - import mod_ecu - - optParser() - - print 'Opening ELM' - elm = ELM(mod_globals.opt_port, mod_globals.opt_speed, mod_globals.opt_log) - - # change serial port baud rate - if mod_globals.opt_speed < mod_globals.opt_rate and not mod_globals.opt_demo: - elm.port.soft_boudrate(mod_globals.opt_rate) - - print "Loading language " - sys.stdout.flush() - - # loading language data - lang = optfile("../Location/DiagOnCan_" + mod_globals.opt_lang + ".bqm", True) - mod_globals.language_dict = lang.dict - print "Done" - - # check if address or xml defined - - if mod_globals.opt_ecuAddr == '' and mod_globals.opt_ddtxml != '': - mod_globals.opt_ecuAddr = get_addr_from_xml(mod_globals.opt_ddtxml) - - # if mod_globals.opt_ddtxml=='' and (mod_globals.opt_ecuAddr=='' or mod_globals.opt_ecuAddr not in mod_ecu.F2A.values()): - if mod_globals.opt_ecuAddr == '' or mod_globals.opt_ecuAddr not in mod_ecu.F2A.values(): - # ask to choose famile - fmls = [] - for f in sorted(mod_ecu.F2A.keys()): - f = str(int(f)) - if mod_scan_ecus.families[f] in mod_globals.language_dict.keys(): - x = f - if len(x) == 1: x = '0' + x - if x in mod_ecu.F2A.keys() and mod_ecu.F2A[x] in mod_elm.dnat.keys(): - fmls.append(f + ":" + mod_globals.language_dict[mod_scan_ecus.families[f]]) - ch = ChoiceLong(fmls, "Choose ECU type :") - family = ch[0].split(':')[0] - if len(family) == 1: family = '0' + family - if family in mod_ecu.F2A.keys(): - mod_globals.opt_ecuAddr = mod_ecu.F2A[family] - else: - print "ERROR : Unknown family!!!!" - sys.exit() - - addr = mod_globals.opt_ecuAddr - # if addr=='' and mod_globals.opt_ddtxml!='': - # addr = get_addr_from_xml( mod_globals.opt_ddtxml ) - - if 'S' in mod_globals.opt_protocol: - # SlowInit KWP - ecudata = {'pin': 'iso', 'slowInit': addr, 'fastInit': addr, 'ecuname': 'ddt_unknown', 'idTx': '', 'idRx': '', - 'ModelId': addr, 'protocol': 'KWP_Slow'} - mod_globals.opt_si = True - elm.init_iso() - elm.set_iso_addr(addr, ecudata) - elif 'F' in mod_globals.opt_protocol: - # FastInitKWP - ecudata = {'pin': 'iso', 'slowInit': addr, 'fastInit': addr, 'ecuname': 'ddt_unknown', 'idTx': '', 'idRx': '', - 'ModelId': addr, 'protocol': 'KWP_Fast'} - mod_globals.opt_si = False - elm.init_iso() - elm.set_iso_addr(addr, ecudata) - elif '250' in mod_globals.opt_protocol: - # CAN 250 - ecudata = {'pin': 'can', 'slowInit': '', 'fastInit': '', 'brp': '1', 'ecuname': 'ddt_unknown', 'idTx': '', - 'idRx': '', 'ModelId': addr, 'protocol': 'CAN_250'} - elm.init_can() - elm.set_can_addr(addr, ecudata) - elif '500' in mod_globals.opt_protocol: - # CAN 500 - ecudata = {'pin': 'can', 'slowInit': '', 'fastInit': '', 'brp': '0', 'ecuname': 'ddt_unknown', 'idTx': '', - 'idRx': '', 'ModelId': addr, 'protocol': 'CAN_500'} - elm.init_can() - elm.set_can_addr(addr, ecudata) - else: - print "ERROR : Unknown protocol!!!!" - sys.exit() - - ecudata['dst'] = addr - - elm.start_session('10C0') - - ddt = DDT(elm, ecudata) - - print "Done" - - class DDTLauncher(): def __init__(self): diff --git a/pyren/mod_ddt_ecu.py b/pyren/mod_ddt_ecu.py index 004de4c..c1ec489 100755 --- a/pyren/mod_ddt_ecu.py +++ b/pyren/mod_ddt_ecu.py @@ -294,10 +294,12 @@ class DDTECU(): # eculist = mod_ddt_utils.loadECUlist() #loading original data # if eculist == None: return #return if no eculist file # pickle.dump( eculist, open( eculistcache, "wb" ) ) #and save cache - + + mod_ddt_utils.searchddtroot() + if len(mod_globals.opt_ddtxml)>0: fname = mod_globals.opt_ddtxml - self.ecufname = '../ecus/'+fname + self.ecufname = mod_globals.ddtroot+'/ecus/'+fname else: problist = ecuSearch(vehTypeCode, Address, DiagVersion, Supplier, Soft, Version, eculist) @@ -312,7 +314,7 @@ class DDTECU(): fname = fname.strip() if len(fname): - self.ecufname = '../ecus/'+fname + self.ecufname = mod_globals.ddtroot+'/ecus/'+fname if os.path.isfile(self.ecufname): break else: diff --git a/pyren/pyren.py b/pyren/pyren.py index c246939..f249c90 100755 --- a/pyren/pyren.py +++ b/pyren/pyren.py @@ -3,6 +3,7 @@ import sys, os import mod_globals import mod_utils +import mod_ddt_utils os.chdir(os.path.dirname(os.path.realpath(sys.argv[0]))) @@ -290,9 +291,11 @@ def main(): verfile = open( "./cache/version09k.txt", "wb" ) verfile.write("Do not remove me if you have v0.9.k or above.\n") verfile.close() - + + mod_ddt_utils.searchddtroot() + #check if DDT present - if os.path.exists('../ecus') and mod_globals.os != 'android': + if os.path.exists(mod_globals.ddtroot+'/ecus') and mod_globals.os != 'android': mod_globals.opt_ddt = True while( 1 ):