Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: help with XS pointers

by syphilis (Archbishop)
on Jul 31, 2020 at 02:24 UTC ( [id://11120109]=note: print w/replies, xml ) Need Help??


in reply to help with XS pointers

If you're having trouble with the basic functionality, I would recommend that you get that basic functionality of your code sorted out and tested in an Inline::C script before you even write SDR::RTLSDR.
That's an approach that has always worked quite well for me.

It also means that you can provide a script that shows everything you're trying to do.
It's pretty hard to work out exactly what you're doing from a few snippets.

I assume your module will link to the librtlsdr library, and I'm wondering why your XS code appears to be creating/declaring its own rtlsdr_open() when that function is already (presumably) provided by that library and the librtlsdr header.

Anyway, for an Inline::C script, you'd want something like:
use strict; use warnings; use Inline C => Config => #CLEAN_AFTER_BUILD => 0, # BUILD_NOISY => 1, # display the compilation inc => '-I/path/to/librtlsdr_headers', libs => '-L/path/to/librtsldr_library, ; use Inline C => <<'EOC'; #include<librtlsdr_header.h> void foo(<args>) { /* do something that uses librtlsdr and print out a success/fail message */ } void bar(<args>) { /* do something else that uses librtlsdr and print out a success/fail message */ } EOC foo(); bar();
Add more functionality and complexity as you get things working.
Inline::C provides typemapping and just about everything else that XS provides. (See the Inline::C documentation and cookbook.)

In the code section, you're essentially just writing C code - but perl API functions can also be used.

Inline::C works by first creating an XS file, which you can find in the ./_Inline directory if you include CLEAN_AFTER_BUILD in the Config section of the script before building.

Cheers,
Rob

Replies are listed 'Best First'.
Re^2: help with XS pointers
by Bpl (Scribe) on Jul 31, 2020 at 09:52 UTC
    OK, no problem. The xs code is as follows:
    #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include <rtl-sdr.h> typedef rtlsdr_dev_t * SDR__RTLSDR; MODULE = SDR::RTLSDR PACKAGE = SDR::RTLSDR PROTOTYPES: DISABLE const char * rtlsdr_get_device_name(index) uint32_t index int rtlsdr_get_device_usb_strings( index, manufact, product, serial) uint32_t index char *manufact char *product char *serial int rtlsdr_get_index_by_serial(serial) const char *serial int rtlsdr_open(dev, index) SDR::RTLSDR **dev uint32_t index int rtlsdr_close(dev) SDR::RTLSDR *dev int rtlsdr_set_xtal_freq(dev, rtl_freq, tuner_freq) SDR::RTLSDR *dev uint32_t rtl_freq uint32_t *tuner_freq int rtlsdr_get_xtal_freq(dev, rtl_freq, tuner_freq) SDR::RTLSDR *dev uint32_t *rtl_freq uint32_t *tuner_freq int rtlsdr_get_usb_strings(dev, manufact, product, serial) SDR::RTLSDR *dev char *manufact char *product char *serial int rtlsdr_write_eeprom(dev, data, offset, len) RTLSDRDevice_T *dev uint8_t *data uint8_t offset uint16_t len int rtlsdr_read_eeprom(dev, data, offset, len) SDR::RTLSDR *dev uint8_t *data uint8_t offset uint16_t len int rtlsdr_set_center_freq(dev, freq) SDR::RTLSDR *dev uint32_t freq uint32_t rtlsdr_get_center_freq(dev) SDR::RTLSDR *dev int rtlsdr_set_freq_correction(dev, ppm) SDR::RTLSDR *dev int ppm int rtlsdr_get_freq_correction(dev) SDR::RTLSDR *dev int rtlsdr_get_tuner_gains( dev, gains ) SDR::RTLSDR *dev int *gains int rtlsdr_set_tuner_gain(dev, gain) SDR::RTLSDR *dev int gain int rtlsdr_set_tuner_bandwidth(dev, bw) SDR::RTLSDR *dev uint32_t bw int rtlsdr_get_tuner_gain(dev) SDR::RTLSDR *dev int rtlsdr_set_tuner_if_gain(dev, stage, gain) SDR::RTLSDR *dev int stage int gain int rtlsdr_set_tuner_gain_mode(dev, manual) SDR::RTLSDR *dev int manual int rtlsdr_set_sample_rate(dev, rate) SDR::RTLSDR *dev uint32_t rate uint32_t rtlsdr_get_sample_rate(dev) SDR::RTLSDR *dev int rtlsdr_set_testmode(dev, on) SDR::RTLSDR *dev int on int rtlsdr_set_agc_mode(dev, on) SDR::RTLSDR *dev int on int rtlsdr_set_direct_sampling(dev, on) SDR::RTLSDR *dev int on int rtlsdr_set_offset_tuning(dev, on) SDR::RTLSDR *dev int on int rtlsdr_get_offset_tuning(dev) SDR::RTLSDR *dev int rtlsdr_reset_bufferrtl(dev) SDR::RTLSDR *dev int rtlsdr_read_sync(dev,buf,len, n_read); SDR::RTLSDR *dev void *buf int len int *n_read
    while the TYMAP file is:
    TYPEMAP RTLSDRDevice_T * T_PTROBJ SDR::RTLSDR T_PTROBJ const char * T_PV int * T_PV char * T_PV unsigned long int T_U_LONG uint8_t T_U_SHORT uint8_t * T_U_SHORT uint16_t T_U_SHORT uint32_t * T_U_SHORT uint32_t T_U_SHORT
    the library code is:
    #ifndef __RTL_SDR_H #define __RTL_SDR_H #ifdef __cplusplus extern "C" { #endif #include <stdint.h> #include <rtl-sdr_export.h> typedef struct rtlsdr_dev rtlsdr_dev_t; RTLSDR_API uint32_t rtlsdr_get_device_count(void); RTLSDR_API const char* rtlsdr_get_device_name(uint32_t index); /*! * Get USB device strings. * * NOTE: The string arguments must provide space for up to 256 bytes. * * \param index the device index * \param manufact manufacturer name, may be NULL * \param product product name, may be NULL * \param serial serial number, may be NULL * \return 0 on success */ RTLSDR_API int rtlsdr_get_device_usb_strings(uint32_t index, char *manufact, char *product, char *serial); /*! * Get device index by USB serial string descriptor. * * \param serial serial string of the device * \return device index of first device where the name matched * \return -1 if name is NULL * \return -2 if no devices were found at all * \return -3 if devices were found, but none with matching name */ RTLSDR_API int rtlsdr_get_index_by_serial(const char *serial); RTLSDR_API int rtlsdr_open(rtlsdr_dev_t **dev, uint32_t index); RTLSDR_API int rtlsdr_close(rtlsdr_dev_t *dev); /* configuration functions */ /*! * Set crystal oscillator frequencies used for the RTL2832 and the tun +er IC. * * Usually both ICs use the same clock. Changing the clock may make se +nse if * you are applying an external clock to the tuner or to compensate th +e * frequency (and samplerate) error caused by the original (cheap) cry +stal. * * NOTE: Call this function only if you fully understand the implicati +ons. * * \param dev the device handle given by rtlsdr_open() * \param rtl_freq frequency value used to clock the RTL2832 in Hz * \param tuner_freq frequency value used to clock the tuner IC in Hz * \return 0 on success */ RTLSDR_API int rtlsdr_set_xtal_freq(rtlsdr_dev_t *dev, uint32_t rtl_fr +eq, uint32_t tuner_freq);
    (this is only the first part, think that I need only the rtlsdr_open function, the other function before it works and return the correct output. Regards Edoardo M.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11120109]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2024-04-25 20:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found