in reply to help with XS pointers
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: help with XS pointers
by Bpl (Scribe) on Jul 31, 2020 at 12:19 UTC | |
by bliako (Monsignor) on Jul 31, 2020 at 12:46 UTC | |
by Bpl (Scribe) on Jul 31, 2020 at 12:58 UTC | |
by bliako (Monsignor) on Jul 31, 2020 at 13:07 UTC |
In Section
Seekers of Perl Wisdom