def test_cython_wrapper(self): print("Device count:", rtlsdr.get_device_count()) print("Device name:", rtlsdr.get_device_name(0)) manufact, product, serial = rtlsdr.get_device_usb_strings(0) print("Manufacturer:", manufact) print("Product:", product) print("Serial", serial) print("Index by serial", rtlsdr.get_index_by_serial(serial)) print("Open:", rtlsdr.open(0)) print("Reset Buffer:", rtlsdr.reset_buffer()) # IMPORTANT print("XTAL Freq:", rtlsdr.get_xtal_freq()) print("USB device strings", rtlsdr.get_usb_strings()) print("Center Freq:", rtlsdr.get_center_freq()) print("Set center freq to 433MHz", rtlsdr.set_center_freq(int(433e6))) print("Center Freq:", rtlsdr.get_center_freq()) print("Freq Correction", rtlsdr.get_freq_correction()) print("Set Freq Correction to 10", rtlsdr.set_freq_correction(10)) print("Freq Correction", rtlsdr.get_freq_correction()) print("tuner type", rtlsdr.get_tuner_type()) print("tuner_gains", rtlsdr.get_tuner_gains()) print("set_manual_gain_mode", rtlsdr.set_tuner_gain_mode(1)) print("tuner gain", rtlsdr.get_tuner_gain()) print("set gain to 338", rtlsdr.set_tuner_gain(338)) print("tuner gain", rtlsdr.get_tuner_gain()) print("set tuner if gain", rtlsdr.set_tuner_if_gain(1, 10)) print("Sample Rate", rtlsdr.get_sample_rate()) print("Set Sample Rate to 300k", rtlsdr.set_sample_rate(300 * 10**3)) print("Sample Rate", rtlsdr.get_sample_rate()) read_samples = rtlsdr.read_sync(1024) print(read_samples)
def process_command(command): logger.debug("RTLSDR: {}".format(command)) if command == "stop": return "stop" tag, value = command.split(":") if tag == "center_freq": logger.info("RTLSDR: Set center freq to {0}".format(int(value))) return rtlsdr.set_center_freq(int(value)) elif tag == "rf_gain": logger.info("RTLSDR: Set tuner gain to {0}".format(int(value))) return rtlsdr.set_tuner_gain(10 * int(value)) # calculate *10 for API elif tag == "sample_rate": logger.info("RTLSDR: Set sample_rate to {0}".format(int(value))) return rtlsdr.set_sample_rate(int(value)) elif tag == "tuner_bandwidth": logger.info("RTLSDR: Set bandwidth to {0}".format(int(value))) return rtlsdr.set_tuner_bandwidth(int(value)) elif tag == "freq_correction": logger.info("RTLSDR: Set freq_correction to {0}".format( int(value))) return rtlsdr.set_freq_correction(int(value)) elif tag == "direct_sampling_mode": logger.info("RTLSDR: Set direct_sampling_mode to {0}".format( int(value))) return rtlsdr.set_direct_sampling(int(value))
def test_cython_wrapper(self): print("Device count:", rtlsdr.get_device_count()) print("Device name:", rtlsdr.get_device_name(0)) manufact, product, serial = rtlsdr.get_device_usb_strings(0) print("Manufacturer:", manufact) print("Product:", product) print("Serial", serial) print("Index by serial", rtlsdr.get_index_by_serial(serial)) print("Open:", rtlsdr.open(0)) print("Reset Buffer:", rtlsdr.reset_buffer()) # IMPORTANT print("XTAL Freq:", rtlsdr.get_xtal_freq()) print("USB device strings", rtlsdr.get_usb_strings()) print("Center Freq:", rtlsdr.get_center_freq()) print("Set center freq to 433MHz", rtlsdr.set_center_freq(int(433e6))) print("Center Freq:", rtlsdr.get_center_freq()) print("Freq Correction", rtlsdr.get_freq_correction()) print("Set Freq Correction to 10", rtlsdr.set_freq_correction(10)) print("Freq Correction", rtlsdr.get_freq_correction()) print("tuner type", rtlsdr.get_tuner_type()) print("tuner_gains", rtlsdr.get_tuner_gains()) print("set_manual_gain_mode", rtlsdr.set_tuner_gain_mode(1)) print("tuner gain", rtlsdr.get_tuner_gain()) print("set gain to 338", rtlsdr.set_tuner_gain(338)) print("tuner gain", rtlsdr.get_tuner_gain()) print("set tuner if gain", rtlsdr.set_tuner_if_gain(1, 10)) print("Sample Rate", rtlsdr.get_sample_rate()) print("Set Sample Rate to 300k", rtlsdr.set_sample_rate(300 * 10 ** 3)) print("Sample Rate", rtlsdr.get_sample_rate()) read_samples = rtlsdr.read_sync(1024) print(read_samples) rtlsdr.close()
def receive_sync(data_connection, ctrl_connection, device_number: int, center_freq: int, sample_rate: int, gain: int, freq_correction: int, direct_sampling_mode: int): ret = rtlsdr.open(device_number) ctrl_connection.send("open:" + str(ret)) ret = rtlsdr.set_center_freq(center_freq) ctrl_connection.send("set_center_freq:" + str(ret)) ret = rtlsdr.set_sample_rate(sample_rate) ctrl_connection.send("set_sample_rate:" + str(ret)) ret = rtlsdr.set_tuner_gain(10 * gain) ctrl_connection.send("set_tuner_gain to {0}:{1}".format(gain, ret)) ret = rtlsdr.set_freq_correction(freq_correction) ctrl_connection.send("set_freq_correction to {0}:{1}".format( freq_correction, ret)) ret = rtlsdr.set_direct_sampling(direct_sampling_mode) ctrl_connection.send("set_direct_sampling_mode to {0}:{1}".format( direct_sampling_mode, ret)) ret = rtlsdr.reset_buffer() ctrl_connection.send("reset_buffer:" + str(ret)) exit_requested = False while not exit_requested: while ctrl_connection.poll(): result = RTLSDR.process_command(ctrl_connection.recv()) if result == "stop": exit_requested = True break if not exit_requested: data_connection.send_bytes(rtlsdr.read_sync()) logger.debug("RTLSDR: closing device") ret = rtlsdr.close() ctrl_connection.send("close:" + str(ret)) data_connection.close() ctrl_connection.close()
def set_freq_correction(self, ppm): ret = rtlsdr.set_freq_correction(int(ppm)) self.log_retcode(ret, "Set frequency correction")