#pragma once #include #include #include #include #include #include #include extern "C" { #include "../ad9361/ad9361_api.h" #include "../ad9361/platform/parameters.h" #include "../ad9361/platform/platform.h" #include "usb_platform.h" }; using namespace std; enum class TxMode { TX_SINE, TX_NOISE }; class RFThread { public: // Start and stop the AD9361 interfacing thread void start(); void stop(); // Set various parameters void setCenterFreq(uint64_t freq); // set rx center freq in Hz void setBandwidth(uint32_t bw); // set rf rx bandwidth in Hz void setGain(int rxgain); // set rx rf gain in dB void setAgcEnable(bool agcEn); // set AGC on or off void setInputPort(int port); // set rx rf input port (0 or 1) void setTxEnable(bool en); // set tx on or off void setTxMode(TxMode mode); // set tx generator mode void setTxOffset(int32_t offset); // set tx generator offset void setTxPower(int power); // set tx output power // Copy the n most recent samples into a buffer (C style complex used for // compatibility reasons) void getSamples(float _Complex *buf, int n); // As above but only get new samples, returning the actual number of samples // obtained int getRecentSamples(double _Complex *buf, int n); uint32_t getCurrentSampleRate(); uint64_t getCenterFreq(); int getGain(); bool getAgcEnable(); int getInputPort(); private: thread rf_thread; atomic centerFreq{2450000000UL}; atomic centerFreqChanged{true}; atomic bandwidth{20000000}; atomic bandwidthChanged{true}; atomic gain{40}; atomic gainChanged{true}; atomic agcEnabled{false}; atomic agcEnabledChanged{true}; atomic inputPort{0}; atomic inputPortChanged; atomic stopRF{false}; atomic transmitEnabled{false}; atomic txEnableChanged{false}; atomic transmitSigMode{TxMode::TX_SINE}; atomic transmitOffset{0}; atomic txGenConfigChanged{true}; atomic txPower{-30}; atomic txPowerChanged{true}; mutex sample_buf_mutex; static const size_t sample_buf_size = 33554432; iq_sample sample_buf[sample_buf_size]; int sample_buf_idx = 0; int sample_buf_read_offset = 0; ad9361_rf_phy *ad9361_phy; void thread_main(); void init_device(); atomic currentSampleRate{20000000}; uint32_t getSampleRateFromBw(uint32_t bw); void beginSettingChange(); void startStreaming(); void stopStreaming(); void endSettingChange(); chrono::high_resolution_clock::time_point last_wrap = chrono::high_resolution_clock::now(); };