Exemple #1
0
 def __init__(self, pu_type):
     self.pu_type = pu_type
     self.radio = radioThread(self)
     self.channel_list = []
     self.json_decoder = json.JSONDecoder()
     self.configEditor = config_editor.ConfigEditor()
     self.ip = "localhost"
     self.primaryLogger = None
Exemple #2
0
 def run(self):
     config_path = get_config_path(self.options.get("--config-path"))
     config = config_editor.ConfigEditor(config_path)
     name = self.options.get("--name")
     value = self.options.get("--value")
     if name and value:
         config.parse()
         config.parsed.add_bind(name, value)
         config.parsed_to_content()
         config.save()
Exemple #3
0
    def run(self):
        config_path = get_config_path(self.options.get("--config-path"))

        config = config_editor.ConfigEditor(config_path)
        bind_name = self.options.get("--bind-name")
        backend_version = int(self.options.get("--backend-version"))
        if bind_name and backend_version:
            config.parse()
            config.parsed.add_db_engine(bind_name, backend_version)
            config.parsed_to_content()
            config.save()
    def __init__(self, dest_addr, dest_port):
        self.configEditor = config_editor.ConfigEditor()

        config_path = os.path.dirname(os.path.abspath(__file__))
        config_path = config_path + '/nodeInfo.cfg'
        self.nodeConfiguration = self.configEditor.read_config_file(
            config_path)

        ip = self.get_ip_address('eth0')

        self.nodeID = self.get_nodeID(
            ip)  #self.nodeConfiguration[node]['nodeID']
        self.reset_message()
        self.dest_addr = dest_addr
        self.dest_port = dest_port
        self.output_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
Exemple #5
0
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)