OBDLink communication fixes

- fix bug that can lead to falsely command end detection in send_can_cfc
- get all frames during first phase of a module performance level inspection
- include ST in refresh rate calculation
- add --caf flag to options
This commit is contained in:
Marianpol 2021-10-18 13:42:03 +02:00
parent a27516ac59
commit 6ceb830aa6
2 changed files with 29 additions and 16 deletions

View File

@ -1505,11 +1505,10 @@ class ELM:
cf = min({BS, frames_left}) # number of frames to send without response cf = min({BS, frames_left}) # number of frames to send without response
while cf > 0: while cf > 0:
burst_size_command = '' burst_size_command = ''.join(raw_command[Fc: Fc + cf])
for f in range(0, cf): burst_size_command_last_frame = burst_size_command[len(''.join(raw_command[Fc: Fc + cf - 1])):]
burst_size_command += raw_command[Fc + f]
if burst_size_command.endswith(raw_command[-1]): if burst_size_command_last_frame == raw_command[-1]:
if init_command in self.l1_cache.keys(): if init_command in self.l1_cache.keys():
burst_size_request = 'STPX D:' + burst_size_command + ",R:" + self.l1_cache[init_command] burst_size_request = 'STPX D:' + burst_size_command + ",R:" + self.l1_cache[init_command]
else: else:
@ -1519,6 +1518,7 @@ class ELM:
# Ensure time gap between frames according to FlowControl # Ensure time gap between frames according to FlowControl
tc = time.time() # current time tc = time.time() # current time
self.screenRefreshTime += ST /1000.
if (tc - tb) * 1000. < ST: if (tc - tb) * 1000. < ST:
target_time = time.clock() + (ST / 1000. - (tc - tb)) target_time = time.clock() + (ST / 1000. - (tc - tb))
while time.clock() < target_time: while time.clock() < target_time:
@ -1528,7 +1528,7 @@ class ELM:
frsp = self.send_raw(burst_size_request) frsp = self.send_raw(burst_size_request)
Fc = Fc + cf Fc = Fc + cf
cf = 0 cf = 0
if burst_size_command.endswith(raw_command[-1]): if burst_size_command_last_frame == raw_command[-1]:
for s in frsp.split('\n'): for s in frsp.split('\n'):
if s.strip()[:4] == "STPX": # echo cancelation if s.strip()[:4] == "STPX": # echo cancelation
continue continue
@ -2041,9 +2041,6 @@ class ELM:
self.check_answer (self.cmd ("at fc sm 1")) self.check_answer (self.cmd ("at fc sm 1"))
self.check_answer (self.cmd ("at st ff")) # reset adaptive timing step 1 self.check_answer (self.cmd ("at st ff")) # reset adaptive timing step 1
self.check_answer (self.cmd ("at at 0")) # reset adaptive timing step 2 self.check_answer (self.cmd ("at at 0")) # reset adaptive timing step 2
if mod_globals.opt_obdlink and mod_globals.opt_caf:
self.check_answer (self.cmd ("STCFCPA " + TXa + ", " + RXa))
# some models of cars may have different CAN buses # some models of cars may have different CAN buses
if 'brp' in ecu.keys () and '1' in ecu['brp'] and '0' in ecu['brp']: # double brp if 'brp' in ecu.keys () and '1' in ecu['brp'] and '0' in ecu['brp']: # double brp
@ -2066,6 +2063,9 @@ class ELM:
self.check_answer (self.cmd ("at at 1")) # reset adaptive timing step 3 self.check_answer (self.cmd ("at at 1")) # reset adaptive timing step 3
self.check_answer (self.cmd ("at cra " + RXa)) self.check_answer (self.cmd ("at cra " + RXa))
if mod_globals.opt_obdlink and mod_globals.opt_caf:
self.check_answer (self.cmd ("STCFCPA " + TXa + ", " + RXa))
self.check_adapter () self.check_adapter ()
def init_iso(self): def init_iso(self):
@ -2171,15 +2171,21 @@ class ELM:
for lvl in range(level): for lvl in range(level):
paramToSend += dataids.keys()[lvl] paramToSend += dataids.keys()[lvl]
if mod_globals.opt_caf: cmd = '22' + paramToSend
cmd = '22' + paramToSend + '1'
else:
cmd = frameLength + '22' + paramToSend + '1'
resp = self.send_raw(cmd) resp = self.cmd(cmd).replace(" ", "") #check response length first
for s in resp.split('\n'): if not all (c in string.hexdigits for c in resp):
if s.strip().startswith('037F'): return False
return False
if self.l1_cache.get(cmd, ""):
if mod_globals.opt_caf:
resp = self.send_raw(cmd + self.l1_cache.get(cmd)) # get all frames, not only first one
else: # prevents from triggering false error_frame error
resp = self.send_raw(frameLength + cmd + self.l1_cache.get(cmd))
for s in resp.split('\n'):
if s.strip().startswith("037F") or "?" in s:
return False
else: # send multiframe command for more than 3 dataids else: # send multiframe command for more than 3 dataids
# Some modules can return NO DATA if multi frame command is sent after some no activity time # Some modules can return NO DATA if multi frame command is sent after some no activity time
# Sending anything before main command usually helps that command to be accepted # Sending anything before main command usually helps that command to be accepted

View File

@ -127,6 +127,12 @@ def optParser():
default=False, default=False,
action="store_true") 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", parser.add_argument("--n1c",
help="turn off L1 cache", help="turn off L1 cache",
dest="n1c", dest="n1c",
@ -239,6 +245,7 @@ def optParser():
mod_globals.opt_verbose = options.verbose mod_globals.opt_verbose = options.verbose
mod_globals.opt_si = options.si mod_globals.opt_si = options.si
mod_globals.opt_cfc0 = options.cfc mod_globals.opt_cfc0 = options.cfc
mod_globals.opt_caf = options.caf
mod_globals.opt_n1c = options.n1c mod_globals.opt_n1c = options.n1c
mod_globals.opt_exp = options.exp mod_globals.opt_exp = options.exp
mod_globals.opt_dump = options.dump mod_globals.opt_dump = options.dump