From 0017625e035bf9623c9dfd832a78e8c7e2d602c9 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Mon, 3 Feb 2020 23:13:34 +0100 Subject: [PATCH 01/57] Test 1 --- pyren/mod_ecu.py | 4 +- pyren/mod_ecu_identification.py | 6 +- pyren/mod_ecu_mnemonic.py | 5 +- pyren/scen_ecri_paraminj1.py | 455 ++++++++++++++++++++++++++++++++ pyren/scen_ecri_paraminj2.py | 102 +++++++ 5 files changed, 568 insertions(+), 4 deletions(-) create mode 100644 pyren/scen_ecri_paraminj1.py create mode 100644 pyren/scen_ecri_paraminj2.py diff --git a/pyren/mod_ecu.py b/pyren/mod_ecu.py index 4ecd032..c245581 100755 --- a/pyren/mod_ecu.py +++ b/pyren/mod_ecu.py @@ -255,7 +255,7 @@ class ECU: return None return self.Parameters[name] - def get_id( self, name ): + def get_id( self, name, raw = 0): if name not in self.Identifications.keys(): for i in self.Identifications.keys(): if name==self.Identifications[i].codeMR: @@ -264,6 +264,8 @@ class ECU: if name not in self.Identifications.keys(): return 'none','unknown identification' self.elm.clear_cache() + if raw: + return get_identification( self.Identifications[name], self.Mnemonics, self.Services, self.elm, self.calc, raw) datastr, help, csvd = get_identification( self.Identifications[name], self.Mnemonics, self.Services, self.elm, self.calc ) return csvd, datastr diff --git a/pyren/mod_ecu_identification.py b/pyren/mod_ecu_identification.py index 99881dd..6d4e512 100755 --- a/pyren/mod_ecu_identification.py +++ b/pyren/mod_ecu_identification.py @@ -7,11 +7,13 @@ from xml.dom.minidom import parseString import xml.dom.minidom import mod_globals -def get_identification( id, mn, se, elm, calc ): +def get_identification( id, mn, se, elm, calc, raw = 0 ): comp = id.computation comp = comp.replace("&","&") for m in sorted(id.mnemolist, key=len, reverse=True): - hex_val = get_mnemonic( mn[m], se, elm ) + hex_val = get_mnemonic( mn[m], se, elm, raw) + if raw: + return hex_val comp = comp.replace(m, hex_val) id.value = calc.calculate(comp) ###### diff --git a/pyren/mod_ecu_mnemonic.py b/pyren/mod_ecu_mnemonic.py index 563a5ec..c2c2c52 100755 --- a/pyren/mod_ecu_mnemonic.py +++ b/pyren/mod_ecu_mnemonic.py @@ -33,7 +33,7 @@ def get_mnemonicDTC( m, resp ): return hexval -def get_mnemonic( m, se, elm ): +def get_mnemonic( m, se, elm, raw = 0 ): #get responce if len(m.sids)>0: @@ -64,6 +64,9 @@ def get_mnemonic( m, se, elm ): hexval = resp[sb*3:(sb+bytes)*3-1] hexval = hexval.replace(" ","") + if raw: + return hexval + #shift and mask val = (int(hexval,16)>>rshift)&(2**bits-1) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py new file mode 100644 index 0000000..45f5ffd --- /dev/null +++ b/pyren/scen_ecri_paraminj1.py @@ -0,0 +1,455 @@ +#!/usr/bin/env python +''' +Scenarium usage example + +Name of this script should be exactly the same as in scenaruim URL but with '.py' extension + +URL - scm:scen_ecri_calinj1#scen_ecri_calinj1_xxxxx.xml + +'run' procedure will be executed by pyren script + +''' + +import os +import sys +import re +import time +import string +import mod_globals +import mod_utils +import mod_ecu +from mod_utils import pyren_encode +from mod_utils import clearScreen +from mod_utils import ASCIITOHEX +from mod_utils import StringToIntToHex +from mod_utils import Choice +from collections import OrderedDict +import xml.dom.minidom +import xml.etree.cElementTree as et + +class ecus: + + vdiag = "" + buttons = {} + ncalib = "" + + def __init__(self, vd, nc, bt): + self.vdiag = vd + self.ncalib = nc + self.buttons = bt + +def run( elm, ecu, command, data ): + ''' + MAIN function of scenarium + + Parameters: + elm - refernce to adapter class + ecu - reference to ecu class + command - refernce to the command this scenarium belongs to + data - name of xml file with parameters from scenarium URL + ''' + + clearScreen() + header = '['+command.codeMR+'] '+command.label + + ScmSet = {} + ScmParam = OrderedDict() + ecusList = [] + correctEcu = '' + vdiagExists = False + ncalibExists = False + + def get_message( msg ): + 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] + return value + + def get_message_by_id( id ): + if id.isdigit() and id in mod_globals.language_dict.keys(): + value = pyren_encode( mod_globals.language_dict[id] ) + return value + + # + # Data file parsing + # + DOMTree = xml.dom.minidom.parse(data) + ScmRoom = DOMTree.documentElement + + root = et.parse(data).getroot() + + ScmParams = ScmRoom.getElementsByTagName("ScmParam") + + for Param in ScmParams: + name = pyren_encode( Param.getAttribute("name") ) + value = pyren_encode( Param.getAttribute("value") ) + + ScmParam[name] = value + + ScmSets = ScmRoom.getElementsByTagName("ScmSet") + + for Set in ScmSets: + if len(Set.attributes) != 1: + setname = pyren_encode(mod_globals.language_dict[Set.getAttribute("name")]) + ScmParams = Set.getElementsByTagName("ScmParam") + + for Param in ScmParams: + name = pyren_encode( Param.getAttribute("name") ) + value = pyren_encode( Param.getAttribute("value") ) + + ScmSet[setname]= value + ScmParam[name] = value + + if "VDiag" in ScmParam.keys(): + vdiagExists = True + if "Ncalib" in ScmParam.keys(): + ncalibExists = True + + # Get nested buttons with VDiag and Ncalib + for vDiag in root: + if vDiag.attrib["name"] == "VDiag": + if len(vDiag.keys()) == 1: + for vDiagName in vDiag: + if vDiagName: + for vDiagButtons in vDiagName: + buttons = OrderedDict() + if vDiagButtons.attrib["name"] == "Ncalib": + for ncalibName in vDiagButtons: + for ncalibButtons in ncalibName: + if ncalibButtons.attrib["name"] == "Buttons": + for ncalibButton in ncalibButtons: + buttons[ncalibButton.attrib["name"]] = ncalibButton.attrib["value"] + ecusList.append(ecus(vDiagName.attrib["name"],ncalibName.attrib["name"], buttons)) + else: + if vDiagButtons.attrib["name"] == "Buttons": + for vDiagButton in vDiagButtons: + buttons[vDiagButton.attrib["name"]] = vDiagButton.attrib["value"] + ecusList.append(ecus(vDiagName.attrib["name"], '', buttons)) + +# Get plain buttons with VDiag + if vdiagExists: + if not ncalibExists: + vdiag = '' + buttons = OrderedDict() + for name in ScmParam.keys(): + if name.startswith("InjectorsButton"): + if buttons: + ecusList.append(ecus(vdiag, '', buttons)) + buttons = OrderedDict() + vdiag = name[-2:] + buttons[name[:-2]] = ScmParam[name] + if vdiag: + if name.endswith("Button" + vdiag): + buttons[name[:-2]] = ScmParam[name] + ecusList.append(ecus(vdiag, '', buttons)) + else: #Get buttons without VDiag + buttons = OrderedDict() + found = False + for name in ScmParam.keys(): + if name == "InjectorsButton": + buttons[name] = ScmParam[name] + found = True + if found: + if name.endswith("Button"): + buttons[name] = ScmParam[name] + else: + found = False + break + ecusList.append(ecus('', '', buttons)) + +# Get correct buttons set + if vdiagExists: + value1, datastr1 = ecu.get_id(ScmParam['VDiag']) + for ecuSet in ecusList: + if ecuSet.vdiag == value1.upper(): + if ncalibExists: + if ecuSet.ncalib: + value2, datastr2 = ecu.get_id(ScmParam['Ncalib']) + if ecuSet.ncalib == value2.upper(): + print datastr1 + print datastr2 + correctEcu = ecuSet + break + elif ecuSet.ncalib == "Other": + print datastr1 + print ecuSet.ncalib + correctEcu = ecuSet + else: + print datastr1 + correctEcu = ecuSet + else: + print datastr1 + correctEcu = ecuSet + else: + correctEcu = ecusList[0] + + # for i in ecusList: + # print i.vdiag + # print i.ncalib + # for l in i.buttons.keys(): + # print l + # print str(i.buttons[l]) + + buttons = OrderedDict() + + for l in correctEcu.buttons.keys(): + if l == 'InjectorsButton': + if str(correctEcu.buttons[l]) == 'true': + buttons[1] = get_message("Injectors") + if l == 'EGRValveButton': + if str(correctEcu.buttons[l]) == 'true': + buttons[2] = get_message("EGR_VALVE") + if l == 'InletFlapButton': + if str(correctEcu.buttons[l]) == 'true': + buttons[3] = get_message("INLET_FLAP") + if l.startswith("Button"): + if str(correctEcu.buttons[l]) == 'true': + buttons[l.strip('Button')] = get_message(l[:-6] + "Text") + + def getIdents(start, end): + identsDict = OrderedDict() + for idnum in range(start,end + 1): + identsDict['D'+str(idnum)] = ScmParam['Ident'+str(idnum)] + return identsDict + + identsList = OrderedDict() + + for param in ScmParam.keys(): + if param.startswith('Idents') and param.endswith('Begin'): + key = param[6:-5] + start = int(ScmParam['Idents'+key+'Begin']) + end = int(ScmParam['Idents'+key+'End']) + identsList[key] = getIdents(start, end) + + + def resetEGRValve(): + params = {} + for child in root: + if child.attrib["name"] == "EGR_VALVE": + if len(child.keys()) == 1: + for param in child: + params[param.attrib("name")] = param.attrib("value") + + for k,v in params.iteritems(): + print k,v + print "gówno" + confirm = get_message('MessageBox5') + successMessage = get_message('Message32') + clearScreen() + + for idKey in identsList['X'].keys(): + identsList['X'][idKey] = ecu.get_id(identsList['X'][idKey], 1) + + print buttons[2] + print + ch = raw_input(confirm + ' : ') + while (ch.upper()!='YES') and (ch.upper()!='NO'): + ch = raw_input(confirm + ' : ') + if ch.upper()!='YES': + return + + # for k,v in identsList['X'].iteritems(): + # print k,v + + + functions = OrderedDict() + functions[2] = resetEGRValve + + infoMessage = get_message('Message1') + mainText = get_message('Title') + confirmButton = get_message_by_id('8405') + + print mainText + print + print infoMessage + print + + choice = Choice(buttons.values(), "Choose :") + for key, value in buttons.iteritems(): + if value == choice[0]: + functions[key]() + + + # print correctEcu.vdiag + # print correctEcu.ncalib + # for l in correctEcu.buttons.keys(): + # print l + # print str(correctEcu.buttons[l]) + + + + # value1, datastr1 = ecu.get_id(ScmParam['VDiag']) + # value2, datastr2 = ecu.get_id(ScmParam['Ncalib']) + # print pyren_encode(datastr1) + # print pyren_encode(datastr2) + + ch = raw_input('') + # + # Important information + # + # clearScreen() +# value1, datastr1 = ecu.get_id(ScmParam['Injecteur1']) +# value2, datastr2 = ecu.get_id(ScmParam['Injecteur2']) +# value3, datastr3 = ecu.get_id(ScmParam['Injecteur3']) +# value4, datastr4 = ecu.get_id(ScmParam['Injecteur4']) +# print pyren_encode(header) +# print get_message('TexteTitre') +# print '*'*80 +# print pyren_encode(datastr1) +# print pyren_encode(datastr2) +# print pyren_encode(datastr3) +# print pyren_encode(datastr4) +# print '*'*80 + +# ch = raw_input('Are you ready to change the Injector Codes? :') +# while (ch.lower() !='y') and (ch.lower() !='n'): +# ch = raw_input('Are you ready to change the Injector Codes? :') +# if ch.lower()!='y': return + +# # +# # INFO +# # + +# clearScreen() +# value1, datastr1 = ecu.get_id(ScmParam['Injecteur1']) +# value2, datastr2 = ecu.get_id(ScmParam['Injecteur2']) +# value3, datastr3 = ecu.get_id(ScmParam['Injecteur3']) +# value4, datastr4 = ecu.get_id(ScmParam['Injecteur4']) +# print pyren_encode(header) +# print '*'*80 +# print pyren_encode(datastr1) +# print pyren_encode(datastr2) +# print pyren_encode(datastr3) +# print pyren_encode(datastr4) +# print '*'*80 +# print pyren_encode('Permitted Characters'),get_message('PermittedCharacters') +# print '*'*80 + +# # +# # Receive data length and format from scenario +# # + +# nbCC = ScmParam['nbCaractereCode'] +# nbCC = int(nbCC) +# if nbCC !=6 and nbCC !=7 and nbCC !=16: +# ch = raw_input('Error nbCaractereCode in scenario xml') +# return +# isHEX = ScmParam['FormatHexadecimal'] +# isHEX = int(isHEX) +# if isHEX != 0 and isHEX != 1: +# ch = raw_input('Error FormatHexadecimal in scenario xml') +# return +# prmCHAR = ScmParam['PermittedCharacters'] +# if len(prmCHAR) << 16 and len(prmCHAR) >> 33: +# ch = raw_input('Error PermittedCharacters in scenario xml') +# return + +# # +# # Get IMA from input +# # + + +# ch1 = raw_input(get_message('dat_Cylindre1')+': ').upper() +# while not (all (c in prmCHAR for c in ch1.upper()) and (len(ch1)==nbCC)): +# ch1 = raw_input(get_message('dat_Cylindre1')+': ').upper() +# ch2 = raw_input(get_message('dat_Cylindre2')+': ').upper() +# while not (all (c in prmCHAR for c in ch2.upper()) and (len(ch2)==nbCC)): +# ch2 = raw_input(get_message('dat_Cylindre2')+': ').upper() +# ch3 = raw_input(get_message('dat_Cylindre3')+': ').upper() +# while not (all (c in prmCHAR for c in ch3.upper()) and (len(ch3)==nbCC)): +# ch3 = raw_input(get_message('dat_Cylindre3')+': ').upper() +# ch4 = raw_input(get_message('dat_Cylindre4')+': ').upper() +# while not (all (c in prmCHAR for c in ch4.upper()) and (len(ch4)==nbCC)): +# ch4 = raw_input(get_message('dat_Cylindre4')+': ').upper() + +# # +# # Check all data format of input +# # + +# chk = ( ch1 + ch2 + ch3 + ch4 ) + +# if isHEX == 1 and not (all (c in prmCHAR for c in chk.upper()) and (len(chk) == nbCC * 4)): +# print '*'*80 +# ch = raw_input('Hexdata check failed. Press ENTER to exit') +# return +# elif isHEX == 0 and not (all (c in prmCHAR for c in chk.upper()) and (len(chk) == nbCC * 4)) : +# print '*'*80 +# ch = raw_input('ASCII check failed. Press ENTER to exit') +# return +# else: +# print '*'*80 +# ch = raw_input('All checks passed successfull. Press ENTER to continue') + + +# # +# # If all checks are successful script prepares the data according to their type +# # + +# if isHEX == 1: +# inj_code = ( ch1 + ch2 + ch3 + ch4 ).upper() +# elif isHEX == 0: +# inj_code = ASCIITOHEX ( ch1 + ch2 + ch3 + ch4 ).upper() +# else: +# print '*'*80 +# ch = raw_input('!!!!!!!!There is a bug somwhere in the scenario, operation aborted!!!!!!!!!') +# return + +# # +# # print old and new data +# # + +# clearScreen() +# print '*'*80 +# print pyren_encode('Old injector codes') +# print pyren_encode(datastr1) +# print pyren_encode(datastr2) +# print pyren_encode(datastr3) +# print pyren_encode(datastr4) +# print '*'*80 +# print pyren_encode('New injector codes') +# print get_message('dat_Cylindre1'),pyren_encode(':'),pyren_encode(ch1) +# print get_message('dat_Cylindre2'),pyren_encode(':'),pyren_encode(ch2) +# print get_message('dat_Cylindre3'),pyren_encode(':'),pyren_encode(ch3) +# print get_message('dat_Cylindre4'),pyren_encode(':'),pyren_encode(ch4) +# print '*'*80 +# print pyren_encode('Permitted Characters'),get_message('PermittedCharacters') +# print '*'*80 + + +# ch = raw_input('Start injectors writing? YES/QUIT>') +# while (ch.upper()!='YES') and (ch.upper()!='QUIT'): +# ch = raw_input('Start injectors codes writing? YES/QUIT>') +# if ch.upper()!='YES': +# return + +# # +# # Write Injector Codes +# # + +# clearScreen() +# cmd = ecu.get_ref_cmd(get_message('EcritureCodeInjecteur')) +# print '*'*80 +# responce = ecu.run_cmd(ScmParam['EcritureCodeInjecteur'],inj_code) +# value5, datastr5 = ecu.get_id(ScmParam['Injecteur1']) +# value6, datastr6 = ecu.get_id(ScmParam['Injecteur2']) +# value7, datastr7 = ecu.get_id(ScmParam['Injecteur3']) +# value8, datastr8 = ecu.get_id(ScmParam['Injecteur4']) +# print '*'*80 +# print pyren_encode('Old injector codes') +# print pyren_encode(datastr1) +# print pyren_encode(datastr2) +# print pyren_encode(datastr3) +# print pyren_encode(datastr4) +# print '*'*80 +# print pyren_encode('New injector codes') +# print pyren_encode(datastr5) +# print pyren_encode(datastr6) +# print pyren_encode(datastr7) +# print pyren_encode(datastr8) +# print '*'*80 + +# ch = raw_input('Press ENTER to exit') +# return diff --git a/pyren/scen_ecri_paraminj2.py b/pyren/scen_ecri_paraminj2.py new file mode 100644 index 0000000..94a1f0d --- /dev/null +++ b/pyren/scen_ecri_paraminj2.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python + +import os +import sys +import re +import time +import string +import mod_globals +import mod_utils +import mod_ecu +from mod_utils import clearScreen +from mod_utils import pyren_encode +from mod_utils import KBHit +import xml.dom.minidom + +def run( elm, ecu, command, data ): + + clearScreen() + header = '['+command.codeMR+'] '+command.label + + ScmSet = {} + ScmParam = {} + + def get_message( msg ): + if msg in ScmParam.keys(): + value = ScmParam[msg] + else: + value = msg + if value.isdigit() and value in mod_globals.language_dict.keys(): + value = pyren_encode( mod_globals.language_dict[value] ) + return value + + def get_message_by_id( id ): + if id.isdigit() and id in mod_globals.language_dict.keys(): + value = pyren_encode( mod_globals.language_dict[id] ) + return value + + + DOMTree = xml.dom.minidom.parse(data) + ScmRoom = DOMTree.documentElement + + ScmParams = ScmRoom.getElementsByTagName("ScmParam") + + for Param in ScmParams: + name = pyren_encode( Param.getAttribute("name") ) + value = pyren_encode( Param.getAttribute("value") ) + + ScmParam[name] = value + + ScmSets = ScmRoom.getElementsByTagName("ScmSet") + + for Set in ScmSets: + setname = pyren_encode(Set.getAttribute("name")) + ScmParams = Set.getElementsByTagName("ScmParam") + + for Param in ScmParams: + name = pyren_encode( Param.getAttribute("name") ) + value = pyren_encode( Param.getAttribute("value") ) + + ScmSet[setname]= value + ScmParam[name] = value + print setname, value + print name + + kb = KBHit() + + # mainText = get_message('TexteTitre') + # important = get_message('TexteConsigne') + # tilt = get_message('TexteValeurInclinaison') + # degreeSymbol = get_message('TexteDegre') + # value2, datastr2 = ecu.get_pr(ScmParam['ParametreInclinaison']) + + # clearScreen() + # print pyren_encode(header) + # print mainText + # print '*'*80 + # print + # print important + # print + + ch = raw_input('Do you want to continue? ') + while (ch.upper() != 'YES') and (ch.upper()!= 'NO'): + ch = raw_input('Do you want to continue? ') + if ch.upper() != 'YES': + return + + # clearScreen() + # cmd = ecu.get_ref_cmd(get_message('Commande1')) + # resVal = ScmParam['ParametreCommande1'] + # print '*'*80 + # responce = ecu.run_cmd(ScmParam['Commande1'], resVal) + # print '*'*80 + # if 'NR' in responce: + # print get_message('TexteProcedureInterompue') + # else: + # print get_message('TexteInitialisationEffectuee') + # print + # print tilt, pyren_encode(':'), value2, degreeSymbol + # print + + # ch = raw_input('Press ENTER to exit') + # return From 64fc845473e4aaba4694336eaaa2e44c24416cc0 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Mon, 3 Feb 2020 23:46:29 +0100 Subject: [PATCH 02/57] First execute --- pyren/scen_ecri_paraminj1.py | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 45f5ffd..d2772c4 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -209,6 +209,13 @@ def run( elm, ecu, command, data ): if str(correctEcu.buttons[l]) == 'true': buttons[l.strip('Button')] = get_message(l[:-6] + "Text") + commands = {} + for child in root: + if child.attrib["name"] == "Commands": + if len(child.keys()) == 1: + for param in child: + commands[param.attrib["name"]] = param.attrib["value"] + def getIdents(start, end): identsDict = OrderedDict() for idnum in range(start,end + 1): @@ -226,20 +233,21 @@ def run( elm, ecu, command, data ): def resetEGRValve(): + paramToSend = "" params = {} for child in root: if child.attrib["name"] == "EGR_VALVE": if len(child.keys()) == 1: for param in child: - params[param.attrib("name")] = param.attrib("value") + params[param.attrib["name"]] = param.attrib["value"] - for k,v in params.iteritems(): - print k,v - print "gówno" confirm = get_message('MessageBox5') successMessage = get_message('Message32') clearScreen() + # for k,v in params.iteritems(): + # print k,v + for idKey in identsList['X'].keys(): identsList['X'][idKey] = ecu.get_id(identsList['X'][idKey], 1) @@ -250,9 +258,16 @@ def run( elm, ecu, command, data ): ch = raw_input(confirm + ' : ') if ch.upper()!='YES': return + + for k,v in params.iteritems(): + identsList['X'][k] = v + + for v in identsList['X'].values(): + paramToSend += v + + ecu.run_cmd(commands['Cmd5'],paramToSend) + - # for k,v in identsList['X'].iteritems(): - # print k,v functions = OrderedDict() From bf380daa22682549d7d0227b7e4693f578a1579a Mon Sep 17 00:00:00 2001 From: Marianpol Date: Mon, 3 Feb 2020 23:51:53 +0100 Subject: [PATCH 03/57] Fix#2 --- pyren/scen_ecri_paraminj1.py | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index d2772c4..218875c 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -169,19 +169,19 @@ def run( elm, ecu, command, data ): if ecuSet.ncalib: value2, datastr2 = ecu.get_id(ScmParam['Ncalib']) if ecuSet.ncalib == value2.upper(): - print datastr1 - print datastr2 + # print datastr1 + # print datastr2 correctEcu = ecuSet break elif ecuSet.ncalib == "Other": - print datastr1 - print ecuSet.ncalib + # print datastr1 + # print ecuSet.ncalib correctEcu = ecuSet else: - print datastr1 + # print datastr1 correctEcu = ecuSet else: - print datastr1 + # print datastr1 correctEcu = ecuSet else: correctEcu = ecusList[0] @@ -208,21 +208,14 @@ def run( elm, ecu, command, data ): if l.startswith("Button"): if str(correctEcu.buttons[l]) == 'true': buttons[l.strip('Button')] = get_message(l[:-6] + "Text") - - commands = {} - for child in root: - if child.attrib["name"] == "Commands": - if len(child.keys()) == 1: - for param in child: - commands[param.attrib["name"]] = param.attrib["value"] + identsList = OrderedDict() + def getIdents(start, end): identsDict = OrderedDict() for idnum in range(start,end + 1): identsDict['D'+str(idnum)] = ScmParam['Ident'+str(idnum)] return identsDict - - identsList = OrderedDict() for param in ScmParam.keys(): if param.startswith('Idents') and param.endswith('Begin'): @@ -231,6 +224,13 @@ def run( elm, ecu, command, data ): end = int(ScmParam['Idents'+key+'End']) identsList[key] = getIdents(start, end) + commands = {} + + for child in root: + if child.attrib["name"] == "Commands": + if len(child.keys()) == 1: + for param in child: + commands[param.attrib["name"]] = param.attrib["value"] def resetEGRValve(): paramToSend = "" @@ -268,8 +268,6 @@ def run( elm, ecu, command, data ): ecu.run_cmd(commands['Cmd5'],paramToSend) - - functions = OrderedDict() functions[2] = resetEGRValve From f2a3bbe5f4dfd973c91ecb76f4f1a2f389f9d11c Mon Sep 17 00:00:00 2001 From: Marianpol Date: Mon, 3 Feb 2020 23:58:40 +0100 Subject: [PATCH 04/57] Fix#3 --- pyren/scen_ecri_paraminj1.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 218875c..430b536 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -169,19 +169,13 @@ def run( elm, ecu, command, data ): if ecuSet.ncalib: value2, datastr2 = ecu.get_id(ScmParam['Ncalib']) if ecuSet.ncalib == value2.upper(): - # print datastr1 - # print datastr2 correctEcu = ecuSet break elif ecuSet.ncalib == "Other": - # print datastr1 - # print ecuSet.ncalib correctEcu = ecuSet else: - # print datastr1 correctEcu = ecuSet else: - # print datastr1 correctEcu = ecuSet else: correctEcu = ecusList[0] @@ -193,6 +187,7 @@ def run( elm, ecu, command, data ): # print l # print str(i.buttons[l]) + #Prepare buttons buttons = OrderedDict() for l in correctEcu.buttons.keys(): @@ -209,6 +204,7 @@ def run( elm, ecu, command, data ): if str(correctEcu.buttons[l]) == 'true': buttons[l.strip('Button')] = get_message(l[:-6] + "Text") + #Get identifications identsList = OrderedDict() def getIdents(start, end): @@ -224,6 +220,7 @@ def run( elm, ecu, command, data ): end = int(ScmParam['Idents'+key+'End']) identsList[key] = getIdents(start, end) + #Get commands commands = {} for child in root: From 94414a6085cd696ee176e61b84d1cebd3758d1ed Mon Sep 17 00:00:00 2001 From: Marianpol Date: Tue, 4 Feb 2020 16:45:57 +0100 Subject: [PATCH 05/57] Refactor --- pyren/scen_ecri_paraminj1.py | 81 ++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 26 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 430b536..eb784f7 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -180,6 +180,8 @@ def run( elm, ecu, command, data ): else: correctEcu = ecusList[0] + if not correctEcu and mod_globals.opt_demo: + correctEcu = ecusList[0] # for i in ecusList: # print i.vdiag # print i.ncalib @@ -206,19 +208,29 @@ def run( elm, ecu, command, data ): #Get identifications identsList = OrderedDict() - - def getIdents(start, end): - identsDict = OrderedDict() - for idnum in range(start,end + 1): - identsDict['D'+str(idnum)] = ScmParam['Ident'+str(idnum)] - return identsDict + identsKeys = OrderedDict() for param in ScmParam.keys(): if param.startswith('Idents') and param.endswith('Begin'): key = param[6:-5] - start = int(ScmParam['Idents'+key+'Begin']) + begin = int(ScmParam['Idents'+key+'Begin']) end = int(ScmParam['Idents'+key+'End']) - identsList[key] = getIdents(start, end) + identsKeys[key] = {"begin": begin, "end": end} + for idnum in range(begin ,end + 1): + identsList['D'+str(idnum)] = ScmParam['Ident'+str(idnum)] + + # def getIdents(start, end): + # identsDict = OrderedDict() + # for idnum in range(start,end + 1): + # identsDict['D'+str(idnum)] = ScmParam['Ident'+str(idnum)] + # return identsDict + + # for param in ScmParam.keys(): + # if param.startswith('Idents') and param.endswith('Begin'): + # key = param[6:-5] + # start = int(ScmParam['Idents'+key+'Begin']) + # end = int(ScmParam['Idents'+key+'End']) + # identsList[key] = getIdents(start, end) #Get commands commands = {} @@ -229,24 +241,33 @@ def run( elm, ecu, command, data ): for param in child: commands[param.attrib["name"]] = param.attrib["value"] - def resetEGRValve(): - paramToSend = "" + def getValuesToChange(resetItem): params = {} for child in root: - if child.attrib["name"] == "EGR_VALVE": + if child.attrib["name"] == resetItem: if len(child.keys()) == 1: for param in child: params[param.attrib["name"]] = param.attrib["value"] + return params + + def replaceValues(params): + for k,v in params.iteritems(): + if v in identsList.keys(): + identsList[k] = ecu.get_id(identsList[v], 1) + else: + identsList[k] = v - confirm = get_message('MessageBox5') + def resetEGRValve(): + paramToSend = "" + params = getValuesToChange("EGR_VALVE") + + confirm = get_message_by_id('19800') successMessage = get_message('Message32') + failMessage = get_message('MessageNACK') clearScreen() - - # for k,v in params.iteritems(): - # print k,v - - for idKey in identsList['X'].keys(): - identsList['X'][idKey] = ecu.get_id(identsList['X'][idKey], 1) + + for idKey in range(identsKeys[identsKeys.keys()[0]]['begin'], identsKeys[identsKeys.keys()[0]]['end'] + 1): + identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) print buttons[2] print @@ -255,15 +276,23 @@ def run( elm, ecu, command, data ): ch = raw_input(confirm + ' : ') if ch.upper()!='YES': return - - for k,v in params.iteritems(): - identsList['X'][k] = v - - for v in identsList['X'].values(): - paramToSend += v - ecu.run_cmd(commands['Cmd5'],paramToSend) + clearScreen() + replaceValues(params) + + for idKey in range(identsKeys[identsKeys.keys()[0]]['begin'], identsKeys[identsKeys.keys()[0]]['end'] + 1): + paramToSend += identsList["D" + str(idKey)] + + print + response = ecu.run_cmd(commands['Cmd5'],paramToSend) + if "NR" in response: + print failMessage + else: + print successMessage + + print + ch = raw_input('Press ENTER to exit') functions = OrderedDict() functions[2] = resetEGRValve @@ -296,7 +325,7 @@ def run( elm, ecu, command, data ): # print pyren_encode(datastr1) # print pyren_encode(datastr2) - ch = raw_input('') + return # # Important information # From b1d3601a19cf7ab11085cd8197de8f5ec2b01b63 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Tue, 4 Feb 2020 23:15:25 +0100 Subject: [PATCH 06/57] EGR done --- pyren/scen_ecri_paraminj1.py | 50 +++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index eb784f7..757b89d 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -182,12 +182,12 @@ def run( elm, ecu, command, data ): if not correctEcu and mod_globals.opt_demo: correctEcu = ecusList[0] - # for i in ecusList: - # print i.vdiag - # print i.ncalib - # for l in i.buttons.keys(): - # print l - # print str(i.buttons[l]) + for i in ecusList: + print i.vdiag + print i.ncalib + for l in i.buttons.keys(): + print l + print str(i.buttons[l]) #Prepare buttons buttons = OrderedDict() @@ -216,8 +216,13 @@ def run( elm, ecu, command, data ): begin = int(ScmParam['Idents'+key+'Begin']) end = int(ScmParam['Idents'+key+'End']) identsKeys[key] = {"begin": begin, "end": end} - for idnum in range(begin ,end + 1): - identsList['D'+str(idnum)] = ScmParam['Ident'+str(idnum)] + try: + identsList['D'+str(begin)] = ScmParam['Ident'+str(begin)] + except: + break + else: + for idnum in range(begin ,end + 1): + identsList['D'+str(idnum)] = ScmParam['Ident'+str(idnum)] # def getIdents(start, end): # identsDict = OrderedDict() @@ -257,17 +262,15 @@ def run( elm, ecu, command, data ): else: identsList[k] = v - def resetEGRValve(): + confirm = get_message_by_id('19800') + successMessage = get_message('Message32') + failMessage = get_message('MessageNACK') + + def resetValues(): paramToSend = "" params = getValuesToChange("EGR_VALVE") - confirm = get_message_by_id('19800') - successMessage = get_message('Message32') - failMessage = get_message('MessageNACK') clearScreen() - - for idKey in range(identsKeys[identsKeys.keys()[0]]['begin'], identsKeys[identsKeys.keys()[0]]['end'] + 1): - identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) print buttons[2] print @@ -278,7 +281,22 @@ def run( elm, ecu, command, data ): return clearScreen() + + if not params: + print + response = ecu.run_cmd(commands['Cmd5']) + print + if "NR" in response: + print failMessage + else: + print successMessage + print + ch = raw_input('Press ENTER to exit') + return + for idKey in range(identsKeys[identsKeys.keys()[0]]['begin'], identsKeys[identsKeys.keys()[0]]['end'] + 1): + identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) + replaceValues(params) for idKey in range(identsKeys[identsKeys.keys()[0]]['begin'], identsKeys[identsKeys.keys()[0]]['end'] + 1): @@ -286,6 +304,7 @@ def run( elm, ecu, command, data ): print response = ecu.run_cmd(commands['Cmd5'],paramToSend) + print if "NR" in response: print failMessage else: @@ -294,6 +313,7 @@ def run( elm, ecu, command, data ): print ch = raw_input('Press ENTER to exit') + functions = OrderedDict() functions[2] = resetEGRValve From fa97dffced524955cbaaac6fece1f3100d55e5ba Mon Sep 17 00:00:00 2001 From: Marianpol Date: Wed, 5 Feb 2020 00:14:06 +0100 Subject: [PATCH 07/57] Fix#10 --- pyren/scen_ecri_paraminj1.py | 70 +++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 8 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 757b89d..4e4a698 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -182,12 +182,13 @@ def run( elm, ecu, command, data ): if not correctEcu and mod_globals.opt_demo: correctEcu = ecusList[0] - for i in ecusList: - print i.vdiag - print i.ncalib - for l in i.buttons.keys(): - print l - print str(i.buttons[l]) + + # for i in ecusList: + # print i.vdiag + # print i.ncalib + # for l in i.buttons.keys(): + # print l + # print str(i.buttons[l]) #Prepare buttons buttons = OrderedDict() @@ -265,13 +266,16 @@ def run( elm, ecu, command, data ): confirm = get_message_by_id('19800') successMessage = get_message('Message32') failMessage = get_message('MessageNACK') + mainText = get_message('Title') - def resetValues(): + def resetEGRValve(): paramToSend = "" params = getValuesToChange("EGR_VALVE") clearScreen() + print mainText + print print buttons[2] print ch = raw_input(confirm + ' : ') @@ -313,12 +317,62 @@ def run( elm, ecu, command, data ): print ch = raw_input('Press ENTER to exit') + def resetInletFlap(): + paramToSend = "" + params = getValuesToChange("INLET_FLAP") + + clearScreen() + + print mainText + print + print buttons[3] + print + ch = raw_input(confirm + ' : ') + while (ch.upper()!='YES') and (ch.upper()!='NO'): + ch = raw_input(confirm + ' : ') + if ch.upper()!='YES': + return + + clearScreen() + + if not params: + print + response = ecu.run_cmd(commands['Cmd6']) + print + if "NR" in response: + print failMessage + else: + print successMessage + print + ch = raw_input('Press ENTER to exit') + return + + for idKey in range(identsKeys[identsKeys.keys()[1]]['begin'], identsKeys[identsKeys.keys()[1]]['end'] + 1): + identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) + + replaceValues(params) + + for idKey in range(identsKeys[identsKeys.keys()[1]]['begin'], identsKeys[identsKeys.keys()[1]]['end'] + 1): + paramToSend += identsList["D" + str(idKey)] + + print + response = ecu.run_cmd(commands['Cmd6'],paramToSend) + print + + if "NR" in response: + print failMessage + else: + print successMessage + + print + ch = raw_input('Press ENTER to exit') + functions = OrderedDict() functions[2] = resetEGRValve + functions[3] = resetInletFlap infoMessage = get_message('Message1') - mainText = get_message('Title') confirmButton = get_message_by_id('8405') print mainText From 27e834acb7e9071683053e595ef6b5f89318a1eb Mon Sep 17 00:00:00 2001 From: Marianpol Date: Wed, 5 Feb 2020 18:19:45 +0100 Subject: [PATCH 08/57] Four buttons works --- pyren/scen_ecri_paraminj1.py | 357 ++++++++++------------------------- 1 file changed, 99 insertions(+), 258 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 4e4a698..55ba69f 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -205,7 +205,17 @@ def run( elm, ecu, command, data ): buttons[3] = get_message("INLET_FLAP") if l.startswith("Button"): if str(correctEcu.buttons[l]) == 'true': - buttons[l.strip('Button')] = get_message(l[:-6] + "Text") + buttons[int(l.strip('Button'))] = get_message(l[:-6] + "Text") + + + #Get commands + commands = {} + + for child in root: + if child.attrib["name"] == "Commands": + if len(child.keys()) == 1: + for param in child: + commands[param.attrib["name"]] = param.attrib["value"] #Get identifications identsList = OrderedDict() @@ -238,15 +248,6 @@ def run( elm, ecu, command, data ): # end = int(ScmParam['Idents'+key+'End']) # identsList[key] = getIdents(start, end) - #Get commands - commands = {} - - for child in root: - if child.attrib["name"] == "Commands": - if len(child.keys()) == 1: - for param in child: - commands[param.attrib["name"]] = param.attrib["value"] - def getValuesToChange(resetItem): params = {} for child in root: @@ -256,28 +257,88 @@ def run( elm, ecu, command, data ): params[param.attrib["name"]] = param.attrib["value"] return params - def replaceValues(params): - for k,v in params.iteritems(): - if v in identsList.keys(): - identsList[k] = ecu.get_id(identsList[v], 1) - else: - identsList[k] = v + # def replaceValues(params): + # for k,v in params.iteritems(): + # if v in identsList.keys(): + # identsList[k] = ecu.get_id(identsList[v], 1) + # else: + # identsList[k] = v confirm = get_message_by_id('19800') successMessage = get_message('Message32') failMessage = get_message('MessageNACK') mainText = get_message('Title') - def resetEGRValve(): + # def resetEGRValve(): + # paramToSend = "" + # params = getValuesToChange("EGR_VALVE") + + # clearScreen() + + # print mainText + # print + # print buttons[2] + # print + # ch = raw_input(confirm + ' : ') + # while (ch.upper()!='YES') and (ch.upper()!='NO'): + # ch = raw_input(confirm + ' : ') + # if ch.upper()!='YES': + # return + + # clearScreen() + + # if not params: + # print + # response = ecu.run_cmd(commands['Cmd5']) + # print + # if "NR" in response: + # print failMessage + # else: + # print successMessage + # print + # ch = raw_input('Press ENTER to exit') + # return + + + # for idKey in range(identsKeys[identsKeys.keys()[0]]['begin'], identsKeys[identsKeys.keys()[0]]['end'] + 1): + # identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) + + # for k,v in params.iteritems(): + # if v in identsList.keys(): + # identsList[k] = ecu.get_id(identsList[v], 1) + # else: + # identsList[k] = v + + # for idKey in range(identsKeys[identsKeys.keys()[0]]['begin'], identsKeys[identsKeys.keys()[0]]['end'] + 1): + # paramToSend += identsList["D" + str(idKey)] + + # print + # response = ecu.run_cmd(commands['Cmd5'],paramToSend) + # print + # if "NR" in response: + # print failMessage + # else: + # print successMessage + + # print + # ch = raw_input('Press ENTER to exit') + + def resetValues(title, button, command, rangeKey, message = ''): paramToSend = "" - params = getValuesToChange("EGR_VALVE") + params = getValuesToChange(title) clearScreen() print mainText print - print buttons[2] + print buttons[button] print + if button == 4: + print get_message_by_id('55662') + print + if button == 5: + print get_message_by_id('55663') + print ch = raw_input(confirm + ' : ') while (ch.upper()!='YES') and (ch.upper()!='NO'): ch = raw_input(confirm + ' : ') @@ -288,7 +349,7 @@ def run( elm, ecu, command, data ): if not params: print - response = ecu.run_cmd(commands['Cmd5']) + response = ecu.run_cmd(command) print if "NR" in response: print failMessage @@ -297,66 +358,25 @@ def run( elm, ecu, command, data ): print ch = raw_input('Press ENTER to exit') return - - for idKey in range(identsKeys[identsKeys.keys()[0]]['begin'], identsKeys[identsKeys.keys()[0]]['end'] + 1): - identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) - - replaceValues(params) - - for idKey in range(identsKeys[identsKeys.keys()[0]]['begin'], identsKeys[identsKeys.keys()[0]]['end'] + 1): - paramToSend += identsList["D" + str(idKey)] - print - response = ecu.run_cmd(commands['Cmd5'],paramToSend) - print - if "NR" in response: - print failMessage - else: - print successMessage + idRangeKey = identsKeys[identsKeys.keys()[rangeKey]] - print - ch = raw_input('Press ENTER to exit') - - def resetInletFlap(): - paramToSend = "" - params = getValuesToChange("INLET_FLAP") - - clearScreen() - - print mainText - print - print buttons[3] - print - ch = raw_input(confirm + ' : ') - while (ch.upper()!='YES') and (ch.upper()!='NO'): - ch = raw_input(confirm + ' : ') - if ch.upper()!='YES': - return - - clearScreen() - - if not params: - print - response = ecu.run_cmd(commands['Cmd6']) - print - if "NR" in response: - print failMessage + for k,v in params.iteritems(): + if v in identsList.keys(): + identsList[k] = ecu.get_id(identsList[v], 1) else: - print successMessage - print - ch = raw_input('Press ENTER to exit') - return - - for idKey in range(identsKeys[identsKeys.keys()[1]]['begin'], identsKeys[identsKeys.keys()[1]]['end'] + 1): - identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) + identsList[k] = v - replaceValues(params) - - for idKey in range(identsKeys[identsKeys.keys()[1]]['begin'], identsKeys[identsKeys.keys()[1]]['end'] + 1): + for idKey in range(idRangeKey['begin'], idRangeKey['end'] + 1): + print str(idKey), identsList["D" + str(idKey)] + if identsList["D" + str(idKey)].startswith("ID"): + identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) paramToSend += identsList["D" + str(idKey)] + print str(idKey), identsList["D" + str(idKey)] + print - response = ecu.run_cmd(commands['Cmd6'],paramToSend) + response = ecu.run_cmd(command,paramToSend) print if "NR" in response: @@ -369,8 +389,10 @@ def run( elm, ecu, command, data ): functions = OrderedDict() - functions[2] = resetEGRValve - functions[3] = resetInletFlap + functions[2] = ["EGR_VALVE", 2, commands['Cmd5'], 0] + functions[3] = ["INLET_FLAP", 3, commands['Cmd6'], 1] + functions[4] = ["PARTICLE_FILTER", 4, commands['Cmd7'], 2] + functions[5] = ["Button5ChangeData", 5, commands['Cmd7'], 2] infoMessage = get_message('Message1') confirmButton = get_message_by_id('8405') @@ -383,186 +405,5 @@ def run( elm, ecu, command, data ): choice = Choice(buttons.values(), "Choose :") for key, value in buttons.iteritems(): if value == choice[0]: - functions[key]() - - - # print correctEcu.vdiag - # print correctEcu.ncalib - # for l in correctEcu.buttons.keys(): - # print l - # print str(correctEcu.buttons[l]) - - - - # value1, datastr1 = ecu.get_id(ScmParam['VDiag']) - # value2, datastr2 = ecu.get_id(ScmParam['Ncalib']) - # print pyren_encode(datastr1) - # print pyren_encode(datastr2) - - return - # - # Important information - # - # clearScreen() -# value1, datastr1 = ecu.get_id(ScmParam['Injecteur1']) -# value2, datastr2 = ecu.get_id(ScmParam['Injecteur2']) -# value3, datastr3 = ecu.get_id(ScmParam['Injecteur3']) -# value4, datastr4 = ecu.get_id(ScmParam['Injecteur4']) -# print pyren_encode(header) -# print get_message('TexteTitre') -# print '*'*80 -# print pyren_encode(datastr1) -# print pyren_encode(datastr2) -# print pyren_encode(datastr3) -# print pyren_encode(datastr4) -# print '*'*80 - -# ch = raw_input('Are you ready to change the Injector Codes? :') -# while (ch.lower() !='y') and (ch.lower() !='n'): -# ch = raw_input('Are you ready to change the Injector Codes? :') -# if ch.lower()!='y': return - -# # -# # INFO -# # - -# clearScreen() -# value1, datastr1 = ecu.get_id(ScmParam['Injecteur1']) -# value2, datastr2 = ecu.get_id(ScmParam['Injecteur2']) -# value3, datastr3 = ecu.get_id(ScmParam['Injecteur3']) -# value4, datastr4 = ecu.get_id(ScmParam['Injecteur4']) -# print pyren_encode(header) -# print '*'*80 -# print pyren_encode(datastr1) -# print pyren_encode(datastr2) -# print pyren_encode(datastr3) -# print pyren_encode(datastr4) -# print '*'*80 -# print pyren_encode('Permitted Characters'),get_message('PermittedCharacters') -# print '*'*80 - -# # -# # Receive data length and format from scenario -# # - -# nbCC = ScmParam['nbCaractereCode'] -# nbCC = int(nbCC) -# if nbCC !=6 and nbCC !=7 and nbCC !=16: -# ch = raw_input('Error nbCaractereCode in scenario xml') -# return -# isHEX = ScmParam['FormatHexadecimal'] -# isHEX = int(isHEX) -# if isHEX != 0 and isHEX != 1: -# ch = raw_input('Error FormatHexadecimal in scenario xml') -# return -# prmCHAR = ScmParam['PermittedCharacters'] -# if len(prmCHAR) << 16 and len(prmCHAR) >> 33: -# ch = raw_input('Error PermittedCharacters in scenario xml') -# return - -# # -# # Get IMA from input -# # - - -# ch1 = raw_input(get_message('dat_Cylindre1')+': ').upper() -# while not (all (c in prmCHAR for c in ch1.upper()) and (len(ch1)==nbCC)): -# ch1 = raw_input(get_message('dat_Cylindre1')+': ').upper() -# ch2 = raw_input(get_message('dat_Cylindre2')+': ').upper() -# while not (all (c in prmCHAR for c in ch2.upper()) and (len(ch2)==nbCC)): -# ch2 = raw_input(get_message('dat_Cylindre2')+': ').upper() -# ch3 = raw_input(get_message('dat_Cylindre3')+': ').upper() -# while not (all (c in prmCHAR for c in ch3.upper()) and (len(ch3)==nbCC)): -# ch3 = raw_input(get_message('dat_Cylindre3')+': ').upper() -# ch4 = raw_input(get_message('dat_Cylindre4')+': ').upper() -# while not (all (c in prmCHAR for c in ch4.upper()) and (len(ch4)==nbCC)): -# ch4 = raw_input(get_message('dat_Cylindre4')+': ').upper() - -# # -# # Check all data format of input -# # - -# chk = ( ch1 + ch2 + ch3 + ch4 ) - -# if isHEX == 1 and not (all (c in prmCHAR for c in chk.upper()) and (len(chk) == nbCC * 4)): -# print '*'*80 -# ch = raw_input('Hexdata check failed. Press ENTER to exit') -# return -# elif isHEX == 0 and not (all (c in prmCHAR for c in chk.upper()) and (len(chk) == nbCC * 4)) : -# print '*'*80 -# ch = raw_input('ASCII check failed. Press ENTER to exit') -# return -# else: -# print '*'*80 -# ch = raw_input('All checks passed successfull. Press ENTER to continue') - - -# # -# # If all checks are successful script prepares the data according to their type -# # - -# if isHEX == 1: -# inj_code = ( ch1 + ch2 + ch3 + ch4 ).upper() -# elif isHEX == 0: -# inj_code = ASCIITOHEX ( ch1 + ch2 + ch3 + ch4 ).upper() -# else: -# print '*'*80 -# ch = raw_input('!!!!!!!!There is a bug somwhere in the scenario, operation aborted!!!!!!!!!') -# return - -# # -# # print old and new data -# # - -# clearScreen() -# print '*'*80 -# print pyren_encode('Old injector codes') -# print pyren_encode(datastr1) -# print pyren_encode(datastr2) -# print pyren_encode(datastr3) -# print pyren_encode(datastr4) -# print '*'*80 -# print pyren_encode('New injector codes') -# print get_message('dat_Cylindre1'),pyren_encode(':'),pyren_encode(ch1) -# print get_message('dat_Cylindre2'),pyren_encode(':'),pyren_encode(ch2) -# print get_message('dat_Cylindre3'),pyren_encode(':'),pyren_encode(ch3) -# print get_message('dat_Cylindre4'),pyren_encode(':'),pyren_encode(ch4) -# print '*'*80 -# print pyren_encode('Permitted Characters'),get_message('PermittedCharacters') -# print '*'*80 - - -# ch = raw_input('Start injectors writing? YES/QUIT>') -# while (ch.upper()!='YES') and (ch.upper()!='QUIT'): -# ch = raw_input('Start injectors codes writing? YES/QUIT>') -# if ch.upper()!='YES': -# return - -# # -# # Write Injector Codes -# # - -# clearScreen() -# cmd = ecu.get_ref_cmd(get_message('EcritureCodeInjecteur')) -# print '*'*80 -# responce = ecu.run_cmd(ScmParam['EcritureCodeInjecteur'],inj_code) -# value5, datastr5 = ecu.get_id(ScmParam['Injecteur1']) -# value6, datastr6 = ecu.get_id(ScmParam['Injecteur2']) -# value7, datastr7 = ecu.get_id(ScmParam['Injecteur3']) -# value8, datastr8 = ecu.get_id(ScmParam['Injecteur4']) -# print '*'*80 -# print pyren_encode('Old injector codes') -# print pyren_encode(datastr1) -# print pyren_encode(datastr2) -# print pyren_encode(datastr3) -# print pyren_encode(datastr4) -# print '*'*80 -# print pyren_encode('New injector codes') -# print pyren_encode(datastr5) -# print pyren_encode(datastr6) -# print pyren_encode(datastr7) -# print pyren_encode(datastr8) -# print '*'*80 - -# ch = raw_input('Press ENTER to exit') -# return + resetValues(functions[key][0],functions[key][1],functions[key][2],functions[key][3]) + return \ No newline at end of file From afba3250deb4716dc9e2fe3dc7d2c03027f2f5fd Mon Sep 17 00:00:00 2001 From: Marianpol Date: Wed, 5 Feb 2020 18:39:10 +0100 Subject: [PATCH 09/57] Cleaning --- pyren/scen_ecri_paraminj1.py | 63 ------------------------------------ 1 file changed, 63 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 55ba69f..a1b3774 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -256,73 +256,12 @@ def run( elm, ecu, command, data ): for param in child: params[param.attrib["name"]] = param.attrib["value"] return params - - # def replaceValues(params): - # for k,v in params.iteritems(): - # if v in identsList.keys(): - # identsList[k] = ecu.get_id(identsList[v], 1) - # else: - # identsList[k] = v confirm = get_message_by_id('19800') successMessage = get_message('Message32') failMessage = get_message('MessageNACK') mainText = get_message('Title') - # def resetEGRValve(): - # paramToSend = "" - # params = getValuesToChange("EGR_VALVE") - - # clearScreen() - - # print mainText - # print - # print buttons[2] - # print - # ch = raw_input(confirm + ' : ') - # while (ch.upper()!='YES') and (ch.upper()!='NO'): - # ch = raw_input(confirm + ' : ') - # if ch.upper()!='YES': - # return - - # clearScreen() - - # if not params: - # print - # response = ecu.run_cmd(commands['Cmd5']) - # print - # if "NR" in response: - # print failMessage - # else: - # print successMessage - # print - # ch = raw_input('Press ENTER to exit') - # return - - - # for idKey in range(identsKeys[identsKeys.keys()[0]]['begin'], identsKeys[identsKeys.keys()[0]]['end'] + 1): - # identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) - - # for k,v in params.iteritems(): - # if v in identsList.keys(): - # identsList[k] = ecu.get_id(identsList[v], 1) - # else: - # identsList[k] = v - - # for idKey in range(identsKeys[identsKeys.keys()[0]]['begin'], identsKeys[identsKeys.keys()[0]]['end'] + 1): - # paramToSend += identsList["D" + str(idKey)] - - # print - # response = ecu.run_cmd(commands['Cmd5'],paramToSend) - # print - # if "NR" in response: - # print failMessage - # else: - # print successMessage - - # print - # ch = raw_input('Press ENTER to exit') - def resetValues(title, button, command, rangeKey, message = ''): paramToSend = "" params = getValuesToChange(title) @@ -374,7 +313,6 @@ def run( elm, ecu, command, data ): paramToSend += identsList["D" + str(idKey)] print str(idKey), identsList["D" + str(idKey)] - print response = ecu.run_cmd(command,paramToSend) print @@ -395,7 +333,6 @@ def run( elm, ecu, command, data ): functions[5] = ["Button5ChangeData", 5, commands['Cmd7'], 2] infoMessage = get_message('Message1') - confirmButton = get_message_by_id('8405') print mainText print From bef10d2b7959829dc8a121df19a48ed8afc98bd2 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Wed, 5 Feb 2020 19:28:31 +0100 Subject: [PATCH 10/57] Ncalib button fix --- pyren/scen_ecri_paraminj1.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index a1b3774..08f89db 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -122,7 +122,8 @@ def run( elm, ecu, command, data ): if ncalibButtons.attrib["name"] == "Buttons": for ncalibButton in ncalibButtons: buttons[ncalibButton.attrib["name"]] = ncalibButton.attrib["value"] - ecusList.append(ecus(vDiagName.attrib["name"],ncalibName.attrib["name"], buttons)) + ecusList.append(ecus(vDiagName.attrib["name"],ncalibName.attrib["name"], buttons)) + buttons = OrderedDict() else: if vDiagButtons.attrib["name"] == "Buttons": for vDiagButton in vDiagButtons: @@ -189,6 +190,12 @@ def run( elm, ecu, command, data ): # for l in i.buttons.keys(): # print l # print str(i.buttons[l]) + # print + + # print correctEcu.vdiag + # print correctEcu.ncalib + # for k,v in correctEcu.buttons.iteritems(): + # print k,v #Prepare buttons buttons = OrderedDict() @@ -227,7 +234,7 @@ def run( elm, ecu, command, data ): begin = int(ScmParam['Idents'+key+'Begin']) end = int(ScmParam['Idents'+key+'End']) identsKeys[key] = {"begin": begin, "end": end} - try: + try: #10099 trap identsList['D'+str(begin)] = ScmParam['Ident'+str(begin)] except: break @@ -262,7 +269,7 @@ def run( elm, ecu, command, data ): failMessage = get_message('MessageNACK') mainText = get_message('Title') - def resetValues(title, button, command, rangeKey, message = ''): + def resetValues(title, button, command, rangeKey): paramToSend = "" params = getValuesToChange(title) @@ -286,7 +293,7 @@ def run( elm, ecu, command, data ): clearScreen() - if not params: + if not params: #VP042 for INLET_FLAP print response = ecu.run_cmd(command) print @@ -307,11 +314,11 @@ def run( elm, ecu, command, data ): identsList[k] = v for idKey in range(idRangeKey['begin'], idRangeKey['end'] + 1): - print str(idKey), identsList["D" + str(idKey)] + # print str(idKey), identsList["D" + str(idKey)] if identsList["D" + str(idKey)].startswith("ID"): identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) paramToSend += identsList["D" + str(idKey)] - print str(idKey), identsList["D" + str(idKey)] + # print str(idKey), identsList["D" + str(idKey)] print response = ecu.run_cmd(command,paramToSend) From 3b1129fa419bcfb28fb57b56b59a21a66ea459b8 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Wed, 5 Feb 2020 21:57:59 +0100 Subject: [PATCH 11/57] Counter 2 only for 10779 --- pyren/scen_ecri_counter2.py | 85 ++++++++++++++++++++++++++++++++++++ pyren/scen_ecri_paraminj2.py | 23 +++++++++- 2 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 pyren/scen_ecri_counter2.py diff --git a/pyren/scen_ecri_counter2.py b/pyren/scen_ecri_counter2.py new file mode 100644 index 0000000..b0b4c03 --- /dev/null +++ b/pyren/scen_ecri_counter2.py @@ -0,0 +1,85 @@ +#!/usr/bin/env python + +import os +import sys +import re +import time +import string +import mod_globals +import mod_utils +import mod_ecu +from mod_utils import clearScreen +from mod_utils import pyren_encode +from mod_utils import KBHit +import xml.dom.minidom + +def run( elm, ecu, command, data ): + + clearScreen() + header = '['+command.codeMR+'] '+command.label + + ScmSet = {} + ScmParam = {} + + def get_message( msg ): + if msg in ScmParam.keys(): + value = ScmParam[msg] + else: + value = msg + if value.isdigit() and value in mod_globals.language_dict.keys(): + value = pyren_encode( mod_globals.language_dict[value] ) + return value + + def get_message_by_id( id ): + if id.isdigit() and id in mod_globals.language_dict.keys(): + value = pyren_encode( mod_globals.language_dict[id] ) + return value + + + DOMTree = xml.dom.minidom.parse(data) + ScmRoom = DOMTree.documentElement + + ScmParams = ScmRoom.getElementsByTagName("ScmParam") + + for Param in ScmParams: + name = pyren_encode( Param.getAttribute("name") ) + value = pyren_encode( Param.getAttribute("value") ) + + ScmParam[name] = value + + ScmSets = ScmRoom.getElementsByTagName("ScmSet") + + for Set in ScmSets: + setname = pyren_encode(Set.getAttribute("name")) + ScmParams = Set.getElementsByTagName("ScmParam") + + for Param in ScmParams: + name = pyren_encode( Param.getAttribute("name") ) + value = pyren_encode( Param.getAttribute("value") ) + + ScmSet[setname]= value + ScmParam[name] = value + + kb = KBHit() + + paramsToSend = "" + + identList = ['ID101', 'ID102', 'ID103', 'ID125', 'ID126', 'ID105', 'ID106', 'ID107', 'ID108', 'ID109', 'ID110', 'ID111', 'ID112', 'ID113', 'ID114', 'ID115', 'ID116', 'ID117', 'ID118', 'ID119', 'ID120', 'ID121', '00000000', 'ID123', 'ID124', 'ID186', 'ID187'] + + for ident in identList: + if ident.startswith("ID"): + paramsToSend += ecu.get_id(ident, 1) + else: + paramsToSend += ident + + ch = raw_input('Do you want to continue? ') + while (ch.upper() != 'YES') and (ch.upper()!= 'NO'): + ch = raw_input('Do you want to continue? ') + if ch.upper() != 'YES': + return + + responce = ecu.run_cmd(ScmParam['Cmde1'], paramsToSend) + + print + ch = raw_input('Press ENTER to exit') + return diff --git a/pyren/scen_ecri_paraminj2.py b/pyren/scen_ecri_paraminj2.py index 94a1f0d..51c7a39 100644 --- a/pyren/scen_ecri_paraminj2.py +++ b/pyren/scen_ecri_paraminj2.py @@ -59,11 +59,30 @@ def run( elm, ecu, command, data ): ScmSet[setname]= value ScmParam[name] = value - print setname, value - print name + # print setname, value + # print name kb = KBHit() + # ids = [] + # for param in ScmParam.keys(): + # if param == "IdentsZBegin": + # key = param[6:-5] + # begin = int(ScmParam['Idents'+key+'Begin']) + # end = int(ScmParam['Idents'+key+'End']) + # for idnum in range(begin ,end + 1): + # ids.append(ScmParam['Ident'+str(idnum)]) + # print ids + + # for ident in identList: + # if ident.startswith("ID") + # paramsToSend += ecu.get_id(ident, 1) + # else: + # paramsToSend += ident +# ['ID101', 'ID102', 'ID103', 'ID125', 'ID126', 'ID105', 'ID106', 'ID107', 'ID108', 'ID109', 'ID110', 'ID111', 'ID112', 'ID113', 'ID114', 'ID115', 'ID116', 'ID117', 'ID118', 'ID119', 'ID120', 'ID121', 'ID122', 'ID123', 'ID124', 'ID186', 'ID187'] + + # responce = ecu.run_cmd(ScmParam['Cmde1'], paramsToSend) + # mainText = get_message('TexteTitre') # important = get_message('TexteConsigne') # tilt = get_message('TexteValeurInclinaison') From 2ac78d130e1a2cb0aee393a05518429a3ba64848 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Wed, 5 Feb 2020 22:45:42 +0100 Subject: [PATCH 12/57] Cleaning paraminj2 --- pyren/scen_ecri_paraminj2.py | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/pyren/scen_ecri_paraminj2.py b/pyren/scen_ecri_paraminj2.py index 51c7a39..1caeae3 100644 --- a/pyren/scen_ecri_paraminj2.py +++ b/pyren/scen_ecri_paraminj2.py @@ -64,24 +64,6 @@ def run( elm, ecu, command, data ): kb = KBHit() - # ids = [] - # for param in ScmParam.keys(): - # if param == "IdentsZBegin": - # key = param[6:-5] - # begin = int(ScmParam['Idents'+key+'Begin']) - # end = int(ScmParam['Idents'+key+'End']) - # for idnum in range(begin ,end + 1): - # ids.append(ScmParam['Ident'+str(idnum)]) - # print ids - - # for ident in identList: - # if ident.startswith("ID") - # paramsToSend += ecu.get_id(ident, 1) - # else: - # paramsToSend += ident -# ['ID101', 'ID102', 'ID103', 'ID125', 'ID126', 'ID105', 'ID106', 'ID107', 'ID108', 'ID109', 'ID110', 'ID111', 'ID112', 'ID113', 'ID114', 'ID115', 'ID116', 'ID117', 'ID118', 'ID119', 'ID120', 'ID121', 'ID122', 'ID123', 'ID124', 'ID186', 'ID187'] - - # responce = ecu.run_cmd(ScmParam['Cmde1'], paramsToSend) # mainText = get_message('TexteTitre') # important = get_message('TexteConsigne') From 957c44e9a2ad22f1706163126869be2b363d65b8 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Wed, 5 Feb 2020 22:46:47 +0100 Subject: [PATCH 13/57] Counter 2 turn off --- pyren/scen_ecri_counter2.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pyren/scen_ecri_counter2.py b/pyren/scen_ecri_counter2.py index b0b4c03..b6f2319 100644 --- a/pyren/scen_ecri_counter2.py +++ b/pyren/scen_ecri_counter2.py @@ -62,24 +62,24 @@ def run( elm, ecu, command, data ): kb = KBHit() - paramsToSend = "" + # paramsToSend = "" - identList = ['ID101', 'ID102', 'ID103', 'ID125', 'ID126', 'ID105', 'ID106', 'ID107', 'ID108', 'ID109', 'ID110', 'ID111', 'ID112', 'ID113', 'ID114', 'ID115', 'ID116', 'ID117', 'ID118', 'ID119', 'ID120', 'ID121', '00000000', 'ID123', 'ID124', 'ID186', 'ID187'] + # identList = ['ID101', 'ID102', 'ID103', 'ID125', 'ID126', 'ID105', 'ID106', 'ID107', 'ID108', 'ID109', 'ID110', 'ID111', 'ID112', 'ID113', 'ID114', 'ID115', 'ID116', 'ID117', 'ID118', 'ID119', 'ID120', 'ID121', '00000000', 'ID123', 'ID124', 'ID186', 'ID187'] - for ident in identList: - if ident.startswith("ID"): - paramsToSend += ecu.get_id(ident, 1) - else: - paramsToSend += ident + # for ident in identList: + # if ident.startswith("ID"): + # paramsToSend += ecu.get_id(ident, 1) + # else: + # paramsToSend += ident - ch = raw_input('Do you want to continue? ') - while (ch.upper() != 'YES') and (ch.upper()!= 'NO'): - ch = raw_input('Do you want to continue? ') - if ch.upper() != 'YES': - return + # ch = raw_input('Do you want to continue? ') + # while (ch.upper() != 'YES') and (ch.upper()!= 'NO'): + # ch = raw_input('Do you want to continue? ') + # if ch.upper() != 'YES': + # return - responce = ecu.run_cmd(ScmParam['Cmde1'], paramsToSend) + # responce = ecu.run_cmd(ScmParam['Cmde1'], paramsToSend) - print + # print ch = raw_input('Press ENTER to exit') return From b2dba05257da11df24cdec537c5ace22b46e7a3c Mon Sep 17 00:00:00 2001 From: Marianpol Date: Thu, 6 Feb 2020 11:27:35 +0100 Subject: [PATCH 14/57] Get idents when screen is loading --- pyren/scen_ecri_paraminj1.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 08f89db..b091aaa 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -272,6 +272,22 @@ def run( elm, ecu, command, data ): def resetValues(title, button, command, rangeKey): paramToSend = "" params = getValuesToChange(title) + + if params: + idRangeKey = identsKeys[identsKeys.keys()[rangeKey]] + + for k,v in params.iteritems(): + if v in identsList.keys(): + identsList[k] = ecu.get_id(identsList[v], 1) + else: + identsList[k] = v + + for idKey in range(idRangeKey['begin'], idRangeKey['end'] + 1): + # print str(idKey), identsList["D" + str(idKey)] + if identsList["D" + str(idKey)].startswith("ID"): + identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) + paramToSend += identsList["D" + str(idKey)] + # print str(idKey), identsList["D" + str(idKey)] clearScreen() @@ -305,21 +321,6 @@ def run( elm, ecu, command, data ): ch = raw_input('Press ENTER to exit') return - idRangeKey = identsKeys[identsKeys.keys()[rangeKey]] - - for k,v in params.iteritems(): - if v in identsList.keys(): - identsList[k] = ecu.get_id(identsList[v], 1) - else: - identsList[k] = v - - for idKey in range(idRangeKey['begin'], idRangeKey['end'] + 1): - # print str(idKey), identsList["D" + str(idKey)] - if identsList["D" + str(idKey)].startswith("ID"): - identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) - paramToSend += identsList["D" + str(idKey)] - # print str(idKey), identsList["D" + str(idKey)] - print response = ecu.run_cmd(command,paramToSend) print From 3d1b62ed45c1ab4f74180c3ec74d280103d044f2 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Thu, 6 Feb 2020 18:18:09 +0100 Subject: [PATCH 15/57] Changes --- pyren/scen_ecri_paraminj1.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index b091aaa..4e3c4aa 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -174,15 +174,24 @@ def run( elm, ecu, command, data ): break elif ecuSet.ncalib == "Other": correctEcu = ecuSet + break else: correctEcu = ecuSet + break else: correctEcu = ecuSet + break else: correctEcu = ecusList[0] - + if not correctEcu and mod_globals.opt_demo: correctEcu = ecusList[0] + + if vdiagExists: + if not correctEcu: + print '*'*80 + ch = raw_input('Unknown diagnostic version. Press ENTER to exit') + return # for i in ecusList: # print i.vdiag @@ -308,21 +317,12 @@ def run( elm, ecu, command, data ): return clearScreen() - - if not params: #VP042 for INLET_FLAP - print - response = ecu.run_cmd(command) - print - if "NR" in response: - print failMessage - else: - print successMessage - print - ch = raw_input('Press ENTER to exit') - return print - response = ecu.run_cmd(command,paramToSend) + if params: + response = ecu.run_cmd(command,paramToSend) + else: #VP042 for INLET_FLAP + response = ecu.run_cmd(command) print if "NR" in response: From 168474a944ced96d4b23072ef702b9bd3284514c Mon Sep 17 00:00:00 2001 From: Marianpol Date: Thu, 6 Feb 2020 20:13:58 +0100 Subject: [PATCH 16/57] Glow plugs type scenario added --- pyren/scen_ecri_paraminj1.py | 94 ++++++++++++++++++++++++++++-------- 1 file changed, 75 insertions(+), 19 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 4e3c4aa..542fea0 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -222,7 +222,7 @@ def run( elm, ecu, command, data ): if l.startswith("Button"): if str(correctEcu.buttons[l]) == 'true': buttons[int(l.strip('Button'))] = get_message(l[:-6] + "Text") - + buttons["exit"] = '' #Get commands commands = {} @@ -251,19 +251,6 @@ def run( elm, ecu, command, data ): for idnum in range(begin ,end + 1): identsList['D'+str(idnum)] = ScmParam['Ident'+str(idnum)] - # def getIdents(start, end): - # identsDict = OrderedDict() - # for idnum in range(start,end + 1): - # identsDict['D'+str(idnum)] = ScmParam['Ident'+str(idnum)] - # return identsDict - - # for param in ScmParam.keys(): - # if param.startswith('Idents') and param.endswith('Begin'): - # key = param[6:-5] - # start = int(ScmParam['Idents'+key+'Begin']) - # end = int(ScmParam['Idents'+key+'End']) - # identsList[key] = getIdents(start, end) - def getValuesToChange(resetItem): params = {} for child in root: @@ -278,6 +265,69 @@ def run( elm, ecu, command, data ): failMessage = get_message('MessageNACK') mainText = get_message('Title') + def setGlowPlugsType(title, button, command, rangeKey): + paramToSend = "" + params = getValuesToChange(title) + currentType = ecu.get_id(identsList[params["IdentToBeDisplayed"].replace("Ident", "D")], 1) + slowTypeValue = get_message('ValueSlowParam') + fastTypeValue = get_message('ValueFastParam') + currentMessage = get_message('Current') + slowMessage = get_message('Slow') + fastMessage = get_message('Fast') + notDefinedMessage = get_message('NotDefined') + message2 = get_message('Message282') + + typesButtons = OrderedDict() + + typesButtons[slowMessage] = slowTypeValue + typesButtons[fastMessage] = fastTypeValue + typesButtons[''] = "" + + clearScreen() + + print mainText + print '*'*80 + print buttons[button] + print '*'*80 + print message2 + print '*'*80 + print + if currentType == slowTypeValue: + print currentMessage + ': ' + slowMessage + elif currentType == fastTypeValue: + print currentMessage + ': ' + fastMessage + else: + print currentMessage + ': ' + notDefinedMessage + print + + choice = Choice(typesButtons.keys(), "Choose :") + if choice[0]=='': return + + idRangeKey = identsKeys[identsKeys.keys()[rangeKey]] + + identsList[params["IdentToBeDisplayed"].replace("Ident", "D")] = typesButtons[choice[0]] + + for idKey in range(idRangeKey['begin'], idRangeKey['end'] + 1): + # print str(idKey), identsList["D" + str(idKey)] + if identsList["D" + str(idKey)].startswith("ID"): + identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) + paramToSend += identsList["D" + str(idKey)] + # print str(idKey), identsList["D" + str(idKey)] + + clearScreen() + + print + response = ecu.run_cmd(command,paramToSend) + print + + if "NR" in response: + print failMessage + else: + print successMessage + + print + ch = raw_input('Press ENTER to exit') + def resetValues(title, button, command, rangeKey): paramToSend = "" params = getValuesToChange(title) @@ -301,15 +351,16 @@ def run( elm, ecu, command, data ): clearScreen() print mainText - print + print '*'*80 print buttons[button] - print + print '*'*80 if button == 4: print get_message_by_id('55662') - print + print '*'*80 if button == 5: print get_message_by_id('55663') - print + print '*'*80 + print ch = raw_input(confirm + ' : ') while (ch.upper()!='YES') and (ch.upper()!='NO'): ch = raw_input(confirm + ' : ') @@ -339,6 +390,7 @@ def run( elm, ecu, command, data ): functions[3] = ["INLET_FLAP", 3, commands['Cmd6'], 1] functions[4] = ["PARTICLE_FILTER", 4, commands['Cmd7'], 2] functions[5] = ["Button5ChangeData", 5, commands['Cmd7'], 2] + functions[8] = ["Button8DisplayData", 8, commands["Cmd9"], 3] infoMessage = get_message('Message1') @@ -349,6 +401,10 @@ def run( elm, ecu, command, data ): choice = Choice(buttons.values(), "Choose :") for key, value in buttons.iteritems(): + if choice[0]=='': return if value == choice[0]: - resetValues(functions[key][0],functions[key][1],functions[key][2],functions[key][3]) + if key == 8: + setGlowPlugsType(functions[key][0],functions[key][1],functions[key][2],functions[key][3]) + else: + resetValues(functions[key][0],functions[key][1],functions[key][2],functions[key][3]) return \ No newline at end of file From e4aae925b1438593f06f794330ebf10f0e499a44 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Thu, 6 Feb 2020 20:27:02 +0100 Subject: [PATCH 17/57] Not supported list added --- pyren/scen_ecri_paraminj1.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 542fea0..a259a9c 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -399,10 +399,16 @@ def run( elm, ecu, command, data ): print infoMessage print + notSupported =[1,6,7] + choice = Choice(buttons.values(), "Choose :") + for key, value in buttons.iteritems(): if choice[0]=='': return if value == choice[0]: + if key in notSupported: + ch = raw_input("\nNot Supported yet. Press ENTER to exit") + return if key == 8: setGlowPlugsType(functions[key][0],functions[key][1],functions[key][2],functions[key][3]) else: From 0ebf21501f4f06e868fc561e7462c4305e95ed3e Mon Sep 17 00:00:00 2001 From: Marianpol Date: Fri, 7 Feb 2020 10:56:54 +0100 Subject: [PATCH 18/57] Fix#13 --- pyren/scen_ecri_paraminj1.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index a259a9c..614fc0e 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -264,6 +264,7 @@ def run( elm, ecu, command, data ): successMessage = get_message('Message32') failMessage = get_message('MessageNACK') mainText = get_message('Title') + inProgressMessage = get_message('CommandInProgressMessage') def setGlowPlugsType(title, button, command, rangeKey): paramToSend = "" @@ -303,6 +304,11 @@ def run( elm, ecu, command, data ): choice = Choice(typesButtons.keys(), "Choose :") if choice[0]=='': return + clearScreen() + + print + print inProgressMessage + idRangeKey = identsKeys[identsKeys.keys()[rangeKey]] identsList[params["IdentToBeDisplayed"].replace("Ident", "D")] = typesButtons[choice[0]] @@ -386,11 +392,16 @@ def run( elm, ecu, command, data ): functions = OrderedDict() - functions[2] = ["EGR_VALVE", 2, commands['Cmd5'], 0] - functions[3] = ["INLET_FLAP", 3, commands['Cmd6'], 1] - functions[4] = ["PARTICLE_FILTER", 4, commands['Cmd7'], 2] - functions[5] = ["Button5ChangeData", 5, commands['Cmd7'], 2] - functions[8] = ["Button8DisplayData", 8, commands["Cmd9"], 3] + for cmdKey in commands.keys(): + if cmdKey == 'Cmd5': + functions[2] = ["EGR_VALVE", 2, commands['Cmd5'], 0] + if cmdKey == 'Cmd6': + functions[3] = ["INLET_FLAP", 3, commands['Cmd6'], 1] + if cmdKey == 'Cmd7': + functions[4] = ["PARTICLE_FILTER", 4, commands['Cmd7'], 2] + functions[5] = ["Button5ChangeData", 5, commands['Cmd7'], 2] + if cmdKey == 'Cmd9': + functions[8] = ["Button8DisplayData", 8, commands["Cmd9"], 3] infoMessage = get_message('Message1') From 9212bf1e66774352635ae9619fbe84fffd2781dd Mon Sep 17 00:00:00 2001 From: Marianpol Date: Fri, 7 Feb 2020 12:31:57 +0100 Subject: [PATCH 19/57] Injectors data reseting added --- pyren/scen_ecri_paraminj1.py | 43 ++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 614fc0e..9fd823c 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -266,6 +266,41 @@ def run( elm, ecu, command, data ): mainText = get_message('Title') inProgressMessage = get_message('CommandInProgressMessage') + def resetInjetorsData(button, commandsList): + injectorsInfoMessage = get_message('Message21') + response = "" + clearScreen() + + print mainText + print '*'*80 + print buttons[button] + print '*'*80 + print injectorsInfoMessage + print '*'*80 + print + + ch = raw_input(confirm + ' : ') + while (ch.upper()!='YES') and (ch.upper()!='NO'): + ch = raw_input(confirm + ' : ') + if ch.upper()!='YES': + return + + clearScreen() + + print + for command in commandsList: + response += ecu.run_cmd(command) + print + + if "NR" in response: + print failMessage + else: + print successMessage + + print + ch = raw_input('Press ENTER to exit') + + def setGlowPlugsType(title, button, command, rangeKey): paramToSend = "" params = getValuesToChange(title) @@ -393,6 +428,8 @@ def run( elm, ecu, command, data ): functions = OrderedDict() for cmdKey in commands.keys(): + if cmdKey == 'Cmd1': + functions[1] = [1, [commands['Cmd1'],commands['Cmd2'],commands['Cmd3'],commands['Cmd4']]] if cmdKey == 'Cmd5': functions[2] = ["EGR_VALVE", 2, commands['Cmd5'], 0] if cmdKey == 'Cmd6': @@ -410,7 +447,7 @@ def run( elm, ecu, command, data ): print infoMessage print - notSupported =[1,6,7] + notSupported = [6,7] choice = Choice(buttons.values(), "Choose :") @@ -420,7 +457,9 @@ def run( elm, ecu, command, data ): if key in notSupported: ch = raw_input("\nNot Supported yet. Press ENTER to exit") return - if key == 8: + if key == 1: + resetInjetorsData(functions[key][0],functions[key][1]) + elif key == 8: setGlowPlugsType(functions[key][0],functions[key][1],functions[key][2],functions[key][3]) else: resetValues(functions[key][0],functions[key][1],functions[key][2],functions[key][3]) From 6f84c940d5f57429f9f5fde4d53f0171e297d354 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Fri, 7 Feb 2020 13:44:21 +0100 Subject: [PATCH 20/57] Glow plugs scenario fixed --- pyren/scen_ecri_paraminj1.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 9fd823c..66d5dd0 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -70,7 +70,7 @@ def run( elm, ecu, command, data ): def get_message_by_id( id ): if id.isdigit() and id in mod_globals.language_dict.keys(): - value = pyren_encode( mod_globals.language_dict[id] ) + value = mod_globals.language_dict[id] return value # @@ -291,7 +291,7 @@ def run( elm, ecu, command, data ): for command in commandsList: response += ecu.run_cmd(command) print - + if "NR" in response: print failMessage else: @@ -307,7 +307,7 @@ def run( elm, ecu, command, data ): currentType = ecu.get_id(identsList[params["IdentToBeDisplayed"].replace("Ident", "D")], 1) slowTypeValue = get_message('ValueSlowParam') fastTypeValue = get_message('ValueFastParam') - currentMessage = get_message('Current') + currentMessage = get_message_by_id('52676') slowMessage = get_message('Slow') fastMessage = get_message('Fast') notDefinedMessage = get_message('NotDefined') @@ -320,7 +320,6 @@ def run( elm, ecu, command, data ): typesButtons[''] = "" clearScreen() - print mainText print '*'*80 print buttons[button] @@ -353,8 +352,8 @@ def run( elm, ecu, command, data ): if identsList["D" + str(idKey)].startswith("ID"): identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) paramToSend += identsList["D" + str(idKey)] - # print str(idKey), identsList["D" + str(idKey)] - + # print str(idKey), identsList["D" + str(idKey)] + # raw_input() clearScreen() print @@ -438,7 +437,7 @@ def run( elm, ecu, command, data ): functions[4] = ["PARTICLE_FILTER", 4, commands['Cmd7'], 2] functions[5] = ["Button5ChangeData", 5, commands['Cmd7'], 2] if cmdKey == 'Cmd9': - functions[8] = ["Button8DisplayData", 8, commands["Cmd9"], 3] + functions[8] = ["Button8DisplayData", 8, commands["Cmd9"], len(identsKeys) - 1] infoMessage = get_message('Message1') From 8d623a91ff3c29cdd896c86f51910ada7bbd5694 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sat, 8 Feb 2020 17:03:30 +0100 Subject: [PATCH 21/57] Reset each injector data --- pyren/scen_ecri_paraminj1.py | 25 +++++---- pyren/scen_ecri_paraminj2.py | 103 ----------------------------------- 2 files changed, 13 insertions(+), 115 deletions(-) delete mode 100644 pyren/scen_ecri_paraminj2.py diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 66d5dd0..e1d6d0d 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -257,7 +257,7 @@ def run( elm, ecu, command, data ): if child.attrib["name"] == resetItem: if len(child.keys()) == 1: for param in child: - params[param.attrib["name"]] = param.attrib["value"] + params[param.attrib["name"].replace("D0", "D")] = param.attrib["value"] return params confirm = get_message_by_id('19800') @@ -266,7 +266,7 @@ def run( elm, ecu, command, data ): mainText = get_message('Title') inProgressMessage = get_message('CommandInProgressMessage') - def resetInjetorsData(button, commandsList): + def resetInjetorsData(button, injectorsList): injectorsInfoMessage = get_message('Message21') response = "" clearScreen() @@ -279,17 +279,13 @@ def run( elm, ecu, command, data ): print '*'*80 print - ch = raw_input(confirm + ' : ') - while (ch.upper()!='YES') and (ch.upper()!='NO'): - ch = raw_input(confirm + ' : ') - if ch.upper()!='YES': - return + choice = Choice(injectorsList.keys(), "Choose :") + if choice[0]=='': return clearScreen() print - for command in commandsList: - response += ecu.run_cmd(command) + response = ecu.run_cmd(injectorsList[choice[0]]) print if "NR" in response: @@ -352,8 +348,7 @@ def run( elm, ecu, command, data ): if identsList["D" + str(idKey)].startswith("ID"): identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) paramToSend += identsList["D" + str(idKey)] - # print str(idKey), identsList["D" + str(idKey)] - # raw_input() + # print str(idKey), identsList["D" + str(idKey)] clearScreen() print @@ -428,7 +423,13 @@ def run( elm, ecu, command, data ): functions = OrderedDict() for cmdKey in commands.keys(): if cmdKey == 'Cmd1': - functions[1] = [1, [commands['Cmd1'],commands['Cmd2'],commands['Cmd3'],commands['Cmd4']]] + 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[''] = "" + functions[1] = [1, injectorsDict] if cmdKey == 'Cmd5': functions[2] = ["EGR_VALVE", 2, commands['Cmd5'], 0] if cmdKey == 'Cmd6': diff --git a/pyren/scen_ecri_paraminj2.py b/pyren/scen_ecri_paraminj2.py deleted file mode 100644 index 1caeae3..0000000 --- a/pyren/scen_ecri_paraminj2.py +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env python - -import os -import sys -import re -import time -import string -import mod_globals -import mod_utils -import mod_ecu -from mod_utils import clearScreen -from mod_utils import pyren_encode -from mod_utils import KBHit -import xml.dom.minidom - -def run( elm, ecu, command, data ): - - clearScreen() - header = '['+command.codeMR+'] '+command.label - - ScmSet = {} - ScmParam = {} - - def get_message( msg ): - if msg in ScmParam.keys(): - value = ScmParam[msg] - else: - value = msg - if value.isdigit() and value in mod_globals.language_dict.keys(): - value = pyren_encode( mod_globals.language_dict[value] ) - return value - - def get_message_by_id( id ): - if id.isdigit() and id in mod_globals.language_dict.keys(): - value = pyren_encode( mod_globals.language_dict[id] ) - return value - - - DOMTree = xml.dom.minidom.parse(data) - ScmRoom = DOMTree.documentElement - - ScmParams = ScmRoom.getElementsByTagName("ScmParam") - - for Param in ScmParams: - name = pyren_encode( Param.getAttribute("name") ) - value = pyren_encode( Param.getAttribute("value") ) - - ScmParam[name] = value - - ScmSets = ScmRoom.getElementsByTagName("ScmSet") - - for Set in ScmSets: - setname = pyren_encode(Set.getAttribute("name")) - ScmParams = Set.getElementsByTagName("ScmParam") - - for Param in ScmParams: - name = pyren_encode( Param.getAttribute("name") ) - value = pyren_encode( Param.getAttribute("value") ) - - ScmSet[setname]= value - ScmParam[name] = value - # print setname, value - # print name - - kb = KBHit() - - - # mainText = get_message('TexteTitre') - # important = get_message('TexteConsigne') - # tilt = get_message('TexteValeurInclinaison') - # degreeSymbol = get_message('TexteDegre') - # value2, datastr2 = ecu.get_pr(ScmParam['ParametreInclinaison']) - - # clearScreen() - # print pyren_encode(header) - # print mainText - # print '*'*80 - # print - # print important - # print - - ch = raw_input('Do you want to continue? ') - while (ch.upper() != 'YES') and (ch.upper()!= 'NO'): - ch = raw_input('Do you want to continue? ') - if ch.upper() != 'YES': - return - - # clearScreen() - # cmd = ecu.get_ref_cmd(get_message('Commande1')) - # resVal = ScmParam['ParametreCommande1'] - # print '*'*80 - # responce = ecu.run_cmd(ScmParam['Commande1'], resVal) - # print '*'*80 - # if 'NR' in responce: - # print get_message('TexteProcedureInterompue') - # else: - # print get_message('TexteInitialisationEffectuee') - # print - # print tilt, pyren_encode(':'), value2, degreeSymbol - # print - - # ch = raw_input('Press ENTER to exit') - # return From 7199698cf04d26435e3850153d6b6c7d293e0fbd Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sun, 9 Feb 2020 21:27:14 +0100 Subject: [PATCH 22/57] Check for non param command --- pyren/scen_ecri_paraminj1.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index e1d6d0d..28cb7f4 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -235,14 +235,14 @@ def run( elm, ecu, command, data ): #Get identifications identsList = OrderedDict() - identsKeys = OrderedDict() + identsRangeKeys = OrderedDict() for param in ScmParam.keys(): if param.startswith('Idents') and param.endswith('Begin'): key = param[6:-5] begin = int(ScmParam['Idents'+key+'Begin']) end = int(ScmParam['Idents'+key+'End']) - identsKeys[key] = {"begin": begin, "end": end} + identsRangeKeys[key] = {"begin": begin, "end": end} try: #10099 trap identsList['D'+str(begin)] = ScmParam['Ident'+str(begin)] except: @@ -339,7 +339,7 @@ def run( elm, ecu, command, data ): print print inProgressMessage - idRangeKey = identsKeys[identsKeys.keys()[rangeKey]] + idRangeKey = identsRangeKeys[identsRangeKeys.keys()[rangeKey]] identsList[params["IdentToBeDisplayed"].replace("Ident", "D")] = typesButtons[choice[0]] @@ -365,10 +365,18 @@ def run( elm, ecu, command, data ): def resetValues(title, button, command, rangeKey): paramToSend = "" + commandTakesParams = True params = getValuesToChange(title) - if params: - idRangeKey = identsKeys[identsKeys.keys()[rangeKey]] + 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 + + if commandTakesParams: + idRangeKey = identsRangeKeys[identsRangeKeys.keys()[rangeKey]] for k,v in params.iteritems(): if v in identsList.keys(): @@ -382,7 +390,6 @@ def run( elm, ecu, command, data ): identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) paramToSend += identsList["D" + str(idKey)] # print str(idKey), identsList["D" + str(idKey)] - clearScreen() print mainText @@ -405,9 +412,9 @@ def run( elm, ecu, command, data ): clearScreen() print - if params: + if commandTakesParams: response = ecu.run_cmd(command,paramToSend) - else: #VP042 for INLET_FLAP + else: response = ecu.run_cmd(command) print @@ -438,10 +445,10 @@ def run( elm, ecu, command, data ): functions[4] = ["PARTICLE_FILTER", 4, commands['Cmd7'], 2] functions[5] = ["Button5ChangeData", 5, commands['Cmd7'], 2] if cmdKey == 'Cmd9': - functions[8] = ["Button8DisplayData", 8, commands["Cmd9"], len(identsKeys) - 1] + functions[8] = ["Button8DisplayData", 8, commands["Cmd9"], len(identsRangeKeys) - 1] infoMessage = get_message('Message1') - + print mainText print print infoMessage From e52e5fea94bbd401712acd1901d527a1e2f3fa7e Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sun, 9 Feb 2020 21:41:30 +0100 Subject: [PATCH 23/57] Check for non param command fix --- pyren/scen_ecri_paraminj1.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 28cb7f4..e7c195e 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -374,6 +374,7 @@ def run( elm, ecu, command, data ): commandTakesParams = False else: commandTakesParams = True + break if commandTakesParams: idRangeKey = identsRangeKeys[identsRangeKeys.keys()[rangeKey]] From 8f5f8845d94013c7fd54eeabce01aa3d879db759 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sun, 9 Feb 2020 21:56:47 +0100 Subject: [PATCH 24/57] Cleaning file --- pyren/scen_ecri_paraminj1.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index e7c195e..e06b19c 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -193,19 +193,6 @@ def run( elm, ecu, command, data ): ch = raw_input('Unknown diagnostic version. Press ENTER to exit') return - # for i in ecusList: - # print i.vdiag - # print i.ncalib - # for l in i.buttons.keys(): - # print l - # print str(i.buttons[l]) - # print - - # print correctEcu.vdiag - # print correctEcu.ncalib - # for k,v in correctEcu.buttons.iteritems(): - # print k,v - #Prepare buttons buttons = OrderedDict() @@ -344,11 +331,10 @@ def run( elm, ecu, command, data ): identsList[params["IdentToBeDisplayed"].replace("Ident", "D")] = typesButtons[choice[0]] for idKey in range(idRangeKey['begin'], idRangeKey['end'] + 1): - # print str(idKey), identsList["D" + str(idKey)] if identsList["D" + str(idKey)].startswith("ID"): identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) paramToSend += identsList["D" + str(idKey)] - # print str(idKey), identsList["D" + str(idKey)] + clearScreen() print @@ -386,11 +372,10 @@ def run( elm, ecu, command, data ): identsList[k] = v for idKey in range(idRangeKey['begin'], idRangeKey['end'] + 1): - # print str(idKey), identsList["D" + str(idKey)] if identsList["D" + str(idKey)].startswith("ID"): identsList["D" + str(idKey)] = ecu.get_id(identsList["D" + str(idKey)], 1) paramToSend += identsList["D" + str(idKey)] - # print str(idKey), identsList["D" + str(idKey)] + clearScreen() print mainText From e15114bf49c6de892f59795d1e4e08122b12a271 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sun, 9 Feb 2020 23:37:30 +0100 Subject: [PATCH 25/57] Counter2 scenario for 01 family --- pyren/scen_ecri_counter2.py | 64 +++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 17 deletions(-) diff --git a/pyren/scen_ecri_counter2.py b/pyren/scen_ecri_counter2.py index b6f2319..0ce8bc5 100644 --- a/pyren/scen_ecri_counter2.py +++ b/pyren/scen_ecri_counter2.py @@ -11,6 +11,7 @@ import mod_ecu from mod_utils import clearScreen from mod_utils import pyren_encode from mod_utils import KBHit +import mod_ecu_mnemonic import xml.dom.minidom def run( elm, ecu, command, data ): @@ -62,24 +63,53 @@ def run( elm, ecu, command, data ): kb = KBHit() - # paramsToSend = "" - - # identList = ['ID101', 'ID102', 'ID103', 'ID125', 'ID126', 'ID105', 'ID106', 'ID107', 'ID108', 'ID109', 'ID110', 'ID111', 'ID112', 'ID113', 'ID114', 'ID115', 'ID116', 'ID117', 'ID118', 'ID119', 'ID120', 'ID121', '00000000', 'ID123', 'ID124', 'ID186', 'ID187'] - - # for ident in identList: - # if ident.startswith("ID"): - # paramsToSend += ecu.get_id(ident, 1) - # else: - # paramsToSend += ident - - # ch = raw_input('Do you want to continue? ') - # while (ch.upper() != 'YES') and (ch.upper()!= 'NO'): - # ch = raw_input('Do you want to continue? ') - # if ch.upper() != 'YES': - # return + confirm = get_message_by_id('19800') + title = get_message("Title") + messageInfo = get_message("Message1") + succesMessage = get_message("CommandFinished") + failMessage = get_message("CommandImpossible") - # responce = ecu.run_cmd(ScmParam['Cmde1'], paramsToSend) + mnemonics = ecu.get_ref_id(ScmParam["default"]).mnemolist - # print + if mnemonics[0][-2:] > mnemonics[1][-2:]: + mnemo1 = mnemonics[1] + mnemo2 = mnemonics[0] + else: + mnemo1 = mnemonics[0] + mnemo2 = mnemonics[1] + + byte1 = int(mnemo1[-2:]) + byte2 = int(re.findall("\d+", mnemo2)[1]) + byteCount = byte2 - byte1 - 1 + resetBytes = byteCount * "00" + + mnemo1Data = mod_ecu_mnemonic.get_mnemonic(ecu.Mnemonics[mnemo1], ecu.Services, elm, 1) + mnemo2Data = mod_ecu_mnemonic.get_mnemonic(ecu.Mnemonics[mnemo2], ecu.Services, elm, 1) + + paramsToSend = mnemo1Data + resetBytes + mnemo2Data + + print title + print '*'*80 + print messageInfo + print '*'*80 + print + ch = raw_input(confirm + ' : ') + while (ch.upper()!='YES') and (ch.upper()!='NO'): + ch = raw_input(confirm + ' : ') + if ch.upper()!='YES': + return + + clearScreen() + + print + response = ecu.run_cmd(ScmParam['Cmde1'], paramsToSend) + print + + if "NR" in response: + print failMessage + else: + print succesMessage + + print ch = raw_input('Press ENTER to exit') return From 12c90d47cbd968c9d8b2cb605116469625b859de Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sun, 9 Feb 2020 23:42:53 +0100 Subject: [PATCH 26/57] Variables name changed --- pyren/scen_ecri_counter2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyren/scen_ecri_counter2.py b/pyren/scen_ecri_counter2.py index 0ce8bc5..31a2171 100644 --- a/pyren/scen_ecri_counter2.py +++ b/pyren/scen_ecri_counter2.py @@ -78,9 +78,9 @@ def run( elm, ecu, command, data ): mnemo1 = mnemonics[0] mnemo2 = mnemonics[1] - byte1 = int(mnemo1[-2:]) - byte2 = int(re.findall("\d+", mnemo2)[1]) - byteCount = byte2 - byte1 - 1 + byteFrom = int(mnemo1[-2:]) + byteTo = int(re.findall("\d+", mnemo2)[1]) + byteCount = byteTo - byteFrom - 1 resetBytes = byteCount * "00" mnemo1Data = mod_ecu_mnemonic.get_mnemonic(ecu.Mnemonics[mnemo1], ecu.Services, elm, 1) From d4476564d6c93a707e75104367d0ccb3ae6367dc Mon Sep 17 00:00:00 2001 From: Marianpol Date: Tue, 11 Feb 2020 00:35:15 +0100 Subject: [PATCH 27/57] After ECU change scenario added --- pyren/scen_ecri_paraminj1.py | 71 +++++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index e06b19c..ac2b74d 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -283,6 +283,72 @@ def run( elm, ecu, command, data ): print ch = raw_input('Press ENTER to exit') + def afterEcuChange(title, button, command, rangeKey): + paramToSend = "" + params = getValuesToChange(title) + infoMessage = get_message("Message262") + mileageText = get_message_by_id('2110') + + clearScreen() + print mainText + print '*'*80 + print buttons[button] + print '*'*80 + print infoMessage + print '*'*80 + print get_message("MessageBox2") + print + ch = raw_input(confirm + ' : ') + if ch.upper()!='YES': + return + mileage = raw_input(mileageText + ': ') + while not (mileage.isdigit() and 2 <= len(mileage) <= 6 and int(mileage) > 10): + print get_message("MessageBox1") + print + mileage = raw_input(mileageText + ': ') + + clearScreen() + + print mileageText + ': ' + mileage + print + ch = raw_input(confirm + ' : ') + while (ch.upper()!='YES') and (ch.upper()!='NO'): + ch = raw_input(confirm + ' : ') + if ch.upper()!='YES': + return + + 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) + hexValue = "{0:0{1}X}".format(mileage,len(identValue)) + identsList[k] = hexValue + else: + identsList[k] = v + + 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)] + + clearScreen() + + print + response = ecu.run_cmd(command,paramToSend) + print + + if "NR" in response: + print failMessage + else: + print successMessage + + print + ch = raw_input('Press ENTER to exit') def setGlowPlugsType(title, button, command, rangeKey): paramToSend = "" @@ -430,6 +496,7 @@ def run( elm, ecu, command, data ): 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] if cmdKey == 'Cmd9': functions[8] = ["Button8DisplayData", 8, commands["Cmd9"], len(identsRangeKeys) - 1] @@ -440,7 +507,7 @@ def run( elm, ecu, command, data ): print infoMessage print - notSupported = [6,7] + notSupported = [7] choice = Choice(buttons.values(), "Choose :") @@ -452,6 +519,8 @@ def run( elm, ecu, command, data ): return if 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]) elif key == 8: setGlowPlugsType(functions[key][0],functions[key][1],functions[key][2],functions[key][3]) else: From 70c28ebe6e93bf3a1acb1206ee5cbf45c87a3940 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Tue, 11 Feb 2020 11:53:04 +0100 Subject: [PATCH 28/57] Refactor --- pyren/scen_ecri_paraminj1.py | 68 +++++++++++++++++------------------- 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index ac2b74d..f9f9847 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -196,19 +196,19 @@ def run( elm, ecu, command, data ): #Prepare buttons buttons = OrderedDict() - for l in correctEcu.buttons.keys(): - if l == 'InjectorsButton': - if str(correctEcu.buttons[l]) == 'true': + for bt in correctEcu.buttons.keys(): + if bt == 'InjectorsButton': + if str(correctEcu.buttons[bt]) == 'true': buttons[1] = get_message("Injectors") - if l == 'EGRValveButton': - if str(correctEcu.buttons[l]) == 'true': + if bt == 'EGRValveButton': + if str(correctEcu.buttons[bt]) == 'true': buttons[2] = get_message("EGR_VALVE") - if l == 'InletFlapButton': - if str(correctEcu.buttons[l]) == 'true': + if bt == 'InletFlapButton': + if str(correctEcu.buttons[bt]) == 'true': buttons[3] = get_message("INLET_FLAP") - if l.startswith("Button"): - if str(correctEcu.buttons[l]) == 'true': - buttons[int(l.strip('Button'))] = get_message(l[:-6] + "Text") + if bt.startswith("Button"): + if str(correctEcu.buttons[bt]) == 'true': + buttons[int(bt.strip('Button'))] = get_message(bt[:-6] + "Text") buttons["exit"] = '' #Get commands @@ -246,6 +246,16 @@ 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 confirm = get_message_by_id('19800') successMessage = get_message('Message32') @@ -284,7 +294,6 @@ def run( elm, ecu, command, data ): ch = raw_input('Press ENTER to exit') def afterEcuChange(title, button, command, rangeKey): - paramToSend = "" params = getValuesToChange(title) infoMessage = get_message("Message262") mileageText = get_message_by_id('2110') @@ -302,7 +311,7 @@ def run( elm, ecu, command, data ): if ch.upper()!='YES': return mileage = raw_input(mileageText + ': ') - while not (mileage.isdigit() and 2 <= len(mileage) <= 6 and int(mileage) > 10): + while not (mileage.isdigit() and 2 <= len(mileage) <= 6 and int(mileage) >= 10): print get_message("MessageBox1") print mileage = raw_input(mileageText + ': ') @@ -317,6 +326,11 @@ def run( elm, ecu, command, data ): if ch.upper()!='YES': return + clearScreen() + + print + print inProgressMessage + mileage = int(mileage) for k,v in params.iteritems(): @@ -324,17 +338,11 @@ def run( elm, ecu, command, data ): identsList[k] = ecu.get_id(identsList[v], 1) elif v == "Mileage": identValue = ecu.get_id(identsList[k], 1) - hexValue = "{0:0{1}X}".format(mileage,len(identValue)) - identsList[k] = hexValue + identsList[k] = "{0:0{1}X}".format(mileage,len(identValue)) else: identsList[k] = v - - 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)] + + paramToSend = getValuesFromEcu(rangeKey) clearScreen() @@ -351,7 +359,6 @@ def run( elm, ecu, command, data ): ch = raw_input('Press ENTER to exit') def setGlowPlugsType(title, button, command, rangeKey): - paramToSend = "" params = getValuesToChange(title) currentType = ecu.get_id(identsList[params["IdentToBeDisplayed"].replace("Ident", "D")], 1) slowTypeValue = get_message('ValueSlowParam') @@ -388,18 +395,12 @@ def run( elm, ecu, command, data ): if choice[0]=='': return clearScreen() - print print inProgressMessage - idRangeKey = identsRangeKeys[identsRangeKeys.keys()[rangeKey]] - identsList[params["IdentToBeDisplayed"].replace("Ident", "D")] = typesButtons[choice[0]] - 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)] + paramToSend = getValuesFromEcu(rangeKey) clearScreen() @@ -429,18 +430,13 @@ def run( elm, ecu, command, data ): break if commandTakesParams: - idRangeKey = identsRangeKeys[identsRangeKeys.keys()[rangeKey]] - for k,v in params.iteritems(): if v in identsList.keys(): identsList[k] = ecu.get_id(identsList[v], 1) else: identsList[k] = v - - 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)] + + paramToSend = getValuesFromEcu(rangeKey) clearScreen() From 839edad66f60eafab5ef56066298a2c54e642e7d Mon Sep 17 00:00:00 2001 From: Marianpol Date: Tue, 11 Feb 2020 12:04:59 +0100 Subject: [PATCH 29/57] Space added --- pyren/scen_ecri_paraminj1.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index f9f9847..0b1243f 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -515,7 +515,7 @@ def run( elm, ecu, command, data ): return if key == 1: resetInjetorsData(functions[key][0],functions[key][1]) - elif key ==6: + elif key == 6: afterEcuChange(functions[key][0],functions[key][1],functions[key][2],functions[key][3]) elif key == 8: setGlowPlugsType(functions[key][0],functions[key][1],functions[key][2],functions[key][3]) From 253b597b968f6c3e9d07404c41ccbbb223ba9056 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sun, 16 Feb 2020 16:28:48 +0100 Subject: [PATCH 30/57] Paraminj2 added, paraminj1 mileage unit added --- pyren/scen_ecri_paraminj1.py | 7 +- pyren/scen_ecri_paraminj2.py | 461 +++++++++++++++++++++++++++++++++++ 2 files changed, 465 insertions(+), 3 deletions(-) create mode 100644 pyren/scen_ecri_paraminj2.py diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 0b1243f..0e026f4 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -297,6 +297,7 @@ def run( elm, ecu, command, data ): params = getValuesToChange(title) infoMessage = get_message("Message262") mileageText = get_message_by_id('2110') + mileageUnit = get_message_by_id('16521') clearScreen() print mainText @@ -310,15 +311,15 @@ def run( elm, ecu, command, data ): ch = raw_input(confirm + ' : ') if ch.upper()!='YES': return - mileage = raw_input(mileageText + ': ') + 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(mileageText + ': ') + mileage = raw_input(mileageText + ' (' + mileageUnit + ')' + ': ') clearScreen() - print mileageText + ': ' + mileage + print mileageText + ': ' + mileage + ' ' + mileageUnit print ch = raw_input(confirm + ' : ') while (ch.upper()!='YES') and (ch.upper()!='NO'): diff --git a/pyren/scen_ecri_paraminj2.py b/pyren/scen_ecri_paraminj2.py new file mode 100644 index 0000000..a8f9058 --- /dev/null +++ b/pyren/scen_ecri_paraminj2.py @@ -0,0 +1,461 @@ +#!/usr/bin/env python +''' +Scenarium usage example + +Name of this script should be exactly the same as in scenaruim URL but with '.py' extension + +URL - scm:scen_ecri_calinj1#scen_ecri_calinj1_xxxxx.xml + +'run' procedure will be executed by pyren script + +''' + +import os +import sys +import re +import time +import string +import mod_globals +import mod_utils +import mod_ecu +from mod_utils import pyren_encode +from mod_utils import clearScreen +from mod_utils import ASCIITOHEX +from mod_utils import StringToIntToHex +from mod_utils import Choice +from collections import OrderedDict +import xml.dom.minidom +import xml.etree.cElementTree as et + +class ecus: + + vdiag = "" + buttons = {} + ncalib = "" + + def __init__(self, vd, nc, bt): + self.vdiag = vd + self.ncalib = nc + self.buttons = bt + +def run( elm, ecu, command, data ): + ''' + MAIN function of scenarium + + Parameters: + elm - refernce to adapter class + ecu - reference to ecu class + command - refernce to the command this scenarium belongs to + data - name of xml file with parameters from scenarium URL + ''' + + clearScreen() + header = '['+command.codeMR+'] '+command.label + + ScmSet = {} + ScmParam = OrderedDict() + ecusList = [] + correctEcu = '' + vdiagExists = False + + def get_message( msg ): + 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] + return value + + def get_message_by_id( id ): + if id.isdigit() and id in mod_globals.language_dict.keys(): + value = mod_globals.language_dict[id] + return value + + # + # Data file parsing + # + DOMTree = xml.dom.minidom.parse(data) + ScmRoom = DOMTree.documentElement + + root = et.parse(data).getroot() + + ScmParams = ScmRoom.getElementsByTagName("ScmParam") + + for Param in ScmParams: + name = pyren_encode( Param.getAttribute("name") ) + value = pyren_encode( Param.getAttribute("value") ) + + ScmParam[name] = value + + ScmSets = ScmRoom.getElementsByTagName("ScmSet") + + for Set in ScmSets: + if len(Set.attributes) != 1: + setname = pyren_encode(mod_globals.language_dict[Set.getAttribute("name")]) + ScmParams = Set.getElementsByTagName("ScmParam") + + for Param in ScmParams: + name = pyren_encode( Param.getAttribute("name") ) + value = pyren_encode( Param.getAttribute("value") ) + + ScmSet[setname]= value + ScmParam[name] = value + + if "IdentVdiag" in ScmParam.keys(): + vdiagExists = True + + # Get nested buttons with VDiag + for vDiag in root: + if vDiag.attrib["name"] == "ListVdiag": + if len(vDiag.keys()) == 1: + for vDiagName in vDiag: + buttons = OrderedDict() + if vDiagName: + for vDiagButton in vDiagName: + buttons[vDiagButton.attrib["name"]] = vDiagButton.attrib["value"] + ecusList.append(ecus(vDiagName.attrib["name"], '', buttons)) + +# Get correct buttons set + if vdiagExists: + value1, datastr1 = ecu.get_id(ScmParam['IdentVdiag']) + for ecuSet in ecusList: + if ecuSet.vdiag == value1.upper(): + correctEcu = ecuSet + break + else: + correctEcu = ecusList[0] + + if not correctEcu and mod_globals.opt_demo: + correctEcu = ecusList[0] + + if vdiagExists: + if not correctEcu: + print '*'*80 + ch = raw_input('Unknown diagnostic version. Press ENTER to exit') + return + + #Prepare buttons + buttons = OrderedDict() + + for bt in correctEcu.buttons.keys(): + if bt == 'InjectorsButton': + if str(correctEcu.buttons[bt]) == 'true': + buttons[1] = get_message("Injectors") + if bt == 'EGRValveButton': + if str(correctEcu.buttons[bt]) == 'true': + buttons[2] = get_message("EGR_VALVE") + if bt == 'InletFlapButton': + if str(correctEcu.buttons[bt]) == 'true': + buttons[3] = get_message("INLET_FLAP") + if bt == 'ParticleFilterButton': + if str(correctEcu.buttons[bt]) == 'true': + buttons[4] = get_message("PARTICLES_FILTER") + if bt.startswith("Button"): + if str(correctEcu.buttons[bt]) == 'true': + buttons[int(bt.strip('Button'))] = get_message(bt[:-6] + "Text") + buttons["exit"] = '' + + #Get commands + commands = {} + + for child in root: + if child.attrib["name"] == "Commands": + if len(child.keys()) == 1: + for param in child: + commands[param.attrib["name"]] = param.attrib["value"] + + #Get identifications + identsList = OrderedDict() + identsRangeKeys = OrderedDict() + + for param in ScmParam.keys(): + if param.startswith('Idents') and param.endswith('Begin'): + 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)] + except: + break + else: + for idnum in range(begin ,end + 1): + identsList['D'+str(idnum)] = ScmParam['Ident'+str(idnum)] + + def getValuesToChange(resetItem): + params = {} + for child in root: + if child.attrib["name"] == resetItem: + if len(child.keys()) == 1: + 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 + + confirm = get_message_by_id('19800') + successMessage = get_message('Message32') + failMessage = get_message('MessageNACK') + mainText = get_message('Title') + inProgressMessage = get_message('CommandInProgressMessage') + + def resetInjetorsData(button, injectorsList): + injectorsInfoMessage = get_message('Message21') + response = "" + clearScreen() + + print mainText + print '*'*80 + print buttons[button] + print '*'*80 + print injectorsInfoMessage + print '*'*80 + print + + choice = Choice(injectorsList.keys(), "Choose :") + if choice[0]=='': return + + clearScreen() + + print + response = ecu.run_cmd(injectorsList[choice[0]]) + print + + if "NR" in response: + print failMessage + else: + print successMessage + + print + ch = raw_input('Press ENTER to exit') + + def afterEcuChange(title, button, command, rangeKey): + params = getValuesToChange(title) + infoMessage = get_message("Message262") + mileageText = get_message_by_id('2110') + mileageUnit = get_message_by_id('16521') + + clearScreen() + print mainText + print '*'*80 + print buttons[button] + print '*'*80 + print infoMessage + print '*'*80 + print get_message("MessageBox2") + print + ch = raw_input(confirm + ' : ') + if ch.upper()!='YES': + return + 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(mileageText + ' (' + mileageUnit + ')' + ': ') + + clearScreen() + + print mileageText + ': ' + mileage + ' ' + mileageUnit + print + 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 + + 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 + + paramToSend = getValuesFromEcu(rangeKey) + + clearScreen() + + print + response = ecu.run_cmd(command,paramToSend) + print + + if "NR" in response: + print failMessage + else: + print successMessage + + print + ch = raw_input('Press ENTER to exit') + + def setGlowPlugsType(title, button, command, rangeKey): + params = getValuesToChange(title) + value, datastr = ecu.get_st(ScmParam['State1']) + + message = get_message('Message29') + currentTypeMessage = get_message_by_id('52676') + + 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[''] = "" + + clearScreen() + print mainText + print '*'*80 + print buttons[button] + print '*'*80 + print message + print '*'*80 + print + print currentTypeMessage + ':' + print + print datastr + print + + choice = Choice(typesButtons.keys(), "Choose :") + if choice[0]=='': return + + clearScreen() + print + print inProgressMessage + + glowPlugType = "{0:0{1}X}".format((int(ScmParam['Mask1']) + int(typesButtons[choice[0]])),2) + + identsList[params.keys()[0]] = glowPlugType + + paramToSend = getValuesFromEcu(rangeKey) + + clearScreen() + + print + response = ecu.run_cmd(command,paramToSend) + print + + if "NR" in response: + print failMessage + else: + print successMessage + + print + ch = raw_input('Press ENTER to exit') + + def resetValues(title, button, command, rangeKey): + 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 + print '*'*80 + print buttons[button] + print '*'*80 + if button == 4: + print get_message_by_id('55662') + print '*'*80 + if button == 5: + print get_message_by_id('55663') + print '*'*80 + print + ch = raw_input(confirm + ' : ') + while (ch.upper()!='YES') and (ch.upper()!='NO'): + ch = raw_input(confirm + ' : ') + if ch.upper()!='YES': + return + + clearScreen() + + print + if commandTakesParams: + response = ecu.run_cmd(command,paramToSend) + else: + response = ecu.run_cmd(command) + print + + if "NR" in response: + print failMessage + else: + print successMessage + + print + ch = raw_input('Press ENTER to exit') + + + functions = OrderedDict() + 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[''] = "" + functions[1] = [1, injectorsDict] + if cmdKey == 'Cmd5': + functions[2] = ["EGR_VALVE", 2, commands['Cmd5'], 0] + if cmdKey == 'Cmd6': + functions[3] = ["INLET_FLAP", 3, commands['Cmd6'], 1] + 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] + if len(commands) == 1 and cmdKey == 'Cmd1': + functions[7] = ["Button7ChangeData", 7, commands["Cmd1"], len(identsRangeKeys) - 1] + + infoMessage = get_message('Message1') + + print mainText + print + print infoMessage + print + + choice = Choice(buttons.values(), "Choose :") + + for key, value in buttons.iteritems(): + if choice[0]=='': return + if value == choice[0]: + if 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]) + elif key == 7: + setGlowPlugsType(functions[key][0],functions[key][1],functions[key][2],functions[key][3]) + else: + resetValues(functions[key][0],functions[key][1],functions[key][2],functions[key][3]) + return \ No newline at end of file From 11cfdb4002555e2977e3793b88eee8796331c0bf Mon Sep 17 00:00:00 2001 From: shrlnm Date: Sun, 16 Feb 2020 22:54:56 +0300 Subject: [PATCH 31/57] some fixes with encoding and DB --- .idea/vcs.xml | 6 ++++++ pyren/mod_db_manager.py | 11 ++++++++++- pyren/scen_ecri_calinj1.py | 3 ++- pyren/scen_ecri_paraminj1.py | 19 ++++++++++--------- pyren/scen_ecri_paraminj2.py | 15 ++++++++------- 5 files changed, 36 insertions(+), 18 deletions(-) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pyren/mod_db_manager.py b/pyren/mod_db_manager.py index 1442470..676c02a 100644 --- a/pyren/mod_db_manager.py +++ b/pyren/mod_db_manager.py @@ -151,7 +151,16 @@ def get_file_from_clip( filename ): if mod_globals.clip_arc=='': return open(os.path.join(mod_globals.cliproot, filename), mode) else: - return mod_globals.clip_arc.open(filename, mode) + if filename.startswith('../'): + filename = filename[3:] + try: + f = mod_globals.clip_arc.open(filename, mode) + return f + except: + fn = filename.split('/')[-1] + lfn = fn.lower() + filename = filename.replace(fn,lfn) + return mod_globals.clip_arc.open(filename, mode) def file_in_clip( pattern ): if mod_globals.clip_arc=='': diff --git a/pyren/scen_ecri_calinj1.py b/pyren/scen_ecri_calinj1.py index f56b0e6..621a2ab 100755 --- a/pyren/scen_ecri_calinj1.py +++ b/pyren/scen_ecri_calinj1.py @@ -18,6 +18,7 @@ import string import mod_globals import mod_utils import mod_ecu +import mod_db_manager from mod_utils import pyren_encode from mod_utils import clearScreen from mod_utils import ASCIITOHEX @@ -59,7 +60,7 @@ def run( elm, ecu, command, data ): # # Data file parsing # - DOMTree = xml.dom.minidom.parse(data) + DOMTree = xml.dom.minidom.parse(mod_db_manager.get_file_from_clip(data)) ScmRoom = DOMTree.documentElement ScmParams = ScmRoom.getElementsByTagName("ScmParam") diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 0e026f4..5b40612 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -18,6 +18,7 @@ import string import mod_globals import mod_utils import mod_ecu +import mod_db_manager from mod_utils import pyren_encode from mod_utils import clearScreen from mod_utils import ASCIITOHEX @@ -76,10 +77,10 @@ def run( elm, ecu, command, data ): # # Data file parsing # - DOMTree = xml.dom.minidom.parse(data) + DOMTree = xml.dom.minidom.parse(mod_db_manager.get_file_from_clip(data)) ScmRoom = DOMTree.documentElement - root = et.parse(data).getroot() + root = et.parse(mod_db_manager.get_file_from_clip(data)).getroot() ScmParams = ScmRoom.getElementsByTagName("ScmParam") @@ -308,22 +309,22 @@ def run( elm, ecu, command, data ): print '*'*80 print get_message("MessageBox2") print - ch = raw_input(confirm + ' : ') + ch = raw_input(pyren_encode(confirm + ' : ')) if ch.upper()!='YES': return - mileage = raw_input(mileageText + ' (' + mileageUnit + ')' + ': ') + mileage = raw_input(pyren_encode(mileageText + ' (' + mileageUnit + ')' + ': ')) while not (mileage.isdigit() and 2 <= len(mileage) <= 6 and int(mileage) >= 10): print get_message("MessageBox1") print - mileage = raw_input(mileageText + ' (' + mileageUnit + ')' + ': ') + mileage = raw_input(pyren_encode(mileageText + ' (' + mileageUnit + ')' + ': ')) clearScreen() print mileageText + ': ' + mileage + ' ' + mileageUnit print - ch = raw_input(confirm + ' : ') + ch = raw_input(pyren_encode(confirm + ' : ')) while (ch.upper()!='YES') and (ch.upper()!='NO'): - ch = raw_input(confirm + ' : ') + ch = raw_input(pyren_encode(confirm + ' : ')) if ch.upper()!='YES': return @@ -452,9 +453,9 @@ def run( elm, ecu, command, data ): print get_message_by_id('55663') print '*'*80 print - ch = raw_input(confirm + ' : ') + ch = raw_input(pyren_encode(confirm + ' : ')) while (ch.upper()!='YES') and (ch.upper()!='NO'): - ch = raw_input(confirm + ' : ') + ch = raw_input(pyren_encode(confirm + ' : ')) if ch.upper()!='YES': return diff --git a/pyren/scen_ecri_paraminj2.py b/pyren/scen_ecri_paraminj2.py index a8f9058..7c96c4f 100644 --- a/pyren/scen_ecri_paraminj2.py +++ b/pyren/scen_ecri_paraminj2.py @@ -18,6 +18,7 @@ import string import mod_globals import mod_utils import mod_ecu +import mod_db_manager from mod_utils import pyren_encode from mod_utils import clearScreen from mod_utils import ASCIITOHEX @@ -75,10 +76,10 @@ def run( elm, ecu, command, data ): # # Data file parsing # - DOMTree = xml.dom.minidom.parse(data) + DOMTree = xml.dom.minidom.parse(mod_db_manager.get_file_from_clip(data)) ScmRoom = DOMTree.documentElement - root = et.parse(data).getroot() + root = et.parse(mod_db_manager.get_file_from_clip(data)).getroot() ScmParams = ScmRoom.getElementsByTagName("ScmParam") @@ -253,20 +254,20 @@ def run( elm, ecu, command, data ): print '*'*80 print get_message("MessageBox2") print - ch = raw_input(confirm + ' : ') + ch = raw_input(pyren_encode(confirm + ' : ')) if ch.upper()!='YES': return - mileage = raw_input(mileageText + ' (' + mileageUnit + ')' + ': ') + mileage = raw_input(pyren_encode(mileageText + ' (' + mileageUnit + ')' + ': ')) while not (mileage.isdigit() and 2 <= len(mileage) <= 6 and int(mileage) >= 10): print get_message("MessageBox1") print - mileage = raw_input(mileageText + ' (' + mileageUnit + ')' + ': ') + mileage = raw_input(pyren_encode(mileageText + ' (' + mileageUnit + ')' + ': ')) clearScreen() print mileageText + ': ' + mileage + ' ' + mileageUnit print - ch = raw_input(confirm + ' : ') + ch = raw_input(pyren_encode(confirm + ' : ')) while (ch.upper()!='YES') and (ch.upper()!='NO'): ch = raw_input(confirm + ' : ') if ch.upper()!='YES': @@ -393,7 +394,7 @@ def run( elm, ecu, command, data ): print get_message_by_id('55663') print '*'*80 print - ch = raw_input(confirm + ' : ') + ch = raw_input(pyren_encode(confirm + ' : ')) while (ch.upper()!='YES') and (ch.upper()!='NO'): ch = raw_input(confirm + ' : ') if ch.upper()!='YES': From 8b1341272092962cf35571899bec8d652072ec75 Mon Sep 17 00:00:00 2001 From: shrlnm Date: Mon, 17 Feb 2020 09:12:48 +0300 Subject: [PATCH 32/57] small fix --- .idea/vcs.xml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From ed07c8c9e254eceff4acf84a437ff269896211fb Mon Sep 17 00:00:00 2001 From: Marianpol Date: Mon, 17 Feb 2020 09:53:11 +0100 Subject: [PATCH 33/57] Loading scenario fix --- pyren/mod_ecu_scenario.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyren/mod_ecu_scenario.py b/pyren/mod_ecu_scenario.py index c885081..c2871bf 100755 --- a/pyren/mod_ecu_scenario.py +++ b/pyren/mod_ecu_scenario.py @@ -26,7 +26,7 @@ def playScenario(command, ecu, elm): if os.path.isfile('./'+scenarioName+'.py'): scen = __import__( scenarioName ) - scen.run( elm, ecu, command, '../'+path+scenarioData ) + scen.run( elm, ecu, command, './'+path+scenarioData ) return print "\nThere is scenarium. I do not support them!!!\n" From bac480136a313a1733913e35c0dfb07c7f2d211a Mon Sep 17 00:00:00 2001 From: Marianpol Date: Mon, 17 Feb 2020 11:09:21 +0100 Subject: [PATCH 34/57] Encoding added --- pyren/scen_ecri_paraminj1.py | 48 ++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 5b40612..8d6b620 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -60,18 +60,24 @@ def run( elm, ecu, command, data ): vdiagExists = False ncalibExists = 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 # @@ -200,16 +206,16 @@ 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.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["exit"] = '' #Get commands @@ -309,22 +315,22 @@ 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(pyren_encode(confirm + ' : ')) + ch = raw_input(confirm + ' : ') if ch.upper()!='YES': return @@ -366,8 +372,8 @@ def run( elm, ecu, command, data ): slowTypeValue = get_message('ValueSlowParam') fastTypeValue = get_message('ValueFastParam') currentMessage = get_message_by_id('52676') - slowMessage = get_message('Slow') - fastMessage = get_message('Fast') + slowMessage = get_message('Slow', 0) + fastMessage = get_message('Fast', 0) notDefinedMessage = get_message('NotDefined') message2 = get_message('Message282') @@ -453,9 +459,9 @@ 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(pyren_encode(confirm + ' : ')) + ch = raw_input(confirm + ' : ') if ch.upper()!='YES': return @@ -481,10 +487,10 @@ def run( elm, ecu, command, data ): for cmdKey in commands.keys(): if cmdKey == 'Cmd1': 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'] + injectorsDict[get_message('Cylinder2', 0)] = commands['Cmd2'] + injectorsDict[get_message('Cylinder3', 0)] = commands['Cmd3'] + injectorsDict[get_message('Cylinder4', 0)] = commands['Cmd4'] injectorsDict[''] = "" functions[1] = [1, injectorsDict] if cmdKey == 'Cmd5': From a3707c21ba58c780b4f37fc30fa1da1038a38330 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Mon, 17 Feb 2020 13:43:51 +0100 Subject: [PATCH 35/57] Loading scenarios fix for different DB types --- pyren/mod_ecu_scenario.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyren/mod_ecu_scenario.py b/pyren/mod_ecu_scenario.py index c2871bf..e3db8a2 100755 --- a/pyren/mod_ecu_scenario.py +++ b/pyren/mod_ecu_scenario.py @@ -26,7 +26,10 @@ def playScenario(command, ecu, elm): if os.path.isfile('./'+scenarioName+'.py'): scen = __import__( scenarioName ) - scen.run( elm, ecu, command, './'+path+scenarioData ) + if mod_globals.clip_arc: + scen.run( elm, ecu, command, '../'+path+scenarioData ) + else: + scen.run( elm, ecu, command, './'+path+scenarioData ) return print "\nThere is scenarium. I do not support them!!!\n" From 313841453397462448318e2d01cfbbe9f4a5f829 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Tue, 18 Feb 2020 17:31:05 +0100 Subject: [PATCH 36/57] Command linked to the frames --- pyren/scen_ecri_paraminj1.py | 134 ++++++++++++++++++++--------------- 1 file changed, 76 insertions(+), 58 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 8d6b620..497dc31 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -219,13 +219,19 @@ def run( elm, ecu, command, data ): buttons["exit"] = '' #Get commands - commands = {} + commands = OrderedDict() for child in root: 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() @@ -236,7 +242,6 @@ 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)] except: @@ -244,6 +249,8 @@ def run( elm, ecu, command, data ): 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 = {} @@ -253,16 +260,41 @@ 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 = "" + + 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(): + 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) + paramToSend += identsList["D" + str(idKey)] + commandToRun = isTakingParams + break + + return commandToRun, paramToSend confirm = get_message_by_id('19800') successMessage = get_message('Message32') @@ -300,7 +332,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') @@ -341,16 +373,12 @@ 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": + identValue = ecu.get_id(identsList[paramkey], 1) + params[paramkey] = "{0:0{1}X}".format(mileage,len(identValue)) - paramToSend = getValuesFromEcu(rangeKey) + command, paramToSend = getValuesFromEcu(params) clearScreen() @@ -366,7 +394,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) currentType = ecu.get_id(identsList[params["IdentToBeDisplayed"].replace("Ident", "D")], 1) slowTypeValue = get_message('ValueSlowParam') @@ -406,9 +434,10 @@ def run( elm, ecu, command, data ): print print inProgressMessage - identsList[params["IdentToBeDisplayed"].replace("Ident", "D")] = typesButtons[choice[0]] + params[params["IdentToBeDisplayed"].replace("Ident", "D")] = typesButtons[choice[0]] + params.pop("IdentToBeDisplayed") - paramToSend = getValuesFromEcu(rangeKey) + command, paramToSend = getValuesFromEcu(params) clearScreen() @@ -424,28 +453,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 @@ -465,13 +477,19 @@ def run( elm, ecu, command, data ): if ch.upper()!='YES': return + clearScreen() + print + print inProgressMessage + + command, paramToSend = getValuesFromEcu(params) + clearScreen() print - if commandTakesParams: + if command: response = ecu.run_cmd(command,paramToSend) else: - response = ecu.run_cmd(command) + response = ecu.run_cmd(defaultCommand) print if "NR" in response: @@ -487,22 +505,22 @@ def run( elm, ecu, command, data ): for cmdKey in commands.keys(): if cmdKey == 'Cmd1': injectorsDict = OrderedDict() - injectorsDict[get_message('Cylinder1', 0)] = commands['Cmd1'] - injectorsDict[get_message('Cylinder2', 0)] = commands['Cmd2'] - injectorsDict[get_message('Cylinder3', 0)] = commands['Cmd3'] - injectorsDict[get_message('Cylinder4', 0)] = 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 cmdKey == 'Cmd9': - functions[8] = ["Button8DisplayData", 8, commands["Cmd9"], len(identsRangeKeys) - 1] + functions[8] = ["Button8DisplayData", 8] infoMessage = get_message('Message1') @@ -524,9 +542,9 @@ def run( elm, ecu, command, data ): if 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 == 8: - 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 From 63af3e9909fac9140f5e2c403e221de011cc67e2 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Wed, 19 Feb 2020 22:43:49 +0100 Subject: [PATCH 37/57] Check for positive response, check for littleendian --- pyren/mod_ecu_mnemonic.py | 5 ++++- pyren/scen_ecri_paraminj1.py | 23 ++++++++++++++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pyren/mod_ecu_mnemonic.py b/pyren/mod_ecu_mnemonic.py index c2c2c52..d3649ee 100755 --- a/pyren/mod_ecu_mnemonic.py +++ b/pyren/mod_ecu_mnemonic.py @@ -65,7 +65,10 @@ def get_mnemonic( m, se, elm, raw = 0 ): hexval = hexval.replace(" ","") if raw: - return hexval + if resp.startswith(m.positive): + return hexval + else: + return 'ERROR' #shift and mask val = (int(hexval,16)>>rshift)&(2**bits-1) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index 497dc31..a4cd958 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -375,10 +375,23 @@ def run( elm, ecu, command, data ): 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) - params[paramkey] = "{0:0{1}X}".format(mileage,len(identValue)) + 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 command, paramToSend = getValuesFromEcu(params) + + if "ERROR" in paramToSend: + raw_input("Data downloading went wrong. Aborting.") + return clearScreen() @@ -438,6 +451,10 @@ def run( elm, ecu, command, data ): params.pop("IdentToBeDisplayed") command, paramToSend = getValuesFromEcu(params) + + if "ERROR" in paramToSend: + raw_input("Data downloading went wrong. Aborting.") + return clearScreen() @@ -483,6 +500,10 @@ def run( elm, ecu, command, data ): command, paramToSend = getValuesFromEcu(params) + if "ERROR" in paramToSend: + raw_input("Data downloading went wrong. Aborting.") + return + clearScreen() print From 4382d41159380703265c93c9d4a86297708f6f80 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Fri, 21 Feb 2020 14:29:03 +0100 Subject: [PATCH 38/57] Snapshot test #1 --- pyren/mod_ecu_default.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pyren/mod_ecu_default.py b/pyren/mod_ecu_default.py index 79b050f..1d0d164 100644 --- a/pyren/mod_ecu_default.py +++ b/pyren/mod_ecu_default.py @@ -384,6 +384,14 @@ class ecu_default: for dr in DataRef: dataref = ecu_screen_dataref( dr ) self.datarefs.append( dataref ) + MemorisedInfo = df.getElementsByTagName("MemorisedInfo") + if MemorisedInfo: + for mi in MemorisedInfo: + DataRef = mi.getElementsByTagName("DataRef") + if DataRef: + for dr in DataRef: + dataref = ecu_screen_dataref( dr ) + self.datarefs.append( dataref ) self.helps = [] Helps = df.getElementsByTagName("Helps") From ea1b6afb2c7b97fc3cf651a373474bd55f6e9137 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sat, 22 Feb 2020 00:48:24 +0100 Subject: [PATCH 39/57] Read Snapshot prototype --- pyren/mod_ecu.py | 7 ++-- pyren/mod_ecu_default.py | 4 ++- pyren/mod_ecu_mnemonic.py | 69 +++++++++++++++++++++++++++++++++++++ pyren/mod_ecu_parameter.py | 7 ++-- pyren/mod_globals.py | 1 + pyren/scen_ecri_counter2.py | 4 ++- 6 files changed, 86 insertions(+), 6 deletions(-) diff --git a/pyren/mod_ecu.py b/pyren/mod_ecu.py index c245581..c5b6dbe 100755 --- a/pyren/mod_ecu.py +++ b/pyren/mod_ecu.py @@ -431,7 +431,10 @@ class ECU: if dr.type=='State': datastr, help, csvd = get_state( self.States[dr.name], self.Mnemonics, self.Services, self.elm, self.calc ) if dr.type=='Parameter': - datastr, help, csvd = get_parameter( self.Parameters[dr.name], self.Mnemonics, self.Services, self.elm, self.calc ) + if self.DataIds and dr in self.Defaults[mod_globals.ext_cur_DTC[:4]].datarefs: + datastr, help, csvd = get_parameter( self.Parameters[dr.name], self.Mnemonics, self.Services, self.elm, self.calc, self.DataIds ) + else: + datastr, help, csvd = get_parameter( self.Parameters[dr.name], self.Mnemonics, self.Services, self.elm, self.calc ) if dr.type=='Identification': datastr, help, csvd = get_identification( self.Identifications[dr.name], self.Mnemonics, self.Services, self.elm, self.calc ) if dr.type=='Command': @@ -748,7 +751,7 @@ class ECU: path = path+' -> '+defstr[dtchex]+'\n\n'+hlpstr[dtchex]+'\n' - tmp_dtrf = self.Defaults[dtchex[:4]].datarefs + self.ext_de + tmp_dtrf = self.Defaults[dtchex[:4]].datarefs + self.Defaults[dtchex[:4]].ssdatarefs + self.ext_de #self.show_datarefs(self.Defaults[dtchex[:4]].datarefs, path) self.show_datarefs(tmp_dtrf, path) diff --git a/pyren/mod_ecu_default.py b/pyren/mod_ecu_default.py index 1d0d164..a5b6059 100644 --- a/pyren/mod_ecu_default.py +++ b/pyren/mod_ecu_default.py @@ -350,6 +350,7 @@ class ecu_default: label = "" status = 0 datarefs = [] + ssdatarefs = [] helps = [] caracter = {} interpInfoPeri = "" @@ -384,6 +385,7 @@ class ecu_default: for dr in DataRef: dataref = ecu_screen_dataref( dr ) self.datarefs.append( dataref ) + self.ssdatarefs = [] MemorisedInfo = df.getElementsByTagName("MemorisedInfo") if MemorisedInfo: for mi in MemorisedInfo: @@ -391,7 +393,7 @@ class ecu_default: if DataRef: for dr in DataRef: dataref = ecu_screen_dataref( dr ) - self.datarefs.append( dataref ) + self.ssdatarefs.append( dataref ) self.helps = [] Helps = df.getElementsByTagName("Helps") diff --git a/pyren/mod_ecu_mnemonic.py b/pyren/mod_ecu_mnemonic.py index d3649ee..eaa96b7 100755 --- a/pyren/mod_ecu_mnemonic.py +++ b/pyren/mod_ecu_mnemonic.py @@ -1,6 +1,7 @@ #!/usr/bin/env python from mod_ecu_service import * +from mod_globals import curPosInSnapshotResp from mod_utils import Choice from xml.dom.minidom import parse @@ -93,6 +94,74 @@ def get_mnemonic( m, se, elm, raw = 0 ): return hexval +def get_SnapShotMnemonic(m, se, elm, dataids): + snapshotService = "" + for sid in se: + if len(se[sid].params) > 1: + if se[sid].params[1]['type'] == 'Snapshot': + snapshotService = se[sid] + + resp = executeService( snapshotService, elm, [], "", True ) + resp = resp.strip().replace(' ','') + if not all(c in string.hexdigits for c in resp): resp = '' + resp = ' '.join(a+b for a,b in zip(resp[::2], resp[1::2])) + resp = resp[8*3:] + + if mod_globals.curPosInSnapshotResp >= len(resp): + mod_globals.curPosInSnapshotResp = 0 + + dataId = resp[mod_globals.curPosInSnapshotResp:mod_globals.curPosInSnapshotResp + 2*3].replace(" ", "") + + didDataLength = int(dataids[dataId].dataBitLength)/8 + didData = resp[mod_globals.curPosInSnapshotResp + 2*3: mod_globals.curPosInSnapshotResp + 2*3 + didDataLength*3] + mod_globals.curPosInSnapshotResp += 2*3 + didDataLength * 3 + + startByte = "" + startBit = "" + + for mn in dataids[dataId].mnemolocations.keys(): + if mn == m.name: + startByte = dataids[dataId].mnemolocations[m.name].startByte + startBit = dataids[dataId].mnemolocations[m.name].startBit + + #prepare local variables + sb = int(startByte) - 1 + bits = int(m.bitsLength) + sbit = int(startBit) + bytes = (bits+sbit-1)/8+1 + rshift = ((bytes+1)*8 - (bits+sbit))%8 + + #check length of responce + if (sb*3+bytes*3-1)>(len(didData)): + return '00' + + #extract hex + hexval = didData[sb*3:(sb+bytes)*3-1] + hexval = hexval.replace(" ","") + + #shift and mask + val = (int(hexval,16)>>rshift)&(2**bits-1) + + #format result + hexval = hex(val)[2:] + #remove 'L' + if hexval[-1:].upper()=='L': + hexval = hexval[:-1] + #add left zero if need + if len(hexval)%2: + hexval = '0'+hexval + + #revert byte order if little endian + if m.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 + + return hexval + class ecu_mnemonic: name = "" diff --git a/pyren/mod_ecu_parameter.py b/pyren/mod_ecu_parameter.py index e69c22e..3274b2b 100755 --- a/pyren/mod_ecu_parameter.py +++ b/pyren/mod_ecu_parameter.py @@ -7,7 +7,7 @@ from xml.dom.minidom import parseString import xml.dom.minidom import mod_globals -def get_parameter( pr, mn, se, elm, calc ): +def get_parameter( pr, mn, se, elm, calc, dataids = {} ): comp = pr.computation comp = comp.replace("&","&") @@ -15,7 +15,10 @@ def get_parameter( pr, mn, se, elm, calc ): for m in sorted(pr.mnemolist, key=len, reverse=True): - val = get_mnemonic( mn[m], se, elm ) + if dataids: + val = get_SnapShotMnemonic(mn[m], se, elm, dataids ) + else: + val = get_mnemonic( mn[m], se, elm ) if mn[m].type=="SNUM8" and int(val,16)>0x7f: val = str(int(val,16)-0x100) elif mn[m].type=="SNUM16" and int(val,16)>0x7fff: diff --git a/pyren/mod_globals.py b/pyren/mod_globals.py index 6b9a146..42fd73a 100755 --- a/pyren/mod_globals.py +++ b/pyren/mod_globals.py @@ -40,6 +40,7 @@ state_scan = False currentDDTscreen = None ext_cur_DTC = "000000" +curPosInSnapshotResp = 0 none_val = "None" diff --git a/pyren/scen_ecri_counter2.py b/pyren/scen_ecri_counter2.py index 31a2171..15c6f11 100644 --- a/pyren/scen_ecri_counter2.py +++ b/pyren/scen_ecri_counter2.py @@ -8,6 +8,7 @@ import string import mod_globals import mod_utils import mod_ecu +import mod_db_manager from mod_utils import clearScreen from mod_utils import pyren_encode from mod_utils import KBHit @@ -37,7 +38,7 @@ def run( elm, ecu, command, data ): return value - DOMTree = xml.dom.minidom.parse(data) + DOMTree = xml.dom.minidom.parse(mod_db_manager.get_file_from_clip(data)) ScmRoom = DOMTree.documentElement ScmParams = ScmRoom.getElementsByTagName("ScmParam") @@ -88,6 +89,7 @@ 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 From 109a9e4e739dd73246aea72373c486a58f0788da Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sat, 22 Feb 2020 00:56:49 +0100 Subject: [PATCH 40/57] Demo option added --- pyren/mod_ecu_mnemonic.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyren/mod_ecu_mnemonic.py b/pyren/mod_ecu_mnemonic.py index eaa96b7..d429512 100755 --- a/pyren/mod_ecu_mnemonic.py +++ b/pyren/mod_ecu_mnemonic.py @@ -102,6 +102,8 @@ def get_SnapShotMnemonic(m, se, elm, dataids): snapshotService = se[sid] resp = executeService( snapshotService, elm, [], "", True ) + if mod_globals.opt_demo and not resp: + return "00" resp = resp.strip().replace(' ','') if not all(c in string.hexdigits for c in resp): resp = '' resp = ' '.join(a+b for a,b in zip(resp[::2], resp[1::2])) From 97684de33e5d825bdbdb8dedc3c4fe3bcaa6ec22 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sat, 22 Feb 2020 15:53:36 +0100 Subject: [PATCH 41/57] Snapshot refactor --- pyren/mod_ecu.py | 19 +++++++++++++++---- pyren/mod_ecu_mnemonic.py | 35 +++++++++++++++++++---------------- pyren/mod_ecu_state.py | 7 +++++-- pyren/mod_globals.py | 1 - 4 files changed, 39 insertions(+), 23 deletions(-) diff --git a/pyren/mod_ecu.py b/pyren/mod_ecu.py index c5b6dbe..0a0a063 100755 --- a/pyren/mod_ecu.py +++ b/pyren/mod_ecu.py @@ -426,12 +426,15 @@ class ECU: print "Press any key to exit" for dr in datarefs: - datastr = dr.name; + datastr = dr.name help = dr.type if dr.type=='State': - datastr, help, csvd = get_state( self.States[dr.name], self.Mnemonics, self.Services, self.elm, self.calc ) + if self.DataIds and DTCpos and dr in self.Defaults[mod_globals.ext_cur_DTC[:4]].ssdatarefs: + datastr, help, csvd = get_state( self.States[dr.name], self.Mnemonics, self.Services, self.elm, self.calc, self.DataIds ) + else: + datastr, help, csvd = get_state( self.States[dr.name], self.Mnemonics, self.Services, self.elm, self.calc ) if dr.type=='Parameter': - if self.DataIds and dr in self.Defaults[mod_globals.ext_cur_DTC[:4]].datarefs: + if self.DataIds and DTCpos and dr in self.Defaults[mod_globals.ext_cur_DTC[:4]].ssdatarefs: datastr, help, csvd = get_parameter( self.Parameters[dr.name], self.Mnemonics, self.Services, self.elm, self.calc, self.DataIds ) else: datastr, help, csvd = get_parameter( self.Parameters[dr.name], self.Mnemonics, self.Services, self.elm, self.calc ) @@ -439,6 +442,8 @@ class ECU: datastr, help, csvd = get_identification( self.Identifications[dr.name], self.Mnemonics, self.Services, self.elm, self.calc ) if dr.type=='Command': datastr = dr.name + " [Command] " + self.Commands[dr.name].label + if dr.type=="Text": + datastr = dr.name if mod_globals.opt_csv and csvf!=0 and (dr.type=='State' or dr.type=='Parameter'): csvline += ";" + (pyren_encode(csvd) if mod_globals.opt_csv_human else str(csvd)) @@ -751,7 +756,13 @@ class ECU: path = path+' -> '+defstr[dtchex]+'\n\n'+hlpstr[dtchex]+'\n' - tmp_dtrf = self.Defaults[dtchex[:4]].datarefs + self.Defaults[dtchex[:4]].ssdatarefs + self.ext_de + 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]].ssdatarefs + 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) self.show_datarefs(tmp_dtrf, path) diff --git a/pyren/mod_ecu_mnemonic.py b/pyren/mod_ecu_mnemonic.py index d429512..044ac85 100755 --- a/pyren/mod_ecu_mnemonic.py +++ b/pyren/mod_ecu_mnemonic.py @@ -1,7 +1,6 @@ #!/usr/bin/env python from mod_ecu_service import * -from mod_globals import curPosInSnapshotResp from mod_utils import Choice from xml.dom.minidom import parse @@ -96,6 +95,7 @@ def get_mnemonic( m, se, elm, raw = 0 ): def get_SnapShotMnemonic(m, se, elm, dataids): snapshotService = "" + posInResp = 0 for sid in se: if len(se[sid].params) > 1: if se[sid].params[1]['type'] == 'Snapshot': @@ -107,24 +107,27 @@ def get_SnapShotMnemonic(m, se, elm, dataids): resp = resp.strip().replace(' ','') if not all(c in string.hexdigits for c in resp): resp = '' resp = ' '.join(a+b for a,b in zip(resp[::2], resp[1::2])) + numberOfIdentifiers = int("0x" + resp[7*3:8*3-1],16) resp = resp[8*3:] - if mod_globals.curPosInSnapshotResp >= len(resp): - mod_globals.curPosInSnapshotResp = 0 - - dataId = resp[mod_globals.curPosInSnapshotResp:mod_globals.curPosInSnapshotResp + 2*3].replace(" ", "") - - didDataLength = int(dataids[dataId].dataBitLength)/8 - didData = resp[mod_globals.curPosInSnapshotResp + 2*3: mod_globals.curPosInSnapshotResp + 2*3 + didDataLength*3] - mod_globals.curPosInSnapshotResp += 2*3 + didDataLength * 3 + didDict = {} + for x in range(numberOfIdentifiers): + dataId = resp[posInResp:posInResp + 2*3].replace(" ", "") + posInResp += 2*3 + didDataLength = int(dataids[dataId].dataBitLength)/8 + didData = resp[posInResp: posInResp + didDataLength*3] + posInResp += didDataLength*3 + didDict[dataId] = didData startByte = "" startBit = "" - - for mn in dataids[dataId].mnemolocations.keys(): - if mn == m.name: - startByte = dataids[dataId].mnemolocations[m.name].startByte - startBit = dataids[dataId].mnemolocations[m.name].startBit + dataId = "" + for did in dataids.keys(): + for mn in dataids[did].mnemolocations.keys(): + if mn == m.name: + dataId = did + startByte = dataids[dataId].mnemolocations[m.name].startByte + startBit = dataids[dataId].mnemolocations[m.name].startBit #prepare local variables sb = int(startByte) - 1 @@ -134,11 +137,11 @@ def get_SnapShotMnemonic(m, se, elm, dataids): rshift = ((bytes+1)*8 - (bits+sbit))%8 #check length of responce - if (sb*3+bytes*3-1)>(len(didData)): + if (sb*3+bytes*3-1)>(len(didDict[dataId])): return '00' #extract hex - hexval = didData[sb*3:(sb+bytes)*3-1] + hexval = didDict[dataId][sb*3:(sb+bytes)*3-1] hexval = hexval.replace(" ","") #shift and mask diff --git a/pyren/mod_ecu_state.py b/pyren/mod_ecu_state.py index 74bdf59..06022a5 100755 --- a/pyren/mod_ecu_state.py +++ b/pyren/mod_ecu_state.py @@ -7,11 +7,14 @@ from xml.dom.minidom import parseString import xml.dom.minidom import mod_globals -def get_state( st, mn, se, elm, calc ): +def get_state( st, mn, se, elm, calc, dataids = {} ): comp = st.computation comp = comp.replace("&","&") for m in sorted(st.mnemolist, key=len, reverse=True): - hex_val = get_mnemonic( mn[m], se, elm ) + if dataids: + hex_val = get_SnapShotMnemonic(mn[m], se, elm, dataids ) + else: + hex_val = get_mnemonic( mn[m], se, elm ) comp = comp.replace(m, "0x"+hex_val) tmp_val = calc.calculate(comp) diff --git a/pyren/mod_globals.py b/pyren/mod_globals.py index 42fd73a..6b9a146 100755 --- a/pyren/mod_globals.py +++ b/pyren/mod_globals.py @@ -40,7 +40,6 @@ state_scan = False currentDDTscreen = None ext_cur_DTC = "000000" -curPosInSnapshotResp = 0 none_val = "None" From f5e864453f0e2f64e931238e0393af2fceaa4c19 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sat, 22 Feb 2020 18:00:55 +0100 Subject: [PATCH 42/57] STD_A freeze frame --- pyren/mod_ecu.py | 10 +++++++++- pyren/mod_ecu_mnemonic.py | 8 ++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/pyren/mod_ecu.py b/pyren/mod_ecu.py index 0a0a063..e30ad54 100755 --- a/pyren/mod_ecu.py +++ b/pyren/mod_ecu.py @@ -714,10 +714,18 @@ class ECU: index = int(choice[1])-1 dtchex = listkeys[index] if len(listkeys) > index else listkeys[0] + 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]].ssdatarefs - self.show_datarefs(self.Defaults[dtchex[:4]].datarefs, path) + tmp_dtrf = mem_dtrf + cur_dtrf + + self.show_datarefs(tmp_dtrf, path) def show_defaults_std_b(self): while(1): diff --git a/pyren/mod_ecu_mnemonic.py b/pyren/mod_ecu_mnemonic.py index 044ac85..ea092fc 100755 --- a/pyren/mod_ecu_mnemonic.py +++ b/pyren/mod_ecu_mnemonic.py @@ -35,6 +35,14 @@ def get_mnemonicDTC( m, resp ): def get_mnemonic( m, se, elm, raw = 0 ): + if not m.serviceID and mod_globals.ext_cur_DTC: + for sid in se.keys(): + if se[sid].startReq.endswith(mod_globals.ext_cur_DTC[:4]): + m.startByte = se[sid].responces[se[sid].responces.keys()[0]].mnemolocations[m.name].startByte + m.startBit = se[sid].responces[se[sid].responces.keys()[0]].mnemolocations[m.name].startBit + m.request = se[sid].startReq + m.positive = se[sid].simpleRsp + #get responce if len(m.sids)>0: for sid in m.sids: From 787d3d264aa65f96b5cffaf9030fba616af868f9 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sat, 22 Feb 2020 18:58:16 +0100 Subject: [PATCH 43/57] Rename --- pyren/mod_ecu.py | 8 ++++---- pyren/mod_ecu_default.py | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/pyren/mod_ecu.py b/pyren/mod_ecu.py index e30ad54..5bad1e4 100755 --- a/pyren/mod_ecu.py +++ b/pyren/mod_ecu.py @@ -429,12 +429,12 @@ class ECU: datastr = dr.name help = dr.type if dr.type=='State': - if self.DataIds and DTCpos and dr in self.Defaults[mod_globals.ext_cur_DTC[:4]].ssdatarefs: + if self.DataIds and DTCpos and dr in self.Defaults[mod_globals.ext_cur_DTC[:4]].memDatarefs: datastr, help, csvd = get_state( self.States[dr.name], self.Mnemonics, self.Services, self.elm, self.calc, self.DataIds ) else: datastr, help, csvd = get_state( self.States[dr.name], self.Mnemonics, self.Services, self.elm, self.calc ) if dr.type=='Parameter': - if self.DataIds and DTCpos and dr in self.Defaults[mod_globals.ext_cur_DTC[:4]].ssdatarefs: + if self.DataIds and DTCpos and dr in self.Defaults[mod_globals.ext_cur_DTC[:4]].memDatarefs: datastr, help, csvd = get_parameter( self.Parameters[dr.name], self.Mnemonics, self.Services, self.elm, self.calc, self.DataIds ) else: datastr, help, csvd = get_parameter( self.Parameters[dr.name], self.Mnemonics, self.Services, self.elm, self.calc ) @@ -721,7 +721,7 @@ class ECU: 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]].ssdatarefs + mem_dtrf = [ecu_screen_dataref(0, mem_dtrf_txt, 'Text')] + self.Defaults[dtchex[:4]].memDatarefs tmp_dtrf = mem_dtrf + cur_dtrf @@ -767,7 +767,7 @@ class ECU: 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]].ssdatarefs + 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 tmp_dtrf = mem_dtrf + cur_dtrf + ext_info_dtrf diff --git a/pyren/mod_ecu_default.py b/pyren/mod_ecu_default.py index a5b6059..d6c598d 100644 --- a/pyren/mod_ecu_default.py +++ b/pyren/mod_ecu_default.py @@ -350,7 +350,7 @@ class ecu_default: label = "" status = 0 datarefs = [] - ssdatarefs = [] + memDatarefs = [] helps = [] caracter = {} interpInfoPeri = "" @@ -385,7 +385,8 @@ class ecu_default: for dr in DataRef: dataref = ecu_screen_dataref( dr ) self.datarefs.append( dataref ) - self.ssdatarefs = [] + + self.memDatarefs = [] MemorisedInfo = df.getElementsByTagName("MemorisedInfo") if MemorisedInfo: for mi in MemorisedInfo: @@ -393,7 +394,7 @@ class ecu_default: if DataRef: for dr in DataRef: dataref = ecu_screen_dataref( dr ) - self.ssdatarefs.append( dataref ) + self.memDatarefs.append( dataref ) self.helps = [] Helps = df.getElementsByTagName("Helps") From 8f9e4d4dff2bb1b846fde3c75d6c69134a032c18 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sun, 23 Feb 2020 10:30:07 +0100 Subject: [PATCH 44/57] Fixes --- pyren/mod_ecu.py | 4 ++-- pyren/mod_ecu_mnemonic.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyren/mod_ecu.py b/pyren/mod_ecu.py index 5bad1e4..83acc3a 100755 --- a/pyren/mod_ecu.py +++ b/pyren/mod_ecu.py @@ -429,12 +429,12 @@ class ECU: datastr = dr.name help = dr.type if dr.type=='State': - if self.DataIds and DTCpos and dr in self.Defaults[mod_globals.ext_cur_DTC[:4]].memDatarefs: + if self.DataIds and "DTC" in path and dr in self.Defaults[mod_globals.ext_cur_DTC[:4]].memDatarefs: datastr, help, csvd = get_state( self.States[dr.name], self.Mnemonics, self.Services, self.elm, self.calc, self.DataIds ) else: datastr, help, csvd = get_state( self.States[dr.name], self.Mnemonics, self.Services, self.elm, self.calc ) if dr.type=='Parameter': - if self.DataIds and DTCpos and dr in self.Defaults[mod_globals.ext_cur_DTC[:4]].memDatarefs: + if self.DataIds and "DTC" in path and dr in self.Defaults[mod_globals.ext_cur_DTC[:4]].memDatarefs: datastr, help, csvd = get_parameter( self.Parameters[dr.name], self.Mnemonics, self.Services, self.elm, self.calc, self.DataIds ) else: datastr, help, csvd = get_parameter( self.Parameters[dr.name], self.Mnemonics, self.Services, self.elm, self.calc ) diff --git a/pyren/mod_ecu_mnemonic.py b/pyren/mod_ecu_mnemonic.py index ea092fc..e19e327 100755 --- a/pyren/mod_ecu_mnemonic.py +++ b/pyren/mod_ecu_mnemonic.py @@ -37,7 +37,7 @@ def get_mnemonic( m, se, elm, raw = 0 ): if not m.serviceID and mod_globals.ext_cur_DTC: for sid in se.keys(): - if se[sid].startReq.endswith(mod_globals.ext_cur_DTC[:4]): + if se[sid].startReq == "120004"+ mod_globals.ext_cur_DTC[:4]: m.startByte = se[sid].responces[se[sid].responces.keys()[0]].mnemolocations[m.name].startByte m.startBit = se[sid].responces[se[sid].responces.keys()[0]].mnemolocations[m.name].startBit m.request = se[sid].startReq From 4e245d4fb6bad59816e946095d4d2f0703f6fb3e Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sun, 23 Feb 2020 11:47:30 +0100 Subject: [PATCH 45/57] Empty delay fix --- pyren/mod_ecu_mnemonic.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyren/mod_ecu_mnemonic.py b/pyren/mod_ecu_mnemonic.py index e19e327..1c139b7 100755 --- a/pyren/mod_ecu_mnemonic.py +++ b/pyren/mod_ecu_mnemonic.py @@ -42,6 +42,7 @@ def get_mnemonic( m, se, elm, raw = 0 ): m.startBit = se[sid].responces[se[sid].responces.keys()[0]].mnemolocations[m.name].startBit m.request = se[sid].startReq m.positive = se[sid].simpleRsp + m.delay = '100' #don't know how much it should be #get responce if len(m.sids)>0: From fb49b5ccaf15aa9b87b665ba052e51a109651027 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sun, 23 Feb 2020 16:25:48 +0100 Subject: [PATCH 46/57] Negative responce handling --- pyren/mod_ecu.py | 2 +- pyren/mod_ecu_mnemonic.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pyren/mod_ecu.py b/pyren/mod_ecu.py index 83acc3a..2d682a3 100755 --- a/pyren/mod_ecu.py +++ b/pyren/mod_ecu.py @@ -444,7 +444,7 @@ class ECU: datastr = dr.name + " [Command] " + self.Commands[dr.name].label if dr.type=="Text": datastr = dr.name - + help = "" if mod_globals.opt_csv and csvf!=0 and (dr.type=='State' or dr.type=='Parameter'): csvline += ";" + (pyren_encode(csvd) if mod_globals.opt_csv_human else str(csvd)) diff --git a/pyren/mod_ecu_mnemonic.py b/pyren/mod_ecu_mnemonic.py index 1c139b7..e2f22fa 100755 --- a/pyren/mod_ecu_mnemonic.py +++ b/pyren/mod_ecu_mnemonic.py @@ -111,7 +111,7 @@ def get_SnapShotMnemonic(m, se, elm, dataids): snapshotService = se[sid] resp = executeService( snapshotService, elm, [], "", True ) - if mod_globals.opt_demo and not resp: + if mod_globals.opt_demo and not resp or not resp.startswith(snapshotService.simpleRsp): return "00" resp = resp.strip().replace(' ','') if not all(c in string.hexdigits for c in resp): resp = '' From a277a94ce96b60e0dca2136d5bbd94551b311bc7 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sun, 23 Feb 2020 22:58:38 +0100 Subject: [PATCH 47/57] Refactor --- pyren/mod_ecu_mnemonic.py | 55 +++++++-------------------------------- 1 file changed, 9 insertions(+), 46 deletions(-) diff --git a/pyren/mod_ecu_mnemonic.py b/pyren/mod_ecu_mnemonic.py index e2f22fa..a6af076 100755 --- a/pyren/mod_ecu_mnemonic.py +++ b/pyren/mod_ecu_mnemonic.py @@ -57,49 +57,8 @@ def get_mnemonic( m, se, elm, raw = 0 ): if not all(c in string.hexdigits for c in resp): resp = '' resp = ' '.join(a+b for a,b in zip(resp[::2], resp[1::2])) if len(m.startByte)==0: m.startByte = u'01' - - #prepare local variables - sb = int(m.startByte) - 1 - bits = int(m.bitsLength) - sbit = int(m.startBit) - bytes = (bits+sbit-1)/8+1 - rshift = ((bytes+1)*8 - (bits+sbit))%8 - - #check length of responce - if (sb*3+bytes*3-1)>(len(resp)): - return '00' - - #extract hex - hexval = resp[sb*3:(sb+bytes)*3-1] - hexval = hexval.replace(" ","") - - if raw: - if resp.startswith(m.positive): - return hexval - else: - return 'ERROR' - - #shift and mask - val = (int(hexval,16)>>rshift)&(2**bits-1) - - #format result - hexval = hex(val)[2:] - #remove 'L' - if hexval[-1:].upper()=='L': - hexval = hexval[:-1] - #add left zero if need - if len(hexval)%2: - hexval = '0'+hexval - - #revert byte order if little endian - if m.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 + hexval = getHexVal(m.startByte, m.bitsLength, m.startBit, m.littleEndian, resp) return hexval def get_SnapShotMnemonic(m, se, elm, dataids): @@ -137,20 +96,24 @@ def get_SnapShotMnemonic(m, se, elm, dataids): dataId = did startByte = dataids[dataId].mnemolocations[m.name].startByte startBit = dataids[dataId].mnemolocations[m.name].startBit + + hexval = getHexVal(startByte, m.bitsLength, startBit, m.littleEndian, didDict[dataId]) + return hexval +def getHexVal(startByte, bitsLength, startBit, littleEndian, resp): #prepare local variables sb = int(startByte) - 1 - bits = int(m.bitsLength) + bits = int(bitsLength) sbit = int(startBit) bytes = (bits+sbit-1)/8+1 rshift = ((bytes+1)*8 - (bits+sbit))%8 #check length of responce - if (sb*3+bytes*3-1)>(len(didDict[dataId])): + if (sb*3+bytes*3-1)>(len(resp)): return '00' #extract hex - hexval = didDict[dataId][sb*3:(sb+bytes)*3-1] + hexval = resp[sb*3:(sb+bytes)*3-1] hexval = hexval.replace(" ","") #shift and mask @@ -166,7 +129,7 @@ def get_SnapShotMnemonic(m, se, elm, dataids): hexval = '0'+hexval #revert byte order if little endian - if m.littleEndian == '1': + if littleEndian == '1': a = hexval b = '' if not len(a) % 2: From db7438b207d946fe0238faf1b6923d1faac88225 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sun, 23 Feb 2020 23:45:51 +0100 Subject: [PATCH 48/57] Fixes --- pyren/mod_ecu.py | 2 ++ pyren/mod_ecu_mnemonic.py | 12 +++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/pyren/mod_ecu.py b/pyren/mod_ecu.py index 2d682a3..64bd795 100755 --- a/pyren/mod_ecu.py +++ b/pyren/mod_ecu.py @@ -540,6 +540,8 @@ class ECU: kb.set_normal_term() if mod_globals.opt_csv and csvf!=0: csvf.close() + if "DTC" in path: + mod_globals.ext_cur_DTC = "000000" return def add_favourite(self): diff --git a/pyren/mod_ecu_mnemonic.py b/pyren/mod_ecu_mnemonic.py index a6af076..278c54c 100755 --- a/pyren/mod_ecu_mnemonic.py +++ b/pyren/mod_ecu_mnemonic.py @@ -35,7 +35,7 @@ def get_mnemonicDTC( m, resp ): def get_mnemonic( m, se, elm, raw = 0 ): - if not m.serviceID and mod_globals.ext_cur_DTC: + if not m.serviceID and mod_globals.ext_cur_DTC != "000000": for sid in se.keys(): if se[sid].startReq == "120004"+ mod_globals.ext_cur_DTC[:4]: m.startByte = se[sid].responces[se[sid].responces.keys()[0]].mnemolocations[m.name].startByte @@ -58,7 +58,7 @@ def get_mnemonic( m, se, elm, raw = 0 ): resp = ' '.join(a+b for a,b in zip(resp[::2], resp[1::2])) if len(m.startByte)==0: m.startByte = u'01' - hexval = getHexVal(m.startByte, m.bitsLength, m.startBit, m.littleEndian, resp) + hexval = getHexVal(m.startByte, m.bitsLength, m.startBit, m.littleEndian, resp, raw) return hexval def get_SnapShotMnemonic(m, se, elm, dataids): @@ -100,7 +100,7 @@ def get_SnapShotMnemonic(m, se, elm, dataids): hexval = getHexVal(startByte, m.bitsLength, startBit, m.littleEndian, didDict[dataId]) return hexval -def getHexVal(startByte, bitsLength, startBit, littleEndian, resp): +def getHexVal(startByte, bitsLength, startBit, littleEndian, resp, raw = 0): #prepare local variables sb = int(startByte) - 1 bits = int(bitsLength) @@ -116,6 +116,12 @@ def getHexVal(startByte, bitsLength, startBit, littleEndian, resp): hexval = resp[sb*3:(sb+bytes)*3-1] hexval = hexval.replace(" ","") + if raw: + if resp.startswith(m.positive): + return hexval + else: + return 'ERROR' + #shift and mask val = (int(hexval,16)>>rshift)&(2**bits-1) From 3f23d862a728b4aaa3706320bf11503e182673a6 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sun, 23 Feb 2020 23:59:08 +0100 Subject: [PATCH 49/57] Missing raw option added --- pyren/mod_ecu_mnemonic.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pyren/mod_ecu_mnemonic.py b/pyren/mod_ecu_mnemonic.py index 278c54c..2ff1efb 100755 --- a/pyren/mod_ecu_mnemonic.py +++ b/pyren/mod_ecu_mnemonic.py @@ -58,7 +58,7 @@ def get_mnemonic( m, se, elm, raw = 0 ): resp = ' '.join(a+b for a,b in zip(resp[::2], resp[1::2])) if len(m.startByte)==0: m.startByte = u'01' - hexval = getHexVal(m.startByte, m.bitsLength, m.startBit, m.littleEndian, resp, raw) + hexval = getHexVal(m, m.startByte, m.startBit, resp, raw) return hexval def get_SnapShotMnemonic(m, se, elm, dataids): @@ -97,13 +97,13 @@ def get_SnapShotMnemonic(m, se, elm, dataids): startByte = dataids[dataId].mnemolocations[m.name].startByte startBit = dataids[dataId].mnemolocations[m.name].startBit - hexval = getHexVal(startByte, m.bitsLength, startBit, m.littleEndian, didDict[dataId]) + hexval = getHexVal(m, startByte, startBit, didDict[dataId]) return hexval -def getHexVal(startByte, bitsLength, startBit, littleEndian, resp, raw = 0): +def getHexVal(m, startByte, startBit, resp, raw = 0): #prepare local variables sb = int(startByte) - 1 - bits = int(bitsLength) + bits = int(m.bitsLength) sbit = int(startBit) bytes = (bits+sbit-1)/8+1 rshift = ((bytes+1)*8 - (bits+sbit))%8 @@ -135,7 +135,7 @@ def getHexVal(startByte, bitsLength, startBit, littleEndian, resp, raw = 0): hexval = '0'+hexval #revert byte order if little endian - if littleEndian == '1': + if m.littleEndian == '1': a = hexval b = '' if not len(a) % 2: From 2c2e10abd972b483d6a52d1f2c0ed98a7a72996b Mon Sep 17 00:00:00 2001 From: shrlnm Date: Sun, 1 Mar 2020 18:17:03 +0300 Subject: [PATCH 50/57] unknown dataId fix --- .idea/vcs.xml | 6 ++++++ pyren/mod_ecu_mnemonic.py | 2 ++ 2 files changed, 8 insertions(+) create mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pyren/mod_ecu_mnemonic.py b/pyren/mod_ecu_mnemonic.py index 2ff1efb..438293d 100755 --- a/pyren/mod_ecu_mnemonic.py +++ b/pyren/mod_ecu_mnemonic.py @@ -82,6 +82,8 @@ def get_SnapShotMnemonic(m, se, elm, dataids): for x in range(numberOfIdentifiers): dataId = resp[posInResp:posInResp + 2*3].replace(" ", "") posInResp += 2*3 + if dataId not in dataids.keys(): + continue didDataLength = int(dataids[dataId].dataBitLength)/8 didData = resp[posInResp: posInResp + didDataLength*3] posInResp += didDataLength*3 From a8433cb3fa4475118491762070f473d99761ff6a Mon Sep 17 00:00:00 2001 From: shrlnm Date: Sun, 1 Mar 2020 18:21:29 +0300 Subject: [PATCH 51/57] rm .idea --- .idea/vcs.xml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From de8b873da0314ebac3531e2502397e51c819bc88 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Mon, 2 Mar 2020 23:50:06 +0100 Subject: [PATCH 52/57] Make and load dump added --- pyren/scen_ecri_paraminj1.py | 101 +++++++++++++++++++++++++++++++---- 1 file changed, 90 insertions(+), 11 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index a4cd958..eddfe00 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -216,6 +216,7 @@ def run( elm, ecu, command, data ): if bt.startswith("Button"): if str(correctEcu.buttons[bt]) == 'true': buttons[int(bt.strip('Button'))] = get_message(bt[:-6] + "Text", 0) + buttons["loadDump"] = get_message_by_id('19802', 0) buttons["exit"] = '' #Get commands @@ -242,10 +243,10 @@ def run( elm, ecu, command, data ): key = param[6:-5] begin = int(ScmParam['Idents'+key+'Begin']) end = int(ScmParam['Idents'+key+'End']) - try: #10099 trap - identsList['D'+str(begin)] = ScmParam['Ident'+str(begin)] + try: + ecu.get_ref_id(ScmParam['Ident' + str(begin)]).mnemolist[0] #10529 ID114 doesn't exist except: - break + continue else: for idnum in range(begin ,end + 1): identsList['D'+str(idnum)] = ScmParam['Ident'+str(idnum)] @@ -271,6 +272,7 @@ def run( elm, ecu, command, data ): paramToSend = "" commandToRun = "" requestToFindInCommandsRequests = "" + backupDict = {} try: idKeyToFindInRange = int((params.keys()[0]).replace("D","")) @@ -283,6 +285,7 @@ def run( elm, ecu, command, data ): 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: @@ -290,10 +293,12 @@ def run( elm, ecu, command, data ): 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') @@ -377,6 +382,8 @@ def run( elm, ecu, command, data ): 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 @@ -413,15 +420,15 @@ def run( elm, ecu, command, data ): slowTypeValue = get_message('ValueSlowParam') fastTypeValue = get_message('ValueFastParam') currentMessage = get_message_by_id('52676') - slowMessage = get_message('Slow', 0) - fastMessage = get_message('Fast', 0) + slowMessage = get_message('Slow') + fastMessage = get_message('Fast') notDefinedMessage = get_message('NotDefined') message2 = get_message('Message282') typesButtons = OrderedDict() - typesButtons[slowMessage] = slowTypeValue - typesButtons[fastMessage] = fastTypeValue + typesButtons[get_message('Slow', 0)] = slowTypeValue + typesButtons[get_message('Fast', 0)] = fastTypeValue typesButtons[''] = "" clearScreen() @@ -521,6 +528,77 @@ def run( elm, ecu, command, data ): 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('./cache/' + ScmParam['FileName']) + + def loadDump(): + clearScreen() + + paramToSend = "" + dumpScmParam = {} + try: + dumpData = open('./cache/' + 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': + return + + clearScreen() + + print + response = ecu.run_cmd(dumpScmParam['Command'],paramToSend) + print + + if "NR" in response: + print failMessage + else: + print successMessage + + print + ch = raw_input('Press ENTER to exit') + functions = OrderedDict() for cmdKey in commands.keys(): @@ -555,12 +633,13 @@ def run( elm, ecu, command, data ): choice = Choice(buttons.values(), "Choose :") for key, value in buttons.iteritems(): - if choice[0]=='': return + if choice[0] =='': return if value == choice[0]: if key in notSupported: ch = raw_input("\nNot Supported yet. Press ENTER to exit") - return - if key == 1: + elif key == 'loadDump': + loadDump() + elif key == 1: resetInjetorsData(functions[key][0],functions[key][1]) elif key == 6: afterEcuChange(functions[key][0],functions[key][1]) From 42965e0d201d52e299fddd6c1bfc9df6dad04382 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Wed, 4 Mar 2020 21:45:49 +0100 Subject: [PATCH 53/57] Dump location changed --- pyren/scen_ecri_paraminj1.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyren/scen_ecri_paraminj1.py b/pyren/scen_ecri_paraminj1.py index eddfe00..92c9ba0 100644 --- a/pyren/scen_ecri_paraminj1.py +++ b/pyren/scen_ecri_paraminj1.py @@ -542,7 +542,7 @@ def run( elm, ecu, command, data ): fileRoot.insert(1,el) tree = et.ElementTree(fileRoot) - tree.write('./cache/' + ScmParam['FileName']) + tree.write(mod_globals.dumps_dir + ScmParam['FileName']) def loadDump(): clearScreen() @@ -550,7 +550,7 @@ def run( elm, ecu, command, data ): paramToSend = "" dumpScmParam = {} try: - dumpData = open('./cache/' + ScmParam['FileName'], 'r') + dumpData = open(mod_globals.dumps_dir + ScmParam['FileName'], 'r') except: print get_message_by_id('2194') raw_input() From f1ce7377cdf3ac29534b2054e5acdf64532cb69f Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sat, 7 Mar 2020 10:28:32 +0100 Subject: [PATCH 54/57] STN CAN2 fix --- pyren/mod_elm.py | 4 +- pyren/savedEcus2.p | 148 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+), 2 deletions(-) create mode 100644 pyren/savedEcus2.p diff --git a/pyren/mod_elm.py b/pyren/mod_elm.py index 711b758..17c649f 100644 --- a/pyren/mod_elm.py +++ b/pyren/mod_elm.py @@ -1834,7 +1834,7 @@ class ELM: def set_can_500(self, addr='XXX'): if mod_globals.opt_can2 and mod_globals.opt_stn: - tmp = self.cmd("STPBR 500000") + tmp = self.cmd("STP 33") if '?' not in tmp: return if len(addr)==3: self.cmd("at sp 6") @@ -1843,7 +1843,7 @@ class ELM: def set_can_250(self, addr='XXX'): if mod_globals.opt_can2 and mod_globals.opt_stn: - tmp = self.cmd("STPBR 250000") + tmp = self.cmd("STP 35") if '?' not in tmp: return if len(addr)==3: self.cmd("at sp 8") diff --git a/pyren/savedEcus2.p b/pyren/savedEcus2.p new file mode 100644 index 0000000..1f6dc78 --- /dev/null +++ b/pyren/savedEcus2.p @@ -0,0 +1,148 @@ +(lp0 +(dp1 +S'vehTypeCode' +p2 +VX74 +p3 +sS'protocol' +p4 +S'' +p5 +sS'pin' +p6 +S'can' +p7 +sS'stopDiagReq' +p8 +V1081 +p9 +sS'CANConfig' +p10 +Vfalse +p11 +sS'KeepAlivePeriod' +p12 +V3000 +p13 +sS'brp' +p14 +V0 +p15 +sS'startDiagRsp' +p16 +V50C0 +p17 +sS'baudRate' +p18 +g5 +sS'dst' +p19 +V57 +p20 +sS'stopDiagRsp' +p21 +V5081 +p22 +sS'programmable' +p23 +Vfalse +p24 +sS'startDiagReq' +p25 +V10C0 +p26 +sS'commRetry' +p27 +V3 +p28 +sS'OptimizerId' +p29 +VSG1010380.XML +p30 +sS'slowInit' +p31 +g5 +sS'rerr' +p32 +S'2' +p33 +sS'ecuname' +p34 +V10380 +p35 +sS'KW1' +p36 +g5 +sS'idRx' +p37 +V767 +p38 +sS'KW2' +p39 +g5 +sS'replyToRequestDelay' +p40 +V0 +p41 +sS'ModelId' +p42 +VFG1010380.XML +p43 +sS'src' +p44 +VF1 +p45 +sS'keepAliveReq' +p46 +V3E01 +p47 +sS'fastInit' +p48 +g5 +sS'idTx' +p49 +V747 +p50 +sS'errorDelay' +p51 +V1000 +p52 +sS'stdType' +p53 +VSTD_A +p54 +sS'ids' +p55 +(lp56 +V2180 +p57 +aV6180 +p58 +aV0 +p59 +aV6 +p60 +aVFF +p61 +aV24 +p62 +asS'timings' +p63 +g5 +sS'doc' +p64 +VNAV_4R_0000_24_A +p65 +sS'idf' +p66 +V10 +p67 +sS'pin2' +p68 +V12 +p69 +sS'pin1' +p70 +V13 +p71 +sa. \ No newline at end of file From 6e04c2ca482bdbc8d172be120aaae51853afa475 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sat, 7 Mar 2020 10:33:31 +0100 Subject: [PATCH 55/57] savedEcus2 removed --- pyren/savedEcus2.p | 148 --------------------------------------------- 1 file changed, 148 deletions(-) delete mode 100644 pyren/savedEcus2.p diff --git a/pyren/savedEcus2.p b/pyren/savedEcus2.p deleted file mode 100644 index 1f6dc78..0000000 --- a/pyren/savedEcus2.p +++ /dev/null @@ -1,148 +0,0 @@ -(lp0 -(dp1 -S'vehTypeCode' -p2 -VX74 -p3 -sS'protocol' -p4 -S'' -p5 -sS'pin' -p6 -S'can' -p7 -sS'stopDiagReq' -p8 -V1081 -p9 -sS'CANConfig' -p10 -Vfalse -p11 -sS'KeepAlivePeriod' -p12 -V3000 -p13 -sS'brp' -p14 -V0 -p15 -sS'startDiagRsp' -p16 -V50C0 -p17 -sS'baudRate' -p18 -g5 -sS'dst' -p19 -V57 -p20 -sS'stopDiagRsp' -p21 -V5081 -p22 -sS'programmable' -p23 -Vfalse -p24 -sS'startDiagReq' -p25 -V10C0 -p26 -sS'commRetry' -p27 -V3 -p28 -sS'OptimizerId' -p29 -VSG1010380.XML -p30 -sS'slowInit' -p31 -g5 -sS'rerr' -p32 -S'2' -p33 -sS'ecuname' -p34 -V10380 -p35 -sS'KW1' -p36 -g5 -sS'idRx' -p37 -V767 -p38 -sS'KW2' -p39 -g5 -sS'replyToRequestDelay' -p40 -V0 -p41 -sS'ModelId' -p42 -VFG1010380.XML -p43 -sS'src' -p44 -VF1 -p45 -sS'keepAliveReq' -p46 -V3E01 -p47 -sS'fastInit' -p48 -g5 -sS'idTx' -p49 -V747 -p50 -sS'errorDelay' -p51 -V1000 -p52 -sS'stdType' -p53 -VSTD_A -p54 -sS'ids' -p55 -(lp56 -V2180 -p57 -aV6180 -p58 -aV0 -p59 -aV6 -p60 -aVFF -p61 -aV24 -p62 -asS'timings' -p63 -g5 -sS'doc' -p64 -VNAV_4R_0000_24_A -p65 -sS'idf' -p66 -V10 -p67 -sS'pin2' -p68 -V12 -p69 -sS'pin1' -p70 -V13 -p71 -sa. \ No newline at end of file From dbe039ec34976c189335108ef1ba7e31653e8e42 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sat, 7 Mar 2020 22:27:04 +0100 Subject: [PATCH 56/57] 19 request added to Allowed list --- pyren/mod_elm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyren/mod_elm.py b/pyren/mod_elm.py index 17c649f..3ab81cd 100644 --- a/pyren/mod_elm.py +++ b/pyren/mod_elm.py @@ -33,7 +33,7 @@ if mod_globals.os != 'android': DevList = ['27', '28', '2E', '30', '31', '32', '34', '35', '36', '37', '3B', '3D'] # List of commands allowed in any mode -AllowedList = ['12', '1A', '21', '22', '23'] +AllowedList = ['12', '19', '1A', '21', '22', '23'] # Max frame burst for Flow Control MaxBurst = 0x7 From a91dc2de24047cab7dc2c173e783ffaaca678852 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Mon, 9 Mar 2020 19:47:01 +0100 Subject: [PATCH 57/57] 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