2014-10-27 20:05:40 -04:00
|
|
|
#pragma once
|
|
|
|
|
2014-11-23 19:39:27 -05:00
|
|
|
#include <atomic>
|
|
|
|
|
2014-10-27 20:05:40 -04:00
|
|
|
#include "wx/wxprec.h"
|
|
|
|
#include "rtl-sdr.h"
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/thread.h"
|
|
|
|
|
2014-11-22 20:57:06 -05:00
|
|
|
#include "ThreadQueue.h"
|
2014-11-22 22:17:33 -05:00
|
|
|
#include "DemodulatorMgr.h"
|
2014-10-28 21:39:59 -04:00
|
|
|
|
2015-01-12 00:40:43 -05:00
|
|
|
class SDRDeviceInfo {
|
|
|
|
public:
|
|
|
|
SDRDeviceInfo() : name(""), serial(""), available(false) { }
|
|
|
|
|
|
|
|
bool isAvailable() const {
|
|
|
|
return available;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setAvailable(bool available) {
|
|
|
|
this->available = available;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& getName() const {
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setName(const std::string& name) {
|
|
|
|
this->name = name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& getSerial() const {
|
|
|
|
return serial;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setSerial(const std::string& serial) {
|
|
|
|
this->serial = serial;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& getTuner() const {
|
|
|
|
return tuner;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setTuner(const std::string& tuner) {
|
|
|
|
this->tuner = tuner;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& getManufacturer() const {
|
|
|
|
return manufacturer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setManufacturer(const std::string& manufacturer) {
|
|
|
|
this->manufacturer = manufacturer;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::string& getProduct() const {
|
|
|
|
return product;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setProduct(const std::string& product) {
|
|
|
|
this->product = product;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string name;
|
|
|
|
std::string serial;
|
|
|
|
std::string product;
|
|
|
|
std::string manufacturer;
|
|
|
|
std::string tuner;
|
|
|
|
bool available;
|
|
|
|
};
|
|
|
|
|
2014-11-22 20:57:06 -05:00
|
|
|
class SDRThreadCommand {
|
|
|
|
public:
|
|
|
|
enum SDRThreadCommandEnum {
|
2015-01-12 00:40:43 -05:00
|
|
|
SDR_THREAD_CMD_NULL, SDR_THREAD_CMD_TUNE, SDR_THREAD_CMD_SET_OFFSET, SDR_THREAD_CMD_SET_SAMPLERATE, SDR_THREAD_CMD_SET_DEVICE
|
2014-11-22 20:57:06 -05:00
|
|
|
};
|
|
|
|
|
2014-12-16 21:30:03 -05:00
|
|
|
SDRThreadCommand() :
|
2015-01-04 17:11:20 -05:00
|
|
|
cmd(SDR_THREAD_CMD_NULL), llong_value(0) {
|
2014-11-22 20:57:06 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-12-16 21:30:03 -05:00
|
|
|
SDRThreadCommand(SDRThreadCommandEnum cmd) :
|
2015-01-04 17:11:20 -05:00
|
|
|
cmd(cmd), llong_value(0) {
|
2014-11-22 20:57:06 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SDRThreadCommandEnum cmd;
|
2015-01-04 17:11:20 -05:00
|
|
|
long long llong_value;
|
2014-11-22 20:57:06 -05:00
|
|
|
};
|
|
|
|
|
2015-01-03 17:07:39 -05:00
|
|
|
class SDRThreadIQData: public ReferenceCounter {
|
2014-11-22 20:57:06 -05:00
|
|
|
public:
|
2015-01-04 17:11:20 -05:00
|
|
|
long long frequency;
|
2015-01-11 17:08:16 -05:00
|
|
|
long long sampleRate;
|
2014-12-23 01:59:03 -05:00
|
|
|
std::vector<signed char> data;
|
2014-11-22 20:57:06 -05:00
|
|
|
|
2014-12-16 21:30:03 -05:00
|
|
|
SDRThreadIQData() :
|
2015-01-11 17:08:16 -05:00
|
|
|
frequency(0), sampleRate(DEFAULT_SAMPLE_RATE) {
|
2014-11-22 20:57:06 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-01-11 17:08:16 -05:00
|
|
|
SDRThreadIQData(long long bandwidth, long long frequency, std::vector<signed char> *data) :
|
|
|
|
frequency(frequency), sampleRate(bandwidth) {
|
2014-11-22 20:57:06 -05:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
~SDRThreadIQData() {
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef ThreadQueue<SDRThreadCommand> SDRThreadCommandQueue;
|
2014-12-23 01:59:03 -05:00
|
|
|
typedef ThreadQueue<SDRThreadIQData *> SDRThreadIQDataQueue;
|
2014-11-22 20:57:06 -05:00
|
|
|
|
|
|
|
class SDRThread {
|
2014-10-27 20:05:40 -04:00
|
|
|
public:
|
2014-11-04 18:39:08 -05:00
|
|
|
rtlsdr_dev_t *dev;
|
2014-10-27 20:05:40 -04:00
|
|
|
|
2014-11-22 20:57:06 -05:00
|
|
|
SDRThread(SDRThreadCommandQueue* pQueue);
|
2014-11-04 18:39:08 -05:00
|
|
|
~SDRThread();
|
2014-10-27 20:05:40 -04:00
|
|
|
|
2015-01-12 00:40:43 -05:00
|
|
|
static int enumerate_rtl(std::vector<SDRDeviceInfo *> *devs);
|
2014-10-27 20:05:40 -04:00
|
|
|
|
2014-11-22 20:57:06 -05:00
|
|
|
void threadMain();
|
|
|
|
|
|
|
|
void setIQDataOutQueue(SDRThreadIQDataQueue* iqDataQueue) {
|
|
|
|
iqDataOutQueue = iqDataQueue;
|
|
|
|
}
|
2014-11-23 19:39:27 -05:00
|
|
|
|
|
|
|
void terminate();
|
2015-01-12 00:40:43 -05:00
|
|
|
|
|
|
|
int getDeviceId() const {
|
|
|
|
return deviceId;
|
|
|
|
}
|
|
|
|
|
|
|
|
void setDeviceId(int deviceId) {
|
|
|
|
this->deviceId = deviceId;
|
|
|
|
}
|
|
|
|
|
2014-10-27 20:05:40 -04:00
|
|
|
protected:
|
2015-01-03 17:07:39 -05:00
|
|
|
uint32_t sampleRate;
|
2015-01-06 00:57:57 -05:00
|
|
|
long long offset;
|
2015-01-03 17:07:39 -05:00
|
|
|
std::atomic<SDRThreadCommandQueue*> commandQueue;
|
2014-11-29 13:58:20 -05:00
|
|
|
std::atomic<SDRThreadIQDataQueue*> iqDataOutQueue;
|
2014-11-18 18:00:06 -05:00
|
|
|
|
2014-11-23 19:39:27 -05:00
|
|
|
std::atomic<bool> terminated;
|
2015-01-12 00:40:43 -05:00
|
|
|
int deviceId;
|
2014-10-27 20:05:40 -04:00
|
|
|
};
|