From a91dc2de24047cab7dc2c173e783ffaaca678852 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Mon, 9 Mar 2020 19:47:01 +0100 Subject: [PATCH] paraminj2 update and other fixes --- pyren/mod_ecu.py | 30 ++-- pyren/mod_utils.py | 2 +- pyren/scen_ecri_counter2.py | 1 - pyren/scen_ecri_paraminj1.py | 2 +- pyren/scen_ecri_paraminj2.py | 282 +++++++++++++++++++++++++---------- 5 files changed, 225 insertions(+), 92 deletions(-) diff --git a/pyren/mod_ecu.py b/pyren/mod_ecu.py index 64bd795..dd2c80e 100755 --- a/pyren/mod_ecu.py +++ b/pyren/mod_ecu.py @@ -189,7 +189,7 @@ class ECU: flist = [] for root, dirs, files in os.walk("./dumps"): for f in files: - if (self.ecudata['ecuname']+'.') in f: + if (self.ecudata['ecuname']+'.txt') in f: flist.append(f) if len(flist)==0: return @@ -720,10 +720,14 @@ class ECU: path = path+' -> '+defstr[dtchex]+'\n\n'+hlpstr[dtchex]+'\n' - mem_dtrf_txt = mod_globals.language_dict['299'] + " DTC" + mod_globals.ext_cur_DTC + "\n" + cur_dtrf = [] + mem_dtrf = [] - cur_dtrf = [ecu_screen_dataref(0, "\n" + mod_globals.language_dict['300'] + "\n", 'Text')] + self.Defaults[dtchex[:4]].datarefs - mem_dtrf = [ecu_screen_dataref(0, mem_dtrf_txt, 'Text')] + self.Defaults[dtchex[:4]].memDatarefs + if self.Defaults[dtchex[:4]].datarefs: + cur_dtrf = [ecu_screen_dataref(0, "\n" + mod_globals.language_dict['300'] + "\n", 'Text')] + self.Defaults[dtchex[:4]].datarefs + if self.Defaults[dtchex[:4]].memDatarefs: + mem_dtrf_txt = mod_globals.language_dict['299'] + " DTC" + mod_globals.ext_cur_DTC + "\n" + mem_dtrf = [ecu_screen_dataref(0, mem_dtrf_txt, 'Text')] + self.Defaults[dtchex[:4]].memDatarefs tmp_dtrf = mem_dtrf + cur_dtrf @@ -765,13 +769,19 @@ class ECU: mod_globals.ext_cur_DTC = dtchex path = path+' -> '+defstr[dtchex]+'\n\n'+hlpstr[dtchex]+'\n' - - mem_dtrf_txt = mod_globals.language_dict['299'] + " DTC" + mod_globals.ext_cur_DTC + "\n" - cur_dtrf = [ecu_screen_dataref(0, "\n" + mod_globals.language_dict['300'] + "\n", 'Text')] + self.Defaults[dtchex[:4]].datarefs - mem_dtrf = [ecu_screen_dataref(0, mem_dtrf_txt, 'Text')] + self.Defaults[dtchex[:4]].memDatarefs - ext_info_dtrf = [ecu_screen_dataref(0, "\n" + mod_globals.language_dict['1691'] + "\n", 'Text')] + self.ext_de - + cur_dtrf = [] + mem_dtrf = [] + ext_info_dtrf = [] + + if self.Defaults[dtchex[:4]].datarefs: + cur_dtrf = [ecu_screen_dataref(0, "\n" + mod_globals.language_dict['300'] + "\n", 'Text')] + self.Defaults[dtchex[:4]].datarefs + if self.Defaults[dtchex[:4]].memDatarefs: + mem_dtrf_txt = mod_globals.language_dict['299'] + " DTC" + mod_globals.ext_cur_DTC + "\n" + mem_dtrf = [ecu_screen_dataref(0, mem_dtrf_txt, 'Text')] + self.Defaults[dtchex[:4]].memDatarefs + if self.ext_de: + ext_info_dtrf = [ecu_screen_dataref(0, "\n" + mod_globals.language_dict['1691'] + "\n", 'Text')] + self.ext_de + tmp_dtrf = mem_dtrf + cur_dtrf + ext_info_dtrf #self.show_datarefs(self.Defaults[dtchex[:4]].datarefs, path) diff --git a/pyren/mod_utils.py b/pyren/mod_utils.py index 7015f28..6a1a420 100755 --- a/pyren/mod_utils.py +++ b/pyren/mod_utils.py @@ -358,7 +358,7 @@ def loadDumpToELM( ecuname, elm ): flist = [] for root, dirs, files in os.walk("./dumps"): for f in files: - if (ecuname+'.') in f: + if (ecuname+'.txt') in f: flist.append(f) if len(flist)==0: return diff --git a/pyren/scen_ecri_counter2.py b/pyren/scen_ecri_counter2.py index 15c6f11..38b927e 100644 --- a/pyren/scen_ecri_counter2.py +++ b/pyren/scen_ecri_counter2.py @@ -89,7 +89,6 @@ def run( elm, ecu, command, data ): paramsToSend = mnemo1Data + resetBytes + mnemo2Data - print mod_ecu_mnemonic.get_mnemonicDTC(ecu.Mnemonics["_CSF_UPSTREAM_TEMPERATURE"], "62 24 42 0F 44 00 00") print title print '*'*80 print messageInfo diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 92c9ba0..f70b816 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -220,7 +220,7 @@ def run( elm, ecu, command, data ): buttons["exit"] = '' #Get commands - commands = OrderedDict() + commands = {} for child in root: if child.attrib["name"] == "Commands": diff --git a/pyren/scen_ecri_paraminj2.py b/pyren/scen_ecri_paraminj2.py index 7c96c4f..2306f07 100644 --- a/pyren/scen_ecri_paraminj2.py +++ b/pyren/scen_ecri_paraminj2.py @@ -59,18 +59,24 @@ def run( elm, ecu, command, data ): correctEcu = '' vdiagExists = False - def get_message( msg ): + def get_message( msg, encode = 1 ): if msg in ScmParam.keys(): value = ScmParam[msg] else: value = msg if value.isdigit() and value in mod_globals.language_dict.keys(): - value = mod_globals.language_dict[value] + if encode: + value = pyren_encode(mod_globals.language_dict[value]) + else: + value = mod_globals.language_dict[value] return value - def get_message_by_id( id ): + def get_message_by_id( id, encode = 1 ): if id.isdigit() and id in mod_globals.language_dict.keys(): - value = mod_globals.language_dict[id] + if encode: + value = pyren_encode(mod_globals.language_dict[id]) + else: + value = mod_globals.language_dict[id] return value # @@ -142,19 +148,20 @@ def run( elm, ecu, command, data ): for bt in correctEcu.buttons.keys(): if bt == 'InjectorsButton': if str(correctEcu.buttons[bt]) == 'true': - buttons[1] = get_message("Injectors") + buttons[1] = get_message("Injectors",0) if bt == 'EGRValveButton': if str(correctEcu.buttons[bt]) == 'true': - buttons[2] = get_message("EGR_VALVE") + buttons[2] = get_message("EGR_VALVE",0) if bt == 'InletFlapButton': if str(correctEcu.buttons[bt]) == 'true': - buttons[3] = get_message("INLET_FLAP") + buttons[3] = get_message("INLET_FLAP",0) if bt == 'ParticleFilterButton': if str(correctEcu.buttons[bt]) == 'true': - buttons[4] = get_message("PARTICLES_FILTER") + buttons[4] = get_message("PARTICLES_FILTER",0) if bt.startswith("Button"): if str(correctEcu.buttons[bt]) == 'true': - buttons[int(bt.strip('Button'))] = get_message(bt[:-6] + "Text") + buttons[int(bt.strip('Button'))] = get_message(bt[:-6] + "Text", 0) + buttons["loadDump"] = get_message_by_id('19802', 0) buttons["exit"] = '' #Get commands @@ -164,7 +171,13 @@ def run( elm, ecu, command, data ): if child.attrib["name"] == "Commands": if len(child.keys()) == 1: for param in child: - commands[param.attrib["name"]] = param.attrib["value"] + serviceIDs = ecu.get_ref_cmd(param.attrib["value"]).serviceID + startReq = "" + for sid in serviceIDs: + if ecu.Services[sid].params: + startReq = ecu.Services[sid].startReq + break + commands[param.attrib["name"]] = {"command": param.attrib["value"], "startReq": startReq} #Get identifications identsList = OrderedDict() @@ -175,14 +188,15 @@ def run( elm, ecu, command, data ): key = param[6:-5] begin = int(ScmParam['Idents'+key+'Begin']) end = int(ScmParam['Idents'+key+'End']) - identsRangeKeys[key] = {"begin": begin, "end": end} try: #10099 trap - identsList['D'+str(begin)] = ScmParam['Ident'+str(begin)] + ecu.get_ref_id(ScmParam['Ident' + str(begin)]).mnemolist[0] except: - break + continue else: for idnum in range(begin ,end + 1): identsList['D'+str(idnum)] = ScmParam['Ident'+str(idnum)] + frame = ecu.Mnemonics[ecu.get_ref_id(identsList['D'+str(begin)]).mnemolist[0]].request + identsRangeKeys[key] = {"begin": begin, "end": end, "frame": frame} def getValuesToChange(resetItem): params = {} @@ -192,16 +206,45 @@ def run( elm, ecu, command, data ): for param in child: params[param.attrib["name"].replace("D0", "D")] = param.attrib["value"] return params - - def getValuesFromEcu(rangeKey): - paramToSend = "" - idRangeKey = identsRangeKeys[identsRangeKeys.keys()[rangeKey]] - for idKey in range(idRangeKey['begin'], idRangeKey['end'] + 1): - if identsList["D" + str(idKey)].startswith("ID"): - identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) - paramToSend += identsList["D" + str(idKey)] - return paramToSend + def takesParams(request): + for cmd in commands.values(): + if cmd['startReq'] == request: + commandToRun = cmd['command'] + return commandToRun + + def getValuesFromEcu(params): + paramToSend = "" + commandToRun = "" + requestToFindInCommandsRequests = "" + backupDict = {} + + try: + idKeyToFindInRange = int((params.keys()[0]).replace("D","")) + except: + return commandToRun, paramToSend + else: + for rangeK in identsRangeKeys.keys(): + if identsRangeKeys[rangeK]['begin'] <= idKeyToFindInRange <= identsRangeKeys[rangeK]['end']: + requestToFindInCommandsRequests = "3B" + identsRangeKeys[rangeK]['frame'][-2:] + isTakingParams = takesParams(requestToFindInCommandsRequests) + if isTakingParams: + for k,v in params.iteritems(): + backupDict[k] = ecu.get_id(identsList[k], 1) + if v in identsList.keys(): + identsList[k] = ecu.get_id(identsList[v], 1) + else: + identsList[k] = v + for idKey in range(identsRangeKeys[rangeK]['begin'], identsRangeKeys[rangeK]['end'] + 1): + if identsList["D" + str(idKey)].startswith("ID"): + identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) + backupDict["D" + str(idKey)] = identsList["D" + str(idKey)] + paramToSend += identsList["D" + str(idKey)] + commandToRun = isTakingParams + break + + makeDump(commandToRun, backupDict) + return commandToRun, paramToSend confirm = get_message_by_id('19800') successMessage = get_message('Message32') @@ -239,7 +282,7 @@ def run( elm, ecu, command, data ): print ch = raw_input('Press ENTER to exit') - def afterEcuChange(title, button, command, rangeKey): + def afterEcuChange(title, button): params = getValuesToChange(title) infoMessage = get_message("Message262") mileageText = get_message_by_id('2110') @@ -254,20 +297,20 @@ def run( elm, ecu, command, data ): print '*'*80 print get_message("MessageBox2") print - ch = raw_input(pyren_encode(confirm + ' : ')) + ch = raw_input(confirm + ' : ') if ch.upper()!='YES': return - mileage = raw_input(pyren_encode(mileageText + ' (' + mileageUnit + ')' + ': ')) + mileage = raw_input(mileageText + ' (' + mileageUnit + ')' + ': ') while not (mileage.isdigit() and 2 <= len(mileage) <= 6 and int(mileage) >= 10): print get_message("MessageBox1") print - mileage = raw_input(pyren_encode(mileageText + ' (' + mileageUnit + ')' + ': ')) + mileage = raw_input(mileageText + ' (' + mileageUnit + ')' + ': ') clearScreen() print mileageText + ': ' + mileage + ' ' + mileageUnit print - ch = raw_input(pyren_encode(confirm + ' : ')) + ch = raw_input(confirm + ' : ') while (ch.upper()!='YES') and (ch.upper()!='NO'): ch = raw_input(confirm + ' : ') if ch.upper()!='YES': @@ -280,16 +323,27 @@ def run( elm, ecu, command, data ): mileage = int(mileage) - for k,v in params.iteritems(): - if v in identsList.keys(): - identsList[k] = ecu.get_id(identsList[v], 1) - elif v == "Mileage": - identValue = ecu.get_id(identsList[k], 1) - identsList[k] = "{0:0{1}X}".format(mileage,len(identValue)) - else: - identsList[k] = v + for paramkey in params.keys(): + if params[paramkey] == "Mileage": + mnemonics = ecu.get_ref_id(identsList[paramkey]).mnemolist[0] + identValue = ecu.get_id(identsList[paramkey], 1) + if identValue == 'ERROR': + identValue = '00000000' + hexval = "{0:0{1}X}".format(mileage,len(identValue)) + if ecu.Mnemonics[mnemonics].littleEndian == '1': + a = hexval + b = '' + if not len(a) % 2: + for i in range(0,len(a),2): + b = a[i:i+2]+b + hexval = b + params[paramkey] = hexval - paramToSend = getValuesFromEcu(rangeKey) + command, paramToSend = getValuesFromEcu(params) + + if "ERROR" in paramToSend: + raw_input("Data downloading went wrong. Aborting.") + return clearScreen() @@ -305,7 +359,7 @@ def run( elm, ecu, command, data ): print ch = raw_input('Press ENTER to exit') - def setGlowPlugsType(title, button, command, rangeKey): + def setGlowPlugsType(title, button): params = getValuesToChange(title) value, datastr = ecu.get_st(ScmParam['State1']) @@ -314,9 +368,9 @@ def run( elm, ecu, command, data ): typesButtons = OrderedDict() - typesButtons[get_message_by_id('54031')] = ScmParam['54031'] - typesButtons[get_message_by_id('54030')] = ScmParam['54030'] - typesButtons[get_message_by_id('54032')] = ScmParam['54032'] + typesButtons[get_message_by_id('54031',0)] = ScmParam['54031'] + typesButtons[get_message_by_id('54030',0)] = ScmParam['54030'] + typesButtons[get_message_by_id('54032',0)] = ScmParam['54032'] typesButtons[''] = "" clearScreen() @@ -341,9 +395,13 @@ def run( elm, ecu, command, data ): glowPlugType = "{0:0{1}X}".format((int(ScmParam['Mask1']) + int(typesButtons[choice[0]])),2) - identsList[params.keys()[0]] = glowPlugType + params[params.keys()[0]] = glowPlugType - paramToSend = getValuesFromEcu(rangeKey) + command, paramToSend = getValuesFromEcu(params) + + if "ERROR" in paramToSend: + raw_input("Data downloading went wrong. Aborting.") + return clearScreen() @@ -359,28 +417,11 @@ def run( elm, ecu, command, data ): print ch = raw_input('Press ENTER to exit') - def resetValues(title, button, command, rangeKey): + def resetValues(title, button, defaultCommand): paramToSend = "" commandTakesParams = True params = getValuesToChange(title) - commandServices = ecu.Commands[command.replace("VP", "V")].serviceID - for sid in commandServices: - if not ecu.Services[sid].params: #For INLET_FLAP VP042 in 10959 or VP018 EGR_VALVE in 10527 - commandTakesParams = False - else: - commandTakesParams = True - break - - if commandTakesParams: - for k,v in params.iteritems(): - if v in identsList.keys(): - identsList[k] = ecu.get_id(identsList[v], 1) - else: - identsList[k] = v - - paramToSend = getValuesFromEcu(rangeKey) - clearScreen() print mainText @@ -394,7 +435,91 @@ def run( elm, ecu, command, data ): print get_message_by_id('55663') print '*'*80 print - ch = raw_input(pyren_encode(confirm + ' : ')) + ch = raw_input(confirm + ' : ') + while (ch.upper()!='YES') and (ch.upper()!='NO'): + ch = raw_input(confirm + ' : ') + if ch.upper()!='YES': + return + + clearScreen() + print + print inProgressMessage + + command, paramToSend = getValuesFromEcu(params) + + if "ERROR" in paramToSend: + raw_input("Data downloading went wrong. Aborting.") + return + + clearScreen() + + print + if command: + response = ecu.run_cmd(command,paramToSend) + else: + response = ecu.run_cmd(defaultCommand) + print + + if "NR" in response: + print failMessage + else: + print successMessage + + print + ch = raw_input('Press ENTER to exit') + + def makeDump(cmd, idents): + fileRoot = et.Element("ScmRoot") + fileRoot.text = "\n " + + cmdElement = et.Element("ScmParam", name="Command", value=cmd) + cmdElement.tail = "\n " + fileRoot.insert(1,cmdElement) + + for k in idents: + el = et.Element("ScmParam", name='D'+ '{:0>2}'.format(k[1:]), value=idents[k]) + el.tail = "\n " + fileRoot.insert(1,el) + + tree = et.ElementTree(fileRoot) + tree.write(mod_globals.dumps_dir + ScmParam['FileName']) + + def loadDump(): + clearScreen() + + paramToSend = "" + dumpScmParam = {} + try: + dumpData = open(mod_globals.dumps_dir + ScmParam['FileName'], 'r') + except: + print get_message_by_id('2194') + raw_input() + return + + dumpDOMTree = xml.dom.minidom.parse(dumpData) + dumpScmRoot = dumpDOMTree.documentElement + dumpScmParams = dumpScmRoot.getElementsByTagName("ScmParam") + + for Param in dumpScmParams: + name = pyren_encode( Param.getAttribute("name") ) + value = pyren_encode( Param.getAttribute("value") ) + + dumpScmParam[name] = value + + for k in sorted(dumpScmParam): + if k != "Command": + paramToSend += dumpScmParam[k] + + if "ERROR" in paramToSend: + raw_input("Data downloading went wrong. Aborting.") + return + + print '*'*80 + print get_message_by_id('19802') + print '*'*80 + print + + ch = raw_input(confirm + ' : ') while (ch.upper()!='YES') and (ch.upper()!='NO'): ch = raw_input(confirm + ' : ') if ch.upper()!='YES': @@ -403,10 +528,7 @@ def run( elm, ecu, command, data ): clearScreen() print - if commandTakesParams: - response = ecu.run_cmd(command,paramToSend) - else: - response = ecu.run_cmd(command) + response = ecu.run_cmd(dumpScmParam['Command'],paramToSend) print if "NR" in response: @@ -422,22 +544,22 @@ def run( elm, ecu, command, data ): for cmdKey in commands.keys(): if cmdKey == 'Cmd1' and "Cmd5" in commands.keys(): injectorsDict = OrderedDict() - injectorsDict[get_message('Cylinder1')] = commands['Cmd1'] - injectorsDict[get_message('Cylinder2')] = commands['Cmd2'] - injectorsDict[get_message('Cylinder3')] = commands['Cmd3'] - injectorsDict[get_message('Cylinder4')] = commands['Cmd4'] + injectorsDict[get_message('Cylinder1', 0)] = commands['Cmd1']['command'] + injectorsDict[get_message('Cylinder2', 0)] = commands['Cmd2']['command'] + injectorsDict[get_message('Cylinder3', 0)] = commands['Cmd3']['command'] + injectorsDict[get_message('Cylinder4', 0)] = commands['Cmd4']['command'] injectorsDict[''] = "" functions[1] = [1, injectorsDict] if cmdKey == 'Cmd5': - functions[2] = ["EGR_VALVE", 2, commands['Cmd5'], 0] + functions[2] = ["EGR_VALVE", 2, commands['Cmd5']['command']] if cmdKey == 'Cmd6': - functions[3] = ["INLET_FLAP", 3, commands['Cmd6'], 1] + functions[3] = ["INLET_FLAP", 3, commands['Cmd6']['command']] if cmdKey == 'Cmd7': - functions[4] = ["PARTICLE_FILTER", 4, commands['Cmd7'], 2] - functions[5] = ["Button5ChangeData", 5, commands['Cmd7'], 2] - functions[6] = ["Button6ChangeData", 6, commands['Cmd7'], 2] + functions[4] = ["PARTICLE_FILTER", 4, commands['Cmd7']['command']] + functions[5] = ["Button5ChangeData", 5, commands['Cmd7']['command']] + functions[6] = ["Button6ChangeData", 6, commands['Cmd7']['command']] if len(commands) == 1 and cmdKey == 'Cmd1': - functions[7] = ["Button7ChangeData", 7, commands["Cmd1"], len(identsRangeKeys) - 1] + functions[7] = ["Button7ChangeData", 7] infoMessage = get_message('Message1') @@ -451,12 +573,14 @@ def run( elm, ecu, command, data ): for key, value in buttons.iteritems(): if choice[0]=='': return if value == choice[0]: - if key == 1: + if key == 'loadDump': + loadDump() + elif key == 1: resetInjetorsData(functions[key][0],functions[key][1]) elif key == 6: - afterEcuChange(functions[key][0],functions[key][1],functions[key][2],functions[key][3]) + afterEcuChange(functions[key][0],functions[key][1]) elif key == 7: - setGlowPlugsType(functions[key][0],functions[key][1],functions[key][2],functions[key][3]) + setGlowPlugsType(functions[key][0],functions[key][1]) else: - resetValues(functions[key][0],functions[key][1],functions[key][2],functions[key][3]) + resetValues(functions[key][0],functions[key][1],functions[key][2]) return \ No newline at end of file