Exemplo n.º 1
0
 def enable_agc(self, enable):
     self.clib.py_rtlsdr_set_agc_mode(self.__dev_ptr, enable=enable)
     self.__enable_agc = enable
     if self.__logging_level == 1:
         if enable:
             print_success_msg("Device internal AGC is enabled.")
         else:
             print_success_msg("Device internal AGC is disabled.")
Exemplo n.º 2
0
    def freq_correction(self, ppm):
        self.clib.py_rtlsdr_set_freq_correction(self.__dev_ptr, ppm)
        self.__freq_correction = ppm

        returned_freq_correction = self.clib.py_rtlsdr_get_freq_correction(
            self.__dev_ptr)
        if self.__logging_level == 1:
            print_success_msg("Freq correct is set to %d ppm" % (ppm))
Exemplo n.º 3
0
    def sample_rate(self, rate):
        self.clib.py_rtlsdr_set_sample_rate(self.__dev_ptr, rate)
        self.__sample_rate = rate

        returned_sample_rate = self.clib.py_rtlsdr_get_sample_rate(
            self.__dev_ptr)
        if self.__logging_level == 1:
            print_success_msg("Device sample rate is set to %d Hz." %
                              (returned_sample_rate))
Exemplo n.º 4
0
    def center_freq(self, freq):
        self.clib.py_rtlsdr_set_center_freq(self.__dev_ptr, freq)
        self.__center_freq = freq

        returned_center_freq = self.clib.py_rtlsdr_get_center_freq(
            self.__dev_ptr)
        if self.__logging_level == 1:
            print_success_msg("Device center freq is set to %d Hz." %
                              (returned_center_freq))
Exemplo n.º 5
0
 def tuner_gain(self, gain):
     """
     Make sure tuner gain selection mode is set to manual
     before over writing the value.
     """
     self.__enable_auto_tuner_gain = False
     self.clib.py_rtlsdr_set_tuner_gain(self.__dev_ptr, gain)
     self.__tuner_gain = gain
     if self.__logging_level == 1:
         print_success_msg("Tuner gain is set to %d dB" % (gain))
Exemplo n.º 6
0
    def enable_auto_tuner_gain(self, enable):
        if type(enable) != bool:
            print_error_msg("Expected bool. Got: %s" % (type(enable)))
            raise ValueError

        self.clib.py_rtlsdr_set_tuner_gain_mode(self.__dev_ptr,
                                                manual=not enable)
        self.__enable_auto_tuner_gain = enable
        if self.__logging_level == 1:
            if enable:
                print_success_msg("Tuner gain selection is set to auto.")
            else:
                print_success_msg("Tuner gain selection is set to manual.")
Exemplo n.º 7
0
 def close(self, ):
     """
     Closes the libusb connection to the SDR device.
     """
     if self.__dev_ptr.value is not None:
         self.clib.py_rtlsdr_close(self.__dev_ptr)
         if self.__logging_level == 1:
             print_success_msg(
                 "Successfully closed the libusb connection to the device.")
     else:
         if self.__logging_level < 4:
             print_warn_msg(
                 "Device handle pointer is None. Skipping close libusb connection to the device."
             )
     self.__dev_ptr = c_void_p(None)
Exemplo n.º 8
0
    def __del__(self):
        """
        Device clearn up function. This function
        is called when the object goes out of scope.
        Closes the connection to the device.
        """

        if self.__dev_ptr.value is not None:
            self.clib.py_rtlsdr_close(self.__dev_ptr)
            if self.__logging_level == 1:
                print_success_msg(
                    "Successfully closed the libusb connection to the device.")
        else:
            if self.__logging_level < 4:
                print_warn_msg(
                    "Device handle pointer is None. Skipping close libusb connection to the device."
                )
        self.__dev_ptr = c_void_p(None)
Exemplo n.º 9
0
    def __init__(self, device_index, logging_level=3):
        self.__librtlsdr = librtlsdr()

        if int(device_index) != device_index:
            print_error_msg("Expected device index to be of int. Got: %s." %
                            (type(device_index)))
            raise TypeError

        device_index = int(device_index)

        self.__device_index = device_index

        if int(logging_level) != logging_level:
            print_error_msg("Expected logging level to be int. Got: %s" %
                            (type(logging_level)))
            raise TypeError

        logging_level = int(logging_level)

        if logging_level < 1 or logging_level > 4:
            print_error_msg("Invalid logging level %d." % (logging_level))
            raise ValueError

        # Setting the logging level.
        self.__logging_level = logging_level

        # Open a device pointer to the SDR.
        self.__dev_ptr = c_void_p(None)
        self.__dev_ptr = self.clib.py_rtlsdr_open(device_index)

        if self.__logging_level == 1:
            print_success_msg(
                "Successfully opened a libusb connection to the device.")

        # Get SDR details
        self.__mid, self.__vid, self.__serial = self.clib.py_rtlsdr_get_device_usb_strings(
            self.__device_index)
        if self.__logging_level < 3:
            device_strings = "Manufacturer: %s, Vendor ID: %s, Serial %s." % (
                self.__mid, self.__vid, self.__serial)
            print_info_msg(device_strings)

        # Attributes
        self.__center_freq = None
        self.__sample_rate = None
        self.__enable_agc = None
        self.__tuner_gain = None
        self.__enable_auto_tuner_gain = None
        self.__tuner_gains = self.clib.py_rtlsdr_get_tuner_gains(
            self.__dev_ptr)
        self.__freq_correction = self.clib.py_rtlsdr_get_freq_correction(
            self.__dev_ptr)
        self.__rtl_xo_freq, self.__tuner_xo_freq = self.clib.py_rtlsdr_get_xtal_freq(
            self.__dev_ptr)
        self.__num_recv_samples = None

        # Init defaults
        self.__init_default()

        # Reset libusb buffer
        self.clib.py_rtlsdr_reset_buffer(self.__dev_ptr)

        if self.__logging_level < 3:
            device_config = 'Intialized device with following default values.'
            device_config += '\n\t1. Center Freq: %d Hz.' % (self.center_freq)
            device_config += '\n\t2. Sample Rate: %d MSPS.' % (
                self.sample_rate)
            device_config += '\n\t3. AGC Enabled: %s.' % (self.enable_agc)
            device_config += '\n\t4. Automatic tuner gain selection: %s.' % (
                self.enable_auto_tuner_gain)
            device_config += '\n\t5. Freq Correction: %d ppm' % (
                self.freq_correction)
            device_config += '\n\t6. Tuner gain: %s dB' % (self.tuner_gain)
            device_config += '\n\t7. Frame size (samples/frame): %d' % (
                self.num_recv_samples)
            print_info_msg(device_config)