Finish send_can_cfc and send_can_cfc_caf implementation
This commit is contained in:
parent
bd9c2db570
commit
beab6ceef6
@ -1213,20 +1213,21 @@ class ELM:
|
||||
return self.send_can_cfc0 (command)
|
||||
else:
|
||||
if mod_globals.opt_obdlink:
|
||||
rsp = self.send_can_cfc(command)
|
||||
# rsp = self.send_can_cfc_caf(command)
|
||||
if mod_globals.opt_caf:
|
||||
rsp = self.send_can_cfc_caf(command)
|
||||
else:
|
||||
rsp = self.send_can_cfc(command)
|
||||
else:
|
||||
rsp = self.send_can (command)
|
||||
# if self.error_frame > 0 or self.error_bufferfull > 0: # then fallback to cfc0
|
||||
# self.ATCFC0 = True
|
||||
# self.cmd ("at cfc0")
|
||||
# rsp = self.send_can_cfc0 (command)
|
||||
if self.error_frame > 0 or self.error_bufferfull > 0: # then fallback to cfc0
|
||||
self.ATCFC0 = True
|
||||
self.cmd ("at cfc0")
|
||||
rsp = self.send_can_cfc0 (command)
|
||||
return rsp
|
||||
|
||||
def send_can(self, command):
|
||||
command = command.strip ().replace (' ', '').upper ()
|
||||
isCommandInCache = command in self.l1_cache.keys()
|
||||
commandString = command
|
||||
|
||||
if len(command) == 0:
|
||||
return
|
||||
@ -1240,7 +1241,7 @@ class ELM:
|
||||
cmd_len = len (command) / 2
|
||||
if cmd_len < 8: # single frame
|
||||
# check L1 cache here
|
||||
if isCommandInCache and int('0x' + self.l1_cache[commandString], 16) < 16:
|
||||
if isCommandInCache and int('0x' + self.l1_cache[command], 16) < 16:
|
||||
raw_command.append (("%0.2X" % cmd_len) + command + self.l1_cache[command])
|
||||
else:
|
||||
raw_command.append (("%0.2X" % cmd_len) + command)
|
||||
@ -1254,17 +1255,7 @@ class ELM:
|
||||
raw_command.append ("2" + ("%X" % frame_number)[-1:] + command[:14])
|
||||
frame_number = frame_number + 1
|
||||
command = command[14:]
|
||||
|
||||
# add response frames number to each frame to increase polling
|
||||
if mod_globals.opt_obdlink and mod_globals.opt_perform:
|
||||
if commandString[:2] in AllowedList and isCommandInCache:
|
||||
for index in range(len(raw_command) - 1):
|
||||
raw_command[index] = raw_command[index] + '1'
|
||||
if int('0x' + self.l1_cache[commandString], 16) < 16:
|
||||
raw_command[-1] = raw_command[-1] + self.l1_cache[commandString]
|
||||
else:
|
||||
raw_command[-1] = "STPX D:" + raw_command[-1] + ",R:" + self.l1_cache[commandString]
|
||||
|
||||
|
||||
responses = []
|
||||
|
||||
# send farmes
|
||||
@ -1332,11 +1323,8 @@ class ELM:
|
||||
if result[:2] == '7F': noerrors = False
|
||||
|
||||
# populate L1 cache
|
||||
if noerrors and commandString[:2] in AllowedList and not mod_globals.opt_n1c:
|
||||
if nframes < 16:
|
||||
self.l1_cache[commandString] = str(hex(nframes))[2:].upper()
|
||||
else: #for OBDLink STPX command
|
||||
self.l1_cache[commandString] = str(nframes)
|
||||
if noerrors and command[:2] in AllowedList and not mod_globals.opt_n1c:
|
||||
self.l1_cache[command] = str(hex(nframes))[2:].upper()
|
||||
|
||||
if len (result) / 2 >= nbytes and noerrors:
|
||||
# split by bytes and return
|
||||
@ -1358,7 +1346,7 @@ class ELM:
|
||||
else:
|
||||
return "WRONG RESPONSE"
|
||||
|
||||
# Can be used only with OBDLink based ELM
|
||||
# Can be used only with OBDLink based ELM, wireless especially.
|
||||
def send_can_cfc_caf(self, command):
|
||||
if len(command) == 0:
|
||||
return
|
||||
@ -1367,7 +1355,7 @@ class ELM:
|
||||
if not all(c in string.hexdigits for c in command):
|
||||
return "HEX ERROR"
|
||||
|
||||
frsp = self.send_raw('STPX D:' + command + ',R:' + '1' + ', T:50')
|
||||
frsp = self.send_raw('STPX D:' + command + ',R:' + '1')
|
||||
|
||||
responses = []
|
||||
|
||||
@ -1958,15 +1946,19 @@ class ELM:
|
||||
self.check_answer(self.cmd("at h0"))
|
||||
self.check_answer(self.cmd("at l0"))
|
||||
self.check_answer(self.cmd("at al"))
|
||||
self.check_answer(self.cmd("at caf0"))
|
||||
# self.check_answer(self.cmd("at caf1"))
|
||||
|
||||
#This need to be enabled to use the send_can_cfc_caf function
|
||||
if mod_globals.opt_obdlink and mod_globals.opt_caf:
|
||||
self.check_answer(self.cmd("AT CAF1"))
|
||||
self.check_answer(self.cmd("STCSEGR 1"))
|
||||
self.check_answer(self.cmd("STCSEGT 1"))
|
||||
else:
|
||||
self.check_answer(self.cmd("at caf0"))
|
||||
|
||||
if self.ATCFC0:
|
||||
self.check_answer(self.cmd("at cfc0"))
|
||||
else:
|
||||
self.check_answer(self.cmd("at cfc1"))
|
||||
|
||||
# self.check_answer(self.cmd("STCSEGR 1"))
|
||||
# self.check_answer(self.cmd("STCSEGT 1"))
|
||||
|
||||
self.lastCMDtime = 0
|
||||
|
||||
@ -2045,7 +2037,10 @@ class ELM:
|
||||
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 at 0")) # reset adaptive timing step 2
|
||||
# self.check_answer (self.cmd ("STCFCPA " + TXa + ", " + RXa))
|
||||
|
||||
# This need to be enabled to use the send_can_cfc_caf function
|
||||
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
|
||||
if 'brp' in ecu.keys () and '1' in ecu['brp'] and '0' in ecu['brp']: # double brp
|
||||
@ -2172,7 +2167,12 @@ class ELM:
|
||||
frameLength = '{:02X}'.format(1 + level * 2)
|
||||
for lvl in range(level):
|
||||
paramToSend += dataids.keys()[lvl]
|
||||
cmd = frameLength + '22' + paramToSend + '1'
|
||||
|
||||
if mod_globals.opt_caf:
|
||||
cmd = '22' + paramToSend + '1'
|
||||
else:
|
||||
cmd = frameLength + '22' + paramToSend + '1'
|
||||
|
||||
resp = self.send_raw(cmd)
|
||||
for s in resp.split('\n'):
|
||||
if s.strip().startswith('037F'):
|
||||
@ -2180,7 +2180,7 @@ class ELM:
|
||||
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
|
||||
# Sending anything before main command usually helps that command to be accepted
|
||||
self.send_raw ("0322" + dataids.keys()[0] + "1")
|
||||
self.send_cmd ("22" + dataids.keys()[0] + "1")
|
||||
|
||||
for lvl in range(level):
|
||||
resp = self.request("22" + dataids.keys()[lvl])
|
||||
|
@ -23,6 +23,7 @@ opt_cmd = False
|
||||
opt_ddt = False
|
||||
opt_si = False #try slow init every time
|
||||
opt_cfc0 = False #turn off automatic FC and do it by script
|
||||
opt_caf = False #turn on CAN Automatic Formatting, need to be enabled when send_can_cfc_caf function is used
|
||||
opt_n1c = False #turn off L1 cache
|
||||
opt_dev = False #switch to development session for commands from DevList
|
||||
opt_devses = '1086' #development session for commands from DevList
|
||||
|
Loading…
x
Reference in New Issue
Block a user