Changeset 391 for vtcross/trunk/src/cognitive_engines/DSA_CE/examples
- Timestamp:
- 07/29/09 16:10:39 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/trunk/src/cognitive_engines/DSA_CE/examples/gnuradio-examples/dsa.py
r390 r391 39 39 def main(): 40 40 41 global n_rcvd, n_right,sync_status,mode,ch,traffic_flag,n_attempts,return_flag41 global stats_array, count_array, time_array, n_rcvd, n_right,sync_status,mode,ch,traffic_flag,n_attempts,return_flag 42 42 n_rcvd = 0 43 43 n_right = 0 44 44 n_attempts = 5 45 45 return_flag = 0 46 47 count_array = [ 0, 0, 0, 0, 0] 48 time_array = [ 0, 0, 0, 0, 0] 49 stats_array = [ 0, 0, 0, 0, 0] 50 46 51 47 52 def send_pkt(self, payload='', eof=False): … … 63 68 return real_channel 64 69 70 def get_average_time(channel,absent_time): 71 72 global count_array, time_array 73 74 count_array[channel] = count_array[channel] + 1 75 average_time = (time_array[channel] + absent_time) / count_array[channel] 76 77 return average_time 78 65 79 def get_freq(hop_freq,probe_level,absent_time): 66 80 … … 76 90 channel = 4 77 91 78 p = Parameter(1)79 92 currentParameters = Parameter(1) 80 o = Observable(1) 81 93 currentParameters[0].name = "channel" 94 currentParameters[0].value = channel 95 96 o = Observable(2) 82 97 o[0].value = probe_level 83 98 o[0].name = "energy" 84 85 currentParameters[0].name = "channel" 86 currentParameters[0].value = channel; 87 88 p = GetOptimalParameters(o,1,currentParameters,1); 89 print p[0].value 99 100 o[1].value = absent_time 101 o[1].name = "communication_time" 102 103 # If time == 0 then we are scanning and we dont want to 104 # use this time in the averaging process. 105 106 if absent_time != 0: 107 UpdateParameterPerformance(currentParameters,1,o,1) 108 109 else: 110 # Get the average communication time 111 average_time = get_average_time(channel, absent_time) 112 o[1].value = average_time 113 o[1].name = "communication_time" 114 UpdateParameterPerformance(currentParameters,1,o,2) 115 116 p = Parameter(1) 117 p = GetOptimalParameters(o,2,currentParameters,1); 90 118 91 119 channel = get_real_channel(int(p[0].value)) … … 96 124 hop_freq = float(1e6 * (467.5625+(channel-8)*0.025))#setting the centre freq frequency for sending packets 97 125 126 stats_array[int(p[0].value)] = stats_array[int(p[0].value)] + 1 127 print "Stats:: 1..",stats_array[1]," 2..",stats_array[2]," 3..",stats_array[3]," 4..",stats_array[4] 98 128 return channel,hop_freq #returning the channel number and hop frequency 99 129 … … 154 184 155 185 parser_tx = OptionParser(option_class=eng_option, conflict_handler="resolve") 156 expert_grp_tx = parser_tx.add_option_group("Expert_tx") 157 186 parser_tx.add_option("", "--vtcross", action="store_true", default=False, 187 help="Use the CROSS engine for DSA decisions: default is random.") 188 158 189 parser_tx.add_option("-m", "--modulation", type="choice", choices=mods.keys(), 159 190 default='gmsk', … … 166 197 help="set megabytes to transmit [default=%default]") 167 198 parser_tx.add_option("","--discontinuous", action="store_true", default=False, 168 help="enable discontinous transmission (bursts of 5 packets)") 199 help="enable discontinous transmission (bursts of 5 packets)") 169 200 parser_tx.add_option("","--from-file", default=None, 170 201 help="use file for packet contents") 171 202 203 expert_grp_tx = parser_tx.add_option_group("Expert_tx") 204 172 205 transmit_path.add_options(parser_tx, expert_grp_tx) 173 206 174 207 for mod in mods.values(): 175 208 mod.add_options(expert_grp_tx) 209 176 210 177 211 (options_tx, args_tx) = parser_tx.parse_args () … … 188 222 options_tx.fusb_nblocks = 16 189 223 options_tx.bitrate = 0.0125e6 190 224 ############# 191 225 192 226 if options_tx.tx_freq is None: … … 195 229 sys.exit(1) 196 230 197 if options_tx.from_file is not None:198 source_file = open(options_tx.from_file, 'r')231 #if options_tx.from_file is not None: 232 # source_file = open(options_tx.from_file, 'r') 199 233 200 234 parser_rx = OptionParser (option_class=eng_option, conflict_handler="resolve") 201 235 expert_grp_rx = parser_rx.add_option_group("Expert_rx") 202 parser_rx.add_option("-m", "--modulation", type="choice", choices=demods.keys(),203 default='gmsk',204 help="Select modulation from: %s [default=%%default]"205 % (', '.join(demods.keys()),))236 #parser_rx.add_option("-m", "--modulation", type="choice", choices=demods.keys(), 237 # default='gmsk', 238 # help="Select modulation from: %s [default=%%default]" 239 # % (', '.join(demods.keys()),)) 206 240 207 241 receive_path.add_options(parser_rx, expert_grp_rx) 208 242 209 for mod in demods.values():210 mod.add_options(expert_grp_rx)243 #for mod in demods.values(): 244 # mod.add_options(expert_grp_rx) 211 245 212 246 (options_rx, args_rx) = parser_rx.parse_args () 213 247 214 if len(args_rx) != 0:215 parser_rx.print_help(sys.stderr)216 sys.exit(1)248 #if len(args_rx) != 0: 249 # parser_rx.print_help(sys.stderr) 250 # sys.exit(1) 217 251 ############# Setting some default values for rx side of the block 218 252 options_rx.rx_freq = 462.5625e6 #setting default rx_freq value … … 224 258 ############# 225 259 226 if options_rx.rx_freq is None:227 sys.stderr.write("You must specify -f FREQ or --freq FREQ\n")228 parser_rx.print_help(sys.stderr)229 sys.exit(1)260 #if options_rx.rx_freq is None: 261 # sys.stderr.write("You must specify -f FREQ or --freq FREQ\n") 262 # parser_rx.print_help(sys.stderr) 263 # sys.exit(1) 230 264 231 265 # build the graph … … 248 282 249 283 # Scan all channels first for inital data 284 time.sleep(0.1) 250 285 251 286 while running: