-
Notifications
You must be signed in to change notification settings - Fork 185
/
receiver.py
88 lines (67 loc) · 1.89 KB
/
receiver.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
'''
RECEIVER
sophia.re
07/06/15
'''
from time import time,sleep
import os
import sys, subprocess
import msvcrt as m
import matplotlib
import matplotlib.pyplot as plt
def main():
while True:
start_time = time()
end_time = time() + 12
print "Receiving Bits in Words (8 bit blocks)....\n"
# records out of order executions and writes averages to file
p = subprocess.Popen("C:/Receiver.exe "+"1 "*8)
while start_time < end_time:
start_time = time()
print time()
# wait because of system latency
p = subprocess.Popen("C:/nop.exe")
p = subprocess.Popen("C:/nop.exe")
# read all recorded out of order executions from file
f = open("C:/Python27/BackupCheck.txt")
txt = f.readlines()
f.close()
txt = txt[0]
print "Received Bits\n"
print txt
# trigger a picture to appear
bits = txt.split(":")
if "11" in bits[0]:
print "\n [+] trigger detected "
exe = "C:/Users/root/Downloads/JPEGView_1_0_29/JPEGView.exe"
args = '"C:/pics"'
p = subprocess.call([exe,args])
sys.exit(0)
quit()
else:
print "\n [+] trigger not detected"
# plot received out of order executions to view step signal
print "\n\nEnter to Plot...."
p.kill()
m.getch()
# plot recorded OoOE step signal to png file
with open("BackupCheck2.txt") as f:
data = f.read()
data = data.split("\n")
y = [float(x) for x in data[0].split(' ')[:-1]]
x = list(xrange(len(y)))
print "There are ", len(y), " elements to plot."
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.set_title("Plot Received OoOE")
ax1.set_xlabel("iterations")
ax1.set_ylabel("out-of-order-execution averages")
ax1.fill_between(x,y,color='yellow')
ax1.plot(x,y, marker='.',lw=1,label='the data', alpha=0.3)
leg = ax1.legend()
plt.savefig('plot.png', bbox_inches='tight')
# repeat
print "\n\nEnter to Continue...."
m.getch()
if __name__ == "__main__":
main()