From fdbe0eae1676da8934618e61e2f8864ad902ab90 Mon Sep 17 00:00:00 2001 From: Marianpol Date: Sat, 5 Feb 2022 00:01:58 +0100 Subject: [PATCH] [mod_term] Use ELM init commands from ELM class --- pyren/macro/init.txt | 85 ------------------- pyren/macro/megane2_scenic2/drl_off.cmd | 2 +- pyren/macro/megane2_scenic2/wipers_manual.cmd | 2 +- .../radiosat_classic_bluetooth_accoustic.cmd | 2 +- pyren/macro/qr25/idle_speed.cmd | 2 +- pyren/macro/rlink2/rlink2-HIGH1-screen.cmd | 2 +- pyren/macro/rlink2/rlink2-HIGH2-screen.cmd | 2 +- pyren/macro/rlink2/rlink2-MID1-screen.cmd | 2 +- pyren/macro/rlink2/rlink2-MID2-screen.cmd | 2 +- pyren/macro/rlink2/rlink2-enable-AAandCP.cmd | 2 +- pyren/macro/rlink2/rlink2-rotate-screen.cmd | 2 +- .../macro/rlink2/rlink2_acoustic_3_and_7.cmd | 2 +- pyren/macro/rlink2/rlink2_acoustic_8.cmd | 2 +- pyren/macro/terminal_7A.cmd | 2 +- pyren/mod_elm.py | 20 ++--- pyren/mod_term.py | 52 +++++++----- 16 files changed, 52 insertions(+), 131 deletions(-) delete mode 100644 pyren/macro/init.txt diff --git a/pyren/macro/init.txt b/pyren/macro/init.txt deleted file mode 100644 index 5d7684c..0000000 --- a/pyren/macro/init.txt +++ /dev/null @@ -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 -} diff --git a/pyren/macro/megane2_scenic2/drl_off.cmd b/pyren/macro/megane2_scenic2/drl_off.cmd index 03b86ff..1e169e7 100644 --- a/pyren/macro/megane2_scenic2/drl_off.cmd +++ b/pyren/macro/megane2_scenic2/drl_off.cmd @@ -1,7 +1,7 @@ # Day running light off $addr = 26 -can500 # init can macro +init_can_500 # init can macro 10C0 3BA01800 diff --git a/pyren/macro/megane2_scenic2/wipers_manual.cmd b/pyren/macro/megane2_scenic2/wipers_manual.cmd index 06eab01..aa5425c 100644 --- a/pyren/macro/megane2_scenic2/wipers_manual.cmd +++ b/pyren/macro/megane2_scenic2/wipers_manual.cmd @@ -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 diff --git a/pyren/macro/megane3_fluence/radiosat_classic_bluetooth_accoustic.cmd b/pyren/macro/megane3_fluence/radiosat_classic_bluetooth_accoustic.cmd index d38be1d..0c86a9e 100644 --- a/pyren/macro/megane3_fluence/radiosat_classic_bluetooth_accoustic.cmd +++ b/pyren/macro/megane3_fluence/radiosat_classic_bluetooth_accoustic.cmd @@ -1,7 +1,7 @@ #Accoustics for R2_08_v3_81 $addr = 13 -can500 # init can macro +init_can_500 # init can macro delay 2 diff --git a/pyren/macro/qr25/idle_speed.cmd b/pyren/macro/qr25/idle_speed.cmd index c2831e9..ecaa073 100644 --- a/pyren/macro/qr25/idle_speed.cmd +++ b/pyren/macro/qr25/idle_speed.cmd @@ -2,7 +2,7 @@ # QR25 Idle speed correction $addr = 7A -can500 # init can macro +init_can_500 # init can macro # check ECU diff --git a/pyren/macro/rlink2/rlink2-HIGH1-screen.cmd b/pyren/macro/rlink2/rlink2-HIGH1-screen.cmd index e3cf2a4..5c26cce 100644 --- a/pyren/macro/rlink2/rlink2-HIGH1-screen.cmd +++ b/pyren/macro/rlink2/rlink2-HIGH1-screen.cmd @@ -1,7 +1,7 @@ # Repair script for rlink2 black screen $addr = 13 -can500 # init can macro +init_can_500 # init can macro 1003 diff --git a/pyren/macro/rlink2/rlink2-HIGH2-screen.cmd b/pyren/macro/rlink2/rlink2-HIGH2-screen.cmd index 238b59f..0c2171e 100644 --- a/pyren/macro/rlink2/rlink2-HIGH2-screen.cmd +++ b/pyren/macro/rlink2/rlink2-HIGH2-screen.cmd @@ -1,7 +1,7 @@ # Repair script for rlink2 black screen $addr = 13 -can500 # init can macro +init_can_500 # init can macro 1003 diff --git a/pyren/macro/rlink2/rlink2-MID1-screen.cmd b/pyren/macro/rlink2/rlink2-MID1-screen.cmd index 228ed39..e7f6ecf 100644 --- a/pyren/macro/rlink2/rlink2-MID1-screen.cmd +++ b/pyren/macro/rlink2/rlink2-MID1-screen.cmd @@ -1,7 +1,7 @@ # Repair script for rlink2 black screen $addr = 13 -can500 # init can macro +init_can_500 # init can macro 1003 diff --git a/pyren/macro/rlink2/rlink2-MID2-screen.cmd b/pyren/macro/rlink2/rlink2-MID2-screen.cmd index 690e531..004952d 100644 --- a/pyren/macro/rlink2/rlink2-MID2-screen.cmd +++ b/pyren/macro/rlink2/rlink2-MID2-screen.cmd @@ -1,7 +1,7 @@ # Repair script for rlink2 black screen $addr = 13 -can500 # init can macro +init_can_500 # init can macro 1003 diff --git a/pyren/macro/rlink2/rlink2-enable-AAandCP.cmd b/pyren/macro/rlink2/rlink2-enable-AAandCP.cmd index 298d777..69f7bd0 100644 --- a/pyren/macro/rlink2/rlink2-enable-AAandCP.cmd +++ b/pyren/macro/rlink2/rlink2-enable-AAandCP.cmd @@ -1,7 +1,7 @@ # Enable AndroidAuto and CarPlay on R-Link2 $addr = 13 -can500 # init can macro +init_can_500 # init can macro 1003 diff --git a/pyren/macro/rlink2/rlink2-rotate-screen.cmd b/pyren/macro/rlink2/rlink2-rotate-screen.cmd index c783c6a..64489b6 100644 --- a/pyren/macro/rlink2/rlink2-rotate-screen.cmd +++ b/pyren/macro/rlink2/rlink2-rotate-screen.cmd @@ -1,7 +1,7 @@ # Rotate R-Link2 screen $addr = 13 -can500 # init can macro +init_can_500 # init can macro 1003 diff --git a/pyren/macro/rlink2/rlink2_acoustic_3_and_7.cmd b/pyren/macro/rlink2/rlink2_acoustic_3_and_7.cmd index 9872b14..bd49e64 100644 --- a/pyren/macro/rlink2/rlink2_acoustic_3_and_7.cmd +++ b/pyren/macro/rlink2/rlink2_acoustic_3_and_7.cmd @@ -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 diff --git a/pyren/macro/rlink2/rlink2_acoustic_8.cmd b/pyren/macro/rlink2/rlink2_acoustic_8.cmd index 3c4cd85..734d0a9 100644 --- a/pyren/macro/rlink2/rlink2_acoustic_8.cmd +++ b/pyren/macro/rlink2/rlink2_acoustic_8.cmd @@ -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 diff --git a/pyren/macro/terminal_7A.cmd b/pyren/macro/terminal_7A.cmd index 2d3f77a..a00a380 100644 --- a/pyren/macro/terminal_7A.cmd +++ b/pyren/macro/terminal_7A.cmd @@ -2,6 +2,6 @@ # terminal $addr = 7A -can500 # init can macro +init_can_500 # init can macro session 10C0 diff --git a/pyren/mod_elm.py b/pyren/mod_elm.py index bcba2d0..081f19b 100644 --- a/pyren/mod_elm.py +++ b/pyren/mod_elm.py @@ -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') diff --git a/pyren/mod_term.py b/pyren/mod_term.py index bf8c098..8e13cef 100755 --- a/pyren/mod_term.py +++ b/pyren/mod_term.py @@ -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