From 4ec29342b35a67443b2cccb4649563f7cd9834bc Mon Sep 17 00:00:00 2001 From: shrlnm Date: Sun, 8 Dec 2019 12:44:43 +0300 Subject: [PATCH] 9q terminal V2 --- pyren/macro/qr25/idle_speed.cmd | 81 +++++++++++++ pyren/macro/terminal_7A.cmd | 7 ++ pyren/mod_ecu.py | 27 ++--- pyren/mod_elm.py | 20 +++- pyren/mod_term.py | 200 ++++++++++++++++++++++++++++---- 5 files changed, 297 insertions(+), 38 deletions(-) create mode 100644 pyren/macro/qr25/idle_speed.cmd create mode 100644 pyren/macro/terminal_7A.cmd diff --git a/pyren/macro/qr25/idle_speed.cmd b/pyren/macro/qr25/idle_speed.cmd new file mode 100644 index 0000000..c2831e9 --- /dev/null +++ b/pyren/macro/qr25/idle_speed.cmd @@ -0,0 +1,81 @@ + +# QR25 Idle speed correction +$addr = 7A + +can500 # init can macro + +# check ECU + +exit_if_not 83 26 8 FF 44 +exit_if_not 83 26 17 FF 43 + +:checkeng +goto_if 1201 5 4 FFFF 0000 runeng + +goto engisrun + +:runeng + +cls +# +# Run ENGINE +# + +if_key q end +wait 1 +goto checkeng + +:engisrun +cls +var lastResponse = $lastResponse +# +# Idle Speed +# +value 1201 5 4 FFFF 25 0 2 +# +# ECU is running +# +# Select correction +# +# Press: +# 0 reset +# 1 +25 +# 2 +50 +# 3 +75 +# 4 +100 +# +# q for Exit +# + +if_key 0 key0 +if_key 1 key1 +if_key 2 key2 +if_key 3 key3 +if_key 4 key4 +if_key q end +wait 1 +goto engisrun + +:key0 +3B0200 +goto engisrun + +:key1 +3B0202 +goto engisrun + +:key2 +3B0204 +goto engisrun + +:key3 +3B0206 +goto engisrun + +:key4 +3B0208 +goto engisrun + +:end + +exit diff --git a/pyren/macro/terminal_7A.cmd b/pyren/macro/terminal_7A.cmd new file mode 100644 index 0000000..2d3f77a --- /dev/null +++ b/pyren/macro/terminal_7A.cmd @@ -0,0 +1,7 @@ + +# terminal +$addr = 7A + +can500 # init can macro + +session 10C0 diff --git a/pyren/mod_ecu.py b/pyren/mod_ecu.py index c410400..7bd36b6 100755 --- a/pyren/mod_ecu.py +++ b/pyren/mod_ecu.py @@ -196,19 +196,20 @@ class ECU: flist.sort() dumpname = os.path.join("./dumps/", flist[-1]) - print 'Loading dump:', dumpname - - df = open(dumpname,'rt') - lines = df.readlines() - df.close() - - for l in lines: - l = l.strip().replace('\n','') - if l.count(':')==1: - req,rsp = l.split(':') - ecudump[req] = rsp - - self.elm.setDump( ecudump ) + #print 'Loading dump:', dumpname + + self.elm.loadDump(dumpname) + #df = open(dumpname,'rt') + #lines = df.readlines() + #df.close() + # + #for l in lines: + # l = l.strip().replace('\n','') + # if l.count(':')==1: + # req,rsp = l.split(':') + # ecudump[req] = rsp + # + #self.elm.setDump( ecudump ) def get_st( self, name ): if name not in self.States.keys(): diff --git a/pyren/mod_elm.py b/pyren/mod_elm.py index 78b5abf..0429373 100755 --- a/pyren/mod_elm.py +++ b/pyren/mod_elm.py @@ -618,7 +618,25 @@ class ELM: def setDump(self, ecudump): """ define ecudum for demo mode""" self.ecudump = ecudump - + + def loadDump(self, dumpname): + + print 'Loading dump:', dumpname + + df = open(dumpname, 'rt') + lines = df.readlines() + df.close() + + ecudump = {} + + for l in lines: + l = l.strip().replace('\n', '') + if l.count(':') == 1: + req, rsp = l.split(':') + ecudump[req] = rsp + + self.setDump(ecudump) + def debugMonitor(self): byte = "" try: diff --git a/pyren/mod_term.py b/pyren/mod_term.py index 7c79352..ea4d9e8 100755 --- a/pyren/mod_term.py +++ b/pyren/mod_term.py @@ -21,6 +21,9 @@ stack = [] auto_macro = "" auto_dia = False +debug_mode = False + +key_pressed = '' mod_globals.os = os.name @@ -175,6 +178,7 @@ def optParser(): global auto_macro global auto_dia + global debug_mode parser = argparse.ArgumentParser( #usage = "%prog -p [options]", @@ -238,6 +242,13 @@ def optParser(): default=False, action="store_true") + parser.add_argument("--debug", + help="for debug purpose only", + dest="dbg", + default=False, + action="store_true") + + options = parser.parse_args() if not options.port and mod_globals.os != 'android': @@ -260,6 +271,7 @@ def optParser(): mod_globals.opt_cfc0 = options.cfc mod_globals.opt_n1c = options.n1c auto_dia = options.dia + debug_mode = options.dbg class FileChooser(): lay = ''' @@ -426,9 +438,17 @@ def play_macro(mname, elm): stack.remove(mname) +def term_cmd( c, elm ): + global var + rsp = elm.request(c, cache=False) + #rsp = elm.cmd(rcmd) + var['$lastResponse'] = rsp + return rsp + def bit_cmd( l, elm, fnc='set_bits' ): - error_msg = '''ERROR: command should have 5 parameters: " + error_msg1 = '''ERROR: command should have 5 parameters: + - ECUs local identifier. Length should be 2 simbols for KWP or 4 for CAN - lengt of command response including positive response bytes, equals MinBytes from ddt db - offeset in bytes to first changed byte (starts from 1 not 0) @@ -437,16 +457,55 @@ def bit_cmd( l, elm, fnc='set_bits' ): and should have equal length ''' + error_msg2 = '''ERROR: command should have 6 parameters: +