forked from Marianpol/pyclip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_ecu_scenario.py
55 lines (50 loc) · 2.21 KB
/
mod_ecu_scenario.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#Embedded file name: /build/PyCLIP/android/app/mod_ecu_scenario.py
import re, os, mod_globals
if mod_globals.os == 'android':
from jnius import autoclass
Environment = autoclass('android.os.Environment')
import sys
scen_dir = Environment.getExternalStorageDirectory().getAbsolutePath() + '/pyren/scen/'
if not os.path.exists(scen_dir):
os.makedirs(scen_dir)
sys.path.append(scen_dir)
def playScenario(command, ecu, elm):
services = ecu.Services
scenarioName, scenarioData = command.scenario.split('#')
print scenarioName
if scenarioName.lower().startswith('scm'):
scenarioName = scenarioName.split(':')[1]
ecuNumberPattern = re.compile(r'_\d{5}')
ecuNumberIndex = ecuNumberPattern.search(scenarioData)
scenarioName = scenarioData[:scenarioData.find(ecuNumberIndex.group(0))].lower()
scenarioData = scenarioData.lower()
else:
scenarioData = scenarioData[5:].replace('=', '_').replace('.xml', '').replace('&', '_')+'.xml'
scenarioName = scenarioName.split(':')[1]
ecuNumberPattern = re.compile(r'_\d{5}')
ecuNumberIndex = ecuNumberPattern.search(scenarioData)
scenarioName = scenarioData[:scenarioData.find(ecuNumberIndex.group(0))].lower()
scenarioData = 'ecudata/'+scenarioData.lower()
if scenarioName == 'scen5':
if scenarioName.endswith('_ecu'):
scen = __import__(scenarioName[:len(scenarioName)-4])
elif scenarioName.endswith('_const'):
scen = __import__(scenarioName[:len(scenarioName)-6])
else:
scen = __import__(scenarioName)
scen.run(elm, ecu, command, scenarioData)
return True
else:
try:
if scenarioName.endswith('_ecu'):
scen = __import__(scenarioName[:len(scenarioName)-4])
elif scenarioName.endswith('_const'):
scen = __import__(scenarioName[:len(scenarioName)-6])
else:
scen = __import__(scenarioName)
scen.run(elm, ecu, command, scenarioData)
return True
except:
scen = __import__('show_scen')
scen.run(elm, ecu, command, scenarioData)
return True