[mod_term] Use ELM init commands from ELM class
This commit is contained in:
parent
c1820285e8
commit
fdbe0eae16
@ -1,85 +0,0 @@
|
||||
#
|
||||
#
|
||||
# Initialisation macros for mod_term
|
||||
#
|
||||
#
|
||||
|
||||
$addr = 7A
|
||||
$txa = 7E0
|
||||
$rxa = 7E8
|
||||
|
||||
# reset elm
|
||||
reset_elm {
|
||||
at ws
|
||||
$prompt = ELM
|
||||
}
|
||||
|
||||
# general CAN init
|
||||
init_can {
|
||||
reset_elm #macro
|
||||
at e1
|
||||
at s0
|
||||
at h0
|
||||
at l0
|
||||
at al
|
||||
at caf0
|
||||
at cfc0
|
||||
at sh $txa
|
||||
at cra $rxa
|
||||
at fc sh $txa
|
||||
at fc sd 30 00 00
|
||||
at fc sm 1
|
||||
$prompt = CAN
|
||||
}
|
||||
|
||||
# CAN 250 init
|
||||
can250 {
|
||||
init_can
|
||||
at st ff
|
||||
at at 0
|
||||
at sp 8
|
||||
at at 1
|
||||
$prompt = CAN250
|
||||
}
|
||||
|
||||
# CAN 500 init
|
||||
can500 {
|
||||
init_can
|
||||
at st ff
|
||||
at at 0
|
||||
at sp 6
|
||||
at at 1
|
||||
$prompt = CAN500
|
||||
}
|
||||
|
||||
# general ISO init
|
||||
init_iso {
|
||||
reset_elm #macro
|
||||
at e1
|
||||
at l1
|
||||
at d1
|
||||
at sh 81 $addr f1
|
||||
at sw 96
|
||||
at wm 81 $addr f1 3E
|
||||
#at wm 82 $addr f1 3E01
|
||||
at ib10
|
||||
at st ff
|
||||
at at 0
|
||||
$prompt = KL
|
||||
}
|
||||
|
||||
# K-Line slow init
|
||||
slow {
|
||||
init_iso
|
||||
at sp 4
|
||||
at at 1
|
||||
$prompt = SLOW
|
||||
}
|
||||
|
||||
# K-Line fast init
|
||||
fast {
|
||||
init_iso
|
||||
at sp 5
|
||||
at at 1
|
||||
$prompt = FAST
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
# Day running light off
|
||||
$addr = 26
|
||||
|
||||
can500 # init can macro
|
||||
init_can_500 # init can macro
|
||||
|
||||
10C0
|
||||
3BA01800
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Car wipers manual control, not managed by rain sensor
|
||||
$addr = 26
|
||||
|
||||
can500 # init can macro
|
||||
init_can_500 # init can macro
|
||||
|
||||
10C0
|
||||
3BA01200
|
||||
|
@ -1,7 +1,7 @@
|
||||
#Accoustics for R2_08_v3_81
|
||||
$addr = 13
|
||||
|
||||
can500 # init can macro
|
||||
init_can_500 # init can macro
|
||||
|
||||
delay 2
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
# QR25 Idle speed correction
|
||||
$addr = 7A
|
||||
|
||||
can500 # init can macro
|
||||
init_can_500 # init can macro
|
||||
|
||||
# check ECU
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Repair script for rlink2 black screen
|
||||
$addr = 13
|
||||
|
||||
can500 # init can macro
|
||||
init_can_500 # init can macro
|
||||
|
||||
1003
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Repair script for rlink2 black screen
|
||||
$addr = 13
|
||||
|
||||
can500 # init can macro
|
||||
init_can_500 # init can macro
|
||||
|
||||
1003
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Repair script for rlink2 black screen
|
||||
$addr = 13
|
||||
|
||||
can500 # init can macro
|
||||
init_can_500 # init can macro
|
||||
|
||||
1003
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Repair script for rlink2 black screen
|
||||
$addr = 13
|
||||
|
||||
can500 # init can macro
|
||||
init_can_500 # init can macro
|
||||
|
||||
1003
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Enable AndroidAuto and CarPlay on R-Link2
|
||||
$addr = 13
|
||||
|
||||
can500 # init can macro
|
||||
init_can_500 # init can macro
|
||||
|
||||
1003
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Rotate R-Link2 screen
|
||||
$addr = 13
|
||||
|
||||
can500 # init can macro
|
||||
init_can_500 # init can macro
|
||||
|
||||
1003
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Phone_acoustic and SPVR for RadNav 3.3 and 7.0
|
||||
$addr = 13
|
||||
|
||||
can500 # init can macro
|
||||
init_can_500 # init can macro
|
||||
|
||||
delay 2
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
# Phone_acoustic and SPVR for RadNav 8.0
|
||||
$addr = 13
|
||||
|
||||
can500 # init can macro
|
||||
init_can_500 # init can macro
|
||||
|
||||
delay 2
|
||||
|
||||
|
@ -2,6 +2,6 @@
|
||||
# terminal
|
||||
$addr = 7A
|
||||
|
||||
can500 # init can macro
|
||||
init_can_500 # init can macro
|
||||
|
||||
session 10C0
|
||||
|
@ -2006,11 +2006,11 @@ class ELM:
|
||||
if self.currentprotocol == "can" and self.currentaddress == addr:
|
||||
return
|
||||
|
||||
if len (ecu['idTx']): dnat[addr] = ecu['idTx']
|
||||
if len (ecu['idRx']): snat[addr] = ecu['idRx']
|
||||
if len(ecu.get('idTx', '')): dnat[addr] = ecu['idTx']
|
||||
if len(ecu.get('idRx', '')): snat[addr] = ecu['idRx']
|
||||
|
||||
if self.lf != 0:
|
||||
self.lf.write ('#' * 60 + "\n#connect to: " + ecu['ecuname'] + " Addr:" + addr + "\n" + '#' * 60 + "\n")
|
||||
self.lf.write ('#' * 60 + "\n#connect to: " + ecu.get('ecuname', '') + " Addr:" + addr + "\n" + '#' * 60 + "\n")
|
||||
self.lf.flush ()
|
||||
|
||||
self.currentprotocol = "can"
|
||||
@ -2096,19 +2096,19 @@ class ELM:
|
||||
self.notSupportedCommands = {}
|
||||
self.tmpNotSupportedCommands = {}
|
||||
|
||||
if self.currentprotocol == "iso" and self.currentaddress == addr and self.currentsubprotocol == ecu['protocol']:
|
||||
if self.currentprotocol == "iso" and self.currentaddress == addr and self.currentsubprotocol == ecu.get('protocol', ''):
|
||||
return
|
||||
|
||||
if self.lf != 0:
|
||||
self.lf.write ('#' * 60 + "\n#connect to: " + ecu['ecuname'] + " Addr:" + addr + " Protocol:" + ecu[
|
||||
'protocol'] + "\n" + '#' * 60 + "\n")
|
||||
self.lf.write ('#' * 60 + "\n#connect to: " + ecu.get('ecuname', '') + " Addr:" + addr + " Protocol:" +
|
||||
ecu.get('protocol', '') + "\n" + '#' * 60 + "\n")
|
||||
self.lf.flush ()
|
||||
|
||||
if self.currentprotocol == "iso":
|
||||
self.check_answer(self.cmd("82")) # close previous session
|
||||
|
||||
self.currentprotocol = "iso"
|
||||
self.currentsubprotocol = ecu['protocol']
|
||||
self.currentsubprotocol = ecu.get('protocol', '')
|
||||
self.currentaddress = addr
|
||||
self.startSession = ""
|
||||
self.lastCMDtime = 0
|
||||
@ -2123,13 +2123,13 @@ class ELM:
|
||||
self.check_answer (self.cmd ("at st ff")) # set timeout to 1 second
|
||||
self.check_answer (self.cmd ("at at 0")) # disable adaptive timing
|
||||
|
||||
if 'PRNA2000' in ecu['protocol'].upper () or mod_globals.opt_si:
|
||||
if 'PRNA2000' in ecu.get('protocol', '').upper () or mod_globals.opt_si:
|
||||
self.cmd ("at sp 4") # slow init mode 4
|
||||
if len (ecu['slowInit']) > 0:
|
||||
if len (ecu.get('slowInit', '')) > 0:
|
||||
self.cmd ("at iia " + ecu['slowInit']) # address for slow init
|
||||
rsp = self.lastinitrsp = self.cmd ("at si") # for slow init mode 4
|
||||
# rsp = self.cmd("81")
|
||||
if 'ERROR' in rsp and len (ecu['fastInit']) > 0:
|
||||
if 'ERROR' in rsp and len (ecu.get('fastInit', '')) > 0:
|
||||
ecu['protocol'] = ''
|
||||
if self.lf != 0:
|
||||
self.lf.write ('### Try fast init\n')
|
||||
|
@ -100,6 +100,7 @@ def pars_macro( file ):
|
||||
l = l.strip()
|
||||
if l == '': continue
|
||||
if '{' in l:
|
||||
print("line { :", l)
|
||||
if macroname=='':
|
||||
literals = l.split('{')
|
||||
macroname = literals[0].strip()
|
||||
@ -114,6 +115,7 @@ def pars_macro( file ):
|
||||
var = {}
|
||||
return
|
||||
if '}' in l:
|
||||
print("line } :", l)
|
||||
if macroname!='':
|
||||
literals = l.split('}')
|
||||
cmd = literals[0].strip()
|
||||
@ -224,6 +226,12 @@ def optParser():
|
||||
default=False,
|
||||
action="store_true")
|
||||
|
||||
parser.add_argument("--caf",
|
||||
help="turn on CAN Auto Formatting. Available only for OBDLink",
|
||||
dest="caf",
|
||||
default=False,
|
||||
action="store_true")
|
||||
|
||||
parser.add_argument("--n1c",
|
||||
help="turn off L1 cache",
|
||||
dest="n1c",
|
||||
@ -274,6 +282,7 @@ def optParser():
|
||||
mod_globals.opt_demo = options.demo
|
||||
mod_globals.opt_si = options.si
|
||||
mod_globals.opt_cfc0 = options.cfc
|
||||
mod_globals.opt_caf = options.caf
|
||||
mod_globals.opt_n1c = options.n1c
|
||||
mod_globals.opt_minordtc = options.minordtc
|
||||
auto_dia = options.dia
|
||||
@ -428,21 +437,21 @@ def play_macro(mname, elm):
|
||||
global var
|
||||
global stack
|
||||
|
||||
if mname in stack:
|
||||
print 'Error: recursion prohibited:', mname
|
||||
return
|
||||
else:
|
||||
stack.append(mname)
|
||||
def run_init_function(mname, elm):
|
||||
global var
|
||||
|
||||
for l in macro[mname]:
|
||||
|
||||
if l in macro.keys():
|
||||
play_macro(l, elm)
|
||||
continue
|
||||
|
||||
proc_line( l, elm )
|
||||
|
||||
stack.remove(mname)
|
||||
if mname in ["init_can_250", "init_can_500"]:
|
||||
elm.init_can()
|
||||
if mname == "init_can_250":
|
||||
elm.set_can_addr(var['$addr'], {'brp': '1'})
|
||||
else:
|
||||
elm.set_can_addr(var['$addr'], {})
|
||||
elif mname in ["init_iso_slow", "init_iso_fast"]:
|
||||
elm.init_iso()
|
||||
if mname == "init_iso_slow":
|
||||
elm.set_iso_addr(var['$addr'], {'protocol': 'PRNA2000'})
|
||||
else:
|
||||
elm.set_iso_addr(var['$addr'], {})
|
||||
|
||||
def term_cmd( c, elm ):
|
||||
global var
|
||||
@ -682,8 +691,8 @@ def proc_line( l, elm ):
|
||||
mod_utils.clearScreen()
|
||||
return
|
||||
|
||||
if l in macro.keys():
|
||||
play_macro(l, elm)
|
||||
if l.startswith("init"):
|
||||
run_init_function(l, elm)
|
||||
return
|
||||
|
||||
m = re.search('\$\S+\s*=\s*\S+', l)
|
||||
@ -713,7 +722,7 @@ def proc_line( l, elm ):
|
||||
l_parts = l.split()
|
||||
if len(l_parts) > 0 and l_parts[0] in ['wait', 'sleep']:
|
||||
try:
|
||||
wait_kb(int(l_parts[1]))
|
||||
wait_kb(float(l_parts[1]))
|
||||
return
|
||||
except:
|
||||
pass
|
||||
@ -726,7 +735,7 @@ def proc_line( l, elm ):
|
||||
pass
|
||||
|
||||
if len(l_parts) > 0 and l_parts[0] in ['delay']:
|
||||
cmd_delay = int(l_parts[1])
|
||||
cmd_delay = float(l_parts[1])
|
||||
return
|
||||
|
||||
if l.lower().startswith('set_bits'):
|
||||
@ -797,9 +806,6 @@ def main():
|
||||
load_macro()
|
||||
|
||||
optParser()
|
||||
|
||||
# disable auto flow control
|
||||
mod_globals.opt_cfc0 = True
|
||||
|
||||
print 'Opening ELM'
|
||||
elm = mod_elm.ELM( mod_globals.opt_port, mod_globals.opt_speed, True )
|
||||
@ -835,8 +841,8 @@ def main():
|
||||
f.close()
|
||||
|
||||
if auto_macro != '':
|
||||
if auto_macro in macro.keys():
|
||||
play_macro( auto_macro, elm )
|
||||
if auto_macro.startswith("init"):
|
||||
run_init_function(auto_macro, elm)
|
||||
else:
|
||||
print 'Error: unknown macro name:', auto_macro
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user