def main(): # TODO: the ability for the user to choose input parameters # TODO: To check if the input from the socket is a JSON Object newCbsd = cbsd.Cbsd("cbd561","A","cbd1","hask124ba","yap") newCbsd.add_registration_parameters("callSign","CB987") json_encoder = json.JSONEncoder() json_request = json_encoder.encode(newCbsd.get_registrationRequestObj()) my_server_connection = server_connection.Server_connection("http://128.173.94.243/spectrumAccessSystem/start.php") print("Request: sending registration request") # get response string response = my_server_connection.send_request(json_request) """
def register(): global newCbsd global my_server_connection getCommand() link = "http://" + newCbsd.sas_ip + "/spectrumAccessSystem/start.php" print link print "--------------------------Starting-----------------------------" my_server_connection = server_connection.Server_connection(link) newCbsd.add_registration_parameters("callSign", "CB987") newCbsd.add_registration_parameters("airInterface", "Antenna") print("Request: sending registration request") # get response string json_decoder = json.JSONDecoder() newCbsd.sendRegistrationRequest(my_server_connection)
def main(): newCbsd = cbsd.Cbsd("cbd561","A","cbd1","hask124ba") newCbsd.add_registration_parameters("callSign","CB987") json_encoder = json.JSONEncoder() json_request = json_encoder.encode(newCbsd.get_registrationRequestObj()) my_server_connection = server_connection.Server_connection("http://10.0.0.3/spectrumAccessSystem/start.php") print("Request: sending registration request") # get response string response = my_server_connection.send_request(json_request) # create json decoder object json_decoder = json.JSONDecoder() # get dictionary json_response = json_decoder.decode(response) #change state of cbsd newCbsd.set_registrationResponseObj(json_response) # send channel inquiry in order of importance newCbsd.add_inquired_channels(890,900) newCbsd.add_inquired_channels(880,890) newCbsd.add_inquired_channels(860,870) newCbsd.add_inquired_channels(870,880) ''' Inquire about the spectrum ''' print "\n---------------------------------------------------------\n" print("Request: sending spectrum Inquiry ") print "Sending Inquiry for the Following Channels:" inquired_channels = newCbsd.get_inquired_channels() for i in newCbsd.get_inquired_channels(): print i print "\n---------------------------------------------------------\n" json_request = json_encoder.encode(newCbsd.get_spectrumInquiryRequestObj()) response = my_server_connection.send_request(json_request) # get dictionary json_response = json_decoder.decode(response) newCbsd.set_spectrumInquiryResponseObj(json_response) print "Below are the Channels Available:" for i in newCbsd.get_available_channels(): print i print "\n---------------------------------------------------------\n" ''' Get Grant Request ''' json_request = json_encoder.encode(newCbsd.get_grantRequestObj()) print "Requesting Grant for the following Channel" print newCbsd.get_operationFrequencyRange() response = my_server_connection.send_request(json_request) # get dictionary json_response = json_decoder.decode(response) newCbsd.set_grantResponseObj(json_response) operationFrequency = newCbsd.get_operationFrequencyRange() print "Channel Grant Accepted" print "\n---------------------------------------------------------\n" print "Sending Initial Heartbeat" freq = operationFrequency['lowFrequency'] heartbeatInterval = newCbsd.get_heartbeatInterval() json_request = json_encoder.encode(newCbsd.get_heartbeatRequestObj()) response = my_server_connection.send_request(json_request) #print("Initial Heartbeat:", response) my_heartbeat_Thread = cbsd_thread.cbsd_thread(newCbsd,my_server_connection,\ "heartbeat",heartbeatInterval,json_r = json_request) print "Heartbeat to be sent every",heartbeatInterval,"s" my_heartbeat_Thread.start() current_time = time.mktime(datetime.datetime.utcnow().timetuple()) # print("server_time: ",newCbsd.get_grantExpireTime()) # print("client time: ", datetime.datetime.utcnow().timetuple()) grantInterval = newCbsd.get_grantExpireTime_seconds() - current_time print "Grant Ends in: ", grantInterval,"s" my_grant_Thread = cbsd_thread.cbsd_thread(newCbsd,my_server_connection,\ "grant",grantInterval,heartbeat_thread = my_heartbeat_Thread) my_grant_Thread.start()
def run_radio(): global stop_radio global newCbsd global my_server_connection json_encoder = json.JSONEncoder() json_request = json_encoder.encode(newCbsd.get_registrationRequestObj()) newCbsd.clear_channels() #change state of cbsd getCommand() link = "http://" + newCbsd.sas_ip + "/spectrumAccessSystem/start.php" my_server_connection = server_connection.Server_connection(link) print "CBSD STATE: ", newCbsd.get_cbsd_state() informationParser = information_parser.InformationParser( newCbsd.sas_ip, 9749) # will need to move this to be part of cbsd groupedIDs = [] if newCbsd.grouped != None: for i in range(0, len(newCbsd.grouped)): groupedIDs.append(informationParser.get_nodeID(newCbsd.grouped[i])) print "grouped: ", groupedIDs[i] # TODO: Add connection to internal database # send channel inquiry in order of importance if (newCbsd.get_cbsd_state() == "REGISTERED"): configEditor = config_editor.ConfigEditor() ''' Inquire about the spectrum ''' informationParser.addStatus("type", "SU") informationParser.addStatus("state", "REGISTERED") informationParser.sendStatus() if newCbsd.manual: try: print "Please Use Low Frequency Above 3550MHz and below 3650MHz" lowFrequency = math.floor( float(input("Low Frequency: ")) / 10) * 10e6 print "User Input in Hz: ", lowFrequency if lowFrequency < 3550e6 or lowFrequency > 3650e6: print "------------------Wrong User Low Frequency-----------------" stop_radio = True newCbsd.stop_cbsd() return else: newCbsd.clear_inquired_channels() newCbsd.clear_channels() newCbsd.add_inquired_channels(lowFrequency, lowFrequency + 10e6) except Exception as e: print "----------------------------Wrong User Input-----------------" stop_radio = True newCbsd.stop_cbsd() return newCbsd.sendSpectrumInquiry(my_server_connection) informationParser.addStatus("type", "SU") informationParser.addStatus("state", "SPECTRUM INQUIRY") #informationParser.addStatus("channels",newCbsd.get_inquired_channels()) if len(groupedIDs) > 0: informationParser.addStatus("group", groupedIDs) informationParser.sendStatus() # Get Grant Request newCbsd.sendGrantRequest(my_server_connection) # start sending heartbeats print "GRANT STATE: ", newCbsd.get_grant_state() if newCbsd.get_grant_state() == "GRANTED" or newCbsd.get_grant_state( ) == "AUTHORIZED": # NOTE: this information is already being sent by crts informationParser.addStatus("type", "SU") informationParser.addStatus("state", "GRANT AUTHORIZED") freq_range = newCbsd.get_operationFrequencyRange() lowFrequency = float(freq_range['lowFrequency']) highFrequency = float(freq_range['highFrequency']) print "lowFrequency", lowFrequency informationParser.addStatus("lowFrequency", lowFrequency) informationParser.addStatus("highFrequency", highFrequency) if len(groupedIDs) > 0: informationParser.addStatus("group", groupedIDs) informationParser.sendStatus() my_heartbeat_Thread = newCbsd.startSendingHeartBeats( my_server_connection) # start radio interface start_radio_Thread = cbsd_thread.cbsd_thread(newCbsd,my_server_connection,\ "start_radio",0,config_editor = configEditor,\ heartbeat_thread = my_heartbeat_Thread) # start grant timer newCbsd.startGrant(my_server_connection, start_radio_Thread) if newCbsd.get_grant_state() != "IDLE": print "Starting Radio" start_radio_Thread.start() if newCbsd.my_heartbeat_Thread != None: sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) my_port = 7816 sock.bind(("localhost", my_port)) sock.settimeout(1.0) data = None while data == None and stop_radio == False: try: data = sock.recvfrom(1024) except Exception as e: if not newCbsd.my_heartbeat_Thread.isAlive(): break pass print "Received something: ", data sock.close() informationParser.addStatus("state", "GRANT RELINQUISHED") informationParser.addStatus("type", "SU") informationParser.sendStatus() else: informationParser.addStatus("state", "UNREGISTERED") informationParser.addStatus("type", "SU") if len(groupedIDs) > 0: informationParser.addStatus("group", groupedIDs) informationParser.sendStatus() print "Stopping All Radio Functionalities" stop_crts() time.sleep(5)
def main(): newCbsd = cbsd.Cbsd("cbd561", "A", "cbd1", "hask124ba") newCbsd.add_registration_parameters("callSign", "CB987") json_encoder = json.JSONEncoder() json_request = json_encoder.encode(newCbsd.get_registrationRequestObj()) my_server_connection = server_connection.Server_connection( "http://172.29.70.54/spectrumAccessSystem/start.php") print "\n---------------------------------------------------------\n" print("Sending Registration Request") # get response string response = my_server_connection.send_request(json_request) # create json decoder object json_decoder = json.JSONDecoder() # get dictionary json_response = json_decoder.decode(response) #change state of cbsd newCbsd.set_registrationResponseObj(json_response) print("Registration Accepted, Radio Authenticated") # send channel inquiry in order of importance newCbsd.add_inquired_channels(880, 890) newCbsd.add_inquired_channels(890, 900) newCbsd.add_inquired_channels(880, 890) newCbsd.add_inquired_channels(860, 870) ''' Inquire about the spectrum ''' print "\n---------------------------------------------------------\n" print("Request: sending spectrum Inquiry ") print "Sending Inquiry for the Following Channels:" inquired_channels = newCbsd.get_inquired_channels() for i in newCbsd.get_inquired_channels(): print i print "\n---------------------------------------------------------\n" json_request = json_encoder.encode(newCbsd.get_spectrumInquiryRequestObj()) response = my_server_connection.send_request(json_request) # get dictionary json_response = json_decoder.decode(response) newCbsd.set_spectrumInquiryResponseObj(json_response) print "Below are the Channels Available:" for i in newCbsd.get_available_channels(): print i print "\n---------------------------------------------------------\n" ''' Get Grant Request ''' json_request = json_encoder.encode(newCbsd.get_grantRequestObj()) print "Requesting Grant for the following Channel" print newCbsd.get_operationFrequencyRange() response = my_server_connection.send_request(json_request) # get dictionary json_response = json_decoder.decode(response) newCbsd.set_grantResponseObj(json_response) operationFrequency = newCbsd.get_operationFrequencyRange() print "Channel Grant Accepted" print "\n---------------------------------------------------------\n" print "Sending Initial Heartbeat" freq = operationFrequency['lowFrequency'] heartbeatInterval = newCbsd.get_heartbeatInterval() json_request = json_encoder.encode(newCbsd.get_heartbeatRequestObj()) response = my_server_connection.send_request(json_request) #print("Initial Heartbeat:", response) my_heartbeat_Thread = cbsd_thread.cbsd_thread(newCbsd,my_server_connection,\ "heartbeat",heartbeatInterval,json_r = json_request) print "Heartbeat to be send every ", heartbeatInterval, "s" my_heartbeat_Thread.start() current_time = time.mktime(datetime.datetime.utcnow().timetuple()) # print("server_time: ",newCbsd.get_grantExpireTime()) # print("client time: ", datetime.datetime.utcnow().timetuple()) grantInterval = newCbsd.get_grantExpireTime_seconds() - current_time print "Grant Ends in: ", grantInterval, "s" my_grant_Thread = cbsd_thread.cbsd_thread(newCbsd,my_server_connection,\ "grant",grantInterval,heartbeat_thread = my_heartbeat_Thread) my_grant_Thread.start() freq = newCbsd.get_operationFrequencyRange() low_freq = freq['lowFrequency'] print "\n---------------------------------------------------------\n" print "Setting Up Transmission" from distutils.version import StrictVersion if StrictVersion(Qt.qVersion()) >= StrictVersion("4.5.0"): style = gr.prefs().get_string('qtgui', 'style', 'raster') Qt.QApplication.setGraphicsSystem(style) qapp = Qt.QApplication(sys.argv) freq = int(low_freq) * 1000000 tb = transmitter() tb.set_freq(freq) tb.start() print "\n---------------------------------------------------------\n" time.sleep(grantInterval) def quitting(): #print("Freq:",tb.get_freq()) tb.stop() tb.wait() quitting()