forked from commaai/panda
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspam_can.py
More file actions
executable file
·60 lines (51 loc) · 1.68 KB
/
spam_can.py
File metadata and controls
executable file
·60 lines (51 loc) · 1.68 KB
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
55
56
57
58
59
60
#!/usr/bin/env python3
import os
import time
import usb1
import random
import argparse
from opendbc.car.structs import CarParams
from panda import Panda
MAX_BUS_ERROR_CNT = 10
def get_test_string():
return b"test" + os.urandom(10)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Read VIN from a vehicle using UDS over CAN.")
parser.add_argument('-b', '--bus', type=int, action='append',
help='CAN bus number to spam (can be specified multiple times, e.g., -b 0 -b 1 -b 2)')
parser.add_argument('-p', '--packets', type=int, default=None,
help='Number of packets to send (default: infinite)')
args = parser.parse_args()
buses = [args.bus] if args.bus is not None else [0, 1, 2]
packets = args.packets
p = Panda()
p.set_safety_mode(CarParams.SafetyModel.allOutput)
print(f"Spamming buses: {buses}")
bus0_count = 0
bus1_count = 0
bus2_count = 0
count = 0
while packets is None or count < packets:
at = random.randint(1, 2000)
st = get_test_string()[0:8]
# Choose random from buses
bus = random.choice(buses)
try:
p.can_send(at, st, bus)
if bus == 0:
bus0_count += 1
elif bus == 1:
bus1_count += 1
elif bus == 2:
bus2_count += 1
count += 1
except usb1.USBErrorTimeout:
pass
except KeyboardInterrupt:
break
print(f"Message Counts... Bus 0: {bus0_count} Bus 1: {bus1_count} Bus 2: {bus2_count} | Total: {count}", end='\r')
print("Clearing CAN buffers...")
time.sleep(1)
for bus in range(3):
p.can_clear(bus)
print(f"Message Counts... Bus 0: {bus0_count} Bus 1: {bus1_count} Bus 2: {bus2_count} | Total: {count}")