-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.py
130 lines (101 loc) · 3.94 KB
/
App.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#Punkt wejścia do programu
from Statistics import Statistics
from SenderSAW import SenderSAW
from RecieverSAW import RecieverSAW
from SenderGBN import SenderGBN
from RecieverGBN import RecieverGBN
from SenderSR import SenderSR
from RecieverSR import RecieverSR
from CommunicationSettings import CheckSum, CommunicationSettings, NoiseType
#Halts the main thread until the simulation is finished
def wait_for_simulation_end() -> None:
while(CommunicationSettings.get_simulation_state() == False):
continue
def stop_and_wait_test(file_name: str, repetitions: int) -> None:
for i in range(repetitions):
#Print proggress
print(f"Run {i + 1}/{repetitions}")
stats = Statistics()
#Setup test specific statistics
CommunicationSettings.check_sum = CheckSum.CRC
#Create sender and reciever
sender = SenderSAW("Sender", stats)
reciever = RecieverSAW("Reciever", stats)
#Setup resoult image name
reciever.set_recreated_image_name(f"Img/res_saw{i + 1}.png")
#Bind them
sender.bind(reciever)
reciever.bind(sender)
#Start them
sender.start()
reciever.start()
#Start transmition
sender.send_image(file_name)
wait_for_simulation_end()
print(stats.get_statistics())
CommunicationSettings.reset_sumulation_state()
def go_back_n_test(file_name: str, repetitions: int) -> None:
for i in range(repetitions):
#Print proggress
print(f"Run {i + 1}/{repetitions}")
stats = Statistics()
#Setup test specific statistics
CommunicationSettings.check_sum = CheckSum.CRC
CommunicationSettings.window_size = 4
#Create sender and reciever
sender = SenderGBN("Sender", stats)
reciever = RecieverGBN("Reciever", stats)
#Setup resoult image name
reciever.set_recreated_image_name(f"Img/res_gbn{i + 1}.png")
#Bind them
sender.bind(reciever)
reciever.bind(sender)
#Start them
sender.start()
reciever.start()
#Start transmition
sender.send_image(file_name)
wait_for_simulation_end()
print(stats.get_statistics())
CommunicationSettings.reset_sumulation_state()
def selective_repeat_test(file_name: str, repetitions: int) -> None:
for i in range(repetitions):
#Print proggress
print(f"Run {i + 1}/{repetitions}")
stats = Statistics()
#Setup test specific statistics
CommunicationSettings.check_sum = CheckSum.CRC
CommunicationSettings.window_size = 4
#Create sender and reciever
sender = SenderSR("Sender", stats)
reciever = RecieverSR("Reciever", stats)
#Setup resoult image name
reciever.set_recreated_image_name(f"Img/res_sr{i + 1}.png")
#Bind them
sender.bind(reciever)
reciever.bind(sender)
#Start them
sender.start()
reciever.start()
#Start transmition
sender.send_image(file_name)
wait_for_simulation_end()
print(stats.get_statistics())
CommunicationSettings.reset_sumulation_state()
#Global settings (the same for all tests)
CommunicationSettings.noise = NoiseType.Simple
CommunicationSettings.data_bytes = 64 #W bajtach 128 * 8 = 1024 bity
CommunicationSettings.key_bits = 16
CommunicationSettings.switch_probability = 0.0001
CommunicationSettings.logging = False # Logging will clutter the console, so keep it disabled
#------------
#INSTRUCTIONS
#------------
#There are some specific settings in the methods (CheckSum and window size)
#To run the test, uncomment the type you want to test and run the application. Resoults will be printed on the console
#Genereated images will be in the "Img" folder
#The string is the name of the image to send
#The number is the amount of tests
#stop_and_wait_test("bee.png", 10)
#go_back_n_test("bee.png", 10)
#selective_repeat_test("bee.png", 10)