forked from skypeachblue/maxxfan-reversing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
58 lines (50 loc) · 1.38 KB
/
plot.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
55
56
57
58
#!/usr/bin/env python3
import matplotlib.pyplot as plt
import numpy as np
import argparse
np.set_printoptions(threshold=np.inf)
np.set_printoptions(precision=0)
np.set_printoptions(linewidth=200)
parser=argparse.ArgumentParser()
parser.add_argument("file",
help="Name of the Flipper IR file")
parser.add_argument("num",
type=int,
help="Number of signals to plot")
args = parser.parse_args()
LEN_SIGNAL = 180
TICK_US = 800
signals = np.zeros((args.num, LEN_SIGNAL), dtype=np.uint8)
i = 0
# read data from flipper file
with open(args.file, 'r') as file:
for line in file:
if not line.startswith("data"):
continue
line = line[6:]
arr = line.split(' ')
j = 0
one_or_zero = True
sum = 0
for item in arr:
sum += int(item)
# convert lengths to binary
ticks = round(int(item) / TICK_US)
for _ in range(ticks):
if (one_or_zero):
signals[i, j] = 1
else:
signals[i, j] = 0
j += 1
one_or_zero = not one_or_zero
#print(round(sum / TICK_US))
#print('')
i += 1
if (i >= args.num):
break
#print(signals)
# plot signals
for i in range(args.num):
plt.plot(signals[i])
plt.show()
plt.close()