This commit is contained in:
Marianpol 2021-02-15 12:16:36 +01:00
parent 3ca2c7b201
commit d36c6558bd
2 changed files with 93 additions and 60 deletions

View File

@ -24,6 +24,7 @@ import mod_db_manager
from xml.dom.minidom import parse from xml.dom.minidom import parse
from datetime import datetime from datetime import datetime
from collections import OrderedDict
from mod_utils import show_doc from mod_utils import show_doc
import xml.dom.minidom import xml.dom.minidom
#import xml.etree.ElementTree as et #import xml.etree.ElementTree as et
@ -432,7 +433,8 @@ class ECU:
tb = time.time() #time of begining tb = time.time() #time of begining
if len(datarefs)==0 and 'DE' not in path: return 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: if mod_globals.opt_csv and mod_globals.opt_csv_only:
print "Data is sending directly to csv-file" 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.write(pyren_decode(csvline).encode('utf8') if mod_globals.opt_csv_human else csvline)
csvf.flush() csvf.flush()
csvline = datetime.now().strftime("%H:%M:%S.%f") 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() self.elm.clear_cache()
if not (tmpArray and mod_globals.opt_csv_only):
for dr in datarefs: 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":
datastr = dr.name datastr = dr.name
help = "" help = dr.type
if mod_globals.opt_csv and csvf!=0 and (dr.type=='State' or dr.type=='Parameter'): if dr.type=='State':
csvline += ";" + (pyren_encode(csvd) if mod_globals.opt_csv_human else str(csvd)) 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): if not (mod_globals.opt_csv and mod_globals.opt_csv_only):
strlst.append(datastr) strlst.append(datastr)
if mod_globals.opt_verbose and len(help)>0: if mod_globals.opt_verbose and len(help)>0:
tmp_str = '' tmp_str = ''
for s in help: for s in help:
#s = s.replace('\n','\n\t') #s = s.replace('\n','\n\t')
s = s.replace('\r','\n') s = s.replace('\r','\n')
s = s.replace('>','>') s = s.replace('>','>')
s = s.replace('&le;','<') s = s.replace('&le;','<')
tmp_str = tmp_str + s + '\n\n' tmp_str = tmp_str + s + '\n\n'
W = 50 W = 50
for line in tmp_str.split('\n'): for line in tmp_str.split('\n'):
i = 0 i = 0
while i*W<len(line): while i*W<len(line):
strlst.append('\t'+line[i*W:(i+1)*W]) strlst.append('\t'+line[i*W:(i+1)*W])
i=i+1 i=i+1
strlst.append('') strlst.append('')
else:
for req in tmpArray:
self.elm.request(req)
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
@ -580,6 +593,15 @@ class ECU:
kb.set_normal_term() kb.set_normal_term()
if mod_globals.opt_csv and csvf!=0: if mod_globals.opt_csv and csvf!=0:
csvf.close() 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: if "DTC" in path:
mod_globals.ext_cur_DTC = "000000" mod_globals.ext_cur_DTC = "000000"
return return

View File

@ -575,7 +575,7 @@ class ELM:
if len(mod_globals.opt_log)>0: # and mod_globals.opt_demo==False: if len(mod_globals.opt_log)>0: # and mod_globals.opt_demo==False:
self.lf = open ("./logs/elm_" + mod_globals.opt_log, "at") 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: if mod_globals.opt_debug and mod_globals.debug_file==None:
mod_globals.debug_file = open ("./logs/debug.txt", "at") mod_globals.debug_file = open ("./logs/debug.txt", "at")
@ -590,7 +590,7 @@ class ELM:
# check OBDLink # check OBDLink
elm_rsp = self.cmd("STPR") elm_rsp = self.cmd("STPR")
if '?' not in elm_rsp: if elm_rsp and '?' not in elm_rsp:
mod_globals.opt_obdlink = True mod_globals.opt_obdlink = True
# check STN # check STN
@ -599,10 +599,10 @@ class ELM:
mod_globals.opt_stn = True mod_globals.opt_stn = True
# Max out the UART speed for the fastest polling rate # 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: if mod_globals.opt_obdlink:
self.port.soft_boudrate(2000000) self.port.soft_boudrate(2000000)
elif self.port.portType == 0: else:
self.port.soft_boudrate(230400) self.port.soft_boudrate(230400)
def __del__(self): def __del__(self):
@ -1205,8 +1205,9 @@ class ELM:
cmd_len = len (command) / 2 cmd_len = len (command) / 2
if cmd_len < 8: # single frame if cmd_len < 8: # single frame
# check L1 cache here # check L1 cache here
if isCommandInCache and int('0x' + self.l1_cache[commandString], 16) < 16: # 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:
raw_command.append ("STPX D:" + ("%0.2X" % cmd_len) + command + ",R:" +self.l1_cache[command])
else: else:
raw_command.append (("%0.2X" % cmd_len) + command) raw_command.append (("%0.2X" % cmd_len) + command)
else: else:
@ -1223,15 +1224,20 @@ class ELM:
# add response frames number to each frame to increase polling # add response frames number to each frame to increase polling
if mod_globals.opt_obdlink and mod_globals.opt_perform: if mod_globals.opt_obdlink and mod_globals.opt_perform:
if commandString[:2] in AllowedList and isCommandInCache: if commandString[:2] in AllowedList and isCommandInCache:
if int('0x' + self.l1_cache[commandString], 16) < 16: readyFrame = ''
for index in range(len(raw_command) - 1): for f in raw_command:
raw_command[index] = raw_command[index] + '1' readyFrame += f
raw_command[-1] = raw_command[-1] + self.l1_cache[commandString] raw_command = ["STPX D:" + readyFrame + ",R:" + self.l1_cache[commandString]]
else:
readyFrame = '' # if int('0x' + self.l1_cache[commandString], 16) < 16:
for f in raw_command: # for index in range(len(raw_command) - 1):
readyFrame += f # raw_command[index] = raw_command[index] + '1'
raw_command = ["STPX D:" + readyFrame + ",R:" + self.l1_cache[commandString]] # 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 = [] responses = []
@ -1301,10 +1307,10 @@ class ELM:
# populate L1 cache # populate L1 cache
if noerrors and commandString[:2] in AllowedList and not mod_globals.opt_n1c: if noerrors and commandString[:2] in AllowedList and not mod_globals.opt_n1c:
if nframes < 16: # if nframes < 16:
self.l1_cache[commandString] = str(hex(nframes))[2:].upper() # self.l1_cache[commandString] = str(hex(nframes))[2:].upper()
else: #for OBDLink STPX command # else: #for OBDLink STPX command
self.l1_cache[commandString] = str(nframes) self.l1_cache[commandString] = str(nframes)
if len (result) / 2 >= nbytes and noerrors: if len (result) / 2 >= nbytes and noerrors:
# split by bytes and return # 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 at 1")) # reset adaptive timing step 3
self.check_answer (self.cmd ("at cra " + RXa)) 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 () self.check_adapter ()
def init_iso(self): def init_iso(self):