This commit is contained in:
shrlnm 2019-02-03 22:28:31 +03:00
parent df27d528cc
commit e8ef5254e8
6 changed files with 145 additions and 23 deletions

View File

@ -7,7 +7,6 @@ import pickle
os.chdir(os.path.dirname(os.path.realpath(sys.argv[0]))) os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
import mod_globals import mod_globals
import mod_ecu
import mod_scan_ecus import mod_scan_ecus
import mod_elm import mod_elm
@ -296,6 +295,8 @@ def get_addr_from_xml( xmlfile ):
def main(): def main():
'''Main function''' '''Main function'''
import mod_ecu
optParser() optParser()
print 'Opening ELM' print 'Opening ELM'

View File

@ -351,6 +351,7 @@ class ECU:
if mod_globals.opt_csv: if mod_globals.opt_csv:
# prepare to csv save # prepare to csv save
self.minimumrefreshrate = 0
csvline = u"Time" csvline = u"Time"
nparams = 0 nparams = 0
for dr in datarefs: for dr in datarefs:
@ -443,7 +444,7 @@ class ECU:
if not (mod_globals.opt_csv and mod_globals.opt_csv_only): if not (mod_globals.opt_csv and mod_globals.opt_csv_only):
newScreen = initScreen newScreen = initScreen
header = "ECU : "+self.ecudata['ecuname']+' '+self.ecudata['doc']+'\n' header = 'ECU : '+self.ecudata['ecuname']+' (RT:'+'{0:.4f}'.format(self.elm.response_time)+') '+self.ecudata['doc']+'\n'
header = header + "Screen : "+path header = header + "Screen : "+path
newScreen = newScreen + pyren_encode( header ) + '\n' newScreen = newScreen + pyren_encode( header ) + '\n'

View File

@ -663,10 +663,14 @@ class ELM:
if byte == '\r' or byte == '\n': if byte == '\r' or byte == '\n':
line = buff.strip () line = buff.strip()
buff = "" buff = ""
if len (line) < 6: continue if len (line) < 6:
continue
if ':' in line:
line = line.split(':')[-1].strip()
if ord (line[4:5]) < 0x31 or ord (line[4:5]) > 0x38: continue if ord (line[4:5]) < 0x31 or ord (line[4:5]) > 0x38: continue

View File

@ -116,6 +116,7 @@ if __name__ == "__main__":
if len(sys.argv)==1: if len(sys.argv)==1:
print "Usage: mod_optfile.py <filename> [key]" print "Usage: mod_optfile.py <filename> [key]"
print " mod_optfile.py ALLSG" print " mod_optfile.py ALLSG"
print " mod_optfile.py HEX <infile> <outfile>"
print "Example:" print "Example:"
print " mod_optfile.py ../Location/DiagOnCan_RU.bqm" print " mod_optfile.py ../Location/DiagOnCan_RU.bqm"
print " mod_optfile.py ../EcuRenault/Sessions/SG0110016.XML P001" print " mod_optfile.py ../EcuRenault/Sessions/SG0110016.XML P001"
@ -144,9 +145,23 @@ if __name__ == "__main__":
f = open(ugFileName,'wt') f = open(ugFileName,'wt')
f.write( rf ) f.write( rf )
f.close() f.close()
exit(0) exit(0)
if sys.argv[1]=='HEX':
lf = open(sys.argv[2], "rb")
of = open(sys.argv[3], "wb")
while(1):
i = lf.tell()
bytes = lf.read(2)
if len(bytes)<2:
exit()
x = 0
x = struct.unpack('<H', bytes)[0]
x = x ^ (i & 0xFFFF) ^ 0x5555
of.write(struct.pack('H', x))
of = optfile(sys.argv[1]) of = optfile(sys.argv[1])
if len(sys.argv)==2: if len(sys.argv)==2:

View File

@ -621,7 +621,7 @@ class ScanEcus:
print " - "+str(len(self.allecus))+" ecus loaded" print " - "+str(len(self.allecus))+" ecus loaded"
def compare_ecu( self, row, rrsp, req ): def compare_ecu( self, row, rrsp, req ):
if len( req )/2==3: rrsp = rrsp[3:] if len( req )/2==3: rrsp = rrsp[3:]
base = 0 base = 0
@ -822,7 +822,7 @@ class ScanEcus:
if rrsp!='': if rrsp!='':
self.reqres.append([row['dst']+row['startDiagReq']+row['stdType']+row['ids'][0]+row['protocol'],rrsp,rerr]) #populate cache for not to ask again self.reqres.append([row['dst']+row['startDiagReq']+row['stdType']+row['ids'][0]+row['protocol'],rrsp,rerr]) #populate cache for not to ask again
compres = False compres = False
if 'ERROR' not in rrsp: if 'ERROR' not in rrsp:
rrsp = rrsp[3:] rrsp = rrsp[3:]
@ -854,7 +854,7 @@ def findTCOM( addr, cmd, rsp ):
vehTCOM = vh.getAttribute("TCOM") vehTCOM = vh.getAttribute("TCOM")
vehicle = vehiclename+'#'+vehTCOM; vehicle = vehiclename+'#'+vehTCOM;
print vehicle #print vehicle
connector = vh.getElementsByTagName("Connector") connector = vh.getElementsByTagName("Connector")
cannetwork = connector.item(0).getElementsByTagName("CANNetwork") cannetwork = connector.item(0).getElementsByTagName("CANNetwork")
@ -887,7 +887,7 @@ def findTCOM( addr, cmd, rsp ):
se = ScanEcus( None ) se = ScanEcus( None )
print 'Loading Uces.xml' print 'Loading Uces.xml'
se.read_Uces_file(True) se.read_Uces_file(True)
print ecuvhc #print ecuvhc
for r in se.allecus.keys(): for r in se.allecus.keys():
if se.allecus[r]['dst']!=addr: continue if se.allecus[r]['dst']!=addr: continue
if se.allecus[r]['ids'][0]!=cmd: continue if se.allecus[r]['ids'][0]!=cmd: continue

View File

@ -1,6 +1,7 @@
#!/usr/bin/env python #!/usr/bin/env python
import sys, os, re import sys, os, re
import time
import mod_globals import mod_globals
import mod_elm import mod_elm
@ -16,6 +17,7 @@ var = {}
stack = [] stack = []
auto_macro = "" auto_macro = ""
auto_dia = False
mod_globals.os = os.name mod_globals.os = os.name
@ -132,14 +134,15 @@ def pars_macro( file ):
def load_macro( mf='' ): def load_macro( mf='' ):
""" """
dynamicly loaded macro should have .txt extension and plased in ./macro directory dynamically loaded macro should have .txt extension and placed in ./macro directory
""" """
if mf=='' : if mf=='' :
for root, dirs, files in os.walk("./macro"): for root, dirs, files in os.walk("./macro"):
for mfile in files: for mfile in files:
full_path = os.path.join("./macro/", mfile) if mfile.endswith('.txt'):
pars_macro(full_path) full_path = os.path.join("./macro/", mfile)
pars_macro(full_path)
else: else:
pars_macro(mf) pars_macro(mf)
@ -173,7 +176,7 @@ def play_macro( mname, elm ):
while m: while m:
vu = m.group(0) vu = m.group(0)
if vu in var.keys(): if vu in var.keys():
l = re.sub('\\'+vu,var[vu], l) l = re.sub("\\"+vu,var[vu], l)
else: else:
print 'Error: unknown variable',vu,'in',mname print 'Error: unknown variable',vu,'in',mname
return return
@ -191,6 +194,7 @@ def print_help():
""" """
[h]elp - this help [h]elp - this help
[q]uit, [e]xit, end - exit from terminal [q]uit, [e]xit, end - exit from terminal
wait|sleep x - wait x seconds
""" """
global var global var
global macro global macro
@ -213,6 +217,7 @@ def optParser():
import argparse import argparse
global auto_macro global auto_macro
global auto_dia
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
#usage = "%prog -p <port> [options]", #usage = "%prog -p <port> [options]",
@ -246,6 +251,30 @@ def optParser():
default=False, default=False,
action="store_true") action="store_true")
parser.add_argument("--si",
help="try SlowInit first",
dest="si",
default=False,
action="store_true")
parser.add_argument("--cfc",
help="turn off automatic FC and do it by script",
dest="cfc",
default=False,
action="store_true")
parser.add_argument("--n1c",
help="turn off L1 cache",
dest="n1c",
default=False,
action="store_true")
parser.add_argument("--dialog",
help="show dialog for selecting macro",
dest="dia",
default=False,
action="store_true")
options = parser.parse_args() options = parser.parse_args()
if not options.port and mod_globals.os != 'android': if not options.port and mod_globals.os != 'android':
@ -264,9 +293,44 @@ def optParser():
auto_macro = options.macro auto_macro = options.macro
mod_globals.opt_log = options.logfile mod_globals.opt_log = options.logfile
mod_globals.opt_demo = options.demo mod_globals.opt_demo = options.demo
mod_globals.opt_si = options.si
mod_globals.opt_cfc0 = options.cfc
mod_globals.opt_n1c = options.n1c
auto_dia = options.dia
def file_chooser():
if mod_globals.os != 'android':
try:
# Python2
import Tkinter as tk
import ttk
import tkFileDialog as filedialog
except ImportError:
# Python3
import tkinter as tk
import tkinter.ttk as ttk
import tkFileDialog as filedialog
root = tk.Tk()
root.withdraw()
my_filetypes = [('command files', '.cmd')]
fname = filedialog.askopenfilename(parent=root,
initialdir="./macro",
title="Please select a file:",
filetypes=my_filetypes)
#root.destroy()
return fname
else:
pass
def main(): def main():
global auto_macro
global auto_dia
global macro global macro
global var global var
@ -284,28 +348,65 @@ def main():
elm.currentaddress = '7A' elm.currentaddress = '7A'
elm.currentprotocol = 'can' elm.currentprotocol = 'can'
if auto_macro!='': cmd_lines = []
cmd_ref = 0
if auto_dia:
fname = file_chooser()
if len(fname)>0:
f = open(fname, 'rt')
cmd_lines = f.readlines()
f.close()
if auto_macro != '':
if auto_macro in macro.keys(): if auto_macro in macro.keys():
play_macro( auto_macro, elm ) play_macro( auto_macro, elm )
else: else:
print 'Error: unknown macro mane:', auto_macro print 'Error: unknown macro mane:', auto_macro
while True: while True:
l = raw_input(var['$addr']+':'+var['$txa']+':'+var['$prompt'] + '#').lower() print var['$addr']+':'+var['$txa']+':'+var['$prompt'] + '#',
if len(cmd_lines)==0:
l = raw_input().lower()
else:
if cmd_ref<len(cmd_lines):
l = cmd_lines[cmd_ref].strip()
cmd_ref += 1
else:
l = "exit"
print l
if '#' in l:
l = l.split('#')[0]
l = l.strip() l = l.strip()
if len(l)==0:
continue
if l in ['q', 'quit', 'e', 'exit', 'end']: if l in ['q', 'quit', 'e', 'exit', 'end']:
break break
if l in ['h', 'help', '?']: if l in ['h', 'help', '?']:
print_help () print_help ()
continue continue
l_parts = l.split()
if len(l_parts)>0 and l_parts[0] in ['wait','sleep']:
try:
time.sleep(int(l_parts[1]))
continue
except:
pass
if l in macro.keys(): if l in macro.keys():
play_macro( l, elm ) play_macro( l, elm )
continue continue
m = re.search('\$\S+\s*=\s*\S+', l) m = re.search('\$\S+\s*=\s*\S+', l)
if m: if m:
#variable definition # variable definition
r = m.group(0).replace(' ', '').replace('\t', '') r = m.group(0).replace(' ', '').replace('\t', '')
rl = r.split('=') rl = r.split('=')
var[rl[0]]=rl[1] var[rl[0]]=rl[1]
@ -318,7 +419,7 @@ def main():
print elm.cmd(l) print elm.cmd(l)
if __name__ == '__main__': if __name__ == '__main__':
main() main()