forked from bmorcelli/io433
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DumpGraphAnalizer.py
53 lines (48 loc) · 2.18 KB
/
DumpGraphAnalizer.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
import matplotlib.pyplot as plt
import serial
import time
# Function to plot the data using Matplotlib
def plot_data(data):
x_values = [point[0] for point in data]
y_values = [point[1] for point in data]
plt.plot(x_values, y_values, marker='o', linestyle='-')
plt.xlabel('X')
plt.ylabel('Y')
plt.title('Data From Dump on CC1101')
plt.grid(True)
plt.show()
# Function to read data from serial port and extract the relevant part
def read_serial_data():
while True:
try:
# change the COM PORT :)
ser = serial.Serial('COM10', 1000000, timeout=1)
print("Serial Port Checked")
time.sleep(5) # Wait for 5 seconds to receive all data
serial_data = ser.read_all().decode('utf-8').strip()
print("Raw Serial Data:", serial_data)
if "Dump transition times:" in serial_data:
start_index = serial_data.find("Dump transition times:") + len("Dump transition times:")
end_index = serial_data.find("Total time (us):")
data_str = serial_data[start_index:end_index].strip()
print("-------------------------------------------")
print("Extracted Data:", data_str)
data_values = [int(x) for x in data_str.split(',') if x]
# Create a list of tuples with corresponding x and y values
table_data = [(i*5+1, val) for i, val in enumerate(data_values)]
print("-------------------------------------------")
print("Table Data:", table_data)
ser.close() # Close the serial connection before returning the data
return table_data
else:
print("Error: Data format not recognized. Retrying...")
ser.close() # Close the serial connection before retrying
time.sleep(0.5) # Wait for 2 seconds before retrying
except serial.SerialException as e:
print("Serial port error:", e)
time.sleep(0.5) # Wait for 2 seconds before retrying
# Main loop
while True:
table_data = read_serial_data()
# Plot data using Matplotlib
plot_data(table_data)