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-21 16:56:32 -04:00
|
|
|
frequency(0), sampleRate(DEFAULT_SAMPLE_RATE), dcCorrected(true), numChannels(0) {
|
2015-09-13 22:18:29 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-01-26 19:20:14 -05:00
|
|
|
SDRThreadIQData(long long bandwidth, long long frequency, std::vector<signed char> * /* data */) :
|
2015-09-13 22:18:29 -04:00
|
|
|
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-11-03 21:06:22 -05:00
|
|
|
enum SDRThreadState { SDR_THREAD_MESSAGE, SDR_THREAD_INITIALIZED, 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();
|
|
|
|
|
2016-01-07 00:35:02 -05:00
|
|
|
void lockFrequency(long long freq);
|
|
|
|
bool isFrequencyLocked();
|
|
|
|
void unlockFrequency();
|
|
|
|
|
2015-10-03 21:35:11 -04:00
|
|
|
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();
|
|
|
|
|
2015-10-27 01:56:49 -04:00
|
|
|
void setAGCMode(bool mode);
|
|
|
|
bool getAGCMode();
|
|
|
|
|
2016-02-15 15:07:57 -05:00
|
|
|
void setIQSwap(bool swap);
|
|
|
|
bool getIQSwap();
|
|
|
|
|
2015-10-27 01:56:49 -04:00
|
|
|
void setGain(std::string name, float value);
|
|
|
|
float getGain(std::string name);
|
|
|
|
|
2015-11-03 21:06:22 -05:00
|
|
|
void writeSetting(std::string name, std::string value);
|
|
|
|
std::string readSetting(std::string name);
|
|
|
|
|
2015-11-04 02:04:52 -05:00
|
|
|
void setStreamArgs(SoapySDR::Kwargs streamArgs);
|
|
|
|
|
2015-09-13 22:18:29 -04:00
|
|
|
protected:
|
2015-10-27 01:56:49 -04:00
|
|
|
void updateGains();
|
2015-11-03 21:06:22 -05:00
|
|
|
void updateSettings();
|
2015-11-04 02:04:52 -05:00
|
|
|
SoapySDR::Kwargs combineArgs(SoapySDR::Kwargs a, SoapySDR::Kwargs b);
|
2015-11-03 21:06:22 -05:00
|
|
|
|
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;
|
2016-01-26 21:49:42 -05:00
|
|
|
SDRThreadIQData overflowBuffer;
|
|
|
|
int numOverflow;
|
2015-10-03 21:35:11 -04:00
|
|
|
std::atomic<DeviceConfig *> deviceConfig;
|
|
|
|
std::atomic<SDRDeviceInfo *> deviceInfo;
|
2015-11-03 21:06:22 -05:00
|
|
|
|
|
|
|
std::mutex setting_busy;
|
|
|
|
std::map<std::string, std::string> settings;
|
|
|
|
std::map<std::string, bool> settingChanged;
|
2015-10-03 21:35:11 -04:00
|
|
|
|
2015-09-13 22:18:29 -04:00
|
|
|
std::atomic<uint32_t> sampleRate;
|
2016-01-07 00:35:02 -05:00
|
|
|
std::atomic_llong frequency, offset, lock_freq;
|
2016-01-26 21:49:42 -05:00
|
|
|
std::atomic_int ppm, numElems, mtuElems, numChannels;
|
2015-11-02 19:02:45 -05:00
|
|
|
std::atomic_bool hasPPM, hasHardwareDC;
|
|
|
|
std::atomic_bool agc_mode, rate_changed, freq_changed, offset_changed,
|
2016-02-15 15:07:57 -05:00
|
|
|
ppm_changed, device_changed, agc_mode_changed, gain_value_changed, setting_value_changed, frequency_locked, frequency_lock_init, iq_swap;
|
2015-10-31 13:35:13 -04:00
|
|
|
|
|
|
|
std::mutex gain_busy;
|
|
|
|
std::map<std::string, float> gainValues;
|
|
|
|
std::map<std::string, bool> gainChanged;
|
2015-11-04 02:04:52 -05:00
|
|
|
|
|
|
|
SoapySDR::Kwargs streamArgs;
|
2015-09-13 22:18:29 -04:00
|
|
|
};
|