Fix
This commit is contained in:
parent
3ca2c7b201
commit
d36c6558bd
104
pyren/mod_ecu.py
104
pyren/mod_ecu.py
@ -24,6 +24,7 @@ import mod_db_manager
|
||||
|
||||
from xml.dom.minidom import parse
|
||||
from datetime import datetime
|
||||
from collections import OrderedDict
|
||||
from mod_utils import show_doc
|
||||
import xml.dom.minidom
|
||||
#import xml.etree.ElementTree as et
|
||||
@ -432,7 +433,8 @@ class ECU:
|
||||
tb = time.time() #time of begining
|
||||
|
||||
if len(datarefs)==0 and 'DE' not in path: return
|
||||
|
||||
self.elm.clear_cache()
|
||||
tmpArray = OrderedDict()
|
||||
|
||||
if mod_globals.opt_csv and mod_globals.opt_csv_only:
|
||||
print "Data is sending directly to csv-file"
|
||||
@ -457,49 +459,60 @@ class ECU:
|
||||
# csvf.write(pyren_decode(csvline).encode('utf8') if mod_globals.opt_csv_human else csvline)
|
||||
csvf.flush()
|
||||
csvline = datetime.now().strftime("%H:%M:%S.%f")
|
||||
|
||||
|
||||
if mod_globals.opt_perform:
|
||||
if not tmpArray or tmpArray.keys()[-1].startswith('21') :
|
||||
for x in self.elm.rsp_cache.keys():
|
||||
if (x.startswith('22') and len(x) > 6) or x.startswith('21') or len(self.elm.rsp_cache) == 1:
|
||||
tmpArray[x] = x
|
||||
if len(self.elm.currentScreenDataIds) > 1:
|
||||
tmpArray["22" + self.elm.currentScreenDataIds[-1][0].id] = "22" + self.elm.currentScreenDataIds[-1][0].id
|
||||
|
||||
self.elm.clear_cache()
|
||||
|
||||
for dr in datarefs:
|
||||
datastr = dr.name
|
||||
help = dr.type
|
||||
if dr.type=='State':
|
||||
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 "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 )
|
||||
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':
|
||||
datastr = dr.name + " [Command] " + self.Commands[dr.name].label
|
||||
if dr.type=="Text":
|
||||
if not (tmpArray and mod_globals.opt_csv_only):
|
||||
for dr in datarefs:
|
||||
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))
|
||||
help = dr.type
|
||||
if dr.type=='State':
|
||||
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 "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 )
|
||||
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':
|
||||
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))
|
||||
|
||||
if not (mod_globals.opt_csv and mod_globals.opt_csv_only):
|
||||
strlst.append(datastr)
|
||||
if mod_globals.opt_verbose and len(help)>0:
|
||||
tmp_str = ''
|
||||
for s in help:
|
||||
#s = s.replace('\n','\n\t')
|
||||
s = s.replace('\r','\n')
|
||||
s = s.replace('>','>')
|
||||
s = s.replace('≤','<')
|
||||
tmp_str = tmp_str + s + '\n\n'
|
||||
W = 50
|
||||
for line in tmp_str.split('\n'):
|
||||
i = 0
|
||||
while i*W<len(line):
|
||||
strlst.append('\t'+line[i*W:(i+1)*W])
|
||||
i=i+1
|
||||
strlst.append('')
|
||||
if not (mod_globals.opt_csv and mod_globals.opt_csv_only):
|
||||
strlst.append(datastr)
|
||||
if mod_globals.opt_verbose and len(help)>0:
|
||||
tmp_str = ''
|
||||
for s in help:
|
||||
#s = s.replace('\n','\n\t')
|
||||
s = s.replace('\r','\n')
|
||||
s = s.replace('>','>')
|
||||
s = s.replace('≤','<')
|
||||
tmp_str = tmp_str + s + '\n\n'
|
||||
W = 50
|
||||
for line in tmp_str.split('\n'):
|
||||
i = 0
|
||||
while i*W<len(line):
|
||||
strlst.append('\t'+line[i*W:(i+1)*W])
|
||||
i=i+1
|
||||
strlst.append('')
|
||||
else:
|
||||
for req in tmpArray:
|
||||
self.elm.request(req)
|
||||
|
||||
if not (mod_globals.opt_csv and mod_globals.opt_csv_only):
|
||||
newScreen = initScreen
|
||||
@ -580,6 +593,15 @@ class ECU:
|
||||
kb.set_normal_term()
|
||||
if mod_globals.opt_csv and csvf!=0:
|
||||
csvf.close()
|
||||
# self.elm.vf.read()
|
||||
# with open ("./logs/ecu_" + mod_globals.opt_log, "r") as f:
|
||||
# for line in f:
|
||||
# print line
|
||||
for line in self.elm.vf:
|
||||
print line
|
||||
raw_input()
|
||||
# raw_input('2322232')
|
||||
# self.elm.vf.read()
|
||||
if "DTC" in path:
|
||||
mod_globals.ext_cur_DTC = "000000"
|
||||
return
|
||||
|
@ -575,7 +575,7 @@ class ELM:
|
||||
|
||||
if len(mod_globals.opt_log)>0: # and mod_globals.opt_demo==False:
|
||||
self.lf = open ("./logs/elm_" + mod_globals.opt_log, "at")
|
||||
self.vf = open ("./logs/ecu_" + mod_globals.opt_log, "at")
|
||||
self.vf = open ("./logs/ecu_" + mod_globals.opt_log, "at+")
|
||||
|
||||
if mod_globals.opt_debug and mod_globals.debug_file==None:
|
||||
mod_globals.debug_file = open ("./logs/debug.txt", "at")
|
||||
@ -590,7 +590,7 @@ class ELM:
|
||||
|
||||
# check OBDLink
|
||||
elm_rsp = self.cmd("STPR")
|
||||
if '?' not in elm_rsp:
|
||||
if elm_rsp and '?' not in elm_rsp:
|
||||
mod_globals.opt_obdlink = True
|
||||
|
||||
# check STN
|
||||
@ -599,10 +599,10 @@ class ELM:
|
||||
mod_globals.opt_stn = True
|
||||
|
||||
# Max out the UART speed for the fastest polling rate
|
||||
if mod_globals.opt_csv:
|
||||
if mod_globals.opt_csv and not mod_globals.opt_demo:
|
||||
if mod_globals.opt_obdlink:
|
||||
self.port.soft_boudrate(2000000)
|
||||
elif self.port.portType == 0:
|
||||
else:
|
||||
self.port.soft_boudrate(230400)
|
||||
|
||||
def __del__(self):
|
||||
@ -1205,8 +1205,9 @@ class ELM:
|
||||
cmd_len = len (command) / 2
|
||||
if cmd_len < 8: # single frame
|
||||
# check L1 cache here
|
||||
if isCommandInCache and int('0x' + self.l1_cache[commandString], 16) < 16:
|
||||
raw_command.append (("%0.2X" % cmd_len) + command + self.l1_cache[command])
|
||||
# if isCommandInCache and int('0x' + self.l1_cache[commandString], 16) < 16:
|
||||
if isCommandInCache:
|
||||
raw_command.append ("STPX D:" + ("%0.2X" % cmd_len) + command + ",R:" +self.l1_cache[command])
|
||||
else:
|
||||
raw_command.append (("%0.2X" % cmd_len) + command)
|
||||
else:
|
||||
@ -1223,15 +1224,20 @@ class ELM:
|
||||
# add response frames number to each frame to increase polling
|
||||
if mod_globals.opt_obdlink and mod_globals.opt_perform:
|
||||
if commandString[:2] in AllowedList and isCommandInCache:
|
||||
if int('0x' + self.l1_cache[commandString], 16) < 16:
|
||||
for index in range(len(raw_command) - 1):
|
||||
raw_command[index] = raw_command[index] + '1'
|
||||
raw_command[-1] = raw_command[-1] + self.l1_cache[commandString]
|
||||
else:
|
||||
readyFrame = ''
|
||||
for f in raw_command:
|
||||
readyFrame += f
|
||||
raw_command = ["STPX D:" + readyFrame + ",R:" + self.l1_cache[commandString]]
|
||||
readyFrame = ''
|
||||
for f in raw_command:
|
||||
readyFrame += f
|
||||
raw_command = ["STPX D:" + readyFrame + ",R:" + self.l1_cache[commandString]]
|
||||
|
||||
# if int('0x' + self.l1_cache[commandString], 16) < 16:
|
||||
# for index in range(len(raw_command) - 1):
|
||||
# raw_command[index] = raw_command[index] + '1'
|
||||
# raw_command[-1] = raw_command[-1] + self.l1_cache[commandString]
|
||||
# else:
|
||||
# readyFrame = ''
|
||||
# for f in raw_command:
|
||||
# readyFrame += f
|
||||
# raw_command = ["STPX D:" + readyFrame + ",R:" + self.l1_cache[commandString]]
|
||||
|
||||
responses = []
|
||||
|
||||
@ -1301,10 +1307,10 @@ class ELM:
|
||||
|
||||
# populate L1 cache
|
||||
if noerrors and commandString[:2] in AllowedList and not mod_globals.opt_n1c:
|
||||
if nframes < 16:
|
||||
self.l1_cache[commandString] = str(hex(nframes))[2:].upper()
|
||||
else: #for OBDLink STPX command
|
||||
self.l1_cache[commandString] = str(nframes)
|
||||
# if nframes < 16:
|
||||
# self.l1_cache[commandString] = str(hex(nframes))[2:].upper()
|
||||
# else: #for OBDLink STPX command
|
||||
self.l1_cache[commandString] = str(nframes)
|
||||
|
||||
if len (result) / 2 >= nbytes and noerrors:
|
||||
# split by bytes and return
|
||||
@ -1962,6 +1968,11 @@ class ELM:
|
||||
self.check_answer (self.cmd ("at at 1")) # reset adaptive timing step 3
|
||||
self.check_answer (self.cmd ("at cra " + RXa))
|
||||
|
||||
|
||||
self.check_answer (self.cmd ("at sh 35C"))
|
||||
self.send_raw ("FA 40 00 00 00 20 60 04")
|
||||
self.check_answer (self.cmd ("at sh " + TXa))
|
||||
|
||||
self.check_adapter ()
|
||||
|
||||
def init_iso(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user