Code Monkey home page Code Monkey logo

librtlsdr's Introduction

rtl-sdr
turns your Realtek RTL2832 based DVB dongle into a SDR receiver
======================================================================

For more information see:
https://osmocom.org/projects/rtl-sdr/wiki

librtlsdr's People

Contributors

argilo avatar berkovskyy avatar edy555 avatar eshaz avatar hayguen avatar hoernchen avatar howard0su avatar jvde-github avatar kasper93 avatar keenerd avatar kukabu avatar laf0rge avatar lcl7 avatar leonsal avatar loudou avatar maitbot avatar mfalkvidd avatar mnhauke avatar mutability avatar osmith42 avatar pallas avatar pinkavaj avatar racerxdl avatar rtlsdrblog avatar steve-m avatar sultanqasim avatar vogelchr avatar willglynn avatar yarda avatar zaitcev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

librtlsdr's Issues

Memory leak in rtlsdr_open() of librtlsdr.c

Calling rtlsdr_open() on an index that is already opened by another rtlsdr device causes a memory leak.

When

r = libusb_claim_interface(dev->devh, 0);

fails @ line 1520 of librtlsdr.c, the memory space opened by libusb (@ line 1488)

dev->devh 

is never closed/freed by the code in the err tag.

This causes a memory leak when a second rtlsdr device is opened at the same index as another one that was succesfully opened.

Trying to call

"rtlsdr_close()"

when rtlsdr_open() fails does not fix the problem because if this happens, the device handle given by rtlsdr_open() is invalid. Therefore, "rtlsdr_close()" has no way of freeing that memory space.

Proposed fix:
changing this at line 1520 of librtlsdr.c:

r = libusb_claim_interface(dev->devh, 0);
if (r < 0) {
	fprintf(stderr, "usb_claim_interface error %d\n", r);
	goto err;
}

for

r = libusb_claim_interface(dev->devh, 0);
if (r < 0)
 {
	fprintf(stderr, "usb_claim_interface error %d\n", r);
	if (dev) 
	{
        	libusb_close(dev->devh);
	}
	goto err;
}

Will ensure that the dev->devh that is dynamically allocated is freed if a claim error occurs.

Edit1: added a short paragraph at the top of the comment.

Edit2: created pull request #50 fixing the problem.

Is this library unmaintained?

It seems that although there was an update to a couple of files two months ago, Almost nothing has happened with this code base for 3 years, and there are a lot of issues and pull requests which just look to be being ignored.

Support of more than 4 dongles

it seems that the library supports only 4 parallel transmitting dongles at the moment. If the fifth dongle is added and started to transfer data, e.g. rtl_test -d 4, the error message appears:
"Failed to submit transfer 3!"
"Library error -5, exiting..."

libusb is 1.0.21 (also tested with 1.0.19)

sdr_trunk is working fine on the same computer and supports at least 5 dongles.

USB Claim Interface Error #6

I use Linux and librtlsdr, and i got these error.
i fixed it by adding
libusb_detach_kernel_driver(dev->devh, 0);
before
r = libusb_claim_interface(dev->devh, 0);

thanks for this software!

rtlsdr_close freezing in latest windows build

I noticed an error when using the latest 32-bit 2019/07/14 windows build from here:

https://ftp.osmocom.org/binaries/windows/rtl-sdr/

Calling rtlsdr_close just blocks/freezes indefinitely. On program exit I'm calling rtlsdr_cancel_async (successful), then joining the sampling thread (successful), then calling rtlsdr_close (freezes).

This was not a problem with the old "RelWithDebInfo" version of this library (built on 2014/1/24).

rtl_power , frequency reporting when using upconverter

Hi,
rtl_power needs an option for reporting upconverted (and downconverted) frequencies.
i.e. My upconverter adds 125Mhz. It would be nice to see corrected values in the output.
I do scans and heatmaps etc and I hate to edit csv manually every time.
Thanks.
Tom.

rtl_sdr stops writing at 2GiB-1Byte under a 32bit OS

I created a filesystem with "mkfs.ext3 -b 4096 -L ext3 /dev/sda1" which should allow a maximum file size of 2TiB. I created a 4GB file with "dd if=/dev/urandom of=testfile bs=65536 count=65536" to confirm that the OS had no problem writing a file larger than 2GiB-1Byte, and it does not.

Eventually I found this link:
https://stackoverflow.com/questions/730709/2gb-limit-on-file-size-when-using-fwrite-in-c

So can this flag be added "-D_FILE_OFFSET_BITS=64" if the source is compiled on ARM architecture.
I did a basic test by adding "#define _FILE_OFFSET_BITS 64" to the very top of librtlsdr/src/rtl_sdr.c and it works correctly (it no longer stops writing to file after 2147483647 bytes).

I would submit a patch, but i have no idea how to create cmake files.

R820T2 not receiving signals if LOOP_THROUGH is ON

I’m involved in an ADS-B project that use librtlsdr now at v0.5.4 and at this point I have a problem when initialising my receiver.

I found that when the function r82xx_set_tv_standard() is called, some R820T2 registers are programmed and I receive nothing on the RF signal chain. But, if I change this function to return (return rc;) just before the "need_calibration = 1;”, skipping all the rest of the function, then my receiver works properly.

My hardware is based on the RTL2382U and R820T2. I already had another hardware working properly. I made some investigations on my own to figure out if something on the PCB layout could be the problem. It is a 6 LAYER PCB because it is attached to the main CPU (everything is on the same board). I also have a small dongle (alone with no CPU part) and with this exact problem. Also with same PCB specifications.

I ran several tests around librtlsdr at function r82xx_set_tv_standard() and concluded that the LOOP_THROUGH ON/OFF (register 0x05 mask 0x80) and LOOP_THROUGH_ATTENUATION (register 0x1F mask 0x80 - not documented) at R820T chip have direct impact on our dongle functionality.

   If I comment these function calls everything works properly.

###CUT FROM tuner_r82xx.c source code###

/* rc = r82xx_write_reg_mask(priv, 0x05, loop_through, 0x80);
if (rc < 0)
{
printf("Return at Loop Through\n");
return rc;
}/
/
Loop through attenuation /
/
rc = r82xx_write_reg_mask(priv, 0x1f, lt_att, 0x80);
if (rc < 0)
{
printf("Return at Loop_Through Attenuation.\n");
return rc;
}*/

###END OF CUT###

If I keep this LOOP off, our dongle starts to receive signals immediately and works properly. Looks like our PCB with 6 copper layers and substrate with only 0.2mm thickness have impact in this feature but we cannot get rid of it because all HW is on same PCB.

So, my question is if you can add this new feature to your LIB to give developers the option to switch LOOP_THROUGH ON or OFF to deal with this.

I know that for years, since the development started, many new features and improvements have been made. Would you consider it? Our goal is to help improve and to keep using standard librtlsdr, not a modified version.

Thanks for your support. I would also like to ear some feedback from other users to understand if my thoughts are correct.

Regards.
Rodrigo Matias

Pull in Keenerd's improvements?

Hi,
There are a couple of improvements by @keenerd documented here: https://www.reddit.com/r/RTLSDR/comments/2cix12/improvements_to_hopping_and_filters_testing/ and used in other projects that depend on librtlsdr. Since this repo is used for OSX homebrew, those changes are not available to homebrew users. This breaks other projects that depend on these changes; Kalibrate-rtl as an example:

 ~/d/b/kalibrate-rtl  ❯ make clean all
Making clean in src
test -z "kal" || rm -f kal
rm -f *.o
make[1]: Nothing to be done for `clean-am'.
/Library/Developer/CommandLineTools/usr/bin/make  all-recursive
Making all in src
g++ -DHAVE_CONFIG_H -I. -I..    -I/usr/local/Cellar/fftw/3.3.4_1/include -I/usr/local/Cellar/librtlsdr/0.5.3/include/ -I/usr/local/Cellar/libusb/1.0.20/include/libusb-1.0 -g -O2 -MT kal-arfcn_freq.o -MD -MP -MF .deps/kal-arfcn_freq.Tpo -c -o kal-arfcn_freq.o `test -f 'arfcn_freq.cc' || echo './'`arfcn_freq.cc
......
.....
g++ -DHAVE_CONFIG_H -I. -I..    -I/usr/local/Cellar/fftw/3.3.4_1/include -I/usr/local/Cellar/librtlsdr/0.5.3/include/ -I/usr/local/Cellar/libusb/1.0.20/include/libusb-1.0 -g -O2 -MT kal-usrp_source.o -MD -MP -MF .deps/kal-usrp_source.Tpo -c -o kal-usrp_source.o `test -f 'usrp_source.cc' || echo './'`usrp_source.cc
usrp_source.cc:153:17: error: use of undeclared identifier 'rtlsdr_set_dithering'
        return (bool)(!rtlsdr_set_dithering(dev, (int)enable));
                       ^
1 error generated.
make[2]: *** [kal-usrp_source.o] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

Please pull in the changes and create a release tag.

Thanks

int.d scripts for rtl-tcp

Ive used rtl-tcp for a long time in the command. I dont like tending the rtl-tcp in command-line on each RPI I run it on. I recently set dump 1090 to run as a int.d script, it keeps it going when im not around. So I thought ... why can I do this with the rtl-tcp. I use sdr#, GHPSDR3, GRC to connect to RPI nodes in remote locations, rtl-tcp dosnt always exit cleanly it gets worse with a -4 and that requires a REBOOT. I dont see, that the LibSDR programs are written to report different exit variables in a manner that I can write case for an int.d script. Im trying to keep rtl-tcp running. Some crashes are complicated like -4 with the kernel module fail, I can just rerunning the command.

Any Ideas or help to stream line the programs for a int.d scripts.

73 Mathison kj6dzb

Support for RTL-SDR Blog v4

Copied and edited from here: f4exb/sdrangel#1783

Recently RTL-SDR Blog V4 was released (https://www.rtl-sdr.com/rtl-sdr-blog-v4-dongle-initial-release/) which is based on the R828D tuner chip. But the hardware is slightly different as it uses a different LO frequency for the R828D compared to what is hardcoded in the drivers, and the RF inputs need to be switched in a different way.

A fork of the Osmocom drivers were created here https://github.com/rtlsdrblog/rtl-sdr-blog-minimal, and a more heavily modified one here with other unrelated changes https://github.com/rtlsdrblog/rtl-sdr-blog. These repo's were modified to add support for the V4, and the -minimal fork has the minimal amount of changed to make it work

A patch to has been submitted to Osmocom and has been upstreamed.

The forked drivers continue to support older RTL-SDRs and other brands/generic models too, nothing has been removed.

Any chance we could merge and bump the tags so homebrew would get updated?

Enhancement Request: Add tuner driver for MxL603/MxL608

There has been a considerable discussion in the past couple of days about a device called the Tzumi MagicTV. This is an Atheros-chipset OpenWRT device connected to an RTL2832P, which seems to be used as a bridge/DAC for a MaxLinear MxL608 tuner and a Panasonic ATSC demodulator.

The device is sold at Wal-Mart stores for $13, and is intended to allow the user to view OTA broadcasts using a WiFi connection to the device, which functions as an access point by default. There also seems to be an Eardatek Tevemo device which is similar.

From tear-down inspection as well as poking around the file system, some uses have concluded that the device could be used as a software defined radio with some software modifications (for example replacing the default ATSC server software with rtl_tcp). However, librtlsdr does not currently support the MxL608 tuner, and right now rtl_tcp (when placed on the openWRT device) defaults to direct sampling mode.

There is a general sense in these discussion groups that MaxLinear's source code could be ported to work with librtlsdr, but someone would have to make that happen.

  1. RTL-SDR.com blog: https://www.rtl-sdr.com/tzumi-magictv-wifi-tv-tuner-device-contains-an-rtl-sdr-openwrt-board-and-battery-for-only-13/

  2. Reddit RTLSDR group: https://www.reddit.com/r/RTLSDR/comments/8mlbps/tzumi_magictv_is_an_openwrt_board_rtlsdr/

  3. Existing code: https://github.com/avlogic/AVL6862/tree/master/2.10.7/tuner/MxL608

  4. MxL608 data sheet: https://datasheet.lcsc.com/szlcsc/MXL608-AG-T_C141783.pdf

OpenELEC

Hi
How to install it OpenELEC?

Faster retune possible

Hi All,

I have a requirement for a faster retune in synchronous, direct sampling mode - which involves

  1. change of frequency
  2. change of sample rate

I am looking at creating a modified version of rtl_sdr, nothing else changes, and there are only 2 datasets I am interested in switching between
Mode 1: FreqA, SampleRateA
Mode 2: FreqB, SampleRateB
When performing the switch I send the data down 1 of 2 different fifo's which have decoders listening for data.

By making calls to the API routines under a high performance Linux OS macine, it seems that the total time to call both routines in succession, is in the order of 100ms
This is quite long, and I noticed that when calling these routines I am guessing a number of housekeeping side effect such as reading back registers, and applying soft reset is undertaken

So my question is, could I optimize these two calls into a single call, in order to not repeat some actions taken in both calls. In my application, speed is of the absolute essence, and clawing back a few ms will make all the difference.

I am happy to change/create (new wrapper) functions myself, but I can find no underlying documentation, which describes what actions are being taken and why, so I am concerned I could break something I do not understand whilst trying to optimize the call for freq & samplerate change

Any help or pointers, greatly appreciated

Thx
Lee

Releasing a new more up-to-date version

Since most packaging system are pointing to official release (Example: homebrew is pointing to 0.5.3).

But right now, 0.5.3 is almost 3 years old.

That would be awesome if someone could release 0.5.4, ideally having a release that would include support for rtlsdr_set_tuner_bandwidth.

thanks

freq_correction reduces sampling frequncy below minimum

If I set the sampling rate to minimum (225001Hz) with rtlsdr_set_sample_rate() and also set an frequency correction of say 25ppm with rtlsdr_set_freq_correction() then there are glitches in the sampling.

I think this is because of the applied frequency correction. It leads to an sampling rate below the allowed minimum or something.

225001Hz - no frequency correction
no_ppm

225001Hz - 25ppm
ppm

Here you can see the periodic higher and lower intesity which is not correct. This is what I mean by "glitching".

OSX `Undefined symbols for architecture x86_64`

Hi there, I'm on OSX 10.12.6 Sierra and I'm having issues running librtlsdr as installed from homebrew. I've included the header file (#include "rtl-sdr.h") but when trying to compile (e.g. g++ test.cpp) I get the following error:

Undefined symbols for architecture x86_64:
  "_rtlsdr_get_device_count", referenced from:
      _main in test-1965f4.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

This error happens for every rtlsdr_{whatever} function I try to call.

I've tried using other librtlsdr repos, thinking other people maybe fixed the issue, but so far no luck. Since this is the default version included with homebrew I thought I'd post this here and see if anyone else is running into this issue or has a workaround or fix for it.

Corrupt descriptors.

I do not understand how it is possible to pass an S64 into a function expecting a U32, without even getting a compiler warning, but it seems to be bad.

Symptoms: corrupt descriptor when launching rtl_fm on 64bit (scientific linux 7)

Hint: 9e23e72

recipe for target 'src/CMakeFiles/rtl_tcp.dir/rtl_tcp.c.o' failed

make produces the following...i have tried the main and mirror to see if there was a difference....
running raspian, the same instructions worked before...however im stuck in my tracks with this one

Scanning dependencies of target convenience_static
[ 5%] Building C object src/CMakeFiles/convenience_static.dir/convenience/convenience.c.o
Linking C static library libconvenience_static.a
[ 5%] Built target convenience_static
Scanning dependencies of target rtlsdr_shared
[ 10%] Building C object src/CMakeFiles/rtlsdr_shared.dir/librtlsdr.c.o
[ 15%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_e4k.c.o
[ 20%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_fc0012.c.o
[ 25%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_fc0013.c.o
[ 30%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_fc2580.c.o
[ 35%] Building C object src/CMakeFiles/rtlsdr_shared.dir/tuner_r82xx.c.o
Linking C shared library librtlsdr.so
[ 35%] Built target rtlsdr_shared
Scanning dependencies of target rtl_adsb
[ 40%] Building C object src/CMakeFiles/rtl_adsb.dir/rtl_adsb.c.o
Linking C executable rtl_adsb
[ 40%] Built target rtl_adsb
Scanning dependencies of target rtl_eeprom
[ 45%] Building C object src/CMakeFiles/rtl_eeprom.dir/rtl_eeprom.c.o
Linking C executable rtl_eeprom
[ 45%] Built target rtl_eeprom
Scanning dependencies of target rtl_fm
[ 50%] Building C object src/CMakeFiles/rtl_fm.dir/rtl_fm.c.o
Linking C executable rtl_fm
[ 50%] Built target rtl_fm
Scanning dependencies of target rtl_power
[ 55%] Building C object src/CMakeFiles/rtl_power.dir/rtl_power.c.o
Linking C executable rtl_power
[ 55%] Built target rtl_power
Scanning dependencies of target rtl_sdr
[ 60%] Building C object src/CMakeFiles/rtl_sdr.dir/rtl_sdr.c.o
Linking C executable rtl_sdr
[ 60%] Built target rtl_sdr
Scanning dependencies of target rtl_tcp
[ 65%] Building C object src/CMakeFiles/rtl_tcp.dir/rtl_tcp.c.o
/home/davinci/librtlsdr/src/rtl_tcp.c:28:23: fatal error: arpa/inet.h: No such file or directory
compilation terminated.
src/CMakeFiles/rtl_tcp.dir/build.make:54: recipe for target 'src/CMakeFiles/rtl_tcp.dir/rtl_tcp.c.o' failed
make[2]: *** [src/CMakeFiles/rtl_tcp.dir/rtl_tcp.c.o] Error 1
CMakeFiles/Makefile2:355: recipe for target 'src/CMakeFiles/rtl_tcp.dir/all' failed
make[1]: *** [src/CMakeFiles/rtl_tcp.dir/all] Error 2
Makefile:113: recipe for target 'all' failed
make: *** [all] Error 2

Multi-use of rtl_tcp

To allow the running of more than one program using the stick, it would be nice when rtl_tcp could accept connections from more than one client in parallel. Of course it should honour settings only from one of the clients (the first?). rtl_tcp should just send the captured data to all connected clients.

Furthermore, it would be nice when rtl_fm could connect to rtl_tcp as well.
With the above, it should be possible to run multiple copies of rtl_fm demodulating different signals in the same band.

PLL exact frequency alignment

R820 devices (ex. R820T2) cannot be tuned on an exact frequency. There is a gap between the real center frequency and the requested frequency (ex. @144mhz : diff +189Hz, +62Hz, +183Hz, +62Hz...)

I suspect an approximation error within r82xx_set_pll function (tuner_r82xx.c file).

Return value of 'get_tuner_gain' if gain value is 0

The comments for rtlsdr_get_tuner_gain state that a return value of 0 is an error, but what would be an appropriate return value if the tuner gain is actually set to 0?

I have checked to see if this is a valid gain setting, and "0" is in the list of values returned by the 'get_tuner_gains' function with my RTL2832.

Could this possibly be a documentation issue, or does "0" definitely indicate an error?

Any way to not compile /bin/ programs when using make install?

I am trying to compile this library to WASM but the /bin/ programs (rtl_tcp, rtl_test, etc) in the sysroot are causing compilation errors because the LD flags are configured incorrectly for wasm
is there a way to skip the build step and only produce the header and library files with no test binaries?

Many thanks

Not recognised via USB Server

My RTL SDR usb sticks (3x) are positioned relatively far away from my computer. USB hubs and longer cable are giving problems. So I tried USB via LAN, but it didn't work. I tried:

  1. USB Redirector Server on Linux and Windows client. Was able to install the drivers via Zadig but SDR# didn't recognise the device.
  2. A hardware device Sharkoon USB LANPORT 400. Same problem, my computer recognizes the stick, can install the driver via Zadig, but no luck with SDR#.

The I suspected SDR#, so I debugged the code and concluded that the problem is within rtlsdr.dll / libusb-1.0.dll. I tested it with rtl_test.exe to rule out SDR#. rtl_test.exe also didn't recognise the usb sticks.

Tested it with the E4000 device. Device is recognised as VID_0CCD&PID_00D7 via both the sharkoon and usb redirector.

I am also experiencing the same problem when I use the rtl device via my NEC USB3.0 hub.

It would be nice if this problem could be fixed so I can use a long lan cable instead of usb cables.

64 bit - fix casts

add compile switch
-Werror=pointer-to-int-cast
-Werror=int-to-pointer-cast
-Werror=shorten-64-to-32

and compile to see result

Read async implementation

Hello,
I´m trying to create asynchronous read data from rtl-sdr. I use sample rate 2Mhz, but this case what I push doesn´t work (Throw Exception), I would like to read data without lost samples.
I whould like to ask for some help or write example with comments. I saw at rtl_adbc.c where I wound this type of solution.

`static pthread_cond_t ready;
static pthread_mutex_t ready_m;

//Shared Global Memory
uint8_t mem1[100000], mem2[50000];

//Lock for read and write
pthread_mutex_t mem1Lock = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t mem2Lock = PTHREAD_MUTEX_INITIALIZER;

BOOL end;

static void* saveData()
{
FILE *output;
output = fopen("D:\black\zkouska.dat", "w");

while (!end) {
	//pthread_mutex_lock(&mem1Lock);
	pthread_cond_wait(&ready, &ready_m);

	for (int i = 0; i < 100000; i += 2)
		fprintf(output, "%d\n%d\n", mem1[i], mem1[i+1]);

	/*pthread_mutex_unlock(&mem1Lock);


	pthread_mutex_lock(&mem2Lock);

	for (int i = 0; i < 50000; i += 2)
		fprintf(output, "%d\n%d\n", mem2[i], mem2[i + 1]);

	pthread_mutex_unlock(&mem2Lock);*/
}

fclose(output);
return NULL;

}

void* readData(rtlsdr_dev_t *dev)
{
int read;

while (!end) {
	pthread_mutex_lock(&mem1Lock);
	rtlsdr_read_sync(dev, mem1, 50000, &read);
	pthread_mutex_unlock(&mem1Lock);


	pthread_mutex_lock(&mem2Lock);
	rtlsdr_read_sync(dev, mem2, 50000, &read);
	pthread_mutex_unlock(&mem2Lock);
}
return NULL;

}

static void getData(unsigned char *buf, uint32_t len, void *ctx)
{
//pthread_mutex_lock(&mem1Lock);
memcpy(mem1, buf, len);
pthread_cond_signal(&ready);
/*pthread_mutex_unlock(&mem1Lock);

pthread_mutex_lock(&mem2Lock);
memcpy(mem2, buf, len);
pthread_mutex_unlock(&mem2Lock);*/

}

void test(rtlsdr_dev_t *dev, double time)
{
pthread_t threadRead, threadWrite;
int rc; end = FALSE;
pthread_cond_init(&ready, NULL);
pthread_mutex_init(&ready_m, NULL);

/*rc = pthread_create(&threadRead, NULL, readData, dev);
if (rc) {
	printf("ERROR; return code from pthread_create() is %d\n", rc);
	exit(-1);
}*/

rtlsdr_reset_buffer(dev);

rc = pthread_create(&threadWrite, NULL, saveData, (void *) NULL);
if (rc) {
	printf("ERROR; return code from pthread_create() is %d\n", rc);
	exit(-1);
}
rtlsdr_read_async(dev, getData, (void *)NULL, 12, 100000);


Sleep(time);

end = TRUE;
rtlsdr_cancel_async(dev);
//pthread_join(threadRead, NULL);
//pthread_join(threadWrite, NULL);

}
`

Thanks for any help

librtlsdr shouldn't output to standard error

The library outputs to standard error via fprintf() calls throughout librtlsdr.c. For a library, this isn't best practice since it can interfere with command line programs. For example, I've run into this issue while prototyping using pyrtlsdr. There seems to be three possible solutions to this:

  • Remove all fprintf() calls in librtlsdr.c. This is the easiest solution, but it makes debugging programs more difficult without the error information.
  • Refactor the API so the error information is reflected via the API rather than via standard error. This is hard and will break the API.
  • Replace all fprintf() calls in librtlsdr.c with a function that only outputs to standard error when the API consumer turns on debug mode. This is a middle ground between the two above. It doesn't break the API, but it adds more kludge.

Bias-Tee option in rtl_sdr utility

It looks like the enable bias-tee option has been in added in every command-line utility except for rtl_sdr! Is there a reason for this? Just an oversight?
I find the rtl_sdr utility very useful as a way of easily extracting samples out of a RTLSDR for piping into other processes.

Print local time with the -e option

Enhancement: It would be useful for long runs if rtl_power printed the local time when invoked with the -e option. Something like Started at DD:HH:MM would be great.

Dongle hangs detection

I have RTL2838 based dongle that hangs very often. rtl_433 detects this and exits with the message: Async read stalled, exiting!
rtl_sdr waits for a response from the dongle and does not exit:

rtl_sdr -f 868.95M -s 1.6M -
Found 1 device(s):
  0:  astrometadvbt2, dvbt2, SN: 

Using device 0: Astrometa DVB-T/DVB-T2
Found Rafael Micro R828D tuner
[R82XX] PLL not locked!
Sampling at 1600000 S/s.
Tuned to 868950000 Hz.
Tuner gain set to automatic.
Reading samples in async mode...

Is there a chance to implement a similar functionality?

Usbreset application is able to properly reset dongle: https://marc.info/?l=linux-usb&m=121459435621262&w=2
Is it possible to implement usbreset code inside rtl_sdr?

segfault on insufficient privileges on /dev/bus/usb

In rtl_433's version of librtlsdr there is a bug that is triggered when the permissions on /dev/bus/usb are insufficient. If permissions are insufficient libusb_init will fail with error code -99 (LIBUSB_ERROR_OTHER), however librtlsdr does not check the return value of libusb_init, thus a subsequent call can segfault (e.g. this would also happen at https://github.com/steve-m/librtlsdr/blob/master/src/librtlsdr.c#L1267-1269 but more locations in librtlsdr follow this patters and migh trigger a segfault).

Although the cause is insufficient permissions on /dev/bus/usb, librtlsdr could probably handle this in a more gracefull way?)

See also merbanan/rtl_433#72 for an example of this issue. As mentioned rtl_433 uses an older version of librtlsdr, but the pattern that leads to the issue is the same in this version

Version mix up of Raspbian and Debain package

Hi,
I'm stuck at a rather strange problem regarding an installation on raspbian and plain debain 10:

On raspbian I have rtl-sdr 0.5.3-11 installed which features the udp frequency retuning option by opening an udp socket.
On my Debian 10 machine I have version 0.6.1 installed which does not feature this option. So are these packages from different repos or git branches? And how can I get the udp functionality on my Debian 10 machine?

I tried to look for any answers but I'm unable to find the sourcecode/changelog of the raspbian version which features the udp socket.

Regards
Joshua

rtlsdr_read_async never finishing

I'm using librtlsdr (via the pyrtlsdr wrapper), and I'm having an issue with rtlsdr_read_async never returning after calling rtlsdr_cancel_async. Stepping through with gdb, it looks like on lines 1689-1690, dev->xfer[i]->status remains at LIBUSB_TRANSFER_COMPLETED forever. I don't receive any further callbacks after calling rtlsdr_cancel_async.

Any ideas?

This is my Python code:

def readSamples(sdr):
  q = Queue()

  def samplesAvailableCallback(data, context):
    q.put(data)

  def startReading():
    sdr.read_samples_async(samplesAvailableCallback, samplesPerRead)

  thread = start_new_thread(startReading, ())

  try:
    while True:
      yield q.get(block=True)
  finally:
    sdr.cancel_read_async()

Mac OS Ventura 13.0.1 M1 - librtlsdr issue

I am trying to run a script rtl-sdr-close-call-monitor and I'm having trouble getting the dependencies working on my M1 Mac. I have installed all of the dependencies via numpy, playsound, pyrtlsdr, and requests via PIP3 and librtlsdr via brew. When I run the script, I get this error:
Traceback (most recent call last): File "/Users/charlesmelidosian/Documents/programming/rtl-sdr/freq-monitor/close-call/monitor_with_sound.py", line 4, in <module> from rtlsdr import RtlSdr File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/rtlsdr/__init__.py", line 56, in <module> from .librtlsdr import librtlsdr File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/rtlsdr/librtlsdr.py", line 52, in <module> librtlsdr = load_librtlsdr() ^^^^^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/rtlsdr/librtlsdr.py", line 47, in load_librtlsdr raise ImportError('Error loading librtlsdr. Make sure librtlsdr '\ ImportError: Error loading librtlsdr. Make sure librtlsdr (and all of its dependencies) are in your path

From my research, I need to add /usr/local/lib to $LD_LIBRARY_PATH and to $PATH, which I've done. Still, I get the same error. Checking in that directory, I have the following files:
la /usr/local/lib total 5936 [... unrelated files ...] -rwxr-xr-x@ 1 root wheel 51K May 24 21:03 librtlsdr.0.0.0.dylib -rwxr-xr-x@ 1 root wheel 51K May 24 21:03 librtlsdr.0.dylib -rwxr-xr-x@ 1 root wheel 51K May 24 21:03 librtlsdr.dylib -rwxr-xr-x 1 root wheel 2.5M Oct 18 2021 libsdrpp_core.dylib -rwxr-xr-x@ 1 root wheel 72K May 24 21:03 libusb-1.0.0.dylib

So I know I have the library file installed, and the path to the library is in both environment variables. Checking the librtlsdr.py library script I know that the driver is loaded with this code:
`def load_librtlsdr():
if sys.platform == "linux" and 'LD_LIBRARY_PATH' in os.environ.keys():
ld_library_paths = [local_path for local_path in os.environ['LD_LIBRARY_PATH'].split(':') if local_path.strip()]
driver_files = [local_path + '/librtlsdr.so' for local_path in ld_library_paths]
else:
driver_files = []
driver_files += ['librtlsdr.so', 'rtlsdr/librtlsdr.so']
driver_files += ['rtlsdr.dll', 'librtlsdr.so', 'librtlsdr.dylib']
driver_files += ['..//rtlsdr.dll', '..//librtlsdr.so']
driver_files += ['rtlsdr//rtlsdr.dll', 'rtlsdr//librtlsdr.so']
driver_files += [lambda : find_library('rtlsdr'), lambda : find_library('librtlsdr')]
dll = None

for driver in driver_files:
    if callable(driver):
        driver = driver()
    if driver is None:
        continue
    try:
        dll = CDLL(driver)
        break
    except:
        pass
else:
    raise ImportError('Error loading librtlsdr. Make sure librtlsdr '\
                      '(and all of its dependencies) are in your path')
return dll

librtlsdr = load_librtlsdr()`

If I run this excerpt in Python, I can reproduce the error. I modified the script it to remove the try/except and error message, I get this:
Traceback (most recent call last): File "/Users/charlesmelidosian/Documents/programming/rtl-sdr/freq-monitor/libsdrtest.py", line 42, in <module> librtlsdr = load_librtlsdr() ^^^^^^^^^^^^^^^^ File "/Users/charlesmelidosian/Documents/programming/rtl-sdr/freq-monitor/libsdrtest.py", line 31, in load_librtlsdr dll = CDLL(driver) ^^^^^^^^^^^^ File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/ctypes/__init__.py", line 376, in __init__ self._handle = _dlopen(self._name, mode) ^^^^^^^^^^^^^^^^^^^^^^^^^ OSError: dlopen(/usr/local/lib/librtlsdr.dylib, 0x0006): tried: '/usr/local/lib/librtlsdr.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/lib/librtlsdr.dylib' (no such file), '/usr/local/lib/librtlsdr.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))

From that error, I know that it's an architecture issue with the library (have 'x86_64', need 'arm64') - but this is where I'm stuck. I have looked into compiling the library but have not been successful. When I try to compile it from source, I get this error:
[ 3%] Linking C shared library librtlsdr.dylib ld: library not found for -lusb-1.0 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[2]: *** [src/librtlsdr.0.6git.dylib] Error 1 make[1]: *** [src/CMakeFiles/rtlsdr.dir/all] Error 2 make: *** [all] Error 2

I read another issue that instructed me to use the make command make LIBRARY_PATH=/usr/local/lib, but I get the same error as before. As you can see from above, the libusb-1.0.0.dylib library file is present in /usr/local/lib

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.