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

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

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

Postby 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 14 times

Reason: No reason

Return to “Code Corner”

Who is online

Users browsing this forum: No registered users and 2 guests