-
Notifications
You must be signed in to change notification settings - Fork 29
/
01_dump.py
executable file
·54 lines (41 loc) · 1.77 KB
/
01_dump.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
import tqdm
from argparse import ArgumentParser
from panda import Panda
from tp20 import TP20Transport
from kwp2000 import KWP2000Client, ECU_IDENTIFICATION_TYPE
try:
from panda.ccp import CcpClient, BYTE_ORDER
except ImportError:
from panda.python.ccp import CcpClient, BYTE_ORDER
CHUNK_SIZE = 4
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("--bus", default=0, type=int, help="CAN bus number to use")
parser.add_argument("--start-address", default=0, type=int, help="start address")
parser.add_argument("--end-address", default=0x5FFFF, type=int, help="end address (inclusive)")
parser.add_argument("--output", required=True, help="output file")
args = parser.parse_args()
p = Panda()
p.can_clear(0xFFFF)
p.set_safety_mode(Panda.SAFETY_ALLOUTPUT)
print("Connecting using KWP2000...")
tp20 = TP20Transport(p, 0x9, bus=args.bus)
kwp_client = KWP2000Client(tp20)
print("Reading ecu identification & flash status")
ident = kwp_client.read_ecu_identifcation(ECU_IDENTIFICATION_TYPE.ECU_IDENT)
print("ECU identification", ident)
status = kwp_client.read_ecu_identifcation(ECU_IDENTIFICATION_TYPE.STATUS_FLASH)
print("Flash status", status)
print("\nConnecting using CCP...")
client = CcpClient(p, 1746, 1747, byte_order=BYTE_ORDER.LITTLE_ENDIAN, bus=args.bus)
client.connect(0x0)
progress = tqdm.tqdm(total=args.end_address - args.start_address)
addr = args.start_address
client.set_memory_transfer_address(0, 0, addr)
with open(args.output, "wb") as f:
while addr < args.end_address:
f.write(client.upload(CHUNK_SIZE)[:CHUNK_SIZE])
f.flush()
addr += CHUNK_SIZE
progress.update(CHUNK_SIZE)