After you posted more code, I can see that:
const char * rtlsdr_get_device_name(index) uint32_t index
And so this:
my $device = rtlsdr_get_device_name( $index );returns the device name as a string, given device index (integer), and not a pointer to a rtlsdr_dev_t structure as you assumed.
Given:
int rtlsdr_open(dev, index) SDR::RTLSDR **dev uint32_t index
I am guessing that one must open a device by specifying the index. The function rtlsdr_open() should probably return the status as an integer and allocates internally the device, that's what I assume when it tells you to supply the double pointer for device: "Give me a memory location and I will do the internal decoration".
Here is a stand-alone C example to demonstrate this pattern:
#include <stdio.h> #include <malloc.h> typedef struct { int a; } s_t; int open_device(s_t **dev, int index); int main(void){ s_t *device = NULL; open_device(&device, 1); printf("A=%d\n", device->a); free(device); } int open_device(s_t **dev, int index){ *dev = (s_t *)malloc(sizeof(s_t)); (*dev)->a = 42; return 1; }
How does that translate to Perl? Hmmm again a guess:
my $serial_number = "00000001"; # from dmesg output my $index = rtlsdr_get_index_by_serial( $serial_number ); # it returns + 0, this is not an error value so I think is good my $name = rtlsdr_get_device_name( $index ); print "device name '$name'\n"; my $device = undef; # = SDL::...->new() ??? # i don't think so/how? my $status = rtlsdr_open( \$device , $index) print "status $status for index $index\n";
cool project!
bw, bliako
In reply to Re: help with XS pointers
by bliako
in thread help with XS pointers
by Bpl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |