Skip to content

Commit

Permalink
SBOOT checksum support, fancy progress bars, less logging
Browse files Browse the repository at this point in the history
  • Loading branch information
bri3d committed Nov 24, 2020
1 parent f5265c7 commit 0c7a7e9
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 12 deletions.
2 changes: 2 additions & 0 deletions checksumsimos18.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import struct

checksum_block_location = {
0: 0x300, # SBOOT
1: 0x300, # CBOOT
2: 0x300, # ASW1
3: 0x0, # ASW2
Expand All @@ -12,6 +13,7 @@
}

base_addresses = {
0: 0x80000000, # SBOOT
1: 0x8001C000, # CBOOT
2: 0x80040000, # ASW1
3: 0x80140000, # ASW2
Expand Down
21 changes: 9 additions & 12 deletions flashsimos18.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import argparse
import isotp
import time
import udsoncan
from os import path
from tqdm import tqdm
from udsoncan.connections import IsoTPSocketConnection
from udsoncan.client import Client
from udsoncan import configs
Expand Down Expand Up @@ -146,7 +147,7 @@ def block_transfer_sizes_patch(block_number, address):
return 0x100
return 0x8

udsoncan.setup_logging()
udsoncan.setup_logging(path.join(path.dirname(path.abspath(__file__)), 'logging.conf'))

params = {
'tx_padding': 0x55
Expand Down Expand Up @@ -248,8 +249,7 @@ def flash_block(client, block_files, block_number):
print("Transferring data... " + str(len(data)) + " bytes to write")
# Transfer Data
counter = 1
for block_base_address in range(0, len(data), block_transfer_sizes[block_number]):
print("Transferring " + str(block_base_address) + " of " + str(len(data)) + " bytes")
for block_base_address in tqdm(range(0, len(data), block_transfer_sizes[block_number]), unit_scale=True, unit="B"):
block_end = min(len(data), block_base_address+block_transfer_sizes[block_number])
client.transfer_data(counter, data[block_base_address:block_end])
counter = next_counter(counter)
Expand Down Expand Up @@ -295,9 +295,9 @@ def patch_block(client, block_files, block_number):
# Transfer Data
counter = 1
transfer_address = 0
progress = tqdm(total=len(data), unit="B", unit_scale=True)
while(transfer_address < len(data)):
transfer_size = block_transfer_sizes_patch(block_number, transfer_address)
print("Transferring PATCH:" + str(transfer_address) + " of " + str(len(data)) + " bytes using size " + str(transfer_size))
block_end = min(len(data), transfer_address+transfer_size)
transfer_data = data[transfer_address:block_end]

Expand All @@ -307,19 +307,19 @@ def patch_block(client, block_files, block_number):
try:
client.transfer_data(counter, transfer_data)
success = True
progress.update(block_end)
counter = next_counter(counter)
except exceptions.NegativeResponseException as e:
print('PATCH refused block (EXPECTED): %s with code "%s" (0x%02x)' % (e.response.service.get_name(), e.response.code_name, e.response.code))
except exceptions.NegativeResponseException:
success = False
counter = next_counter(counter)

transfer_address += transfer_size

progress.close()
print("Exiting PATCH transfer...")
# Exit Transfer
client.request_transfer_exit()

for block in block_files:
for block in tqdm(block_files, unit="Block"):
if block <= 5:
flash_block(client, block_files, block)
if block > 5:
Expand All @@ -341,10 +341,7 @@ def patch_block(client, block_files, block_number):
print("Sending 0x4 Clear Emissions DTCs over OBD-2")
send_obd(bytes([0x4]))

print("Clearing DTC...")
client.change_session(services.DiagnosticSessionControl.Session.extendedDiagnosticSession)
client.tester_present()
client.control_dtc_setting(udsoncan.services.ControlDTCSetting.SettingType.off, data=bytes([0xFF, 0xFF, 0xFF]))

print("Done!")
except exceptions.NegativeResponseException as e:
Expand Down
47 changes: 47 additions & 0 deletions logging.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[loggers]
keys=root,UdsClient,Connection,UdsClient_unittest,Connection_unittest

[handlers]
keys=consoleHandler,fileHandler,nullHandler

[formatters]
keys=simpleFormatter



[logger_root]
level=ERROR
handlers=consoleHandler

[logger_UdsClient]
level=INFO
handlers=fileHandler
qualname=UdsClient
propagate=0

[logger_Connection]
level=DEBUG
handlers=fileHandler
qualname=Connection
propagate=0

[handler_consoleHandler]
class=StreamHandler
formatter=simpleFormatter
args=(sys.stdout,)

[handler_fileHandler]
class=FileHandler
formatter=simpleFormatter
args=('udsoncan.log',)

[handler_nullHandler]
class=NullHandler
formatter=simpleFormatter
args=()



[formatter_simpleFormatter]
format=%(asctime)s [%(levelname)s] %(name)s: %(message)s
datefmt=%Y-%m-%d %H:%M:%S
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
udsoncan
can-isotp
sa2-seed-key
tqdm

0 comments on commit 0c7a7e9

Please sign in to comment.