satdump/libsdr/sdr/sdr.cpp

258 lines
6.9 KiB
C++
Raw Normal View History

2021-03-23 22:47:59 +00:00
#include "sdr.h"
2021-05-28 20:43:36 +02:00
SDRDevice::SDRDevice(std::map<std::string, std::string> parameters, uint64_t /*id*/)
2021-05-25 21:25:42 +02:00
: d_parameters(parameters)
2021-03-23 22:47:59 +00:00
{
2021-10-22 15:26:17 +02:00
output_stream = std::make_shared<dsp::stream<complex_t>>();
2021-03-23 22:47:59 +00:00
}
void SDRDevice::start()
{
}
void SDRDevice::stop()
{
}
void SDRDevice::drawUI()
{
}
void SDRDevice::init()
{
}
2021-06-05 12:14:09 +02:00
void SDRDevice::setFrequency(float frequency)
2021-03-23 22:47:59 +00:00
{
2021-03-31 18:15:26 +02:00
d_frequency = frequency;
}
2021-06-05 12:14:09 +02:00
void SDRDevice::setSamplerate(float samplerate)
2021-03-31 18:15:26 +02:00
{
d_samplerate = samplerate;
}
2021-06-06 14:11:02 +02:00
float SDRDevice::getFrequency()
2021-03-31 18:15:26 +02:00
{
return d_frequency;
}
2021-06-06 14:11:02 +02:00
float SDRDevice::getSamplerate()
2021-03-31 18:15:26 +02:00
{
return d_samplerate;
}
std::vector<std::tuple<std::string, sdr_device_type, uint64_t>> SDRDevice::getDevices()
{
std::vector<std::tuple<std::string, sdr_device_type, uint64_t>> results;
2021-03-23 22:47:59 +00:00
return results;
}
2021-05-25 21:25:42 +02:00
std::map<std::string, std::string> SDRDevice::drawParamsUI()
{
return std::map<std::string, std::string>();
}
2021-03-23 22:47:59 +00:00
#include "airspy.h"
2021-05-04 16:39:27 +02:00
#include "rtlsdr.h"
2021-05-26 22:14:25 +02:00
#include "hackrf.h"
2021-06-04 23:03:48 +02:00
#include "limesdr.h"
2021-08-12 23:22:49 +02:00
#include "airspyhf.h"
2021-05-25 21:25:42 +02:00
#include "spyserver.h"
2021-06-30 16:08:15 +02:00
#include "rtltcp.h"
2021-08-16 01:06:56 +02:00
#include "file.h"
2021-03-23 22:47:59 +00:00
void initSDRs()
{
2021-06-16 16:33:05 +02:00
#ifndef DISABLE_SDR_AIRSPY
2021-03-23 22:47:59 +00:00
SDRAirspy::init();
2021-06-16 16:33:05 +02:00
#endif
#ifndef DISABLE_SDR_HACKRF
2021-05-26 22:14:25 +02:00
SDRHackRF::init();
2021-06-16 16:33:05 +02:00
#endif
2021-03-23 22:47:59 +00:00
}
2021-08-14 20:13:46 +02:00
// Android support
#ifdef __ANDROID__
bool rtlsdr_device_android_ready;
int rtlsdr_device_android_fd;
std::string rtlsdr_device_android_path;
bool airspy_device_android_ready;
int airspy_device_android_fd;
std::string airspy_device_android_path;
bool airspyhf_device_android_ready;
int airspyhf_device_android_fd;
std::string airspyhf_device_android_path;
#endif
2021-03-31 18:15:26 +02:00
std::vector<std::tuple<std::string, sdr_device_type, uint64_t>> getAllDevices()
2021-03-23 22:47:59 +00:00
{
2021-03-31 18:15:26 +02:00
std::vector<std::tuple<std::string, sdr_device_type, uint64_t>> results;
2021-03-23 22:47:59 +00:00
2021-06-16 16:33:05 +02:00
#ifndef DISABLE_SDR_AIRSPY
2021-03-31 18:15:26 +02:00
std::vector<std::tuple<std::string, sdr_device_type, uint64_t>> airspy_results = SDRAirspy::getDevices();
2021-08-14 20:13:46 +02:00
#ifdef __ANDROID__
if (airspy_device_android_ready)
#endif
results.insert(results.end(), airspy_results.begin(), airspy_results.end());
2021-06-16 16:33:05 +02:00
#endif
2021-03-23 22:47:59 +00:00
2021-06-16 16:33:05 +02:00
#ifndef DISABLE_SDR_RTLSDR
2021-05-04 16:39:27 +02:00
std::vector<std::tuple<std::string, sdr_device_type, uint64_t>> rtlsdr_results = SDRRtlSdr::getDevices();
2021-08-14 20:13:46 +02:00
#ifdef __ANDROID__
if (rtlsdr_device_android_ready)
#endif
results.insert(results.end(), rtlsdr_results.begin(), rtlsdr_results.end());
2021-06-16 16:33:05 +02:00
#endif
2021-05-04 16:39:27 +02:00
2021-06-16 16:33:05 +02:00
#ifndef DISABLE_SDR_HACKRF
2021-05-26 22:14:25 +02:00
std::vector<std::tuple<std::string, sdr_device_type, uint64_t>> hackrf_results = SDRHackRF::getDevices();
2021-10-22 15:26:17 +02:00
results.insert(results.end(), hackrf_results.begin(), hackrf_results.end());
2021-06-16 16:33:05 +02:00
#endif
2021-05-26 22:14:25 +02:00
#ifndef DISABLE_SDR_LIMESDR
2021-06-04 23:03:48 +02:00
std::vector<std::tuple<std::string, sdr_device_type, uint64_t>> limesdr_results = SDRLimeSDR::getDevices();
results.insert(results.end(), limesdr_results.begin(), limesdr_results.end());
2021-06-05 12:06:27 +02:00
#endif
2021-06-04 23:03:48 +02:00
2021-08-12 23:22:49 +02:00
#ifndef DISABLE_SDR_AIRSPYHF
std::vector<std::tuple<std::string, sdr_device_type, uint64_t>> airspyhf_results = SDRAirspyHF::getDevices();
2021-08-14 20:13:46 +02:00
#ifdef __ANDROID__
if (airspyhf_device_android_ready)
#endif
results.insert(results.end(), airspyhf_results.begin(), airspyhf_results.end());
2021-08-12 23:22:49 +02:00
#endif
2021-06-16 16:33:05 +02:00
#ifndef DISABLE_SDR_SPYSERVER
2021-05-25 21:25:42 +02:00
std::vector<std::tuple<std::string, sdr_device_type, uint64_t>> spyserver_results = SDRSpyServer::getDevices();
results.insert(results.end(), spyserver_results.begin(), spyserver_results.end());
2021-06-16 16:33:05 +02:00
#endif
2021-05-25 21:25:42 +02:00
2021-06-30 16:08:15 +02:00
#ifndef DISABLE_SDR_RTLTCP
std::vector<std::tuple<std::string, sdr_device_type, uint64_t>> rtltcp_results = SDRRtlTcp::getDevices();
results.insert(results.end(), rtltcp_results.begin(), rtltcp_results.end());
#endif
2021-08-16 01:06:56 +02:00
std::vector<std::tuple<std::string, sdr_device_type, uint64_t>> file_results = SDRFile::getDevices();
results.insert(results.end(), file_results.begin(), file_results.end());
2021-03-23 22:47:59 +00:00
return results;
}
2021-03-31 18:15:26 +02:00
2021-05-25 21:25:42 +02:00
std::map<std::string, std::string> drawParamsUIForID(std::vector<std::tuple<std::string, sdr_device_type, uint64_t>> devList, int num)
{
sdr_device_type type = std::get<1>(devList[num]);
2021-06-25 20:18:23 +02:00
#ifndef DISABLE_SDR_SPYSERVER
2021-05-25 21:25:42 +02:00
if (type == SPYSERVER)
return SDRSpyServer::drawParamsUI();
2021-06-25 20:18:23 +02:00
#endif
2021-06-30 16:08:15 +02:00
#ifndef DISABLE_SDR_RTLTCP
if (type == RTLTCP)
return SDRRtlTcp::drawParamsUI();
#endif
2021-08-16 01:06:56 +02:00
if (type == FILESRC)
return SDRFile::drawParamsUI();
2021-06-30 16:08:15 +02:00
return std::map<std::string, std::string>();
2021-05-25 21:25:42 +02:00
}
2021-06-06 14:11:02 +02:00
std::string getDeviceIDStringByID(std::vector<std::tuple<std::string, sdr_device_type, uint64_t>> devList, int num)
{
sdr_device_type type = std::get<1>(devList[num]);
if (type == AIRSPY)
return "airspy";
if (type == RTLSDR)
return "rtlsdr";
if (type == HACKRF)
return "hackrf";
if (type == LIMESDR)
return "limesdr";
2021-08-12 23:22:49 +02:00
if (type == AIRSPYHF)
return "airspyhf";
2021-06-06 14:11:02 +02:00
if (type == SPYSERVER)
return "spyserver";
2021-06-30 16:08:15 +02:00
if (type == RTLTCP)
return "rtltcp";
2021-08-16 01:06:56 +02:00
if (type == FILESRC)
return "file";
2021-06-25 20:18:23 +02:00
return "none";
}
sdr_device_type getDeviceIDbyIDString(std::string idString)
{
if (idString == "airspy")
return AIRSPY;
else if (idString == "rtlsdr")
return RTLSDR;
else if (idString == "hackrf")
return HACKRF;
else if (idString == "limesdr")
return LIMESDR;
else if (idString == "airspyhf")
return AIRSPYHF;
else if (idString == "spyserver")
return SPYSERVER;
else if (idString == "rtltcp")
return RTLTCP;
2021-08-16 01:06:56 +02:00
else if (idString == "file")
return FILESRC;
else
return NONE;
2021-06-06 14:11:02 +02:00
}
2021-05-25 21:25:42 +02:00
std::shared_ptr<SDRDevice> getDeviceByID(std::vector<std::tuple<std::string, sdr_device_type, uint64_t>> devList, std::map<std::string, std::string> parameters, int num)
2021-03-31 18:15:26 +02:00
{
sdr_device_type type = std::get<1>(devList[num]);
uint64_t id = std::get<2>(devList[num]);
2021-06-16 16:33:05 +02:00
#ifndef DISABLE_SDR_AIRSPY
2021-03-31 18:15:26 +02:00
if (type == AIRSPY)
2021-08-14 20:13:46 +02:00
#ifdef __ANDROID__
return std::make_shared<SDRAirspy>(parameters, airspy_device_android_fd, airspy_device_android_path);
#else
2021-05-25 21:25:42 +02:00
return std::make_shared<SDRAirspy>(parameters, id);
2021-06-16 16:33:05 +02:00
#endif
2021-08-14 20:13:46 +02:00
#endif
2021-06-16 16:33:05 +02:00
#ifndef DISABLE_SDR_RTLSDR
2021-05-04 16:39:27 +02:00
if (type == RTLSDR)
2021-08-14 20:13:46 +02:00
#ifdef __ANDROID__
return std::make_shared<SDRRtlSdr>(parameters, rtlsdr_device_android_fd, rtlsdr_device_android_path);
#else
2021-05-25 21:25:42 +02:00
return std::make_shared<SDRRtlSdr>(parameters, id);
2021-06-16 16:33:05 +02:00
#endif
2021-08-14 20:13:46 +02:00
#endif
2021-06-16 16:33:05 +02:00
#ifndef DISABLE_SDR_HACKRF
2021-05-26 22:14:25 +02:00
if (type == HACKRF)
return std::make_shared<SDRHackRF>(parameters, id);
2021-06-16 16:33:05 +02:00
#endif
#ifndef DISABLE_SDR_LIMESDR
2021-06-04 23:03:48 +02:00
if (type == LIMESDR)
return std::make_shared<SDRLimeSDR>(parameters, id);
2021-06-06 22:21:34 +02:00
#endif
2021-08-12 23:22:49 +02:00
#ifndef DISABLE_SDR_AIRSPYHF
if (type == AIRSPYHF)
2021-08-14 20:13:46 +02:00
#ifdef __ANDROID__
return std::make_shared<SDRAirspyHF>(parameters, airspyhf_device_android_fd, airspyhf_device_android_path);
#else
2021-08-12 23:22:49 +02:00
return std::make_shared<SDRAirspyHF>(parameters, id);
#endif
2021-08-14 20:13:46 +02:00
#endif
2021-06-16 16:33:05 +02:00
#ifndef DISABLE_SDR_SPYSERVER
2021-05-25 21:25:42 +02:00
if (type == SPYSERVER)
return std::make_shared<SDRSpyServer>(parameters, id);
2021-06-16 16:33:05 +02:00
#endif
2021-06-30 16:08:15 +02:00
#ifndef DISABLE_SDR_RTLTCP
if (type == RTLTCP)
return std::make_shared<SDRRtlTcp>(parameters, id);
#endif
2021-08-16 01:06:56 +02:00
if (type == FILESRC)
return std::make_shared<SDRFile>(parameters, id);
2021-06-25 20:18:23 +02:00
return nullptr;
2021-03-31 18:15:26 +02:00
}