acf insert addr and sesion based on TCOMs
This commit is contained in:
parent
82d4a0a19a
commit
951742363a
@ -6,6 +6,7 @@ import mod_db_manager
|
||||
import mod_utils
|
||||
from mod_optfile import *
|
||||
from mod_scan_ecus import families as families
|
||||
from mod_scan_ecus import findTCOM as findTCOM
|
||||
|
||||
os.chdir(os.path.dirname(os.path.realpath(sys.argv[0])))
|
||||
|
||||
@ -202,7 +203,7 @@ def main():
|
||||
mod_utils.chkDirTree()
|
||||
mod_db_manager.find_DBs()
|
||||
|
||||
'''Check direcories'''
|
||||
'''Check directories'''
|
||||
if not os.path.exists('../BVMEXTRACTION'):
|
||||
print("Can't find MTC database. (../BVMEXTRACTION)")
|
||||
exit()
|
||||
@ -214,8 +215,6 @@ def main():
|
||||
if mod_globals.opt_speed<mod_globals.opt_rate and not mod_globals.opt_demo:
|
||||
elm.port.soft_boudrate( mod_globals.opt_rate )
|
||||
|
||||
|
||||
|
||||
print("Loading language ")
|
||||
sys.stdout.flush()
|
||||
#loading language data
|
||||
@ -230,6 +229,13 @@ def main():
|
||||
if mod_globals.opt_can2:
|
||||
SEFname = "savedEcus2.p"
|
||||
|
||||
pl_id_cache = './cache/pl_id_attr.p'
|
||||
if os.path.isfile(pl_id_cache): #if cache exists
|
||||
pl_id = pickle.load( open( pl_id_cache, "rb" ) ) #load it
|
||||
else: #else
|
||||
findTCOM('', '', '', True) #make cache
|
||||
pl_id = pickle.load( open( pl_id_cache, "rb" ) ) #load it
|
||||
|
||||
if mod_globals.opt_demo and len(mod_globals.opt_ecuid)>0:
|
||||
# demo mode with predefined ecu list
|
||||
se.read_Uces_file( all = True )
|
||||
@ -297,7 +303,10 @@ def main():
|
||||
if 'mo' in list(m.keys()) and m['mo']!='':
|
||||
print("%2s : %s : %s" % (m['idf'],m['sref'],m['mo'].NOM))
|
||||
|
||||
acf_MTC_generateDefaults( m, mtc )
|
||||
attr = []
|
||||
if platform in pl_id.keys() and m['idf'] in pl_id[platform].keys():
|
||||
attr = pl_id[platform][m['idf']]
|
||||
acf_MTC_generateDefaults( m, mtc, attr )
|
||||
#acf_MTC_findDiff( m, mtc, elm )
|
||||
|
||||
else:
|
||||
|
@ -6,6 +6,7 @@ import time
|
||||
import mod_globals
|
||||
import mod_elm
|
||||
import shutil
|
||||
import pickle
|
||||
|
||||
from mod_mtc import acf_MTC_finde
|
||||
from mod_mtc import acf_MTC_and
|
||||
@ -68,7 +69,7 @@ def acf_form_commands( m, cu, op ):
|
||||
m['acf_wc'][cu.RW] = acf_pack_command( True, ace.req[cu.RW], cu.DW, m['acf_wc'][cu.RW], op.TW, op.MW)
|
||||
ace.req[cu.RW].SentDI[cu.DW].val = op.VW + ' #[' + cu.TE + ' : ' + op.TEX + '](' + op.MTC + ')'
|
||||
|
||||
def acf_MTC_generateDefaults( m, mtc ):
|
||||
def acf_MTC_generateDefaults( m, mtc, attr ):
|
||||
""" m - module definition map """
|
||||
''' mtc - list of options '''
|
||||
''' this function generates default values'''
|
||||
@ -136,14 +137,26 @@ def acf_MTC_generateDefaults( m, mtc ):
|
||||
sf = open(scriptn,'wt')
|
||||
|
||||
#print "--------------- Write Commands --------------------"
|
||||
attr = list(attr)
|
||||
attr_dst = ''
|
||||
attr_ses = ''
|
||||
if len(attr)>0:
|
||||
attr_dst, attr_ses = attr[0].split('#')
|
||||
if len(attr)>1:
|
||||
attr_dst = attr_dst + ' #'
|
||||
attr_ses = attr_ses + ' #'
|
||||
for a in attr[1:]:
|
||||
dst,ses = a.split('#')
|
||||
attr_dst = attr_dst + ' ' + dst
|
||||
attr_ses = attr_ses + ' ' + ses
|
||||
|
||||
# write preamble
|
||||
sf.write('# ' + mod_globals.vin + '\n\n')
|
||||
sf.write('$addr = ' + m['dst'] +'\n\n')
|
||||
sf.write('$addr = ' + attr_dst +'\n\n')
|
||||
sf.write('can500 # init can macro\n\n')
|
||||
sf.write('delay 1\n\n')
|
||||
sf.write('# open session\n')
|
||||
sf.write('session ' + m['startDiagReq'] + '\n\n')
|
||||
sf.write('session ' + attr_ses + '\n\n')
|
||||
sf.write('# configuration\n')
|
||||
|
||||
# save write commands
|
||||
|
@ -68,14 +68,20 @@ def acf_buildFull( platf ):
|
||||
return
|
||||
|
||||
mtc = {}
|
||||
mtcf = open(plDIR+'/MTC.dat', 'rt')
|
||||
mtc_name = 'MTC.dat'
|
||||
for fn in os.listdir(plDIR):
|
||||
if fn.upper()=='MTC.DAT': mtc_name = fn
|
||||
mtcf = open(plDIR + '/' + mtc_name, 'rt')
|
||||
mtc_list = csv.reader(mtcf, delimiter=';')
|
||||
for i in mtc_list:
|
||||
if i:
|
||||
mtc[int(i[0][:-4])] = i[1:]
|
||||
|
||||
ref = {}
|
||||
reff = open(plDIR+'/REF.dat', 'rt')
|
||||
ref_name = 'REF.dat'
|
||||
for fn in os.listdir(plDIR):
|
||||
if fn.upper()=='REF.DAT': ref_name = fn
|
||||
reff = open(plDIR + '/' + ref_name, 'rt')
|
||||
ref_list = csv.reader(reff, delimiter=';')
|
||||
for i in ref_list:
|
||||
if i:
|
||||
@ -205,7 +211,10 @@ def acf_getMTC( VIN, preferFile=False ):
|
||||
|
||||
#check if there is an mtc file
|
||||
|
||||
mz = open(vindir+'MTC.dat','r')
|
||||
mtc_name = 'MTC.dat'
|
||||
for fn in os.listdir(vindir):
|
||||
if fn.upper()=='MTC.DAT': mtc_name = fn
|
||||
mz = open(vindir+mtc_name,'r')
|
||||
mtclist = mz.read().split('\n')
|
||||
mz.close()
|
||||
for l in mtclist:
|
||||
@ -213,7 +222,10 @@ def acf_getMTC( VIN, preferFile=False ):
|
||||
mtcdata = l
|
||||
|
||||
try:
|
||||
rz = open(vindir+'REF.dat','r')
|
||||
ref_name = 'REF.dat'
|
||||
for fn in os.listdir(vindir):
|
||||
if fn.upper()=='REF.DAT': ref_name = fn
|
||||
rz = open(vindir+ref_name,'r')
|
||||
reflist = rz.read().split('\n')
|
||||
rz.close()
|
||||
for l in reflist:
|
||||
|
@ -999,8 +999,9 @@ def readECUIds( elm ):
|
||||
return StartSession, DiagVersion, Supplier, Version, Soft, Std, VIN
|
||||
|
||||
|
||||
def findTCOM( addr, cmd, rsp ):
|
||||
def findTCOM( addr, cmd, rsp, pl_id = False ):
|
||||
ecuvhc = {}
|
||||
pl_id = {}
|
||||
vehicle = ''
|
||||
print('Read models')
|
||||
file_list = mod_db_manager.get_file_list_from_clip('Vehicles/TCOM_*.[Xx]ml')
|
||||
@ -1013,7 +1014,7 @@ def findTCOM( addr, cmd, rsp ):
|
||||
vehTypeCode = vh.getAttribute("vehTypeCode")
|
||||
vehTCOM = vh.getAttribute("TCOM")
|
||||
vehicle = vehiclename+'#'+vehTCOM;
|
||||
|
||||
pl_id[vehTypeCode] = {}
|
||||
#print vehicle
|
||||
|
||||
connector = vh.getElementsByTagName("Connector")
|
||||
@ -1024,9 +1025,13 @@ def findTCOM( addr, cmd, rsp ):
|
||||
if eculist:
|
||||
ecukind = eculist.item(0).getElementsByTagName("EcuKind")
|
||||
for ek in ecukind:
|
||||
id = ek.getAttribute("idFamily")
|
||||
pl_id[vehTypeCode][id] = {}
|
||||
pl_id[vehTypeCode][id]['refs'] = []
|
||||
ecuref = ek.getElementsByTagName("EcuRef")
|
||||
for er in ecuref:
|
||||
ecuname = er.getAttribute("name")
|
||||
pl_id[vehTypeCode][id]['refs'].append(ecuname)
|
||||
if ecuname in list(ecuvhc.keys()):
|
||||
ecuvhc[ecuname].append(vehicle)
|
||||
else:
|
||||
@ -1036,9 +1041,14 @@ def findTCOM( addr, cmd, rsp ):
|
||||
if eculist:
|
||||
ecukind = eculist.item(0).getElementsByTagName("EcuKind")
|
||||
for ek in ecukind:
|
||||
id = ek.getAttribute("idFamily")
|
||||
if id not in pl_id[vehTypeCode].keys():
|
||||
pl_id[vehTypeCode][id] = {}
|
||||
pl_id[vehTypeCode][id]['refs'] = []
|
||||
ecuref = ek.getElementsByTagName("EcuRef")
|
||||
for er in ecuref:
|
||||
ecuname = er.getAttribute("name")
|
||||
pl_id[vehTypeCode][id]['refs'].append(ecuname)
|
||||
if ecuname in list(ecuvhc.keys()):
|
||||
ecuvhc[ecuname].append(vehicle)
|
||||
else:
|
||||
@ -1047,15 +1057,34 @@ def findTCOM( addr, cmd, rsp ):
|
||||
se = ScanEcus( None )
|
||||
print('Loading Uces.xml')
|
||||
se.read_Uces_file(True)
|
||||
#print ecuvhc
|
||||
for r in list(se.allecus.keys()):
|
||||
if se.allecus[r]['dst']!=addr: continue
|
||||
if se.allecus[r]['ids'][0]!=cmd: continue
|
||||
if se.compare_ecu( se.allecus[r]['ids'], rsp, cmd ):
|
||||
try:
|
||||
print(r, se.allecus[r]['doc'], se.allecus[r]['ids'], ecuvhc[r])
|
||||
except:
|
||||
print()
|
||||
|
||||
if pl_id:
|
||||
#save pl_id
|
||||
for pl in pl_id.keys():
|
||||
for id in pl_id[pl].keys():
|
||||
attr = set()
|
||||
for r in pl_id[pl][id]['refs']:
|
||||
if r in se.allecus.keys():
|
||||
#attr.add(se.allecus[r]['stdType']+"#"+se.allecus[r]['dst']+"#"+se.allecus[r]['startDiagReq'])
|
||||
attr.add(se.allecus[r]['dst']+"#"+se.allecus[r]['startDiagReq'])
|
||||
#else:
|
||||
# print(r)
|
||||
del pl_id[pl][id]['refs']
|
||||
pl_id[pl][id] = attr
|
||||
pickle.dump( pl_id, open( './cache/pl_id_attr.p', "wb" ) )
|
||||
else:
|
||||
#print found ecus
|
||||
for r in list(se.allecus.keys()):
|
||||
if se.allecus[r]['dst']!=addr: continue
|
||||
if se.allecus[r]['ids'][0]!=cmd: continue
|
||||
if se.compare_ecu( se.allecus[r]['ids'], rsp, cmd ):
|
||||
try:
|
||||
print(r, se.allecus[r]['doc'], se.allecus[r]['ids'], ecuvhc[r])
|
||||
except:
|
||||
print()
|
||||
|
||||
|
||||
|
||||
def generateSavedEcus( eculist, fileName ):
|
||||
se = ScanEcus( 0 )
|
||||
se.read_Uces_file( all = True )
|
||||
@ -1078,6 +1107,8 @@ if __name__ == "__main__":
|
||||
|
||||
mod_db_manager.find_DBs()
|
||||
|
||||
#findTCOM( '', '', '', pl_id=True)
|
||||
|
||||
# 10016,10074 savedEcus.p_gen
|
||||
if len(sys.argv)==3: generateSavedEcus( sys.argv[1], sys.argv[2] )
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user