Initial commit of basic dependencies and demo code
This commit is contained in:
commit
9c2b1c0ad5
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
__pycache__/
|
||||||
|
dependencies/
|
||||||
|
*.log
|
||||||
15
README.md
Normal file
15
README.md
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
# SDRPlay RSP1A demo code
|
||||||
|
|
||||||
|
This repository is demo only.
|
||||||
|
|
||||||
|
# Instructions
|
||||||
|
|
||||||
|
- Install the SDRPlay device driver
|
||||||
|
- `./SDRplay_RSP_API-Linux-3.07.1.run`
|
||||||
|
- Follow the prompts, there is some audience participation
|
||||||
|
- Install the project dependencies
|
||||||
|
- `./build_dependencies`
|
||||||
|
- This should be mostly unattended. SoapySDR & plugins will be installed in the system directories.
|
||||||
|
- Run the demos. The demo code is provided by SoapySDR and required minimal modification.
|
||||||
|
- C++ demo: `make && ./Example`
|
||||||
|
- Python demo: `./example.py`
|
||||||
1750
SDRplay_RSP_API-Linux-3.07.1.run
Executable file
1750
SDRplay_RSP_API-Linux-3.07.1.run
Executable file
File diff suppressed because it is too large
Load Diff
111
build_dependencies
Executable file
111
build_dependencies
Executable file
@ -0,0 +1,111 @@
|
|||||||
|
#! /bin/bash
|
||||||
|
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
echo "Beginning project setup for SDRPlay interface." > build.log
|
||||||
|
date >> build.log
|
||||||
|
mkdir -p dependencies && pushd dependencies
|
||||||
|
|
||||||
|
# Install build dependencies
|
||||||
|
# Debian:
|
||||||
|
sudo apt-get update
|
||||||
|
sudo apt-get install -y \
|
||||||
|
git build-essential automake cmake \
|
||||||
|
libpulse-dev libgtk-3-dev \
|
||||||
|
freeglut3 freeglut3-dev
|
||||||
|
# RedHat:
|
||||||
|
#sudo dnf install pulseaudio-libs-devel gtk3-devel freeglut-devel
|
||||||
|
|
||||||
|
|
||||||
|
# These are necessary for building the python bindings for SoapySDR.
|
||||||
|
# These must be installed before building SoapySDR for the python
|
||||||
|
# bindings to be available on the system.
|
||||||
|
sudo apt-get install -y python-dev swig
|
||||||
|
|
||||||
|
|
||||||
|
# Build SoapySDR
|
||||||
|
if ! [ -d SoapySDR ]; then
|
||||||
|
git clone https://github.com/pothosware/SoapySDR.git
|
||||||
|
pushd SoapySDR
|
||||||
|
mkdir build
|
||||||
|
pushd build
|
||||||
|
cmake .. -DCMAKE_BUILD_TYPE=Release
|
||||||
|
make -j
|
||||||
|
sudo make install
|
||||||
|
sudo ldconfig
|
||||||
|
SoapySDRUtil --info #test SoapySDR install
|
||||||
|
popd
|
||||||
|
popd
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Build SoapySDRPlay plugin
|
||||||
|
if ! [ -d SoapySDRPlay ]; then
|
||||||
|
git clone https://github.com/pothosware/SoapySDRPlay.git
|
||||||
|
pushd SoapySDRPlay
|
||||||
|
mkdir build
|
||||||
|
pushd build
|
||||||
|
cmake .. -DCMAKE_BUILD_TYPE=Release
|
||||||
|
make
|
||||||
|
sudo make install
|
||||||
|
sudo ldconfig
|
||||||
|
SoapySDRUtil --info
|
||||||
|
popd
|
||||||
|
popd
|
||||||
|
fi
|
||||||
|
|
||||||
|
# SoapySDRPlay plugin can overwrite some of the installed files for SoapySDR with older
|
||||||
|
# versions - re-run the installer for SoapySDR base to ensure we have the latest ones.
|
||||||
|
pushd SoapySDR/build
|
||||||
|
sudo make install
|
||||||
|
popd
|
||||||
|
|
||||||
|
# Build liquid-dsp
|
||||||
|
if ! [ -d liquid-dsp ]; then
|
||||||
|
git clone https://github.com/jgaeddert/liquid-dsp
|
||||||
|
pushd liquid-dsp
|
||||||
|
./bootstrap.sh
|
||||||
|
CFLAGS="-march=native -O3" ./configure --enable-fftoverride
|
||||||
|
make -j
|
||||||
|
sudo make install
|
||||||
|
sudo ldconfig
|
||||||
|
popd
|
||||||
|
fi
|
||||||
|
|
||||||
|
popd #dependencies
|
||||||
|
echo "Setup completed." >> build.log
|
||||||
|
date >> build.log
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
|
||||||
|
########################### DONT NEED THIS STUFF ###################################
|
||||||
|
## Build wxWidgets
|
||||||
|
#if ! [ -d wxWidgets-3.2.1 ]; then
|
||||||
|
#wget https://github.com/wxWidgets/wxWidgets/releases/download/v3.2.1/wxWidgets-3.2.1.tar.bz2
|
||||||
|
#tar -xvjf wxWidgets-3.2.1.tar.bz2
|
||||||
|
#rm wxWidgets-3.2.1.tar.bz2
|
||||||
|
#pushd wxWidgets-3.2.1
|
||||||
|
# ./autogen.sh
|
||||||
|
# ./configure \
|
||||||
|
# --with-opengl --disable-glcanvasegl --disable-shared --enable-monolithic \
|
||||||
|
# --with-libjpeg --with-libtiff --with-libpng --with-zlib --disable-sdltest \
|
||||||
|
# --enable-unicode --enable-display --enable-propgrid --disable-webview \
|
||||||
|
# --disable-webviewwebkit CXXFLAGS="-std=c++0x"
|
||||||
|
#
|
||||||
|
# make -j
|
||||||
|
# sudo make install
|
||||||
|
#popd
|
||||||
|
#fi
|
||||||
|
#
|
||||||
|
## Build CubicSDR
|
||||||
|
#if ! [ -d CubicSDR ]; then
|
||||||
|
#git clone https://github.com/cjcliffe/CubicSDR.git
|
||||||
|
#pushd CubicSDR
|
||||||
|
# mkdir build
|
||||||
|
# pushd build
|
||||||
|
# cmake ../ -DCMAKE_BUILD_TYPE=Release \
|
||||||
|
# -DwxWidgets_CONFIG_EXECUTABLE=/usr/local/bin/wx-config
|
||||||
|
# make -j
|
||||||
|
# sudo make install
|
||||||
|
# popd
|
||||||
|
#popd
|
||||||
|
#fi
|
||||||
108
example.cpp
Normal file
108
example.cpp
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
#include <cstdio> //stdandard output
|
||||||
|
#include <cstdlib>
|
||||||
|
|
||||||
|
#include <SoapySDR/Device.hpp>
|
||||||
|
#include <SoapySDR/Types.hpp>
|
||||||
|
#include <SoapySDR/Formats.hpp>
|
||||||
|
|
||||||
|
#include <string> // std::string
|
||||||
|
#include <vector> // std::vector<...>
|
||||||
|
#include <map> // std::map< ... , ... >
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
|
||||||
|
// 0. enumerate devices (list all devices' information)
|
||||||
|
SoapySDR::KwargsList results = SoapySDR::Device::enumerate();
|
||||||
|
SoapySDR::Kwargs::iterator it;
|
||||||
|
|
||||||
|
for( int i = 0; i < results.size(); ++i)
|
||||||
|
{
|
||||||
|
printf("Found device #%d: ", i);
|
||||||
|
for( it = results[i].begin(); it != results[i].end(); ++it)
|
||||||
|
{
|
||||||
|
printf("%s = %s\n", it->first.c_str(), it->second.c_str());
|
||||||
|
}
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 1. create device instance
|
||||||
|
|
||||||
|
// 1.1 set arguments
|
||||||
|
// args can be user defined or from the enumeration result
|
||||||
|
// We use first results as args here:
|
||||||
|
SoapySDR::Kwargs args = results[0];
|
||||||
|
|
||||||
|
// 1.2 make device
|
||||||
|
SoapySDR::Device *sdr = SoapySDR::Device::make(args);
|
||||||
|
|
||||||
|
if( sdr == NULL )
|
||||||
|
{
|
||||||
|
fprintf(stderr, "SoapySDR::Device::make failed\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. query device info
|
||||||
|
std::vector< std::string > str_list; //string list
|
||||||
|
|
||||||
|
// 2.1 antennas
|
||||||
|
str_list = sdr->listAntennas( SOAPY_SDR_RX, 0);
|
||||||
|
printf("Rx antennas: ");
|
||||||
|
for(int i = 0; i < str_list.size(); ++i)
|
||||||
|
printf("%s,", str_list[i].c_str());
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
// 2.2 gains
|
||||||
|
str_list = sdr->listGains( SOAPY_SDR_RX, 0);
|
||||||
|
printf("Rx Gains: ");
|
||||||
|
for(int i = 0; i < str_list.size(); ++i)
|
||||||
|
printf("%s, ", str_list[i].c_str());
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
// 2.3. ranges(frequency ranges)
|
||||||
|
SoapySDR::RangeList ranges = sdr->getFrequencyRange( SOAPY_SDR_RX, 0);
|
||||||
|
printf("Rx freq ranges: ");
|
||||||
|
for(int i = 0; i < ranges.size(); ++i)
|
||||||
|
printf("[%g Hz -> %g Hz], ", ranges[i].minimum(), ranges[i].maximum());
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
// 3. apply settings
|
||||||
|
sdr->setSampleRate( SOAPY_SDR_RX, 0, 10e6);
|
||||||
|
|
||||||
|
sdr->setFrequency( SOAPY_SDR_RX, 0, 433e6);
|
||||||
|
|
||||||
|
// 4. setup a stream (complex floats)
|
||||||
|
SoapySDR::Stream *rx_stream = sdr->setupStream( SOAPY_SDR_RX, SOAPY_SDR_CF32);
|
||||||
|
if( rx_stream == NULL)
|
||||||
|
{
|
||||||
|
fprintf( stderr, "Failed\n");
|
||||||
|
SoapySDR::Device::unmake( sdr );
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
sdr->activateStream( rx_stream, 0, 0, 0);
|
||||||
|
|
||||||
|
// 5. create a re-usable buffer for rx samples
|
||||||
|
std::complex<float> buff[1024];
|
||||||
|
|
||||||
|
// 6. receive some samples
|
||||||
|
for( int i = 0; i < 10; ++i)
|
||||||
|
{
|
||||||
|
void *buffs[] = {buff};
|
||||||
|
int flags;
|
||||||
|
long long time_ns;
|
||||||
|
int ret = sdr->readStream( rx_stream, buffs, 1024, flags, time_ns, 1e5);
|
||||||
|
printf("ret = %d, flags = %d, time_ns = %lld\n", ret, flags, time_ns);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 7. shutdown the stream
|
||||||
|
sdr->deactivateStream( rx_stream, 0, 0); //stop streaming
|
||||||
|
sdr->closeStream( rx_stream );
|
||||||
|
|
||||||
|
// 8. cleanup device handle
|
||||||
|
SoapySDR::Device::unmake( sdr );
|
||||||
|
printf("Done\n");
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
52
example.py
Executable file
52
example.py
Executable file
@ -0,0 +1,52 @@
|
|||||||
|
#! /usr/bin/env python3
|
||||||
|
|
||||||
|
#
|
||||||
|
# Example script for interfacing with SDRPlay radio.
|
||||||
|
#
|
||||||
|
# Modified from: https://github.com/pothosware/SoapySDR/wiki/PythonSupport
|
||||||
|
#
|
||||||
|
|
||||||
|
import SoapySDR
|
||||||
|
from SoapySDR import * #SOAPY_SDR_ constants
|
||||||
|
import numpy #use numpy for buffers
|
||||||
|
import sys
|
||||||
|
|
||||||
|
#enumerate devices
|
||||||
|
devices = [dict(device) for device in SoapySDR.Device.enumerate()]
|
||||||
|
for device in devices:
|
||||||
|
print(device)
|
||||||
|
|
||||||
|
if len(devices) == 0:
|
||||||
|
print('No SDR devices available.')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
#create device instance
|
||||||
|
sdr = SoapySDR.Device(devices[0])
|
||||||
|
|
||||||
|
#query device info
|
||||||
|
print(sdr.listAntennas(SOAPY_SDR_RX, 0))
|
||||||
|
print(sdr.listGains(SOAPY_SDR_RX, 0))
|
||||||
|
freqs = sdr.getFrequencyRange(SOAPY_SDR_RX, 0)
|
||||||
|
for freqRange in freqs: print(freqRange)
|
||||||
|
|
||||||
|
#apply settings
|
||||||
|
sdr.setSampleRate(SOAPY_SDR_RX, 0, 1e6)
|
||||||
|
sdr.setFrequency(SOAPY_SDR_RX, 0, 912.3e6)
|
||||||
|
|
||||||
|
#setup a stream (complex floats)
|
||||||
|
rxStream = sdr.setupStream(SOAPY_SDR_RX, SOAPY_SDR_CF32)
|
||||||
|
sdr.activateStream(rxStream) #start streaming
|
||||||
|
|
||||||
|
#create a re-usable buffer for rx samples
|
||||||
|
buff = numpy.array([0]*1024, numpy.complex64)
|
||||||
|
|
||||||
|
#receive some samples
|
||||||
|
for i in range(10):
|
||||||
|
sr = sdr.readStream(rxStream, [buff], len(buff))
|
||||||
|
print(sr.ret) #num samples or error code
|
||||||
|
print(sr.flags) #flags set by receive operation
|
||||||
|
print(sr.timeNs) #timestamp for receive buffer
|
||||||
|
|
||||||
|
#shutdown the stream
|
||||||
|
sdr.deactivateStream(rxStream) #stop streaming
|
||||||
|
sdr.closeStream(rxStream)
|
||||||
Loading…
Reference in New Issue
Block a user