9n fix #8
This commit is contained in:
parent
df27d528cc
commit
e8ef5254e8
@ -7,7 +7,6 @@ import pickle
|
||||
os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
|
||||
|
||||
import mod_globals
|
||||
import mod_ecu
|
||||
import mod_scan_ecus
|
||||
import mod_elm
|
||||
|
||||
@ -296,6 +295,8 @@ def get_addr_from_xml( xmlfile ):
|
||||
def main():
|
||||
'''Main function'''
|
||||
|
||||
import mod_ecu
|
||||
|
||||
optParser()
|
||||
|
||||
print 'Opening ELM'
|
||||
|
@ -351,6 +351,7 @@ class ECU:
|
||||
|
||||
if mod_globals.opt_csv:
|
||||
# prepare to csv save
|
||||
self.minimumrefreshrate = 0
|
||||
csvline = u"Time"
|
||||
nparams = 0
|
||||
for dr in datarefs:
|
||||
@ -443,7 +444,7 @@ class ECU:
|
||||
|
||||
if not (mod_globals.opt_csv and mod_globals.opt_csv_only):
|
||||
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
|
||||
newScreen = newScreen + pyren_encode( header ) + '\n'
|
||||
|
||||
|
@ -663,10 +663,14 @@ class ELM:
|
||||
|
||||
if byte == '\r' or byte == '\n':
|
||||
|
||||
line = buff.strip ()
|
||||
line = buff.strip()
|
||||
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
|
||||
|
||||
|
@ -116,6 +116,7 @@ if __name__ == "__main__":
|
||||
if len(sys.argv)==1:
|
||||
print "Usage: mod_optfile.py <filename> [key]"
|
||||
print " mod_optfile.py ALLSG"
|
||||
print " mod_optfile.py HEX <infile> <outfile>"
|
||||
print "Example:"
|
||||
print " mod_optfile.py ../Location/DiagOnCan_RU.bqm"
|
||||
print " mod_optfile.py ../EcuRenault/Sessions/SG0110016.XML P001"
|
||||
@ -146,6 +147,20 @@ if __name__ == "__main__":
|
||||
f.close()
|
||||
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])
|
||||
|
||||
|
@ -854,7 +854,7 @@ def findTCOM( addr, cmd, rsp ):
|
||||
vehTCOM = vh.getAttribute("TCOM")
|
||||
vehicle = vehiclename+'#'+vehTCOM;
|
||||
|
||||
print vehicle
|
||||
#print vehicle
|
||||
|
||||
connector = vh.getElementsByTagName("Connector")
|
||||
cannetwork = connector.item(0).getElementsByTagName("CANNetwork")
|
||||
@ -887,7 +887,7 @@ def findTCOM( addr, cmd, rsp ):
|
||||
se = ScanEcus( None )
|
||||
print 'Loading Uces.xml'
|
||||
se.read_Uces_file(True)
|
||||
print ecuvhc
|
||||
#print ecuvhc
|
||||
for r in se.allecus.keys():
|
||||
if se.allecus[r]['dst']!=addr: continue
|
||||
if se.allecus[r]['ids'][0]!=cmd: continue
|
||||
|
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import sys, os, re
|
||||
import time
|
||||
import mod_globals
|
||||
import mod_elm
|
||||
|
||||
@ -16,6 +17,7 @@ var = {}
|
||||
stack = []
|
||||
|
||||
auto_macro = ""
|
||||
auto_dia = False
|
||||
|
||||
mod_globals.os = os.name
|
||||
|
||||
@ -132,12 +134,13 @@ def pars_macro( file ):
|
||||
|
||||
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=='' :
|
||||
for root, dirs, files in os.walk("./macro"):
|
||||
for mfile in files:
|
||||
if mfile.endswith('.txt'):
|
||||
full_path = os.path.join("./macro/", mfile)
|
||||
pars_macro(full_path)
|
||||
else:
|
||||
@ -173,7 +176,7 @@ def play_macro( mname, elm ):
|
||||
while m:
|
||||
vu = m.group(0)
|
||||
if vu in var.keys():
|
||||
l = re.sub('\\'+vu,var[vu], l)
|
||||
l = re.sub("\\"+vu,var[vu], l)
|
||||
else:
|
||||
print 'Error: unknown variable',vu,'in',mname
|
||||
return
|
||||
@ -191,6 +194,7 @@ def print_help():
|
||||
"""
|
||||
[h]elp - this help
|
||||
[q]uit, [e]xit, end - exit from terminal
|
||||
wait|sleep x - wait x seconds
|
||||
"""
|
||||
global var
|
||||
global macro
|
||||
@ -213,6 +217,7 @@ def optParser():
|
||||
import argparse
|
||||
|
||||
global auto_macro
|
||||
global auto_dia
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
#usage = "%prog -p <port> [options]",
|
||||
@ -246,6 +251,30 @@ def optParser():
|
||||
default=False,
|
||||
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()
|
||||
|
||||
if not options.port and mod_globals.os != 'android':
|
||||
@ -264,9 +293,44 @@ def optParser():
|
||||
auto_macro = options.macro
|
||||
mod_globals.opt_log = options.logfile
|
||||
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():
|
||||
|
||||
global auto_macro
|
||||
global auto_dia
|
||||
global macro
|
||||
global var
|
||||
|
||||
@ -284,28 +348,65 @@ def main():
|
||||
elm.currentaddress = '7A'
|
||||
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():
|
||||
play_macro( auto_macro, elm )
|
||||
else:
|
||||
print 'Error: unknown macro mane:', auto_macro
|
||||
|
||||
|
||||
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()
|
||||
|
||||
if len(l)==0:
|
||||
continue
|
||||
|
||||
if l in ['q', 'quit', 'e', 'exit', 'end']:
|
||||
break
|
||||
|
||||
if l in ['h', 'help', '?']:
|
||||
print_help ()
|
||||
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():
|
||||
play_macro( l, elm )
|
||||
continue
|
||||
|
||||
m = re.search('\$\S+\s*=\s*\S+', l)
|
||||
if m:
|
||||
#variable definition
|
||||
# variable definition
|
||||
r = m.group(0).replace(' ', '').replace('\t', '')
|
||||
rl = r.split('=')
|
||||
var[rl[0]]=rl[1]
|
||||
|
Loading…
x
Reference in New Issue
Block a user