-
Notifications
You must be signed in to change notification settings - Fork 0
/
id_finder.py
44 lines (36 loc) · 1.48 KB
/
id_finder.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
import matplotlib.pyplot as plt
import re
import sys
def parse_sym_file(sym_file_path):
used_ids = set()
# Regular expression for matching ID lines
id_pattern = re.compile(r'ID=(\w+)h', re.IGNORECASE)
with open(sym_file_path, 'r') as file:
for line in file:
id_match = id_pattern.search(line)
if id_match:
can_id = int(id_match.group(1), 16) # Convert hex to int
# Only add IDs within the 11-bit CAN ID range (0x000 to 0x7FF)
if 0x000 <= can_id <= 0x7FF:
used_ids.add(can_id)
return used_ids
def plot_can_id_space(used_ids):
# Define the full 11-bit CAN ID range (0x000 to 0x7FF)
all_ids = set(range(0x000, 0x800))
available_ids = all_ids - used_ids
plt.figure(figsize=(15, 6))
# Plotting available and used CAN IDs
plt.scatter(sorted(available_ids), [1] * len(available_ids), color='green', label='Available', s=10)
plt.scatter(sorted(used_ids), [1] * len(used_ids), color='red', label='Used', s=10)
plt.xlabel('CAN ID')
plt.ylabel('Availability')
plt.yticks([]) # No need for y-axis ticks
plt.title('CAN ID Space (0x000 to 0x7FF) Availability')
plt.grid(axis='x', linestyle='--', linewidth=0.5)
plt.legend()
plt.tight_layout()
plt.show()
if __name__ == "__main__":
sym_file_path = sys.argv[1] # Replace with your actual .sym file path
used_ids = parse_sym_file(sym_file_path)
plot_can_id_space(used_ids)