CubicSDR/src/sdr/SDRThread.h

156 lines
3.1 KiB
C
Raw Normal View History

#pragma once
#include <atomic>
#include "wx/wxprec.h"
#include "rtl-sdr.h"
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
#include "wx/thread.h"
#include "ThreadQueue.h"
#include "DemodulatorMgr.h"
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;
};
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-12-16 21:30:03 -05:00
SDRThreadCommand() :
cmd(SDR_THREAD_CMD_NULL), llong_value(0) {
}
2014-12-16 21:30:03 -05:00
SDRThreadCommand(SDRThreadCommandEnum cmd) :
cmd(cmd), llong_value(0) {
}
SDRThreadCommandEnum cmd;
long long llong_value;
};
class SDRThreadIQData: public ReferenceCounter {
public:
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-12-16 21:30:03 -05:00
SDRThreadIQData() :
2015-01-11 17:08:16 -05:00
frequency(0), sampleRate(DEFAULT_SAMPLE_RATE) {
}
2015-01-11 17:08:16 -05:00
SDRThreadIQData(long long bandwidth, long long frequency, std::vector<signed char> *data) :
frequency(frequency), sampleRate(bandwidth) {
}
~SDRThreadIQData() {
}
};
typedef ThreadQueue<SDRThreadCommand> SDRThreadCommandQueue;
2014-12-23 01:59:03 -05:00
typedef ThreadQueue<SDRThreadIQData *> SDRThreadIQDataQueue;
class SDRThread {
public:
rtlsdr_dev_t *dev;
SDRThread(SDRThreadCommandQueue* pQueue);
~SDRThread();
2015-01-12 00:40:43 -05:00
static int enumerate_rtl(std::vector<SDRDeviceInfo *> *devs);
void threadMain();
void setIQDataOutQueue(SDRThreadIQDataQueue* iqDataQueue) {
iqDataOutQueue = iqDataQueue;
}
void terminate();
2015-01-12 00:40:43 -05:00
int getDeviceId() const {
return deviceId;
}
void setDeviceId(int deviceId) {
this->deviceId = deviceId;
}
protected:
uint32_t sampleRate;
long long offset;
std::atomic<SDRThreadCommandQueue*> commandQueue;
std::atomic<SDRThreadIQDataQueue*> iqDataOutQueue;
std::atomic<bool> terminated;
2015-01-12 00:40:43 -05:00
int deviceId;
};