Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found