Snapshot refactor

This commit is contained in:
Marianpol 2020-02-22 15:53:36 +01:00
parent 109a9e4e73
commit 97684de33e
4 changed files with 39 additions and 23 deletions

View File

@ -426,12 +426,15 @@ class ECU:
print "Press any key to exit"
for dr in datarefs:
datastr = dr.name;
datastr = dr.name
help = dr.type
if dr.type=='State':
datastr, help, csvd = get_state( self.States[dr.name], self.Mnemonics, self.Services, self.elm, self.calc )
if self.DataIds and DTCpos and dr in self.Defaults[mod_globals.ext_cur_DTC[:4]].ssdatarefs:
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 dr in self.Defaults[mod_globals.ext_cur_DTC[:4]].datarefs:
if self.DataIds and DTCpos and dr in self.Defaults[mod_globals.ext_cur_DTC[:4]].ssdatarefs:
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 )
@ -439,6 +442,8 @@ class ECU:
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
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))
@ -751,7 +756,13 @@ class ECU:
path = path+' -> '+defstr[dtchex]+'\n\n'+hlpstr[dtchex]+'\n'
tmp_dtrf = self.Defaults[dtchex[:4]].datarefs + self.Defaults[dtchex[:4]].ssdatarefs + self.ext_de
mem_dtrf_txt = mod_globals.language_dict['299'] + " DTC" + mod_globals.ext_cur_DTC + "\n"
cur_dtrf = [ecu_screen_dataref(0, "\n" + mod_globals.language_dict['300'] + "\n", 'Text')] + self.Defaults[dtchex[:4]].datarefs
mem_dtrf = [ecu_screen_dataref(0, mem_dtrf_txt, 'Text')] + self.Defaults[dtchex[:4]].ssdatarefs
ext_info_dtrf = [ecu_screen_dataref(0, "\n" + mod_globals.language_dict['1691'] + "\n", 'Text')] + self.ext_de
tmp_dtrf = mem_dtrf + cur_dtrf + ext_info_dtrf
#self.show_datarefs(self.Defaults[dtchex[:4]].datarefs, path)
self.show_datarefs(tmp_dtrf, path)

View File

@ -1,7 +1,6 @@
#!/usr/bin/env python
from mod_ecu_service import *
from mod_globals import curPosInSnapshotResp
from mod_utils import Choice
from xml.dom.minidom import parse
@ -96,6 +95,7 @@ def get_mnemonic( m, se, elm, raw = 0 ):
def get_SnapShotMnemonic(m, se, elm, dataids):
snapshotService = ""
posInResp = 0
for sid in se:
if len(se[sid].params) > 1:
if se[sid].params[1]['type'] == 'Snapshot':
@ -107,24 +107,27 @@ def get_SnapShotMnemonic(m, se, elm, dataids):
resp = resp.strip().replace(' ','')
if not all(c in string.hexdigits for c in resp): resp = ''
resp = ' '.join(a+b for a,b in zip(resp[::2], resp[1::2]))
numberOfIdentifiers = int("0x" + resp[7*3:8*3-1],16)
resp = resp[8*3:]
if mod_globals.curPosInSnapshotResp >= len(resp):
mod_globals.curPosInSnapshotResp = 0
dataId = resp[mod_globals.curPosInSnapshotResp:mod_globals.curPosInSnapshotResp + 2*3].replace(" ", "")
didDataLength = int(dataids[dataId].dataBitLength)/8
didData = resp[mod_globals.curPosInSnapshotResp + 2*3: mod_globals.curPosInSnapshotResp + 2*3 + didDataLength*3]
mod_globals.curPosInSnapshotResp += 2*3 + didDataLength * 3
didDict = {}
for x in range(numberOfIdentifiers):
dataId = resp[posInResp:posInResp + 2*3].replace(" ", "")
posInResp += 2*3
didDataLength = int(dataids[dataId].dataBitLength)/8
didData = resp[posInResp: posInResp + didDataLength*3]
posInResp += didDataLength*3
didDict[dataId] = didData
startByte = ""
startBit = ""
for mn in dataids[dataId].mnemolocations.keys():
if mn == m.name:
startByte = dataids[dataId].mnemolocations[m.name].startByte
startBit = dataids[dataId].mnemolocations[m.name].startBit
dataId = ""
for did in dataids.keys():
for mn in dataids[did].mnemolocations.keys():
if mn == m.name:
dataId = did
startByte = dataids[dataId].mnemolocations[m.name].startByte
startBit = dataids[dataId].mnemolocations[m.name].startBit
#prepare local variables
sb = int(startByte) - 1
@ -134,11 +137,11 @@ def get_SnapShotMnemonic(m, se, elm, dataids):
rshift = ((bytes+1)*8 - (bits+sbit))%8
#check length of responce
if (sb*3+bytes*3-1)>(len(didData)):
if (sb*3+bytes*3-1)>(len(didDict[dataId])):
return '00'
#extract hex
hexval = didData[sb*3:(sb+bytes)*3-1]
hexval = didDict[dataId][sb*3:(sb+bytes)*3-1]
hexval = hexval.replace(" ","")
#shift and mask

View File

@ -7,11 +7,14 @@ from xml.dom.minidom import parseString
import xml.dom.minidom
import mod_globals
def get_state( st, mn, se, elm, calc ):
def get_state( st, mn, se, elm, calc, dataids = {} ):
comp = st.computation
comp = comp.replace("&","&")
for m in sorted(st.mnemolist, key=len, reverse=True):
hex_val = get_mnemonic( mn[m], se, elm )
if dataids:
hex_val = get_SnapShotMnemonic(mn[m], se, elm, dataids )
else:
hex_val = get_mnemonic( mn[m], se, elm )
comp = comp.replace(m, "0x"+hex_val)
tmp_val = calc.calculate(comp)

View File

@ -40,7 +40,6 @@ state_scan = False
currentDDTscreen = None
ext_cur_DTC = "000000"
curPosInSnapshotResp = 0
none_val = "None"