From 838520e001dfa2481438dfcb7a2d1465d35de3fb Mon Sep 17 00:00:00 2001 From: Marianpol Date: Thu, 13 May 2021 23:13:52 +0200 Subject: [PATCH] Find dataId that is defined in the module file When one or more undefined dataids in the snapshot response, try to find next dataId that is defined in the module file. When mnemonic request uses 21 service, do not use get_SnapShotMnemonic function. Disable perfomance mode, it needs to be integrated with the send_can_cfc method. --- pyren/mod_ecu.py | 3 +-- pyren/mod_ecu_mnemonic.py | 27 +++++++++++++++++++-------- pyren/mod_ecu_parameter.py | 2 +- pyren/mod_ecu_state.py | 2 +- pyren/pyren.py | 7 +++++++ 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/pyren/mod_ecu.py b/pyren/mod_ecu.py index 133625a..fdced12 100755 --- a/pyren/mod_ecu.py +++ b/pyren/mod_ecu.py @@ -152,8 +152,7 @@ class ECU: self.elm.start_session( self.ecudata['startDiagReq'] ) if mod_globals.os == 'android' or mod_globals.opt_csv: - if self.ecudata['pin'].lower()=='can' and self.DataIds: - mod_globals.opt_perform = True + if self.ecudata['pin'].lower()=='can' and self.DataIds and mod_globals.opt_perform: self.elm.checkModulePerformaceLevel(self.DataIds) print "Done" diff --git a/pyren/mod_ecu_mnemonic.py b/pyren/mod_ecu_mnemonic.py index 9e12803..7757644 100755 --- a/pyren/mod_ecu_mnemonic.py +++ b/pyren/mod_ecu_mnemonic.py @@ -64,7 +64,7 @@ def get_mnemonic( m, se, elm, raw = False ): def get_SnapShotMnemonic(m, se, elm, dataids): snapshotService = "" - byteLength = 3 + byteLength = 3 #number of chars in one byte string (two chars with one whitespace) dataIdByteLength = 2 for sid in se: @@ -81,24 +81,35 @@ def get_SnapShotMnemonic(m, se, elm, dataids): numberOfIdentifiers = int("0x" + resp[7*byteLength:8*byteLength-1],16) resp = resp[8*byteLength:] - didDict = {} + didDict = {} #dataIds with their corresponding data + numberOfPossibleDataId = 0 #number of unknown dataIds posInResp = 0 - dataIdLength = dataIdByteLength * byteLength + dataIdLength = dataIdByteLength * byteLength - for x in range(numberOfIdentifiers): + for idNum in range(numberOfIdentifiers): + #break if unknown dataids number plus current number dataid number is larger than overall number of dataids in the response + if (idNum + numberOfPossibleDataId > numberOfIdentifiers): + break + dataId = resp[posInResp:posInResp + dataIdLength].replace(" ", "") posInResp += dataIdLength - if dataId not in dataids.keys(): + + if dataId not in dataids.keys(): #unknown dataId in the snapShot response bytePos = 1 restOfResp = resp[posInResp:] - while True: + while True: #try to find a next dataId that is defined in the module file posInRestResp = bytePos*byteLength + + #using '2' as possible start of dataId is not the best approach, to fix in the future if len(restOfResp) > posInRestResp + dataIdLength and restOfResp[posInRestResp] == '2': + numberOfPossibleDataId = numberOfPossibleDataId + 1 possibleDataId = restOfResp[posInRestResp:posInRestResp + dataIdLength].replace(" ", "") if possibleDataId in dataids.keys(): posInResp += posInRestResp break + else: + bytePos += 1 else: bytePos += 1 continue @@ -108,8 +119,8 @@ def get_SnapShotMnemonic(m, se, elm, dataids): posInResp += didDataLength*byteLength didDict[dataId] = didData - startByte = "" - startBit = "" + startByte = "1" + startBit = "0" dataId = "" for did in dataids.keys(): for mn in dataids[did].mnemolocations.keys(): diff --git a/pyren/mod_ecu_parameter.py b/pyren/mod_ecu_parameter.py index 1aadba8..618b717 100755 --- a/pyren/mod_ecu_parameter.py +++ b/pyren/mod_ecu_parameter.py @@ -15,7 +15,7 @@ def get_parameter( pr, mn, se, elm, calc, dataids = {} ): for m in sorted(pr.mnemolist, key=len, reverse=True): - if dataids: + if dataids and mn[m].request.startswith("22"): val = get_SnapShotMnemonic(mn[m], se, elm, dataids ) else: val = get_mnemonic( mn[m], se, elm ) diff --git a/pyren/mod_ecu_state.py b/pyren/mod_ecu_state.py index 53e1e0d..e86bd1f 100755 --- a/pyren/mod_ecu_state.py +++ b/pyren/mod_ecu_state.py @@ -11,7 +11,7 @@ def get_state( st, mn, se, elm, calc, dataids = {} ): comp = st.computation comp = comp.replace("&","&") for m in sorted(st.mnemolist, key=len, reverse=True): - if dataids: + if dataids and mn[m].request.startswith("22"): hex_val = get_SnapShotMnemonic(mn[m], se, elm, dataids ) else: hex_val = get_mnemonic( mn[m], se, elm ) diff --git a/pyren/pyren.py b/pyren/pyren.py index 6bb7b5c..63592a2 100755 --- a/pyren/pyren.py +++ b/pyren/pyren.py @@ -196,6 +196,12 @@ def optParser(): default=False, action="store_true") + parser.add_argument("--perform", + help="use UDS performance mode, not fully developed yet", + dest="perform", + default=False, + action="store_true") + options = parser.parse_args() if not options.port and mod_globals.os != 'android': @@ -231,6 +237,7 @@ def optParser(): mod_globals.opt_exp = options.exp mod_globals.opt_dump = options.dump mod_globals.opt_can2 = options.can2 + mod_globals.opt_perform = options.perform mod_globals.opt_sd = options.sd if options.dev=='' or len(options.dev)!=4 or options.dev[0:2]!='10': mod_globals.opt_dev = False