33#----------------------------------------------------------------------------
44# Created By : Bryson Schiel - @schielb (GitHub)
55# Created Date: Feb 1, 2023
6- # Latest Update: Feb 15 , 2023
7- # version ='1.0 '
6+ # Latest Update: May 25 , 2023
7+ # version ='1.1 '
88# ---------------------------------------------------------------------------
99"""
1010 A python file to iteratively test different attenuation values on
1919from threading import Event , Thread
2020import time
2121import os
22- from datetime import date
22+ from datetime import datetime
2323import matplotlib .pyplot as plt
2424
2525def call_repeatedly (interval , func , * args ):
@@ -81,37 +81,38 @@ def uniquify(path):
8181
8282 return path
8383
84+ cap_folder_name = "Packet_Captures/" + datetime .now ().strftime ("%b-%d-%H:%M:%S" )
85+ res_folder_name = "Results/" + datetime .now ().strftime ("%b-%d-%H:%M:%S" )
86+
87+ #See if we need to create a new folder and csv file for today for today
88+ for newpath in [cap_folder_name , res_folder_name ]:
89+ if not os .path .exists (newpath ):
90+ os .makedirs (newpath )
91+
92+ ###############################################################################
93+ # At this point, folders have been set up, now we will gather the attenuations.
94+ ###############################################################################
8495for attenuation in yaml_data ["attenuations" ]:
8596 # Clear the data and declare the start of the trial
8697 clear_data ()
8798 print ("\x1B [32mSetting up trial on attenuation value\x1B [35m %d\x1B [32m db for\x1B [35m %d\x1B [32m seconds...\x1B [37m"
8899 % (attenuation , yaml_data ["trial_length" ]))
89100
90- cap_folder_name = "Packet_Captures/" + date .today ().strftime ("%b-%d" )
91- res_folder_name = "Results/" + date .today ().strftime ("%b-%d" )
92-
93- #See if we need to create a new folder and csv file for today for today
94- for newpath in [cap_folder_name , res_folder_name ]:
95- if not os .path .exists (newpath ):
96- os .makedirs (newpath )
97-
98101 cap_file_name = uniquify (cap_folder_name + "/attenuation_%d.pcap" % attenuation )
99102
100103 cap = pyshark .LiveCapture (interface = yaml_data ["wireshark_interface" ],
101104 bpf_filter = "udp and not src host %s" % yaml_data ['host_ip' ],
102105 output_file = cap_file_name )
103106
104-
105107
106108 # Go through and set all the attenuation values we need
107109 for tx_port in yaml_data ["static_mesh_ports" ]:
108110 for rsu in rsus .keys ():
109111 rx_port = rsus [rsu ]["mesh_port" ]
110- partial_att = rsus [rsu ]["att_offset " ]
112+ partial_att = rsus [rsu ]["static_att " ]
111113 diff_att = attenuation - partial_att
112114 diff_att = round (diff_att * 4 ) / 4 # needs a multiple of 0.25
113115
114- #print('dbg: mesh.set_att(%s, %s, %f)' % (tx_port, rx_port, diff_att))
115116 mesh .set_att (tx_port , rx_port , diff_att )
116117
117118 time .sleep (10 ) # Delay to allow new setup to settle
@@ -130,31 +131,22 @@ def uniquify(path):
130131 pass
131132 finally :
132133 end_timer ()
133- #timer.cancel()
134134 print ()
135135 print ("\x1B [32mEnding trial for\x1B [35m %d\x1B [32m db\x1B [37m" % attenuation , end = "\n " )
136136
137137 print ("Saving data from trial..." )
138- # Save the results in their own files
139- res_folder_name = "Results/" + date .today ().strftime ("%b-%d" )
140-
141- #See if we need to create a new folder and csv file for today for today
142- if not os .path .exists (res_folder_name ):
143- os .makedirs (res_folder_name )
138+
144139
140+ # Save the results in their own files
145141 cap .close ()
146142 for rsu in rsus :
147143
148-
149144 total_time_gap = yaml_data ["trial_length" ]
150145 num_packets = data [rsu ]
151146
152147 estimated_num_spaced = int (total_time_gap * 10 )
153148 percent_reception = float (float (num_packets ) / float (estimated_num_spaced ))
154149
155-
156-
157-
158150 summaries_file_name = '%s/summaries_%s.txt' % (res_folder_name , rsu )
159151
160152 print ("Saving %s data in %s" % (rsu , summaries_file_name ))
@@ -173,10 +165,9 @@ def uniquify(path):
173165# At this point, all attenuations have been gathered, and we are ready to display the results.
174166##############################################################################################
175167
176- folder_name = "Results/" + date .today ().strftime ("%b-%d" )
177-
168+ # Display each individual RSU's performance
178169for rsu in rsus :
179- file_name = folder_name + "/summaries_%s.txt" % rsu
170+ file_name = res_folder_name + "/summaries_%s.txt" % rsu
180171
181172 values = []
182173
@@ -213,9 +204,10 @@ def uniquify(path):
213204 plt .ylim (- 4 , 104 )
214205 plt .axhline (y = 90 , color = 'red' , linestyle = '--' , label = 'Critical Safety Limit: 90%' )
215206 plt .show ()
216- plt .savefig (folder_name + '/Attenuations-%s.png' % rsu )
207+ plt .savefig (res_folder_name + '/Attenuations-%s.png' % rsu )
217208 plt .clf ()
218209
210+ # Display all performances on a single graph for comparison
219211for rsu in rsus :
220212 plt .plot (data ['att' ], data [rsu ]['rate' ], label = rsu , marker = 'o' )
221213
@@ -225,7 +217,7 @@ def uniquify(path):
225217plt .title ("Reception Rate per Attenuation (All RSU Comparison)" )
226218plt .axhline (y = 90 , color = 'red' , linestyle = '--' , label = 'Critical Safety Limit: 90%' )
227219plt .legend ()
228- plt .savefig (folder_name + '/Comparison-Attenuations.png' )
220+ plt .savefig (res_folder_name + '/Comparison-Attenuations.png' )
229221plt .show ()
230222plt .clf ()
231223
0 commit comments