def main(): parser = OptionParser(option_class=eng_option, conflict_handler="resolve") expert_grp = parser.add_option_group("Expert") channel_grp = parser.add_option_group("Channel") modes = ['default','loopback'] parser.add_option("-m", "--mode", type="choice", choices=modes, default=modes[0], help="Select operating mode from: %s [default=%%default]" % (', '.join(modes),)) parser.add_option("","--source", action="store_true", default=False, help="Set the node to source (transmitter) [default=%default]") parser.add_option("-v", "--verbose", action="store_true", default=False) cnPHY.add_options(parser,expert_grp,channel_grp) (options, args) = parser.parse_args () if len(args) != 0: parser.print_help() sys.exit(1) r = gr.enable_realtime_scheduling() if r != gr.RT_OK: print "Warning: failed to enable realtime scheduling" nodeinfo = getNodeInfo() displayTitle ( nodeinfo ) #============================================================================ # Create a Physical layer (Open GNURadio Core) #============================================================================ layer_1 = cnPHY(options) #============================================================================ # Create Protocol Stacks #============================================================================ usrp = usrp_utils(options) #============================================================================ # Create a MAC/Link layer #============================================================================ layer_2 = cnMAC('123456') #============================================================================ # Create a MAC/Link layer #============================================================================ layer_7 = cnAPP(options, usrp) #============================================================================ # Bind the MAC/Link and network layer #============================================================================ print "... Bind the PHY, MAC and APP layer" cnConnect(layer_1, layer_2, layer_7) print "... USRP Tick Period = %d (us)"%usrp.tick_period() time.sleep(1) print "" if options.source == True: #============================================================================ # First phase #============================================================================ tproc = 0.05 bitrate = options.bitrate sps = options.samples_per_symbol sample_duration = (1e9)/(bitrate*sps) gap = long((tproc*float(bitrate*sps))) print '[Configuration]' print ' Bitrate = ',bitrate print ' Samples per symbol = ',sps print ' Sample duration = ',sample_duration print ' Transmission gap = ', gap gap = 30000 trials = 10000 while trials: layer_7.data_request('12345678') time.sleep(0.2) trials = trials - 1 else: while True: time.sleep(1) layer_1.tb.wait() # wait for it to finish
def main(): parser = OptionParser(option_class=eng_option, conflict_handler="resolve") expert_grp = parser.add_option_group("Expert") channel_grp = parser.add_option_group("Channel") modes = ['default','loopback'] parser.add_option("-m", "--mode", type="choice", choices=modes, default=modes[0], help="Select operating mode from: %s [default=%%default]" % (', '.join(modes),)) parser.add_option("-v", "--verbose", action="store_true", default=False) cnPHY.add_options(parser,expert_grp,channel_grp) (options, args) = parser.parse_args () if len(args) != 0: parser.print_help() sys.exit(1) r = gr.enable_realtime_scheduling() if r != gr.RT_OK: print "Warning: failed to enable realtime scheduling" nodeinfo = getNodeInfo() displayTitle ( nodeinfo ) #============================================================================ # Create Protocol Stacks #============================================================================ #============================================================================ # Create a Physical layer (Open GNURadio Core) #============================================================================ layer_1 = cnPHY(options) #============================================================================ # Create a MAC/Link layer #============================================================================ localmacaddr = getNodeInfo()['mac'] layer_2 = cnCANDIMAC(MACAddr(localmacaddr)) #============================================================================ # Create a MAC/Link layer #============================================================================ layer_7 = cnAPP_TPSN(options) ## modified by Haejoon (11/30) #============================================================================ # Bind the MAC/Link and network layer #============================================================================ print "... Bind the PHY, MAC and APP layer" cnConnect(layer_1, layer_2, layer_7) time.sleep(1) print "" #============================================================================ # CANDI Protocol #============================================================================ if layer_7.node_mode == 1: # If it is the Root1 #============================================================================ # First phase #============================================================================ tproc = 0.05 bitrate = options.bitrate sps = options.samples_per_symbol sample_duration = (1e9)/(bitrate*sps) gap = long((tproc*float(bitrate*sps))) print '[Configuration]' print ' Bitrate = ',bitrate print ' Samples per symbol = ',sps print ' Sample duration = ',sample_duration print ' Transmission gap = ', gap layer_7.SendSPREQ1() time.sleep(1) else: while True: time.sleep(1) layer_1.tb.wait() # wait for it to finish