2015-09-13 22:18:29 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
|
|
|
|
#include "ThreadQueue.h"
|
|
|
|
#include "DemodulatorMgr.h"
|
|
|
|
#include "SDRDeviceInfo.h"
|
2015-10-03 21:35:11 -04:00
|
|
|
#include "AppConfig.h"
|
2015-09-13 22:18:29 -04:00
|
|
|
|
2015-10-03 21:35:11 -04:00
|
|
|
#include <SoapySDR/Version.hpp>
|
|
|
|
#include <SoapySDR/Modules.hpp>
|
|
|
|
#include <SoapySDR/Registry.hpp>
|
|
|
|
#include <SoapySDR/Device.hpp>
|
2015-09-13 22:18:29 -04:00
|
|
|
|
|
|
|
|
|
|
|
class SDRThreadIQData: public ReferenceCounter {
|
|
|
|
public:
|
|
|
|
long long frequency;
|
|
|
|
long long sampleRate;
|
2015-09-30 23:45:06 -04:00
|
|
|
bool dcCorrected;
|
2015-10-14 00:54:48 -04:00
|
|
|
int numChannels;
|
|
|
|
std::vector<liquid_float_complex> data;
|
2015-09-13 22:18:29 -04:00
|
|
|
|
|
|
|
SDRThreadIQData() :
|
2015-10-20 23:57:54 -04:00
|
|
|
frequency(0), sampleRate(0), dcCorrected(true), numChannels(0) {
|
2015-09-13 22:18:29 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SDRThreadIQData(long long bandwidth, long long frequency, std::vector<signed char> *data) :
|
|
|
|
frequency(frequency), sampleRate(bandwidth) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
~SDRThreadIQData() {
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef ThreadQueue<SDRThreadIQData *> SDRThreadIQDataQueue;
|
|
|
|
|
|
|
|
class SDRThread : public IOThread {
|
2015-10-03 21:35:11 -04:00
|
|
|
private:
|
|
|
|
void init();
|
|
|
|
void deinit();
|
|
|
|
void readStream(SDRThreadIQDataQueue* iqDataOutQueue);
|
|
|
|
void readLoop();
|
|
|
|
|
2015-09-13 22:18:29 -04:00
|
|
|
public:
|
|
|
|
SDRThread();
|
|
|
|
~SDRThread();
|
2015-10-05 02:21:08 -04:00
|
|
|
enum SDRThreadState { SDR_THREAD_MESSAGE, SDR_THREAD_TERMINATED, SDR_THREAD_FAILED };
|
2015-10-03 21:35:11 -04:00
|
|
|
|
2015-09-13 22:18:29 -04:00
|
|
|
void run();
|
2015-10-03 21:35:11 -04:00
|
|
|
|
|
|
|
SDRDeviceInfo *getDevice();
|
|
|
|
void setDevice(SDRDeviceInfo *dev);
|
2015-09-22 21:03:23 -04:00
|
|
|
int getOptimalElementCount(long long sampleRate, int fps);
|
2015-10-14 00:54:48 -04:00
|
|
|
int getOptimalChannelCount(long long sampleRate);
|
2015-10-03 21:35:11 -04:00
|
|
|
|
|
|
|
void setFrequency(long long freq);
|
|
|
|
long long getFrequency();
|
|
|
|
|
|
|
|
void setOffset(long long ofs);
|
|
|
|
long long getOffset();
|
|
|
|
|
|
|
|
void setSampleRate(int rate);
|
|
|
|
int getSampleRate();
|
2015-09-13 22:18:29 -04:00
|
|
|
|
2015-10-03 21:35:11 -04:00
|
|
|
void setPPM(int ppm);
|
|
|
|
int getPPM();
|
|
|
|
|
|
|
|
void setDirectSampling(int dsMode);
|
|
|
|
int getDirectSampling();
|
|
|
|
|
2015-09-13 22:18:29 -04:00
|
|
|
protected:
|
2015-10-03 21:35:11 -04:00
|
|
|
SoapySDR::Stream *stream;
|
|
|
|
SoapySDR::Device *device;
|
|
|
|
void *buffs[1];
|
|
|
|
ReBuffer<SDRThreadIQData> buffers;
|
2015-10-15 01:35:03 -04:00
|
|
|
SDRThreadIQData inpBuffer;
|
2015-10-03 21:35:11 -04:00
|
|
|
std::atomic<DeviceConfig *> deviceConfig;
|
|
|
|
std::atomic<SDRDeviceInfo *> deviceInfo;
|
|
|
|
|
2015-09-13 22:18:29 -04:00
|
|
|
std::atomic<uint32_t> sampleRate;
|
2015-10-03 21:35:11 -04:00
|
|
|
std::atomic_llong frequency, offset;
|
2015-10-14 00:54:48 -04:00
|
|
|
std::atomic_int ppm, direct_sampling_mode, numElems, numChannels;
|
2015-10-03 21:35:11 -04:00
|
|
|
std::atomic_bool hasPPM, hasHardwareDC;
|
|
|
|
|
|
|
|
std::atomic_bool rate_changed, freq_changed, offset_changed,
|
|
|
|
ppm_changed, direct_sampling_changed, device_changed;
|
2015-09-13 22:18:29 -04:00
|
|
|
};
|