Handle paraminj4 scenario

This commit is contained in:
Marianpol 2020-11-01 14:02:19 +01:00
parent 361a1bf219
commit 15c78eea4b
5 changed files with 288 additions and 5 deletions

View File

@ -259,7 +259,7 @@ class ECU:
return None return None
return self.Parameters[name] return self.Parameters[name]
def get_id( self, name, raw = 0): def get_id( self, name, raw = False):
if name not in self.Identifications.keys(): if name not in self.Identifications.keys():
for i in self.Identifications.keys(): for i in self.Identifications.keys():
if name==self.Identifications[i].codeMR: if name==self.Identifications[i].codeMR:
@ -364,7 +364,7 @@ class ECU:
if int(self.States[st].value): if int(self.States[st].value):
masks.append(self.States[st].name) masks.append(self.States[st].name)
if mask: if mask and not mod_globals.opt_demo:
for dr in datarefs: for dr in datarefs:
if dr.type=='State': if dr.type=='State':
if self.States[dr.name].mask and self.States[dr.name].mask not in masks: if self.States[dr.name].mask and self.States[dr.name].mask not in masks:

View File

@ -7,7 +7,7 @@ from xml.dom.minidom import parseString
import xml.dom.minidom import xml.dom.minidom
import mod_globals import mod_globals
def get_identification( id, mn, se, elm, calc, raw = 0 ): def get_identification( id, mn, se, elm, calc, raw = False ):
comp = id.computation comp = id.computation
comp = comp.replace("&","&") comp = comp.replace("&","&")
for m in sorted(id.mnemolist, key=len, reverse=True): for m in sorted(id.mnemolist, key=len, reverse=True):

View File

@ -33,7 +33,7 @@ def get_mnemonicDTC( m, resp ):
return hexval return hexval
def get_mnemonic( m, se, elm, raw = 0 ): def get_mnemonic( m, se, elm, raw = False ):
if not m.serviceID and mod_globals.ext_cur_DTC != "000000": if not m.serviceID and mod_globals.ext_cur_DTC != "000000":
for sid in se.keys(): for sid in se.keys():
@ -123,7 +123,7 @@ def get_SnapShotMnemonic(m, se, elm, dataids):
hexval = getHexVal(m, startByte, startBit, didDict[dataId]) hexval = getHexVal(m, startByte, startBit, didDict[dataId])
return hexval return hexval
def getHexVal(m, startByte, startBit, resp, raw = 0): def getHexVal(m, startByte, startBit, resp, raw = False):
#prepare local variables #prepare local variables
sb = int(startByte) - 1 sb = int(startByte) - 1
bits = int(m.bitsLength) bits = int(m.bitsLength)

View File

@ -14,6 +14,7 @@ GNU General Public License for more details.
import sys import sys
import os import os
import string
import signal import signal
import atexit import atexit
import subprocess import subprocess
@ -469,6 +470,9 @@ def DBG( tag, s ):
mod_globals.debug_file.write( '### ' + tag + '\n') mod_globals.debug_file.write( '### ' + tag + '\n')
mod_globals.debug_file.write( '"' + s + '"\n') mod_globals.debug_file.write( '"' + s + '"\n')
def isHex(s):
return all(c in string.hexdigits for c in s)
def kill_server(): def kill_server():
if mod_globals.doc_server_proc is None: if mod_globals.doc_server_proc is None:
pass pass

View File

@ -0,0 +1,279 @@
#!/usr/bin/env python
'''
Scenarium usage example
Name of this script should be exactly the same as in scenaruim URL but with '.py' extension
URL - scm:scen_ecri_calinj1#scen_ecri_calinj1_xxxxx.xml
'run' procedure will be executed by pyren script
'''
import os
import sys
import re
import time
import string
import mod_globals
import mod_utils
import mod_ecu
import mod_db_manager
from mod_ply import *
from mod_utils import pyren_encode
from mod_utils import clearScreen
from mod_utils import Choice
from mod_utils import isHex
from collections import OrderedDict
import xml.dom.minidom
import xml.etree.cElementTree as et
def run( elm, ecu, command, data ):
'''
MAIN function of scenarium
Parameters:
elm - refernce to adapter class
ecu - reference to ecu class
command - refernce to the command this scenarium belongs to
data - name of xml file with parameters from scenarium URL
'''
clearScreen()
header = '['+command.codeMR+'] '+command.label
ScmSet = {}
ScmParam = OrderedDict()
def get_message( msg, encode = True ):
if msg in ScmParam.keys():
value = ScmParam[msg]
else:
value = msg
if value.isdigit() and value in mod_globals.language_dict.keys():
if encode:
value = pyren_encode(mod_globals.language_dict[value])
else:
value = mod_globals.language_dict[value]
return value
def get_message_by_id( id, encode = True ):
if id.isdigit() and id in mod_globals.language_dict.keys():
if encode:
value = pyren_encode(mod_globals.language_dict[id])
else:
value = mod_globals.language_dict[id]
return value
#
# Data file parsing
#
DOMTree = xml.dom.minidom.parse(mod_db_manager.get_file_from_clip(data))
ScmRoom = DOMTree.documentElement
root = et.parse(mod_db_manager.get_file_from_clip(data)).getroot()
ScmParams = ScmRoom.getElementsByTagName("ScmParam")
for Param in ScmParams:
name = pyren_encode( Param.getAttribute("name") )
value = pyren_encode( Param.getAttribute("value") )
ScmParam[name] = value
ScmSets = ScmRoom.getElementsByTagName("ScmSet")
for Set in ScmSets:
setname = pyren_encode(Set.getAttribute("name"))
ScmParams = Set.getElementsByTagName("ScmParam")
scmParamsDict = OrderedDict()
for Param in ScmParams:
name = pyren_encode( Param.getAttribute("name") )
value = pyren_encode( Param.getAttribute("value") )
scmParamsDict[name] = value
ScmSet[setname]= scmParamsDict
confirm = get_message_by_id('19800')
successMessage = get_message("EndScreenMessage3", False)
failMessage = get_message("EndScreenMessage4", False)
#Prepare buttons
buttons = OrderedDict()
buttons[1] = get_message("Subtitle", False)
buttons["loadDump"] = get_message_by_id('19802', False)
buttons["exit"] = '<exit>'
def getIdsDump():
idsDump = OrderedDict()
for name, value in ScmSet['CommandIdentifications'].iteritems():
idValue = ecu.get_id(ScmSet['Identifications'][value], True)
if isHex(idValue):
idsDump[ScmSet['Commands'][name]] = idValue
return idsDump
def makeDump():
fileRoot = et.Element("ScmRoot")
fileRoot.text = "\n "
idsDump = getIdsDump()
if not idsDump: return
for cmd, value in idsDump.iteritems():
el = et.Element("ScmParam", name=cmd, value=value)
el.tail = "\n "
fileRoot.insert(1,el)
tree = et.ElementTree(fileRoot)
tree.write(mod_globals.dumps_dir + ScmParam['FileName'])
def loadDump():
dumpScmParam = {}
clearScreen()
try:
dumpData = open(mod_globals.dumps_dir + ScmParam['FileName'], 'r')
except:
print get_message_by_id('2194')
print
raw_input('Press ENTER to exit')
return
dumpDOMTree = xml.dom.minidom.parse(dumpData)
dumpScmRoot = dumpDOMTree.documentElement
dumpScmParams = dumpScmRoot.getElementsByTagName("ScmParam")
for Param in dumpScmParams:
name = pyren_encode( Param.getAttribute("name") )
value = pyren_encode( Param.getAttribute("value") )
dumpScmParam[name] = value
print '*'*80
print get_message_by_id('19802')
print '*'*80
print
ch = raw_input(confirm + ' <YES/NO>: ')
while (ch.upper()!='YES') and (ch.upper()!='NO'):
ch = raw_input(confirm + ' <YES/NO>: ')
if ch.upper()!='YES':
return
clearScreen()
responses = ''
for name, value in dumpScmParam.iteritems():
responses += ecu.run_cmd(name, value)
print '*'*80
print
if "NR" in responses:
print failMessage
else:
print successMessage
print
raw_input('Press ENTER to exit')
def resetValues():
info = get_message('Informations')
infoContent = get_message('InformationsContent')
inProgressMessage = get_message('CommandInProgressMessage')
clearScreen()
print title
print '*'*80
print subtitle
print '*'*80
print info
print
print infoContent
print '*'*80
print
ch = raw_input(confirm + ' <YES/NO>: ')
while (ch.upper()!='YES') and (ch.upper()!='NO'):
ch = raw_input(confirm + ' <YES/NO>: ')
if ch.upper()!='YES':
return
clearScreen()
print inProgressMessage
makeDump()
responses = ''
clearScreen()
for name, value in ScmSet['CommandParameters'].iteritems():
if isHex(value):
responses += ecu.run_cmd(ScmSet['Commands'][name],value)
else:
result = re.search(r"[^a-zA-Z\d\s:]", value)
if result:
parameters = re.findall(r"Ident\d+", value)
paramByteLength = len(parameters[0])/2
comp = value
for param in parameters:
paramValue = ecu.get_id(ScmSet['Identifications'][param], True)
if not isHex(paramValue):
comp = ''
break
comp = comp.replace(param, '0x' + ecu.get_id(ScmSet['Identifications'][param], True))
if not comp:
continue
calc = Calc()
idValue = calc.calculate(comp)
hexVal = hex(idValue)[2:]
if len(hexVal)%2:
hexVal = '0' + hexVal
if (len(hexVal)/2) % paramByteLength:
hexVal = '00' * (paramByteLength - len(hexVal)/2) + hexVal
responses += ecu.run_cmd(ScmSet['Commands'][name],hexVal)
else:
idValue = ecu.get_id(ScmSet['Identifications'][value], True)
if isHex(idValue):
responses += ecu.run_cmd(ScmSet['Commands'][name],idValue)
print '*'*80
print
if "NR" in responses:
print failMessage
else:
print successMessage
print
raw_input('Press ENTER to exit')
title = get_message('Title')
subtitle = get_message('Subtitle')
print title
print '*'*80
print subtitle
print '*'*80
print
choice = Choice(buttons.values(), "Choose :")
for key, value in buttons.iteritems():
if choice[0] =='<exit>': return
if value == choice[0]:
if key == 'loadDump':
loadDump()
else:
resetValues()
return