#ifndef UHD_DEVICE_H
#define UHD_DEVICE_H
#include <uhd/types/tune_request.hpp>
#include <uhd/usrp/multi_usrp.hpp>
#include <uhd/utils/safe_main.hpp>
#include <uhd/utils/thread.hpp>
#include <chrono>
#include <complex>
#include <csignal>
#include <fstream>
#include <iostream>
#include <functional>
#include <vector>
#include <atomic>
#include <QThread>
class uhd_io_thread: public QThread{
	Q_OBJECT
public:
	explicit uhd_io_thread (QObject * p);
	explicit uhd_io_thread (std::function<void (void)> runner,QObject * p);
	void setRunner(std::function<void (void)> r){ m_runner = r;}
public:
	void run() override;
private:
	std::function<void (void)> m_runner;
};

class uhd_device{
public:
	uhd_device();
	uhd_device(const std::string &args);
	~uhd_device();
public:
	void setDevArgs(const std::string &args);
	std::string devArgs() const ;
public:
	bool open_device();
	bool close_device();
	void run_IO();
protected:
	std::atomic<bool> stop_signal_called;
	std::atomic<bool> streaming;
	std::string m_dev_args;
	size_t m_spb_size = 10000;
	uhd::usrp::multi_usrp::sptr		usrp;
	int m_channel = 0;
protected:
	//初始化队列
	std::vector< uhd::time_spec_t >		vec_buffer_tm;
	std::vector< std::shared_ptr< short > >	vec_buffer;
	std::vector< int >					vec_buffersz;
	const int bufsz = 65536;
	//收发计数
	std::atomic<long long> rx_count ;

};

#endif // UHD_DEVICE_H
