#pragma once #include #include "ThreadQueue.h" #include "DemodulatorMgr.h" #include "SDRDeviceInfo.h" #include "AppConfig.h" #include #include #include #include class SDRThreadIQData: public ReferenceCounter { public: long long frequency; long long sampleRate; bool dcCorrected; int numChannels; std::vector data; SDRThreadIQData() : frequency(0), sampleRate(DEFAULT_SAMPLE_RATE), dcCorrected(true), numChannels(0) { } SDRThreadIQData(long long bandwidth, long long frequency, std::vector *data) : frequency(frequency), sampleRate(bandwidth) { } ~SDRThreadIQData() { } }; typedef ThreadQueue SDRThreadIQDataQueue; class SDRThread : public IOThread { private: void init(); void deinit(); void readStream(SDRThreadIQDataQueue* iqDataOutQueue); void readLoop(); public: SDRThread(); ~SDRThread(); enum SDRThreadState { SDR_THREAD_MESSAGE, SDR_THREAD_INITIALIZED, SDR_THREAD_TERMINATED, SDR_THREAD_FAILED }; void run(); SDRDeviceInfo *getDevice(); void setDevice(SDRDeviceInfo *dev); int getOptimalElementCount(long long sampleRate, int fps); int getOptimalChannelCount(long long sampleRate); void setFrequency(long long freq); long long getFrequency(); void setOffset(long long ofs); long long getOffset(); void setSampleRate(int rate); int getSampleRate(); void setPPM(int ppm); int getPPM(); void setAGCMode(bool mode); bool getAGCMode(); void setGain(std::string name, float value); float getGain(std::string name); void writeSetting(std::string name, std::string value); std::string readSetting(std::string name); void setStreamArgs(SoapySDR::Kwargs streamArgs); protected: void updateGains(); void updateSettings(); SoapySDR::Kwargs combineArgs(SoapySDR::Kwargs a, SoapySDR::Kwargs b); SoapySDR::Stream *stream; SoapySDR::Device *device; void *buffs[1]; ReBuffer buffers; SDRThreadIQData inpBuffer; std::atomic deviceConfig; std::atomic deviceInfo; std::mutex setting_busy; std::map settings; std::map settingChanged; std::atomic sampleRate; std::atomic_llong frequency, offset; std::atomic_int ppm, numElems, numChannels; std::atomic_bool hasPPM, hasHardwareDC; std::atomic_bool agc_mode, rate_changed, freq_changed, offset_changed, ppm_changed, device_changed, agc_mode_changed, gain_value_changed, setting_value_changed; std::mutex gain_busy; std::map gainValues; std::map gainChanged; SoapySDR::Kwargs streamArgs; };