Running SDRplay API 3.01 example code under Linux (Fedora 29)

Add useful snippets of code or links to entire SDR projects.
Post Reply
fventuri
Posts: 37
Joined: Sun Dec 25, 2016 4:24 pm

Running SDRplay API 3.01 example code under Linux (Fedora 29)

Post by fventuri » Sat Jan 05, 2019 8:05 pm

Last night I saw the announcement that the beta version of the Linux API 3.01 (the one that is able to take advantage of the dual tuner in the RSPduo) is now available to the public (https://sdrplay.com/community/viewtopic.php?f=6&t=3997), so this morning I wanted to give it a try running the sample code listed in chapter 4 of the 3.01 API specification PDF, and here are my quick initial notes on running it on Linux.
Some of these comments are specific to my version of Linux (Fedora 29), so your experience might be slightly different.
  • Since in Fedora the user installed 64-bit libraries should go under '/usr/local/lib64' (instead of '/usr/local/lib'), I moved the library 'libsdrplay_api.so.3.01' and its related symlinks to '/usr/local/lib64'
  • Also since Fedora uses systemd, I replaced the 'sdrplayService' init script with this very simple systemd service script, that I called '/etc/systemd/system/sdrplay_api.service':

    Code: Select all

    [Unit]
    Description=Service for SDRplay API
    After=network.target
    
    [Service]
    Type=simple
    ExecStart=/usr/local/bin/sdrplay_apiService
    
    [Install]
    WantedBy=multi-user.target
    
    For those unfamiliar with systemd, these are the commands I ran in order to make systemd "see" the new script, start it, check its status, and possibly enable it automatically a boot time:

    Code: Select all

    systemctl daemon-reload
    systemctl start sdrplay_api
    systemctl status sdrplay_api
    systemctl enable sdrplay_api    (<- to enable it automatically at boot time)
    
  • Next I made a few changes to the sample code listed in chapter 4 of the 3.01 API specification PDF to make it compile under Linux without errors or warnings - I removed the includes for 'Windows.h' and 'conio.h', I added a few includes needed in Linux, I replaced the call to the '_kbhit()' function (only available in Windows) with a call to 'select()', and perhaps a couple of other things I don't remember now.
    I am attaching the version of the source code for 'sdrplay_api_sample_app.c' with all these changes; it compiles and runs with my Linux distribution.
  • I also created this simple Makefile to compile it and run it:

    Code: Select all

    CC=gcc
    ###CFLAGS=-O -Wall
    CFLAGS=-g -Wall -Wl,-rpath=/usr/local/lib64
    LDLIBS=-lsdrplay_api
    
    all: sdrplay_api_sample_app
    
    run: sdrplay_api_sample_app
    	./sdrplay_api_sample_app
    
    clean:
    	rm -f *.o sdrplay_api_sample_app
    
  • Last I ran it with './sdrplay_api_sample_app' and this a sample of my output:

    Code: Select all

    ./sdrplay_api_sample_app 
    requested TunerA Mode=Single_Tuner
    MaxDevs=6 NumDevs=1
    Dev0: SerNo=******** hwVer=2 tuner=0x01
    chosenDevice = 0
    sdrplay_api_EventCb: sdrplay_api_GainChange, tuner=sdrplay_api_Tuner_A gRdB=40 lnaGRdB=34 systemGain=49.19
    sdrplay_api_StreamACallback: numSamples=1344
    sdrplay_api_EventCb: sdrplay_api_GainChange, tuner=sdrplay_api_Tuner_A gRdB=41 lnaGRdB=34 systemGain=48.19
    sdrplay_api_EventCb: sdrplay_api_GainChange, tuner=sdrplay_api_Tuner_A gRdB=42 lnaGRdB=34 systemGain=47.19
    sdrplay_api_EventCb: sdrplay_api_GainChange, tuner=sdrplay_api_Tuner_A gRdB=41 lnaGRdB=34 systemGain=48.19
    sdrplay_api_EventCb: sdrplay_api_GainChange, tuner=sdrplay_api_Tuner_A gRdB=40 lnaGRdB=34 systemGain=49.19
    sdrplay_api_PowerOverloadChange: tuner=sdrplay_api_Tuner_A powerOverloadChangeType=sdrplay_api_Overload_Corrected
    
Unfortunately I only have an RSP2 (not the RSPduo model); it would be interesting if anyone who has an RSPduo could try running it under Linux and report their results.

Franco
Attachments
sdrplay_api_sample_app.tar
Source code for sdrplay_api_sample_app.c
(20 KiB) Downloaded 1096 times

Reason: No reason

fmoessbauer
Posts: 1
Joined: Tue Jan 29, 2019 12:47 pm

Re: Running SDRplay API 3.01 example code under Linux (Fedora 29)

Post by fmoessbauer » Tue Jan 29, 2019 1:20 pm

Hi,

thanks for this detailed and clean setup description. Here is my experience with the SDRPlay2 Duo
I tested this driver / service on Ubuntu 18.10 where the init.d script is correctly handled. However, IMO your solution is the more clean one. Probably the vendor should change the name of the service as well. Maybe something like sdrplayAPI is better as it closer maps to the function (IMO Service in a name of a service is bad).

Update: The callback is called multiple times, but the message is only displayed on a stream reset. Processing the stream works correctly. In case of the issues regarding Tuner B: The gains where too high for the output of my antenna. After reducing the gain, this also worked correctly.

Tuner A

Code: Select all

./sdrplay_api_sample_app A
requested TunerA Mode=Single_Tuner
MaxDevs=6 NumDevs=1
Dev0: SerNo=******* hwVer=3 tuner=0x03 rspDuoMode=0x07
chosenDevice = 0
Dev0: selected rspDuoMode=0x01 tuner=0x01
sdrplay_api_EventCb: sdrplay_api_GainChange, tuner=sdrplay_api_Tuner_A gRdB=40 lnaGRdB=26 systemGain=52.11
sdrplay_api_StreamACallback: numSamples=1344
[<no further output>]
Tuner B

Code: Select all

./sdrplay_api_sample_app B
requested TunerB Mode=Single_Tuner
MaxDevs=6 NumDevs=1
Dev0: SerNo=******* hwVer=3 tuner=0x03 rspDuoMode=0x07
chosenDevice = 0
Dev0: selected rspDuoMode=0x01 tuner=0x02
sdrplay_api_EventCb: sdrplay_api_GainChange, tuner=sdrplay_api_Tuner_B gRdB=40 lnaGRdB=26 systemGain=51.40
sdrplay_api_StreamACallback: numSamples=1344
sdrplay_api_PowerOverloadChange: tuner=sdrplay_api_Tuner_B powerOverloadChangeType=sdrplay_api_Overload_Detected
sdrplay_api_PowerOverloadChange: tuner=sdrplay_api_Tuner_B powerOverloadChangeType=sdrplay_api_Overload_Corrected
sdrplay_api_PowerOverloadChange: tuner=sdrplay_api_Tuner_B powerOverloadChangeType=sdrplay_api_Overload_Detected
sdrplay_api_PowerOverloadChange: tuner=sdrplay_api_Tuner_B powerOverloadChangeType=sdrplay_api_Overload_Corrected
...
After stopping the execution of 1 (tuner A), the service is not working properly anymore:

Code: Select all

./sdrplay_api_sample_app B
requested TunerB Mode=Single_Tuner
sdrplay_api_DebugEnable failed sdrplay_api_ServiceNotResponding
sdrplay_api_ApiVersion failed sdrplay_api_ServiceNotResponding
API version don't match (local=3.01 dll=0.00)
Changing the SoapySDRPlay connector to use the new API does not seem to be too complicated. I will give it a try this week.

Felix
Last edited by fmoessbauer on Thu Jan 01, 1970 12:00 am, edited 0 times in total.
Reason: No reason

fventuri
Posts: 37
Joined: Sun Dec 25, 2016 4:24 pm

Re: Running SDRplay API 3.01 example code under Linux (Fedora 29)

Post by fventuri » Wed Jan 30, 2019 3:27 am

Felix,
I am kind of surprised the second 'sdrplay_api_sample_app' (the one with the tuner B) even worked for you.
I see that you ran both in 'Single Tuner' mode; according to SDRplay specifications for the API version 3.01, the second call to the function 'sdrplay_api_SelectDevice()' should have failed since:
Once a device has been selected, it is no longer available for other applications (unless the device is a RSPduo in master/slave mode).
(the quote above is from the description of sdrplay_api_SelectDevice in section 3.7 on page 19).

If I understand correctly what you were trying to do, you should have ran them in 'Master/Slave' mode, using the 'ms' option (after the tuner selection A/B) in the sample application.

Franco

Reason: No reason

Post Reply